Create particles per code [SOLVED]

Coolzero

21-03-2010 08:35:53

Hi,
i work with VB 2008 Express and Mogre v1.4.8, so far so good.
Now i want to insert particle effects like smoke, but won't use script files (*.particle)
I'm using following code to create the particlesystem and the emitter:

Shared Function Smoke1(ByVal scene As Mogre.SceneManager) As Boolean
Dim ps As New Mogre.ParticleSystem()

ps.ParticleQuota = 500 'Maximale Anzahl an Partikeln die erzeugt werden
ps.Visible = True

ps.DefaultWidth = 5
ps.DefaultHeight = 5

'Emitter dem PartikelSystem hinzuf├╝gen
ps.AddEmitter("Point")

'Emitter Eigenschaften festlegen
With ps.GetEmitter(CUShort(0))
.Name = "SmokeEmitter"
.SetColour(Mogre.ColourValue.Blue, Mogre.ColourValue.Red)
.ParticleVelocity = 5
.Direction = New Mogre.Vector3(0, 1, 0)
.Position = New Mogre.Vector3(-2, 32, 2)
.MinParticleVelocity = 6 'minimal Geschwindigkeit der Partikel
.MaxParticleVelocity = 8 'maximal Geschwindigkeit der Partikel
.Angle = 0.25 'maximaler Winkel in dem die Partikel ausgesendet werden
.TimeToLive = 4 'Lebenszeit eines Partikels in Sekunden
End With

ps.AddAffector("ColourImage")
ps.GetAffector(CUShort(0)).SetParameter("image", "smoke.png")

'das ParticleSystem der Szene zuweisen
scene.RootSceneNode.CreateChildSceneNode().AttachObject(ps)
Return True
End Function


But the emitted particles need a texture too :wink:, and here is my problem. I know to add a texture i must use the affector ColourImage.
But how can i set the texture :?:. ps.GetAffector(CUShort(0)).SetParameter("image", "smoke.png") doesn't seems to be working here.
Can some one help me please ?

thx

smiley80

21-03-2010 12:03:25

You have to create a material for the particle system.
"ColourImage" only affects the colour of that material.


MaterialPtr mat = MaterialManager.Singleton.Create("mat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
Pass p = mat.GetTechnique(0).GetPass(0);
p.SetSceneBlending(SceneBlendType.SBT_TRANSPARENT_ALPHA);
p.DepthWriteEnabled = false;
p.LightingEnabled = false;
p.CreateTextureUnitState("smoke.png");

ParticleSystem ps = sceneMgr.CreateParticleSystem("Smoke");
ps.ParticleQuota = 500;
ps.Visible = true;
ps.CullIndividually = true;
ps.DefaultWidth = 5;
ps.DefaultHeight = 5;
ps.MaterialName = mat.Name;

ParticleEmitter pe = ps.AddEmitter("Point");
pe.Name = "SmokeEmitter";
pe.ParticleVelocity = 5;
pe.Direction = new Mogre.Vector3(0, 1, 0);
pe.Position = new Mogre.Vector3(-2, 32, 2);
pe.MinParticleVelocity = 6;
pe.MaxParticleVelocity = 8;
pe.Angle = 0.25f;
pe.TimeToLive = 4;

ps.AddAffector("ColourImage").SetParameter("image", "smokecolors.png");

sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(ps);

Coolzero

21-03-2010 15:36:02

Thank's for your reply.
Your example works fine for me :mrgreen: (after converting to vb code :wink: )

Here is the VB version:

Shared Function Smoke1(ByVal scene As Mogre.SceneManager) As Boolean
Dim MAT_Smoke1 As MaterialPtr = MaterialManager.Singleton.Create("MAT_Smoke1", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME)
Dim p As Pass = MAT_Smoke1.GetTechnique(CUShort(0)).GetPass(CUShort(0))
p.SetSceneBlending(SceneBlendFactor.SBF_ONE)
p.DepthWriteEnabled = False
p.LightingEnabled = False
p.CreateTextureUnitState("smoke.png")

Dim ps As New ParticleSystem()

ps.MaterialName = MAT_Smoke1.Name

ps.ParticleQuota = 500 'Maximale Anzahl an Partikeln die erzeugt werden
ps.Visible = True

ps.DefaultWidth = 5
ps.DefaultHeight = 5

'Emitter dem PartikelSystem hinzuf├╝gen
ps.AddEmitter("Point")

'Emitter Eigenschaften festlegen
With ps.GetEmitter(CUShort(0))
.Name = "SmokeEmitter"
.Direction = New Vector3(0, 1, 0)
.Position = New Vector3(-2, 32, 2)
.MinParticleVelocity = 6 'minimal Geschwindigkeit der Partikel
.MaxParticleVelocity = 7 'maximal Geschwindigkeit der Partikel
.Angle = 0.3 'maximaler Winkel in dem die Partikel ausgesendet werden
.TimeToLive = 4 'Lebenszeit eines Partikels in Sekunden
End With

ps.AddAffector("Scaler")
ps.GetAffector(CUShort(0)).SetParameter("rate", "1.3")

'das ParticleSystem der Szene zuweisen
scene.RootSceneNode.CreateChildSceneNode().AttachObject(ps)
Return True
End Function