Get deltas between two anim curves?

Get deltas between two anim curves?

Anonymous
Not applicable
1,045 Views
4 Replies
Message 1 of 5

Get deltas between two anim curves?

Anonymous
Not applicable

Hi all,

 

I'm wondering if there's a quick way to get the "delta" animation curve between two anim curves using OpenMaya. 

As of now, I'm just going through each frame and subtracting the values from one to the other and storing the difference as a vector.

 

My goal is to be able to nullify all but the "jiggle" from a particle dynamics simulation so that can be used as an additive animation layer instead of override. 

 

Thanks,

 

Ben

 

 

Here's what I have so far:

 

import maya.cmds as cmds
import maya.OpenMaya as om


def translation_dynamics(cc=None,stiffness=1.5):
    if not cc:
        return
        
    start_time = cmds.playbackOptions(q=1,min=1)
    end_time = cmds.playbackOptions(q=1,max=1)
    cmds.currentTime(start_time)
    
    cc_loc = cmds.spaceLocator()[0]
    cmds.matchTransform(cc_loc,cc)
    cmds.parent(cc_loc,cc,a=1)
    
    cc_pos = cmds.xform(cc,q=1,t=1,ws=1)
    
    n_particle = cmds.nParticle(p=cc_pos,c=1)
    particle_shape = cmds.pickWalk(n_particle,d="down")[0]
    
    cmds.goal(n_particle,g=cc_loc)
    
    particle_loc = cmds.spaceLocator()[0]
    
    cmds.matchTransform(cc_loc,cc)
    
    cmds.connectAttr(particle_shape + ".worldCentroid",particle_loc + ".t")
    
    # a low dynamics weight will make the particle end closer to the cc
    cmds.setAttr(particle_shape + ".dynamicsWeight",.001)
    
    cmds.setAttr(particle_shape + ".damp",.001)
    
    cmds.setAttr(particle_shape + ".goalSmoothness",stiffness)
    
    
    # bake simulation on particle_loc
    cmds.bakeResults(particle_loc,t=(start_time,end_time),simulation=1)
    cmds.delete(cmds.pickWalk(n_particle,d="right")[0],n_particle,cc_loc)
    
    # make anim layer
    cmds.select(cc)
    lyr = cmds.animLayer(cc + "_tDynamics",addSelectedObjects=1,override=1)
    
    # TODO: make the translation additive instead of override. 
    # will need to calculate the translational vectors for each frame
    
    cmds.pointConstraint(particle_loc,cc,mo=1,layer=lyr)
    
    cmds.bakeResults(cc,t=(start_time,end_time),simulation=1,dl=lyr)
    
    cmds.delete(particle_loc)
    
    
    
    
translation_dynamics(cc=cmds.ls(sl=1)[0])
0 Likes
1,046 Views
4 Replies
Replies (4)
Message 2 of 5

sean.heasley
Alumni
Alumni

Hi @Anonymous

 

Is this code working for you somewhat or is it what you have so far?

 

Generally we can't help much with writing custom scripts that said if you have a scene file that works I'd be happy to take a look at it! When you get a chance, can you please zip and attach the scene file here or via dropbox/google drive or another file sharing program so I can take a look at it?

 

 

0 Likes
Message 3 of 5

sean.heasley
Alumni
Alumni

Hi @Anonymous

 

Just wanted to check in to see how things were going. Are you still having this issue?

 

If your issue is resolved, please click Accept as Solution on the posts that helped you so others in the community can find them easily.

0 Likes
Message 4 of 5

Anonymous
Not applicable
Hi Sean,

It’s less of an issue and more of a conceptual question I guess. I’m curious if there’s a way using the Maya API to get an vector array back as the result of subtracting two animation curves where the keyframes on them are represented as vectors.

Currently I’m just doing this manually.

- Ben
0 Likes
Message 5 of 5

chris.unterberg
Explorer
Explorer

Obviously this is from 2018 - but google still leads here so people might find it.

 

I don't have a script ( yet ) - but the manual way of getting where you want to be is:
- Bake Animation to a fresh Anim Layer that is set to 'override'

- Create a new Animation Layer below the one that has the baked data. Make sure it is set to 'additive'

- Merge the two Animation Layers down, set the 'Resulting Layer Mode' to additive ( or leave it automatic )

= You now have the animation converted to an additive layer.

 

- Chris

 

0 Likes