PDA

View Full Version : resample baked f-curve



liero
10-Jun-11, 22:17
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 :|



#####################################
# 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
14-Jun-11, 02:58
Liero what does this script do ?
Any pics?
Thanx.

liero
14-Jun-11, 07:52
@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
14-Jun-11, 17:21
I like this script, unbake an animation its very useful. Thanks for sharing

tungee
14-Jun-11, 17:50
Liero, could you port this to an Addon?

liero
14-Jun-11, 21:26
sure tungee, I can do that..! got to think again the adding a new action stuff
here is a quick version (http://dl.dropbox.com/u/16486113/Blender/unbake.py)... remember to first select an f-curve

tungee
15-Jun-11, 05:52
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
30-Jun-11, 13:04
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
30-Jun-11, 14:06
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
30-Jun-11, 15:16
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
17-Aug-11, 01:42
Your Addon is super useful!! Thanks so much!! :)

(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
30-Jan-12, 16:39
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?

liero
31-Jan-12, 08:40
you mean when you bake a sound to a curve..? don't really get what you needm maybe explain that again
and check also this thread for a cool looking related script that may help you...

http://blenderartists.org/forum/showthread.php?236729-Audio-Visualiser

jabeck
31-Jan-12, 14:37
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:)

http://youtu.be/nfwD05XA2YQ

3pointEdit
11-Feb-12, 22:35
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.

liero
11-Feb-12, 22:46
I would just use a sound editor for that ;)

go and check batFINGER's Speaker Tools (http://blenderartists.org/forum/showthread.php?236729-Speaker-Tools-(Audio-Visualiser-Driver-Lipsync-)), it is a great script to drive stuff with audio...

saludos

batFINGER
14-Feb-12, 09:48
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.


That's where I'm getting to now. I have both the min/max of all and each frequency range within the range baked. Drop me a hoy in http://blenderartists.org/forum/showthread.php?236729-Speaker-Tools-(Audio-Visualiser-Driver-Lipsync-) on what type of functionality i could add.

producent
21-Aug-12, 03:05
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
22-Aug-12, 23:04
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
20-Sep-12, 14:50
hey, super skript!!

ahmed.d
28-Nov-12, 03:51
thanks man awesome script

copperplate
24-Jun-15, 09:08
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. :)

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
25-Jul-15, 08:55
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?

liero
25-Jul-15, 09:04
yes that's the latest one... guess you just need to select your object -and curves-

justavisitor
25-Jul-15, 09:16
yes that's the latest one... guess you just need to select your object -and curves-

Whoa, thank you for your extremely fast answer! :)

The object is selected. However, I can't select/deselect the corresponding (baked) curve in the Graph Editor (all options under 'Select' are greyed out). But again, the curve looks like it's selected as it's red...

copperplate
25-Jul-15, 09:28
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?

A quickstart tutorial example:

1. After installing the addon, open a new blend file.

2. Select the cube and press "I" to insert a "Location" key frame.

3. Change the timeline to the graph editor window, and on the left under CubeAction expand the Location channel. Click the Z Location channel.

4. Hit "N" inside the graph editor to bring up the properties panel. Under the "Modifiers" tab, click "Add Modifier" and choose "Noise". Increase the "Strength" to 5.

5. Hit "ALT-A" to play the animation. You should see the cube bouncing up and down.

6. In the graph editor window, click "Key" and press "Bake Curve" (or just press ALT-C) and left click to confirm.

7. Now in the 3D window, in the left toolbar window, navigate to the "Animation" tab (Hit "T" if the toolbar window is not visible).

8. Click "Unbake to Action". You will notice down in the graph editor, the whole length of the Z Location channel is now covered in orange, editable keyframes.

justavisitor
25-Jul-15, 09:42
A quickstart tutorial example:

1. After installing the addon, open a new blend file.

2. Select the cube and press "I" to insert a "Location" key frame.

3. Change the timeline to the graph editor window, and on the left under CubeAction expand the Location channel. Click the Z Location channel.

4. Hit "N" inside the graph editor to bring up the properties panel. Under the "Modifiers" tab, click "Add Modifier" and choose "Noise". Increase the "Strength" to 5.

5. Hit "ALT-A" to play the animation. You should see the cube bouncing up and down.

6. In the graph editor window, click "Key" and press "Bake Curve" (or just press ALT-C) and left click to confirm.

7. Now in the 3D window, in the left toolbar window, navigate to the "Animation" tab (Hit "T" if the toolbar window is not visible).

8. Click "Unbake to Action". You will notice down in the graph editor, the whole length of the Z Location channel is now covered in orange, editable keyframes.

Hi Copperplate,
Thank you for your great tutorial. The noise option was seriously funny :) and the addown works just like it should. But it looks very different from my other file, in which I baked sound to F-curves. That curve is red and does not have any selectable points. The curve in your project is blue and has selectable points or vertices...

batFINGER
25-Jul-15, 09:42
A quick note.

I was using similar code to unbake sound drivers. Not sure when these were introduced



>>> fc = bpy.data.actions['SoundAction'].fcurves[0]

>>> fc.convert_to_
keyframes(
samples(
>>> fc.convert_to_keyframes(
convert_to_keyframes()
FCurve.convert_to_keyframes(start, end)
Convert current FCurve from sample points to keyframes (linear interpolation), if necessary
>>> fc.convert_to_keyframes(1,1000)
>>> fc.convert_to_samples(
convert_to_samples()
FCurve.convert_to_samples(start, end)
Convert current FCurve from keyframes to sample points, if necessary
>>> fc.convert_to_samples(1, 1000)
>>>


they're pretty quick.

justavisitor
25-Jul-15, 12:39
I can't bake and unbake the curve in this simple .blend.

The unBake buttons are greyed out...

EDIT: Perhaps the plugin doesn't work with Shapekeys (which I use in this project)? The buttons work as expected if add a new object and animate it directly

EDIT2: OK, I added a bone instead of the shapekey, and that works.

level1rock
12-Apr-16, 11:20
Hi,

How can I generate a f-curve from the upper and lower points of another one?

(check out the image as example. I want to generate the green f-curve from the red f-curve)

http://blenderartists.org/forum/attachment.php?attachmentid=432203&stc=1

Thank you ;)

Cowboyhat
02-Sep-17, 07:41
I can't bake and unbake the curve in this simple .blend.

The unBake buttons are greyed out...

EDIT: Perhaps the plugin doesn't work with Shapekeys (which I use in this project)? The buttons work as expected if add a new object and animate it directly

EDIT2: OK, I added a bone instead of the shapekey, and that works.


I can confirm this script works on object properties only - so loc, rot, scale curves will un-gray the buttons and it works.
BUT, if you want to use shape keys, the buttons will remain grayed out.

Workaround: unless/until support for shapekeys is added, you can still get this to work.

Add a fake/temporary object (perhaps an empty) and insert a location keyframe, then bake sound curves to that location curve.
Then go to your real object with shapekeys and insert a "shapekey keyframe" which causes a curve to be created.
Now you can copy and paste the curve from the empty to your real object's shapekey.
Lastly, delete the empty/temp object