zoukankan      html  css  js  c++  java
  • MaxScript 学习笔记【有转载】

    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

     

     

     

    1. 数组的表示方法,ms中的数组是一种稀疏数组,每个元素的类型可以不同,数组中元素的个数不限  
    2. 数组的索引从1开始,而不是其他语言的从0开始,数组的长度属性是count  
    3. An array can be expressed in two forms. The first is:  
    4. #()  
    5. 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.  
    6. #( <expr> , <expr> )  
    7. 例如:#(3, 4, "sdsd", "test")  
    8.   
    9. 字符串用""括起来,ms里面没有char的概念,一切皆string  
    10.   
    11. 给数组中添加元素用append  
    12. myArr = #();    -- 创建数组  
    13. append myArr "richard stevens tcp/ip illustrated"   -- 给数组中添加元素  
    14.   
    15. ms中变量名以字母或者下划线开头,与普通编程语言不同,ms变量名不分大小写  
    16. ms中可以进行数学运算,并且内建一些数学常量,如输入pi,ms控制台返回3.14159  
    17. 字符串连接在ms中也可以,如"a" + "b"输出"ab"  
    18. ms也能进行三角以及指数等运算如sin,cosh,atan,以及log,sqrt,exp等  
    19.   
    20. random 1 100返回一个1到100之间的随机数,返回类型与第一个参数类型相同,这个值只会在每次启动max才会变,  
    21. 要实现As3中的随机数,请使用seed <number>来  
    22.   
    23. 也支持*=,/=等操作符  
    24.   
    25. ms也支持强转如:  
    26. s = sphere();  
    27. msg = s.radius as String -- as对数字进行了强转,将其转换为字符串  
    28.   
    29. 行注释的书写以两个横杠开始如下:  
    30. showClass "box*" -- all 3ds max classes starting box  
    31. showClass "box.*" -- all the accessible properties of the  
    32. -- box class  
    33. showClass "*:mod*" -- all the modifier classes  
    34. showClass "*.*rad*" -- all the classes with a property name   
    35. -- containing   
    36.   
    37. showClass 显示对应类的一些属性方法什么的  
    38. showProperties <node> 显示对应节点的属性,注意这里的是只能使用实例化的物件名如mybox而不是简单的Box类  
    39. showProperties 的简写方式是show,这个只会显示物件自身的属性,一些所有节点的公共属性不会打印出来  
    40. 如:  
    41. mybox = box()  
    42. showProperties mybox  
    43.   
    44. 也可以使用C语言一样的块注释,注释多行  
    45. /*  
    46.     what a fucking day!  
    47.     we all want a code to live by  
    48. */  
    49.   
    50. //移动变换  
    51. move mybox [10,0,0]  
    52. //缩放语法  
    53. scale name_obj [<x,y,z]  
    54.   
    55. //旋转比较麻烦有3种方式欧拉角,四元数以及轴角,具体看文档 搜Rotating the Box  
    56. Euler Angles  
    57. Quaternions  
    58. Angleaxis  
    59.   
    60. Moving, scaling, or rotating objects, or setting transform-related properties operates in the World Coordinate System,   
    61. by default. If you want to perform these transformations in another coordinate system, see Coordsys.   
    62.   
    63. //为场景中的物件添加修改器  
    64. addModifier mybox (twist angle:30)  
    65.   
    66. 在Max脚本编辑器中,可以提供基本的ms脚本高亮,如果没有按ctrl + d就可以  
    67. max语言全部使用小括号进行缩进,搞的跟lisp一样  
    68.   
    69. max中的if then else  
    70. 如果if表达式为真,则执行then语句,如果为假则执行else语句,其语句语法也与普通编程语言不相同  
    71. 在其if判断语句后总是要跟着do或者then,如果只是if判断没有else,if表达式后面跟do,否则后面跟then  
    72. if mybox.height == 10 do  
    73. (  
    74.     mybox.height == 1  
    75. )  
    76.   
    77. if mybox.height == 10 then  
    78. (  
    79.     mybox.height = 2  
    80. )  
    81. else  
    82. (  
    83.     -- learning maxscript  
    84. )  
    85.   
    86.   
    87. if mybox.height == 25 then  
    88. (  
    89.     mybox.height = 5  
    90. )  
    91. else mybox.height = 10 then  
    92. (  
    93.     mybox.height = 15  
    94. )  
    95. else  
    96. (  
    97.     -- 干点别的  
    98. )  
    99.   
    100. 逻辑操作符用英文not and or来表示如:  
    101. if (not s.radius == 10) then  
    102. (  
    103.     messagebox "infomation to alert"  
    104. )  
    105.   
    106. if (x == 5 and y == 6) then  
    107. (  
    108.     z = 10  
    109. )  
    110.   
    111. if (x == 5 or y == 6) then  
    112. (  
    113.     z = 0  
    114. )  
    115.   
    116. 在ms中真可以用on表示,假用off表示,true和false也能用  
    117. 其数组循环索引为1,而不是0  
    118. for i = 1 to 5 by 2 do  
    119. (  
    120.     box_copy = copy mybox   
    121.     box_copy.pos = [i * 50, 0, 0]  
    122. )  
    123.   
    124. as3等价版  
    125. for(var i:int = 0; i < 5; i += 2)  
    126. {  
    127.     box_copy = copy mybox  
    128.     box_copy.pos = [i * 50,0,0]  
    129. }  
    130.   
    131. //do while 循环,与普通编程语言一样  
    132. do <expr> while <expr> -- do loop  
    133.   
    134. //while循环,相比于普通语言,条件表达式后面要加一个do  
    135. while <expr> do <expr> -- while loop  
    136.   
    137. x = 0  
    138. while x > 0 do  
    139. (  
    140.     x -= 1  
    141. )  
    142.   
    143. 全局和本地变量分别用global和local声明  
    144. 本地变量是在代码段块()之间定义的变量,出了代码块则没用了  
    145.   
    146. 函数定义fn关键字表示函数开始, 之后是函数名 之后是参数个数,=表示函数体的开始  
    147. fn subtract x y =  
    148. (  
    149.     x - y  
    150. )  
    151.   
    152. fn是function的缩写,也可以使用function来定义函数如:  
    153. function subtract x y =  
    154. (  
    155.     x - y  
    156. )  
    157.   
    158. 函数参数要有默认值的话如:  
    159. function subtract x:0 y:0 =  
    160. (  
    161.     x - y  
    162. )  
    163.   
    164. 调用时 subtract x:4 y:2制定参数顺序,ms中可选参数的顺序不重要  
    165. 如subtract y:2 x:4 一样能够运行  
    166.   
    167. ms的函数也支持按值传递和按引用传递  
    168. eg.按值传递  
    169. fn addnums2 x y =  
    170. (  
    171.     x = 10.0;  
    172.     x + y  
    173. )  
    174. m = 24.4  
    175. n = 23  
    176. addnums2 m n  
    177. m  
    178.   
    179. 输出  
    180. addnums2()  
    181. 24.4    --m  
    182. 23      --n  
    183. 33.0    --函数求的和  
    184. 24.4    --m值保持不变,并没有函数体中x = 10.0发生改变  
    185. OK  
    186. eg.按引用传递  
    187.   
    188. 函数返回值可以写return也可以不写,不写return比写return执行快一点但是可读性差  
    189.   
    190. 在ms里面使用结构体  
    191. struct person  
    192. (  
    193.     name,  
    194.     height,  
    195.     age,  
    196.     sex  
    197. )  
    198.   
    199. 创建结构体的一种方式  
    200. stevens = person name:"stevens" height:180 age:31 sex:1  
    201. stevens.name  
    202. stevens.height  
    203. stevens.age  
    204. stevens.sex  
    205. 创建的另一种方式  
    206. stevens = person()  
    207. stevens.name = "stevens"  
    208. stevens.height = 180  
    209.   
    210. -- 调用max软件指令,就像flash pro里面的fl代表flash pro工作环境一样  
    211. max quick render  
    212.   
    213. -- 简单的使用max弹框  
    214. messagebox "learning maxscipt"  
    215.   
    216. animationRange.start  
    217. animationRange.end  
    218. frameRate  
    219.   
    220. 判断一个数值的具体类型,ms里就两种数据类型,32位有符号整形和float型  
    221. if classOf val == Integer then  
    222. (  
    223.     -- 是int型  
    224. )  
    225. else  
    226. (  
    227.     -- 是float类型,  
    228. )  
  • 相关阅读:
    Java 线程终止
    Android Jetpack架构之ProcessLifeCycleOwner
    Android Jetpack架构之LifecycleService
    Android Jetpack架构之Lifecycle
    Android Jetpack架构
    深入理解JNI技术
    Java虚拟机类加载器机制
    Java HashMap、HashTable、ConcurrentHashMap区别
    Java内存分配策略
    Java 方法分派
  • 原文地址:https://www.cnblogs.com/timeObjserver/p/8194751.html
Copyright © 2011-2022 走看看