leocad/common/lc_mesh.h

122 lines
2.7 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;
};
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 19:30:45 +02:00
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
2019-07-21 17:56:37 +02:00
enum class lcMeshFlag
2019-07-21 19:30:45 +02:00
#else
enum lcMeshFlag
#endif
2019-07-21 17:56:37 +02:00
{
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
HasLogoStud = 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;
lcMesh(lcMesh&&) = delete;
lcMesh& operator=(const lcMesh&) = delete;
lcMesh& operator=(lcMesh&&) = delete;
2017-12-02 21:22:04 +01:00
void Create(quint16 NumSections[LC_NUM_MESH_LODS], int NumVertices, int NumTexturedVertices, int NumIndices);
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);
bool MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDist);
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;
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;
int mIndexType;
};
extern lcMesh* gPlaceholderMesh;