Create vertex_animation_notes.md

This commit is contained in:
Spencer Killen 2022-11-26 16:22:17 -07:00 committed by GitHub
parent 2797e6146c
commit 23f2343941
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 0 deletions

51
vertex_animation_notes.md Normal file
View File

@ -0,0 +1,51 @@
- The alembic format serves as a good way to bake mesh data with lots of modifiers
- This script will convert mesh animations to shapekeys. Digusting, but it just might work
- https://gist.github.com/fire/495fb6a35168500df53c002695a1f5fe
Code reproduced below for archival purposes
- Enable the .mdd addon in blender to export as a mesh cache
- It might work as a direct export to .mdd, but I did alembic first, then rexported to mdd
- Create new object with same mesh and empty modifier stack and add a mesh cache modifier to load exported file.
```
# MIT LICENSE
# Authored by iFire#6518 and alexfreyre#1663
# This code ONLY apply to a mesh and simulations with ONLY the same vertex number
import bpy
#Converts a MeshCache or Cloth modifiers to ShapeKeys
frame = bpy.context.scene.frame_start
for frame in range(bpy.context.scene.frame_end + 1):
bpy.context.scene.frame_current = frame
#for alembic files converted to MDD and loaded as MeshCache
bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=True, modifier="MeshCache")
#for cloth simulations inside blender using a Cloth modifier
#bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=True, modifier="Cloth")
# loop through shapekeys and add as keyframe per frame
# https://blender.stackexchange.com/q/149045/87258
frame = bpy.context.scene.frame_start
for frame in range(bpy.context.scene.frame_end + 1):
bpy.context.scene.frame_current = frame
for shapekey in bpy.data.shape_keys:
for i, keyblock in enumerate(shapekey.key_blocks):
if keyblock.name != "Basis":
curr = i - 1
if curr != frame:
keyblock.value = 0
keyblock.keyframe_insert("value", frame=frame)
else:
keyblock.value = 1
keyblock.keyframe_insert("value", frame=frame)
# bpy.ops.object.modifier_remove(modifier="MeshCache")
# bpy.ops.object.modifier_remove(modifier="Cloth")
```