UNPKG

@polygonjs/polygonjs

Version:

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

67 lines (66 loc) 2.33 kB
"use strict"; import { OrthographicCamera, PerspectiveCamera } from "three"; import { isBooleanTrue } from "../../core/Type"; import { NamedFunction0, ObjectNamedFunction2, ObjectNamedFunction3, ObjectNamedFunction4 } from "./_Base"; import { dummyReadRefVal } from "../../core/reactivity/CoreReactivity"; import { coreGetDefaultCamera } from "../../core/render/renderPixel/CoreGetDefautCamera"; export class setPerspectiveCameraFov extends ObjectNamedFunction3 { static type() { return "setPerspectiveCameraFov"; } func(object3D, fov, lerp, updateProjectionMatrix) { if (!(object3D instanceof PerspectiveCamera)) { return; } const perspectiveCamera = object3D; const newFov = lerp * fov + (1 - lerp) * perspectiveCamera.fov; perspectiveCamera.fov = newFov; if (isBooleanTrue(updateProjectionMatrix)) { perspectiveCamera.updateProjectionMatrix(); } } } export class setPerspectiveCameraNearFar extends ObjectNamedFunction4 { static type() { return "setPerspectiveCameraNearFar"; } func(object3D, near, far, lerp, updateProjectionMatrix) { if (!(object3D instanceof PerspectiveCamera)) { return; } const perspectiveCamera = object3D; const newNear = lerp * near + (1 - lerp) * perspectiveCamera.near; const newFar = lerp * far + (1 - lerp) * perspectiveCamera.far; perspectiveCamera.near = newNear; perspectiveCamera.far = newFar; if (isBooleanTrue(updateProjectionMatrix)) { perspectiveCamera.updateProjectionMatrix(); } } } export class getDefaultCamera extends NamedFunction0 { static type() { return "getDefaultCamera"; } func() { dummyReadRefVal(this.timeController.timeUniform().value); return coreGetDefaultCamera(this.scene); } } export class setCameraViewOffset extends ObjectNamedFunction2 { static type() { return "setCameraViewOffset"; } func(object3D, min, max) { if (!(object3D instanceof PerspectiveCamera || object3D instanceof OrthographicCamera)) { return; } const viewer = this.scene.viewersRegister.lastRenderedViewer(); if (!viewer) { return; } const camera = object3D; const size = viewer.camerasController().size; camera.setViewOffset(size.x, size.y, size.x * min.x, size.y * min.y, size.x * max.x, size.y * max.y); } }