5 def reset_transform(ob
):
10 def func_add_pose_shape_fast(source
, target
):
12 reset_transform(target
)
13 # If target object doesn't have Basis shape key, create it.
15 num_keys
= len(target
.data
.shape_keys
.key_blocks
)
17 basis
= target
.shape_key_add()
20 key_index
= target
.active_shape_key_index
22 # Insert new shape key
23 new_shapekey
= target
.shape_key_add()
24 new_shapekey
.name
= "Shape_" + source
.name
25 new_shapekey_name
= new_shapekey
.name
26 key_index
= len(target
.data
.shape_keys
.key_blocks
) - 1
27 target
.active_shape_key_index
= key_index
28 # else, the active shape will be used (updated)
29 target
.show_only_shape_key
= True
30 shape_key_verts
= target
.data
.shape_keys
.key_blocks
[key_index
].data
32 vgroup
= target
.active_shape_key
.vertex_group
33 target
.active_shape_key
.vertex_group
= ''
36 result
= "***ERROR*** blub"
38 # copy the local vertex positions to the new shape
39 verts
= source
.data
.vertices
41 for n
in range(len(verts
)):
42 shape_key_verts
[n
].co
= verts
[n
].co
43 # go to all armature modifies and unpose the shape
45 message
= "***ERROR***, meshes have different number of vertices"
47 for n
in target
.modifiers
:
48 if n
.type == 'ARMATURE' and n
.show_viewport
:
50 n
.use_bone_envelopes
= False
51 n
.use_deform_preserve_volume
= False
52 n
.use_vertex_groups
= True
54 unposeMesh(shape_key_verts
, target
, armature
)
57 # set the new shape key value to 1.0, so we see the result instantly
58 target
.data
.shape_keys
.key_blocks
[ target
.active_shape_key_index
].value
= 1.0
60 target
.active_shape_key
.vertex_group
= vgroup
63 result
= result
+ "bluba"
65 target
.show_only_shape_key
= False
70 class add_pose_shape_fast(bpy
.types
.Operator
):
71 bl_idname
= "object.add_pose_shape_fast"
72 bl_label
= "Add object as corrective shape faster"
73 bl_description
= "Adds 1st object as shape to 2nd object as pose shape (only 1 armature)"
76 def poll(cls
, context
):
77 return context
.active_object
is not None
79 def execute(self
, context
):
81 if len(context
.selected_objects
) > 2:
82 print("Select source and target objects please")
85 selection
= context
.selected_objects
86 target
= context
.active_object
87 if context
.active_object
== selection
[0]:
93 func_add_pose_shape_fast(source
, target
)