UNPKG

@polygonjs/polygonjs

Version:

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

105 lines (104 loc) 3.66 kB
"use strict"; import { CADSopNode } from "./_BaseCAD"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { step } from "../../../core/geometry/modules/cad/CadConstant"; import { CoreCadType } from "../../../core/geometry/modules/cad/CadCoreType"; import { traverseEdges } from "../../../core/geometry/modules/cad/CadTraverse"; import { cadGeometryTypeFromShape } from "../../../core/geometry/modules/cad/CadCommon"; import { TypeAssert } from "../../poly/Assert"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { CadObject } from "../../../core/geometry/modules/cad/CadObject"; import { CadLoaderSync } from "../../../core/geometry/modules/cad/CadLoaderSync"; import { EntityGroupType } from "../../../core/geometry/EntityGroupCollection"; import { CadEntityGroupCollection } from "../../../core/geometry/modules/cad/CadEntityGroupCollection"; var FilletMode = /* @__PURE__ */ ((FilletMode2) => { FilletMode2["ROUND"] = "round"; FilletMode2["STRAIGHT"] = "straight"; return FilletMode2; })(FilletMode || {}); const FILLET_MODES = ["straight" /* STRAIGHT */, "round" /* ROUND */]; class CADFilletSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param edges group */ this.group = ParamConfig.STRING(""); /** @param mode */ this.mode = ParamConfig.INTEGER(FILLET_MODES.indexOf("round" /* ROUND */), { menu: { entries: FILLET_MODES.map((name, value) => ({ name, value })) } }); /** @param radius */ this.radius = ParamConfig.FLOAT(0.1, { range: [0, 1], rangeLocked: [true, false], step }); } } const ParamsConfig = new CADFilletSopParamsConfig(); export class CADFilletSopNode extends CADSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.CAD_FILLET; } initializeNode() { this.io.inputs.setCount(1); } cook(inputCoreGroups) { const oc = CadLoaderSync.oc(); const inputCoreGroup = inputCoreGroups[0]; const mode = FILLET_MODES[this.pv.mode]; const newObjects = []; const inputObjects = inputCoreGroup.cadObjects(); if (inputObjects) { const groupName = this.pv.group; for (const object of inputObjects) { if (CoreCadType.isShape(object)) { const shape = object.cadGeometry(); const api = _getApi(oc, mode, shape); const radius = this.pv.radius; let edgesCount = 0; CadEntityGroupCollection.traverseEntitiesInGroup({ groupName, groupType: EntityGroupType.EDGE, object, shape, traverseFunction: traverseEdges, onEntityTraversed: (edge, i) => { api.Add_2(radius, edge); edgesCount++; } }); if (edgesCount > 0) { const newShape = api.Shape(); api.delete(); const type = cadGeometryTypeFromShape(oc, newShape); if (type) { newObjects.push(new CadObject(newShape, type)); } else { console.log("no type", newShape); } } else { newObjects.push(object); } } } } this.setCADObjects(newObjects); } } function _getApi(oc, mode, shape) { switch (mode) { case "round" /* ROUND */: { return new oc.BRepFilletAPI_MakeFillet(shape, oc.ChFi3d_FilletShape.ChFi3d_Rational); } case "straight" /* STRAIGHT */: { return new oc.BRepFilletAPI_MakeChamfer(shape); } } TypeAssert.unreachable(mode); }