top of page

Code snippet: Create uv along curves

Ellie Ansell

Code dump! Some bits of code from groom work.


Varying fur direction based on tangentu (create a polyframe sop beforehand, or use gettanuv vex in H18.5) and using this to drive furdirection in a guideprocess:


float angle = chf("angle");
vector cross = cross(v@N, v@tangentv);
matrix rot = ident();
rotate(rot, angle, cross);
v@furdirection=v@N*rot;
v@Cd=v@furdirection;

Create UVs along curve:


int pts [] = primpoints(0, @primnum);
int npts = len(pts);
int vtx;
vector uv;

foreach(int pt; pts)
{
    vtx = vertexprimindex(0, pt);
    uv = set(float(vtx)/npts, 0.0, 1.0);
    setpointattrib(0, "uv", pt, uv, "set");
}

This isn't very efficient, I won't lie; but I'm obsessed with keeping things in wrangles. So here we are, set width and colour:

int prims = nprimitives(0);
int types = chi("type");
string group_parm = "hair_group";
string width_parm = "width";
float width;
string group;
vector uv, cd;

for(int i=0; i<types+1; i++)
{
    for(int prim=0; prim<prims; prim++)
    {
        group=chs(concat(group_parm, itoa(i)));
        if(inprimgroup(0, group, prim))
        {
            int pts [] = primpoints(0, prim);
            foreach(int pt; pts)
            {
                uv = point(0, "uv", pt);
                width = chramp(concat(width_parm, itoa(i)), uv.x);
                setpointattrib(0, "width", pt, width, "set");
                cd = width*set(hscript_rand(i), 
                            hscript_rand(i*.5), 
                            hscript_rand(i+.9));
                setpointattrib(0, "Cd", pt, cd, "set");
                
            }
        }
    }
}

19 views0 comments

Recent Posts

See All

Comments


  • LinkedIn // Professional Bio
  • Facebook // ellieansellart page
  • Instagram // Informal fun
  • Vimeo

© 2020 by Ellie Ansell

Happily created using Wix.com

bottom of page