Iraklo Posted August 20, 2017 Share Posted August 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted August 20, 2017 Share Posted August 20, 2017 Use an attribpromote from points, verts or prims to detail and set the promotion method to min or max. 1 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted August 20, 2017 Share Posted August 20, 2017 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 Quote Link to comment Share on other sites More sharing options...
f1480187 Posted August 20, 2017 Share Posted August 20, 2017 @konstantin magnus, try function-style cast: vector(vertex(0, "uv", 0)) 3 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted August 20, 2017 Share Posted August 20, 2017 @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 Quote Link to comment Share on other sites More sharing options...
Iraklo Posted August 20, 2017 Author Share Posted August 20, 2017 @konstantin magnus @f1480187 Thanks for help guys Quote Link to comment Share on other sites More sharing options...
ikoon Posted August 21, 2017 Share Posted August 21, 2017 (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 August 21, 2017 by ikoon grammar check 1 Quote Link to comment Share on other sites More sharing options...
petz Posted August 21, 2017 Share Posted August 21, 2017 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 Quote Link to comment Share on other sites More sharing options...
Iraklo Posted August 21, 2017 Author Share Posted August 21, 2017 @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. Quote Link to comment Share on other sites More sharing options...
f1480187 Posted August 21, 2017 Share Posted August 21, 2017 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 Quote Link to comment Share on other sites More sharing options...
petz Posted August 21, 2017 Share Posted August 21, 2017 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 6 Quote Link to comment Share on other sites More sharing options...
Iraklo Posted August 22, 2017 Author Share Posted August 22, 2017 @petz @f1480187 Thanks again guys. Much appreciated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.