
typescriptIn this project we demonstrate how to load Cloud image assets and create BabylonJS texture from them. Then we apply texture to material and add material on the mesh.
const start = async () => {
setupEnvironment();
const mat = await setupTextureAndMaterial("dogs-small.jpeg");
createGeometryAndAssignMaterial(mat);
}
async function setupTextureAndMaterial(cloudAssetFileName: string) {
const file = await bitbybit.asset.getFile({
fileName: cloudAssetFileName
});
const objectUrl = bitbybit.asset.createObjectURL({
file
});
const textureOptions = new Bit.Inputs.BabylonTexture.TextureSimpleDto();
textureOptions.url = objectUrl;
const texture = bitbybit.babylon.texture.createSimple(textureOptions);
const materialOptions = new Bit.Inputs.BabylonMaterial.PBRMetallicRoughnessDto();
materialOptions.roughness = 0.9;
materialOptions.metallic = 0.1;
materialOptions.baseColor = "#ffffff";
const mat = bitbybit.babylon.material.pbrMetallicRoughness.create(materialOptions);
mat.baseTexture = texture;
return mat;
}
function createGeometryAndAssignMaterial(mat: BABYLON.PBRMetallicRoughnessMaterial) {
const cubeOptions = new Bit.Inputs.BabylonMeshBuilder.CreateCubeDto();
cubeOptions.size = 10;
const cubeMesh = bitbybit.babylon.meshBuilder.createCube(cubeOptions);
cubeMesh.material = mat;
bitbybit.babylon.mesh.moveUp({
babylonMesh: cubeMesh,
distance: 7,
})
const squarePlaneOptions = new Bit.Inputs.BabylonMeshBuilder.CreateSquarePlaneDto();
squarePlaneOptions.size = 40;
const planeSquareMesh = bitbybit.babylon.meshBuilder.createSquarePlane(squarePlaneOptions);
bitbybit.babylon.mesh.pitch({
babylonMesh: planeSquareMesh,
rotate: 90
})
planeSquareMesh.material = mat;
}
function setupEnvironment() {
const skyboxOptions = new Bit.Inputs.BabylonScene.SkyboxDto();
bitbybit.babylon.scene.enableSkybox(skyboxOptions);
const dirLightOptions = new Bit.Inputs.BabylonScene.DirectionalLightDto();
dirLightOptions.intensity = 5;
bitbybit.babylon.scene.drawDirectionalLight(dirLightOptions);
}
start();
Editor plans for 3D development, API keys for server-side CAD algorithms
Cloud storage, private projects & 3D algorithms for Bitbybit editors
Run CAD algorithms on managed cloud servers from your own backend applications
Custom software development, dedicated servers & CAD automation at scale.