New point cache file format:
[blender.git] / release / ui / buttons_physics_softbody.py
1
2 import bpy
3
4 class PhysicButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "physics"
8
9         def poll(self, context):
10                 ob = context.object
11                 rd = context.scene.render_data
12                 return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
13                 
14 class PHYSICS_PT_softbody(PhysicButtonsPanel):
15         __label__ = "Soft Body"
16
17         def draw(self, context):
18                 layout = self.layout
19                 
20                 md = context.soft_body
21                 ob = context.object
22
23                 split = layout.split()
24                 split.operator_context = "EXEC_DEFAULT"
25
26                 if md:
27                         # remove modifier + settings
28                         split.set_context_pointer("modifier", md)
29                         split.itemO("object.modifier_remove", text="Remove")
30
31                         row = split.row(align=True)
32                         row.itemR(md, "render", text="")
33                         row.itemR(md, "realtime", text="")
34                 else:
35                         # add modifier
36                         split.item_enumO("object.modifier_add", "type", 'SOFT_BODY', text="Add")
37                         split.itemL("")
38                         
39                 if md:
40                         softbody = md.settings
41
42                         # General
43                         split = layout.split()
44                         
45                         col = split.column()
46                         col.itemL(text="Object:")
47                         col.itemR(softbody, "mass")
48                         col.itemR(softbody, "friction")
49
50                         col = split.column()
51                         col.itemL(text="Simulation:")
52                         col.itemR(softbody, "gravity")
53                         col.itemR(softbody, "speed")
54                         
55 class PHYSICS_PT_softbody_cache(PhysicButtonsPanel):
56         __label__ = "Soft Body Cache"
57         __default_closed__ = True
58
59         def poll(self, context):
60                 return (context.soft_body)
61
62         def draw(self, context):
63                 layout = self.layout
64
65                 cache = context.soft_body.point_cache
66                 layout.set_context_pointer("PointCache", cache)
67                 
68                 row = layout.row()
69                 row.template_list(cache, "point_cache_list", cache, "active_point_cache_index")
70                 col = row.column(align=True)
71                 col.itemO("ptcache.add_new", icon="ICON_ZOOMIN", text="")
72                 col.itemO("ptcache.remove", icon="ICON_ZOOMOUT", text="")
73                 
74                 row = layout.row()
75                 row.itemR(cache, "name")
76                 
77                 row = layout.row()
78                 row.itemR(cache, "start_frame")
79                 row.itemR(cache, "end_frame")
80                 
81                 row = layout.row()
82                 
83                 if cache.baked == True:
84                         row.itemO("ptcache.free_bake", text="Free Bake")
85                 else:
86                         row.item_booleanO("ptcache.bake", "bake", True, text="Bake")
87                 
88                 sub = row.row()
89                 sub.enabled = cache.frames_skipped or cache.outdated
90                 sub.itemO("ptcache.bake", "bake", False, text="Calculate to Current Frame")
91                         
92                 row = layout.row()
93                 row.itemO("ptcache.bake_from_cache", text="Current Cache to Bake")
94                 row.itemR(cache, "step");
95         
96                 row = layout.row()
97                 row.itemR(cache, "quick_cache")
98                 row.itemR(cache, "disk_cache")
99                 
100                 layout.itemL(text=cache.info)
101                 
102                 layout.itemS()
103                 
104                 row = layout.row()
105                 row.itemO("ptcache.bake_all", "bake", True, text="Bake All Dynamics")
106                 row.itemO("ptcache.free_bake_all", text="Free All Bakes")
107                 layout.itemO("ptcache.bake_all", "bake", False, text="Update All Dynamics to current frame")
108                 
109 class PHYSICS_PT_softbody_goal(PhysicButtonsPanel):
110         __label__ = "Soft Body Goal"
111         
112         def poll(self, context):
113                 return (context.soft_body)
114                 
115         def draw_header(self, context):
116                 layout = self.layout
117                 
118                 softbody = context.soft_body.settings
119         
120                 layout.itemR(softbody, "use_goal", text="")
121                 
122         def draw(self, context):
123                 layout = self.layout
124                 
125                 md = context.soft_body
126                 ob = context.object
127
128                 split = layout.split()
129                         
130                 if md:
131                         softbody = md.settings
132                         layout.active = softbody.use_goal
133
134                         # Goal 
135                         split = layout.split()
136
137                         col = split.column()
138                         col.itemL(text="Goal Strengths:")
139                         col.itemR(softbody, "goal_default", text="Default")
140                         sub = col.column(align=True)
141                         sub.itemR(softbody, "goal_min", text="Minimum")
142                         sub.itemR(softbody, "goal_max", text="Maximum")
143                         
144                         col = split.column()
145                         col.itemL(text="Goal Settings:")
146                         col.itemR(softbody, "goal_spring", text="Stiffness")
147                         col.itemR(softbody, "goal_friction", text="Damping")
148                         
149                         layout.item_pointerR(softbody, "goal_vertex_group", ob, "vertex_groups", text="Vertex Group")
150
151 class PHYSICS_PT_softbody_edge(PhysicButtonsPanel):
152         __label__ = "Soft Body Edges"
153         
154         def poll(self, context):
155                 return (context.soft_body)
156                 
157         def draw_header(self, context):
158                 layout = self.layout
159                 
160                 softbody = context.soft_body.settings
161         
162                 layout.itemR(softbody, "use_edges", text="")
163                 
164         def draw(self, context):
165                 layout = self.layout
166                 
167                 md = context.soft_body
168                 ob = context.object
169                         
170                 if md:
171                         softbody = md.settings
172                         
173                         layout.active = softbody.use_edges
174                         
175                         split = layout.split()
176                         
177                         col = split.column()
178                         col.itemL(text="Springs:")
179                         col.itemR(softbody, "pull")
180                         col.itemR(softbody, "push")
181                         col.itemR(softbody, "damp")
182                         col.itemR(softbody, "plastic")
183                         col.itemR(softbody, "bending")
184                         col.itemR(softbody, "spring_length", text="Length")
185                         
186                         col = split.column()
187                         col.itemR(softbody, "stiff_quads")
188                         sub = col.column()
189                         sub.active = softbody.stiff_quads
190                         sub.itemR(softbody, "shear")
191                         
192                         col.itemR(softbody, "new_aero", text="Aero")
193                         sub = col.column()
194                         sub.enabled = softbody.new_aero
195                         sub.itemR(softbody, "aero", text="Factor")
196
197                         col.itemL(text="Collision:")
198                         col.itemR(softbody, "edge_collision", text="Edge")
199                         col.itemR(softbody, "face_collision", text="Face")
200                         
201 class PHYSICS_PT_softbody_collision(PhysicButtonsPanel):
202         __label__ = "Soft Body Collision"
203         
204         def poll(self, context):
205                 return (context.soft_body)
206                 
207         def draw_header(self, context):
208                 layout = self.layout
209                 
210                 softbody = context.soft_body.settings
211         
212                 layout.itemR(softbody, "self_collision", text="")
213                 
214         def draw(self, context):
215                 layout = self.layout
216                 
217                 md = context.soft_body
218                 ob = context.object
219                         
220                 if md:
221                         softbody = md.settings
222
223                         layout.active = softbody.self_collision
224                         
225                         layout.itemL(text="Collision Type:")
226                         layout.itemR(softbody, "collision_type", expand=True)
227                         
228                         col = layout.column(align=True)
229                         col.itemL(text="Ball:")
230                         col.itemR(softbody, "ball_size", text="Size")
231                         col.itemR(softbody, "ball_stiff", text="Stiffness")
232                         col.itemR(softbody, "ball_damp", text="Dampening")
233
234 class PHYSICS_PT_softbody_solver(PhysicButtonsPanel):
235         __label__ = "Soft Body Solver"
236         
237         def poll(self, context):
238                 return (context.soft_body)
239                 
240         def draw(self, context):
241                 layout = self.layout
242                 
243                 md = context.soft_body
244                 ob = context.object
245                 
246                 if md:
247                         softbody = md.settings
248
249                         # Solver
250                         split = layout.split()
251                         
252                         col = split.column(align=True)
253                         col.itemL(text="Step Size:")
254                         col.itemR(softbody, "minstep")
255                         col.itemR(softbody, "maxstep")
256                         col.itemR(softbody, "auto_step", text="Auto-Step")
257                         
258                         col = split.column()
259                         col.itemR(softbody, "error_limit")
260                         col.itemL(text="Helpers:")
261                         col.itemR(softbody, "choke")
262                         col.itemR(softbody, "fuzzy")
263                         
264                         layout.itemL(text="Diagnostics:")
265                         layout.itemR(softbody, "diagnose")
266         
267 bpy.types.register(PHYSICS_PT_softbody)
268 bpy.types.register(PHYSICS_PT_softbody_cache)
269 bpy.types.register(PHYSICS_PT_softbody_goal)
270 bpy.types.register(PHYSICS_PT_softbody_edge)
271 bpy.types.register(PHYSICS_PT_softbody_collision)
272 bpy.types.register(PHYSICS_PT_softbody_solver)