日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MaxScript 学习笔记【有转载】

發(fā)布時(shí)間:2025/3/18 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MaxScript 学习笔记【有转载】 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

MaxScript 學(xué)習(xí)筆記【有轉(zhuǎn)載】

1. string

string類型的變量是一個(gè)數(shù)組,下列操作合法:
strName = $.name -- output: "Shemmy_03"

strName[1] --得到字符串strName第一個(gè)元素 "S"
strName[3] --得到字符串strName第一個(gè)元素 "e"
strName.count --得到字符串strName的字符個(gè)數(shù)為 9
--交換最后兩個(gè)數(shù)字的順序
num = strName.count --記下該字符串中字符的個(gè)數(shù)
temp = strName[num-1] --記下倒數(shù)第二個(gè)的數(shù)字,這里是“0”
strName[num-1]=strName[num] --將字符串中最后一個(gè)字符賦給倒數(shù)第二個(gè)數(shù)字
strName[num]=temp --將保存下來的倒數(shù)第二個(gè)的數(shù)字給字符串最后一個(gè)字符
strName -- 輸入變量名,得到:"Shemmy_30",可以看見最后兩個(gè)數(shù)字順序交換了

?

2. 相機(jī)繞圓形軌道旋轉(zhuǎn) - 路徑約束

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. ---------導(dǎo)出場(chǎng)景中的物體到指定的文件夾下-------------
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 --將場(chǎng)景中的物體導(dǎo)出到默認(rèn)的文件夾下
)


?1 將場(chǎng)景中的物體導(dǎo)出后,再導(dǎo)進(jìn)來,法向發(fā)生了變化。?
---- 導(dǎo)出obj時(shí)的選項(xiàng),optimize的normal不用勾選;
?2 貼圖導(dǎo)不出來
---- 版本的緣故,2010應(yīng)該可以。
?3 場(chǎng)景中所有的piece都導(dǎo)入到一個(gè)文件中,因?yàn)橛袝r(shí)候只需要導(dǎo)出選中的物體。
---- 先選中物體,對(duì)exportFile函數(shù)添加參數(shù)selectedOnly:true

?

4. 通過打開對(duì)話框,獲得文件名稱,而非路徑
GetSaveFileName()
GetOpenFileName()


getFiles <wild_card_filename_string>
返回指定路徑下所有文件的名稱

?

getDir
獲得默認(rèn)路徑

?

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轉(zhuǎn)化為網(wǎng)格曲面。

flagForeground <node> <boolean> -- mapped 設(shè)置前景

showclassid? --顯示物體所在的類

?

7. --------------- visibility的動(dòng)畫:-------------------------------

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. -----設(shè)置文字的關(guān)鍵幀的tangent 類型為:step
for s in shapes do
(
?for k in s.visibility.controller.keys do
?(
??k.inTangentType = k.outTangentType = #step
?)
)

?

9. view > saveActivePerspectiveView/restoreActivePerspectiveView 可以用來鎖定當(dāng)前的視圖

?

10. --------------maxScript 概念理解------------------------------
for obj in geometry do
for s in shapes do
geometry, shapes是場(chǎng)景中的兩類物體,

shape 可以用該函數(shù):convertToMesh <node>? 轉(zhuǎn)化為可編輯的網(wǎng)格,從而可以obj格式輸出;

?

與動(dòng)畫相關(guān)的概念:
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相當(dāng)于是在track view中建立了一個(gè)track,如:
a.visibility = bezier_float() --create visibility controller track in track view

對(duì)于一般屬性,如:position, scale, rotation 在track view中默認(rèn)存在,它們分別都有三個(gè)軌道:X, Y, Z, 故訪問其中一個(gè)軌道可以這樣:
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的三個(gè)軌道所有的關(guān)鍵幀的切向都設(shè)為:#step


copy, instance scene geometry的區(qū)別:
copy:復(fù)制一個(gè)物體,但是復(fù)制得到的物體與原來的物體之間是獨(dú)立的。比如修改其中一個(gè)物體的屬性,或者給它加個(gè)修改器,另一個(gè)物體仍然保持原來的。
instance: 復(fù)制一個(gè)物體,但是它得到的是原來物體的引用。即若修改其中一個(gè)物體的屬性,或者給它加個(gè)修改器,另一個(gè)物體同時(shí)發(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 --提取變換矩陣中的旋轉(zhuǎn)部分,只讀。 它的值與obj.rotation相同。

obj.pivot

obj.pos --
tranM.translationpart --提取變換矩陣中的平移部分,只讀。它的值與obj.pos相同。

obj.scale --
tranM.scalepart --提取變換矩陣中的放縮部分,只讀。它的值與obj.scale相同。

參考文件:
1. 在maxScript幫助文件中,找標(biāo)題為:Matrix3 Values
2. 在maxScript幫助文件中,找標(biāo)題為:Node Transform Properties
3. 在maxScript幫助文件中,找標(biāo)題為:Using Node Transform Properties

?

改變物體的變換矩陣
tranM = $.transform
tranM.row1 =?
tranM.row2 =?
tranM.row3 =
tranM.row4 =?
$.transform = tranM

?

?

?

  • 數(shù)組的表示方法,ms中的數(shù)組是一種稀疏數(shù)組,每個(gè)元素的類型可以不同,數(shù)組中元素的個(gè)數(shù)不限??
  • 數(shù)組的索引從1開始,而不是其他語言的從0開始,數(shù)組的長度屬性是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??
  • ??
  • 給數(shù)組中添加元素用append??
  • myArr?=?#();????--?創(chuàng)建數(shù)組??
  • append?myArr?"richard?stevens?tcp/ip?illustrated"???--?給數(shù)組中添加元素??
  • ??
  • ms中變量名以字母或者下劃線開頭,與普通編程語言不同,ms變量名不分大小寫??
  • ms中可以進(jìn)行數(shù)學(xué)運(yùn)算,并且內(nèi)建一些數(shù)學(xué)常量,如輸入pi,ms控制臺(tái)返回3.14159??
  • 字符串連接在ms中也可以,如"a"?+?"b"輸出"ab"??
  • ms也能進(jìn)行三角以及指數(shù)等運(yùn)算如sin,cosh,atan,以及l(fā)og,sqrt,exp等??
  • ??
  • random?1?100返回一個(gè)1到100之間的隨機(jī)數(shù),返回類型與第一個(gè)參數(shù)類型相同,這個(gè)值只會(huì)在每次啟動(dòng)max才會(huì)變,??
  • 要實(shí)現(xiàn)As3中的隨機(jī)數(shù),請(qǐng)使用seed?<number>來??
  • ??
  • 也支持*=,/=等操作符??
  • ??
  • ms也支持強(qiáng)轉(zhuǎn)如:??
  • s?=?sphere();??
  • msg?=?s.radius?as?String?--?as對(duì)數(shù)字進(jìn)行了強(qiáng)轉(zhuǎn),將其轉(zhuǎn)換為字符串??
  • ??
  • 行注釋的書寫以兩個(gè)橫杠開始如下:??
  • 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?顯示對(duì)應(yīng)類的一些屬性方法什么的??
  • showProperties?<node>?顯示對(duì)應(yīng)節(jié)點(diǎn)的屬性,注意這里的是只能使用實(shí)例化的物件名如mybox而不是簡單的Box類??
  • showProperties?的簡寫方式是show,這個(gè)只會(huì)顯示物件自身的屬性,一些所有節(jié)點(diǎn)的公共屬性不會(huì)打印出來??
  • 如:??
  • mybox?=?box()??
  • showProperties?mybox??
  • ??
  • 也可以使用C語言一樣的塊注釋,注釋多行??
  • /*??
  • ????what?a?fucking?day!??
  • ????we?all?want?a?code?to?live?by??
  • */??
  • ??
  • //移動(dòng)變換??
  • move?mybox?[10,0,0]??
  • //縮放語法??
  • scale?name_obj?[<x,y,z]??
  • ??
  • //旋轉(zhuǎn)比較麻煩有3種方式歐拉角,四元數(shù)以及軸角,具體看文檔?搜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.???
  • ??
  • //為場(chǎng)景中的物件添加修改器??
  • addModifier?mybox?(twist?angle:30)??
  • ??
  • 在Max腳本編輯器中,可以提供基本的ms腳本高亮,如果沒有按ctrl?+?d就可以??
  • max語言全部使用小括號(hào)進(jìn)行縮進(jìn),搞的跟lisp一樣??
  • ??
  • max中的if?then?else??
  • 如果if表達(dá)式為真,則執(zhí)行then語句,如果為假則執(zhí)行else語句,其語句語法也與普通編程語言不相同??
  • 在其if判斷語句后總是要跟著do或者then,如果只是if判斷沒有else,if表達(dá)式后面跟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??
  • (??
  • ????--?干點(diǎn)別的??
  • )??
  • ??
  • 邏輯操作符用英文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也能用??
  • 其數(shù)組循環(huán)索引為1,而不是0??
  • for?i?=?1?to?5?by?2?do??
  • (??
  • ????box_copy?=?copy?mybox???
  • ????box_copy.pos?=?[i?*?50,?0,?0]??
  • )??
  • ??
  • as3等價(jià)版??
  • for(var?i:int?=?0;?i?<?5;?i?+=?2)??
  • {??
  • ????box_copy?=?copy?mybox??
  • ????box_copy.pos?=?[i?*?50,0,0]??
  • }??
  • ??
  • //do?while?循環(huán),與普通編程語言一樣??
  • do?<expr>?while?<expr>?--?do?loop??
  • ??
  • //while循環(huán),相比于普通語言,條件表達(dá)式后面要加一個(gè)do??
  • while?<expr>?do?<expr>?--?while?loop??
  • ??
  • x?=?0??
  • while?x?>?0?do??
  • (??
  • ????x?-=?1??
  • )??
  • ??
  • 全局和本地變量分別用global和local聲明??
  • 本地變量是在代碼段塊()之間定義的變量,出了代碼塊則沒用了??
  • ??
  • 函數(shù)定義fn關(guān)鍵字表示函數(shù)開始,?之后是函數(shù)名?之后是參數(shù)個(gè)數(shù),=表示函數(shù)體的開始??
  • fn?subtract?x?y?=??
  • (??
  • ????x?-?y??
  • )??
  • ??
  • fn是function的縮寫,也可以使用function來定義函數(shù)如:??
  • function?subtract?x?y?=??
  • (??
  • ????x?-?y??
  • )??
  • ??
  • 函數(shù)參數(shù)要有默認(rèn)值的話如:??
  • function?subtract?x:0?y:0?=??
  • (??
  • ????x?-?y??
  • )??
  • ??
  • 調(diào)用時(shí)?subtract?x:4?y:2制定參數(shù)順序,ms中可選參數(shù)的順序不重要??
  • 如subtract?y:2?x:4?一樣能夠運(yùn)行??
  • ??
  • ms的函數(shù)也支持按值傳遞和按引用傳遞??
  • 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????--函數(shù)求的和??
  • 24.4????--m值保持不變,并沒有函數(shù)體中x?=?10.0發(fā)生改變??
  • OK??
  • eg.按引用傳遞??
  • ??
  • 函數(shù)返回值可以寫return也可以不寫,不寫return比寫return執(zhí)行快一點(diǎn)但是可讀性差??
  • ??
  • 在ms里面使用結(jié)構(gòu)體??
  • struct?person??
  • (??
  • ????name,??
  • ????height,??
  • ????age,??
  • ????sex??
  • )??
  • ??
  • 創(chuàng)建結(jié)構(gòu)體的一種方式??
  • stevens?=?person?name:"stevens"?height:180?age:31?sex:1??
  • stevens.name??
  • stevens.height??
  • stevens.age??
  • stevens.sex??
  • 創(chuàng)建的另一種方式??
  • stevens?=?person()??
  • stevens.name?=?"stevens"??
  • stevens.height?=?180??
  • ??
  • --?調(diào)用max軟件指令,就像flash?pro里面的fl代表flash?pro工作環(huán)境一樣??
  • max?quick?render??
  • ??
  • --?簡單的使用max彈框??
  • messagebox?"learning?maxscipt"??
  • ??
  • animationRange.start??
  • animationRange.end??
  • frameRate??
  • ??
  • 判斷一個(gè)數(shù)值的具體類型,ms里就兩種數(shù)據(jù)類型,32位有符號(hào)整形和float型??
  • if?classOf?val?==?Integer?then??
  • (??
  • ????--?是int型??
  • )??
  • else??
  • (??
  • ????--?是float類型,??
  • ) ?
  • posted on 2018-01-04 17:54 時(shí)空觀察者9號(hào) 閱讀(...) 評(píng)論(...) 編輯 收藏

    總結(jié)

    以上是生活随笔為你收集整理的MaxScript 学习笔记【有转载】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。