def parse_textures(self, filename):
     
     try:
         dirpath = rapi.getDirForFilePath(rapi.getInputName())
         f = open(dirpath + filename + ".tex", 'rb')
         data = f.read()
         bs = NoeBitStream(data)
         
         header = bs.readBytes(4)
         size, numTex, null = bs.read('3L')
         for i in range(numTex):
             texSize = bs.readUInt()
             texFmt = noeStrFromBytes(bs.readBytes(4))
             if texFmt == "tex":
                 texFmt = "dds"
             bs.read('2L')
             texName = noeStrFromBytes(bs.readBytes(32))
             texData = bs.readBytes(texSize)
             
             tex = rapi.loadTexByHandler(texData, "." + texFmt)
             if tex is not None:
                 tex.name = texName
                 self.texList.append(tex)
     except:
         pass
    def parse_textures(self, numTex):

        for i in range(numTex):
            texName = self.read_name(260)

            if not isinstance(texName, str):
                cut = texName.split(b'\x5C')
                if len(cut) > 1:
                    texName = noeStrFromBytes(cut[-1])
                else:

                    texName = noeStrFromBytes(temp)

            try:
                texName = texName.replace('bmp', 'dds')
                filename, ext = os.path.splitext(texName)
                f = open(self.dirpath + texName, 'rb')
                tex = rapi.loadTexByHandler(f.read(), ext)
                if tex is not None:
                    tex.name = texName
                    self.texList.append(tex)
                else:

                    tex = NoeTexture("dummy", 0, 0, 0, 0)
                    self.texList.append(tex)
            except:
                print("Couldn't find file: %s" % texName)
                tex = NoeTexture("dummy", 0, 0, 0, 0)
                self.texList.append(tex)
 def parse_file(self):
     
     idstring = self.inFile.readBytes(4)
     filesize = self.inFile.readUInt()
     
     numTex = self.inFile.readUShort()
     self.inFile.readUShort()
     self.inFile.seek(52, 1)
     
     texInfo = []
     for i in range(numTex):
         tex = Texture()
         tex.name = self.read_name(16)
         tex.offset = self.inFile.readUInt()
         tex.size = self.inFile.readUInt()
         self.inFile.read('4H')
         texInfo.append(tex)
         
     for entry in texInfo:
         self.inFile.seek(entry.offset)
         data = self.inFile.readBytes(entry.size)
         tex = rapi.loadTexByHandler(data, '.dds')
         if tex:
             tex.name = entry.name
             self.texList.append(tex)
    def write_textures(self):

        #how many textures we actually find
        texFound = 0
        numTex = len(self.texList)
        pos = self.outFile.tell()
        self.outFile.writeUInt(numTex)
        for tex in self.texList:
            texName = tex.name
            unk1 = b'\x00\x00\x00\x00'
            unk2 = b'\x01\x00\x00\x00\x01\x00\x00\x00\x14\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00'
            texture = rapi.loadTexByHandler(tex.data, tex.ext)
            if texture:
                self.write_name(texName)
                self.outFile.writeBytes(unk1)
                self.outFile.writeUInt(texture.width)
                self.outFile.writeUInt(texture.height)
                self.outFile.writeBytes(unk2)
                self.outFile.writeByte(1)  #checksum
                self.outFile.writeUInt(tex.size)
                self.outFile.writeBytes(tex.data)
                texFound += 1
            else:
                print("%s not found" % texName)
                continue

        curr = self.outFile.tell()
        self.outFile.seek(pos)
        self.outFile.writeUInt(texFound)
        self.outFile.seek(curr)
    def __load_sub__(self, start, size):
        self.log("Load_Sub: Start={}, Size={} ", start, size)

        # Read TGA from buffer
        self.bs.seek(start)
        buffer = self.bs.readBytes(size)
        tex = rapi.loadTexByHandler(buffer, '.tga')
        tex.name = "{0}.{1:02}.tga".format(self.name, self.count)

        if not tex:
            return 0, 0, 0

        # Check if it's 1BPP, 3BPP, or 4BPP
        # https://github.com/python-pillow/Pillow/blob/7aaf021822297a0c5aae258a9f68adfd2b590258/src/PIL/TgaImagePlugin.py
        self.bs.seek(start)
        tga_header = self.bs.readBytes(18)
        image_type = int.from_bytes(tga_header[2:4], byteorder='little')

        if image_type in (1, 9):
            bpp = 1
        elif image_type in (2, 10):
            if tex.pixelType == noesis.NOESISTEX_RGBA32:
                bpp = 4
            elif tex.pixelType == noesis.NOESISTEX_RGB24:
                bpp = 3
        else:
            bpp = 4
            self.log("Unsupported pixel type: {}", tex.pixelType)

        self.count += 1
        self.tex_list.append(tex)
        return tex, bpp
 def write_textures(self):
     
     #how many textures we actually find
     texFound = 0
     numTex = len(self.texList)
     pos = self.outFile.tell()
     self.outFile.writeUInt(numTex)
     for tex in self.texList:
         texName = tex.name
         unk1 = b'\x00\x00\x00\x00'
         unk2 = b'\x01\x00\x00\x00\x01\x00\x00\x00\x14\x00\x00\x00\x03\x00\x00\x00\x03\x00\x00\x00'
         texture = rapi.loadTexByHandler(tex.data, tex.ext)
         if texture:
             self.write_name(texName)
             self.outFile.writeBytes(unk1)
             self.outFile.writeUInt(texture.width)
             self.outFile.writeUInt(texture.height)
             self.outFile.writeBytes(unk2)
             self.outFile.writeByte(1) #checksum
             self.outFile.writeUInt(tex.size)
             self.outFile.writeBytes(tex.data)
             texFound += 1
         else:
             print("%s not found" %texName)
             continue
         
     curr = self.outFile.tell()
     self.outFile.seek(pos)
     self.outFile.writeUInt(texFound)
     self.outFile.seek(curr)
 def CreateMaterial(self,index):
     try:mF                  = open( TEXPATH + '/' +self.materials[index] ,'r')
     except:
         for mat in self.materials:print(mat)
         raise
     diffuse     = None
     normal      = None
     specular    = None
     for i in range(10):
         line    = mF.readline()
         line    = ''.join(line.split('\x00')).lower()
         if 'colourtexture' in line:
             diffuse     = line[14:-2].split('art/')[-1]
         elif 'normalspeculartexture' in line:
             normal      = line[14:-2].split('art/')[-1]
             specular    = normal
         mF.readline()
     material            = NoeMaterial( self.meshNames[index] , '' )
     material.setTexture(diffuse.split('/')[-1])
     try:
         material.setNormalTexture(normal.split('/')[-1])
         material.setSpecularTexture(specular.split('/')[-1])
     except: pass
     for t in [diffuse,normal,specular]:
         try:
             tex         = open(TEXPATH + '/' +t,'rb').read()
             tex         = rapi.loadTexByHandler(tex,'.dds')
             tex.name    = t.split('/')[-1]
             self.texList.append(tex)
         except:pass
     self.matList.append(material)
示例#8
0
    def parse_textures(self, filename):

        try:
            dirpath = rapi.getDirForFilePath(rapi.getInputName())
            f = open(dirpath + filename + ".tex", 'rb')
            data = f.read()
            bs = NoeBitStream(data)

            header = bs.readBytes(4)
            size, numTex, null = bs.read('3L')
            for i in range(numTex):
                texSize = bs.readUInt()
                texFmt = noeStrFromBytes(bs.readBytes(4))
                if texFmt == "tex":
                    texFmt = "dds"
                bs.read('2L')
                texName = noeStrFromBytes(bs.readBytes(32))
                texData = bs.readBytes(texSize)

                tex = rapi.loadTexByHandler(texData, "." + texFmt)
                if tex is not None:
                    tex.name = texName
                    self.texList.append(tex)
        except:
            pass
 def parse_textures(self, numTex):
     
     for i in range(numTex):
         texName = self.read_name(260)
         
         if not isinstance(texName, str):
             cut = texName.split(b'\x5C')
             if len(cut) > 1:
                 texName = noeStrFromBytes(cut[-1])
             else:
                 
                 texName = noeStrFromBytes(temp)
         
         try:
             texName = texName.replace('bmp', 'dds')
             filename, ext = os.path.splitext(texName)
             f = open(self.dirpath + texName, 'rb')
             tex = rapi.loadTexByHandler(f.read(), ext)
             if tex is not None:
                 tex.name = texName
                 self.texList.append(tex)
             else:
                 
                 tex = NoeTexture("dummy", 0, 0, 0, 0)
                 self.texList.append(tex)                    
         except:
             print("Couldn't find file: %s" %texName)
             tex = NoeTexture("dummy", 0, 0, 0, 0)
             self.texList.append(tex)
 def parse_texture(self):
         
     size = self.inFile.dataSize - self.inFile.tell()
     data = self.inFile.readBytes(size)
     tex = rapi.loadTexByHandler(data, ".rin")
     print(tex)
     if tex:
         self.texList.append(tex)
    def parse_texture(self):

        size = self.inFile.dataSize - self.inFile.tell()
        data = self.inFile.readBytes(size)
        tex = rapi.loadTexByHandler(data, ".rin")
        print(tex)
        if tex:
            self.texList.append(tex)
示例#12
0
 def parse_file(self):
     
     self.inFile.readBytes(4)
     texData = self.inFile.readBytes(self.inFile.dataSize - 4)
     tex = rapi.loadTexByHandler(texData, ".dds")
     if tex:
         tex.name = "texture"
         self.texList.append(tex)        
示例#13
0
    def CreateGeo(self):
        print(len(self.idxs))
        x = 0
        y = len(self.geos)  #8
        n = []  #[5,6,7]
        GEO_C = 0
        self.matList = []
        self.texList = []
        dirPath = rapi.getDirForFilePath(rapi.getInputName())
        for mat in self.mats:
            self.matList.append(mat.material)
            mat = mat.material
            diffuse = mat.texName
            normal = mat.nrmTexName
            specular = mat.specTexName
            for t in [diffuse, normal, specular]:
                try:
                    tex = open(dirPath + '/' + t, 'rb').read()
                    tex = rapi.loadTexByHandler(tex, '.dds')
                    tex.name = t
                    self.texList.append(tex)
                except:
                    raise

        for i in range(x, x + y):
            #for i in range(len(self.idxs)):
            idx = self.idxs[i]
            geo = self.geos[i]
            prop = geo.props
            print("%d: " % i, idx.name, " | ", geo.name)
            print(idx.numTri, idx.numIdx, geo.numVert)
            if not i in n:

                #material = self.matList[MaterialLink[idx.name]]
                rapi.rpgSetMaterial(MaterialLink[idx.name])
                rapi.rpgBindPositionBufferOfs(geo.vertBuffer,
                                              noesis.RPGEODATA_FLOAT,
                                              geo.vertLength, prop['position'])
                rapi.rpgBindUV1BufferOfs(geo.uvBuffer, noesis.RPGEODATA_FLOAT,
                                         geo.uvLength, prop['tex0'])
                rapi.rpgBindNormalBufferOfs(geo.vertBuffer,
                                            noesis.RPGEODATA_FLOAT,
                                            geo.vertLength, prop['normal'])
                rapi.rpgBindTangentBufferOfs(geo.vertBuffer,
                                             noesis.RPGEODATA_FLOAT,
                                             geo.vertLength, prop['tangent'])
                rapi.rpgCommitTriangles(idx.idxBuffer, noesis.RPGEODATA_USHORT,
                                        idx.numIdx, noesis.RPGEO_TRIANGLE, 1)
                #rapi.rpgCommitTriangles         (idx.idxBuffer,    noesis.RPGEODATA_USHORT, idx.numTri,     noesis.RPGEO_TRIANGLE, 1)
            if GEO_C == 1:
                bs = NoeBitStream()
                fileG = open("geo-%d.p3ddump" % i, 'wb')
                bs.writeUInt(geo.numVert)
                bs.writeBytes(geo.vertBuffer)
                bs.writeUInt(idx.numTri)
                bs.writeBytes(idx.idxBuffer)
                fileG.write(bs.getBuffer())
                fileG.close()
 def parse_textures(self):
     
     for i in range(len(self.textures)):
         texName, offset, texSize = self.textures[i]
         self.inFile.seek(offset)
         tex = tex = rapi.loadTexByHandler(self.inFile.readBytes(texSize), ".bmp")
         if tex is not None:
             tex.name = texName
             self.texList.append(tex)
示例#15
0
def LoadTexture(texName):
    if ARTPATH == None:
        name = rapi.getDirForFilePath(rapi.getInputName())+texName
    else:
        name = texName.split('\\')[-1]
    tex = open(name,'rb').read()
    tex = rapi.loadTexByHandler(tex,'.dds')
    tex.name = texName
    return tex
示例#16
0
 def load_sub(self, start, size):
     self.bs.seek(start)
     buffer = self.bs.readBytes(size)
     tex = rapi.loadTexByHandler(buffer, '.tga')
     if not tex:
         return 0
     tex.name = "{0}.{1:02}.tga".format(self.name, self.count)
     self.count += 1
     self.texList.append(tex)
     return tex
示例#17
0
 def parse_textures(self, numTex):
     
     for i in range(numTex):
         texName = self.read_name()
         texSize = self.inFile.readUInt()
         texData = self.inFile.readBytes(texSize)
         tex = rapi.loadTexByHandler(texData, ".dds")
         if tex is not None:
             tex.name = texName
             self.texList.append(tex)     
 def load_texture(self, name, texID, path):
    
    ext = name[-4:]
    f = open(self.dirpath + name, 'rb')
    tex = rapi.loadTexByHandler(f.read(), ext)
    if tex is not None:
       tex.name = name
       self.texList.append(tex)
       self.texIDs[texID] = tex
    f.close()
    def parse_textures(self):

        for i in range(len(self.textures)):
            texName, offset, texSize = self.textures[i]
            self.inFile.seek(offset)
            tex = tex = rapi.loadTexByHandler(self.inFile.readBytes(texSize),
                                              ".bmp")
            if tex is not None:
                tex.name = texName
                self.texList.append(tex)
示例#20
0
    def parse_texture(self, data):

        matNum = len(self.matList)
        mat = NoeMaterial("material%d" % matNum, "")
        texture = rapi.loadTexByHandler(data, ".dds")
        if texture:
            texture.name = "texture%d" % (len(self.texList))
            self.texList.append(texture)
            mat.setTexture(texture.name)
        self.matList.append(mat)
 def parse_texture(self, data):
 
     matNum = len(self.matList)
     mat = NoeMaterial("material%d" %matNum, "")
     texture = rapi.loadTexByHandler(data, ".dds")
     if texture:
         texture.name = "texture%d" %(len(self.texList))
         self.texList.append(texture)
         mat.setTexture(texture.name)
     self.matList.append(mat)
 def parse_file(self):
     
     idstring = self.inFile.readBytes(3)
     imgType = self.inFile.readByte()
     self.inFile.seek(143, 1)
     self.inFile.readUInt()
     size = self.inFile.readUInt()
     texData = self.inFile.readBytes(size)
     
     tex = None
     if imgType == 0:
         tex = rapi.loadTexByHandler(texData, ".jpg")
     elif imgType in [1, 2]:
         tex = rapi.loadTexByHandler(texData, ".tga")
     else:
         print("unknown image type: %d" %imgType)
     if tex is not None:
         tex.name = "texture"
         self.texList.append(tex)                        
    def parse_file(self):

        idstring = self.inFile.readBytes(3)
        imgType = self.inFile.readByte()
        self.inFile.seek(143, 1)
        self.inFile.readUInt()
        size = self.inFile.readUInt()
        texData = self.inFile.readBytes(size)

        tex = None
        if imgType == 0:
            tex = rapi.loadTexByHandler(texData, ".jpg")
        elif imgType in [1, 2]:
            tex = rapi.loadTexByHandler(texData, ".tga")
        else:
            print("unknown image type: %d" % imgType)
        if tex is not None:
            tex.name = "texture"
            self.texList.append(tex)
示例#24
0
    def parseMaterials(self):
        dirPath = rapi.getDirForFilePath(rapi.getInputName())
        self.data.seek(28)
        self.numMat = self.data.readUInt()
        matOffset = self.data.readUInt()
        self.data.seek(matOffset - 4, 1)
        materialArray = ANetModelMaterialArray(self.data)
        self.data.seek(materialArray.materialOffset - 4, 1)
        current = self.data.tell()
        offsetTable = self.data.read("%di" % materialArray.materialCount)
        diffuse = [0x67531924]
        normal = [2332802439, 2774157488]
        lightmap = [
            1745599879,
        ]
        for i in range(materialArray.materialCount):
            self.data.seek(current + offsetTable[i] + i * 4)
            matInfo = ANetModelMaterialInfo(self.data)
            self.data.seek(matInfo.texturepos + matInfo.textureOffset)
            material = NoeMaterial(str(i), '')
            #material.setBlendMode("GL_SRC_COLOR","GL_ONE")

            texInfos = []
            for t in range(matInfo.textureCount):
                texInfos.append(ANetModelTextureReference(self.data))

            for texInfo in texInfos:
                self.data.seek(texInfo.referencepos +
                               texInfo.offsetToFileReference)
                texInDAT = self.data.read('3H')
                if texInfo.hash in diffuse or texInfo.hash in normal or texInfo.hash in lightmap:
                    texture = 0xFF00 * (texInDAT[1] - 0x100) + (texInDAT[0] -
                                                                0x100) + 1
                    if texInfo.hash in diffuse:
                        material.setTexture(str(texture))
                    elif texInfo.hash in normal:
                        material.setNormalTexture(str(texture))
                    elif texInfo.hash in lightmap:
                        self.lightMapList[i] = NoeMaterial(str(i), "")
                        self.lightMapList[i].setTexture(str(texture))
                        self.lightMapList[i].setBlendMode("GL_ONE", "GL_ONE")
                    try:
                        path = glob.glob(dirPath + str(texture) + '*.atex')[0]
                        tex = open(path, 'rb').read()
                        tex = rapi.loadTexByHandler(tex, '.atex')
                        tex.name = str(texture) + '.atex'
                        self.texList.append(tex)
                    except:
                        print("Can't load", texture)
                else:
                    texture = 0xFF00 * (texInDAT[1] - 0x100) + (texInDAT[0] -
                                                                0x100) + 1
                    #print(texture, texInfo.hash)
            self.matList.append(material)
 def parse_texture(self):
     texName = self.read_name()
     texSize = self.inFile.readUInt()
     texData = self.inFile.readBytes(texSize)
     self.inFile.seek(26, 1)
     
     tex = rapi.loadTexByHandler(texData, ".dds")
     if tex is not None:
         tex.name = texName
         
         self.texList.append(tex)
     return texName
    def parse_texture(self):
        texName = self.read_name()
        texSize = self.inFile.readUInt()
        texData = self.inFile.readBytes(texSize)
        self.inFile.seek(26, 1)

        tex = rapi.loadTexByHandler(texData, ".dds")
        if tex is not None:
            tex.name = texName

            self.texList.append(tex)
        return texName
    def parse_texture(self):

        texName = self.get_texture_name()
        if texName:
            f = open(self.dirpath + texName, 'rb')
            tex = rapi.loadTexByHandler(f.read(), ".dds")
            f.close()
            if tex is not None:
                tex.name = texName
                self.texList.append(tex)
            return texName
        else:
            return ""
    def parse_texture(self):

        texName = self.get_texture_name()
        if texName:
            f = open(self.dirpath + texName, "rb")
            tex = rapi.loadTexByHandler(f.read(), ".dds")
            f.close()
            if tex is not None:
                tex.name = texName
                self.texList.append(tex)
            return texName
        else:
            return ""
示例#29
0
def loadTex(files, fname):
    ftype = os.path.splitext(fname)[1]

    data = None
    if ftype == ".jpg":
        data = find(files["image/jpeg"], "filename", fname)["data"]
    if ftype == ".png":
        data = find(files["image/png"], "filename", fname)["data"]

    tex = rapi.loadTexByHandler(data, ftype)
    tex.name = fname

    return tex
    def parse_textures(self, numTex):

        for i in range(numTex):
            texName = self.read_name()
            texUnk1 = self.inFile.readBytes(4)
            width, height = self.inFile.read('2L')

            texUnk2 = self.inFile.readBytes(20)
            checksum = self.inFile.readByte()
            dataSize = self.inFile.readUInt()
            ext = os.path.splitext(texName)[1]
            data = self.inFile.readBytes(dataSize)
            if ext == ".bmp":
                texData = bytes()
                texData += b'\x42\x4D'
                texData += data[2:]
                tex = rapi.loadTexByHandler(texData, ext)
            else:
                tex = rapi.loadTexByHandler(data, ext)

            if tex is not None:
                tex.name = texName
                self.texList.append(tex)
    def parse_file(self):

        idstring = self.inFile.readBytes(3)
        numTex = self.inFile.readUInt()
        self.inFile.readByte()
        dataSize = self.inFile.readUInt() - 4
        self.inFile.seek(4, 1)
        imgData = bytes()

        imgData += b"\x44\x44\x53\x20"
        imgData += self.inFile.readBytes(dataSize)
        tex = rapi.loadTexByHandler(imgData, '.dds')
        if tex:
            self.texList.append(tex)
 def parse_file(self):
     
     idstring = self.inFile.readBytes(3)
     numTex = self.inFile.readUInt()
     self.inFile.readByte()
     dataSize = self.inFile.readUInt() - 4
     self.inFile.seek(4, 1)
     imgData = bytes()
     
     imgData += b"\x44\x44\x53\x20"
     imgData += self.inFile.readBytes(dataSize)
     tex = rapi.loadTexByHandler(imgData, '.dds')
     if tex:
         self.texList.append(tex)
 def parse_textures(self, numTex):
     
     for i in range(numTex):
         texName = self.read_name()
         texUnk1 = self.inFile.readBytes(4)
         width, height = self.inFile.read('2L')
         
         texUnk2 = self.inFile.readBytes(20)
         checksum = self.inFile.readByte()
         dataSize = self.inFile.readUInt()
         ext = os.path.splitext(texName)[1]
         data = self.inFile.readBytes(dataSize)
         if ext == ".bmp":
             texData = bytes()
             texData += b'\x42\x4D'
             texData += data[2:]
             tex = rapi.loadTexByHandler(texData, ext)
         else:
             tex = rapi.loadTexByHandler(data, ext)
        
         if tex is not None:
             tex.name = texName
             self.texList.append(tex)   
    def CreateGeo(self):
        print(len(self.idxs))
        x=0
        y=len(self.geos)#8
        n = []#[5,6,7]
        GEO_C = 0
        self.matList    = []
        self.texList    = []
        dirPath         = rapi.getDirForFilePath(rapi.getInputName())
        for mat in self.mats:
            self.matList.append(mat.material)
            mat         = mat.material
            diffuse     = mat.texName
            normal      = mat.nrmTexName
            specular    = mat.specTexName
            for t in [diffuse,normal,specular]:
                try:
                    tex         = open(dirPath + '/' +t,'rb').read()
                    tex         = rapi.loadTexByHandler(tex,'.dds')
                    tex.name    = t
                    self.texList.append(tex)
                except:
                    raise
        
        for i in range(x,x+y):
        #for i in range(len(self.idxs)):
            idx  = self.idxs[i]
            geo  = self.geos[i]
            prop = geo.props
            print("%d: "%i,idx.name," | ",geo.name)
            print(idx.numTri,idx.numIdx,geo.numVert)
            if not i in n:

                #material = self.matList[MaterialLink[idx.name]]
                rapi.rpgSetMaterial(MaterialLink[idx.name])
                rapi.rpgBindPositionBufferOfs   (geo.vertBuffer,   noesis.RPGEODATA_FLOAT,  geo.vertLength, prop['position'])
                rapi.rpgBindUV1BufferOfs        (geo.uvBuffer,     noesis.RPGEODATA_FLOAT,  geo.uvLength,   prop['tex0'])
                rapi.rpgBindNormalBufferOfs     (geo.vertBuffer,   noesis.RPGEODATA_FLOAT,  geo.vertLength, prop['normal'])
                rapi.rpgBindTangentBufferOfs    (geo.vertBuffer,   noesis.RPGEODATA_FLOAT,  geo.vertLength, prop['tangent'])
                rapi.rpgCommitTriangles         (idx.idxBuffer,    noesis.RPGEODATA_USHORT, idx.numIdx,     noesis.RPGEO_TRIANGLE, 1)
                #rapi.rpgCommitTriangles         (idx.idxBuffer,    noesis.RPGEODATA_USHORT, idx.numTri,     noesis.RPGEO_TRIANGLE, 1)
            if GEO_C == 1:
                bs = NoeBitStream()
                fileG = open("geo-%d.p3ddump"%i,'wb')
                bs.writeUInt(geo.numVert)
                bs.writeBytes(geo.vertBuffer)
                bs.writeUInt(idx.numTri)
                bs.writeBytes(idx.idxBuffer)
                fileG.write(bs.getBuffer())
                fileG.close()
示例#35
0
def noepyLoadRGBA(data,texList):
    noesis.logPopup()
    file = TEX(data)
    if file.header['version'] == Reversed:
        q=file.WriteFixedDDS()
        q=q.getBuffer()
    else:
        Data = NoeBitStream(data)
        Data.readBytes(12)
        q=Data.getBuffer()
        q=q[12:]
    tex = rapi.loadTexByHandler(q, '.dds')
    if tex: texList.append(tex)
    return 1
示例#36
0
    def load_texture(self, matName):

        #texPath, ext = os.path.splitext(self.abspath.replace("mesh", "mtrl"))
        #f = open(texPath + ".ddj")
        try:
            f = open(self.basename + ".ddj", 'rb')
            f.seek(20)
            tex = rapi.loadTexByHandler(f.read(), ".dds")
            if tex is not None:
                tex.name = matName
                self.texList.append(tex)

            material = NoeMaterial(matName, matName)
            self.matList.append(material)
        except:
            pass
    def parse_file(self):

        idstring = self.inFile.readBytes(4)
        filesize = self.inFile.readUInt()
        numTex, null = self.inFile.read('2L')
        for i in range(numTex):
            texSize = self.inFile.readUInt()
            texFmt = self.read_name(4)
            self.inFile.read('2L')
            texName = self.read_name(32)
            texData = self.inFile.readBytes(texSize)

            tex = rapi.loadTexByHandler(texData, "." + texFmt)
            if tex is not None:
                tex.name = texName
                self.texList.append(tex)
 def loadTexture(path, name):
     if path in loadedTextures:
         return loadedTextures[path]
     log("---> load texture: " + texFinalPath)
     try:
         tex = open(path, 'rb').read()
     except IOError:
         log("failed")
         return None
     texture = rapi.loadTexByHandler(tex, impl.getTexHandlerName())
     if texture is None:
         return None
     texture.name = name
     loadedTextures[path] = texture
     self.textures.append(texture)
     return texture
 def load_texture(self, matName):
     
     #texPath, ext = os.path.splitext(self.abspath.replace("mesh", "mtrl"))
     #f = open(texPath + ".ddj")
     try:
         f = open(self.basename + ".ddj", 'rb')
         f.seek(20)
         tex = rapi.loadTexByHandler(f.read(), ".dds")
         if tex is not None:
             tex.name = matName
             self.texList.append(tex)           
             
         material = NoeMaterial(matName, matName)
         self.matList.append(material)             
     except:
         pass        
 def parse_file(self):
     
     idstring = self.inFile.readBytes(4)
     filesize = self.inFile.readUInt()
     numTex, null = self.inFile.read('2L')
     for i in range(numTex):
         texSize = self.inFile.readUInt()
         texFmt = self.read_name(4)
         self.inFile.read('2L')
         texName = self.read_name(32)
         texData = self.inFile.readBytes(texSize)
         
         tex = rapi.loadTexByHandler(texData, "." + texFmt)
         if tex is not None:
             tex.name = texName
             self.texList.append(tex)            
 def parse_texture(self, template):
     
     token = template.get_token()
     if token:
         texName = os.path.basename(token.get_value())
         ext = os.path.splitext(texName)[1]
         texPath = self.dirpath + texName
         if rapi.checkFileExists(texPath):
             f = open(texPath, 'rb')
             tex = rapi.loadTexByHandler(f.read(), ext)
             print(texName, ext)
             if tex is not None:
                 tex.name = texName
                 
                 self.texList.append(tex)
                 self.matList[-1].setTexture(texName)
             f.close()
 def parseMaterials(self):
     dirPath = rapi.getDirForFilePath(rapi.getInputName())
     self.data.seek(28)
     self.numMat = self.data.readUInt()
     matOffset =self.data.readUInt()
     self.data.seek(matOffset-4,1)
     materialArray = ANetModelMaterialArray(self.data)
     self.data.seek(materialArray.materialOffset-4,1)
     current = self.data.tell()
     offsetTable = self.data.read("%di"%materialArray.materialCount)
     diffuse  = [0x67531924]
     normal   = [2332802439,2774157488]
     lightmap = [1745599879,]
     for i in range(materialArray.materialCount):
         self.data.seek(current + offsetTable[i] + i*4)
         matInfo = ANetModelMaterialInfo(self.data)
         self.data.seek(matInfo.texturepos + matInfo.textureOffset)
         material = NoeMaterial(str(i),'')
         #material.setBlendMode("GL_SRC_COLOR","GL_ONE")
         
         texInfos = []
         for t in range(matInfo.textureCount):texInfos.append(ANetModelTextureReference(self.data))
         
         for texInfo in texInfos:
             self.data.seek(texInfo.referencepos + texInfo.offsetToFileReference)
             texInDAT = self.data.read('3H')
             if texInfo.hash in diffuse or texInfo.hash in normal or texInfo.hash in lightmap:
                 texture = 0xFF00 * (texInDAT[1] - 0x100) + (texInDAT[0] - 0x100) + 1
                 if texInfo.hash in diffuse:  material.setTexture(str(texture))
                 elif texInfo.hash in normal: material.setNormalTexture(str(texture))
                 elif texInfo.hash in lightmap:
                     self.lightMapList[i]=NoeMaterial(str(i),"")
                     self.lightMapList[i].setTexture(str(texture))
                     self.lightMapList[i].setBlendMode("GL_ONE","GL_ONE")
                 try:
                     path = glob.glob(dirPath+str(texture)+'*.atex')[0]
                     tex=open(path,'rb').read()
                     tex=rapi.loadTexByHandler(tex,'.atex')
                     tex.name=str(texture)+'.atex'
                     self.texList.append(tex)
                 except:print("Can't load", texture)
             else:
                 texture = 0xFF00 * (texInDAT[1] - 0x100) + (texInDAT[0] - 0x100) + 1
                 #print(texture, texInfo.hash)
         self.matList.append(material)
    def parse_textures(self, numTex):

        for i in range(numTex):
            texName = self.read_name()
            ext = texName[-4:]
            f = self.open_file(texName)
            if f:
                try:
                    tex = rapi.loadTexByHandler(f.read(), ext)
                    if tex is not None:
                        tex.name = texName
                        self.texList.append(tex)
                except:
                    tex = NoeTexture("dummy", 0, 0, 0, 0)
                    self.texList.append(tex)
            else:
                tex = NoeTexture("dummy", 0, 0, 0, 0)
                self.texList.append(tex)
 def parse_textures(self, numTex):
     
     for i in range(numTex):
         texName = self.read_name()
         ext = texName[-4:]
         f = self.open_file(texName)
         if f:
             try:
                 tex = rapi.loadTexByHandler(f.read(), ext)
                 if tex is not None:
                     tex.name = texName
                     self.texList.append(tex)
             except:
                 tex = NoeTexture("dummy", 0, 0, 0, 0)
                 self.texList.append(tex)
         else:
             tex = NoeTexture("dummy", 0, 0, 0, 0)
             self.texList.append(tex)                
    def parse_textures(self, numTex, texInfo):

        for i in range(numTex):
            texOfs = texInfo[i]
            texSize = texInfo[i + 1] - texOfs
            self.inFile.seek(texOfs)

            self.read_name(12)
            texName = self.read_name(32)
            width, height = self.inFile.read('2L')
            self.inFile.readUInt()
            self.inFile.read('2H')
            datSize = self.inFile.readUInt()
            data = self.inFile.readBytes(datSize)

            tex = rapi.loadTexByHandler(data, ".dds")
            if tex:
                tex.name = texName
                self.texList.append(tex)
 def parse_textures(self, numTex, texInfo):
     
     for i in range(numTex):
         texOfs = texInfo[i]
         texSize = texInfo[i+1] - texOfs
         self.inFile.seek(texOfs)
         
         self.read_name(12)
         texName = self.read_name(32)
         width, height = self.inFile.read('2L')
         self.inFile.readUInt()
         self.inFile.read('2H')
         datSize = self.inFile.readUInt()
         data = self.inFile.readBytes(datSize)
         
         tex = rapi.loadTexByHandler(data, ".dds")
         if tex:
             tex.name = texName
             self.texList.append(tex)            
示例#47
0
def bhLoadRGBA(data, texList):
    texCount = 0
    bs = NoeBitStream(data)
    fileSize = bs.getSize()
    fileSizeDiv4 = fileSize // 4
    for i in range(0, fileSizeDiv4 - 1):
        temp = bs.readUInt()

        if (temp == 0x20534444):
            texCount += 1
            print(texCount)
            offset = bs.tell()
            print("Found texture header at: " + hex(offset - 0x04))
            bs.seek(0x08, NOESEEK_REL)
            height = bs.readUInt()
            width = bs.readUInt()
            print("Height: " + str(height))
            print("Width: " + str(width))
            bs.seek(0x08, NOESEEK_REL)
            mipCount = bs.readUInt()
            print("Mips: " + str(mipCount))
            bs.seek(0x34, NOESEEK_REL)
            type = bs.readBytes(0x04).decode()
            print("Type: " + str(type))
            bs.seek(-0x58, NOESEEK_REL)

            if mipCount == 0x00:
                textureSize = (height * width * 0x06) + 0x80
            else:
                textureSize = (height * width) + 0x80

                for i in range(1, mipCount):
                    height //= 0x02
                    width //= 0x02
                    textureSize += max(0x01, ((width + 0x03) // 0x04)) * max(
                        0x01, ((height + 0x03) // 0x04)) * 0x10

            img = rapi.loadTexByHandler(bs.readBytes(textureSize), ".dds")
            img.name = str(texCount)
            texList.append(img)
    return 1
示例#48
0
 def ReadMaterials(self):
     self.SearchChunk("353010")
     self.data.seek(7, 1)
     self.matEmis = {}
     self.matID_F = {}
     for i in range(self.data.readUInt()):
         self.data.seek(17, 1)
         size = self.data.readUInt()
         self.data.seek(2, 1)
         length = self.data.readUByte()
         nameMat = noeStrFromBytes(self.data.readBytes(length))
         nameMat = nameMat.split('\\')[-1]
         self.data.seek(-length - 2, 1)
         matbuffer = self.data.readBytes(size)
         matbuffer = matbuffer.split(b"\x31\x03")
         buffer = matbuffer[1:]
         material = NoeMaterial(nameMat, "")
         for t in range(0, len(buffer), 2):
             length = int(buffer[t][6])
             name = buffer[t][7:6 + length]
             name = name.split(b'/')[-1]
             name = name[:-3] + b'dds'
             name = name.decode("utf-8")
             if "_diff.dds" in name:
                 material.setTexture(name)
             elif "_norm.dds" in name:
                 material.setNormalTexture(name)
             elif "_spec.dds" in name:
                 material.setSpecularTexture(name)
             elif "_emis.dds" in name:
                 self.matEmis[i] = NoeMaterial(nameMat + "_Emiss", name)
                 self.matEmis[i].setBlendMode("GL_ONE", "GL_ONE")
                 self.matEmis[i].setAlphaTest(0.5)
         self.matList.append(material)
     for t in self.matEmis.keys():
         self.matList.append(self.matEmis[t])
     texList = []
     for t in self.matList:
         try:
             name = rapi.getDirForFilePath(rapi.getInputName()) + t.texName
             if not t.texName in texList:
                 tex = open(name, 'rb').read()
                 tex = rapi.loadTexByHandler(tex, '.dds')
                 tex.name = t.texName
                 if "_diff.dds" in tex.name:
                     try:
                         norm = rapi.getDirForFilePath(
                             rapi.getInputName()) + t.nrmTexName
                         spec = rapi.getDirForFilePath(
                             rapi.getInputName()) + t.specTexName
                         norm = open(norm, 'rb').read()
                         spec = open(spec, 'rb').read()
                         norm = rapi.loadTexByHandler(norm, '.dds')
                         spec = rapi.loadTexByHandler(spec, '.dds')
                         norm.name = t.nrmTexName
                         spec.name = t.specTexName
                         decodeHOMM6NormalMap(norm)
                         self.texList.append(norm)
                         self.texList.append(spec)
                     except:
                         pass
                 self.texList.append(tex)
         except:
             print("Couldn't find", t.texName)
     #MrAdults - make a list of emissive textures, find the corresponding diffuse texture, and copy its alpha over
     emissiveTexs = [t for t in self.texList if "_emis.dds" in t.name]
     for t in emissiveTexs:
         diffName = t.name.replace("_emis.dds", "_diff.dds")
         for d in self.texList:
             if d.name == diffName:
                 copyTextureAlpha(d, t)
                 break
示例#49
0
 def load_texture(self):
     size, zsize = self.inFile.read('2L')
     compData = self.inFile.readBytes(zsize)
     decompData = rapi.decompInflate(compData, size)
     tex = rapi.loadTexByHandler(decompData, ".dds")
     return tex
 def load_texture(self):
     size, zsize = self.inFile.read('2L')
     compData = self.inFile.readBytes(zsize)
     decompData = rapi.decompInflate(compData, size)
     tex = rapi.loadTexByHandler(decompData, ".dds")
     return tex
 def ReadMaterials(self):
     self.SearchChunk("353010")
     self.data.seek(7,1)
     self.matEmis={}
     self.matID_F={}
     for i in range(self.data.readUInt()):
         self.data.seek(17,1)
         size        = self.data.readUInt()
         self.data.seek(2,1)
         length      = self.data.readUByte()
         nameMat     = noeStrFromBytes(self.data.readBytes(length))
         nameMat     = nameMat.split('\\')[-1]
         self.data.seek(-length-2,1)
         matbuffer   = self.data.readBytes(size)
         matbuffer   = matbuffer.split(b"\x31\x03")
         buffer      =   matbuffer[1:]
         material    = NoeMaterial(nameMat,"")
         for t in range (0,len(buffer),2):
             length  = int(buffer[t][6])
             name    = buffer[t][7:6+length]
             name    = name.split(b'/')[-1]
             name    = name[:-3]+b'dds'
             name    = name.decode("utf-8")
             if "_diff.dds" in name:
                 material.setTexture(name)
             elif "_norm.dds" in name:
                 material.setNormalTexture(name)
             elif "_spec.dds" in name:
                 material.setSpecularTexture(name)
             elif "_emis.dds" in name:
                 self.matEmis[i] = NoeMaterial(nameMat+"_Emiss", name)
                 self.matEmis[i].setBlendMode("GL_ONE","GL_ONE")
                 self.matEmis[i].setAlphaTest(0.5)
         self.matList.append(material)
     for t in self.matEmis.keys():
         self.matList.append(self.matEmis[t])
     texList = []
     for t in self.matList:
         try:
             name=rapi.getDirForFilePath(rapi.getInputName())+t.texName
             if not t.texName in texList:
                 tex = open(name,'rb').read()
                 tex = rapi.loadTexByHandler(tex,'.dds')
                 tex.name = t.texName
                 if "_diff.dds" in tex.name:
                     try:
                         norm = rapi.getDirForFilePath(rapi.getInputName())+t.nrmTexName
                         spec = rapi.getDirForFilePath(rapi.getInputName())+t.specTexName
                         norm = open(norm,'rb').read()
                         spec = open(spec,'rb').read()
                         norm = rapi.loadTexByHandler(norm,'.dds')
                         spec = rapi.loadTexByHandler(spec,'.dds')
                         norm.name = t.nrmTexName
                         spec.name = t.specTexName
                         decodeHOMM6NormalMap(norm)
                         self.texList.append(norm)
                         self.texList.append(spec)
                     except:pass
                 self.texList.append(tex)
         except:
             print("Couldn't find",t.texName)
     #MrAdults - make a list of emissive textures, find the corresponding diffuse texture, and copy its alpha over
     emissiveTexs = [t for t in self.texList if "_emis.dds" in t.name]
     for t in emissiveTexs:
         diffName = t.name.replace("_emis.dds", "_diff.dds")
         for d in self.texList:
             if d.name == diffName:
                 copyTextureAlpha(d, t)
                 break