Help me with particle effects

Koiu Lpoi

18-06-2006 00:38:14

Ok, So I have particle effects working in PyOgre. They're pretty and all, I can move them around OK, etc., and I really like the system overall.

However, the only way I know of stopping the particles is to call ParticleSystemManager.destroySystem on them. This causes all the particles to instantly disappear, which is not what I'm looking for. I want the particles to fade out and disappear, not instantly disappear. Basically, I want the system to just stop emitting particles, not to delete it completely.

Istari

18-06-2006 01:41:27

for i in range(particleSystem.numEmitters):
emitter = particleSystem.getEmitter(i)
emitter.enabled = False

Koiu Lpoi

18-06-2006 02:00:58

Well, I tried it out, and i get
TypeError: range() integer end argument expected, got property.

Istari

18-06-2006 02:39:19

That's strange, it works for me.
Is your code short enough to post here? If so, post it. Otherwise post the smallest code stub that still raises the exception.

Koiu Lpoi

18-06-2006 05:41:38

from pyogre import ogre
import SampleFramework
import ode
import random

class myFrameListener(SampleFramework.FrameListener):
def __init__(self,renderWindow, camera,sceneManager):
SampleFramework.FrameListener.__init__(self,renderWindow,camera)
self.sceneManager = sceneManager
self.bullets = []
self.bulletnode = []
self.zup = True
self.xup = True
self.bulletspeed = 700

def frameStarted(self,evt): #here's the main loop
inputDevice = self.inputDevice
inputDevice.capture()
self.mover = ogre.Vector3(0,0,0) #thing to hold the movement
self.move = 100 #constant of movement
if inputDevice.isKeyDown(ogre.KC_UP):
self.mover.y += self.move
if inputDevice.isKeyDown(ogre.KC_DOWN):
self.mover.y -= self.move
if inputDevice.isKeyDown(ogre.KC_LEFT):
self.mover.x -= self.move
if inputDevice.isKeyDown(ogre.KC_RIGHT):
self.mover.x += self.move
nodePlayer = self.sceneManager.getSceneNode("PlayerNode")
nodePlayer.translate(self.mover * evt.timeSinceLastFrame)

if inputDevice.isKeyDown(ogre.KC_Z) & self.zup == True:
psm = ogre.ParticleSystemManager.getSingleton()
self.bullets.append(psm.createSystem('fountain'+str(len(self.bullets)), 'Examples/JetEngine2'))
self.bulletnode.append(self.sceneManager.rootSceneNode.createChildSceneNode())
self.bulletnode[-1].attachObject(self.bullets[-1])
self.bulletnode[-1].translate(self.sceneManager.getSceneNode("PlayerNode").position+(random.sample(xrange(50,100),1)[0],random.sample(xrange(-50,50),1)[0],1))
self.zup = False
if not inputDevice.isKeyDown(ogre.KC_Z):
self.zup = True

for x in range(len(self.bullets)):
self.bulletnode[x].translate((self.bulletspeed*evt.timeSinceLastFrame,0,0))

if inputDevice.isKeyDown(ogre.KC_X)& self.xup == True:
for x in range(len(self.bullets)):
#if len(self.bullets)>0:
psm = ogre.ParticleSystemManager.getSingleton()
#psm.destroySystem('fountain'+str(len(self.bullets)-1))
#psm._destroyEmitter('fountain'+str(len(self.bullets)-1))
for i in range(ogre.ParticleSystem.numEmitters):
emitter = ogreparticleSystem.getEmitter(i)
emitter.enabled = False
self.bullets.pop()
self.bulletnode.pop()
self.xup = False
if not inputDevice.isKeyDown(ogre.KC_X):
self.xup = True



return not inputDevice.isKeyDown(ogre.KC_ESCAPE)

class InitApp(SampleFramework.Application):
def _createScene(self):
sceneManager = self.sceneManager
sceneManager.ambientLight = (0.5,0.5,0.5)

entPlayer = sceneManager.createEntity("Player","razor.mesh");
entPlayer.setMaterialName('Examples/EnvMappedRustySteel')
nodePlayer = sceneManager.rootSceneNode.createChildSceneNode("PlayerNode")
nodePlayer.attachObject(entPlayer)
nodePlayer.yaw(ogre.Degree(90))

sceneManager.setSkyBox(True, "Examples/SpaceSkyBox")

cameraNode = sceneManager.rootSceneNode.createChildSceneNode()
cameraNode.attachObject(self.camera)
cameraNode.translate(0,0,500)

def _createCamera(self):
self.camera = self.sceneManager.createCamera("PlayerCam")
self.camera.nearClipDistance = 0.1

def _createFrameListener(self):
self.frameListener = myFrameListener(self.renderWindow, self.camera,self.sceneManager)
self.root.addFrameListener(self.frameListener)
self.frameListener.showDebugOverlay(True)

def _isPsycoEnabled(self):
return False

if __name__ == "__main__":
app = InitApp()
app.go()


There's the entire code.

Note 1: I'm still a bit of a noob at this, so this requires the "sampleframework.py" from the tutorials directory, along with some of those media files.

Note 2: Hit Z to shoot a particle, hit X to stop them. The particles will shoot downward, iirc. They're supposed to go to the right, but you'd have to edit the particles file to see it that way.

dermont

18-06-2006 09:35:08

Looks like you are trying to retrieve the Emitter / Affector attributes from
ogre.ParticleSystem which is returning a type. You should be doing this from your ParticleSystem.

Since it looks like you are using pyOgre v1.0.6:

ps = psm.getSystem("Your Particle System Name")

Your code should look something like:

psm = ogre.ParticleSystemManager.getSingleton()
#psm.destroySystem('fountain'+str(len(self.bullets)-1))
#psm._destroyEmitter('fountain'+str(len(self.bullets)-1))

ps = psm.getSystem('fountain'+str(len(self.bullets)-1))
for i in range(ps.numEmitters):
emitter = ps.getEmitter(i)

...

Koiu Lpoi

18-06-2006 20:41:18

Excellent! That worked great, thanks so much!

Now, to clean up my code... it's gotten uuuuglllly...