this is called UV’s
Mesh.getVerticesData(BABYLON.VertexBuffer.UVKind)
I was actually theorising how to implement a simple solution for this yesterday,
like meshA.setUvs(0,0,1,1) to display entire texture,
meshB.setUvs(0, 0, 0.5, 0.5) to display a 1/4 size square of the texture (bottom left).
But it’s slightly more complicated than that behind the scenes, i’ll pick up where i left it and see if i can make it work
Update;
First attempt, works only for ground meshes, (mesh.CreateGround)
But works exactly how i imagine it should, you set x,y,z,w aka (u, v, u2, v2) and they are updated.
This was quite simple to do as we have the information needed, easily available, (subdivisions)
https://playground.babylonjs.com/#QFRJ7K#1 (inspired by VertexData.CreateGround)
Second attempt
Big Issue: Expanding the function to be used on any type of mesh, including custom meshes.
Solution: Hope and assume the meshes are created with 0,0,1,1 (full texture) uvs.
Then edit existing uv’s instead of creating new, now works for any type of mesh.
https://playground.babylonjs.com/#QFRJ7K#4 (inspired by custom mesh docs & SPS particle uv’s)
Protential issue:
If a custom mesh is made without full texture uvs, to avoid issues, manually setting
mesh.__uvsCache = new BABYLON.Vector4( u, v, u2, v2);
with the used uvs (at creation) is required before calling mesh.setUvs().
Any smart people out there who might have an idea how to avoid using a “uvsCache” please do give it a go, it annoys me greatly