Reference Source
public class | source

Metrics

Extends:

Component → Metrics

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 [0,0,0] sits.

public get

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

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.

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 "meters", "centimeters", "millimeters", "metres", "centimetres", "millimetres", "yards", "feet" and "inches".

public get

Gets the Scene's Real-space unit type.

public get

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

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

scheduleTask(task: *)

Schedule a task to perform on the next browser interval

public

warn(message: String)

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:

*

"scale" event on change, with the value of this property.

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:

*

"units" event on change, with the value of this property.

public get units: String source

Gets the Scene's Real-space unit type.

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.

Params:

NameTypeAttributeDescription
realPos Number[]

Real-space 3D position.

worldPos Number[]
  • optional

Destination for World-space 3D position.

Return:

Number[]

World-space 3D position.

public worldToRealPos(worldPos: Number[], realPos: Number[]): Number[] source

Converts a 3D position from World-space to Real-space.

This is equivalent to realPos = #origin + (worldPos * #scale).

Params:

NameTypeAttributeDescription
worldPos Number[]

World-space 3D position, in World coordinate system units.

realPos Number[]
  • optional

Destination for Real-space 3D position.

Return:

Number[]

Real-space 3D position, in units indicated by Metrics#units.