UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

66 lines (65 loc) 2.12 kB
"use strict"; import { CADSopNode } from "./_BaseCAD"; import { NodeParamsConfig } from "../utils/params/ParamsConfig"; import { CadGC } from "../../../core/geometry/modules/cad/CadCommon"; import { CoreCadType } from "../../../core/geometry/modules/cad/CadCoreType"; import { cadEdgeCreate } from "../../../core/geometry/modules/cad/toObject3D/CadEdge"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { CadLoaderSync } from "../../../core/geometry/modules/cad/CadLoaderSync"; class CADCurveFromPointsSopParamsConfig extends NodeParamsConfig { } const ParamsConfig = new CADCurveFromPointsSopParamsConfig(); export class CADCurveFromPointsSopNode extends CADSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.CAD_CURVE_FROM_POINTS; } initializeNode() { this.io.inputs.setCount(1); } cook(inputCoreGroups) { const objects = inputCoreGroups[0].cadObjects(); const vertices = []; if (objects) { for (const object of objects) { if (CoreCadType.isVertex(object)) { vertices.push(object.cadGeometry()); } } } if (vertices.length >= 3) { const oc = CadLoaderSync.oc(); CadGC.withGC((r) => { const positions = r(new oc.TColgp_Array1OfPnt_2(0, vertices.length - 1)); const points = []; let index = 0; for (const vertex of vertices) { const point = oc.BRep_Tool.Pnt(vertex); points.push(point); positions.SetValue(index, point); index++; } const _createBezier = () => { const curve = new oc.Geom_BezierCurve_1(positions); const edge2 = cadEdgeCreate(oc, curve); return edge2; }; const createFunction = _createBezier; const edge = createFunction(); for (const point of points) { point.delete(); } if (edge) { this.setCADShape(edge); } else { this.setCADObjects([]); } }); } else { this.setCADObjects([]); } } }