View Full Version : help. how to get event handle in particle system

10 October 2006, 03:20 PM
hello, every one :
im new to the particle flow system. i have a question for help:

what i want is :
2 particles , if move too close ,or u can say they are collided , and then i can use the script , to do something with the 2 particles . and how to write the scripts ? use script operator ? i mean particles collide with particles , not the collision test ,cause the collision test is for the particle collide with a deflactors .

or i show what i want in script language , maybe like this :
if <collided> then
<the first particle stop,the second particle move to other direction that i can define in a script >
else <do........>
on <particles collide with eachother > do ( <i can do something with the particles> )
and i know in particle script operator ,the code should be writen in other format.

i dont know well with the script operator now . how it works together with the other helpers . and how to get events and then control other helpers.

i know well with max script , but need help in useing script in particle system .

thanks all .

found something , use script wiring . still going on ...
nobody help me , feel so lonely . the use script wiring is something inverse with my wish . i want when <keep apart> then <modify the particle>. but it looks just inverse direction .
still going on ....

maybe i misunderstand the <keep apart > helper , i should use < collision > to test . but is here any collision test which test the collision between the particles ?

10 October 2006, 09:43 PM
My own experience with scripting particle flow is limited, but I think I can help you. The general syntax of scripted operators in PFlow is the exact same as Maxscript, only with different objects and properties. If I understand correctly, you basically want to write an inter-particle collision system, so for this you're going to need a Script Test operator. Within this Script Test you will be checking distances between every particle, and the particles that are close enough will "pass" the Script Test and move on to the next event, where you can do whatever else you want to do with them. What's important to realize with scripted operators in PFlow is that the script you write is essentially being executed at every integration step. It is not something that is only executed once; it is executed everytime the system calculates forward in order to move the particles through space.

Another important note: particles in PFlow are moved through space using vectors. This means that at every integration step, or every PFlow calculation, PFlow simply takes the particle's current position, and translates it along the speed vector for that particle. This is how particles move through time.

Here is a Script Test I wrote up to do this. You can read in the help files what each code block is meant for (ChannelsUsed, Init, Proceed, and Release), but the more important ones are ChannelsUsed and Proceed. Proceed is the block that gets executed at every integration step. My code is straight-forward -- it assigns the number of particles to a variable ("count"), makes a distance variable to hold the threshold that dictates how close particles can get before they get sent to the next event ("theDistance"), and initializes an empty array to store particle indices that pass the test ("passParticles"). It then loops through every particle, grabbing its position, then checking that particle against every other particle in the system, in a double-loop fashion, gathering up particles that "pass" the test in the passParticles array. After that loop it loops through the passParticles array and sets each particle found to test "true", and sends along the time as well.

on ChannelsUsed pCont do
pCont.useTime = true
pCont.usePosition = true

on Init pCont do


on Proceed pCont do
count = pCont.NumParticles()
theDistance = 20.0
passParticles = #()

for x = 1 to count do
alphaPos = pCont.getParticlePosition x

for i = 1 to count where i != x do
betaPos = pCont.getParticlePosition i
if distance alphaPos betaPos < theDistance do
if finditem passParticles i == 0 do append passParticles i

for p in passParticles do
pCont.particleIndex = p
pCont.particleTestStatus = true
pCont.particleTestTime = pCont.particleTime

on Release pCont do


Its certainly not the most elegant solution, but it works, and so long as you're not simulating a crazy amount of particles, the double loop shouldn't be too strenuous. Play around with "theDistance" to adjust how close you want to allow your particles to get before getting sent to the next event.

I hope this helps, if someone has a more elegant solution to test distances between every particle, it would be most enlightening!

10 October 2006, 05:39 AM
just as u say , what i want is that max has a internal function to caculate the distance between the particles , and can be called by us . but have not found it .

if we use the script test to do the distance testing of many particles ,it is easy to write a script but i am afraid it will cost too much of times . maybe very slow .

and now , without any new idea , we have to caculete it by our script testing .

as u wish , and i wish too, there has a more efficent function to do this job .

thanks again .

10 October 2006, 03:10 PM
You can check out the demo of Particle Flow Tools: Box#3 (at It has a suboperator Particles that can calculate inter-particle distance in very efficient manner.

Oleg B.

10 October 2006, 03:17 PM
I was just going to suggest box#3... :rolleyes:

Data operators are sweet, unfortunately I have not enough time in the day to learn them sufficiently right now, but I don't know what I'd do without box#1.

10 October 2006, 03:30 PM
thanks ,man . i found the box#3 now . checking .
have download the zip file of box#3 ,but need many subOperators plugins .
have to find them in the forum of orbaz.

by the way , the website is looks very good place for particle flow . feel lucky now .

thanks .

10 October 2006, 06:52 PM
Here you can get the installer for the demo version:

It's not a zip, it's .exe of the installer - after the installation you would have all the Box#3 modules, documentation/help/reference and examples.

Oleg B.

CGTalk Moderation
10 October 2006, 06:52 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.