1 # SPDX-License-Identifier: GPL-2.0-or-later
7 def reset_transform(ob
):
12 def func_add_pose_shape_fast(source
, target
):
14 reset_transform(target
)
15 # If target object doesn't have Basis shape key, create it.
17 num_keys
= len(target
.data
.shape_keys
.key_blocks
)
19 basis
= target
.shape_key_add()
22 key_index
= target
.active_shape_key_index
24 # Insert new shape key
25 new_shapekey
= target
.shape_key_add()
26 new_shapekey
.name
= "Shape_" + source
.name
27 new_shapekey_name
= new_shapekey
.name
28 key_index
= len(target
.data
.shape_keys
.key_blocks
) - 1
29 target
.active_shape_key_index
= key_index
30 # else, the active shape will be used (updated)
31 target
.show_only_shape_key
= True
32 shape_key_verts
= target
.data
.shape_keys
.key_blocks
[key_index
].data
34 vgroup
= target
.active_shape_key
.vertex_group
35 target
.active_shape_key
.vertex_group
= ''
38 result
= "***ERROR*** blub"
40 # copy the local vertex positions to the new shape
41 verts
= source
.data
.vertices
43 for n
in range(len(verts
)):
44 shape_key_verts
[n
].co
= verts
[n
].co
45 # go to all armature modifies and unpose the shape
47 message
= "***ERROR***, meshes have different number of vertices"
49 for n
in target
.modifiers
:
50 if n
.type == 'ARMATURE' and n
.show_viewport
:
52 n
.use_bone_envelopes
= False
53 n
.use_deform_preserve_volume
= False
54 n
.use_vertex_groups
= True
56 unposeMesh(shape_key_verts
, target
, armature
)
59 # set the new shape key value to 1.0, so we see the result instantly
60 target
.data
.shape_keys
.key_blocks
[ target
.active_shape_key_index
].value
= 1.0
62 target
.active_shape_key
.vertex_group
= vgroup
65 result
= result
+ "bluba"
67 target
.show_only_shape_key
= False
72 class add_pose_shape_fast(bpy
.types
.Operator
):
73 bl_idname
= "object.add_pose_shape_fast"
74 bl_label
= "Add object as corrective shape faster"
75 bl_description
= "Adds 1st object as shape to 2nd object as pose shape (only 1 armature)"
78 def poll(cls
, context
):
79 return context
.active_object
is not None
81 def execute(self
, context
):
83 if len(context
.selected_objects
) > 2:
84 print("Select source and target objects please")
87 selection
= context
.selected_objects
88 target
= context
.active_object
89 if context
.active_object
== selection
[0]:
95 func_add_pose_shape_fast(source
, target
)