playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
75 lines (74 loc) • 1.49 kB
JavaScript
import { EventHandler } from "../../core/event-handler.js";
import { Vec3 } from "../../core/math/vec3.js";
import { Quat } from "../../core/math/quat.js";
class XrTrackedImage extends EventHandler {
static EVENT_TRACKED = "tracked";
static EVENT_UNTRACKED = "untracked";
_image;
_width;
_bitmap = null;
_measuredWidth = 0;
_trackable = false;
_tracking = false;
_emulated = false;
_pose = null;
_position = new Vec3();
_rotation = new Quat();
constructor(image, width) {
super();
this._image = image;
this._width = width;
}
get image() {
return this._image;
}
set width(value) {
this._width = value;
}
get width() {
return this._width;
}
get trackable() {
return this._trackable;
}
get tracking() {
return this._tracking;
}
get emulated() {
return this._emulated;
}
prepare() {
if (this._bitmap) {
return {
image: this._bitmap,
widthInMeters: this._width
};
}
return createImageBitmap(this._image).then((bitmap) => {
this._bitmap = bitmap;
return {
image: this._bitmap,
widthInMeters: this._width
};
});
}
destroy() {
this._image = null;
this._pose = null;
if (this._bitmap) {
this._bitmap.close();
this._bitmap = null;
}
}
getPosition() {
if (this._pose) this._position.copy(this._pose.transform.position);
return this._position;
}
getRotation() {
if (this._pose) this._rotation.copy(this._pose.transform.orientation);
return this._rotation;
}
}
export {
XrTrackedImage
};