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. )  

posted on 2018-01-04 17:54 时空观察者9号 阅读(...) 评论(...) 编辑 收藏

MaxScript 学习笔记【有转载】相关推荐

  1. CVX学习笔记(转载

    网址链接:CVX学习笔记 一.使用报错及问题分析案例1: 1)错误示例 variable u(9); x(1) = 1; for k = 1 : 9,x(k+1) = sqrt( x(k) + u(k ...

  2. 【Python从入门到入门】一、基础学习笔记【转载】

    本文转载于简书,链接为:https://www.jianshu.com/p/8b87c6e9798f 因学习需要,转载至CSDN供自己和更多有兴趣的开发者学习查看. 第一部分 初识Python语言 第 ...

  3. 数据结构学习笔记(转载)

    数据结构笔记(1) 第一章 概  论 1.数据:信息的载体,能被计算机识别.存储和加工处理. 2.数据元素:数据的基本单位,可由若干个数据项组成,数据项是具有独立含义的最小标识单位. 3.数据结构:数 ...

  4. Linux内核模块学习笔记(转载)

    Linux内核模块    Linux设备驱动会以内核模块的形式出现,因此学会编写Linux内核模块编程是学习linux设备驱动的先决条件. 1.1linux内核模块简介 Linux内核的整体结构非常庞 ...

  5. 支付风控学习笔记(转载)

    最近看了一些支付风控方面的文章,顺便了解一下支付风控的流程,于是将看的几篇文章整理了一下,写了这篇笔记.对于这块本人非专业人士,如有理解不当的地方请多多指正. 目录 1.支付风险类型 2.支付风控流程 ...

  6. springMVC学习笔记_转载(一)-----springMVC原理

    阅读目录 一.什么是springmvc 二.mvc在b/s系统下的应用 三.SpringMVC框架介绍 回到顶部 一.什么是springmvc springMVC是spring框架的一个模块,spri ...

  7. 孙鑫VC++学习笔记(转载至程序员之家--虎非龙)[11--15] .

    第11课 1.创建4个菜单,为其添加消息响应,用成员变量保存绘画类型.添加LButtonDown和Up消息. 2.当窗口重绘时,如果想再显示原先画的数据,则需要保存数据.为此创建一个新类来记录绘画类型 ...

  8. 孙鑫VC++学习笔记(转载至程序员之家--虎非龙)[11--15]

    第11课 1.创建4个菜单,为其添加消息响应,用成员变量保存绘画类型.添加LButtonDown和Up消息. 2.当窗口重绘时,如果想再显示原先画的数据,则需要保存数据.为此创建一个新类来记录绘画类型 ...

  9. 阿赵的MaxScript学习笔记分享五《UI组件使用篇》

    大家好,我是阿赵.这个专题的内容比较多,所以抓紧时间更新.这是第五篇,UI组件使用篇. 这里主要是把maxscript的rollout窗体支持的UI组件列举一下,并每个组件写一个使用范例,以方便理解和 ...

最新文章

  1. Pipe Utilization管道利用率
  2. Hivr:基于BCH的社交应用
  3. IPv6 — 移动性支持
  4. sqlite3.h--dbhelp.h数据库底层文件
  5. Spring下@ResponseBody响应中文内容乱码问题
  6. 数据结构Java03【(时间、空间复杂度),排序(冒泡、快速、插入、希尔、选择、归并、基数、队列基数)】
  7. 微信小程序销毁某一注册函数_微信小程序云开发API 删除一条记录
  8. C语言之原码、反码和补码
  9. 《Servlet和JSP学习指南》一2.5 小结
  10. Cocos2dx使用 TexturePacker导出的.plist
  11. 【GIS】GIS矢量空间分析(上)
  12. 硬盘格式化了怎么恢复数据
  13. InfoPath 2007 常见问题
  14. 幂模函数方程组的解法(一)
  15. 麦肯锡精英的48个工作习惯~书摘
  16. 拨开字符编码的迷雾--编译器如何处理文件编码
  17. 野路子玩Qt,第三十一集,擦玻璃游戏
  18. java反射的作用于原理、初学者
  19. 【微服务】配置了端口号却还是在 8080端口启动的原因
  20. 美团后台开发一面算法题

热门文章

  1. 笔记-信息系统开发基础-信息系统开发模型
  2. PHP 中 9 大缓存技术总结
  3. CentOS中启动Jar包、后台启动、查看输出日志、查看服务进程、杀死进程
  4. Android中实现长按照片弹出右键菜单
  5. AndroidStudio修改默认C盘配置文件夹(.android.gradle.AndroidStudio)以及修改后避免踩的坑
  6. Winform中在使用VS+svn进行协同开发时添加引用时的相对路径和绝对路径的问题
  7. Winform中设置ZedGraph的X轴的刻度根据曲线获取
  8. SpringBoot中在配置文件中限制文件上传的大小
  9. SpringBoot中整合Mail实现发送模板邮件
  10. Eclipse中新建SpringBoot项目完成对json、pojo、map、list的请求