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