mirror of
https://github.com/leozide/leocad
synced 2025-01-28 19:58:12 +01:00
Moved mesh flags to the mesh class.
This commit is contained in:
parent
6c7291b919
commit
e68ce05b57
8 changed files with 43 additions and 36 deletions
|
@ -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)
|
||||
Info->mFlags |= LC_PIECE_HAS_DEFAULT;
|
||||
else
|
||||
{
|
||||
if (lcIsColorTranslucent(DstSection.ColorIndex))
|
||||
Info->mFlags |= LC_PIECE_HAS_TRANSLUCENT;
|
||||
else
|
||||
Info->mFlags |= LC_PIECE_HAS_SOLID;
|
||||
}
|
||||
}
|
||||
if (DstSection.ColorIndex == gDefaultColor)
|
||||
Mesh->mFlags |= lcMeshFlag::HasDefault;
|
||||
else
|
||||
Info->mFlags |= LC_PIECE_HAS_LINES;
|
||||
|
||||
if (DstSection.PrimitiveType == LC_MESH_TEXTURED_TRIANGLES || DstSection.PrimitiveType == LC_MESH_TEXTURED_LINES)
|
||||
Info->mFlags |= LC_PIECE_HAS_TEXTURE;
|
||||
{
|
||||
if (lcIsColorTranslucent(DstSection.ColorIndex))
|
||||
Mesh->mFlags |= lcMeshFlag::HasTranslucent;
|
||||
else
|
||||
Mesh->mFlags |= lcMeshFlag::HasSolid;
|
||||
}
|
||||
}
|
||||
else
|
||||
Mesh->mFlags |= lcMeshFlag::HasLines;
|
||||
|
||||
if (DstSection.PrimitiveType == LC_MESH_TEXTURED_TRIANGLES || DstSection.PrimitiveType == LC_MESH_TEXTURED_LINES)
|
||||
Mesh->mFlags |= lcMeshFlag::HasTexture;
|
||||
|
||||
NumIndices += DstSection.NumIndices;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ lcMesh::lcMesh()
|
|||
mIndexDataSize = 0;
|
||||
mVertexCacheOffset = -1;
|
||||
mIndexCacheOffset = -1;
|
||||
mFlags = 0;
|
||||
}
|
||||
|
||||
lcMesh::~lcMesh()
|
||||
|
@ -77,6 +78,7 @@ void lcMesh::CreateBox()
|
|||
mRadius = lcLength(Max - Min) / 2.0f;
|
||||
mBoundingBox.Min = Min;
|
||||
mBoundingBox.Max = Max;
|
||||
mFlags |= lcMeshFlag::HasDefault | lcMeshFlag::HasLines;
|
||||
|
||||
lcVertex* Verts = (lcVertex*)mVertexData;
|
||||
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)
|
||||
return false;
|
||||
|
||||
mFlags = static_cast<lcMeshFlags>(File.ReadU32());
|
||||
mBoundingBox.Min = File.ReadVector3();
|
||||
mBoundingBox.Max = File.ReadVector3();
|
||||
mRadius = File.ReadFloat();
|
||||
|
@ -431,6 +434,7 @@ bool lcMesh::FileSave(lcMemFile& File)
|
|||
File.WriteU32(LC_MESH_FILE_ID);
|
||||
File.WriteU32(LC_MESH_FILE_VERSION);
|
||||
|
||||
File.WriteU32(mFlags);
|
||||
File.WriteVector3(mBoundingBox.Min);
|
||||
File.WriteVector3(mBoundingBox.Max);
|
||||
File.WriteFloat(mRadius);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "lc_math.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
|
||||
{
|
||||
|
@ -50,6 +50,18 @@ enum
|
|||
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
|
||||
{
|
||||
public:
|
||||
|
@ -83,6 +95,7 @@ public:
|
|||
lcMeshLod mLods[LC_NUM_MESH_LODS];
|
||||
lcBoundingBox mBoundingBox;
|
||||
float mRadius;
|
||||
lcMeshFlags mFlags;
|
||||
|
||||
void* mVertexData;
|
||||
int mVertexDataSize;
|
||||
|
|
|
@ -43,7 +43,7 @@ void lcScene::End()
|
|||
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();
|
||||
|
||||
|
@ -55,14 +55,15 @@ void lcScene::AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorInde
|
|||
RenderMesh.LodIndex = RenderMesh.Mesh->GetLodIndex(RenderMesh.Distance);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
if (Flags & LC_PIECE_HAS_TEXTURE)
|
||||
if (Flags & lcMeshFlag::HasTexture)
|
||||
mHasTexture = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
void Begin(const lcMatrix44& ViewMatrix);
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -669,7 +669,7 @@ void lcPiece::AddMainModelRenderMeshes(lcScene& Scene, bool Highlight) const
|
|||
if (!mMesh)
|
||||
mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, RenderMeshState, ParentActive);
|
||||
else
|
||||
Scene.AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState, mPieceInfo->mFlags);
|
||||
Scene.AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState);
|
||||
|
||||
if (RenderMeshState == lcRenderMeshState::FOCUSED || RenderMeshState == lcRenderMeshState::SELECTED)
|
||||
Scene.AddInterfaceObject(this);
|
||||
|
@ -692,7 +692,7 @@ void lcPiece::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMat
|
|||
if (!mMesh)
|
||||
mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, ActiveSubmodelInstance == this);
|
||||
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))
|
||||
Scene.AddInterfaceObject(this);
|
||||
|
|
|
@ -47,7 +47,7 @@ void PieceInfo::SetPlaceholder()
|
|||
mBoundingBox.Max = lcVector3(10.0f, 10.0f, 4.0f);
|
||||
ReleaseMesh();
|
||||
|
||||
mFlags = LC_PIECE_PLACEHOLDER | LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES;
|
||||
mFlags = LC_PIECE_PLACEHOLDER;
|
||||
mModel = nullptr;
|
||||
mProject = nullptr;
|
||||
}
|
||||
|
@ -146,10 +146,7 @@ void PieceInfo::Load()
|
|||
if (lcGetPiecesLibrary()->LoadPieceData(this))
|
||||
mFlags &= ~LC_PIECE_PLACEHOLDER;
|
||||
else
|
||||
{
|
||||
mFlags |= LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES;
|
||||
mBoundingBox = gPlaceholderMesh->mBoundingBox;
|
||||
}
|
||||
}
|
||||
else
|
||||
lcGetPiecesLibrary()->LoadPieceData(this);
|
||||
|
@ -303,13 +300,13 @@ void PieceInfo::ZoomExtents(float FoV, float AspectRatio, lcMatrix44& Projection
|
|||
void PieceInfo::AddRenderMesh(lcScene& Scene)
|
||||
{
|
||||
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
|
||||
{
|
||||
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)
|
||||
mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);
|
||||
|
|
|
@ -4,14 +4,9 @@
|
|||
#include "lc_math.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_MODEL 0x20 // Piece is a model
|
||||
#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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue