Browse Source

looping between frames

David Rose 23 years ago
parent
commit
808d469b01
2 changed files with 35 additions and 6 deletions
  1. 34 5
      direct/src/actor/Actor.py
  2. 1 1
      direct/src/interval/ActorInterval.py

+ 34 - 5
direct/src/actor/Actor.py

@@ -463,6 +463,28 @@ class Actor(PandaObject, NodePath):
         else:
             Actor.notify.warning("no part named %s" % (partName))
         return None
+    
+    def getBaseFrameRate(self, animName=None, partName=None):
+        """getBaseFrameRate(self, string, string=None)
+        Return duration of given anim name and given part, unmodified
+        by any play rate in effect.
+        """
+        lodName = self.__animControlDict.keys()[0]
+
+        if (partName == None):
+            partName = self.__animControlDict[lodName].keys()[0]
+    
+        if (animName==None):
+            animName = self.getCurrentAnim(partName)
+
+        # get duration for named part only
+        if (self.__animControlDict[lodName].has_key(partName)):        
+            animControl = self.getAnimControl(animName, partName, lodName)
+            if (animControl != None):
+                return animControl.getAnim().getBaseFrameRate()
+        else:
+            Actor.notify.warning("no part named %s" % (partName))
+        return None
 
     def getPlayRate(self, animName=None, partName=None):
         """getPlayRate(self, string=None, string=None)
@@ -967,7 +989,8 @@ class Actor(PandaObject, NodePath):
                         animControl.play(fromFrame, toFrame)
 
 
-    def loop(self, animName, restart=1, partName=None):
+    def loop(self, animName, restart=1, partName=None,
+             fromFrame=None, toFrame=None):
         """loop(self, string, int=1, string=None)
         Loop the given animation on the given part of the actor,
         restarting at zero frame if requested. If no part name
@@ -979,15 +1002,21 @@ class Actor(PandaObject, NodePath):
                 # loop all parts
                 for thisPart in animControlDict.keys():
                     animControl = self.getAnimControl(animName, thisPart,
-                                                        thisLod)
+                                                      thisLod)
                     if (animControl != None):
-                        animControl.loop(restart)
+                        if (fromFrame == None):
+                            animControl.loop(restart)
+                        else:
+                            animControl.loop(restart, fromFrame, toFrame)
             else:
                 # loop a specific part
                 animControl = self.getAnimControl(animName, partName,
-                                                    thisLod)
+                                                  thisLod)
                 if (animControl != None):
-                    animControl.loop(restart)
+                    if (fromFrame == None):
+                        animControl.loop(restart)
+                    else:
+                        animControl.loop(restart, fromFrame, toFrame)
 
     def pingpong(self, animName, fromFrame, toFrame, restart=1, partName=None):
         """pingpong(self, string, fromFrame, toFrame, int=1, string=None)

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

@@ -33,7 +33,7 @@ class ActorInterval(Interval.Interval):
         self.actor = actor
         self.animName = animName
         self.loopAnim = loop
-        self.frameRate = self.actor.getFrameRate(self.animName) * playRate
+        self.frameRate = self.actor.getBaseFrameRate(self.animName) * playRate
         self.numFrames = self.actor.getNumFrames(self.animName)
         # Compute start time
         self.startTime = startTime