Node
Extends:
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.
import {Viewer, Mesh, Node, PhongMaterial} from "xeokit-sdk.es.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 Float64Array containing the min/max extents of the
axis-aligned volume, ie. |
|
public set |
Sets if this Node and all child Nodes and Meshes cast shadows. |
|
public get |
Gets if this Node casts 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 set |
Sets if this Node and all child Nodes and Meshes are included in boundary calculations. |
|
public get |
Gets if this Node is included in boundary calculations. |
|
public set |
Sets the RGB colorize color for this Node and all child Nodes and Meshes}. |
|
public get |
Gets the RGB colorize color for this Node. |
|
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 |
|
public get |
Returns true to indicate that this Component is a Node. |
|
public get abstract |
Returns |
|
public set |
Sets the Node's local modeling transform matrix. Default value is |
|
public get |
Gets the Node's local modeling transform matrix. Default value is |
|
public get |
Number of child Nodes or Meshes. |
|
public get |
The number of triangles in this Node. |
|
public set |
Sets the 3D World-space offset for this Node and all child Nodes and Meshes}. |
|
public get |
Gets the Node's 3D World-space offset. Default value is Child Nodes and Meshes may have different values for this property. |
|
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 Child Nodes and Meshes may have different values for this property. |
|
public set |
Sets the World-space origin for this Node. |
|
public get |
Gets the World-space origin for this Node. |
|
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 |
|
public get |
Gets the Node's local translation. Default value is |
|
public set |
quaternion: Number[] Sets the Node's local rotation quaternion. Default value is |
|
public get |
quaternion: Number[] Gets the Node's local rotation quaternion. Default value is |
|
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 |
|
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 |
|
public set |
this set was deprecated.
Sets the World-space origin for this Node. |
|
public get |
this get was deprecated.
Gets the World-space origin for this Node. |
|
public get abstract |
Gets if this Node can have Scalable Ambient Obscurance (SAO) applied to it. |
|
public set |
Sets the Node's local scale. Default value is |
|
public get |
Gets the Node's local scale. Default value is |
|
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 |
Adds a child Node or Mesh. |
|
public |
destroy() Destroys this Node. |
|
public |
removeChild(child: Node | Mesh) Removes the given child Node or Mesh. |
|
public |
Removes all child Nodes and Meshes. |
|
public |
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 |
Rotates the Node about the local X-axis by the given increment. |
|
public |
Rotates the Node about the local Y-axis by the given increment. |
|
public |
Rotates the Node about the local Z-axis by the given increment. |
|
public |
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 |
destroy() Destroys this component. |
|
public |
Logs an error for this component to the JavaScript console. |
|
public |
Fires an event on this component. |
|
public |
Returns true if there are any subscribers to the given event on this component. |
|
public |
Tests if this component is of the given type, or is a subclass of the given type. |
|
public |
Logs a console debugging message for this component. |
|
public |
Cancels an event subscription that was previously made with Component#on or Component#once. |
|
public |
Subscribes to an event on this component. |
|
public |
Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd. |
|
public |
scheduleTask(task: *) Schedule a task to perform on the next browser interval |
|
public |
Logs a warning for this component to the JavaScript console. |
Public Constructors
public constructor(owner: Component, cfg: *) source
Override:
Component#constructorParams:
Name | Type | Attribute | Description |
owner | Component | Owner component. When destroyed, the owner will destroy this component as well. |
|
cfg | * |
|
Configs |
cfg.id | String |
|
Optional ID, unique among all components in the parent scene, generated automatically when omitted. |
cfg.isModel | Boolean |
|
Specify |
cfg.isObject | Boolean |
|
Specify |
cfg.parent | Node |
|
The parent Node. |
cfg.origin | Number[] |
|
World-space origin for this Node. |
cfg.rtcCenter | Number[] |
|
Deprecated - renamed to |
cfg.position | Number[] |
|
Local 3D position. |
cfg.scale | Number[] |
|
Local scale. |
cfg.rotation | Number[] |
|
Local rotation, as Euler angles given in degrees, for each of the X, Y and Z axis. |
cfg.matrix | Number[] |
|
|
cfg.offset | Number[] |
|
World-space 3D translation offset. Translates the Node in World space, after modelling transforms. |
cfg.visible | Boolean |
|
Indicates if the Node is initially visible. |
cfg.culled | Boolean |
|
Indicates if the Node is initially culled from view. |
cfg.pickable | Boolean |
|
Indicates if the Node is initially pickable. |
cfg.clippable | Boolean |
|
Indicates if the Node is initially clippable. |
cfg.collidable | Boolean |
|
Indicates if the Node is initially included in boundary calculations. |
cfg.castsShadow | Boolean |
|
Indicates if the Node initially casts shadows. |
cfg.receivesShadow | Boolean |
|
Indicates if the Node initially receives shadows. |
cfg.xrayed | Boolean |
|
Indicates if the Node is initially xrayed. |
cfg.highlighted | Boolean |
|
Indicates if the Node is initially highlighted. |
cfg.selected | Boolean |
|
Indicates if the Mesh is initially selected. |
cfg.edges | Boolean |
|
Indicates if the Node's edges are initially emphasized. |
cfg.colorize | Number[] |
|
Node's initial RGB colorize color, multiplies by the rendered fragment colors. |
cfg.opacity | Number |
|
Node's initial opacity factor, multiplies by the rendered fragment alpha. |
cfg.children | Array |
|
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 |
|
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 Float64Array containing the min/max extents of the
axis-aligned volume, ie. [xmin, ymin,zmin,xmax,ymax, zmax]
.
public set castsShadow: Boolean source
Sets if this Node and all child Nodes and Meshes cast shadows.
public get castsShadow: Boolean source
Gets if this Node casts shadows.
Child Nodes and Meshes may have different values for this property.
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 set collidable: Boolean source
Sets if this Node and all child Nodes and Meshes are included in boundary calculations.
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 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 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 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 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 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 set offset: Number[] source
Sets the 3D World-space offset for this Node and all child Nodes and Meshes}.
The offset dynamically translates those components in World-space.
Default value is [0, 0, 0]
.
Note that child Nodes and Meshes may subsequently be given different values for this property.
public get offset: Number[] source
Gets the Node's 3D World-space offset.
Default value is [0, 0, 0]
.
Child Nodes and Meshes may have different values for this property.
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 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 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 rtcCenter: Float64Array source
Sets the World-space origin for this Node.
Deprecated and replaced by Node#origin.
public get rtcCenter: Float64Array source
Gets the World-space origin for this Node.
Deprecated and replaced by Node#origin.
public get abstract saoEnabled: Boolean source
Gets if this Node can have Scalable Ambient Obscurance (SAO) applied to it.
SAO is configured by SAO.
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
child | Node | Mesh | String | Instance or ID of the child to add. |
|
inheritStates | * |
|
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. |
public rotate(axis: Number[], angle: Number): * source
Rotates the Node about the given local axis by the given increment.
Return:
* |
public rotateOnWorldAxis(axis: Number[], angle: Number): * source
Rotates the Node about the given World-space axis by the given increment.
Return:
* |
public rotateX(angle: Number): * source
Rotates the Node about the local X-axis by the given increment.
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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.
Return:
* |
public translateX(distance: Number): * source
Translates the Node along the local X-axis by the given increment.
Params:
Name | Type | Attribute | Description |
distance | Number | Distance to translate along the X-axis. |
Return:
* |