So, I’ve procedurally generated a mesh.
This is just a plane polygon made up on n faces.
I understand how to uv map a texture onto this shape, but I would like be able repeat the texture rather than stretch the texture.
How do I do this?
So, I’ve procedurally generated a mesh.
This is just a plane polygon made up on n faces.
I understand how to uv map a texture onto this shape, but I would like be able repeat the texture rather than stretch the texture.
How do I do this?
To do this, you’d take the polygon, and use modulo on it. Lets say you have a grid of polygons and you want the texture to repeat on them. You’d run through all the vertices, and assign the modulo of it’s position to it’s uv.
Pseudo code:
for(vertex in vertices) {
vertex.uv.x = vertex.position.x % texture.width;
vertex.uv.y = vertex.position.y % texture.height;
}
Pseudo code in action:
+-----+-----+-----+
| 0,2 | 1,2 | 2,2 |
+-----+-----+-----+
| 0,1 | 1,1 | 2,1 |
+-----+-----+-----+
| 0,0 | 1,0 | 2,0 |
+-----+-----+-----+
Lets say this is a grid of vertices. If we run them through the loop (with 2.0 as width and height), the result will be:
+-----+-----+-----+
| 0,0 | 1,0 | 0,0 |
+-----+-----+-----+
| 0,1 | 1,1 | 0,1 |
+-----+-----+-----+
| 0,0 | 1,0 | 0,0 |
+-----+-----+-----+
A tiled texture.
–David–
One way is the same as anything else – set the tiling in the Material to the number of repeats you want.
Or, when you create the UV coords, multiply them all by the number of tiles you want.
These seem like the same thing, because they are. They both give you DavidDeb’s picture#1. FYI, picture#2 tiles them forwards, backwards, forwards… . It’s a trick to make non-tiling textures tile (since the right side never touches the left side.)