Rigidbody: Add option to choose mesh source for collision shapes
[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         split = layout.split()
77
78         col = split.column()
79         col.label(text="Surface Response:")
80         col.prop(rbo, "friction")
81         col.prop(rbo, "restitution", text="Bounciness")
82
83         col = split.column()
84         col.label(text="Sensitivity:")
85         if rbo.collision_shape in {'MESH', 'CONE'}:
86             col.prop(rbo, "collision_margin", text="Margin")
87         else:
88             col.prop(rbo, "use_margin")
89             sub = col.column()
90             sub.active = rbo.use_margin
91             sub.prop(rbo, "collision_margin", text="Margin")
92
93         layout.prop(rbo, "collision_groups")
94
95
96 class PHYSICS_PT_rigid_body_dynamics(PHYSICS_PT_rigidbody_panel, Panel):
97     bl_label = "Rigid Body Dynamics"
98     bl_default_closed = True
99
100     @classmethod
101     def poll(cls, context):
102         obj = context.object
103         return (obj and obj.rigid_body and
104                 obj.rigid_body.type == 'ACTIVE' and
105                 (not context.scene.render.use_game_engine))
106
107     def draw(self, context):
108         layout = self.layout
109
110         ob = context.object
111         rbo = ob.rigid_body
112
113         #col = layout.column(align=1)
114         #col.label(text="Activation:")
115         # XXX: settings such as activate on collison/etc.
116
117         split = layout.split()
118
119         col = split.column()
120         col.label(text="Deactivation:")
121         col.prop(rbo, "use_deactivation")
122         sub = col.column()
123         sub.active = rbo.use_deactivation
124         sub.prop(rbo, "use_start_deactivated")
125         sub.prop(rbo, "deactivate_linear_velocity", text="Linear Vel")
126         sub.prop(rbo, "deactivate_angular_velocity", text="Angular Vel")
127         # TODO: other params such as time?
128
129         col = split.column()
130         col.label(text="Damping:")
131         col.prop(rbo, "linear_damping", text="Translation")
132         col.prop(rbo, "angular_damping", text="Rotation")
133
134 if __name__ == "__main__":  # only for live edit.
135     bpy.utils.register_module(__name__)