2019-07-28 01:31:16 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "lc_array.h"
|
|
|
|
#include "lc_math.h"
|
|
|
|
#include "lc_mesh.h"
|
|
|
|
|
|
|
|
#define LC_LIBRARY_VERTEX_UNTEXTURED 0x1
|
|
|
|
#define LC_LIBRARY_VERTEX_TEXTURED 0x2
|
|
|
|
|
|
|
|
enum lcMeshDataType
|
|
|
|
{
|
|
|
|
LC_MESHDATA_HIGH,
|
|
|
|
LC_MESHDATA_LOW,
|
|
|
|
LC_MESHDATA_SHARED,
|
|
|
|
LC_NUM_MESHDATA_TYPES
|
|
|
|
};
|
|
|
|
|
2021-03-07 03:54:24 +01:00
|
|
|
struct lcMeshLoaderVertex
|
2019-07-28 01:31:16 +02:00
|
|
|
{
|
|
|
|
lcVector3 Position;
|
|
|
|
lcVector3 Normal;
|
|
|
|
float NormalWeight;
|
|
|
|
lcVector2 TexCoord;
|
|
|
|
quint32 Usage;
|
|
|
|
};
|
|
|
|
|
2021-03-07 03:54:24 +01:00
|
|
|
struct lcMeshLoaderConditionalVertex
|
|
|
|
{
|
|
|
|
lcVector3 Position[4];
|
|
|
|
};
|
|
|
|
|
2021-04-11 01:18:15 +02:00
|
|
|
class lcMeshLoaderSection
|
2019-07-28 01:31:16 +02:00
|
|
|
{
|
|
|
|
public:
|
2021-04-11 01:18:15 +02:00
|
|
|
lcMeshLoaderSection(lcMeshPrimitiveType PrimitiveType, quint32 Color, lcTexture* Texture)
|
2019-07-28 01:31:16 +02:00
|
|
|
: mIndices(1024, 1024)
|
|
|
|
{
|
|
|
|
mPrimitiveType = PrimitiveType;
|
|
|
|
mColor = Color;
|
|
|
|
mTexture = Texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcMeshPrimitiveType mPrimitiveType;
|
|
|
|
quint32 mColor;
|
|
|
|
lcTexture* mTexture;
|
|
|
|
lcArray<quint32> mIndices;
|
|
|
|
};
|
|
|
|
|
2021-06-06 19:51:34 +02:00
|
|
|
struct lcMergeSection
|
|
|
|
{
|
|
|
|
lcMeshLoaderSection* Shared;
|
|
|
|
lcMeshLoaderSection* Lod;
|
|
|
|
};
|
|
|
|
|
2021-03-07 03:54:24 +01:00
|
|
|
enum class lcMeshLoaderTextureMapType
|
2019-07-28 01:31:16 +02:00
|
|
|
{
|
2021-03-07 03:54:24 +01:00
|
|
|
Planar,
|
|
|
|
Cylindrical,
|
|
|
|
Spherical
|
2019-07-28 01:31:16 +02:00
|
|
|
};
|
|
|
|
|
2021-03-07 03:54:24 +01:00
|
|
|
struct lcMeshLoaderTextureMap
|
2019-07-28 01:31:16 +02:00
|
|
|
{
|
|
|
|
lcTexture* Texture;
|
|
|
|
|
|
|
|
union lcTextureMapParams
|
|
|
|
{
|
|
|
|
lcTextureMapParams()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
struct lcTextureMapPlanarParams
|
|
|
|
{
|
|
|
|
lcVector4 Planes[2];
|
|
|
|
} Planar;
|
|
|
|
|
|
|
|
struct lcTextureMapCylindricalParams
|
|
|
|
{
|
|
|
|
lcVector4 FrontPlane;
|
|
|
|
float UpLength;
|
|
|
|
lcVector4 Plane1;
|
|
|
|
lcVector4 Plane2;
|
2021-04-11 01:18:15 +02:00
|
|
|
float Angle;
|
2019-07-28 01:31:16 +02:00
|
|
|
} Cylindrical;
|
|
|
|
|
|
|
|
struct lcTextureMapSphericalParams
|
|
|
|
{
|
|
|
|
lcVector4 FrontPlane;
|
|
|
|
lcVector3 Center;
|
|
|
|
lcVector4 Plane1;
|
|
|
|
lcVector4 Plane2;
|
2021-04-11 01:18:15 +02:00
|
|
|
float Angle1;
|
|
|
|
float Angle2;
|
2019-07-28 01:31:16 +02:00
|
|
|
} Spherical;
|
|
|
|
} Params;
|
|
|
|
|
2021-03-07 03:54:24 +01:00
|
|
|
lcMeshLoaderTextureMapType Type;
|
2019-07-28 01:31:16 +02:00
|
|
|
bool Fallback;
|
|
|
|
bool Next;
|
|
|
|
};
|
|
|
|
|
2021-03-07 03:54:24 +01:00
|
|
|
class lcMeshLoaderTypeData
|
2019-07-28 01:31:16 +02:00
|
|
|
{
|
|
|
|
public:
|
2021-03-07 03:54:24 +01:00
|
|
|
lcMeshLoaderTypeData()
|
2019-07-28 01:31:16 +02:00
|
|
|
{
|
2021-03-07 03:54:24 +01:00
|
|
|
mVertices.SetGrow(1024);
|
|
|
|
mConditionalVertices.SetGrow(1024);
|
|
|
|
}
|
2019-07-28 01:31:16 +02:00
|
|
|
|
2021-03-07 03:54:24 +01:00
|
|
|
lcMeshLoaderTypeData(const lcMeshLoaderTypeData&) = delete;
|
|
|
|
lcMeshLoaderTypeData& operator=(const lcMeshLoaderTypeData&) = delete;
|
|
|
|
|
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
|
|
|
return mSections.empty();
|
2019-07-28 01:31:16 +02:00
|
|
|
}
|
|
|
|
|
2021-03-07 03:54:24 +01:00
|
|
|
void Clear()
|
2019-07-28 01:31:16 +02:00
|
|
|
{
|
2021-03-07 03:54:24 +01:00
|
|
|
mSections.clear();
|
|
|
|
mVertices.RemoveAll();
|
|
|
|
mConditionalVertices.RemoveAll();
|
|
|
|
}
|
|
|
|
|
2021-04-11 01:18:15 +02:00
|
|
|
lcMeshLoaderSection* AddSection(lcMeshPrimitiveType PrimitiveType, quint32 ColorCode, lcTexture* Texture);
|
2021-03-07 03:54:24 +01:00
|
|
|
|
|
|
|
quint32 AddVertex(const lcVector3& Position, bool Optimize);
|
|
|
|
quint32 AddVertex(const lcVector3& Position, const lcVector3& Normal, bool Optimize);
|
|
|
|
quint32 AddTexturedVertex(const lcVector3& Position, const lcVector2& TexCoord, bool Optimize);
|
|
|
|
quint32 AddTexturedVertex(const lcVector3& Position, const lcVector3& Normal, const lcVector2& TexCoord, bool Optimize);
|
2021-03-07 18:57:17 +01:00
|
|
|
quint32 AddConditionalVertex(const lcVector3 (&Position)[4]);
|
2021-03-07 03:54:24 +01:00
|
|
|
|
2021-03-07 18:57:17 +01:00
|
|
|
void ProcessLine(int LineType, quint32 ColorCode, bool WindingCCW, lcVector3 (&Vertices)[4], bool Optimize);
|
2021-03-07 03:54:24 +01:00
|
|
|
void ProcessTexturedLine(int LineType, quint32 ColorCode, bool WindingCCW, const lcMeshLoaderTextureMap& Map, const lcVector3* Vertices, bool Optimize);
|
|
|
|
|
|
|
|
void AddMeshData(const lcMeshLoaderTypeData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap);
|
|
|
|
void AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap);
|
|
|
|
|
2021-04-11 01:18:15 +02:00
|
|
|
std::vector<std::unique_ptr<lcMeshLoaderSection>> mSections;
|
2021-03-07 03:54:24 +01:00
|
|
|
lcArray<lcMeshLoaderVertex> mVertices;
|
|
|
|
lcArray<lcMeshLoaderConditionalVertex> mConditionalVertices;
|
|
|
|
};
|
|
|
|
|
|
|
|
class lcLibraryMeshData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcLibraryMeshData()
|
|
|
|
{
|
|
|
|
mHasTextures = false;
|
|
|
|
mHasStyleStud = false;
|
2019-07-28 01:31:16 +02:00
|
|
|
}
|
|
|
|
|
2020-05-04 00:39:39 +02:00
|
|
|
lcLibraryMeshData(const lcLibraryMeshData&) = delete;
|
|
|
|
lcLibraryMeshData& operator=(const lcLibraryMeshData&) = delete;
|
|
|
|
|
2019-07-28 01:31:16 +02:00
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
2021-03-07 03:54:24 +01:00
|
|
|
for (const lcMeshLoaderTypeData& Data : mData)
|
|
|
|
if (!Data.IsEmpty())
|
2019-07-28 01:31:16 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-07 03:54:24 +01:00
|
|
|
void Clear()
|
2019-09-24 01:22:11 +02:00
|
|
|
{
|
2021-03-07 03:54:24 +01:00
|
|
|
for (lcMeshLoaderTypeData& Data : mData)
|
|
|
|
Data.Clear();
|
2019-09-24 01:22:11 +02:00
|
|
|
|
|
|
|
mHasTextures = false;
|
2021-03-07 03:54:24 +01:00
|
|
|
mHasStyleStud = false;
|
2019-09-24 01:22:11 +02:00
|
|
|
}
|
|
|
|
|
2019-07-28 01:31:16 +02:00
|
|
|
lcMesh* CreateMesh();
|
2021-03-07 03:54:24 +01:00
|
|
|
void AddVertices(lcMeshDataType MeshDataType, int VertexCount, int* BaseVertex, lcMeshLoaderVertex** VertexBuffer);
|
2019-07-28 01:31:16 +02:00
|
|
|
void AddIndices(lcMeshDataType MeshDataType, lcMeshPrimitiveType PrimitiveType, quint32 ColorCode, int IndexCount, quint32** IndexBuffer);
|
2021-03-07 03:54:24 +01:00
|
|
|
void AddMeshData(const lcLibraryMeshData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap, lcMeshDataType OverrideDestIndex);
|
|
|
|
void AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap, lcMeshDataType OverrideDestIndex);
|
|
|
|
|
|
|
|
std::array<lcMeshLoaderTypeData, LC_NUM_MESHDATA_TYPES> mData;
|
2019-07-28 01:31:16 +02:00
|
|
|
bool mHasTextures;
|
2021-01-20 13:19:29 +01:00
|
|
|
bool mHasStyleStud;
|
2021-03-07 19:14:48 +01:00
|
|
|
|
|
|
|
protected:
|
2021-06-06 19:51:34 +02:00
|
|
|
template<typename IndexType>
|
|
|
|
void WriteSections(lcMesh* Mesh, const lcArray<lcMergeSection> (&MergeSections)[LC_NUM_MESH_LODS], int (&BaseVertices)[LC_NUM_MESHDATA_TYPES], int (&BaseTexturedVertices)[LC_NUM_MESHDATA_TYPES], int (&BaseConditionalVertices)[LC_NUM_MESHDATA_TYPES]);
|
|
|
|
|
2021-03-07 19:14:48 +01:00
|
|
|
static void UpdateMeshBoundingBox(lcMesh* Mesh);
|
|
|
|
template<typename IndexType>
|
|
|
|
static void UpdateMeshSectionBoundingBox(lcMesh* Mesh, lcMeshSection& Section, lcVector3& SectionMin, lcVector3& SectionMax);
|
2019-07-28 01:31:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class lcMeshLoader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcMeshLoader(lcLibraryMeshData& MeshData, bool Optimize, Project* CurrentProject, bool SearchProjectFolder);
|
|
|
|
|
|
|
|
bool LoadMesh(lcFile& File, lcMeshDataType MeshDataType);
|
|
|
|
|
|
|
|
protected:
|
2021-06-06 02:44:20 +02:00
|
|
|
bool ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform, quint32 CurrentColorCode, bool InvertWinding, lcMeshDataType MeshDataType);
|
2019-07-28 01:31:16 +02:00
|
|
|
|
2021-06-06 02:44:20 +02:00
|
|
|
lcArray<lcMeshLoaderTextureMap> mTextureStack;
|
2019-07-28 01:31:16 +02:00
|
|
|
lcLibraryMeshData& mMeshData;
|
|
|
|
bool mOptimize;
|
|
|
|
Project* mCurrentProject;
|
|
|
|
bool mSearchProjectFolder;
|
|
|
|
};
|