From 7a7dce51ed2ac1cc1affe5a4649319b4bfb92d6d Mon Sep 17 00:00:00 2001 From: TigerKat Date: Thu, 11 Jul 2019 01:09:33 +0930 Subject: [PATCH] Implemented reading and writing of tex_idx and AltPivotInfo. Fixed ModelHeader output to match GetVrml's output. bugfix: Would include BoneInfo even if the model has no bones. --- README.md | 1 - geo.py | 124 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 87 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 1cb7ec7..7ce11a7 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,4 @@ Dumps all the meshes contained in <file.geo> to <geo_name>/<model ##Known issues: - - Not all structures are read from the .geo file. (AltPivotInfo) - Not all structures are regenerated when writing a .geo file. (PolyGrid and Reductions) diff --git a/geo.py b/geo.py index 849552f..3d32319 100755 --- a/geo.py +++ b/geo.py @@ -33,7 +33,7 @@ from bones import * #16 4 i32: lodinfo_blocksize (only present in version 2 to 6) #? texname_blocksize PackNames block of texture names #? objname_blocksize objnames -#? texidx_blocksize texidx +#? texidx_blocksize TexID[]: texidx_block, #? lodinfo_blocksize lodinfo (only present in version 2 to 6) #? ModelHeader ??? @@ -84,12 +84,12 @@ from bones import * # Offset Size Description # 0 4 i32: size # 4 4 f32: radius -# 8 4 i32: tex_count +# 8 4 i32: tex_count, The number of TexID entries in the texidx_block. # 12 4 ptr(BoneInfo): boneinfo ? # 16 4 i32: vert_count # 20 4 i32: tri_count #ver 8+ 24 4 i32: reflection_quad_count -# +4 4 i32: tex_idx +# +4 4 ptr(TexID): tex_idx, Byte offset in the texidx_block to the first TexID for this model. # +4 32 PolyGrid: grid # +32 4 ptr(char): name # +4 4 ptr(AltPivotInfo): @@ -129,6 +129,10 @@ from bones import * #8 4 ptr(u8): data, The offset of this block of data inside the .geo's main data block. #12 +#TexID: +#Offset Size Description +#0 2 u16: id, Index to the texture name in the texture name list. +#2 2 u16: count, Number of tris using this texture. #struct PolyGrid: "libs/UtilitiesLib/components/gridpoly.h" #Offset Size Description @@ -481,8 +485,13 @@ class Data: if offset is None: offset = self.offset self.data[0 : offset] + def __len__(self): + return len(self.data) + def __str__(self): + return str(self.data) + def __repr__(self): + return repr(self.data) - class Reductions: def __init__(self, model): self.model = model @@ -630,25 +639,25 @@ class Model: self.pack_reflection_quads = self.geo.getHeaderElement(" 0: + bone_data = struct.pack("<" + "i" * (1 + 15), self.bone_count, *self.bone_ids) + bone_data += struct.pack(" 0: + api_data = struct.pack(" 0: + self.api_ptr = self.geo.encodeMainData(api_data) + else: + self.api_ptr = 0 #Encode shared header data - print("unhandled: model.texidx_ptr !") - self.texidx_ptr = 0 + self.texidx_ptr = len(self.geo.header_texidx_data) + texidx_data = self.geo.header_texidx_data + texidx_data.seekEnd() + for t in self.tex_idx: + texidx_data.encode("= 2 and self.version <= 6: self.header_data += struct.pack("= 2 and self.version <= 6: self.header_data += self.lodinfo_data #Encode the main model header. self.header_data += storeString(self.header_modelheader_name, 124) - self.header_data += struct.pack("