From db7259b7a5170e4b993e850049038132d62a2e1d Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 6 Dec 2020 19:33:15 -0800 Subject: [PATCH] Fixed ugly border in the Minifig Wizard. --- common/lc_global.h | 1 + common/lc_model.cpp | 21 +++++++++++++++- common/lc_model.h | 1 + common/minifig.cpp | 55 +++++++++++++++++++++++++++++++---------- qt/lc_qminifigdialog.ui | 2 +- 5 files changed, 65 insertions(+), 15 deletions(-) diff --git a/common/lc_global.h b/common/lc_global.h index bf3dcdcd..ba7eb3d8 100644 --- a/common/lc_global.h +++ b/common/lc_global.h @@ -66,6 +66,7 @@ class lcGroup; class PieceInfo; typedef std::map> lcPartsList; struct lcModelPartsEntry; +struct lcMinifig; class lcVector2; class lcVector3; diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 82038d2d..3d3ab695 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -1227,7 +1227,8 @@ void lcModel::DuplicateSelectedPieces() void lcModel::GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const { - mPieceInfo->AddRenderMesh(*Scene); + if (mPieceInfo) + mPieceInfo->AddRenderMesh(*Scene); for (const lcPiece* Piece : mPieces) { @@ -4434,6 +4435,24 @@ void lcModel::ShowMinifigDialog() SaveCheckpoint(tr("Minifig")); } +void lcModel::SetMinifig(const lcMinifig& Minifig) +{ + DeleteModel(); + + for (int PartIdx = 0; PartIdx < LC_MFW_NUMITEMS; PartIdx++) + { + if (!Minifig.Parts[PartIdx]) + continue; + + lcPiece* Piece = new lcPiece(Minifig.Parts[PartIdx]); + + Piece->Initialize(Minifig.Matrices[PartIdx], 1); + Piece->SetColorIndex(Minifig.Colors[PartIdx]); + AddPiece(Piece); + Piece->UpdatePosition(1); + } +} + void lcModel::UpdateInterface() { gMainWindow->UpdateTimeline(true, false); diff --git a/common/lc_model.h b/common/lc_model.h index a73b7e51..a253a6f6 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -222,6 +222,7 @@ public: mSavedHistory = mUndoHistory[0]; } + void SetMinifig(const lcMinifig& Minifig); void SetPreviewPiece(lcPiece* Piece) { AddPiece(Piece); diff --git a/common/minifig.cpp b/common/minifig.cpp index f2dff1ea..67e000e2 100644 --- a/common/minifig.cpp +++ b/common/minifig.cpp @@ -1,9 +1,9 @@ #include "lc_global.h" +#include "minifig.h" #include "lc_colors.h" -#include "lc_math.h" #include #include -#include "minifig.h" +#include "camera.h" #include "pieceinf.h" #include "project.h" #include "lc_model.h" @@ -41,6 +41,9 @@ MinifigWizard::MinifigWizard() LoadSettings(); LoadTemplates(); + mModel = new lcModel(QString(), false); + mCamera = new lcCamera(true); + mRotateX = 75.0f; mRotateZ = 180.0f; mDistance = 10.0f; @@ -54,7 +57,10 @@ MinifigWizard::~MinifigWizard() for (int i = 0; i < LC_MFW_NUMITEMS; i++) if (mMinifig.Parts[i]) - Library->ReleasePieceInfo(mMinifig.Parts[i]); + Library->ReleasePieceInfo(mMinifig.Parts[i]); // todo: don't call ReleasePieceInfo here because it may release textures and they need a GL context current + + delete mModel; + delete mCamera; SaveTemplates(); } @@ -324,11 +330,34 @@ void MinifigWizard::OnDraw() { mContext->SetDefaultState(); - const float Aspect = (float)mWidth/(float)mHeight; mContext->SetViewport(0, 0, mWidth, mHeight); DrawBackground(); + // todo: temp viewport drawing code until this is merged with View + { + mContext->SetWorldMatrix(lcMatrix44Identity()); + mContext->SetViewMatrix(lcMatrix44Translation(lcVector3(0.375, 0.375, 0.0))); + mContext->SetProjectionMatrix(lcMatrix44Ortho(0.0f, mWidth, 0.0f, mHeight, -1.0f, 1.0f)); + + mContext->SetDepthWrite(false); + glDisable(GL_DEPTH_TEST); + +// if (gMainWindow->GetActiveView() == this) + { + mContext->SetMaterial(lcMaterialType::UnlitColor); + mContext->SetColor(lcVector4FromColor(lcGetPreferences().mActiveViewColor)); + float Verts[8] = { 0.0f, 0.0f, mWidth - 1.0f, 0.0f, mWidth - 1.0f, mHeight - 1.0f, 0.0f, mHeight - 1.0f }; + + mContext->SetVertexBufferPointer(Verts); + mContext->SetVertexFormatPosition(2); + mContext->DrawPrimitives(GL_LINE_LOOP, 0, 4); + } + + mContext->SetDepthWrite(true); + glEnable(GL_DEPTH_TEST); + } + lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX); for (int InfoIdx = 0; InfoIdx < LC_MFW_NUMITEMS; InfoIdx++) @@ -357,10 +386,11 @@ void MinifigWizard::OnDraw() Eye = lcMul30(Eye, lcMatrix44RotationX(-mRotateX * LC_DTOR)); Eye = lcMul30(Eye, lcMatrix44RotationZ(-mRotateZ * LC_DTOR)); + const float Aspect = (float)mWidth / (float)mHeight; const lcMatrix44 Projection = lcMatrix44Perspective(30.0f, Aspect, 1.0f, 2500.0f); mContext->SetProjectionMatrix(Projection); - lcMatrix44 ViewMatrix; + lcMatrix44& ViewMatrix = mCamera->mWorldView; if (mAutoZoom) { @@ -384,17 +414,14 @@ void MinifigWizard::OnDraw() Calculate(); - lcScene Scene; - Scene.Begin(ViewMatrix); - Scene.SetAllowLOD(false); + mScene->Begin(ViewMatrix); + mScene->SetAllowLOD(false); - for (int PieceIdx = 0; PieceIdx < LC_MFW_NUMITEMS; PieceIdx++) - if (mMinifig.Parts[PieceIdx]) - mMinifig.Parts[PieceIdx]->AddRenderMeshes(&Scene, mMinifig.Matrices[PieceIdx], mMinifig.Colors[PieceIdx], lcRenderMeshState::Default, true); + mModel->GetScene(mScene.get(), mCamera, false, false); - Scene.End(); + mScene->End(); - Scene.Draw(mContext); + mScene->Draw(mContext); mContext->ClearResources(); } @@ -638,6 +665,8 @@ void MinifigWizard::Calculate() Mat.SetTranslation(lcMul31(Center, Mat2)); Matrices[LC_MFW_LLEGA] = lcMul(Mat, Matrices[LC_MFW_LLEG]); } + + mModel->SetMinifig(mMinifig); } int MinifigWizard::GetSelectionIndex(int Type) const diff --git a/qt/lc_qminifigdialog.ui b/qt/lc_qminifigdialog.ui index e5987abf..25819793 100644 --- a/qt/lc_qminifigdialog.ui +++ b/qt/lc_qminifigdialog.ui @@ -68,7 +68,7 @@ - QFrame::Panel + QFrame::NoFrame QFrame::Plain