UNPKG

@polygonjs/polygonjs

Version:

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

56 lines (55 loc) 1.8 kB
"use strict"; import { CSGSopNode } from "./_BaseCSG"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { csgIsGeom3 } from "../../../core/geometry/modules/csg/CsgCoreType"; import { extrusions } from "@jscad/modeling"; import { vector3ToCsgVec3 } from "../../../core/geometry/modules/csg/CsgVecToVector"; const { project } = extrusions; class CSGProjectSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param axis */ this.axis = ParamConfig.VECTOR3([0, 1, 0]); /** @param origin */ this.origin = ParamConfig.VECTOR3([0, 0, 0]); } } const ParamsConfig = new CSGProjectSopParamsConfig(); export class CSGProjectSopNode extends CSGSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; this._axis = [0, 0, 0]; this._origin = [0, 0, 0]; } static type() { return SopType.CSG_PROJECT; } initializeNode() { this.io.inputs.setCount(1); } cook(inputCoreGroups) { const inputObjects = inputCoreGroups[0].csgObjects(); if (inputObjects && inputObjects.length != 0) { vector3ToCsgVec3(this.pv.axis, this._axis); vector3ToCsgVec3(this.pv.origin, this._origin); const options = { axis: this._axis, origin: this._origin }; const newGeometries = []; for (const inputObject of inputObjects) { const inputGeometry = inputObject.csgGeometry(); if (csgIsGeom3(inputGeometry)) { newGeometries.push(project(options, inputGeometry)); } else { newGeometries.push(inputGeometry); } } this.setCSGGeometries(newGeometries); } else { this.setCSGObjects([]); } } }