示例#1
0
def GetTerrain(chunklist):
    global mVertRows
    global mVertCols
    global heights
    
    nowPath = os.getcwd()
    temppath = nowPath + '\\' + 'temp\\'
    terrainpath = temppath + 'terrain'

    
    vertexPoseslist = []
    vertexTcslist = []
    vertexNormalslist = []
    indexslist = []
    fileName = []

    hash_map = []
    resultdict = {}
    for chunk in chunklist:
        if chunk[:-6] in hash_map:
            continue
        hash_map.append(chunk[:-6])
        filepath = chunk.replace('.chunk', '.cdata') 
        chunkfilepath = chunk.replace('.cdata', '.chunk')
        CorrectDir = GetCorrectDir(chunkfilepath)
        idx = chunkfilepath.find(GetCorrectDir(chunkfilepath))
        fileName.append(chunk[idx + len(CorrectDir) + 1:-6])
        
        tempdict = xp.ParseChunkXml(chunkfilepath)
        resultdict.update(tempdict)
        matrix = tempdict.get(chunkfilepath)
        binsec.extract(filepath, temppath)

        terrainInfo = rotate_height.rotate(terrainpath)

        dh.cleanDir(temppath)
        os.rmdir(temppath)

        mVertRows = terrainInfo[0]
        mVertCols = terrainInfo[1]
        

        heights = terrainInfo[2]
        
        assert mVertRows == mVertCols and (mVertRows == 28 or mVertRows == 53)  
        
        Pos, Tcs, Normal, Index = BuildGeometry(matrix)

        vertexPoseslist.append(Pos)
        vertexTcslist.append(Tcs)
        vertexNormalslist.append(Normal)
        indexslist.append(Index)

    return vertexPoseslist, vertexTcslist, vertexNormalslist, indexslist, fileName, mVertRows == 28, resultdict
示例#2
0
def GetInfoFromPrimitives(filename):
    indexList = []
    vertexList = []
    vertexs = []
    index = []
    groupList = []
    indexFormat = ''

    dh.cleanDir(temppath)

    if os.path.isdir(temppath):
        os.rmdir(temppath)
    
    binsec.extract(filename, temppath)
    listItems = os.listdir(temppath)
    for listItem in listItems:
        if listItem.find('vertices') != -1:
            vertexList.append(listItem)
        elif listItem.find('indices') != -1:
            indexList.append(listItem)

    #read vertex information
    for vertex in vertexList:
        f = open(temppath + "\\" + vertex, 'rb')

        dataInfo = f.read(64 + 4)
        dataValue = struct.unpack('64s1i', dataInfo)
        vertexFormat = dataValue[0]
        vertexNumber = dataValue[1]
        
        vertexFormatEnd = ''
        
        for char in vertexFormat:
            if char >= 'a' and char <= 'z':
                vertexFormatEnd += char
            else:
                break
        
        for i in xrange(0, vertexNumber):
            vertexInfo = f.read(32)

            vertexValue = struct.unpack('3f1I2f1I1I', vertexInfo)
            vPos = (vertexValue[0], vertexValue[1], vertexValue[2])
            vUV = (vertexValue[4], vertexValue[5])
            vNormal = unpackIntToFloat(vertexValue[3])
            vT = unpackIntToFloat(vertexValue[6])
            vB = unpackIntToFloat(vertexValue[7])
            vertexs.append((vPos, vUV, vNormal, vT, vB))
        
        f.close()

    for indice in indexList:
        f = open(temppath + '\\' + indice, 'rb')
        indiceInfo = f.read(64 + 4 + 4)

        indiceValue = struct.unpack('64s2i', indiceInfo)
        indiceFormat = indiceValue[0]
        indiceNumber = indiceValue[1]
        groupNumber = indiceValue[2]
        for indicenumber in xrange(0, indiceNumber):
            DataInfo = f.read(2)
            DataValue = struct.unpack('H', DataInfo)[0]

            index.append(DataValue)
        
        for groupnumber in xrange(0, groupNumber):
            groupInfo = []
            for i in xrange(0, 4):
                groupData = f.read(4)
                groupValue = struct.unpack('i', groupData)[0]
                groupInfo.append(groupValue)
            groupList.append(groupInfo)

        f.close()

    if not DEBUG:
        dh.cleanDir(temppath)
        if os.path.isdir(temppath):
            os.rmdir(temppath)

    return (vertexs, index, groupList, vertexFormat, vertexFormatEnd, indexFormat)