UNPKG

polygonjs-engine

Version:

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

56 lines (55 loc) 2.09 kB
import {HemisphereLight as HemisphereLight2} from "three/src/lights/HemisphereLight"; import {HemisphereLightHelper as HemisphereLightHelper2} from "./utils/helpers/HemisphereLightHelper"; import {TypedLightObjNode} from "./_BaseLight"; import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig"; import {HelperController as HelperController2} from "./utils/HelperController"; import {ColorConversion} from "../../../core/Color"; import {Color as Color3} from "three/src/math/Color"; const DEFAULT = { skyColor: new Color3(1, 1, 1), groundColor: new Color3(0, 0, 0) }; class HemisphereLightObjParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.skyColor = ParamConfig.COLOR(DEFAULT.skyColor, { conversion: ColorConversion.SRGB_TO_LINEAR }); this.groundColor = ParamConfig.COLOR(DEFAULT.groundColor, { conversion: ColorConversion.SRGB_TO_LINEAR }); this.intensity = ParamConfig.FLOAT(1); this.position = ParamConfig.VECTOR3([0, 1, 0]); this.showHelper = ParamConfig.BOOLEAN(0); this.helperSize = ParamConfig.FLOAT(1, {visibleIf: {showHelper: 1}}); } } const ParamsConfig2 = new HemisphereLightObjParamsConfig(); export class HemisphereLightObjNode extends TypedLightObjNode { constructor() { super(...arguments); this.params_config = ParamsConfig2; this._helper_controller = new HelperController2(this, HemisphereLightHelper2, "HemisphereLightHelper"); } static type() { return "hemisphereLight"; } create_light() { const light = new HemisphereLight2(); light.matrixAutoUpdate = false; light.color.copy(DEFAULT.skyColor); light.groundColor.copy(DEFAULT.groundColor); return light; } initializeNode() { this.io.inputs.setCount(0, 1); this._helper_controller.initializeNode(); } update_light_params() { this.light.color = this.pv.skyColor; this.light.groundColor = this.pv.groundColor; this.light.position.copy(this.pv.position); this.light.intensity = this.pv.intensity; this._helper_controller.update(); } }