-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNGviewer beta 1_1.py
332 lines (276 loc) · 11.7 KB
/
NGviewer beta 1_1.py
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
bl_info = {
"name": "NGviewer beta 1.1",
"author": "Andrew Stevenson",
"version": (1, 1),
"blender": (2, 80, 0),
"location": "View3D > N-Panel",
"description": "easily edit node group perameters from the 3D view",
"category": "Node",
}
import bpy
import nodeitems_utils
from bpy.types import Panel
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
PointerProperty,
)
#Feel free to change this but it would be great for me if you would consider buying the addon first ;)
is_trial = True
# class NGPreferences(bpy.types.AddonPreferences):
# bl_idname = __name__
# category : EnumProperty(
# name = "Panel area:",
# description = "area to display the addon",
# items = (
# ("Tool", "Tool", "Display addon in the Tool panel in the sidebar"),
# ("NGviewer", "New panel", "Display addon in a new panel in the sidebar")
# ),
# default = "Tool")
# def draw(self, context):
# layout = self.layout
# if is_trial:
# draw_trial(layout)
# row = layout.row()
# row.label(text = "Panel location:")
# row.prop(self, "category",expand = True)
def draw_trial(col):
row = col.row(align=True)
row.operator('wm.url_open',
text="",
icon='FUND',
emboss=False).url = "https://gumroad.com/l/qWuvv"
row.alert = True
row.label(text="Trial Version")
def node_group_enum(self, context):
enum_items = []
node_group_names = []
node_group_labels = []
ng_tool = bpy.context.scene.ng_tool
nodes = bpy.data.materials[ng_tool.material].node_tree.nodes
for node in nodes:
if node.type == 'GROUP':
node_group_names.append(node.name)
node_group_labels.append(node.label)
for group, label in zip(node_group_names, node_group_labels):
if label == "":
enum_items.append((group,
group,
group,
))
else:
enum_items.append((group,
label,
group,
))
return enum_items
def material_enum(self, context):
enum_items = []
material_slots = bpy.context.active_object.material_slots
ng_tool = bpy.context.scene.ng_tool
i = 0
for material_slot in material_slots:
if ng_tool.show_non_group_materials:
if material_slot.material is not None:
material_name = material_slot.material.name
enum_items.append((material_name,
material_name,
material_name,
bpy.data.materials[material_name].preview.icon_id,
i
))
i+=1
else:
nodes = material_slot.material.node_tree.nodes
node_groups = []
for node in nodes:
if node.type == 'GROUP':
node_groups.append(node.name)
if material_slot.material is not None and len(node_groups) != 0:
material_name = material_slot.material.name
enum_items.append((material_name,
material_name,
material_name,
bpy.data.materials[material_name].preview.icon_id,
i
))
i+=1
return enum_items
class NodeGroupSettings(bpy.types.PropertyGroup):
material : EnumProperty(
name = "",
description = "material to display",
items = material_enum,
)
category : EnumProperty(
name = "Panel area:",
description = "area to display the addon",
items = (
("Tool", "Tool", "Display addon in the Tool panel in the sidebar"),
("NGviewer", "New panel", "Display addon in a new panel in the sidebar")
),
default = "Tool")
node_group : EnumProperty(
name = "",
description = "node group to display",
items = node_group_enum,
)
#material settings
show_material_settings : BoolProperty(
name = "show material settings",
description = "show material settings",
default = False,
)
show_non_group_materials : BoolProperty(
name = "show non node group materials",
description = "show materials with no node groups in them",
default = False,
)
grumpy : BoolProperty(
name = "grumpy",
description = "remove happiness from messages",
default = False,
)
#group settings
show_group_settings : BoolProperty(
name = "show group settings",
description = "show group settings",
default = False,
)
edit_node_links : BoolProperty(
name = "show node links",
description = "show node links",
default = False,
)
use_boxes : BoolProperty(
name = "use boxes",
description = "put inputs in a box",
default = True,
)
align_inputs : BoolProperty(
name = "align",
description = "align inputs",
default = False,
)
# class NG_PT_node_panel(Panel):
# """Creates a Panel in the node"""
# bl_space_type = "VIEW_3D"
# bl_idname = "ng.panel"
# bl_region_type = "UI"
# bl_label = "NGviewer"
# bl_category = "Tool"
class NG_PT_panel(Panel):
"""Creates a Panel in the Tool panel"""
bl_space_type = "VIEW_3D"
bl_idname = "ng.panel"
bl_region_type = "UI"
bl_label = "NGviewer"
bl_category = "Tool"
# ng_tool = bpy.context.scene.ng_tool
# if ng_tool.category is "Tool":
# bl_category = "Tool"
# else:
# bl_category = "NGviewer"
def draw(self, context):
ng_tool = bpy.context.scene.ng_tool
grumpy = ng_tool.grumpy
layout = self.layout
if grumpy:
face = ""
else:
face = ": )"
if is_trial:
draw_trial(layout)
try:
#check for active object
if bpy.context.active_object is not None:
material_slots = bpy.context.active_object.material_slots
#check for material slots
if len(material_slots) != 0:
#check for materials
if bpy.data.materials[ng_tool.material] is not None and bpy.context.active_object.active_material is not None:
col = layout.column(align = True)
row = col.row(align = True)
row.scale_y = 1.2
row.scale_x = 1.13
row.prop(ng_tool, "material",)
row.prop(ng_tool, "show_material_settings", text="", icon='PREFERENCES')
#settings panel
if ng_tool.show_material_settings:
box = col.box()
boxcol = box.column(align = True)
boxcol.prop(ng_tool, "show_non_group_materials")
boxcol.prop(ng_tool, "grumpy")
col.separator()
#check for node tree
if bpy.data.materials[ng_tool.material].node_tree is not None:
node_groups = []
nodes = bpy.data.materials[ng_tool.material].node_tree.nodes
#check for node groups
for node in nodes:
if node.type == 'GROUP':
node_groups.append(node.name)
if len(node_groups) is not 0:
node_tree = bpy.data.materials[ng_tool.material].node_tree
group_node = node_tree.nodes[ng_tool.node_group]
#def_input_boxes(group_node)
row = col.row(align = True)
row.scale_y = 1.2
row.scale_x = 1.13
row.prop(ng_tool, "node_group", icon = "NODETREE")
row.prop(ng_tool, "show_group_settings", text="", icon='PREFERENCES')
#settings panel
if ng_tool.show_group_settings:
box = col.box()
boxcol = box.column(align = True)
boxcol.prop(ng_tool, "edit_node_links")
boxcol.prop(ng_tool, "use_boxes")
boxcol.prop(ng_tool, "align_inputs")
#draw inputs
value_inputs = [socket for socket in group_node.inputs if socket.enabled and not socket.is_linked and not socket.hide_value]
if value_inputs:
layout.label(text="Inputs:")
#use boxes or not
if ng_tool.use_boxes:
box = layout.box()
else:
box = layout
#align or not
col = box.column(align = ng_tool.align_inputs)
#draw type
if ng_tool.edit_node_links:
for socket in range(len(value_inputs)):
col.template_node_view(node_tree, group_node, group_node.inputs[socket])
else:
for socket in value_inputs:
socket.draw(context, col, group_node, socket.name)
else:
layout.label(text = "No node groups in this material " + face)
else:
layout.label(text = "No active node tree " + face)
else:
layout.label(text = "No active material " + face)
else:
layout.label(text = "No material slots " + face)
else:
layout.label(text = "No object selected " + face)
except KeyError:
layout.label(text = "Please select a material " + face)
classes = (
NodeGroupSettings,
NG_PT_panel,
#NGPreferences,
#NG_PT_node_panel,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.ng_tool = bpy.props.PointerProperty(type=NodeGroupSettings)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()