Drunkenpanda Posted May 19, 2021 Share Posted May 19, 2021 (edited) Hello, I'm having troubles getting around how vex works sometimes. I would like to do something like (Detail) vector avgN = 0; for (int i=0; i < nprimitives(0) ; i++) { avgN = avgN + prim(0, "N", i); } avgN = avgN / nprimitives(0); (plz ignore my name) Edited May 19, 2021 by Drunkenpanda Quote Link to comment Share on other sites More sharing options...
underscoreus Posted May 20, 2021 Share Posted May 20, 2021 Heyo, there are a few ways to solve this that I can think of at the top of my head. 1. Use the "avg" vex function. Just make an array of all the normal attribute values and then plug that array of vectors into the "avg" function and it will give you the average value of all the vectors in the array. 2. Use the "attribute promote" node. Just add the "attribute promote" node and set it to promote the "N" attribute from primitives to detail and set the promotion mode to "average" (this is the default) and boom, you should now have it all averaged out and as a detail attribute. Hope that can be helpful! Quote Link to comment Share on other sites More sharing options...
acey195 Posted May 21, 2021 Share Posted May 21, 2021 (edited) Your code does look ok, but it does rely on the N attribute to exist on primitives already (usually they are on points or vertices) so you could also do either vector avgN = 0; for (int i=0; i < npoints(0) ; i++) { avgN = avgN + vector(point(0, "N", i)); } avgN = avgN / npoints(0); or directly fetch the primitive normal with the native function for that: vector avgN = 0; for (int i=0; i < nprimitives(0) ; i++) { avgN = avgN + prim_normal(0, i, {0.5, 0.5, 0.5}); } avgN = avgN / nprimitives(0); but like underscoreus said, the easiest way is probably to use an attributepromote SOP (combined with a facet SOP to generate the N attribute for your points) Edited May 21, 2021 by acey195 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.