def dump_proj(): camera = 'Camera_Centrifugeuse_Agi' particles = 'Agisoft_Ptc_1' out_path = 'C:/work/tracks.txt' step = 1 export.particlesToTracks(camera, particles, out_path, step=step)
def exportAgiScene(): quiet = True initSel = cmds.ls(sl=1, l=1) showProgWin = 1 div = 100 warn = 'Select Agi Camera Then Agi Sparse Cloud' if len(initSel)==2: cShape = cmds.listRelatives(initSel[0], f=1, typ='shape') pShape = cmds.listRelatives(initSel[1], f=1, typ='shape') if cmds.nodeType(cShape)=='camera' and cmds.nodeType(pShape)=='particle': cws = cmds.workspace(q=1 ,fn=1) wFile = cmds.fileDialog2(cap='Export Agi Scene Description', dir=cws, fm=0, ff='Text Files (*.txt)') if not quiet else ['C:/work/datas/scenes/tde/exports/tdc.txt'] if wFile: pCount = cmds.getAttr(pShape[0] + '.count') if not quiet: resp = cmds.promptDialog(title='Particles step', message='Enter step size over %d particles :' % pCount, button=['OK', 'Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel', text=str(div)) if resp == 'OK': div = int(cmds.promptDialog(query=True, text=True)) else: return allPanels = cmds.getPanel(type = 'modelPanel') minF = int(cmds.playbackOptions(q=1,min=1)) maxF = int(cmds.playbackOptions(q=1,max=1)) frameLength = maxF-minF+1 current = cmds.currentTime(q=1) frame = minF for allPanel in allPanels: cmds.modelEditor(allPanel, e=1, alo=0) # force render settings resolution resolution = cmds.listConnections("defaultRenderGlobals.resolution")[0] cmds.setAttr(resolution + ".width") cmds.setAttr(resolution + ".height") if showProgWin == 1: inc = 1 max = 100 progWin = cmds.window(t='Export Lens', w=350, h=20, s=0) cmds.showWindow(progWin) cmds.columnLayout(progWin) #progBar1 = cmds.progressBar(max=max, w=350, h=20) progBar1 = cmds.progressBar(max=int(pCount / div), w=350, h=20) progBar2 = cmds.progressBar(max=maxF - minF + 1, w=350, h=20) cmds.progressBar(progBar1, e=1, s=1) cmds.progressBar(progBar2, e=1, s=1) wFile = wFile[0] path = wFile.split('.txt')[0] #path = 'C:/test' lensFile = (path + '_Lens.txt') trackFile = (path + '_Tracks.txt') surveyFile = (path + '_Surveys.txt') #fLens = open(lensFile, 'w') #fSurveys = open(surveyFile, 'w') with open(lensFile, 'w') as fLens: # LENS FILE hfa = cmds.getAttr(cShape[0] + '.hfa') vfa = cmds.getAttr(cShape[0] + '.vfa') fl = cmds.getAttr(cShape[0] + '.fl') fa = str(hfa/vfa) hfacm = str(hfa*2.54) vfacm = str(vfa*2.54) flmm = str(fl/10) fLens.write('Agisoft_lens\r\n' + hfacm + ' ' + vfacm + ' ' + flmm + ' ' + fa + ' 0 0 1\r\n') fLens.write('DISTORTION_STATIC\r\n3DE Classic LD Model\r\nDistortion\r\n0\r\n0\r\nAnamorphic Squeeze\r\n1\r\n1\r\n0.1 1 -1 0 1 0 LINEAR\r\n') fLens.write('Curvature X\r\n0\r\n0\r\nCurvature Y\r\n0\r\n0\r\nQuartic Distortion\r\n0\r\n0\r\n<end_of_file>\r\n') fLens.write('<begin_2dlut_samples>\r\nDistortion\r\n0\r\nAnamorphic Squeeze\r\n1\r\nCurvature X\r\n0\r\nCurvature Y\r\n0\r\nQuartic Distortion\r\n0\r\n<end_2dlut_samples>') # SURVEY FILE if showProgWin == 1: cmds.window(progWin, e=1, t='Export Survey File') cmds.refresh(progBar1) prefix = 'agisoft_' with open(surveyFile, 'w') as fSurveys: partDag = projcam.getDagPath(initSel[1]) positions = projcam.getParticlesPosition(partDag) inc = 0 wid = 1 for pid in xrange(0, positions.length(), div): pos = positions[pid] name = '%s%d' % (prefix, wid) fSurveys.write('%s %.10f %.10f %.10f%s' % (name, pos.x, pos.y, pos.z, os.linesep)) cmds.progressBar(progBar1, e=1, s=1) wid += 1 # TRACK FILE if showProgWin == 1: cmds.window(progWin, e=1, t='Export Tracks File') export.particlesToTracks(initSel[0], initSel[1], trackFile, prefix=prefix, step=div, start=minF, end=maxF, pBar=(progBar2 if showProgWin == 1 else None)) if showProgWin == 1: cmds.progressBar(progBar1, ep=1) cmds.progressBar(progBar2, ep=1) cmds.deleteUI(progWin, wnd=1) for allPanel in allPanels: cmds.modelEditor(allPanel, e=1, alo=1) else: cmds.warning(warn) else: cmds.warning(warn) #exportAgiScene()