Merge from trunk -r 24247:24313, -r 24313:24390.
[blender-staging.git] / release / scripts / ui / properties_physics_fluid.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22
23 class PhysicButtonsPanel(bpy.types.Panel):
24     bl_space_type = 'PROPERTIES'
25     bl_region_type = 'WINDOW'
26     bl_context = "physics"
27
28     def poll(self, context):
29         ob = context.object
30         rd = context.scene.render_data
31         return (ob and ob.type == 'MESH') and (not rd.use_game_engine)
32
33
34 class PHYSICS_PT_fluid(PhysicButtonsPanel):
35     bl_label = "Fluid"
36
37     def draw(self, context):
38         layout = self.layout
39
40         md = context.fluid
41         ob = context.object
42
43         split = layout.split()
44         split.operator_context = 'EXEC_DEFAULT'
45
46         if md:
47             # remove modifier + settings
48             split.set_context_pointer("modifier", md)
49             split.itemO("object.modifier_remove", text="Remove")
50
51             row = split.row(align=True)
52             row.itemR(md, "render", text="")
53             row.itemR(md, "realtime", text="")
54
55             fluid = md.settings
56
57         else:
58             # add modifier
59             split.item_enumO("object.modifier_add", "type", 'FLUID_SIMULATION', text="Add")
60             split.itemL()
61
62             fluid = None
63
64
65         if fluid:
66             layout.itemR(fluid, "type")
67
68             if fluid.type == 'DOMAIN':
69                 layout.itemO("fluid.bake", text="Bake Fluid Simulation", icon='ICON_MOD_FLUIDSIM')
70                 split = layout.split()
71
72                 col = split.column()
73                 col.itemL(text="Resolution:")
74                 col.itemR(fluid, "resolution", text="Final")
75                 col.itemL(text="Render Display:")
76                 col.itemR(fluid, "render_display_mode", text="")
77                 col.itemL(text="Time:")
78                 sub = col.column(align=True)
79                 sub.itemR(fluid, "start_time", text="Start")
80                 sub.itemR(fluid, "end_time", text="End")
81
82                 col = split.column()
83                 col.itemL(text="Required Memory: " + fluid.memory_estimate)
84                 col.itemR(fluid, "preview_resolution", text="Preview")
85                 col.itemL(text="Viewport Display:")
86                 col.itemR(fluid, "viewport_display_mode", text="")
87                 col.itemL()
88                 col.itemR(fluid, "generate_speed_vectors")
89                 col.itemR(fluid, "reverse_frames")
90
91                 layout.itemR(fluid, "path", text="")
92
93             elif fluid.type == 'FLUID':
94                 split = layout.split()
95
96                 col = split.column()
97                 col.itemL(text="Volume Initialization:")
98                 col.itemR(fluid, "volume_initialization", text="")
99                 col.itemR(fluid, "export_animated_mesh")
100
101                 col = split.column()
102                 col.itemL(text="Initial Velocity:")
103                 col.itemR(fluid, "initial_velocity", text="")
104
105             elif fluid.type == 'OBSTACLE':
106                 split = layout.split()
107
108                 col = split.column()
109                 col.itemL(text="Volume Initialization:")
110                 col.itemR(fluid, "volume_initialization", text="")
111                 col.itemR(fluid, "export_animated_mesh")
112
113                 col = split.column()
114                 col.itemL(text="Slip Type:")
115                 col.itemR(fluid, "slip_type", text="")
116                 if fluid.slip_type == 'PARTIALSLIP':
117                     col.itemR(fluid, "partial_slip_factor", slider=True, text="Amount")
118
119                 col.itemL(text="Impact:")
120                 col.itemR(fluid, "impact_factor", text="Factor")
121
122             elif fluid.type == 'INFLOW':
123                 split = layout.split()
124
125                 col = split.column()
126                 col.itemL(text="Volume Initialization:")
127                 col.itemR(fluid, "volume_initialization", text="")
128                 col.itemR(fluid, "export_animated_mesh")
129                 col.itemR(fluid, "local_coordinates")
130
131                 col = split.column()
132                 col.itemL(text="Inflow Velocity:")
133                 col.itemR(fluid, "inflow_velocity", text="")
134
135             elif fluid.type == 'OUTFLOW':
136                 split = layout.split()
137
138                 col = split.column()
139                 col.itemL(text="Volume Initialization:")
140                 col.itemR(fluid, "volume_initialization", text="")
141                 col.itemR(fluid, "export_animated_mesh")
142
143                 split.column()
144
145             elif fluid.type == 'PARTICLE':
146                 split = layout.split(percentage=0.5)
147
148                 col = split.column()
149                 col.itemL(text="Influence:")
150                 col.itemR(fluid, "particle_influence", text="Size")
151                 col.itemR(fluid, "alpha_influence", text="Alpha")
152
153                 col = split.column()
154                 col.itemL(text="Type:")
155                 col.itemR(fluid, "drops")
156                 col.itemR(fluid, "floats")
157                 col = split.column()
158                 col.itemL()
159                 col.itemR(fluid, "tracer")
160
161                 layout.itemR(fluid, "path", text="")
162
163             elif fluid.type == 'CONTROL':
164                 split = layout.split()
165
166                 col = split.column()
167                 col.itemL(text="")
168                 col.itemR(fluid, "quality", slider=True)
169                 col.itemR(fluid, "reverse_frames")
170
171                 col = split.column()
172                 col.itemL(text="Time:")
173                 sub = col.column(align=True)
174                 sub.itemR(fluid, "start_time", text="Start")
175                 sub.itemR(fluid, "end_time", text="End")
176
177                 split = layout.split()
178
179                 col = split.column()
180                 col.itemL(text="Attraction Force:")
181                 sub = col.column(align=True)
182                 sub.itemR(fluid, "attraction_strength", text="Strength")
183                 sub.itemR(fluid, "attraction_radius", text="Radius")
184
185                 col = split.column()
186                 col.itemL(text="Velocity Force:")
187                 sub = col.column(align=True)
188                 sub.itemR(fluid, "velocity_strength", text="Strength")
189                 sub.itemR(fluid, "velocity_radius", text="Radius")
190
191
192 class PHYSICS_PT_domain_gravity(PhysicButtonsPanel):
193     bl_label = "Domain World"
194     bl_default_closed = True
195
196     def poll(self, context):
197         md = context.fluid
198         return md and (md.settings.type == 'DOMAIN')
199
200     def draw(self, context):
201         layout = self.layout
202
203         fluid = context.fluid.settings
204
205         split = layout.split()
206
207         col = split.column()
208         col.itemL(text="Gravity:")
209         col.itemR(fluid, "gravity", text="")
210         col.itemL(text="Real World Size:")
211         col.itemR(fluid, "real_world_size", text="Metres")
212
213         col = split.column()
214         col.itemL(text="Viscosity Presets:")
215         sub = col.column(align=True)
216         sub.itemR(fluid, "viscosity_preset", text="")
217
218         if fluid.viscosity_preset == 'MANUAL':
219             sub.itemR(fluid, "viscosity_base", text="Base")
220             sub.itemR(fluid, "viscosity_exponent", text="Exponent", slider=True)
221         else:
222             sub.itemL()
223             sub.itemL()
224
225         col.itemL(text="Optimization:")
226         sub = col.column(align=True)
227         sub.itemR(fluid, "grid_levels", slider=True)
228         sub.itemR(fluid, "compressibility", slider=True)
229
230
231 class PHYSICS_PT_domain_boundary(PhysicButtonsPanel):
232     bl_label = "Domain Boundary"
233     bl_default_closed = True
234
235     def poll(self, context):
236         md = context.fluid
237         return md and (md.settings.type == 'DOMAIN')
238
239     def draw(self, context):
240         layout = self.layout
241
242         fluid = context.fluid.settings
243
244         split = layout.split()
245
246         col = split.column()
247         col.itemL(text="Slip Type:")
248         sub = col.column(align=True)
249         sub.itemR(fluid, "slip_type", text="")
250         if fluid.slip_type == 'PARTIALSLIP':
251             sub.itemR(fluid, "partial_slip_factor", slider=True, text="Amount")
252
253         col = split.column()
254         col.itemL(text="Surface:")
255         sub = col.column(align=True)
256         sub.itemR(fluid, "surface_smoothing", text="Smoothing")
257         sub.itemR(fluid, "surface_subdivisions", text="Subdivisions")
258
259
260 class PHYSICS_PT_domain_particles(PhysicButtonsPanel):
261     bl_label = "Domain Particles"
262     bl_default_closed = True
263
264     def poll(self, context):
265         md = context.fluid
266         return md and (md.settings.type == 'DOMAIN')
267
268     def draw(self, context):
269         layout = self.layout
270
271         fluid = context.fluid.settings
272
273         col = layout.column(align=True)
274         col.itemR(fluid, "tracer_particles")
275         col.itemR(fluid, "generate_particles")
276
277 bpy.types.register(PHYSICS_PT_fluid)
278 bpy.types.register(PHYSICS_PT_domain_gravity)
279 bpy.types.register(PHYSICS_PT_domain_boundary)
280 bpy.types.register(PHYSICS_PT_domain_particles)