resample baked f-curve


(liero) #1

hi, these days there have been a couple of threads about baking sound to f-curves, mainly because of some popular site’s tutorial on this… I played with the feature some time ago, and wrote this little scripts to get keyframes or even a 3d curve from the baked one… maybe someone finds them useful

> first script will create a new action & f-curve with plenty of keyframes there to play with, you can then copy paste keyframes or assign the new action to the object
> second script will add curve objects with the shape of your baked f-curves to the scene

select the curves in fc editor so the script is able to know what to work on…
there may be better ways of resampling the baked curve, but I could’t find any at the moment :expressionless:


#####################################
# unbake ¿? f-curve to a new action #
#####################################

import bpy
obj = bpy.context.object

for c in obj.animation_data.action.fcurves:
    if c.sampled_points and c.select:
        obj.animation_data.action = bpy.data.actions.new(name='Lot_of_Keys')
        fcu = obj.animation_data.action.fcurves.new(data_path=c.data_path, index=c.array_index)
        sam = c.sampled_points
        fcu.keyframe_points.add(len(sam))
        for i in range(len(sam)):
            w = fcu.keyframe_points[i]
            w.co = w.handle_left = w.handle_right = sam[i].co


###################################
# unbake ¿? f-curve to a 3d curve #
###################################

import bpy
obj = bpy.context.object
xscale = 0.1
zscale = 5

for c in obj.animation_data.action.fcurves:
    if c.sampled_points and c.select:
        sam = c.sampled_points
        cu = bpy.data.curves.new('path','CURVE')
        cu.dimensions = '3D'
        spline = cu.splines.new('BEZIER')
        spline.bezier_points.add(len(sam)-1)
        curva = bpy.data.objects.new('curve',cu)
        bpy.context.scene.objects.link(curva)
        for i in range(len(sam)):
            w = spline.bezier_points[i]
            coords = (xscale*sam[i].co[0],0,zscale*sam[i].co[1])
            w.co = w.handle_left = w.handle_right = coords

get updated script here >> https://www.dropbox.com/s/cd8ufiauilh85hj/unbake.py?dl=1


(tungee) #2

Liero what does this script do ?
Any pics?
Thanx.


(liero) #3

@tungee, in Blender there is a nice Bake sound to f-curve operator that returns an animation from a sound file… you could map it to z scale of an object as an example. The problem is the resulting f-curve is baked, has no points to edit, so this scripts would give you new editable curves from that baked one. That is all it does, helps a bit when using baked f-curves.
A simple example here http://www.pasteall.org/blend/6982


(Mackraken) #4

I like this script, unbake an animation its very useful. Thanks for sharing


(tungee) #5

Liero, could you port this to an Addon?


(liero) #6

sure tungee, I can do that…! got to think again the adding a new action stuff
here is a quick version… remember to first select an f-curve


(tungee) #7

Liero it works! Big Thanx.
Liero, it would be nice to have an option to minimize the created point.
Tonight i will make some sound to curve tests.
Thanx again!


(sesoit) #8

Holy shiz, yea I was also one who was introduced to this via that tutorial you mentioned and it was bugging me that I couldn’t transform the curve it outputted. Great thanks bro, I can do a lot more with values not just in the range of 0 - 1

I have a problem though:
I baked my sound to an fcurve for scaling on axes x, y, and z. When I run your script, it gets rid of all but the last one I selected in sequence and outputs an action that scales just the z-axis (z just happened to be the last one I selected)

Is there a way to keep all the axes? Or could I just duplicate the one action and apply it to the other axes? I tried copy and pasting keys. I’m really new to blender’s new animating scheme, any help appreciated.


(liero) #9

sesoit, just changed the script to create a single action -not one for each curve- so it is easier to use…

http://img684.imageshack.us/img684/3175/unbk.jpg

anyway, to paste your keyframes in F-Curve editor select / copy them all, create a new keyframe on startframe -so you have a curve also for X and Y- and paste over the curves…


(sesoit) #10

Hmm… yea that’s what I was trying.
Maybe I’m just copy and pasting wrong, I’ll try again when I get back shouldn’t be too hard to find out, thanks again for this!


(EpicFrySauce) #11

Your Addon is super useful!! Thanks so much!! :slight_smile:

(I was trying to create a script like this for the baked sound F curves, but I’m afraid I know nothing of code. Then I found this topic and your script, thanks!)


(jabeck) #12

I hope I’m not bumping a thread that is too old - I also love this script, but it doesn’t appear to be doing what I’d like it to for shapekey key-frames. I’m trying to set shape key 1 to one audio track, and shape key 2 to another. When I bake the curves to a sound, blender always bakes both set of keys to the same sound which seems inconsistent with the way it does, for example, independent rotations on axis. I thought this script would come to the rescue, but whatever is causing the first bug must also affect this script too. Anyone have any ideas?


(jabeck) #13

Sorry - hard to explain, but I actually tried it again this morning, and I got it right this time… Basically I’m just trying to bake two different shape keys on one mesh, to two separate audio tracks. Not sure what I was doing wrong the first time, but thanks for the help! Trying for something like this, but obviously mine will suck in comparison:)


(3pointEdit) #14

Didn’t know about this addon, sounds like it would be great for acting as a Compressor limiter on audio. Apply this apply this to a source audio waveform, then invert it, then add an envelope to limit it’s action.

Hmmm, thanks liero.


(producent) #15

Hi Liero!

Seems like addon do not cooperate with latest official Blender release. Selecting baked f-curve and executing neither ‘unBake to Action’ nor ‘unBake to 3D’ gives any effect. Could you take a look at that?


(liero) #16

hi producent, sorry for the delay…! script worked here in some recent build, also in 2.63
but pm me a blend if you still need this and have any trouble, welcome to forum btw


(animelix) #17

hey, super skript!!


(ahmed.d) #18

thanks man awesome script


(copperplate) #19

Thank you so much, liero, for this amazing script! This is indeed super-useful! I needed a way to fix the “lip-sync” from an animation driven by a baked f-curve (from a sound file) and now I can edit the individual points! Awesome. :slight_smile:

***EDIT: There is an much easier way to install the script then what I did below: :o

Just RIGHT-Click the dropbox link, download the .py file and install from file in the user preferences. The following info should still work, but probably is not necessary unless the install from file function doesn’t work for some reason.
***

For anyone like me who is unsure how to use this script, just click the dropbox link, hit CTRL+A to select all, CTRL+C to copy, then open the “Text Editor” window in Blender, click “New”, press CTRL+V to paste the script you copied in, then click the “Run Script” button. You will now have 2 new buttons in the “Animation” tab of the 3D view’s “Tool” window (“T” key to call up).

NOTE: You may be able to go to File > User Preferences > Add-ons (“User” Category) and if the script is there and enabled, you should be able to just click “Save User Preferences” at the bottom of the window and Blender will remember the script the next time you launch Blender. However, if that doesn’t work, then do this:

Back in the “Text Editor” window with the script pasted in, you can click the “Text” menu, then “Save As”, and save your script as: unbake.py

Then you can go to File > User Preferences > Add-ons; “Install from File”, enable, and click “Save User Preferences” as you would any other Add-on.


(justavisitor) #20

I installed the addon, but the two buttons - unBake to Action and unBake to 3D - are greyed out.

Why is that?

I haven’t used baked F-curves before, so I’m not quite sure about this, but the curve does look like it’s selected (it’s red)…

It’s version 0.5 - is that the latest version?