有没有办法在 3DSMax 2023 中使用 MAXScript 使用控制器的线性 ORT 值添加关键帧?

问题描述 投票:0回答:1

我正在尝试找出 MAXScript 中的关键帧。我有一个脚本,可以生成虚拟对象并创建关键帧,以给定的速度沿着样条线移动它们。我正在更新别人几年前编写的脚本,这在很大程度上是有意义的,但我在执行我的愿望时遇到了麻烦。

脚本放置假人,然后假人沿着样条线移动的速度如下:

miles = pathlngth/5280.0 -- length of path in miles
framecount = 0
framecount = (miles/carspeed.value)*60*60*30

到目前为止对我来说是有意义的。然后我们就到这里:

--Make initial Dummy at 0%
newDummy = dummy size:1
WorldAlignPivot newDummy
newDummy.name = ("D_" + drivePath.name as string + "_001")
newDummy.pos.controller = path follow:true
PosCntrl = newDummy.pos.controller
PosCntrl.path = drivePath
PosCntrl.axis = 2
PosCntrl.percent = 1.0
PosCntrl.percent.controller.keys[2].time = framecount
PosCntrl.axisFlip = off
PosCntrl.constantVel = on
PosCntrl.axis = 0
setBeforeORT (newDummy) #linear
setAfterORT (newDummy) #linear

据我所知,PosCntrl 将“样条线百分比”值设置为帧计数数字,以获得允许假人以给定速度行进所需的斜率。这导致曲线编辑器看起来像这样: image of curve editor with Linear ORT

请注意,插值在第二个关键帧之后变成虚线。我想在代码中沿着该插值线在动画末尾添加一个关键帧。您可以通过右键单击并按曲线编辑器本身中的“添加关键帧”来完成此操作,但我想让它自动进行。当尝试使用这行代码执行此操作时:

--previous code block goes here
addNewKey newDummy animationRange.end

我在曲线编辑器中得到这个结果:post addNewKey attempt

我想,我明白为什么我会做这样的事情。但这不是我想要的。请帮忙!

autodesk 3dsmax maxscript
1个回答
0
投票

找到答案了。我的比例错误。事实证明,您可以在关键帧控制器中设置所需的值,获取该值,然后将其乘以用于更改关键帧本身位置的比率。解释如下,如果您知道不同的方式,请在此处发布!

--get the ratio from where the framecount would be and the end of the animation.
--remember, framecount is where the dummy will reach the original spot  
--on the spline after n time going the speed set by the user.
                        ratio = animationRange.end / framecount
                        
--set the keyframe to the original frame count
PosCntrl.percent.controller.keys[2].time = framecount
                        
--get the value of the orignal frame
ogVal = PosCntrl.percent.controller.keys[2].value
                        
--multiply it by the ratio found above
newVal = ogVal * ratio
                        
--set the keyframe to the end of the animation by multiplying the frame count by the ratio
PosCntrl.percent.controller.keys[2].time = framecount * ratio 
                        
--set the value of that keyframe to the new value found via old*ratio
PosCntrl.percent.controller.keys[2].value = newVal

如您所见,这就像计算原始值并将其乘以比率一样简单。简单的数学花了我一天的时间才记住,我可能会或可能不会为此感到羞耻,哈哈。

我希望这对那些正在与 maxscript 作斗争的人有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.