Pages

Monday, 19 January 2015

Get Primitive's Points with VEX

Note:
Code below was developed for Houdini 13
Since Houdini 14 the primpoints(int input, int @primnum); function returns an array of points per primitive. Obviously a much better solution


Attribute Wrangle in Detail Attribute mode

The following VEX code returns the points associated with the given primitive. In this case the primitive is chosen based on the proximity to the current point, using the xyzdist() function, where the first argument is the geometry containing the primitives to test against the current point, argument defined as "1" gives access to the second input of the attribute wrangle node.

i@prim;
v@uv;
float dist = xyzdist(1, @P, @prim, @uv);
//Above gets the prim(n) and prim(uv) for a given point position
//Also the distance between the given point and the prim returned
//Although all we really need is the primitive number

//--

//Create array to store the primitive's point numbers
int primpoints[];
v@primpoints;//This vector is used to store the 3 points instead of using an array, due to a limit with array attributes. 

NOTE:
Basically if you want to access the array in another wrangle further down the chain, you need to use a data type other than an array instead, a vector or matrix can be used to store array like data structures.

//Get the number of vertex for a given prim
int nvtx = primvertexcount(1, @prim); 

//Loop over the vertercies to find their associated points
for (int i = 0; i < nvtx; i++){

    //Get the linear vertex numbers for the prim(n)
    int linearvertex = vertexindex(1, @prim, i);

    //Get the point number from the linear vertex number
    int vertexpoint = vertexpoint(1, linearvertex); 

    //Put point numbers into the points array
    primpoints[i] = vertexpoint;
    @primpoints[i] = vertexpoint;
}

//Display primitive's point numbers
//printf("%g \n", points);

No comments:

Post a Comment