def test_ObjectInfoWnd(): bvhFilePath = '../samples/wd2_WalkSameSame00.bvh' jointMotion1, frameTime = yf.readBvhFileAsJointMotion(bvhFilePath, .01) bvhFilePath = '../samples/wd2_WalkForwardVFast00.bvh' jointMotion2, frameTime = yf.readBvhFileAsJointMotion(bvhFilePath, .01) meshFilePath = '../samples/physics2_woody_binding1.mesh.xml' skinMesh, js = yol.readOgreDataFiles(meshFilePath, .01) meshFilePath = '../samples/physics2_woody_binding1.mesh.xml' mesh = yol.readOgreMeshFileAsMesh(meshFilePath, .01) ysu.mergePoints(skinMesh) ysu.mergePoints(mesh) skinMesh.update(js[0][80]) viewer = SimpleViewer() viewer.doc.addRenderer('motion1(%s)'%jointMotion1.resourceName, yr.JointMotionRenderer(jointMotion1, (0, 0, 255), yr.LINK_LINE)) viewer.doc.addObject('motion1(%s)'%jointMotion1.resourceName, jointMotion1) viewer.doc.addRenderer('motion2(%s)'%jointMotion2.resourceName, yr.JointMotionRenderer(jointMotion2, (0, 0, 255), yr.LINK_LINE)) viewer.doc.addObject('motion2(%s)'%jointMotion1.resourceName, jointMotion2) viewer.doc.addRenderer('skinMesh', yr.MeshRenderer(skinMesh)) viewer.doc.addObject('skinMesh', skinMesh) viewer.doc.addRenderer('mesh', yr.MeshRenderer(mesh)) viewer.doc.addObject('mesh', mesh) viewer.startTimer(frameTime) viewer.show() Fl.run()
def test_compare_skeletonanimation_vs_bvhmotion(): meshFilePath = '../samples/physics2_woody_binding1.mesh.xml' skeletonFilePath = '../samples/physics2_woody_binding1.skeleton.xml' skeletonMesh, skeletonMotions = readOgreDataFiles( meshFilePath, .01, skeletonFilePath) skeletonMotion = skeletonMotions[0] ysu.mergePoints(skeletonMesh) bvhMotion = yf.readBvhFile('../samples/wd2_WalkSameSame00.bvh', .01) bvhMesh = copy.deepcopy(skeletonMesh) # bvhMesh.initialize(bvhMotion[0]) viewer = ysv.SimpleViewer() viewer.doc.addRenderer( 'skeletonMotion', yr.JointMotionRenderer(skeletonMotion, (0, 0, 255), yr.LINK_LINE)) viewer.doc.addMotion2('skeletonMotion', skeletonMotion) viewer.doc.addRenderer( 'skeletonMesh', yr.MeshRenderer(skeletonMesh, (255 * .5, 255 * .5, 255))) viewer.doc.addRenderer( 'bvhMotion', yr.JointMotionRenderer(bvhMotion, (0, 255, 0), yr.LINK_LINE)) viewer.doc.addMotion2('bvhMotion', bvhMotion) viewer.doc.addRenderer( 'bvhMesh', yr.MeshRenderer(bvhMesh, (255 * .5, 255, 255 * .5))) def preFrameCallback(frame): if frame < len(skeletonMotion): skeletonMesh.update(skeletonMotion[frame]) if frame < len(bvhMotion): bvhMesh.update(bvhMotion[frame]) viewer.setPreFrameCallback(preFrameCallback) viewer.startTimer(1 / 30.) viewer.show() Fl.run()
def main(): # mesh = yol.readOgreMeshFileAsMesh('Data/box_rotate.mesh.xml', .1) # mesh = yol.readOgreMeshFileAsMesh('Data/box.mesh.xml', .1) # mesh = yol.readOgreMeshFileAsMesh('Data/foot_box.mesh.xml', .1) # mesh = yol.readOgreMeshFileAsMesh('Data/woody2_4.mesh.xml', .01) mesh, motions = yol.readOgreDataFiles('Data/woody2_7.mesh.xml', .01, None) ysu.mergePoints(mesh) print 'MESH' print mesh motion, frameTime = yf.readBvhFileAsJointMotion( 'Data/wd2_WalkSameSame00.bvh', .01) motion = motion[:100] mesh.update(motion[0]) config = {} config['meshKs'] = 10000. config['meshKd'] = 500. config['muscleKs'] = 10000. config['muscleKd'] = 500. config['footKs'] = 10000. config['footKd'] = 500. # config['2D'] = True config['vertexMasses'] = [1.] * len(mesh.vertices) config['mu'] = 1. model = csm.SpringModel3D(mesh, config) print 'MODEL' print model print viewer = ysv.SimpleViewer() viewer.doc.addRenderer('mesh', yr.MeshRenderer(mesh)) viewer.doc.addObject('mesh', mesh) viewer.doc.addRenderer( 'model', csr.SpringModel3DRenderer(model, (255, 255, 255), True, True)) viewer.setRecSimulObjs([model]) viewer.setMaxFrame(len(motion) - 1) frameTime = 1. / 30. stepsPerFrame = 10 timeStep = frameTime / stepsPerFrame print 'SIMULATION' print 'timeStep', timeStep print # with rendering pt = [0] def preFrameCallback(frame): if frame == 0: pt[0] = time.time() mesh.update(motion[frame]) def simulateCallback(frame): print frame model.updateSprings(mesh) for i in range(int(stepsPerFrame)): model.step(timeStep) print frame, model.getUpperCOMPos()[1] if frame == len(motion) - 1: print 'elapsed time:', time.time() - pt[0] viewer.setPreFrameCallback(preFrameCallback) viewer.setSimulateCallback(simulateCallback) # # without rendering # pt = time.time() # for frame in range(len(motion)): # motion.frame = frame # mesh.update(motion[frame]) # model.updateSprings(mesh) # for step in range(int(stepsPerFrame)): # model.step(timeStep) # print 'elapsed time:', time.time()-pt viewer.startTimer(frameTime) viewer.show() Fl.run()