mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +05:30
Added python interface of texture component
This commit is contained in:
parent
e06d7dcd8f
commit
be691baffb
@ -240,17 +240,87 @@ devil1geo = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO")
|
|||||||
|
|
||||||
class PLDHeader:
|
class PLDHeader:
|
||||||
def __init__(self, filedata = None):
|
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:
|
if filedata:
|
||||||
h = PldHeader()
|
devil1pld.getheader(ctypes.byref(self.cstruct), filedata)
|
||||||
devil1pld.getheader(ctypes.byref(h), filedata)
|
self.eof = len(filedata)
|
||||||
self.offsets = h.offsets[:h.numOffset]
|
|
||||||
|
|
||||||
def __str__(self):
|
# def __str__(self):
|
||||||
output = "numOffset: %s" % str(len(self.offsets))
|
# output = "numOffset: %s" % str(len(self.offsets))
|
||||||
for offset in self.offsets:
|
# for offset in self.offsets:
|
||||||
output += "\n\t" + str(hex(offset))
|
# output += "\n\t" + str(hex(offset))
|
||||||
return output
|
# 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
|
# Regular Python
|
||||||
@ -312,9 +382,14 @@ if __name__ == "__main__":
|
|||||||
with open("pl01.pld", "rb") as f:
|
with open("pl01.pld", "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
pld = PLDHeader(data)
|
pld = PLDHeader(data)
|
||||||
print(pld)
|
pld.show()
|
||||||
pld2 = PLDHeader()
|
pld2 = PLDHeader()
|
||||||
print(pld2)
|
pld2.show()
|
||||||
|
|
||||||
|
with open("pl01.pld_1.txp", "rb") as f:
|
||||||
|
data = f.read()
|
||||||
|
txp = TEXturePack(data)
|
||||||
|
txp.show()
|
||||||
#---------------------------------------+
|
#---------------------------------------+
|
||||||
# main()
|
# main()
|
||||||
mainx()
|
mainx()
|
||||||
|
Loading…
Reference in New Issue
Block a user