Parametric box
Parametric Box
Section titled “Parametric Box”A hollow box with rounded corners — a practical starting point for enclosures, storage, and mounting bases.
How it works
Section titled “How it works”The outer shell is a roundedCuboid. An inner cavity — slightly smaller
on all sides and shifted upward by the wall thickness — is subtracted from
it using subtract, leaving walls and a solid floor of uniform thickness.
Parameters
Section titled “Parameters”| Parameter | Effect |
|---|---|
| Width / Depth / Height | Outer dimensions of the box |
| Wall thickness | How thick the sides and floor are |
| Corner radius | Rounding on the vertical edges |
Try setting Wall thickness close to Corner radius for a smooth, organic look, or keep them independent for a more industrial style.
"use strict";
const jscad = require('@jscad/modeling');const { roundedCuboid } = jscad.primitives;const { subtract } = jscad.booleans;const { translate } = jscad.transforms;const { colorize } = jscad.colors;
const getParameterDefinitions = () => [ { name: 'width', type: 'number', widget: 'slider', caption: 'Width (mm)', default: 80, min: 20, max: 200, step: 1 }, { name: 'depth', type: 'number', widget: 'slider', caption: 'Depth (mm)', default: 50, min: 20, max: 200, step: 1 }, { name: 'height', type: 'number', widget: 'slider', caption: 'Height (mm)', default: 30, min: 10, max: 100, step: 1 }, { name: 'wall', type: 'number', widget: 'slider', caption: 'Wall thickness (mm)', default: 2.5, min: 1, max: 10, step: 0.5 }, { name: 'radius', type: 'number', widget: 'slider', caption: 'Corner radius (mm)', default: 4, min: 0, max: 15, step: 0.5 },];
function main(params) { const { width, depth, height, wall, radius } = params;
// Outer shell const outer = roundedCuboid({ size: [width, depth, height], roundRadius: radius, segments: 32, });
// Inner cavity — offset upward so the floor stays solid const innerRadius = Math.max(0, radius - wall); const inner = translate( [0, 0, wall], roundedCuboid({ size: [width - wall * 2, depth - wall * 2, height], roundRadius: innerRadius, segments: 32, }), );
return colorize([0.204, 0.596, 0.859], subtract(outer, inner));}
module.exports = { main, getParameterDefinitions };