TypeScript Manifold Example

TypeScript Manifold Example script details
Type
Typescript logo image
typescript
App Version
0.19.0
Visibility
public
Date Created
Nov 27, 2024, 2:03:31 PM
Last Edit Date
Nov 27, 2024, 2:18:20 PM

Script Details

The Code
const { manifold } = bitbybit.manifold; const { occt } = bitbybit; const s = async () => { createEnvironment(); const sphereManifold = await bitbybit.manifold.manifold.shapes.sphere({ radius: 1, circularSegments: 32, }); const span = bitbybit.vector.span({ step: 0.1, min: -1, max: 1, }); const slicedManifolds = await manifold.booleans.splitByPlaneOnOffsets({ manifold: sphereManifold, normal: [1, 1, 0.3], originOffsets: span }); const spanTranslations = bitbybit.vector.span({ step: 0.2, min: 0, max: 4.2, }); const translatedManifoldPromises = []; slicedManifolds.forEach((s, i) => { const translated = manifold.transforms.translate({ manifold: s, vector: [0, spanTranslations[i], 0] }); translatedManifoldPromises.push(translated); }); const translatedManifolds = await Promise.all(translatedManifoldPromises); const composedManifold = await manifold.operations.compose({ manifolds: translatedManifolds }); const options = new Bit.Inputs.Draw.DrawManifoldOrCrossSectionOptions(); options.faceColour = "#ff00ff"; const meshDrawn = await bitbybit.draw.drawAnyAsync({ entity: composedManifold, options }); const circleGround = await occt.shapes.face.createCircleFace({ radius: 5, center: [0, -1, 0], direction: [0, 1, 0], }); bitbybit.time.registerRenderFunction(() => { bitbybit.babylon.mesh.yaw({ babylonMesh: meshDrawn, rotate: 0.5 }); }); bitbybit.draw.drawAnyAsync({ entity: circleGround }); } function createEnvironment() { const skybox = new Bit.Inputs.BabylonScene.SkyboxDto(); bitbybit.babylon.scene.enableSkybox(skybox); const lightOpt = new Bit.Inputs.BabylonScene.DirectionalLightDto(); lightOpt.intensity = 3; lightOpt.direction = [-100,-100,-50] bitbybit.babylon.scene.drawDirectionalLight(lightOpt); } s();