models/obs_stopper_base.jscad

128 lines
2.6 KiB
JavaScript

const { polygon, cylinder } = require('@jscad/modeling').primitives;
const { extrudeLinear } = require('@jscad/modeling').extrusions;
const { translate, rotate } = require('@jscad/modeling').transforms;
const { intersect, subtract, union } = require('@jscad/modeling').booleans
function stripRounding(pointArray) {
return pointArray.map(point => point.slice(0, 2));
}
function polyRound({ points, factor }) {
return polygon({points: stripRounding(points)});
}
function polyRoundExtrude({points, length, startRadius, endRadius, factor}) {
return extrudeLinear({height: length}, polyRound({ points, factor }))
}
const baseWidth = 32;
const baseLength = 27;
const baseHeight = 1;
const ridgeWidth = 5;
const ridgeHeight = 3;
function ridge() {
const length = baseWidth;
const offset = [0, 8, baseHeight];
const radii = [
[0, 0, 0],
[length, 0, 0],
[length, ridgeWidth, 0],
[0, ridgeWidth, 0],
];
return translate(
offset,
polyRoundExtrude({ points: radii, length: ridgeHeight })
);
}
function base() {
const radii = [
[0, 0, 0],
[baseWidth, 0, 0],
[baseWidth, baseLength, 0],
[0, baseLength, 0],
];
return polyRoundExtrude({ points: radii, length: baseHeight });
}
function ridgeSpace() {
const height = 2;
const width = ridgeWidth;
const length = 12;
const offset = [0, 8, baseHeight + ridgeHeight - height];
const radii = [
[0, 0, 0],
[length, 0, 0],
[length, width, 0],
[0, width, 0],
];
return translate(
offset,
polyRoundExtrude({ points: radii, length: height })
);
}
function hole() {
const radius = 5 / 2;
const offset = [6, 8 + radius, 0];
return translate(
offset,
cylinder({height: ridgeHeight + baseHeight, radius: radius * 1.1})
);
}
function wingBase() {
const height = 1;
const width = 5.5;
const wingBaseLength = 15.5;
const wingEdgeLength = 10;
const wingEdgeOffset = 1;
const offset = [0, 3, baseHeight];
const radii = [
[0, 0, 0],
[width, wingEdgeOffset, 0],
[width, wingEdgeLength + 1, 0],
[0, wingBaseLength, 0],
];
// FIXME - this piece is not well-shaped
const rootRadii = [
[-1, 0, 0],
[0, 0, 0],
[0, wingBaseLength, 0],
[-1, wingBaseLength, 0],
];
return translate(
offset,
rotate(
[0, -3*Math.PI / 4, 0],
union(
polyRoundExtrude({ points: radii, length: height }),
polyRoundExtrude({ points: rootRadii, length: height })
)
)
);
}
const main = () => {
return subtract(
union(
base(),
ridge(),
wingBase()
),
ridgeSpace(),
hole()
);
}
module.exports = { main }