Recently added IES conflicts w/ EEVEE
[blender.git] / release / scripts / startup / nodeitems_builtins.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 import nodeitems_utils
22 from nodeitems_utils import (
23     NodeCategory,
24     NodeItem,
25     NodeItemCustom,
26 )
27
28
29 # Subclasses for standard node types
30
31 class SortedNodeCategory(NodeCategory):
32     def __init__(self, identifier, name, description="", items=None):
33         # for builtin nodes the convention is to sort by name
34         if isinstance(items, list):
35             items = sorted(items, key=lambda item: item.label.lower())
36
37         super().__init__(identifier, name, description, items)
38
39
40 class CompositorNodeCategory(SortedNodeCategory):
41     @classmethod
42     def poll(cls, context):
43         return (context.space_data.tree_type == 'CompositorNodeTree')
44
45
46 class ShaderNewNodeCategory(SortedNodeCategory):
47     @classmethod
48     def poll(cls, context):
49         return (context.space_data.tree_type == 'ShaderNodeTree' and
50                 context.scene.render.use_shading_nodes)
51
52
53 class ShaderOldNodeCategory(SortedNodeCategory):
54     @classmethod
55     def poll(cls, context):
56         return (context.space_data.tree_type == 'ShaderNodeTree' and
57                 not context.scene.render.use_shading_nodes)
58
59
60 class TextureNodeCategory(SortedNodeCategory):
61     @classmethod
62     def poll(cls, context):
63         return context.space_data.tree_type == 'TextureNodeTree'
64
65
66 # menu entry for node group tools
67 def group_tools_draw(self, layout, context):
68     layout.operator("node.group_make")
69     layout.operator("node.group_ungroup")
70     layout.separator()
71
72 # maps node tree type to group node type
73 node_tree_group_type = {
74     'CompositorNodeTree': 'CompositorNodeGroup',
75     'ShaderNodeTree': 'ShaderNodeGroup',
76     'TextureNodeTree': 'TextureNodeGroup',
77     }
78
79
80 # generic node group items generator for shader, compositor and texture node groups
81 def node_group_items(context):
82     if context is None:
83         return
84     space = context.space_data
85     if not space:
86         return
87     ntree = space.edit_tree
88     if not ntree:
89         return
90
91     yield NodeItemCustom(draw=group_tools_draw)
92
93     def contains_group(nodetree, group):
94         if nodetree == group:
95             return True
96         else:
97             for node in nodetree.nodes:
98                 if node.bl_idname in node_tree_group_type.values() and node.node_tree is not None:
99                     if contains_group(node.node_tree, group):
100                         return True
101         return False
102
103     for group in context.blend_data.node_groups:
104         if group.bl_idname != ntree.bl_idname:
105             continue
106         # filter out recursive groups
107         if contains_group(group, ntree):
108             continue
109
110         yield NodeItem(node_tree_group_type[group.bl_idname],
111                        group.name,
112                        {"node_tree": "bpy.data.node_groups[%r]" % group.name})
113
114
115 # only show input/output nodes inside node groups
116 def group_input_output_item_poll(context):
117     space = context.space_data
118     if space.edit_tree in bpy.data.node_groups.values():
119         return True
120     return False
121
122
123 # only show input/output nodes when editing line style node trees
124 def line_style_shader_nodes_poll(context):
125     snode = context.space_data
126     return (snode.tree_type == 'ShaderNodeTree' and
127             snode.shader_type == 'LINESTYLE')
128
129
130 # only show nodes working in world node trees
131 def world_shader_nodes_poll(context):
132     snode = context.space_data
133     return (snode.tree_type == 'ShaderNodeTree' and
134             snode.shader_type == 'WORLD')
135
136
137 # only show nodes working in object node trees
138 def object_shader_nodes_poll(context):
139     snode = context.space_data
140     return (snode.tree_type == 'ShaderNodeTree' and
141             snode.shader_type == 'OBJECT')
142
143
144 # All standard node categories currently used in nodes.
145
146 shader_node_categories = [
147     # Shader Nodes
148     ShaderOldNodeCategory("SH_INPUT", "Input", items=[
149         NodeItem("ShaderNodeMaterial"),
150         NodeItem("ShaderNodeCameraData"),
151         NodeItem("ShaderNodeFresnel"),
152         NodeItem("ShaderNodeLayerWeight"),
153         NodeItem("ShaderNodeLampData"),
154         NodeItem("ShaderNodeValue"),
155         NodeItem("ShaderNodeRGB"),
156         NodeItem("ShaderNodeTexture"),
157         NodeItem("ShaderNodeGeometry"),
158         NodeItem("ShaderNodeExtendedMaterial"),
159         NodeItem("ShaderNodeParticleInfo"),
160         NodeItem("ShaderNodeObjectInfo"),
161         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
162         ]),
163     ShaderOldNodeCategory("SH_OUTPUT", "Output", items=[
164         NodeItem("ShaderNodeOutput"),
165         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
166         ]),
167     ShaderOldNodeCategory("SH_OP_COLOR", "Color", items=[
168         NodeItem("ShaderNodeMixRGB"),
169         NodeItem("ShaderNodeRGBCurve"),
170         NodeItem("ShaderNodeInvert"),
171         NodeItem("ShaderNodeHueSaturation"),
172         NodeItem("ShaderNodeGamma"),
173         ]),
174     ShaderOldNodeCategory("SH_OP_VECTOR", "Vector", items=[
175         NodeItem("ShaderNodeNormal"),
176         NodeItem("ShaderNodeMapping"),
177         NodeItem("ShaderNodeVectorCurve"),
178         NodeItem("ShaderNodeVectorTransform"),
179         NodeItem("ShaderNodeNormalMap"),
180         ]),
181     ShaderOldNodeCategory("SH_CONVERTOR", "Converter", items=[
182         NodeItem("ShaderNodeValToRGB"),
183         NodeItem("ShaderNodeRGBToBW"),
184         NodeItem("ShaderNodeMath"),
185         NodeItem("ShaderNodeVectorMath"),
186         NodeItem("ShaderNodeSqueeze"),
187         NodeItem("ShaderNodeSeparateRGB"),
188         NodeItem("ShaderNodeCombineRGB"),
189         NodeItem("ShaderNodeSeparateHSV"),
190         NodeItem("ShaderNodeCombineHSV"),
191         ]),
192     ShaderOldNodeCategory("SH_GROUP", "Group", items=node_group_items),
193     ShaderOldNodeCategory("SH_LAYOUT", "Layout", items=[
194         NodeItem("NodeFrame"),
195         NodeItem("NodeReroute"),
196         ]),
197
198     # New Shader Nodes (Cycles)
199     ShaderNewNodeCategory("SH_NEW_INPUT", "Input", items=[
200         NodeItem("ShaderNodeTexCoord"),
201         NodeItem("ShaderNodeAttribute"),
202         NodeItem("ShaderNodeLightPath"),
203         NodeItem("ShaderNodeFresnel"),
204         NodeItem("ShaderNodeLayerWeight"),
205         NodeItem("ShaderNodeRGB"),
206         NodeItem("ShaderNodeValue"),
207         NodeItem("ShaderNodeTangent"),
208         NodeItem("ShaderNodeNewGeometry"),
209         NodeItem("ShaderNodeWireframe"),
210         NodeItem("ShaderNodeBevel"),
211         NodeItem("ShaderNodeObjectInfo"),
212         NodeItem("ShaderNodeHairInfo"),
213         NodeItem("ShaderNodeParticleInfo"),
214         NodeItem("ShaderNodeCameraData"),
215         NodeItem("ShaderNodeUVMap"),
216         NodeItem("ShaderNodeUVAlongStroke", poll=line_style_shader_nodes_poll),
217         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
218         ]),
219     ShaderNewNodeCategory("SH_NEW_OUTPUT", "Output", items=[
220         NodeItem("ShaderNodeOutputMaterial", poll=object_shader_nodes_poll),
221         NodeItem("ShaderNodeOutputLamp", poll=object_shader_nodes_poll),
222         NodeItem("ShaderNodeOutputWorld", poll=world_shader_nodes_poll),
223         NodeItem("ShaderNodeOutputLineStyle", poll=line_style_shader_nodes_poll),
224         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
225         ]),
226     ShaderNewNodeCategory("SH_NEW_SHADER", "Shader", items=[
227         NodeItem("ShaderNodeMixShader"),
228         NodeItem("ShaderNodeAddShader"),
229         NodeItem("ShaderNodeBsdfDiffuse", poll=object_shader_nodes_poll),
230         NodeItem("ShaderNodeBsdfPrincipled", poll=object_shader_nodes_poll),
231         NodeItem("ShaderNodeBsdfGlossy", poll=object_shader_nodes_poll),
232         NodeItem("ShaderNodeBsdfTransparent", poll=object_shader_nodes_poll),
233         NodeItem("ShaderNodeBsdfRefraction", poll=object_shader_nodes_poll),
234         NodeItem("ShaderNodeBsdfGlass", poll=object_shader_nodes_poll),
235         NodeItem("ShaderNodeBsdfTranslucent", poll=object_shader_nodes_poll),
236         NodeItem("ShaderNodeBsdfAnisotropic", poll=object_shader_nodes_poll),
237         NodeItem("ShaderNodeBsdfVelvet", poll=object_shader_nodes_poll),
238         NodeItem("ShaderNodeBsdfToon", poll=object_shader_nodes_poll),
239         NodeItem("ShaderNodeSubsurfaceScattering", poll=object_shader_nodes_poll),
240         NodeItem("ShaderNodeEmission", poll=object_shader_nodes_poll),
241         NodeItem("ShaderNodeBsdfHair", poll=object_shader_nodes_poll),
242         NodeItem("ShaderNodeBackground", poll=world_shader_nodes_poll),
243         NodeItem("ShaderNodeAmbientOcclusion", poll=object_shader_nodes_poll),
244         NodeItem("ShaderNodeHoldout", poll=object_shader_nodes_poll),
245         NodeItem("ShaderNodeVolumeAbsorption"),
246         NodeItem("ShaderNodeVolumeScatter"),
247         NodeItem("ShaderNodeVolumePrincipled"),
248         ]),
249     ShaderNewNodeCategory("SH_NEW_TEXTURE", "Texture", items=[
250         NodeItem("ShaderNodeTexImage"),
251         NodeItem("ShaderNodeTexEnvironment"),
252         NodeItem("ShaderNodeTexSky"),
253         NodeItem("ShaderNodeTexNoise"),
254         NodeItem("ShaderNodeTexWave"),
255         NodeItem("ShaderNodeTexVoronoi"),
256         NodeItem("ShaderNodeTexMusgrave"),
257         NodeItem("ShaderNodeTexGradient"),
258         NodeItem("ShaderNodeTexMagic"),
259         NodeItem("ShaderNodeTexChecker"),
260         NodeItem("ShaderNodeTexBrick"),
261         NodeItem("ShaderNodeTexPointDensity"),
262         NodeItem("ShaderNodeTexIES"),
263         ]),
264     ShaderNewNodeCategory("SH_NEW_OP_COLOR", "Color", items=[
265         NodeItem("ShaderNodeMixRGB"),
266         NodeItem("ShaderNodeRGBCurve"),
267         NodeItem("ShaderNodeInvert"),
268         NodeItem("ShaderNodeLightFalloff"),
269         NodeItem("ShaderNodeHueSaturation"),
270         NodeItem("ShaderNodeGamma"),
271         NodeItem("ShaderNodeBrightContrast"),
272         ]),
273     ShaderNewNodeCategory("SH_NEW_OP_VECTOR", "Vector", items=[
274         NodeItem("ShaderNodeMapping"),
275         NodeItem("ShaderNodeBump"),
276         NodeItem("ShaderNodeDisplacement"),
277         NodeItem("ShaderNodeVectorDisplacement"),
278         NodeItem("ShaderNodeNormalMap"),
279         NodeItem("ShaderNodeNormal"),
280         NodeItem("ShaderNodeVectorCurve"),
281         NodeItem("ShaderNodeVectorTransform"),
282         ]),
283     ShaderNewNodeCategory("SH_NEW_CONVERTOR", "Converter", items=[
284         NodeItem("ShaderNodeMath"),
285         NodeItem("ShaderNodeValToRGB"),
286         NodeItem("ShaderNodeRGBToBW"),
287         NodeItem("ShaderNodeVectorMath"),
288         NodeItem("ShaderNodeSeparateRGB"),
289         NodeItem("ShaderNodeCombineRGB"),
290         NodeItem("ShaderNodeSeparateXYZ"),
291         NodeItem("ShaderNodeCombineXYZ"),
292         NodeItem("ShaderNodeSeparateHSV"),
293         NodeItem("ShaderNodeCombineHSV"),
294         NodeItem("ShaderNodeWavelength"),
295         NodeItem("ShaderNodeBlackbody"),
296         ]),
297     ShaderNewNodeCategory("SH_NEW_SCRIPT", "Script", items=[
298         NodeItem("ShaderNodeScript"),
299         ]),
300     ShaderNewNodeCategory("SH_NEW_GROUP", "Group", items=node_group_items),
301     ShaderNewNodeCategory("SH_NEW_LAYOUT", "Layout", items=[
302         NodeItem("NodeFrame"),
303         NodeItem("NodeReroute"),
304         ]),
305     ]
306
307 compositor_node_categories = [
308     # Compositor Nodes
309     CompositorNodeCategory("CMP_INPUT", "Input", items=[
310         NodeItem("CompositorNodeRLayers"),
311         NodeItem("CompositorNodeImage"),
312         NodeItem("CompositorNodeMovieClip"),
313         NodeItem("CompositorNodeMask"),
314         NodeItem("CompositorNodeRGB"),
315         NodeItem("CompositorNodeValue"),
316         NodeItem("CompositorNodeTexture"),
317         NodeItem("CompositorNodeBokehImage"),
318         NodeItem("CompositorNodeTime"),
319         NodeItem("CompositorNodeTrackPos"),
320         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
321         ]),
322     CompositorNodeCategory("CMP_OUTPUT", "Output", items=[
323         NodeItem("CompositorNodeComposite"),
324         NodeItem("CompositorNodeViewer"),
325         NodeItem("CompositorNodeSplitViewer"),
326         NodeItem("CompositorNodeOutputFile"),
327         NodeItem("CompositorNodeLevels"),
328         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
329         ]),
330     CompositorNodeCategory("CMP_OP_COLOR", "Color", items=[
331         NodeItem("CompositorNodeMixRGB"),
332         NodeItem("CompositorNodeAlphaOver"),
333         NodeItem("CompositorNodeInvert"),
334         NodeItem("CompositorNodeCurveRGB"),
335         NodeItem("CompositorNodeHueSat"),
336         NodeItem("CompositorNodeColorBalance"),
337         NodeItem("CompositorNodeHueCorrect"),
338         NodeItem("CompositorNodeBrightContrast"),
339         NodeItem("CompositorNodeGamma"),
340         NodeItem("CompositorNodeColorCorrection"),
341         NodeItem("CompositorNodeTonemap"),
342         NodeItem("CompositorNodeZcombine"),
343         ]),
344     CompositorNodeCategory("CMP_CONVERTOR", "Converter", items=[
345         NodeItem("CompositorNodeMath"),
346         NodeItem("CompositorNodeValToRGB"),
347         NodeItem("CompositorNodeSetAlpha"),
348         NodeItem("CompositorNodePremulKey"),
349         NodeItem("CompositorNodeIDMask"),
350         NodeItem("CompositorNodeRGBToBW"),
351         NodeItem("CompositorNodeSepRGBA"),
352         NodeItem("CompositorNodeCombRGBA"),
353         NodeItem("CompositorNodeSepHSVA"),
354         NodeItem("CompositorNodeCombHSVA"),
355         NodeItem("CompositorNodeSepYUVA"),
356         NodeItem("CompositorNodeCombYUVA"),
357         NodeItem("CompositorNodeSepYCCA"),
358         NodeItem("CompositorNodeCombYCCA"),
359         NodeItem("CompositorNodeSwitchView"),
360         ]),
361     CompositorNodeCategory("CMP_OP_FILTER", "Filter", items=[
362         NodeItem("CompositorNodeBlur"),
363         NodeItem("CompositorNodeBilateralblur"),
364         NodeItem("CompositorNodeDilateErode"),
365         NodeItem("CompositorNodeDespeckle"),
366         NodeItem("CompositorNodeFilter"),
367         NodeItem("CompositorNodeBokehBlur"),
368         NodeItem("CompositorNodeVecBlur"),
369         NodeItem("CompositorNodeDefocus"),
370         NodeItem("CompositorNodeGlare"),
371         NodeItem("CompositorNodeInpaint"),
372         NodeItem("CompositorNodeDBlur"),
373         NodeItem("CompositorNodePixelate"),
374         NodeItem("CompositorNodeSunBeams"),
375         ]),
376     CompositorNodeCategory("CMP_OP_VECTOR", "Vector", items=[
377         NodeItem("CompositorNodeNormal"),
378         NodeItem("CompositorNodeMapValue"),
379         NodeItem("CompositorNodeMapRange"),
380         NodeItem("CompositorNodeNormalize"),
381         NodeItem("CompositorNodeCurveVec"),
382         ]),
383     CompositorNodeCategory("CMP_MATTE", "Matte", items=[
384         NodeItem("CompositorNodeKeying"),
385         NodeItem("CompositorNodeKeyingScreen"),
386         NodeItem("CompositorNodeChannelMatte"),
387         NodeItem("CompositorNodeColorSpill"),
388         NodeItem("CompositorNodeBoxMask"),
389         NodeItem("CompositorNodeEllipseMask"),
390         NodeItem("CompositorNodeLumaMatte"),
391         NodeItem("CompositorNodeDiffMatte"),
392         NodeItem("CompositorNodeDistanceMatte"),
393         NodeItem("CompositorNodeChromaMatte"),
394         NodeItem("CompositorNodeColorMatte"),
395         NodeItem("CompositorNodeDoubleEdgeMask"),
396         ]),
397     CompositorNodeCategory("CMP_DISTORT", "Distort", items=[
398         NodeItem("CompositorNodeScale"),
399         NodeItem("CompositorNodeLensdist"),
400         NodeItem("CompositorNodeMovieDistortion"),
401         NodeItem("CompositorNodeTranslate"),
402         NodeItem("CompositorNodeRotate"),
403         NodeItem("CompositorNodeFlip"),
404         NodeItem("CompositorNodeCrop"),
405         NodeItem("CompositorNodeDisplace"),
406         NodeItem("CompositorNodeMapUV"),
407         NodeItem("CompositorNodeTransform"),
408         NodeItem("CompositorNodeStabilize"),
409         NodeItem("CompositorNodePlaneTrackDeform"),
410         NodeItem("CompositorNodeCornerPin"),
411         ]),
412     CompositorNodeCategory("CMP_GROUP", "Group", items=node_group_items),
413     CompositorNodeCategory("CMP_LAYOUT", "Layout", items=[
414         NodeItem("NodeFrame"),
415         NodeItem("NodeReroute"),
416         NodeItem("CompositorNodeSwitch"),
417         ]),
418     ]
419
420 texture_node_categories = [
421     # Texture Nodes
422     TextureNodeCategory("TEX_INPUT", "Input", items=[
423         NodeItem("TextureNodeCurveTime"),
424         NodeItem("TextureNodeCoordinates"),
425         NodeItem("TextureNodeTexture"),
426         NodeItem("TextureNodeImage"),
427         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
428         ]),
429     TextureNodeCategory("TEX_OUTPUT", "Output", items=[
430         NodeItem("TextureNodeOutput"),
431         NodeItem("TextureNodeViewer"),
432         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
433         ]),
434     TextureNodeCategory("TEX_OP_COLOR", "Color", items=[
435         NodeItem("TextureNodeMixRGB"),
436         NodeItem("TextureNodeCurveRGB"),
437         NodeItem("TextureNodeInvert"),
438         NodeItem("TextureNodeHueSaturation"),
439         NodeItem("TextureNodeCompose"),
440         NodeItem("TextureNodeDecompose"),
441         ]),
442     TextureNodeCategory("TEX_PATTERN", "Pattern", items=[
443         NodeItem("TextureNodeChecker"),
444         NodeItem("TextureNodeBricks"),
445         ]),
446     TextureNodeCategory("TEX_TEXTURE", "Textures", items=[
447         NodeItem("TextureNodeTexNoise"),
448         NodeItem("TextureNodeTexDistNoise"),
449         NodeItem("TextureNodeTexClouds"),
450         NodeItem("TextureNodeTexBlend"),
451         NodeItem("TextureNodeTexVoronoi"),
452         NodeItem("TextureNodeTexMagic"),
453         NodeItem("TextureNodeTexMarble"),
454         NodeItem("TextureNodeTexWood"),
455         NodeItem("TextureNodeTexMusgrave"),
456         NodeItem("TextureNodeTexStucci"),
457         ]),
458     TextureNodeCategory("TEX_CONVERTOR", "Converter", items=[
459         NodeItem("TextureNodeMath"),
460         NodeItem("TextureNodeValToRGB"),
461         NodeItem("TextureNodeRGBToBW"),
462         NodeItem("TextureNodeValToNor"),
463         NodeItem("TextureNodeDistance"),
464         ]),
465     TextureNodeCategory("TEX_DISTORT", "Distort", items=[
466         NodeItem("TextureNodeScale"),
467         NodeItem("TextureNodeTranslate"),
468         NodeItem("TextureNodeRotate"),
469         NodeItem("TextureNodeAt"),
470         ]),
471     TextureNodeCategory("TEX_GROUP", "Group", items=node_group_items),
472     TextureNodeCategory("TEX_LAYOUT", "Layout", items=[
473         NodeItem("NodeFrame"),
474         NodeItem("NodeReroute"),
475         ]),
476     ]
477
478
479 def register():
480     nodeitems_utils.register_node_categories('SHADER', shader_node_categories)
481     nodeitems_utils.register_node_categories('COMPOSITING', compositor_node_categories)
482     nodeitems_utils.register_node_categories('TEXTURE', texture_node_categories)
483
484
485 def unregister():
486     nodeitems_utils.unregister_node_categories('SHADER')
487     nodeitems_utils.unregister_node_categories('COMPOSITING')
488     nodeitems_utils.unregister_node_categories('TEXTURE')
489
490
491 if __name__ == "__main__":
492     register()