@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
41 lines (40 loc) • 1.07 kB
JavaScript
"use strict";
import { Vector2 } from "three";
export class ViewerCamerasController {
constructor(_viewer) {
this._viewer = _viewer;
this._size = new Vector2(100, 100);
this._aspect = 1;
}
camera() {
return this._viewer.camera();
}
get size() {
return this._size;
}
get aspect() {
return this._aspect;
}
computeSizeAndAspect(pixelRatio) {
this._updateSize();
this._viewer.scene().uniformsController.updateResolution(this._size, pixelRatio);
this._aspect = this._getAspect();
}
_updateSize() {
var _a, _b;
this._size.x = ((_a = this._viewer.domElement()) == null ? void 0 : _a.offsetWidth) || 0;
this._size.y = ((_b = this._viewer.domElement()) == null ? void 0 : _b.offsetHeight) || 0;
}
_getAspect() {
return this._size.x / this._size.y;
}
updateCameraAspect() {
this._viewer.updateCameraAspect(this._aspect, this._size);
}
async prepareCurrentCamera() {
await this._updateFromCameraContainer();
}
async _updateFromCameraContainer() {
this.updateCameraAspect();
}
}