mddWriter.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:pw_mGeoExporter 作者: paulwinex 项目源码 文件源码
def export(self, path, start, end, step, scale):
        #open file
        res = True
        try:
            mddFile = open(path, 'wb')
        except IOError:
            self.par.msg2(1, 'Error open file ' + path)
            return False
        #get objects
        selection = om.MSelectionList()
        om.MGlobal.getActiveSelectionList(selection)
        pivotFilterSelection = self.filterObjects(selection)

        #first frame
        cmds.currentTime(start, edit=True)
        vertexPositionList = self.getPoints(selection, scale, pivotFilterSelection)
        #variables
        fps = float(mel.eval('currentTimeUnitToFPS'))
        self.par.msg2(2, 'FPS:', fps)
        numframes = int((end - start + 1)/step)
        numverts = len(vertexPositionList)/3
        self.pointCount = numverts
        print 'Frames', numframes
        print  'Point count', numverts
        #start write to file
        mddFile.write(struct.pack(">2i", numframes, numverts))
        times = [(frame/fps)*step for frame in xrange(numframes)]
        # print times
        mddFile.write(struct.pack(">%df" % numframes, *times))
        mddFile.write(struct.pack(">%df" % (numverts*3), *[v for v in vertexPositionList]))
        prev = 0
        #write sequence
        cmds.progressBar(self.par.progress, edit=True, pr=0)
        frame = start
        while frame < end+1:
            # if cmds.progressBar(self.par.progress, q=1, ic=1):
            if self.par.isCacneled():
                self.par.caselExport()
                res =  False
                break
            rng = end-start
            prc = (frame*100.0)/(end-start)
            cmds.progressBar(self.par.progress, edit=True, pr=int(prc))
            prev = int(prc)
            cmds.currentTime(frame, edit=True)
            self.par.statusMsg('Write cache frame '+str(frame))
            vertexPositionList = self.getPoints(selection, scale, pivotFilterSelection)
            if not (numverts*3) == len(vertexPositionList):
                om.MGlobal.displayError('TOPOLOGY HAS CHANGED!!!')
                self.par.msg2(1, 'TOPOLOGY HAS CHANGED!!!')
                res =  False
                break
            mddFile.write(struct.pack(">%df" % (numverts*3), *[v for v in vertexPositionList]))
            frame += step
        #close file
        mddFile.close()
        cmds.currentTime(start, edit=True)
        return res
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号