Texture of a polygon

Hello, everyone.The thing is, I have a picture of an exhibition of paintings.Now I have this picture on a plane in Babylon, but I would like to replace one of the paintings with a new texture.You know, because of perspective, the pictures are not rectangular, but something like a trapezoid.So I’m going to create a polygon of the same shape use “CreatePolygon”, and then use the new texture.But I found that if I use “diffuseTexture”, only a part of the texture in the polygon. How can it show all, even if stretched or distorted.
Or do you have some other methods to replace the painting without make a Polygon.

Could you create a repro in the playground ? I suspect the uvs to not fit with your use case

https://www.babylonjs-playground.com/#9RUHH#36
Thank you.

In the case of earcut I do not think you can specify all the uvs manually it basically means that either you need to construct the shape by code or rely on some exported object with chosen UVs from 3ds max, blender or maya.

As a workaround you could try to modify the uvs after their creation in Earcut but it might be a bit tricky.

As I understand it you want to create a 2D image of the gallery to display in the 3D world of Babylon.js and to be able to change the image within a particular picture on the wall. You could of course display the gallery in 3D and perspectives would be calculated for you.

You could construct a custom trapezium mesh as in this PG https://www.babylonjs-playground.com/#9RUHH#39

As an alternative you could produce a 3D image of a picture in BJS and use a screenshot to capture the image like this image

using https://www.babylonjs-playground.com/#9RUHH#38

Using dynamicTexture you could draw your gallery and replace parts of the image on its canvas.

3 Likes

And why not simply use a Perspective tool from a 2D software (photopea.com for example)? This will give you directly a texture ready to be mapped on a classic plane:

1 Like

We are working on a scenario that allows users to replace the images they want, and it’s automated.

Thank you very much. In fact, I want to use this method for 360 panoramic video. I want to replace one thing in 360 panoramic video (such as a picture in a museum) with a texture automatically.