Improved Particle Emitters
by Sebastiaan Keek · 04/08/2003 (1:42 pm) · 48 comments
Download Code File
First off this is my first attempt at torque coding besides coppy and pasting other code. The (not all that nicely) documented added and expanded fields have been tested to a good extend and "if" you get what the heck it is they actually do.. you'l find them very usefull for creating certain special effects and whatnot.
This code is meant for the latest head of approx early april 2003.
It seems to be incompatible with 1.1.1.
I've included a readme for reference an screenshot and a modified scorchedPlanet.mis to showcase some of the posibilities. And ofcourse the code files.
The code files overwrite your current particleEmitter and ParticleEngine source files. If you made any changes to them, you could try merging, thought I recommend testing out my version first to see if it's worth it ;).
But it's worth it.. trust me. The additions allow for creations of complex rotating fields of particles, cubic fields of particles and particles relative to objects..
Also it removes the need for a model node by introducing a virtual node in the emitter system.
I also enabled the ability for emitters to scale, either by datablock or by linked object wich allows for player jetpacks to dynamically scale along with the rest of the model.
However with the introduction of new fields also comes added complexity. I'l try to update my documentation and hopefully shed light on questions anyone might have.
Finally, please feel free to make comments, ask questions or make sugestions either by email or on this page.
*Updated to version 0.3
First off this is my first attempt at torque coding besides coppy and pasting other code. The (not all that nicely) documented added and expanded fields have been tested to a good extend and "if" you get what the heck it is they actually do.. you'l find them very usefull for creating certain special effects and whatnot.
This code is meant for the latest head of approx early april 2003.
It seems to be incompatible with 1.1.1.
I've included a readme for reference an screenshot and a modified scorchedPlanet.mis to showcase some of the posibilities. And ofcourse the code files.
The code files overwrite your current particleEmitter and ParticleEngine source files. If you made any changes to them, you could try merging, thought I recommend testing out my version first to see if it's worth it ;).
But it's worth it.. trust me. The additions allow for creations of complex rotating fields of particles, cubic fields of particles and particles relative to objects..
Also it removes the need for a model node by introducing a virtual node in the emitter system.
I also enabled the ability for emitters to scale, either by datablock or by linked object wich allows for player jetpacks to dynamically scale along with the rest of the model.
However with the introduction of new fields also comes added complexity. I'l try to update my documentation and hopefully shed light on questions anyone might have.
Finally, please feel free to make comments, ask questions or make sugestions either by email or on this page.
*Updated to version 0.3
#2
04/09/2003 (12:06 am)
Sounds good, have you put this up for to be added to the CVS? I'm sure alot of people would like that :-).
#3
Updated to version 0.3.
Added some extra features that might be nice.
04/10/2003 (2:51 am)
That might be an idea, thought I don't think complexifying the system is one of their goals. ;)Updated to version 0.3.
Added some extra features that might be nice.
#4
04/11/2003 (7:15 am)
Am I to assume that this is for v1.1.2 or the current HEAD? I can't really compile it with 1.1.1 because it uses some non-existent functions for **compressedPoint.
#5
I don't really see the point of working with old code, even when the new is possibly unstable.
04/14/2003 (1:19 am)
You'r correct, this code was build of the latest head.I don't really see the point of working with old code, even when the new is possibly unstable.
#6
04/14/2003 (6:42 am)
Yeah, well, we have an actual production going with 1.1.1 and have already made way too many modifications and twists to go back and try them out with 1.1.2 or HEAD.
#7
04/14/2003 (12:58 pm)
Well.. if you are specifically interesed in a certain area of effects you wish to create I'm sure I could make something for 1.1.1
#8
"Also it removes the need for a model node by introducing a virtual node in the emitter system."
04/15/2003 (9:05 am)
What is meant by the following:"Also it removes the need for a model node by introducing a virtual node in the emitter system."
#9
04/15/2003 (9:30 am)
The code includes an internal offset system allowing you to give the emitter an internal rotation and position, allowing you to move around for example your player's jet emitter inside the model by modifying the datablock rather than the model or the engine code.
#10
1.) Link an emitter to my object. ( by default where will the emitter be placed? )
2.) Offset the location of that emitter.
04/15/2003 (9:35 am)
Okay, tell me if I have this straight then. I can:1.) Link an emitter to my object. ( by default where will the emitter be placed? )
2.) Offset the location of that emitter.
#11
04/15/2003 (9:41 am)
This seems a very useful code. But I cant get it to compile. I get errors regarding non presence of read/writeCompressedPoint in bitStream.h. What do you expect these functions to do? Maybe I can add in a few lines of code for the functionality without having to download the new engine code. Thanks.
#12
The original torque works like this.
Object -> node -> emitter. //However this only worked for offsets.
The current one works like this.
Object -> node -> virtual node -> emitter. //This works for offset but also for particle paths so if the objects move, all particles move along with it.
linking your emitter to your object as in LinkRotation = True; will link particle movement to the object like I said.
Offsetting the location of that emitter changes the location of the "virtual node".
Injae: read/writeCompressedPoint only transmits an Point3F.
It's possible to Transver each part seperately with
writeFloat(point.x,8); ect.
However I suggest using some kind of write/read function wich transmits the point3F as a whole if possible.
04/15/2003 (9:55 am)
Kurt: There is a series of links.The original torque works like this.
Object -> node -> emitter. //However this only worked for offsets.
The current one works like this.
Object -> node -> virtual node -> emitter. //This works for offset but also for particle paths so if the objects move, all particles move along with it.
linking your emitter to your object as in LinkRotation = True; will link particle movement to the object like I said.
Offsetting the location of that emitter changes the location of the "virtual node".
Injae: read/writeCompressedPoint only transmits an Point3F.
It's possible to Transver each part seperately with
writeFloat(point.x,8); ect.
However I suggest using some kind of write/read function wich transmits the point3F as a whole if possible.
#13
06/08/2003 (12:41 am)
Great improvement! I was able to get it to work in 1.1.2 by adding in just the write/read compressed point and supporting functions.
#14
06/09/2003 (9:03 am)
Just wanted to say this is very cool! I just tried it out and looked at the .mis file included.
#15
I know you've been asked this before, but I think it would be great it you were to submit this as a patch. I don't see any reason why we shouldn't be adding new features to Torque. As I recall, thats one of the moaning points for some...moan...it doesn't have all the gee-wiz features like the Blorbo-notso-sucko engine v321...wahh....
Anyway, I'm sure you get my point. I personally would like to see this get added. Please consider this.
-Ed Maurina
07/15/2003 (10:41 pm)
Sebastiaan,I know you've been asked this before, but I think it would be great it you were to submit this as a patch. I don't see any reason why we shouldn't be adding new features to Torque. As I recall, thats one of the moaning points for some...moan...it doesn't have all the gee-wiz features like the Blorbo-notso-sucko engine v321...wahh....
Anyway, I'm sure you get my point. I personally would like to see this get added. Please consider this.
-Ed Maurina
#16
05/05/2004 (11:37 pm)
Has any1 successfully compiled either v1.2 or latest HEAD with this patch?
#17
12/13/2004 (5:13 pm)
just implemented this with version 1.3... compiles fine with a small tweak... the new particle effects are nice, however I can't figure out how to link them to objects... anyone have a working example they can post the code on ?
#18
Particle emitters always have an object they spawn from.
Most bassically this is a ParticleEmitterNode() (wich is just a dummy object for (mostly) map based emitters), but it could be vehicles,players and projectiles.
In particleEmitter.cc you see
This is where the "particle emitter" is created for our particle emitter "node".
In player.cc you used to see this:
Notice for both cases the particle emitter gets created and then (if everything checks out) this line:
"Emitter->LinkObject = this"
This will tell the emitter what object it should link to.
Notice however that "linking" in this case, is for the new functions like linkPosition and linkRotation. This means that once the linked object moves, the particles move with it.
This is not linking in the old sense, where you link the location a particle emitter spawns it's particles to the location of an object. (To do that your going to have to look for the original way that's done)
12/13/2004 (10:23 pm)
Ok let me explain for linking objects,Particle emitters always have an object they spawn from.
Most bassically this is a ParticleEmitterNode() (wich is just a dummy object for (mostly) map based emitters), but it could be vehicles,players and projectiles.
In particleEmitter.cc you see
if (isClientObject()) {
ParticleEmitter* pEmitter = new ParticleEmitter;
pEmitter->onNewDataBlock(mEmitterDatablock);
if (pEmitter->registerObject() == false) {
Con::warnf(ConsoleLogEntry::General, "Could not register base emitter for particle of class: %s", mDataBlock->getName());
delete pEmitter;
return false;
}
mEmitter = pEmitter;
pEmitter->LinkObject = this;
}This is where the "particle emitter" is created for our particle emitter "node".
In player.cc you used to see this:
U32 i;
for( i=0; i<PlayerData::NUM_SPLASH_EMITTERS; i++ )
{
mSplashEmitter[i] = new ParticleEmitter;
mSplashEmitter[i]->onNewDataBlock( mDataBlock->splashEmitterList[i] );
if( !mSplashEmitter[i]->registerObject() )
{
Con::warnf( ConsoleLogEntry::General, "Could not register dust emitter for class: %s", mDataBlock->getName() );
delete mSplashEmitter[i];
mSplashEmitter[i] = NULL;
}
mSplashEmitter[i]->LinkObject = this;
}Notice for both cases the particle emitter gets created and then (if everything checks out) this line:
"Emitter->LinkObject = this"
This will tell the emitter what object it should link to.
Notice however that "linking" in this case, is for the new functions like linkPosition and linkRotation. This means that once the linked object moves, the particles move with it.
This is not linking in the old sense, where you link the location a particle emitter spawns it's particles to the location of an object. (To do that your going to have to look for the original way that's done)
#19
and thank you for explaining this, particles are still a shady area of coding for me, I know some c++ (still learning engine based c++) though been trying to figure out how particles work...
so linking the object affects how the particle affect will look, by moving, rotation etc? (through your link commands)... though not in the sense of a particle affect being "mounted" to a player ?
btw with your particle knowledge do you think it would be feasible to port over the mounting system of shapebase to particles, or a modified version ... I'm trying to get particles on my player and weapons...
thanks agian
12/14/2004 (6:04 am)
ahhh... for one thanks for the response, been a long time since you've submitted this so didnt think I'd get one... especially so quick..and thank you for explaining this, particles are still a shady area of coding for me, I know some c++ (still learning engine based c++) though been trying to figure out how particles work...
so linking the object affects how the particle affect will look, by moving, rotation etc? (through your link commands)... though not in the sense of a particle affect being "mounted" to a player ?
btw with your particle knowledge do you think it would be feasible to port over the mounting system of shapebase to particles, or a modified version ... I'm trying to get particles on my player and weapons...
thanks agian
#20
Instead you could write your own small mounting routine just for particle emitter nodes. I think it will be sufficient to simple make "linkObject" of the emitter that belongs to the particle emiter node equal to the object it's mounted to. (contrairy to what I said earlier, it seems particles are made to spawn from linkobject's location).
You'l need to write a small function that allows the setting of the mount for a particle emitter node and ofcourse the required update through netcode.
I'm not hunderd percent positive this will all work properly.. but it should.
So.. simply make "pEmitter->LinkObject" for a given particle emitter node equal to the object you want to mount the emitter to, and it "should' work.
12/14/2004 (6:36 am)
It's feasable, but not practical.. infact I ported over an improved version of mounting objects from shapebase to gamebase wich includes emitters. But doing such a thing is pretty involded (althought not too much) and is best left if you really want to mess around with how mounting works.Instead you could write your own small mounting routine just for particle emitter nodes. I think it will be sufficient to simple make "linkObject" of the emitter that belongs to the particle emiter node equal to the object it's mounted to. (contrairy to what I said earlier, it seems particles are made to spawn from linkobject's location).
You'l need to write a small function that allows the setting of the mount for a particle emitter node and ofcourse the required update through netcode.
I'm not hunderd percent positive this will all work properly.. but it should.
So.. simply make "pEmitter->LinkObject" for a given particle emitter node equal to the object you want to mount the emitter to, and it "should' work.

Torque 3D Owner Xavier "eXoDuS" Amado
Default Studio Name