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

properties_material_gpencil.py « bl_ui « startup « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b26b950d5d0a81fa270d522e43a44ccdf5a4f49 (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
# ##### 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 Menu, Panel, UIList
from rna_prop_ui import PropertyPanel
from bl_ui.utils import PresetPanel

from bl_ui.properties_grease_pencil_common import (
    GreasePencilMaterialsPanel,
)


class GPENCIL_MT_material_context_menu(Menu):
    bl_label = "Material Specials"

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

        layout.operator("gpencil.material_reveal", icon='RESTRICT_VIEW_OFF', text="Show All")
        layout.operator("gpencil.material_hide", icon='RESTRICT_VIEW_ON', text="Hide Others").unselected = True

        layout.separator()

        layout.operator("gpencil.material_lock_all", icon='LOCKED', text="Lock All")
        layout.operator("gpencil.material_unlock_all", icon='UNLOCKED', text="Unlock All")

        layout.operator("gpencil.material_lock_unused", text="Lock Unselected")
        layout.operator("gpencil.lock_layer", text="Lock Unused")

        layout.separator()

        layout.operator("gpencil.material_to_vertex_color", text="Convert Materials to Vertex Color")
        layout.operator("gpencil.extract_palette_vertex", text="Extract Palette from Vertex Color")

        layout.separator()

        layout.operator("gpencil.materials_copy_to_object", text="Copy Material to Selected").only_active = True
        layout.operator("gpencil.materials_copy_to_object", text="Copy All Materials to Selected").only_active = False

        layout.separator()

        layout.operator("gpencil.stroke_merge_material", text="Merge Similar")
        layout.operator("object.material_slot_remove_unused")


class GPENCIL_UL_matslots(UIList):
    def draw_item(self, _context, layout, _data, item, icon, _active_data, _active_propname, _index):
        slot = item
        ma = slot.material
        if (ma is not None) and (ma.grease_pencil is not None):
            gpcolor = ma.grease_pencil

            if self.layout_type in {'DEFAULT', 'COMPACT'}:
                if gpcolor.lock:
                    layout.active = False

                row = layout.row(align=True)
                row.enabled = not gpcolor.lock
                row.prop(ma, "name", text="", emboss=False, icon_value=icon)

                row = layout.row(align=True)

                if gpcolor.ghost is True:
                    icon = 'ONIONSKIN_OFF'
                else:
                    icon = 'ONIONSKIN_ON'
                row.prop(gpcolor, "ghost", text="", icon=icon, emboss=False)
                row.prop(gpcolor, "hide", text="", emboss=False)
                row.prop(gpcolor, "lock", text="", emboss=False)

            elif self.layout_type == 'GRID':
                layout.alignment = 'CENTER'
                layout.label(text="", icon_value=icon)


class GPMaterialButtonsPanel:
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "material"

    @classmethod
    def poll(cls, context):
        ma = context.material
        return ma and ma.grease_pencil


class MATERIAL_PT_gpencil_slots(GreasePencilMaterialsPanel, Panel):
    bl_label = "Grease Pencil Material Slots"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "material"
    bl_options = {'HIDE_HEADER'}

    @classmethod
    def poll(cls, context):
        ob = context.object
        ma = context.material

        return (ma and ma.grease_pencil) or (ob and ob.type == 'GPENCIL')


# Used as parent for "Stroke" and "Fill" panels
class MATERIAL_PT_gpencil_surface(GPMaterialButtonsPanel, Panel):
    bl_label = "Surface"

    @classmethod
    def poll(cls, context):
        mat = context.material
        ob = context.active_object
        is_scene_render = ob and ob.use_grease_pencil_scene_engine
        return (mat and (mat.use_nodes is False or is_scene_render is False))

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

    def draw(self, context):
        layout = self.layout
        ob = context.active_object
        is_scene_render = ob and ob.use_grease_pencil_scene_engine
        mat = context.material
        if is_scene_render:
            layout.prop(mat, "use_nodes", icon='NODETREE')


class MATERIAL_PT_gpencil_strokecolor(GPMaterialButtonsPanel, Panel):
    bl_label = "Stroke"
    bl_parent_id = 'MATERIAL_PT_gpencil_surface'

    def draw_header(self, context):
        ma = context.material
        if ma is not None and ma.grease_pencil is not None:
            gpcolor = ma.grease_pencil
            self.layout.enabled = not gpcolor.lock
            self.layout.prop(gpcolor, "show_stroke", text="")

    def draw(self, context):
        layout = self.layout
        layout.use_property_split = True
        ob = context.active_object
        is_scene_render = ob and ob.use_grease_pencil_scene_engine
        ma = context.material
        if ma is not None and ma.grease_pencil is not None:
            gpcolor = ma.grease_pencil

            col = layout.column()
            col.enabled = not gpcolor.lock

            col.prop(gpcolor, "mode")

            col.prop(gpcolor, "stroke_style", text="Style")

            col.prop(gpcolor, "color", text="Base Color")
            if not is_scene_render:
                col.prop(gpcolor, "use_stroke_holdout")

            if gpcolor.stroke_style == 'TEXTURE':
                row = col.row()
                row.enabled = not gpcolor.lock
                col = row.column(align=True)
                col.template_ID(gpcolor, "stroke_image", open="image.open")

            if gpcolor.stroke_style == 'TEXTURE':
                row = col.row()
                row.prop(gpcolor, "mix_stroke_factor", text="Blend", slider=True)
                if gpcolor.mode == 'LINE':
                    col.prop(gpcolor, "pixel_size", text="UV Factor")

            if gpcolor.mode in {'DOTS', 'BOX'}:
                col.prop(gpcolor, "alignment_mode")
                col.prop(gpcolor, "alignment_rotation")

            if gpcolor.mode == 'LINE' and not is_scene_render:
                col.prop(gpcolor, "use_overlap_strokes")


class MATERIAL_PT_gpencil_fillcolor(GPMaterialButtonsPanel, Panel):
    bl_label = "Fill"
    bl_parent_id = 'MATERIAL_PT_gpencil_surface'

    def draw_header(self, context):
        ma = context.material
        gpcolor = ma.grease_pencil
        self.layout.enabled = not gpcolor.lock
        self.layout.prop(gpcolor, "show_fill", text="")

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

        ob = context.active_object
        is_scene_render = ob and ob.use_grease_pencil_scene_engine
        ma = context.material
        gpcolor = ma.grease_pencil

        # color settings
        col = layout.column()
        col.enabled = not gpcolor.lock
        col.prop(gpcolor, "fill_style", text="Style")

        if gpcolor.fill_style == 'SOLID':
            col.prop(gpcolor, "fill_color", text="Base Color")
            if not is_scene_render:
                col.prop(gpcolor, "use_fill_holdout")

        elif gpcolor.fill_style == 'GRADIENT':
            col.prop(gpcolor, "gradient_type")

            col.prop(gpcolor, "fill_color", text="Base Color")
            col.prop(gpcolor, "mix_color", text="Secondary Color")
            if not is_scene_render:
                col.prop(gpcolor, "use_fill_holdout")
            col.prop(gpcolor, "mix_factor", text="Blend", slider=True)
            col.prop(gpcolor, "flip", text="Flip Colors")

            col.prop(gpcolor, "texture_offset", text="Location")

            row = col.row()
            row.enabled = gpcolor.gradient_type == 'LINEAR'
            row.prop(gpcolor, "texture_angle", text="Rotation")

            col.prop(gpcolor, "texture_scale", text="Scale")

        elif gpcolor.fill_style == 'TEXTURE':
            col.prop(gpcolor, "fill_color", text="Base Color")
            if not is_scene_render:
                col.prop(gpcolor, "use_fill_holdout")

            col.template_ID(gpcolor, "fill_image", open="image.open")

            col.prop(gpcolor, "mix_factor", text="Blend", slider=True)

            col.prop(gpcolor, "texture_offset", text="Location")
            col.prop(gpcolor, "texture_angle", text="Rotation")
            col.prop(gpcolor, "texture_scale", text="Scale")
            col.prop(gpcolor, "texture_clamp", text="Clip Image")


class MATERIAL_PT_gpencil_preview(GPMaterialButtonsPanel, Panel):
    bl_label = "Preview"
    COMPAT_ENGINES = {'BLENDER_EEVEE'}
    bl_options = {'DEFAULT_CLOSED'}

    @classmethod
    def poll(cls, context):
        mat = context.material
        ob = context.active_object
        is_scene_render = ob and ob.use_grease_pencil_scene_engine
        return (mat and mat.grease_pencil and (mat.use_nodes is False or is_scene_render is False))

    def draw(self, context):
        ma = context.material
        self.layout.label(text=ma.name)
        self.layout.template_preview(ma)


class MATERIAL_PT_gpencil_custom_props(GPMaterialButtonsPanel, PropertyPanel, Panel):
    COMPAT_ENGINES = {'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
    _context_path = "object.active_material"
    _property_type = bpy.types.Material

    @classmethod
    def poll(cls, context):
        mat = context.material
        ob = context.active_object
        is_scene_render = ob and ob.use_grease_pencil_scene_engine
        return (mat and mat.grease_pencil and (mat.use_nodes is False or is_scene_render is False))


def draw_material_settings(self, context):
    ob = context.active_object
    is_scene_render = ob and ob.use_grease_pencil_scene_engine
    layout = self.layout
    layout.use_property_split = True
    layout.use_property_decorate = False
    mat = context.material

    if is_scene_render:
        layout.prop(mat, "use_backface_culling")
        layout.prop(mat, "blend_method")
        layout.prop(mat, "shadow_method")

        row = layout.row()
        row.active = ((mat.blend_method == 'CLIP') or (mat.shadow_method == 'CLIP'))
        row.prop(mat, "alpha_threshold")

        if mat.blend_method not in {'OPAQUE', 'CLIP', 'HASHED'}:
            layout.prop(mat, "show_transparent_back")

        layout.prop(mat, "use_screen_refraction")
        layout.prop(mat, "refraction_depth")
        layout.prop(mat, "use_sss_translucency")

    layout.prop(mat, "pass_index")


class MATERIAL_PT_gpencil_settings(GPMaterialButtonsPanel, Panel):
    bl_label = "Settings"
    bl_options = {'DEFAULT_CLOSED'}

    @classmethod
    def poll(cls, context):
        mat = context.material
        ob = context.active_object
        is_scene_render = ob and ob.use_grease_pencil_scene_engine
        return (mat and mat.grease_pencil and (mat.use_nodes is False or is_scene_render is False))

    def draw(self, context):
        draw_material_settings(self, context)


class MATERIAL_PT_gpencil_material_presets(PresetPanel, Panel):
    """Material settings"""
    bl_label = "Material Presets"
    preset_subdir = "gpencil_material"
    preset_operator = "script.execute_preset"
    preset_add_operator = "scene.gpencil_material_preset_add"


classes = (
    GPENCIL_UL_matslots,
    GPENCIL_MT_material_context_menu,
    MATERIAL_PT_gpencil_slots,
    MATERIAL_PT_gpencil_preview,
    MATERIAL_PT_gpencil_material_presets,
    MATERIAL_PT_gpencil_surface,
    MATERIAL_PT_gpencil_strokecolor,
    MATERIAL_PT_gpencil_fillcolor,
    MATERIAL_PT_gpencil_settings,
    MATERIAL_PT_gpencil_custom_props,
)

if __name__ == "__main__":  # only for live edit.
    from bpy.utils import register_class

    for cls in classes:
        register_class(cls)