UNPKG

@polygonjs/polygonjs

Version:

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

63 lines (62 loc) 2.21 kB
"use strict"; import { TypedSopNode } from "./_Base"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { InputCloneMode } from "../../poly/InputCloneMode"; import { VertexTangentsHelper } from "three/examples/jsm/helpers/VertexTangentsHelper"; 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 TangentsHelperSopParamsConfig 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 TangentsHelperSopParamsConfig(); export class TangentsHelperSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.TANGENTS_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 geometry = object.geometry; if (geometry) { const tangentAttribute = geometry.getAttribute("tangent"); if (!tangentAttribute) { this.states.error.set(`no tangent attribute found on geometry '${object.name}'`); return; } else { const helper = new VertexTangentsHelper(object, this.pv.size); if (isBooleanTrue(this.pv.keepInput)) { newObjects.push(object); } newObjects.push(helper); } } } this.setObjects(newObjects); } }