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