How to calculate uvs for roof procedurally generated?

Hi, after a few attempts I decided to seek help here.
I have a roof generated procedurally and I’m using to its coordinates (u, v) the same coordinates of the vertices (x, z), but the result is not as expected and similar to reality.

Can anyone help with any tips on how to calculate the coordinates (u, v)?

Note: Vertices not shared. Have also tried to use this script: link text

Sorry for my english.

Thanks!

Try something like this for each vertex…

// This gives a vector pointing up the roof:
Vector3 vAxis = Vector3.Scale(normal, new Vector3(-1, 0, -1)).normalized;

// This will make the u axis perpendicular to the v axis (ie. parallel to the roof edge)
Vector3 uAxis = new Vector3(vAxis.z, 0, -vAxis.x);

// I originally used vAxis here, but changed to position.y so you get more predticable alignment at edges.
// Set eaveHeight to the y coordinate of the bottom edge of the roof.
Vector2 uv = new Vector2(Vector3.Dot(position, uAxis), position.y - eaveHeight);

// You may need to scale the uv vector's x and y to get the aspect ratio you want.
// The scale factor will vary with the roof's slope.

Note that this won’t behave well where the vertices on a triangle have different normals, like around a curved turret, or level portions where the normal points straight up.

Edges between different slopes may act up, so it may look good to add an extra bit of geometry to cap them:
alt text

Hey, i know it is offtopic but, I am very curoius what algorithm do you use for generating roof mesh because I am currently working on that too. Thanks :slight_smile:

Hello Daviz, I use Straight Skeleton Algorithm to make the roof Skeleton, and after I use triangulation to make the Mesh.

easier to use this calculator Roof Pitch Calculator - Myrooff.com