showbase: Add functions to get interval for Iris Transitions

This commit is contained in:
Drew Rogers 2024-07-01 15:57:54 -05:00 committed by rdb
parent 21b39da65d
commit 37152710b7

View File

@ -264,25 +264,17 @@ class Transitions:
self.iris = base.loader.loadModel(self.IrisModelName)
self.iris.setPos(0, 0, 0)
def irisIn(self, t=0.5, finishIval=None, blendType = 'noBlend'):
def getIrisInIval(self, t=0.5, finishIval=None, blendType='noBlend'):
"""
Play an iris in transition over t seconds.
Places a polygon on the aspect2d plane then lerps the scale
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.
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()
if t == 0:
self.iris.detachNode()
fut = AsyncFuture()
fut.setResult(None)
return fut
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,
transitionIval = Sequence(Func(self.iris.reparentTo, ShowBaseGlobal.aspect2d, DGG.FADE_SORT_INDEX),
LerpScaleInterval(self.iris, t,
scale = scale,
startScale = 0.01,
blendType=blendType),
@ -290,6 +282,50 @@ class Transitions:
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'):
"""
Play an iris in transition over t seconds.
Places a polygon on the aspect2d plane then lerps the scale
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.
"""
if t == 0:
self.iris.detachNode()
fut = AsyncFuture()
fut.setResult(None)
return fut
else:
self.transitionIval = self.getIrisInIval(t, finishIval, blendType)
self.__transitionFuture = AsyncFuture()
if finishIval:
self.transitionIval.append(finishIval)
@ -304,9 +340,6 @@ class Transitions:
lerp is finished, it leaves the iris polygon covering the
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:
self.iris.detachNode()
self.fadeOut(0)
@ -314,19 +347,7 @@ class Transitions:
fut.setResult(None)
return fut
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()
if finishIval:
self.transitionIval.append(finishIval)