create node child object
parent
e33b0e5b1d
commit
f92b68f62a
66
core/node.py
66
core/node.py
|
@ -83,31 +83,25 @@ class Node:
|
|||
if self._parent:
|
||||
self.bl_node.parent = self._parent.bl_node
|
||||
|
||||
@property
|
||||
def scene(self):
|
||||
"""Get the name of the scene used by the node.
|
||||
|
||||
Returns:
|
||||
str: scene name.
|
||||
"""
|
||||
if self._scene:
|
||||
return self._scene.name
|
||||
|
||||
@scene.setter
|
||||
def scene(self, value):
|
||||
"""Set the blender scene using the bpy Scene object or its name.
|
||||
@classmethod
|
||||
def from_blender_node(cls, bl_node, tree):
|
||||
"""Instanciate an abstract class based of the blender node idname.
|
||||
|
||||
Args:
|
||||
value (str|bpy.types.Scene): scene name or scene object to set the node.
|
||||
bl_node (bpy.types.Node): Blender Node To create abstraction from.
|
||||
tree (NodeTree): Node tree object node belongs to.
|
||||
|
||||
Returns:
|
||||
Node: Node abstract according to the blender node type.
|
||||
"""
|
||||
if isinstance(value, str):
|
||||
self._scene = bpy.data.scenes[value]
|
||||
if bl_node.bl_idname == 'CompositorNodeRLayers':
|
||||
return RenderLayersNode(bl_node, tree)
|
||||
|
||||
elif isinstance(value, bpy.types.Scene):
|
||||
self._scene = value
|
||||
elif bl_node.bl_idname == 'CompositorNodeValToRGB':
|
||||
return ColorRampNode(bl_node, tree)
|
||||
|
||||
if self._scene:
|
||||
self.bl_node.scene = self._scene
|
||||
else:
|
||||
return cls(bl_node, tree)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data, tree):
|
||||
|
@ -122,7 +116,7 @@ class Node:
|
|||
"""
|
||||
|
||||
new_bl_node = tree.bl_node_tree.nodes.new(type=data['bl_idname'])
|
||||
node = cls(new_bl_node, parent=tree)
|
||||
node = cls.from_blender_node(new_bl_node, tree)
|
||||
|
||||
node.id = data['id']
|
||||
for p in node.parameters:
|
||||
|
@ -167,6 +161,36 @@ class Node:
|
|||
return self.data
|
||||
|
||||
|
||||
class RenderLayersNode(Node):
|
||||
"""Blender Render Layers Node abstraction"""
|
||||
|
||||
@property
|
||||
def scene(self):
|
||||
"""Get the name of the scene used by the node.
|
||||
|
||||
Returns:
|
||||
str: scene name.
|
||||
"""
|
||||
if self._scene:
|
||||
return self._scene.name
|
||||
|
||||
@scene.setter
|
||||
def scene(self, value):
|
||||
"""Set the blender scene using the bpy Scene object or its name.
|
||||
|
||||
Args:
|
||||
value (str|bpy.types.Scene): scene name or scene object to set the node.
|
||||
"""
|
||||
if isinstance(value, str):
|
||||
self._scene = bpy.data.scenes[value]
|
||||
|
||||
elif isinstance(value, bpy.types.Scene):
|
||||
self._scene = value
|
||||
|
||||
if self._scene:
|
||||
self.bl_node.scene = self._scene
|
||||
|
||||
|
||||
class Link:
|
||||
"""Blender Link abstraction."""
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class NodeTree:
|
|||
self.links = [Link(lnk, parent=self) for lnk in self.bl_node_tree.links]
|
||||
self.nodes = []
|
||||
for n in self.bl_node_tree.nodes:
|
||||
self.nodes.append(Node(n, parent=self))
|
||||
self.nodes.append(Node.from_blender_node(n, self))
|
||||
|
||||
def to_dict(self, select_only=False):
|
||||
"""Convert all blender nodes and links inside the tree into a dictionnary.
|
||||
|
|
Loading…
Reference in New Issue