Texture.updateURL should accept ImageBitmap

I think this is a pretty minor request as Texture’s _buffer field already can be an ImageBitmap.

Here’s a quick playground that shows that it should work

You’re right and it was an easy one!

2 Likes

Hi @Evgeni_Popov, I failed to create a texture from ImageBitmap, can you have a look at my PG? https://playground.babylonjs.com/#KBS9I5#36046

In the PG, I tried to create a texture from blob and it works well.

/// create texture from blob url
const blob = new Blob([buffer], {type: "image/jpeg"});
const blobUrl = URL.createObjectURL(blob);
roofMat.diffuseTexture = new BABYLON.Texture(blobUrl);

But I failed to create a texture with ImageBitmap as buffer

/// create texture from ImageBitmap
const blob = new Blob([buffer], {type: "image/jpeg"});
createImageBitmap(blob, {
    premultiplyAlpha: 'none',
    colorSpaceConversion: 'none',
}).then((bitmap) => {
    console.info("sx: bitmap created");
    roofMat.diffuseTexture = new BABYLON.Texture("", engine, true, true, undefined, () => {
        console.info("sx: load success");
    }, (msg) => {
        console.info("sx: load error");
    }, bitmap);
});

I wonder am I making any mistakes? Many thanks~

When passing a buffer, you must set the “url” parameter to the name to give to the texture:

3 Likes

Got it, thank youuuuuu