Welcome to mirror list, hosted at ThFree Co, Russian Federation.

properties_physics_fluid.py « bl_ui « startup « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8817d35b88af437f4ca81c9be3ab71c48b3cc2db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

import bpy
from bpy.types import (
    Panel,
)
from bpy.app.translations import pgettext_iface as iface_
from bl_ui.utils import PresetPanel


class FLUID_PT_presets(PresetPanel, Panel):
    bl_label = "Fluid Presets"
    preset_subdir = "fluid"
    preset_operator = "script.execute_preset"
    preset_add_operator = "fluid.preset_add"


class PhysicButtonsPanel:
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "physics"

    @staticmethod
    def poll_fluid(context):
        ob = context.object
        if not ((ob and ob.type == 'MESH') and (context.fluid)):
            return False

        return (bpy.app.build_options.mod_fluid)

    @staticmethod
    def poll_fluid_settings(context):
        if not (PhysicButtonsPanel.poll_fluid(context)):
            return False

        md = context.fluid
        return md and md.settings and (md.settings.type != 'NONE')

    @staticmethod
    def poll_fluid_domain(context):
        if not PhysicButtonsPanel.poll_fluid(context):
            return False

        md = context.fluid
        return md and md.settings and (md.settings.type == 'DOMAIN')


class PHYSICS_PT_fluid(PhysicButtonsPanel, Panel):
    bl_label = "Fluid"
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

    @classmethod
    def poll(cls, context):
        ob = context.object
        return (ob and ob.type == 'MESH') and context.engine in cls.COMPAT_ENGINES and (context.fluid)

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True

        if not bpy.app.build_options.mod_fluid:
            col = layout.column()
            col.alignment = 'RIGHT'
            col.label(text="Built without fluids")
            return

        md = context.fluid
        fluid = md.settings

        col = layout.column()
        col.prop(fluid, "type")


class PHYSICS_PT_fluid_flow(PhysicButtonsPanel, Panel):
    bl_label = "Flow"
    bl_parent_id = "PHYSICS_PT_fluid"
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

    @classmethod
    def poll(cls, context):
        md = context.fluid
        fluid = md.settings

        if not PhysicButtonsPanel.poll_fluid_settings(context):
            return False
        return fluid.type in {'INFLOW', 'OUTFLOW', 'CONTROL'} and (context.engine in cls.COMPAT_ENGINES)

    def draw_header(self, context):
        md = context.fluid
        fluid = md.settings

        self.layout.prop(fluid, "use", text="")

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True

        md = context.fluid
        fluid = md.settings

        flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)

        flow.active = fluid.use

        if fluid.type == 'INFLOW':
            col = flow.column()
            col.prop(fluid, "volume_initialization", text="Volume Initialization")
            col.prop(fluid, "use_animated_mesh")

            row = col.row()
            row.active = not fluid.use_animated_mesh
            row.prop(fluid, "use_local_coords")

            col = flow.column()
            col.prop(fluid, "inflow_velocity", text="Inflow Velocity")

        elif fluid.type == 'OUTFLOW':
            col = flow.column()
            col.prop(fluid, "volume_initialization", text="Volume Initialization")

            col = flow.column()
            col.prop(fluid, "use_animated_mesh")

        elif fluid.type == 'CONTROL':
            col = flow.column()
            col.prop(fluid, "quality", slider=True)
            col.prop(fluid, "use_reverse_frames")

            col = flow.column()
            col.prop(fluid, "start_time", text="Time Start")
            col.prop(fluid, "end_time", text="End")

            col.separator()

            col = flow.column()
            col.prop(fluid, "attraction_strength", text="Attraction Strength")
            col.prop(fluid, "attraction_radius", text="Radius")

            col.separator()

            col = flow.column(align=True)
            col.prop(fluid, "velocity_strength", text="Velocity Strength")
            col.prop(fluid, "velocity_radius", text="Radius")


class PHYSICS_PT_fluid_settings(PhysicButtonsPanel, Panel):
    bl_label = "Settings"
    bl_parent_id = "PHYSICS_PT_fluid"
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

    @classmethod
    def poll(cls, context):
        md = context.fluid
        fluid = md.settings

        if not PhysicButtonsPanel.poll_fluid_settings(context):
            return False
        return fluid.type in {'DOMAIN', 'FLUID', 'OBSTACLE', 'PARTICLE'} and (context.engine in cls.COMPAT_ENGINES)

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True

        md = context.fluid
        fluid = md.settings

        flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)

        if fluid.type not in {'NONE', 'DOMAIN', 'PARTICLE', 'FLUID', 'OBSTACLE'}:
            flow.active = fluid.use

        if fluid.type == 'DOMAIN':
            col = flow.column()

            if bpy.app.build_options.openmp:
                col.prop(fluid, "threads", text="Simulation Threads")
                col.separator()

            col.prop(fluid, "resolution", text="Final Resolution")
            col.prop(fluid, "preview_resolution", text="Preview")

            col.separator()

            col = flow.column()
            col.prop(fluid, "render_display_mode", text="Render Display")
            col.prop(fluid, "viewport_display_mode", text="Viewport")

            col.separator()

            col = flow.column()
            sub = col.column(align=True)
            sub.prop(fluid, "start_time", text="Time Start")
            sub.prop(fluid, "end_time", text="End")
            col.prop(fluid, "simulation_rate", text="Speed")

            col = flow.column()
            col.prop(fluid, "use_speed_vectors")
            col.prop(fluid, "use_reverse_frames")
            col.prop(fluid, "frame_offset", text="Offset")

        elif fluid.type == 'FLUID':
            col = flow.column()
            col.prop(fluid, "volume_initialization", text="Volume Initialization")
            col.prop(fluid, "use_animated_mesh")

            col = flow.column()
            col.prop(fluid, "initial_velocity", text="Initial Velocity")

        elif fluid.type == 'OBSTACLE':
            col = flow.column()
            col.prop(fluid, "volume_initialization", text="Volume Initialization")
            col.prop(fluid, "use_animated_mesh")

            col = flow.column()
            subcol = col.column()
            subcol.enabled = not fluid.use_animated_mesh
            subcol.prop(fluid, "slip_type", text="Slip Type")

            if fluid.slip_type == 'PARTIALSLIP':
                subcol.prop(fluid, "partial_slip_factor", text="Amount", slider=True)

            col.prop(fluid, "impact_factor", text="Impact Factor")

        elif fluid.type == 'PARTICLE':
            col = flow.column()
            col.prop(fluid, "particle_influence", text="Influence Size")
            col.prop(fluid, "alpha_influence", text="Alpha")

            col = flow.column()
            col.prop(fluid, "use_drops")
            col.prop(fluid, "use_floats")
            col.prop(fluid, "show_tracer")


class PHYSICS_PT_fluid_particle_cache(PhysicButtonsPanel, Panel):
    bl_label = "Cache"
    bl_parent_id = "PHYSICS_PT_fluid"
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

    @classmethod
    def poll(cls, context):
        if not PhysicButtonsPanel.poll_fluid_settings(context):
            return False

        md = context.fluid
        return md and md.settings and (md.settings.type == 'PARTICLE') and (context.engine in cls.COMPAT_ENGINES)

    def draw(self, context):
        layout = self.layout

        md = context.fluid
        fluid = md.settings

        layout.prop(fluid, "filepath", text="")


class PHYSICS_PT_domain_bake(PhysicButtonsPanel, Panel):
    bl_label = "Bake"
    bl_parent_id = 'PHYSICS_PT_fluid'
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

    @classmethod
    def poll(cls, context):
        if not PhysicButtonsPanel.poll_fluid_domain(context):
            return False

        return (context.engine in cls.COMPAT_ENGINES)

    def draw(self, context):
        layout = self.layout

        md = context.fluid
        fluid = md.settings

        row = layout.row(align=True)
        row.alignment = 'RIGHT'
        row.label(text="Cache Path")

        layout.prop(fluid, "filepath", text="")

        # odd formatting here so translation script can extract string
        layout.operator(
            "fluid.bake", text=iface_("Bake (Req. Memory: %s)") % fluid.memory_estimate,
            translate=False, icon='MOD_FLUIDSIM'
        )


class PHYSICS_PT_domain_gravity(PhysicButtonsPanel, Panel):
    bl_label = "World"
    bl_parent_id = 'PHYSICS_PT_fluid'
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

    @classmethod
    def poll(cls, context):
        if not PhysicButtonsPanel.poll_fluid_domain(context):
            return False

        return (context.engine in cls.COMPAT_ENGINES)

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True

        fluid = context.fluid.settings
        scene = context.scene

        col = layout.column()

        use_gravity = scene.use_gravity
        use_units = scene.unit_settings.system != 'NONE'

        if use_gravity or use_units:
            s_gravity = " Gravity" if use_gravity else ""
            s_units = " Units" if use_units else ""
            s_and = " and " if use_gravity and use_units else ""
            warn = f"Using {s_gravity}{s_and}{s_units} from Scene"

            sub = col.column()
            sub.alignment = 'RIGHT'
            sub.label(text=warn)

        flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)

        col = flow.column()
        sub = col.column()
        sub.enabled = not use_gravity
        sub.prop(fluid, "gravity", text="Gravity")

        sub = col.column()
        sub.enabled = not use_units
        sub.prop(fluid, "simulation_scale", text="Scene Size Meters" if use_units else "World Size Meters")

        col.separator()

        col = flow.column()
        col.prop(fluid, "grid_levels", text="Optimization", slider=True)
        col.prop(fluid, "compressibility", slider=True)


class PHYSICS_PT_domain_viscosity(PhysicButtonsPanel, Panel):
    bl_label = "Viscosity"
    bl_parent_id = 'PHYSICS_PT_fluid'
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

    @classmethod
    def poll(cls, context):
        if not PhysicButtonsPanel.poll_fluid_domain(context):
            return False

        return (context.engine in cls.COMPAT_ENGINES)

    def draw_header_preset(self, _context):
        FLUID_PT_presets.draw_panel_header(self.layout)

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True
        flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)

        fluid = context.fluid.settings

        col = flow.column()
        col.prop(fluid, "viscosity_base", text="Base")

        col = flow.column()
        col.prop(fluid, "viscosity_exponent", text="Exponent", slider=True)


class PHYSICS_PT_domain_boundary(PhysicButtonsPanel, Panel):
    bl_label = "Boundary"
    bl_parent_id = 'PHYSICS_PT_fluid'
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

    @classmethod
    def poll(cls, context):
        if not PhysicButtonsPanel.poll_fluid_domain(context):
            return False

        return (context.engine in cls.COMPAT_ENGINES)

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True
        flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)

        fluid = context.fluid.settings

        col = flow.column()
        col.prop(fluid, "slip_type", text="Type")

        col.separator()

        if fluid.slip_type == 'PARTIALSLIP':
            col.prop(fluid, "partial_slip_factor", slider=True, text="Amount")

        col = flow.column()
        col.prop(fluid, "surface_smooth", text="Surface Smoothing")
        col.prop(fluid, "surface_subdivisions", text="Subdivisions")
        col.prop(fluid, "use_surface_noobs")


class PHYSICS_PT_domain_particles(PhysicButtonsPanel, Panel):
    bl_label = "Particles"
    bl_parent_id = 'PHYSICS_PT_fluid'
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

    @classmethod
    def poll(cls, context):
        if not PhysicButtonsPanel.poll_fluid_domain(context):
            return False

        return (context.engine in cls.COMPAT_ENGINES)

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True
        flow = layout.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=True)

        fluid = context.fluid.settings

        col = flow.column()
        col.prop(fluid, "tracer_particles", text="Tracer")

        col = flow.column()
        col.prop(fluid, "generate_particles", text="Generate")


classes = (
    FLUID_PT_presets,
    PHYSICS_PT_fluid,
    PHYSICS_PT_fluid_settings,
    PHYSICS_PT_fluid_flow,
    PHYSICS_PT_fluid_particle_cache,
    PHYSICS_PT_domain_bake,
    PHYSICS_PT_domain_boundary,
    PHYSICS_PT_domain_particles,
    PHYSICS_PT_domain_gravity,
    PHYSICS_PT_domain_viscosity,
)

if __name__ == "__main__":  # only for live edit.
    from bpy.utils import register_class
    for cls in classes:
        register_class(cls)