From aae2cbc339fff6505f61666e86f71ea16cedd504 Mon Sep 17 00:00:00 2001 From: TigerKat Date: Wed, 24 Jul 2019 10:08:14 +0930 Subject: [PATCH] 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. --- geo.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/geo.py b/geo.py index bfba493..54c35da 100755 --- a/geo.py +++ b/geo.py @@ -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(" 3: print("Usage:") - print(" %s []") + print(" %s []" % (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])