Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2013-03-18 20:34:57 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2013-03-18 20:34:57 +0400
commit4638e5f99a9ba59ad0b8a1fd52b12e876480b9e8 (patch)
tree2444f12b4612440f44cf02835cdf5951b6564e92 /release/scripts/modules/bpy_types.py
parent7bfef29f2f2a1b262d28abdc6e30fcd9c1f1caad (diff)
Merge of the PyNodes branch (aka "custom nodes") into trunk.
PyNodes opens up the node system in Blender to scripters and adds a number of UI-level improvements. === Dynamic node type registration === Node types can now be added at runtime, using the RNA registration mechanism from python. This enables addons such as render engines to create a complete user interface with nodes. Examples of how such nodes can be defined can be found in my personal wiki docs atm [1] and as a script template in release/scripts/templates_py/custom_nodes.py [2]. === Node group improvements === Each node editor now has a tree history of edited node groups, which allows opening and editing nested node groups. The node editor also supports pinning now, so that different spaces can be used to edit different node groups simultaneously. For more ramblings and rationale see (really old) blog post on code.blender.org [3]. The interface of node groups has been overhauled. Sockets of a node group are no longer displayed in columns on either side, but instead special input/output nodes are used to mirror group sockets inside a node tree. This solves the problem of long node lines in groups and allows more adaptable node layout. Internal sockets can be exposed from a group by either connecting to the extension sockets in input/output nodes (shown as empty circle) or by adding sockets from the node property bar in the "Interface" panel. Further details such as the socket name can also be changed there. [1] http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes [2] http://projects.blender.org/scm/viewvc.php/trunk/blender/release/scripts/templates_py/custom_nodes.py?view=markup&root=bf-blender [3] http://code.blender.org/index.php/2012/01/improving-node-group-interface-editing/
Diffstat (limited to 'release/scripts/modules/bpy_types.py')
-rw-r--r--release/scripts/modules/bpy_types.py155
1 files changed, 144 insertions, 11 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index 4398b1721f7..f42fd8e3107 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -485,17 +485,6 @@ class Text(bpy_types.ID):
)
-class NodeSocket(StructRNA): # , metaclass=RNAMeta
- __slots__ = ()
-
- @property
- def links(self):
- """List of node links from or to this socket"""
- return tuple(link for link in self.id_data.links
- if (link.from_socket == self or
- link.to_socket == self))
-
-
# values are module: [(cls, path, line), ...]
TypeMap = {}
@@ -757,3 +746,147 @@ class Region(StructRNA):
return None
+
+class NodeTree(bpy_types.ID, metaclass=RNAMetaPropGroup):
+ __slots__ = ()
+
+
+class NodeSocketTemplate():
+ type = 'UNDEFINED'
+
+ # Default implementation:
+ # Create a single property using the socket template's 'value_property' attribute
+ # value_property should be created in the __init__ function
+ #
+ # If necessary this function can be overloaded in subclasses, e.g. to create multiple value properties
+ def define_node_properties(self, node_type, prefix):
+ if hasattr(self, "value_property"):
+ setattr(node_type, prefix+"value", self.value_property)
+
+ def init_socket(self, socket):
+ socket.type = self.type
+ if hasattr(self, "value_property"):
+ socket.value_property = self.value_property[1]['attr']
+
+
+def gen_valid_identifier(seq):
+ # get an iterator
+ itr = iter(seq)
+ # pull characters until we get a legal one for first in identifer
+ for ch in itr:
+ if ch == '_' or ch.isalpha():
+ yield ch
+ break
+ # pull remaining characters and yield legal ones for identifier
+ for ch in itr:
+ if ch == '_' or ch.isalpha() or ch.isdigit():
+ yield ch
+
+def sanitize_identifier(name):
+ return ''.join(gen_valid_identifier(name))
+
+def unique_identifier(name, identifier_list):
+ # First some basic sanitation, to make a usable identifier string from the name
+ base = sanitize_identifier(name)
+ # Now make a unique identifier by appending an unused index
+ identifier = base
+ index = 0
+ while identifier in identifier_list:
+ index += 1
+ identifier = base + str(index)
+ return identifier
+
+class RNAMetaNode(RNAMetaPropGroup):
+ def __new__(cls, name, bases, classdict, **args):
+ # Wrapper for node.init, to add sockets from templates
+
+ def create_sockets(self):
+ inputs = getattr(self, 'input_templates', None)
+ if inputs:
+ for temp in inputs:
+ socket = self.inputs.new(type=temp.bl_socket_idname, name=temp.name, identifier=temp.identifier)
+ temp.init_socket(socket)
+ outputs = getattr(self, 'output_templates', None)
+ if outputs:
+ for temp in outputs:
+ socket = self.outputs.new(type=temp.bl_socket_idname, name=temp.name, identifier=temp.identifier)
+ temp.init_socket(socket)
+
+ init_base = classdict.get('init', None)
+ if init_base:
+ def init_node(self, context):
+ create_sockets(self)
+ init_base(self, context)
+ else:
+ def init_node(self, context):
+ create_sockets(self)
+
+ classdict['init'] = init_node
+
+ # Create the regular class
+ result = RNAMetaPropGroup.__new__(cls, name, bases, classdict)
+
+ # Add properties from socket templates
+ inputs = classdict.get('input_templates', None)
+ if inputs:
+ for i, temp in enumerate(inputs):
+ temp.identifier = unique_identifier(temp.name, [t.identifier for t in inputs[0:i]])
+ temp.define_node_properties(result, "input_"+temp.identifier+"_")
+ outputs = classdict.get('output_templates', None)
+ if outputs:
+ for i, temp in enumerate(outputs):
+ temp.identifier = unique_identifier(temp.name, [t.identifier for t in outputs[0:i]])
+ temp.define_node_properties(result, "output_"+temp.identifier+"_")
+
+ return result
+
+
+class Node(StructRNA, metaclass=RNAMetaNode):
+ __slots__ = ()
+
+ @classmethod
+ def poll(cls, ntree):
+ return True
+
+
+class NodeSocket(StructRNA, metaclass=RNAMetaPropGroup):
+ __slots__ = ()
+
+ @property
+ def links(self):
+ """List of node links from or to this socket"""
+ return tuple(link for link in self.id_data.links
+ if (link.from_socket == self or
+ link.to_socket == self))
+
+
+class NodeSocketInterface(StructRNA, metaclass=RNAMetaPropGroup):
+ __slots__ = ()
+
+
+# These are intermediate subclasses, need a bpy type too
+class CompositorNode(Node):
+ __slots__ = ()
+
+ @classmethod
+ def poll(cls, ntree):
+ return ntree.bl_idname == 'CompositorNodeTree'
+
+ def update(self):
+ self.tag_need_exec()
+
+class ShaderNode(Node):
+ __slots__ = ()
+
+ @classmethod
+ def poll(cls, ntree):
+ return ntree.bl_idname == 'ShaderNodeTree'
+
+
+class TextureNode(Node):
+ __slots__ = ()
+
+ @classmethod
+ def poll(cls, ntree):
+ return ntree.bl_idname == 'TextureNodeTree'
+