import {Metrics} from '@xeokit/xeokit-sdk/src/viewer/scene/metriqs/Metriqs.js'
Metrics
Extends:
Configures its Scene's measurement unit and mapping between the Real-space and World-space 3D Cartesian coordinate systems.
Overview
- Located at Scene#metrics.
- Metrics#units configures the Real-space unit type, which is
"meters"
by default. - Metrics#scale configures the number of Real-space units represented by each unit within the World-space 3D coordinate system. This is
1.0
by default. - Metrics#origin configures the 3D Real-space origin, in current Real-space units, at which this Scene's World-space coordinate origin sits, This is
[0,0,0]
by default.
Usage
Let's load a model using an XKTLoaderPlugin, then configure the Real-space unit type and the coordinate mapping between the Real-space and World-space 3D coordinate systems.
import {Viewer, XKTLoaderPlugin} from "xeokit-sdk.es.js";
const viewer = new Viewer({
canvasId: "myCanvas"
});
viewer.scene.camera.eye = [-2.37, 18.97, -26.12];
viewer.scene.camera.look = [10.97, 5.82, -11.22];
viewer.scene.camera.up = [0.36, 0.83, 0.40];
const xktLoader = new XKTLoaderPlugin(viewer);
const model = xktLoader.load({
src: "./models/xkt/duplex/duplex.xkt"
});
const metrics = viewer.scene.metrics;
metrics.units = "meters";
metrics.scale = 10.0;
metrics.origin = [100.0, 0.0, 200.0];
Member Summary
Public Members | ||
public set |
Sets the Real-space 3D origin, in Real-space units, at which this Scene's World-space coordinate origin |
|
public get |
Gets the 3D Real-space origin, in Real-space units, at which this Scene's World-space coordinate origin |
|
public set |
Sets the number of Real-space units represented by each unit of the Scene's World-space coordinate system. For example, if Metrics#units is |
|
public get |
Gets the number of Real-space units represented by each unit of the Scene's World-space coordinate system. |
|
public set |
Sets the Scene's Real-space unit type. Accepted values are |
|
public get |
Gets the Scene's Real-space unit type. |
|
public get |
unitsInfo: * Gets info about the supported Real-space unit types. |
Method Summary
Public Methods | ||
public |
realToWorldPos(realPos: Number[], worldPos: Number[]): Number[] Converts a 3D position from Real-space to World-space. |
|
public |
worldToRealPos(worldPos: Number[], realPos: Number[]): Number[] Converts a 3D position from World-space to Real-space. |
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 Members
public set origin: Number[] source
Sets the Real-space 3D origin, in Real-space units, at which this Scene's World-space coordinate origin [0,0,0]
sits.
Emit:
* |
"origin" event on change, with the value of this property. |
public get origin: Number[] source
Gets the 3D Real-space origin, in Real-space units, at which this Scene's World-space coordinate origin [0,0,0]
sits.
public set scale: Number source
Sets the number of Real-space units represented by each unit of the Scene's World-space coordinate system.
For example, if Metrics#units is "meters"
, and there are ten meters per World-space coordinate system unit, then scale
would have a value of 10.0
.
Emit:
* |
|
public get scale: Number source
Gets the number of Real-space units represented by each unit of the Scene's World-space coordinate system.
public set units: String source
Sets the Scene's Real-space unit type.
Accepted values are "meters"
, "centimeters"
, "millimeters"
, "metres"
, "centimetres"
, "millimetres"
, "yards"
, "feet"
and "inches"
.
Emit:
* |
|
public get unitsInfo: * source
Gets info about the supported Real-space unit types.
This will be:
{
{
meters: {
abbrev: "m"
},
metres: {
abbrev: "m"
},
centimeters: {
abbrev: "cm"
},
centimetres: {
abbrev: "cm"
},
millimeters: {
abbrev: "mm"
},
millimetres: {
abbrev: "mm"
},
yards: {
abbrev: "yd"
},
feet: {
abbrev: "ft"
},
inches: {
abbrev: "in"
}
}
}
Public Methods
public realToWorldPos(realPos: Number[], worldPos: Number[]): Number[] source
Converts a 3D position from Real-space to World-space.
This is equivalent to worldPos = (worldPos - #origin) / #scale
.