How to manage the unwrap direction based on geometry position in 3d space?

   1915   5   1
User Avatar
Member
43 posts
Joined: Dec. 2017
Offline
Hi guys
i have a very simple geo which is need to unwrap. I'd love all the faces to have the same orientation towards the vertical direction (as you can see, that's a roof, it's very useful for roof tiles!). obj in attached for those who want to try

Image Not Found



All i need is something like this, but done procedurally




How would you do that?

Attachments:
roof geo.obj (3.2 KB)
roof.JPG (92.8 KB)
roof unwrap.JPG (43.8 KB)

User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
You can orient the polygons by the direction from vertex 0 to vertex 1.

Attachments:
roof_uv_winding.jpg (26.3 KB)
roof_uv_raised.jpg (32.0 KB)
roof_uv.hipnc (184.5 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
In case of randomly shifted vertex orders or if you want to keep it more generic you could also build rotation matrices based on the primitive normals:

vector nml = prim_normal(0, @primnum, vector(0.0));
vector up = set(0, 1, 0);
vector x = cross(nml, up);
vector z = cross(nml, x);

3@r = set(x, nml, z);

Which gives a visually similar result:

Attachments:
roof_uv2.hipnc (185.9 KB)
roof_uv_prim_normals.jpg (31.6 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
43 posts
Joined: Dec. 2017
Offline
Hi Konstantin
that looks awesome, does exactly what i need. I'm going to have a better look at it, as i'm not into matrices as i should.

Thanks heaps
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
just stopping by to say thanks for sharing this nice technique
cheers
User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
I made another variant that keeps the surface geometry intact at all times (no faceting and fusing needed), and also makes the tiles match.
Edited by Konstantin Magnus - June 2, 2019 11:39:37

Attachments:
UV_roof_tiles.jpg (33.3 KB)
roof_uv3.hipnc (185.5 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
  • Quick Links