UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

57 lines (56 loc) 1.34 kB
import { EventHandler } from "../../core/event-handler.js"; import { Vec3 } from "../../core/math/vec3.js"; import { Quat } from "../../core/math/quat.js"; class XrMesh extends EventHandler { static EVENT_REMOVE = "remove"; static EVENT_CHANGE = "change"; _meshDetection; _xrMesh; _lastChanged = 0; _position = new Vec3(); _rotation = new Quat(); constructor(meshDetection, xrMesh) { super(); this._meshDetection = meshDetection; this._xrMesh = xrMesh; this._lastChanged = this._xrMesh.lastChangedTime; } get xrMesh() { return this._xrMesh; } get label() { return this._xrMesh.semanticLabel || ""; } get vertices() { return this._xrMesh.vertices; } get indices() { return this._xrMesh.indices; } destroy() { if (!this._xrMesh) return; this._xrMesh = null; this.fire("remove"); } update(frame) { const manager = this._meshDetection._manager; const pose = frame.getPose(this._xrMesh.meshSpace, manager._referenceSpace); if (pose) { this._position.copy(pose.transform.position); this._rotation.copy(pose.transform.orientation); } if (this._lastChanged !== this._xrMesh.lastChangedTime) { this._lastChanged = this._xrMesh.lastChangedTime; this.fire("change"); } } getPosition() { return this._position; } getRotation() { return this._rotation; } } export { XrMesh };