Script: Cloud Assets

Cloud Assets picture
Type
Typescript logo indicatortypescript
Author
matas
Date Created
Jan 27, 2024, 9:15:57 AM
Last Edit Date
Jan 27, 2024, 11:57:34 AM

Project Information

This project contains demo scripts for TypeScript Monaco editor that are used as examples in the "Getting Started" section of the documentation.

View Full Project

Script Code

const drawOptions = new Bit.Inputs.Draw.DrawOcctShapeSimpleOptions();
drawOptions.edgeWidth = 1;
drawOptions.precision = 0.001;
drawOptions.faceColour = "#ffffff";

const start = async () => {
    nonEssentials();
    loadBoomBox();
    loadCalmCup();
    createGround();
}

async function loadCalmCup() {
    const fileCalmCup = await bitbybit.asset.getFile({
        fileName: "CalmCup.step"
    });

    const calmCupShape = await bitbybit.occt.io.loadSTEPorIGES({
        assetFile: fileCalmCup,
        adjustZtoY: false,
    });

    const scaledCalmCup = await bitbybit.occt.transforms.scale({
        shape: calmCupShape,
        factor: 0.3,
    });

    const transformedCalmCup = await bitbybit.occt.transforms.translate({
        shape: scaledCalmCup,
        translation: [-2, 0, 0],
    });

    await bitbybit.draw.drawAnyAsync({
        entity: transformedCalmCup,
        options: drawOptions
    });

    // It is a good practice to keep the memory of OCCT clean after you have constructed your drawn mesh.
    // Unless, of course, you will need some of these shapes in the future.
    bitbybit.occt.deleteShapes({
        shapes: [
            calmCupShape,
            scaledCalmCup,
            transformedCalmCup
        ]
    })
}

async function loadBoomBox() {
    const fileBoomBox = await bitbybit.asset.getFile({
        fileName: "BoomBox.glb"
    });
    const boomboxMesh = await bitbybit.babylon.io.loadAssetIntoScene({
        assetFile: fileBoomBox,
        hidden: false
    });
    boomboxMesh.position.x = 2;
}

async function createGround() {
    const groundShape = await bitbybit.occt.shapes.face.createCircleFace({
        radius: 7,
        center: [0, 0, 0],
        direction: [0, 1, 0]
    });
    
    await bitbybit.draw.drawAnyAsync({
        entity: groundShape,
        options: drawOptions
    });

    bitbybit.occt.deleteShape({
        shape: groundShape
    })
}

function nonEssentials() {
    bitbybit.babylon.scene.useRightHandedSystem({
        use: true
    });
    const dirLightOptions = new Bit.Inputs.BabylonScene.DirectionalLightDto();
    dirLightOptions.direction = [-100, -100, 100];
    bitbybit.babylon.scene.drawDirectionalLight(dirLightOptions);
    const skyboxOptions = new Bit.Inputs.BabylonScene.SkyboxDto();
    skyboxOptions.skybox = Bit.Inputs.Base.skyboxEnum.clearSky;
    bitbybit.babylon.scene.enableSkybox(skyboxOptions);
}

start();