diff --git a/Tools/MeshConv.py b/Tools/MeshConv.py index cced666..f1485c1 100644 --- a/Tools/MeshConv.py +++ b/Tools/MeshConv.py @@ -19,18 +19,10 @@ def GetFileLength(fs: io.BufferedReader) -> int: fs.seek(pos, io.SEEK_SET) return fsize -def EvaluateVertexCount(filename: str) -> int: +def EvaluateCount(filename: str, unit_size: int) -> int: with open(filename, 'rb') as fs: filesize = GetFileLength(fs) - count, modrem = divmod(filesize, 3 * 4) # 3 float(4 byte) - if modrem != 0: - raise Exception("invalid file length") - return count - -def EvaluateFaceCount(filename: str) -> int: - with open(filename, 'rb') as fs: - filesize = GetFileLength(fs) - count, modrem = divmod(filesize, 3 * 2) # 3 WORD(2 byte) + count, modrem = divmod(filesize, unit_size) if modrem != 0: raise Exception("invalid file length") return count @@ -80,19 +72,21 @@ if __name__ == '__main__': # parse arg args = parser.parse_args() - input("Prepare VertexPositions please.") - vertexcount = EvaluateVertexCount(args.in_bin) + #input("Prepare VertexPositions please.") + vertexcount = EvaluateCount(args.in_vpos, 3 * 4) # 3 float(4 bytes) print(f'Vertex Count Evaluated: {vertexcount}') - vpos = RecoupleTuple(ReadFloats(args.in_bin, 3 * vertexcount), 3) + vpos = RecoupleTuple(ReadFloats(args.in_vpos, 3 * vertexcount), 3) - input("Prepare VertexNormals please.") - vnml = RecoupleTuple(ReadFloats(args.in_bin, 3 * vertexcount), 3) + #input("Prepare VertexNormals please.") + vnml = RecoupleTuple(ReadFloats(args.in_vnml, 3 * vertexcount), 3) - input("Prepare VertexUVs please.") - vuv = RecoupleTuple(ReadFloats(args.in_bin, 2 * vertexcount), 2) + #input("Prepare VertexUVs please.") + vuv = RecoupleTuple(ReadFloats(args.in_vuv, 2 * vertexcount), 2) - input("Prepare FaceIndices please.") - findices = RecoupleTuple(ReadShorts(args.in_bin, 3 * vertexcount), 3) + #input("Prepare FaceIndices please.") + facecount = EvaluateCount(args.in_findices, 3 * 2) # 3 WORD(2 bytes) + print(f'Face Count Evaluated: {facecount}') + findices = RecoupleTuple(ReadShorts(args.in_findices, 3 * facecount), 3) GenerateObj(args.out_obj, vpos, vnml, vuv, findices) print('Done') diff --git a/Unvirt/StructFormatter.cpp b/Unvirt/StructFormatter.cpp index 91a4636..212e44b 100644 --- a/Unvirt/StructFormatter.cpp +++ b/Unvirt/StructFormatter.cpp @@ -78,6 +78,42 @@ namespace Unvirt::StructFormatter { fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); } + static void PrintCKGroupDetail(LibCmo::CK2::ObjImpls::CKGroup* obj) { + PrintCKBeObjectDetail(obj); + fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKGroup\n")), stdout); + fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); + } + + static void PrintCKRenderObjectDetail(LibCmo::CK2::ObjImpls::CKRenderObject* obj) { + PrintCKBeObjectDetail(obj); + fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKRenderObject\n")), stdout); + fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); + } + + static void PrintCK3dEntityDetail(LibCmo::CK2::ObjImpls::CK3dEntity* obj) { + PrintCKRenderObjectDetail(obj); + fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CK3dEntity\n")), stdout); + fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); + } + + static void PrintCK3dObjectDetail(LibCmo::CK2::ObjImpls::CK3dObject* obj) { + PrintCK3dEntityDetail(obj); + fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CK3dObject\n")), stdout); + fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); + } + + static void PrintCKTextureDetail(LibCmo::CK2::ObjImpls::CKTexture* obj) { + PrintCKBeObjectDetail(obj); + fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKTexture\n")), stdout); + fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); + } + + static void PrintCKMaterialDetail(LibCmo::CK2::ObjImpls::CKMaterial* obj) { + PrintCKBeObjectDetail(obj); + fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKMaterial\n")), stdout); + fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); + } + static void PrintCKMeshDetail(LibCmo::CK2::ObjImpls::CKMesh* obj) { PrintCKBeObjectDetail(obj); fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKMesh\n")), stdout); @@ -232,6 +268,33 @@ namespace Unvirt::StructFormatter { LibCmo::CK2::ObjImpls::CKObject* mobj = const_cast(obj); switch (mobj->GetClassID()) { + case LibCmo::CK2::CK_CLASSID::CKCID_OBJECT: + PrintCKObjectDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_SCENEOBJECT: + PrintCKSceneObjectDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_BEOBJECT: + PrintCKBeObjectDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_GROUP: + PrintCKGroupDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_RENDEROBJECT: + PrintCKRenderObjectDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_3DENTITY: + PrintCK3dEntityDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_3DOBJECT: + PrintCK3dObjectDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_TEXTURE: + PrintCKTextureDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_MATERIAL: + PrintCKMaterialDetail(static_cast(mobj)); + break; case LibCmo::CK2::CK_CLASSID::CKCID_MESH: PrintCKMeshDetail(static_cast(mobj)); break; @@ -244,7 +307,7 @@ namespace Unvirt::StructFormatter { void PrintCKBaseManager(const LibCmo::CK2::MgrImpls::CKBaseManager* mgr) { fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKBaseManager\n")), stdout); if (mgr == nullptr) { - fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); + fputs(UNVIRT_TERMCOL_LIGHT_RED(("Null Manager\n")), stdout); return; } @@ -253,7 +316,7 @@ namespace Unvirt::StructFormatter { void PrintCKStateChunk(const LibCmo::CK2::CKStateChunk* chunk) { fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKStateChunk\n")), stdout); if (chunk == nullptr) { - fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); + fputs(UNVIRT_TERMCOL_LIGHT_RED(("Null Chunk\n")), stdout); return; }