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