瀏覽代碼

*** empty log message ***

Mike Goslin 25 年之前
父節點
當前提交
f099c4e7e3

+ 11 - 0
direct/src/directutil/Mopath.py

@@ -62,6 +62,17 @@ class Mopath(PandaObject):
             for child in nodePath.getChildrenAsList():
                 self.__extractCurves(child)
 
+    def getFinalState(self):
+	""" getFinalState()
+	"""
+	pos = Point3(0)
+	if (self.xyzNurbsCurve != None):
+	    self.xyzNurbsCurve.getPoint(self.maxT, pos)
+	hpr = Point3(0)
+	if (self.hprNurbsCurve != None):
+	    self.hprNurbsCurve.getPoint(self.maxT, hpr)
+	return (pos, hpr)
+
     def goTo(self, node, time):
 	if (self.xyzNurbsCurve == None) and (self.hprNurbsCurve == None):
 	    print 'Mopath: Mopath has no curves'

+ 18 - 2
direct/src/interval/Interval.py

@@ -9,13 +9,19 @@ class Interval(DirectObject):
     notify = directNotify.newCategory("Interval")
     #notify.setDebug(1)
 
+    PrevEndRelative = 1
+    PrevStartRelative = 2
+    TrackStartRelative = 3
+
     # special methods
     
-    def __init__(self, name, duration):
-        """__init__(name, duration)
+    def __init__(self, name, duration, t0 = 0.0, type = PrevEndRelative):
+        """__init__(name, duration, t0, type)
         """
 	self.name = name
 	self.duration = duration
+	self.startTime = t0
+	self.type = type
 
     def getName(self):
 	""" getName()
@@ -27,6 +33,16 @@ class Interval(DirectObject):
 	"""
 	return self.duration
 
+    def getStartTime(self):
+	""" getStartTime()
+	"""
+	return self.startTime
+
+    def getType(self):
+	""" getType()
+	"""
+	return self.type
+
     def setT(self, t):
 	""" setT(t)
 	    Go to time t

+ 6 - 11
direct/src/interval/IntervalTest.py

@@ -1,13 +1,8 @@
 from PandaModules import *
 from DirectSessionGlobal import *
-from LerpInterval import *
-from WaitInterval import *
+from IntervalGlobal import *
 
 import Mopath
-import MopathInterval
-import SoundInterval
-import Track
-import MultiTrack
 import IntervalPlayer
 
 AudioManager.spawnUpdate()
@@ -21,21 +16,21 @@ dock.reparentTo(render)
 mp = Mopath.Mopath()
 mp.loadFile(Filename('phase_6/paths/dd-e-w'))
 
-boatMopath = MopathInterval.MopathInterval('boatpath', mp, boat)
+boatMopath = MopathInterval('boatpath', mp, boat)
 
 sound = loader.loadSound('phase_6/audio/sfx/SZ_DD_waterlap.mp3')
-waterSound = SoundInterval.SoundInterval('watersound', sound)
+waterSound = SoundInterval('watersound', sound)
 
 pos = Point3(0, 0, -5)
 hpr = Vec3(0, 0, 0)
 dockLerp = LerpPosHprInterval('lerp', dock, pos, hpr, 5.0)
 
-boatTrack = Track.Track([boatMopath])
+boatTrack = Track.Track([boatMopath], 'boattrack')
 dockWaitTime = boatMopath.getDuration() - dockLerp.getDuration()
-dockTrack = Track.Track([Wait(dockWaitTime), dockLerp])
+dockTrack = Track.Track([Wait(dockWaitTime), dockLerp], 'docktrack')
 postSoundWaitTime = 3.0
 preSoundWaitTime = boatMopath.getDuration() - (waterSound.getDuration() + postSoundWaitTime)
-soundTrack = Track.Track([Wait(preSoundWaitTime), waterSound, Wait(postSoundWaitTime)])
+soundTrack = Track.Track([Wait(preSoundWaitTime), waterSound, Wait(postSoundWaitTime)], 'soundtrack')
 
 mtrack = MultiTrack.MultiTrack([boatTrack, dockTrack, soundTrack])
 

+ 15 - 14
direct/src/interval/LerpInterval.py

@@ -2,33 +2,33 @@
 
 import Interval
 import Lerp
+import PosHprInterval
 
 class LerpInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, node, duration):
-        """__init__(name, node, duration)
+    def __init__(self, name, node, duration, t0=0.0, 
+				type=Interval.Interval.PrevEndRelative):
+        """__init__(name, node, duration, t0, type)
         """
 	self.name = name
 	self.node = node	
 	self.duration = duration
-
-    def setT(self, t):
-	""" setT(t)
-	    Go to time t
-	"""
-	pass
+	self.startTime = t0
+	self.type = type
 
 class LerpPosHprInterval(LerpInterval):
 
-    def __init__(self, name, node, pos, hpr, duration, other=None,
+    def __init__(self, name, node, pos, hpr, duration, t0=0.0, 
+		type=Interval.Interval.PrevEndRelative, other=None,
 			blendType='noBlend'):
-	""" __init__(name, node, pos, hpr, duration, other, blendType)
+	""" __init__(name, node, pos, hpr, duration, t0, type, other, 
+					blendType)
 	"""
         import PosHprLerpFunctor
 
-	LerpInterval.__init__(self, name, node, duration)
+	LerpInterval.__init__(self, name, node, duration, t0, type)
 	self.pos = pos
 	self.hpr = hpr
 
@@ -52,10 +52,11 @@ class LerpPosHprInterval(LerpInterval):
     def setT(self, t):
 	""" setT(t)
 	"""
+	assert(t >= 0.0)
 	if (t > self.duration):
-	    return
-	assert(t >= 0)
-	self.lerp.setT(t)
+	    self.lerp.setT(self.duration)
+	else:
+	    self.lerp.setT(t)
 
     def __getBlend(self, blendType):
         """__getBlend(self, string)

+ 10 - 5
direct/src/interval/MopathInterval.py

@@ -2,24 +2,29 @@
 
 import Interval
 import Mopath
+import PosHprInterval
 
 class MopathInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, mopath, node):
-        """__init__(name, mopath, node)
+    def __init__(self, name, mopath, node, t0=0.0, 
+				type=Interval.Interval.PrevEndRelative):
+        """__init__(name, mopath, node, t0, type)
         """
 	self.name = name
 	self.node = node	
 	self.mopath = mopath 
 	self.duration = self.mopath.getMaxT()
+	self.startTime = t0
+	self.type = type
 
     def setT(self, t):
 	""" setT(t)
 	    Go to time t
 	"""
+	assert(t >= 0.0)
 	if (t > self.duration):
-	    return
-	assert(t >= 0)
-	self.mopath.goTo(self.node, t)
+	    self.mopath.goTo(self.node, self.duration)
+	else:
+	    self.mopath.goTo(self.node, t)

+ 13 - 12
direct/src/interval/MultiTrack.py

@@ -13,31 +13,32 @@ class MultiTrack(Interval.Interval):
         """__init__(trackList, name)
         """
 	if (name == None):
-	    self.name = 'MultiTrack-%d' % self.multiTrackNum
-	    self.multiTrackNum = self.multiTrackNum + 1
+	    self.name = 'MultiTrack-%d' % MultiTrack.multiTrackNum
+	    MultiTrack.multiTrackNum = MultiTrack.multiTrackNum + 1
 	else:
 	    self.name = name
 	self.tlist = trackList
-	self.getDuration()
+	self.duration = self.getDuration()
+	self.startTime = 0.0
+	self.type = Interval.Interval.PrevEndRelative
 
     def getDuration(self):
 	""" getDuration()
+	    Returns the duration of the longest Track 
 	"""
-	#if (len(self.tlist == 0)):
-	#    Interval.notify.warning('MultiTrack.getDuration(): no Tracks')
-	#    return 0.0
-	self.duration = self.tlist[0].getDuration()
+	duration = 0.0
 	for t in self.tlist:
-	    if (self.duration != t.getDuration()):
-		Interval.Interval.notify.warning('MultiTrack.getDuration(): tracks not all same duration')
-	return self.duration
+	    dur = t.getDuration()
+	    if (dur > duration):
+		duration = dur
+	return 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
+	    Interval.notify.warning(
+		'MultiTrack.setT(): t = %f > duration' % t)
 	for track in self.tlist:
 	    track.setT(t)

+ 5 - 5
direct/src/interval/PosHprInterval.py

@@ -8,20 +8,20 @@ class PosHprInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, node, pos, hpr, duration):
-        """__init__(name, node, pos, hpr, duration)
+    def __init__(self, name, node, pos, hpr, duration, t0=0.0,
+				type=Interval.Interval.PrevEndRelative):
+        """__init__(name, node, pos, hpr, duration, t0, type)
         """
 	self.name = name
 	self.node = node
 	self.pos = pos
 	self.hpr = hpr
 	self.duration = duration
+	self.startTime = t0
+	self.type = type
 
     def setT(self, t):
 	""" setT(t)
 	    Go to time t
 	"""
-	if (t > self.duration):
-	    return
-	assert(t >= 0)
 	self.node.setPosHpr(self.pos, self.hpr)

+ 7 - 2
direct/src/interval/SoundInterval.py

@@ -3,24 +3,29 @@
 from PandaModules import *
 
 import Interval
+import WaitInterval
 
 class SoundInterval(Interval.Interval):
 
     # special methods
     
-    def __init__(self, name, sound, loop = 0):
-        """__init__(name, sound)
+    def __init__(self, name, sound, loop=0, t0=0.0, 
+				type=Interval.Interval.PrevEndRelative):
+        """__init__(name, sound, loop, t0, type)
         """
 	self.name = name
 	self.sound = sound
 	self.duration = self.sound.length() 
 	self.loop = loop
 	self.isPlaying = 0
+	self.startTime = t0
+	self.type = type
 
     def setT(self, t):
 	""" setT(t)
 	    Go to time t
 	"""
+	print 'SoundInterval.setT(): t: %f' % t
 	if (t > self.duration):
 	    return
 	assert(t >= 0)

+ 84 - 32
direct/src/interval/Track.py

@@ -1,6 +1,7 @@
 """Track module: contains the Track class"""
 
 import Interval
+import types
 
 class Track(Interval.Interval):
 
@@ -12,54 +13,105 @@ class Track(Interval.Interval):
         """__init__(intervalList, name)
         """
 	if (name == None):
-	    self.name = 'Track-%d' % self.trackNum
-	    self.trackNum = self.trackNum + 1
+	    self.name = 'Track-%d' % Track.trackNum
+	    Track.trackNum = Track.trackNum + 1
 	else:
 	    self.name = name
+
 	self.ilist = intervalList
-	self.dlist = []
-	self.computeDuration()
+	self.duration = self.__computeDuration(len(self.ilist))
+	self.startTime = 0.0
+	self.type = Interval.Interval.PrevEndRelative
 
-    def computeDuration(self):
-	""" computeDuration()
+    def __computeDuration(self, length):
+	""" __computeDuration(length)
 	"""
-	self.duration = 0.0
-	for i in self.ilist:
-	    dur = i.getDuration()
-	    self.duration = self.duration + dur
-	    self.dlist.append(dur)
+	assert(length <= len(self.ilist))
+	duration = 0.0
+	prev = None
+	for i in self.ilist[0:length]:
+	    type = i.getType()
+	    t0 = i.getStartTime()
+	    assert(t0 >= 0.0)
+	    fillTime = t0 
+	    if (type == Interval.Interval.PrevEndRelative):
+		pass
+	    elif (type == Interval.Interval.PrevStartRelative):
+		if (prev != None):
+		    fillTime = t0 - prev.getDuration()
+	    elif (type == Interval.Interval.TrackStartRelative):
+		fillTime = t0 - duration
+	    else:
+		Interval.notify.error(
+			'Track.__computeDuration(): unknown type: %d' % type)
+	    if (fillTime < 0.0):
+		Interval.notify.error(
+			'Track.__computeDuration(): overlap detected')
+	    duration = duration + fillTime + i.getDuration()
+	    prev = i
+	return duration
 
-    def getStartTimeOf(self, name):
-	""" getStartTimeOf(name)
+    def getTrackRelativeStartTime(self, name):
+	""" getTrackRelativeStartTime(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)
+	    if (self.ilist[i].getName() == name):	
+		return self.__computeDuration(i) - self.ilist[i].getDuration()
+	Interval.notify.warning(
+		'Track.getRelativeStartTime(): no Interval named: %s' % name)
 	return 0.0
 
-    def getEndTimeOf(self, name):
-	""" getEndTimeOf(name)
+    def __getTrackRelativeStartTime(self, interval):
+	""" __getTrackRelativeStartTime(interval)
+	"""
+	return (self.__computeDuration(self.ilist.index(interval)+1) -
+			interval.getDuration())
+
+    def getTrackRelativeEndTime(self, name):
+	""" getTrackRelativeEndTime(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)
+	    if (self.ilist[i].getName() == name):	
+		return self.__computeDuration(i)
+	Interval.notify.warning(
+		'Track.getRelativeEndTime(): 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)
+	if (len(self.ilist) == 0):
+	    Interval.notify.warning('Track.setT(): track has no intervals')
 	    return
-	for i in range(len(self.dlist)):
-	    if (t <= self.dlist[i]):
-		self.ilist[i].setT(t)
+	elif (t > self.duration):
+	    # Anything beyond the end of the track is assumed to be the 
+	    # final state of the last Interval on the track
+	    self.ilist[len(self.ilist)-1].setT(t)
+	    print self.name + ': t > self.duration'
+	else:
+	    # Find out which Interval applies
+	    prev = None
+	    print self.name
+	    for i in self.ilist:
+		# Calculate the track relative start time for the interval
+		t0 = self.__getTrackRelativeStartTime(i)
+
+		# Determine if the Interval is applicable
+		if (t < t0):
+		    if (prev != None):
+			print 'in a gap at t: %f' % t
+			# Gaps between Intervals take the final state of
+			# the previous Interval
+			prev.setT(t)
+			return
+		    else:
+			Interval.Interval.notify.warning(
+				'Track.setT(): state undefined at t: %f' % t)
+			return
+		elif (t0 <= t) and (t <= t0 + i.getDuration()):
+		    print 'in interval: ' + i.getName() + ' at t: %f' % t
+		    i.setT(t - t0)
+		    return
+		prev = i
+	    print 'no intervals apply at t: %f' % t

+ 7 - 4
direct/src/interval/WaitInterval.py

@@ -10,12 +10,15 @@ class Wait(Interval.Interval):
 
     # special methods
     
-    def __init__(self, duration, name = None):
-        """__init__(duration, name)
+    def __init__(self, duration, name=None, t0=0.0,
+				type=Interval.Interval.PrevEndRelative):
+        """__init__(duration, name, t0, type)
         """
 	if (name == None):
-	    self.name = 'wait-%d' % self.waitNum
-	    self.waitNum = self.waitNum + 1
+	    self.name = 'wait-%d' % Wait.waitNum
+	    Wait.waitNum = Wait.waitNum + 1
 	else:
 	    self.name = name
 	self.duration = duration 
+	self.startTime = 0.0
+	self.type = type