Particle Attachment for AI: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
(New page: == Attaching Particles to an AI == Fairly easy to attach particles to an AI once someone looks into the SDK for you :D The particle will be attached to a bone, this gives you plenty o...)
 
No edit summary
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Attaching Particles to an AI ==
== Attaching Particles to an AI ==
This page covers attaching particle systems to specific bones on an animated model (such as an AI).
This should work for any animated object, it must have an md5 file so it contains bones.


Fairly easy to attach particles to an AI once someone looks into the SDK for you :D
The particle will be attached to a bone, this gives you plenty of options as most AI have 20+ bones. The names of the bones can be found in the AI's md5 file which can be opened with notepad or wordpad. For example, ''steambot.md5mesh'' contains the bones for the steambot. The joint names are usually fairly obvious as the animators need to find that info easily. left_hand is obviously a bone in the left hand.
 
The particle will be attached to a bone, this gives you plenty of options as most AI has 20+ bones. The names of the bones can be found in the AI's md5 file which can be opened with notepad or wordpad.
ie: ''pagan_female_mesh.md5mesh'' , usually the joint names are fairly obvious as the animators need to find that info easily. left_hand is obviously a bone in the left hand.
 
  You'll need to create a particle effect. Once you have that you can add some info to your AI's def file. It's probably best if you want to add a fire particle to a pagan females hand that you copy her .def file and give it a new name, this way the pagan_female files won't get messed up.
 
There are probably 2 ways to go with the particle attachment:
1-constantly emitted particle
2-particle emitted at intervals.
 
Adding this line to your AI's entity def description will add a particle (''bc_sparx'') to the joint named ''smokestack''.
 
'''"smokeParticleSystem1" "bc_sparx-smokestack"'''
 
Alternately you can add the particle named ''smokestack'' to the joint named smokestack by using this line
 
'''"smokeParticleSystem1" "smokestack"'''


The first option is probably best as you can reuse particles instead of making a new one to match the joint name.
You'll need to create a particle effect using the [[Particle Editor]], or you can use an existing particle effect. Once you have that you can add some info to your AI's def file. Be wary that editing an existing particle in the editor will change all particles of that type, so it's best to add a new particle via the editor (you can copy settings from a similar particle if you like).


    anim walk models/md5/chars/steambots/lant_bot_searc.md5anim
There are probably 2 ways to go with the particle attachment:
{
*constantly emitted particle
  frame 12 footstep
*particle emitted at intervals.
  frame 31 footstep
      frame 31    triggerSmokeParticle smokestack
}


This calls for some investigation. To the SDK!
Adding the following [[spawnarg]] to your AI will add a particle named ''steam_puff'' to the joint named ''smokestack''.  


[...a little while later...]
'''"smokeParticleSystem1" "steam_puff-smokestack"'''


Yes, spawnargs starting with "smokeParticleSystem" (so that includes smokeParticleSystem, smokeParticleSystem1, smokeParticleSystemBobsYourUncle, etc.) are indeed referenced in the SDK. This is the relevant SDK function (it's called with keyName equal to "smokeParticleSystem"):
Alternatively you can add the particle named ''smokestack'' to the joint named ''smokestack'' by using this line


'''"smokeParticleSystem1" "smokestack"'''


CODE
The first option is probably best as you can reuse particles instead of making a new one to match the joint name. Either way you'll notice that the above lines contain ''smokeParticleSystem1''. An AI can have multiple smokeParticleSystems attached, in which case just increase the number: smokeParticleSystem2, smokeParticleSystem3, etc. The Monster_Boss_Cyberdemon.def from standard Doom 3 has 9 of these; 2 are used for footsteps, the other seem to be permanently attached flame particles to his back and mouth.
/*
=====================
idAI::SpawnParticles
=====================
*/
void idAI::SpawnParticles( const char *keyName ) {
    const idKeyValue *kv = spawnArgs.MatchPrefix( keyName, NULL );
    while ( kv ) {
        particleEmitter_t pe;


        idStr particleName = kv->GetValue();
'''Note:''' Even though the spawnargs are called ''smoke''ParticleSystem#, you don't have to use them just for smoke. They work with any particle effect.


        if ( particleName.Length() ) {
OK, great you say. But I only want a steam puff coming from my steambot's smokestack everytime the top of the stack opens. (In this case the stack happens to open towards the end of each animation.)


            idStr jointName = kv->GetValue();
If so you'll need to add a line to your AI's ''model def description'', as in the example below. This can be found in the AI's .def file (in this case lantern_bot.def).
            int dash = jointName.Find('-');
            if ( dash > 0 ) {
                particleName = particleName.Left( dash );
                jointName = jointName.Right( jointName.Length() - dash - 1 );
            }


            SpawnParticlesOnJoint( pe, particleName, jointName );
anim walk models/md5/chars/steambots/lant_bot_walk.md5anim
            particles.Append( pe );
{
        }
frame 12 footstep
frame 31 footstep
frame 31    '''triggerSmokeParticle smokestack'''
}


        kv = spawnArgs.MatchPrefix( keyName, kv );
In the above example, all of the particle effects attached to the bone named "smokestack" will start from the beginning every time the "walk" animation is at frame 31.
    }
}


Importing the model and animation into a 3d program are probably the easiest way to find a specific frame, but you can also get it right by trial/error guessing. Most animations are around 30 frames, look for cycles. A bipeds walk anim is usually 2 steps (ie left foot, right foot) so a dust cloud coming from his right foot would be somewhere around frame 25, if it's late or early you can adjust until you get it close enough.


That's probably Greek to you if you've never seen C++ before...  So I'll explain it. Basically what it's doing is looking for a dash (-) in the value of the spawnarg. Everything left of the dash is the name of the particle. Everything to the right of the dash is the name of the joint (for our purposes, a joint just means a bone). If there's no dash, then the particle name is the same as the joint name - this is probably what's happening in your case. It's finding the bone named "smokestack", but it's also looking for a particle named "smokestack". Since it doesn't find such a particle, you get black squares.
The benefit of using this method instead of a timing script is that you can match the particles timing to an AI's action even if something happens in time to mess up the sync.


So if you want a particle called myawesomeparticle to be (permanently!) emitted from the bone smokestack, you might use the following spawnarg:
Once you have the particle attached to the AI you can go in game and bring down the console ( ''Shift ~'' ) and type '''editparticles'''. This will open the [[Particle Editor]] and you can edit the size, shape, timing, gravity, ect... of the particles. It takes a minute so be patient, once it has been opened it will only take a second to open again until you restart game mode.


"smokeParticleSystem1" "myawesomeparticle-smokestack"
If your number of particles being emitted is too high, the movement speed is too low, or a combination of these two then you might not notice them being emitted at the desired keyframe. If you want visible puffs using only one or two particles, increase as needed.


So far so good, but it's not active yet (I think - you might want to test this yourself to be sure). So you need to use the triggerSmokeParticle frame command to turn it on. As you've discovered, this is placed within an "anim" block and takes this format:


frame [framenumber] [bonename]
------------This is probably to be deleted soon, need to test self starting particles
I believe nothing other than '''"smokeParticleSystem1" "smokestack"''' is needed, they seem to start on their own, but if you want to start them you need to use above instruct
---------


Where [framenumber] is the frame number of the animation, and [bonename] is the name of the bone/joint on which to trigger particle effects. Note that all particle effects on that bone will be triggered, if you have more than one.
[[Category:AI]]
[[Category:Tutorial]]

Latest revision as of 14:15, 10 June 2007

Attaching Particles to an AI

This page covers attaching particle systems to specific bones on an animated model (such as an AI). This should work for any animated object, it must have an md5 file so it contains bones.

The particle will be attached to a bone, this gives you plenty of options as most AI have 20+ bones. The names of the bones can be found in the AI's md5 file which can be opened with notepad or wordpad. For example, steambot.md5mesh contains the bones for the steambot. The joint names are usually fairly obvious as the animators need to find that info easily. left_hand is obviously a bone in the left hand.

You'll need to create a particle effect using the Particle Editor, or you can use an existing particle effect. Once you have that you can add some info to your AI's def file. Be wary that editing an existing particle in the editor will change all particles of that type, so it's best to add a new particle via the editor (you can copy settings from a similar particle if you like).

There are probably 2 ways to go with the particle attachment:

  • constantly emitted particle
  • particle emitted at intervals.

Adding the following spawnarg to your AI will add a particle named steam_puff to the joint named smokestack.

"smokeParticleSystem1" "steam_puff-smokestack"

Alternatively you can add the particle named smokestack to the joint named smokestack by using this line

"smokeParticleSystem1" "smokestack"

The first option is probably best as you can reuse particles instead of making a new one to match the joint name. Either way you'll notice that the above lines contain smokeParticleSystem1. An AI can have multiple smokeParticleSystems attached, in which case just increase the number: smokeParticleSystem2, smokeParticleSystem3, etc. The Monster_Boss_Cyberdemon.def from standard Doom 3 has 9 of these; 2 are used for footsteps, the other seem to be permanently attached flame particles to his back and mouth.

Note: Even though the spawnargs are called smokeParticleSystem#, you don't have to use them just for smoke. They work with any particle effect.

OK, great you say. But I only want a steam puff coming from my steambot's smokestack everytime the top of the stack opens. (In this case the stack happens to open towards the end of each animation.)

If so you'll need to add a line to your AI's model def description, as in the example below. This can be found in the AI's .def file (in this case lantern_bot.def).

anim walk		 models/md5/chars/steambots/lant_bot_walk.md5anim
{
frame 12	footstep
frame 31	footstep
frame 31     triggerSmokeParticle smokestack
}

In the above example, all of the particle effects attached to the bone named "smokestack" will start from the beginning every time the "walk" animation is at frame 31.

Importing the model and animation into a 3d program are probably the easiest way to find a specific frame, but you can also get it right by trial/error guessing. Most animations are around 30 frames, look for cycles. A bipeds walk anim is usually 2 steps (ie left foot, right foot) so a dust cloud coming from his right foot would be somewhere around frame 25, if it's late or early you can adjust until you get it close enough.

The benefit of using this method instead of a timing script is that you can match the particles timing to an AI's action even if something happens in time to mess up the sync.

Once you have the particle attached to the AI you can go in game and bring down the console ( Shift ~ ) and type editparticles. This will open the Particle Editor and you can edit the size, shape, timing, gravity, ect... of the particles. It takes a minute so be patient, once it has been opened it will only take a second to open again until you restart game mode.

If your number of particles being emitted is too high, the movement speed is too low, or a combination of these two then you might not notice them being emitted at the desired keyframe. If you want visible puffs using only one or two particles, increase as needed.



This is probably to be deleted soon, need to test self starting particles

I believe nothing other than "smokeParticleSystem1" "smokestack" is needed, they seem to start on their own, but if you want to start them you need to use above instruct