UNPKG

@polygonjs/polygonjs

Version:

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

68 lines (67 loc) 2.28 kB
"use strict"; import { BaseSopOperation } from "./_Base"; import { InputCloneMode } from "../../../engine/poly/InputCloneMode"; import { RectAreaLightUniformsLib } from "three/examples/jsm/lights/RectAreaLightUniformsLib"; import { isBooleanTrue } from "../../../core/BooleanValue"; import { Group } from "three"; import { CoreRectAreaLightHelper, DEFAULT_AREA_LIGHT_PARAMS } from "../../../core/lights/AreaLight"; import { CoreSceneObjectsFactory, GeneratorName } from "../../../core/CoreSceneObjectsFactory"; export class AreaLightSopOperation extends BaseSopOperation { static type() { return "areaLight"; } cook(inputCoreGroups, params) { const light = this.createLight(); light.name = params.name; this.updateLightParams(light, params); if (isBooleanTrue(params.showHelper)) { const group = new Group(); group.matrixAutoUpdate = false; group.add(light); const helper = this._createHelper(light); if (helper) { group.add(helper); } group.name = `AreaLightGroup_${light.name}`; return this.createCoreGroupFromObjects([group]); } else { return this.createCoreGroupFromObjects([light]); } } createLight() { var _a; const light = CoreSceneObjectsFactory.generator(GeneratorName.AREA_LIGHT)({ color: 16777215, intensity: 1, width: 1, height: 1 }); light.matrixAutoUpdate = false; const nodeName = (_a = this._node) == null ? void 0 : _a.name(); if (nodeName) { light.name = `AreaLight_${nodeName}`; } if (!RectAreaLightUniformsLib.initialized) { RectAreaLightUniformsLib.init(); RectAreaLightUniformsLib.initialized = true; } return light; } updateLightParams(light, params) { light.color = params.color; light.intensity = params.intensity; light.width = params.width; light.height = params.height; } _createHelper(light) { var _a; const nodeName = (_a = this._node) == null ? void 0 : _a.name(); if (nodeName) { const helper = new CoreRectAreaLightHelper(light, nodeName); helper.update(); return helper; } } } AreaLightSopOperation.DEFAULT_PARAMS = DEFAULT_AREA_LIGHT_PARAMS; AreaLightSopOperation.INPUT_CLONED_STATE = InputCloneMode.NEVER;