UV coordinates on recursively subdivided grid

   2016   1   1
User Avatar
Member
29 posts
Joined: Oct. 2015
Offline
Hi, I'm trying to texture individual tiles from a subdivided grid and I can't quite figure out how to properly calculate the uv coordinates of each tile.

I'm doing the subdivision with a for loop nested inside foreach loop as in this entagma tutorial: https://vimeo.com/172335635 [vimeo.com]

I've somewhat aligned the images with a uv_texture sop, using this calculation in the scale field:

4 * (1 + detail( ‘../repeat_begin1_metadata1/’, iteration, 0)) * (1 + detail( ‘../foreach_begin1_metadata1/’, iteration, 0))

but I haven't figured out yet how to set the offsets. I suspect my issue is with world space vs object space coordinates, but not sure how to go about it.

Is the uv_texture the right tool for this?


Additional quesiton, I am currently applying uv_texture and material in two places - within the for loop, and outside of it for the very first iteration, which doesn't get textured by the nested for loop. Is there a way to avoid this duplication?
Edited by Lyubomir Popov - June 13, 2017 11:37:14

Attachments:
recursive-grid.zip (921.5 KB)
Screen Shot 2017-06-13 at 16.21.15.png (528.7 KB)

User Avatar
Member
29 posts
Joined: Oct. 2015
Offline
Update: I found a simple way to do it with a primitive wrangle, by just setting vertex uvs manually like so :

i@pts = primvertices(0, i@primnum);
for (int i = 0; i < len(@pts); ++i) {
@pt = @pts;
float u = i == 0 || i == 1 ? 0 : -1;
float v = i == 1 || i == 2 ? 1 : 0;

vector uv = set(v, u, 0);
int vattr = setvertexattrib(0, ‘uv’, @primnum, i, uv);
}

Would appreciate understanding why the uv_texture doesn't work though.
  • Quick Links