2023-09-21 13:47:30 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <VTUserAll.hpp>
|
|
|
|
#include <vector>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cinttypes>
|
|
|
|
|
|
|
|
namespace BMap {
|
|
|
|
|
|
|
|
class BMMeshTransition {
|
|
|
|
private:
|
|
|
|
struct TransitionVertex {
|
|
|
|
TransitionVertex(
|
|
|
|
const LibCmo::VxMath::VxVector3& vec,
|
|
|
|
const LibCmo::VxMath::VxVector3& norm,
|
|
|
|
const LibCmo::VxMath::VxVector2& uv);
|
|
|
|
LibCmo::VxMath::VxVector3 m_Vertex;
|
|
|
|
LibCmo::VxMath::VxVector3 m_Norm;
|
|
|
|
LibCmo::VxMath::VxVector2 m_UV;
|
|
|
|
};
|
|
|
|
struct TransitionFace {
|
2023-09-23 15:55:57 +08:00
|
|
|
TransitionFace(LibCmo::CKDWORD _i1, LibCmo::CKDWORD _i2, LibCmo::CKDWORD _i3, LibCmo::CKDWORD mtl_id);
|
|
|
|
LibCmo::CKDWORD m_Idx1, m_Idx2, m_Idx3;
|
|
|
|
LibCmo::CKDWORD m_MtlSlotIdx;
|
2023-09-21 13:47:30 +08:00
|
|
|
};
|
|
|
|
struct TransitionVertexCompare {
|
|
|
|
bool operator()(const TransitionVertex& lhs, const TransitionVertex& rhs) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
BMMeshTransition();
|
|
|
|
~BMMeshTransition();
|
2023-09-23 16:25:26 +08:00
|
|
|
LIBCMO_DISABLE_COPY_MOVE(BMMeshTransition);
|
2023-09-21 13:47:30 +08:00
|
|
|
|
2023-09-23 15:55:57 +08:00
|
|
|
void PrepareVertexCount(LibCmo::CKDWORD count);
|
|
|
|
LibCmo::VxMath::VxVector3* PrepareVertex();
|
|
|
|
void PrepareNormalCount(LibCmo::CKDWORD count);
|
|
|
|
LibCmo::VxMath::VxVector3* PrepareNormal();
|
|
|
|
void PrepareUVCount(LibCmo::CKDWORD count);
|
|
|
|
LibCmo::VxMath::VxVector2* PrepareUV();
|
|
|
|
void PrepareMtlSlotCount(LibCmo::CKDWORD count);
|
|
|
|
LibCmo::CK2::ObjImpls::CKMaterial** PrepareMtlSlot();
|
|
|
|
void PrepareFaceCount(LibCmo::CKDWORD count);
|
|
|
|
LibCmo::CKDWORD* PrepareFaceVertexIndices();
|
|
|
|
LibCmo::CKDWORD* PrepareFaceNormalIndices();
|
|
|
|
LibCmo::CKDWORD* PrepareFaceUVIndices();
|
|
|
|
LibCmo::CKDWORD* PrepareFaceMtlSlot();
|
|
|
|
|
|
|
|
bool Parse(LibCmo::CK2::ObjImpls::CKMesh* write_into_mesh);
|
2023-09-21 13:47:30 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void DoRealParse();
|
2023-09-23 15:55:57 +08:00
|
|
|
void ApplyToMesh(LibCmo::CK2::ObjImpls::CKMesh* write_into_mesh);
|
2023-09-21 13:47:30 +08:00
|
|
|
|
|
|
|
bool m_IsVertexOK, m_IsNormalOK, m_IsUVOK, m_IsFaceOK, m_IsMtlSlotOK;
|
|
|
|
bool m_IsParsed;
|
|
|
|
|
|
|
|
std::vector<LibCmo::VxMath::VxVector3> m_Vertexs, m_Normals;
|
|
|
|
std::vector<LibCmo::VxMath::VxVector2> m_UVs;
|
2023-09-23 15:55:57 +08:00
|
|
|
std::vector<LibCmo::CKDWORD> m_FaceVertexs, m_FaceNormals, m_FaceUVs;
|
|
|
|
std::vector<LibCmo::CKDWORD> m_FaceMtlSlotIdxs;
|
|
|
|
std::vector<LibCmo::CK2::ObjImpls::CKMaterial*> m_MtlSlots;
|
2023-09-21 13:47:30 +08:00
|
|
|
|
|
|
|
std::vector<TransitionVertex> m_ProcVertexs;
|
|
|
|
std::vector<TransitionFace> m_ProcFaces;
|
2023-09-23 15:55:57 +08:00
|
|
|
/**
|
|
|
|
@brief The core duplication vertex remover.
|
|
|
|
@remark
|
|
|
|
unordered_map have performance problem when dealing with massive data (in this case, big mesh).
|
|
|
|
so we use map to get stable time cost.
|
|
|
|
*/
|
|
|
|
std::map<TransitionVertex, LibCmo::CKDWORD, TransitionVertexCompare> m_ProcDupRemover;
|
2023-09-21 13:47:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class BMFile {
|
|
|
|
public:
|
2023-09-23 15:55:57 +08:00
|
|
|
BMFile(LibCmo::CKSTRING temp_folder, LibCmo::CKSTRING texture_folder, LibCmo::CKDWORD encoding_count, LibCmo::CKSTRING encodings[], bool is_reader);
|
2023-09-21 13:47:30 +08:00
|
|
|
~BMFile();
|
2023-09-23 16:25:26 +08:00
|
|
|
LIBCMO_DISABLE_COPY_MOVE(BMFile);
|
2023-09-21 13:47:30 +08:00
|
|
|
|
2023-09-23 16:25:26 +08:00
|
|
|
bool IsFailed();
|
2023-09-23 15:55:57 +08:00
|
|
|
bool Load(LibCmo::CKSTRING filename);
|
|
|
|
bool Save(LibCmo::CKSTRING filename, LibCmo::CKINT compress_level);
|
|
|
|
|
|
|
|
#define VISITOR_DECL(namepart) \
|
|
|
|
LibCmo::CKDWORD Get ## namepart ## Count(); \
|
|
|
|
LibCmo::CK2::ObjImpls::CK ## namepart * Get ## namepart (LibCmo::CKDWORD idx); \
|
|
|
|
LibCmo::CK2::ObjImpls::CK ## namepart * Create ## namepart (LibCmo::CKSTRING name);
|
|
|
|
|
|
|
|
VISITOR_DECL(Group)
|
|
|
|
VISITOR_DECL(3dObject)
|
|
|
|
VISITOR_DECL(Mesh)
|
|
|
|
VISITOR_DECL(Material)
|
|
|
|
VISITOR_DECL(Texture)
|
|
|
|
|
|
|
|
#undef VISITOR_DECL
|
|
|
|
|
2023-09-21 13:47:30 +08:00
|
|
|
private:
|
2023-09-23 16:25:26 +08:00
|
|
|
bool m_IsFailed;
|
2023-09-23 15:55:57 +08:00
|
|
|
bool m_IsReader;
|
2023-09-21 13:47:30 +08:00
|
|
|
LibCmo::CK2::CKContext* m_Context;
|
2023-09-23 15:55:57 +08:00
|
|
|
|
|
|
|
#define VISITOR_SELF(namepart) \
|
|
|
|
std::vector<LibCmo::CK2::ObjImpls::CK ## namepart *> m_Obj ## namepart ## s;
|
|
|
|
|
|
|
|
VISITOR_SELF(Group)
|
|
|
|
VISITOR_SELF(3dObject)
|
|
|
|
VISITOR_SELF(Mesh)
|
|
|
|
VISITOR_SELF(Material)
|
|
|
|
VISITOR_SELF(Texture)
|
|
|
|
|
|
|
|
#undef VISITOR_SELF
|
2023-09-21 13:47:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|