Browse Source

*** empty log message ***

Mark Mine 25 years ago
parent
commit
650e414ea1

+ 14 - 16
direct/src/actor/Actor.py

@@ -211,7 +211,7 @@ class Actor(PandaObject, NodePath):
         """getPartNames(self):
         """getPartNames(self):
         Return list of Actor part names. If not an multipart actor,
         Return list of Actor part names. If not an multipart actor,
         returns 'modelRoot' NOTE: returns parts of first LOD"""
         returns 'modelRoot' NOTE: returns parts of first LOD"""
-        return self.__partBundleDict[0].keys()
+        return self.__partBundleDict.values()[0].keys()
     
     
     def getGeomNode(self):
     def getGeomNode(self):
         """getGeomNode(self)
         """getGeomNode(self)
@@ -335,7 +335,7 @@ class Actor(PandaObject, NodePath):
 
 
         # get duration for named part only
         # get duration for named part only
         if (self.__animControlDict[lodName].has_key(partName)):        
         if (self.__animControlDict[lodName].has_key(partName)):        
-            animControl = self.__getAnimControl(animName, partName, lodName)
+            animControl = self.getAnimControl(animName, partName, lodName)
             if (animControl != None):
             if (animControl != None):
                 return animControl.getFrameRate()
                 return animControl.getFrameRate()
         else:
         else:
@@ -357,7 +357,7 @@ class Actor(PandaObject, NodePath):
         if (animName==None):
         if (animName==None):
             animName = self.getCurrentAnim(partName)
             animName = self.getCurrentAnim(partName)
             
             
-        animControl = self.__getAnimControl(animName, partName, lodName)
+        animControl = self.getAnimControl(animName, partName, lodName)
         if (animControl != None):
         if (animControl != None):
             return animControl.getPlayRate()
             return animControl.getPlayRate()
         else:
         else:
@@ -382,7 +382,7 @@ class Actor(PandaObject, NodePath):
             for partName in partNames:
             for partName in partNames:
                 if (animName==None):
                 if (animName==None):
                     animName = self.getCurrentAnim(partName)          
                     animName = self.getCurrentAnim(partName)          
-                animControl = self.__getAnimControl(animName, partName, lodName)
+                animControl = self.getAnimControl(animName, partName, lodName)
                 if (animControl != None):
                 if (animControl != None):
                     animControl.setPlayRate(rate)
                     animControl.setPlayRate(rate)
             
             
@@ -401,7 +401,7 @@ class Actor(PandaObject, NodePath):
 
 
         # get duration for named part only
         # get duration for named part only
         if (self.__animControlDict[lodName].has_key(partName)):        
         if (self.__animControlDict[lodName].has_key(partName)):        
-            animControl = self.__getAnimControl(animName, partName, lodName)
+            animControl = self.getAnimControl(animName, partName, lodName)
             if (animControl != None):
             if (animControl != None):
                 return (animControl.getNumFrames() / \
                 return (animControl.getNumFrames() / \
                         animControl.getFrameRate())
                         animControl.getFrameRate())
@@ -422,7 +422,7 @@ class Actor(PandaObject, NodePath):
         # loop through all anims for named part and find if any are playing
         # loop through all anims for named part and find if any are playing
         if (self.__animControlDict[lodName].has_key(partName)):
         if (self.__animControlDict[lodName].has_key(partName)):
             for animName in self.__animControlDict[lodName][partName].keys():
             for animName in self.__animControlDict[lodName][partName].keys():
-                if (self.__getAnimControl(animName, partName, lodName).isPlaying()):
+                if (self.getAnimControl(animName, partName, lodName).isPlaying()):
                     return animName
                     return animName
         else:
         else:
             Actor.notify.warning("no part named %s" % (partName))
             Actor.notify.warning("no part named %s" % (partName))
@@ -772,13 +772,13 @@ class Actor(PandaObject, NodePath):
             if (partName == None):
             if (partName == None):
                 # loop all parts
                 # loop all parts
                 for thisPart in animControlDict.keys():            
                 for thisPart in animControlDict.keys():            
-                    animControl = self.__getAnimControl(animName, thisPart,
+                    animControl = self.getAnimControl(animName, thisPart,
                                                         lodName)
                                                         lodName)
                     if (animControl != None):
                     if (animControl != None):
                         animControl.play()
                         animControl.play()
 
 
             else:
             else:
-                animControl = self.__getAnimControl(animName, partName,
+                animControl = self.getAnimControl(animName, partName,
                                                     lodName)
                                                     lodName)
                 if (animControl != None):
                 if (animControl != None):
                     animControl.play()
                     animControl.play()
@@ -795,13 +795,13 @@ class Actor(PandaObject, NodePath):
             if (partName == None):
             if (partName == None):
                 # loop all parts
                 # loop all parts
                 for thisPart in animControlDict.keys():
                 for thisPart in animControlDict.keys():
-                    animControl = self.__getAnimControl(animName, thisPart,
+                    animControl = self.getAnimControl(animName, thisPart,
                                                         lodName)
                                                         lodName)
                     if (animControl != None):
                     if (animControl != None):
                         animControl.loop(restart)
                         animControl.loop(restart)
             else:
             else:
                 # loop a specific part
                 # loop a specific part
-                animControl = self.__getAnimControl(animName, partName,
+                animControl = self.getAnimControl(animName, partName,
                                                     lodName)
                                                     lodName)
                 if (animControl != None):
                 if (animControl != None):
                     animControl.loop(restart)
                     animControl.loop(restart)
@@ -816,21 +816,19 @@ class Actor(PandaObject, NodePath):
             if (partName==None):
             if (partName==None):
                 # pose all parts
                 # pose all parts
                 for thisPart in animControlDict.keys():
                 for thisPart in animControlDict.keys():
-                    animControl = self.__getAnimControl(animName, thisPart,
+                    animControl = self.getAnimControl(animName, thisPart,
                                                         lodName)
                                                         lodName)
                     if (animControl != None):
                     if (animControl != None):
                         animControl.pose(frame)
                         animControl.pose(frame)
             else:
             else:
                 # pose a specific part
                 # pose a specific part
-                animControl = self.__getAnimControl(animName, partName,
+                animControl = self.getAnimControl(animName, partName,
                                                     lodName)
                                                     lodName)
                 if (animControl != None):
                 if (animControl != None):
                     animControl.pose(frame)
                     animControl.pose(frame)
         
         
-    #private
-    
-    def __getAnimControl(self, animName, partName, lodName="lodRoot"):
-        """__getAnimControl(self, string, string, string="lodRoot")
+    def getAnimControl(self, animName, partName, lodName="lodRoot"):
+        """getAnimControl(self, string, string, string="lodRoot")
         Search the animControl dictionary indicated by lodName for
         Search the animControl dictionary indicated by lodName for
         a given anim and part. Return the animControl if present,
         a given anim and part. Return the animControl if present,
         or None otherwise
         or None otherwise

+ 22 - 20
direct/src/interval/AnimInterval.py

@@ -7,43 +7,45 @@ class AnimInterval(Interval):
     # Name counter
     # Name counter
     animNum = 1
     animNum = 1
     # Class methods
     # Class methods
-    def __init__(self, animControl, loop=0, name=None):
+    def __init__(self, animControl, loop = 0, duration = 0.0, name=None):
         """__init__(name)
         """__init__(name)
         """
         """
         # Record class specific variables
         # Record class specific variables
 	self.animControl = animControl
 	self.animControl = animControl
-	self.loop = loop
+        self.loop = loop
         # Generate unique name if necessary
         # Generate unique name if necessary
 	if (name == None):
 	if (name == None):
 	    name = 'Anim-%d' % AnimInterval.animNum
 	    name = 'Anim-%d' % AnimInterval.animNum
 	    AnimInterval.animNum += 1
 	    AnimInterval.animNum += 1
         # Compute anim duration
         # Compute anim duration
-	duration = (float(animControl.getNumFrames()) /
-			animControl.getFrameRate())
+        self.numFrames = self.animControl.getNumFrames()
+        if duration == 0.0:
+            duration = (float(self.numFrames)/animControl.getFrameRate())
         # Initialize superclass
         # Initialize superclass
 	Interval.__init__(self, name, duration)
 	Interval.__init__(self, name, duration)
-
     def updateFunc(self, t, event = IVAL_NONE):
     def updateFunc(self, t, event = IVAL_NONE):
 	""" updateFunc(t, event)
 	""" updateFunc(t, event)
 	    Go to time t
 	    Go to time t
 	"""
 	"""
         # Update animation based upon current time
         # Update animation based upon current time
-        if (t == self.getDuration()):
-	    if (self.isPlaying == 1):
-		self.isPlaying = 0
-		if (self.loop):
-		    self.animControl.stop()
+        # Pose or stop anim
+        if (t >= self.getDuration()) or (event == IVAL_STOP):
+            self.animControl.stop()
+        elif self.loop == 1:
+            if event == IVAL_INIT:
+                # Determine the current frame
+                frame = (int(self.animControl.getFrameRate() * t) %
+                         self.numFrames)
+                # Pose anim
+                self.animControl.pose(frame)
+                # And start loop
+                self.animControl.loop(0)
         else:
         else:
-            # Set flag
-	    self.isPlaying = 1
-	    # Determine the current frame
-	    frame = int(self.animControl.getFrameRate() * t)
+            # Determine the current frame
+            frame = (int(self.animControl.getFrameRate() * t) %
+                     self.numFrames)
             # Pose anim
             # Pose anim
-	    if (self.loop):
-		self.animControl.pos(frame)	
-		self.animControl.loop(0)
-	    else:
-		self.animControl.play(frame, self.animControl.getNumFrames())
-
+            self.animControl.pose(frame)
+            
 
 
 
 

+ 3 - 2
direct/src/interval/FunctionInterval.py

@@ -25,8 +25,9 @@ class FunctionInterval(Interval):
 	""" updateFunc(t, event)
 	""" updateFunc(t, event)
 	    Go to time t
 	    Go to time t
 	"""
 	"""
-        # Evaluate the function
-        self.function()
+        if event != IVAL_STOP:
+            # Evaluate the function
+            self.function()
 
 
 ### FunctionInterval subclass for throwing events ###
 ### FunctionInterval subclass for throwing events ###
 class EventInterval(FunctionInterval):
 class EventInterval(FunctionInterval):

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

@@ -7,6 +7,7 @@ import Task
 # Interval events
 # Interval events
 IVAL_NONE = 0
 IVAL_NONE = 0
 IVAL_INIT = 1
 IVAL_INIT = 1
+IVAL_STOP = 2
 
 
 class Interval(DirectObject):
 class Interval(DirectObject):
     """Interval class: Base class for timeline functionality"""
     """Interval class: Base class for timeline functionality"""
@@ -98,6 +99,7 @@ class Interval(DirectObject):
         """ stop()
         """ stop()
         """
         """
         taskMgr.removeTasksNamed(self.name + '-play')
         taskMgr.removeTasksNamed(self.name + '-play')
+        self.setT(self.curr_t, event = IVAL_STOP)
 	return self.curr_t
 	return self.curr_t
 
 
     def __playTask(self, task):
     def __playTask(self, task):
@@ -137,8 +139,14 @@ class Interval(DirectObject):
             tl, text = 'Time',
             tl, text = 'Time',
             min = 0, max = string.atof(fpformat.fix(self.duration, 2)),
             min = 0, max = string.atof(fpformat.fix(self.duration, 2)),
             command = lambda t, s = self: s.setT(t))
             command = lambda t, s = self: s.setT(t))
-        es.onRelease = lambda s=self, es = es: s.setT(es.get(),
-                                                      event = IVAL_INIT)
+        # So when you drag scale with mouse its like you started a playback
+        def onPress(s=self,es=es):
+            # Kill playback task
+            taskMgr.removeTasksNamed(s.name + '-play')
+            # INIT interval
+            s.setT(es.get(), event = IVAL_INIT)
+        es.onPress = onPress
+        es.onRelease = lambda s=self: s.stop()
         es.onReturnRelease = lambda s=self, es = es: s.setT(es.get(),
         es.onReturnRelease = lambda s=self, es = es: s.setT(es.get(),
                                                             event = IVAL_INIT)
                                                             event = IVAL_INIT)
         es.pack(expand = 1, fill = X)
         es.pack(expand = 1, fill = X)

+ 17 - 1
direct/src/interval/IntervalTest.py

@@ -1,12 +1,19 @@
 from PandaModules import *
 from PandaModules import *
 from DirectSessionGlobal import *
 from DirectSessionGlobal import *
 from IntervalGlobal import *
 from IntervalGlobal import *
+from Actor import *
 
 
 import Mopath
 import Mopath
 
 
 boat = loader.loadModel('models/directmodels/smiley')
 boat = loader.loadModel('models/directmodels/smiley')
 boat.reparentTo(render)
 boat.reparentTo(render)
 
 
+donald = Actor()
+donald.loadModel("phase_3/models/char/donald-wheel-mod")
+donald.loadAnims({"steer":"phase_3/models/char/donald-wheel-chan"})
+steerAnimControl = donald.getAnimControl('steer', 'modelRoot')
+donald.reparentTo(boat)
+
 dock = loader.loadModel('models/directmodels/smiley')
 dock = loader.loadModel('models/directmodels/smiley')
 dock.reparentTo(render)
 dock.reparentTo(render)
 
 
@@ -21,6 +28,14 @@ boatTrack = Track([boatMopath], 'boattrack')
 BOAT_START = boatTrack.getIntervalStartTime('boatpath')
 BOAT_START = boatTrack.getIntervalStartTime('boatpath')
 BOAT_END = boatTrack.getIntervalEndTime('boatpath')
 BOAT_END = boatTrack.getIntervalEndTime('boatpath')
 
 
+# This will create an anim interval that is posed every frame
+donaldSteerInterval = AnimInterval(steerAnimControl)
+# This will create an anim interval that is started at t = 0 and then
+# loops for 10 seconds
+donaldLoopInterval = AnimInterval(steerAnimControl, loop = 1, duration = 10.0)
+donaldSteerTrack = Track([donaldSteerInterval, donaldLoopInterval],
+                         name = 'steerTrack')
+
 # Make the dock lerp up so that it's up when the boat reaches the end of
 # Make the dock lerp up so that it's up when the boat reaches the end of
 # its mopath
 # its mopath
 dockLerp = LerpPosHprInterval(dock, 5.0, 
 dockLerp = LerpPosHprInterval(dock, 5.0, 
@@ -48,7 +63,8 @@ waterDone = EventInterval('water-is-done')
 waterEventTrack = Track([waterDone])
 waterEventTrack = Track([waterDone])
 waterEventTrack.setIntervalStartTime('water-is-done', eventTime)
 waterEventTrack.setIntervalStartTime('water-is-done', eventTime)
 
 
-mtrack = MultiTrack([boatTrack, dockTrack, soundTrack, waterEventTrack])
+mtrack = MultiTrack([boatTrack, dockTrack, soundTrack, waterEventTrack,
+                     donaldSteerTrack])
 # Print out MultiTrack parameters
 # Print out MultiTrack parameters
 print(mtrack)
 print(mtrack)
 
 

+ 2 - 2
direct/src/interval/MultiTrack.py

@@ -44,9 +44,9 @@ class MultiTrack(Interval):
             # Compare time with track's end times
             # Compare time with track's end times
             if (t > tEnd):
             if (t > tEnd):
                 if (self.prev_t < tEnd) or (event == IVAL_INIT):
                 if (self.prev_t < tEnd) or (event == IVAL_INIT):
-                    track.setT(t)
+                    track.setT(t, event)
             else:
             else:
-                track.setT(t)
+                track.setT(t, event)
 
 
     def __repr__(self, indent=0):
     def __repr__(self, indent=0):
 	""" __repr__(indent)
 	""" __repr__(indent)

+ 1 - 1
direct/src/interval/SoundInterval.py

@@ -26,7 +26,7 @@ class SoundInterval(Interval):
 	""" updateFunc(t, event)
 	""" updateFunc(t, event)
         Go to time t
         Go to time t
 	"""
 	"""
-        if(t == self.duration):
+        if (t == self.duration) or (event == IVAL_STOP):
             # Stop sound if necessary
             # Stop sound if necessary
 	    if (self.isPlaying == 1):
 	    if (self.isPlaying == 1):
 		self.isPlaying = 0
 		self.isPlaying = 0

+ 7 - 6
direct/src/interval/Track.py

@@ -168,19 +168,20 @@ class Track(Interval):
 	    for ival, itime, itype, tStart, tEnd in self.ilist:
 	    for ival, itime, itype, tStart, tEnd in self.ilist:
                 # Compare time with ival's start/end times
                 # Compare time with ival's start/end times
                 if (t < tStart):
                 if (t < tStart):
-                    if self.prev_t > tStart:
+                    if (self.prev_t > tStart) and (event != IVAL_STOP):
                         # We just crossed the start of this interval
                         # We just crossed the start of this interval
                         # going backwards (e.g. via the slider)
                         # going backwards (e.g. via the slider)
                         # Execute this interval at its start time
                         # Execute this interval at its start time
-                        ival.setT(0.0)
+                        ival.setT(0.0, event)
                     # Done checking intervals
                     # Done checking intervals
                     break
                     break
                 elif (t >= tStart) and (t <= tEnd):
                 elif (t >= tStart) and (t <= tEnd):
                     # Between start/end, record current interval
                     # Between start/end, record current interval
                     currentInterval = ival
                     currentInterval = ival
                     # Make sure event == IVAL_INIT if entering new interval
                     # Make sure event == IVAL_INIT if entering new interval
-                    if ((self.prev_t < tStart) or
-                        (ival != self.currentInterval)):
+                    if ((event == IVAL_NONE) and
+                        ((self.prev_t < tStart) or
+                          (ival != self.currentInterval))):
                         event = IVAL_INIT
                         event = IVAL_INIT
                     # Evaluate interval at interval relative time
                     # Evaluate interval at interval relative time
                     currentInterval.setT(t - tStart, event)
                     currentInterval.setT(t - tStart, event)
@@ -188,13 +189,13 @@ class Track(Interval):
                     break
                     break
                 elif (t > tEnd):
                 elif (t > tEnd):
                     # Crossing over interval end 
                     # Crossing over interval end 
-                    if ((self.prev_t < tEnd) or
+                    if (((event == IVAL_NONE) and (self.prev_t < tEnd)) or
                         ((event == IVAL_INIT) and ival.getfOpenEnded())):
                         ((event == IVAL_INIT) and ival.getfOpenEnded())):
                         # If we've just crossed the end of this interval
                         # If we've just crossed the end of this interval
                         # or its an INIT event after the interval's end
                         # or its an INIT event after the interval's end
                         # and the interval is openended,
                         # and the interval is openended,
                         # then execute the interval at its end time
                         # then execute the interval at its end time
-                        ival.setT(ival.getDuration())
+                        ival.setT(ival.getDuration(), event)
                      # May not be the last, keep checking other intervals
                      # May not be the last, keep checking other intervals
             # Record current interval (may be None)
             # Record current interval (may be None)
             self.currentInterval = currentInterval
             self.currentInterval = currentInterval

+ 18 - 7
direct/src/tkwidgets/EntryScale.py

@@ -36,6 +36,7 @@ class EntryScale(Pmw.MegaWidget):
         # Initialize some class variables
         # Initialize some class variables
         self.value = self['initialValue']
         self.value = self['initialValue']
         self.entryFormat = '%.2f'
         self.entryFormat = '%.2f'
+        self.fScaleCommand = 0
 
 
         # Create the components.
         # Create the components.
 
 
@@ -104,12 +105,8 @@ class EntryScale(Pmw.MegaWidget):
         self.scale.pack(side = 'left', expand = 1, fill = 'x')
         self.scale.pack(side = 'left', expand = 1, fill = 'x')
         # Set scale to the middle of its range
         # Set scale to the middle of its range
         self.scale.set(self['initialValue'])
         self.scale.set(self['initialValue'])
-        self.scale.bind('<Button-1>',
-                        lambda event, s = self:
-                        apply(s.onPress, s['callbackData']))
-        self.scale.bind('<ButtonRelease-1>',
-                        lambda event, s = self:
-                        apply(s.onRelease, s['callbackData']))
+        self.scale.bind('<Button-1>', self.__onPress)
+        self.scale.bind('<ButtonRelease-1>', self.__onRelease)
 
 
         self.maxLabel = self.createcomponent('maxLabel', (), None,
         self.maxLabel = self.createcomponent('maxLabel', (), None,
                                              Button, self.minMaxFrame,
                                              Button, self.minMaxFrame,
@@ -174,6 +171,8 @@ class EntryScale(Pmw.MegaWidget):
         self.maxLabel['text'] = self['max']
         self.maxLabel['text'] = self['max']
 
 
     def _scaleCommand(self, strVal):
     def _scaleCommand(self, strVal):
+        if not self.fScaleCommand:
+            return
         # convert scale val to float
         # convert scale val to float
         self.set(string.atof(strVal))
         self.set(string.atof(strVal))
         """
         """
@@ -213,7 +212,7 @@ class EntryScale(Pmw.MegaWidget):
         # Round by resolution
         # Round by resolution
         if self['resolution'] is not None:
         if self['resolution'] is not None:
             newVal = round(newVal / self['resolution']) * self['resolution']
             newVal = round(newVal / self['resolution']) * self['resolution']
-        
+
         # Record updated value
         # Record updated value
         self.value = newVal
         self.value = newVal
         # Update scale's position
         # Update scale's position
@@ -234,10 +233,22 @@ class EntryScale(Pmw.MegaWidget):
         """ User redefinable callback executed on <Return> release in entry """
         """ User redefinable callback executed on <Return> release in entry """
         pass
         pass
 
 
+    def __onPress(self, event):
+        # First execute onpress callback
+        apply(self.onPress, self['callbackData'])
+        # Now enable slider command
+        self.fScaleCommand = 1
+
     def onPress(self, *args):
     def onPress(self, *args):
         """ User redefinable callback executed on button press """
         """ User redefinable callback executed on button press """
         pass
         pass
 
 
+    def __onRelease(self, event):
+        # Now disable slider command
+        self.fScaleCommand = 0
+        # First execute onpress callback
+        apply(self.onRelease, self['callbackData'])
+
     def onRelease(self, *args):
     def onRelease(self, *args):
         """ User redefinable callback executed on button release """
         """ User redefinable callback executed on button release """
         pass
         pass