Moved mesh flags to the mesh class.

This commit is contained in:
Leonardo Zide 2019-07-21 08:56:37 -07:00
parent 6c7291b919
commit e68ce05b57
8 changed files with 43 additions and 36 deletions

View file

@ -1671,26 +1671,23 @@ lcMesh* lcPiecesLibrary::CreateMesh(PieceInfo* Info, lcLibraryMeshData& MeshData
} }
} }
if (Info)
{
if (DstSection.PrimitiveType == LC_MESH_TRIANGLES || DstSection.PrimitiveType == LC_MESH_TEXTURED_TRIANGLES) if (DstSection.PrimitiveType == LC_MESH_TRIANGLES || DstSection.PrimitiveType == LC_MESH_TEXTURED_TRIANGLES)
{ {
if (DstSection.ColorIndex == gDefaultColor) if (DstSection.ColorIndex == gDefaultColor)
Info->mFlags |= LC_PIECE_HAS_DEFAULT; Mesh->mFlags |= lcMeshFlag::HasDefault;
else else
{ {
if (lcIsColorTranslucent(DstSection.ColorIndex)) if (lcIsColorTranslucent(DstSection.ColorIndex))
Info->mFlags |= LC_PIECE_HAS_TRANSLUCENT; Mesh->mFlags |= lcMeshFlag::HasTranslucent;
else else
Info->mFlags |= LC_PIECE_HAS_SOLID; Mesh->mFlags |= lcMeshFlag::HasSolid;
} }
} }
else else
Info->mFlags |= LC_PIECE_HAS_LINES; Mesh->mFlags |= lcMeshFlag::HasLines;
if (DstSection.PrimitiveType == LC_MESH_TEXTURED_TRIANGLES || DstSection.PrimitiveType == LC_MESH_TEXTURED_LINES) if (DstSection.PrimitiveType == LC_MESH_TEXTURED_TRIANGLES || DstSection.PrimitiveType == LC_MESH_TEXTURED_LINES)
Info->mFlags |= LC_PIECE_HAS_TEXTURE; Mesh->mFlags |= lcMeshFlag::HasTexture;
}
NumIndices += DstSection.NumIndices; NumIndices += DstSection.NumIndices;
} }

View file

@ -26,6 +26,7 @@ lcMesh::lcMesh()
mIndexDataSize = 0; mIndexDataSize = 0;
mVertexCacheOffset = -1; mVertexCacheOffset = -1;
mIndexCacheOffset = -1; mIndexCacheOffset = -1;
mFlags = 0;
} }
lcMesh::~lcMesh() lcMesh::~lcMesh()
@ -77,6 +78,7 @@ void lcMesh::CreateBox()
mRadius = lcLength(Max - Min) / 2.0f; mRadius = lcLength(Max - Min) / 2.0f;
mBoundingBox.Min = Min; mBoundingBox.Min = Min;
mBoundingBox.Max = Max; mBoundingBox.Max = Max;
mFlags |= lcMeshFlag::HasDefault | lcMeshFlag::HasLines;
lcVertex* Verts = (lcVertex*)mVertexData; lcVertex* Verts = (lcVertex*)mVertexData;
quint16* Indices = (quint16*)mIndexData; quint16* Indices = (quint16*)mIndexData;
@ -365,6 +367,7 @@ bool lcMesh::FileLoad(lcMemFile& File)
if (File.ReadU32() != LC_MESH_FILE_ID || File.ReadU32() != LC_MESH_FILE_VERSION) if (File.ReadU32() != LC_MESH_FILE_ID || File.ReadU32() != LC_MESH_FILE_VERSION)
return false; return false;
mFlags = static_cast<lcMeshFlags>(File.ReadU32());
mBoundingBox.Min = File.ReadVector3(); mBoundingBox.Min = File.ReadVector3();
mBoundingBox.Max = File.ReadVector3(); mBoundingBox.Max = File.ReadVector3();
mRadius = File.ReadFloat(); mRadius = File.ReadFloat();
@ -431,6 +434,7 @@ bool lcMesh::FileSave(lcMemFile& File)
File.WriteU32(LC_MESH_FILE_ID); File.WriteU32(LC_MESH_FILE_ID);
File.WriteU32(LC_MESH_FILE_VERSION); File.WriteU32(LC_MESH_FILE_VERSION);
File.WriteU32(mFlags);
File.WriteVector3(mBoundingBox.Min); File.WriteVector3(mBoundingBox.Min);
File.WriteVector3(mBoundingBox.Max); File.WriteVector3(mBoundingBox.Max);
File.WriteFloat(mRadius); File.WriteFloat(mRadius);

View file

@ -3,7 +3,7 @@
#include "lc_math.h" #include "lc_math.h"
#define LC_MESH_FILE_ID LC_FOURCC('M', 'E', 'S', 'H') #define LC_MESH_FILE_ID LC_FOURCC('M', 'E', 'S', 'H')
#define LC_MESH_FILE_VERSION 0x0114 #define LC_MESH_FILE_VERSION 0x0115
enum lcMeshPrimitiveType enum lcMeshPrimitiveType
{ {
@ -50,6 +50,18 @@ enum
LC_NUM_MESH_LODS LC_NUM_MESH_LODS
}; };
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
};
Q_DECLARE_FLAGS(lcMeshFlags, lcMeshFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(lcMeshFlags)
class lcMesh class lcMesh
{ {
public: public:
@ -83,6 +95,7 @@ public:
lcMeshLod mLods[LC_NUM_MESH_LODS]; lcMeshLod mLods[LC_NUM_MESH_LODS];
lcBoundingBox mBoundingBox; lcBoundingBox mBoundingBox;
float mRadius; float mRadius;
lcMeshFlags mFlags;
void* mVertexData; void* mVertexData;
int mVertexDataSize; int mVertexDataSize;

View file

@ -43,7 +43,7 @@ void lcScene::End()
std::sort(mTranslucentMeshes.begin(), mTranslucentMeshes.end(), TranslucentMeshCompare); std::sort(mTranslucentMeshes.begin(), mTranslucentMeshes.end(), TranslucentMeshCompare);
} }
void lcScene::AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State, int Flags) void lcScene::AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State)
{ {
lcRenderMesh& RenderMesh = mRenderMeshes.Add(); lcRenderMesh& RenderMesh = mRenderMeshes.Add();
@ -55,14 +55,15 @@ void lcScene::AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorInde
RenderMesh.LodIndex = RenderMesh.Mesh->GetLodIndex(RenderMesh.Distance); RenderMesh.LodIndex = RenderMesh.Mesh->GetLodIndex(RenderMesh.Distance);
bool Translucent = lcIsColorTranslucent(ColorIndex); bool Translucent = lcIsColorTranslucent(ColorIndex);
lcMeshFlags Flags = Mesh->mFlags;
if ((Flags & (LC_PIECE_HAS_SOLID | LC_PIECE_HAS_LINES)) || ((Flags & LC_PIECE_HAS_DEFAULT) && !Translucent)) if ((Flags & (lcMeshFlag::HasSolid | lcMeshFlag::HasLines)) || ((Flags & lcMeshFlag::HasDefault) && !Translucent))
mOpaqueMeshes.Add(mRenderMeshes.GetSize() - 1); mOpaqueMeshes.Add(mRenderMeshes.GetSize() - 1);
if ((Flags & LC_PIECE_HAS_TRANSLUCENT) || ((Flags & LC_PIECE_HAS_DEFAULT) && Translucent)) if ((Flags & lcMeshFlag::HasTranslucent) || ((Flags & lcMeshFlag::HasDefault) && Translucent))
mTranslucentMeshes.Add(mRenderMeshes.GetSize() - 1); mTranslucentMeshes.Add(mRenderMeshes.GetSize() - 1);
if (Flags & LC_PIECE_HAS_TEXTURE) if (Flags & lcMeshFlag::HasTexture)
mHasTexture = true; mHasTexture = true;
} }

View file

@ -41,7 +41,7 @@ public:
void Begin(const lcMatrix44& ViewMatrix); void Begin(const lcMatrix44& ViewMatrix);
void End(); void End();
void AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State, int Flags); void AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State);
void AddInterfaceObject(const lcObject* Object) void AddInterfaceObject(const lcObject* Object)
{ {

View file

@ -669,7 +669,7 @@ void lcPiece::AddMainModelRenderMeshes(lcScene& Scene, bool Highlight) const
if (!mMesh) if (!mMesh)
mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, RenderMeshState, ParentActive); mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, RenderMeshState, ParentActive);
else else
Scene.AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState, mPieceInfo->mFlags); Scene.AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState);
if (RenderMeshState == lcRenderMeshState::FOCUSED || RenderMeshState == lcRenderMeshState::SELECTED) if (RenderMeshState == lcRenderMeshState::FOCUSED || RenderMeshState == lcRenderMeshState::SELECTED)
Scene.AddInterfaceObject(this); Scene.AddInterfaceObject(this);
@ -692,7 +692,7 @@ void lcPiece::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMat
if (!mMesh) if (!mMesh)
mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, ActiveSubmodelInstance == this); mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, ActiveSubmodelInstance == this);
else else
Scene.AddMesh(mMesh, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, mPieceInfo->mFlags); Scene.AddMesh(mMesh, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState);
if (ParentActive && (RenderMeshState == lcRenderMeshState::FOCUSED || RenderMeshState == lcRenderMeshState::SELECTED)) if (ParentActive && (RenderMeshState == lcRenderMeshState::FOCUSED || RenderMeshState == lcRenderMeshState::SELECTED))
Scene.AddInterfaceObject(this); Scene.AddInterfaceObject(this);

View file

@ -47,7 +47,7 @@ void PieceInfo::SetPlaceholder()
mBoundingBox.Max = lcVector3(10.0f, 10.0f, 4.0f); mBoundingBox.Max = lcVector3(10.0f, 10.0f, 4.0f);
ReleaseMesh(); ReleaseMesh();
mFlags = LC_PIECE_PLACEHOLDER | LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES; mFlags = LC_PIECE_PLACEHOLDER;
mModel = nullptr; mModel = nullptr;
mProject = nullptr; mProject = nullptr;
} }
@ -146,11 +146,8 @@ void PieceInfo::Load()
if (lcGetPiecesLibrary()->LoadPieceData(this)) if (lcGetPiecesLibrary()->LoadPieceData(this))
mFlags &= ~LC_PIECE_PLACEHOLDER; mFlags &= ~LC_PIECE_PLACEHOLDER;
else else
{
mFlags |= LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES;
mBoundingBox = gPlaceholderMesh->mBoundingBox; mBoundingBox = gPlaceholderMesh->mBoundingBox;
} }
}
else else
lcGetPiecesLibrary()->LoadPieceData(this); lcGetPiecesLibrary()->LoadPieceData(this);
} }
@ -303,13 +300,13 @@ void PieceInfo::ZoomExtents(float FoV, float AspectRatio, lcMatrix44& Projection
void PieceInfo::AddRenderMesh(lcScene& Scene) void PieceInfo::AddRenderMesh(lcScene& Scene)
{ {
if (mMesh) if (mMesh)
Scene.AddMesh(mMesh, lcMatrix44Identity(), gDefaultColor, lcRenderMeshState::NORMAL, mFlags); Scene.AddMesh(mMesh, lcMatrix44Identity(), gDefaultColor, lcRenderMeshState::NORMAL);
} }
void PieceInfo::AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const void PieceInfo::AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const
{ {
if ((mMesh) || (mFlags & LC_PIECE_PLACEHOLDER)) if ((mMesh) || (mFlags & LC_PIECE_PLACEHOLDER))
Scene.AddMesh((mFlags & LC_PIECE_PLACEHOLDER) ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, RenderMeshState, mFlags); Scene.AddMesh((mFlags & LC_PIECE_PLACEHOLDER) ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, RenderMeshState);
if (mFlags & LC_PIECE_MODEL) if (mFlags & LC_PIECE_MODEL)
mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive); mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);

View file

@ -4,14 +4,9 @@
#include "lc_math.h" #include "lc_math.h"
#include "lc_array.h" #include "lc_array.h"
#define LC_PIECE_HAS_DEFAULT 0x01 // Piece has triangles using the default color
#define LC_PIECE_HAS_SOLID 0x02 // Piece has triangles using a solid color
#define LC_PIECE_HAS_TRANSLUCENT 0x04 // Piece has triangles using a translucent color
#define LC_PIECE_HAS_LINES 0x08 // Piece has lines
#define LC_PIECE_PLACEHOLDER 0x10 // Placeholder for a piece not in the library #define LC_PIECE_PLACEHOLDER 0x10 // Placeholder for a piece not in the library
#define LC_PIECE_MODEL 0x20 // Piece is a model #define LC_PIECE_MODEL 0x20 // Piece is a model
#define LC_PIECE_PROJECT 0x40 // Piece is a project #define LC_PIECE_PROJECT 0x40 // Piece is a project
#define LC_PIECE_HAS_TEXTURE 0x80 // Piece has sections using textures
#define LC_PIECE_NAME_LEN 256 #define LC_PIECE_NAME_LEN 256