56 lines
2.1 KiB
Markdown
56 lines
2.1 KiB
Markdown
- 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.
|
|
|
|
|
|
- This method is better
|
|
- https://github.com/yanorax/Godot-VertexAnimation-Demo
|
|
- But it would need to be extended to support a mesh cache modifier. (Should be possible given following code
|
|
|
|
```
|
|
|
|
# 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")
|
|
```
|
|
|
|
|