diff --git a/common/minifig.cpp b/common/minifig.cpp index 7d5f175b..661d9ef4 100644 --- a/common/minifig.cpp +++ b/common/minifig.cpp @@ -1050,14 +1050,18 @@ void MinifigWizard::OnDraw() Calculate(); - for (int PieceIdx = 0; PieceIdx < LC_MFW_NUMITEMS; PieceIdx++) - { - if (!mMinifig->Parts[PieceIdx]) - continue; + lcArray OpaqueMeshes(LC_MFW_NUMITEMS); + lcArray 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() diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp index df6b772e..cf54f6ca 100644 --- a/common/pieceinf.cpp +++ b/common/pieceinf.cpp @@ -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& OpaqueMeshes, lcArray& 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); + } +} diff --git a/common/pieceinf.h b/common/pieceinf.h index 0149b52f..35740744 100644 --- a/common/pieceinf.h +++ b/common/pieceinf.h @@ -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& OpaqueMeshes, lcArray& TranslucentMeshes); void CreatePlaceholder(const char* Name); diff --git a/common/project.cpp b/common/project.cpp index d993dd61..bfc3d448 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -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);