WebGL FinalMesh API | 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 state. BIt combination of following flags:

  • 1 - this node and object visible. If not set, object attached to this node is hidden.
  • 2 - children nodes are visible. If not set, all sub-objects are hidden.
  • 4 - selected. Set if node currently selected.
  • 8 - closed.
  • 16 - no z write. May be used by markups or other nodes in order to provide "special" effects.
  • 64 - no hit testing. When set, object can't be selected by mouse click in 3d window.
  • 0x80 - hide in tree view. Used by tree view control.
  • 0x100 - cast shadows (this object only)
  • 0x200 - receive shadows (this object only)
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.

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.

.search(name)

Method searches sub-node in this node by name.

name Name of the node.

null is returned if such node was not found.

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:

 

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
	  

Learn more

.getWTM()

Method returns world space transformation matrix of this node.

.getBoundingBox(tm,b,vis)

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.