Skip to main content

convertCoordinate

Summary

Converts coordinates between different coordinate systems, including:

  • The global coordinate system of a Spatial Scene container: based on the 2D layout system, using a left-handed coordinate system, with the origin at the top-left corner of the backplate, Y pointing downward, Z pointing toward the user, and lengths expressed by default in the GUI-oriented point unit (px)
  • The local coordinate system of a spatialized HTML element: based on the 2D layout system, using a left-handed coordinate system, with the origin at the top-left corner of the 2D plane, Y pointing downward, Z pointing toward the user, and lengths expressed by default in the GUI-oriented point unit (px)
  • The local coordinate system of a 3D entity: based on the 3D engine system, using a right-handed coordinate system, with the origin at the center point of the local 3D space corresponding to the 3D content container, Y pointing upward, Z pointing toward the user, and lengths expressed by default in the physical world unit (m) oriented toward real-world objects

Signature

import { convertCoordinate } from "@webspatial/react-sdk";

const e2e = await convertCoordinate(position, {
from: elementOrEntity,
to: elementOrEntity,
});
const e2w = await convertCoordinate(position, {
from: elementOrEntity,
to: window,
});
const w2e = await convertCoordinate(position, {
from: window,
to: elementOrEntity,
});

Parameters

position

type CoordinateLike = { x: number; y: number; z: number };

The position point to convert. This position must use the coordinate values and default unit of the coordinate system specified by options.from.

options

  • options.from: source coordinate system
  • options.to: target coordinate system

Return Shape

Promise<CoordinateLike>;

Returns a Promise that resolves to the converted coordinate point.