def __lerp(self, functorFunc, duration, blendType, taskName=None): """ __lerp(self, functorFunc, float, string, string) Basic lerp functionality used by other lerps. Fire off a lerp. Make it a task if taskName given. """ # functorFunc is a function which can be called to create a functor. # functor creation is defered so initial state (sampled in functorFunc) # will be appropriate for the time the lerp is spawned from direct.task import Task from direct.interval import LerpBlendHelpers from direct.task.TaskManagerGlobal import taskMgr # upon death remove the functorFunc def lerpUponDeath(task): # Try to break circular references try: del task.functorFunc except: pass try: del task.lerp except: pass # make the task function def lerpTaskFunc(task): from pandac.Lerp import Lerp from pandac.ClockObject import ClockObject from direct.task.Task import Task, cont, done if task.init == 1: # make the lerp functor = task.functorFunc() task.lerp = Lerp(functor, task.duration, task.blendType) task.init = 0 dt = globalClock.getDt() task.lerp.setStepSize(dt) task.lerp.step() if (task.lerp.isDone()): # Reset the init flag, in case the task gets re-used task.init = 1 return (done) else: return (cont) # make the lerp task lerpTask = Task.Task(lerpTaskFunc) lerpTask.init = 1 lerpTask.functorFunc = functorFunc lerpTask.duration = duration lerpTask.blendType = LerpBlendHelpers.getBlend(blendType) lerpTask.setUponDeath(lerpUponDeath) if (taskName == None): # don't spawn a task, return one instead return lerpTask else: # spawn the lerp task taskMgr.add(lerpTask, taskName) return lerpTask
def __lerp(self, functorFunc, duration, blendType, taskName=None): """ __lerp(self, functorFunc, float, string, string) Basic lerp functionality used by other lerps. Fire off a lerp. Make it a task if taskName given. """ # functorFunc is a function which can be called to create a functor. # functor creation is defered so initial state (sampled in functorFunc) # will be appropriate for the time the lerp is spawned from direct.task import Task from direct.interval import LerpBlendHelpers from direct.task.TaskManagerGlobal import taskMgr # upon death remove the functorFunc def lerpUponDeath(task): # Try to break circular references try: del task.functorFunc except: pass try: del task.lerp except: pass # make the task function def lerpTaskFunc(task): from pandac.Lerp import Lerp from pandac.ClockObject import ClockObject from direct.task.Task import Task, cont, done if task.init == 1: # make the lerp functor = task.functorFunc() task.lerp = Lerp(functor, task.duration, task.blendType) task.init = 0 dt = globalClock.getDt() task.lerp.setStepSize(dt) task.lerp.step() if (task.lerp.isDone()): # Reset the init flag, in case the task gets re-used task.init = 1 return(done) else: return(cont) # make the lerp task lerpTask = Task.Task(lerpTaskFunc) lerpTask.init = 1 lerpTask.functorFunc = functorFunc lerpTask.duration = duration lerpTask.blendType = LerpBlendHelpers.getBlend(blendType) lerpTask.setUponDeath(lerpUponDeath) if (taskName == None): # don't spawn a task, return one instead return lerpTask else: # spawn the lerp task taskMgr.add(lerpTask, taskName) return lerpTask
def __autoLerp(self, functorFunc, time, blendType, taskName): """_autoLerp(self, functor, float, string, string) This lerp uses C++ to handle the stepping. Bonus is its more efficient, trade-off is there is less control""" from pandac import AutonomousLerp from direct.interval import LerpBlendHelpers # make a lerp that lives in C++ land functor = functorFunc() lerp = AutonomousLerp.AutonomousLerp(functor, time, LerpBlendHelpers.getBlend(blendType), base.eventHandler) lerp.start() return lerp