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

properties_physics_dynamicpaint.py « bl_ui « startup « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec7287ef363ae83889e4922449a4c8f91849e2b9 (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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# ##### 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, UIList

from bl_ui.properties_physics_common import (
        point_cache_ui,
        effector_weights_ui,
        )


class PHYSICS_UL_dynapaint_surfaces(UIList):
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
        # assert(isinstance(item, bpy.types.DynamicPaintSurface)
        surf = item
        sticon = layout.enum_item_icon(surf, "surface_type", surf.surface_type)
        if self.layout_type in {'DEFAULT', 'COMPACT'}:
            row = layout.row(align=True)
            row.label(text="", icon_value=icon)
            row.prop(surf, "name", text="", emboss=False, icon_value=sticon)
            row = layout.row(align=True)
            if surf.use_color_preview:
                row.prop(surf, "show_preview", text="", emboss=False,
                         icon='RESTRICT_VIEW_OFF' if surf.show_preview else 'RESTRICT_VIEW_ON')
            row.prop(surf, "is_active", text="")
        elif self.layout_type == 'GRID':
            layout.alignment = 'CENTER'
            row = layout.row(align=True)
            row.label(text="", icon_value=icon)
            row.label(text="", icon_value=sticon)


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

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


class PHYSICS_PT_dynamic_paint(PhysicButtonsPanel, Panel):
    bl_label = "Dynamic Paint"
    COMPAT_ENGINES = {'BLENDER_RENDER'}

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

        md = context.dynamic_paint

        layout.row().prop(md, "ui_type", expand=True)

        if md.ui_type == 'CANVAS':
            canvas = md.canvas_settings

            if canvas is None:
                layout.operator("dpaint.type_toggle", text="Add Canvas").type = 'CANVAS'
            else:
                layout.operator("dpaint.type_toggle", text="Remove Canvas", icon='X').type = 'CANVAS'

                surface = canvas.canvas_surfaces.active

                row = layout.row()
                row.template_list("PHYSICS_UL_dynapaint_surfaces", "", canvas, "canvas_surfaces",
                                  canvas.canvas_surfaces, "active_index", rows=1)

                col = row.column(align=True)
                col.operator("dpaint.surface_slot_add", icon='ZOOMIN', text="")
                col.operator("dpaint.surface_slot_remove", icon='ZOOMOUT', text="")

                if surface:
                    layout.prop(surface, "surface_format")

                    col = layout.column()
                    if surface.surface_format != 'VERTEX':
                        col.label(text="Quality:")
                        col.prop(surface, "image_resolution")
                    col.prop(surface, "use_antialiasing")

                    col = layout.column()
                    col.label(text="Frames:")
                    split = col.split()

                    col = split.column(align=True)
                    col.prop(surface, "frame_start", text="Start")
                    col.prop(surface, "frame_end", text="End")

                    split.prop(surface, "frame_substeps")

        elif md.ui_type == 'BRUSH':
            brush = md.brush_settings
            use_shading_nodes = context.scene.render.use_shading_nodes

            if brush is None:
                layout.operator("dpaint.type_toggle", text="Add Brush").type = 'BRUSH'
            else:
                layout.operator("dpaint.type_toggle", text="Remove Brush", icon='X').type = 'BRUSH'

                split = layout.split()

                col = split.column()
                col.prop(brush, "use_absolute_alpha")
                col.prop(brush, "use_paint_erase")
                col.prop(brush, "paint_wetness", text="Wetness")

                col = split.column()
                if not use_shading_nodes:
                    sub = col.column()
                    sub.active = (brush.paint_source != 'PARTICLE_SYSTEM')
                    sub.prop(brush, "use_material")
                if brush.use_material and brush.paint_source != 'PARTICLE_SYSTEM' and not use_shading_nodes:
                    col.prop(brush, "material", text="")
                    col.prop(brush, "paint_alpha", text="Alpha Factor")
                else:
                    col.prop(brush, "paint_color", text="")
                    col.prop(brush, "paint_alpha", text="Alpha")


class PHYSICS_PT_dp_advanced_canvas(PhysicButtonsPanel, Panel):
    bl_label = "Dynamic Paint Advanced"
    COMPAT_ENGINES = {'BLENDER_RENDER'}

    @classmethod
    def poll(cls, context):
        md = context.dynamic_paint
        rd = context.scene.render
        return md and md.ui_type == 'CANVAS' and md.canvas_settings and md.canvas_settings.canvas_surfaces.active and rd.engine in cls.COMPAT_ENGINES

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

        canvas = context.dynamic_paint.canvas_settings
        surface = canvas.canvas_surfaces.active

        surface_type = surface.surface_type

        layout.prop(surface, "surface_type")
        layout.separator()

        # dissolve
        if surface_type == 'PAINT':
            split = layout.split(percentage=0.35)
            split.prop(surface, "use_drying", text="Dry:")

            col = split.column()
            col.active = surface.use_drying
            split = col.split(percentage=0.7)
            col = split.column(align=True)
            col.prop(surface, "dry_speed", text="Time")
            col.prop(surface, "color_dry_threshold")
            split.prop(surface, "use_dry_log", text="Slow")

        if surface_type != 'WAVE':
            split = layout.split(percentage=0.35)
            col = split.column()
            if surface_type == 'WEIGHT':
                col.prop(surface, "use_dissolve", text="Fade:")
            else:
                col.prop(surface, "use_dissolve", text="Dissolve:")
            col = split.column()
            col.active = surface.use_dissolve
            split = col.split(percentage=0.7)
            split.prop(surface, "dissolve_speed", text="Time")
            split.prop(surface, "use_dissolve_log", text="Slow")

        # per type settings
        if surface_type == 'DISPLACE':
            layout.prop(surface, "use_incremental_displace")
            if surface.surface_format == 'VERTEX':
                row = layout.row()
                row.prop(surface, "depth_clamp")
                row.prop(surface, "displace_factor")

        elif surface_type == 'WAVE':
            layout.prop(surface, "use_wave_open_border")

            split = layout.split()

            col = split.column(align=True)
            col.prop(surface, "wave_timescale")
            col.prop(surface, "wave_speed")

            col = split.column(align=True)
            col.prop(surface, "wave_damping")
            col.prop(surface, "wave_spring")
            col.prop(surface, "wave_smoothness")

        layout.separator()
        layout.prop(surface, "brush_group")
        row = layout.row()
        row.prop(surface, "brush_influence_scale")
        row.prop(surface, "brush_radius_scale")


class PHYSICS_PT_dp_canvas_output(PhysicButtonsPanel, Panel):
    bl_label = "Dynamic Paint Output"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER'}

    @classmethod
    def poll(cls, context):
        md = context.dynamic_paint
        rd = context.scene.render
        if not (md and md.ui_type == 'CANVAS' and md.canvas_settings):
            return 0
        surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
        return (surface and
                (not (surface.surface_format == 'VERTEX' and (surface.surface_type in {'DISPLACE', 'WAVE'}))) and
                (rd.engine in cls.COMPAT_ENGINES))

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

        canvas = context.dynamic_paint.canvas_settings
        surface = canvas.canvas_surfaces.active
        ob = context.object

        surface_type = surface.surface_type

        # vertex format outputs
        if surface.surface_format == 'VERTEX':
            if surface_type == 'PAINT':
                # toggle active preview
                layout.prop(surface, "preview_id")

                # paint-map output
                row = layout.row()
                row.prop_search(surface, "output_name_a", ob.data, "vertex_colors", text="Paintmap Layer")
                if surface.output_exists(object=ob, index=0):
                    ic = 'ZOOMOUT'
                else:
                    ic = 'ZOOMIN'

                row.operator("dpaint.output_toggle", icon=ic, text="").output = 'A'

                # wet-map output
                row = layout.row()
                row.prop_search(surface, "output_name_b", ob.data, "vertex_colors", text="Wetmap Layer")
                if surface.output_exists(object=ob, index=1):
                    ic = 'ZOOMOUT'
                else:
                    ic = 'ZOOMIN'

                row.operator("dpaint.output_toggle", icon=ic, text="").output = 'B'

            elif surface_type == 'WEIGHT':
                row = layout.row()
                row.prop_search(surface, "output_name_a", ob, "vertex_groups", text="Vertex Group")
                if surface.output_exists(object=ob, index=0):
                    ic = 'ZOOMOUT'
                else:
                    ic = 'ZOOMIN'

                row.operator("dpaint.output_toggle", icon=ic, text="").output = 'A'

        # image format outputs
        if surface.surface_format == 'IMAGE':
            layout.operator("dpaint.bake", text="Bake Image Sequence", icon='MOD_DYNAMICPAINT')
            layout.prop_search(surface, "uv_layer", ob.data, "uv_textures", text="UV Map")
            layout.separator()

            layout.prop(surface, "image_output_path", text="")
            row = layout.row()
            row.prop(surface, "image_fileformat", text="")
            row.prop(surface, "use_premultiply", text="Premultiply Alpha")

            if surface_type == 'PAINT':
                split = layout.split(percentage=0.4)
                split.prop(surface, "use_output_a", text="Paintmaps:")
                sub = split.row()
                sub.active = surface.use_output_a
                sub.prop(surface, "output_name_a", text="")

                split = layout.split(percentage=0.4)
                split.prop(surface, "use_output_b", text="Wetmaps:")
                sub = split.row()
                sub.active = surface.use_output_b
                sub.prop(surface, "output_name_b", text="")
            else:
                col = layout.column()
                col.prop(surface, "output_name_a", text="Filename:")
                if surface_type == 'DISPLACE':
                    col.prop(surface, "displace_type", text="Displace Type")
                    col.prop(surface, "depth_clamp")
                elif surface_type == 'WAVE':
                    col.prop(surface, "depth_clamp", text="Wave Clamp")


class PHYSICS_PT_dp_canvas_initial_color(PhysicButtonsPanel, Panel):
    bl_label = "Dynamic Paint Initial Color"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER'}

    @classmethod
    def poll(cls, context):
        md = context.dynamic_paint
        rd = context.scene.render
        if not (md and md.ui_type == 'CANVAS' and md.canvas_settings):
            return 0
        surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
        return (surface and surface.surface_type == 'PAINT') and (rd.engine in cls.COMPAT_ENGINES)

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

        canvas = context.dynamic_paint.canvas_settings
        surface = canvas.canvas_surfaces.active
        ob = context.object

        layout.prop(surface, "init_color_type", expand=False)
        if surface.init_color_type != 'NONE':
            layout.separator()

        # dissolve
        if surface.init_color_type == 'COLOR':
            layout.prop(surface, "init_color")

        elif surface.init_color_type == 'TEXTURE':
            layout.prop(surface, "init_texture")
            layout.prop_search(surface, "init_layername", ob.data, "uv_textures", text="UV Map")

        elif surface.init_color_type == 'VERTEX_COLOR':
            layout.prop_search(surface, "init_layername", ob.data, "vertex_colors", text="Color Layer")


class PHYSICS_PT_dp_effects(PhysicButtonsPanel, Panel):
    bl_label = "Dynamic Paint Effects"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER'}

    @classmethod
    def poll(cls, context):
        md = context.dynamic_paint
        rd = context.scene.render
        if not (md and md.ui_type == 'CANVAS' and md.canvas_settings):
            return False
        surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
        return (surface and surface.surface_type == 'PAINT') and (rd.engine in cls.COMPAT_ENGINES)

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

        canvas = context.dynamic_paint.canvas_settings
        surface = canvas.canvas_surfaces.active

        layout.row().prop(surface, "effect_ui", expand=True)

        if surface.effect_ui == 'SPREAD':
            layout.prop(surface, "use_spread")

            row = layout.row()
            row.active = surface.use_spread
            row.prop(surface, "spread_speed")
            row.prop(surface, "color_spread_speed")

        elif surface.effect_ui == 'DRIP':
            layout.prop(surface, "use_drip")

            col = layout.column()
            col.active = surface.use_drip
            effector_weights_ui(self, context, surface.effector_weights, 'DYNAMIC_PAINT')

            layout.label(text="Surface Movement:")
            row = layout.row()
            row.prop(surface, "drip_velocity", slider=True)
            row.prop(surface, "drip_acceleration", slider=True)

        elif surface.effect_ui == 'SHRINK':
            layout.prop(surface, "use_shrink")

            row = layout.row()
            row.active = surface.use_shrink
            row.prop(surface, "shrink_speed")


class PHYSICS_PT_dp_cache(PhysicButtonsPanel, Panel):
    bl_label = "Dynamic Paint Cache"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER'}

    @classmethod
    def poll(cls, context):
        md = context.dynamic_paint
        rd = context.scene.render
        return (md and
                md.ui_type == 'CANVAS' and
                md.canvas_settings and
                md.canvas_settings.canvas_surfaces.active and
                md.canvas_settings.canvas_surfaces.active.is_cache_user and
                (rd.engine in cls.COMPAT_ENGINES))

    def draw(self, context):
        surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active
        cache = surface.point_cache

        point_cache_ui(self, context, cache, (cache.is_baked is False), 'DYNAMIC_PAINT')


class PHYSICS_PT_dp_brush_source(PhysicButtonsPanel, Panel):
    bl_label = "Dynamic Paint Source"
    COMPAT_ENGINES = {'BLENDER_RENDER'}

    @classmethod
    def poll(cls, context):
        md = context.dynamic_paint
        rd = context.scene.render
        return md and md.ui_type == 'BRUSH' and md.brush_settings and (rd.engine in cls.COMPAT_ENGINES)

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

        brush = context.dynamic_paint.brush_settings
        ob = context.object

        split = layout.split()
        col = split.column()
        col.prop(brush, "paint_source")

        if brush.paint_source == 'PARTICLE_SYSTEM':
            col.prop_search(brush, "particle_system", ob, "particle_systems", text="")
            if brush.particle_system:
                col.label(text="Particle Effect:")
                sub = col.column()
                sub.active = not brush.use_particle_radius
                sub.prop(brush, "solid_radius", text="Solid Radius")
                col.prop(brush, "use_particle_radius", text="Use Particle's Radius")
                col.prop(brush, "smooth_radius", text="Smooth Radius")

        if brush.paint_source in {'DISTANCE', 'VOLUME_DISTANCE', 'POINT'}:
            col.prop(brush, "paint_distance", text="Paint Distance")
            split = layout.row().split(percentage=0.4)
            sub = split.column()
            if brush.paint_source in {'DISTANCE', 'VOLUME_DISTANCE'}:
                sub.prop(brush, "use_proximity_project")
            if brush.paint_source == 'VOLUME_DISTANCE':
                sub.prop(brush, "invert_proximity")
                sub.prop(brush, "use_negative_volume")

            sub = split.column()
            if brush.paint_source in {'DISTANCE', 'VOLUME_DISTANCE'}:
                column = sub.column()
                column.active = brush.use_proximity_project
                column.prop(brush, "ray_direction")
            sub.prop(brush, "proximity_falloff")
            if brush.proximity_falloff == 'RAMP':
                col = layout.row().column()
                col.separator()
                col.prop(brush, "use_proximity_ramp_alpha", text="Only Use Alpha")
                col.template_color_ramp(brush, "paint_ramp", expand=True)


class PHYSICS_PT_dp_brush_velocity(PhysicButtonsPanel, Panel):
    bl_label = "Dynamic Paint Velocity"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER'}

    @classmethod
    def poll(cls, context):
        md = context.dynamic_paint
        rd = context.scene.render
        return md and md.ui_type == 'BRUSH' and md.brush_settings and (rd.engine in cls.COMPAT_ENGINES)

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

        brush = context.dynamic_paint.brush_settings

        split = layout.split()

        col = split.column()
        col.prop(brush, "use_velocity_alpha")
        col.prop(brush, "use_velocity_color")

        split.prop(brush, "use_velocity_depth")

        col = layout.column()
        col.active = (brush.use_velocity_alpha or brush.use_velocity_color or brush.use_velocity_depth)
        col.prop(brush, "velocity_max")
        col.template_color_ramp(brush, "velocity_ramp", expand=True)
        layout.separator()

        row = layout.row()
        row.prop(brush, "use_smudge")
        sub = row.row()
        sub.active = brush.use_smudge
        sub.prop(brush, "smudge_strength")


class PHYSICS_PT_dp_brush_wave(PhysicButtonsPanel, Panel):
    bl_label = "Dynamic Paint Waves"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER'}

    @classmethod
    def poll(cls, context):
        md = context.dynamic_paint
        rd = context.scene.render
        return md and md.ui_type == 'BRUSH' and md.brush_settings and (rd.engine in cls.COMPAT_ENGINES)

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

        brush = context.dynamic_paint.brush_settings

        layout.prop(brush, "wave_type")
        if brush.wave_type != 'REFLECT':
            row = layout.row()
            row.prop(brush, "wave_factor")
            row.prop(brush, "wave_clamp")


classes = (
    PHYSICS_UL_dynapaint_surfaces,
    PHYSICS_PT_dynamic_paint,
    PHYSICS_PT_dp_advanced_canvas,
    PHYSICS_PT_dp_canvas_output,
    PHYSICS_PT_dp_canvas_initial_color,
    PHYSICS_PT_dp_effects,
    PHYSICS_PT_dp_cache,
    PHYSICS_PT_dp_brush_source,
    PHYSICS_PT_dp_brush_velocity,
    PHYSICS_PT_dp_brush_wave,
)

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