Browse Source

showbase: Add functions to get interval for Iris Transitions

Drew Rogers 1 year ago
parent
commit
37152710b7
1 changed files with 50 additions and 29 deletions
  1. 50 29
      direct/src/showbase/Transitions.py

+ 50 - 29
direct/src/showbase/Transitions.py

@@ -264,6 +264,54 @@ class Transitions:
             self.iris = base.loader.loadModel(self.IrisModelName)
             self.iris = base.loader.loadModel(self.IrisModelName)
             self.iris.setPos(0, 0, 0)
             self.iris.setPos(0, 0, 0)
 
 
+    def getIrisInIval(self, t=0.5, finishIval=None, blendType='noBlend'):
+        """
+        Returns an interval without starting it.  This is particularly useful in
+        cutscenes, so when the cutsceneIval is escaped out of we can finish the iris immediately
+        """
+        self.noTransitions()
+        self.loadIris()
+
+        scale = 0.18 * max(base.a2dRight, base.a2dTop)
+        transitionIval = Sequence(Func(self.iris.reparentTo, ShowBaseGlobal.aspect2d, DGG.FADE_SORT_INDEX),
+                                  LerpScaleInterval(self.iris, t,
+                                                    scale = scale,
+                                                    startScale = 0.01,
+                                                    blendType=blendType),
+                                 Func(self.iris.detachNode),
+                                 Func(self.__finishTransition),
+                                 name = self.irisTaskName,
+                                 )
+        if finishIval:
+            transitionIval.append(finishIval)
+        return transitionIval
+
+    def getIrisOutIval(self, t=0.5, finishIval=None, blendType='noBlend'):
+        """
+        Create a sequence that lerps the iris out, then
+        parents the iris to hidden
+        """
+        self.noTransitions()
+        self.loadIris()
+        self.loadFade()  # we need this to cover up the hole.
+
+        scale = 0.18 * max(base.a2dRight, base.a2dTop)
+        transitionIval = Sequence(Func(self.iris.reparentTo, ShowBaseGlobal.aspect2d, DGG.FADE_SORT_INDEX),
+                                  LerpScaleInterval(self.iris, t,
+                                                    scale = 0.01,
+                                                    startScale = scale,
+                                                    blendType=blendType),
+                                 Func(self.iris.detachNode),
+                                 # Use the fade to cover up the hole that the iris would leave
+                                 Func(self.fadeOut, 0),
+                                 Func(self.__finishTransition),
+                                 name = self.irisTaskName,
+                                 )
+
+        if finishIval:
+            transitionIval.append(finishIval)
+        return transitionIval
+
     def irisIn(self, t=0.5, finishIval=None, blendType = 'noBlend'):
     def irisIn(self, t=0.5, finishIval=None, blendType = 'noBlend'):
         """
         """
         Play an iris in transition over t seconds.
         Play an iris in transition over t seconds.
@@ -271,25 +319,13 @@ class Transitions:
         of the iris polygon up so it looks like we iris in. When the
         of the iris polygon up so it looks like we iris in. When the
         scale lerp is finished, it parents the iris polygon to hidden.
         scale lerp is finished, it parents the iris polygon to hidden.
         """
         """
-        self.noTransitions()
-        self.loadIris()
         if t == 0:
         if t == 0:
             self.iris.detachNode()
             self.iris.detachNode()
             fut = AsyncFuture()
             fut = AsyncFuture()
             fut.setResult(None)
             fut.setResult(None)
             return fut
             return fut
         else:
         else:
-            self.iris.reparentTo(ShowBaseGlobal.aspect2d, DGG.FADE_SORT_INDEX)
-
-            scale = 0.18 * max(base.a2dRight, base.a2dTop)
-            self.transitionIval = Sequence(LerpScaleInterval(self.iris, t,
-                                                   scale = scale,
-                                                   startScale = 0.01,
-                                                   blendType=blendType),
-                                 Func(self.iris.detachNode),
-                                 Func(self.__finishTransition),
-                                 name = self.irisTaskName,
-                                 )
+            self.transitionIval = self.getIrisInIval(t, finishIval, blendType)
             self.__transitionFuture = AsyncFuture()
             self.__transitionFuture = AsyncFuture()
             if finishIval:
             if finishIval:
                 self.transitionIval.append(finishIval)
                 self.transitionIval.append(finishIval)
@@ -304,9 +340,6 @@ class Transitions:
         lerp is finished, it leaves the iris polygon covering the
         lerp is finished, it leaves the iris polygon covering the
         aspect2d plane until you irisIn or call noIris.
         aspect2d plane until you irisIn or call noIris.
         """
         """
-        self.noTransitions()
-        self.loadIris()
-        self.loadFade()  # we need this to cover up the hole.
         if t == 0:
         if t == 0:
             self.iris.detachNode()
             self.iris.detachNode()
             self.fadeOut(0)
             self.fadeOut(0)
@@ -314,19 +347,7 @@ class Transitions:
             fut.setResult(None)
             fut.setResult(None)
             return fut
             return fut
         else:
         else:
-            self.iris.reparentTo(ShowBaseGlobal.aspect2d, DGG.FADE_SORT_INDEX)
-
-            scale = 0.18 * max(base.a2dRight, base.a2dTop)
-            self.transitionIval = Sequence(LerpScaleInterval(self.iris, t,
-                                                   scale = 0.01,
-                                                   startScale = scale,
-                                                   blendType=blendType),
-                                 Func(self.iris.detachNode),
-                                 # Use the fade to cover up the hole that the iris would leave
-                                 Func(self.fadeOut, 0),
-                                 Func(self.__finishTransition),
-                                 name = self.irisTaskName,
-                                 )
+            self.transitionIval = self.getIrisOutIval(t, finishIval, blendType)
             self.__transitionFuture = AsyncFuture()
             self.__transitionFuture = AsyncFuture()
             if finishIval:
             if finishIval:
                 self.transitionIval.append(finishIval)
                 self.transitionIval.append(finishIval)