@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
73 lines • 2.76 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { AxesHelper, Object3D } from "three";
import { serializable } from "../../engine/engine_serialization_decorator.js";
import { getParam } from "../../engine/engine_utils.js";
import { NeedleXRSession } from "../../engine/engine_xr.js";
import { Behaviour } from "../Component.js";
import { BoxGizmo } from "../Gizmos.js";
const debug = getParam("debugwebxr");
/**
* A user in XR (VR or AR) is parented to an XR rig during the session.
* When moving through the scene the rig is moved instead of the user.
* @category XR
* @group Components
*/
export class XRRig extends Behaviour {
priority = 0;
get isActive() { return this.activeAndEnabled && this.gameObject.visible; }
/**
* Sets this rig to be the active XR rig (needs to be called during an active XR session)
* Note that this might modify the priority of this rig to be the highest.
*/
setAsActiveXRRig() {
NeedleXRSession.active?.setRigActive(this);
}
/**
* Sets the priority of the rig.
*/
setPriority(value) {
this.priority = value;
}
/** @internal */
awake() {
if (debug) {
const gizmoObj = new Object3D();
gizmoObj.position.y += .5;
this.gameObject.add(gizmoObj);
const box = gizmoObj.addNewComponent(BoxGizmo);
if (box)
box.isGizmo = false;
const axes = new AxesHelper(.5);
this.gameObject.add(axes);
}
}
isXRRig() {
return true;
}
supportsXR(_mode) {
return true;
}
_startScale;
/** @internal */
onEnterXR(args) {
this._startScale = this.gameObject.scale.clone();
args.xr.addRig(this);
if (debug)
console.log("WebXR: add Rig", this.name, this.priority);
}
/** @internal */
onLeaveXR(args) {
args.xr.removeRig(this);
if (this._startScale && this.gameObject)
this.gameObject.scale.copy(this._startScale);
}
}
__decorate([
serializable()
], XRRig.prototype, "priority", void 0);
//# sourceMappingURL=WebXRRig.js.map