UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

66 lines (65 loc) 1.66 kB
"use strict"; var EVENT = /* @__PURE__ */ ((EVENT2) => { EVENT2["CHANGE"] = "change"; EVENT2["MOVEEND"] = "moveend"; return EVENT2; })(EVENT || {}); export class CameraController { constructor(_callback) { this._callback = _callback; this._updateAlways = true; this._listenerAdded = false; this._listener = this._executeCallback.bind(this); } removeTarget() { this.setTarget(void 0); } setTarget(target) { if (!target) { this._removeCameraEvent(); } const old_target = this._target; this._target = target; if (this._target != null) { this._executeCallback(); } if ((this._target != null ? this._target.uuid : void 0) !== (old_target != null ? old_target.uuid : void 0)) { this._addCameraEvent(); } } setUpdateAlways(newUpdateAlways) { this._removeCameraEvent(); this._updateAlways = newUpdateAlways; this._addCameraEvent(); } _currentEventName() { if (this._updateAlways) { return "change" /* CHANGE */; } else { return "moveend" /* MOVEEND */; } } _addCameraEvent() { if (this._listenerAdded) { return; } if (this._target != null) { this._target.addEventListener(this._currentEventName(), this._listener); this._listenerAdded = true; } } _removeCameraEvent() { if (this._listenerAdded !== true) { return; } if (this._target != null) { this._target.removeEventListener(this._currentEventName(), this._listener); this._listenerAdded = false; } } _executeCallback() { if (this._target != null) { this._callback(this._target); } } }