NLA bake does not bake shape keys values #101149

Closed
opened 2022-09-17 16:03:45 +02:00 by Andrej · 4 comments
Contributor

Tested on Blender 3.2, 3.3

Short description

I have a shape key animation that's driven by some other property (for example, object location).
If I try to bake it in NLA (F3 - nla.bake and run bake will options checked) it does bake object location, rotation etc but it ignores shape keys values.

It is important to be able to bake shape keys values to keyframes too because:

  1. after bake it will be possible to edit shape keys data as curves
  2. sometimes baking is required to be able to export shape keys values in some other software

My suggestion will be to either to bake shape keys values all the time or to add an option to do so.
Other thing is there is no option to bake custom properties too.

I've found some people that met this issue before - [here ]] and [ https:*www.reddit.com/r/blenderhelp/comments/rhgwck/comment/hoqino2/ | there, usually people add multiple bones to drive shape keys and then work with those bones animation.
Which seems redundant if you have really many shape keys (for example in productions for face animation we use around more than 50 of them).

Exact steps to reproduce the error
I've attached blend file with example - it's just a cube that has 1 shape key that's attached to cube's X location with driver. cube_shapekey_bake.blend
You can try to bake it with nla.bake and then check in Dope Sheet that no shape keys values keyframes was added.

I've also wrote a script that does exactly that.
I've attached the script to the blend file - you can go to scripting and run it to get the bake shape keys values for currently selected object.
It might be helpful for someone who struggles with that issue until it solved.

import bpy

context = bpy.context
scene = context.scene
object = context.object
frame_start = scene.frame_start
frame_end = scene.frame_end

# bake current shapekeys values to keyframes (no need to actually store them)
for frame in range(frame_start, frame_end+1):

scene.frame_set(frame)
for sk in object.data.shape_keys.key_blocks:
if sk.name == 'Basis':
continue
sk.keyframe_insert("value", frame=frame)


# remove baked drivers from shapekeys
drivers = object.data.shape_keys.animation_data.drivers
drivers_to_remove = list()
for fcurve in object.data.shape_keys.animation_data.drivers.values():

data_path = fcurve.data_path
sk_name = data_path.split('key_blocks["')[1].rsplit('"].value')[0]
drivers_to_remove.append(fcurve)


for driver in drivers_to_remove:

print(f'removing driver {driver}')
drivers.remove(driver)


Tested on Blender 3.2, 3.3 **Short description** I have a shape key animation that's driven by some other property (for example, object location). If I try to bake it in NLA (F3 - nla.bake and run bake will options checked) it does bake object location, rotation etc but it ignores shape keys values. It is important to be able to bake shape keys values to keyframes too because: 1) after bake it will be possible to edit shape keys data as curves 2) sometimes baking is required to be able to export shape keys values in some other software My suggestion will be to either to bake shape keys values all the time or to add an option to do so. Other thing is there is no option to bake custom properties too. I've found some people that met this issue before - [here ]] and [[ https:*www.reddit.com/r/blenderhelp/comments/rhgwck/comment/hoqino2/ | there](https:*blenderartists.org/t/bake-action-and-shape-key-action/1310333), usually people add multiple bones to drive shape keys and then work with those bones animation. Which seems redundant if you have really many shape keys (for example in productions for face animation we use around more than 50 of them). **Exact steps to reproduce the error** I've attached blend file with example - it's just a cube that has 1 shape key that's attached to cube's X location with driver. [cube_shapekey_bake.blend](https://archive.blender.org/developer/F13504130/cube_shapekey_bake.blend) You can try to bake it with nla.bake and then check in Dope Sheet that no shape keys values keyframes was added. I've also wrote a script that does exactly that. I've attached the script to the blend file - you can go to scripting and run it to get the bake shape keys values for currently selected object. It might be helpful for someone who struggles with that issue until it solved. ```python import bpy context = bpy.context scene = context.scene object = context.object frame_start = scene.frame_start frame_end = scene.frame_end # bake current shapekeys values to keyframes (no need to actually store them) for frame in range(frame_start, frame_end+1): ``` scene.frame_set(frame) for sk in object.data.shape_keys.key_blocks: if sk.name == 'Basis': continue sk.keyframe_insert("value", frame=frame) ``` # remove baked drivers from shapekeys drivers = object.data.shape_keys.animation_data.drivers drivers_to_remove = list() for fcurve in object.data.shape_keys.animation_data.drivers.values(): ``` data_path = fcurve.data_path sk_name = data_path.split('key_blocks["')[1].rsplit('"].value')[0] drivers_to_remove.append(fcurve) ``` for driver in drivers_to_remove: ``` print(f'removing driver {driver}') drivers.remove(driver) ``` ```
Author
Contributor

Added subscriber: @Andrej-4

Added subscriber: @Andrej-4
Member

Added subscriber: @OmarEmaraDev

Added subscriber: @OmarEmaraDev
Member

This seems to be the same general issue in #65773 and #96459, which is considered a to-do because the bake operator is specifically made for transformation data.
But it seems there is work toward supporting other properties like shape keys and custom properties, so you can track that in the linked task, which I will merge to.

This seems to be the same general issue in #65773 and #96459, which is considered a to-do because the bake operator is specifically made for transformation data. But it seems there is work toward supporting other properties like shape keys and custom properties, so you can track that in the linked task, which I will merge to.
Member

Closed as duplicate of #65773

Closed as duplicate of #65773
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#101149
No description provided.