@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
47 lines (46 loc) • 1.41 kB
JavaScript
;
import { CSGSopNode } from "./_BaseCSG";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { primitives, booleans, utils, transforms, maths } from "@jscad/modeling";
const { cuboid } = primitives;
const { intersect } = booleans;
const { rotateX, rotateZ, scale } = transforms;
const { degToRad } = utils;
const dodecahedron = (h) => {
let cuboid1 = cuboid({ size: [20, 20, 10] });
for (let i = 0; i <= 4; i++) {
cuboid1 = intersect(
cuboid1,
rotateZ(i * degToRad(72), rotateX(degToRad(116.565), cuboid({ size: [20, 20, 10] })))
);
}
return scale([h, h, h], cuboid1);
};
class CSGDodecahedronSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param radius */
this.radius = ParamConfig.FLOAT(1, {
range: [maths.constants.EPS, 1],
rangeLocked: [true, false]
});
}
}
const ParamsConfig = new CSGDodecahedronSopParamsConfig();
export class CSGDodecahedronSopNode extends CSGSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.CSG_DODECAHEDRON;
}
initializeNode() {
this.io.inputs.setCount(0);
}
cook(inputCoreGroups) {
const object = dodecahedron(this.pv.radius * 0.1);
this.setCSGGeometry(object);
}
}