Jump to content

Delete percentage of points after specific frame


Recommended Posts

Hello, I have a sim set up using flip objects with geo copied to points. I want to be able to delete 5% of my points every frame after a specific frame, so there is a gradual deletion. I referenced this post which triggers from frame 1.


Can I achieve that same setup, but trigger it from a specific frame number, rather than from frame 1?

I'm a beginner and still getting my head around vex. 

Any help is appreciated. Thanks.


Link to comment
Share on other sites

I'm not completely sure about the syntax here since I'm not in front of a machine with Houdini to test on, but maybe something like this inside a pop wrangle:

if(@Frame >= yourframenumber)
  if(rand(@ptnum) > 0.95)

Just replace "yourframenumber" with the frame you want it to start at and if you want to delete more (or less) than 5% change 0.95 to another number. The number you want here is basically: 1 - (your % number / 100).
So for 5% it is: 1 - (5 / 100) -> 1 - 0.05 = 0.95.

Just as a quick explainer:
- if() statements let you compare two values and then if the comparison criteria are met then it will execute the code inside the {}. The most common comparators are == (equals), != (not equals), < (less than), > (greater than), && (and), || (or). Some of these can also be combined, like the equals and less than / greater than to become equals or less, equals or greater.
- "@ptnum" and "@Frame" are both attributes that are always present on points even if they don't show up in the geometry spreadsheet the same way other attributes do (ptnum actually shows up kinda, all the way to the left as the number on the side). Ptnum is each point's unique id and Frame simply just gets the current frame.
- The rand() function generates a random number between 0 and 1 based on a "seed" value, usually, this is a value where we want every point to have its own unique value which is why ptnum is very often used here, but it could be any value.
- Lastly the removepoint() function does mostly what it says in the name, it removes a specific point, all it needs to know is what geometry stream and which point to delete. If the point has passed both the if() statements we laid out previously we know that it is currently some frame after the time where we should start deleting points and then the current point is among the 5% of points with a value higher than 0.95, meaning that we want to delete it.

One small final note on this setup is that it might not remove EXACTLY 5% of points each frame, since the rand() function generates a random distribution of numbers the 5% is only theoretical based on the assumption that the random will give you a more or less even spread, so if you need it to be EXACTLY 5% every frame you might need something more accurate.

  • Like 2
Link to comment
Share on other sites

@underscoreus Hey thanks so much for taking the time to explain this so clearly. Really appreciate it. That pop wrangle works great. And your breakdown helps me understand it a little more. I definitely need to venture into VEX territory more often to truly understand it properly. Thanks again mate!

  • Like 1
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...