UNPKG

polygonjs-engine

Version:

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

47 lines (46 loc) 1.47 kB
import {TypedSopNode} from "./_Base"; import {InputCloneMode as InputCloneMode2} from "../../poly/InputCloneMode"; import {InstancedBufferGeometry as InstancedBufferGeometry2} from "three/src/core/InstancedBufferGeometry"; import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig"; class InstancesCountSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.useMax = ParamConfig.BOOLEAN(0); this.max = ParamConfig.INTEGER(1, { range: [0, 100], rangeLocked: [true, false], visibleIf: {useMax: 1} }); } } const ParamsConfig2 = new InstancesCountSopParamsConfig(); export class InstancesCountSopNode extends TypedSopNode { constructor() { super(...arguments); this.params_config = ParamsConfig2; } static type() { return "instancesCount"; } initializeNode() { this.io.inputs.setCount(1); this.io.inputs.initInputsClonedState(InputCloneMode2.FROM_NODE); } async cook(input_contents) { const core_group = input_contents[0]; const objects = core_group.objectsWithGeo(); for (let object of objects) { const geometry = object.geometry; if (geometry) { if (geometry instanceof InstancedBufferGeometry2) { if (this.pv.useMax) { geometry.instanceCount = this.pv.max; } else { geometry.instanceCount = Infinity; } } } } this.setCoreGroup(core_group); } }