-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path__init__.py
309 lines (245 loc) · 14 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import bpy
import os
script_dir = os.path.dirname(os.path.realpath(__file__))
# import sys
# sys.path.append(script_dir)
# print("*****RELOADED*****")
# from importlib import reload
# import mesh_data_transfer as md
# reload(md)
# import operators as op
# reload(op)
# print("****************RELOADED MODULES**************")
from bpy.types import (PropertyGroup)
from bpy.props import (PointerProperty)
from .operators import ( TransferShapeKeyDrivers, TransferMeshData, MapTopology)
bl_info = {
"name" : "MeshDataTransfer",
"author" : "Maurizio Memoli",
"description" : "This add on will transfer geometry data from one mesh to another based on 3 different spaces:"
" 'world, object, uv' also will tranfer UVs based on topology",
"blender" : (4, 1, 0),
"version" : (2, 0, 5,),
"location" : "(Object Mode) Mesh > ObjectData > Mesh Data Transfer ",
"warning" : "",
"wiki_url": "",
"category" : "Mesh"
}
def scene_chosenobject_poll( context, object):
if bpy.context.active_object == object:
return False
return object.type in ['MESH']
def pick_armature( context, object):
if bpy.context.active_object == object:
return False
return object.type in ['ARMATURE']
def update_search_method (self, context):
active = context.active_object
if not active:
return
attributes_to_transfer = context.object.mesh_data_transfer_object.attributes_to_transfer
search_method = context.object.mesh_data_transfer_object.search_method
if search_method == "UVS" and attributes_to_transfer == "UVS":
context.object.mesh_data_transfer_object.search_method = 'CLOSEST'
class MeshDataSettings(PropertyGroup):
mesh_object_space: bpy.props.EnumProperty(
items=[('WORLD', 'World', '', 1),('LOCAL', 'Local', '', 2)],
name="Object Space", default = 'LOCAL')
gp_object_space: bpy.props.EnumProperty(
items=[('WORLD', 'World', '', 1),('LOCAL', 'Local', '', 2)],
name="Object Space", default = 'LOCAL')
search_method: bpy.props.EnumProperty(
items=[('CLOSEST', 'Closest', "Closest Point on Surface Search Method", 1),
('RAYCAST', 'Raycast', "Bidirectional Projection Search Method", 2),
('TOPOLOGY', 'Topology', "Vertex ID or Topology Search Methood", 3)
,('UVS', 'Active UV', "Active UV Search Method", 4)],
name="Search method", default='CLOSEST' )
attributes_to_transfer: bpy.props.EnumProperty(
items=[('SHAPE', 'Shape', '', 1),('UVS', 'UV set', '', 2),('SHAPE_KEYS', 'Shape Keys', '', 3)
,('VERTEX_GROUPS', 'Vertex Groups', '', 4)],
name="Attributes to to transfer", default = "SHAPE", update = update_search_method)
mesh_source: bpy.props.PointerProperty(name="Source mesh", description= "Pick a source armature for transfer"
,type=bpy.types.Object, poll=scene_chosenobject_poll)
arm_source: bpy.props.PointerProperty(name="Source armature", description= "Pick a target armature for transfer"
,type=bpy.types.Object, poll=pick_armature)
arm_target: bpy.props.PointerProperty(name="Target armature", description= "Pick a source mesh for transfer"
,type=bpy.types.Object, poll=pick_armature)
vertex_group_filter: bpy.props.StringProperty (name="Vertex Group",
description="Filter transfer using a vertex group.")
invert_vertex_group_filter: bpy.props.BoolProperty (name= "Invert vertex group values")
transfer_edit_selection: bpy.props.BoolProperty(name= "Only edit mode selection",
description= "Restrict transfer to selection in edit mode")
transfer_shape_as_key : bpy.props.BoolProperty (name="Transfer as shape key",
description="Transfer vertices position as a shape key")
transfer_to_new_uv : bpy.props.BoolProperty()
transfer_modified_source : bpy.props.BoolProperty (name="Transfer deformed source",
description="Transfer the source mesh deformed by modifiers and shapeKeys")
exclude_muted_shapekeys : bpy.props.BoolProperty (name= "Exclude muted",
description="Muted shape keys will not be transferred")
exclude_locked_groups: bpy.props.BoolProperty (name= "Exclude locked",
description="Locked vertex groups will not be transferred")
snap_to_closest_shape: bpy.props.BoolProperty (name="Snap shape to closest vertex",
description="Snap transferred vertices to closest vertex on source mesh")
snap_to_closest_shapekey: bpy.props.BoolProperty (name="Snap shape key to closest vertex",
description="Snap transferred shape keys vertices to closest vertex on source shape key")
#=========================================UI===============================================================
class DATA_PT_mesh_data_transfer(bpy.types.Panel):
bl_label = "Mesh Data Transfer"
bl_idname = "MESH_PT_mesh_data_transfer"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'data'
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
# To reactivate GPencil change the variable to: ['MESH','GPENCIL']
return context.active_object.type in ['MESH']
@classmethod
def is_vert_count_matching(cls,context, identifier):
active = bpy.context.active_object
source = active.mesh_data_transfer_object.mesh_source
if identifier == "TOPOLOGY":
if not source:
return False
if len(source.data.vertices) == len(active.data.vertices):
return True
else:
return False
elif identifier== "UVS":
if not source:
return False
if active.mesh_data_transfer_object.attributes_to_transfer == "UVS":
return False
if source.data.uv_layers.active:
return True
else:
return False
return True
def draw(self, context):
active = bpy.context.active_object
ob_prop = context.object.mesh_data_transfer_object
# sc_prop = context.scene.mesh_data_transfer_global
obj = context.object
# mesh_object_space layout
main_box_layout = self.layout.box()
sample_main_box = main_box_layout.box()
search_space_label = sample_main_box.row()
search_space_label.alignment = 'CENTER'
search_space_label.label(text="SEARCH METHOD")
option_row = sample_main_box.row()
items = ob_prop.bl_rna.properties["search_method"].enum_items_static
search_icons = ["ARROW_LEFTRIGHT","PROP_PROJECTED","MESH_DATA","UV_DATA"]
for i, item in enumerate(items):
search_icon = search_icons[i]
# This is the first item of the enum item tuple, eg. "NONE", or "BONE_GROUPS" :
identifier = item.identifier
# This seems overkill but we need individual access to the field layout to disable it :
item_layout = option_row.row(align=True)
if i == 2:
if not active.mesh_data_transfer_object.attributes_to_transfer =="UVS":
item_layout.prop_enum(ob_prop, "search_method", identifier, text="Vertex ID",icon=search_icon)
else:
item_layout.prop_enum(ob_prop, "search_method", identifier, icon=search_icon)
else:
item_layout.prop_enum(ob_prop, "search_method", identifier, icon = search_icon)
item_layout.enabled = self.is_vert_count_matching(context, identifier)
top_row_box_layout = main_box_layout.box()
attribute_label = top_row_box_layout.row()
attribute_label.alignment = 'CENTER'
attribute_label.label(text="ATTRIBUTE TO TRANSFER")
# attribute to transfer
top_row_layout = top_row_box_layout.row()
attributes_to_transfer = ob_prop.bl_rna.properties["attributes_to_transfer"].enum_items_static
left_top_row_box_layout = top_row_layout.box()
shape_cols_layout = left_top_row_box_layout.row(align=True)
shape_identifier = attributes_to_transfer[0].identifier
uv_identifier = attributes_to_transfer[1].identifier
shape_keys_identifier = attributes_to_transfer[2].identifier
vertex_groups_identifier = attributes_to_transfer[3].identifier
shape_cols_layout.prop_enum (ob_prop, "attributes_to_transfer", shape_identifier, icon="MOD_DATA_TRANSFER")
# split = shape_cols_layout.split()
snap_shape_icon = "SNAP_OFF"
if ob_prop.snap_to_closest_shape:
snap_shape_icon = "SNAP_ON"
shape_cols_layout.prop (ob_prop , "snap_to_closest_shape" , text="" , toggle=True , icon=snap_shape_icon)
shape_cols_layout.prop (ob_prop , "transfer_shape_as_key" , text="", toggle=True, icon='SHAPEKEY_DATA')
left_bottom_row_box_layout = left_top_row_box_layout.row(align=True)
left_bottom_row_box_layout.prop_enum(ob_prop, "attributes_to_transfer", shape_keys_identifier,
icon="SHAPEKEY_DATA")
snap_key_icon = "SNAP_OFF"
if ob_prop.snap_to_closest_shapekey:
snap_key_icon = "SNAP_ON"
left_bottom_row_box_layout.prop(ob_prop , "snap_to_closest_shapekey" , text="",
toggle=True, icon=snap_key_icon)
left_bottom_row_box_layout.prop(ob_prop , "exclude_muted_shapekeys" , text="",
toggle=True, icon='CHECKMARK')
top_row_layout.split()
right_top_row_box_layout = top_row_layout.box()
right_top_row_box_layout.prop_enum (ob_prop, "attributes_to_transfer", uv_identifier,
icon="UV_DATA")
right_bottom_row_box_layout = right_top_row_box_layout.row(align=True)
right_bottom_row_box_layout.prop_enum(ob_prop, "attributes_to_transfer", vertex_groups_identifier,
icon="GROUP_VERTEX")
right_bottom_row_box_layout.prop(ob_prop , "exclude_locked_groups" , text="",
toggle=True, icon='LOCKED')
#mesh picker layout
mesh_picker_box_layout = main_box_layout.box()
mesh_picker_row = mesh_picker_box_layout.row(align=True)
mesh_picker_row.prop_search(ob_prop, "mesh_source", context.scene, "objects", text="Source")
mesh_picker_row.prop(ob_prop, "mesh_object_space", toggle=True, text="", icon ="WORLD" )
mesh_picker_row.prop(ob_prop, 'transfer_modified_source',text="", icon='MOD_MESHDEFORM')
# vertex group filter
vgroup_picker_box_layout = main_box_layout.box()
vgroup_row = vgroup_picker_box_layout.row(align=True)
vgroup_row.prop_search(ob_prop, "vertex_group_filter", active, "vertex_groups")
vgroup_row.prop (ob_prop , "invert_vertex_group_filter" , text="" , toggle=True , icon='ARROW_LEFTRIGHT')
# Mesh transfer button
transfer_box_layout = main_box_layout.box()
transfer_layout = transfer_box_layout.row()
restrict_icon = "RESTRICT_SELECT_ON"
if ob_prop.transfer_edit_selection:
restrict_icon = "RESTRICT_SELECT_OFF"
transfer_layout.prop(ob_prop, "transfer_edit_selection", text="", toggle =True, icon = restrict_icon)
transfer_layout.operator("object.transfer_mesh_data", text="Transfer Mesh Data",
icon="MOD_DATA_TRANSFER")
# # transfer_layout.prop(ob_prop, "transfer_edit_selection", text="", toggle =True, icon = restrict_icon)
# transfer_layout.operator("object.map_topology", text="Map Topology",
# icon="MOD_DATA_TRANSFER")
#
# Rigging utilities
utility_box_layout = main_box_layout.box()
utility_label = utility_box_layout.row(align=True)
utility_label.prop(obj, "expanded",
icon="TRIA_DOWN" if obj.expanded else "TRIA_RIGHT",
icon_only=True, emboss=False, expand=False)
utility_label.label(text="RIGGING HELPERS")
utility_label.alignment = "LEFT"
if obj.expanded:
#armature picker layout
source_arm_picker_box_layout = utility_box_layout.box()
source_arm_picker_box_layout.prop_search(ob_prop, "arm_source", context.scene, "objects", text="Source Armature")
target_arm_picker_box_layout = utility_box_layout.box()
target_arm_picker_box_layout.prop_search(ob_prop, "arm_target", context.scene, "objects", text="Target Armature")
transfer_drivers_layout = utility_box_layout.row()
transfer_drivers_layout.operator("object.transfer_shape_key_drivers", text="Transfer Shape Keys drivers",
icon="DRIVER")
#=================================================================================================================
classes = (DATA_PT_mesh_data_transfer, MeshDataSettings,
TransferShapeKeyDrivers, TransferMeshData, MapTopology)
def register():
global classes
for cl in classes:
bpy.utils.register_class(cl)
bpy.types.Object.mesh_data_transfer_object = PointerProperty (type=MeshDataSettings)
bpy.types.Object.expanded = bpy.props.BoolProperty(default=False)
# bpy.types.Scene.mesh_data_transfer_global = PointerProperty (type=MeshDataGlobalSettings)
def unregister():
global classes
for cl in classes:
# print (cl)
bpy.utils.unregister_class (cl)
del bpy.types.Object.mesh_data_transfer_object
del bpy.types.Object.expanded
# del bpy.types.Scene.mesh_data_transfer_global
if __name__ == "__main__":
register()