32b0a6459b58f7d36ba43498d42da4075483fc82
[blender-staging.git] / release / scripts / ui / properties_physics_softbody.py
1 # This software is distributable under the terms of the GNU
2 # General Public License (GPL) v2, the text of which can be found at
3 # http://www.gnu.org/copyleft/gpl.html. Installing, importing or otherwise
4 # using this module constitutes acceptance of the terms of this License.
5
6
7 import bpy
8
9 from properties_physics_common import point_cache_ui
10 from properties_physics_common import effector_weights_ui
11
12 def softbody_panel_enabled(md):
13     return md.point_cache.baked==False
14
15 class PhysicButtonsPanel(bpy.types.Panel):
16     bl_space_type = 'PROPERTIES'
17     bl_region_type = 'WINDOW'
18     bl_context = "physics"
19
20     def poll(self, context):
21         ob = context.object
22         rd = context.scene.render_data
23         return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
24
25 class PHYSICS_PT_softbody(PhysicButtonsPanel):
26     bl_label = "Soft Body"
27
28     def draw(self, context):
29         layout = self.layout
30
31         md = context.soft_body
32         ob = context.object
33
34         split = layout.split()
35         split.operator_context = "EXEC_DEFAULT"
36
37         if md:
38             # remove modifier + settings
39             split.set_context_pointer("modifier", md)
40             split.itemO("object.modifier_remove", text="Remove")
41
42             row = split.row(align=True)
43             row.itemR(md, "render", text="")
44             row.itemR(md, "realtime", text="")
45         else:
46             # add modifier
47             split.item_enumO("object.modifier_add", "type", 'SOFT_BODY', text="Add")
48             split.itemL("")
49
50         if md:
51             softbody = md.settings
52
53             # General
54             split = layout.split()
55             split.enabled = softbody_panel_enabled(md)
56
57             col = split.column()
58             col.itemL(text="Object:")
59             col.itemR(softbody, "mass")
60             col.itemR(softbody, "friction")
61
62             col = split.column()
63             col.itemL(text="Simulation:")
64             col.itemR(softbody, "speed")
65
66 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel):
67     bl_label = "Soft Body Cache"
68     bl_default_closed = True
69
70     def poll(self, context):
71         return context.soft_body
72
73     def draw(self, context):
74         md = context.soft_body
75         point_cache_ui(self, md.point_cache, softbody_panel_enabled(md), 0, 0)
76
77 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel):
78     bl_label = "Soft Body Goal"
79     bl_default_closed = True
80
81     def poll(self, context):
82         return context.soft_body
83
84     def draw_header(self, context):
85         softbody = context.soft_body.settings
86
87         self.layout.active = softbody_panel_enabled(context.soft_body)
88         self.layout.itemR(softbody, "use_goal", text="")
89
90     def draw(self, context):
91         layout = self.layout
92
93         md = context.soft_body
94         softbody = md.settings
95         ob = context.object
96
97         layout.active = softbody.use_goal and softbody_panel_enabled(md)
98
99         split = layout.split()
100
101         # Goal
102         split = layout.split()
103
104         col = split.column()
105         col.itemL(text="Goal Strengths:")
106         col.itemR(softbody, "goal_default", text="Default")
107         sub = col.column(align=True)
108         sub.itemR(softbody, "goal_min", text="Minimum")
109         sub.itemR(softbody, "goal_max", text="Maximum")
110
111         col = split.column()
112         col.itemL(text="Goal Settings:")
113         col.itemR(softbody, "goal_spring", text="Stiffness")
114         col.itemR(softbody, "goal_friction", text="Damping")
115
116         layout.item_pointerR(softbody, "goal_vertex_group", ob, "vertex_groups", text="Vertex Group")
117
118 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel):
119     bl_label = "Soft Body Edges"
120     bl_default_closed = True
121
122     def poll(self, context):
123         return context.soft_body
124
125     def draw_header(self, context):
126         softbody = context.soft_body.settings
127
128         self.layout.active = softbody_panel_enabled(context.soft_body)
129         self.layout.itemR(softbody, "use_edges", text="")
130
131     def draw(self, context):
132         layout = self.layout
133
134         md = context.soft_body
135         softbody = md.settings
136         ob = context.object
137
138         layout.active = softbody.use_edges and softbody_panel_enabled(md)
139
140         split = layout.split()
141
142         col = split.column()
143         col.itemL(text="Springs:")
144         col.itemR(softbody, "pull")
145         col.itemR(softbody, "push")
146         col.itemR(softbody, "damp")
147         col.itemR(softbody, "plastic")
148         col.itemR(softbody, "bending")
149         col.itemR(softbody, "spring_length", text="Length")
150
151         col = split.column()
152         col.itemR(softbody, "stiff_quads")
153         sub = col.column()
154         sub.active = softbody.stiff_quads
155         sub.itemR(softbody, "shear")
156
157         col.itemR(softbody, "new_aero", text="Aero")
158         sub = col.column()
159         sub.enabled = softbody.new_aero
160         sub.itemR(softbody, "aero", text="Factor")
161
162         col.itemL(text="Collision:")
163         col.itemR(softbody, "edge_collision", text="Edge")
164         col.itemR(softbody, "face_collision", text="Face")
165
166 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel):
167     bl_label = "Soft Body Collision"
168     bl_default_closed = True
169
170     def poll(self, context):
171         return context.soft_body
172
173     def draw_header(self, context):
174         softbody = context.soft_body.settings
175
176         self.layout.active = softbody_panel_enabled(context.soft_body)
177         self.layout.itemR(softbody, "self_collision", text="")
178
179     def draw(self, context):
180         layout = self.layout
181
182         md = context.soft_body
183         softbody = md.settings
184         ob = context.object
185
186         layout.active = softbody.self_collision and softbody_panel_enabled(md)
187
188         layout.itemL(text="Collision Type:")
189         layout.itemR(softbody, "collision_type", expand=True)
190
191         col = layout.column(align=True)
192         col.itemL(text="Ball:")
193         col.itemR(softbody, "ball_size", text="Size")
194         col.itemR(softbody, "ball_stiff", text="Stiffness")
195         col.itemR(softbody, "ball_damp", text="Dampening")
196
197 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel):
198     bl_label = "Soft Body Solver"
199     bl_default_closed = True
200
201     def poll(self, context):
202         return context.soft_body
203
204     def draw(self, context):
205         layout = self.layout
206
207         md = context.soft_body
208         softbody = md.settings
209         ob = context.object
210
211         layout.active = softbody_panel_enabled(md)
212
213         # Solver
214         split = layout.split()
215
216         col = split.column(align=True)
217         col.itemL(text="Step Size:")
218         col.itemR(softbody, "minstep")
219         col.itemR(softbody, "maxstep")
220         col.itemR(softbody, "auto_step", text="Auto-Step")
221
222         col = split.column()
223         col.itemR(softbody, "error_limit")
224         col.itemL(text="Helpers:")
225         col.itemR(softbody, "choke")
226         col.itemR(softbody, "fuzzy")
227
228         layout.itemL(text="Diagnostics:")
229         layout.itemR(softbody, "diagnose")
230
231 class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel):
232     bl_label = "Soft Body Field Weights"
233     bl_default_closed = True
234
235     def poll(self, context):
236         return (context.soft_body)
237
238     def draw(self, context):
239         md = context.soft_body
240         softbody = md.settings
241         effector_weights_ui(self, softbody.effector_weights)
242
243 bpy.types.register(PHYSICS_PT_softbody)
244 bpy.types.register(PHYSICS_PT_softbody_cache)
245 bpy.types.register(PHYSICS_PT_softbody_goal)
246 bpy.types.register(PHYSICS_PT_softbody_edge)
247 bpy.types.register(PHYSICS_PT_softbody_collision)
248 bpy.types.register(PHYSICS_PT_softbody_solver)
249 bpy.types.register(PHYSICS_PT_softbody_field_weights)