UNPKG

@polygonjs/polygonjs

Version:

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

54 lines (53 loc) 1.87 kB
"use strict"; import { TypedSopNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { InputCloneMode } from "../../poly/InputCloneMode"; import { VertexNormalsHelper } from "three/examples/jsm/helpers/VertexNormalsHelper"; import { isBooleanTrue } from "../../../core/Type"; import { CoreMask } from "../../../core/geometry/Mask"; import { object3DHasGeometry } from "../../../core/geometry/GeometryUtils"; import { SopType } from "../../poly/registers/nodes/types/Sop"; class NormalsHelperSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param group to assign the material to */ this.group = ParamConfig.STRING("", { objectMask: true }); /** @param keep input */ this.keepInput = ParamConfig.BOOLEAN(1); /** @param size of the box */ this.size = ParamConfig.FLOAT(1, { range: [0, 1], rangeLocked: [false, false] }); } } const ParamsConfig = new NormalsHelperSopParamsConfig(); export class NormalsHelperSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.NORMALS_HELPER; } initializeNode() { this.io.outputs.setHasNoOutput(); this.io.inputs.setCount(1); this.io.inputs.initInputsClonedState(InputCloneMode.NEVER); } cook(inputCoreGroups) { const inputCoreGroup = inputCoreGroups[0]; const selectedObjects = CoreMask.filterThreejsObjects(inputCoreGroup, this.pv).filter(object3DHasGeometry); const newObjects = []; for (const object of selectedObjects) { const helper = new VertexNormalsHelper(object, this.pv.size); if (isBooleanTrue(this.pv.keepInput)) { newObjects.push(object); } newObjects.push(helper); } this.setObjects(newObjects); } }