Jump to content

Instance random keyframe/animation with Python


sant0s81

Recommended Posts

Good morning,

since I deeply fall in love with python, I would like to know where it makes sense to use Python or better VEX.

I have a cube, that has on each frame from 1-10 a random rotation keyframed.

Now I would like to copy/scatter these cube as a instance on a grid, but of course each cube should use a random animation of that 10 keyframes.

Does that make sense in Python?

And how would I start or what do I have to look for?

I also would like to specify that I only use a range of keyframes.
Lets say frames 1-5 have only rotation in x, frames 6-10 have rotation on y.

My first thougts are:

def pose_1_5_x():
     keyframes_x = hou.parmTuple('/obj/box_object1/box1/r')
     for frame in range(1, keyframes_x 1):
          frames = (get all keyframes)
          retime = frames (set all keyframes to frame 1)
          etc etc etc ^^
 

 

But I guess, thats total bullshit :D

I know, probably its more easy doing that in VEX or with for each - but would like to understand how to do that with Python.

Thanks alot! :)
         
 

Link to comment
Share on other sites

I made some progress, still with problems :D

The plan now is to find a way in python, to randomize a range of frames and output that in a timeshift.

So far I have that:

import random

def retime_frames():

    # values from dropdown tokens
    fr_get = hou.evalParm('choose_frame_set')

    for frX in range(fr_get):
        fRandom = (random.choice(frX))
        hou.parm('retime_frame').set(str(fRandom))
        print fRandom

It gives me an error, that something with my strings is not okay.

A working version with a list inside is that:

def retime_frames():
    random_num = ['1', '2', '3', '4', '5']
    fRandom = (random.choice(random_num))
    frame = hou.parm('retime_frame').set(str(fRandom))
    return fRandom

 

As soon as I try to use a variable inside the list or create a range function, it does not work anymore.

 

retime_frame.jpg

range_randomize_retime_isntances_with_animations_v001.hiplc

range_randomize_and_retime_instance_with_animation_v1a.hdalc

Edited by sant0s81
Link to comment
Share on other sites

1 hour ago, Atom said:

I don't think I would use Python at all, it is still single threaded. It's not going to scale very well when you throw a large object count at it.

Hey @Atom :)

Yeah, I also found some solutions for random instance with offset animation and it works.
Its more for learning purpose to understand python.
Lots of the stuff I am just doing in Python is probably total nonsense and quicker in VEX or just with nodes.

And good to know about the single threaded siatuation, makes sense!

Thanks for the example scene, works perfect and quick. :)

 

Link to comment
Share on other sites

I made some progress.

Not much change, but some.

Only one more thing I wonder how to do that in the for loop.

Right now when I specify the frame range, I have to use a token like '1-10'.

But what, if I would like to have an extra numer or two different frame ranges? For example '1-10, 14, 20-25'

Thx alot :)

Here is the actuall scene and HDA.

Solution:

 else: a = int(frames)      to        else: fr_sequence.append(int(frames))

 

 

retime_frame.thumb.jpg.9476c12b688d8a8ed5be356523a511bc.jpg

 

range_randomize_and_retimerange_randomize_retime_isntances_with_animations_v001.hiplc

instance_with_animation_v1a.hdalc

Edited by sant0s81
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...