SceneLoader.ImportMesh causes duplication and conversion of textures

Hello everbody, I love babylon.js and the community behind. Thanks in advance for any help about my problem.

Firstly I use babylon.js to create a kind of a 3d model editor that allows users to upload models, import them to babylon scene by using SceneLoader.ImportMesh and exports the scene by using GLTF2Export.GLBAsync.

The gltf model I use can be downloaded from here Industrial Box Steel Containers - Download Free 3D model by 3Danielart (@3Danielart) [d8c9437] - Sketchfab.

When I import this model with SceneLoader.ImportMesh, jpeg texture files are converted to png and duplicating. This causes model sizes in my application are increased dramatically by default.

In some models, duplication does not happen but still jpeg files are being converted to png files and this also causes model sizes to be increased.

Model before importing to babylon

box_steel_2_baseColor.jpeg (363kb)
box_steel_3_baseColor.jpeg (637kb)
jonathan-provencal-sol_baseColor.jpeg (763kb)
scene.bin (2,67kb)
scene.gltf (7,41kb)

Model after importing to babylon

box_steel_2 (Base Color).png (893kb)
box_steel_2 (Emissive).png (893kb)
box_steel_3 (Base Color).png (1,62mb)
box_steel_3 (Emissive).png (1,62mb)
jonathan-provencal-sol (Base Color).png (1,64mb)
jonathan-provencal-sol (Emissive).png (1,64mb)
scene.bin (2,67kb)
scene.gltf (9,79kb)

I wonder if there is any workaround to import this model and leaving its textures untouched. Is there any way to prevent this png conversion?

Thanks,
Have a nice day!

Welcome aboard!

Note that in memory, there are only 3 pictures: the base and emissive textures are pointing to the same picture data.

It’s only in the exported file that the picture data are duplicated, because the loader created two different textures. Maybe a fix could be that the loader only creates a single texture for base and emissive, as those are really pointing to the same entry in the gltf file. However, there may be some good reasons to do it as it is done currently, I will let people knowing more about gltf import/export than me answer.

You can also have a look here about this issue: GLTF Exporter : Optimize textures files

1 Like

was there aver a fix for the GLTF Exporter creating duplicates of the textures on export?

im finding certain textures like emissives and normals are getting multiple times for every mesh but not the base color or metallic roughness.

Don’t get what the relevance could be.

Im finding this strange behaviour with:

const options = {
    shouldExportNode: (node: Node) => {
      return node.name !== 'BackgroundHelper' && node.name !== 'Background';
    }
 };
GLTF2Export.GLBAsync(this.scene, fileName, options).then((glb) => {
    glb.downloadFiles();
});

Can you share a repro ?

@sebavan
I bet you already have a keyboard shortcut for a macro which randomly types one of the following: “Can you share a repro?”
“Can you create a PG?”
etc…

:smiley:

I should definitely do that in my Stream Deck :slight_smile:

1 Like