|
|
@@ -5,16 +5,13 @@ from Interval import *
|
|
|
import Lerp
|
|
|
|
|
|
class LerpInterval(Interval):
|
|
|
-
|
|
|
- # special methods
|
|
|
-
|
|
|
+ # Class methods
|
|
|
def __init__(self, name, duration, functorFunc, blendType='noBlend'):
|
|
|
"""__init__(name, duration, functorFunc, blendType)
|
|
|
"""
|
|
|
self.functorFunc = functorFunc
|
|
|
- self.blendType = self.__getBlend(blendType)
|
|
|
+ self.blendType = self.getBlend(blendType)
|
|
|
Interval.__init__(self, name, duration)
|
|
|
-
|
|
|
def setT(self, t, entry=0):
|
|
|
""" setT(t, entry)
|
|
|
"""
|
|
|
@@ -27,13 +24,11 @@ class LerpInterval(Interval):
|
|
|
self.lerp.setT(self.duration)
|
|
|
elif (t <= self.duration):
|
|
|
self.lerp.setT(t)
|
|
|
-
|
|
|
- def __getBlend(self, blendType):
|
|
|
+ def getBlend(self, blendType):
|
|
|
"""__getBlend(self, string)
|
|
|
Return the C++ blend class corresponding to blendType string
|
|
|
"""
|
|
|
import LerpBlendHelpers
|
|
|
-
|
|
|
if (blendType == "easeIn"):
|
|
|
return LerpBlendHelpers.LerpBlendHelpers.easeIn
|
|
|
elif (blendType == "easeOut"):
|
|
|
@@ -46,48 +41,6 @@ class LerpInterval(Interval):
|
|
|
raise Exception(
|
|
|
'Error: LerpInterval.__getBlend: Unknown blend type')
|
|
|
|
|
|
-class LerpPosHprInterval(LerpInterval):
|
|
|
-
|
|
|
- lerpPosHprNum = 1
|
|
|
-
|
|
|
- def __init__(self, node, duration, pos, hpr, startPos=None,
|
|
|
- startHpr=None, other=None, blendType='noBlend', name=None):
|
|
|
- """ __init__(node, duration, pos, hpr, startPos, startHpr,
|
|
|
- other, blendType, name)
|
|
|
- """
|
|
|
- def functorFunc(self=self, node=node, pos=pos, hpr=hpr,
|
|
|
- startPos=startPos, startHpr=startHpr, other=other):
|
|
|
- import PosHprLerpFunctor
|
|
|
-
|
|
|
- assert(not node.isEmpty())
|
|
|
- if (other != None):
|
|
|
- # lerp wrt other
|
|
|
- if (startPos == None):
|
|
|
- startPos = node.getPos(other)
|
|
|
- if (startHpr == None):
|
|
|
- startHpr = node.getHpr(other)
|
|
|
- functor = PosHprLerpFunctor.PosHprLerpFunctor(
|
|
|
- node, startPos, pos,
|
|
|
- startHpr, hpr, other)
|
|
|
- else:
|
|
|
- if (startPos == None):
|
|
|
- startPos = node.getPos()
|
|
|
- if (startHpr == None):
|
|
|
- startHpr = node.getHpr()
|
|
|
- functor = PosHprLerpFunctor.PosHprLerpFunctor(
|
|
|
- node, startPos, pos,
|
|
|
- startHpr, hpr)
|
|
|
- return functor
|
|
|
-
|
|
|
- if (name == None):
|
|
|
- n = 'LerpPosHpr-%d' % LerpPosHprInterval.lerpPosHprNum
|
|
|
- LerpPosHprInterval.lerpPosHprNum += 1
|
|
|
- else:
|
|
|
- n = name
|
|
|
-
|
|
|
- LerpInterval.__init__(self, n, duration, functorFunc, blendType)
|
|
|
-
|
|
|
-
|
|
|
class LerpPosInterval(LerpInterval):
|
|
|
|
|
|
lerpPosNum = 1
|
|
|
@@ -115,7 +68,7 @@ class LerpPosInterval(LerpInterval):
|
|
|
return functor
|
|
|
|
|
|
if (name == None):
|
|
|
- n = 'LerpPos-%d' % LerpPosInterval.lerpPosNum
|
|
|
+ n = 'LerpPosInterval-%d' % LerpPosInterval.lerpPosNum
|
|
|
LerpPosInterval.lerpPosNum += 1
|
|
|
else:
|
|
|
n = name
|
|
|
@@ -124,8 +77,9 @@ class LerpPosInterval(LerpInterval):
|
|
|
|
|
|
class LerpHprInterval(LerpInterval):
|
|
|
|
|
|
+ # Interval counter
|
|
|
lerpHprNum = 1
|
|
|
-
|
|
|
+ # Class methods
|
|
|
def __init__(self, node, duration, hpr, startHpr=None,
|
|
|
other=None, blendType='noBlend', name=None):
|
|
|
""" __init__(node, duration, hpr, startHpr, other, blendType, name)
|
|
|
@@ -149,9 +103,201 @@ class LerpHprInterval(LerpInterval):
|
|
|
return functor
|
|
|
|
|
|
if (name == None):
|
|
|
- n = 'LerpHpr-%d' % LerpHprInterval.lerpHprNum
|
|
|
+ n = 'LerpHprInterval-%d' % LerpHprInterval.lerpHprNum
|
|
|
LerpHprInterval.lerpHprNum += 1
|
|
|
else:
|
|
|
n = name
|
|
|
|
|
|
LerpInterval.__init__(self, n, duration, functorFunc, blendType)
|
|
|
+
|
|
|
+class LerpScaleInterval(LerpInterval):
|
|
|
+
|
|
|
+ # Interval counter
|
|
|
+ lerpScaleNum = 1
|
|
|
+ # Class methods
|
|
|
+ def __init__(self, node, duration, scale, startScale=None,
|
|
|
+ other=None, blendType='noBlend', name=None):
|
|
|
+ """ __init__(node, duration, scale, startScale, other, blendType, name)
|
|
|
+ """
|
|
|
+ def functorFunc(self=self, node=node, scale=scale,
|
|
|
+ startScale=startScale, other=other):
|
|
|
+ import ScaleLerpFunctor
|
|
|
+
|
|
|
+ assert(not node.isEmpty())
|
|
|
+ if (other != None):
|
|
|
+ # lerp wrt other
|
|
|
+ if (startScale == None):
|
|
|
+ startScale = node.getScale(other)
|
|
|
+ functor = ScaleLerpFunctor.ScaleLerpFunctor(
|
|
|
+ node, startScale, scale, other)
|
|
|
+ else:
|
|
|
+ if (startScale == None):
|
|
|
+ startScale = node.getScale()
|
|
|
+ functor = ScaleLerpFunctor.ScaleLerpFunctor(
|
|
|
+ node, startScale, scale)
|
|
|
+ return functor
|
|
|
+
|
|
|
+ if (name == None):
|
|
|
+ n = 'LerpScaleInterval-%d' % LerpScaleInterval.lerpScaleNum
|
|
|
+ LerpScaleInterval.lerpScaleNum += 1
|
|
|
+ else:
|
|
|
+ n = name
|
|
|
+
|
|
|
+ LerpInterval.__init__(self, n, duration, functorFunc, blendType)
|
|
|
+
|
|
|
+class LerpPosHprInterval(LerpInterval):
|
|
|
+ # Interval counter
|
|
|
+
|
|
|
+ lerpPosHprNum = 1
|
|
|
+
|
|
|
+ def __init__(self, node, duration, pos, hpr, startPos=None,
|
|
|
+ startHpr=None, other=None, blendType='noBlend', name=None):
|
|
|
+ """ __init__(node, duration, pos, hpr, startPos, startHpr,
|
|
|
+ other, blendType, name)
|
|
|
+ """
|
|
|
+ def functorFunc(self=self, node=node, pos=pos, hpr=hpr,
|
|
|
+ startPos=startPos, startHpr=startHpr, other=other):
|
|
|
+ import PosHprLerpFunctor
|
|
|
+
|
|
|
+ assert(not node.isEmpty())
|
|
|
+ if (other != None):
|
|
|
+ # lerp wrt other
|
|
|
+ if (startPos == None):
|
|
|
+ startPos = node.getPos(other)
|
|
|
+ if (startHpr == None):
|
|
|
+ startHpr = node.getHpr(other)
|
|
|
+ functor = PosHprLerpFunctor.PosHprLerpFunctor(
|
|
|
+ node, startPos, pos,
|
|
|
+ startHpr, hpr, other)
|
|
|
+ else:
|
|
|
+ if (startPos == None):
|
|
|
+ startPos = node.getPos()
|
|
|
+ if (startHpr == None):
|
|
|
+ startHpr = node.getHpr()
|
|
|
+ functor = PosHprLerpFunctor.PosHprLerpFunctor(
|
|
|
+ node, startPos, pos,
|
|
|
+ startHpr, hpr)
|
|
|
+ return functor
|
|
|
+
|
|
|
+ if (name == None):
|
|
|
+ n = 'LerpPosHpr-%d' % LerpPosHprInterval.lerpPosHprNum
|
|
|
+ LerpPosHprInterval.lerpPosHprNum += 1
|
|
|
+ else:
|
|
|
+ n = name
|
|
|
+
|
|
|
+ LerpInterval.__init__(self, n, duration, functorFunc, blendType)
|
|
|
+
|
|
|
+class LerpPosHprScaleInterval(LerpInterval):
|
|
|
+ # Interval counter
|
|
|
+ lerpPosHprScaleNum = 1
|
|
|
+ # Class methods
|
|
|
+ def __init__(self, node, duration, pos, hpr, scale,
|
|
|
+ startPos=None, startHpr=None, startScale=None,
|
|
|
+ other=None, blendType='noBlend', name=None):
|
|
|
+ """ __init__(node, duration, pos, hpr, scale,
|
|
|
+ startPos, startHpr, startScale,
|
|
|
+ other, blendType, name)
|
|
|
+ """
|
|
|
+ def functorFunc(self=self, node=node, pos=pos, hpr=hpr, scale=scale,
|
|
|
+ startPos=startPos, startHpr=startHpr,
|
|
|
+ startScale=startScale, other=other):
|
|
|
+ import PosHprScaleLerpFunctor
|
|
|
+
|
|
|
+ assert(not node.isEmpty())
|
|
|
+ if (other != None):
|
|
|
+ # lerp wrt other
|
|
|
+ if (startPos == None):
|
|
|
+ startPos = node.getPos(other)
|
|
|
+ if (startHpr == None):
|
|
|
+ startHpr = node.getHpr(other)
|
|
|
+ if (startScale == None):
|
|
|
+ startScale = node.getScale(other)
|
|
|
+ functor = PosHprScaleLerpFunctor.PosHprScaleLerpFunctor(
|
|
|
+ node, startPos, pos, startHpr, hpr,
|
|
|
+ startScale, scale, other)
|
|
|
+ else:
|
|
|
+ if (startPos == None):
|
|
|
+ startPos = node.getPos()
|
|
|
+ if (startHpr == None):
|
|
|
+ startHpr = node.getHpr()
|
|
|
+ if (startScale == None):
|
|
|
+ startScale = node.getScale()
|
|
|
+ functor = PosHprScaleLerpFunctor.PosHprScaleLerpFunctor(
|
|
|
+ node, startPos, pos, startHpr, hpr, startScale, scale)
|
|
|
+ return functor
|
|
|
+
|
|
|
+ if (name == None):
|
|
|
+ n = ('LerpPosHprScale-%d' %
|
|
|
+ LerpPosHprScaleInterval.lerpPosHprScaleNum)
|
|
|
+ LerpPosHprScaleInterval.lerpPosHprScaleNum += 1
|
|
|
+ else:
|
|
|
+ n = name
|
|
|
+
|
|
|
+ LerpInterval.__init__(self, n, duration, functorFunc, blendType)
|
|
|
+
|
|
|
+# Class used to execute a function over time. Function can access fromData
|
|
|
+# and toData to perform blend
|
|
|
+class LerpFunctionInterval(Interval):
|
|
|
+ # Interval counter
|
|
|
+ lerpFunctionIntervalNum = 1
|
|
|
+ # Class methods
|
|
|
+ def __init__(self, function, fromData = 0, toData = 1, duration = 0.0,
|
|
|
+ blendType = 'noBlend', name = None):
|
|
|
+ """__init__(function, duration, fromData, toData, name)
|
|
|
+ """
|
|
|
+ self.function = function
|
|
|
+ self.fromData = fromData
|
|
|
+ self.toData = toData
|
|
|
+ self.blendType = self.getBlend(blendType)
|
|
|
+ if (name == None):
|
|
|
+ name = ('LerpFunctionInterval-%d' %
|
|
|
+ LerpFunctionInterval.lerpFunctionIntervalNum)
|
|
|
+ LerpFunctionInterval.lerpFunctionIntervalNum += 1
|
|
|
+ # Initialize superclass
|
|
|
+ Interval.__init__(self, name, duration)
|
|
|
+ def setT(self, t, entry=0):
|
|
|
+ """ setT(t, entry)
|
|
|
+ """
|
|
|
+ if (t < 0):
|
|
|
+ return
|
|
|
+ if (entry == 1) and (t > self.duration):
|
|
|
+ self.function(self.toData)
|
|
|
+ elif (t <= self.duration):
|
|
|
+ try:
|
|
|
+ #bt = self.blendType(t/self.duration)
|
|
|
+ bt = t/self.duration
|
|
|
+ data = (self.fromData * (1 - bt)) + (self.toData * bt)
|
|
|
+ self.function(data)
|
|
|
+ except ZeroDivisionError:
|
|
|
+ self.function(self.toData)
|
|
|
+ def getBlend(self, blendType):
|
|
|
+ """__getBlend(self, string)
|
|
|
+ Return the C++ blend class corresponding to blendType string
|
|
|
+ """
|
|
|
+ import LerpBlendHelpers
|
|
|
+ def easeIn(t):
|
|
|
+ x = t*t
|
|
|
+ return ((3 * x) - (t * x)) * 0.5
|
|
|
+ def easeOut(t):
|
|
|
+ return ((3 * t) - (t * t * t)) * 0.5
|
|
|
+ def easeInOut(t):
|
|
|
+ x = t*t
|
|
|
+ return (3 * x) - (2 * t * x)
|
|
|
+ def noBlend(t):
|
|
|
+ return t
|
|
|
+ if (blendType == "easeIn"):
|
|
|
+ #return LerpBlendHelpers.LerpBlendHelpers.easeIn
|
|
|
+ return easeIn
|
|
|
+ elif (blendType == "easeOut"):
|
|
|
+ #return LerpBlendHelpers.LerpBlendHelpers.easeOut
|
|
|
+ return easeOut
|
|
|
+ elif (blendType == "easeInOut"):
|
|
|
+ #return LerpBlendHelpers.LerpBlendHelpers.easeInOut
|
|
|
+ return easeInOut
|
|
|
+ elif (blendType == "noBlend"):
|
|
|
+ #return LerpBlendHelpers.LerpBlendHelpers.noBlend
|
|
|
+ return noBlend
|
|
|
+ else:
|
|
|
+ raise Exception(
|
|
|
+ 'Error: LerpInterval.__getBlend: Unknown blend type')
|
|
|
+
|