【问题标题】:Need help creating curves based on set keyframe positions (maya/python)需要帮助根据设置的关键帧位置创建曲线 (maya/python)
【发布时间】:2016-06-28 22:54:25
【问题描述】:

我正在尝试使用 python 在 Maya 中创建一个工具,该工具根据对象关键帧位置创建曲线。最终目标是创建对象可以混合的不同动画曲线,以便对主动画进行调整。这是我到目前为止所拥有的。它创建一条跟随运动路径的曲线,但它不是基于关键帧位置。任何帮助将不胜感激。

import maya.cmds as cmds

def createAnimCurve( startFrame, endFrame, numCV, object ):
    curveCVstep = ((endFrame - startFrame)+startFrame)/numCV
    points = []
    for step in range( startFrame, endFrame, int(curveCVstep)):
        # Moves throughout the specified timeline to find point results
        cmds.currentTime( step )
        # Queries the pivot position to draw the curve relative to the controller
        xpos = cmds.xform( object,q=1,ws=1,rp=1 )
        # convert the tuple (vector) to a string
        points.append(xpos)
    cmds.curve(d=3, ws=True, p=points, n=object+'_xPath')

createAnimCurve(1,24,12,"L_hand_CTL")  

【问题讨论】:

    标签: python animation maya curve keyframe


    【解决方案1】:

    如果我理解正确,您将希望遍历关键帧(使用 keyframetimeChange 查询)而不是开始/结束范围步进 numCvs。

    keyframes = sorted(list(set(cmds.keyframe(object, q=True, timeChange=True))))
    

    另外,请避免使用 object 作为内置变量名。

    【讨论】:

    • 这听起来像是我需要的,但是在查看输出时,它似乎一遍又一遍地循环了几个关键帧。这是我的意思的一个例子。 [1.0, 5.0, 9.0, 13.0, 17.0, 21.0, 24.0, 1.0, 5.0, 9.0, 13.0, 17.0, 21.0, 24.0, 1.0, 5.0, 9.0, 13.0, 17.0, 21.0, 24.0, 1.0, 3.0.0, 9.0, 1.0, 3.0.0, 9 , 17.0, 21.0, 24.0, 1.0, 5.0, 9.0, 13.0, 17.0, 21.0, 24.0, 1.0, 5.0, 9.0, 13.0, 17.0, 21.0, 24.0, 1.0, 5.0, 9.0, 13.0, 17.0, 4. 2 , 5.0, 9.0, 13.0, 17.0, 21.0, 24.0, 1.0, 5.0, 9.0, 13.0, 17.0, 21.0, 24.0] 另外谢谢你,我会确保将对象变量更改为其他变量。
    • 啊,当然,它会给你每条曲线的时间变化。如果您的每个 abimCurve 的关键帧或所有关键帧排序一组(请参阅编辑),则传递 animCurve。
    • 或者您可以使用列表推导来检查每个值是否唯一,然后再附加您不能依赖排序的实例。
    • 如果我理解正确以清除结果,您将值放入一个集合中,然后创建一个列表,然后对其进行排序?你能解释一下它是如何工作的吗?我相信这会有所帮助。
    • 是的。集合是元素的无序集合。每个元素都是唯一的,并且必须是可散列的。由于一个集合是无序的,我们将它转​​换为一个列表(它仍然是一个集合),然后对该列表进行排序。见programiz.com/python-programming/set
    猜你喜欢
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2010-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多