-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
121 lines (97 loc) · 3.93 KB
/
ui.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
import bpy
from bpy.types import Panel, Operator, PropertyGroup
from . import utils, ops_structure
import bmesh
class STRA_PT_Joint(Panel):
bl_idname = "STRA_PT_Joint"
bl_label = "Create joints"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Structura"
bl_context = "objectmode"
def draw(self, context):
layout = self.layout
props_structure = context.scene.stra_props_structure
props_joint = context.scene.stra_props_joint
col_joints = utils.get_collection_joints(False)
all_objects_have_rigidbody = True
mesh_amount = 0
for ob in context.selected_objects:
if ob.rigid_body is None:
all_objects_have_rigidbody = False
if ob.type != 'MESH':
continue
if utils.OBJNAME_COLLIDER in ob.name:
continue
mesh_amount += 1
layout.label(text=f'{mesh_amount} mesh object(s) selected')
if mesh_amount < 2:
layout.label(text=f'(Select at least 2 mesh objects)')
return
if not all_objects_have_rigidbody:
layout.label(text=f'(Not all selected objects have rigid body)')
return
layout.separator(factor=1)
r = layout.row()
r.scale_y = 0.5
r.label(text='Generation mode:')
layout.prop(props_structure, "mode", expand=True)
layout.separator(factor=1.8)
r = layout.row()
c1 = r.column()
c2 = r.column()
c1.label(text='Joint type:')
c2.prop(props_joint, "type", text="")
if props_joint.type == 'GENERIC':
r = layout.row()
r.prop(props_joint, "leeway_linear")
r.prop(props_joint, "leeway_angular")
layout.prop(props_joint, "use_local_collisions")
layout.prop(props_joint, "break_threshold", )
if props_structure.mode == "EXACT":
layout.prop(props_joint, "use_overlap_volume")
if col_joints is not None and len(col_joints.objects) > 0:
r = layout.row()
r.scale_y = 2
r.operator("stra.structure_modify", icon='MOD_NORMALEDIT', text=f'Apply to joints of selected objects')
layout.separator(factor=2)
layout.prop(props_structure, "overlap_margin")
if props_structure.mode == "EXACT":
layout.prop(props_structure, "min_overlap_threshold")
layout.separator(factor=0.1)
r = layout.row()
r.scale_y = 0.5
r.label(text="Existing joint behaviour:")
layout.prop(props_structure, "existing_joint_behaviour", text="")
if props_structure.progress > 0.0 and props_structure.progress < 1.0:
r = layout.row()
r.label(text=f"Progress: {props_structure.progress*100:.2f}%")
if mesh_amount > 1:
r = layout.row()
r.scale_y = 2
txt_button = f'Generate between {mesh_amount} objects'
r.operator("stra.structure_generate", icon='MOD_MESHDEFORM', text=txt_button)
class STRA_PT_Utilities(Panel):
bl_idname = "STRA_PT_Utilities"
bl_label = "Utilities"
bl_category = "Structura"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_context = "objectmode"
bl_options = {'DEFAULT_CLOSED'}
def draw(self, context):
layout = self.layout
amount_selected_meshes = 0
joints = []
for ob in context.selected_objects:
if ob.type == 'MESH':
amount_selected_meshes += 1
if ob.get("joints"):
for name in ob["joints"]:
if name not in joints:
joints.append(name)
layout.label(text=f'{amount_selected_meshes} selected meshes')
layout.label(text=f'with {len(joints)} joints')
r = layout.row()
r.operator("stra.utils_select_joints", icon='ACTION_TWEAK', text="Select joints", )
r.enabled = len(joints) > 0