Esempio n. 1
0
def extendByIntegration(motion, extendLength, preserveJoints=[], finiteDiff=1):
    lastFrame = len(motion) - 1
    p = motion.getJointPositionGlobal(0, lastFrame)
    v = motion.getJointVelocityGlobal(0, lastFrame - finiteDiff, lastFrame)
    a = motion.getJointAccelerationGlobal(0, lastFrame - finiteDiff, lastFrame)
    ap = motion.getJointOrientationsLocal(lastFrame)
    av = motion.getJointAngVelocitiesLocal(lastFrame - finiteDiff, lastFrame)
    aa = motion.getJointAngAccelerationsLocal(lastFrame - finiteDiff,
                                              lastFrame)
    t = 1 / motion.fps

    # integration
    extended = ym.JointMotion(
        [motion[0].getTPose() for i in range(extendLength)])
    for i in range(extendLength):
        p += v * t
        v += a * t
        ap = map(lambda R0, dR: np.dot(R0, mm.exp(t * dR)), ap, av)
        av = map(lambda V0, dV: V0 + t * dV, av, aa)
        extended[i].rootPos = p.copy()
        extended.setJointOrientationsLocal(i, ap)

    # preserve joint orientations
    preserveJointOrientations = [
        motion[-1].getJointOrientationGlobal(footJoint)
        for footJoint in preserveJoints
    ]
    for extendedPosture in extended:
        for i in range(len(preserveJoints)):
            extendedPosture.setJointOrientationGlobal(
                preserveJoints[i], preserveJointOrientations[i])

    return extended
Esempio n. 2
0
def blendSegmentSmooth(motionSegment0,
                       motionSegment1,
                       attachPosition=True,
                       attachOrientation=True):
    motionSegment1 = motionSegment1.copy()
    if attachPosition:
        p_offset = motionSegment0[0].rootPos - motionSegment1[0].rootPos
        motionSegment1.translateByOffset(p_offset)
    if attachOrientation:
        R_offset = np.dot(motionSegment0[0].localRs[0],
                          motionSegment1[0].localRs[0].T)
        R_offset = mm.exp(
            mm.projectionOnVector(mm.logSO3(R_offset),
                                  mm.v3(0, 1, 0)))  # # project on y axis
        motionSegment1.rotateTrajectory(R_offset)

    newMotion = ym.JointMotion([None] * (int(
        (len(motionSegment0) + len(motionSegment1)) / 2.)))
    # newMotion = ym.JointMotion( [None]*(int( t*len(motionSegment0) + (1-t)*len(motionSegment1)) ) )
    df0 = float(len(newMotion)) / len(motionSegment0)
    df1 = float(len(newMotion)) / len(motionSegment1)
    for frame in range(len(newMotion)):
        normalizedFrame = float(frame) / (len(newMotion) - 1)
        normalizedFrame2 = yfg.H1(normalizedFrame)
        normalizedFrame2 += df0 * yfg.H2(normalizedFrame)
        normalizedFrame2 += df1 * yfg.H3(normalizedFrame)

        posture0_at_normalizedFrame = motionSegment0.getPostureAt(
            normalizedFrame2 * (len(motionSegment0) - 1))
        posture1_at_normalizedFrame = motionSegment1.getPostureAt(
            normalizedFrame2 * (len(motionSegment1) - 1))
        newMotion[frame] = posture0_at_normalizedFrame.blendPosture(
            posture1_at_normalizedFrame, normalizedFrame2)
    return newMotion
Esempio n. 3
0
def stitchSegment(motion, transitionFunc, d, lastMatch=False):
    scaledTransFunc = yfg.scale(transitionFunc, [0, len(motion)])
    newMotion = ym.JointMotion([None] * len(motion))
    for i in range(len(motion)):
        t = scaledTransFunc(i) if lastMatch == False else scaledTransFunc(i +
                                                                          1)
        newMotion[i] = motion[i] + t * d
#        print i, t
    return newMotion
Esempio n. 4
0
    def toJointMotion(self, scale, applyRootOffset):
        skeleton = self.toJointSkeleton(scale, applyRootOffset)

        jointMotion = ym.JointMotion()
        for i in range(len(self.motionList)):
            jointPosture = ym.JointPosture(skeleton)
            self.addJointSO3FromBvhJoint(jointPosture, self.joints[0],
                                         self.motionList[i], scale)
            jointPosture.updateGlobalT()
            jointMotion.append(jointPosture)

        jointMotion.fps = 1. / self.frameTime
        return jointMotion
Esempio n. 5
0
def extendByIntegration_root(motion, extendLength, finiteDiff=1):
    lastFrame = len(motion) - 1
    p = motion.getJointPositionGlobal(0, lastFrame)
    v = motion.getJointVelocityGlobal(0, lastFrame - finiteDiff, lastFrame)
    a = motion.getJointAccelerationGlobal(0, lastFrame - finiteDiff, lastFrame)
    t = 1 / motion.fps

    # integration
    extended = ym.JointMotion([motion[-1].copy() for i in range(extendLength)])
    for i in range(extendLength):
        p += v * t
        v += a * t
        extended[i].rootPos = p.copy()
        extended[i].updateGlobalT()

    return extended
Esempio n. 6
0
def timescale(motion, newLength, scalingFunc=yfg.identity):
    if newLength == len(motion):
        return motion
    else:
        newMotion = ym.JointMotion([None] * newLength)
        df0 = float(newLength) / len(motion)
        df1 = float(newLength) / (2 * newLength - len(motion))
        for frame in range(len(newMotion)):
            normalizedFrame = float(frame) / (newLength - 1)
            if scalingFunc == None:
                normalizedFrame2 = yfg.H1(normalizedFrame)
                normalizedFrame2 += df0 * yfg.H2(normalizedFrame)
                normalizedFrame2 += df1 * yfg.H3(normalizedFrame)
            else:
                normalizedFrame2 = scalingFunc(normalizedFrame)
            newMotion[frame] = motion.getPostureAt(normalizedFrame2 *
                                                   (len(motion) - 1))
        return newMotion