MaxScript 学习笔记【有转载】
MaxScript 學習筆記【有轉載】
1. string
string類型的變量是一個數(shù)組,下列操作合法:
strName = $.name -- output: "Shemmy_03"
strName[1] --得到字符串strName第一個元素 "S"
strName[3] --得到字符串strName第一個元素 "e"
strName.count --得到字符串strName的字符個數(shù)為 9
--交換最后兩個數(shù)字的順序
num = strName.count --記下該字符串中字符的個數(shù)
temp = strName[num-1] --記下倒數(shù)第二個的數(shù)字,這里是“0”
strName[num-1]=strName[num] --將字符串中最后一個字符賦給倒數(shù)第二個數(shù)字
strName[num]=temp --將保存下來的倒數(shù)第二個的數(shù)字給字符串最后一個字符
strName -- 輸入變量名,得到:"Shemmy_30",可以看見最后兩個數(shù)字順序交換了
?
2. 相機繞圓形軌道旋轉 - 路徑約束
NowTime +=duration?
?animate on at time NowTime
?(
??
????cirCenter = $Camera01.target.pos
??camPath = circle() --圓形軌道
??camPath.center = cirCenter
??camPath.center.z = $Camera01.pos.z --set path center
??camPath.radius = distance cirCenter $Camera01.pos --set path radius
??pc = path_constraint() --create a path constraint
??pc.path = camPath --assign current path
??$Camera01.pos.controller = pc -- attach obj with path
)
?
3. ---------導出場景中的物體到指定的文件夾下-------------
for obj in geometry do
(
??select obj
?exportFile ("E://Shemmy//Shemmy_Research//3DPuzzle//Oc29_animationSample_script//animation_text_list _withMtl//" + getFilenameFile (obj.name)+".obj") #noPrompt selectedOnly:true --將場景中的物體導出到默認的文件夾下
)
?1 將場景中的物體導出后,再導進來,法向發(fā)生了變化。?
---- 導出obj時的選項,optimize的normal不用勾選;
?2 貼圖導不出來
---- 版本的緣故,2010應該可以。
?3 場景中所有的piece都導入到一個文件中,因為有時候只需要導出選中的物體。
---- 先選中物體,對exportFile函數(shù)添加參數(shù)selectedOnly:true
?
4. 通過打開對話框,獲得文件名稱,而非路徑
GetSaveFileName()
GetOpenFileName()
getFiles <wild_card_filename_string>
返回指定路徑下所有文件的名稱
?
getDir
獲得默認路徑
?
5. material:
--------------get and set material----------------------------
<node>.material Material default: undefined
Get or set the object's material.
?
---------------- meditMaterials -------------------
meditMaterials
Contains a virtual array of materials and root level maps corresponding to the slots in the material editor. You can access material editor materials and root level maps via array indexing and iterate over them in a for loop. The array can be indexed by number to specify slot number or name or string to select by material and root level map name.
eg:
$foo.material = meditMaterials[1]
meditMaterials["foo mat"].diffuse = red
for m in meditMaterials do print m.diffuseMap
meditMaterials[1]=standard()
print meditMaterials.count -- number of slots
?
6.?
convertToMesh <node>; 可以將shape轉化為網(wǎng)格曲面。
flagForeground <node> <boolean> -- mapped 設置前景
showclassid? --顯示物體所在的類
?
7. --------------- visibility的動畫:-------------------------------
a.visibility = bezier_float() --create visibility controller track
at time (TheCurrentFrame + 1.0) a.visibility.controller.value = 1.0
at time (TheCurrentFrame) a.visibility.controller.value = 0.0
?
或者:
????curObj.visibility = bezier_float()
????
????k = addNewKey curObj.visibility.controller time1
????k.value = 1
????--k.inTangentType = #step
????
????k = addNewKey curObj.visibility.controller time2
????k.value = 0
?
8. -----設置文字的關鍵幀的tangent 類型為:step
for s in shapes do
(
?for k in s.visibility.controller.keys do
?(
??k.inTangentType = k.outTangentType = #step
?)
)
?
9. view > saveActivePerspectiveView/restoreActivePerspectiveView 可以用來鎖定當前的視圖
?
10. --------------maxScript 概念理解------------------------------
for obj in geometry do
for s in shapes do
geometry, shapes是場景中的兩類物體,
shape 可以用該函數(shù):convertToMesh <node>? 轉化為可編輯的網(wǎng)格,從而可以obj格式輸出;
?
與動畫相關的概念:
All animation in 3ds max is implemented using one of the many controller classes accesible in the track view and montion panel.
重要概念:
cotroller calsses
track view, motion panel
?
cotroller相當于是在track view中建立了一個track,如:
a.visibility = bezier_float() --create visibility controller track in track view
對于一般屬性,如:position, scale, rotation 在track view中默認存在,它們分別都有三個軌道:X, Y, Z, 故訪問其中一個軌道可以這樣:
b.rotation.controller[1].controller.keys -- all keys on X rotation track
比如這樣的操作:
for i = 1 to 3 do
(
for k in b.rotation.controller[i].controller.keys do
?(
??k.inTangentType = k.outTangentType = #step
?)
) --rotation的三個軌道所有的關鍵幀的切向都設為:#step
copy, instance scene geometry的區(qū)別:
copy:復制一個物體,但是復制得到的物體與原來的物體之間是獨立的。比如修改其中一個物體的屬性,或者給它加個修改器,另一個物體仍然保持原來的。
instance: 復制一個物體,但是它得到的是原來物體的引用。即若修改其中一個物體的屬性,或者給它加個修改器,另一個物體同時發(fā)生改變。
?
user interface items: command panels, rollouts, dialogs, commands, windows, viewport
By switching from one tabbed window to another in command panesl, different commands then become available to the user.For example, mesh editing commands are only available from the modify panel.
SetCommandPanelTaskMode [mode:] <panel name> --switch to current command panel
GetCommandPanelTaskMode() --get currently opened command panel
command panel names,such as #create, #modify, #hierarchy...
Understanding objects and classes
classOf obj/class name
?
11. maxScript 變換矩陣
tranM = obj.transform --得到物體的變換矩陣
obj.objecttransform --得到物體的變換矩陣,只讀
obj.rotation
tranM.rotationpart --提取變換矩陣中的旋轉部分,只讀。 它的值與obj.rotation相同。
obj.pivot
obj.pos --
tranM.translationpart --提取變換矩陣中的平移部分,只讀。它的值與obj.pos相同。
obj.scale --
tranM.scalepart --提取變換矩陣中的放縮部分,只讀。它的值與obj.scale相同。
參考文件:
1. 在maxScript幫助文件中,找標題為:Matrix3 Values
2. 在maxScript幫助文件中,找標題為:Node Transform Properties
3. 在maxScript幫助文件中,找標題為:Using Node Transform Properties
?
改變物體的變換矩陣
tranM = $.transform
tranM.row1 =?
tranM.row2 =?
tranM.row3 =
tranM.row4 =?
$.transform = tranM
?
?
?
posted on 2018-01-04 17:54 時空觀察者9號 閱讀(...) 評論(...) 編輯 收藏
總結
以上是生活随笔為你收集整理的MaxScript 学习笔记【有转载】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LUA和C#关于字符串中\0的处理
- 下一篇: U3D中的又一个坑