Пример #1
0
    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)
Пример #2
0
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 panda3d.direct.task import Task
    from panda3d.direct.showbase import LerpBlendHelpers
    from panda3d.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 panda3d.pandac.Lerp import Lerp
        from panda3d.pandac.ClockObject import ClockObject
        from panda3d.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
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
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 panda3d.direct.task import Task
    from panda3d.direct.showbase import LerpBlendHelpers
    from panda3d.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 panda3d.pandac.Lerp import Lerp
        from panda3d.pandac.ClockObject import ClockObject
        from panda3d.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
Пример #7
0
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 panda3d.pandac import AutonomousLerp
    from panda3d.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
Пример #8
0
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 panda3d.pandac import AutonomousLerp
    from panda3d.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