1. string
string類型的變量是一個數組,下列操作合法:
strName = $.name -- output: "Shemmy_03"
strName[1] --得到字符串strName第一個元素 "S"
strName[3] --得到字符串strName第一個元素 "e"
strName.count --得到字符串strName的字符個數爲 9
--交換最後兩個數字的順序
num = strName.count --記下該字符串中字符的個數
temp = strName[num-1] --記下倒數第二個的數字,這裏是“0”
strName[num-1]=strName[num] --將字符串中最後一個字符賦給倒數第二個數字
strName[num]=temp --將保存下來的倒數第二個的數字給字符串最後一個字符
strName -- 輸入變量名,得到:"Shemmy_30",可以看見最後兩個數字順序交換了
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 將場景中的物體導出後,再導進來,法向發生了變化。
---- 導出obj時的選項,optimize的normal不用勾選;
?2 貼圖導不出來
---- 版本的緣故,2010應該可以。
?3 場景中所有的piece都導入到一個文件中,因爲有時候只需要導出選中的物體。
---- 先選中物體,對exportFile函數添加參數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轉化爲網格曲面。
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 可以用該函數:convertToMesh <node> 轉化爲可編輯的網格,從而可以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的區別:
copy:複製一個物體,但是複製得到的物體與原來的物體之間是獨立的。比如修改其中一個物體的屬性,或者給它加個修改器,另一個物體仍然保持原來的。
instance: 複製一個物體,但是它得到的是原來物體的引用。即若修改其中一個物體的屬性,或者給它加個修改器,另一個物體同時發生改變。
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
- 數組的表示方法,ms中的數組是一種稀疏數組,每個元素的類型可以不同,數組中元素的個數不限
- 數組的索引從1開始,而不是其他語言的從0開始,數組的長度屬性是count
- An array can be expressed in two forms. The first is:
- #()
- This is the most basic type of array: an empty one. It is important to note that all arrays must be defined with the number character (#) and a pair of parentheses.
- #( <expr> , <expr> )
- 例如:#(3, 4, "sdsd", "test")
- 字符串用""括起來,ms裏面沒有char的概念,一切皆string
- 給數組中添加元素用append
- myArr = #(); -- 創建數組
- append myArr "richard stevens tcp/ip illustrated" -- 給數組中添加元素
- ms中變量名以字母或者下劃線開頭,與普通編程語言不同,ms變量名不分大小寫
- ms中可以進行數學運算,並且內建一些數學常量,如輸入pi,ms控制檯返回3.14159
- 字符串連接在ms中也可以,如"a" + "b"輸出"ab"
- ms也能進行三角以及指數等運算如sin,cosh,atan,以及log,sqrt,exp等
- random 1 100返回一個1到100之間的隨機數,返回類型與第一個參數類型相同,這個值只會在每次啓動max纔會變,
- 要實現As3中的隨機數,請使用seed <number>來
- 也支持*=,/=等操作符
- ms也支持強轉如:
- s = sphere();
- msg = s.radius as String -- as對數字進行了強轉,將其轉換爲字符串
- 行註釋的書寫以兩個橫槓開始如下:
- showClass "box*" -- all 3ds max classes starting box
- showClass "box.*" -- all the accessible properties of the
- -- box class
- showClass "*:mod*" -- all the modifier classes
- showClass "*.*rad*" -- all the classes with a property name
- -- containing
- showClass 顯示對應類的一些屬性方法什麼的
- showProperties <node> 顯示對應節點的屬性,注意這裏的是隻能使用實例化的物件名如mybox而不是簡單的Box類
- showProperties 的簡寫方式是show,這個只會顯示物件自身的屬性,一些所有節點的公共屬性不會打印出來
- 如:
- mybox = box()
- showProperties mybox
- 也可以使用C語言一樣的塊註釋,註釋多行
- /*
- what a fucking day!
- we all want a code to live by
- */
- //移動變換
- move mybox [10,0,0]
- //縮放語法
- scale name_obj [<x,y,z]
- //旋轉比較麻煩有3種方式歐拉角,四元數以及軸角,具體看文檔 搜Rotating the Box
- Euler Angles
- Quaternions
- Angleaxis
- Moving, scaling, or rotating objects, or setting transform-related properties operates in the World Coordinate System,
- by default. If you want to perform these transformations in another coordinate system, see Coordsys.
- //爲場景中的物件添加修改器
- addModifier mybox (twist angle:30)
- 在Max腳本編輯器中,可以提供基本的ms腳本高亮,如果沒有按ctrl + d就可以
- max語言全部使用小括號進行縮進,搞的跟lisp一樣
- max中的if then else
- 如果if表達式爲真,則執行then語句,如果爲假則執行else語句,其語句語法也與普通編程語言不相同
- 在其if判斷語句後總是要跟着do或者then,如果只是if判斷沒有else,if表達式後面跟do,否則後面跟then
- if mybox.height == 10 do
- (
- mybox.height == 1
- )
- if mybox.height == 10 then
- (
- mybox.height = 2
- )
- else
- (
- -- learning maxscript
- )
- if mybox.height == 25 then
- (
- mybox.height = 5
- )
- else mybox.height = 10 then
- (
- mybox.height = 15
- )
- else
- (
- -- 乾點別的
- )
- 邏輯操作符用英文not and or來表示如:
- if (not s.radius == 10) then
- (
- messagebox "infomation to alert"
- )
- if (x == 5 and y == 6) then
- (
- z = 10
- )
- if (x == 5 or y == 6) then
- (
- z = 0
- )
- 在ms中真可以用on表示,假用off表示,true和false也能用
- 其數組循環索引爲1,而不是0
- for i = 1 to 5 by 2 do
- (
- box_copy = copy mybox
- box_copy.pos = [i * 50, 0, 0]
- )
- as3等價版
- for(var i:int = 0; i < 5; i += 2)
- {
- box_copy = copy mybox
- box_copy.pos = [i * 50,0,0]
- }
- //do while 循環,與普通編程語言一樣
- do <expr> while <expr> -- do loop
- //while循環,相比於普通語言,條件表達式後面要加一個do
- while <expr> do <expr> -- while loop
- x = 0
- while x > 0 do
- (
- x -= 1
- )
- 全局和本地變量分別用global和local聲明
- 本地變量是在代碼段塊()之間定義的變量,出了代碼塊則沒用了
- 函數定義fn關鍵字表示函數開始, 之後是函數名 之後是參數個數,=表示函數體的開始
- fn subtract x y =
- (
- x - y
- )
- fn是function的縮寫,也可以使用function來定義函數如:
- function subtract x y =
- (
- x - y
- )
- 函數參數要有默認值的話如:
- function subtract x:0 y:0 =
- (
- x - y
- )
- 調用時 subtract x:4 y:2制定參數順序,ms中可選參數的順序不重要
- 如subtract y:2 x:4 一樣能夠運行
- ms的函數也支持按值傳遞和按引用傳遞
- eg.按值傳遞
- fn addnums2 x y =
- (
- x = 10.0;
- x + y
- )
- m = 24.4
- n = 23
- addnums2 m n
- m
- 輸出
- addnums2()
- 24.4 --m
- 23 --n
- 33.0 --函數求的和
- 24.4 --m值保持不變,並沒有函數體中x = 10.0發生改變
- OK
- eg.按引用傳遞
- 函數返回值可以寫return也可以不寫,不寫return比寫return執行快一點但是可讀性差
- 在ms裏面使用結構體
- struct person
- (
- name,
- height,
- age,
- sex
- )
- 創建結構體的一種方式
- stevens = person name:"stevens" height:180 age:31 sex:1
- stevens.name
- stevens.height
- stevens.age
- stevens.sex
- 創建的另一種方式
- stevens = person()
- stevens.name = "stevens"
- stevens.height = 180
- -- 調用max軟件指令,就像flash pro裏面的fl代表flash pro工作環境一樣
- max quick render
- -- 簡單的使用max彈框
- messagebox "learning maxscipt"
- animationRange.start
- animationRange.end
- frameRate
- 判斷一個數值的具體類型,ms裏就兩種數據類型,32位有符號整形和float型
- if classOf val == Integer then
- (
- -- 是int型
- )
- else
- (
- -- 是float類型,
- )