import {NavCubePlugin} from '@xeokit/xeokit-sdk/src/plugins/NavCubePlugin/NavCubePlugin.js'
NavCubePlugin
Extends:
Viewer plugin that lets us look at the entire Scene from along a chosen axis or diagonal.
Overview
- Rotating the NavCube causes the Viewer's Camera to orbit its current point-of-interest. Conversely, orbiting the Camera causes the NavCube to rotate accordingly.
- The faces of the NavCube are aligned with the Viewer's Scene's World-space coordinate axis. Clicking on a face moves the Camera to look at the entire Scene along the corresponding axis. Clicking on an edge or a corner looks at the entire Scene along a diagonal.
- The NavCube can be configured to either jump or fly the Camera to each new position. We can configure how tightly the NavCube fits the Scene to view, and when flying, we can configure how fast it flies. We can also configure whether the NavCube fits all objects to view, or just the currently visible objects. See below for a usage example.
- Clicking the NavCube also sets CameraControl#pivotPos to the center of the fitted objects.
Usage
In the example below, we'll create a Viewer and add a NavCubePlugin, which will create a NavCube gizmo in the canvas with the given ID. Then we'll use the XKTLoaderPlugin to load a model into the Viewer's Scene. We can then use the NavCube to look at the model along each axis or diagonal.
import {Viewer, XKTLoaderPlugin, NavCubePlugin} from "xeokit-sdk.es.js";
const viewer = new Viewer({
canvasId: "myCanvas"
});
viewer.camera.eye = [-3.93, 2.85, 27.01];
viewer.camera.look = [4.40, 3.72, 8.89];
viewer.camera.up = [-0.01, 0.99, 0.03];
const navCube = new NavCubePlugin(viewer, {
canvasID: "myNavCubeCanvas",
visible: true, // Initially visible (default)
cameraFly: true, // Fly camera to each selected axis/diagonal
cameraFitFOV: 45, // How much field-of-view the scene takes once camera has fitted it to view
cameraFlyDuration: 0.5,// How long (in seconds) camera takes to fly to each new axis/diagonal
fitVisible: false, // Fit whole scene, including invisible objects (default)
synchProjection: false // Keep NavCube in perspective projection, even when camera switches to ortho (default)
});
const xktLoader = new XKTLoaderPlugin(viewer);
const model = xktLoader.load({
id: "myModel",
src: "./models/xkt/Duplex.ifc.xkt",
edges: true
});
Constructor Summary
Public Constructor | ||
public |
constructor(viewer: Viewer, cfg: Object) |
Method Summary
Public Methods | ||
public |
destroy() Destroys this NavCubePlugin. |
|
public | ||
public |
Gets whether the Camera flies or jumps to each selected axis or diagonal. |
|
public |
When flying the Camera to each new axis or diagonal, gets how long, in seconds, that the Camera takes to get there. |
|
public | ||
public |
Gets whether the NavCube switches between project north and true north |
|
public |
Gets the offset angle between project north and true north |
|
public |
Gets whether the NavCube switches between perspective and orthographic projections in synchrony with the Camera. |
|
public |
Gets if the NavCube is visible. |
|
public |
send(name: *, value: *) |
|
public |
setCameraFitFOV(cameraFitFOV: Number) |
|
public |
setCameraFly(cameraFly: Boolean) Sets whether the Camera flies or jumps to each selected axis or diagonal. |
|
public |
setCameraFlyDuration(cameraFlyDuration: Boolean) When flying the Camera to each new axis or diagonal, sets how long, in seconds, that the Camera takes to get there. |
|
public |
setFitVisible(fitVisible: Boolean) |
|
public |
setIsProjectNorth(isProjectNorth: Boolean) Sets whether the NavCube switches between project north and true north |
|
public |
setProjectNorthOffsetAngle(projectNorthOffsetAngle: number) Sets the NavCube project north offset angle (used when isProjectNorth is |
|
public |
setSynchProjection(synchProjection: Boolean) Sets whether the NavCube switches between perspective and orthographic projections in synchrony with the Camera. |
|
public |
setVisible(visible: Boolean) Sets if the NavCube is visible. |
Inherited Summary
From class Plugin | ||
public |
ID for this Plugin, unique within its Viewer. |
|
public |
The Viewer that contains this Plugin. |
|
public |
destroy() Destroys this Plugin and removes it from its Viewer. |
|
public |
Logs an error message to the JavaScript developer console, prefixed with the ID of this Plugin. |
|
public |
Fires an event on this Plugin. |
|
public |
Returns true if there are any subscribers to the given event on this Plugin. |
|
public |
Logs a message to the JavaScript developer console, prefixed with the ID of this Plugin. |
|
public |
Cancels an event subscription that was previously made with Plugin#on or Plugin#once. |
|
public |
Subscribes to an event on this Plugin. |
|
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 message to the JavaScript developer console, prefixed with the ID of this Plugin. |
Public Constructors
public constructor(viewer: Viewer, cfg: Object) source
Creates this Plugin and installs it into the given Viewer.
Override:
Plugin#constructorParams:
Name | Type | Attribute | Description |
viewer | Viewer | The Viewer. |
|
cfg | Object | NavCubePlugin configuration. |
|
cfg.id | String |
|
Optional ID for this plugin, so that we can find it within Viewer#plugins. |
cfg.canvasId | String |
|
ID of an existing HTML canvas to display the NavCube - either this or canvasElement is mandatory. When both values are given, the element reference is always preferred to the ID. |
cfg.canvasElement | HTMLCanvasElement |
|
Reference of an existing HTML canvas to display the NavCube - either this or canvasId is mandatory. When both values are given, the element reference is always preferred to the ID. |
cfg.visible | Boolean |
|
Initial visibility. |
cfg.shadowVisible | Boolean |
|
Whether the shadow of the cube is visible. |
cfg.cameraFly | String |
|
Whether the Camera flies or jumps to each selected axis or diagonal. |
cfg.cameraFitFOV | String |
|
How much of the field-of-view, in degrees, that the 3D scene should fill the Canvas when the Camera moves to an axis or diagonal. |
cfg.cameraFlyDuration | String |
|
When flying the Camera to each new axis or diagonal, how long, in seconds, that the Camera takes to get there. |
cfg.color | String |
|
Custom uniform color for the faces of the NavCube. |
cfg.frontColor | String |
|
Custom color for the front face of the NavCube. Overrides |
cfg.backColor | String |
|
Custom color for the back face of the NavCube. Overrides |
cfg.leftColor | String |
|
Custom color for the left face of the NavCube. Overrides |
cfg.rightColor | String |
|
Custom color for the right face of the NavCube. Overrides |
cfg.topColor | String |
|
Custom color for the top face of the NavCube. Overrides |
cfg.bottomColor | String |
|
Custom color for the bottom face of the NavCube. Overrides |
cfg.hoverColor | String |
|
Custom color for highlighting regions on the NavCube as we hover the pointer over them. |
cfg.textColor | String |
|
Custom text color for labels of the NavCube. |
cfg.fitVisible | Boolean |
|
Sets whether the axis, corner and edge-aligned views will fit the
view to the entire Scene or just to visible object-Entitys. Entitys are visible objects when Entity#isObject and Entity#visible are both |
cfg.synchProjection | Boolean |
|
Sets whether the NavCube switches between perspective and orthographic projections in synchrony with the Camera. When |
cfg.isProjectNorth | Boolean |
|
sets whether the NavCube switches between true north and project north - using the project north offset angle. |
cfg.projectNorthOffsetAngle | number |
|
sets the NavCube project north offset angle - when the isProjectNorth is true. |
Public Methods
public destroy() source
Destroys this NavCubePlugin.
Does not destroy the canvas the NavCubePlugin was configured with.
Override:
Plugin#destroypublic getCameraFitFOV(): Number source
Gets how much of the field-of-view, in degrees, that the Scene should fill the canvas when flying or jumping the Camera to each selected axis or diagonal.
Default value is 45
.
public getCameraFly(): Boolean source
Gets whether the Camera flies or jumps to each selected axis or diagonal.
Default is true
, to fly.
public getCameraFlyDuration(): Boolean source
When flying the Camera to each new axis or diagonal, gets how long, in seconds, that the Camera takes to get there.
Default is 0.5
.
public getFitVisible(): Boolean source
Gets whether the axis, corner and edge-aligned views will fit the view to the entire Scene or just to visible object-Entitys.
Entitys are visible objects when Entity#isObject and Entity#visible are both true
.
public getIsProjectNorth(): Boolean source
Gets whether the NavCube switches between project north and true north
public getProjectNorthOffsetAngle(): number source
Gets the offset angle between project north and true north
public getSynchProjection(): Boolean source
Gets whether the NavCube switches between perspective and orthographic projections in synchrony with
the Camera. When false
, the NavCube will always be rendered with perspective projection.
public send(name: *, value: *) source
Params:
Name | Type | Attribute | Description |
name | * | ||
value | * |
public setCameraFitFOV(cameraFitFOV: Number) source
Sets how much of the field-of-view, in degrees, that the Scene should fill the canvas when flying or jumping the Camera to each selected axis or diagonal.
Default value is 45
.
Params:
Name | Type | Attribute | Description |
cameraFitFOV | Number | New FOV value. |
public setCameraFly(cameraFly: Boolean) source
Sets whether the Camera flies or jumps to each selected axis or diagonal.
Default is true
, to fly.
Params:
Name | Type | Attribute | Description |
cameraFly | Boolean | Set |
public setCameraFlyDuration(cameraFlyDuration: Boolean) source
When flying the Camera to each new axis or diagonal, sets how long, in seconds, that the Camera takes to get there.
Default is 0.5
.
Params:
Name | Type | Attribute | Description |
cameraFlyDuration | Boolean | Camera flight duration in seconds. |
public setFitVisible(fitVisible: Boolean) source
Sets whether the axis, corner and edge-aligned views will fit the view to the entire Scene or just to visible object-Entitys.
Entitys are visible objects when Entity#isObject and Entity#visible are both true
.
Params:
Name | Type | Attribute | Description |
fitVisible | Boolean | Set |
public setIsProjectNorth(isProjectNorth: Boolean) source
Sets whether the NavCube switches between project north and true north
Params:
Name | Type | Attribute | Description |
isProjectNorth | Boolean | Set |
public setProjectNorthOffsetAngle(projectNorthOffsetAngle: number) source
Sets the NavCube project north offset angle (used when isProjectNorth is true
Params:
Name | Type | Attribute | Description |
projectNorthOffsetAngle | number | Set the vector offset for project north |
public setSynchProjection(synchProjection: Boolean) source
Sets whether the NavCube switches between perspective and orthographic projections in synchrony with
the Camera. When false
, the NavCube will always be rendered with perspective projection.
Params:
Name | Type | Attribute | Description |
synchProjection | Boolean | Set |