Browse Source

*** empty log message ***

Mark Mine 24 năm trước cách đây
mục cha
commit
af7d856efc
1 tập tin đã thay đổi với 28 bổ sung19 xóa
  1. 28 19
      direct/src/interval/ActorInterval.py

+ 28 - 19
direct/src/interval/ActorInterval.py

@@ -2,6 +2,7 @@
 
 
 from PandaModules import *
 from PandaModules import *
 from Interval import *
 from Interval import *
+import math
 
 
 import DirectNotifyGlobal
 import DirectNotifyGlobal
 
 
@@ -32,6 +33,7 @@ class ActorInterval(Interval):
 	self.actor = actor
 	self.actor = actor
 	self.animName = animName
 	self.animName = animName
         self.loop = loop
         self.loop = loop
+        self.frameRate = self.actor.getFrameRate(self.animName)
 	self.numFrames = self.actor.getNumFrames(self.animName)
 	self.numFrames = self.actor.getNumFrames(self.animName)
         # Compute start time
         # Compute start time
         self.startTime = startTime
         self.startTime = startTime
@@ -49,6 +51,23 @@ class ActorInterval(Interval):
             self.stopEvent = id + '_stopEvent'
             self.stopEvent = id + '_stopEvent'
             self.stopEventList = [self.stopEvent]
             self.stopEventList = [self.stopEvent]
 
 
+    def calcFrame(self, t):
+        # Compute current frame based upon current time
+        floatFrame = self.frameRate * (self.startTime + t)
+        # Need max to avoid frame = -1 when t = 0
+        frame = max(0, int(math.ceil(floatFrame)) - 1)
+        # Modulo in case of looping anim
+        return frame % self.numFrames
+
+    def goToT(self, t):
+        # Calc integer frame number
+        frame = self.calcFrame(t)
+        # Pose anim
+        self.actor.pose(self.animName, frame)
+        # Print debug information
+        self.notify.debug('goToT() - pose to frame: %d' % frame)
+        return frame
+
     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
@@ -60,33 +79,23 @@ class ActorInterval(Interval):
         # Pose or stop anim
         # Pose or stop anim
         if (t >= (self.startTime + self.getDuration())):
         if (t >= (self.startTime + self.getDuration())):
             self.actor.stop()
             self.actor.stop()
-            currT = (self.actor.getFrameRate(self.animName) *
-                         (self.startTime + self.getDuration()))
-            frame = int(round(currT)) % self.numFrames
-            # Pose anim
-	    self.notify.debug('updateFunc() - stopping at frame: %d of %d' \
-		% (frame, self.numFrames))
-            self.actor.pose(self.animName, frame)
+            frame = self.goToT(self.getDuration())
             if self.loop:
             if self.loop:
                 self.ignore(self.stopEvent)
                 self.ignore(self.stopEvent)
+            # Print debug information
+	    self.notify.debug(
+                'updateFunc() - stoping at frame: ' +
+                '%d Num frames: %d' % (frame, self.numFrames))
         elif self.loop == 1:
         elif self.loop == 1:
             if event == IVAL_INIT:
             if event == IVAL_INIT:
-                # Determine the current frame
-                currT = (self.actor.getFrameRate(self.animName) *
-                         (self.startTime + t))
-                frame = int(round(currT)) % self.numFrames
                 # Pose anim
                 # Pose anim
-                self.actor.pose(self.animName, frame)
+                self.goToT(t)
                 # And start loop, restart flag says continue from current frame
                 # And start loop, restart flag says continue from current frame
                 self.actor.loop(self.animName, restart=0)
                 self.actor.loop(self.animName, restart=0)
                 self.accept(self.stopEvent, self.actor.stop)
                 self.accept(self.stopEvent, self.actor.stop)
+                # Print debug information
+                self.notify.debug('updateFunc() - IVAL_INIT looping anim')
         else:
         else:
-            # Determine the current frame
-            currT = (self.actor.getFrameRate(self.animName) *
-                     (self.startTime + t))
-            frame = int(round(currT)) % self.numFrames
             # Pose anim
             # Pose anim
-            self.actor.pose(self.animName, frame)
-            
-
+            self.goToT(t)