MaxScript入门指引系列(四)MaxScript Editor和Macroscripts

MaxScript入门指引系列(四)MaxScript Editor和Macroscripts_第1张图片

MaxScript Listener用来测试小段代码,测试成功后再写到最终的脚本语言编辑器Eidtor。
故在用Editor写脚本程序时,对于单独的功能可以先在Listener进行测试。故推荐使用两个文件夹:一个用来存放用Listener写的代码,另一个用来存放最终的代码,它应含有错误检查,文档及界面等。ctrl+E,执行代码。

1. 旋转

  • 上次我们讲过移动move,使用比较简单。旋转在MaxScript中的使用时比较奇怪的,需要先创建一个旋转物体("rotation object"),然后再应用rotate.
  • 旋转有三种类型:Euler angles, Quaternions(四元数) and Angleaxis.
    eulerAngles <x_degrees> <y_degrees> <z_degrees>
    --第一,二,三个参数分别表示绕着x轴,y轴,z轴选转的角度
    quat <x_float> <y_float> <z_float> <w_float>
    The x, y, z values make up the vector portion. w is the angle of rotation about the vector.--x,y,z构成一个向量作为旋转轴,w作为绕该轴旋转的角度。
    angleaxis <degrees_float> <axis_point3> --第二个参数类型是Point3,它作为旋转轴,第一个参数是绕着该轴旋转的角度。
  • 下面以eulerAngles为例:
    step1: 创建旋转物体,cube_rot_obj = eulerangles 0 20 0,意思是创建了一个绕着y轴旋转20度的旋转;
    step2: 应用旋转动作,rotate $ cube_rot_obj

2. 代码注释用--

 

3. Macroscripts - 用来自定义快捷键,菜单和按钮

创建了Macroscript,可以与快捷键,菜单和按钮绑定。把一些常用的功能制成Macroscript,方便以后使用。

  • 创建Macroscript的模板(在Editor中输入)是这样的:
    MacroScript Script_Name category:"Category Name" buttonText:"Name of Button or Menu Item" tooltip:"Tooltip Name" --这一部分输入时,要主要空格
    (
    your script code goes here
    )
  • 创建Macroscript并将其制成menu的流程,举个例子说明:

step1: 在Editor中输入:
MacroScript Random_Rotate category:"Shemmy Tools" buttonText:"Random Rotate" tooltip:"Random Rotate"
(
for obj in $ do -- Loop over currently selected objects
(
randXrot = random -3.0 3.0 -- create a random X rotation value and store as a variable
randYrot = random -3.0 3.0 -- create a random Y rotation value and store as a variable
randZrot = random -3.0 3.0 -- create a random Z rotation value and store as a variable
rot_obj = eulerangles randXrot randYrot randZrot -- Build our rotation object and store
rotate obj rot_obj -- Apply the rotation to the current obj
)
)
保存它并且按ctrl+E执行。如果没有问题的话,在listener窗口中会出现一个数字,但是此时对场景中的物体不产生影响;否则如果有问题,则会在listener窗口中提示错误。

 

step2: 打开Customize > Customize User Interface, 选则menu标签,在Catergory的下拉中应该能找到Shemmy Tools,同时在Action面板中出现了我们自定义的动作Random Rotate;
MaxScript入门指引系列(四)MaxScript Editor和Macroscripts_第2张图片 MaxScript入门指引系列(四)MaxScript Editor和Macroscripts_第3张图片
step3: 在窗口右边,单击New...键入菜单名称Shemmy Tools。此时在Menus的下拉中能找到该菜单;

 

step4: 将上一步骤创建的菜单名称Drag and Drop到窗口右边的菜单面板中,再将Action面板中的Random Rotate动作Drag and Drop到该菜单下面,如图示;

 

step5: 将该菜单保存为另外一个名称,如MaxStartUI2.mnu;

 

step6: 关掉Customize User Interface这个窗口,到Customize > Load custom UI scheme,选择上述菜单导入。这样,在主菜单条上就会出现Shemmy Tools这个菜单。

 

注意:第一,如果没有选择场景中的物体,就执行该菜单下的动作会crash; 第二,如果想改变旋转的角度该怎么办?这两个问题是需要解决的。

 

Practice: 对上次创建的篱笆园,绕X,Y,Z轴随机旋转一个角度。
for obj in $ do
(
randXrot = random -3.0 3.0
randYrot = random -3.0 3.0
randZrot = random -3.0 3.0
rot_obj = eulerangles randXrot randYrot randZrot
rotate obj rot_obj
)

你可能感兴趣的:(MaxScript入门指引系列(四)MaxScript Editor和Macroscripts)