Jump to content
statuskwoh

[beginner] Unique prims based on point names

Recommended Posts

Note: fairly new to houdini and vex, so if this is super obvious I apologize. google-fu has been failing me. Also, I haven't scripted/coded for awhile, so I may also be making obvious mistakes there.

I am trying to setup a primitive wrangle that goes over geo I'm setting up for a constraint network. I'm trying to make sure I only have 1 constraint per any set of 2 objects. The object names are on the point as name attributes.

I'm able to go through, grab the point names just fine. My intention was to add the point names together to create two strings pointAname+pointBname and pointBname+pointAname. See if either of those combinations existed in an array. If no, add them to the array, if yes delete theprimitive.

What I have so far is:

int points[] = primpoints(0,@primnum);
int successVar;
string curValues[];
string names = pointattrib(0,"name", points[0], successVar)+pointattrib(0,"name", points[1], successVar);
string rnames = pointattrib(0,"name", points[1], successVar)+pointattrib(0,"name", points[0], successVar); 
int moveOn = 0;

foreach(string checkName; curValues){    
    if (moveOn == 1) break;
    if (checkName == names || checkName == rnames) {
        removeprim(0,@primnum,1);
        moveOn = 1;
        }
    }

if (moveOn == 1){ 
    append(curValues, names);
    append(curValues, rnames);
    moveOn = 0;
    }
else moveOn = 0;

However, it doesn't seem like the array persists as it runs over the primitives. I tried using an attribute on another created piece of geo to store it, but it looks like VEX doesn't set attributes until the full wrangle is run.

Is there a way to have an array persist throughout a wrangle? Should I be approaching this another way? Am I making a dumb mistake?

Share this post


Link to post
Share on other sites

Not exactly...

I'm trying to take a collection of lines and remove them if their two point names are the same as another line's two point names. So in your example if there were 3 lines that were p1_p3, I'd want to run a wrangle that makes it so I only have 1.

Share this post


Link to post
Share on other sites

Oh, now I see what you mean. You don't have overlaps at all and just want to leave single constraint between pieces. You need to sort names in wrangle to avoid two possible variants of same constraint name. Then use for-each per name and blast everything except single prim. I would prefer to set point position to it's corresponding piece center. In this case you will get many overlaps and can use Fuse and PolyDoctor technique. Constraints will be placed better.

constraint_from_scatter.hipnc

Edited by f1480187

Share this post


Link to post
Share on other sites

Awesome, the sort and for-each-name blast is perfect for what I was looking for.

Out of curiousity, the fuse-polydoctor technique looks like it ends up with a similar result from a connect-adjacent-pieces using adjacent points from surface applied to the original geometry merge. Is there and advantage to the fuse/polydoctor technique? or just different ways to get to the same spot.

Share this post


Link to post
Share on other sites

You may input for-each result into Attribute Copy and delete fuse-doctor stuff. Same ways of getting similar result.

 

CAP will give you even better result, if you know how to distinguish inner and outer constraints. Using inside surface may help, I like to manage cluster attribute, since it is useful anyway.

conadj_constraints.png

 

conadj_constraints.hipnc

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

×