-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
188 lines (146 loc) · 7.11 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
bl_info = {
"name": "mmd_tools_rigid_body_collision_optimize",
"description": "Put rigid bodys into appropriate collision collection in order to avoid collision between selected rigid bodys.",
"author": "rint",
"version": (0, 0, 3),
"blender": (2, 93, 18),
"location": "View3D > Sidebar > MMD Tools Panel",
"category": "Object",
}
import bpy
import mmd_tools.core.model as mmd_model
import mmd_tools
from mmd_tools_rigid_body_collision_optimize.utils import *
# Define a property group to store the custom toggles
class mmd_tools_rigid_body_collision_optimize_PG(bpy.types.PropertyGroup):
#for i in range(20):
# exec(f"custom_toggle_{i}: bpy.props.BoolProperty(name='{i}', default=True)")
#element_list = [0, 10, 1, 11, 2, 12, 3, 13, 4, 14]
#for i in element_list:
# exec(f"custom_toggle_{i}: bpy.props.BoolProperty(name='{i}', default=True)")
#element_list = [5, 15, 6, 16, 7, 17, 8, 18, 9, 19]
#for i in element_list:
# exec(f"custom_toggle_{i}: bpy.props.BoolProperty(name='{i}', default=False)")
custom_toggles: bpy.props.BoolVectorProperty(
name = "Available Collections",
description = "",
size = 20
)
def __init__(self):
element_list = [0, 10, 1, 11, 2, 12, 3, 13, 4, 14]
for i in element_list:
self.custom_toggles[i] = True
class PANEL1_PT_mmd_tools_rigid_body_collision_optimize(bpy.types.Panel):
bl_label = "Collision Collection Interleave"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "MMD"
def draw(self, context):
layout = self.layout
scene = context.scene
test5_property_group = context.scene.test5_property_group # Get the property group
col = self.layout.column(align=True)
col.label(text='Rigid Body')
grid = col.grid_flow(row_major=True, align=True)
row = grid.row(align=True)
row.operator_context = 'EXEC_DEFAULT'
op = row.operator('mmd_tools.rigid_body_select', text='Select', icon='RESTRICT_SELECT_OFF')
row.separator()
op = row.operator('mmd_tools_rigid_body_collision_optimize.clear', text='Clear')
op = row.operator('mmd_tools_rigid_body_collision_optimize.interleave', text='Interleave')
op = row.operator('mmd_tools_rigid_body_collision_optimize.put_into_all', text='Put into All')
# Use the property group to draw the toggles
col = self.layout.column(align=True)
col.label(text='Available Collections')
grid = layout.grid_flow(columns=11, align=True)
element_list = [0, 10, 1, 11, 2, 12, 3, 13, 4, 14]
for i in element_list:
grid.prop(test5_property_group, 'custom_toggles', index=i, text='', toggle=True)
grid.separator()
grid.separator()
element_list = [5, 15, 6, 16, 7, 17, 8, 18, 9, 19]
for i in element_list:
grid.prop(test5_property_group, 'custom_toggles', index=i, text='', toggle=True)
class mmd_tools_rigid_body_collision_optimize_Button0(bpy.types.Operator):
bl_idname = 'mmd_tools_rigid_body_collision_optimize.clear'
bl_label = 'Collision Collection Clear'
bl_description = 'Unassign rigid body to all collection.'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: bpy.types.Context):
return mmd_model.isRigidBodyObject(context.active_object)
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context: bpy.types.Context):
try:
rigid_body_collection_clear(context)
message = 'OK'
self.report({'INFO'}, f"{message}")
except Exception as ex:
self.report(type={'ERROR'}, message=str(ex))
return {'CANCELLED'}
return {'FINISHED'}
class mmd_tools_rigid_body_collision_optimize_Button1(bpy.types.Operator):
bl_idname = 'mmd_tools_rigid_body_collision_optimize.interleave'
bl_label = 'Collision Collection Interleave'
bl_description = 'Put rigid bodys into appropriate collision collection in order to avoid collision between selected rigid bodys.'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: bpy.types.Context):
return mmd_model.isRigidBodyObject(context.active_object)
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context: bpy.types.Context):
try:
test5_property_group = context.scene.test5_property_group
rigid_body_collection_coloring(context, available_collections=test5_property_group.custom_toggles)
message = 'OK'
self.report({'INFO'}, f"{message}")
except Exception as ex:
self.report(type={'ERROR'}, message=str(ex))
return {'CANCELLED'}
return {'FINISHED'}
class mmd_tools_rigid_body_collision_optimize_Button2(bpy.types.Operator):
bl_idname = 'mmd_tools_rigid_body_collision_optimize.put_into_all'
bl_label = 'Collision Collection Put into All'
bl_description = 'Put rigid bodys into all available collections(selected).'
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context: bpy.types.Context):
return mmd_model.isRigidBodyObject(context.active_object)
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def execute(self, context: bpy.types.Context):
try:
test5_property_group = context.scene.test5_property_group
rigid_body_collection_put_into_all(context, available_collections=test5_property_group.custom_toggles)
message = 'OK'
self.report({'INFO'}, f"{message}")
except Exception as ex:
self.report(type={'ERROR'}, message=str(ex))
return {'CANCELLED'}
return {'FINISHED'}
classes = (
mmd_tools_rigid_body_collision_optimize_PG,
PANEL1_PT_mmd_tools_rigid_body_collision_optimize,
mmd_tools_rigid_body_collision_optimize_Button0,
mmd_tools_rigid_body_collision_optimize_Button1,
mmd_tools_rigid_body_collision_optimize_Button2
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.test5_property_group = bpy.props.PointerProperty(type=mmd_tools_rigid_body_collision_optimize_PG)
# 翻譯
from mmd_tools_rigid_body_collision_optimize.m17n import translation_dict
bpy.app.translations.register(bl_info['name'], translation_dict)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.test5_property_group
# 翻譯
bpy.app.translations.unregister(bl_info['name'])
# 插件名可以改一下,容易辨識,也可以不改,不會導致衝突
# bl_idname不能和其他插件一樣,插件同時啟用會導致衝突
# classes名不能和其他插件一樣,插件同時啟用會導致衝突
# Test_Panel3.bl_category和其他插件一樣就會放在一起