3D Table Configurator TypeScript

3D Table Configurator TypeScript script details
Type
Typescript logo image
typescript
App Version
0.15.14
Visibility
public
Date Created
Jul 25, 2024, 10:03:55 AM
Last Edit Date
Jul 28, 2024, 11:07:20 AM

Script Details

The Code
type Inputs = { width: number; length: number; height: number; thickness: number; }; const defaultValues: Inputs = { width: 1, length: 1, height: 0.5, thickness: 0.05, }; Bit.mockBitbybitRunnerInputs(defaultValues); const inputs: Inputs = Bit.getBitbybitRunnerInputs(); const { solid, compound, face } = bitbybit.occt.shapes; const legHeight = inputs.height - inputs.thickness; const halfLegHeight = legHeight / 2; const halfThickness = inputs.thickness / 2; const widthOffset = inputs.width / 2 - halfThickness; const lengthOffset = inputs.length / 2 - halfThickness; const start = async () => { const skyboxOptions = new Bit.Inputs.BabylonScene.SkyboxDto(); skyboxOptions.skybox = Bit.Inputs.Base.skyboxEnum.clearSky; bitbybit.babylon.scene.enableSkybox(skyboxOptions); const lightOptions = new Bit.Inputs.BabylonScene.DirectionalLightDto(); lightOptions.intensity = 3; bitbybit.babylon.scene.drawDirectionalLight(lightOptions); const tableTopShape = await solid.createBox({ width: inputs.width, length: inputs.length, height: inputs.thickness, center: [0, inputs.height - halfThickness, 0], }); const leg1Shape = await solid.createBox({ width: inputs.thickness, length: inputs.thickness, height: legHeight, center: [widthOffset, halfLegHeight, lengthOffset], }); const leg2Shape = await solid.createBox({ width: inputs.thickness, length: inputs.thickness, height: legHeight, center: [-widthOffset, halfLegHeight, lengthOffset], }); const leg3Shape = await solid.createBox({ width: inputs.thickness, length: inputs.thickness, height: legHeight, center: [widthOffset, halfLegHeight, -lengthOffset], }); const leg4Shape = await solid.createBox({ width: inputs.thickness, length: inputs.thickness, height: legHeight, center: [-widthOffset, halfLegHeight, -lengthOffset], }); const groundShape = await face.createCircleFace({ radius: 2, center: [0, 0, 0], direction: [0, 1, 0] }); const compoundShape = await compound.makeCompound({ shapes: [tableTopShape, leg1Shape, leg2Shape, leg3Shape, leg4Shape, groundShape], }); const drawOptions = new Bit.Inputs.Draw.DrawOcctShapeSimpleOptions(); drawOptions.faceColour = "#555577"; drawOptions.edgeWidth = 1; const table = await bitbybit.draw.drawAnyAsync({ entity: compoundShape, options: drawOptions }); return { table }; } const runnerOutput = start(); Bit.setBitbybitRunnerResult(runnerOutput);