# 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.

##### Share on other sites

Use an attribpromote from points, verts or prims to detail and set the promotion method to min or max.

• 1

##### 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?

• 2

##### Share on other sites
f1480187    454

@konstantin magnus, try function-style cast:

`vector(vertex(0, "uv", 0))`

• 3

##### 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;
}```

• 1

##### Share on other sites

Thanks for help guys

##### Share on other sites
ikoon    102
Posted (edited)

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
• 1

##### Share on other sites
petz    306

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");```

• 4

##### Share on other sites

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 on other sites
f1480187    454

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");```

• 1

##### Share on other sites
petz    306

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

• 4

##### Share on other sites

Thanks again guys. Much appreciated.

## 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