Cycles:
[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("ShaderNodeValue"),
115         NodeItem("ShaderNodeRGB"),
116         NodeItem("ShaderNodeTexture"),
117         NodeItem("ShaderNodeGeometry"),
118         NodeItem("ShaderNodeExtendedMaterial"),
119         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
120         ]),
121     ShaderOldNodeCategory("SH_OUTPUT", "Output", items=[
122         NodeItem("ShaderNodeOutput"),
123         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
124         ]),
125     ShaderOldNodeCategory("SH_OP_COLOR", "Color", items=[
126         NodeItem("ShaderNodeMixRGB"),
127         NodeItem("ShaderNodeRGBCurve"),
128         NodeItem("ShaderNodeInvert"),
129         NodeItem("ShaderNodeHueSaturation"),
130         ]),
131     ShaderOldNodeCategory("SH_OP_VECTOR", "Vector", items=[
132         NodeItem("ShaderNodeNormal"),
133         NodeItem("ShaderNodeMapping"),
134         NodeItem("ShaderNodeVectorCurve"),
135         ]),
136     ShaderOldNodeCategory("SH_CONVERTOR", "Converter", items=[
137         NodeItem("ShaderNodeValToRGB"),
138         NodeItem("ShaderNodeRGBToBW"),
139         NodeItem("ShaderNodeMath"),
140         NodeItem("ShaderNodeVectorMath"),
141         NodeItem("ShaderNodeSqueeze"),
142         NodeItem("ShaderNodeSeparateRGB"),
143         NodeItem("ShaderNodeCombineRGB"),
144         ]),
145     ShaderOldNodeCategory("SH_GROUP", "Group", items=node_group_items),
146     ShaderOldNodeCategory("SH_LAYOUT", "Layout", items=[
147         NodeItem("NodeFrame"),
148         NodeItem("NodeReroute"),
149         ]),
150
151     # New Shader Nodes (Cycles)
152     ShaderNewNodeCategory("SH_NEW_INPUT", "Input", items=[
153         NodeItem("ShaderNodeTexCoord"),
154         NodeItem("ShaderNodeAttribute"),
155         NodeItem("ShaderNodeLightPath"),
156         NodeItem("ShaderNodeFresnel"),
157         NodeItem("ShaderNodeLayerWeight"),
158         NodeItem("ShaderNodeRGB"),
159         NodeItem("ShaderNodeValue"),
160         NodeItem("ShaderNodeTangent"),
161         NodeItem("ShaderNodeNewGeometry"),
162         NodeItem("ShaderNodeWireframe"),
163         NodeItem("ShaderNodeObjectInfo"),
164         NodeItem("ShaderNodeHairInfo"),
165         NodeItem("ShaderNodeParticleInfo"),
166         NodeItem("ShaderNodeCameraData"),
167         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
168         ]),
169     ShaderNewNodeCategory("SH_NEW_OUTPUT", "Output", items=[
170         NodeItem("ShaderNodeOutputMaterial"),
171         NodeItem("ShaderNodeOutputLamp"),
172         NodeItem("ShaderNodeOutputWorld"),
173         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
174         ]),
175     ShaderNewNodeCategory("SH_NEW_SHADER", "Shader", items=[
176         NodeItem("ShaderNodeMixShader"),
177         NodeItem("ShaderNodeAddShader"),
178         NodeItem("ShaderNodeBsdfDiffuse"),
179         NodeItem("ShaderNodeBsdfGlossy"),
180         NodeItem("ShaderNodeBsdfTransparent"),
181         NodeItem("ShaderNodeBsdfRefraction"),
182         NodeItem("ShaderNodeBsdfGlass"),
183         NodeItem("ShaderNodeBsdfTranslucent"),
184         NodeItem("ShaderNodeBsdfAnisotropic"),
185         NodeItem("ShaderNodeBsdfVelvet"),
186         NodeItem("ShaderNodeBsdfToon"),
187         NodeItem("ShaderNodeSubsurfaceScattering"),
188         NodeItem("ShaderNodeEmission"),
189         NodeItem("ShaderNodeBackground"),
190         NodeItem("ShaderNodeAmbientOcclusion"),
191         NodeItem("ShaderNodeHoldout"),
192         ]),
193     ShaderNewNodeCategory("SH_NEW_TEXTURE", "Texture", items=[
194         NodeItem("ShaderNodeTexImage"),
195         NodeItem("ShaderNodeTexEnvironment"),
196         NodeItem("ShaderNodeTexSky"),
197         NodeItem("ShaderNodeTexNoise"),
198         NodeItem("ShaderNodeTexWave"),
199         NodeItem("ShaderNodeTexVoronoi"),
200         NodeItem("ShaderNodeTexMusgrave"),
201         NodeItem("ShaderNodeTexGradient"),
202         NodeItem("ShaderNodeTexMagic"),
203         NodeItem("ShaderNodeTexChecker"),
204         NodeItem("ShaderNodeTexBrick"),
205         ]),
206     ShaderNewNodeCategory("SH_NEW_OP_COLOR", "Color", items=[
207         NodeItem("ShaderNodeMixRGB"),
208         NodeItem("ShaderNodeRGBCurve"),
209         NodeItem("ShaderNodeInvert"),
210         NodeItem("ShaderNodeLightFalloff"),
211         NodeItem("ShaderNodeHueSaturation"),
212         NodeItem("ShaderNodeGamma"),
213         NodeItem("ShaderNodeBrightContrast"),
214         ]),
215     ShaderNewNodeCategory("SH_NEW_OP_VECTOR", "Vector", items=[
216         NodeItem("ShaderNodeMapping"),
217         NodeItem("ShaderNodeBump"),
218         NodeItem("ShaderNodeNormalMap"),
219         NodeItem("ShaderNodeNormal"),
220         NodeItem("ShaderNodeVectorCurve"),
221         NodeItem("ShaderNodeVectorTransform"),
222         ]),
223     ShaderNewNodeCategory("SH_NEW_CONVERTOR", "Converter", items=[
224         NodeItem("ShaderNodeMath"),
225         NodeItem("ShaderNodeValToRGB"),
226         NodeItem("ShaderNodeRGBToBW"),
227         NodeItem("ShaderNodeVectorMath"),
228         NodeItem("ShaderNodeSeparateRGB"),
229         NodeItem("ShaderNodeCombineRGB"),
230         NodeItem("ShaderNodeSeparateHSV"),
231         NodeItem("ShaderNodeCombineHSV"),
232         NodeItem("ShaderNodeWavelength"),
233         NodeItem("ShaderNodeBlackbody"),
234         ]),
235     ShaderNewNodeCategory("SH_NEW_SCRIPT", "Script", items=[
236         NodeItem("ShaderNodeScript"),
237         ]),
238     ShaderNewNodeCategory("SH_NEW_GROUP", "Group", items=node_group_items),
239     ShaderNewNodeCategory("SH_NEW_LAYOUT", "Layout", items=[
240         NodeItem("NodeFrame"),
241         NodeItem("NodeReroute"),
242         ]),
243     ]
244
245 compositor_node_categories = [
246     # Compositor Nodes
247     CompositorNodeCategory("CMP_INPUT", "Input", items=[
248         NodeItem("CompositorNodeRLayers"),
249         NodeItem("CompositorNodeImage"),
250         NodeItem("CompositorNodeMovieClip"),
251         NodeItem("CompositorNodeMask"),
252         NodeItem("CompositorNodeRGB"),
253         NodeItem("CompositorNodeValue"),
254         NodeItem("CompositorNodeTexture"),
255         NodeItem("CompositorNodeBokehImage"),
256         NodeItem("CompositorNodeTime"),
257         NodeItem("CompositorNodeTrackPos"),
258         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
259         ]),
260     CompositorNodeCategory("CMP_OUTPUT", "Output", items=[
261         NodeItem("CompositorNodeComposite"),
262         NodeItem("CompositorNodeViewer"),
263         NodeItem("CompositorNodeSplitViewer"),
264         NodeItem("CompositorNodeOutputFile"),
265         NodeItem("CompositorNodeLevels"),
266         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
267         ]),
268     CompositorNodeCategory("CMP_OP_COLOR", "Color", items=[
269         NodeItem("CompositorNodeMixRGB"),
270         NodeItem("CompositorNodeAlphaOver"),
271         NodeItem("CompositorNodeInvert"),
272         NodeItem("CompositorNodeCurveRGB"),
273         NodeItem("CompositorNodeHueSat"),
274         NodeItem("CompositorNodeColorBalance"),
275         NodeItem("CompositorNodeHueCorrect"),
276         NodeItem("CompositorNodeBrightContrast"),
277         NodeItem("CompositorNodeGamma"),
278         NodeItem("CompositorNodeColorCorrection"),
279         NodeItem("CompositorNodeTonemap"),
280         NodeItem("CompositorNodeZcombine"),
281         ]),
282     CompositorNodeCategory("CMP_CONVERTOR", "Converter", items=[
283         NodeItem("CompositorNodeMath"),
284         NodeItem("CompositorNodeValToRGB"),
285         NodeItem("CompositorNodeSetAlpha"),
286         NodeItem("CompositorNodePremulKey"),
287         NodeItem("CompositorNodeIDMask"),
288         NodeItem("CompositorNodeRGBToBW"),
289         NodeItem("CompositorNodeSepRGBA"),
290         NodeItem("CompositorNodeCombRGBA"),
291         NodeItem("CompositorNodeSepHSVA"),
292         NodeItem("CompositorNodeCombHSVA"),
293         NodeItem("CompositorNodeSepYUVA"),
294         NodeItem("CompositorNodeCombYUVA"),
295         NodeItem("CompositorNodeSepYCCA"),
296         NodeItem("CompositorNodeCombYCCA"),
297         ]),
298     CompositorNodeCategory("CMP_OP_FILTER", "Filter", items=[
299         NodeItem("CompositorNodeBlur"),
300         NodeItem("CompositorNodeBilateralblur"),
301         NodeItem("CompositorNodeDilateErode"),
302         NodeItem("CompositorNodeDespeckle"),
303         NodeItem("CompositorNodeFilter"),
304         NodeItem("CompositorNodeBokehBlur"),
305         NodeItem("CompositorNodeVecBlur"),
306         NodeItem("CompositorNodeDefocus"),
307         NodeItem("CompositorNodeGlare"),
308         NodeItem("CompositorNodeInpaint"),
309         NodeItem("CompositorNodeDBlur"),
310         NodeItem("CompositorNodePixelate"),
311         ]),
312     CompositorNodeCategory("CMP_OP_VECTOR", "Vector", items=[
313         NodeItem("CompositorNodeNormal"),
314         NodeItem("CompositorNodeMapValue"),
315         NodeItem("CompositorNodeMapRange"),
316         NodeItem("CompositorNodeNormalize"),
317         NodeItem("CompositorNodeCurveVec"),
318         ]),
319     CompositorNodeCategory("CMP_MATTE", "Matte", items=[
320         NodeItem("CompositorNodeKeying"),
321         NodeItem("CompositorNodeKeyingScreen"),
322         NodeItem("CompositorNodeChannelMatte"),
323         NodeItem("CompositorNodeColorSpill"),
324         NodeItem("CompositorNodeBoxMask"),
325         NodeItem("CompositorNodeEllipseMask"),
326         NodeItem("CompositorNodeLumaMatte"),
327         NodeItem("CompositorNodeDiffMatte"),
328         NodeItem("CompositorNodeDistanceMatte"),
329         NodeItem("CompositorNodeChromaMatte"),
330         NodeItem("CompositorNodeColorMatte"),
331         NodeItem("CompositorNodeDoubleEdgeMask"),
332         ]),
333     CompositorNodeCategory("CMP_DISTORT", "Distort", items=[
334         NodeItem("CompositorNodeScale"),
335         NodeItem("CompositorNodeLensdist"),
336         NodeItem("CompositorNodeMovieDistortion"),
337         NodeItem("CompositorNodeTranslate"),
338         NodeItem("CompositorNodeRotate"),
339         NodeItem("CompositorNodeFlip"),
340         NodeItem("CompositorNodeCrop"),
341         NodeItem("CompositorNodeDisplace"),
342         NodeItem("CompositorNodeMapUV"),
343         NodeItem("CompositorNodeTransform"),
344         NodeItem("CompositorNodeStabilize"),
345         ]),
346     CompositorNodeCategory("CMP_GROUP", "Group", items=node_group_items),
347     CompositorNodeCategory("CMP_LAYOUT", "Layout", items=[
348         NodeItem("NodeFrame"),
349         NodeItem("NodeReroute"),
350         NodeItem("CompositorNodeSwitch"),
351         ]),
352     ]
353
354 texture_node_categories = [
355     # Texture Nodes
356     TextureNodeCategory("TEX_INPUT", "Input", items=[
357         NodeItem("TextureNodeCurveTime"),
358         NodeItem("TextureNodeCoordinates"),
359         NodeItem("TextureNodeTexture"),
360         NodeItem("TextureNodeImage"),
361         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
362         ]),
363     TextureNodeCategory("TEX_OUTPUT", "Output", items=[
364         NodeItem("TextureNodeOutput"),
365         NodeItem("TextureNodeViewer"),
366         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
367         ]),
368     TextureNodeCategory("TEX_OP_COLOR", "Color", items=[
369         NodeItem("TextureNodeMixRGB"),
370         NodeItem("TextureNodeCurveRGB"),
371         NodeItem("TextureNodeInvert"),
372         NodeItem("TextureNodeHueSaturation"),
373         NodeItem("TextureNodeCompose"),
374         NodeItem("TextureNodeDecompose"),
375         ]),
376     TextureNodeCategory("TEX_PATTERN", "Pattern", items=[
377         NodeItem("TextureNodeChecker"),
378         NodeItem("TextureNodeBricks"),
379         ]),
380     TextureNodeCategory("TEX_TEXTURE", "Textures", items=[
381         NodeItem("TextureNodeTexNoise"),
382         NodeItem("TextureNodeTexDistNoise"),
383         NodeItem("TextureNodeTexClouds"),
384         NodeItem("TextureNodeTexBlend"),
385         NodeItem("TextureNodeTexVoronoi"),
386         NodeItem("TextureNodeTexMagic"),
387         NodeItem("TextureNodeTexMarble"),
388         NodeItem("TextureNodeTexWood"),
389         NodeItem("TextureNodeTexMusgrave"),
390         NodeItem("TextureNodeTexStucci"),
391         ]),
392     TextureNodeCategory("TEX_CONVERTOR", "Converter", items=[
393         NodeItem("TextureNodeMath"),
394         NodeItem("TextureNodeValToRGB"),
395         NodeItem("TextureNodeRGBToBW"),
396         NodeItem("TextureNodeValToNor"),
397         NodeItem("TextureNodeDistance"),
398         ]),
399     TextureNodeCategory("TEX_DISTORT", "Distort", items=[
400         NodeItem("TextureNodeScale"),
401         NodeItem("TextureNodeTranslate"),
402         NodeItem("TextureNodeRotate"),
403         ]),
404     TextureNodeCategory("TEX_GROUP", "Group", items=node_group_items),
405     TextureNodeCategory("TEX_LAYOUT", "Layout", items=[
406         NodeItem("NodeFrame"),
407         NodeItem("NodeReroute"),
408         ]),
409     ]
410
411
412 def register():
413     nodeitems_utils.register_node_categories('SHADER', shader_node_categories)
414     nodeitems_utils.register_node_categories('COMPOSITING', compositor_node_categories)
415     nodeitems_utils.register_node_categories('TEXTURE', texture_node_categories)
416
417
418 def unregister():
419     nodeitems_utils.unregister_node_categories('SHADER')
420     nodeitems_utils.unregister_node_categories('COMPOSITING')
421     nodeitems_utils.unregister_node_categories('TEXTURE')
422
423
424 if __name__ == "__main__":
425     register()