ソースを参照

*** empty log message ***

Mike Goslin 25 年 前
コミット
1b261fc21f

+ 1 - 0
direct/src/configfiles/direct.pth

@@ -9,6 +9,7 @@ src/distributed
 src/ffi
 src/fsm
 src/gui
+src/interval
 src/leveleditor
 src/net
 src/particles

+ 34 - 0
direct/src/interval/Interval.py

@@ -0,0 +1,34 @@
+"""Interval module: contains the Interval class"""
+
+from DirectObject import *
+
+class Interval(DirectObject):
+    """Interval class: Base class for timeline functionality"""
+
+    # create Interval DirectNotify category
+    notify = directNotify.newCategory("Interval")
+    #notify.setDebug(1)
+
+    # special methods
+    
+    def __init__(self, name, duration):
+        """__init__(name, duration)
+        """
+	self.name = name
+	self.duration = duration
+
+    def getName(self):
+	""" getName()
+	"""
+	return self.name
+
+    def getDuration(self):
+	""" getDuration()
+	"""
+	return self.duration
+
+    def setT(self, t):
+	""" setT(t)
+	    Go to time t
+	"""
+	pass

+ 25 - 0
direct/src/interval/IntervalTest.py

@@ -0,0 +1,25 @@
+from PandaModules import *
+from DirectSessionGlobal import *
+from LerpInterval import *
+
+import Mopath
+import MopathInterval
+import SoundInterval
+import Track
+
+AudioManager.spawnUpdate()
+
+smiley = loader.loadModel('models/directmodels/smiley')
+smiley.reparentTo(render)
+
+mp = Mopath.Mopath()
+mp.loadFile(Filename('phase_6/paths/dd-e-w'))
+
+mpi = MopathInterval.MopathInterval('boatpath', mp, smiley)
+
+sound = loader.loadSound('phase_6/audio/sfx/SZ_DD_waterlap.mp3')
+si = SoundInterval.SoundInterval('watersound', sound)
+
+pos = Point3(0, 0, -5)
+hpr = Vec3(0, 0, 0)
+li = LerpPosHprInterval('lerp', smiley, pos, hpr, 5.0)

+ 79 - 0
direct/src/interval/LerpInterval.py

@@ -0,0 +1,79 @@
+"""LerpInterval module: contains the LerpInterval class"""
+
+import Interval
+import Lerp
+
+class LerpInterval(Interval.Interval):
+
+    # special methods
+    
+    def __init__(self, name, node, duration):
+        """__init__(name, node, duration)
+        """
+	self.name = name
+	self.node = node	
+	self.duration = duration
+
+    def setT(self, t):
+	""" setT(t)
+	    Go to time t
+	"""
+	pass
+
+class LerpPosHprInterval(LerpInterval):
+
+    def __init__(self, name, node, pos, hpr, duration, other=None,
+			blendType='noBlend'):
+	""" __init__(name, node, pos, hpr, duration, other, blendType)
+	"""
+        import PosHprLerpFunctor
+
+	LerpInterval.__init__(self, name, node, duration)
+	self.pos = pos
+	self.hpr = hpr
+
+        if (other != None):
+            # lerp wrt other
+            startPos = self.node.getPos(other)
+            startHpr = self.node.getHpr(other)
+            functor = PosHprLerpFunctor.PosHprLerpFunctor(
+                    self.node, startPos, pos,
+                    startHpr, hpr, other)
+        else:
+            startPos = self.node.getPos()
+            startHpr = self.node.getHpr()
+            functor = PosHprLerpFunctor.PosHprLerpFunctor(
+                    self.node, startPos, pos,
+                    startHpr, hpr)
+
+	self.blendType = self.__getBlend(blendType)
+	self.lerp = Lerp.Lerp(functor, self.duration, self.blendType)
+	self.lastT = 0.0
+
+    def setT(self, t):
+	""" setT(t)
+	"""
+	if (t > self.duration):
+	    return
+	assert(t >= 0)
+	tt = t - self.lastT
+	self.lastT = t
+	self.lerp.setStepSize(tt)
+	self.lerp.step()
+
+    def __getBlend(self, blendType):
+        """__getBlend(self, string)
+        Return the C++ blend class corresponding to blendType string
+        """
+        import LerpBlendHelpers
+
+        if (blendType == "easeIn"):
+            return LerpBlendHelpers.LerpBlendHelpers.easeIn
+        elif (blendType == "easeOut"):
+            return LerpBlendHelpers.LerpBlendHelpers.easeOut
+        elif (blendType == "easeInOut"):
+            return LerpBlendHelpers.LerpBlendHelpers.easeInOut
+        elif (blendType == "noBlend"):
+            return LerpBlendHelpers.LerpBlendHelpers.noBlend
+        else:
+            raise Exception("Error: NodePath.__getBlend: Unknown blend type")

+ 25 - 0
direct/src/interval/MopathInterval.py

@@ -0,0 +1,25 @@
+"""MopathInterval module: contains the MopathInterval class"""
+
+import Interval
+import Mopath
+
+class MopathInterval(Interval.Interval):
+
+    # special methods
+    
+    def __init__(self, name, mopath, node):
+        """__init__(name, mopath, node)
+        """
+	self.name = name
+	self.node = node	
+	self.mopath = mopath 
+	self.duration = self.mopath.getMaxT()
+
+    def setT(self, t):
+	""" setT(t)
+	    Go to time t
+	"""
+	if (t > self.duration):
+	    return
+	assert(t >= 0)
+	self.mopath.goTo(self.node, t)

+ 36 - 0
direct/src/interval/MultiTrack.py

@@ -0,0 +1,36 @@
+"""MultiTrack module: contains the MultiTrack class"""
+
+import Interval
+import Track
+
+class MultiTrack(Interval.Interval):
+
+    # special methods
+    
+    def __init__(self, name, trackList):
+        """__init__(name, trackList)
+        """
+	self.name = name
+	self.tlist = trackList
+	self.getDuration()
+
+    def getDuration(self):
+	""" getDuration()
+	"""
+	if (len(self.tlist == 0):
+	    Interval.notify.warning('MultiTrack.getDuration(): no Tracks')
+	    return 0.0
+	self.duration = self.tlist[0].getDuration()
+	for t in self.tlist:
+	    assert(self.duration = t.getDuration())
+	return self.duration
+
+    def setT(self, t):
+	""" setT(t)
+	    Go to time t
+	"""
+	if (t > self.duration):
+	    Interval.notify.warning('MultiTrack.setT(): t = %f > duration' % t)
+	    return
+	for track in self.tlist:
+	    track.setT(t)

+ 34 - 0
direct/src/interval/SoundInterval.py

@@ -0,0 +1,34 @@
+"""SoundInterval module: contains the SoundInterval class"""
+
+from PandaModules import *
+
+import Interval
+
+class SoundInterval(Interval.Interval):
+
+    # special methods
+    
+    def __init__(self, name, sound, loop = 0):
+        """__init__(name, sound)
+        """
+	self.name = name
+	self.sound = sound
+	self.duration = self.sound.length() 
+	self.loop = loop
+	self.isPlaying = 0
+
+    def setT(self, t):
+	""" setT(t)
+	    Go to time t
+	"""
+	if (t > self.duration):
+	    return
+	assert(t >= 0)
+	if (t == 0):
+	    AudioManager.play(self.sound)
+	    if (self.loop):
+		AudioManager.setLoop(self.sound, 1)
+	elif (self.loop) and (self.isPlaying == 0):
+	    AudioManager.play(self.sound)
+	    AudioManager.setLoop(self.sound, 1)
+	    self.isPlaying = 1

+ 60 - 0
direct/src/interval/Track.py

@@ -0,0 +1,60 @@
+"""Track module: contains the Track class"""
+
+import Interval
+
+class Track(Interval.Interval):
+
+    # special methods
+    
+    def __init__(self, name, intervalList):
+        """__init__(name, intervalList)
+        """
+	self.name = name
+	self.ilist = intervalList
+	self.dlist = []
+	self.getDuration()
+
+    def getDuration(self):
+	""" getDuration()
+	"""
+	self.duration = 0.0
+	for i in self.ilist:
+	    dur = i.getDuration()
+	    self.duration = self.duration + dur
+	    self.dlist.append(dur)
+	return self.duration
+
+    def getStartTimeOf(self, name):
+	""" getStartTimeOf(name)
+	"""
+	t = 0.0
+	for i in range(len(self.ilist)):
+	    if (self.ilist[i].getName() == name):
+		return t 
+	    t = t + self.dlist[i]
+	Interval.notify.warning('Track.getStartOf(): no Interval named: %s' %
+					name)
+	return 0.0
+
+    def getEndTimeOf(self, name):
+	""" getEndTimeOf(name)
+	"""
+	t = 0.0
+	for i in range(len(self.ilist)):
+	    t = t + self.dlist[i]
+	    if (self.ilist[i].getName() == name):
+		return t 
+	Interval.notify.warning('Track.getStartOf(): no Interval named: %s' %
+					name)
+	return 0.0
+
+    def setT(self, t):
+	""" setT(t)
+	    Go to time t
+	"""
+	if (t > self.duration):
+	    Interval.notify.warning('Track.setT(): t = %f > duration' % t)
+	    return
+	for i in range(len(self.dlist)):
+	    if (t <= self.dlist[i]):
+		self.ilist[i].setT(t)