-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
162 lines (147 loc) · 6.34 KB
/
Copy path__init__.py
File metadata and controls
162 lines (147 loc) · 6.34 KB
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
bl_info = {
"name": "COM3D2 Group Converter",
"author": "Toys0125",
"blender": (2,93,0),
"version": (0,1,0),
"location": "View 3D > Tool Shelf > Misc > COM3D2 group Converter",
"description": "Remap vertex groups into simplfied armature",
"category": "3D View"
}
import bpy
from . import translatetable
class COM3D2ObjectProperties(bpy.types.PropertyGroup):
selectedObject : bpy.props.PointerProperty( # bl 2.80 use testint: bpy.props
name="selectedObject",
description="selectedObject",
type=bpy.types.Object
)
applyMods: bpy.props.BoolProperty(
name="Apply Vertex Mix Mods",
description="Apply all Vertex Mix mods",
default=True
)
class ExecuteVertexRemapping(bpy.types.Operator):
bl_idname = "object.execute_vertex_remapping"
bl_label = "ExecuteVertexRemapping"
# Here you declare everything you want to show in the dialog
# This is the method that is called when the ok button is pressed
# which is what calls the ApplyModifers() method
def execute(self, context):
try:
bpy.ops.object.decode_cm3d2_vertex_group_names()
except RuntimeError:
pass
translateVertexGroups(context,context.scene.COM3D2objectProperties)
self.report({'INFO'}, "Remapping done")
return {'FINISHED'}
def cancel(self,context):
return None
# This method adds a cube to the current scene and then applys scale and
# name to the cube
def apply_modifiers(obj):
ctx = bpy.context.copy()
ctx['object'] = obj
for _, m in enumerate(obj.modifiers):
if m.type == 'VERTEX_WEIGHT_MIX':
try:
ctx['modifier'] = m
bpy.ops.object.modifier_apply(ctx, modifier=m.name)
except RuntimeError:
print(f"Error applying {m.name} to {obj.name}.")
# Calls the menu when the script is ran
class COM3D2GroupConverter(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Misc" # not used in blender 2.80
bl_context = "objectmode"
bl_label = "COM3D2 Group Converter"
bl_idname = "VIEW3D_PT_COM3D2_Group_Converter"
def draw(self, context):
layout = self.layout
obj = context.object
props = context.scene.COM3D2objectProperties
row = layout.row()
row.prop(props,"applyMods")
row= layout.row()
row.operator('object.execute_vertex_remapping')
def translateVertexGroups(context,props):
translate = translatetable.translateTable
selected = context.selected_objects
if len(selected) == 0:
raise ValueError("No objects selected")
for item in selected:
for modifiername,mod in item.modifiers.items():
if mod.type == 'VERTEX_WEIGHT_MIX':
item.modifiers.remove(mod)
print("Removed modifier for "+ modifiername)
for key,value in translate.items():
if value["L/R"]:
if item.vertex_groups.find(key+"L") != -1:
item.vertex_groups.remove(item.vertex_groups[key+"L"])
if item.vertex_groups.find(key+"R") != -1:
item.vertex_groups.remove(item.vertex_groups[key+"R"])
item.vertex_groups.new(name=key+"L")
item.vertex_groups.new(name=key+"R")
else:
if item.vertex_groups.find(key) != -1:
item.vertex_groups.remove(item.vertex_groups[key])
item.vertex_groups.new(name=key)
Nogroups = True
isLeftorRightUsed = [True,True]
for group in value["Groups"]:
if value["L/R"]:
if item.vertex_groups.find(group+"L") == -1 and item.vertex_groups.find(group+"R") == -1:
continue
if item.vertex_groups.find(group+"L") != -1:
mod1 = item.modifiers.new(key+"L+"+group+"L",type="VERTEX_WEIGHT_MIX")
mod1.mix_mode='ADD'
mod1.mix_set='ALL'
mod1.vertex_group_a=key+"L"
mod1.vertex_group_b=group+"L"
mod1.show_expanded = False
isLeftorRightUsed[0] = False
if item.vertex_groups.find(group+"R") != -1:
mod2 = item.modifiers.new(key+"R+"+group+"R",type="VERTEX_WEIGHT_MIX")
mod2.mix_mode='ADD'
mod2.mix_set='ALL'
mod2.vertex_group_a=key+"R"
mod2.vertex_group_b=group+"R"
mod2.show_expanded = False
isLeftorRightUsed[1]= False
else:
if item.vertex_groups.find(group) == -1:
continue
mod = item.modifiers.new(key+"+"+group,type="VERTEX_WEIGHT_MIX")
mod.mix_mode='ADD'
mod.mix_set='ALL'
mod.vertex_group_a=key
mod.vertex_group_b=group
mod.show_expanded = False
Nogroups = False
if Nogroups:
if value["L/R"]:
item.vertex_groups.remove(item.vertex_groups[key+"L"])
item.vertex_groups.remove(item.vertex_groups[key+"R"])
else:
item.vertex_groups.remove(item.vertex_groups[key])
else:
if value["L/R"]:
if isLeftorRightUsed[0]:
item.vertex_groups.remove(item.vertex_groups[key+"L"])
if isLeftorRightUsed[1]:
item.vertex_groups.remove(item.vertex_groups[key+"R"])
if props.applyMods:
apply_modifiers(item)
def register():
classes = [COM3D2GroupConverter,ExecuteVertexRemapping,COM3D2ObjectProperties]
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.COM3D2objectProperties = bpy.props.PointerProperty(
type=COM3D2ObjectProperties)
def unregister():
classes = [COM3D2GroupConverter,ExecuteVertexRemapping,COM3D2ObjectProperties]
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.COM3D2objectProperties
if __name__ == "__main__":
register()