intersect with a Plane

intersect with a Plane script details
Type
Typescript logo image
typescript
App Version
0.20.3
Visibility
public
Date Created
Jan 3, 2025, 4:22:26 PM
Last Edit Date
May 6, 2025, 10:02:58 AM

Script Details

The Code
const start = async () => { // const cube = await bitbybit.occt.shapes.solid.createBox({ // width: 2, // length: 2, // height: 2, // center: [0, 0, 0], // }); // get bounding box of the box // const cc = await bitbybit.occt.operations.boundingBoxCenterOfShape({ // shape: cube // }); // console.log("cc before", cc); // await bitbybit.draw.drawAnyAsync({ entity: cube, options: undefined }); const file = await bitbybit.asset.getLocalFile({ fileName: "model" }) as File; const fileSS = await bitbybit.asset.getLocalFile({ fileName: "ss" }) as File; const shape = await bitbybit.occt.io.loadSTEPorIGES({ assetFile: file, adjustZtoY: true, }); const shapeSS = await bitbybit.occt.io.loadSTEPorIGES({ assetFile: fileSS, adjustZtoY: true, }); console.log("shape", shape); // Bounding box before translation const bb = await bitbybit.occt.operations.boundingBoxCenterOfShape({ shape: shape }); console.log("bb before", bb); const bbSS = await bitbybit.occt.operations.boundingBoxCenterOfShape({ shape: shapeSS }); console.log("bbSS before", bbSS); // Translate const translatedShape = await bitbybit.occt.transforms.translate({ shape: shape, translation: [-bb[0], -bb[1], -bb[2]] }); const translatedShapeSS = await bitbybit.occt.transforms.translate({ shape: shapeSS, translation: [-bbSS[0], -bbSS[1], -bbSS[2]] }); // Bounding box after translation const bbAfter = await bitbybit.occt.operations.boundingBoxCenterOfShape({ shape: translatedShape }); console.log("bb after translation", bbAfter); const bbSSAfter = await bitbybit.occt.operations.boundingBoxCenterOfShape({ shape: translatedShapeSS }); console.log("bbSS after translation", bbSSAfter); const translatedShape2 = await bitbybit.occt.transforms.translate({ shape: shape, translation: [-bbSS[0], -bbSS[1], -bbSS[2]] }); const ccube = await bitbybit.occt.transforms.transform({ shape: translatedShape2, translation: bbAfter, // Valid translation rotationAngle: 0, // No rotation scaleFactor: 1, // Set to 1 to avoid scaling issues rotationAxis: [0, 0, 0] // Provide a valid axis (though not used since rotationAngle is 0) }); //offset SS const offsetSS = await bitbybit.occt.operations.offset({ shape: translatedShapeSS, distance: -0.5, tolerance: 0.001 }); const drawOpt = new Bit.Inputs.Draw.DrawOcctShapeOptions(); drawOpt.faceColour = "#0000ff"; // Using one color for simplicity drawOpt.precision = 0.001; // await bitbybit.draw.drawAnyAsync({ // entity: [ccube], // options: drawOpt // }); // const drawOpt1 = new Bit.Inputs.Draw.DrawOcctShapeOptions(); // drawOpt1.faceColour = "#ff0000"; // Using one color for simplicity // drawOpt1.precision = 0.001; // await bitbybit.draw.drawAnyAsync({ // entity: [offsetSS], // options: drawOpt1 // }); //intersect console.log("going to intersect"); const intersect = await bitbybit.occt.booleans.intersection({ shapes: [ccube, offsetSS], keepEdges: false }); console.log("finished intersection"); const drawOpt2 = new Bit.Inputs.Draw.DrawOcctShapeOptions(); drawOpt2.faceColour = "#00ff00"; // Using one color for simplicity drawOpt2.precision = 0.001; await bitbybit.draw.drawAnyAsync({ entity: [intersect], options: drawOpt2 }); } start();