def CreateScene(pSdkManager, pScene, files): lSceneInfo = KFbxDocumentInfo.Create(pSdkManager, "SceneInfo") lSceneInfo.mTitle = "Body scan" lSceneInfo.mSubject = "A body scan" lSceneInfo.mAuthor = "Team KinectOpenNiRosBoostGraphLibDaiPclEigen" lSceneInfo.mRevision = "rev. 0.1" lSceneInfo.mKeywords = "body mesh rigged" lSceneInfo.mComment = "no comments" pScene.SetSceneInfo(lSceneInfo) import os,glob skelFiles = glob.glob(os.path.dirname(files['skeleton'])+'/*.yaml') skelFiles.sort() print 'starting export' baseSkeletonData = Skeleton.fromFunnyYaml(skelFiles[0]) print 'imported skeleton' lMeshNode,T,V = CreateMesh(pSdkManager, files['obj']) pScene.GetRootNode().AddChild(lMeshNode) print 'converted mesh' CreateSkeletonNodes(pSdkManager, "Skeleton", baseSkeletonData) pScene.GetRootNode().AddChild(baseSkeletonData.torsoNode) return print 'created skeleton' LinkMeshToSkeleton(lSdkManager, lMeshNode, baseSkeletonData, files['weights']) print 'added skin' print 'now adding animation (slow)' skels = [(int(fname[-10:-5])/15.,Skeleton.fromFunnyYaml(fname)) for fname in skelFiles[1:]] print 'imported all skeletons' AnimateSkeleton(pSdkManager, pScene, baseSkeletonData, skels) print 'animated skeleton' return True
def main(): assert len(sys.argv) >= 4 pcdFile = sys.argv[1] yamlFile = sys.argv[2] outputFile = sys.argv[3] if len(sys.argv) == 5: offset = float(sys.argv[4])/2 # for displaying several together, non overlapping else: offset = 0 assert pcdFile.endswith('pcd') assert yamlFile.endswith('yaml') assert outputFile.endswith('obj') weightFile = 'temp-weights' cmd = '../segmentation/build/sharpSegmentation %s %s %s'%(pcdFile,yamlFile,weightFile) assert os.system(cmd) == 0 skel = Skeleton.fromFunnyYaml(yamlFile, relative=False) # save it so that they all use the same skel canonFile = 'canon.pickle' if os.path.exists(canonFile): canon = pickle.load(open(canonFile,'r')) else: canon = skel.Duplicate() canon.Canonicalize() #canon.sk = None #safe? pickle.dump(canon, open(canonFile,'w')) points = list(pcd.read(pcdFile)) weights = ReadWeights(weightFile) I = ((1,0,0),(0,1,0),(0,0,1)) newPoints = [[offset,0,0,r,g,b] for (_,_,_,r,g,b) in points] if True: # the right code for jointName,skin in weights.iteritems(): src = Frame(skel.GetRot(jointName), skel.GetPos(jointName)) dst = Frame(I, canon.GetPos(jointName)) print jointName,src.o,dst.o for index,weight in skin: plusEq(newPoints[index], mult(absolute(dst, relative(src, points[index])), weight)) else: # tesing code j = 0 for jointName,skin in weights.iteritems(): src = Frame(skel.GetRot(jointName), skel.GetPos(jointName)) dst = Frame(I, canon.GetPos(jointName)) print jointName,src.o,dst.o for index,weight in skin: plusEq(newPoints[index], relative(src, points[index])) plusEq(newPoints[index], (j,0,0)) j += 0.5 f = open(outputFile, 'w') for row in newPoints: if row[0] == row[0]: f.write('v %f %f %f %f %f %f\n'%tuple(row)) f.close() print 'output to',outputFile
def CreateScene(pSdkManager, pScene, files): lSceneInfo = KFbxDocumentInfo.Create(pSdkManager, "SceneInfo") lSceneInfo.mTitle = "Body scan" lSceneInfo.mSubject = "A body scan" lSceneInfo.mAuthor = "Team KinectOpenNiRosBoostGraphLibDaiPclEigen" lSceneInfo.mRevision = "rev. 0.1" lSceneInfo.mKeywords = "body mesh rigged" lSceneInfo.mComment = "no comments" pScene.SetSceneInfo(lSceneInfo) import os, glob skelFiles = glob.glob(os.path.dirname(files['skeleton']) + '/*.yaml') skelFiles.sort() print 'starting export' baseSkeletonData = Skeleton.fromFunnyYaml(skelFiles[0]) print 'imported skeleton' lMeshNode, T, V = CreateMesh(pSdkManager, files['obj']) pScene.GetRootNode().AddChild(lMeshNode) print 'converted mesh' CreateSkeletonNodes(pSdkManager, "Skeleton", baseSkeletonData) pScene.GetRootNode().AddChild(baseSkeletonData.torsoNode) return print 'created skeleton' LinkMeshToSkeleton(lSdkManager, lMeshNode, baseSkeletonData, files['weights']) print 'added skin' print 'now adding animation (slow)' skels = [(int(fname[-10:-5]) / 15., Skeleton.fromFunnyYaml(fname)) for fname in skelFiles[1:]] print 'imported all skeletons' AnimateSkeleton(pSdkManager, pScene, baseSkeletonData, skels) print 'animated skeleton' return True
def main(): assert len(sys.argv) >= 4 pcdFile = sys.argv[1] yamlFile = sys.argv[2] outputFile = sys.argv[3] if len(sys.argv) == 5: offset = float( sys.argv[4] ) / 2 # for displaying several together, non overlapping else: offset = 0 assert pcdFile.endswith('pcd') assert yamlFile.endswith('yaml') assert outputFile.endswith('obj') weightFile = 'temp-weights' cmd = '../segmentation/build/sharpSegmentation %s %s %s' % ( pcdFile, yamlFile, weightFile) assert os.system(cmd) == 0 skel = Skeleton.fromFunnyYaml(yamlFile, relative=False) # save it so that they all use the same skel canonFile = 'canon.pickle' if os.path.exists(canonFile): canon = pickle.load(open(canonFile, 'r')) else: canon = skel.Duplicate() canon.Canonicalize() #canon.sk = None #safe? pickle.dump(canon, open(canonFile, 'w')) points = list(pcd.read(pcdFile)) weights = ReadWeights(weightFile) I = ((1, 0, 0), (0, 1, 0), (0, 0, 1)) newPoints = [[offset, 0, 0, r, g, b] for (_, _, _, r, g, b) in points] if True: # the right code for jointName, skin in weights.iteritems(): src = Frame(skel.GetRot(jointName), skel.GetPos(jointName)) dst = Frame(I, canon.GetPos(jointName)) print jointName, src.o, dst.o for index, weight in skin: plusEq( newPoints[index], mult(absolute(dst, relative(src, points[index])), weight)) else: # tesing code j = 0 for jointName, skin in weights.iteritems(): src = Frame(skel.GetRot(jointName), skel.GetPos(jointName)) dst = Frame(I, canon.GetPos(jointName)) print jointName, src.o, dst.o for index, weight in skin: plusEq(newPoints[index], relative(src, points[index])) plusEq(newPoints[index], (j, 0, 0)) j += 0.5 f = open(outputFile, 'w') for row in newPoints: if row[0] == row[0]: f.write('v %f %f %f %f %f %f\n' % tuple(row)) f.close() print 'output to', outputFile