Last active
November 21, 2023 09:54
-
-
Save fire/495fb6a35168500df53c002695a1f5fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") | |
bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=True, modifier="MeshSequenceCache") | |
#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") |
This gives error for Mesh Sequence Cache!!
I changed it like this
bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=True, modifier="MeshSequenceCache")
Will check
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looks like what I need, thanks.