Fixed a bunch of code inconsistencies

This commit is contained in:
2026-08-31 07:02:19 -05:00
parent 320c5e6ce5
commit fcf0de72af
30 changed files with 1033 additions and 619 deletions
+25 -31
View File
@@ -18,8 +18,8 @@ Usage:
Reads raw vertex bytes from vertices.bin and writes a DMF file.
"""
import argparse
import struct
import sys
import os
MAGIC = b'DMF\x00'
@@ -28,42 +28,36 @@ VERTEX_SIZE = 20
def write_dmf(path, vertex_bytes):
if len(vertex_bytes) % VERTEX_SIZE != 0:
raise ValueError(
f"Vertex data size {len(vertex_bytes)} is not a "
f"multiple of {VERTEX_SIZE}"
)
vert_count = len(vertex_bytes) // VERTEX_SIZE
buf = bytearray()
buf += MAGIC
buf += struct.pack('<I', VERSION)
buf += struct.pack('<I', vert_count)
buf += vertex_bytes
with open(path, 'wb') as f:
f.write(buf)
print(
f'Wrote {path}: {vert_count} vertices, {len(buf)} bytes'
if len(vertex_bytes) % VERTEX_SIZE != 0:
raise ValueError(
f"Vertex data size {len(vertex_bytes)} is not a "
f"multiple of {VERTEX_SIZE}"
)
return vert_count
vert_count = len(vertex_bytes) // VERTEX_SIZE
buf = bytearray()
buf += MAGIC
buf += struct.pack('<I', VERSION)
buf += struct.pack('<I', vert_count)
buf += vertex_bytes
with open(path, 'wb') as f:
f.write(buf)
print(
f'Wrote {path}: {vert_count} vertices, {len(buf)} bytes'
)
return vert_count
def main():
args = sys.argv[1:]
if len(args) != 2:
print(
"Usage: python3 -m tools.asset.dmf "
"<output.dmf> <vertices.bin>"
)
sys.exit(1)
parser = argparse.ArgumentParser(description="Write a DMF (Dusk Mesh Format) file")
parser.add_argument('output', help='Path to output .dmf file')
parser.add_argument('vertices', help='Path to raw vertex bytes file')
args = parser.parse_args()
dst = args[0]
src = args[1]
with open(args.vertices, 'rb') as f:
vertex_bytes = f.read()
with open(src, 'rb') as f:
vertex_bytes = f.read()
write_dmf(dst, vertex_bytes)
write_dmf(args.output, vertex_bytes)
if __name__ == '__main__':
main()
main()