Jump to content
Sign in to follow this  
AiyaPK

Baking animation to curve from expression

Recommended Posts

I have an imported character animation from abc. I would like to offset the animation to do FX. I have a centroid as that's all i need. I would like to bake that out as an animated curve so I can manually scale the inverse curve to my liking.
I tried using a point() expression to get the transform channels into a transform node. I then tried baking the channels view the baking menu, but it crashed houdini. I'm guessing there's a proper way of doing this........
I heard people were using chops, but also that it was meant for exporting to unity or something? I don't need to export the animation curves to another software. I literally just need animation curves to edit in the animation curve editor.
Thanks!

Share this post


Link to post
Share on other sites

here is a simple example with Python, I attached an example:

parm = hou.parm('/obj/geo1/sphere1/ty')

# store all values in list
values=[]
for i in range(100):
  val = parm.evalAsFloatAtFrame(i)
  values.append(val)

# remove parm expression
parm.deleteAllKeyFrames()

# set values from list to keyframes
for i in range(100):
  myKey = hou.Keyframe()
  myKey.setFrame(i)
  myKey.setValue(values[i])
  parm.setKeyframe(myKey)


 

bake_keyframes.hipnc

  • Like 2

Share this post


Link to post
Share on other sites

Awesome thanks Julien!

Just wanted to throw this out there in case anyone else needs this script:
1)  the 'F' in parm.deleteAllKeyframes() is lower case.
2)  if the shot does not start at frame 1, but instead 1001, an offset value will need to be calculated for  myKey.setValue(values[j]) where j is i-1001 (for example)
It took me a bit longer than it should've to realize values was trying to pull a value from an index that didn't exist (1001)

Share this post


Link to post
Share on other sites

Thanks Wilson, I noticed the lowercase F afterwards and couldn't edit the code unfortunately.
here is a improved code with start/end frame/increment - yes, you can use decimal frames too!
 

import numpy as np

parm = hou.parm('/obj/geo1/sphere1/ty')

startframe = 1001
endframe = 1100
increment = 1

# store all values in list
values=[]

for i in np.arange(startframe, endframe, increment):
  frame = round(i*100)/100.0
  value = parm.evalAsFloatAtFrame(frame)
  mydict = {'frame':frame , 'value':value}
  values.append(mydict)

# remove parm expression
parm.deleteAllKeyframes()

# set values from list to keyframes
for i in values:
  myKey = hou.Keyframe()
  myKey.setFrame(i['frame'])
  myKey.setValue(i['value'])
  parm.setKeyframe(myKey)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×