When Serialising a PBR Material - How to also serialize albedo texture without relying on a url

Hi Everyone,

I’m trying to serialise a PBR Material and save it as a file on my server. I’m using this function:
let serialised_material = BABYLON.SerializationHelper.Serialize<BABYLON.Material>(material);

The problem is my material has a texture that uses a url I believe of some image in the cache.
I want this image to be serialised aswell as a base64 string.

Thanks,
-Brian

Unfortunately you will have to do it manually.
Babylon.js does not serialize texture buffer content

I was able to get it serialzed by converting blob to base64 string.

            let buffer = (mat.albedoTexture as BABYLON.Texture)._buffer;
            if (buffer instanceof Blob) {
                image_string = await blob_to_base64_string(buffer);
                if (image_string) {
                    (mat.albedoTexture as BABYLON.Texture)._buffer = image_string;
                }
            }
1 Like