Import_3ds: Improved distance cue node setup
[blender-addons.git] / amaranth / node_editor / id_panel.py
blob6d2e21744676e1c7d3a73b5c6aa3cebb55a311f2
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 """
6 Object / Material Indices Panel
8 When working with ID Masks in the Nodes Editor, is hard to follow track
9 of which objects/materials have which ID.
10 This adds a panel on the sidebar when an ID Mask node is selected.
11 The active object is highlighted between [square brackets] On the Nodes
12 Editor's sidebar, when an ID Mask node is selected.
13 """
15 import bpy
18 class AMTH_NODE_PT_indices(bpy.types.Panel):
19 bl_space_type = "NODE_EDITOR"
20 bl_region_type = "UI"
21 bl_label = "Object / Material Indices"
22 bl_options = {"DEFAULT_CLOSED"}
24 @classmethod
25 def poll(cls, context):
26 node = context.active_node
27 return node and node.type == "ID_MASK"
29 def draw(self, context):
30 layout = self.layout
32 objects = bpy.data.objects
33 materials = bpy.data.materials
34 node = context.active_node
36 show_ob_id = False
37 show_ma_id = False
38 matching_ids = False
40 if context.active_object:
41 ob_act = context.active_object
42 else:
43 ob_act = False
45 for ob in objects:
46 if ob and ob.pass_index > 0:
47 show_ob_id = True
48 for ma in materials:
49 if ma and ma.pass_index > 0:
50 show_ma_id = True
51 row = layout.row(align=True)
52 row.prop(node, "index", text="Mask Index")
53 row.prop(node, "use_matching_indices", text="Only Matching IDs")
55 layout.separator()
57 if not show_ob_id and not show_ma_id:
58 layout.label(
59 text="No objects or materials indices so far.", icon="INFO")
61 if show_ob_id:
62 split = layout.split()
63 col = split.column()
64 col.label(text="Object Name")
65 split.label(text="ID Number")
66 row = layout.row()
67 for ob in objects:
68 icon = "OUTLINER_DATA_" + ob.type
69 if ob.library:
70 icon = "LIBRARY_DATA_DIRECT"
71 elif ob.is_library_indirect:
72 icon = "LIBRARY_DATA_INDIRECT"
74 if ob and node.use_matching_indices \
75 and ob.pass_index == node.index \
76 and ob.pass_index != 0:
77 matching_ids = True
78 row.label(
79 text="[{}]".format(ob.name)
80 if ob_act and ob.name == ob_act.name else ob.name,
81 icon=icon)
82 row.label(text="%s" % ob.pass_index)
83 row = layout.row()
85 elif ob and not node.use_matching_indices \
86 and ob.pass_index > 0:
88 matching_ids = True
89 row.label(
90 text="[{}]".format(ob.name)
91 if ob_act and ob.name == ob_act.name else ob.name,
92 icon=icon)
93 row.label(text="%s" % ob.pass_index)
94 row = layout.row()
96 if node.use_matching_indices and not matching_ids:
97 row.label(text="No objects with ID %s" %
98 node.index, icon="INFO")
100 layout.separator()
102 if show_ma_id:
103 split = layout.split()
104 col = split.column()
105 col.label(text="Material Name")
106 split.label(text="ID Number")
107 row = layout.row()
109 for ma in materials:
110 icon = "BLANK1"
111 if ma.use_nodes:
112 icon = "NODETREE"
113 elif ma.library:
114 icon = "LIBRARY_DATA_DIRECT"
115 if ma.is_library_indirect:
116 icon = "LIBRARY_DATA_INDIRECT"
118 if ma and node.use_matching_indices \
119 and ma.pass_index == node.index \
120 and ma.pass_index != 0:
121 matching_ids = True
122 row.label(text="%s" % ma.name, icon=icon)
123 row.label(text="%s" % ma.pass_index)
124 row = layout.row()
126 elif ma and not node.use_matching_indices \
127 and ma.pass_index > 0:
129 matching_ids = True
130 row.label(text="%s" % ma.name, icon=icon)
131 row.label(text="%s" % ma.pass_index)
132 row = layout.row()
134 if node.use_matching_indices and not matching_ids:
135 row.label(text="No materials with ID %s" %
136 node.index, icon="INFO")
139 def register():
140 bpy.utils.register_class(AMTH_NODE_PT_indices)
143 def unregister():
144 bpy.utils.unregister_class(AMTH_NODE_PT_indices)