Skip to main content

A simple vase

This is a simple vase that shows off the smoothSpline API.

We can have a look at the rendered shape.

And here is what the code looks like.

const defaultParams = {
height: 100,
baseWidth: 20,
wallThickness: 5,
lowerCircleRadius: 1.5,
lowerCirclPosition: 0.25,
higherCircleRadius: 0.75,
higherCirclePosition: 0.75,
topRadius: 0.9,
topFillet: true,
bottomHeavy: true,
};

/** @typedef { typeof import("replicad") } replicadLib */
/** @type {function(replicadLib, typeof defaultParams): any} */
const main = (
{ Sketcher },
{
height,
baseWidth,
wallThickness,
lowerCirclPosition,
lowerCircleRadius,
higherCircleRadius,
higherCirclePosition,
topRadius,
topFillet,
bottomHeavy,
}
) => {
const splinesConfig = [
{ position: lowerCirclPosition, radius: lowerCircleRadius },
{
position: higherCirclePosition,
radius: higherCircleRadius,
startFactor: bottomHeavy ? 3 : 1,
},
{ position: 1, radius: topRadius, startFactor: bottomHeavy ? 3 : 1 },
];

const sketchVaseProfile = new Sketcher("XZ").hLine(baseWidth);

splinesConfig.forEach(({ position, radius, startFactor, endFactor }) => {
sketchVaseProfile.smoothSplineTo([baseWidth * radius, height * position], {
endTangent: [0, 1],
startFactor,
endFactor,
});
});

let vase = sketchVaseProfile.lineTo([0, height]).close().revolve();

if (wallThickness) {
vase = vase.shell(wallThickness, (f) => f.containsPoint([0, 0, height]));
}

if (topFillet) {
vase = vase.fillet(wallThickness / 3, (e) => e.inPlane("XY", height));
}

return vase;
};