MAXScript101_5.1 ChainMaker-Geometry Creation using Splines

MAXScript101_5.1 ChainMaker-Geometry Creation using Splines


MAXScript101_5.1 ChainMaker-Geometry Creation using Splines_第1张图片

1. 测试torus的法向

pos = lengthInterp $Line01 0.5
-- 曲线在某一点的切向沿着曲线方向,在图中显示为local coordsys的z 向
tanV= lengthTangent $Line01 0.5
-- 物体的方向定义为local coordsys的z -axis 方向
box width: 10 height:20 pos: pos dir:tanV
torus radius:25 radius2:10 pos: pos dir: tanV

注:上图中,torus中心显示的坐标系为其local coordsys;

 

2. chainMaker1 - rollout
-- 1. 选择曲线作为链条的路径,同时pickButon下面的label显示相应曲线的名字;
-- 2. 修改直径,厚度 以及线框颜色值;
-- 3. 按 Create Chain 按钮,创建链条
-- 4. 注:修改直径,厚度的值,场景中的链条不会发生相应改变
MAXScript101_5.1 ChainMaker-Geometry Creation using Splines_第2张图片
-- rollout; group; pickButton, label, spinner, colorPicker, button -- 拾取曲线,按照spinner给定的数值,创建一条沿着该曲线的一系列torus,并且站立,平躺交替出现 rollout ChainMaker "Chain Maker" ( local curve -- holds the picked curve -- pick filter function, only allow shapes to be picked fn shapesOnly obj = isKindOf obj shape -- group "Controlling Curve" ( pickButton pickCurve "Pick Curve" width:100 filter:shapesOnly label theCurve "-- none --" ) group "Chain Parameters" ( spinner diam "Link Diameter: " range:[1, 500, 12] -- thickness 记录torus实体部分直径 spinner thickness "Link Thickness: " range:[0.1, 500, 2] colorPicker wireColor "Wire Color: " align: #center ) -- 初始化按钮,当没有选择好curve时,该按钮不起作用 button create "Create Chain" width: 100 enabled: false -- 在场景中选择一条曲线,存入变量curve中,并且改变label的文本,同时激活create按钮 on pickCurve picked obj do ( -- handle pick, remember picked object & display its name curve = obj theCurve.text = obj.name create.enabled = true ) -- 按下按钮,创建链条 on create pressed do ( -- create the chain local len = curvelength curve, uStep = (diam.value - thickness.value) / len, up = true -- step along curve param based on link diameter & thickness for u = 0.0 to 1.0 by uStep do ( -- figure point & tangent on line, create torus at -- that location and direction local pos = lengthInterp curve u, -- 曲线在参数值为u时点的切向量 tan = lengthTangent curve u, t = torus radius1: (diam.value/2) radius2:(thickness.value/2) pos: pos dir: tan wireColor: wireColor.color -- test the interpolation position sphere radius:2 pos: pos wireColor: red --rotate the torus around local y or x to sit flat or up along curve -- 保证torus,沿着曲线方向,平放 交替出现 coordsys local rotate t 90 (if up then y_axis else x_axis) -- toggle rotate direction up = not up ) ) ) createDialog chainMaker width:180 

 

3. chainMaker2 - rollout
-- 1. 选择曲线作为链条的路径,并且pickButon下面的label显示相应曲线的名字;同时创建默认值的链条;
-- 2. 修改直径,厚度以及相框颜色值,场景中的链条发生相应改变;
-- 3. 按 Delete Chains 按钮,删除场景中的链条,并且pickButon下面的label重新显示为"-- none --";
MAXScript101_5.1 ChainMaker-Geometry Creation using Splines_第3张图片
-- rollout; group; pickButton, label, spinner, colorPicker, button -- 拾取曲线,按照spinner给定的数值,创建一条沿着该曲线的一系列torus,并且站立,平躺交替出现 rollout ChainMaker "Chain Maker" ( local curve, -- holds the picked curve chain = #() -- holds links -- pick filter function, only allow shapes to be picked fn shapesOnly obj = isKindOf obj shape -- group "Controlling Curve" ( pickButton pickCurve "Pick Curve" width:100 filter:shapesOnly label theCurve "-- none --" ) group "Chain Parameters" ( spinner diam "Link Diameter: " range:[1, 500, 12] -- thickness 记录torus实体部分直径 spinner thickness "Link Thickness: " range:[0.1, 500, 2] colorPicker wireColor "Wire Color: " align: #center ) -- 初始化创建按钮,当没有选择好curve时,该按钮不起作用 --button create "Create Chain" width: 100 enabled: false -- 初始化删除按钮 button deleteChain "Delete Chains" width:100 enabled:false fn updateChain = ( -- compute curve param step based on link diameter & thickness local len = curvelength curve, uStep = (diam.value - thickness.value) / len, up = true, i = 1 -- step along curve -- 1: 初始时,chain.count = 0; i记录循环的次数, -- 2:在场景中没有链条的时候,创建链条 -- 3: 在场景中存在链条的时候,由于 i 不可能超过chain.count,故for循环语句中,不再生成torus,但会改变torus的状态 for u = 0.0 to 1.0 by uStep do ( -- add a new link if needed, create a torus if i > chain.count then chain[i] = torus wireColor: wireColor.color -- grab next link; size, place & orient local t = chain[i] t.radius1 = diam.value / 2 t.radius2 = thickness.value / 2 t.pos = lengthInterp curve u t.dir = lengthTangent curve u coordsys local rotate t 90 (if up then y_axis else x_axis) -- toggle rotate direction & bump link index up = not up i += 1 ) -- delete any extraneous links,删除多余的torus for j in i to chain.count do ( -- delete 删除结点,但是在数组中的那个位置仍然存在 delete chain[i] -- deleteItem 删除数组的位置,数组的size减1 deleteItem chain i ) ) -- 在场景中选择一条曲线,存入变量curve中,并且改变label的文本,同时激活delete按钮,创建链条 on pickCurve picked obj do ( -- handle pick, remember picked object & display its name curve = obj theCurve.text = obj.name deleteChain.enabled = true updateChain() ) on deleteChain pressed do (delete chain; chain = #(); theCurve.text = "-- none --") on diam changed val do updateChain() on thickness changed val do updateChain() on wireColor changed val do chain.wireColor = val ) createDialog chainMaker width:180 

 

4. 将.ms制作成菜单

(1) 假设上述的MAXScript存成chain Maker2.ms

(2) 新建maxscript文件,输入制作菜单模板如下,并且保存到与chain Maker2.ms同一个文件夹下

macroScript ChainMaker2Macro category: "My Tools" buttonText: "Chain Maker" toolTip: "Makes chains along a curve"

(

global ChainMaker2

if ChainMaker2 == undefined or not ChainMaker2.open do

fileIn "chain Maker2.ms" -- 该ms文件与macro文件在同一个文件夹下

)

(3) 按ctrl + E 运行之,这样就会在custom > custome user interface 的all commands中产生名为为"My Tools";

(4) 接下来,按照制作菜单流程操作就可以了。 可以参照 MaxScript入门指引系列(四)MaxScript Editor和Macroscripts

 

你可能感兴趣的:(function,filter,delete,Parameters,button,Shapes)