[SOLVED] Fixing UV scaling on random scaled meshes

Community Forums/General Help/[SOLVED] Fixing UV scaling on random scaled meshes

RustyKristi(Posted 2015) [#1]
Hey guys,

So I'm trying to sort out some random texture tiling and scaling problems with texture using LoadBrush. I'm trying to tile properly the texture using su and sv along with the mesh being scaled.

Here's a snippet on what I'm trying to do:

sizey = Rnd(1,4) ;random cube height
randwidth# = Rnd(.5,1) ;random cube width
su=sizey 
sv=randwidth

texture$ = "brick.jpg"
...
surface1 = CreateSurface(cube)
...
;Right Side
brush1 = LoadBrush(texture$,49,su,sv) ;load brush with su,sv scale 
PaintSurface surface1,brush1

ScaleMesh cube, randwidth , ys, randwidth


The result is always stretched out on taller generated cubes. I'm kinda confused on how to apply proper texture scaling on any size generated.


Matty(Posted 2015) [#2]
Try scaling inversed. Ie 0.25 etc.


RustyKristi(Posted 2015) [#3]
Thanks Matty. So how do I calculate that since this is randomize?


RemiD(Posted 2015) [#4]

The result is always stretched out on taller generated cubes. I'm kinda confused on how to apply proper texture scaling on any size generated.


If you want to avoid a texture to look stretched, you don't want to scale the texture, instead you want to generate a texture which has an appropriate pwidth pheight depending on the width, height, depth of the surface in the world, and this can be difficult because after you have generated the texture, you will need to unweld the surface correctly and then to uvmap each vertex correctly.
So it is easy to do that if you use square shapes (like the sides of a cube) but for random shapes it is not easy...


RustyKristi(Posted 2015) [#5]
Thanks RemiD. Right now I got these options for the LoadBrush u and v params.. (su,sv)

sizey = Rand(1,4)

If sizey = 1 su = 1 : sv = 1
If sizey = 2 su = .8 : sv = 1
If sizey = 3 su = .6 : sv = 1
If sizey = 4 su = 1 : sv = .8


I'm just starting to test Matty's solution and if you got any ideas/solutions I would love to hear them. :-)


RustyKristi(Posted 2015) [#6]
It looks like the texture applied is clamping instead of tiling. How do you force to tile a texture into a surface?


RemiD(Posted 2015) [#7]
I can give you a simple tip to caclulate the UV coords :
Knowing that a texture must always have a pwidth pheight which is either 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096. (the pwidth can be different from the pheight, and vice versa)
This does not simplify the task to have one texel = one specific size in the 3d world.
So, let's say that you want one texel corresponds to 0.1x0.1 units in the 3d world and the surface you want to texture has a size of 1.0x1.0 unit (a quad or a side of a cube).
In this case you will need a texture which is 10x10texels (1texel per 0.1unit), but you can't have that, you have to use a texture which is bigger than 10x10texels, like 16x16texels.
Now in order to calculate the UV coords of each vertex, it is easy :
v0X = -0.5 | v0Y = 0.5 | v0Z = 0
v0U = 0.0/16.0 | v0V = 0.0/16.0
v1X = 0.5 | v1Y = 0.5 | v1Z = 0
v1U = 10.0/16.0 | v1V = 0.0/16.0
v2X = -0.5 | v2Y = -0.5 | v2Z = 0
v2U = 0.0/16.0 | v2V = 10.0/16.0
v3X = 0.5 | v3Y = -0.5 | v3Z = 0
v3U = 10.0/16.0 | v3V = 10.0/16.0

Using this logic, it is also easy to uvmap a surface or parts of a surface which can be "flattened" on one view. So you will have to see how you can unweld (and consequently rebuild) your surface in separate parts (different parts must not use the same vertices on the edges), then you will be able to texelsfill and uvmap each part.

And of course if you can use premade parts, (already unwelded, texelsfilled, uvmaped) that's easier...


RustyKristi(Posted 2015) [#8]
Thanks for that tip! I got a question and I think I must have set the UV clamping to prevent tiling (1=Color, 16=Clamp U, 32=Clamp V) = 49 which was my flags before but now having just color does not seem to have any effect with the clamping..

I'm doing this now..

LoadBrush(textureside$,1,su,sv)

Any ideas?


RustyKristi(Posted 2015) [#9]
My mistake and this is now solved! thanks Matty and RemiD, I did get some idea with your surface mapping and finally I created a good tiling! :D

cheers.