Script: 3D Table Configurator TypeScript

3D Table Configurator TypeScript picture
Type
Typescript logo indicatortypescript
Date Created
Jul 25, 2024, 12:03:55 PM
Last Edit Date
Jul 28, 2024, 1:07:20 PM

Project Information

This project contains some examples used in various tutorials for showing how BITBYBIT-RUNNER.JS works

View Full Project

Script 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);
Plans & Pricing

Choose Your Plan

Editor plans for 3D development, API keys for server-side CAD algorithms

B2B

ENTERPRISE

Custom pricing

Custom software development, dedicated servers & CAD automation at scale.

CAD Automation & Software
  • Custom software development
  • Cloud CAD automation pipelines
  • 3D configurators (STEP & GLTF)
  • Batch export jobs
  • Custom algorithms & deployment
Infrastructure & Support
  • Custom compute allocation
  • Dedicated / VPS server tenants
  • Long-running computation jobs
  • Custom upload limits & overage
  • SLA & premium support