Skip to content

Instantly share code, notes, and snippets.

@Jason0214
Last active May 17, 2019 04:47
Show Gist options
  • Save Jason0214/28b31f0479718b29e7f20a5fe1bf8348 to your computer and use it in GitHub Desktop.
Save Jason0214/28b31f0479718b29e7f20a5fe1bf8348 to your computer and use it in GitHub Desktop.
Blender2.8 bake shape key to mesh
import bmesh
base_key = obj.data.shape_keys.reference_key
for index, shape_key in enumerate(obj.data.shape_keys.key_blocks):
if shape_key == base_key:
continue
obj.show_only_shape_key = True
obj.active_shape_key_index = index
bpy.context.scene.update()
shape_key_mesh = obj.to_mesh(bpy.context.view_layer.depsgraph, apply_modifiers=True, calc_undeformed=True)
obj.show_only_shape_key = False
tri_mesh = bmesh.new()
tri_mesh.from_mesh(shape_key_mesh)
bmesh.ops.triangulate(tri_mesh, faces=tri_mesh.faces, quad_method="ALTERNATE")
tri_mesh.to_mesh(shape_key_mesh)
tri_mesh.free()
shape_key_mesh.update(calc_loop_triangles=True)
if obj.data.uv_layers:
shape_key_mesh.calc_tangents()
else:
shape_key_mesh.calc_normals_split()
new_obj = bpy.data.objects.new('shape_key_mesh', shape_key_mesh)
bpy.context.view_layer.active_layer_collection.collection.objects.link(new_obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment