nodeitems_builtins.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. # <pep8 compliant>
  19. import bpy
  20. import nodeitems_utils
  21. from nodeitems_utils import (
  22. NodeCategory,
  23. NodeItem,
  24. NodeItemCustom,
  25. )
  26. # Subclasses for standard node types
  27. class SortedNodeCategory(NodeCategory):
  28. def __init__(self, identifier, name, description="", items=None):
  29. # for builtin nodes the convention is to sort by name
  30. if isinstance(items, list):
  31. items = sorted(items, key=lambda item: item.label.lower())
  32. super().__init__(identifier, name, description, items)
  33. class CompositorNodeCategory(SortedNodeCategory):
  34. @classmethod
  35. def poll(cls, context):
  36. return (context.space_data.type == 'NODE_EDITOR' and
  37. context.space_data.tree_type == 'CompositorNodeTree')
  38. class ShaderNodeCategory(SortedNodeCategory):
  39. @classmethod
  40. def poll(cls, context):
  41. return (context.space_data.type == 'NODE_EDITOR' and
  42. context.space_data.tree_type == 'ShaderNodeTree')
  43. class TextureNodeCategory(SortedNodeCategory):
  44. @classmethod
  45. def poll(cls, context):
  46. return (context.space_data.type == 'NODE_EDITOR' and
  47. context.space_data.tree_type == 'TextureNodeTree')
  48. # menu entry for node group tools
  49. def group_tools_draw(self, layout, context):
  50. layout.operator("node.group_make")
  51. layout.operator("node.group_ungroup")
  52. layout.separator()
  53. # maps node tree type to group node type
  54. node_tree_group_type = {
  55. 'CompositorNodeTree': 'CompositorNodeGroup',
  56. 'ShaderNodeTree': 'ShaderNodeGroup',
  57. 'TextureNodeTree': 'TextureNodeGroup',
  58. }
  59. # generic node group items generator for shader, compositor and texture node groups
  60. def node_group_items(context):
  61. if context is None:
  62. return
  63. space = context.space_data
  64. if not space:
  65. return
  66. ntree = space.edit_tree
  67. if not ntree:
  68. return
  69. yield NodeItemCustom(draw=group_tools_draw)
  70. def contains_group(nodetree, group):
  71. if nodetree == group:
  72. return True
  73. else:
  74. for node in nodetree.nodes:
  75. if node.bl_idname in node_tree_group_type.values() and node.node_tree is not None:
  76. if contains_group(node.node_tree, group):
  77. return True
  78. return False
  79. for group in context.blend_data.node_groups:
  80. if group.bl_idname != ntree.bl_idname:
  81. continue
  82. # filter out recursive groups
  83. if contains_group(group, ntree):
  84. continue
  85. # filter out hidden nodetrees
  86. if group.name.startswith('.'):
  87. continue
  88. yield NodeItem(node_tree_group_type[group.bl_idname],
  89. group.name,
  90. {"node_tree": "bpy.data.node_groups[%r]" % group.name})
  91. # only show input/output nodes inside node groups
  92. def group_input_output_item_poll(context):
  93. space = context.space_data
  94. if space.edit_tree in bpy.data.node_groups.values():
  95. return True
  96. return False
  97. # only show input/output nodes when editing line style node trees
  98. def line_style_shader_nodes_poll(context):
  99. snode = context.space_data
  100. return (snode.tree_type == 'ShaderNodeTree' and
  101. snode.shader_type == 'LINESTYLE')
  102. # only show nodes working in world node trees
  103. def world_shader_nodes_poll(context):
  104. snode = context.space_data
  105. return (snode.tree_type == 'ShaderNodeTree' and
  106. snode.shader_type == 'WORLD')
  107. # only show nodes working in object node trees
  108. def object_shader_nodes_poll(context):
  109. snode = context.space_data
  110. return (snode.tree_type == 'ShaderNodeTree' and
  111. snode.shader_type == 'OBJECT')
  112. def cycles_shader_nodes_poll(context):
  113. return context.engine == 'CYCLES'
  114. def eevee_shader_nodes_poll(context):
  115. return context.engine == 'BLENDER_EEVEE'
  116. def eevee_cycles_shader_nodes_poll(context):
  117. return (cycles_shader_nodes_poll(context) or
  118. eevee_shader_nodes_poll(context))
  119. def object_cycles_shader_nodes_poll(context):
  120. return (object_shader_nodes_poll(context) and
  121. cycles_shader_nodes_poll(context))
  122. def object_eevee_shader_nodes_poll(context):
  123. return (object_shader_nodes_poll(context) and
  124. eevee_shader_nodes_poll(context))
  125. def object_eevee_cycles_shader_nodes_poll(context):
  126. return (object_shader_nodes_poll(context) and
  127. eevee_cycles_shader_nodes_poll(context))
  128. # All standard node categories currently used in nodes.
  129. shader_node_categories = [
  130. # Shader Nodes (Cycles and Eevee)
  131. ShaderNodeCategory("SH_NEW_INPUT", "Input", items=[
  132. NodeItem("ShaderNodeTexCoord"),
  133. NodeItem("ShaderNodeAttribute"),
  134. NodeItem("ShaderNodeLightPath"),
  135. NodeItem("ShaderNodeFresnel"),
  136. NodeItem("ShaderNodeLayerWeight"),
  137. NodeItem("ShaderNodeRGB"),
  138. NodeItem("ShaderNodeValue"),
  139. NodeItem("ShaderNodeTangent"),
  140. NodeItem("ShaderNodeNewGeometry"),
  141. NodeItem("ShaderNodeWireframe"),
  142. NodeItem("ShaderNodeBevel"),
  143. NodeItem("ShaderNodeAmbientOcclusion"),
  144. NodeItem("ShaderNodeObjectInfo"),
  145. NodeItem("ShaderNodeHairInfo"),
  146. NodeItem("ShaderNodeParticleInfo"),
  147. NodeItem("ShaderNodeCameraData"),
  148. NodeItem("ShaderNodeUVMap"),
  149. NodeItem("ShaderNodeUVAlongStroke", poll=line_style_shader_nodes_poll),
  150. NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
  151. ]),
  152. ShaderNodeCategory("SH_NEW_OUTPUT", "Output", items=[
  153. NodeItem("ShaderNodeOutputMaterial", poll=object_eevee_cycles_shader_nodes_poll),
  154. NodeItem("ShaderNodeOutputLight", poll=object_cycles_shader_nodes_poll),
  155. NodeItem("ShaderNodeOutputWorld", poll=world_shader_nodes_poll),
  156. NodeItem("ShaderNodeOutputLineStyle", poll=line_style_shader_nodes_poll),
  157. NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
  158. ]),
  159. ShaderNodeCategory("SH_NEW_SHADER", "Shader", items=[
  160. NodeItem("ShaderNodeMixShader", poll=eevee_cycles_shader_nodes_poll),
  161. NodeItem("ShaderNodeAddShader", poll=eevee_cycles_shader_nodes_poll),
  162. NodeItem("ShaderNodeBsdfDiffuse", poll=object_eevee_cycles_shader_nodes_poll),
  163. NodeItem("ShaderNodeBsdfPrincipled", poll=object_eevee_cycles_shader_nodes_poll),
  164. NodeItem("ShaderNodeBsdfGlossy", poll=object_eevee_cycles_shader_nodes_poll),
  165. NodeItem("ShaderNodeBsdfTransparent", poll=object_eevee_cycles_shader_nodes_poll),
  166. NodeItem("ShaderNodeBsdfRefraction", poll=object_eevee_cycles_shader_nodes_poll),
  167. NodeItem("ShaderNodeBsdfGlass", poll=object_eevee_cycles_shader_nodes_poll),
  168. NodeItem("ShaderNodeBsdfTranslucent", poll=object_eevee_cycles_shader_nodes_poll),
  169. NodeItem("ShaderNodeBsdfAnisotropic", poll=object_cycles_shader_nodes_poll),
  170. NodeItem("ShaderNodeBsdfVelvet", poll=object_cycles_shader_nodes_poll),
  171. NodeItem("ShaderNodeBsdfToon", poll=object_cycles_shader_nodes_poll),
  172. NodeItem("ShaderNodeSubsurfaceScattering", poll=object_eevee_cycles_shader_nodes_poll),
  173. NodeItem("ShaderNodeEmission", poll=eevee_cycles_shader_nodes_poll),
  174. NodeItem("ShaderNodeBsdfHair", poll=object_cycles_shader_nodes_poll),
  175. NodeItem("ShaderNodeBackground", poll=world_shader_nodes_poll),
  176. NodeItem("ShaderNodeHoldout", poll=object_cycles_shader_nodes_poll),
  177. NodeItem("ShaderNodeVolumeAbsorption", poll=eevee_cycles_shader_nodes_poll),
  178. NodeItem("ShaderNodeVolumeScatter", poll=eevee_cycles_shader_nodes_poll),
  179. NodeItem("ShaderNodeVolumePrincipled"),
  180. NodeItem("ShaderNodeEeveeSpecular", poll=object_eevee_shader_nodes_poll),
  181. NodeItem("ShaderNodeBsdfHairPrincipled", poll=object_cycles_shader_nodes_poll)
  182. ]),
  183. ShaderNodeCategory("SH_NEW_TEXTURE", "Texture", items=[
  184. NodeItem("ShaderNodeTexImage"),
  185. NodeItem("ShaderNodeTexEnvironment"),
  186. NodeItem("ShaderNodeTexSky"),
  187. NodeItem("ShaderNodeTexNoise"),
  188. NodeItem("ShaderNodeTexWave"),
  189. NodeItem("ShaderNodeTexVoronoi"),
  190. NodeItem("ShaderNodeTexMusgrave"),
  191. NodeItem("ShaderNodeTexGradient"),
  192. NodeItem("ShaderNodeTexMagic"),
  193. NodeItem("ShaderNodeTexChecker"),
  194. NodeItem("ShaderNodeTexBrick"),
  195. NodeItem("ShaderNodeTexPointDensity"),
  196. NodeItem("ShaderNodeTexIES"),
  197. ]),
  198. ShaderNodeCategory("SH_NEW_OP_COLOR", "Color", items=[
  199. NodeItem("ShaderNodeMixRGB"),
  200. NodeItem("ShaderNodeRGBCurve"),
  201. NodeItem("ShaderNodeInvert"),
  202. NodeItem("ShaderNodeLightFalloff"),
  203. NodeItem("ShaderNodeHueSaturation"),
  204. NodeItem("ShaderNodeGamma"),
  205. NodeItem("ShaderNodeBrightContrast"),
  206. ]),
  207. ShaderNodeCategory("SH_NEW_OP_VECTOR", "Vector", items=[
  208. NodeItem("ShaderNodeMapping"),
  209. NodeItem("ShaderNodeBump"),
  210. NodeItem("ShaderNodeDisplacement"),
  211. NodeItem("ShaderNodeVectorDisplacement"),
  212. NodeItem("ShaderNodeNormalMap"),
  213. NodeItem("ShaderNodeNormal"),
  214. NodeItem("ShaderNodeVectorCurve"),
  215. NodeItem("ShaderNodeVectorTransform"),
  216. ]),
  217. ShaderNodeCategory("SH_NEW_CONVERTOR", "Converter", items=[
  218. NodeItem("ShaderNodeMath"),
  219. NodeItem("ShaderNodeValToRGB"),
  220. NodeItem("ShaderNodeRGBToBW"),
  221. NodeItem("ShaderNodeShaderToRGB", poll=object_eevee_shader_nodes_poll),
  222. NodeItem("ShaderNodeVectorMath"),
  223. NodeItem("ShaderNodeSeparateRGB"),
  224. NodeItem("ShaderNodeCombineRGB"),
  225. NodeItem("ShaderNodeSeparateXYZ"),
  226. NodeItem("ShaderNodeCombineXYZ"),
  227. NodeItem("ShaderNodeSeparateHSV"),
  228. NodeItem("ShaderNodeCombineHSV"),
  229. NodeItem("ShaderNodeWavelength"),
  230. NodeItem("ShaderNodeBlackbody"),
  231. ]),
  232. ShaderNodeCategory("SH_NEW_SCRIPT", "Script", items=[
  233. NodeItem("ShaderNodeScript"),
  234. ]),
  235. ShaderNodeCategory("SH_NEW_GROUP", "Group", items=node_group_items),
  236. ShaderNodeCategory("SH_NEW_LAYOUT", "Layout", items=[
  237. NodeItem("NodeFrame"),
  238. NodeItem("NodeReroute"),
  239. ]),
  240. ]
  241. compositor_node_categories = [
  242. # Compositor Nodes
  243. CompositorNodeCategory("CMP_INPUT", "Input", items=[
  244. NodeItem("CompositorNodeRLayers"),
  245. NodeItem("CompositorNodeImage"),
  246. NodeItem("CompositorNodeMovieClip"),
  247. NodeItem("CompositorNodeMask"),
  248. NodeItem("CompositorNodeRGB"),
  249. NodeItem("CompositorNodeValue"),
  250. NodeItem("CompositorNodeTexture"),
  251. NodeItem("CompositorNodeBokehImage"),
  252. NodeItem("CompositorNodeTime"),
  253. NodeItem("CompositorNodeTrackPos"),
  254. NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
  255. ]),
  256. CompositorNodeCategory("CMP_OUTPUT", "Output", items=[
  257. NodeItem("CompositorNodeComposite"),
  258. NodeItem("CompositorNodeViewer"),
  259. NodeItem("CompositorNodeSplitViewer"),
  260. NodeItem("CompositorNodeOutputFile"),
  261. NodeItem("CompositorNodeLevels"),
  262. NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
  263. ]),
  264. CompositorNodeCategory("CMP_OP_COLOR", "Color", items=[
  265. NodeItem("CompositorNodeMixRGB"),
  266. NodeItem("CompositorNodeAlphaOver"),
  267. NodeItem("CompositorNodeInvert"),
  268. NodeItem("CompositorNodeCurveRGB"),
  269. NodeItem("CompositorNodeHueSat"),
  270. NodeItem("CompositorNodeColorBalance"),
  271. NodeItem("CompositorNodeHueCorrect"),
  272. NodeItem("CompositorNodeBrightContrast"),
  273. NodeItem("CompositorNodeGamma"),
  274. NodeItem("CompositorNodeColorCorrection"),
  275. NodeItem("CompositorNodeTonemap"),
  276. NodeItem("CompositorNodeZcombine"),
  277. ]),
  278. CompositorNodeCategory("CMP_CONVERTOR", "Converter", items=[
  279. NodeItem("CompositorNodeMath"),
  280. NodeItem("CompositorNodeValToRGB"),
  281. NodeItem("CompositorNodeSetAlpha"),
  282. NodeItem("CompositorNodePremulKey"),
  283. NodeItem("CompositorNodeIDMask"),
  284. NodeItem("CompositorNodeRGBToBW"),
  285. NodeItem("CompositorNodeSepRGBA"),
  286. NodeItem("CompositorNodeCombRGBA"),
  287. NodeItem("CompositorNodeSepHSVA"),
  288. NodeItem("CompositorNodeCombHSVA"),
  289. NodeItem("CompositorNodeSepYUVA"),
  290. NodeItem("CompositorNodeCombYUVA"),
  291. NodeItem("CompositorNodeSepYCCA"),
  292. NodeItem("CompositorNodeCombYCCA"),
  293. NodeItem("CompositorNodeSwitchView"),
  294. ]),
  295. CompositorNodeCategory("CMP_OP_FILTER", "Filter", items=[
  296. NodeItem("CompositorNodeBlur"),
  297. NodeItem("CompositorNodeBilateralblur"),
  298. NodeItem("CompositorNodeDilateErode"),
  299. NodeItem("CompositorNodeDespeckle"),
  300. NodeItem("CompositorNodeFilter"),
  301. NodeItem("CompositorNodeBokehBlur"),
  302. NodeItem("CompositorNodeVecBlur"),
  303. NodeItem("CompositorNodeDefocus"),
  304. NodeItem("CompositorNodeGlare"),
  305. NodeItem("CompositorNodeInpaint"),
  306. NodeItem("CompositorNodeDBlur"),
  307. NodeItem("CompositorNodePixelate"),
  308. NodeItem("CompositorNodeSunBeams"),
  309. ]),
  310. CompositorNodeCategory("CMP_OP_VECTOR", "Vector", items=[
  311. NodeItem("CompositorNodeNormal"),
  312. NodeItem("CompositorNodeMapValue"),
  313. NodeItem("CompositorNodeMapRange"),
  314. NodeItem("CompositorNodeNormalize"),
  315. NodeItem("CompositorNodeCurveVec"),
  316. ]),
  317. CompositorNodeCategory("CMP_MATTE", "Matte", items=[
  318. NodeItem("CompositorNodeKeying"),
  319. NodeItem("CompositorNodeKeyingScreen"),
  320. NodeItem("CompositorNodeChannelMatte"),
  321. NodeItem("CompositorNodeColorSpill"),
  322. NodeItem("CompositorNodeBoxMask"),
  323. NodeItem("CompositorNodeEllipseMask"),
  324. NodeItem("CompositorNodeLumaMatte"),
  325. NodeItem("CompositorNodeDiffMatte"),
  326. NodeItem("CompositorNodeDistanceMatte"),
  327. NodeItem("CompositorNodeChromaMatte"),
  328. NodeItem("CompositorNodeColorMatte"),
  329. NodeItem("CompositorNodeDoubleEdgeMask"),
  330. NodeItem("CompositorNodeCryptomatte"),
  331. ]),
  332. CompositorNodeCategory("CMP_DISTORT", "Distort", items=[
  333. NodeItem("CompositorNodeScale"),
  334. NodeItem("CompositorNodeLensdist"),
  335. NodeItem("CompositorNodeMovieDistortion"),
  336. NodeItem("CompositorNodeTranslate"),
  337. NodeItem("CompositorNodeRotate"),
  338. NodeItem("CompositorNodeFlip"),
  339. NodeItem("CompositorNodeCrop"),
  340. NodeItem("CompositorNodeDisplace"),
  341. NodeItem("CompositorNodeMapUV"),
  342. NodeItem("CompositorNodeTransform"),
  343. NodeItem("CompositorNodeStabilize"),
  344. NodeItem("CompositorNodePlaneTrackDeform"),
  345. NodeItem("CompositorNodeCornerPin"),
  346. ]),
  347. CompositorNodeCategory("CMP_GROUP", "Group", items=node_group_items),
  348. CompositorNodeCategory("CMP_LAYOUT", "Layout", items=[
  349. NodeItem("NodeFrame"),
  350. NodeItem("NodeReroute"),
  351. NodeItem("CompositorNodeSwitch"),
  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. NodeItem("TextureNodeAt"),
  404. ]),
  405. TextureNodeCategory("TEX_GROUP", "Group", items=node_group_items),
  406. TextureNodeCategory("TEX_LAYOUT", "Layout", items=[
  407. NodeItem("NodeFrame"),
  408. NodeItem("NodeReroute"),
  409. ]),
  410. ]
  411. def register():
  412. nodeitems_utils.register_node_categories('SHADER', shader_node_categories)
  413. nodeitems_utils.register_node_categories('COMPOSITING', compositor_node_categories)
  414. nodeitems_utils.register_node_categories('TEXTURE', texture_node_categories)
  415. def unregister():
  416. nodeitems_utils.unregister_node_categories('SHADER')
  417. nodeitems_utils.unregister_node_categories('COMPOSITING')
  418. nodeitems_utils.unregister_node_categories('TEXTURE')
  419. if __name__ == "__main__":
  420. register()