Maxscript_基础_遍历与递归
本文最后更新于702 天前,其中的信息可能已经过时,如有错误请发送邮件到84581927@qq.com

1. 遍历

例子1:对所有所选的物体做一些事

-- selection 是内建的表示当前所选的集合
-- 遍历当前所选,打印它们的名字
fn LoopSelection= (     for s in selection do     (         print s.name     )     /* -- 也可以写成:     for s = 1 to selection.count do     (         print (selection[s].name)     )     */ )

例子2:对场景内所有几何体做一些事

-- geometry 是3dsMax内建的表示场景中所有几何体的集合 fn PrintGeomNames = (     -- 遍历场景里所有的几何体     for g in geometry do     (         -- 打印几何体的名称         print g.name     ) )

例子3:多维遍历的应用:

 

-- 例子: 创建一个彩色盒子矩阵 fn CreateAColorCube= (     -- 每行的数量     local num = 10.00          -- 每个box的大小     local size = 10.0          -- 遍历     -- 三层遍历最终会创建 10 x 10 x 10 个box     for r = 1 to num do     (         for g = 1 to num do         (             for b =1 to num do             (                 -- 创建box并设置属性                 theBox = box()                 theBox.name = "box_" + ((r as string) +"_") + ((g as string) +"_") +(b as string) -- 每个box的名称                                  theBox.width = size -- 宽                 theBox.height = size -- 高                 theBox.length = size -- 长                                  theBox.pos = [r,g,b] * size -- 位置                                  theBox.wirecolor = [(r/num * 255),(g/num *255.00),(b/num *255.00)] -- 颜色             )         )     ) )

While_Do的例子

-- 注意1 条件判断,如果永远达不到停止条件,会成死循环,3dsMax会成假死状态 -- 注意2 while . . . do 和 do . . . while 的区别 maxnul = 10 i = 1 while( i < maxnum )do (     print i  i+=1 ) /* do (     print i  i+=1)while( i <= maxnum ) */ ```

2,递归

  • 例子:撸 Bip骨骼,搜集一个Bip所有的骨骼到一个集合内:

 

-- 声明一个集合,用于搜集Bipglobal RecurseCollector = #() -- 递归函数 fn RecurseChildren currNode= (     -- 当前物体是否为Biped实体骨骼     if(classof currNode == Biped_Object)then     (         --收集操作         append RecurseCollector currNode     )     local childNodes = currNode.children     if(childNodes.count &gt;0)then for c in childNodes do     (         RecurseChildren c     ) ) -- 递归开始 fn RecurseStart currNode= (     -- 清空集合     RecurseCollector = #()          -- 开始递归     RecurseChildren currNode          -- 返回       return RecurseCollector )          -- 选择 BIP的根骨骼     -- 搜集所有的Bip001上所有的骨骼     bipList = RecurseStart $Bip001_Pelvis
文末附加内容
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇