Reference Source
public class | source

Node

Extends:

Component → Node

Implements:

An Entity that is a scene graph node that can have child Nodes and Meshes.

Usage

The example below is the same as the one given for Mesh, since the two classes work together. In this example, we'll create a scene graph in which a root Node represents a group and the Meshs are leaves. Since Node implements Entity, we can designate the root Node as a model, causing it to be registered by its ID in Scene#models.

Since Mesh also implements Entity, we can designate the leaf Meshes as objects, causing them to be registered by their IDs in Scene#objects.

We can then find those Entity types in Scene#models and Scene#objects.

We can also update properties of our object-Meshes via calls to Scene#setObjectsHighlighted etc.

[Run this example]

import {Viewer} from "../src/viewer/Viewer.js";
import {Mesh} from "../src/scene/mesh/Mesh.js";
import {Node} from "../src/scene/nodes/Node.js";
import {PhongMaterial} from "../src/scene/materials/PhongMaterial.js";

const viewer = new Viewer({
    canvasId: "myCanvas"
});

viewer.scene.camera.eye = [-21.80, 4.01, 6.56];
viewer.scene.camera.look = [0, -5.75, 0];
viewer.scene.camera.up = [0.37, 0.91, -0.11];

new Node(viewer.scene, {
     id: "table",
     isModel: true, // <---------- Node represents a model, so is registered by ID in viewer.scene.models
     rotation: [0, 50, 0],
     position: [0, 0, 0],
     scale: [1, 1, 1],

     children: [

         new Mesh(viewer.scene, { // Red table leg
             id: "redLeg",
             isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects
             position: [-4, -6, -4],
             scale: [1, 3, 1],
             rotation: [0, 0, 0],
             material: new PhongMaterial(viewer.scene, {
                 diffuse: [1, 0.3, 0.3]
             })
         }),

         new Mesh(viewer.scene, { // Green table leg
             id: "greenLeg",
             isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects
             position: [4, -6, -4],
             scale: [1, 3, 1],
             rotation: [0, 0, 0],
             material: new PhongMaterial(viewer.scene, {
                 diffuse: [0.3, 1.0, 0.3]
             })
         }),

         new Mesh(viewer.scene, {// Blue table leg
             id: "blueLeg",
             isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects
             position: [4, -6, 4],
             scale: [1, 3, 1],
             rotation: [0, 0, 0],
             material: new PhongMaterial(viewer.scene, {
                 diffuse: [0.3, 0.3, 1.0]
             })
         }),

         new Mesh(viewer.scene, {  // Yellow table leg
             id: "yellowLeg",
             isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects
             position: [-4, -6, 4],
             scale: [1, 3, 1],
             rotation: [0, 0, 0],
             material: new PhongMaterial(viewer.scene, {
                  diffuse: [1.0, 1.0, 0.0]
             })
         }),

         new Mesh(viewer.scene, { // Purple table top
             id: "tableTop",
             isObject: true, // <------ Node represents an object, so is registered by ID in viewer.scene.objects
             position: [0, -3, 0],
             scale: [6, 0.5, 6],
             rotation: [0, 0, 0],
             material: new PhongMaterial(viewer.scene, {
                 diffuse: [1.0, 0.3, 1.0]
             })
         })
     ]
 });

// Find Nodes and Meshes by their IDs

var table = viewer.scene.models["table"];                // Since table Node has isModel == true

var redLeg = viewer.scene.objects["redLeg"];             // Since the Meshes have isObject == true
var greenLeg = viewer.scene.objects["greenLeg"];
var blueLeg = viewer.scene.objects["blueLeg"];

// Highlight one of the table leg Meshes

viewer.scene.setObjectsHighlighted(["redLeg"], true);    // Since the Meshes have isObject == true

// Periodically update transforms on our Nodes and Meshes

viewer.scene.on("tick", function () {

      // Rotate legs
      redLeg.rotateY(0.5);
      greenLeg.rotateY(0.5);
      blueLeg.rotateY(0.5);

      // Rotate table
      table.rotateY(0.5);
      table.rotateX(0.3);
  });

Metadata

As mentioned, we can also associate MetaModels and MetaObjects with our Nodes and Meshes, within a MetaScene. See MetaScene for an example.

Constructor Summary

Public Constructor
public

constructor(owner: Component, cfg: *)

Member Summary

Public Members
public get

Gets the Node's World-space 3D axis-aligned bounding box.

Represented by a six-element Float32Array containing the min/max extents of the axis-aligned volume, ie. [xmin, ymin,zmin,xmax,ymax, zmax].

public get

Gets if this Node casts shadows.

public set

Sets if this Node and all child Nodes and Meshes cast shadows.

public get

Array of child Nodes or Meshes.

public set

Sets if this Node and all child Nodes and Meshes are clippable.

public get

Gets if this Node is clippable.

public get

Gets if this Node is included in boundary calculations.

public set

Sets if this Node and all child Nodes and Meshes are included in boundary calculations.

public get

Gets the RGB colorize color for this Node.

public set

Sets the RGB colorize color for this Node and all child Nodes and Meshes}.

public set

Sets if this Node and all child Nodes and Meshes are culled.

public get

Gets if this Node is culled.

public set

Sets if this Node and all child Nodes and Meshes are edge-enhanced.

public get

Gets if this Node's edges are enhanced.

Child Nodes and Meshes may have different values for this property.

public set

Sets if this Node and all child Nodes and Meshes are highlighted.

public get

Gets if this Node is highlighted.

public get

Returns true to indicate that this Component is an Entity.

public get

Returns true if this Mesh represents a model.

public get

Returns true to indicate that this Component is a Node.

public get abstract

Returns true if this Node represents an object.

public set

Sets the Node's local modeling transform matrix.

Default value is [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1].

public get

Gets the Node's local modeling transform matrix.

Default value is [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1].

public get

Number of child Nodes or Meshes.

public set

Sets the opacity factor for this Node and all child Nodes and Meshes.

public get

Gets this Node's opacity factor.

This is a factor in range [0..1] which multiplies by the rendered fragment alphas.

Child Nodes and Meshes may have different values for this property.

public set

The parent Node.

public get

The parent Node.

public set

Sets if this Node and all child Nodes and Meshes are pickable.

public get

Gets if to this Node is pickable.

public set

Sets the Node's local translation.

Default value is [0,0,0].

public get

Gets the Node's local translation.

Default value is [0,0,0].

public set

Sets the Node's local rotation quaternion.

Default value is [0,0,0,1].

public get

Gets the Node's local rotation quaternion.

Default value is [0,0,0,1].

public set

Sets if this Node and all child Nodes and Meshes can have shadows cast upon them.

public get

Whether or not to this Node can have shadows cast upon it.

public set

Sets the Node's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis.

Default value is [0,0,0].

public get

Gets the Node's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis.

Default value is [0,0,0].

public set

Sets the Node's local scale.

Default value is [1,1,1].

public get

Gets the Node's local scale.

Default value is [1,1,1].

public set

Sets if this Node and all child Nodes and Meshes are selected.

public get

Gets if this Node is selected.

public set

Sets if this Node and all child Nodes and Meshes are visible.

public get

Gets if this Node is visible.

public get

Gets the Node's World matrix.

public set

Sets if this Node and all child Nodes and Meshes are xrayed.

public get

Gets if this Node is xrayed.

Method Summary

Public Methods
public

addChild(child: Node | Mesh | String, inheritStates: *): Node | Mesh

Adds a child Node or Mesh.

public

Destroys this Node.

public

removeChild(child: Node | Mesh)

Removes the given child Node or Mesh.

public

Removes all child Nodes and Meshes.

public

rotate(axis: Number[], angle: Number): *

Rotates the Node about the given local axis by the given increment.

public

rotateOnWorldAxis(axis: Number[], angle: Number): *

Rotates the Node about the given World-space axis by the given increment.

public

rotateX(angle: Number): *

Rotates the Node about the local X-axis by the given increment.

public

rotateY(angle: Number): *

Rotates the Node about the local Y-axis by the given increment.

public

rotateZ(angle: Number): *

Rotates the Node about the local Z-axis by the given increment.

public

translate(axis: Number[], distance: Number): *

Translates the Node along local space vector by the given increment.

public

translateX(distance: Number): *

Translates the Node along the local X-axis by the given increment.

public

translateY(distance: Number): *

Translates the Node along the local Y-axis by the given increment.

public

translateZ(distance: Number): *

Translates the Node along the local Z-axis by the given increment.

Inherited Summary

From class Component
public get

The Component that owns the lifecycle of this Component, if any.

public

True as soon as this Component has been destroyed

public

ID of this Component, unique within the Scene.

public

meta: *

Arbitrary, user-defined metadata on this component.

public

The parent Scene that contains this Component.

public

The viewer that contains this Scene.

public

clear()

Destroys all Components that are owned by this.

public

Destroys this component.

public

error(message: String)

Logs an error for this component to the JavaScript console.

public

fire(event: String, value: Object, forget: Boolean)

Fires an event on this component.

public

Returns true if there are any subscribers to the given event on this component.

public

isType(type: *): *: Boolean

Tests if this component is of the given type, or is a subclass of the given type.

public

log(message: String)

Logs a console debugging message for this component.

public

off(subId: String)

Cancels an event subscription that was previously made with Component#on or Component#once.

public

on(event: String, callback: Function, scope: Object): String

Subscribes to an event on this component.

public

once(event: String, callback: Function, scope: Object)

Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd.

public

warn(message: String)

Logs a warning for this component to the JavaScript console.

Public Constructors

public constructor(owner: Component, cfg: *) source

Override:

Component#constructor

Params:

NameTypeAttributeDescription
owner Component

Owner component. When destroyed, the owner will destroy this component as well.

cfg *
  • optional

Configs

cfg.id String
  • optional

Optional ID, unique among all components in the parent scene, generated automatically when omitted.

cfg.isModel Boolean
  • optional

Specify true if this Mesh represents a model, in which case the Mesh will be registered by Mesh#id in Scene#models and may also have a corresponding MetaModel with matching MetaModel#id, registered by that ID in MetaScene#metaModels.

cfg.isObject Boolean
  • optional

Specify true if this Mesh represents an object, in which case the Mesh will be registered by Mesh#id in Scene#objects and may also have a corresponding MetaObject with matching MetaObject#id, registered by that ID in MetaScene#metaObjects.

cfg.parent Node
  • optional

The parent Node.

cfg.position Number[]
  • optional
  • default: [0,0,0]

Local 3D position.

cfg.scale Number[]
  • optional
  • default: [1,1,1]

Local scale.

cfg.rotation Number[]
  • optional
  • default: [0,0,0]

Local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis.

cfg.matrix Number[]
  • optional
  • default: [1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1] Local modelling transform matrix. Overrides the position, scale and rotation parameters.
cfg.visible Boolean
  • optional
  • default: true

Indicates if the Node is initially visible.

cfg.culled Boolean
  • optional
  • default: false

Indicates if the Node is initially culled from view.

cfg.pickable Boolean
  • optional
  • default: true

Indicates if the Node is initially pickable.

cfg.clippable Boolean
  • optional
  • default: true

Indicates if the Node is initially clippable.

cfg.collidable Boolean
  • optional
  • default: true

Indicates if the Node is initially included in boundary calculations.

cfg.castsShadow Boolean
  • optional
  • default: true

Indicates if the Node initially casts shadows.

cfg.receivesShadow Boolean
  • optional
  • default: true

Indicates if the Node initially receives shadows.

cfg.xrayed Boolean
  • optional
  • default: false

Indicates if the Node is initially xrayed.

cfg.highlighted Boolean
  • optional
  • default: false

Indicates if the Node is initially highlighted.

cfg.selected Boolean
  • optional
  • default: false

Indicates if the Mesh is initially selected.

cfg.edges Boolean
  • optional
  • default: false

Indicates if the Node's edges are initially emphasized.

cfg.colorize Number[]
  • optional
  • default: [1.0,1.0,1.0]

Node's initial RGB colorize color, multiplies by the rendered fragment colors.

cfg.opacity Number
  • optional
  • default: 1.0

Node's initial opacity factor, multiplies by the rendered fragment alpha.

cfg.children Array
  • optional

Child Nodes or Meshes to add initially. Children must be in the same Scene and will be removed first from whatever parents they may already have.

cfg.inheritStates Boolean
  • optional
  • default: true

Indicates if children given to this constructor should inherit rendering state from this parent as they are added. Rendering state includes Node#visible, Node#culled, Node#pickable, Node#clippable, Node#castsShadow, Node#receivesShadow, Node#selected, Node#highlighted, Node#colorize and Node#opacity.

Public Members

public get aabb: Number[] source

Gets the Node's World-space 3D axis-aligned bounding box.

Represented by a six-element Float32Array containing the min/max extents of the axis-aligned volume, ie. [xmin, ymin,zmin,xmax,ymax, zmax].

public get castsShadow: Boolean source

Gets if this Node casts shadows.

Child Nodes and Meshes may have different values for this property.

public set castsShadow: Boolean source

Sets if this Node and all child Nodes and Meshes cast shadows.

public get children: Array source

Array of child Nodes or Meshes.

public set clippable: Boolean source

Sets if this Node and all child Nodes and Meshes are clippable.

Clipping is done by the SectionPlanes in Scene#clips.

public get clippable: Boolean source

Gets if this Node is clippable.

Clipping is done by the SectionPlanes in Scene#clips.

Child Nodes and Meshes may have different values for this property.

public get collidable: Boolean source

Gets if this Node is included in boundary calculations.

Child Nodes and Meshes may have different values for this property.

public set collidable: Boolean source

Sets if this Node and all child Nodes and Meshes are included in boundary calculations.

public get colorize: Number[] source

Gets the RGB colorize color for this Node.

Each element of the color is in range [0..1].

Child Nodes and Meshes may have different values for this property.

public set colorize: Number[] source

Sets the RGB colorize color for this Node and all child Nodes and Meshes}.

Multiplies by rendered fragment colors.

Each element of the color is in range [0..1].

public set culled: Boolean source

Sets if this Node and all child Nodes and Meshes are culled.

public get culled: Boolean source

Gets if this Node is culled.

public set edges: Boolean source

Sets if this Node and all child Nodes and Meshes are edge-enhanced.

public get edges: Boolean source

Gets if this Node's edges are enhanced.

Child Nodes and Meshes may have different values for this property.

public set highlighted: Boolean source

Sets if this Node and all child Nodes and Meshes are highlighted.

When Node#isObject and Node#highlighted are both true the Node will be registered by Node#id in Scene#highlightedObjects.

public get highlighted: Boolean source

Gets if this Node is highlighted.

When Node#isObject and Node#highlighted are both true the Node will be registered by Node#id in Scene#highlightedObjects.

Child Nodes and Meshes may have different values for this property.

public get isEntity: Boolean source

Returns true to indicate that this Component is an Entity.

public get isModel: Boolean source

Returns true if this Mesh represents a model.

When this returns true, the Mesh will be registered by Mesh#id in Scene#models and may also have a corresponding MetaModel.

public get isNode: Boolean source

Returns true to indicate that this Component is a Node.

public get abstract isObject: Boolean source

Returns true if this Node represents an object.

When true the Node will be registered by Node#id in Scene#objects and may also have a MetaObject with matching MetaObject#id.

public set matrix: Number[] source

Sets the Node's local modeling transform matrix.

Default value is [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1].

public get matrix: Number[] source

Gets the Node's local modeling transform matrix.

Default value is [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1].

public get numChildren: Number source

Number of child Nodes or Meshes.

public set opacity: Number source

Sets the opacity factor for this Node and all child Nodes and Meshes.

This is a factor in range [0..1] which multiplies by the rendered fragment alphas.

public get opacity: Number source

Gets this Node's opacity factor.

This is a factor in range [0..1] which multiplies by the rendered fragment alphas.

Child Nodes and Meshes may have different values for this property.

public set parent: Node source

The parent Node.

The parent Node may also be set by passing the Node to the parent's Node#addChild method.

public get parent: Node source

The parent Node.

public set pickable: Boolean source

Sets if this Node and all child Nodes and Meshes are pickable.

Picking is done via calls to Scene#pick.

public get pickable: Boolean source

Gets if to this Node is pickable.

Picking is done via calls to Scene#pick.

Child Nodes and Meshes may have different values for this property.

public set position: Number[] source

Sets the Node's local translation.

Default value is [0,0,0].

public get position: Number[] source

Gets the Node's local translation.

Default value is [0,0,0].

public set quaternion: Number[] source

Sets the Node's local rotation quaternion.

Default value is [0,0,0,1].

public get quaternion: Number[] source

Gets the Node's local rotation quaternion.

Default value is [0,0,0,1].

public set receivesShadow: Boolean source

Sets if this Node and all child Nodes and Meshes can have shadows cast upon them.

public get receivesShadow: Boolean source

Whether or not to this Node can have shadows cast upon it.

Child Nodes and Meshes may have different values for this property.

public set rotation: Number[] source

Sets the Node's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis.

Default value is [0,0,0].

public get rotation: Number[] source

Gets the Node's local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis.

Default value is [0,0,0].

public set scale: Number[] source

Sets the Node's local scale.

Default value is [1,1,1].

public get scale: Number[] source

Gets the Node's local scale.

Default value is [1,1,1].

public set selected: Boolean source

Sets if this Node and all child Nodes and Meshes are selected.

When Node#isObject and Node#selected are both true the Node will be registered by Node#id in Scene#selectedObjects.

public get selected: Boolean source

Gets if this Node is selected.

When Node#isObject and Node#selected are both true the Node will be registered by Node#id in Scene#selectedObjects.

Child Nodes and Meshes may have different values for this property.

public set visible: Boolean source

Sets if this Node and all child Nodes and Meshes are visible.

Only rendered both Node#visible is true and Node#culled is false.

When Node#isObject and Node#visible are both true the Node will be registered by Node#id in Scene#visibleObjects.

public get visible: Boolean source

Gets if this Node is visible.

Child Nodes and Meshes may have different values for this property.

When Node#isObject and Node#visible are both true the Node will be registered by Node#id in Scene#visibleObjects.

public get worldMatrix: Number[] source

Gets the Node's World matrix.

Properties:

NameTypeAttributeDescription
worldMatrix *

public set xrayed: Boolean source

Sets if this Node and all child Nodes and Meshes are xrayed.

When Node#isObject and Node#xrayed are both true the Node will be registered by Node#id in Scene#xrayedObjects.

public get xrayed: Boolean source

Gets if this Node is xrayed.

When Node#isObject and Node#xrayed are both true the Node will be registered by Node#id in Scene#xrayedObjects.

Child Nodes and Meshes may have different values for this property.

Public Methods

public addChild(child: Node | Mesh | String, inheritStates: *): Node | Mesh source

Adds a child Node or Mesh.

The child must be a Node or Mesh in the same Scene.

If the child already has a parent, will be removed from that parent first.

Does nothing if already a child.

Params:

NameTypeAttributeDescription
child Node | Mesh | String

Instance or ID of the child to add.

inheritStates *
  • optional
  • default: false

Indicates if the child should inherit rendering states from this parent as it is added. Rendering state includes Node#visible, Node#culled, Node#pickable, Node#clippable, Node#castsShadow, Node#receivesShadow, Node#selected, Node#highlighted, Node#colorize and Node#opacity.

Return:

Node | Mesh

The child.

public destroy() source

Destroys this Node.

Override:

Component#destroy

public removeChild(child: Node | Mesh) source

Removes the given child Node or Mesh.

Params:

NameTypeAttributeDescription
child Node | Mesh

Child to remove.

public removeChildren() source

Removes all child Nodes and Meshes.

public rotate(axis: Number[], angle: Number): * source

Rotates the Node about the given local axis by the given increment.

Params:

NameTypeAttributeDescription
axis Number[]

Local axis about which to rotate.

angle Number

Angle increment in degrees.

Return:

*

public rotateOnWorldAxis(axis: Number[], angle: Number): * source

Rotates the Node about the given World-space axis by the given increment.

Params:

NameTypeAttributeDescription
axis Number[]

Local axis about which to rotate.

angle Number

Angle increment in degrees.

Return:

*

public rotateX(angle: Number): * source

Rotates the Node about the local X-axis by the given increment.

Params:

NameTypeAttributeDescription
angle Number

Angle increment in degrees.

Return:

*

public rotateY(angle: Number): * source

Rotates the Node about the local Y-axis by the given increment.

Params:

NameTypeAttributeDescription
angle Number

Angle increment in degrees.

Return:

*

public rotateZ(angle: Number): * source

Rotates the Node about the local Z-axis by the given increment.

Params:

NameTypeAttributeDescription
angle Number

Angle increment in degrees.

Return:

*

public translate(axis: Number[], distance: Number): * source

Translates the Node along local space vector by the given increment.

Params:

NameTypeAttributeDescription
axis Number[]

Normalized local space 3D vector along which to translate.

distance Number

Distance to translate along the vector.

Return:

*

public translateX(distance: Number): * source

Translates the Node along the local X-axis by the given increment.

Params:

NameTypeAttributeDescription
distance Number

Distance to translate along the X-axis.

Return:

*

public translateY(distance: Number): * source

Translates the Node along the local Y-axis by the given increment.

Params:

NameTypeAttributeDescription
distance Number

Distance to translate along the Y-axis.

Return:

*

public translateZ(distance: Number): * source

Translates the Node along the local Z-axis by the given increment.

Params:

NameTypeAttributeDescription
distance Number

Distance to translate along the Z-axis.

Return:

*