VEX Wrangle

   4869   10   1
User Avatar
Member
53 posts
Joined: June 2009
Offline
Hi !

I am trying to replace primitives by their centroid point within an attribute wrangle node, inheriting all their attributes.

So I read the detail intrinsic “primitiveattributes” and loop over this array

I can create the points, with attributes, but I can't get the attribute types and dimension right
For instance Cd gets created, but is only one dimension instead of three

Any idea how to achieve this ?

Thanks
B

Here is my code:

// add point at primitive center
int ptnum = addpoint(geoself(), @P);

// get primitive attributes list
string primattribs[] = detailintrinsic(geoself(), "primitiveattributes");

// for each attribute get type, name and value and create point attribute
foreach(string attribname; primattribs)
{
string typeinfo = attribtypeinfo(geoself(), "prim", attribname);
int attribsize = attribsize("defgeo.bgeo", "prim", attribname);
float attribvalue = prim(geoself(), attribname, @primnum);

addattrib(geoself(), "point", attribname, 0.0);
setattribtypeinfo(geoself(), "point", attribname, typeinfo);
setattrib(geoself(), "point", attribname, ptnum, @primnum, attribvalue, "set");
}

// remove primitive
removeprim(0, @primnum, 1);
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Hi
It looks to me like “attribvalue” is declared as a float. So when you “setattrib” at the bottom of the foreach loop they are all set to float.

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
1737 posts
Joined: May 2006
Online
If the goal is the end result rather than learning vex, you can do this with some abuse of the assemble sop and attrib promote:

Attachments:
prims_to_centroid_points_with_attribs.hipnc (238.0 KB)

http://www.tokeru.com/cgwiki [www.tokeru.com]
https://www.patreon.com/mattestela [www.patreon.com]
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
also try this combination:

- facet SOP, turn on the unique points flag (split points per primitive)
- attribPromote SOP to promote all your prim attributes to point
- primitive SOP to scale all primitives to the centroid (turn on “do transform” and scale to something like 0.001)
- fuse SOP to fuse all the prim points to a single point in the centroid


I do this quite a bit
-G
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Hi
Figured it out. When you're adding a new attribute you're setting it's default value to a float by setting it's default value to “0.0”:
addattrib(geoself(), "point", attribname, 0.0);
So when you get to a vector attribute in you're "primattribs" array, you're casting a vector to a float.

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
53 posts
Joined: June 2009
Offline
Hi, thanks for your help

GrayOlorin, yes your setup works great, but i was looking for vex learning as Mestela guessed

Bonsak,
Yes it is declared as float in this variation
I thought the setattribtypeinfo() would change the type after creation, but no it does not

I tried various other things:

- using typeinfo:
addattrib(geoself(), "point", attribname, typeinfo);
but it initialize it as a string since typeinfo is a string

- using the result of prim as default value:
addattrib(geoself(), "point", attribname, prim(geoself(), attribname, @primnum));
but vex can't do that either since it does not know which signature of prim() to use

- I tried variations with addpointattrib(), setpointattrib()
addattribute() is in the doc but not recognized (BTW I am using Indie 15.0.306)

No luck so far
Any insight would be much appreciated

thanks!
Bruno
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Hi
I deleted my previous post because the solution didn't work and i couldn't edit my post
Check out this [forums.odforce.net] link for a similar problem.

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
53 posts
Joined: June 2009
Offline
Bonsak,

Thanks for the link, perfect
I was hoping I could avoid those if statements, but I will go with that!

Any idea if it is possible at all to delete the primitive attributes after I delete the primitive ?
I could not find any attribdelete() function
I can use a SOP, but would like to pack up everything in one wrangle node, if possible at all

B
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
All your primitive attributes are deleted when you delete the primitives right?
Don't know if there is a way to remove attributes on geo in VEX. Maybe there is a way to modify the detail intrinsic pointattributes array or something. I don't know.

-b
Edited by bonsak - July 29, 2016 08:55:45
http://www.racecar.no [www.racecar.no]
User Avatar
Member
53 posts
Joined: June 2009
Offline
Actually no, the attributes are still available
I attached the snapshot
As I said, no big deal, just CBB

I also attached the scene, if anyone needs the code
thanks!
Edited by bebe - Feb. 21, 2017 15:24:03

Attachments:
wrangle.png (72.3 KB)
wrangles.hipnc (326.1 KB)

User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
You're right. My bad. The definitions are there but there are no values.

-b
http://www.racecar.no [www.racecar.no]
  • Quick Links