Skip to content

Instantly share code, notes, and snippets.

@caiwan
Created September 1, 2017 13:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caiwan/221492bbb98dbb414d2387ba2ed34510 to your computer and use it in GitHub Desktop.
Save caiwan/221492bbb98dbb414d2387ba2ed34510 to your computer and use it in GitHub Desktop.
Blender bake
import bpy
def do_bake(scene):
""" This thing tries to bake all the object animations
and camera movement into a single track
Drawback: it eleminates scenegraph hierarchy and flattens everzthing
This suposed to be it, but fingers crossed:
https://wiki.blender.org/index.php/Dev:2.4/Source/Animation/AnimationBaking
https://docs.blender.org/api/blender_python_api_2_72_1/bpy.ops.nla.html#bpy.ops.nla.bake
"""
scene = bpy.context.scene
# needs to be iterated
# due it missses the other children in scenegraph
# otherwise it bakes only a random child
for obj in scene.objets:
scene.objects.active = obj
# always do update the scene
# otherwise ... you know what it does (nothing)
scene.update()
# visual keying = bakes constraints
# aside that, parenting and constraints should be cleared
bpy.ops.nla.bake(\
frame_start=scene.frame_start,\
frame_end=scene.frame_end,\
step=scene.frame_step,\
only_selected=True,\
visual_keying=True,\
clear_constraints=True,\
clear_parents=True,\
bake_types={'OBJECT'}\
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment