[Bf-blender-cvs] [7b379313ded] blender2.8: Bpy Extras: Port cycles node functions to new node_utils.py
Clément Foucault
noreply at git.blender.org
Tue May 30 17:18:21 CEST 2017
Commit: 7b379313ded90b58422497bac5af5dfda440aeb8
Author: Clément Foucault
Date: Tue May 30 17:15:58 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB7b379313ded90b58422497bac5af5dfda440aeb8
Bpy Extras: Port cycles node functions to new node_utils.py
===================================================================
M intern/cycles/blender/addon/ui.py
M release/scripts/modules/bpy_extras/__init__.py
A release/scripts/modules/bpy_extras/node_utils.py
===================================================================
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index c8d63daee5f..a8018e3824d 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -17,6 +17,7 @@
# <pep8 compliant>
import bpy
+from bpy_extras.node_utils import find_node_input, find_output_node
from bpy.types import (
Panel,
@@ -898,30 +899,6 @@ class CYCLES_OT_use_shading_nodes(Operator):
return {'FINISHED'}
-def find_node(material, nodetype):
- if material and material.node_tree:
- ntree = material.node_tree
-
- active_output_node = None
- for node in ntree.nodes:
- if getattr(node, "type", None) == nodetype:
- if getattr(node, "is_active_output", True):
- return node
- if not active_output_node:
- active_output_node = node
- return active_output_node
-
- return None
-
-
-def find_node_input(node, name):
- for input in node.inputs:
- if input.name == name:
- return input
-
- return None
-
-
def panel_node_draw(layout, id_data, output_type, input_name):
if not id_data.use_nodes:
layout.operator("cycles.use_shading_nodes", icon='NODETREE')
@@ -929,7 +906,7 @@ def panel_node_draw(layout, id_data, output_type, input_name):
ntree = id_data.node_tree
- node = find_node(id_data, output_type)
+ node = find_output_node(ntree, output_type)
if not node:
layout.label(text="No output node")
else:
diff --git a/release/scripts/modules/bpy_extras/__init__.py b/release/scripts/modules/bpy_extras/__init__.py
index c8d12070de8..cd176e77aed 100644
--- a/release/scripts/modules/bpy_extras/__init__.py
+++ b/release/scripts/modules/bpy_extras/__init__.py
@@ -29,5 +29,6 @@ __all__ = (
"image_utils",
"keyconfig_utils",
"mesh_utils",
+ "node_utils",
"view3d_utils",
)
diff --git a/release/scripts/modules/bpy_extras/__init__.py b/release/scripts/modules/bpy_extras/node_utils.py
similarity index 54%
copy from release/scripts/modules/bpy_extras/__init__.py
copy to release/scripts/modules/bpy_extras/node_utils.py
index c8d12070de8..3b8d4ad7c2a 100644
--- a/release/scripts/modules/bpy_extras/__init__.py
+++ b/release/scripts/modules/bpy_extras/node_utils.py
@@ -18,16 +18,30 @@
# <pep8-80 compliant>
-"""
-Utility modules associated with the bpy module.
-"""
-
__all__ = (
- "anim_utils",
- "object_utils",
- "io_utils",
- "image_utils",
- "keyconfig_utils",
- "mesh_utils",
- "view3d_utils",
+ "find_node_input",
+ "find_output_node",
)
+
+
+# XXX Names are not unique. Returns the first match.
+def find_node_input(node, name):
+ for input in node.inputs:
+ if input.name == name:
+ return input
+
+ return None
+
+# Return the output node to display in the UI
+def find_output_node(ntree, nodetype):
+ if ntree:
+ active_output_node = None
+ for node in ntree.nodes:
+ if getattr(node, "type", None) == nodetype:
+ if getattr(node, "is_active_output", True):
+ return node
+ if not active_output_node:
+ active_output_node = node
+ return active_output_node
+
+ return None
More information about the Bf-blender-cvs
mailing list