home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 6448 / tex_TasogareNoSinsemillaPortableV3_pbn.7z / tex_TasogareNoSinsemillaPortable_pbn.py
Encoding:
Python Source  |  2013-06-02  |  2.6 KB  |  85 lines

  1. from inc_noesis import *
  2. import noesis
  3. import rapi
  4.  
  5.  
  6. def registerNoesisTypes():
  7.     handle = noesis.register("Tasogare no Sinsemilla Portable", ".pbn")
  8.     noesis.setHandlerTypeCheck(handle, TSPCheckType)
  9.     noesis.setHandlerLoadModel(handle, TSPLoadRGBA)
  10.     #noesis.logPopup()
  11.     return 1
  12.  
  13. def TSPCheckType(data):
  14.     bs = NoeBitStream(data)
  15.     magic = bs.readUInt()
  16.     if magic != 0x48584554:
  17.         return 0
  18.     return 1
  19.  
  20. def TSPLoadRGBA(data, mdlList):
  21.     texList = []
  22.     bs = NoeBitStream(data)
  23.     header = bs.read("8I")
  24.  
  25.     texInfo1 = []
  26.     bs.seek(header[3], NOESEEK_ABS)
  27.     for a in range(0, header[2]):
  28.         texInfo1.append(bs.read("2B5H3I"))
  29.     #print(texInfo1)
  30.  
  31.     texInfo2 = []
  32.     bs.seek(header[5], NOESEEK_ABS)
  33.     for a in range(0, header[4]):
  34.         texInfo2.append(bs.read("4I"))
  35.     #print(texInfo2)
  36.  
  37.     texInfo3 = []
  38.     bs.seek(header[7], NOESEEK_ABS)
  39.     for a in range(0, header[6]):
  40.         texInfo3.append(bs.read("4B2I"))
  41.     #print(texInfo3)
  42.  
  43.     texInfo4 = []
  44.     for a in range(0, header[2]):
  45.         bs.seek(texInfo1[a][9], NOESEEK_ABS)
  46.         texInfo4.append(bs.read("4H"))
  47.     #print(texInfo4)
  48.  
  49.     for a in range(0, header[2]):
  50.         if texInfo1[a][6] == 5:
  51.             width, height = texInfo1[a][2], texInfo4[a][3]
  52.             if a != (header[2] - 1):
  53.                 texSize = texInfo1[(a + 1)][8] - texInfo1[a][8]
  54.             else:
  55.                 texSize = len(data) - texInfo1[a][8]
  56.             bs.seek(texInfo1[a][7], NOESEEK_ABS)
  57.             palData = bs.readBytes(0x400)
  58.             bs.seek(texInfo1[a][8], NOESEEK_ABS)
  59.             texData = bs.readBytes(texSize)
  60.             pix = rapi.imageUntwiddlePSP(texData, width, height, 8)
  61.             pix = rapi.imageDecodeRawPal(pix, palData, width, height, 8, "r8g8b8a8p0")
  62.             tex = NoeTexture(str(a), width, height, pix, noesis.NOESISTEX_RGBA32)
  63.             tex.setFlags(noesis.NTEXFLAG_WRAP_CLAMP)
  64.             texList.append(tex)
  65.         elif texInfo1[a][6] == 4:
  66.             pass
  67.         elif texInfo1[a][6] == 3:
  68.             pass
  69.     meshes = []
  70.     matList = []
  71.     for a in range(0, header[2]):
  72.         width, height = texInfo3[a][4], texInfo3[a][5]
  73.         material = NoeMaterial(str(a), "")
  74.         material.setTexture(str(a))
  75.         material.setFlags(0, 1)
  76.         matList.append(material)
  77.         idxList = [1, 0, 2, 1, 2, 3]
  78.         posList = [NoeVec3 ((width, -height, 0.0)), NoeVec3 ((width + texInfo4[a][2], -height, 0.0)), NoeVec3 ((width, -height + -texInfo4[a][3], 0.0)), NoeVec3 ((width + texInfo4[a][2], -height + -texInfo4[a][3], 0.0))]
  79.         mesh = NoeMesh(idxList, posList, str(0), str(a))
  80.         mesh.uvs = [NoeVec3 ((0.0, 0.0, 1.0)), NoeVec3 ((1.0, 0.0, 1.0)), NoeVec3 ((0.0, 1.0, 1.0)), NoeVec3 ((1.0, 1.0, 1.0))]
  81.         meshes.append(mesh)
  82.     mdl = NoeModel(meshes)
  83.     mdl.setModelMaterials(NoeModelMaterials(texList, matList))
  84.     mdlList.append(mdl)
  85.     return 1