mirror of
https://github.com/leozide/leocad
synced 2025-01-29 20:34:50 +01:00
Reuse same mesh for all placeholder pieces.
This commit is contained in:
parent
450063656a
commit
b6f8e8e651
6 changed files with 46 additions and 23 deletions
|
@ -7,6 +7,8 @@
|
|||
#include "lc_application.h"
|
||||
#include "lc_library.h"
|
||||
|
||||
lcMesh* gPlaceholderMesh;
|
||||
|
||||
lcMesh::lcMesh()
|
||||
{
|
||||
mSections = NULL;
|
||||
|
|
|
@ -179,4 +179,6 @@ struct lcRenderMesh
|
|||
int lcTranslucentRenderMeshCompare(const lcRenderMesh& a, const lcRenderMesh& b);
|
||||
int lcOpaqueRenderMeshCompare(const lcRenderMesh& a, const lcRenderMesh& b);
|
||||
|
||||
extern lcMesh* gPlaceholderMesh;
|
||||
|
||||
#endif // _LC_MESH_H_
|
||||
|
|
|
@ -156,10 +156,7 @@ lcModel::~lcModel()
|
|||
{
|
||||
if (mPieceInfo)
|
||||
{
|
||||
if (gMainWindow->mPreviewWidget->GetCurrentPiece() == mPieceInfo)
|
||||
gMainWindow->mPreviewWidget->SetCurrentPiece(NULL);
|
||||
|
||||
mPieceInfo->SetModel(NULL);
|
||||
mPieceInfo->SetPlaceholder();
|
||||
mPieceInfo->Release();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ PieceInfo::PieceInfo()
|
|||
mZipFileType = LC_NUM_ZIPFILES;
|
||||
mZipFileIndex = -1;
|
||||
mFlags = 0;
|
||||
mMesh = NULL;
|
||||
mRefCount = 0;
|
||||
mMesh = NULL;
|
||||
mModel = NULL;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,22 @@ QString PieceInfo::GetSaveID() const
|
|||
return QString::fromLatin1(m_strName) + QLatin1String(".DAT");
|
||||
}
|
||||
|
||||
void PieceInfo::SetPlaceholder()
|
||||
{
|
||||
m_fDimensions[0] = 10.0f;
|
||||
m_fDimensions[1] = 10.0f;
|
||||
m_fDimensions[2] = 4.0f;
|
||||
m_fDimensions[3] = -10.0f;
|
||||
m_fDimensions[4] = -10.0f;
|
||||
m_fDimensions[5] = -24.0f;
|
||||
|
||||
mFlags = LC_PIECE_PLACEHOLDER | LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES;
|
||||
mModel = NULL;
|
||||
|
||||
delete mMesh;
|
||||
mMesh = NULL;
|
||||
}
|
||||
|
||||
void PieceInfo::SetModel(lcModel* Model)
|
||||
{
|
||||
mFlags = LC_PIECE_MODEL;
|
||||
|
@ -64,7 +80,7 @@ void PieceInfo::CreatePlaceholder(const char* Name)
|
|||
strncpy(m_strDescription, Name, sizeof(m_strDescription));
|
||||
m_strDescription[sizeof(m_strDescription)-1] = 0;
|
||||
|
||||
mFlags = LC_PIECE_PLACEHOLDER;
|
||||
SetPlaceholder();
|
||||
}
|
||||
|
||||
void PieceInfo::Load()
|
||||
|
@ -72,19 +88,7 @@ void PieceInfo::Load()
|
|||
if (mFlags & LC_PIECE_MODEL)
|
||||
return;
|
||||
else if (mFlags & LC_PIECE_PLACEHOLDER)
|
||||
{
|
||||
mMesh = new lcMesh();
|
||||
mMesh->CreateBox();
|
||||
|
||||
mFlags |= LC_PIECE_HAS_DEFAULT | LC_PIECE_HAS_LINES;
|
||||
|
||||
m_fDimensions[0] = 10.0f;
|
||||
m_fDimensions[1] = 10.0f;
|
||||
m_fDimensions[2] = 4.0f;
|
||||
m_fDimensions[3] = -10.0f;
|
||||
m_fDimensions[4] = -10.0f;
|
||||
m_fDimensions[5] = -24.0f;
|
||||
}
|
||||
else
|
||||
lcGetPiecesLibrary()->LoadPiece(this);
|
||||
}
|
||||
|
@ -124,6 +128,9 @@ bool PieceInfo::MinIntersectDist(const lcMatrix44& WorldMatrix, const lcVector3&
|
|||
if (!lcBoundingBoxRayIntersectDistance(Min, Max, Start, End, &Distance, NULL) || (Distance >= MinDistance))
|
||||
return false;
|
||||
|
||||
if (mFlags & LC_PIECE_PLACEHOLDER)
|
||||
return true;
|
||||
|
||||
lcVector3 Intersection;
|
||||
|
||||
return mMesh->MinIntersectDist(Start, End, MinDistance, Intersection);
|
||||
|
@ -182,6 +189,9 @@ bool PieceInfo::BoxTest(const lcMatrix44& WorldMatrix, const lcVector4 WorldPlan
|
|||
if (OutcodesAND != 0)
|
||||
return false;
|
||||
|
||||
if (mFlags & LC_PIECE_PLACEHOLDER)
|
||||
return OutcodesOR == 0;
|
||||
|
||||
return OutcodesOR == 0 || mMesh->IntersectsPlanes(LocalPlanes);
|
||||
}
|
||||
|
||||
|
@ -232,7 +242,7 @@ void PieceInfo::AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, i
|
|||
lcRenderMesh RenderMesh;
|
||||
|
||||
RenderMesh.WorldMatrix = WorldMatrix;
|
||||
RenderMesh.Mesh = mMesh;
|
||||
RenderMesh.Mesh = (mFlags & LC_PIECE_PLACEHOLDER) ? gPlaceholderMesh : mMesh;
|
||||
RenderMesh.ColorIndex = ColorIndex;
|
||||
RenderMesh.Focused = Focused;
|
||||
RenderMesh.Selected = Selected;
|
||||
|
@ -257,7 +267,7 @@ void PieceInfo::AddRenderMeshes(const lcMatrix44& ViewMatrix, const lcMatrix44&
|
|||
lcRenderMesh RenderMesh;
|
||||
|
||||
RenderMesh.WorldMatrix = WorldMatrix;
|
||||
RenderMesh.Mesh = mMesh;
|
||||
RenderMesh.Mesh = (mFlags & LC_PIECE_PLACEHOLDER) ? gPlaceholderMesh : mMesh;
|
||||
RenderMesh.ColorIndex = ColorIndex;
|
||||
RenderMesh.Focused = Focused;
|
||||
RenderMesh.Selected = Selected;
|
||||
|
|
|
@ -106,6 +106,7 @@ public:
|
|||
|
||||
void CreatePlaceholder(const char* Name);
|
||||
|
||||
void SetPlaceholder();
|
||||
void SetModel(lcModel* Model);
|
||||
bool IncludesModel(const lcModel* Model) const;
|
||||
bool MinIntersectDist(const lcMatrix44& WorldMatrix, const lcVector3& WorldStart, const lcVector3& WorldEnd, float& MinDistance) const;
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
#include "view.h"
|
||||
#include "texfont.h"
|
||||
#include "lc_texture.h"
|
||||
#include "lc_mesh.h"
|
||||
|
||||
static int gWidgetCount;
|
||||
|
||||
void lcGLWidget::MakeCurrent()
|
||||
{
|
||||
|
@ -128,12 +131,16 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcQGLWidget *share, lcGLWidget *owner,
|
|||
|
||||
// TODO: Find a better place for the grid texture and font
|
||||
gTexFont.Load();
|
||||
if (!gGridTexture)
|
||||
if (!gWidgetCount)
|
||||
{
|
||||
gGridTexture = new lcTexture;
|
||||
gGridTexture->CreateGridTexture();
|
||||
gGridTexture->AddRef();
|
||||
|
||||
gPlaceholderMesh = new lcMesh;
|
||||
gPlaceholderMesh->CreateBox();
|
||||
}
|
||||
gGridTexture->AddRef();
|
||||
gWidgetCount++;
|
||||
|
||||
preferredSize = QSize(0, 0);
|
||||
setMouseTracking(true);
|
||||
|
@ -148,11 +155,15 @@ lcQGLWidget::lcQGLWidget(QWidget *parent, lcQGLWidget *share, lcGLWidget *owner,
|
|||
|
||||
lcQGLWidget::~lcQGLWidget()
|
||||
{
|
||||
gWidgetCount--;
|
||||
gTexFont.Release();
|
||||
if (!gGridTexture->Release())
|
||||
if (!gWidgetCount)
|
||||
{
|
||||
delete gGridTexture;
|
||||
gGridTexture = NULL;
|
||||
|
||||
delete gPlaceholderMesh;
|
||||
gPlaceholderMesh = NULL;
|
||||
}
|
||||
|
||||
if (isView)
|
||||
|
|
Loading…
Add table
Reference in a new issue