polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
41 lines (40 loc) • 1.13 kB
JavaScript
import {Vector2 as Vector22} from "three/src/math/Vector2";
export class ViewerCamerasController {
constructor(_viewer) {
this._viewer = _viewer;
this._size = new Vector22(100, 100);
this._aspect = 1;
}
cameraNode() {
return this._viewer.cameraNode();
}
get size() {
return this._size;
}
get aspect() {
return this._aspect;
}
computeSizeAndAspect() {
this._update_size();
this.cameraNode().scene().uniforms_controller.update_resolution_dependent_uniform_owners(this._size);
this._aspect = this._get_aspect();
}
_update_size() {
this._size.x = this._viewer.container().offsetWidth;
this._size.y = this._viewer.container().offsetHeight;
}
_get_aspect() {
return this._size.x / this._size.y;
}
updateCameraAspect() {
this.cameraNode().setup_for_aspect_ratio(this._aspect);
}
async prepareCurrentCamera() {
await this.cameraNode().requestContainer();
await this._update_from_camera_container();
}
async _update_from_camera_container() {
this.updateCameraAspect();
await this._viewer.controlsController?.create_controls();
}
}