mirror of
https://github.com/leozide/leocad
synced 2025-01-28 19:58:12 +01:00
Refactored adding meshes.
This commit is contained in:
parent
7e2180e132
commit
38757baec7
4 changed files with 45 additions and 29 deletions
|
@ -1050,14 +1050,18 @@ void MinifigWizard::OnDraw()
|
|||
|
||||
Calculate();
|
||||
|
||||
for (int PieceIdx = 0; PieceIdx < LC_MFW_NUMITEMS; PieceIdx++)
|
||||
{
|
||||
if (!mMinifig->Parts[PieceIdx])
|
||||
continue;
|
||||
lcArray<lcRenderMesh> OpaqueMeshes(LC_MFW_NUMITEMS);
|
||||
lcArray<lcRenderMesh> TranslucentMeshes;
|
||||
|
||||
mContext->SetWorldViewMatrix(lcMul(mMinifig->Matrices[PieceIdx], ViewMatrix));
|
||||
mMinifig->Parts[PieceIdx]->RenderPiece(mMinifig->Colors[PieceIdx]);
|
||||
}
|
||||
for (int PieceIdx = 0; PieceIdx < LC_MFW_NUMITEMS; PieceIdx++)
|
||||
if (mMinifig->Parts[PieceIdx])
|
||||
mMinifig->Parts[PieceIdx]->AddRenderMeshes(ViewMatrix, &mMinifig->Matrices[PieceIdx], mMinifig->Colors[PieceIdx], false, false, OpaqueMeshes, TranslucentMeshes);
|
||||
|
||||
OpaqueMeshes.Sort(lcOpaqueRenderMeshCompare);
|
||||
mContext->DrawOpaqueMeshes(ViewMatrix, OpaqueMeshes);
|
||||
|
||||
TranslucentMeshes.Sort(lcTranslucentRenderMeshCompare);
|
||||
mContext->DrawTranslucentMeshes(ViewMatrix, TranslucentMeshes);
|
||||
}
|
||||
|
||||
void MinifigWizard::OnLeftButtonDown()
|
||||
|
|
|
@ -113,3 +113,28 @@ void PieceInfo::RenderPiece(int nColor)
|
|||
{
|
||||
mMesh->Render(nColor, false, false);
|
||||
}
|
||||
|
||||
void PieceInfo::AddRenderMeshes(const lcMatrix44& ViewMatrix, lcMatrix44* WorldMatrix, int ColorIndex, bool Focused, bool Selected, lcArray<lcRenderMesh>& OpaqueMeshes, lcArray<lcRenderMesh>& TranslucentMeshes)
|
||||
{
|
||||
lcRenderMesh RenderMesh;
|
||||
|
||||
RenderMesh.WorldMatrix = WorldMatrix;
|
||||
RenderMesh.Mesh = mMesh;
|
||||
RenderMesh.ColorIndex = ColorIndex;
|
||||
RenderMesh.Focused = Focused;
|
||||
RenderMesh.Selected = Selected;
|
||||
|
||||
bool Translucent = lcIsColorTranslucent(ColorIndex);
|
||||
|
||||
if ((mFlags & (LC_PIECE_HAS_SOLID | LC_PIECE_HAS_LINES)) || ((mFlags & LC_PIECE_HAS_DEFAULT) && !Translucent))
|
||||
OpaqueMeshes.Add(RenderMesh);
|
||||
|
||||
if ((mFlags & LC_PIECE_HAS_TRANSLUCENT) || ((mFlags & LC_PIECE_HAS_DEFAULT) && Translucent))
|
||||
{
|
||||
lcVector3 Pos = lcMul31((*WorldMatrix)[3], ViewMatrix);
|
||||
|
||||
RenderMesh.Distance = Pos[2];
|
||||
|
||||
TranslucentMeshes.Add(RenderMesh);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "opengl.h"
|
||||
#endif
|
||||
#include "lc_math.h"
|
||||
#include "lc_array.h"
|
||||
#include "lc_mesh.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
|
||||
|
@ -76,6 +78,7 @@ public:
|
|||
// Operations
|
||||
void ZoomExtents(float Fov, float Aspect, float* EyePos = NULL) const;
|
||||
void RenderPiece(int nColor);
|
||||
void AddRenderMeshes(const lcMatrix44& ViewMatrix, lcMatrix44* WorldMatrix, int ColorIndex, bool Focused, bool Selected, lcArray<lcRenderMesh>& OpaqueMeshes, lcArray<lcRenderMesh>& TranslucentMeshes);
|
||||
|
||||
void CreatePlaceholder(const char* Name);
|
||||
|
||||
|
|
|
@ -1710,36 +1710,20 @@ void Project::RenderScenePieces(View* view, bool DrawInterface)
|
|||
continue;
|
||||
|
||||
PieceInfo* Info = Piece->mPieceInfo;
|
||||
lcRenderMesh RenderMesh;
|
||||
|
||||
RenderMesh.WorldMatrix = &Piece->mModelWorld;
|
||||
RenderMesh.Mesh = Info->mMesh;
|
||||
RenderMesh.ColorIndex = Piece->mColorIndex;
|
||||
bool Focused, Selected;
|
||||
|
||||
if (DrawInterface)
|
||||
{
|
||||
RenderMesh.Focused = Piece->IsFocused();
|
||||
RenderMesh.Selected = Piece->IsSelected();
|
||||
Focused = Piece->IsFocused();
|
||||
Selected = Piece->IsSelected();
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderMesh.Focused = false;
|
||||
RenderMesh.Selected = false;
|
||||
Focused = false;
|
||||
Selected = false;
|
||||
}
|
||||
|
||||
bool Translucent = lcIsColorTranslucent(Piece->mColorIndex);
|
||||
|
||||
if ((Info->mFlags & (LC_PIECE_HAS_SOLID | LC_PIECE_HAS_LINES)) || ((Info->mFlags & LC_PIECE_HAS_DEFAULT) && !Translucent))
|
||||
OpaqueMeshes.Add(RenderMesh);
|
||||
|
||||
if ((Info->mFlags & LC_PIECE_HAS_TRANSLUCENT) || ((Info->mFlags & LC_PIECE_HAS_DEFAULT) && Translucent))
|
||||
{
|
||||
lcVector3 Pos = lcMul31(Piece->mPosition, ViewMatrix);
|
||||
|
||||
RenderMesh.Distance = Pos[2];
|
||||
|
||||
TranslucentMeshes.Add(RenderMesh);
|
||||
}
|
||||
Info->AddRenderMeshes(ViewMatrix, &Piece->mModelWorld, Piece->mColorIndex, Focused, Selected, OpaqueMeshes, TranslucentMeshes);
|
||||
}
|
||||
|
||||
OpaqueMeshes.Sort(lcOpaqueRenderMeshCompare);
|
||||
|
|
Loading…
Add table
Reference in a new issue