mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +05:30
Added interface for geometry functions
This commit is contained in:
parent
d71a89b840
commit
c1bb8c457f
@ -89,29 +89,144 @@ class Devil1TEX_FN(ctypes.Structure):
|
|||||||
# Devil 1: GEO
|
# Devil 1: GEO
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
|
|
||||||
|
class Header(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("numMesh", ctypes.c_ubyte),
|
||||||
|
("unknownNumberB", ctypes.c_ubyte),
|
||||||
|
("unknownNumberC", ctypes.c_ubyte),
|
||||||
|
("unknownNumberD", ctypes.c_ubyte),
|
||||||
|
("padding", ctypes.c_int),
|
||||||
|
("unknownOffset", ctypes.c_ulonglong)
|
||||||
|
]
|
||||||
|
|
||||||
|
class MeshHeader(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("numBatch", ctypes.c_short),
|
||||||
|
("numVertex", ctypes.c_short),
|
||||||
|
("u", ctypes.c_uint),
|
||||||
|
("offsetBatches", ctypes.c_ulonglong),
|
||||||
|
("flags", ctypes.c_ulonglong)
|
||||||
|
]
|
||||||
|
|
||||||
|
class Coordinate(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("x", ctypes.c_float),
|
||||||
|
("y", ctypes.c_float),
|
||||||
|
("z", ctypes.c_float)
|
||||||
|
]
|
||||||
|
|
||||||
|
class UVs(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("u", ctypes.c_short),
|
||||||
|
("v", ctypes.c_short)
|
||||||
|
]
|
||||||
|
|
||||||
|
class BoneIndexes(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("indexes", ctypes.c_ubyte * 4),
|
||||||
|
]
|
||||||
|
|
||||||
|
class BoneWeights(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("weights", ctypes.c_short)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class BatchData(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("numVertex", ctypes.c_short),
|
||||||
|
("uB", ctypes.c_short),
|
||||||
|
("padding", ctypes.c_uint),
|
||||||
|
("offsetPositions", ctypes.c_ulonglong),
|
||||||
|
("offsetNormals", ctypes.c_ulonglong),
|
||||||
|
("offsetUVs", ctypes.c_ulonglong),
|
||||||
|
("offsetBoneIndexes", ctypes.c_ulonglong),
|
||||||
|
("offsetBoneWeights", ctypes.c_ulonglong),
|
||||||
|
("offsets", ctypes.c_ulonglong)
|
||||||
|
]
|
||||||
|
|
||||||
|
class VertexData(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("positions", ctypes.POINTER(Coordinate)),
|
||||||
|
("normals", ctypes.POINTER(Coordinate)),
|
||||||
|
("u", ctypes.POINTER(UVs)),
|
||||||
|
("bi", ctypes.POINTER(BoneIndexes)),
|
||||||
|
("bw", ctypes.POINTER(BoneWeights))
|
||||||
|
]
|
||||||
|
|
||||||
|
class Batch(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("bd", ctypes.POINTER(BatchData)),
|
||||||
|
("vd", VertexData)
|
||||||
|
]
|
||||||
|
|
||||||
|
class Mesh(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("b", ctypes.POINTER(Batch))
|
||||||
|
]
|
||||||
|
|
||||||
|
class Devil1GEO_FN(ctypes.Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("printheader", ctypes.CFUNCTYPE(
|
||||||
|
None,
|
||||||
|
ctypes.POINTER(Header))),
|
||||||
|
("printmeshheader", ctypes.CFUNCTYPE(
|
||||||
|
None,
|
||||||
|
ctypes.POINTER(MeshHeader))),
|
||||||
|
("printbatch", ctypes.CFUNCTYPE(
|
||||||
|
None,
|
||||||
|
ctypes.POINTER(Batch))),
|
||||||
|
("printcoordinate", ctypes.CFUNCTYPE(
|
||||||
|
None,
|
||||||
|
ctypes.POINTER(Coordinate))),
|
||||||
|
("getmeshheader", ctypes.CFUNCTYPE(
|
||||||
|
ctypes.c_bool,
|
||||||
|
ctypes.POINTER(MeshHeader),
|
||||||
|
ctypes.c_uint,
|
||||||
|
ctypes.c_char_p)),
|
||||||
|
("getbatch", ctypes.CFUNCTYPE(
|
||||||
|
ctypes.c_bool,
|
||||||
|
ctypes.POINTER(Batch),
|
||||||
|
ctypes.c_uint,
|
||||||
|
ctypes.c_char_p)),
|
||||||
|
("getmesh", ctypes.CFUNCTYPE(
|
||||||
|
ctypes.c_bool,
|
||||||
|
ctypes.POINTER(Mesh),
|
||||||
|
ctypes.c_uint,
|
||||||
|
ctypes.c_char_p,
|
||||||
|
ctypes.c_uint))
|
||||||
|
]
|
||||||
|
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
# Regular Python
|
# Regular Python
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
|
if __name__ == "__main__":
|
||||||
def pldtest(devil1pld, pldheader):
|
def pldtest(devil1pld, pldheader):
|
||||||
with open("pl01.pld", "rb") as f:
|
with open("pl01.pld", "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
devil1pld.getheader(ctypes.byref(pldheader), data)
|
devil1pld.getheader(ctypes.byref(pldheader), data)
|
||||||
devil1pld.printheader(ctypes.byref(pldheader))
|
devil1pld.printheader(ctypes.byref(pldheader))
|
||||||
|
|
||||||
def textest(devil1tex, texheader):
|
def textest(devil1tex, texheader):
|
||||||
with open("pl01.pld_1.txp", "rb") as f:
|
with open("pl01.pld_1.txp", "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
texheader = ctypes.cast(data, ctypes.POINTER(TexturePack))
|
texheader = ctypes.cast(data, ctypes.POINTER(TexturePack))
|
||||||
devil1tex.printheader(texheader)
|
devil1tex.printheader(texheader)
|
||||||
|
|
||||||
def main():
|
def geotest(devil1geo, geoheader):
|
||||||
|
with open("pl00.pld_0", "rb") as f:
|
||||||
|
data = f.read()
|
||||||
|
geoheader = ctypes.cast(data, ctypes.POINTER(Header))
|
||||||
|
devil1geo.printheader(geoheader)
|
||||||
|
|
||||||
|
def main():
|
||||||
sharedlib='./lib3ddevil1.so'
|
sharedlib='./lib3ddevil1.so'
|
||||||
libc = ctypes.cdll.LoadLibrary(sharedlib)
|
libc = ctypes.cdll.LoadLibrary(sharedlib)
|
||||||
if (not libc):
|
if (not libc):
|
||||||
print("Couldn't load %s" % sharedlib)
|
print("Couldn't load %s" % sharedlib)
|
||||||
return 1
|
return 1
|
||||||
print("OK")
|
print("OK")
|
||||||
|
|
||||||
pldfn = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
pldfn = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
||||||
pldh = PldHeader()
|
pldh = PldHeader()
|
||||||
pldtest(pldfn, pldh)
|
pldtest(pldfn, pldh)
|
||||||
@ -120,7 +235,10 @@ def main():
|
|||||||
texh = TexturePack()
|
texh = TexturePack()
|
||||||
textest(texfn, texh)
|
textest(texfn, texh)
|
||||||
|
|
||||||
|
geofn = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO")
|
||||||
|
geoh = Header()
|
||||||
|
geotest(geofn, geoh)
|
||||||
|
|
||||||
#---------------------------------------+
|
#---------------------------------------+
|
||||||
|
main()
|
||||||
main()
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user