UNPKG

@polygonjs/polygonjs

Version:

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

64 lines (63 loc) 1.94 kB
"use strict"; import { CSGSopNode } from "./_BaseCSG"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { primitives, maths } from "@jscad/modeling"; import { vector2ToCsgVec2 } from "../../../core/geometry/modules/csg/CsgVecToVector"; const { star } = primitives; class CSGStarSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param center */ this.center = ParamConfig.VECTOR2([0, 0]); /** @param vertices */ this.vertices = ParamConfig.INTEGER(5, { range: [2, 10], rangeLocked: [true, false] }); /** @param outer radius */ this.innerRadius = ParamConfig.FLOAT(1, { range: [2 * maths.constants.EPS, 10], rangeLocked: [true, false] }); /** @param outer radius */ this.outerRadius = ParamConfig.FLOAT(2, { range: [2 * maths.constants.EPS, 10], rangeLocked: [true, false] }); /** @param start angle */ this.startAngle = ParamConfig.FLOAT(0, { range: [0, 2 * Math.PI], rangeLocked: [true, true] }); } } const ParamsConfig = new CSGStarSopParamsConfig(); export class CSGStarSopNode extends CSGSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; this._center = [0, 0]; } static type() { return SopType.CSG_STAR; } cook(inputCoreGroups) { try { vector2ToCsgVec2(this.pv.center, this._center); const { vertices, outerRadius, innerRadius, startAngle } = this.pv; const geo = star({ center: this._center, vertices, outerRadius, innerRadius, startAngle }); this.setCSGGeometry(geo); } catch (err) { const message = err instanceof Error ? err.message : "failed to create geometry"; this.states.error.set(message); this.setCSGObjects([]); } } }