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

properties_view_layer.py « bl_ui « startup « scripts « release - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ce534452990a450397a2a598ce498efc0d4086c (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
# ##### 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


class ViewLayerButtonsPanel:
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "view_layer"
    # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here

    @classmethod
    def poll(cls, context):
        return (context.engine in cls.COMPAT_ENGINES)


class VIEWLAYER_PT_layer(ViewLayerButtonsPanel, Panel):
    bl_label = "View Layer"
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}

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

        scene = context.scene
        rd = scene.render
        layer = bpy.context.view_layer

        layout.prop(layer, "use", text="Use for Rendering")
        layout.prop(rd, "use_single_layer", text="Render Single Layer")


class VIEWLAYER_PT_eevee_layer_passes(ViewLayerButtonsPanel, Panel):
    bl_label = "Passes"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_EEVEE'}

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

        scene = context.scene
        rd = scene.render
        view_layer = context.view_layer

        col = layout.column()
        col.prop(view_layer, "use_pass_combined")
        col.prop(view_layer, "use_pass_z")
        col.prop(view_layer, "use_pass_mist")
        col.prop(view_layer, "use_pass_normal")
        col.prop(view_layer, "use_pass_ambient_occlusion")
        col.prop(view_layer, "use_pass_subsurface_direct", text="Subsurface Direct")
        col.prop(view_layer, "use_pass_subsurface_color", text="Subsurface Color")


class VIEWLAYER_UL_override_sets(UIList):
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
        row = layout.row(align=True)
        row.prop(item, "use", text="", index=index)
        row.prop(item, "name", text="", index=index, icon_value=icon, emboss=False)


class ViewLayerOverridesPanel():
    @classmethod
    def poll(cls, context):
        return context.view_layer.override_sets.active

    @staticmethod
    def _icon_from_id_type(id_type):
        return id_type + '_DATA'

    @staticmethod
    def _value_name_override_mode_get(data_type, data_subtype):
        """
        return Tuple: value name and whether the property supports override modes
        """
        # TODO: Finish this.
        proptype_map = {
            'BOOLEAN': {
                'NONE': ("value_boolean", False)},
            'INT': {
                'NONE': ("value_int", True)},
            'FLOAT': {
                'NONE': ("value_float", True),
                'COLOR': ("value_color", False)},
            'STRING': {
                'NONE': (None, False)},
            'ENUM': {
                'NONE': (None, False)},
            'POINTER': {
                'NONE': (None, False)},
            'COLLECTION': {
                'NONE': (None, False)},
        }

        type_lookup = proptype_map[data_type]
        value_name = type_lookup.get(data_subtype)

        if value_name is None:
            value_name = type_lookup['NONE']

        return value_name

    def _draw_property(self, layout, dyn_prop, index, property_type):
        box = layout.box()
        row = box.row()
        row.prop(dyn_prop, "use", text="")
        subrow = row.row()
        subrow.active = dyn_prop.use

        subrow.label(text=dyn_prop.name, icon=self._icon_from_id_type(dyn_prop.id_type))
        value_propname, override_mode_support = self._value_name_override_mode_get(dyn_prop.data_type, dyn_prop.data_subtype)

        if override_mode_support:
            subrow.prop(dyn_prop, "override_mode", text="")
            subrow.prop(dyn_prop, value_propname, text="")
        elif value_propname is not None:
            subrow.prop(dyn_prop, value_propname, text="")

        ops = row.operator("scene.view_layer_override_remove", text="", icon='ZOOMOUT', emboss=False)
        ops.index = index
        ops.property_type = property_type


class VIEWLAYER_OT_overrides(ViewLayerButtonsPanel, Panel):
    bl_label = "Overrides"
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_CLAY', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}

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

        scene = context.scene
        view_layer = context.view_layer

        row = layout.row(align=True)
        row.label(text="Override Sets")

        row = layout.row()
        col = row.column()

        col.template_list("VIEWLAYER_UL_override_sets", "name", view_layer, "override_sets", view_layer.override_sets, "active_index", rows=2)

        col = row.column(align=True)
        col.operator("scene.view_layer_override_set_add", icon='ZOOMIN', text="")
        col.operator("scene.view_layer_override_set_remove", icon='ZOOMOUT', text="")

        override_set = view_layer.override_sets.active


class VIEWLAYER_OT_overrides_scene_properties(ViewLayerOverridesPanel, ViewLayerButtonsPanel, Panel):
    bl_label = "Scene Properties"
    bl_parent_id = "VIEWLAYER_OT_overrides"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_CLAY', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}

    def draw(self, context):
        layout = self.layout
        override_set = context.view_layer.override_sets.active

        if override_set.scene_properties:
            for i, dyn_prop in enumerate(override_set.scene_properties):
                self._draw_property(layout, dyn_prop, i, 'SCENE')
        else:
            layout.label(text="No scene property")


class VIEWLAYER_UL_override_set_collections(UIList):
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
        layout.row().label(text=item.name, icon_value=icon)


class VIEWLAYER_OT_overrides_affected_collections(ViewLayerOverridesPanel, ViewLayerButtonsPanel, Panel):
    bl_label = "Affected Collections"
    bl_parent_id = "VIEWLAYER_OT_overrides"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_CLAY', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}

    def draw(self, context):
        layout = self.layout
        override_set = context.view_layer.override_sets.active

        row = layout.row()
        col = row.column()

        col.template_list("VIEWLAYER_UL_override_set_collections", "", override_set, "affected_collections", override_set.affected_collections, "active_index", rows=1)

        col = row.column(align=True)
        col.operator("scene.override_set_collection_link", icon='ZOOMIN', text="")
        col.operator("scene.override_set_collection_unlink", icon='ZOOMOUT', text="")


class VIEWLAYER_OT_overrides_collection_properties(ViewLayerOverridesPanel, ViewLayerButtonsPanel, Panel):
    bl_label = "Collection Properties"
    bl_parent_id = "VIEWLAYER_OT_overrides"
    bl_options = {'DEFAULT_CLOSED'}
    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_CLAY', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}

    def draw(self, context):
        layout = self.layout
        override_set = context.view_layer.override_sets.active

        if override_set.collection_properties:
            for i, dyn_prop in enumerate(override_set.collection_properties):
                self._draw_property(layout, dyn_prop, i, 'COLLECTION')
        else:
            layout.label(text="No collection property")


classes = (
    VIEWLAYER_PT_layer,
    VIEWLAYER_PT_eevee_layer_passes,
    VIEWLAYER_UL_override_set_collections,
    VIEWLAYER_UL_override_sets,
    VIEWLAYER_OT_overrides,
    VIEWLAYER_OT_overrides_scene_properties,
    VIEWLAYER_OT_overrides_affected_collections,
    VIEWLAYER_OT_overrides_collection_properties,
)

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