leocad/common/lc_mesh.h

137 lines
2.8 KiB
C
Raw Normal View History

#pragma once
2013-08-09 06:57:18 +02:00
#include "lc_math.h"
#define LC_MESH_FILE_ID LC_FOURCC('M', 'E', 'S', 'H')
2019-07-21 17:56:37 +02:00
#define LC_MESH_FILE_VERSION 0x0115
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_LINES = 0x04,
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;
};
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
};
Q_DECLARE_FLAGS(lcMeshFlags, lcMeshFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(lcMeshFlags)
2013-08-09 06:57:18 +02:00
class lcMesh
{
public:
lcMesh();
~lcMesh();
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>
bool IntersectsPlanes(const lcVector4 Planes[6]);
bool IntersectsPlanes(const lcVector4 Planes[6]);
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;
};
enum class lcRenderMeshState : int
2015-05-04 02:51:41 +02:00
{
NORMAL,
SELECTED,
FOCUSED,
DISABLED,
HIGHLIGHT
2015-05-04 02:51:41 +02:00
};
2014-04-20 03:50:41 +02:00
struct lcRenderMesh
{
2014-12-24 16:52:52 +01:00
lcMatrix44 WorldMatrix;
2014-04-20 03:50:41 +02:00
lcMesh* Mesh;
float Distance;
2015-02-08 19:54:51 +01:00
int ColorIndex;
2015-05-24 06:36:25 +02:00
int LodIndex;
2015-05-04 02:51:41 +02:00
lcRenderMeshState State;
2014-04-20 03:50:41 +02:00
};
extern lcMesh* gPlaceholderMesh;