// joint parameters
const jointTotalHeight = 14;
const jointWallThickness = 0.3;
const jointEdgeFilletRadiusPercentage = 0;
// joint hole parameters
const jointRadiusOfTheHole = 0.83;
const jointHoleDepth = 2;
// joint rotation parameters
const xDivisions = 1;
const zDivisions = 1;
// output parameters
const splitInHalfFor3DPrint = true;
const saveStepFile = false;
const whiteColour = '#ffffff';
const faceColour = '#ff2966';
const edgeColour = '#297fff';
const doubleHeight = jointTotalHeight * 3;
bitbybit.babylon.scene.drawPointLight({ position: [doubleHeight, doubleHeight, doubleHeight], intensity: 3000, radius: 0, diffuse: whiteColour, specular: whiteColour });
start();
async function start() {
const cylinder = await makeCylinder(jointWallThickness, jointRadiusOfTheHole, jointTotalHeight / 2, jointHoleDepth, (jointWallThickness / 2) * (jointEdgeFilletRadiusPercentage / 100));
const rotatedShapes = await rotateInPositions(cylinder, xDivisions, zDivisions);
const union = await bitbybit.occt.booleans.union({ shapes: rotatedShapes, keepEdges: false });
let resultShape = union;
if (splitInHalfFor3DPrint) {
const box = await bitbybit.occt.shapes.solid.createBox({ width: doubleHeight, height: doubleHeight, length: doubleHeight, center: [0, 0, -doubleHeight / 2] });
const half = await bitbybit.occt.booleans.difference({ shape: union, shapes: [box], keepEdges: false });
resultShape = half;
}
const drawOptions = new Bit.Inputs.Draw.DrawOcctShapeOptions();
drawOptions.faceColour = faceColour;
drawOptions.edgeColour = edgeColour;
drawOptions.edgeOpacity = 0.3;
drawOptions.edgeWidth = 5;
bitbybit.draw.drawAnyAsync({ entity: resultShape, options: drawOptions });
if (saveStepFile) {
bitbybit.occt.io.saveShapeSTEP({ shape: resultShape, fileName: 'bitbybit-dev.step', adjustYtoZ: true })
}
}
async function makeCylinder(thickness: number, radiusHole: number, height: number, holeDepth: number, roundRadius: number) {
const cylinderBase = await bitbybit.occt.shapes.solid.createCylinder({ center: [0, 0, 0], height, radius: radiusHole + thickness, direction: [0, 1, 0] });
const cylinderHole = await bitbybit.occt.shapes.solid.createCylinder({ center: [0, holeDepth, 0], height, radius: radiusHole, direction: [0, 1, 0] });
const cyl = await bitbybit.occt.booleans.difference({ shape: cylinderBase, shapes: [cylinderHole], keepEdges: false });
const mirrored = await bitbybit.occt.transforms.mirror({ shape: cyl, direction: [0, 0, 1], origin: [0, 0, 0] });
const finalCyl = await bitbybit.occt.booleans.union({ shapes: [cyl, mirrored], keepEdges: false });
let result = finalCyl
let finalRoundRadius;
if (roundRadius * 2 >= thickness) {
finalRoundRadius = roundRadius - 0.0001;
} else {
finalRoundRadius = roundRadius;
}
if (finalRoundRadius !== 0) {
result = await bitbybit.occt.fillets.filletEdges({ shape: finalCyl, radius: finalRoundRadius, indexes: [1, 3, 4, 5] });
}
return result;
}
async function rotateInPositions(shape: any, numOnXAxis: number, numOnZAxis: number) {
const shapes = [];
for (let i = -90 + (90 / numOnXAxis); i < 90; i += 90 / numOnXAxis) {
const rotation = new Bit.Inputs.OCCT.RotateDto(shape, [1, 0, 0], i);
const rotatedShapeX = await bitbybit.occt.transforms.rotate(rotation);
for (let j = -90; j < 90; j += 90 / numOnZAxis) {
const rotationY = new Bit.Inputs.OCCT.RotateDto(rotatedShapeX, [0, 0, 1], j);
const rotatedShapeXY = await bitbybit.occt.transforms.rotate(rotationY);
shapes.push(rotatedShapeXY);
}
}
const rotation = new Bit.Inputs.OCCT.RotateDto(shape, [1, 0, 0], 90);
const rotatedShapeToY = await bitbybit.occt.transforms.rotate(rotation);
shapes.push(rotatedShapeToY);
return shapes;
}