def test_setPositionTarget(): bvhFilePath = '../samples/wd2_WalkSameSame00.bvh' motion = yf.readBvhFile(bvhFilePath, .01) print(motion[0].skeleton) lFoot = motion[0].skeleton.getJointIndex('LeftFoot') oripos = motion[0].getJointPositionGlobal(lFoot) newpos = oripos + mm.vec3(0, 1, 0) motion_edit1 = copy.deepcopy(motion) setPositionTarget(motion_edit1, lFoot, newpos) motion_edit2 = copy.deepcopy(motion) setPositionTarget(motion_edit2, lFoot, newpos, [10, 20], 5, yfg.identity) print(len(motion), len(motion_edit2)) viewer = ysv.SimpleViewer() viewer.record(False) viewer.doc.addRenderer( 'ys_motion', yr.JointMotionRenderer(motion, (0, 0, 255), yr.LINK_LINE)) viewer.doc.addObject('ys_motion', motion) viewer.doc.addRenderer( 'motion_edit1', yr.JointMotionRenderer(motion_edit1, (0, 255, 0), yr.LINK_LINE)) viewer.doc.addObject('motion_edit1', motion_edit1) viewer.doc.addRenderer( 'motion_edit2', yr.JointMotionRenderer(motion_edit2, (255, 255, 0), yr.LINK_LINE)) viewer.doc.addObject('motion_edit2', motion_edit2) viewer.startTimer(1 / 30.) viewer.show() Fl.run()
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.vec3(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
def getBlendedNextMotion2(nextMotionA, nextMotionB, prevEndPosture, t=None, attachPosition=True, attachOrientation=True): dA = prevEndPosture - nextMotionA[0] dB = prevEndPosture - nextMotionB[0] newNextMotionA = nextMotionA.copy() newNextMotionB = nextMotionB.copy() if attachPosition: p_offset_A = dA.rootPos p_offset_B = dB.rootPos # d.disableTranslation() newNextMotionA.translateByOffset(p_offset_A) newNextMotionB.translateByOffset(p_offset_B) if attachOrientation: R_offset_A = dA.getJointOrientationLocal(0) R_offset_A = mm.exp( mm.projectionOnVector(mm.logSO3(R_offset_A), mm.vec3(0, 1, 0))) # # project on y axis R_offset_B = dA.getJointOrientationLocal(0) R_offset_B = mm.exp( mm.projectionOnVector(mm.logSO3(R_offset_B), mm.vec3(0, 1, 0))) # # project on y axis # d.disableRotations([0]) newNextMotionA.rotateTrajectory(R_offset_A) newNextMotionB.rotateTrajectory(R_offset_B) if t is None: blendedNextMotion = blendSegmentSmooth(newNextMotionA, newNextMotionB) else: blendedNextMotion = blendSegmentFixed(newNextMotionA, newNextMotionB, t) # del blendedNextMotion[0] return blendedNextMotion
def test_FramesRenderer_OrientationsRenderer(): frame0 = mm.i_se3() frame1 = mm.r_p_to_t(mm.exp(mm.vec3(0, 1, 0), math.pi / 8.), (1, 0, 0)) viewer = ysv.SimpleViewer() viewer.doc.addRenderer('frame0', FramesRenderer([frame0], (255, 0, 0))) viewer.doc.addRenderer('frame1', FramesRenderer([frame1], (255, 0, 0))) viewer.doc.addRenderer( 'orientation0', OrientationsRenderer([mm.t_to_r(frame0)], [mm.t_to_p(frame0)], (0, 255, 0))) viewer.doc.addRenderer( 'orientation1', OrientationsRenderer([mm.t_to_r(frame1)], [mm.t_to_p(frame1)], (0, 255, 0))) viewer.show() Fl.run()
node = mcfg.getNode('Spine') node.width = .22 node = mcfg.getNode('RightFoot') node.length = .25 node = mcfg.getNode('LeftFoot') node.length = .25 return mcfg g_motionDirConfigMap = {} g_motionDirConfigMap['../../../Data/woody2/Motion/Physics2/'] = \ {'footRot': mm.exp(mm.vec3(1,0,0), -.4), 'yOffset': .0, 'scale':1.,'rootRot': mm.i_so3()} g_motionDirConfigMap['../../../Data/woody2/Motion/Balancing/'] = \ {'footRot': mm.exp(mm.vec3(1,-.5,0), -.6), 'yOffset': .0, 'scale':1.,'rootRot': mm.exp(mm.vec3(1,0,0), .01)} g_motionDirConfigMap['../../../Data/woody2/Motion/Picking/'] = \ {'footRot': mm.exp(mm.vec3(1,0,0), -.5), 'yOffset': .0, 'scale':1.,'rootRot': mm.i_so3()} g_motionDirConfigMap['../../../Data/woody2/Motion/Samsung/'] = \ {'footRot': mm.rotX(-.5), 'yOffset': .0, 'scale':2.53999905501,'rootRot': mm.i_so3()} g_motionDirConfigMap['../../../Data/woody2/Motion/VideoMotion/'] = \ {'footRot': mm.exp(mm.vec3(1,0,0), -.05), 'yOffset': .01, 'scale':2.53999905501,'rootRot': mm.exp(mm.vec3(1,0,0), .0)} if __name__=='__main__': #=============================================================================== # initialize motion #=============================================================================== motionFiles = []
hRef = .1 vRef = .5 clHeel = yma.getElementContactStates(motion, LFOOT, hRef, vRef) crHeel = yma.getElementContactStates(motion, RFOOT, hRef, vRef) clToe = yma.getElementContactStates(motion, LTOE, hRef, vRef) crToe = yma.getElementContactStates(motion, RTOE, hRef, vRef) clFoot = list(map(op.or_, clHeel, clToe)) crFoot = list(map(op.or_, crHeel, crToe)) lFootStates = yma.getFootStates(clHeel, clToe) rFootStates = yma.getFootStates(crHeel, crToe) lIntervals, lStates = yma.states2intervals(lFootStates) rIntervals, rStates = yma.states2intervals(rFootStates) footNames = [LFOOT, RFOOT] horizontalDirection = mm.vec3(-1, 0, 0) horizontalRight = np.cross(horizontalDirection, (0, 1, 0)) horizontalLeft = -horizontalRight sagittalAxis = horizontalRight lateralAxisMap = {LFOOT: horizontalDirection, RFOOT: -horizontalDirection} size_sagittals_map = { LFOOT: [None] * len(motion), RFOOT: [None] * len(motion) } size_laterals_map = { LFOOT: [None] * len(motion), RFOOT: [None] * len(motion) } for i in range(len(motion)):