Jump to content

Sticky Attribute Or Stiky Group


Recommended Posts


I'm working with Vex and I'm trying to get an atribute to hold a value based off a dynamic condition.

I'm calculating the distance between 2 points. If the distance is less than 1, I want to either add an attribute (with a val of 1) or create a point group called "KurtisBlow". The catch is, once the point is inside the group (or the atrribute has a value of 1), I don't want them to be removed from the group (or attribute value changed) if the distance happens to change. I want to keep history that these points were once within a distance of 1. I hope I'm clear explaining what i'm trying to achieve.

In other languages I would create an accumilating arrary or list of the point numbers and then perform an operation on that list.

Any ideas would be most welcome.


Here's what I have so far but of course it's not working......

#pragma opmininputs	 2
#pragma opmaxinputs	 2
	vecotor oP;
	float dist;

	// Import P from OPinput2
	import("P", oP, 1, 0);

	// Calc dist bet cur pt and oP
	dist = distance(P, oP);

	// add dist attr for debugging
	addattribute("dist2oP", dist);

	if(dist <= 1)}
		addatribute("KurtisBlow", 1);

Link to comment
Share on other sites

Generally, SOPs (and Objects) are not history dependent. There are exceptions but not with VEX. I'm sure everyone will have their favourite solution to this problem. Here's one by using the Group POP's Preserve Group option.

edward! Please!

Could you explain whata's going on in your hip! Sorry, but I don't get it. What this POP does?

Link to comment
Share on other sites

The Group POP in the hip file adds all the points that are found in the "inside" group from the second input of the popnet (ie. /obj/model/group1) into its own group (also called "inside"). Normally, it creates a group with only those points that match its condition (ie. the haspoint() expression) but with Preserve Group enabled, it will only add to its group, not remove. The reason why this works is because in POPs, the same geometry is being reused across frames (as opposed to SOPs which make a new copy each time). The Source POP is used to essentially cache a copy of the points from input1 (at frame 1), effectively doing what Rick talks about creating a separate list and accumulating. Finally, the copy_from_popnet AttribCreate SOP copies the result of the "inside" group in the popnet as an attribute (also named "inside") which the Paint SOP then uses for its visualization. Perhaps I confused things a bit by calling everything "inside". :)

The only other trick in the .hip file is to copy spheres to the input2 geometry and then using the Bounding Object option of the Group SOP to effectively do what Rick was trying to do with his distance calculations.

BTW, if you happen to see anything weird in the results, it will be from the Cache SOP (cache1), because it attempted to cache the POP while going backwards which can't work for POPs. To fix this, you can go to frame 1, click on Clear Cache, hit play to cache the POP simulation again.

Link to comment
Share on other sites

Thank you edward! Now I think I got it... more or less. Gosh! I used to have the same problem and I didn't find the solution: how to add points to groups but never take them off from it... but it was 6 months ago :unsure:

again, thanks for your explanation!



Link to comment
Share on other sites

jlait notes that using the Bounding Object option with spheres to this type of operation is not that efficient. Using the VEX point clouds to do it would be the most efficient.

Cheers Edward. That sure does work. I was hoping to do it all in vex to exercise my vex muscles but using the group pop makes sense. I'll investigate point clouds.


Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...