leocad/common/lc_mesh.h
Leonardo Zide 9499dd9daa Fixed stud LOD not working. Fixes #390.
Also fixed cached pieces not updating their logo settings.
2019-09-29 12:58:18 -07:00

134 lines
2.8 KiB
C++

#pragma once
#include "lc_math.h"
enum lcMeshPrimitiveType
{
LC_MESH_LINES = 0x01,
LC_MESH_TRIANGLES = 0x02,
LC_MESH_TEXTURED_LINES = 0x04,
LC_MESH_TEXTURED_TRIANGLES = 0x08,
LC_MESH_CONDITIONAL_LINES = 0x10,
LC_MESH_NUM_PRIMITIVE_TYPES
};
struct lcVertex
{
lcVector3 Position;
quint32 Normal;
};
struct lcVertexTextured
{
lcVector3 Position;
quint32 Normal;
lcVector2 TexCoord;
};
struct lcMeshSection
{
int ColorIndex;
int IndexOffset;
int NumIndices;
lcMeshPrimitiveType PrimitiveType;
lcTexture* Texture;
};
struct lcMeshLod
{
lcMeshSection* Sections;
int NumSections;
};
enum
{
LC_MESH_LOD_HIGH,
LC_MESH_LOD_LOW,
LC_NUM_MESH_LODS
};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
enum class lcMeshFlag
#else
enum lcMeshFlag
#endif
{
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
};
Q_DECLARE_FLAGS(lcMeshFlags, lcMeshFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(lcMeshFlags)
class lcMesh
{
public:
lcMesh();
~lcMesh();
void Create(quint16 NumSections[LC_NUM_MESH_LODS], int NumVertices, int NumTexturedVertices, int NumIndices);
void CreateBox();
bool FileLoad(lcMemFile& File);
bool FileSave(lcMemFile& File);
template<typename IndexType>
void ExportPOVRay(lcFile& File, const char* MeshName, const char** ColorTable);
void ExportPOVRay(lcFile& File, const char* MeshName, const char** ColorTable);
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);
template<typename IndexType>
bool IntersectsPlanes(const lcVector4 Planes[6]);
bool IntersectsPlanes(const lcVector4 Planes[6]);
int GetLodIndex(float Distance) const;
lcMeshLod mLods[LC_NUM_MESH_LODS];
lcBoundingBox mBoundingBox;
float mRadius;
lcMeshFlags mFlags;
void* mVertexData;
int mVertexDataSize;
void* mIndexData;
int mIndexDataSize;
int mVertexCacheOffset;
int mIndexCacheOffset;
int mNumVertices;
int mNumTexturedVertices;
int mIndexType;
};
enum class lcRenderMeshState : int
{
NORMAL,
SELECTED,
FOCUSED,
DISABLED,
HIGHLIGHT
};
struct lcRenderMesh
{
lcMatrix44 WorldMatrix;
lcMesh* Mesh;
float Distance;
int ColorIndex;
int LodIndex;
lcRenderMeshState State;
};
extern lcMesh* gPlaceholderMesh;