February 19, 2023

MAXScript学习笔记

MAXScript学习笔记

简介

MAXscript是3ds Max内置脚本语言,Max2.0及以后加入的功能。也能使用在与3ds Max相关的产品中如Autodesk VIZ,character studio,Plasma和GMax;脚本可使用于建模,动画,材质,渲染等等。它是专门为3D Studio Max设计的。

环境配置

3dsMax内部的环境

VSCode环境配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
-- 导出资源的例子
rollout AnimExporter "动画资产导出"
(
group "Export Setting" (

edittext ExportPath "路径:"

button GetCurrentPath "获取路径" width: 200 height:30


)
button Export "导出" width: 200 height:30
button ShowIn "打开目录" width: 200 height:30
-- Get Folder Path
fn GetFolderPath =(
folderPath = maxFilePath
return folderPath
)
-- Fbx Export
fn ExportFbx go assetPath =(
path = assetPath+go.name
exportFile path #noPrompt selectedOnly:true using:FBXEXP
)

-- Get Head Dummy
fn GetHeadDummy gos =(
result
for i in gos do
if Classof i == Dummy && i.children.count == 0 && i.parent==null do
result =i
return i
)
-- Get Polys
fn GetPolys gos =(
result = #()
for i in gos do
if Classof i == PolyMeshObject do
append result i
return result
)

fn GetHairPolys PolyMeshs =(
result
for i in PolyMeshs do (
polyMeshName = i.name
if matchpattern i.name pattern: "*Hair*" == true do (
result = i
)
)
return result
)
-- 获得所有子集 http://tk.v5cg.com/help/250.html
fn RecurseChildren RecurseCollector currNode=
(
append RecurseCollector currNode
local childNodes = currNode.children
if(childNodes.count !=0)then for c in childNodes do
(
RecurseChildren RecurseCollector c
)
)

fn GetChildrens currNode=
(
-- 清空集合
RecurseCollector = #()
-- 开始递归
RecurseChildren RecurseCollector currNode
-- 返回
return RecurseCollector
)
-- 获得skin列表
fn GetBipsOnSkin skin =(
result = #()
num = skinOps.GetNumberBones skin
for i=1 to num do
boneName = skinOps.GetBoneName skin i 0
append result boneName
return result
)
-- 按键
on GetCurrentPath pressed do
(
path = GetFolderPath()
if(path.count==0)
then(
messageBox "错误!"
)
else(
ExportPath.text = GetFolderPath()
)

)

on Export pressed do
(
aa = $
ExportFbx aa ExportPath.text
)

on ShowIn pressed do
(

a= $.modifiers[#Skin]
cc = GetBipsOnSkin a
for i in cc do
print i

)

)

-- 获取当前文件的地址
-- 获取当前文件中的物体列表
-- 列表
-- Editable_Poly
-- Dummy

-- 获得层级的全部子级
-- 创建组合好的选择列表
-- 按mesh名创建FBX
-- 分别导出到当前文件地址下



createdialog AnimExporter 220 200

参考

  1. 霜狼_may-Maxscrip教程

  2. 3ds MAXscript 脚本语言完全学习手册

关于本文

本文作者 Master Gong Sheng, 许可由 CC BY-NC 4.0.