mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
*** empty log message ***
This commit is contained in:
parent
2fe7c24618
commit
f099c4e7e3
@ -62,6 +62,17 @@ class Mopath(PandaObject):
|
|||||||
for child in nodePath.getChildrenAsList():
|
for child in nodePath.getChildrenAsList():
|
||||||
self.__extractCurves(child)
|
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):
|
def goTo(self, node, time):
|
||||||
if (self.xyzNurbsCurve == None) and (self.hprNurbsCurve == None):
|
if (self.xyzNurbsCurve == None) and (self.hprNurbsCurve == None):
|
||||||
print 'Mopath: Mopath has no curves'
|
print 'Mopath: Mopath has no curves'
|
||||||
|
@ -9,13 +9,19 @@ class Interval(DirectObject):
|
|||||||
notify = directNotify.newCategory("Interval")
|
notify = directNotify.newCategory("Interval")
|
||||||
#notify.setDebug(1)
|
#notify.setDebug(1)
|
||||||
|
|
||||||
|
PrevEndRelative = 1
|
||||||
|
PrevStartRelative = 2
|
||||||
|
TrackStartRelative = 3
|
||||||
|
|
||||||
# special methods
|
# special methods
|
||||||
|
|
||||||
def __init__(self, name, duration):
|
def __init__(self, name, duration, t0 = 0.0, type = PrevEndRelative):
|
||||||
"""__init__(name, duration)
|
"""__init__(name, duration, t0, type)
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
self.startTime = t0
|
||||||
|
self.type = type
|
||||||
|
|
||||||
def getName(self):
|
def getName(self):
|
||||||
""" getName()
|
""" getName()
|
||||||
@ -27,6 +33,16 @@ class Interval(DirectObject):
|
|||||||
"""
|
"""
|
||||||
return self.duration
|
return self.duration
|
||||||
|
|
||||||
|
def getStartTime(self):
|
||||||
|
""" getStartTime()
|
||||||
|
"""
|
||||||
|
return self.startTime
|
||||||
|
|
||||||
|
def getType(self):
|
||||||
|
""" getType()
|
||||||
|
"""
|
||||||
|
return self.type
|
||||||
|
|
||||||
def setT(self, t):
|
def setT(self, t):
|
||||||
""" setT(t)
|
""" setT(t)
|
||||||
Go to time t
|
Go to time t
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
from PandaModules import *
|
from PandaModules import *
|
||||||
from DirectSessionGlobal import *
|
from DirectSessionGlobal import *
|
||||||
from LerpInterval import *
|
from IntervalGlobal import *
|
||||||
from WaitInterval import *
|
|
||||||
|
|
||||||
import Mopath
|
import Mopath
|
||||||
import MopathInterval
|
|
||||||
import SoundInterval
|
|
||||||
import Track
|
|
||||||
import MultiTrack
|
|
||||||
import IntervalPlayer
|
import IntervalPlayer
|
||||||
|
|
||||||
AudioManager.spawnUpdate()
|
AudioManager.spawnUpdate()
|
||||||
@ -21,21 +16,21 @@ dock.reparentTo(render)
|
|||||||
mp = Mopath.Mopath()
|
mp = Mopath.Mopath()
|
||||||
mp.loadFile(Filename('phase_6/paths/dd-e-w'))
|
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')
|
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)
|
pos = Point3(0, 0, -5)
|
||||||
hpr = Vec3(0, 0, 0)
|
hpr = Vec3(0, 0, 0)
|
||||||
dockLerp = LerpPosHprInterval('lerp', dock, pos, hpr, 5.0)
|
dockLerp = LerpPosHprInterval('lerp', dock, pos, hpr, 5.0)
|
||||||
|
|
||||||
boatTrack = Track.Track([boatMopath])
|
boatTrack = Track.Track([boatMopath], 'boattrack')
|
||||||
dockWaitTime = boatMopath.getDuration() - dockLerp.getDuration()
|
dockWaitTime = boatMopath.getDuration() - dockLerp.getDuration()
|
||||||
dockTrack = Track.Track([Wait(dockWaitTime), dockLerp])
|
dockTrack = Track.Track([Wait(dockWaitTime), dockLerp], 'docktrack')
|
||||||
postSoundWaitTime = 3.0
|
postSoundWaitTime = 3.0
|
||||||
preSoundWaitTime = boatMopath.getDuration() - (waterSound.getDuration() + postSoundWaitTime)
|
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])
|
mtrack = MultiTrack.MultiTrack([boatTrack, dockTrack, soundTrack])
|
||||||
|
|
||||||
|
@ -2,33 +2,33 @@
|
|||||||
|
|
||||||
import Interval
|
import Interval
|
||||||
import Lerp
|
import Lerp
|
||||||
|
import PosHprInterval
|
||||||
|
|
||||||
class LerpInterval(Interval.Interval):
|
class LerpInterval(Interval.Interval):
|
||||||
|
|
||||||
# special methods
|
# special methods
|
||||||
|
|
||||||
def __init__(self, name, node, duration):
|
def __init__(self, name, node, duration, t0=0.0,
|
||||||
"""__init__(name, node, duration)
|
type=Interval.Interval.PrevEndRelative):
|
||||||
|
"""__init__(name, node, duration, t0, type)
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.node = node
|
self.node = node
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
self.startTime = t0
|
||||||
def setT(self, t):
|
self.type = type
|
||||||
""" setT(t)
|
|
||||||
Go to time t
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
class LerpPosHprInterval(LerpInterval):
|
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'):
|
blendType='noBlend'):
|
||||||
""" __init__(name, node, pos, hpr, duration, other, blendType)
|
""" __init__(name, node, pos, hpr, duration, t0, type, other,
|
||||||
|
blendType)
|
||||||
"""
|
"""
|
||||||
import PosHprLerpFunctor
|
import PosHprLerpFunctor
|
||||||
|
|
||||||
LerpInterval.__init__(self, name, node, duration)
|
LerpInterval.__init__(self, name, node, duration, t0, type)
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
self.hpr = hpr
|
self.hpr = hpr
|
||||||
|
|
||||||
@ -52,10 +52,11 @@ class LerpPosHprInterval(LerpInterval):
|
|||||||
def setT(self, t):
|
def setT(self, t):
|
||||||
""" setT(t)
|
""" setT(t)
|
||||||
"""
|
"""
|
||||||
|
assert(t >= 0.0)
|
||||||
if (t > self.duration):
|
if (t > self.duration):
|
||||||
return
|
self.lerp.setT(self.duration)
|
||||||
assert(t >= 0)
|
else:
|
||||||
self.lerp.setT(t)
|
self.lerp.setT(t)
|
||||||
|
|
||||||
def __getBlend(self, blendType):
|
def __getBlend(self, blendType):
|
||||||
"""__getBlend(self, string)
|
"""__getBlend(self, string)
|
||||||
|
@ -2,24 +2,29 @@
|
|||||||
|
|
||||||
import Interval
|
import Interval
|
||||||
import Mopath
|
import Mopath
|
||||||
|
import PosHprInterval
|
||||||
|
|
||||||
class MopathInterval(Interval.Interval):
|
class MopathInterval(Interval.Interval):
|
||||||
|
|
||||||
# special methods
|
# special methods
|
||||||
|
|
||||||
def __init__(self, name, mopath, node):
|
def __init__(self, name, mopath, node, t0=0.0,
|
||||||
"""__init__(name, mopath, node)
|
type=Interval.Interval.PrevEndRelative):
|
||||||
|
"""__init__(name, mopath, node, t0, type)
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.node = node
|
self.node = node
|
||||||
self.mopath = mopath
|
self.mopath = mopath
|
||||||
self.duration = self.mopath.getMaxT()
|
self.duration = self.mopath.getMaxT()
|
||||||
|
self.startTime = t0
|
||||||
|
self.type = type
|
||||||
|
|
||||||
def setT(self, t):
|
def setT(self, t):
|
||||||
""" setT(t)
|
""" setT(t)
|
||||||
Go to time t
|
Go to time t
|
||||||
"""
|
"""
|
||||||
|
assert(t >= 0.0)
|
||||||
if (t > self.duration):
|
if (t > self.duration):
|
||||||
return
|
self.mopath.goTo(self.node, self.duration)
|
||||||
assert(t >= 0)
|
else:
|
||||||
self.mopath.goTo(self.node, t)
|
self.mopath.goTo(self.node, t)
|
||||||
|
@ -13,31 +13,32 @@ class MultiTrack(Interval.Interval):
|
|||||||
"""__init__(trackList, name)
|
"""__init__(trackList, name)
|
||||||
"""
|
"""
|
||||||
if (name == None):
|
if (name == None):
|
||||||
self.name = 'MultiTrack-%d' % self.multiTrackNum
|
self.name = 'MultiTrack-%d' % MultiTrack.multiTrackNum
|
||||||
self.multiTrackNum = self.multiTrackNum + 1
|
MultiTrack.multiTrackNum = MultiTrack.multiTrackNum + 1
|
||||||
else:
|
else:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.tlist = trackList
|
self.tlist = trackList
|
||||||
self.getDuration()
|
self.duration = self.getDuration()
|
||||||
|
self.startTime = 0.0
|
||||||
|
self.type = Interval.Interval.PrevEndRelative
|
||||||
|
|
||||||
def getDuration(self):
|
def getDuration(self):
|
||||||
""" getDuration()
|
""" getDuration()
|
||||||
|
Returns the duration of the longest Track
|
||||||
"""
|
"""
|
||||||
#if (len(self.tlist == 0)):
|
duration = 0.0
|
||||||
# Interval.notify.warning('MultiTrack.getDuration(): no Tracks')
|
|
||||||
# return 0.0
|
|
||||||
self.duration = self.tlist[0].getDuration()
|
|
||||||
for t in self.tlist:
|
for t in self.tlist:
|
||||||
if (self.duration != t.getDuration()):
|
dur = t.getDuration()
|
||||||
Interval.Interval.notify.warning('MultiTrack.getDuration(): tracks not all same duration')
|
if (dur > duration):
|
||||||
return self.duration
|
duration = dur
|
||||||
|
return duration
|
||||||
|
|
||||||
def setT(self, t):
|
def setT(self, t):
|
||||||
""" setT(t)
|
""" setT(t)
|
||||||
Go to time t
|
Go to time t
|
||||||
"""
|
"""
|
||||||
if (t > self.duration):
|
if (t > self.duration):
|
||||||
Interval.notify.warning('MultiTrack.setT(): t = %f > duration' % t)
|
Interval.notify.warning(
|
||||||
return
|
'MultiTrack.setT(): t = %f > duration' % t)
|
||||||
for track in self.tlist:
|
for track in self.tlist:
|
||||||
track.setT(t)
|
track.setT(t)
|
||||||
|
@ -8,20 +8,20 @@ class PosHprInterval(Interval.Interval):
|
|||||||
|
|
||||||
# special methods
|
# special methods
|
||||||
|
|
||||||
def __init__(self, name, node, pos, hpr, duration):
|
def __init__(self, name, node, pos, hpr, duration, t0=0.0,
|
||||||
"""__init__(name, node, pos, hpr, duration)
|
type=Interval.Interval.PrevEndRelative):
|
||||||
|
"""__init__(name, node, pos, hpr, duration, t0, type)
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.node = node
|
self.node = node
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
self.hpr = hpr
|
self.hpr = hpr
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
self.startTime = t0
|
||||||
|
self.type = type
|
||||||
|
|
||||||
def setT(self, t):
|
def setT(self, t):
|
||||||
""" setT(t)
|
""" setT(t)
|
||||||
Go to time t
|
Go to time t
|
||||||
"""
|
"""
|
||||||
if (t > self.duration):
|
|
||||||
return
|
|
||||||
assert(t >= 0)
|
|
||||||
self.node.setPosHpr(self.pos, self.hpr)
|
self.node.setPosHpr(self.pos, self.hpr)
|
||||||
|
@ -3,24 +3,29 @@
|
|||||||
from PandaModules import *
|
from PandaModules import *
|
||||||
|
|
||||||
import Interval
|
import Interval
|
||||||
|
import WaitInterval
|
||||||
|
|
||||||
class SoundInterval(Interval.Interval):
|
class SoundInterval(Interval.Interval):
|
||||||
|
|
||||||
# special methods
|
# special methods
|
||||||
|
|
||||||
def __init__(self, name, sound, loop = 0):
|
def __init__(self, name, sound, loop=0, t0=0.0,
|
||||||
"""__init__(name, sound)
|
type=Interval.Interval.PrevEndRelative):
|
||||||
|
"""__init__(name, sound, loop, t0, type)
|
||||||
"""
|
"""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.sound = sound
|
self.sound = sound
|
||||||
self.duration = self.sound.length()
|
self.duration = self.sound.length()
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
self.isPlaying = 0
|
self.isPlaying = 0
|
||||||
|
self.startTime = t0
|
||||||
|
self.type = type
|
||||||
|
|
||||||
def setT(self, t):
|
def setT(self, t):
|
||||||
""" setT(t)
|
""" setT(t)
|
||||||
Go to time t
|
Go to time t
|
||||||
"""
|
"""
|
||||||
|
print 'SoundInterval.setT(): t: %f' % t
|
||||||
if (t > self.duration):
|
if (t > self.duration):
|
||||||
return
|
return
|
||||||
assert(t >= 0)
|
assert(t >= 0)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Track module: contains the Track class"""
|
"""Track module: contains the Track class"""
|
||||||
|
|
||||||
import Interval
|
import Interval
|
||||||
|
import types
|
||||||
|
|
||||||
class Track(Interval.Interval):
|
class Track(Interval.Interval):
|
||||||
|
|
||||||
@ -12,54 +13,105 @@ class Track(Interval.Interval):
|
|||||||
"""__init__(intervalList, name)
|
"""__init__(intervalList, name)
|
||||||
"""
|
"""
|
||||||
if (name == None):
|
if (name == None):
|
||||||
self.name = 'Track-%d' % self.trackNum
|
self.name = 'Track-%d' % Track.trackNum
|
||||||
self.trackNum = self.trackNum + 1
|
Track.trackNum = Track.trackNum + 1
|
||||||
else:
|
else:
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
self.ilist = intervalList
|
self.ilist = intervalList
|
||||||
self.dlist = []
|
self.duration = self.__computeDuration(len(self.ilist))
|
||||||
self.computeDuration()
|
self.startTime = 0.0
|
||||||
|
self.type = Interval.Interval.PrevEndRelative
|
||||||
|
|
||||||
def computeDuration(self):
|
def __computeDuration(self, length):
|
||||||
""" computeDuration()
|
""" __computeDuration(length)
|
||||||
"""
|
"""
|
||||||
self.duration = 0.0
|
assert(length <= len(self.ilist))
|
||||||
for i in self.ilist:
|
duration = 0.0
|
||||||
dur = i.getDuration()
|
prev = None
|
||||||
self.duration = self.duration + dur
|
for i in self.ilist[0:length]:
|
||||||
self.dlist.append(dur)
|
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):
|
def getTrackRelativeStartTime(self, name):
|
||||||
""" getStartTimeOf(name)
|
""" getTrackRelativeStartTime(name)
|
||||||
"""
|
"""
|
||||||
t = 0.0
|
|
||||||
for i in range(len(self.ilist)):
|
for i in range(len(self.ilist)):
|
||||||
if (self.ilist[i].getName() == name):
|
if (self.ilist[i].getName() == name):
|
||||||
return t
|
return self.__computeDuration(i) - self.ilist[i].getDuration()
|
||||||
t = t + self.dlist[i]
|
Interval.notify.warning(
|
||||||
Interval.notify.warning('Track.getStartOf(): no Interval named: %s' %
|
'Track.getRelativeStartTime(): no Interval named: %s' % name)
|
||||||
name)
|
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
def getEndTimeOf(self, name):
|
def __getTrackRelativeStartTime(self, interval):
|
||||||
""" getEndTimeOf(name)
|
""" __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)):
|
for i in range(len(self.ilist)):
|
||||||
t = t + self.dlist[i]
|
if (self.ilist[i].getName() == name):
|
||||||
if (self.ilist[i].getName() == name):
|
return self.__computeDuration(i)
|
||||||
return t
|
Interval.notify.warning(
|
||||||
Interval.notify.warning('Track.getStartOf(): no Interval named: %s' %
|
'Track.getRelativeEndTime(): no Interval named: %s' % name)
|
||||||
name)
|
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
def setT(self, t):
|
def setT(self, t):
|
||||||
""" setT(t)
|
""" setT(t)
|
||||||
Go to time t
|
Go to time t
|
||||||
"""
|
"""
|
||||||
if (t > self.duration):
|
if (len(self.ilist) == 0):
|
||||||
Interval.notify.warning('Track.setT(): t = %f > duration' % t)
|
Interval.notify.warning('Track.setT(): track has no intervals')
|
||||||
return
|
return
|
||||||
for i in range(len(self.dlist)):
|
elif (t > self.duration):
|
||||||
if (t <= self.dlist[i]):
|
# Anything beyond the end of the track is assumed to be the
|
||||||
self.ilist[i].setT(t)
|
# 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
|
||||||
|
@ -10,12 +10,15 @@ class Wait(Interval.Interval):
|
|||||||
|
|
||||||
# special methods
|
# special methods
|
||||||
|
|
||||||
def __init__(self, duration, name = None):
|
def __init__(self, duration, name=None, t0=0.0,
|
||||||
"""__init__(duration, name)
|
type=Interval.Interval.PrevEndRelative):
|
||||||
|
"""__init__(duration, name, t0, type)
|
||||||
"""
|
"""
|
||||||
if (name == None):
|
if (name == None):
|
||||||
self.name = 'wait-%d' % self.waitNum
|
self.name = 'wait-%d' % Wait.waitNum
|
||||||
self.waitNum = self.waitNum + 1
|
Wait.waitNum = Wait.waitNum + 1
|
||||||
else:
|
else:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
|
self.startTime = 0.0
|
||||||
|
self.type = type
|
||||||
|
Loading…
x
Reference in New Issue
Block a user