sun_position: fix warning from deleted prop in User Preferences
[blender-addons.git] / add_mesh_geodesic_domes / add_shape_geodesic.py
blobd461bd152a8d547c01e0322d1fb8689e18cdbc38
1 import bpy
2 import mathutils
5 def reset_transform(ob):
6 m = mathutils.Matrix()
7 ob.matrix_local = m
10 def func_add_pose_shape_fast(source, target):
11 result = ""
12 reset_transform(target)
13 # If target object doesn't have Basis shape key, create it.
14 try:
15 num_keys = len(target.data.shape_keys.key_blocks)
16 except:
17 basis = target.shape_key_add()
18 basis.name = "Basis"
19 target.data.update()
20 key_index = target.active_shape_key_index
21 if key_index == 0:
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
31 try:
32 vgroup = target.active_shape_key.vertex_group
33 target.active_shape_key.vertex_group = ''
34 except:
35 print("blub")
36 result = "***ERROR*** blub"
37 pass
38 # copy the local vertex positions to the new shape
39 verts = source.data.vertices
40 try:
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
44 except:
45 message = "***ERROR***, meshes have different number of vertices"
46 result = message
47 for n in target.modifiers:
48 if n.type == 'ARMATURE' and n.show_viewport:
49 # print("got one")
50 n.use_bone_envelopes = False
51 n.use_deform_preserve_volume = False
52 n.use_vertex_groups = True
53 armature = n.object
54 unposeMesh(shape_key_verts, target, armature)
55 break
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
59 try:
60 target.active_shape_key.vertex_group = vgroup
61 except:
62 print("bluba")
63 result = result + "bluba"
64 pass
65 target.show_only_shape_key = False
66 target.data.update()
67 return result
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)"
75 @classmethod
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")
83 return {'FINISHED'}
85 selection = context.selected_objects
86 target = context.active_object
87 if context.active_object == selection[0]:
88 source = selection[1]
89 else:
90 source = selection[0]
91 print(source)
92 print(target)
93 func_add_pose_shape_fast(source, target)
95 return {'FINISHED'}