Cleanup: unused imports
[blender.git] / release / scripts / startup / bl_ui / properties_physics_rigidbody_constraint.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 from bpy.types import (
22     Panel,
23 )
24
25
26 class PHYSICS_PT_rigidbody_constraint_panel:
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "physics"
30
31
32 class PHYSICS_PT_rigid_body_constraint(PHYSICS_PT_rigidbody_constraint_panel, Panel):
33     bl_label = "Rigid Body Constraint"
34     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
35
36     @classmethod
37     def poll(cls, context):
38         ob = context.object
39         return (ob and ob.rigid_body_constraint and context.engine in cls.COMPAT_ENGINES)
40
41     def draw(self, context):
42         layout = self.layout
43         layout.use_property_split = True
44
45         ob = context.object
46         rbc = ob.rigid_body_constraint
47
48         layout.prop(rbc, "type")
49
50
51 class PHYSICS_PT_rigid_body_constraint_settings(PHYSICS_PT_rigidbody_constraint_panel, Panel):
52     bl_label = "Settings"
53     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
54     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
55
56     @classmethod
57     def poll(cls, context):
58         ob = context.object
59         return (ob and ob.rigid_body_constraint and context.engine in cls.COMPAT_ENGINES)
60
61     def draw(self, context):
62         layout = self.layout
63         layout.use_property_split = True
64         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
65
66         ob = context.object
67         rbc = ob.rigid_body_constraint
68
69         col = flow.column()
70         col.prop(rbc, "enabled")
71         col.prop(rbc, "disable_collisions")
72
73         if rbc.type != 'MOTOR':
74             col = flow.column()
75             col.prop(rbc, "use_breaking")
76
77             sub = col.column()
78             sub.active = rbc.use_breaking
79             sub.prop(rbc, "breaking_threshold", text="Threshold")
80
81
82 class PHYSICS_PT_rigid_body_constraint_objects(PHYSICS_PT_rigidbody_constraint_panel, Panel):
83     bl_label = "Objects"
84     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
85     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
86
87     @classmethod
88     def poll(cls, context):
89         ob = context.object
90         return (ob and ob.rigid_body_constraint and context.engine in cls.COMPAT_ENGINES)
91
92     def draw(self, context):
93         layout = self.layout
94         layout.use_property_split = True
95
96         ob = context.object
97         rbc = ob.rigid_body_constraint
98
99         layout.prop(rbc, "object1", text="First")
100         layout.prop(rbc, "object2", text="Second")
101
102
103 class PHYSICS_PT_rigid_body_constraint_override_iterations(PHYSICS_PT_rigidbody_constraint_panel, Panel):
104     bl_label = "Override Iterations"
105     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
106     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
107
108     @classmethod
109     def poll(cls, context):
110         ob = context.object
111         return (ob and ob.rigid_body_constraint and context.engine in cls.COMPAT_ENGINES)
112
113     def draw_header(self, context):
114         ob = context.object
115         rbc = ob.rigid_body_constraint
116         self.layout.row().prop(rbc, "use_override_solver_iterations", text="")
117
118     def draw(self, context):
119         layout = self.layout
120         layout.use_property_split = True
121
122         ob = context.object
123         rbc = ob.rigid_body_constraint
124
125         layout.active = rbc.use_override_solver_iterations
126         layout.prop(rbc, "solver_iterations", text="Iterations")
127
128
129 class PHYSICS_PT_rigid_body_constraint_limits(PHYSICS_PT_rigidbody_constraint_panel, Panel):
130     bl_label = "Limits"
131     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
132     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
133
134     @classmethod
135     def poll(cls, context):
136         ob = context.object
137         rbc = ob.rigid_body_constraint
138
139         return (ob and rbc and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'HINGE', 'SLIDER', 'PISTON'})
140                 and context.engine in cls.COMPAT_ENGINES)
141
142     def draw(self, context):
143         return  # do nothing.
144
145
146 class PHYSICS_PT_rigid_body_constraint_limits_linear(PHYSICS_PT_rigidbody_constraint_panel, Panel):
147     bl_label = "Linear"
148     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_limits'
149     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
150
151     @classmethod
152     def poll(cls, context):
153         ob = context.object
154         rbc = ob.rigid_body_constraint
155
156         return (ob and rbc
157                 and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'SLIDER', 'PISTON'})
158                 and context.engine in cls.COMPAT_ENGINES)
159
160     def draw(self, context):
161         layout = self.layout
162         layout.use_property_split = True
163         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
164
165         ob = context.object
166         rbc = ob.rigid_body_constraint
167
168         if rbc.type in {'PISTON', 'SLIDER'}:
169             col = flow.column()
170             col.prop(rbc, "use_limit_lin_x")
171
172             sub = col.column(align=True)
173             sub.active = rbc.use_limit_lin_x
174             sub.prop(rbc, "limit_lin_x_lower", text="X Lower")
175             sub.prop(rbc, "limit_lin_x_upper", text="Upper")
176
177         elif rbc.type in {'GENERIC', 'GENERIC_SPRING'}:
178             col = flow.column()
179             col.prop(rbc, "use_limit_lin_x")
180
181             sub = col.column(align=True)
182             sub.active = rbc.use_limit_lin_x
183             sub.prop(rbc, "limit_lin_x_lower", text="X Lower")
184             sub.prop(rbc, "limit_lin_x_upper", text="Upper")
185
186             col = flow.column()
187             col.prop(rbc, "use_limit_lin_y")
188
189             sub = col.column(align=True)
190             sub.active = rbc.use_limit_lin_y
191             sub.prop(rbc, "limit_lin_y_lower", text="Y Lower")
192             sub.prop(rbc, "limit_lin_y_upper", text="Upper")
193
194             col = flow.column()
195             col.prop(rbc, "use_limit_lin_z")
196
197             sub = col.column(align=True)
198             sub.active = rbc.use_limit_lin_z
199             sub.prop(rbc, "limit_lin_z_lower", text="Z Lower")
200             sub.prop(rbc, "limit_lin_z_upper", text="Upper")
201
202
203 class PHYSICS_PT_rigid_body_constraint_limits_angular(PHYSICS_PT_rigidbody_constraint_panel, Panel):
204     bl_label = "Angular"
205     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_limits'
206     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
207
208     @classmethod
209     def poll(cls, context):
210         ob = context.object
211         rbc = ob.rigid_body_constraint
212
213         return (ob and rbc
214                 and (rbc.type in {'GENERIC', 'GENERIC_SPRING', 'HINGE', 'PISTON'})
215                 and context.engine in cls.COMPAT_ENGINES)
216
217     def draw(self, context):
218         layout = self.layout
219         layout.use_property_split = True
220         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
221
222         ob = context.object
223         rbc = ob.rigid_body_constraint
224
225         if rbc.type == 'HINGE':
226             col = flow.column()
227             col.prop(rbc, "use_limit_ang_z")
228
229             sub = col.column(align=True)
230             sub.active = rbc.use_limit_ang_z
231             sub.prop(rbc, "limit_ang_z_lower", text="Z Lower")
232             sub.prop(rbc, "limit_ang_z_upper", text="Upper")
233
234         elif rbc.type == 'PISTON':
235             col = flow.column()
236             col.prop(rbc, "use_limit_ang_x")
237
238             sub = col.column(align=True)
239             sub.active = rbc.use_limit_ang_x
240             sub.prop(rbc, "limit_ang_x_lower", text="X Lower")
241             sub.prop(rbc, "limit_ang_x_upper", text="Upper")
242
243         elif rbc.type in {'GENERIC', 'GENERIC_SPRING'}:
244             col = flow.column()
245             col.prop(rbc, "use_limit_ang_x")
246
247             sub = col.column(align=True)
248             sub.active = rbc.use_limit_ang_x
249             sub.prop(rbc, "limit_ang_x_lower", text="X Lower")
250             sub.prop(rbc, "limit_ang_x_upper", text="Upper")
251
252             col = flow.column()
253             col.prop(rbc, "use_limit_ang_y")
254
255             sub = col.column(align=True)
256             sub.active = rbc.use_limit_ang_y
257             sub.prop(rbc, "limit_ang_y_lower", text="Y Lower")
258             sub.prop(rbc, "limit_ang_y_upper", text="Upper")
259
260             col = flow.column()
261             col.prop(rbc, "use_limit_ang_z")
262
263             sub = col.column(align=True)
264             sub.active = rbc.use_limit_ang_z
265             sub.prop(rbc, "limit_ang_z_lower", text="Z Lower")
266             sub.prop(rbc, "limit_ang_z_upper", text="Upper")
267
268
269 class PHYSICS_PT_rigid_body_constraint_motor(PHYSICS_PT_rigidbody_constraint_panel, Panel):
270     bl_label = "Motor"
271     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
272     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
273
274     @classmethod
275     def poll(cls, context):
276         ob = context.object
277         rbc = ob.rigid_body_constraint
278
279         return (ob and rbc and rbc.type == 'MOTOR'
280                 and context.engine in cls.COMPAT_ENGINES)
281
282     def draw(self, context):
283         return  # do nothing.
284
285
286 class PHYSICS_PT_rigid_body_constraint_motor_angular(PHYSICS_PT_rigidbody_constraint_panel, Panel):
287     bl_label = "Angular"
288     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_motor'
289     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
290
291     @classmethod
292     def poll(cls, context):
293         ob = context.object
294         rbc = ob.rigid_body_constraint
295
296         return (ob and rbc and rbc.type == 'MOTOR'
297                 and context.engine in cls.COMPAT_ENGINES)
298
299     def draw_header(self, context):
300         ob = context.object
301         rbc = ob.rigid_body_constraint
302
303         self.layout.row().prop(rbc, "use_motor_ang", text="")
304
305     def draw(self, context):
306         layout = self.layout
307         layout.use_property_split = True
308         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
309
310         ob = context.object
311         rbc = ob.rigid_body_constraint
312
313         flow.active = rbc.use_motor_ang
314
315         col = flow.column(align=True)
316         col.prop(rbc, "motor_ang_target_velocity", text="Target Velocity")
317
318         col = flow.column(align=True)
319         col.prop(rbc, "motor_ang_max_impulse", text="Max Impulse")
320
321
322 class PHYSICS_PT_rigid_body_constraint_motor_linear(PHYSICS_PT_rigidbody_constraint_panel, Panel):
323     bl_label = "Linear"
324     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_motor'
325     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
326
327     @classmethod
328     def poll(cls, context):
329         ob = context.object
330         rbc = ob.rigid_body_constraint
331
332         return (ob and rbc and rbc.type == 'MOTOR'
333                 and context.engine in cls.COMPAT_ENGINES)
334
335     def draw_header(self, context):
336         ob = context.object
337         rbc = ob.rigid_body_constraint
338
339         self.layout.row().prop(rbc, "use_motor_lin", text="")
340
341     def draw(self, context):
342         layout = self.layout
343         layout.use_property_split = True
344         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
345
346         ob = context.object
347         rbc = ob.rigid_body_constraint
348
349         flow.active = rbc.use_motor_lin
350
351         col = flow.column(align=True)
352         col.prop(rbc, "motor_lin_target_velocity", text="Target Velocity")
353
354         col = flow.column(align=True)
355         col.prop(rbc, "motor_lin_max_impulse", text="Max Impulse")
356
357
358 class PHYSICS_PT_rigid_body_constraint_springs(PHYSICS_PT_rigidbody_constraint_panel, Panel):
359     bl_label = "Springs"
360     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint'
361     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
362
363     @classmethod
364     def poll(cls, context):
365         ob = context.object
366         rbc = ob.rigid_body_constraint
367
368         return (ob and ob.rigid_body_constraint
369                 and rbc.type in {'GENERIC_SPRING'}
370                 and context.engine in cls.COMPAT_ENGINES)
371
372     def draw(self, context):
373         layout = self.layout
374         layout.use_property_split = True
375
376         ob = context.object
377         rbc = ob.rigid_body_constraint
378
379         layout.prop(rbc, "spring_type", text="Type")
380
381
382 class PHYSICS_PT_rigid_body_constraint_springs_angular(PHYSICS_PT_rigidbody_constraint_panel, Panel):
383     bl_label = "Angular"
384     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_springs'
385     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
386
387     @classmethod
388     def poll(cls, context):
389         ob = context.object
390         rbc = ob.rigid_body_constraint
391
392         return (ob and ob.rigid_body_constraint
393                 and rbc.type in {'GENERIC_SPRING'}
394                 and context.engine in cls.COMPAT_ENGINES)
395
396     def draw(self, context):
397         layout = self.layout
398         layout.use_property_split = True
399
400         ob = context.object
401         rbc = ob.rigid_body_constraint
402
403         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
404
405         col = flow.column()
406         col.prop(rbc, "use_spring_ang_x", text="X Angle")
407
408         sub = col.column(align=True)
409         sub.active = rbc.use_spring_ang_x
410         sub.prop(rbc, "spring_stiffness_ang_x", text="X Stiffness")
411         sub.prop(rbc, "spring_damping_ang_x", text="Damping")
412
413         col = flow.column()
414         col.prop(rbc, "use_spring_ang_y", text="Y Angle")
415
416         sub = col.column(align=True)
417         sub.active = rbc.use_spring_ang_y
418         sub.prop(rbc, "spring_stiffness_ang_y", text="Y Stiffness")
419         sub.prop(rbc, "spring_damping_ang_y", text="Damping")
420
421         col = flow.column()
422         col.prop(rbc, "use_spring_ang_z", text="Z Angle")
423
424         sub = col.column(align=True)
425         sub.active = rbc.use_spring_ang_z
426         sub.prop(rbc, "spring_stiffness_ang_z", text="Z Stiffness")
427         sub.prop(rbc, "spring_damping_ang_z", text="Damping")
428
429
430 class PHYSICS_PT_rigid_body_constraint_springs_linear(PHYSICS_PT_rigidbody_constraint_panel, Panel):
431     bl_label = "Linear"
432     bl_parent_id = 'PHYSICS_PT_rigid_body_constraint_springs'
433     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
434
435     @classmethod
436     def poll(cls, context):
437         ob = context.object
438         rbc = ob.rigid_body_constraint
439
440         return (ob and ob.rigid_body_constraint
441                 and rbc.type in {'GENERIC_SPRING'}
442                 and context.engine in cls.COMPAT_ENGINES)
443
444     def draw(self, context):
445         layout = self.layout
446         layout.use_property_split = True
447
448         ob = context.object
449         rbc = ob.rigid_body_constraint
450
451         flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)
452
453         col = flow.column()
454         col.prop(rbc, "use_spring_x", text="X Axis")
455
456         sub = col.column(align=True)
457         sub.active = rbc.use_spring_x
458         sub.prop(rbc, "spring_stiffness_x", text="X Stiffness")
459         sub.prop(rbc, "spring_damping_x", text="Damping")
460
461         col = flow.column()
462         col.prop(rbc, "use_spring_y", text="Y Axis")
463
464         sub = col.column(align=True)
465         sub.active = rbc.use_spring_y
466         sub.prop(rbc, "spring_stiffness_y", text="Stiffness")
467         sub.prop(rbc, "spring_damping_y", text="Damping")
468
469         col = flow.column()
470         col.prop(rbc, "use_spring_z", text="Z Axis")
471
472         sub = col.column(align=True)
473         sub.active = rbc.use_spring_z
474         sub.prop(rbc, "spring_stiffness_z", text="Stiffness")
475         sub.prop(rbc, "spring_damping_z", text="Damping")
476
477
478 classes = (
479     PHYSICS_PT_rigid_body_constraint,
480     PHYSICS_PT_rigid_body_constraint_settings,
481     PHYSICS_PT_rigid_body_constraint_limits,
482     PHYSICS_PT_rigid_body_constraint_limits_angular,
483     PHYSICS_PT_rigid_body_constraint_limits_linear,
484     PHYSICS_PT_rigid_body_constraint_motor,
485     PHYSICS_PT_rigid_body_constraint_motor_angular,
486     PHYSICS_PT_rigid_body_constraint_motor_linear,
487     PHYSICS_PT_rigid_body_constraint_objects,
488     PHYSICS_PT_rigid_body_constraint_override_iterations,
489     PHYSICS_PT_rigid_body_constraint_springs,
490     PHYSICS_PT_rigid_body_constraint_springs_angular,
491     PHYSICS_PT_rigid_body_constraint_springs_linear,
492 )
493
494
495 if __name__ == "__main__":  # only for live edit.
496     from bpy.utils import register_class
497     for cls in classes:
498         register_class(cls)