Script TS TypeScript Free

Camera Animation Setup

Author
bitbybit
Created
Jun 6, 2024, 7:40:38 AM
Last edit
Jun 11, 2024, 8:21:42 AM

Edit scriptPreview

Project

Parametric Table With Gaussian Splatting Palm Tree

This project demonstrates the possibilities of combining parametric CAD table 3D model with palm tree 3D scan imported through gaussian splatting feature

View full project
const { occt } = bitbybit;

enum cameraAnimationEnum {
    ellipse,
    spiral,
    line,
};

let activeAnimation = cameraAnimationEnum.spiral;

const start = async () => {
    const assetPalm = await bitbybit.asset.getFile({ fileName: "palm.splat" });
    const objectUrl = bitbybit.asset.createObjectURL({ file: assetPalm });
    const gs = await bitbybit.babylon.gaussianSplatting.create({
        url: objectUrl
    });

    gs.position = new BABYLON.Vector3(-0.2, 1, 0.5)

    const skyboxDto = new Bit.Inputs.BabylonScene.SkyboxDto();
    skyboxDto.blur = 0.5;
    skyboxDto.skybox = Bit.Inputs.Base.skyboxEnum.city;
    bitbybit.babylon.scene.enableSkybox(skyboxDto);

    const lightDto = new Bit.Inputs.BabylonScene.DirectionalLightDto();
    lightDto.intensity = 2;
    lightDto.shadowGeneratorMapSize = 4000;
    lightDto.diffuse = "#2E58FF";
    bitbybit.babylon.scene.drawDirectionalLight(lightDto);

    const lightDto2 = new Bit.Inputs.BabylonScene.DirectionalLightDto();
    lightDto2.direction = [100, -100, -100];
    lightDto2.intensity = 2;
    lightDto2.shadowGeneratorMapSize = 4000;
    lightDto2.diffuse = "#2E58FF";
    bitbybit.babylon.scene.drawDirectionalLight(lightDto2);


    const assetTable = await bitbybit.asset.getFile({ fileName: "parametric-table.glb" });

    const table = await bitbybit.babylon.io.loadAssetIntoScene({
        assetFile: assetTable,
        hidden: false,
    });

    setupCameraAndAnimations();
}


async function setupCameraAndAnimations() {

    let wire;
    if (activeAnimation === cameraAnimationEnum.ellipse) {
        wire = await occt.shapes.wire.createEllipseWire({
            center: [0, 4, 0],
            radiusMinor: 8,
            radiusMajor: 10,
            direction: [0.3, 1, 0]
        });
    } else if (activeAnimation === cameraAnimationEnum.line) {
        wire = await occt.shapes.wire.createLineWire({
            start: [15, 2, 15],
            end: [-3, 2, -15],
        });
    } else if (activeAnimation === cameraAnimationEnum.spiral) {
        const radius = 9;
        const step = 0.5;


        const ptsSpiralBase: Bit.Inputs.Base.Point3[] = [
            [radius, step * 4, 0],
            [5, step * 5, radius - 1],
            [-radius + 2, step * 6, 0],
            [5, step * 7, -radius + 3],
            [radius - 4, step * 8, 0],
            [0, step * 9, radius - 5],
            [-radius + 6, step * 10, 0],
            [0, step * 11, -radius + 7],
        ];
        wire = await occt.shapes.wire.interpolatePoints({ points: ptsSpiralBase, periodic: false, tolerance: 0.01 });
    }
    const points = await occt.shapes.wire.divideWireByEqualDistanceToPoints({ shape: wire, nrOfDivisions: 10000, removeStartPoint: false, removeEndPoint: true });

    const ptsLooped = [...points, ...points.reverse()]

    const camera = bitbybit.babylon.scene.getActiveCamera() as BABYLON.ArcRotateCamera;
    camera.target = new BABYLON.Vector3(0, 2, 0);
    let index = 0;
    bitbybit.time.registerRenderFunction(() => {
        if (index < ptsLooped.length) {
            const pt = ptsLooped[index];
            camera.setPosition(new BABYLON.Vector3(pt[0], pt[1], pt[2]))
            index++;
        } else {
            index = 0;
        }
    });
}

start();

Plans and pricing

Choose your plan

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

EnterpriseB2BCustompricing

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

Learn moreContact us

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

All prices exclude applicable taxesView all plan details

Contact

Talk to us

Tell us what you are building or what is blocking you, through whichever channel suits you.