Fix T55958: allow the user to select between spring and spring2.
[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 import bpy
21 from bpy.types import Panel
22
23
24 class PHYSICS_PT_rigidbody_constraint_panel:
25     bl_space_type = 'PROPERTIES'
26     bl_region_type = 'WINDOW'
27     bl_context = "physics"
28
29
30 class PHYSICS_PT_rigid_body_constraint(PHYSICS_PT_rigidbody_constraint_panel, Panel):
31     bl_label = "Rigid Body Constraint"
32     COMPAT_ENGINES = {'BLENDER_RENDER'}
33
34     @classmethod
35     def poll(cls, context):
36         ob = context.object
37         rd = context.scene.render
38         return (ob and ob.rigid_body_constraint and rd.engine in cls.COMPAT_ENGINES)
39
40     def draw(self, context):
41         layout = self.layout
42
43         ob = context.object
44         rbc = ob.rigid_body_constraint
45
46         layout.prop(rbc, "type")
47
48         row = layout.row()
49         row.prop(rbc, "enabled")
50         row.prop(rbc, "disable_collisions")
51
52         layout.prop(rbc, "object1")
53         layout.prop(rbc, "object2")
54
55         if rbc.type != 'MOTOR':
56             row = layout.row()
57             row.prop(rbc, "use_breaking")
58             sub = row.row()
59             sub.active = rbc.use_breaking
60             sub.prop(rbc, "breaking_threshold", text="Threshold")
61
62         row = layout.row()
63         row.prop(rbc, "use_override_solver_iterations", text="Override Iterations")
64         sub = row.row()
65         sub.active = rbc.use_override_solver_iterations
66         sub.prop(rbc, "solver_iterations", text="Iterations")
67
68         if rbc.type == 'HINGE':
69             col = layout.column(align=True)
70             col.label("Limits:")
71
72             row = col.row(align=True)
73             sub = row.row(align=True)
74             sub.scale_x = 0.5
75             sub.prop(rbc, "use_limit_ang_z", toggle=True)
76             sub = row.row(align=True)
77             sub.active = rbc.use_limit_ang_z
78             sub.prop(rbc, "limit_ang_z_lower", text="Lower")
79             sub.prop(rbc, "limit_ang_z_upper", text="Upper")
80
81         elif rbc.type == 'SLIDER':
82             col = layout.column(align=True)
83             col.label("Limits:")
84
85             row = col.row(align=True)
86             sub = row.row(align=True)
87             sub.scale_x = 0.5
88             sub.prop(rbc, "use_limit_lin_x", toggle=True)
89             sub = row.row(align=True)
90             sub.active = rbc.use_limit_lin_x
91             sub.prop(rbc, "limit_lin_x_lower", text="Lower")
92             sub.prop(rbc, "limit_lin_x_upper", text="Upper")
93
94         elif rbc.type == 'PISTON':
95             col = layout.column(align=True)
96             col.label("Limits:")
97
98             row = col.row(align=True)
99             sub = row.row(align=True)
100             sub.scale_x = 0.5
101             sub.prop(rbc, "use_limit_lin_x", toggle=True)
102             sub = row.row(align=True)
103             sub.active = rbc.use_limit_lin_x
104             sub.prop(rbc, "limit_lin_x_lower", text="Lower")
105             sub.prop(rbc, "limit_lin_x_upper", text="Upper")
106
107             col = layout.column(align=True)
108
109             row = col.row(align=True)
110             sub = row.row(align=True)
111             sub.scale_x = 0.5
112             sub.prop(rbc, "use_limit_ang_x", toggle=True)
113             sub = row.row(align=True)
114             sub.active = rbc.use_limit_ang_x
115             sub.prop(rbc, "limit_ang_x_lower", text="Lower")
116             sub.prop(rbc, "limit_ang_x_upper", text="Upper")
117
118         elif rbc.type == 'MOTOR':
119             col = layout.column(align=True)
120             col.label("Linear motor:")
121
122             row = col.row(align=True)
123             sub = row.row(align=True)
124             sub.scale_x = 0.5
125             sub.prop(rbc, "use_motor_lin", toggle=True, text="Enable")
126             sub = row.row(align=True)
127             sub.active = rbc.use_motor_lin
128             sub.prop(rbc, "motor_lin_target_velocity", text="Target Velocity")
129             sub.prop(rbc, "motor_lin_max_impulse", text="Max Impulse")
130
131             col.label("Angular motor:")
132
133             row = col.row(align=True)
134             sub = row.row(align=True)
135             sub.scale_x = 0.5
136             sub.prop(rbc, "use_motor_ang", toggle=True, text="Enable")
137             sub = row.row(align=True)
138             sub.active = rbc.use_motor_ang
139             sub.prop(rbc, "motor_ang_target_velocity", text="Target Velocity")
140             sub.prop(rbc, "motor_ang_max_impulse", text="Max Impulse")
141
142         elif rbc.type in {'GENERIC', 'GENERIC_SPRING'}:
143             if rbc.type == 'GENERIC_SPRING':
144                 row = layout.row()
145                 row.label("Spring Type:")
146                 row.prop(rbc, "spring_type", text="")
147
148             col = layout.column(align=True)
149             col.label("Limits:")
150
151             row = col.row(align=True)
152             sub = row.row(align=True)
153             sub.scale_x = 0.5
154             sub.prop(rbc, "use_limit_lin_x", toggle=True)
155             sub = row.row(align=True)
156             sub.active = rbc.use_limit_lin_x
157             sub.prop(rbc, "limit_lin_x_lower", text="Lower")
158             sub.prop(rbc, "limit_lin_x_upper", text="Upper")
159
160             row = col.row(align=True)
161             sub = row.row(align=True)
162             sub.scale_x = 0.5
163             sub.prop(rbc, "use_limit_lin_y", toggle=True)
164             sub = row.row(align=True)
165             sub.active = rbc.use_limit_lin_y
166             sub.prop(rbc, "limit_lin_y_lower", text="Lower")
167             sub.prop(rbc, "limit_lin_y_upper", text="Upper")
168
169             row = col.row(align=True)
170             sub = row.row(align=True)
171             sub.scale_x = 0.5
172             sub.prop(rbc, "use_limit_lin_z", toggle=True)
173             sub = row.row(align=True)
174             sub.active = rbc.use_limit_lin_z
175             sub.prop(rbc, "limit_lin_z_lower", text="Lower")
176             sub.prop(rbc, "limit_lin_z_upper", text="Upper")
177
178             col = layout.column(align=True)
179
180             row = col.row(align=True)
181             sub = row.row(align=True)
182             sub.scale_x = 0.5
183             sub.prop(rbc, "use_limit_ang_x", toggle=True)
184             sub = row.row(align=True)
185             sub.active = rbc.use_limit_ang_x
186             sub.prop(rbc, "limit_ang_x_lower", text="Lower")
187             sub.prop(rbc, "limit_ang_x_upper", text="Upper")
188
189             row = col.row(align=True)
190             sub = row.row(align=True)
191             sub.scale_x = 0.5
192             sub.prop(rbc, "use_limit_ang_y", toggle=True)
193             sub = row.row(align=True)
194             sub.active = rbc.use_limit_ang_y
195             sub.prop(rbc, "limit_ang_y_lower", text="Lower")
196             sub.prop(rbc, "limit_ang_y_upper", text="Upper")
197
198             row = col.row(align=True)
199             sub = row.row(align=True)
200             sub.scale_x = 0.5
201             sub.prop(rbc, "use_limit_ang_z", toggle=True)
202             sub = row.row(align=True)
203             sub.active = rbc.use_limit_ang_z
204             sub.prop(rbc, "limit_ang_z_lower", text="Lower")
205             sub.prop(rbc, "limit_ang_z_upper", text="Upper")
206
207             if rbc.type == 'GENERIC_SPRING':
208                 col = layout.column(align=True)
209                 col.label("Springs:")
210
211                 row = col.row(align=True)
212                 sub = row.row(align=True)
213                 sub.scale_x = 0.5
214                 sub.prop(rbc, "use_spring_x", toggle=True, text="X Axis")
215                 sub = row.row(align=True)
216                 sub.active = rbc.use_spring_x
217                 sub.prop(rbc, "spring_stiffness_x", text="Stiffness")
218                 sub.prop(rbc, "spring_damping_x", text="Damping")
219
220                 row = col.row(align=True)
221                 sub = row.row(align=True)
222                 sub.scale_x = 0.5
223                 sub.prop(rbc, "use_spring_y", toggle=True, text="Y Axis")
224                 sub = row.row(align=True)
225                 sub.active = rbc.use_spring_y
226                 sub.prop(rbc, "spring_stiffness_y", text="Stiffness")
227                 sub.prop(rbc, "spring_damping_y", text="Damping")
228
229                 row = col.row(align=True)
230                 sub = row.row(align=True)
231                 sub.scale_x = 0.5
232                 sub.prop(rbc, "use_spring_z", toggle=True, text="Z Axis")
233                 sub = row.row(align=True)
234                 sub.active = rbc.use_spring_z
235                 sub.prop(rbc, "spring_stiffness_z", text="Stiffness")
236                 sub.prop(rbc, "spring_damping_z", text="Damping")
237
238                 col = layout.column(align=True)
239
240                 row = col.row(align=True)
241                 sub = row.row(align=True)
242                 sub.scale_x = 0.5
243                 sub.prop(rbc, "use_spring_ang_x", toggle=True, text="X Angle")
244                 sub = row.row(align=True)
245                 sub.active = rbc.use_spring_ang_x
246                 sub.prop(rbc, "spring_stiffness_ang_x", text="Stiffness")
247                 sub.prop(rbc, "spring_damping_ang_x", text="Damping")
248
249                 row = col.row(align=True)
250                 sub = row.row(align=True)
251                 sub.scale_x = 0.5
252                 sub.prop(rbc, "use_spring_ang_y", toggle=True, text="Y Angle")
253                 sub = row.row(align=True)
254                 sub.active = rbc.use_spring_ang_y
255                 sub.prop(rbc, "spring_stiffness_ang_y", text="Stiffness")
256                 sub.prop(rbc, "spring_damping_ang_y", text="Damping")
257
258                 row = col.row(align=True)
259                 sub = row.row(align=True)
260                 sub.scale_x = 0.5
261                 sub.prop(rbc, "use_spring_ang_z", toggle=True, text="Z Angle")
262                 sub = row.row(align=True)
263                 sub.active = rbc.use_spring_ang_z
264                 sub.prop(rbc, "spring_stiffness_ang_z", text="Stiffness")
265                 sub.prop(rbc, "spring_damping_ang_z", text="Damping")
266
267
268 classes = (
269     PHYSICS_PT_rigid_body_constraint,
270 )
271
272 if __name__ == "__main__":  # only for live edit.
273     from bpy.utils import register_class
274     for cls in classes:
275         register_class(cls)