View Full Version : Particle expressions

03 March 2003, 07:59 PM
I'm working on a CG short that involves a huge wooden river barge in a violent sea storm. I want to setup the simulation so that when the boat hits rocks sticking out of the ocean - dust and wooden chips from the boat are emitted at those points where the collision takes place. I know I have to use MEL to accomplish this and I found a few commands to generate the data neccesary. My problem is I really don't know where to start or exactly what to do. Is there anyone out there that has worked on a similar situation and could give me some direction? I looked into Alex Alvarez's tutorial that sortof tapped into this. He describes the short way (which is what the tutorial is concerning) and the long way - I need to find out the long way. Thanks ahead of time for any help you can give.

03 March 2003, 10:15 PM
I have a fast and a long way.

The fast one would be to let the geometry emit invisible particles with a short livetime, and an inherit velocity, which means that they will go the same way the geometry does on creating. The short livetime will let them pass through the rocks on collision, so you can let those particles create 2ndary particles on collision with the rocks, and make them look like dust and wooden chips by sprites or something.

The long way would be to query the collision data and use it to create particles using the emit function.
The very first thing youŽll have to do is to locate the rigidSolver in the Channel Box and set the "contactData" attribute to ON.

After that, you can start creating an expression for your barge.

I canŽt give you the complete script, but I have one somewhere, so IŽll search for it. What I remember so dar is thet you can query the contact position, and the contact velocity:

rigid Body -q -vel WoodBarge;

>> will give you the speed of the Object on collision. You will need that later to controll the amount and direction of your particles. A fast collision will make a large amount of dust, a slow one less.

You should write it in a string:

float $vel[] = `rigidBody -q -vel WoodBarge`;

and than read out the magnitude (beceause vel is a vector) you can use later for the emit function:

float $speed = mag(<<$vel[0], $vel[1],$vel[2]>>);

This will query the contact Position:

$cPos = "`rigidBody -q -cp WoodBarge`;

Beceause this position gives you a single point in space, you have to add a random function like rand or gauss to the emmit command to spread the created particles in a volume.
You can use an Creation or Lifetime Expression to controll the speed and direction, or maybe connect it to $vel.

IŽll search for the full script, maybe ItŽll help you more than this.

03 March 2003, 12:23 AM
Thanks so much for the speedy reply. If you come back to this thread and read this - Thanks for the help and your time, it is most sincerely appreciated.

03 March 2003, 09:35 PM
Here's another way to do it that gasp uses MEL a lot less.

The idea is to use particle collision events to emit more particles (for dust and for instancing wood chunks.)

Select the ship's geometry pieces and choose "Emit from Object," opening the option box. Set the emitter type to "surface," set the emission speed attributes to Speed: 1, Speed Random: 0, Tangent Speed: 0, and Normal Speed: 0.010. Also, set the emission rate to maybe 10,000 particles per second or more.

Now, play back the animation. You should see a ton of particles slowly expanding outward from the boat's surface.

When there are enough to cover the surface reasonably densely (you may have to tweak the rate to do this), and when they're forming a cloud that closely conforms to the boat's shape, stop the playback. Open the outliner and delete the emitter you just created, and BEFORE touching the timeline, select the particle object and choose Solvers > Initial State > Set for Selected.

Now, those particles are fixed in space in a cloud around the ship. Hide this particle object and parent it to the ship.

Now, choose the particle object in the outliner and also pick the dock geometry, choosing Make Collide under the Particles menu.

Finally, open the Particle Collision Events window under the Particles menu. You can use this to make a second particle object whose particles are emitted on collisions between the hidden particle cloud on the ship and the dock. You'll probably want to do this twice, once for dust and once for chunks of wood.

Now, set up your rigid body dynamics on the ship and the dock without regard to the particles, and use particle expressions to manage stuff like how wood chunks get instanced, initial velocity per particle, and so on.

The advantage of doing this over some complicated MEL arrangement involving rigid bodies is that it will run a lot faster.

-- Mark

03 March 2003, 09:39 PM
The other advantage is that, by doing it using particle collision events, you aren't using MEL commands like rigidBody -q in your particle expressions, which are the fast road to slow-scene-evaluation hell.

-- Mark

03 March 2003, 10:40 PM
Originally posted by mark_wilkins
The other advantage is that, by doing it using particle collision events, you aren't using MEL commands like rigidBody -q in your particle expressions, which are the fast road to slow-scene-evaluation hell.

-- Mark

I need to second that!
Using particle velocities as a base for your impact calculation is the way to go. Never try to get velocities out of a rigid body for particle stuff, use particle velocities (create extra particles for measuring speed if necessary)

Mark: do you know how all that particle collision event thing is built? I used it once and it worked flawlessly. But since there were no extra nodes or expressions or anything in the scene as far as i remember, I wonder where the logic behind particle collision events sits. The only thing that seems to be indicative of particle coll. events use are extra attrs on the particleShape and the options you see when opening the coll. events options.


03 March 2003, 10:48 PM
Collision events, I believe (maybe I'm wrong!), are handled as part the same event queue used to trigger scriptJobs.

BTW, while using MEL commands in particle expressions is really bad, I confess to doing so in one of the particle expression examples in my book, but I did explain why it's a bad idea in the presentation of it. :D

-- Mark

CGTalk Moderation
01 January 2006, 03:00 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.