Graphics

 View Only
  • 1.  Delayed copy of an animation using keyframes

    Posted 05-20-2014 14:26
    I'd like to be able to animated in a quad on the x-axis. And have several other quads animated in the same way but on a delay. Changing the animation of the primary quad will change the animation of all the other quads at the same time. (Similar ValueAtTime() in after affects).

    What would be the best way to pull this off using scripts? Right now I'm thinking I'd need to grab the keyframes from my primary quad and dynamically copy them to my other quads distributed a few frames after. Is there a better way?

    EDIT:

    Here's the script I've written so far. It's not working though.... :(

    dim q1, q2 as xpquadobject

    dim k1p, k1v, k2p, k2v as decimal

    dim delay as integer = 5

    dim tst as xptextobject

    dim track as xpscenedirectortrack

    dim clp as xpscenedirectorclip

    self.getobjectbyname("Quad1", q1)

    self.getobjectbyname("Quad2", q2)

    self.getobjectbyname("test", tst)

    self.scenedirector.gettrackbyname("Track1", track) 'RETURNS TRUE

    track.getfirstclip(clp) 'RETURNS TRUE

    tst.text=clp.getfirstkeyframe(k1p, k1v) 'RETURNS FALSE; ANIMCONTROLLER1 IS THE ONLY CLIP; KEYFRAMES EXIST

    clp.getnextkeyframe(k2p, k2v)

    k1p=k1p+delay

    k2p=k2p+delay

    q2.setkeyframeposition(k1p, k1v, q2.posy, q2.posz, 3)

    q2.setkeyframeposition(k2p, k2v, q2.posy, q2.posz, 3)


    EDIT2: I know I'm not grabbing the keyframes correctly.

    EDIT3: Updated the current script. I think it's closer to what I need. The script breaks at the 'clp.getfirstkeyframe' line. Gotta be doing something wrong.


  • 2.  RE: Delayed copy of an animation using keyframes

    Posted 05-20-2014 14:58
    Do you really need to do this through scripting? It's pretty easy to copy/paste on anim controller to another and delay them on the scene director. When you paste the animation controller you can have it automatically take all of the keyframes from one object and apply them to a different object.

    #XPression


  • 3.  RE: Delayed copy of an animation using keyframes

    Posted 05-20-2014 15:06
    No, I don't really need to but I would like to know how to. What I learn here will help me know how to do more later.

    EDIT: I've given up for today. Any help pointing out what I did wrong would be great.

    #XPression


  • 4.  RE: Delayed copy of an animation using keyframes

    Posted 05-20-2014 20:02
    The keyframes on the xpSceneDirector clip aren't actually the keyframes you're looking for. Those keyframes are the "alpha keyframes" that you can set directly in the scene director by clicking the "down arrow" and recording keyframes on the scene director.

    For what you are trying to do you need to get the AnimController and get the keyframes out of it.

    Something like this (untested off the top of my head), but maybe it will get you on the right track.. Also look in the API help file in the Examples section for "Reading keyframes from an Animcation Controller". That example (although it's in C#) will loop over all keyframes and retrieve their values.

    dim ac as xpAnimController

    dim Obj1 as xpBaseObject

    dim Obj2 as xpBaseObject

    dim Keyframe as xpKeyFrame

    xpScene.GetAnimControllerByName("MyAnim", ac)

    xpScene.GetObjectByName("MyObject", Obj1)

    xpScene.GetObjectByName("MyObject2", Obj2)

    ac.GetFirstKeyFrame(Obj1, "Position.X", keyframe)

    'Keyframe.Value and Keyframe.Time now hold the time/value of the X Position from the first keyframe.

    ac.SetKeyframeValue(obj2, keyframe.time+delay, "Position.X", keyframe.Value)

    #XPression


  • 5.  RE: Delayed copy of an animation using keyframes

    Posted 05-21-2014 15:29
    Thank You Much!

    #XPression


  • 6.  RE: Delayed copy of an animation using keyframes

    Posted 05-27-2014 15:58
    (deleted)
    ..........
    #XPression


  • 7.  RE: Delayed copy of an animation using keyframes

    Posted 05-27-2014 17:06
    I wanted to share a copy of my final scripts. Simply paste this code at the end of your script.



    '----------Transfer Pos X----------

    End Sub

    sub TransferPosX(s as xpScene, a as string, o1 as string, o2 as string, optional d as integer=0, optional o as integer=0)

    dim Keyframe, Keyframe2 as xpKeyFrame

    dim Obj1,Obj2 as xpBaseObject

    dim ac as xpanimcontroller

    dim time as integer=0

    s.getObjectByName(o1, Obj1)

    s.getObjectByName(o2, Obj2)

    s.GetAnimControllerByName(a, ac)

    Obj2.PosX=Obj1.PosX+o

    while ac.GetKeyFrame(Obj1, "Position.X", time, keyframe)

    ac.SetKeyframeValue(Obj2, keyframe.time+d, "Position.X", keyframe.Value+o, keyframe.interpolation)

    time=keyframe.time+1

    end while

    '----------Transfer Pos Y----------

    End Sub

    sub TransferPosY(s as xpScene, a as string, o1 as string, o2 as string, optional d as integer=0, optional o as integer=0)

    dim Keyframe as xpKeyFrame

    dim Obj1,Obj2 as xpBaseObject

    dim ac as xpanimcontroller

    dim time as integer=0

    s.getObjectByName(o1, Obj1)

    s.getObjectByName(o2, Obj2)

    s.GetAnimControllerByName(a, ac)

    Obj2.PosY=Obj1.PosY+o

    while ac.GetKeyFrame(Obj1, "Position.Y", time, keyframe)

    ac.SetKeyframeValue(Obj2, keyframe.time+d, "Position.Y", keyframe.Value+o, keyframe.interpolation)

    time=keyframe.time+1

    end while

    '----------Transfer Pos Z----------

    End Sub

    sub TransferPosZ(s as xpScene, a as string, o1 as string, o2 as string, optional d as integer=0, optional o as integer=0)

    dim Keyframe as xpKeyFrame

    dim Obj1,Obj2 as xpBaseObject

    dim ac as xpanimcontroller

    dim time as integer=0

    s.getObjectByName(o1, Obj1)

    s.getObjectByName(o2, Obj2)

    s.GetAnimControllerByName(a, ac)

    Obj2.PosZ=Obj1.PosZ+o

    while ac.GetKeyFrame(Obj1, "Position.Z", time, keyframe)

    ac.SetKeyframeValue(Obj2, keyframe.time+d, "Position.Z", keyframe.Value+o, keyframe.interpolation)

    time=keyframe.time+1

    end while

    '----------Transfer Rot X----------

    End Sub

    sub TransferRotX(s as xpScene, a as string, o1 as string, o2 as string, optional d as integer = 0, optional o as integer=0)

    dim Keyframe as xpKeyFrame

    dim Obj1,Obj2 as xpBaseObject

    dim ac as xpanimcontroller

    dim time as integer = 0

    s.getObjectByName(o1, Obj1)

    s.getObjectByName(o2, Obj2)

    s.GetAnimControllerByName(a, ac)

    Obj2.RotX=Obj1.RotX+o

    while ac.GetKeyFrame(Obj1, "Rotation.X", time, keyframe)

    ac.SetKeyframeValue(Obj2, keyframe.time+d, "Rotation.X", keyframe.Value+o,keyframe.interpolation)

    time=keyframe.time+1

    end while

    '----------Transfer Rot Y----------

    End Sub

    sub TransferRotY(s as xpScene, a as string, o1 as string, o2 as string, optional d as integer = 0, optional o as integer=0)

    dim Keyframe as xpKeyFrame

    dim Obj1,Obj2 as xpBaseObject

    dim ac as xpanimcontroller

    dim time as integer = 0

    s.getObjectByName(o1, Obj1)

    s.getObjectByName(o2, Obj2)

    s.GetAnimControllerByName(a, ac)

    Obj2.RotY=Obj1.RotY+o

    while ac.GetKeyFrame(Obj1, "Rotation.Y", time, keyframe)

    ac.SetKeyframeValue(Obj2, keyframe.time+d, "Rotation.Y", keyframe.Value+o,keyframe.interpolation)

    time=keyframe.time+1

    end while

    '----------Transfer Rot Z----------

    End Sub

    sub TransferRotZ(s as xpScene, a as string, o1 as string, o2 as string, optional d as integer = 0, optional o as integer=0)

    dim Keyframe as xpKeyFrame

    dim Obj1,Obj2 as xpBaseObject

    dim ac as xpanimcontroller

    dim time as integer = 0

    s.getObjectByName(o1, Obj1)

    s.getObjectByName(o2, Obj2)

    s.GetAnimControllerByName(a, ac)

    Obj2.RotZ=Obj1.RotZ+o

    while ac.GetKeyFrame(Obj1, "Rotation.Z", time, keyframe)

    ac.SetKeyframeValue(Obj2, keyframe.time+d, "Rotation.Z", keyframe.Value+o,keyframe.interpolation)

    time=keyframe.time+1

    end while

    '----------Transfer Alpha----------

    End Sub

    sub TransferAlpha(s as xpScene, a as string, o1 as string, o2 as string, optional d as integer = 0, optional o as integer=0)

    dim Keyframe as xpKeyFrame

    dim Obj1,Obj2 as xpBaseObject

    dim ac as xpanimcontroller

    dim time as integer=0

    s.getObjectByName(o1, Obj1)

    s.getObjectByName(o2, Obj2)

    s.GetAnimControllerByName(a, ac)

    Obj2.alpha=Obj1.alpha+o

    while ac.GetKeyFrame(Obj1, "Alpha", time, keyframe)

    ac.SetKeyframeValue(Obj2, keyframe.time+d, "Alpha", keyframe.Value+o,keyframe.interpolation)

    time=keyframe.time+1

    end while


    And then call these subroutines at the beginning of your script with code like this;



    TransferPosX(

    self (xpScene)

    "animation controller name" (as string),

    "primary object name" (as string),

    "secondary object name" (as string),

    delay (integer - optional),

    value offset (integer - optional),

    )


    EDIT: Updated the scripts so that the property will transfer to a second object even if there are no keyframes.

    #XPression