polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
75 lines (74 loc) • 2.47 kB
JavaScript
import {TypedSopNode} from "./_Base";
import {CoreObject} from "../../../core/geometry/Object";
import {CoreGeometry} from "../../../core/geometry/Geometry";
import {AttribClassMenuEntries, AttribClass} from "../../../core/geometry/Constant";
import {InputCloneMode as InputCloneMode2} from "../../poly/InputCloneMode";
import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig";
class AttribDeleteSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.class = ParamConfig.INTEGER(AttribClass.VERTEX, {
menu: {
entries: AttribClassMenuEntries
}
});
this.name = ParamConfig.STRING("");
}
}
const ParamsConfig2 = new AttribDeleteSopParamsConfig();
export class AttribDeleteSopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.params_config = ParamsConfig2;
}
static type() {
return "attribDelete";
}
static displayedInputNames() {
return ["geometry to delete attributes from"];
}
initializeNode() {
this.io.inputs.setCount(1);
this.io.inputs.initInputsClonedState(InputCloneMode2.FROM_NODE);
this.scene().dispatchController.onAddListener(() => {
this.params.onParamsCreated("params_label", () => {
this.params.label.init([this.p.name]);
});
});
}
cook(input_contents) {
const core_group = input_contents[0];
const attrib_names = core_group.attribNamesMatchingMask(this.pv.name);
for (let attrib_name of attrib_names) {
switch (this.pv.class) {
case AttribClass.VERTEX:
this.delete_vertex_attribute(core_group, attrib_name);
case AttribClass.OBJECT:
this.delete_object_attribute(core_group, attrib_name);
}
}
this.setCoreGroup(core_group);
}
delete_vertex_attribute(core_group, attrib_name) {
for (let object of core_group.objects()) {
object.traverse((object3d) => {
const child = object3d;
if (child.geometry) {
const core_geometry = new CoreGeometry(child.geometry);
core_geometry.deleteAttribute(attrib_name);
}
});
}
}
delete_object_attribute(core_group, attrib_name) {
for (let object of core_group.objects()) {
let index = 0;
object.traverse((object3d) => {
const child = object3d;
const core_object = new CoreObject(child, index);
core_object.deleteAttribute(attrib_name);
index++;
});
}
}
}