@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
62 lines (61 loc) • 2.13 kB
JavaScript
;
import { NamedFunction2 } from "./_Base";
import { DeviceOrientationControls } from "../../core/camera/controls/DeviceOrientationControls";
import { dummyReadRefVal } from "../../core/reactivity/CoreReactivity";
class DeviceOrientationControlsHandler {
// private previousMagicWindowYaw: number | undefined;
constructor(scene) {
this.scene = scene;
// private _dummyObject = new Object3D();
this._lastUpdatedFrame = -1;
}
update() {
const currentFrame = this.scene.frame();
if (currentFrame == this._lastUpdatedFrame) {
return;
}
this._controls = this._controls || new DeviceOrientationControls();
if (this._controls.enabled) {
this._controls.update();
}
this._lastUpdatedFrame = currentFrame;
}
quaternion(target) {
this.update();
if (!this._controls) {
console.warn("no controls");
return;
}
this._controls.quaternion(target);
}
setSmoothAmount(smoothAmount) {
var _a;
(_a = this._controls) == null ? void 0 : _a.setSmoothAmount(smoothAmount);
}
// from aframe look-controls .updateMagicWindowOrientation()
// protected _compensate() {
// magicWindowAbsoluteEuler.setFromQuaternion(this._dummyObject.quaternion, ROTATION_ORDER);
// if (!this.previousMagicWindowYaw && magicWindowAbsoluteEuler.y !== 0) {
// this.previousMagicWindowYaw = magicWindowAbsoluteEuler.y;
// }
// if (this.previousMagicWindowYaw) {
// magicWindowDeltaEuler.x = magicWindowAbsoluteEuler.x;
// magicWindowDeltaEuler.y += magicWindowAbsoluteEuler.y - this.previousMagicWindowYaw;
// magicWindowDeltaEuler.z = magicWindowAbsoluteEuler.z;
// this.previousMagicWindowYaw = magicWindowAbsoluteEuler.y;
// }
// }
}
let _handler;
export class deviceOrientation extends NamedFunction2 {
static type() {
return "deviceOrientation";
}
func(target, smoothAmount) {
dummyReadRefVal(this.timeController.timeUniform().value);
_handler = _handler || new DeviceOrientationControlsHandler(this.scene);
_handler.setSmoothAmount(smoothAmount);
_handler.quaternion(target);
return target;
}
}