伙计们!我的问题涉及我目前正在尝试解决的 Python 练习(好吧,更具体地说,该程序是 Autodesk Maya,但我使用的是 Python 编码)。该练习涉及获取数组/列表中包含的多个对象(球体),然后使用增量变量使它们在偏移动画中移动。换句话说,我希望第一个球体移动,然后下一个球体在延迟的时间内移动,然后下一个球体的延迟时间更长,等等。
我的代码如下:
spheres = mc.ls(selection=True)
count=0
for i in range(len(spheres)):
count+=2
mc.selectKey(spheres)
mc.keyframe(edit=True, relative=True, timeChange=count)
print spheres(i)
球体是我的对象,正如我所说,我希望第一个球体在时间轴中正常移动,然后下一个球体以 2 的延迟时间移动,然后下一个以 4 的延迟时间移动,等等。
如有任何帮助,我们将不胜感激。
谢谢, E
最佳答案
您实际上并没有在单个球体上设置关键帧;看起来你在所有领域都设置了它
您的 for
循环通常形式不佳,而且用处不大。尝试将其更改为:
spheres = mc.ls(selection=True)
count=0
for sphere in spheres:
count += 2
mc.selectKey(sphere) # only selecting the one sphere!
mc.keyframe(edit=True, relative=True, timeChange=count)
print sphere # no need to look up the element
# which by the way should have been [i] not (i)
输出:
关键帧最初都是排成一行的,但现在每个关键帧都与之前的帧偏移了两帧。
关于python - 如何获得一个 For 循环来影响每个单独的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21030237/