def __init__(self, interval, startT = 0, endT = None, playRate = 1, duration = None, blendType = 'noBlend', name = None): self.interval = interval self.startAtStart = (startT == 0) self.endAtEnd = (endT == None or endT == interval.getDuration()) if endT == None: endT = interval.getDuration() if duration == None: duration = abs(endT - startT) / playRate if (name == None): name = ('IndirectInterval-%d' % IndirectInterval.indirectIntervalNum) IndirectInterval.indirectIntervalNum += 1 self.startT = startT self.endT = endT self.deltaT = endT - startT self.blendType = LerpBlendHelpers.getBlend(blendType) Interval.Interval.__init__(self, name, duration)
def __init__(self, interval, startT=0, endT=None, playRate=1, duration=None, blendType='noBlend', name=None): self.interval = interval self.startAtStart = (startT == 0) self.endAtEnd = (endT == None or endT == interval.getDuration()) if endT == None: endT = interval.getDuration() if duration == None: duration = abs(endT - startT) / playRate if (name == None): name = ('IndirectInterval-%d' % IndirectInterval.indirectIntervalNum) IndirectInterval.indirectIntervalNum += 1 self.startT = startT self.endT = endT self.deltaT = endT - startT self.blendType = LerpBlendHelpers.getBlend(blendType) Interval.Interval.__init__(self, name, duration)
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.showbase 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): from direct.task import Task from direct.showbase import LerpBlendHelpers from direct.task.TaskManagerGlobal import taskMgr def lerpTaskFunc(task): from pandac.PandaModules import Lerp from pandac.PandaModules import ClockObject from direct.task.Task import Task, cont, done if task.init == 1: 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(): task.init = 1 return done else: return cont lerpTask = Task.Task(lerpTaskFunc) lerpTask.init = 1 lerpTask.functorFunc = functorFunc lerpTask.duration = duration lerpTask.blendType = LerpBlendHelpers.getBlend(blendType) if taskName == None: return lerpTask else: taskMgr.add(lerpTask, taskName) return lerpTask return
def __autoLerp(self, functorFunc, time, blendType, taskName): from pandac.PandaModules import AutonomousLerp from direct.showbase import LerpBlendHelpers functor = functorFunc() lerp = AutonomousLerp.AutonomousLerp(functor, time, LerpBlendHelpers.getBlend(blendType), base.eventHandler) lerp.start() return lerp
def __lerp(self, functorFunc, duration, blendType, taskName=None): from direct.task import Task from direct.showbase import LerpBlendHelpers from direct.task.TaskManagerGlobal import taskMgr def lerpTaskFunc(task): from pandac.PandaModules import Lerp from pandac.PandaModules import ClockObject from direct.task.Task import Task, cont, done if task.init == 1: 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(): task.init = 1 return done else: return cont lerpTask = Task.Task(lerpTaskFunc) lerpTask.init = 1 lerpTask.functorFunc = functorFunc lerpTask.duration = duration lerpTask.blendType = LerpBlendHelpers.getBlend(blendType) if taskName == None: return lerpTask else: taskMgr.add(lerpTask, taskName) return lerpTask return
def __init__(self, function, duration = 0.0, fromData = 0, toData = 1, blendType = 'noBlend', extraArgs = [], name = None): """__init__(function, duration, fromData, toData, name) """ # Record instance variables self.function = function self.fromData = fromData self.toData = toData self.blendType = LerpBlendHelpers.getBlend(blendType) self.extraArgs = extraArgs # Generate unique name if necessary if (name == None): name = ('LerpFunctionInterval-%s-%d' % (function.__name__, LerpFunctionInterval.lerpFunctionIntervalNum)) LerpFunctionInterval.lerpFunctionIntervalNum += 1 else: # Allow the user to pass in a %d in the name and we'll go ahead # and uniquify the name for them. if "%d" in name: name = name % LerpFunctionInterval.lerpFunctionIntervalNum LerpFunctionInterval.lerpFunctionIntervalNum += 1 # Initialize superclass Interval.Interval.__init__(self, name, duration)
def __init__(self, function, duration=0.0, fromData=0, toData=1, blendType='noBlend', extraArgs=[], name=None): """__init__(function, duration, fromData, toData, name) """ # Record instance variables self.function = function self.fromData = fromData self.toData = toData self.blendType = LerpBlendHelpers.getBlend(blendType) self.extraArgs = extraArgs # Generate unique name if necessary if (name == None): name = ('LerpFunctionInterval-%s-%d' % (function.__name__, LerpFunctionInterval.lerpFunctionIntervalNum)) LerpFunctionInterval.lerpFunctionIntervalNum += 1 else: # Allow the user to pass in a %d in the name and we'll go ahead # and uniquify the name for them. if "%d" in name: name = name % LerpFunctionInterval.lerpFunctionIntervalNum LerpFunctionInterval.lerpFunctionIntervalNum += 1 # Initialize superclass Interval.Interval.__init__(self, name, duration)
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.showbase 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
def __init__(self, function, duration = 0.0, fromData = 0, toData = 1, blendType = 'noBlend', extraArgs = [], name = None): self.function = function self.fromData = fromData self.toData = toData self.blendType = LerpBlendHelpers.getBlend(blendType) self.extraArgs = extraArgs if name == None: name = 'LerpFunctionInterval-%s-%d' % (function.__name__, LerpFunctionInterval.lerpFunctionIntervalNum) LerpFunctionInterval.lerpFunctionIntervalNum += 1 elif '%d' in name: name = name % LerpFunctionInterval.lerpFunctionIntervalNum LerpFunctionInterval.lerpFunctionIntervalNum += 1 Interval.Interval.__init__(self, name, duration) return
def __init__(self, function, fromData = 0, toData = 1, duration = 0.0, blendType = 'noBlend', extraArgs = [], name = None): """__init__(function, duration, fromData, toData, name) """ # Record instance variables self.function = function self.fromData = fromData self.toData = toData self.blendType = LerpBlendHelpers.getBlend(blendType) self.extraArgs = extraArgs # Generate unique name if necessary if (name == None): name = ('LerpFunctionInterval-%d' % LerpFunctionInterval.lerpFunctionIntervalNum) LerpFunctionInterval.lerpFunctionIntervalNum += 1 # Initialize superclass Interval.Interval.__init__(self, name, duration)
def __init__(self, function, duration=0.0, fromData=0, toData=1, blendType='noBlend', extraArgs=[], name=None): self.function = function self.fromData = fromData self.toData = toData self.blendType = LerpBlendHelpers.getBlend(blendType) self.extraArgs = extraArgs if name == None: name = 'LerpFunctionInterval-%d' % LerpFunctionNoStateInterval.lerpFunctionIntervalNum LerpFunctionNoStateInterval.lerpFunctionIntervalNum += 1 elif '%d' in name: name = name % LerpFunctionNoStateInterval.lerpFunctionIntervalNum LerpFunctionNoStateInterval.lerpFunctionIntervalNum += 1 Interval.Interval.__init__(self, name, duration)
def __init__(self, function, fromData=0, toData=1, duration=0.0, blendType='noBlend', extraArgs=[], name=None): """__init__(function, duration, fromData, toData, name) """ # Record instance variables self.function = function self.fromData = fromData self.toData = toData self.blendType = LerpBlendHelpers.getBlend(blendType) self.extraArgs = extraArgs # Generate unique name if necessary if (name == None): name = ('LerpFunctionInterval-%d' % LerpFunctionInterval.lerpFunctionIntervalNum) LerpFunctionInterval.lerpFunctionIntervalNum += 1 # Initialize superclass Interval.Interval.__init__(self, name, duration)