Script: First Contact

First Contact picture
Type
Typescript logo indicatortypescript
Author
matas
Date Created
Oct 31, 2023, 1:22:31 PM
Last Edit Date
Dec 5, 2023, 3:08:46 PM

Project Information

The course that introduces the bitbybit.dev platform to BabylonJS developers.

View Full Project

Script Code

type Point3 = Bit.Inputs.Base.Point3;
// We use bitbybit to get the default engine
const engine = bitbybit.babylon.engine.getEngine();

const scene = new BABYLON.Scene(engine);

// It is important to inform bitbybit that we use non-default scene
bitbybit.babylon.scene.setAndAttachScene({ scene });

var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(4, 4, -4), scene);
camera.setTarget(BABYLON.Vector3.Zero());

// We can only re-use the existing rendering canvas from default engine
const canvas = bitbybit.babylon.engine.getRenderingCanvas();

camera.attachControl(canvas, true);
camera.speed = 0.15;
camera.minZ = 0;

// BabylonJS way of creating lights
const light = new BABYLON.HemisphericLight("HemiLight", new BABYLON.Vector3(0, 1, 0), scene);
light.intensityMode = BABYLON.Light.INTENSITYMODE_ILLUMINANCE;
light.intensity = 1;

const start = async () => {

    const gridOptions = new Bit.Inputs.Draw.SceneDrawGridMeshDto();
    bitbybit.draw.drawGridMesh(gridOptions);

    const points: Point3[] = [
        [2, 1, 2],
        [2, 1, 0],
        [-2, 1, -2],
        [0, 1, 2]
    ];

    const pointDrawOptions = new Bit.Inputs.Draw.DrawBasicGeometryOptions();
    pointDrawOptions.colours = ["#ff00ff"];

    bitbybit.draw.drawAnyAsync({
        entity: points,
        options: pointDrawOptions
    });

    const wireThroughPoints = await bitbybit.occt.shapes.wire.interpolatePoints({
        points,
        periodic: true,
        tolerance: 0.01,
    });

    const wireDrawOptions = new Bit.Inputs.Draw.DrawOcctShapeOptions();
    wireDrawOptions.edgeColour = "#0000ff";
    bitbybit.draw.drawAnyAsync({
        entity: wireThroughPoints,
        options: wireDrawOptions
    });

    const extrusion = await bitbybit.occt.operations.extrude({
        shape: wireThroughPoints,
        direction: [0, 2, 0]
    });

    const extrusionFaces = await bitbybit.occt.shapes.face.getFaces({
        shape: extrusion
    });

    const bottomFace = await bitbybit.occt.shapes.face.createFaceFromWire({
        shape: wireThroughPoints,
        planar: false
    });

    const shell = await bitbybit.occt.shapes.shell.sewFaces({
        shapes: [...extrusionFaces, bottomFace],
        tolerance: 0.001
    });

    const fillet = await bitbybit.occt.fillets.filletEdges({
        shape: shell,
        radius: 0.2,
    });

    const thickSolid = await bitbybit.occt.operations.makeThickSolidSimple({
        shape: fillet,
        offset: -1
    });

    const filletThick = await bitbybit.occt.fillets.filletEdges({
        shape: thickSolid,
        radiusList: [0.1, 0.4],
        indexes: [3, 7],
    });

    const finalDrawOptions = new Bit.Inputs.Draw.DrawOcctShapeOptions();
    finalDrawOptions.precision = 0.002;
    finalDrawOptions.faceOpacity = 0.5;

    const mesh = await bitbybit.draw.drawAnyAsync({
        entity: filletThick,
        options: finalDrawOptions
    });

}

start();
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