Fixed ugly border in the Minifig Wizard.

This commit is contained in:
Leonardo Zide 2020-12-06 19:33:15 -08:00
parent e52ea0ab63
commit db7259b7a5
5 changed files with 65 additions and 15 deletions

View file

@ -66,6 +66,7 @@ class lcGroup;
class PieceInfo;
typedef std::map<const PieceInfo*, std::map<int, int>> lcPartsList;
struct lcModelPartsEntry;
struct lcMinifig;
class lcVector2;
class lcVector3;

View file

@ -1227,6 +1227,7 @@ void lcModel::DuplicateSelectedPieces()
void lcModel::GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const
{
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);

View file

@ -222,6 +222,7 @@ public:
mSavedHistory = mUndoHistory[0];
}
void SetMinifig(const lcMinifig& Minifig);
void SetPreviewPiece(lcPiece* Piece)
{
AddPiece(Piece);

View file

@ -1,9 +1,9 @@
#include "lc_global.h"
#include "minifig.h"
#include "lc_colors.h"
#include "lc_math.h"
#include <string.h>
#include <stdio.h>
#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

View file

@ -68,7 +68,7 @@
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>