diff --git a/common/lc_glwidget.cpp b/common/lc_glwidget.cpp index 3610aaff..b9e19091 100644 --- a/common/lc_glwidget.cpp +++ b/common/lc_glwidget.cpp @@ -4,8 +4,10 @@ #include "lc_context.h" #include "camera.h" #include "texfont.h" +#include "lc_scene.h" lcGLWidget::lcGLWidget() + : mScene(new lcScene()) { mContext = new lcContext(); } diff --git a/common/lc_glwidget.h b/common/lc_glwidget.h index 708358f0..4a5a8dc4 100644 --- a/common/lc_glwidget.h +++ b/common/lc_glwidget.h @@ -111,11 +111,15 @@ public: protected: int mMouseX = 0; int mMouseY = 0; + int mMouseDownX = 0; + int mMouseDownY = 0; Qt::KeyboardModifiers mMouseModifiers = Qt::NoModifier; lcTrackButton mTrackButton = lcTrackButton::None; lcCursor mCursor = lcCursor::Default; + std::unique_ptr mScene; + lcCamera* mCamera = nullptr; bool mDeleteContext = true; }; diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 0d0d4c11..82038d2d 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -1225,9 +1225,9 @@ void lcModel::DuplicateSelectedPieces() 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) { @@ -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) if (Camera != ViewCamera && Camera->IsVisible()) - Scene.AddInterfaceObject(Camera); + Scene->AddInterfaceObject(Camera); for (lcLight* Light : mLights) 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) if (Piece->IsVisibleInSubModel()) @@ -1403,7 +1403,7 @@ QImage lcModel::GetPartsListImage(int MaxWidth, lcStep Step) const Scene.SetAllowLOD(false); 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(); diff --git a/common/lc_model.h b/common/lc_model.h index 7cb39115..a4967f90 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -234,8 +234,8 @@ public: void Paste(); void DuplicateSelectedPieces(); - 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 GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) 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 GetPartsListImage(int MaxWidth, lcStep Step) const; void SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Zoom, int Width, int Height, lcStep Start, lcStep End); diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index 794de3b4..b90a0a88 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -427,7 +427,7 @@ void lcPartSelectionListModel::DrawPreview(int InfoIndex) Scene.SetAllowLOD(false); Scene.Begin(ViewMatrix); - Info->AddRenderMeshes(Scene, lcMatrix44Identity(), mColorIndex, lcRenderMeshState::Default, false); + Info->AddRenderMeshes(&Scene, lcMatrix44Identity(), mColorIndex, lcRenderMeshState::Default, false); Scene.End(); diff --git a/common/lc_previewwidget.cpp b/common/lc_previewwidget.cpp index 84a03be3..8c54f6f8 100644 --- a/common/lc_previewwidget.cpp +++ b/common/lc_previewwidget.cpp @@ -80,16 +80,13 @@ void lcPreviewDockWidget::SetPreviewLock() } lcPreviewWidget::lcPreviewWidget() - : mLoader(new Project(true/*IsPreview*/)), - mViewSphere(this/*Preview*/) + : mLoader(new Project(true)), mViewSphere(this) { - mTool = lcTool::Select; mTrackTool = lcTrackTool::None; mTrackButton = lcTrackButton::None; mLoader->SetActiveModel(0); mModel = mLoader->GetActiveModel(); - mCamera = nullptr; SetDefaultCamera(); } @@ -380,13 +377,6 @@ lcCursor lcPreviewWidget::GetCursor() const return lcCursor::Select; } -void lcPreviewWidget::OnInitialUpdate() -{ - MakeCurrent(); - - mContext->SetDefaultState(); -} - void lcPreviewWidget::OnDraw() { if (!mModel) @@ -395,16 +385,16 @@ void lcPreviewWidget::OnDraw() lcPreferences& Preferences = lcGetPreferences(); const bool DrawInterface = mWidget != nullptr; - mScene.SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr); - mScene.SetLODDistance(Preferences.mMeshLODDistance); + mScene->SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr); + 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(); @@ -416,7 +406,7 @@ void lcPreviewWidget::OnDraw() mContext->SetLineWidth(Preferences.mLineWidth); - mScene.Draw(mContext); + mScene->Draw(mContext); if (DrawInterface) { diff --git a/common/lc_previewwidget.h b/common/lc_previewwidget.h index 0a0c0212..d2da352d 100644 --- a/common/lc_previewwidget.h +++ b/common/lc_previewwidget.h @@ -43,11 +43,6 @@ public: lcPreviewWidget(); ~lcPreviewWidget(); - lcTool GetTool() const - { - return mTool; - } - QString GetDescription() const { return mDescription; @@ -71,7 +66,6 @@ public: return mIsModel; } - void OnInitialUpdate() override; void OnDraw() override; void OnUpdateCursor() override; void OnLeftButtonDown() override; @@ -96,15 +90,10 @@ protected: lcModel* mModel; lcViewSphere mViewSphere; - lcScene mScene; - - lcTool mTool; lcTrackTool mTrackTool; QString mDescription; bool mIsModel; bool mTrackUpdated; - int mMouseDownX; - int mMouseDownY; }; diff --git a/common/lc_viewsphere.h b/common/lc_viewsphere.h index 551f9191..cbd69655 100644 --- a/common/lc_viewsphere.h +++ b/common/lc_viewsphere.h @@ -19,8 +19,8 @@ enum class lcViewSphereLocation class lcViewSphere { public: - lcViewSphere(View *View); - lcViewSphere(lcPreviewWidget *Preview); + lcViewSphere(View* View); + lcViewSphere(lcPreviewWidget* Preview); void Draw(); bool OnMouseMove(); diff --git a/common/minifig.cpp b/common/minifig.cpp index 0ca23bcb..75c25d32 100644 --- a/common/minifig.cpp +++ b/common/minifig.cpp @@ -389,7 +389,7 @@ void MinifigWizard::OnDraw() 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); + mMinifig.Parts[PieceIdx]->AddRenderMeshes(&Scene, mMinifig.Matrices[PieceIdx], mMinifig.Colors[PieceIdx], lcRenderMeshState::Default, true); Scene.End(); diff --git a/common/piece.cpp b/common/piece.cpp index 78b0aa5c..8215ab5a 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -649,7 +649,7 @@ void lcPiece::RemoveKeyFrames() 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; bool ParentActive = false; @@ -660,9 +660,9 @@ void lcPiece::AddMainModelRenderMeshes(lcScene& Scene, bool Highlight, bool Fade if (Fade) RenderMeshState = lcRenderMeshState::Faded; - if (Scene.GetDrawInterface()) + if (Scene->GetDrawInterface()) { - lcPiece* ActiveSubmodelInstance = Scene.GetActiveSubmodelInstance(); + lcPiece* ActiveSubmodelInstance = Scene->GetActiveSubmodelInstance(); if (!ActiveSubmodelInstance) RenderMeshState = IsFocused() ? lcRenderMeshState::Focused : (IsSelected() ? lcRenderMeshState::Selected : RenderMeshState); @@ -675,20 +675,20 @@ void lcPiece::AddMainModelRenderMeshes(lcScene& Scene, bool Highlight, bool Fade if (!mMesh) mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, RenderMeshState, ParentActive); else - Scene.AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState); + Scene->AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState); 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; if (ColorIndex == gDefaultColor) ColorIndex = DefaultColorIndex; - lcPiece* ActiveSubmodelInstance = Scene.GetActiveSubmodelInstance(); + lcPiece* ActiveSubmodelInstance = Scene->GetActiveSubmodelInstance(); if (ActiveSubmodelInstance == this) RenderMeshState = lcRenderMeshState::Default; @@ -698,10 +698,10 @@ void lcPiece::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMat if (!mMesh) mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, ActiveSubmodelInstance == this); 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)) - Scene.AddInterfaceObject(this); + Scene->AddInterfaceObject(this); } void lcPiece::SubmodelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const diff --git a/common/piece.h b/common/piece.h index ad26cfbf..450c2e49 100644 --- a/common/piece.h +++ b/common/piece.h @@ -409,8 +409,8 @@ public: void DrawInterface(lcContext* Context, const lcScene& Scene) const override; void RemoveKeyFrames() override; - void AddMainModelRenderMeshes(lcScene& Scene, bool Highlight, bool Fade) const; - void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) 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 SubmodelCompareBoundingBox(const lcMatrix44& WorldMatrix, lcVector3& Min, lcVector3& Max) const; void InsertTime(lcStep Start, lcStep Time); diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp index 89311aff..049031e5 100644 --- a/common/pieceinf.cpp +++ b/common/pieceinf.cpp @@ -305,10 +305,10 @@ void PieceInfo::AddRenderMesh(lcScene& Scene) 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()) - Scene.AddMesh(IsPlaceholder() ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, RenderMeshState); + Scene->AddMesh(IsPlaceholder() ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, RenderMeshState); if (IsModel()) mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive); diff --git a/common/pieceinf.h b/common/pieceinf.h index cf9b273a..c6774a7e 100644 --- a/common/pieceinf.h +++ b/common/pieceinf.h @@ -159,7 +159,7 @@ public: void ZoomExtents(float FoV, float AspectRatio, lcMatrix44& ProjectionMatrix, lcMatrix44& ViewMatrix) const; 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); diff --git a/common/view.cpp b/common/view.cpp index 5ecec44c..c0ce8ca6 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -8,6 +8,7 @@ #include "piece.h" #include "pieceinf.h" #include "lc_synth.h" +#include "lc_scene.h" lcVertexBuffer View::mRotateMoveVertexBuffer; lcIndexBuffer View::mRotateMoveIndexBuffer; @@ -797,15 +798,15 @@ void View::OnDraw() const lcPreferences& Preferences = lcGetPreferences(); const bool DrawInterface = mWidget != nullptr; - mScene.SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr); - mScene.SetLODDistance(Preferences.mMeshLODDistance); + mScene->SetAllowLOD(Preferences.mAllowLOD && mWidget != nullptr); + mScene->SetLODDistance(Preferences.mMeshLODDistance); - mScene.Begin(mCamera->mWorldView); + mScene->Begin(mCamera->mWorldView); - mScene.SetActiveSubmodelInstance(mActiveSubmodelInstance, mActiveSubmodelTransform); - mScene.SetDrawInterface(DrawInterface); + mScene->SetActiveSubmodelInstance(mActiveSubmodelInstance, mActiveSubmodelTransform); + 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) { @@ -818,14 +819,14 @@ void View::OnDraw() if (GetActiveModel() != mModel) 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) - mScene.SetPreTranslucentCallback([this]() { DrawGrid(); }); + mScene->SetPreTranslucentCallback([this]() { DrawGrid(); }); - mScene.End(); + mScene->End(); int TotalTileRows = 1; int TotalTileColumns = 1; @@ -878,7 +879,7 @@ void View::OnDraw() mContext->SetLineWidth(Preferences.mLineWidth); - mScene.Draw(mContext); + mScene->Draw(mContext); if (!mRenderImage.isNull()) { @@ -910,7 +911,7 @@ void View::OnDraw() if (DrawInterface) { - mScene.DrawInterfaceObjects(mContext); + mScene->DrawInterfaceObjects(mContext); mContext->SetLineWidth(1.0f); diff --git a/common/view.h b/common/view.h index dd286d08..e40bd03c 100644 --- a/common/view.h +++ b/common/view.h @@ -2,7 +2,6 @@ #include "lc_glwidget.h" #include "camera.h" -#include "lc_scene.h" #include "lc_viewsphere.h" #include "lc_commands.h" @@ -146,13 +145,10 @@ protected: lcPiece* mActiveSubmodelInstance; lcMatrix44 mActiveSubmodelTransform; - lcScene mScene; lcDragState mDragState; lcTrackTool mTrackTool; bool mTrackToolFromOverlay; bool mTrackUpdated; - int mMouseDownX; - int mMouseDownY; lcVector3 mMouseDownPosition; PieceInfo* mMouseDownPiece; QImage mRenderImage;