UNPKG

@polygonjs/polygonjs

Version:

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

66 lines (65 loc) 2.03 kB
"use strict"; import { CSGSopNode } from "./_BaseCSG"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { step } from "../../../core/geometry/modules/csg/CsgConstant"; import { csgIsGeom2 } from "../../../core/geometry/modules/csg/CsgCoreType"; import { extrusions } from "@jscad/modeling"; const { extrudeRotate } = extrusions; class CSGExtrudeRotateSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param angle */ this.angle = ParamConfig.FLOAT(0, { range: [-2 * Math.PI, 2 * Math.PI], rangeLocked: [false, false], step }); /** @param start angle */ this.startAngle = ParamConfig.FLOAT(0, { range: [-2 * Math.PI, 2 * Math.PI], rangeLocked: [false, false], step }); /** @param segments */ this.segments = ParamConfig.INTEGER(4, { range: [1, 64], rangeLocked: [true, false] }); } } const ParamsConfig = new CSGExtrudeRotateSopParamsConfig(); export class CSGExtrudeRotateSopNode extends CSGSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.CSG_EXTRUDE_ROTATE; } initializeNode() { this.io.inputs.setCount(1); } cook(inputCoreGroups) { const inputObjects = inputCoreGroups[0].csgObjects(); if (inputObjects && inputObjects.length != 0) { const options = { angle: this.pv.angle, startAngle: this.pv.startAngle, segments: this.pv.segments * 4 }; const newGeometries = []; for (const inputObject of inputObjects) { const inputGeometry = inputObject.csgGeometry(); if (csgIsGeom2(inputGeometry)) { newGeometries.push(extrudeRotate(options, inputGeometry)); } else { newGeometries.push(inputGeometry); } } this.setCSGGeometries(newGeometries); } else { this.setCSGObjects([]); } } }