How to reference result of addpoint() function ?

   1133   3   0
User Avatar
Member
7 posts
Joined: 6月 2015
Offline
Suppose, I have an attribute wrangler running over primitives ...
// create new point at primitive center
vector center = primuv(0, "P", @elemnum, {0.5, 0.5, 0});
int pt = addpoint(0, center);
// reference new point from primitive
setprimattrib(0, "prim_center", @elemnum, pt);
But, point number returned by addpoint() function isn't final number. After operation, all primitives have the same
value for prim_center attribute which is @numpt of the input. How to fix this behaviour ?
User Avatar
Member
2544 posts
Joined: 6月 2008
Offline
I consider that a VEX language error, but it's so well known that VEX just works that way.
When you enter a primitive or point wrangle, a snapshot of the geometry is presented for your code to work on. Once the wrangle is executed, the snapshot is updated by applying the actions your code generated.

The default sphere contains 266 points. This means the addpoint() function will always return the next point number of the snapshot total point count of 266. This is why the documentation [www.sidefx.com] mentions the return value for addpoint() is essentially useless. You can use the result to check for an error.

Because you are running in the primitive context, however, you don't need to call the setprimattrib() function at all, you can assign primitive attributes directly.
// create new point at primitive center
vector center = primuv(0, "P", @primnum, {0.5, 0.5, 0});
int pt = addpoint(0, center);
// reference new point from primitive
//setprimattrib(0, "prim_center", @primnum, pt);
v@prim_center =center;
i@center_point_number = pt; //Check spreadsheet, always the same number.
Edited by Enivob - 2022年4月23日 14:01:43
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
7 posts
Joined: 6月 2015
Offline
Thank you for this clarification. I've solved this problem by using point @id's instead of point numbers. Also it's possible to pregenerate points in another wrangle, and then set their positions.
User Avatar
Member
4528 posts
Joined: 2月 2012
Offline
For this kind of geometry creation, I would recommend pre-generating points using Point Generate SOP for max performance.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
  • Quick Links