@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
51 lines (50 loc) • 1.81 kB
JavaScript
;
import { CADSopNode } from "./_BaseCAD";
import { NodeParamsConfig } from "../utils/params/ParamsConfig";
import { cadGeometryTypeFromShape, cadDowncast } from "../../../core/geometry/modules/cad/CadCommon";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { CadLoaderSync } from "../../../core/geometry/modules/cad/CadLoaderSync";
import { CadObject } from "../../../core/geometry/modules/cad/CadObject";
import { CoreCadType } from "../../../core/geometry/modules/cad/CadCoreType";
class CADUnpackSopParamsConfig extends NodeParamsConfig {
}
const ParamsConfig = new CADUnpackSopParamsConfig();
export class CADUnpackSopNode extends CADSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.CAD_UNPACK;
}
initializeNode() {
this.io.inputs.setCount(1);
}
cook(inputCoreGroups) {
const inputCoreGroup = inputCoreGroups[0];
const newObjects = [];
const inputObjects = inputCoreGroup.cadObjects();
if (inputObjects) {
const oc = CadLoaderSync.oc();
for (const inputObject of inputObjects) {
const shape = inputObject.cadGeometry();
if (CoreCadType.isGeometryShape(shape)) {
const iterator = new oc.TopoDS_Iterator_2(shape, true, true);
while (iterator.More()) {
const newShape = cadDowncast(oc, iterator.Value());
const type = cadGeometryTypeFromShape(oc, newShape);
if (type) {
const newObject = new CadObject(newShape, type);
newObjects.push(newObject);
}
iterator.Next();
}
iterator.delete();
} else {
newObjects.push(inputObject);
}
}
}
this.setCADObjects(newObjects);
}
}