HTML element as Texture source seems to bug

Hello, BJS Community!

I just discovered that you can use an HTML image element as a source for a texture which is perfect for my use-case.

But I noticed that if you use that feature with two different elements, it will always show the result of the first HTML element used no matter how texture you create as you can see in this playground: https://www.babylonjs-playground.com/#FT8Z42#1

Cheers, Pichou

When passing an HTML image to the Texture constructor, the url (first parameter) is used to “tag” the texture cache. If you pass the same value in both cases, the first texture will be reused in the second case because it will be found in the cache. You simply have to use a different url when creating the textures:

Note that pointing to https://encrypted-tbn0.gstatic.com/... triggers a CORS error, so I tested with two images coming from the Playground textures directory.

[…] Using Tools.SetCorsBehavior makes it work with your url:

3 Likes

Thanks @Evgeni_Popov,

I didn’t know the first parameter was used for that.
Plus I had my own management of CORS issues but great to know I can also handle it with BJS Tools. :muscle: :muscle: :muscle: