Saving a .babylon with textures

Hi everyone,

I’m looking to you for a question.
Is it possible to save a “.babylon” with these textures?

The goal is to be able to reopen it in another environment than that of my main project, where I do not have access to the jpg/png textures.

Thank you in advance for your response.

Welcome aboard!

AFAIK, serializing textures is not supported in the .babylon files. Maybe you can try to export to .glb instead, which does support this feature?

Using glb would indeed be a better option.

But it does exist, BABYLON.Texture.ForceSerializeBuffers

False by default, setting as true will ensure the textures are embedded in the .babylon file, at a large size cost.

BABYLON.Texture.ForceSerializeBuffers = true;

2 Likes

I will try with a GLB, to avoid excessively large file sizes.

Thx you for your answers.

I tested both solutions, but I have a problem in both cases.
In the .glb solution, my file weighs 700MB while the same in Babylon version only weighs 10MB.

Here is the .babylon concerned. To reproduce, simply open it in the sandbox and re-export it in GLB.

In the solution to include the textures in the .babylon, I have an error message that I don’t quite understand.

Can you help me ?

THANKS

700MB in glb… dang.

How big are your textures?
and how many are there?

So, the babylon file’s 10MB is probably without textures since they errored out…?

Storing textures in a .babylon file (json) is done as a base64 string, which should result in a larger total size than the GLB. AFAIK.
It purely exists for convenience, and is not suited for a production environment, unless using very small models/textures where the loading difference would only be a few ms.

I don’t think it comes from the textures, because the test carried out with the .babylon provided allows us to account for the problem without even adding a texture.
Just, by loading the .babylon into the sandbox (without textures, 10MB) and exporting it to GLB without any modification, the output file reaches 700MB.

1 Like

Ok now i understood. I thought we were still talking about textures :smile:

@Evgeni_Popov not sure what’s happening there.

1 Like

cc @bghgary

By unpacking the .glb file, we can see that the .bin file is 700Mb:

I seem to remember that we recently had a problem with a small source file being exported to a very large file, but I don’t remember the details or the cause of this behavior (and even if it was in the context of a .glb export)…

I haven’t verified this, but most likely what is happening is that there are vertex buffers being shared. The glTF exporter probably will duplicate the shared buffers and cause an explosion in size.

Lol, so it’s not what I said at all. The reason why the export is so big is because there are a bunch of animations in the scene that are animating the rotation via rotation.x which causes the glTF exporter to bake the animation because glTF can’t animate x by itself. This animation is repeated many times in the scene:

            "animations": [
                {
                    "name": "xRotation",
                    "property": "rotation.x",
                    "framePerSecond": 800,
                    "dataType": 0,
                    "loopBehavior": 1,
                    "blendingSpeed": 0.01,
                    "keys": [
                        {
                            "frame": 0,
                            "values": [
                                0
                            ]
                        },
                        {
                            "frame": 9600,
                            "values": [
                                1.5707963267948966
                            ]
                        },
                        {
                            "frame": 15360.000000000002,
                            "values": [
                                1.5707963267948966
                            ]
                        },
                        {
                            "frame": 28800,
                            "values": [
                                0
                            ]
                        },
                        {
                            "frame": 34560,
                            "values": [
                                0
                            ]
                        }
                    ],
                    "ranges": []
                }
            ],

If I delete these animations manually with some code in the browser console:

BABYLON.Engine.LastCreatedScene.meshes.forEach(mesh => mesh.animations.length = 0)

Then, it exports into a 2.24MB file.

I don’t know how this scene is created, but it has a bunch of weird things going on.

4 Likes