Script
Laptop holder runner example
- Project
- Laptop vertical stand
- Author
- matas
- Created
- Jul 10, 2024, 12:32:24 PM
- Last edit
- Jul 29, 2024, 3:59:09 PM
Project
Laptop vertical stand
Multi slot and single slot configurable laptop stand. Change parameters and you will be able to configure this stand for your own purposes in minutes.
View full projectScript code
Bit.mockBitbybitRunnerInputs({
"Laptop Type": "MacBook Pro 16",
"Number Laptops": "3",
"Color": "Black",
});
const inputs = Bit.getBitbybitRunnerInputs();
const laptops: Laptop[] = []
let laptop: Laptop;
switch (inputs["Laptop Type"]) {
case "MacBook Pro 16":
laptop = {
length: 1.63,
width: 35.8,
height: 24.6
};
break;
case "MacBook Pro 14":
laptop = {
length: 1.57,
width: 31.3,
height: 22.2
}
break;
case "MacBook Air":
laptop = {
length: 1.2,
width: 30.5,
height: 21.6
}
break;
default:
break;
}
let flipColor = false;
switch (inputs["Color"]) {
case "Blue":
flipColor = true;
break;
default:
break;
}
console.log("laptop ", laptop);
const nrLaptops = +inputs["Number Laptops"];
for (let i = 0; i < nrLaptops; i++) {
laptops.push({ ...laptop });
}
const whiteColor = "#ffffff";
const holderColor = "#333333";
const laptopLiftedHeight = 3;
const distanceBetweenLaptops = 1.7;
const exportSTEP = false;
bitbybit.babylon.scene.backgroundColour({ colour: "#bbbbbb" });
const pointLightConf = new Bit.Inputs.BabylonScene.PointLightDto();
pointLightConf.position = [-15, 20, -5];
pointLightConf.intensity = 8000;
pointLightConf.diffuse = "#3333ff";
pointLightConf.radius = 0;
bitbybit.babylon.scene.drawPointLight(pointLightConf);
const controlPoints = [
[-12.5, 0, 0],
[-8, 13, 0],
[-4, 11, 0],
[-2, 6, 0],
[2, 6, 0],
[4, 14, 0],
[8, 17, 0],
[12.5, 0, 0]
] as Bit.Inputs.Base.Point3[];
let laptopStand;
let laptopStandMesh;
const laptopsFilletsMesh = [];
async function start() {
const ground = await bitbybit.occt.shapes.face.createCircleFace({ center: [0, 0, 0], direction: [0, 1, 0], radius: 75, });
const groundOptions = new Bit.Inputs.Draw.DrawOcctShapeOptions();
groundOptions.faceColour = whiteColor;
groundOptions.drawEdges = false;
await bitbybit.draw.drawAnyAsync({ entity: ground, options: groundOptions });
const renderLaptops = async (laptops) => {
laptops.forEach(laptop => {
laptop.center = [0, laptop.height / 2 + laptopLiftedHeight, 0] as Bit.Inputs.Base.Point3;
});
let laptopFillets = [];
let totalDistance = 0;
let previousLaptopLength = 0;
laptops.forEach(async (laptop, index) => {
totalDistance += distanceBetweenLaptops + laptop.length / 2 + previousLaptopLength / 2;
previousLaptopLength = laptop.length;
laptop.center[2] = totalDistance;
const laptopBaseModel = await bitbybit.occt.shapes.solid.createBox({
width: laptop.width,
length: laptop.length,
height: laptop.height,
center: laptop.center
});
const laptopFillet = await bitbybit.occt.fillets.filletEdges({ shape: laptopBaseModel, indexes: undefined, radius: 0.2 });
laptopFillets.push(laptopFillet);
const laptopVisModel = await bitbybit.occt.shapes.solid.createBox({
width: laptop.width,
length: laptop.length - 0.01,
height: laptop.height,
center: laptop.center
});
const laptopVisFillet = await bitbybit.occt.fillets.filletEdges({ shape: laptopVisModel, indexes: undefined, radius: 0.2 });
laptopFillets.push(laptopFillet);
const di = new Bit.Inputs.OCCT.DrawShapeDto(laptopVisFillet);
di.faceOpacity = 0.2;
di.edgeWidth = 5;
di.edgeOpacity = 0.6;
di.edgeColour = whiteColor;
di.faceColour = whiteColor;
const laptopFilletMesh = await bitbybit.occt.drawShape(di);
laptopsFilletsMesh.push(laptopFilletMesh);
})
const polygonWire = await bitbybit.occt.shapes.wire.createPolygonWire({
points: controlPoints
});
const extrusion = await bitbybit.occt.operations.extrude({
shape: polygonWire, direction: [0, 0, totalDistance += distanceBetweenLaptops + previousLaptopLength / 2]
});
const laptopStandFillet = await bitbybit.occt.fillets.filletEdges({ shape: extrusion, indexes: undefined, radius: 1 });
const laptopStandThick = await bitbybit.occt.operations.makeThickSolidSimple({ shape: laptopStandFillet, offset: -0.5 });
laptopStand = await bitbybit.occt.booleans.difference({ shape: laptopStandThick, shapes: laptopFillets, keepEdges: false });
const li = new Bit.Inputs.OCCT.DrawShapeDto(laptopStand);
li.faceOpacity = 1;
if (flipColor) {
li.faceColour = "#0000ff";
li.edgeColour = whiteColor;
} else {
li.faceColour = holderColor;
li.edgeColour = whiteColor;
}
li.edgeWidth = 5;
laptopStandMesh = await bitbybit.draw.drawAnyAsync({ entity: laptopStand, options: li });
const laptopsMeshes = await Promise.all(laptopsFilletsMesh);
return [laptopStandMesh, ...laptopsMeshes];
}
const meshes = await renderLaptops(laptops);
return { meshes };
}
class Laptop {
width: number;
length: number;
height: number;
center?: Bit.Inputs.Base.Point3;
}
Bit.setBitbybitRunnerResult(start());