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