WebGL 3D Node
iv.node
This is 3d node in 3d space.
Constructor
iv.node();
Use new iv.node() or node.newNode() in order to create new node. new iv.node() creates node with zero reference count.
Properties
object | 3d object, triangle mesh, light or camera for instance. | ||||||||||||||||||||||||||||||
tm | Local transformation matrix. May be null - equals to identity matrix. | ||||||||||||||||||||||||||||||
wtm | World space transformation matrix. May be used for caching purposes. | ||||||||||||||||||||||||||||||
name | Node name. Empty string is default. | ||||||||||||||||||||||||||||||
material | Material attached to node. This material is used only by object attached to this node. Does not applied recursively to all subnodes | ||||||||||||||||||||||||||||||
state | Node flags. BIt combination of the following values:
|
||||||||||||||||||||||||||||||
stage | Node render stage. It can be one of the following values.
If order-independent transparency is used, transparency stages (4, 5) are rendered in one stage and z-buffer is not affected by transparent objects. |
||||||||||||||||||||||||||||||
parent | Parent node. May be null or undefined. | ||||||||||||||||||||||||||||||
firstChild | First child node. May be null or undefined. | ||||||||||||||||||||||||||||||
lastChild | Last child node. May be null or undefined. | ||||||||||||||||||||||||||||||
next | Next node in list of child nodes. May be null or undefined. | ||||||||||||||||||||||||||||||
ref | Reference count to this node. | ||||||||||||||||||||||||||||||
anim | Optional data for animation. | ||||||||||||||||||||||||||||||
rmode | per node render mode. Affects whole subtree, starting from this node. Set to string name of render mode. During rendering it may be replaced intrenal index of render mode. For list of possible value see this. | ||||||||||||||||||||||||||||||
opacity | Opacity of node and all sub-nodes. undefined means 1.0 opacity. Please note that opacity of rendered object is multiplication of all parent nodes opacities. | ||||||||||||||||||||||||||||||
meta | Optional metadata object. Learn more about metadata usage. |
Methods
.setState(a)
Method can change state variable of this node.
state | State to set |
mask | Mask |
Method returns true is state was changed, false if state was same already.
.newNode()
Method creates new child node and returns it.
.insert(node)
Method inserts node as child into this node.
node | Node to select. |
Method returns inserted node. Method increments reference count of node.
.remove(node)
Method removes child node.
node | Node to remove. |
If the method succeeds, the return value is true.
.clear()
Methods removes all objects and nodes from whole sub-tree.
.setObject(obj)
Method attaches object to this node. This method increases reference count of new object and decreases count of old one.
obj | Object. |
Method searches sub-node in this node by name.
name | Name of the node. |
null is returned if such node was not found.
Notifications
Learn more about notification functions, node notification events.
Selection
.select(node,sel,keep)
Method selects node in 3d space. This method works with 3rd bit (state&4)of state attribute.
node | Node to select. |
sel | true for select node, false - deselect. |
keep | Keep old selection. In false previous selection will be removed. |
.getSelection(a)
Method return list of selected nodes.
a | Optional empty array, where selection will be stored. If a was not specified and selection is not empty, new array will be created. |
If selection is empty, unmodified a will be returned.
Visibility
Visibility of node is controlled by 0 and 1 bits in state variable. state&1 - node itself is visible, state&2 children objects are visible.
Toggle visibility can be done in one of the following ways:
- n.state^=3;
- n.state|=1; // show this object
- n.state&=~1; // hide this object
- if(n.visible())n.hide();else n.show();
- n.show(!n.visible());
Following function can be used in order to show hide nodes.
.show(a)
Show or hide node.
a | [optional] if a is not specified, visibility status will be set. If a is provided, visibility will be set to value a. |
Method returns true is state was changed, false if node was visible/hidden already. You should update viewport in order to reflect changes.
.hide()
Hides node. Method returns false if node was hidden before.
.visible()
It returns true if node is visible and false if hidden.
Transformations
Position of node is defined by local transformation matrix. tm property.
.enableTM()
Method creates local transformation matrix - if not exist already and returns it. You can modify returned in order to change position of node. In order to reset transformation, set matrix to identity state or set .tm property to null.
var tm=n.enableTM(); tm[12]=x; // move node by X axis
.getWTM()
Method returns world space transformation matrix of this node.
Method calculates world space bounding box using specified transformation matrix.
tm | Transformation matrix |
b | b should be null for first call. |
vis | boolean flags. When true, only visible objects will be included in bounding box |
Methods returns bounding box in required coordinate system. Bounding box is defined by two points - first point in first 3 elements of array, second is in last 3.
Animation
.setTime(time)
Method changes current animation position measured in seconds. It updates transformation matrix by calculating new position, rotation and scaling.
time | Time in seconds |
.getTime()
Method retrieves current animation position, in seconds.