Particle System Example

fletch27502

30-05-2008 20:24:13

Does anyone have any sample code of creating a particle system that they could post? I had ParticleSystems implemented in my Director Extra that I built, but the API for the ParticleSystemManager seems to have changed. I've searched around but really haven't found any info on the subject. TIA, Scott

El_Zorro

31-05-2008 22:48:50

Hi,

Here is the ported code of the Ogre3D ParticleFX sample to work with MOGRE.

It creates five particle systems and an Ogre head. One of them rotates around the head.

using System;
using Mogre;

namespace Demo.ParticleFX
{
class ParticleApplication : Mogre.Demo.ExampleApplication.Example
{
SceneNode mFountainNode;

// Just override the mandatory create scene method
public override void CreateScene()
{
// Set ambient light
this.sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f);
Entity ent = sceneMgr.CreateEntity("head", "ogrehead.mesh");

// Add entity to the root scene node
sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(ent);


// Create some nice fireworks
sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(
sceneMgr.CreateParticleSystem("Fireworks", "Examples/Fireworks"));

// Create shared node for 2 fountains
mFountainNode = sceneMgr.RootSceneNode.CreateChildSceneNode();

// fountain 1
ParticleSystem pSys2 = sceneMgr.CreateParticleSystem("fountain1",
"Examples/PurpleFountain");
// Point the fountain at an angle
SceneNode fNode = mFountainNode.CreateChildSceneNode();
fNode.Translate(200, -100, 0);
fNode.Rotate(Vector3.UNIT_Z, new Degree(20));
fNode.AttachObject(pSys2);

// fountain 2
ParticleSystem pSys3 = sceneMgr.CreateParticleSystem("fountain2",
"Examples/PurpleFountain");
// Point the fountain at an angle
fNode = mFountainNode.CreateChildSceneNode();
fNode.Translate(-200, -100, 0);
fNode.Rotate(Vector3.UNIT_Z, new Degree(-20));
fNode.AttachObject(pSys3);

// Create a rainstorm
ParticleSystem pSys4 = sceneMgr.CreateParticleSystem("rain",
"Examples/Rain");
SceneNode rNode = sceneMgr.RootSceneNode.CreateChildSceneNode();
rNode.Translate(0, 1000, 0);
rNode.AttachObject(pSys4);
// Fast-forward the rain so it looks more natural
pSys4.FastForward(5);

// Aureola around Ogre perpendicular to the ground
ParticleSystem pSys5 = sceneMgr.CreateParticleSystem("Aureola",
"Examples/Aureola");
sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(pSys5);

// Set nonvisible timeout
ParticleSystem.DefaultNonVisibleUpdateTimeout = 5;
}

protected override void HandleInput(FrameEvent evt)
{
base.HandleInput(evt);
if (shutDown) return;
mFountainNode.Yaw(new Degree(evt.timeSinceLastFrame * 30));
}
}
}


The particle scripts are in the media\particle directory of MOGRE directory.

This class extends from Mogre.Demo.ExampleApplication.Example so you should add that reference to your project.

RcALTIN

03-09-2012 19:24:11

I know this is very old topic but i have a problem related with these example code.

Firstly I added particle_fx plugin to mogre system, after this, I defined the particle directory in my resources.cfg as "../../Media/particle". Then i placed particle files from SDK to the defined directory, but i have got "SEHException" error when ParticleSystem instance line is compiling. Because given template name never found, although its already defined in resource.cfg and already exists its container .particle file in media/particle/ directory...

In ogre.log it explanied like this :
OGRE EXCEPTION(2:InvalidParametersException): Cannot find required template 'Examples/Rain' in ParticleSystemManager::createSystem at ..\..\ogre\OgreMain\src\OgreParticleSystemManager.cpp (line 327)

what is the problem, any idea?

(I'm using Mogre 1.7.1 Net4 version)

RcALTIN

06-09-2012 13:06:18

i found the problem, at least a fixing method. it is lack of "particle_system" keyword in .particle files...(i dont know why the creator of file didn't add this keyword for every particle definitions, probably there is another calling method for particles which i don't know)

fixed Example.particle file:
// Example particle systems

// Exudes greeny particles which float upwards
particle_system Examples/GreenyNimbus
{
material Examples/FlarePointSprite
point_rendering true
// point rendering means size is controlled by material
// provide fallback sizes for hardware that doesn't support point sprite
particle_width 30
particle_height 30
cull_each false
cull_each false
quota 10000
billboard_type point

// Area emitter
emitter Box
{
angle 30
emission_rate 30
time_to_live 5
direction 0 1 0
velocity 0
colour_range_start 1 1 0
colour_range_end 0.3 1 0.3
width 60
height 60
depth 60
}

// Make em float upwards
affector LinearForce
{
force_vector 0 100 0
force_application add
}

// Fader
affector ColourFader
{
red -0.25
green -0.25
blue -0.25
}


}

// A sparkly purple fountain
particle_system Examples/PurpleFountain
{
material Examples/Flare2
particle_width 20
particle_height 40
cull_each false
quota 10000
billboard_type oriented_self

// Area emitter
emitter Point
{
angle 15
emission_rate 75
time_to_live 3
direction 0 1 0
velocity_min 250
velocity_max 300
colour_range_start 0 0 0
colour_range_end 1 1 1
}

// Gravity
affector LinearForce
{
force_vector 0 -100 0
force_application add
}

// Fader
affector ColourFader
{
red -0.25
green -0.25
blue -0.25
}
}


// A downpour
particle_system Examples/Rain
{
material Examples/Droplet
particle_width 20
particle_height 100
cull_each true
quota 10000
// Make common direction straight down (faster than self oriented)
billboard_type oriented_common
common_direction 0 -1 0

// Area emitter
emitter Box
{
angle 0
emission_rate 100
time_to_live 5
direction 0 -1 0
velocity 50
colour_range_start 0.3 1 0.3
colour_range_end 0.7 1 0.7
width 1000
height 1000
depth 0
}

// Gravity
affector LinearForce
{
force_vector 0 -200 0
force_application add
}

}

// A jet engine (of sorts)
particle_system Examples/JetEngine1
{
material Examples/Flare
particle_width 25
particle_height 25
cull_each false
quota 200
billboard_type point

emitter Point
{
angle 5
emission_rate 100
time_to_live 1
direction 0 -1 0
velocity_min 250
velocity_max 300
colour_range_start 1 1 0.5
colour_range_end 1 0.8 0.3

}
affector ColourFader
{
red -0.25
green -1
blue -1
}

}
particle_system Examples/JetEngine2
{
material Examples/Flare
particle_width 15
particle_height 15
cull_each false
quota 200
billboard_type point

emitter Point
{
angle 3
emission_rate 100
time_to_live 1
direction 0 -1 0
velocity_min 350
velocity_max 400
colour_range_start 0.5 1 1
colour_range_end 0.3 0.8 1

}
affector ColourFader
{
red -1
green -1
blue -0.5
}

}

// Exudes aureola particles which around the model float upwards
particle_system Examples/Aureola
{
material Examples/Aureola
particle_width 200
particle_height 200
cull_each false
quota 100
billboard_type perpendicular_common
common_direction 0 1 0
common_up_vector 0 0 1

// Area emitter
emitter Box
{
angle 30
emission_rate 4
time_to_live 5
position 0 -100 0
direction 0 1 0
velocity_min 0
velocity_max 30
colour_range_start 0.3 0.3 0.3 0.0
colour_range_end 0.8 0.8 0.8 0.0
width 10
height 10
depth 30
}

// Make em float upwards
affector LinearForce
{
force_vector 0 70 0
force_application add
}

// Fader
affector ColourFader2
{
red1 +0.4
green1 +0.4
blue1 +0.4
alpha1 +0.7

red2 -0.25
green2 -0.25
blue2 -0.25
alpha2 -0.3333

state_change 3.5
}

// Rotater
affector Rotator
{
rotation_range_start 0
rotation_range_end 360
rotation_speed_range_start 0
rotation_speed_range_end 180
}
}


particle_system Examples/Swarm
{
quota 3000
material Examples/Flare2
particle_width 12
particle_height 24
cull_each true
renderer billboard
sorted true
local_space false
billboard_type oriented_self

emitter Box
{
angle 180
colour 1 1 1 1
colour_range_start 1 1 1 1
colour_range_end 1 1 1 1
direction 0 1 0
emission_rate 30
position 0 0 0
velocity 50
velocity_min 50
velocity_max 1
time_to_live 20
time_to_live_min 20
time_to_live_max 20
duration 0
duration_min 0
duration_max 0
repeat_delay 0
repeat_delay_min 0
repeat_delay_max 0
width 80
height 80
depth 80
}

affector ColourFader
{
red -0.05
green 0
blue 0
alpha 0
}

affector DeflectorPlane
{
plane_point 0 -50 0
plane_normal 0 1 0
bounce 1
}

affector DeflectorPlane
{
plane_point 0 50 0
plane_normal 0 -1 0
bounce 1
}

affector DeflectorPlane
{
plane_point 50 0 0
plane_normal -1 0 0
bounce 1
}

affector DeflectorPlane
{
plane_point -50 0 0
plane_normal 1 0 0
bounce 1
}

affector DeflectorPlane
{
plane_point 0 0 50
plane_normal 0 0 -1
bounce 1
}

affector DeflectorPlane
{
plane_point 0 0 -50
plane_normal 0 0 1
bounce 1
}

affector DirectionRandomiser
{
randomness 60
}
}


particle_system Examples/Snow
{
quota 2000
material Examples/Flare
particle_width 4
particle_height 4
cull_each true
renderer billboard
sorted true
local_space false
billboard_type point

emitter Box
{
angle 0
colour 1 1 1 1
colour_range_start 1 1 1 1
colour_range_end 1 1 1 1
direction 0 -1 0
emission_rate 100
position 0 200 0
velocity 20
velocity_min 20
velocity_max 20
time_to_live 20
time_to_live_min 20
time_to_live_max 20
duration 0
duration_min 0
duration_max 0
repeat_delay 0
repeat_delay_min 0
repeat_delay_max 0
width 200
height 200
depth 1
}

affector DeflectorPlane
{
plane_point 0 0 0
plane_normal 0 1 0
bounce 0
}

affector DirectionRandomiser
{
randomness 10
}
}