@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
55 lines (54 loc) • 1.67 kB
JavaScript
;
import { TypedSopNode } from "./_Base";
import { InputCloneMode } from "../../poly/InputCloneMode";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { isBooleanTrue } from "../../../core/BooleanValue";
class DrawRangeSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param start of the draw range */
this.start = ParamConfig.INTEGER(0, {
range: [0, 100],
rangeLocked: [true, false]
});
/** @param defines if count is used */
this.useCount = ParamConfig.BOOLEAN(0);
/** @param number of items in the draw range */
this.count = ParamConfig.INTEGER(0, {
range: [0, 100],
rangeLocked: [true, false],
visibleIf: { useCount: 1 }
});
}
}
const ParamsConfig = new DrawRangeSopParamsConfig();
export class DrawRangeSopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "drawRange";
}
initializeNode() {
this.io.inputs.setCount(0, 1);
this.io.inputs.initInputsClonedState(InputCloneMode.FROM_NODE);
}
cook(input_contents) {
const core_group = input_contents[0];
const objects = core_group.threejsObjects();
for (const object of objects) {
const geometry = object.geometry;
if (geometry) {
const draw_range = geometry.drawRange;
draw_range.start = this.pv.start;
if (isBooleanTrue(this.pv.useCount)) {
draw_range.count = this.pv.count;
} else {
draw_range.count = Infinity;
}
}
}
this.setCoreGroup(core_group);
}
}