Jump to content

VEX compare attrib values to each other


Iraklo

Recommended Posts

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
Link to comment
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
Link to comment
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
Link to comment
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 6
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...