leocad/common/lc_mesh.h

141 lines
3.3 KiB
C
Raw Normal View History

#pragma once
2013-08-09 06:57:18 +02:00
#include "lc_math.h"
2016-08-22 03:11:32 +02:00
enum lcMeshPrimitiveType
{
2017-04-02 01:53:54 +02:00
LC_MESH_LINES = 0x01,
LC_MESH_TRIANGLES = 0x02,
LC_MESH_TEXTURED_TRIANGLES = 0x08,
LC_MESH_CONDITIONAL_LINES = 0x10,
2016-08-22 03:11:32 +02:00
LC_MESH_NUM_PRIMITIVE_TYPES
};
2013-08-09 06:57:18 +02:00
struct lcVertex
{
lcVector3 Position;
2017-02-18 20:12:35 +01:00
quint32 Normal;
2013-08-09 06:57:18 +02:00
};
struct lcVertexTextured
{
lcVector3 Position;
2017-02-18 20:12:35 +01:00
quint32 Normal;
2013-08-09 06:57:18 +02:00
lcVector2 TexCoord;
};
2021-03-07 03:54:24 +01:00
struct lcVertexConditional
{
lcVector3 Position1;
lcVector3 Position2;
lcVector3 Position3;
lcVector3 Position4;
};
2013-08-09 06:57:18 +02:00
struct lcMeshSection
{
int ColorIndex;
int IndexOffset;
int NumIndices;
2016-08-22 03:11:32 +02:00
lcMeshPrimitiveType PrimitiveType;
2013-08-09 06:57:18 +02:00
lcTexture* Texture;
2019-11-22 21:48:40 +01:00
lcBoundingBox BoundingBox;
float Radius;
2013-08-09 06:57:18 +02:00
};
2015-05-24 06:36:25 +02:00
struct lcMeshLod
{
lcMeshSection* Sections;
int NumSections;
};
enum
{
LC_MESH_LOD_HIGH,
LC_MESH_LOD_LOW,
LC_NUM_MESH_LODS
};
2019-07-21 17:56:37 +02:00
enum class lcMeshFlag
{
HasDefault = 0x01, // Mesh has triangles using the default color
HasSolid = 0x02, // Mesh has triangles using a solid color
HasTranslucent = 0x04, // Mesh has triangles using a translucent color
HasLines = 0x08, // Mesh has lines
HasTexture = 0x10, // Mesh has sections using textures
2021-01-20 13:19:29 +01:00
HasStyleStud = 0x20 // Mesh has a stud that can have a logo applied
2019-07-21 17:56:37 +02:00
};
Q_DECLARE_FLAGS(lcMeshFlags, lcMeshFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(lcMeshFlags)
2013-08-09 06:57:18 +02:00
class lcMesh
{
public:
lcMesh();
~lcMesh();
2020-05-04 00:39:39 +02:00
lcMesh(const lcMesh&) = delete;
2021-11-15 03:34:24 +01:00
lcMesh(lcMesh&&) = delete;
2020-05-04 00:39:39 +02:00
lcMesh& operator=(const lcMesh&) = delete;
2021-11-15 03:34:24 +01:00
lcMesh& operator=(lcMesh&&) = delete;
2020-05-04 00:39:39 +02:00
2021-03-07 03:54:24 +01:00
void Create(quint16 (&NumSections)[LC_NUM_MESH_LODS], int VertexCount, int TexturedVertexCount, int ConditionalVertexCount, int IndexCount);
2013-08-09 06:57:18 +02:00
void CreateBox();
bool FileLoad(lcMemFile& File);
bool FileSave(lcMemFile& File);
2013-08-09 06:57:18 +02:00
template<typename IndexType>
void ExportPOVRay(lcFile& File, const char* MeshName, const char** ColorTable);
void ExportPOVRay(lcFile& File, const char* MeshName, const char** ColorTable);
2013-08-09 06:57:18 +02:00
template<typename IndexType>
void ExportWavefrontIndices(lcFile& File, int DefaultColorIndex, int VertexOffset);
void ExportWavefrontIndices(lcFile& File, int DefaultColorIndex, int VertexOffset);
template<typename IndexType>
bool MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDist, lcVector3& HitPlane);
bool MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDist, lcVector3& HitPlane);
2013-08-09 06:57:18 +02:00
template<typename IndexType>
2020-03-23 04:32:04 +01:00
bool IntersectsPlanes(const lcVector4 (&Planes)[6]);
bool IntersectsPlanes(const lcVector4 (&Planes)[6]);
2013-08-09 06:57:18 +02:00
2015-05-24 06:36:25 +02:00
int GetLodIndex(float Distance) const;
2021-03-07 19:14:48 +01:00
const lcVertex* GetVertexData() const
{
return static_cast<lcVertex*>(mVertexData);
}
const lcVertexTextured* GetTexturedVertexData() const
{
return reinterpret_cast<lcVertexTextured*>(static_cast<char*>(mVertexData) + mNumVertices * sizeof(lcVertex));
}
const lcVertexConditional* GetConditionalVertexData() const
{
return reinterpret_cast<lcVertexConditional*>(static_cast<char*>(mVertexData) + mNumVertices * sizeof(lcVertex) + mNumTexturedVertices * sizeof(lcVertexTextured));
}
2015-05-24 06:36:25 +02:00
lcMeshLod mLods[LC_NUM_MESH_LODS];
2016-02-19 18:53:54 +01:00
lcBoundingBox mBoundingBox;
2015-05-24 06:36:25 +02:00
float mRadius;
2019-07-21 17:56:37 +02:00
lcMeshFlags mFlags;
2013-08-09 06:57:18 +02:00
void* mVertexData;
int mVertexDataSize;
void* mIndexData;
int mIndexDataSize;
int mVertexCacheOffset;
int mIndexCacheOffset;
2013-08-09 06:57:18 +02:00
int mNumVertices;
int mNumTexturedVertices;
2021-03-07 03:54:24 +01:00
int mConditionalVertexCount;
2013-08-09 06:57:18 +02:00
int mIndexType;
};