Sidor

Sunday, November 7, 2021

Morphing Armatures and Rendering

Recently we introduced support for ERC morphs, which not only affect shapekeys and bone poses, but also change the armature in edit mode. By adding a handler we could update the armature morphs on each frame change, allowing ERC morphs to be animated. However, Surody discovered a serious flaw with this: automatic armature morphing only works in the viewport but not when rendering animations. The following image illustrates what can happen.

Apparently the problem arises because rendering and scene update run on different threads. The Blender documentation says the following.

Note on Altering Data

Altering data from handlers should be done carefully. While rendering the frame_change_pre and frame_change_post handlers are called from one thread and the viewport updates from a different thread. If the handler changes data that is accessed by the viewport, this can cause a crash of Blender. In such cases, lock the interface (Render → Lock Interface or bpy.types.RenderSettings.use_lock_interface) before starting a render.


So the suggestion is that we should enable Render > Lock interface. That does not work, however, because Blender throws an error when we try to enter edit mode, and nothing is rendered at all.

To circumvent this problem, a new button has been introduced in the Utilities panel: Render Frames. This tool renders the active frame range as a sequence of still images, and updates the armature morphs before rendering each frame. There is also an analogous tool for doing OpenGL rendering. All render settings are found in the usual places. There is an option whether we want to morph all armatures in the scene, or only the selected ones.

And now the rendered images look much better.

Warning: Adding automatic armature morphing as described in the previous post is risky, since it works in the viewport but not during render. Therefore, this possibility will probably be removed in the future.