From a349c8da52436b4817dafe0a8a4146967faac467 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Tue, 24 Apr 2018 21:19:44 -0700 Subject: [PATCH 01/18] Added pythonic PLDHeader object --- bindings/py3devil1.py | 51 +++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 82bb2a0..a3ed6d2 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 -import ctypes +import ctypes, sys #--------------------------------------+ -# Devil 1: PLD +# Devil 1: PLD Base #--------------------------------------+ class PldHeader(ctypes.Structure): @@ -12,12 +12,6 @@ class PldHeader(ctypes.Structure): ("offsets", ctypes.POINTER(ctypes.c_int)) ] - def getoffsets(self): - pyoffsets = [] - for i in range(0, self.numOffset): - pyoffsets.append(self.offsets[i]) - return pyoffsets - class Devil1PLD_FN(ctypes.Structure): _fields_ = [ ("getheader" , ctypes.CFUNCTYPE( @@ -33,7 +27,7 @@ class Devil1PLD_FN(ctypes.Structure): ] #--------------------------------------+ -# Devil 1: TEX +# Devil 1: TEX Base #--------------------------------------+ class TexturePack(ctypes.Structure): @@ -104,7 +98,7 @@ class Devil1TEX_FN(ctypes.Structure): ] #--------------------------------------+ -# Devil 1: GEO +# Devil 1: GEO Base #--------------------------------------+ class Header(ctypes.Structure): @@ -229,6 +223,35 @@ class Devil1GEO_FN(ctypes.Structure): ctypes.c_uint)) ] +#--------------------------------------+ +# Python Objs +#--------------------------------------+ + +sharedlib = './lib3ddevil1.so' +libc = ctypes.cdll.LoadLibrary(sharedlib) +if not libc: + print("Couldn't load %s" % sharedlib) + sys.exit() + +print("\nlib3ddevil1 loaded.") +devil1pld = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD") +devil1tex = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX") +devil1geo = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO") + +class PLDHeader: + def __init__(self, filedata): + h = PldHeader() + devil1pld.getheader(ctypes.byref(h), filedata) + self.offsets = [] + for i in range(0, h.numOffset): + self.offsets.append(h.offsets[i]) + + def __str__(self): + output = "numOffset: %s" % str(len(self.offsets)) + for offset in self.offsets: + output += "\n\t" + str(hex(offset)) + return output + #--------------------------------------+ # Regular Python #--------------------------------------+ @@ -285,6 +308,12 @@ if __name__ == "__main__": geoh = Header() geotest(geofn, geoh) + def mainx(): + with open("pl01.pld", "rb") as f: + data = f.read() + pld = PLDHeader(data) + print(pld) #---------------------------------------+ - main() + # main() + mainx() From e06d7dcd8fd96fcab97bd9781385e433b3a97221 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Tue, 24 Apr 2018 21:51:11 -0700 Subject: [PATCH 02/18] Adjusted constructor to allow default 'blank' pld's --- bindings/py3devil1.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index a3ed6d2..0e54412 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -239,12 +239,12 @@ devil1tex = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX") devil1geo = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO") class PLDHeader: - def __init__(self, filedata): - h = PldHeader() - devil1pld.getheader(ctypes.byref(h), filedata) + def __init__(self, filedata = None): self.offsets = [] - for i in range(0, h.numOffset): - self.offsets.append(h.offsets[i]) + if filedata: + h = PldHeader() + devil1pld.getheader(ctypes.byref(h), filedata) + self.offsets = h.offsets[:h.numOffset] def __str__(self): output = "numOffset: %s" % str(len(self.offsets)) @@ -313,6 +313,8 @@ if __name__ == "__main__": data = f.read() pld = PLDHeader(data) print(pld) + pld2 = PLDHeader() + print(pld2) #---------------------------------------+ # main() mainx() From be691baffb2b8ed72d208f2d5e6a56d5aaa03b25 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Fri, 27 Apr 2018 04:42:18 -0700 Subject: [PATCH 03/18] Added python interface of texture component --- bindings/py3devil1.py | 97 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 0e54412..24b9ada 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -240,17 +240,87 @@ devil1geo = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO") class PLDHeader: def __init__(self, filedata = None): - self.offsets = [] +# self.offsets = [] +# if filedata: +# h = PldHeader() +# devil1pld.getheader(ctypes.byref(h), filedata) +# self.offsets = h.offsets[:h.numOffset] +# self.offsets.append(len(filedata)) + # Store C Struct in order to call C functions + self.cstruct = PldHeader() if filedata: - h = PldHeader() - devil1pld.getheader(ctypes.byref(h), filedata) - self.offsets = h.offsets[:h.numOffset] + devil1pld.getheader(ctypes.byref(self.cstruct), filedata) + self.eof = len(filedata) - def __str__(self): - output = "numOffset: %s" % str(len(self.offsets)) - for offset in self.offsets: - output += "\n\t" + str(hex(offset)) - return output + # def __str__(self): + # output = "numOffset: %s" % str(len(self.offsets)) + # for offset in self.offsets: + # output += "\n\t" + str(hex(offset)) + # return output + + def show(self): + devil1pld.printheader(ctypes.byref(self.cstruct)) + return + + def getnumoffsets(self): + return self.cstruct.numOffsets + + # return pythonic list of offsets + def getoffsets(self): + return self.cstruct.offsets[:self.cstruct.numOffset] + + def sizeofsector(self, i): + ptr = ctypes.byref(self.cstruct) + return devil1pld.sizeofsector(ptr, i, self.eof) + +class TEXturePack: + def __init__(self, filedata): + self.cstruct = TexturePack() + self.th = ctypes.pointer(self.cstruct) + devil1tex.getheader(ctypes.byref(self.th), filedata) + devil1tex.printheader(self.th) + return + + def show(self): + devil1tex.printheader(ctypes.byref(self.cstruct)) + devil1tex.printheader(self.th) + + def getbatchno(self): + return self.cstruct.batchNumber + + def getfirstbatchoffset(self): + return self.cstruct.firstBatchOffset + +class TEXtureBatchDescriptor: + def __init__(self, i, filedata): + self.cstruct = TextureBatchDescriptor() + ptrofptr = ctypes.byref(ctypes.byref(self.cstruct)) + if filedata(): + devil1tex.getbatchdesc(ptrofptr, i, filedata, len(filedata)) + return + + def show(self): + ptr = ctypes.byref(self.cstruct) + devil1tex.printbatchdesc(ptr) + + def getbatchidx(self): + return self.cstruct.batchIdx + + def gethash(self): + return self.cstruct.hash + + def gettexno(self): + return self.cstruct.texNumber + + def gettexturesize(self): + return self.cstruct.textureSize + +class TEXtures: + def __init__(self, i, batchdescriptor, filedata): + self.cstruct = Texture()[batchdescriptor.gettexno()] + if filedata: + devil1tex.gettextures(self.cstruct, i, filedata, len(filedata)) + return #--------------------------------------+ # Regular Python @@ -312,9 +382,14 @@ if __name__ == "__main__": with open("pl01.pld", "rb") as f: data = f.read() pld = PLDHeader(data) - print(pld) + pld.show() pld2 = PLDHeader() - print(pld2) + pld2.show() + + with open("pl01.pld_1.txp", "rb") as f: + data = f.read() + txp = TEXturePack(data) + txp.show() #---------------------------------------+ # main() mainx() From 62841adcb96f212b1946322f6ea8640f5ef3c7f2 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Fri, 27 Apr 2018 04:44:55 -0700 Subject: [PATCH 04/18] Fixed TEXturePack struct --- bindings/py3devil1.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 24b9ada..20c5b4d 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -275,21 +275,18 @@ class PLDHeader: class TEXturePack: def __init__(self, filedata): - self.cstruct = TexturePack() - self.th = ctypes.pointer(self.cstruct) - devil1tex.getheader(ctypes.byref(self.th), filedata) - devil1tex.printheader(self.th) + self.cstruct = ctypes.pointer(TexturePack()) + devil1tex.getheader(ctypes.byref(self.cstruct), filedata) return def show(self): - devil1tex.printheader(ctypes.byref(self.cstruct)) - devil1tex.printheader(self.th) + devil1tex.printheader(self.cstruct) def getbatchno(self): - return self.cstruct.batchNumber + return self.cstruct.contents.batchNumber def getfirstbatchoffset(self): - return self.cstruct.firstBatchOffset + return self.cstruct.contents.firstBatchOffset class TEXtureBatchDescriptor: def __init__(self, i, filedata): @@ -390,6 +387,8 @@ if __name__ == "__main__": data = f.read() txp = TEXturePack(data) txp.show() + print(txp.getbatchno()) + print(txp.getfirstbatchoffset()) #---------------------------------------+ # main() mainx() From b30359aabc1a25528cf39f10f666343e2dd106fc Mon Sep 17 00:00:00 2001 From: _ <_> Date: Fri, 27 Apr 2018 04:57:35 -0700 Subject: [PATCH 05/18] Fixed TEXtureBatchDescriptor --- bindings/py3devil1.py | 53 ++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 20c5b4d..bf879af 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -240,24 +240,12 @@ devil1geo = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO") class PLDHeader: def __init__(self, filedata = None): -# self.offsets = [] -# if filedata: -# h = PldHeader() -# devil1pld.getheader(ctypes.byref(h), filedata) -# self.offsets = h.offsets[:h.numOffset] -# self.offsets.append(len(filedata)) # Store C Struct in order to call C functions self.cstruct = PldHeader() if filedata: devil1pld.getheader(ctypes.byref(self.cstruct), filedata) self.eof = len(filedata) - # def __str__(self): - # output = "numOffset: %s" % str(len(self.offsets)) - # for offset in self.offsets: - # output += "\n\t" + str(hex(offset)) - # return output - def show(self): devil1pld.printheader(ctypes.byref(self.cstruct)) return @@ -290,27 +278,26 @@ class TEXturePack: class TEXtureBatchDescriptor: def __init__(self, i, filedata): - self.cstruct = TextureBatchDescriptor() - ptrofptr = ctypes.byref(ctypes.byref(self.cstruct)) - if filedata(): + self.cstruct = ctypes.pointer(TextureBatchDescriptor()) + ptrofptr = ctypes.byref(self.cstruct) + if filedata: devil1tex.getbatchdesc(ptrofptr, i, filedata, len(filedata)) return - def show(self): - ptr = ctypes.byref(self.cstruct) - devil1tex.printbatchdesc(ptr) + def show(self): + devil1tex.printbatchdesc(self.cstruct) - def getbatchidx(self): - return self.cstruct.batchIdx + def getbatchidx(self): + return self.cstruct.contents.batchIdx - def gethash(self): - return self.cstruct.hash + def gethash(self): + return self.cstruct.contents.hash - def gettexno(self): - return self.cstruct.texNumber + def gettexno(self): + return self.cstruct.contents.texNumber - def gettexturesize(self): - return self.cstruct.textureSize + def gettexturesize(self): + return self.cstruct.contents.textureSize class TEXtures: def __init__(self, i, batchdescriptor, filedata): @@ -328,10 +315,11 @@ if __name__ == "__main__": data = f.read() devil1pld.getheader(ctypes.byref(pldheader), data) devil1pld.printheader(ctypes.byref(pldheader)) - for offset in pldheader.getoffsets(): - print(hex(offset)) + # for offset in pldheader.getoffsets(): + # print(hex(offset)) def textest(devil1tex, texheader): + print("texture test") with open("pl01.pld_1.txp", "rb") as f: data = f.read() # texheader = ctypes.cast(data, ctypes.POINTER(TexturePack)) @@ -342,8 +330,11 @@ if __name__ == "__main__": bd = ctypes.pointer(batchdesc) print("\nbatch descriptor:") devil1tex.getbatchdesc(ctypes.byref(bd), 1, data, len(data)) + devil1tex.printbatchdesc(bd) + print(bd.contents.textureSize) def geotest(devil1geo, geoheader): + print("geo test") with open("pl00.pld_0", "rb") as f: data = f.read() # geoheader = ctypes.cast(data, ctypes.POINTER(Header)) @@ -389,7 +380,11 @@ if __name__ == "__main__": txp.show() print(txp.getbatchno()) print(txp.getfirstbatchoffset()) + tbd = TEXtureBatchDescriptor(1, data) + tbd.show() + print(tbd.gettexturesize()) + #---------------------------------------+ - # main() + main() mainx() From 626fc66d6462fe856a39fac9ea6ae9a84e78e482 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Fri, 27 Apr 2018 05:25:26 -0700 Subject: [PATCH 06/18] Added notice about questionably working Textures --- bindings/py3devil1.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index bf879af..9b958cf 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -89,7 +89,7 @@ class Devil1TEX_FN(ctypes.Structure): ctypes.c_uint, ctypes.c_char_p, ctypes.c_uint)), - ("gettexture", ctypes.CFUNCTYPE( + ("gettextures", ctypes.CFUNCTYPE( ctypes.c_bool, ctypes.POINTER(Texture), ctypes.c_uint, @@ -299,9 +299,12 @@ class TEXtureBatchDescriptor: def gettexturesize(self): return self.cstruct.contents.textureSize + +# Needs testing / correction - gettextures will 'return by parameter' +# a dynamic array of textures. Need to be able to access multiple Texture() class TEXtures: - def __init__(self, i, batchdescriptor, filedata): - self.cstruct = Texture()[batchdescriptor.gettexno()] + def __init__(self, i, count, filedata): + self.cstruct = ctypes.byref(Texture()) if filedata: devil1tex.gettextures(self.cstruct, i, filedata, len(filedata)) return @@ -383,6 +386,7 @@ if __name__ == "__main__": tbd = TEXtureBatchDescriptor(1, data) tbd.show() print(tbd.gettexturesize()) + tx = TEXtures(0, tbd.gettexno(), data) #---------------------------------------+ main() From accf440047793abd6e44f19071ce3778799c4ad8 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 01:08:56 -0700 Subject: [PATCH 07/18] Added interface for GEOHeader --- bindings/py3devil1.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 9b958cf..18d1e67 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -309,6 +309,18 @@ class TEXtures: devil1tex.gettextures(self.cstruct, i, filedata, len(filedata)) return +class GEOHeader: + def __init__(self, filedata): + self.cstruct = ctypes.pointer(Header()) + ptrofptr = ctypes.byref(self.cstruct) + if filedata: + devil1geo.getheader(ptrofptr, filedata) + return + + def show(self): + devil1geo.printheader(self.cstruct) + pass + #--------------------------------------+ # Regular Python #--------------------------------------+ @@ -388,7 +400,12 @@ if __name__ == "__main__": print(tbd.gettexturesize()) tx = TEXtures(0, tbd.gettexno(), data) + with open("pl00.pld_0", "rb") as f: + data = f.read() + gh = GEOHeader(data) + gh.show() + #---------------------------------------+ - main() + # main() mainx() From 49a3c8f0b7965347f940979c981f6362c4dcd88e Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 01:33:12 -0700 Subject: [PATCH 08/18] Added init and show for mesh headers --- bindings/py3devil1.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 18d1e67..6554ed5 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -321,6 +321,18 @@ class GEOHeader: devil1geo.printheader(self.cstruct) pass +class MEShHeader: + def __init__(self, i, filedata): + self.cstruct = ctypes.pointer(MeshHeader()) + ptrofptr = ctypes.byref(self.cstruct) + if filedata: + devil1geo.getmeshheader(ptrofptr, i, filedata) + return + pass + + def show(self): + devil1geo.printmeshheader(self.cstruct) + #--------------------------------------+ # Regular Python #--------------------------------------+ @@ -404,6 +416,8 @@ if __name__ == "__main__": data = f.read() gh = GEOHeader(data) gh.show() + mh = MEShHeader(3, data) + mh.show() #---------------------------------------+ # main() From e4aeba9421880f6c615662c34a5bdcc375e1b5db Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 02:44:05 -0700 Subject: [PATCH 09/18] Added init and show for Meshes --- bindings/py3devil1.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 6554ed5..4a60930 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -333,6 +333,31 @@ class MEShHeader: def show(self): devil1geo.printmeshheader(self.cstruct) + def getbatchno(self): + return self.cstruct.contents.numBatch + +class MEsh: + def __init__(self, i, filedata): + self.cstruct = Mesh() + if filedata: + mh = MEShHeader(i, filedata) + # allocate memory for the size of batch * number of batches + memsize = ctypes.sizeof(Batch) * mh.getbatchno() + self.cstruct.b = ctypes.cast(ctypes.create_string_buffer(memsize), + ctypes.POINTER(Batch)) + if not devil1geo.getmesh(ctypes.byref(self.cstruct), + i, + filedata, + len(filedata)): + print("failed to get mesh") + return + + def show(self): + if self.cstruct.b: + devil1geo.printbatch(self.cstruct.b) + else: + print("nothing to show") + #--------------------------------------+ # Regular Python #--------------------------------------+ @@ -418,7 +443,8 @@ if __name__ == "__main__": gh.show() mh = MEShHeader(3, data) mh.show() - + m = MEsh(0, data) + m.show() #---------------------------------------+ # main() mainx() From 8fdc05b9c052f9dd51dbe30f9a2b8620e6e1de8c Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 03:38:23 -0700 Subject: [PATCH 10/18] Added getpositions and printable coordinates --- bindings/py3devil1.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 4a60930..48f9f2e 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -130,6 +130,9 @@ class Coordinate(ctypes.Structure): ("z", ctypes.c_float) ] + def __str__(self): + return "(%s, %s, %s)" % (str(self.x), str(self.y), str(self.z)) + class UVs(ctypes.Structure): _pack_ = 1 _fields_ = [ @@ -232,7 +235,7 @@ libc = ctypes.cdll.LoadLibrary(sharedlib) if not libc: print("Couldn't load %s" % sharedlib) sys.exit() - +del sys print("\nlib3ddevil1 loaded.") devil1pld = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD") devil1tex = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX") @@ -343,13 +346,16 @@ class MEsh: mh = MEShHeader(i, filedata) # allocate memory for the size of batch * number of batches memsize = ctypes.sizeof(Batch) * mh.getbatchno() - self.cstruct.b = ctypes.cast(ctypes.create_string_buffer(memsize), - ctypes.POINTER(Batch)) - if not devil1geo.getmesh(ctypes.byref(self.cstruct), + self.cstruct.b = ctypes.cast( + ctypes.create_string_buffer(memsize), + ctypes.POINTER(Batch)) + if not devil1geo.getmesh( + ctypes.byref(self.cstruct), i, filedata, len(filedata)): print("failed to get mesh") + del mh, memsize return def show(self): @@ -358,6 +364,10 @@ class MEsh: else: print("nothing to show") + def getpositions(self): + length = self.cstruct.b.contents.bd.contents.numVertex + return self.cstruct.b.contents.vd.positions[:length] + #--------------------------------------+ # Regular Python #--------------------------------------+ @@ -445,6 +455,9 @@ if __name__ == "__main__": mh.show() m = MEsh(0, data) m.show() + p = m.getpositions() + for point in p: + print(point) #---------------------------------------+ # main() mainx() From 650178f3a4ce2caa625875a5d3da73bcb35dd7d2 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 03:43:50 -0700 Subject: [PATCH 11/18] Added getnormals() --- bindings/py3devil1.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 48f9f2e..127c2bf 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -368,6 +368,10 @@ class MEsh: length = self.cstruct.b.contents.bd.contents.numVertex return self.cstruct.b.contents.vd.positions[:length] + def getnormals(self): + length = self.cstruct.b.contents.bd.contents.numVertex + return self.cstruct.b.contents.vd.normals[:length] + #--------------------------------------+ # Regular Python #--------------------------------------+ @@ -458,6 +462,9 @@ if __name__ == "__main__": p = m.getpositions() for point in p: print(point) + n = m.getnormals() + for point in n: + print(point) #---------------------------------------+ # main() mainx() From c45c8d758a599ba2febde832f88470044d67decb Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 09:54:57 -0700 Subject: [PATCH 12/18] Added getuvs() --- bindings/py3devil1.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 127c2bf..9a14667 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -140,6 +140,9 @@ class UVs(ctypes.Structure): ("v", ctypes.c_short) ] + def __str__(self): + return "(%s, %s)" % (str(self.u), str(self.v)) + class BoneIndexes(ctypes.Structure): _pack_ = 1 _fields_ = [ @@ -372,6 +375,10 @@ class MEsh: length = self.cstruct.b.contents.bd.contents.numVertex return self.cstruct.b.contents.vd.normals[:length] + def getuvs(self): + length = self.cstruct.b.contents.bd.contents.numVertex + return self.cstruct.b.contents.vd.u[:length] + #--------------------------------------+ # Regular Python #--------------------------------------+ @@ -460,11 +467,17 @@ if __name__ == "__main__": m = MEsh(0, data) m.show() p = m.getpositions() + print("positions:") for point in p: print(point) n = m.getnormals() + print("normals:") for point in n: print(point) + u = m.getuvs() + print("uvs:") + for point in u: + print(point) #---------------------------------------+ # main() mainx() From 7835a8d90d6f0188a83030a1210886e03cffcdc2 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 11:28:23 -0700 Subject: [PATCH 13/18] Added get functions for bones --- bindings/py3devil1.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 9a14667..051df07 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -379,6 +379,14 @@ class MEsh: length = self.cstruct.b.contents.bd.contents.numVertex return self.cstruct.b.contents.vd.u[:length] + def getboneindexes(self): + length = self.cstruct.b.contents.bd.contents.numVertex + return self.cstruct.b.contents.vd.bi[:length] + + def getboneweights(self): + length = self.cstruct.b.contents.bd.contents.numVertex + return self.cstruct.b.contents.vd.bw[:length] + #--------------------------------------+ # Regular Python #--------------------------------------+ From a8d2cfeb4a5f76e6986f378eee6c08f0a1cbce64 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 13:47:22 -0700 Subject: [PATCH 14/18] Added getbatchdata function --- bindings/py3devil1.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 051df07..65dfb27 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -367,6 +367,9 @@ class MEsh: else: print("nothing to show") + def getbatchdata(self): + return self.cstruct.b.contents.bd.contents + def getpositions(self): length = self.cstruct.b.contents.bd.contents.numVertex return self.cstruct.b.contents.vd.positions[:length] @@ -474,18 +477,21 @@ if __name__ == "__main__": mh.show() m = MEsh(0, data) m.show() - p = m.getpositions() - print("positions:") - for point in p: - print(point) - n = m.getnormals() - print("normals:") - for point in n: - print(point) - u = m.getuvs() - print("uvs:") - for point in u: - print(point) + # p = m.getpositions() + # print("positions:") + # for point in p: + # print(point) + # n = m.getnormals() + # print("normals:") + # for point in n: + # print(point) + # u = m.getuvs() + # print("uvs:") + # for point in u: + # print(point) + dbatch = m.getbatchdata() + print(hex(dbatch.numVertex)) + print(hex(dbatch.padding)) #---------------------------------------+ # main() mainx() From cb96add3f2a564e0b6d562b49edea77061839af2 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 13:52:09 -0700 Subject: [PATCH 15/18] Added getter functions for mesh header attributes --- bindings/py3devil1.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 65dfb27..47fd0bc 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -342,6 +342,18 @@ class MEShHeader: def getbatchno(self): return self.cstruct.contents.numBatch + def getnumvertex(self): + return self.cstruct.contents.numVertex + + def getunknown(self) + return hex(self.cstruct.contents.u) + + def getoffsetbatches(self): + return self.cstruct.contents.offsetBatches + + def getflags(self): + return self.cstruct.contents.flags + class MEsh: def __init__(self, i, filedata): self.cstruct = Mesh() From a2d4aaae11a0739522b7e6d4f6da791995e49a1d Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 13:53:11 -0700 Subject: [PATCH 16/18] Fixed missing colon at fn define --- bindings/py3devil1.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 47fd0bc..7c0ff40 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -327,6 +327,7 @@ class GEOHeader: devil1geo.printheader(self.cstruct) pass + class MEShHeader: def __init__(self, i, filedata): self.cstruct = ctypes.pointer(MeshHeader()) @@ -345,7 +346,7 @@ class MEShHeader: def getnumvertex(self): return self.cstruct.contents.numVertex - def getunknown(self) + def getunknown(self): return hex(self.cstruct.contents.u) def getoffsetbatches(self): From 2f98c2a1a2140153394bfc9e9be98947fe54a169 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 14:07:21 -0700 Subject: [PATCH 17/18] Added getter attributes for geo header --- bindings/py3devil1.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 7c0ff40..e0de918 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -325,7 +325,24 @@ class GEOHeader: def show(self): devil1geo.printheader(self.cstruct) - pass + + def getmeshno(self): + return self.cstruct.contents.numMesh + + def getunknownb(self): + return self.cstruct.contents.unknownNumberB + + def getunknownc(self): + return self.cstruct.contents.unknownNumberC + + def getunknownd(self): + return self.cstruct.contents.unknownNumberD + + def getpadding(self): + return hex(self.cstruct.contents.padding) + + def getunknownoffset(self): + return hex(self.cstruct.contents.unknownOffset) class MEShHeader: @@ -486,6 +503,13 @@ if __name__ == "__main__": data = f.read() gh = GEOHeader(data) gh.show() + print("-------------") + print(gh.getmeshno()) + print(gh.getunknownb()) + print(gh.getunknownc()) + print(gh.getunknownd()) + print(gh.getpadding()) + print(gh.getunknownoffset()) mh = MEShHeader(3, data) mh.show() m = MEsh(0, data) From b1b281cccdae99f072f76e69b6648c2ee31c07c8 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Sun, 13 May 2018 14:38:53 -0700 Subject: [PATCH 18/18] Resolve issue with getting textures. --- bindings/py3devil1.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index e0de918..d63c10b 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -53,7 +53,7 @@ class TextureBatchDescriptor(ctypes.Structure): class Texture(ctypes.Structure): _pack_ = 1 _fields_ = [ - ("data", ctypes.c_ubyte) + ("data", ctypes.POINTER(ctypes.c_ubyte)) ] class TextureBatch(ctypes.Structure): @@ -305,16 +305,23 @@ class TEXtureBatchDescriptor: def gettexturesize(self): return self.cstruct.contents.textureSize - -# Needs testing / correction - gettextures will 'return by parameter' -# a dynamic array of textures. Need to be able to access multiple Texture() -class TEXtures: - def __init__(self, i, count, filedata): - self.cstruct = ctypes.byref(Texture()) +class TEXtureBatch: + def __init__(self, i, filedata): + self.cstruct = TextureBatch() if filedata: - devil1tex.gettextures(self.cstruct, i, filedata, len(filedata)) + self.cstruct.batch = None + tbd = TEXtureBatchDescriptor(i, filedata) + self.amount = tbd.gettexno() + memsize = self.amount * tbd.gettexturesize() + self.cstruct.batch = ctypes.cast( + ctypes.create_string_buffer(memsize), + ctypes.POINTER(Texture)) + devil1tex.gettextures(self.cstruct.batch, i, filedata, len(filedata)) return + def gettextures(self): + return self.cstruct.batch[:self.amount] + class GEOHeader: def __init__(self, filedata): self.cstruct = ctypes.pointer(Header()) @@ -497,7 +504,11 @@ if __name__ == "__main__": tbd = TEXtureBatchDescriptor(1, data) tbd.show() print(tbd.gettexturesize()) - tx = TEXtures(0, tbd.gettexno(), data) + #tx = TEXtures(0, tbd.gettexno(), data) + tx = TEXtureBatch(0, data) + ts = tx.gettextures() + for i in range(0, 10): + print(ts[0].data[i]) with open("pl00.pld_0", "rb") as f: data = f.read()