UNPKG

@polygonjs/polygonjs

Version:

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

91 lines (90 loc) 3.21 kB
"use strict"; import { TypedSopNode } from "./_Base"; import { PerspectiveCameraSopOperation } from "../../operations/sop/PerspectiveCamera"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { CameraNodeType } from "../../poly/NodeContext"; import { PERSPECTIVE_CAMERA_DEFAULT, registerPerspectiveCamera } from "../../../core/camera/CorePerspectiveCamera"; import { updateCameraTransformParams } from "./utils/camera/updateCameraTransformParams"; const DEFAULT = PerspectiveCameraSopOperation.DEFAULT_PARAMS; class PerspectiveCameraSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.default = ParamConfig.FOLDER(); /** @param camera fov */ this.fov = ParamConfig.FLOAT(DEFAULT.fov, { range: PERSPECTIVE_CAMERA_DEFAULT.fovRange, rangeLocked: [true, false] }); /** @param camera near */ this.near = ParamConfig.FLOAT(DEFAULT.near, { range: [0, 100], rangeLocked: [true, false] }); /** @param camera far */ this.far = ParamConfig.FLOAT(DEFAULT.far, { range: [0, 100], rangeLocked: [true, false] }); /** @param camera position */ this.position = ParamConfig.VECTOR3(DEFAULT.position); /** @param camera rotation */ this.rotation = ParamConfig.VECTOR3(DEFAULT.rotation); /** @param show helper */ this.showHelper = ParamConfig.BOOLEAN(DEFAULT.showHelper); /** @param matrixAutoUpdate */ this.matrixAutoUpdate = ParamConfig.BOOLEAN(DEFAULT.matrixAutoUpdate); /** @param camera name */ this.name = ParamConfig.STRING("`$OS`"); /** @param set main camera */ this.updateTransformFromCamera = ParamConfig.BUTTON(null, { callback: (node) => { updateCameraTransformParams(node); } }); this.PBR = ParamConfig.FOLDER(); /** @param apertureBlades */ this.apertureBlades = ParamConfig.INTEGER(6, { range: [0, 10], rangeLocked: [true, false] }); /** @param apertureBlades */ this.fStop = ParamConfig.FLOAT(0.5, { range: [0.02, 20], rangeLocked: [true, false] }); /** @param focusDistance */ this.focusDistance = ParamConfig.FLOAT(10, { range: [0, 100], rangeLocked: [true, false] }); /** @param apertureRotation */ this.apertureRotation = ParamConfig.FLOAT(0, { range: [0, 12.5], rangeLocked: [true, false] }); /** @param anamorphicRatio */ this.anamorphicRatio = ParamConfig.FLOAT(1, { range: [0.1, 10], rangeLocked: [true, false] }); } } const ParamsConfig = new PerspectiveCameraSopParamsConfig(); export class PerspectiveCameraSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return CameraNodeType.PERSPECTIVE; } initializeNode() { this.io.inputs.setCount(0); } cook(inputCoreGroups) { this._operation = this._operation || new PerspectiveCameraSopOperation(this._scene, this.states, this); const coreGroup = this._operation.cook(inputCoreGroups, this.pv); this.setCoreGroup(coreGroup); } } PerspectiveCameraSopNode.onRegister = registerPerspectiveCamera;