bugfix: geo.py would crash when writing models with no triangles.

bugfix: geo.py would erase the input file if the output file was the same.
Made geo.py print usage if too many command line arguments were given.
master
TigerKat 5 years ago
parent f59690ea32
commit aae2cbc339

@ -743,11 +743,11 @@ class Model:
#Encode data into the main block.
#note: PackData should go first, otherwise other ptr types might point to the start of the data block, which would result in a 0 point, which is treated as not present.
self.pack_tris = self.geo.encodeMainDataPackedDeltas(self.tris, 3, len(self.tris), "I", 1)
self.pack_verts = self.geo.encodeMainDataPackedDeltas(self.verts, 3, len(self.verts), "f", 0x8000)
self.pack_norms = self.geo.encodeMainDataPackedDeltas(self.norms, 3, len(self.norms), "f", 0x100)
self.pack_sts = self.geo.encodeMainDataPackedDeltas(self.sts, 2, len(self.verts), "f", 0x1000)
self.pack_sts3 = self.geo.encodeMainDataPackedDeltas(self.sts3, 2, len(self.verts), "f", 0x8000)
self.pack_tris = self.geo.encodeMainDataPackedDeltas(self.tris, 3, self.tris and len(self.tris), "I", 1)
self.pack_verts = self.geo.encodeMainDataPackedDeltas(self.verts, 3, self.verts and len(self.verts), "f", 0x8000)
self.pack_norms = self.geo.encodeMainDataPackedDeltas(self.norms, 3, self.norms and len(self.norms), "f", 0x100)
self.pack_sts = self.geo.encodeMainDataPackedDeltas(self.sts, 2, self.sts and len(self.sts), "f", 0x1000)
self.pack_sts3 = self.geo.encodeMainDataPackedDeltas(self.sts3, 2, self.sts3 and len(self.sts3), "f", 0x8000)
self.pack_weights = self.geo.encodeMainDataPacked(self.weights_data)
self.pack_matidxs = self.geo.encodeMainDataPacked(self.matidxs_data)
self.pack_grid = self.geo.encodeMainDataPacked(self.grid_data)
@ -780,8 +780,8 @@ class Model:
for t in self.tex_idx:
texidx_data.encode("<HH", *t)
self.tex_count = len(self.tex_idx)
self.vert_count = len(self.verts)
self.tri_count = len(self.tris)
self.vert_count = self.verts and len(self.verts) or 0
self.tri_count = self.tris and len(self.tris) or 0
self.name_ptr = len(self.geo.header_objname_data)
self.geo.header_objname_data += self.name + ZERO_BYTE
self.geo.header_objnames.append(self.name)
@ -1221,22 +1221,24 @@ class Geo:
return self.models[-1]
if __name__ == "__main__":
if len(sys.argv) <= 1:
if len(sys.argv) <= 1 or len(sys.argv) > 3:
print("Usage:")
print(" %s <file_in> [<file_out>]")
print(" %s <file_in> [<file_out>]" % (sys.argv[0], ))
print("Test loads a .geo file, dumps its content, and optionally writes its content out.")
exit(0)
fh = open(sys.argv[1], "rb")
geo = Geo()
geo.loadFromFile(fh)
fh.close()
#print(sys.argv)
if len(sys.argv) <= 2:
fho = None
else:
fho = open(sys.argv[2], "wb")
geo = Geo()
geo.loadFromFile(fh)
if fho is not None:
data = geo.saveToData()
#geo.dump()
geo.saveToFile(fho)
fho.write(data)
else:
geo.dump()
#print("%s" % [geo.header_data])

Loading…
Cancel
Save