Widget merging.

This commit is contained in:
Leonardo Zide 2020-12-05 11:02:10 -08:00
parent 21d36bbac4
commit 60a0f9190d
15 changed files with 53 additions and 71 deletions

View file

@ -4,8 +4,10 @@
#include "lc_context.h" #include "lc_context.h"
#include "camera.h" #include "camera.h"
#include "texfont.h" #include "texfont.h"
#include "lc_scene.h"
lcGLWidget::lcGLWidget() lcGLWidget::lcGLWidget()
: mScene(new lcScene())
{ {
mContext = new lcContext(); mContext = new lcContext();
} }

View file

@ -111,11 +111,15 @@ public:
protected: protected:
int mMouseX = 0; int mMouseX = 0;
int mMouseY = 0; int mMouseY = 0;
int mMouseDownX = 0;
int mMouseDownY = 0;
Qt::KeyboardModifiers mMouseModifiers = Qt::NoModifier; Qt::KeyboardModifiers mMouseModifiers = Qt::NoModifier;
lcTrackButton mTrackButton = lcTrackButton::None; lcTrackButton mTrackButton = lcTrackButton::None;
lcCursor mCursor = lcCursor::Default; lcCursor mCursor = lcCursor::Default;
std::unique_ptr<lcScene> mScene;
lcCamera* mCamera = nullptr; lcCamera* mCamera = nullptr;
bool mDeleteContext = true; bool mDeleteContext = true;
}; };

View file

@ -1225,9 +1225,9 @@ void lcModel::DuplicateSelectedPieces()
SaveCheckpoint(tr("Duplicating Pieces")); SaveCheckpoint(tr("Duplicating Pieces"));
} }
void lcModel::GetScene(lcScene& Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const void lcModel::GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const
{ {
mPieceInfo->AddRenderMesh(Scene); mPieceInfo->AddRenderMesh(*Scene);
for (const lcPiece* Piece : mPieces) for (const lcPiece* Piece : mPieces)
{ {
@ -1238,19 +1238,19 @@ void lcModel::GetScene(lcScene& Scene, lcCamera* ViewCamera, bool AllowHighlight
} }
} }
if (Scene.GetDrawInterface() && !Scene.GetActiveSubmodelInstance()) if (Scene->GetDrawInterface() && !Scene->GetActiveSubmodelInstance())
{ {
for (lcCamera* Camera : mCameras) for (lcCamera* Camera : mCameras)
if (Camera != ViewCamera && Camera->IsVisible()) if (Camera != ViewCamera && Camera->IsVisible())
Scene.AddInterfaceObject(Camera); Scene->AddInterfaceObject(Camera);
for (lcLight* Light : mLights) for (lcLight* Light : mLights)
if (Light->IsVisible()) if (Light->IsVisible())
Scene.AddInterfaceObject(Light); Scene->AddInterfaceObject(Light);
} }
} }
void lcModel::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const void lcModel::AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const
{ {
for (lcPiece* Piece : mPieces) for (lcPiece* Piece : mPieces)
if (Piece->IsVisibleInSubModel()) if (Piece->IsVisibleInSubModel())
@ -1403,7 +1403,7 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step) const
Scene.SetAllowLOD(false); Scene.SetAllowLOD(false);
Scene.Begin(ViewMatrix); Scene.Begin(ViewMatrix);
Image.Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Image.ColorIndex, lcRenderMeshState::Default, true); Image.Info->AddRenderMeshes(&Scene, lcMatrix44Identity(), Image.ColorIndex, lcRenderMeshState::Default, true);
Scene.End(); Scene.End();

View file

@ -234,8 +234,8 @@ public:
void Paste(); void Paste();
void DuplicateSelectedPieces(); void DuplicateSelectedPieces();
void GetScene(lcScene& Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const; void GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const;
void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const; void AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
QImage GetStepImage(bool Zoom, int Width, int Height, lcStep Step); QImage GetStepImage(bool Zoom, int Width, int Height, lcStep Step);
QImage GetPartsListImage(int MaxWidth, lcStep Step) const; QImage GetPartsListImage(int MaxWidth, lcStep Step) const;
void SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Zoom, int Width, int Height, lcStep Start, lcStep End); void SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Zoom, int Width, int Height, lcStep Start, lcStep End);

View file

@ -427,7 +427,7 @@ void lcPartSelectionListModel::DrawPreview(int InfoIndex)
Scene.SetAllowLOD(false); Scene.SetAllowLOD(false);
Scene.Begin(ViewMatrix); Scene.Begin(ViewMatrix);
Info->AddRenderMeshes(Scene, lcMatrix44Identity(), mColorIndex, lcRenderMeshState::Default, false); Info->AddRenderMeshes(&Scene, lcMatrix44Identity(), mColorIndex, lcRenderMeshState::Default, false);
Scene.End(); Scene.End();

View file

@ -80,16 +80,13 @@ void lcPreviewDockWidget::SetPreviewLock()
} }
lcPreviewWidget::lcPreviewWidget() lcPreviewWidget::lcPreviewWidget()
: mLoader(new Project(true/*IsPreview*/)), : mLoader(new Project(true)), mViewSphere(this)
mViewSphere(this/*Preview*/)
{ {
mTool = lcTool::Select;
mTrackTool = lcTrackTool::None; mTrackTool = lcTrackTool::None;
mTrackButton = lcTrackButton::None; mTrackButton = lcTrackButton::None;
mLoader->SetActiveModel(0); mLoader->SetActiveModel(0);
mModel = mLoader->GetActiveModel(); mModel = mLoader->GetActiveModel();
mCamera = nullptr;
SetDefaultCamera(); SetDefaultCamera();
} }
@ -380,13 +377,6 @@ lcCursor lcPreviewWidget::GetCursor() const
return lcCursor::Select; return lcCursor::Select;
} }
void lcPreviewWidget::OnInitialUpdate()
{
MakeCurrent();
mContext->SetDefaultState();
}
void lcPreviewWidget::OnDraw() void lcPreviewWidget::OnDraw()
{ {
if (!mModel) if (!mModel)
@ -395,16 +385,16 @@ void lcPreviewWidget::OnDraw()
lcPreferences& Preferences = lcGetPreferences(); lcPreferences& Preferences = lcGetPreferences();
const bool DrawInterface = mWidget != nullptr; const bool DrawInterface = mWidget != nullptr;
mScene.SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr); mScene->SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr);
mScene.SetLODDistance(Preferences.mMeshLODDistance); mScene->SetLODDistance(Preferences.mMeshLODDistance);
mScene.Begin(mCamera->mWorldView); mScene->Begin(mCamera->mWorldView);
mScene.SetDrawInterface(DrawInterface); mScene->SetDrawInterface(DrawInterface);
mModel->GetScene(mScene, mCamera, false /*HighlightNewParts*/, false/*mFadeSteps*/); mModel->GetScene(mScene.get(), mCamera, false /*HighlightNewParts*/, false/*mFadeSteps*/);
mScene.End(); mScene->End();
mContext->SetDefaultState(); mContext->SetDefaultState();
@ -416,7 +406,7 @@ void lcPreviewWidget::OnDraw()
mContext->SetLineWidth(Preferences.mLineWidth); mContext->SetLineWidth(Preferences.mLineWidth);
mScene.Draw(mContext); mScene->Draw(mContext);
if (DrawInterface) if (DrawInterface)
{ {

View file

@ -43,11 +43,6 @@ public:
lcPreviewWidget(); lcPreviewWidget();
~lcPreviewWidget(); ~lcPreviewWidget();
lcTool GetTool() const
{
return mTool;
}
QString GetDescription() const QString GetDescription() const
{ {
return mDescription; return mDescription;
@ -71,7 +66,6 @@ public:
return mIsModel; return mIsModel;
} }
void OnInitialUpdate() override;
void OnDraw() override; void OnDraw() override;
void OnUpdateCursor() override; void OnUpdateCursor() override;
void OnLeftButtonDown() override; void OnLeftButtonDown() override;
@ -96,15 +90,10 @@ protected:
lcModel* mModel; lcModel* mModel;
lcViewSphere mViewSphere; lcViewSphere mViewSphere;
lcScene mScene;
lcTool mTool;
lcTrackTool mTrackTool; lcTrackTool mTrackTool;
QString mDescription; QString mDescription;
bool mIsModel; bool mIsModel;
bool mTrackUpdated; bool mTrackUpdated;
int mMouseDownX;
int mMouseDownY;
}; };

View file

@ -19,8 +19,8 @@ enum class lcViewSphereLocation
class lcViewSphere class lcViewSphere
{ {
public: public:
lcViewSphere(View *View); lcViewSphere(View* View);
lcViewSphere(lcPreviewWidget *Preview); lcViewSphere(lcPreviewWidget* Preview);
void Draw(); void Draw();
bool OnMouseMove(); bool OnMouseMove();

View file

@ -389,7 +389,7 @@ void MinifigWizard::OnDraw()
for (int PieceIdx = 0; PieceIdx < LC_MFW_NUMITEMS; PieceIdx++) for (int PieceIdx = 0; PieceIdx < LC_MFW_NUMITEMS; PieceIdx++)
if (mMinifig.Parts[PieceIdx]) if (mMinifig.Parts[PieceIdx])
mMinifig.Parts[PieceIdx]->AddRenderMeshes(Scene, mMinifig.Matrices[PieceIdx], mMinifig.Colors[PieceIdx], lcRenderMeshState::Default, true); mMinifig.Parts[PieceIdx]->AddRenderMeshes(&Scene, mMinifig.Matrices[PieceIdx], mMinifig.Colors[PieceIdx], lcRenderMeshState::Default, true);
Scene.End(); Scene.End();

View file

@ -649,7 +649,7 @@ void lcPiece::RemoveKeyFrames()
ChangeKey(mRotationKeys, lcMatrix33(mModelWorld), 1, true); ChangeKey(mRotationKeys, lcMatrix33(mModelWorld), 1, true);
} }
void lcPiece::AddMainModelRenderMeshes(lcScene& Scene, bool Highlight, bool Fade) const void lcPiece::AddMainModelRenderMeshes(lcScene* Scene, bool Highlight, bool Fade) const
{ {
lcRenderMeshState RenderMeshState = lcRenderMeshState::Default; lcRenderMeshState RenderMeshState = lcRenderMeshState::Default;
bool ParentActive = false; bool ParentActive = false;
@ -660,9 +660,9 @@ void lcPiece::AddMainModelRenderMeshes(lcScene& Scene, bool Highlight, bool Fade
if (Fade) if (Fade)
RenderMeshState = lcRenderMeshState::Faded; RenderMeshState = lcRenderMeshState::Faded;
if (Scene.GetDrawInterface()) if (Scene->GetDrawInterface())
{ {
lcPiece* ActiveSubmodelInstance = Scene.GetActiveSubmodelInstance(); lcPiece* ActiveSubmodelInstance = Scene->GetActiveSubmodelInstance();
if (!ActiveSubmodelInstance) if (!ActiveSubmodelInstance)
RenderMeshState = IsFocused() ? lcRenderMeshState::Focused : (IsSelected() ? lcRenderMeshState::Selected : RenderMeshState); RenderMeshState = IsFocused() ? lcRenderMeshState::Focused : (IsSelected() ? lcRenderMeshState::Selected : RenderMeshState);
@ -675,20 +675,20 @@ void lcPiece::AddMainModelRenderMeshes(lcScene& Scene, bool Highlight, bool Fade
if (!mMesh) if (!mMesh)
mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, RenderMeshState, ParentActive); mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, RenderMeshState, ParentActive);
else else
Scene.AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState); Scene->AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState);
if (RenderMeshState == lcRenderMeshState::Focused || RenderMeshState == lcRenderMeshState::Selected) if (RenderMeshState == lcRenderMeshState::Focused || RenderMeshState == lcRenderMeshState::Selected)
Scene.AddInterfaceObject(this); Scene->AddInterfaceObject(this);
} }
void lcPiece::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const void lcPiece::AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const
{ {
int ColorIndex = mColorIndex; int ColorIndex = mColorIndex;
if (ColorIndex == gDefaultColor) if (ColorIndex == gDefaultColor)
ColorIndex = DefaultColorIndex; ColorIndex = DefaultColorIndex;
lcPiece* ActiveSubmodelInstance = Scene.GetActiveSubmodelInstance(); lcPiece* ActiveSubmodelInstance = Scene->GetActiveSubmodelInstance();
if (ActiveSubmodelInstance == this) if (ActiveSubmodelInstance == this)
RenderMeshState = lcRenderMeshState::Default; RenderMeshState = lcRenderMeshState::Default;
@ -698,10 +698,10 @@ void lcPiece::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMat
if (!mMesh) if (!mMesh)
mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, ActiveSubmodelInstance == this); mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, ActiveSubmodelInstance == this);
else else
Scene.AddMesh(mMesh, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState); Scene->AddMesh(mMesh, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState);
if (ParentActive && (RenderMeshState == lcRenderMeshState::Focused || RenderMeshState == lcRenderMeshState::Selected)) if (ParentActive && (RenderMeshState == lcRenderMeshState::Focused || RenderMeshState == lcRenderMeshState::Selected))
Scene.AddInterfaceObject(this); Scene->AddInterfaceObject(this);
} }
void lcPiece::SubmodelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const void lcPiece::SubmodelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const

View file

@ -409,8 +409,8 @@ public:
void DrawInterface(lcContext* Context, const lcScene& Scene) const override; void DrawInterface(lcContext* Context, const lcScene& Scene) const override;
void RemoveKeyFrames() override; void RemoveKeyFrames() override;
void AddMainModelRenderMeshes(lcScene& Scene, bool Highlight, bool Fade) const; void AddMainModelRenderMeshes(lcScene* Scene, bool Highlight, bool Fade) const;
void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const; void AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
void SubmodelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const; void SubmodelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const;
void InsertTime(lcStep Start, lcStep Time); void InsertTime(lcStep Start, lcStep Time);

View file

@ -305,10 +305,10 @@ void PieceInfo::AddRenderMesh(lcScene& Scene)
Scene.AddMesh(mMesh, lcMatrix44Identity(), gDefaultColor, lcRenderMeshState::Default); Scene.AddMesh(mMesh, lcMatrix44Identity(), gDefaultColor, lcRenderMeshState::Default);
} }
void PieceInfo::AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const void PieceInfo::AddRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const
{ {
if (mMesh || IsPlaceholder()) if (mMesh || IsPlaceholder())
Scene.AddMesh(IsPlaceholder() ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, RenderMeshState); Scene->AddMesh(IsPlaceholder() ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, RenderMeshState);
if (IsModel()) if (IsModel())
mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive); mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);

View file

@ -159,7 +159,7 @@ public:
void ZoomExtents(float FoV, float AspectRatio, lcMatrix44& ProjectionMatrix, lcMatrix44& ViewMatrix) const; void ZoomExtents(float FoV, float AspectRatio, lcMatrix44& ProjectionMatrix, lcMatrix44& ViewMatrix) const;
void AddRenderMesh(lcScene& Scene); void AddRenderMesh(lcScene& Scene);
void AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const; void AddRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
void CreatePlaceholder(const char* Name); void CreatePlaceholder(const char* Name);

View file

@ -8,6 +8,7 @@
#include "piece.h" #include "piece.h"
#include "pieceinf.h" #include "pieceinf.h"
#include "lc_synth.h" #include "lc_synth.h"
#include "lc_scene.h"
lcVertexBuffer View::mRotateMoveVertexBuffer; lcVertexBuffer View::mRotateMoveVertexBuffer;
lcIndexBuffer View::mRotateMoveIndexBuffer; lcIndexBuffer View::mRotateMoveIndexBuffer;
@ -797,15 +798,15 @@ void View::OnDraw()
const lcPreferences& Preferences = lcGetPreferences(); const lcPreferences& Preferences = lcGetPreferences();
const bool DrawInterface = mWidget != nullptr; const bool DrawInterface = mWidget != nullptr;
mScene.SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr); mScene->SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr);
mScene.SetLODDistance(Preferences.mMeshLODDistance); mScene->SetLODDistance(Preferences.mMeshLODDistance);
mScene.Begin(mCamera->mWorldView); mScene->Begin(mCamera->mWorldView);
mScene.SetActiveSubmodelInstance(mActiveSubmodelInstance, mActiveSubmodelTransform); mScene->SetActiveSubmodelInstance(mActiveSubmodelInstance, mActiveSubmodelTransform);
mScene.SetDrawInterface(DrawInterface); mScene->SetDrawInterface(DrawInterface);
mModel->GetScene(mScene, mCamera, Preferences.mHighlightNewParts, Preferences.mFadeSteps); mModel->GetScene(mScene.get(), mCamera, Preferences.mHighlightNewParts, Preferences.mFadeSteps);
if (DrawInterface && mTrackTool == lcTrackTool::Insert) if (DrawInterface && mTrackTool == lcTrackTool::Insert)
{ {
@ -818,14 +819,14 @@ void View::OnDraw()
if (GetActiveModel() != mModel) if (GetActiveModel() != mModel)
WorldMatrix = lcMul(WorldMatrix, mActiveSubmodelTransform); WorldMatrix = lcMul(WorldMatrix, mActiveSubmodelTransform);
Info->AddRenderMeshes(mScene, WorldMatrix, gMainWindow->mColorIndex, lcRenderMeshState::Focused, false); Info->AddRenderMeshes(mScene.get(), WorldMatrix, gMainWindow->mColorIndex, lcRenderMeshState::Focused, false);
} }
} }
if (DrawInterface) if (DrawInterface)
mScene.SetPreTranslucentCallback([this]() { DrawGrid(); }); mScene->SetPreTranslucentCallback([this]() { DrawGrid(); });
mScene.End(); mScene->End();
int TotalTileRows = 1; int TotalTileRows = 1;
int TotalTileColumns = 1; int TotalTileColumns = 1;
@ -878,7 +879,7 @@ void View::OnDraw()
mContext->SetLineWidth(Preferences.mLineWidth); mContext->SetLineWidth(Preferences.mLineWidth);
mScene.Draw(mContext); mScene->Draw(mContext);
if (!mRenderImage.isNull()) if (!mRenderImage.isNull())
{ {
@ -910,7 +911,7 @@ void View::OnDraw()
if (DrawInterface) if (DrawInterface)
{ {
mScene.DrawInterfaceObjects(mContext); mScene->DrawInterfaceObjects(mContext);
mContext->SetLineWidth(1.0f); mContext->SetLineWidth(1.0f);

View file

@ -2,7 +2,6 @@
#include "lc_glwidget.h" #include "lc_glwidget.h"
#include "camera.h" #include "camera.h"
#include "lc_scene.h"
#include "lc_viewsphere.h" #include "lc_viewsphere.h"
#include "lc_commands.h" #include "lc_commands.h"
@ -146,13 +145,10 @@ protected:
lcPiece* mActiveSubmodelInstance; lcPiece* mActiveSubmodelInstance;
lcMatrix44 mActiveSubmodelTransform; lcMatrix44 mActiveSubmodelTransform;
lcScene mScene;
lcDragState mDragState; lcDragState mDragState;
lcTrackTool mTrackTool; lcTrackTool mTrackTool;
bool mTrackToolFromOverlay; bool mTrackToolFromOverlay;
bool mTrackUpdated; bool mTrackUpdated;
int mMouseDownX;
int mMouseDownY;
lcVector3 mMouseDownPosition; lcVector3 mMouseDownPosition;
PieceInfo* mMouseDownPiece; PieceInfo* mMouseDownPiece;
QImage mRenderImage; QImage mRenderImage;