Jump to content
Iraklo

VEX compare attrib values to each other

Recommended Posts

Hi guys,

 

how do I compare to each other and get max and min values of attribute for different elements.

 

Basically I want to compare these guys and get min and max.

attribs.JPG

Share this post


Link to post
Share on other sites

As you requested a VEX solution, I would put something like this into a detail wrangle:

int all = nvertices(0);
@min = vertex(0, "uv", 0);
@max = vertex(0, "uv", 0);

for(int i = 0; i < all; i++){
    float compare = vertex(0, "uv", i);
    if(compare < @min) @min = compare;
    if(compare > @max) @max = compare;
}

Unfortunately I would not know how to access a single vector component in this manner:

@min = vertex(0, "uv.y", 0); // these lines
@max = vertex(0, "uv", 0).y; // do not work

Maybe someone can help me out here?

  • Like 2

Share this post


Link to post
Share on other sites

@f1480187, ah thank you! So I guess, its:

int all = nvertices(0);
@min = vector(vertex(0, "uv", 0)).y;
@max = vector(vertex(0, "uv", 0)).y;

for(int i = 0; i < all; i++){
    float compare = vector(vertex(0, "uv", i)).y;
    if(compare < @min) @min = compare;
    if(compare > @max) @max = compare;
}

 

  • Like 1

Share this post


Link to post
Share on other sites

I am used to access vector component like this, I hope it is a good solution as well:

    vector compare = vertex(0, "uv", i);
    if(compare[2] < @min) @min = compare[2];

Edited by ikoon
grammar check
  • Like 1

Share this post


Link to post
Share on other sites

you could put the following two lines in a vertex wrangle:

setdetailattrib(geoself(), "min_val", @uv.y, "min");
setdetailattrib(geoself(), "max_val", @uv.y, "max");

 

  • Like 4

Share this post


Link to post
Share on other sites

@ikoon @petz

Thanks for reply guys. :)

One quick question here: how is it possible to create array from numbers I marked in the first post's screen? Right now it's irrelevant, but in future it would help me.

Share this post


Link to post
Share on other sites

You can do it in Detail Wrangle:

for (int i = 0; i < @numvtx; i++)
{
    vector uv = vertex(0, "uv", i);
    append(f[]@uvx, uv.x);
}

Or in Vertex Wrangle (very slow):

float uvx[] = array(@uv.x);
setdetailattrib(0, "uvx", uvx, "append");

 

  • Like 1

Share this post


Link to post
Share on other sites

depending on the number of vertices, the easiest method is most probably using setdetailattrib() like in f1's second example. however, for very dense meshes and if performance is important it's better to iterate over the vertices and resize the array in advance instead of appending in a loop. this way you avoid continuous bounds checking of the array.

int num = detailintrinsic(@OpInput1, "primitivecount");
f[]@val_array;
resize(@val_array, num);
for(int i = 0; i < num; i++)
    @val_array[i] = vector(vertex(@OpInput1, "uv", i)).y;

hth.

petz

  • Like 5

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×