Parametric UVs

   1416   1   2
User Avatar
Member
130 posts
Joined: June 2016
Offline
Hi Guys,
I wanted to map the parametric uvs of each primitive to the actual vertex uvs. Is there any way to do this?
Currently I am running a loop over all primitives in detail mode and hard-code uv values on each vertices of each primitives.


i[]@prims = expandprimgroup(0,"");

foreach (int prim; @prims){
    i[]@vts = primvertices(0,prim);    
    addvertexattrib(0, "uv", {1,1});
    setvertexattrib(0, "uv",  @primnum, @vts[0], {0,0},"set");
    setvertexattrib(0, "uv",  @primnum, @vts[3], {1,0},"set");
    setvertexattrib(0, "uv",  @primnum, @vts[2], {1,1},"set");
    setvertexattrib(0, "uv",  @primnum, @vts[1], {0,1},"set");
}

But I want a simple approach to do the same,I expect something like @uv = @parametricuv;
Please let me know if you have any tricks.



Also there is another problem , i tried to run the code in primitive mode but strangely it doesnt work attached an image of that
i[]@vts = primvertices(0,@primnum);

setvertexattrib(0, "uv", @primnum, @vts[0], {0,0},"set");
setvertexattrib(0, "uv", @primnum, @vts[3], {1,0},"set");
setvertexattrib(0, "uv", @primnum, @vts[2], {1,1},"set");
setvertexattrib(0, "uv", @primnum, @vts[1], {0,1},"set");




Thanks.
Edited by Mohanpugaz - Dec. 18, 2018 08:02:41

Attachments:
primwrangle.png (2.8 KB)
parametricuvs.png (19.7 KB)

Mohan Pugaz
movfx
https://www.instagram.com/movfx/ [www.instagram.com]
https://www.youtube.com/channel/@_movfx
User Avatar
Member
7770 posts
Joined: Sept. 2011
Offline
Something like this might work better for more cases, and not require a detail level loop:

vector tri[] = {{1,0,0}, {1,1,0}, {0,1,0}};
vector quad[] = {{0,0,0}, {0,1,0}, {1,1,0}, {1,0,0}};
// The actual parametric coords for a quad in mantra are quad[] = {{0,0,0}, {1,0,0}, {1,1,0}, {0,1,0}};
// but the above faces out correctly.

int vt = vertexprimindex(0, @vtxnum);
int vtnum = primvertexcount(0, @primnum);
if (vtnum==3)
    @uv = tri[vt];
else if (vtnum==4)
    @uv = quad[vt];
else {
    float th = (float)vt/(float)(vtnum) * M_TWO_PI;
    @uv = set(-cos(th), sin(th), 0);
    @uv = @uv*0.5 + 0.5;
}

It's not possible to create the parametric uv's of tris or ngons, since a tri ends up with 4 vertices for the st map, and an ngon turns into a triangle fan, with a vertex at the center.

For those cases, I have some arbitrary maps. The ngon case is a planar projection, and the tri is half a quad.
Edited by jsmack - Dec. 18, 2018 13:04:13
  • Quick Links