UNPKG

@polygonjs/polygonjs

Version:

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

73 lines (72 loc) 2.1 kB
"use strict"; import { CSGSopNode } from "./_BaseCSG"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { csgIsPath2, csgIsGeom2, csgIsGeom3 } from "../../../core/geometry/modules/csg/CsgCoreType"; import { geom2ApplyTransforms } from "../../../core/geometry/modules/csg/math/CsgMat4"; import { hulls } from "@jscad/modeling"; const { hull, hullChain } = hulls; class CSGHullSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param chain */ this.chain = ParamConfig.BOOLEAN(0); } } const ParamsConfig = new CSGHullSopParamsConfig(); export class CSGHullSopNode extends CSGSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.CSG_HULL; } initializeNode() { this.io.inputs.setCount(1); } cook(inputCoreGroups) { const geom3 = []; const geom2 = []; const path2 = []; const objects = inputCoreGroups[0].csgObjects(); if (objects) { for (const object of objects) { const geometry = object.csgGeometry(); if (csgIsGeom3(geometry)) { geom3.push(geometry); } if (csgIsGeom2(geometry)) { geom2ApplyTransforms(geometry); geom2.push(geometry); } if (csgIsPath2(geometry)) { path2.push(geometry); } } if (geom3.length == 1) { geom3.push(geom3[0]); } if (geom2.length == 1) { geom2.push(geom2[0]); } if (path2.length == 1) { path2.push(path2[0]); } const method = this.pv.chain ? hullChain : hull; const newGeometries = []; if (geom3.length >= 2) { newGeometries.push(method(geom3)); } if (geom2.length >= 2) { newGeometries.push(method(geom2)); } if (path2.length >= 2) { newGeometries.push(method(path2)); } this.setCSGGeometries(newGeometries); } else { this.setCSGObjects([]); } } }