PDA

View Full Version : How to test if inside volume


lo
10-30-2007, 06:07 PM
Hi

I'm trying to find a way that will allow me to test if particles are inside the volume of a certain object, not just hitting it's surface, like a deflector.

For instance, I have a field of static particles and I want to delete all particles which are randomly born inside a certain box.

Is this possible? Thanks.

SoLiTuDe
10-30-2007, 08:29 PM
I think the easiest way would be if you have box 1 (addon for pflow) you can use the group operators to select particles inside a volume and delete them.

BrandonD
10-31-2007, 12:39 AM
The easiest "hack" method without plugins is to just use a CollisionTest, but set the operation to None so that there is no interaction. Then pass the result of the test on to something else. With Box 3 I very quickly made an operator that does exactly what you're talking about. I'll see about publishing it.

OlegB
10-31-2007, 01:50 AM
is to just use a CollisionTest

Would not work for static particles. As mentioned before, both Box#1 and Box#3 have solution for this problem.

Thanks,
Oleg B.

Bobo
10-31-2007, 03:36 AM
Would not work for static particles. As mentioned before, both Box#1 and Box#3 have solution for this problem.

Thanks,
Oleg B.

And, thanks to the amazingly versatile Script Operator, it is also scriptable :)

1. Create a PFlow with Box (or whatever shape you want) emitter.
2. Create a Box primitive (or any other geometry to use as volume)
3. Add a Script Test, wire to an event with a Delete operator.
4. Enter in the Script Test:

on ChannelsUsed pCont do
(
pCont.usePosition= true
)

on Init pCont do ( )

on Proceed pCont do
(
count = pCont.NumParticles()
theObject = $Box01
for i in 1 to count do
(
pCont.particleIndex = i
if IntersectRay theObject (Ray pCont.particlePosition (theObject.center-pCont.particlePosition)) == undefined do
(
pCont.particleTestStatus = true
pCont.particleTestTime = pCont.particleTime
)
)
)

on Release pCont do ( )

Instead of a box, you can use any other convex geometry. With complex geometry like a Teapot though, this test is likely to be not very precise.

Of course, if the volume in question is really just a box, you could transform the particle's position into the Box' space and check against its width, height and length to see if the particle is inside or outside its local bounding box. It would be probably faster, but since a box is a very special case, the code above is much more universal.

Also note that the default script inside the Script Test does about the same, but with a Sphere at the world's origin (courtesy to Oleg B. ;))

lo
10-31-2007, 09:28 AM
Bobo - thank you, you are a lifesaver! The script works great, but creates something odd which I don't understand

The blue plane is moving in the direction of the arrow, creating static particles as it moves.

The script tests true for all particles inside the box (shown in yellow).

What I don't understand is why their position changes. Any ideas?

Thanks

Bobo
10-31-2007, 03:23 PM
Bobo - thank you, you are a lifesaver! The script works great, but creates something odd which I don't understand

The blue plane is moving in the direction of the arrow, creating static particles as it moves.

The script tests true for all particles inside the box (shown in yellow).

What I don't understand is why their position changes. Any ideas?

Thanks

*What does it look like when you disable the Test? Is it different?
*Is your PFLow set to show 100% of particles in the Viewport?
*What are the settings in the Position Object operator?

I could not reproduce the problem, but I don't have the same scene. Can you upload your test scene?

lo
10-31-2007, 04:32 PM
I could not reproduce the problem, but I don't have the same scene. Can you upload your test scene?

Hey Bobo. While I haven't figured out what was wrong, I've found a different approach to the scene, which might work better.

Here is the scene incase you wish to try and find out what was the problem

Thanks.

Bobo
10-31-2007, 06:27 PM
Hey Bobo. While I haven't figured out what was wrong, I've found a different approach to the scene, which might work better.

Here is the scene incase you wish to try and find out what was the problem

Thanks.

It is the Separation option that causes the difference. The Separation creates particles at a forced distance from their neighbors FROM THE CURRENT EVENT.
When a new particle is created and placed, its position is tested against all neigbors in the event and the position is adjusted (up to 300 times by default) to keep a given distance. But if there are less neighbor particles (because some were sent out previously to another event), then the separation has a less crowded event to work with and it doesn't have to separate the new particles so much.

lo
10-31-2007, 08:54 PM
It is the Separation option that causes the difference. The Separation creates particles at a forced distance from their neighbors FROM THE CURRENT EVENT.
When a new particle is created and placed, its position is tested against all neigbors in the event and the position is adjusted (up to 300 times by default) to keep a given distance. But if there are less neighbor particles (because some were sent out previously to another event), then the separation has a less crowded event to work with and it doesn't have to separate the new particles so much.

That makes a lot of sense... I didn't know the seperation parameter only works on the current event. Thanks a lot for all of your help! :)

PsychoSilence
11-01-2007, 03:20 PM
nice script, bobo! *copies script to his HD*

CGTalk Moderation
11-01-2007, 03:20 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.