intersect with a Plane

intersect with a Plane script details
Type
Typescript logo image
typescript
App Version
0.19.1
Visibility
public
Date Created
Jan 3, 2025, 4:22:26 PM
Last Edit Date
Jan 7, 2025, 4:01:50 PM

Script Details

The Code
const start = async () => { const slicingStep = 0.1; const sphereOpt = new Bit.Inputs.OCCT.SphereDto(); sphereOpt.center = [0, 0, 2]; const slicingDirection = sphereOpt.center; const sphere = await bitbybit.occt.shapes.solid.createSphere(sphereOpt); const slices = await sliceSphere(sphere, slicingStep, slicingDirection); const slicingPosition = [ sphereOpt.center[0] + slicingStep * slicingDirection[0], sphereOpt.center[1] + slicingStep * slicingDirection[1], sphereOpt.center[2] + slicingStep * slicingDirection[2], ]; const newPlane = await createPlane(slicingPosition, slicingDirection); // Create the slicing plane // console.info(slices); const faces = await bitbybit.occt.shapes.face.getFaces({ shape: slices }); console.info(faces); const drawOptions = new Bit.Inputs.Draw.DrawOcctShapeOptions(); drawOptions.faceColour = "#ffffff"; drawOptions.edgeColour = "#000000"; drawOptions.edgeWidth = 1; drawOptions.precision = 0.005; await bitbybit.draw.drawAnyAsync({ entity: faces, options: drawOptions }); // await bitbybit.draw.drawAnyAsync({ // entity: newPlane, // options: drawOptions // }); // const ptLightOpt = new Bit.Inputs.BabylonScene.PointLightDto(); // ptLightOpt.position = [-3, 3, 0]; // ptLightOpt.shadowGeneratorMapSize = 2056; // ptLightOpt.diffuse = "#ff00ff"; // bitbybit.babylon.scene.drawPointLight(ptLightOpt) } async function createPlane(slicingPosition, slicingDirection) { const plane2 = await bitbybit.occt.shapes.face.createSquareFace({ size: 10, // Size of the plane (adjust as needed) center: slicingPosition, // Center of the plane direction: slicingDirection, // Plane normal matches slicing direction }); return plane2; } async function sliceSphere(sphere, slicingStep, slicingDirection) { const slices = await bitbybit.occt.operations.slice({ shape: sphere, direction: slicingDirection, step: slicingStep, }); return slices; } start();