4
def reset_transform(ob):
8
def func_add_corrective_pose_shape_fast(source, target):
10
reset_transform(target)
11
# If target object doesn't have Basis shape key, create it.
13
num_keys = len( target.data.shape_keys.key_blocks )
15
basis = target.shape_key_add()
18
key_index = target.active_shape_key_index
20
# Insert new shape key
21
new_shapekey = target.shape_key_add()
22
new_shapekey.name = "Shape_" + source.name
23
new_shapekey_name = new_shapekey.name
24
key_index = len(target.data.shape_keys.key_blocks)-1
25
target.active_shape_key_index = key_index
26
# else, the active shape will be used (updated)
27
target.show_only_shape_key = True
28
shape_key_verts = target.data.shape_keys.key_blocks[ key_index ].data
30
vgroup = target.active_shape_key.vertex_group
31
target.active_shape_key.vertex_group = ''
34
result = "***ERROR*** blub"
36
# copy the local vertex positions to the new shape
37
verts = source.data.vertices
39
for n in range( len(verts)):
40
shape_key_verts[n].co = verts[n].co
41
# go to all armature modifies and unpose the shape
43
message = "***ERROR***, meshes have different number of vertices"
45
for n in target.modifiers:
46
if n.type == 'ARMATURE' and n.show_viewport:
48
n.use_bone_envelopes = False
49
n.use_deform_preserve_volume = False
50
n.use_vertex_groups = True
52
unposeMesh( shape_key_verts, target, armature)
55
# set the new shape key value to 1.0, so we see the result instantly
56
target.data.shape_keys.key_blocks[ target.active_shape_key_index].value = 1.0
58
target.active_shape_key.vertex_group = vgroup
61
result = result + "bluba"
63
target.show_only_shape_key = False
67
class add_corrective_pose_shape_fast(bpy.types.Operator):
68
"""Add 1st object as shape to 2nd object as pose shape (only 1 armature)"""
69
bl_idname = "object.add_corrective_pose_shape_fast"
70
bl_label = "Add object as corrective shape faster"
73
def poll(cls, context):
74
return context.active_object != None
76
def execute(self, context):
78
if len(context.selected_objects) > 2:
79
print("Select source and target objects please")
82
selection = context.selected_objects
83
target = context.active_object
84
if context.active_object == selection[0]:
90
func_add_corrective_pose_shape_fast( source, target)
94
bpy.utils.register_module(__name__)
97
bpy.utils.unregister_module(__name__)
99
if __name__ == "__main__":