# Tiled texture -

**URL:** https://forum.babylonjs.com/t/tiled-texture/2285
**Category:** Questions
**Created:** [April 2, 2019, 5:37am UTC](https://forum.babylonjs.com/t/tiled-texture/2285 "2019-04-02T05:37:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Subrahmanya\_Chakrava](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/subrahmanya_chakrava/32/3313_2.png) [@Subrahmanya\_Chakrava](https://forum.babylonjs.com/u/Subrahmanya_Chakrava)
#### Post date: [April 2, 2019, 5:37am UTC](https://forum.babylonjs.com/t/tiled-texture/2285/1 "2019-04-02T05:37:02Z")

</div>

Hi,  
I am referring to the problem described by @ceejay at [Changing the uScale and&nbsp;vScale of the texture on an object-by-object basis - Questions & Answers - HTML5 Game Devs Forum](http://www.html5gamedevs.com/topic/23576-changing-the-uscale-and%C2%A0vscale-of-the-texture-on-an-object-by-object-basis/)

This is a old post. I would like to know if a solution is built in BabylonJS Api or we need to implement our own solution?

Hi @Wingnut,  
In that post, you said…

“Perhaps﻿… mesh.materialWrapPerMeshScale﻿ = true/false ? Or﻿ maybe mesh.allowMaterialScaling = false ? (neith﻿er ﻿exist, ye﻿﻿﻿t)”.

Do they exist now?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)
#### Post date: [April 2, 2019, 8:21am UTC](https://forum.babylonjs.com/t/tiled-texture/2285/2 "2019-04-02T08:21:41Z")

</div>

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](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](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 😄

---

<div class="post-metadata">

### Author: ![Subrahmanya\_Chakrava](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/subrahmanya_chakrava/32/3313_2.png) [@Subrahmanya\_Chakrava](https://forum.babylonjs.com/u/Subrahmanya_Chakrava)
#### Post date: [April 2, 2019, 7:52pm UTC](https://forum.babylonjs.com/t/tiled-texture/2285/3 "2019-04-02T19:52:10Z")

</div>

Great. But my new question is, how do I compute the values to be passed to the setUVS function?

---

<div class="post-metadata">

### Author: ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)
#### Post date: [April 2, 2019, 8:19pm UTC](https://forum.babylonjs.com/t/tiled-texture/2285/4 "2019-04-02T20:19:00Z")

</div>

You would have to look at your texture,  
the range is generally 0 to 1,  
u = Horizontal starting point, 0 = Left, 0.5 = Center, 1 = Right, etc  
v = Vertical starting point, 0 = Bottom, 0.5 = Center, 1 = Top…  
u2 = Horizontal ending point,  
v2 = Vertical ending point.

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/3/398d5a6bd6454e3eb77995201ec46e4e79268adc.png)  
say you have a texture with 4 tiles, and you want the top left tile, e.g. orange on picture.  
u = 0; // start at 0 on horizontal axis  
v = 0.5; // start at center on vertical axis  
u2 = 0.5; // end at center on horizontal  
v2 = 1; // end at top on vertical  
setUvs( u, v, u2, v2 )

---

<div class="post-metadata">

### Author: ![Richard](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@Richard](https://forum.babylonjs.com/u/Richard)
#### Post date: [September 8, 2020, 7:56am UTC](https://forum.babylonjs.com/t/tiled-texture/2285/5 "2020-09-08T07:56:07Z")

</div>

I found this thread and the playground very helpful. Thank you! Am surprised something like this setUVs function hasn’t been added as a native Mesh method.

---

<div class="post-metadata">

### Author: ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)
#### Post date: [September 8, 2020, 2:40pm UTC](https://forum.babylonjs.com/t/tiled-texture/2285/6 "2020-09-08T14:40:39Z")

</div>

Short answer,  
it’s incomplete and uvs are complex when you have to support any imagineable scenario 😄

---

<div class="post-metadata">

### Author: ![Richard](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@Richard](https://forum.babylonjs.com/u/Richard)
#### Post date: [September 8, 2020, 2:43pm UTC](https://forum.babylonjs.com/t/tiled-texture/2285/7 "2020-09-08T14:43:15Z")

</div>

Aye I can only imagine. Thinking about it too much would turn my hair grey. 😀
