|Version 1 (modified by osg, 7 years ago)|
Help saving particle systems to file and loading them.
If you follow the tutorial to create a particle system, you'll end up with a scene graph that looks something like the figure on the left. The Particle System (Drawable) is a child of a geode that has as it's parent the root node. The other particle system elements (Modular Program, Updater and Emitter are under a transform associated with our model. This gives us 'well behaved' particle systems: In the case of the tutorial the dust effect follows the tank around the scene. The particle system drawables are not under the vehicle transform and life is good.
If we save a cool osg effect as an osg file there is a small problem. When we load the file using osgDB::ReadNodeFile?() we get a pointer to a single node. This node has all of the elements associated with the particle effect as children. If we add this node as a child of some transform, the drawables are transformed. This results in a particle system that is not 'well behaved.'
Well behaved particle systems need to have particle system drawables that are not transformed. There are a few different ways to do this. One method would be to read the file in and get a handle to the drawables. You could then remove the drawable as a child of the node read from file and make it a child of the root node. This could get messy if you had a number of different effects and wanted to manipulate them - turn them on/off, change their ancestry in the scene, etc.
There are advantages to keeping all of the particle effects under the same node in the scene graph. The problem then is to make sure the drawables are not affected by any transforms. Once again there are a number of ways to do this. One method would be to put an 'absolute' transform above the particle system drawables. This does bad things to the culling algorithm. (Since absolute nodes always have to be traversed, all nodes above it in the scene also have to be traversed.) The following scheme seems reasonable: Create a transform that reverses the effect of all transforms above it as the parent of the particle system drawables. This is depicted in the figure on the right below. It seems to work.