[maxsprict] 一个转换逐帧动画以及改变骨骼层级的脚本

来源:互联网 发布:java 树遍历treenode 编辑:程序博客网 时间:2024/06/06 00:50

maxsprict
某大厂的测试题,我觉得挺有用,从中也学了很多,发出来看看
总的思路就是:既然要变换为逐帧,其实就是把当前帧的Transform信息保存到一个临时OBJ然后把原OBJ的Transform清除,然后在把临时OBJ的Transform还给原OBJ,就相当于KEY了一个帧。
改变骨骼层级一句代码即可搞定。
看代码把!
存为mcr格式即可,里面基本都有注释

macroscript TA_Test category:"TA_Test" buttonText:"改变骨骼层级并转换逐帧"toolTip:"改变骨骼层级并转换逐帧"(    on execute do (        -- 把当前选择的obj加入数组        objlist = $selection as array         -- 遍历数组并把元素值付给currentobj        for currentobj in objlist do (              format "正在转换obj %\n" currentobj.name            local tempobj = undefined             -- 存一个档 当发生意外的时候将读这个档            local record = copy currentobj.transform.controller            with undo on (                try (                    -- 创建一个临时obj来存放transform信息                    tempobj = Point()                    -- 遍历整个动画                    for i = animationRange.start to animationRange.end do (                        -- 时间轴同步                        sliderTime = i                        -- 把当前obj的transform付给临时obj                        at time i (                            with animate on tempobj.transform = currentobj.transform                        )                    )                    -- 付一个空值给transform.controller                    currentobj.transform.controller = transform_script()                        currentobj.transform.controller = prs()                     -- 将没有打组的obj解除父级的练习并强制指定为顶级对象                    if not (isGroupMember currentobj) then currentobj.parent = undefined                    -- 再次遍历整个动画                    for i = animationRange.start to animationRange.end do (                        -- 把临时obj的transform重新KEY到当前obj                        at time i (                            with animate on currentobj.transform = tempobj.transform                        )                    )                    -- 删除掉临时obj                    delete tempobj                    tempobj = undefined                -- 如果出现错误执行下面的方法                ) catch (                    format "出现错误!正在恢复...\n"                    if tempobj!=undefined then delete tempobj                    currentobj.transform.controller = record                )             )        )        format "完成!一共转换%个对象\n" objlist.count        -- 如果没有选中物体给出提示        if objlist.count == 0 then (            format "没有目标\n"        )    ))
0 0