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_joint2Point_Motion(): bvhFilePath = '../samples/physics2_WalkSameSame00.bvh' jointMotion, frameTime = yf.readBvhFileAsJointMotion(bvhFilePath, .1) pointMotion = joint2Point_Motion(jointMotion) print 'jointMotion.skeleton', jointMotion[0].skeleton print 'pointMotion.skeleton', pointMotion[0].skeleton print 'jointMotion.skeleton - pointMotion.skeleton', set( jointMotion[0].skeleton.joints.keys( )) - pointMotion[0].skeleton.pointSet print 'pointMotion.skeleton - jointMotion.skeleton', pointMotion[ 0].skeleton.pointSet - set(jointMotion[0].skeleton.joints.keys()) motionSystem = ym.MotionSystem() motionSystem.addMotion(pointMotion) motionSystem.addMotion(jointMotion) renderers = [] renderers.append(yr.PointMotionRenderer(pointMotion)) renderers.append( yr.JointMotionRenderer(jointMotion, (0, 255, 0), yr.LINK_LINE)) viewer = yv.Viewer2(100, 100, 800, 650, None, motionSystem, renderers) viewer.startTimer(frameTime) viewer.show() Fl.run()
def test_joint2Point_Motion(): bvhFilePath = '../samples/physics2_WalkSameSame00.bvh' jointMotion, frameTime = yf.readBvhFileAsJointMotion(bvhFilePath, .1) # bvhFilePath = '../../../Walking/ppmotion/wd2_WalkForwardNormal00.bvh' # jointMotion = yf.readBvhFile(bvhFilePath) # frameTime = 1/jointMotion.fps pointMotion = joint2Point_Motion(jointMotion) # pointMotion = joint2mm_Motion(jointMotion) print('jointMotion.skeleton', jointMotion[0].skeleton) print('pointMotion.skeleton', pointMotion[0].skeleton) print('jointMotion.skeleton - pointMotion.skeleton', set(jointMotion[0].skeleton.joints.keys()) - pointMotion[0].skeleton.pointSet) print('pointMotion.skeleton - jointMotion.skeleton', pointMotion[0].skeleton.pointSet - set(jointMotion[0].skeleton.joints.keys())) motionSystem = ym.MotionSystem() motionSystem.addMotion(pointMotion) motionSystem.addMotion(jointMotion) renderers = [] renderers.append(yr.PointMotionRenderer(pointMotion)) renderers.append(yr.JointMotionRenderer(jointMotion, (0,255,0), yr.LINK_LINE)) viewer = yv.Viewer2(100, 100, 800, 650, None, motionSystem, renderers) # viewer = yv.MotionViewer(100, 100, 800, 650) viewer.setRenderers(renderers) viewer.setMotionSystem(motionSystem) viewer.startTimer(frameTime) viewer.show() Fl.run()
def test_IMSModel_mesh(): frameTime = 1 / 30. stepsPerFrame = 10 timeStep = frameTime / stepsPerFrame print 'time step', timeStep mesh, t = yol.readOgreDataFiles('../samples/woody2_15.mesh.xml', .01, None) motion, frameTime = yf.readBvhFileAsJointMotion( '../samples/wd2_WalkSameSame00.bvh', .01) mesh.update(motion[0]) dynamicMu = .5 staticMu = 1. particleConfigs = yiu.getParticleConfigsFromMesh(mesh, massMap, motion[:2], dynamicMu, staticMu) Ks = 10000. Kd = 100. springConfigs = yiu.getSpringConfigsFromMesh(mesh, Ks, Kd) systemConfig = cmm.SystemConfig() model = cmm.IMSModel(particleConfigs, springConfigs, systemConfig) viewer = ysv.SimpleViewer() # viewer.record(False) viewer.doc.addRenderer('mesh', yr.MeshRenderer(mesh, (50, 100, 150))) viewer.doc.addObject('mesh', mesh) viewer.doc.addRenderer( 'motion', yr.JointMotionRenderer(motion, (0, 255, 255), yr.LINK_BONE)) viewer.doc.addObject('motion', motion) viewer.doc.addRenderer('model', cr.IMSModelRenderer(model)) # viewer.setRecSimulObjs([model]) def preFrameCallback(frame): mesh.update(motion[frame]) def simulateCallback(frame): model.updateSprings(yiu.getSpringLengthsFromMesh(mesh, springConfigs)) for i in range(int(stepsPerFrame)): model.step(timeStep) viewer.setPreFrameCallback(preFrameCallback) viewer.setSimulateCallback(simulateCallback) viewer.startTimer(1 / 30.) viewer.show() Fl.run()
def test_joint2Point_Motion(): bvhFilePath = '../samples/physics2_WalkSameSame00.bvh' jointMotion, frameTime = yf.readBvhFileAsJointMotion(bvhFilePath, .1) pointMotion = joint2Point_Motion(jointMotion) print 'jointMotion.skeleton', jointMotion[0].skeleton print 'pointMotion.skeleton', pointMotion[0].skeleton print 'jointMotion.skeleton - pointMotion.skeleton', set(jointMotion[0].skeleton.joints.keys()) - pointMotion[0].skeleton.pointSet print 'pointMotion.skeleton - jointMotion.skeleton', pointMotion[0].skeleton.pointSet - set(jointMotion[0].skeleton.joints.keys()) motionSystem = ym.MotionSystem() motionSystem.addMotion(pointMotion) motionSystem.addMotion(jointMotion) renderers = [] renderers.append(yr.PointMotionRenderer(pointMotion)) renderers.append(yr.JointMotionRenderer(jointMotion, (0,255,0), yr.LINK_LINE)) viewer = yv.Viewer2(100, 100, 800, 650, None, motionSystem, renderers) viewer.startTimer(frameTime) viewer.show() Fl.run()
import psyco psyco.full() from fltk import * import sys sys.path.append('../PyCommon/modules') import Math.mmMath as mmMath import Resource.ysMotionLoader as yf import Renderer.ysRenderer as yr import GUI.ysSimpleViewer as ysv if __name__ == "__main__": motion0, frameTime = yf.readBvhFileAsJointMotion( 'Data/wd2_WalkSameSame00.bvh', .01) motion1, frameTime = yf.readBvhFileAsJointMotion( 'Data/wd2_spiral_walk_normal05.bvh', .01) length0 = mmMath.length(motion0[0].getGlobalPos('RightUpLeg') - motion0[0].getGlobalPos('RightLeg')) length1 = mmMath.length(motion1[0].getGlobalPos('RightUpLeg') - motion1[0].getGlobalPos('RightLeg')) scale = length0 / length1 print 'scale', scale scaledMotion1, frameTime = yf.readBvhFileAsJointMotion( 'Data/wd2_spiral_walk_normal05.bvh', .01 * scale) viewer = ysv.SimpleViewer() viewer.record(False) viewer.doc.addRenderer( 'motion0', yr.JointMotionRenderer(motion0, (255, 0, 0), yr.LINK_BONE))
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()