Randomise f-curve offsets?

I have a force field acting on a number of rigid bodies which I baked to keyframes to further manipulate their animation. I want to randomly offset the location curves of each object so that they appear to move at different times. Obviously I can just select each one and reposition its f-curve along the x axis but this would be a chore for hundreds of objects.

How can I apply random offsets to each curve without having to manually edit each one?

I thought of trying to enter
mathutils.noise.random()

in grab mode and then hitting shift+R to repeat the action, but it says “invalid”. I thought it was possible to enter python expressions into any value entry dialogue?

Couldn’t you perform a random increment over a selection of objects, it would need a simple script but I’m not great with that. Try asking at BlenderStack Exchange, I’m sure someone there can knock up a few lines.

here’s a snippet, just save your file before, also try the O key to clean up fcurves
there are a couple of addons around that can do this


import bpy, random
objs = [o for o in bpy.context.selected_objects if o.animation_data]
for o in objs:
    delta = random.uniform(0, 15) # << adjust noise range here
    for fcu in o.animation_data.action.fcurves:
        for k in fcu.keyframe_points:
            k.co[0] += delta
            k.handle_left[0] += delta
            k.handle_right[0] += delta

about your idea, read Psyfi was adding proportional editing to fcurves, but not for retiming!? also O key won’t work there

gave your code a go, seems to work very well, especially if i add a negative value to the random range so that the curves are distributed around their current position more evenly.

thanks!

and i agree, proportional f-curve editing would be great and seems like an obvious addition considering blender’s general philosophy of having “everything, everywhere”. or at least, things seems to be going that way, and that’s one of my favourite things about it.

love u a lot

1 Like