def joint2mm_Posture(jointPosture, pointSkeleton): pointPosture = ym.PointPosture(pointSkeleton) for joint in jointPosture.skeleton.joints.values(): if not (joint.parent != None and len(joint.parent.children) > 1): pointPosture.addPoint(joint.name, jointPosture.getGlobalPos(joint.name)) return pointPosture
def mesh2PointPosture(mesh, pointSkeleton=None): if pointSkeleton==None: pointSkeleton = ym.PointSkeleton() for i in range(mesh.getVertexNum()): pointSkeleton.addElement(None, None) pointPosture = ym.PointPosture(pointSkeleton) # for v in mesh.vertices: # pointPosture.addPoint2(v.pos) for i in range(mesh.getVertexNum()): pointPosture.setPosition(i, mesh.vertices[i].pos) return pointPosture
def readTrcFile(trcFilePath, scale=1.0): f = open(trcFilePath) fileLines = f.readlines() pointMotion = ym.Motion() i = 0 while i != len(fileLines): splited = fileLines[i].split() boneNames = [] if i == 2: dataRate = float(splited[0]) numFrames = int(splited[2]) numMarkers = int(splited[3]) # print numFrames, numMarkers elif i == 3: markerNames = [name.split(':')[1] for name in splited[2:]] skeleton = ym.PointSkeleton() for name in markerNames: skeleton.addElement(None, name) # print markerNames elif i > 5: markerPositions = splited[2:] # print markerPositions # print 'i', i pointPosture = ym.PointPosture(skeleton) for m in range(numMarkers): point = numpy.array([ float(markerPositions[m * 3]), float(markerPositions[m * 3 + 1]), float(markerPositions[m * 3 + 2]) ]) point = numpy.dot( mm.exp(numpy.array([1, 0, 0]), -math.pi / 2.), point) * scale # pointPosture.addPoint(markerNames[m], point) pointPosture.setPosition(m, point) # print 'm', m # print markerNames[m], (markerPositions[m*3],markerPositions[m*3+1],markerPositions[m*3+2]) pointMotion.append(pointPosture) i += 1 f.close() pointMotion.fps = dataRate return pointMotion