polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
30 lines (29 loc) • 820 B
JavaScript
export class CamerasController {
constructor(scene) {
this.scene = scene;
this._masterCameraNodePath = null;
}
setMasterCameraNodePath(camera_node_path) {
this._masterCameraNodePath = camera_node_path;
}
masterCameraNodePath() {
return this._masterCameraNodePath;
}
masterCameraNode() {
if (this.masterCameraNodePath) {
const path = this.masterCameraNodePath();
if (!path) {
return this._find_any_camera();
}
const camera_node = this.scene.node(path);
return camera_node;
} else {
console.warn("master camera node not found");
return this._find_any_camera();
}
}
_find_any_camera() {
const root = this.scene.root();
return root.nodesByType("perspectiveCamera")[0] || root.nodesByType("orthographicCamera")[0];
}
}