NodeΒΆ
class Node
Base class of all the document's nodes.
Hierarchy
Children classes : class ChannelReader , class ControlNode , class DeletableNode , class Document , class EnvironmentBase , class GraphPlug , class RenderFarm , class RenderOutput , class RibAttributes , class Script , class SelectableNode , class Shader , class ShaderDataNode , class ShaderNodeIn , class ShaderNodeOut , class Texture
Members
string | Name | RW | The node name |
| belongstoreference | (
|
Tells if the node belongs to the reference, or a sub reference |
| delete | ( ) | Delete a node |
| eval | (
|
Called by the framework when plug (a node's plug) must be evaluated |
| findchild | (
|
Find a child node or plug using a path |
| findparent | (
|
Find the first parent Node of this Node of a specific class |
| getchild | (
|
Get a child node by its name |
| getname | ( ) | Get the Node name in its parent |
| getparent | ( ) | Get the parent Node of this Node |
| getpath | ( ) | Returns the node path as a string that can be reused with findchild |
| getreference | ( ) | Returns the reference node it is connected to |
| getreferences | (
[
|
Returns the references in the document sorted depth first. |
| getstringcopy | ( ) | Return a copy of the node and its content as a string to be pasted |
| gettopreference | ( ) | Returns the top reference node it is connected to |
| iseditable | ( ) | Indicates if the node can be edited by the user in the UI |
| isindocument | ( ) | Tells if the node is inside a document, or is pending in the void |
| ismoveable | ( ) | Tells if the node can be moved |
| isparent | (
|
Tells if this node is parent of the potential child |
| isreference | ( ) | Tells if a node comes from a reference project |
| isselected | ( ) | Tell if the node is selected |
| loadfile | (
|
load a file content in this node. Possible options are: overrideclass to enforce a specific class for the root node. |
| loadtemplate | (
|
load a template file |
| move | (
|
Move a node to a new parent |
| onpathchanged | ( ) | Called by the framework when the name of this node or of one of its parent is modified |
| pastestringcopy | (
|
Paste a string copy into this node |
| referencefile | (
|
reference a file content in this node. |
| rename | (
|
Rename a node |
| savefile | (
|
load a node to a file |
| seteditable | (
|
Change the editable state of the node |
| setflags | ( ) | Set the node flags |
Documentation
The node name
Tells if the node belongs to the reference, or a sub reference
ref The reference to test
result true is the node belongs to the reference or a sub reference
Delete a node
This method delete the node, without any recording in the undo/redo stack. To benefit from undo/redo, use Modifier.deletenode.
-- Assumes Node|Child is a node
local node = _"Node|Child"
node:delete ()
Called by the framework when plug (a node's plug) must be evaluated
The eval method is called when the node framework queries the value of a plug which is invalid or dependent on other plugs. This is the duty of the parent node to compute that value and return it.
-- Declare a Dummy class which inherits from Node
class ("DummyClass", "Node")
-- The constructor, with dependent plugs
function Dummy:construct (parent, name)
Plug (self, "Plug", "HalfWidth", 0, types.int{}, 0)
self.HalfWith:adddependencies (Document.ProjectWidth)
end
-- Evaluate HalfWidth
function Dummy:eval (plug)
if plug == self.HalfWidth then
-- The framework is querying HalfWidth value
-- Get the Document's ProjectWidth and divide by 2
local w = Document.ProjectWidth:get ()
return math.floor ((w+0.5)/2)
end
-- If we don't know the plug to eval, return an error
-- Note: if your class inherits a class that implements
-- eval, then you have to call it! Use parenteval to
-- evaluate parent classes in order
return Plug.EvalError
end
plug
value The evaluated plug value
Find a child node or plug using a path
path the child node or plug path
child the child node or plug
Find the first parent Node of this Node of a specific class
This method returns the first parent node of the given class.
-- Get the parent RenderPass of a Layer
local renderpass = _"RenderPass|Layer":getparent ("RenderPass")
name the parent's class
parent the node's parent
Get a child node by its name
name the child name
result The child node
Get the Node name in its parent
print (_"RenderPass|Layer":getname ())
-- prints "Layer" in the console
name The Node name
Get the parent Node of this Node
parent the node's parent
Returns the node path as a string that can be reused with findchild
This method returns the path of a node. This path can be used by the _ function.
Note: getpath also returns an extra value, which you shouldn' care of.
-- Get the path of a node
local layer = _"RenderPass|Layer"
local path = layer:getpath ()
print (path)
assert (path == "RenderPath|Layer"
path The node's path, each parent being separated by a '|'
Returns the reference node it is connected to
reference the reference node or nil if not referenced
Returns the references in the document sorted depth first.
Reference an optional top reference
table references
Return a copy of the node and its content as a string to be pasted
-- Duplicate Layer in RenderPass
local strcopy = _"RenderPass|Layer":getstringcopy ()
local copy = _"RenderPass":pastestringcopy (strcopy)
-- copy is a list of the copied nodes
result The string copy
Returns the top reference node it is connected to
reference the top reference node or nil if not referenced
Indicates if the node can be edited by the user in the UI
editable true if the node can be edited
Tells if the node is inside a document, or is pending in the void
indocument true if the node belongs to a document
Tells if the node can be moved
result True if the node can be moved
Tells if this node is parent of the potential child
This method returns true if the node is a parent of the given child.
-- Test that the Perspective camera is a child of the Document
assert (Document:isparent (_"Perspective"))
-- Note that a node is considered a child of itself!
assert (Document:isparent (Document))
child the potential child to check
result
Tells if a node comes from a reference project
result true if the node is a reference
Tell if the node is selected
This method returns true if the node is selected. Note that only SelectableNode nodes can be selected, thus simple Node always return false.
-- Select the Perspective camera
local modifier = Document:modify ()
modifier.select ({_"Perspective"})
modifier.finish ()
assert (_"Perspective":isselected ())
state true if the node is selected
load a file content in this node. Possible options are: overrideclass to enforce a specific class for the root node.
This method loads the content of a Guerilla file (.gmaterial, .glight ..) into the node. For a .gproject file, use the mergedocument function. If a node in the file is not accepted (that is, it cannot be a child of the node because of its class), the whole loading is aborted.
The returned value is a list of the root nodes contained in this file.
Use savefile to save a node into a file.
local result = Document:loadfile ("$(LIBRARY)/material/surface.gmaterial")
for k, node in pairs (result) do
local path = node:getpath ()
print ("Loaded node "..path)
end
filename The file name to loadoptions Loading options as a table/dictionary
result The created nodes or nil if failed
load a template file
This method loads the content of a file into the node. The file must contain exactly one node or the method fails. If the node type is not accepted (because of its class), the method fails.
The template name is the file name without base path. Guerilla will first look up template pathes given in the TemplateDirectory Local Setting, and eventually in $(LIBRARY)/templates. The first matching file is loaded as the template.
This method is used in Guerilla to load files instead of creating new nodes from scratch, so you can provide Guerilla with default custom nodes.
-- Load the template for new renderpass
local result = Document:loadtemplate ("new_renderpass.glayer")
Possible templates are:
- new_document.gproject: template used when creating a new document
- export.gproject: template used when exporting a project from Maya or another host package
- new_rendergraph.grendergraph: template used when creating a new RenderGraph
- new_light.glight: template used when creating a new Light
- new_camera.glocator: template used when creating a new Camera
- new_material.glocator: template used when creating a new Material
- new_renderpass.glayer: template used when creating a new RenderPass
- new_composition.gcomp: template used when creating a new Compositing
- new_bake2d.glayer: template used when creating a new Bake2d render pass
- new_shadernode.gnode: template used when creating a new shader macro
To use additional template directories:
Edit the guerilla.conf of your Guerilla installation and add a TemplateDirectory=/the/path/to/my/main/templates\n/the/path/to/my/other/templates line to it.
template The template file name to loadname The loaded template name to use
result The created node or nil if failed
Move a node to a new parent
parent The new parent node
Called by the framework when the name of this node or of one of its parent is modified
Paste a string copy into this node
copy The string copy to pasteoptions The set of node creation options
result,error The pasted nodes, or nil if failed and an error message
reference a file content in this node.
name the reference node namerefpath the referenced file pathoptions the reference options
refnode the resulting reference node
Rename a node
name The new node name
load a node to a file
This method saves a node and its hierarchy into a file.
-- Save the RenderPass into a temporary file
_"RenderPass":savefile ("/tmp/renderpass.glayer")
filename The file name to save
success,error True if success, or nil and an error message
Change the editable state of the node
editable The new state of the node
Set the node flags