improve mesh checking

This commit is contained in:
yyc12345 2023-09-19 10:53:48 +08:00
parent 0faa51694f
commit f60ee5058a
6 changed files with 124 additions and 11 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ CodeGen/*.cpp
CodeGen/EnumsMigration/dest/*.hpp CodeGen/EnumsMigration/dest/*.hpp
CodeGen/EnumsMigration/dest/*.cpp CodeGen/EnumsMigration/dest/*.cpp
Tools/*.bin
Tools/*.obj Tools/*.obj
Tools/*.mtl Tools/*.mtl

View File

@ -231,6 +231,7 @@
<ClInclude Include="VTEncoding.hpp" /> <ClInclude Include="VTEncoding.hpp" />
<ClInclude Include="CK2\ObjImpls\CKObject.hpp" /> <ClInclude Include="CK2\ObjImpls\CKObject.hpp" />
<ClInclude Include="VTImage.hpp" /> <ClInclude Include="VTImage.hpp" />
<ClInclude Include="VTUserAll.hpp" />
<ClInclude Include="VTUtils.hpp" /> <ClInclude Include="VTUtils.hpp" />
<ClInclude Include="VxMath\VxEnums.hpp" /> <ClInclude Include="VxMath\VxEnums.hpp" />
<ClInclude Include="VxMath\VxMath.hpp" /> <ClInclude Include="VxMath\VxMath.hpp" />

View File

@ -233,5 +233,8 @@
<ClInclude Include="VTImage.hpp"> <ClInclude Include="VTImage.hpp">
<Filter>Headers</Filter> <Filter>Headers</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="VTUserAll.hpp">
<Filter>Headers</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

31
LibCmo/VTUserAll.hpp Normal file
View File

@ -0,0 +1,31 @@
#pragma once
/*
This file is provided for user of LibCmo.
This file should not be included in LibCmo project inside.
Use VTAll.hpp for project internal including.
*/
#include "VTAll.hpp"
#include "CK2/CKContext.hpp"
#include "CK2/CKStateChunk.hpp"
// Data handlers
#include "CK2/DataHandlers/CKBitmapHandler.hpp"
// Objects
#include "CK2/ObjImpls/CKObject.hpp"
#include "CK2/ObjImpls/CKSceneObject.hpp"
#include "CK2/ObjImpls/CKBeObject.hpp"
#include "CK2/ObjImpls/CKGroup.hpp"
#include "CK2/ObjImpls/CKRenderObject.hpp"
#include "CK2/ObjImpls/CK3dEntity.hpp"
#include "CK2/ObjImpls/CK3dObject.hpp"
#include "CK2/ObjImpls/CKTexture.hpp"
#include "CK2/ObjImpls/CKMaterial.hpp"
#include "CK2/ObjImpls/CKMesh.hpp"
// Managers
#include "CK2/MgrImpls/CKBaseManager.hpp"
#include "CK2/MgrImpls/CKObjectManager.hpp"
#include "CK2/MgrImpls/CKPathManager.hpp"

View File

@ -2,7 +2,10 @@ import argparse, io, math, struct
# setup parser # setup parser
parser = argparse.ArgumentParser(description='The Mesh Converter.') parser = argparse.ArgumentParser(description='The Mesh Converter.')
parser.add_argument('-b', '--in-bin', required=True, type=str, action='store', dest='in_bin', metavar='mesh.bin') parser.add_argument('-p', '--in-vpos', required=True, type=str, action='store', dest='in_vpos', metavar='vpos.bin')
parser.add_argument('-n', '--in-vbml', required=True, type=str, action='store', dest='in_vnml', metavar='vnml.bin')
parser.add_argument('-u', '--in-vuv', required=True, type=str, action='store', dest='in_vuv', metavar='vuv.bin')
parser.add_argument('-i', '--in-findices', required=True, type=str, action='store', dest='in_findices', metavar='findices.bin')
parser.add_argument('-o', '--out-obj', required=True, type=str, action='store', dest='out_obj', metavar='mesh.obj') parser.add_argument('-o', '--out-obj', required=True, type=str, action='store', dest='out_obj', metavar='mesh.obj')
parser.add_argument('-m', '--out-mtl', required=True, type=str, action='store', dest='out_mtl', metavar='mesh.mtl') parser.add_argument('-m', '--out-mtl', required=True, type=str, action='store', dest='out_mtl', metavar='mesh.mtl')
@ -24,6 +27,14 @@ def EvaluateVertexCount(filename: str) -> int:
raise Exception("invalid file length") raise Exception("invalid file length")
return count 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)
if modrem != 0:
raise Exception("invalid file length")
return count
def AssertFileSize(fs: io.BufferedReader, expected_size: int): def AssertFileSize(fs: io.BufferedReader, expected_size: int):
if expected_size != GetFileLength(fs): if expected_size != GetFileLength(fs):
raise Exception("invalid file length") raise Exception("invalid file length")
@ -72,17 +83,16 @@ if __name__ == '__main__':
input("Prepare VertexPositions please.") input("Prepare VertexPositions please.")
vertexcount = EvaluateVertexCount(args.in_bin) vertexcount = EvaluateVertexCount(args.in_bin)
print(f'Vertex Count Evaluated: {vertexcount}') print(f'Vertex Count Evaluated: {vertexcount}')
vpos = RecoupleTuple(ReadFloats(3 * vertexcount), 3) vpos = RecoupleTuple(ReadFloats(args.in_bin, 3 * vertexcount), 3)
input("Prepare VertexNormals please.") input("Prepare VertexNormals please.")
vnml = RecoupleTuple(ReadFloats(3 * vertexcount), 3) vnml = RecoupleTuple(ReadFloats(args.in_bin, 3 * vertexcount), 3)
input("Prepare VertexUVs please.") input("Prepare VertexUVs please.")
vuv = RecoupleTuple(ReadFloats(2 * vertexcount), 2) vuv = RecoupleTuple(ReadFloats(args.in_bin, 2 * vertexcount), 2)
input("Prepare FaceIndices please.") input("Prepare FaceIndices please.")
findices = RecoupleTuple(ReadShorts(3 * vertexcount), 3) findices = RecoupleTuple(ReadShorts(args.in_bin, 3 * vertexcount), 3)
GenerateObj(args.out_obj, vpos, vnml, vuv, findices) GenerateObj(args.out_obj, vpos, vnml, vuv, findices)
print('Done') print('Done')

View File

@ -1,5 +1,4 @@
#include <VTAll.hpp> #include <VTUserAll.hpp>
#include <CK2/CKStateChunk.hpp>
#include "StructFormatter.hpp" #include "StructFormatter.hpp"
#include "AccessibleValue.hpp" #include "AccessibleValue.hpp"
#include "TerminalHelper.hpp" #include "TerminalHelper.hpp"
@ -60,6 +59,66 @@ namespace Unvirt::StructFormatter {
#pragma endregion #pragma endregion
#pragma region Object Printer
static void PrintCKObjectDetail(LibCmo::CK2::ObjImpls::CKObject* obj) {
fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKObject\n")), stdout);
fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout);
}
static void PrintCKSceneObjectDetail(LibCmo::CK2::ObjImpls::CKSceneObject* obj) {
PrintCKObjectDetail(obj);
fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKSceneObject\n")), stdout);
fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout);
}
static void PrintCKBeObjectDetail(LibCmo::CK2::ObjImpls::CKBeObject* obj) {
PrintCKSceneObjectDetail(obj);
fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKBeObject\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);
fputs("Vertex:\n", stdout);
fprintf(stdout, "Vertex Count: %" PRIuCKDWORD "\n", obj->GetVertexCount());
fputs("VertexPositions: ", stdout);
PrintPointer(obj->GetVertexPositions());
fputc('\n', stdout);
fputs("VertexNormals: ", stdout);
PrintPointer(obj->GetVertexNormals());
fputc('\n', stdout);
fputs("VertexUVs: ", stdout);
PrintPointer(obj->GetVertexUVs());
fputc('\n', stdout);
fputs("VertexColors: ", stdout);
PrintPointer(obj->GetVertexColors());
fputc('\n', stdout);
fputs("VertexSpecularColors: ", stdout);
PrintPointer(obj->GetVertexSpecularColors());
fputc('\n', stdout);
fputs("VertexWeights: ", stdout);
PrintPointer(obj->GetVertexWeights());
fputc('\n', stdout);
fputs("Face:\n", stdout);
fprintf(stdout, "Face Count: %" PRIuCKDWORD "\n", obj->GetFaceCount());
fputs("FaceIndices: ", stdout);
PrintPointer(obj->GetFaceIndices());
fputc('\n', stdout);
fputs("FaceMaterialSlotIndexs: ", stdout);
PrintPointer(obj->GetFaceMaterialSlotIndexs());
fputc('\n', stdout);
}
#pragma endregion
void PrintCKFileInfo(const LibCmo::CK2::CKFileInfo& fileinfo) { void PrintCKFileInfo(const LibCmo::CK2::CKFileInfo& fileinfo) {
fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKFileInfo\n")), stdout); fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKFileInfo\n")), stdout);
@ -166,13 +225,21 @@ namespace Unvirt::StructFormatter {
} }
void PrintCKObject(const LibCmo::CK2::ObjImpls::CKObject* obj) { void PrintCKObject(const LibCmo::CK2::ObjImpls::CKObject* obj) {
fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKObject\n")), stdout);
if (obj == nullptr) { if (obj == nullptr) {
fputs(UNVIRT_TERMCOL_LIGHT_RED(("No Data\n")), stdout); fputs(UNVIRT_TERMCOL_LIGHT_RED(("Null Object\n")), stdout);
return; return;
} }
LibCmo::CK2::ObjImpls::CKObject* mobj = const_cast<LibCmo::CK2::ObjImpls::CKObject*>(obj);
switch (mobj->GetClassID()) {
case LibCmo::CK2::CK_CLASSID::CKCID_MESH:
PrintCKMeshDetail(static_cast<LibCmo::CK2::ObjImpls::CKMesh*>(mobj));
break;
default:
fputs(UNVIRT_TERMCOL_LIGHT_RED(("Not Implemented.\n")), stdout); fputs(UNVIRT_TERMCOL_LIGHT_RED(("Not Implemented.\n")), stdout);
break;
}
} }
void PrintCKBaseManager(const LibCmo::CK2::MgrImpls::CKBaseManager* mgr) { void PrintCKBaseManager(const LibCmo::CK2::MgrImpls::CKBaseManager* mgr) {
fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKBaseManager\n")), stdout); fputs(UNVIRT_TERMCOL_LIGHT_YELLOW(("CKBaseManager\n")), stdout);