Rigidbody: Allow triangle mesh shapes to deform during simulation
[blender.git] / release / scripts / startup / bl_ui / properties_physics_rigidbody.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_panel():
25     bl_space_type = 'PROPERTIES'
26     bl_region_type = 'WINDOW'
27     bl_context = "physics"
28
29
30 class PHYSICS_PT_rigid_body(PHYSICS_PT_rigidbody_panel, Panel):
31     bl_label = "Rigid Body"
32
33     @classmethod
34     def poll(cls, context):
35         obj = context.object
36         return (obj and obj.rigid_body and
37                 (not context.scene.render.use_game_engine))
38
39     def draw(self, context):
40         layout = self.layout
41
42         ob = context.object
43         rbo = ob.rigid_body
44
45         if rbo is not None:
46             layout.prop(rbo, "type", text="Type")
47             row = layout.row()
48             if rbo.type == 'ACTIVE':
49                 row.prop(rbo, "enabled", text="Dynamic")
50             row.prop(rbo, "kinematic", text="Animated")
51
52             if rbo.type == 'ACTIVE':
53                 layout.prop(rbo, "mass")
54
55
56 class PHYSICS_PT_rigid_body_collisions(PHYSICS_PT_rigidbody_panel, Panel):
57     bl_label = "Rigid Body Collisions"
58
59     @classmethod
60     def poll(cls, context):
61         obj = context.object
62         return (obj and obj.rigid_body and
63                 (not context.scene.render.use_game_engine))
64
65     def draw(self, context):
66         layout = self.layout
67
68         ob = context.object
69         rbo = ob.rigid_body
70
71         layout.prop(rbo, "collision_shape", text="Shape")
72
73         if rbo.collision_shape in {'MESH', 'CONVEX_HULL'}:
74             layout.prop(rbo, "mesh_source", text="Source")
75
76         if rbo.collision_shape == 'MESH' and rbo.mesh_source == 'DEFORM':
77             layout.prop(rbo, "use_deform", text="Deforming")
78
79         split = layout.split()
80
81         col = split.column()
82         col.label(text="Surface Response:")
83         col.prop(rbo, "friction")
84         col.prop(rbo, "restitution", text="Bounciness")
85
86         col = split.column()
87         col.label(text="Sensitivity:")
88         if rbo.collision_shape in {'MESH', 'CONE'}:
89             col.prop(rbo, "collision_margin", text="Margin")
90         else:
91             col.prop(rbo, "use_margin")
92             sub = col.column()
93             sub.active = rbo.use_margin
94             sub.prop(rbo, "collision_margin", text="Margin")
95
96         layout.prop(rbo, "collision_groups")
97
98
99 class PHYSICS_PT_rigid_body_dynamics(PHYSICS_PT_rigidbody_panel, Panel):
100     bl_label = "Rigid Body Dynamics"
101     bl_default_closed = True
102
103     @classmethod
104     def poll(cls, context):
105         obj = context.object
106         return (obj and obj.rigid_body and
107                 obj.rigid_body.type == 'ACTIVE' and
108                 (not context.scene.render.use_game_engine))
109
110     def draw(self, context):
111         layout = self.layout
112
113         ob = context.object
114         rbo = ob.rigid_body
115
116         #col = layout.column(align=1)
117         #col.label(text="Activation:")
118         # XXX: settings such as activate on collison/etc.
119
120         split = layout.split()
121
122         col = split.column()
123         col.label(text="Deactivation:")
124         col.prop(rbo, "use_deactivation")
125         sub = col.column()
126         sub.active = rbo.use_deactivation
127         sub.prop(rbo, "use_start_deactivated")
128         sub.prop(rbo, "deactivate_linear_velocity", text="Linear Vel")
129         sub.prop(rbo, "deactivate_angular_velocity", text="Angular Vel")
130         # TODO: other params such as time?
131
132         col = split.column()
133         col.label(text="Damping:")
134         col.prop(rbo, "linear_damping", text="Translation")
135         col.prop(rbo, "angular_damping", text="Rotation")
136
137 if __name__ == "__main__":  # only for live edit.
138     bpy.utils.register_module(__name__)