Cycles: add dedicated UV Map node, easier to find and has convenient auto complete.
[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 NodeCategory, NodeItem, NodeItemCustom
23
24
25 # Subclasses for standard node types
26
27 class CompositorNodeCategory(NodeCategory):
28     @classmethod
29     def poll(cls, context):
30         return (context.space_data.tree_type == 'CompositorNodeTree')
31
32
33 class ShaderNewNodeCategory(NodeCategory):
34     @classmethod
35     def poll(cls, context):
36         return (context.space_data.tree_type == 'ShaderNodeTree' and
37                 context.scene.render.use_shading_nodes)
38
39
40 class ShaderOldNodeCategory(NodeCategory):
41     @classmethod
42     def poll(cls, context):
43         return (context.space_data.tree_type == 'ShaderNodeTree' and
44                 not context.scene.render.use_shading_nodes)
45
46
47 class TextureNodeCategory(NodeCategory):
48     @classmethod
49     def poll(cls, context):
50         return context.space_data.tree_type == 'TextureNodeTree'
51
52
53 # menu entry for making a new group from selected nodes
54 def group_make_draw(self, layout, context):
55     layout.operator("node.group_make")
56     layout.separator()
57
58 # maps node tree type to group node type
59 node_tree_group_type = {
60     'CompositorNodeTree': 'CompositorNodeGroup',
61     'ShaderNodeTree': 'ShaderNodeGroup',
62     'TextureNodeTree': 'TextureNodeGroup',
63     }
64
65
66 # generic node group items generator for shader, compositor and texture node groups
67 def node_group_items(context):
68     space = context.space_data
69     if not space:
70         return
71     ntree = space.edit_tree
72     if not ntree:
73         return
74
75     yield NodeItemCustom(draw=group_make_draw)
76
77     def contains_group(nodetree, group):
78         if nodetree == group:
79             return True
80         else:
81             for node in nodetree.nodes:
82                 if node.bl_idname in node_tree_group_type.values() and node.node_tree is not None:
83                     if contains_group(node.node_tree, group):
84                         return True
85         return False
86
87     for group in context.blend_data.node_groups:
88         if group.bl_idname != ntree.bl_idname:
89             continue
90         # filter out recursive groups
91         if contains_group(group, ntree):
92             continue
93
94         yield NodeItem(node_tree_group_type[group.bl_idname],
95                        group.name,
96                        {"node_tree": "bpy.data.node_groups[%r]" % group.name})
97
98
99 # only show input/output nodes inside node groups
100 def group_input_output_item_poll(context):
101     space = context.space_data
102     if space.edit_tree in bpy.data.node_groups.values():
103         return True
104     return False
105
106
107 # All standard node categories currently used in nodes.
108
109 shader_node_categories = [
110     # Shader Nodes
111     ShaderOldNodeCategory("SH_INPUT", "Input", items=[
112         NodeItem("ShaderNodeMaterial"),
113         NodeItem("ShaderNodeCameraData"),
114         NodeItem("ShaderNodeLampData"),
115         NodeItem("ShaderNodeValue"),
116         NodeItem("ShaderNodeRGB"),
117         NodeItem("ShaderNodeTexture"),
118         NodeItem("ShaderNodeGeometry"),
119         NodeItem("ShaderNodeExtendedMaterial"),
120         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
121         ]),
122     ShaderOldNodeCategory("SH_OUTPUT", "Output", items=[
123         NodeItem("ShaderNodeOutput"),
124         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
125         ]),
126     ShaderOldNodeCategory("SH_OP_COLOR", "Color", items=[
127         NodeItem("ShaderNodeMixRGB"),
128         NodeItem("ShaderNodeRGBCurve"),
129         NodeItem("ShaderNodeInvert"),
130         NodeItem("ShaderNodeHueSaturation"),
131         ]),
132     ShaderOldNodeCategory("SH_OP_VECTOR", "Vector", items=[
133         NodeItem("ShaderNodeNormal"),
134         NodeItem("ShaderNodeMapping"),
135         NodeItem("ShaderNodeVectorCurve"),
136         ]),
137     ShaderOldNodeCategory("SH_CONVERTOR", "Converter", items=[
138         NodeItem("ShaderNodeValToRGB"),
139         NodeItem("ShaderNodeRGBToBW"),
140         NodeItem("ShaderNodeMath"),
141         NodeItem("ShaderNodeVectorMath"),
142         NodeItem("ShaderNodeSqueeze"),
143         NodeItem("ShaderNodeSeparateRGB"),
144         NodeItem("ShaderNodeCombineRGB"),
145         NodeItem("ShaderNodeSeparateHSV"),
146         NodeItem("ShaderNodeCombineHSV"),
147         ]),
148     ShaderOldNodeCategory("SH_GROUP", "Group", items=node_group_items),
149     ShaderOldNodeCategory("SH_LAYOUT", "Layout", items=[
150         NodeItem("NodeFrame"),
151         NodeItem("NodeReroute"),
152         ]),
153
154     # New Shader Nodes (Cycles)
155     ShaderNewNodeCategory("SH_NEW_INPUT", "Input", items=[
156         NodeItem("ShaderNodeTexCoord"),
157         NodeItem("ShaderNodeAttribute"),
158         NodeItem("ShaderNodeLightPath"),
159         NodeItem("ShaderNodeFresnel"),
160         NodeItem("ShaderNodeLayerWeight"),
161         NodeItem("ShaderNodeRGB"),
162         NodeItem("ShaderNodeValue"),
163         NodeItem("ShaderNodeTangent"),
164         NodeItem("ShaderNodeNewGeometry"),
165         NodeItem("ShaderNodeWireframe"),
166         NodeItem("ShaderNodeObjectInfo"),
167         NodeItem("ShaderNodeHairInfo"),
168         NodeItem("ShaderNodeParticleInfo"),
169         NodeItem("ShaderNodeCameraData"),
170         NodeItem("ShaderNodeUVMap"),
171         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
172         ]),
173     ShaderNewNodeCategory("SH_NEW_OUTPUT", "Output", items=[
174         NodeItem("ShaderNodeOutputMaterial"),
175         NodeItem("ShaderNodeOutputLamp"),
176         NodeItem("ShaderNodeOutputWorld"),
177         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
178         ]),
179     ShaderNewNodeCategory("SH_NEW_SHADER", "Shader", items=[
180         NodeItem("ShaderNodeMixShader"),
181         NodeItem("ShaderNodeAddShader"),
182         NodeItem("ShaderNodeBsdfDiffuse"),
183         NodeItem("ShaderNodeBsdfGlossy"),
184         NodeItem("ShaderNodeBsdfTransparent"),
185         NodeItem("ShaderNodeBsdfRefraction"),
186         NodeItem("ShaderNodeBsdfGlass"),
187         NodeItem("ShaderNodeBsdfTranslucent"),
188         NodeItem("ShaderNodeBsdfAnisotropic"),
189         NodeItem("ShaderNodeBsdfVelvet"),
190         NodeItem("ShaderNodeBsdfToon"),
191         NodeItem("ShaderNodeSubsurfaceScattering"),
192         NodeItem("ShaderNodeEmission"),
193         NodeItem("ShaderNodeBsdfHair"),
194         NodeItem("ShaderNodeBackground"),
195         NodeItem("ShaderNodeAmbientOcclusion"),
196         NodeItem("ShaderNodeHoldout"),
197         NodeItem("ShaderNodeVolumeAbsorption"),
198         NodeItem("ShaderNodeVolumeScatter"),
199         ]),
200     ShaderNewNodeCategory("SH_NEW_TEXTURE", "Texture", items=[
201         NodeItem("ShaderNodeTexImage"),
202         NodeItem("ShaderNodeTexEnvironment"),
203         NodeItem("ShaderNodeTexSky"),
204         NodeItem("ShaderNodeTexNoise"),
205         NodeItem("ShaderNodeTexWave"),
206         NodeItem("ShaderNodeTexVoronoi"),
207         NodeItem("ShaderNodeTexMusgrave"),
208         NodeItem("ShaderNodeTexGradient"),
209         NodeItem("ShaderNodeTexMagic"),
210         NodeItem("ShaderNodeTexChecker"),
211         NodeItem("ShaderNodeTexBrick"),
212         ]),
213     ShaderNewNodeCategory("SH_NEW_OP_COLOR", "Color", items=[
214         NodeItem("ShaderNodeMixRGB"),
215         NodeItem("ShaderNodeRGBCurve"),
216         NodeItem("ShaderNodeInvert"),
217         NodeItem("ShaderNodeLightFalloff"),
218         NodeItem("ShaderNodeHueSaturation"),
219         NodeItem("ShaderNodeGamma"),
220         NodeItem("ShaderNodeBrightContrast"),
221         ]),
222     ShaderNewNodeCategory("SH_NEW_OP_VECTOR", "Vector", items=[
223         NodeItem("ShaderNodeMapping"),
224         NodeItem("ShaderNodeBump"),
225         NodeItem("ShaderNodeNormalMap"),
226         NodeItem("ShaderNodeNormal"),
227         NodeItem("ShaderNodeVectorCurve"),
228         NodeItem("ShaderNodeVectorTransform"),
229         ]),
230     ShaderNewNodeCategory("SH_NEW_CONVERTOR", "Converter", items=[
231         NodeItem("ShaderNodeMath"),
232         NodeItem("ShaderNodeValToRGB"),
233         NodeItem("ShaderNodeRGBToBW"),
234         NodeItem("ShaderNodeVectorMath"),
235         NodeItem("ShaderNodeSeparateRGB"),
236         NodeItem("ShaderNodeCombineRGB"),
237         NodeItem("ShaderNodeSeparateHSV"),
238         NodeItem("ShaderNodeCombineHSV"),
239         NodeItem("ShaderNodeWavelength"),
240         NodeItem("ShaderNodeBlackbody"),
241         ]),
242     ShaderNewNodeCategory("SH_NEW_SCRIPT", "Script", items=[
243         NodeItem("ShaderNodeScript"),
244         ]),
245     ShaderNewNodeCategory("SH_NEW_GROUP", "Group", items=node_group_items),
246     ShaderNewNodeCategory("SH_NEW_LAYOUT", "Layout", items=[
247         NodeItem("NodeFrame"),
248         NodeItem("NodeReroute"),
249         ]),
250     ]
251
252 compositor_node_categories = [
253     # Compositor Nodes
254     CompositorNodeCategory("CMP_INPUT", "Input", items=[
255         NodeItem("CompositorNodeRLayers"),
256         NodeItem("CompositorNodeImage"),
257         NodeItem("CompositorNodeMovieClip"),
258         NodeItem("CompositorNodeMask"),
259         NodeItem("CompositorNodeRGB"),
260         NodeItem("CompositorNodeValue"),
261         NodeItem("CompositorNodeTexture"),
262         NodeItem("CompositorNodeBokehImage"),
263         NodeItem("CompositorNodeTime"),
264         NodeItem("CompositorNodeTrackPos"),
265         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
266         ]),
267     CompositorNodeCategory("CMP_OUTPUT", "Output", items=[
268         NodeItem("CompositorNodeComposite"),
269         NodeItem("CompositorNodeViewer"),
270         NodeItem("CompositorNodeSplitViewer"),
271         NodeItem("CompositorNodeOutputFile"),
272         NodeItem("CompositorNodeLevels"),
273         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
274         ]),
275     CompositorNodeCategory("CMP_OP_COLOR", "Color", items=[
276         NodeItem("CompositorNodeMixRGB"),
277         NodeItem("CompositorNodeAlphaOver"),
278         NodeItem("CompositorNodeInvert"),
279         NodeItem("CompositorNodeCurveRGB"),
280         NodeItem("CompositorNodeHueSat"),
281         NodeItem("CompositorNodeColorBalance"),
282         NodeItem("CompositorNodeHueCorrect"),
283         NodeItem("CompositorNodeBrightContrast"),
284         NodeItem("CompositorNodeGamma"),
285         NodeItem("CompositorNodeColorCorrection"),
286         NodeItem("CompositorNodeTonemap"),
287         NodeItem("CompositorNodeZcombine"),
288         ]),
289     CompositorNodeCategory("CMP_CONVERTOR", "Converter", items=[
290         NodeItem("CompositorNodeMath"),
291         NodeItem("CompositorNodeValToRGB"),
292         NodeItem("CompositorNodeSetAlpha"),
293         NodeItem("CompositorNodePremulKey"),
294         NodeItem("CompositorNodeIDMask"),
295         NodeItem("CompositorNodeRGBToBW"),
296         NodeItem("CompositorNodeSepRGBA"),
297         NodeItem("CompositorNodeCombRGBA"),
298         NodeItem("CompositorNodeSepHSVA"),
299         NodeItem("CompositorNodeCombHSVA"),
300         NodeItem("CompositorNodeSepYUVA"),
301         NodeItem("CompositorNodeCombYUVA"),
302         NodeItem("CompositorNodeSepYCCA"),
303         NodeItem("CompositorNodeCombYCCA"),
304         ]),
305     CompositorNodeCategory("CMP_OP_FILTER", "Filter", items=[
306         NodeItem("CompositorNodeBlur"),
307         NodeItem("CompositorNodeBilateralblur"),
308         NodeItem("CompositorNodeDilateErode"),
309         NodeItem("CompositorNodeDespeckle"),
310         NodeItem("CompositorNodeFilter"),
311         NodeItem("CompositorNodeBokehBlur"),
312         NodeItem("CompositorNodeVecBlur"),
313         NodeItem("CompositorNodeDefocus"),
314         NodeItem("CompositorNodeGlare"),
315         NodeItem("CompositorNodeInpaint"),
316         NodeItem("CompositorNodeDBlur"),
317         NodeItem("CompositorNodePixelate"),
318         ]),
319     CompositorNodeCategory("CMP_OP_VECTOR", "Vector", items=[
320         NodeItem("CompositorNodeNormal"),
321         NodeItem("CompositorNodeMapValue"),
322         NodeItem("CompositorNodeMapRange"),
323         NodeItem("CompositorNodeNormalize"),
324         NodeItem("CompositorNodeCurveVec"),
325         ]),
326     CompositorNodeCategory("CMP_MATTE", "Matte", items=[
327         NodeItem("CompositorNodeKeying"),
328         NodeItem("CompositorNodeKeyingScreen"),
329         NodeItem("CompositorNodeChannelMatte"),
330         NodeItem("CompositorNodeColorSpill"),
331         NodeItem("CompositorNodeBoxMask"),
332         NodeItem("CompositorNodeEllipseMask"),
333         NodeItem("CompositorNodeLumaMatte"),
334         NodeItem("CompositorNodeDiffMatte"),
335         NodeItem("CompositorNodeDistanceMatte"),
336         NodeItem("CompositorNodeChromaMatte"),
337         NodeItem("CompositorNodeColorMatte"),
338         NodeItem("CompositorNodeDoubleEdgeMask"),
339         ]),
340     CompositorNodeCategory("CMP_DISTORT", "Distort", items=[
341         NodeItem("CompositorNodeScale"),
342         NodeItem("CompositorNodeLensdist"),
343         NodeItem("CompositorNodeMovieDistortion"),
344         NodeItem("CompositorNodeTranslate"),
345         NodeItem("CompositorNodeRotate"),
346         NodeItem("CompositorNodeFlip"),
347         NodeItem("CompositorNodeCrop"),
348         NodeItem("CompositorNodeDisplace"),
349         NodeItem("CompositorNodeMapUV"),
350         NodeItem("CompositorNodeTransform"),
351         NodeItem("CompositorNodeStabilize"),
352         NodeItem("CompositorNodePlaneTrackDeform"),
353         NodeItem("CompositorNodeCornerPin"),
354         ]),
355     CompositorNodeCategory("CMP_GROUP", "Group", items=node_group_items),
356     CompositorNodeCategory("CMP_LAYOUT", "Layout", items=[
357         NodeItem("NodeFrame"),
358         NodeItem("NodeReroute"),
359         NodeItem("CompositorNodeSwitch"),
360         ]),
361     ]
362
363 texture_node_categories = [
364     # Texture Nodes
365     TextureNodeCategory("TEX_INPUT", "Input", items=[
366         NodeItem("TextureNodeCurveTime"),
367         NodeItem("TextureNodeCoordinates"),
368         NodeItem("TextureNodeTexture"),
369         NodeItem("TextureNodeImage"),
370         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
371         ]),
372     TextureNodeCategory("TEX_OUTPUT", "Output", items=[
373         NodeItem("TextureNodeOutput"),
374         NodeItem("TextureNodeViewer"),
375         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
376         ]),
377     TextureNodeCategory("TEX_OP_COLOR", "Color", items=[
378         NodeItem("TextureNodeMixRGB"),
379         NodeItem("TextureNodeCurveRGB"),
380         NodeItem("TextureNodeInvert"),
381         NodeItem("TextureNodeHueSaturation"),
382         NodeItem("TextureNodeCompose"),
383         NodeItem("TextureNodeDecompose"),
384         ]),
385     TextureNodeCategory("TEX_PATTERN", "Pattern", items=[
386         NodeItem("TextureNodeChecker"),
387         NodeItem("TextureNodeBricks"),
388         ]),
389     TextureNodeCategory("TEX_TEXTURE", "Textures", items=[
390         NodeItem("TextureNodeTexNoise"),
391         NodeItem("TextureNodeTexDistNoise"),
392         NodeItem("TextureNodeTexClouds"),
393         NodeItem("TextureNodeTexBlend"),
394         NodeItem("TextureNodeTexVoronoi"),
395         NodeItem("TextureNodeTexMagic"),
396         NodeItem("TextureNodeTexMarble"),
397         NodeItem("TextureNodeTexWood"),
398         NodeItem("TextureNodeTexMusgrave"),
399         NodeItem("TextureNodeTexStucci"),
400         ]),
401     TextureNodeCategory("TEX_CONVERTOR", "Converter", items=[
402         NodeItem("TextureNodeMath"),
403         NodeItem("TextureNodeValToRGB"),
404         NodeItem("TextureNodeRGBToBW"),
405         NodeItem("TextureNodeValToNor"),
406         NodeItem("TextureNodeDistance"),
407         ]),
408     TextureNodeCategory("TEX_DISTORT", "Distort", items=[
409         NodeItem("TextureNodeScale"),
410         NodeItem("TextureNodeTranslate"),
411         NodeItem("TextureNodeRotate"),
412         NodeItem("TextureNodeAt"),
413         ]),
414     TextureNodeCategory("TEX_GROUP", "Group", items=node_group_items),
415     TextureNodeCategory("TEX_LAYOUT", "Layout", items=[
416         NodeItem("NodeFrame"),
417         NodeItem("NodeReroute"),
418         ]),
419     ]
420
421
422 def register():
423     nodeitems_utils.register_node_categories('SHADER', shader_node_categories)
424     nodeitems_utils.register_node_categories('COMPOSITING', compositor_node_categories)
425     nodeitems_utils.register_node_categories('TEXTURE', texture_node_categories)
426
427
428 def unregister():
429     nodeitems_utils.unregister_node_categories('SHADER')
430     nodeitems_utils.unregister_node_categories('COMPOSITING')
431     nodeitems_utils.unregister_node_categories('TEXTURE')
432
433
434 if __name__ == "__main__":
435     register()