@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
51 lines (50 loc) • 1.58 kB
JavaScript
;
import { TypedSopNode } from "./_Base";
import { InputCloneMode } from "../../poly/InputCloneMode";
import { InstancedBufferGeometry } from "three";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { isBooleanTrue } from "../../../core/BooleanValue";
class InstancesCountSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param sets if max is used */
this.useMax = ParamConfig.BOOLEAN(0);
/** @param max number of instances to display */
this.max = ParamConfig.INTEGER(1, {
range: [0, 100],
rangeLocked: [true, false],
visibleIf: { useMax: 1 }
});
}
}
const ParamsConfig = new InstancesCountSopParamsConfig();
export class InstancesCountSopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "instancesCount";
}
initializeNode() {
this.io.inputs.setCount(1);
this.io.inputs.initInputsClonedState(InputCloneMode.FROM_NODE);
}
cook(input_contents) {
const core_group = input_contents[0];
const objects = core_group.threejsObjectsWithGeo();
for (const object of objects) {
const geometry = object.geometry;
if (geometry) {
if (geometry instanceof InstancedBufferGeometry) {
if (isBooleanTrue(this.pv.useMax)) {
geometry.instanceCount = this.pv.max;
} else {
geometry.instanceCount = Infinity;
}
}
}
}
this.setCoreGroup(core_group);
}
}