Preserving aspect ratio on a image texture that is tiled using multimaterials and submeshes

Hi!
I am trying out multi-materials and submeshes for the first time to accomplish applying multiple textures onto a mesh.

My mesh is a large diameter tube and I would like to tile a series of images on the inside of the tube.
This succeeds however my difficulty is in preserving the aspect ratio of the images.

How would I calculate my submeshes (I suppose this would be the indices parameters?) to ensure that the images fit inside the tube with the right aspect ratio? (There may be additional parameters on the texture itself?) I do know the pixel dimensions of my images.

Thanks!

Hello perhaps you could share a playground of your current state? This would be easier for us to hack with you on it :wink:

Sure - here is a simplified version of what i was working on:

https://www.babylonjs-playground.com/#KKFPYU

I’m curious to know if there is a parameter that can preserve original image aspect ratio’s? If so I thought it could be one way to neatly arrange images within a given mesh structure.

The example also includes an attempt to interact with the submesh but it looks like this is not possible (similar interaction code worked fine for the parent tube mesh).

Thanks!

Ok gotcha. So you will have to create your own UV (texture coordinates) to map the textures where you want them.

Here is a first doc on how to update vertex data: Update Vertices - Babylon.js Documentation
And here is one to get the concept of UV and how to use it to map textures to faces: Apply Material to Individual Faces - Babylon.js Documentation

1 Like