2010年5月24日

A commonly needed effect is the emission of particles at the exact location of object collision. For example, as a sword scrapes along a wall we may need sparks; As a boulder rolls down a mountainside we may need smaller instanced rocks and pebbles to appear; As a character walks along a dirtroad we would expect dust to appear at his feet.



Such effects require the ability to specifically determine particle emission at certain UV coordinates of the surfaces. This can be accomplished in a couple of ways: easy and involved. The involved technique requires us to use rigid body collisions, where the Rigid Solver has Contact Data turned on. This attribute allows some 'read-only' attributes to be accessible on the rigid body, such as 'contactCount' and 'contactPosition'. We could then query these attributes and use them with the 'emit' mel command to determine particle creation. But for those who prefer to avoid expressions, we are going to discuss a much simpler method using Softbodies.

Say we have a boulder which needs to roll down a hill creating dust clouds as it rolls. The boulder could be an active rigid body falling with a gravity field, while the ground is a passive rigid body. With this already set-up in the scene, select the rigid body boulder and turn it into a softbody. In the dialog box for 'create softbody', choose 'Duplicate, make copy soft', turn off 'hide original', turn on 'make non soft a goal' and set the goal weight to something greater than '.5'. At this point, what will be created in the scene, if you look in the Outliner, will be a duplicate of your boulder which has an associated Particle Object with particles at the location of each of the boulder's vertices. At this point select the 'shape node' of the duplicate 'soft' boulder and hide it. We only want to see the particles of the 'soft boulder', not the geometry. (we are not trying to make a jello boulder). If you play back your dynamic simulation, you will see the particles of the soft boulder trailing the original a bit due to the softbody goal weight value. When the boulder bounces off the ground, you should notice the softbody particles moving through the ground a little.



What we are now going to do is have the softbody particles collide with the ground plane. Select the ground and choose Particles/Make Collide. In the dialog box set the resilience and friction to zero. Then open the Dynamic Relationships editor and connect the softbody particle's collision to the ground plane. Playing back the simulation will now show the particles no longer going through the ground.

The next step is to select the softbody particle object and open the dialog box for Particles/Particle Collision Events. As you may now understand, by using collision events, we will have the softbody particles emit particles as they collide with the ground. So in the Collision events window, use the following settings: collisions should be set to 'all'. We want particles to 'emit', not 'split'. Then turn on 'random # particles' and set the max number to about 10. (you will raise or decrease this value later based on the desired effect). Set spread to about .7, Inherit Velocity to '0', and original particle dies to 'off'. Then hit 'create event'. If you now look in the Outliner, a new particle object will be there. This is the new particle object which particles are emitted into by the softbody particles when they collide with the ground. If you playback the simulation, you should now see particles appearing on the ground where the boulder collides. At this point on it becomes of matter of designing the look of the particles as well as their motion using fields, etc. Remember that you can also set these particles to collide with the ground, as well as the boulder (but you would also need to select the boulder and choose Particles/MakeCollide). The two main things you will be tweaking at this point will be the number of particles created by the collision event, as well as the goal weight of the softbody particles, based on the speed that the boulder is moving.



Our example uses two rigid bodies... but our scene could have as many objects as we like, where the above steps are applied to each. Remember that the collision events window allows multiple collision events to emit into the same particle object (the 'target particle' field in the collision events window).

If you are going to be hardware rendering your particles, by the way, you will notice that the softbody particles will be rendering as grey points. Just add an opacity attribute to them set to a value of '0', so that they will not be visible.



As a final note, this technique does not require us to use rigid bodies. In an example where a character's feet are creating dust, the ground would have 'make collide' applied, but it doesn't necessarily need to be a rigid body. Also, the foot itself doesn't need to be the object turned into a softbody... you could just skin a simpler object to the foot joints which is converted to a softbody. (and this object wouldn't be rendered, of course). So I hope you were able to follow along... its a relatively simple technique with a wide range of applications.


*****
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.

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

Post a Comment:

留言會在通過機器人審核後才會顯示~留言完畢沒有顯示並不是留言失敗喔!

版權所有 © 2016 Jacys Lin All Rights Reserved. | 轉載請註明出處 |