mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
intermediate/remedial checkin
This commit is contained in:
parent
d202b5e0e2
commit
13ff6084fb
@ -9,52 +9,21 @@ from Interval import Interval
|
|||||||
from direct.particles import ParticleEffect
|
from direct.particles import ParticleEffect
|
||||||
|
|
||||||
class ParticleInterval(Interval):
|
class ParticleInterval(Interval):
|
||||||
"""
|
|
||||||
Use this interval when you want to have greater control over a
|
|
||||||
ParticleEffect. The interval does not register the effect with
|
|
||||||
the global particle and physics managers, but it does call upon
|
|
||||||
them to perform its stepping. You should NOT call
|
|
||||||
particleEffect.start() with an effect that is being controlled
|
|
||||||
by a ParticleInterval.
|
|
||||||
"""
|
|
||||||
# Name counter
|
# Name counter
|
||||||
particleNum = 1
|
particleNum = 1
|
||||||
# create ParticleInterval DirectNotify category
|
# create ParticleInterval DirectNotify category
|
||||||
notify = directNotify.newCategory('ParticleInterval')
|
notify = directNotify.newCategory('ParticleInterval')
|
||||||
# Class methods
|
# Class methods
|
||||||
def __init__(self,
|
def __init__(self, particleEffect, parent, worldRelative=1, loop=0,
|
||||||
particleEffect,
|
duration=0.0, name=None, cleanup = False):
|
||||||
parent,
|
"""
|
||||||
worldRelative = 1,
|
particleEffect is ??
|
||||||
renderParent = None,
|
parent is ??
|
||||||
duration = 0.0,
|
worldRelative is a boolean
|
||||||
softStopT = 0.0,
|
loop is a boolean
|
||||||
cleanup = False,
|
duration is a float for the time
|
||||||
name = None):
|
name is ??
|
||||||
"""
|
"""
|
||||||
particleEffect is a ParticleEffect
|
|
||||||
parent is a NodePath: this is where the effect will be
|
|
||||||
parented in the scenegraph
|
|
||||||
worldRelative is a boolean: this will override 'renderParent'
|
|
||||||
with render
|
|
||||||
renderParent is a NodePath: this is where the particles will
|
|
||||||
be rendered in the scenegraph
|
|
||||||
duration is a float for the time
|
|
||||||
softStopT is a float: no effect if 0.0,
|
|
||||||
a positive value will count from the
|
|
||||||
start of the interval,
|
|
||||||
a negative value will count from the
|
|
||||||
end of the interval
|
|
||||||
|
|
||||||
cleanup is a boolean: if True the effect will be destroyed
|
|
||||||
and removed from the scenegraph upon
|
|
||||||
interval completion
|
|
||||||
set to False if planning on reusing
|
|
||||||
the interval
|
|
||||||
name is a string: use this for unique intervals so that
|
|
||||||
they can be easily found in the taskMgr
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Generate unique name
|
# Generate unique name
|
||||||
id = 'Particle-%d' % ParticleInterval.particleNum
|
id = 'Particle-%d' % ParticleInterval.particleNum
|
||||||
ParticleInterval.particleNum += 1
|
ParticleInterval.particleNum += 1
|
||||||
@ -62,72 +31,49 @@ class ParticleInterval(Interval):
|
|||||||
name = id
|
name = id
|
||||||
# Record instance variables
|
# Record instance variables
|
||||||
self.particleEffect = particleEffect
|
self.particleEffect = particleEffect
|
||||||
self.cleanup = cleanup
|
self.parent = parent
|
||||||
|
self.worldRelative = worldRelative
|
||||||
if parent != None:
|
self.fLoop = loop
|
||||||
self.particleEffect.reparentTo(parent)
|
assert duration > 0.0 or loop == 1
|
||||||
if worldRelative:
|
|
||||||
renderParent = render
|
|
||||||
if renderParent:
|
|
||||||
for particles in self.particleEffect.getParticlesList():
|
|
||||||
particles.setRenderParent(renderParent.node())
|
|
||||||
|
|
||||||
if softStopT == 0.0:
|
|
||||||
self.softStopT = duration
|
|
||||||
elif softStopT < 0.0:
|
|
||||||
self.softStopT = duration+softStopT
|
|
||||||
else:
|
|
||||||
self.softStopT = softStopT
|
|
||||||
|
|
||||||
# Initialize superclass
|
# Initialize superclass
|
||||||
Interval.__init__(self, name, duration)
|
Interval.__init__(self, name, duration)
|
||||||
|
|
||||||
def __step(self,dt):
|
def __del__(self):
|
||||||
if self.particleEffect:
|
if self.particleEffect:
|
||||||
self.particleEffect.accelerate(dt,1,0.05)
|
self.particleEffect.cleanup()
|
||||||
|
self.particleEffect = None
|
||||||
def __softStart(self):
|
|
||||||
if self.particleEffect:
|
|
||||||
self.particleEffect.softStart()
|
|
||||||
self.__softStopped = False
|
|
||||||
|
|
||||||
def __softStop(self):
|
|
||||||
if self.particleEffect:
|
|
||||||
self.particleEffect.softStop()
|
|
||||||
self.__softStopped = True
|
|
||||||
|
|
||||||
|
|
||||||
def privInitialize(self, t):
|
def privInitialize(self, t):
|
||||||
if self.state != CInterval.SPaused:
|
renderParent = None
|
||||||
# Restarting from a hard stop or just interrupting the
|
if self.worldRelative:
|
||||||
# current play
|
renderParent = render
|
||||||
self.__softStart()
|
|
||||||
if self.particleEffect:
|
|
||||||
self.particleEffect.clearToInitial()
|
|
||||||
self.currT = 0
|
|
||||||
|
|
||||||
if self.particleEffect:
|
if self.particleEffect:
|
||||||
for forceGroup in self.particleEffect.getForceGroupList():
|
self.particleEffect.start(self.parent, renderParent)
|
||||||
forceGroup.enable()
|
self.state = CInterval.SStarted
|
||||||
|
self.currT = t
|
||||||
Interval.privInitialize(self,t)
|
|
||||||
|
|
||||||
def privStep(self, t):
|
def privStep(self, t):
|
||||||
if self.state == CInterval.SPaused or t < self.currT:
|
if self.state == CInterval.SPaused:
|
||||||
# Restarting from a pause.
|
# Restarting from a pause.
|
||||||
self.privInitialize(t)
|
self.privInitialize(t)
|
||||||
else:
|
else:
|
||||||
if not self.__softStopped and t > self.softStopT:
|
self.state = CInterval.SStarted
|
||||||
self.__step(self.softStopT-self.currT)
|
self.currT = t
|
||||||
self.__softStop()
|
|
||||||
self.__step(t-self.softStopT)
|
|
||||||
else:
|
|
||||||
self.__step(t-self.currT)
|
|
||||||
Interval.privStep(self,t)
|
|
||||||
|
|
||||||
def privFinalize(self):
|
def privFinalize(self):
|
||||||
Interval.privFinalize(self)
|
if self.particleEffect:
|
||||||
if self.cleanup and self.particleEffect:
|
|
||||||
self.particleEffect.cleanup()
|
self.particleEffect.cleanup()
|
||||||
self.particleEffect = None
|
self.particleEffect = None
|
||||||
|
self.currT = self.getDuration()
|
||||||
|
self.state = CInterval.SFinal
|
||||||
|
|
||||||
|
def privInstant(self):
|
||||||
|
if self.particleEffect:
|
||||||
|
self.particleEffect.cleanup()
|
||||||
|
self.particleEffect = None
|
||||||
|
self.currT = self.getDuration()
|
||||||
|
self.state = CInterval.SFinal
|
||||||
|
|
||||||
|
def privInterrupt(self):
|
||||||
|
self.particleEffect.disable()
|
||||||
|
self.state = CInterval.SPaused
|
||||||
|
Loading…
x
Reference in New Issue
Block a user