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