UNPKG

@polygonjs/polygonjs

Version:

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

46 lines (45 loc) 1.58 kB
"use strict"; import { CADSopNode } from "./_BaseCAD"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { step } from "../../../core/geometry/modules/cad/CadConstant"; import { CadLoader } from "../../../core/geometry/modules/cad/CadLoader"; import { cadShapeTranslate } from "../../../core/geometry/modules/cad/toObject3D/CadShapeCommon"; import { Vector3 } from "three"; const size = new Vector3(); const centerOffset = new Vector3(); class CADBoxSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param size */ this.size = ParamConfig.FLOAT(1, { range: [0, 10], rangeLocked: [true, false], step }); /** @param sizes */ this.sizes = ParamConfig.VECTOR3([1, 1, 1]); /** @param center */ this.center = ParamConfig.VECTOR3([0, 0, 0]); } } const ParamsConfig = new CADBoxSopParamsConfig(); export class CADBoxSopNode extends CADSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.CAD_BOX; } async cook() { const oc = await CadLoader.core(this); size.copy(this.pv.sizes).multiplyScalar(this.pv.size); const api = new oc.BRepPrimAPI_MakeBox_2(size.x, size.y, size.z); centerOffset.copy(size).multiplyScalar(-0.5); const centered = cadShapeTranslate(api.Shape(), centerOffset); const shape = cadShapeTranslate(centered, this.pv.center); api.delete(); this.setCADShape(shape); } }