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:
|
if self._parent:
|
||||||
self.bl_node.parent = self._parent.bl_node
|
self.bl_node.parent = self._parent.bl_node
|
||||||
|
|
||||||
@property
|
@classmethod
|
||||||
def scene(self):
|
def from_blender_node(cls, bl_node, tree):
|
||||||
"""Get the name of the scene used by the node.
|
"""Instanciate an abstract class based of the blender node idname.
|
||||||
|
|
||||||
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:
|
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):
|
if bl_node.bl_idname == 'CompositorNodeRLayers':
|
||||||
self._scene = bpy.data.scenes[value]
|
return RenderLayersNode(bl_node, tree)
|
||||||
|
|
||||||
elif isinstance(value, bpy.types.Scene):
|
elif bl_node.bl_idname == 'CompositorNodeValToRGB':
|
||||||
self._scene = value
|
return ColorRampNode(bl_node, tree)
|
||||||
|
|
||||||
if self._scene:
|
else:
|
||||||
self.bl_node.scene = self._scene
|
return cls(bl_node, tree)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data, tree):
|
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'])
|
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']
|
node.id = data['id']
|
||||||
for p in node.parameters:
|
for p in node.parameters:
|
||||||
|
@ -167,6 +161,36 @@ class Node:
|
||||||
return self.data
|
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:
|
class Link:
|
||||||
"""Blender Link abstraction."""
|
"""Blender Link abstraction."""
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ class NodeTree:
|
||||||
self.links = [Link(lnk, parent=self) for lnk in self.bl_node_tree.links]
|
self.links = [Link(lnk, parent=self) for lnk in self.bl_node_tree.links]
|
||||||
self.nodes = []
|
self.nodes = []
|
||||||
for n in self.bl_node_tree.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):
|
def to_dict(self, select_only=False):
|
||||||
"""Convert all blender nodes and links inside the tree into a dictionnary.
|
"""Convert all blender nodes and links inside the tree into a dictionnary.
|
||||||
|
|
Loading…
Reference in New Issue