Jump to content

# Remove Primitive by Sphere

## Recommended Posts

if(@primnum>45){
vector ghh = point(1,"P",i);
removeprim(0,ghh,1);

I'm hoping I can get some help.

*ghh* is a variable which represents a sphere.  What I want is, when moving the sphere around if it should come in contact with primitives with numbers greater then 45 then it removes those primitives; although it's not working, what am I doing wrong ?

#### Share this post

##### Share on other sites

I see my error.

What I should've asked is; how can I translate a sphere around and when it comes in contact with the primitives of another object as in a sphere, it deletes primitives based on a threshold distance ?

#### Share this post

##### Share on other sites

one simple way is using an attribute transfer as I mention before, there is many ways to do this.

deleteprims.hipnc

• 1

#### Share this post

##### Share on other sites

What are the other ways ?

#### Share this post

##### Share on other sites

Is your sphre (the « trigger » object) a simple primitive (therefore only one point), or is it polygon sphres, with many points ?

What you can do is use the xyzdist vex function to calculate, for each point or primitive of your object, the closest distance to the sphere, and when it reaches a threshold close to zero (ie. When there is contact), you use removeprim.

But this is very similar to the use of the trasnfer attribute and grouping method explained above.

#### Share this post

##### Share on other sites

It's a single primitive, therefore with one point.

#### Share this post

##### Share on other sites

This should work:

// Get distance of primitive to point position of second input, Sphere is plugged in to second input //
float dist = distance(@P, point(1, "P", 0));
// Get radius of sphere, I made a relative reference to the spheres scale in the radius parameter that is created //
float rad = chf("radius");
// If the primitive is inside the sphere, delete//
if(dist<=rad){
removeprim(0, @primnum, 1);
}

Edited by Sean-R
Fixed code error
• 1

#### Share this post

##### Share on other sites

Shouldn't it be dist, rather then @dist ?

#### Share this post

##### Share on other sites

Yes! I've fixed the code

• 1

## 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

×
• Donations

• Leaderboard