__test__.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/usr/bin/python3
  2. from py3devil1pld import pyPldHeader
  3. from py3devil1tex import pyTexturePack, pyTextureBatchDescriptor, pyTextureBatch
  4. from py3devil1geo import pyGeoHeader, pyMeshHeader, pyMesh
  5. #print(libc)
  6. #--------------------------------------+
  7. # Regular Python
  8. #--------------------------------------+
  9. if __name__ == "__main__":
  10. def pldtest(devil1pld, pldheader):
  11. with open("pl01.pld", "rb") as f:
  12. data = f.read()
  13. devil1pld.getheader(ctypes.byref(pldheader), data)
  14. devil1pld.printheader(ctypes.byref(pldheader))
  15. # for offset in pldheader.getoffsets():
  16. # print(hex(offset))
  17. def textest(devil1tex, texheader):
  18. print("texture test")
  19. with open("pl01.pld_1.txp", "rb") as f:
  20. data = f.read()
  21. # texheader = ctypes.cast(data, ctypes.POINTER(TexturePack))
  22. th = ctypes.pointer(texheader)
  23. devil1tex.getheader(ctypes.byref(th), data)
  24. devil1tex.printheader(th)
  25. batchdesc = TextureBatchDescriptor()
  26. bd = ctypes.pointer(batchdesc)
  27. print("\nbatch descriptor:")
  28. devil1tex.getbatchdesc(ctypes.byref(bd), 1, data, len(data))
  29. devil1tex.printbatchdesc(bd)
  30. print(bd.contents.textureSize)
  31. def geotest(devil1geo, geoheader):
  32. print("geo test")
  33. with open("pl00.pld_0", "rb") as f:
  34. data = f.read()
  35. # geoheader = ctypes.cast(data, ctypes.POINTER(Header))
  36. gh = ctypes.pointer(geoheader)
  37. devil1geo.getheader(ctypes.byref(gh), data)
  38. devil1geo.printheader(gh)
  39. meshheader = MeshHeader()
  40. mh = ctypes.pointer(meshheader)
  41. devil1geo.getmeshheader(ctypes.byref(mh), 1, data)
  42. devil1geo.printmeshheader(mh)
  43. def main():
  44. sharedlib='./lib3ddevil1.so'
  45. libc = ctypes.cdll.LoadLibrary(sharedlib)
  46. if (not libc):
  47. print("Couldn't load %s" % sharedlib)
  48. return 1
  49. print("OK")
  50. pldfn = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
  51. pldh = pyPldHeader()
  52. pldtest(pldfn, pldh)
  53. texfn = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX")
  54. texh = TexturePack()
  55. textest(texfn, texh)
  56. geofn = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO")
  57. geoh = Header()
  58. geotest(geofn, geoh)
  59. def mainx():
  60. with open("pl01.pld", "rb") as f:
  61. data = f.read()
  62. pld = pyPldHeader(data)
  63. pld.show()
  64. pld2 = pyPldHeader()
  65. pld2.show()
  66. with open("pl01.pld_1.txp", "rb") as f:
  67. data = f.read()
  68. txp = pyTexturePack(data)
  69. txp.show()
  70. print(txp.getbatchnumber())
  71. print(txp.getfirstbatchoffset())
  72. tbd = pyTextureBatchDescriptor(1, data)
  73. tbd.show()
  74. print(tbd.gettexturesize())
  75. #tx = pyTextures(0, tbd.gettexno(), data)
  76. tx = pyTextureBatch(0, data)
  77. ts = tx.gettextures()
  78. for i in range(0, 10):
  79. print(ts[0].data[i])
  80. with open("pl00.pld_0", "rb") as f:
  81. data = f.read()
  82. gh = pyGeoHeader(data)
  83. gh.show()
  84. print("-------------")
  85. print(gh.getnummesh())
  86. print(gh.getunknownb())
  87. print(gh.getunknownc())
  88. print(gh.getunknownd())
  89. print(gh.getpadding())
  90. print(gh.getunknownoffset())
  91. mh = pyMeshHeader(3, data)
  92. print("-------------")
  93. try:
  94. mh = pyMeshHeader(87, data)
  95. except RuntimeError as e:
  96. print(str(e))
  97. try:
  98. mh = pyMesh(87, data)
  99. except RuntimeError as e:
  100. print(str(e))
  101. print("-------------")
  102. mh.show()
  103. m = pyMesh(0, data)
  104. m.show()
  105. # p = m.getpositions()
  106. # print("positions:")
  107. # for point in p:
  108. # print(point)
  109. # n = m.getnormals()
  110. # print("normals:")
  111. # for point in n:
  112. # print(point)
  113. # u = m.getuvs()
  114. # print("uvs:")
  115. # for point in u:
  116. # print(point)
  117. dbatch = m.getbatchdata()
  118. print(hex(dbatch.numVertex))
  119. print(hex(dbatch.padding))
  120. #---------------------------------------+
  121. # main()
  122. mainx()