UNPKG

@polygonjs/polygonjs

Version:

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

57 lines (56 loc) 1.78 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 } from "../../../core/geometry/modules/csg/CsgCoreType"; import { extrusions } from "@jscad/modeling"; const { extrudeRectangular } = extrusions; class CSGExtrudeRectangularSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param size */ this.size = ParamConfig.FLOAT(0.5, { range: [1e-8, 1], rangeLocked: [true, false] }); /** @param height */ this.height = ParamConfig.FLOAT(0.5, { range: [1e-8, 1], rangeLocked: [true, false] }); } } const ParamsConfig = new CSGExtrudeRectangularSopParamsConfig(); export class CSGExtrudeRectangularSopNode extends CSGSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.CSG_EXTRUDE_RECTANGULAR; } initializeNode() { this.io.inputs.setCount(1); } cook(inputCoreGroups) { const inputObjects = inputCoreGroups[0].csgObjects(); if (inputObjects && inputObjects.length != 0) { const options = { size: this.pv.size, height: this.pv.height }; const newGeometries = []; for (const inputObject of inputObjects) { const inputGeometry = inputObject.csgGeometry(); if (csgIsPath2(inputGeometry) || csgIsGeom2(inputGeometry)) { newGeometries.push(extrudeRectangular(options, inputGeometry)); } else { newGeometries.push(inputGeometry); } } this.setCSGGeometries(newGeometries); } else { this.setCSGObjects([]); } } }