Capítulo 438 de 859

Chapter 438: Node

Core Idea

Base class for all nodes.

Key Concepts

  • global : boolean: Whether this node is global or not. This property is relevant for the internal node caching system. All nodes which should be declared just…
  • id : number (readonly): The unique ID of the node.
  • isNode : boolean (readonly): This flag can be used for type testing.
  • name : string: The name of the node.
  • needsUpdate : boolean: Set this property to true when the node should be regenerated.
  • nodeType : string: The node type. This represents the result type of the node (e.g. float or vec3).
  • parents : boolean: Create a list of parents for this node during the build process.
  • stackTrace : string: The stack trace of the node for debugging purposes.
  • type : string (readonly): The type of the class. The value is usually the constructor name.
  • updateAfterType : string: The update type of the node's Node#updateAfter method. Possible values are listed in [NodeUpdateType](global.html#…

Reference Tables

Constructor

Signature
new Node( nodeType : string )

Properties

PropertyDescription
.global : booleanWhether this node is global or not. This property is relevant for the internal node caching system. All nodes which should be declared just once should set this flag to true (a typical example is […
.id : number (readonly)The unique ID of the node.
.isNode : boolean (readonly)This flag can be used for type testing.
.name : stringThe name of the node.
.needsUpdate : booleanSet this property to true when the node should be regenerated.
.nodeType : stringThe node type. This represents the result type of the node (e.g. float or vec3).
.parents : booleanCreate a list of parents for this node during the build process.
.stackTrace : stringThe stack trace of the node for debugging purposes.
.type : string (readonly)The type of the class. The value is usually the constructor name.
.updateAfterType : stringThe update type of the node's Node#updateAfter method. Possible values are listed in NodeUpdateType.
.updateBeforeType : stringThe update type of the node's Node#updateBefore method. Possible values are listed in NodeUpdateType.
.updateType : stringThe update type of the node's Node#update method. Possible values are listed in NodeUpdateType.
.uuid : string (readonly)The UUID of the node.
.version : number (readonly)The version of the node. The version automatically is increased when Node#needsUpdate is set to true.
.captureStackTrace : booleanEnables or disables the automatic capturing of stack traces for nodes.

Methods

MethodDescription
.analyze( builder : NodeBuilder, output : Node )Represents the analyze stage which is the second step of the build process, see Node#build method. This stage analyzes the node hierarchy and ensures descendent nodes are built.
`.build( builder : NodeBuilder, output : stringNode ) : Node
.customCacheKey() : numberGenerate a custom cache key for this node.
.deserialize( json : Object )Deserializes the node from the given JSON.
.dispose()Calling this method dispatches the dispose event. This event can be used to register event listeners for clean up tasks.
.generate( builder : NodeBuilder, output : string ) : stringRepresents the generate stage which is the third step of the build process, see Node#build method. This state builds the output node and returns the resulting shader string.
.generateNodeType( builder : NodeBuilder, output : string ) : stringReturns the node's type.
.getArrayCount( builder : NodeBuilder ) : numberReturns the number of elements in the node array.
.getCacheKey( force : boolean, ignores : Set.<Node> ) : numberReturns the cache key for this node.
.getChildren() : Node (generator)Generator function that can be used to iterate over the child nodes.
.getElementType( builder : NodeBuilder ) : stringCertain types are composed of multiple elements. For example a vec3 is composed of three float values. This method returns the type of these elements.
.getHash( builder : NodeBuilder ) : stringReturns the hash of the node which is used to identify the node. By default it's the Node#uuid however derived node classes might have to overwrite this method depending on their im…
.getMemberType( builder : NodeBuilder, name : string ) : stringReturns the node member type for the given name.
.getNodeType( builder : NodeBuilder, output : string ) : stringReturns the node's type.
.getScope() : NodeReturns the references to this node which is by default this.
.getSerializeChildren() : Generator.<Object>Returns the child nodes as a JSON object.
.getShared( builder : NodeBuilder ) : NodeThis method is used during the build process of a node and ensures equal nodes are not built multiple times but just once. For example if attribute( 'uv' ) is used multiple times by the user, the b…
.getUpdateAfterType() : NodeUpdateTypeReturns the update type of Node#updateAfter.
.getUpdateBeforeType() : NodeUpdateTypeReturns the update type of Node#updateBefore.
.getUpdateType() : NodeUpdateTypeReturns the update type of Node#update.
.isGlobal( builder : NodeBuilder ) : booleanBy default this method returns the value of the Node#global flag. This method can be overwritten in derived classes if an analytical way is required to determine the global cache …
.onFrameUpdate( callback : function ) : NodeConvenient method for defining Node#update. Similar to Node#onUpdate, but this method automatically sets the update type to FRAME.
.onObjectUpdate( callback : function ) : NodeConvenient method for defining Node#update. Similar to Node#onUpdate, but this method automatically sets the update type to OBJECT.
.onReference( callback : function ) : NodeConvenient method for defining Node#updateReference.
.onRenderUpdate( callback : function ) : NodeConvenient method for defining Node#update. Similar to Node#onUpdate, but this method automatically sets the update type to RENDER.
.onUpdate( callback : function, updateType : string ) : NodeConvenient method for defining Node#update.
.serialize( json : Object )Serializes the node to JSON.
.setup( builder : NodeBuilder ) : NodeRepresents the setup stage which is the first step of the build process, see Node#build method. This method is often overwritten in derived modules to prepare the node which is use…
.toJSON( meta : Object ) : ObjectSerializes the node into the three.js JSON Object/Scene format.
.traverse( callback : traverseCallback )Can be used to traverse through the node's hierarchy.
.update( frame : NodeFrame ) : boolean (abstract)The method can be implemented to update the node's internal state when it is used to render an object. The Node#updateType property defines how often the update is executed.
.updateAfter( frame : NodeFrame ) : boolean (abstract)The method can be implemented to update the node's internal state after it was used to render an object. The Node#updateAfterType property defines how often the update is…
.updateBefore( frame : NodeFrame ) : boolean (abstract)The method can be implemented to update the node's internal state before it is used to render an object. The Node#updateBeforeType property defines how often the update …
.updateReference( state : any ) : anyNodes might refer to other objects like materials. This method allows to dynamically update the reference to such objects based on a given state (e.g. the current node frame or builder).

Key Takeaways

  1. Node extends: EventDispatcher
  2. Most relevant properties: global, id, isNode, name.
  3. Key methods: analyze, build, customCacheKey, deserialize.

Connects To