@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
46 lines (45 loc) • 1.45 kB
JavaScript
;
import { CADSopNode } from "./_BaseCAD";
import { NodeParamsConfig } from "../utils/params/ParamsConfig";
import { CoreCadType } from "../../../core/geometry/modules/cad/CadCoreType";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { CadLoaderSync } from "../../../core/geometry/modules/cad/CadLoaderSync";
class CADCurveFromPoints2DSopParamsConfig extends NodeParamsConfig {
}
const ParamsConfig = new CADCurveFromPoints2DSopParamsConfig();
export class CADCurveFromPoints2DSopNode extends CADSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.CAD_CURVE_FROM_POINTS_2D;
}
initializeNode() {
this.io.inputs.setCount(1);
}
cook(inputCoreGroups) {
const cadObjects = inputCoreGroups[0].cadObjects();
const points = [];
if (cadObjects) {
for (const object of cadObjects) {
if (CoreCadType.isPoint2d(object)) {
points.push(object.cadGeometry());
}
}
}
if (points.length >= 3) {
const oc = CadLoaderSync.oc();
const positions = new oc.TColgp_Array1OfPnt2d_2(0, points.length - 1);
let index = 0;
for (const point of points) {
positions.SetValue(index, point);
index++;
}
const curve = new oc.Geom2d_BezierCurve_1(positions);
this.setCADGeom2dCurve(curve);
} else {
this.setCADObjects([]);
}
}
}