<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Creating an animation curve by code using cubic-bezier values in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/creating-an-animation-curve-by-code-using-cubic-bezier-values/m-p/7272600#M11532</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd love some help on this subject. I have some animation curves that i'd like to recreate in Maya. The problem is they're in a cubic bezier fashion like so...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://cubic-bezier.com/#.17,.25,.67,1" target="_blank"&gt;http://cubic-bezier.com/#.17,.25,.67,1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any suggestions how I can covert this style of animation curve to Maya's (angle/weight) via Mel/Python?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2017 20:57:53 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-08-02T20:57:53Z</dc:date>
    <item>
      <title>Creating an animation curve by code using cubic-bezier values</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/creating-an-animation-curve-by-code-using-cubic-bezier-values/m-p/7272600#M11532</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd love some help on this subject. I have some animation curves that i'd like to recreate in Maya. The problem is they're in a cubic bezier fashion like so...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://cubic-bezier.com/#.17,.25,.67,1" target="_blank"&gt;http://cubic-bezier.com/#.17,.25,.67,1&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any suggestions how I can covert this style of animation curve to Maya's (angle/weight) via Mel/Python?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 20:57:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/creating-an-animation-curve-by-code-using-cubic-bezier-values/m-p/7272600#M11532</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-08-02T20:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an animation curve by code using cubic-bezier values</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/creating-an-animation-curve-by-code-using-cubic-bezier-values/m-p/7280498#M11533</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you may want to check the document of &lt;A href="http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__cpp_ref_class_m_fn_anim_curve_html" target="_blank"&gt;MFnAnimCurve&lt;/A&gt;. It explains how cubic 2d Bezier is working in Maya.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yours,&lt;/P&gt;
&lt;P&gt;Li&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2017 07:29:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/creating-an-animation-curve-by-code-using-cubic-bezier-values/m-p/7280498#M11533</guid>
      <dc:creator>cheng_xi_li</dc:creator>
      <dc:date>2017-08-07T07:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an animation curve by code using cubic-bezier values</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/creating-an-animation-curve-by-code-using-cubic-bezier-values/m-p/9230807#M11534</link>
      <description>&lt;P&gt;This is probably too late, but for future references, here's the code I wrote for converting bezier curve to anim curve:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import maya.api.OpenMaya as om2
import maya.api.OpenMayaAnim as oma
import maya.cmds as mc


def bezierCrvToAnimCrv(crv):
    cvs = mc.ls(crv + '.cv[*]', fl=True)
    cv_ids = [int(x.split('[')[-1][:-1]) for x in cvs]

    animCrv = mc.createNode('animCurveTU')
    for keyIndex, i in enumerate(range(0, len(cvs), 3)):
        # create keys
        x = mc.getAttr(cvs[i] + '.xValue')
        y = mc.getAttr(cvs[i] + '.yValue')
        mc.setKeyframe(animCrv, time=x, value=y)
        mc.keyTangent(animCrv, edit=True, weightedTangents=True)
        mc.keyTangent(animCrv, e=True, itt='auto', ott='auto')

    for keyIndex, i in enumerate(range(0, len(cvs), 3)):
        # set tangents
        inWeight = 0
        outWeight = 0
        in_x, in_y = (0, 0)
        out_x, out_y = (0, 0)
        if i == 0:  # first cv
            out_x, out_y, outWeight = getWeightAndTangent(cvs[i], cvs[i + 1])
        elif i == cv_ids[-1]:  # last cv
            in_x, in_y, inWeight = getWeightAndTangent(cvs[i - 1], cvs[i])
        else:  # middle cvs
            in_x, in_y, inWeight = getWeightAndTangent(cvs[i], cvs[i - 1])
            out_x, out_y, outWeight = getWeightAndTangent(cvs[i], cvs[i + 1])

        # set tangents
        setWeightAndTangent(animCrv=animCrv, index=keyIndex,
                            x=in_x, y=in_y, weight=inWeight, isInTangent=True)
        setWeightAndTangent(animCrv=animCrv, index=keyIndex,
                            x=out_x, y=out_y, weight=outWeight, isInTangent=False)

    return animCrv


def getWeightAndTangent(pnt1, pnt2):
    pos1 = mc.xform(pnt1, q=1, ws=1, t=1)
    pos2 = mc.xform(pnt2, q=1, ws=1, t=1)
    vec = om2.MVector(pos2) - om2.MVector(pos1)

    return vec.x, vec.y, vec.length()


def setWeightAndTangent(animCrv, index, x, y, weight, isInTangent):
    sel = om2.MSelectionList()
    sel.add(animCrv)
    node = sel.getDependNode(0)
    animCrvFn = oma.MFnAnimCurve(node)
    animCrvFn.setTangent(index, x, y, isInTangent)
    animCrvFn.setWeight(index, weight, isInTangent)&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jan 2020 12:34:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/creating-an-animation-curve-by-code-using-cubic-bezier-values/m-p/9230807#M11534</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-01-04T12:34:49Z</dc:date>
    </item>
  </channel>
</rss>

