MAXSCRIPT笔记
本文最后更新于826 天前,其中的信息可能已经过时,如有错误请发送邮件到84581927@qq.com
  1 getnodebyname "circle01"
2 for o in objects do
if o.name == "circle01" then
3 select $Box* – select any objects with the name box at the beginning of them.
4 move, scale rotate
move obj [x,y,z]
scale obj [x,y,z]
rotate obj (eulerangles x y z)
rot = eulerangles x y z --建立一个四元数旋转,可以在需要地方使用
5 max commands in maxscript 
n addition to controlling modeling and animation, MAXScript scripts can invoke 3ds Max menu and toolbar commands. You do this using the "max" keyword.
for example:
max file open
max unhide all
max quick render
help:
max time ?
max sel ?
max ?

6 select
select obj --单选,选择当前,之前的被释放
selectmore obj --多选
deselect obj
deselectNode node

clearselection() --清空所有

max select all
max select child --每调用一次,选中一个节点
7 show class "*"
show class "box"
show class "box.*"
8 --exit 跳出循环,而不是使用break
9 --函数
function myFunc x y = () --普通函数,调用: myFunc 3 4
function myFunc x y:20 = () --带默认参数的函数,调用:myFunc 3或 myFunc 3 y:4
function myFunc x:10 y:20 = () --全默认参数函数,调用: myFunc x:3 y:4或myFunc y:4 x:3
10 --文件操作相关
getFilenamePath "c:/test/abc.txt" --"c:\test\"
getOpenFileName 
caption:"Render To Texture Object Presets Open" 
filename:(getDir #renderPresets + @"") 
types:"Object Preset(*.rtp)|*.rtp" 
historyCategory:"RTTObjectPresets"
getSavePath caption:"my title" initialDir:"$scripts"
file="g:\\subdir1\\subdir2\\myImage.jpg"

filenameFromPath file -- returns: "myImage.jpg"
getFilenamePath file -- returns: "g:\subdir1\subdir2\"
getFilenameFile file -- returns: "myImage"
getFilenameType file -- returns: ".jpg"
pathIsNetworkPath "c:\\temp\\test.txt" --returns: false
pathIsNetworkPath "\\\\someserver\\temp\\test.txt" --returns: true
11 --string 
findString "Thanks for all the fish!" "all" -- returns 12
filterString "MAX Script, is-dead-funky" ", -" --#("MAX","Script","is","dead","funky")
s1=replace "1234567890" 5 3 "inserted string" --"1234inserted string890"

s ="Balerofon"
ss = substring s 5 3-- returns "rof"
ss = substring s 5 -1-- returns "rofon"
ss = substring s 5 100-- returns "rofon"

s="text1"
matchPattern s pattern:"text?"-- returns true
matchPattern s pattern:"T*"-- returns true
matchPattern s pattern:"T*"ignoreCase:false-- returns false
matchPattern s pattern:"s*"-- returns false

trimright "MAXScript \n " --spaces and new line trimmed
--"MAXScript"
trimright "$Teapot0911" "1234567890" --remove trailing numbers
--"$Teapot"

12 --Working with Values
--------------------------------------------------------
ClassOf SuperClassOf
--------------------------------------------------------
b Box GeometryClass
box GeometryClass Node
GeometryClass Node MAXWrapper
Node MAXWrapper Value
MAXWrapper Value Value
Value Value Value
--------------------------------------------------------

--FOR EXAMPLE
--either of the following will collect all objects of class box into variable allBoxes :
allBoxes=for obj in $* where (isKindOf obj box) collect obj
allBoxes=#()
for obj in $* do (if classOf obj == box then append allBoxes obj)

--the following function limits the choices to shape objects:
fn shape_filt obj = isKindOf obj Shape
13 --数组相关操作
--赋值
arr = #()
append arr 3
append arr "hello"
arr[3] = 12.2

--遍历
for o in arr do print o
for i=1 to arr.count print arr[i]

14 --maxscript language reference -collections
--ObjectSets represent the main scene object categories in 3ds Max. 
objects --all the objects
geometry --the standard 3ds Max categories...
lights
cameras
helpers
shapes
systems
spacewarps
selection --the current selection

--for example
for s in shapes do print s
for i=1 to geometry.count do print geometry[i]
15 --rootscene 与 rootnode
rootNode 
------------------------------------------------------------------------------------------
Contains a Node value that defines the root node of the scene.
The root node does not physically exist in the scene, rather it is a special node that is the parent node of all nodes that are not linked to another node.
The scene objects can be enumerated by accessing the children property of the root node.
A run-time error is generated if you try to perform other node operations on the root node.

rootScene 
------------------------------------------------------------------------------------------
Represents the scene root in scripts and Macro Recorder output.
The subAnims of rootScene include the node hierarchy, the Material Editor, Track View, Scene Material Library etc

--遍历场景中最***的物体
for o in rootNode.children do
(
print o
print o.parent --undefined
)

--注意,MAX场景是以树结构来组织的,一个场景可以多个不相连的子树,也就是有多个根结点
--这些子树都以rootnode为根,但parent却是undefined,如上

--导出FBX模型与动画
--1,导出模型和骨骼层级
--注意:骨骼层级必须和模型一起导出,否则对它设置动画无效果,这个很容易忽视

--等价于 select geometry
for o in objects do
(
cls = classof o
if cls == Biped_Object or cls == BoneGeometry or cls == PolyMeshObject then
(--选择所有网格,和所有骨骼(biped_object, boneGeometry)
selectmore o
)

)

--2,导出不带模型的纯动画
for o in objects do
(
cls = classof o
if cls == Biped_Object or cls == BoneGeometry then
(--所有骨骼(biped_object, boneGeometry)
selectmore o
)
)
16 --material
------------------------------------------------------------------------------------------
--The following will render the diffuse map assigned to the material of object $foo
-- to a bitmap of size 640x480 and save it to the file "foodif.bmp"
------------------------------------------------------------------------------------------
rm = renderMap $foo.material.diffuseMap size:[640,480] \
fileName:"foodif.bmp"
save rm
close rm

------------------------------------------------------------------------------------------
--材质,每个模型只有一个material,但这个material可以是单材质或多重材质
--每个材质可以有多个贴图,对应各种颜色: 
--diffusemap :漫反射
--不透明贴图:不透明度
--高光贴图:高光颜色
--光泽度贴图:光泽度
--自发光贴图:自发光
--凹凸贴图,反射贴图,折射贴图,置换贴图。。。。
------------------------------------------------------------------------------------------
showTextureMap $foo.material $foo.material.diffuseMap on
tm = checker()
mat = standardMaterial diffuseMap:tm
mm = multimaterial() --多重材质
mm[1] = mat
$box01.material = mm
showTextureMap mm[1] tm on

getnumsubmtls --获取子材质数量

-----------------------------------------------------------
--如何获取模型上的贴图
b = box()
b.material.diffuseMap.filename --或
b.material.diffuseMap.bitmap
17 --show properites
b = box()
showproperties b.material
18 --external command
--注意,DOS命令是WINDOWS网格的分割符,是下坡线,maxscript是上坡线,必须转换
doscommand "copy f:\\abc.fbx f:\\test" --将 f:\abc.fbx拷贝到f:\test文件夹下
文末附加内容
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇