Fixed selection tinting when editing submodels.

This commit is contained in:
Leonardo Zide 2018-04-07 11:45:00 -07:00
parent 4a9cd5556b
commit 718b31a2bd
13 changed files with 93 additions and 57 deletions

View file

@ -96,13 +96,13 @@ public:
int mIndexType;
};
enum lcRenderMeshState
enum class lcRenderMeshState : int
{
LC_RENDERMESH_NONE,
LC_RENDERMESH_SELECTED,
LC_RENDERMESH_FOCUSED,
LC_RENDERMESH_DISABLED,
LC_RENDERMESH_HIGHLIGHT
NORMAL,
SELECTED,
FOCUSED,
DISABLED,
HIGHLIGHT
};
struct lcRenderMesh

View file

@ -1254,12 +1254,14 @@ void lcModel::DuplicateSelectedPieces()
void lcModel::GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const
{
Scene.Begin(ViewCamera->mWorldView);
Scene.SetActiveSubmodelInstance(ActiveSubmodelInstance);
Scene.SetDrawInterface(DrawInterface);
mPieceInfo->AddRenderMesh(Scene);
for (lcPiece* Piece : mPieces)
if (Piece->IsVisible(mCurrentStep))
Piece->AddRenderMeshes(Scene, DrawInterface, Highlight && Piece->GetStepShow() == mCurrentStep, ActiveSubmodelInstance);
Piece->AddMainModelRenderMeshes(Scene, Highlight && Piece->GetStepShow() == mCurrentStep);
if (DrawInterface && !ActiveSubmodelInstance)
{
@ -1283,11 +1285,11 @@ void lcModel::GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface,
Scene.End();
}
void lcModel::SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected, bool Disabled, lcPiece* ActiveSubmodelInstance) const
void lcModel::AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const
{
for (lcPiece* Piece : mPieces)
if (Piece->GetStepHide() == LC_STEP_MAX)
Piece->SubModelAddRenderMeshes(Scene, WorldMatrix, DefaultColorIndex, Focused, Selected, Disabled, ActiveSubmodelInstance);
Piece->AddSubModelRenderMeshes(Scene, WorldMatrix, DefaultColorIndex, RenderMeshState, ParentActive);
}
void lcModel::DrawBackground(lcGLWidget* Widget)

View file

@ -19,6 +19,7 @@
#define LC_SEL_CAN_REMOVE_CONTROL_POINT 0x1000 // Can remove control points from focused piece
class lcGLWidget;
enum class lcRenderMeshState : int;
enum class lcSelectionMode
{
@ -233,7 +234,7 @@ public:
void DuplicateSelectedPieces();
void GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const;
void SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected, bool Disabled, lcPiece* ActiveSubmodelInstance) const;
void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
void DrawBackground(lcGLWidget* Widget);
void SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Zoom, bool Highlight, int Width, int Height, lcStep Start, lcStep End);

View file

@ -370,7 +370,7 @@ void lcPartSelectionListModel::DrawPreview(int InfoIndex)
lcScene Scene;
Scene.Begin(ViewMatrix);
Info->AddRenderMeshes(Scene, lcMatrix44Identity(), mColorIndex, false, false, false, false, nullptr);
Info->AddRenderMeshes(Scene, lcMatrix44Identity(), mColorIndex, lcRenderMeshState::NORMAL, true);
Scene.End();

View file

@ -10,11 +10,14 @@
lcScene::lcScene()
: mRenderMeshes(0, 1024), mOpaqueMeshes(0, 1024), mTranslucentMeshes(0, 1024), mInterfaceObjects(0, 1024)
{
mActiveSubmodelInstance = nullptr;
}
void lcScene::Begin(const lcMatrix44& ViewMatrix)
{
mViewMatrix = ViewMatrix;
mActiveSubmodelInstance = nullptr;
mDrawInterface = false;
mRenderMeshes.RemoveAll();
mOpaqueMeshes.RemoveAll();
mTranslucentMeshes.RemoveAll();
@ -94,20 +97,20 @@ void lcScene::DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool Enab
switch (RenderMesh.State)
{
case LC_RENDERMESH_NONE:
case LC_RENDERMESH_HIGHLIGHT:
case lcRenderMeshState::NORMAL:
case lcRenderMeshState::HIGHLIGHT:
Context->SetColorIndex(ColorIndex);
break;
case LC_RENDERMESH_SELECTED:
case lcRenderMeshState::SELECTED:
Context->SetColorIndexTinted(ColorIndex, LC_COLOR_SELECTED, 0.5f);
break;
case LC_RENDERMESH_FOCUSED:
case lcRenderMeshState::FOCUSED:
Context->SetColorIndexTinted(ColorIndex, LC_COLOR_FOCUSED, 0.5f);
break;
case LC_RENDERMESH_DISABLED:
case lcRenderMeshState::DISABLED:
Context->SetColorIndexTinted(ColorIndex, LC_COLOR_DISABLED, 0.25f);
break;
}
@ -116,26 +119,26 @@ void lcScene::DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool Enab
{
switch (RenderMesh.State)
{
case LC_RENDERMESH_NONE:
case lcRenderMeshState::NORMAL:
if (ColorIndex == gEdgeColor)
Context->SetEdgeColorIndex(RenderMesh.ColorIndex);
else
Context->SetColorIndex(ColorIndex);
break;
case LC_RENDERMESH_SELECTED:
case lcRenderMeshState::SELECTED:
Context->SetInterfaceColor(LC_COLOR_SELECTED);
break;
case LC_RENDERMESH_FOCUSED:
case lcRenderMeshState::FOCUSED:
Context->SetInterfaceColor(LC_COLOR_FOCUSED);
break;
case LC_RENDERMESH_HIGHLIGHT:
case lcRenderMeshState::HIGHLIGHT:
Context->SetInterfaceColor(LC_COLOR_HIGHLIGHT);
break;
case LC_RENDERMESH_DISABLED:
case lcRenderMeshState::DISABLED:
Context->SetInterfaceColor(LC_COLOR_DISABLED);
break;
}

View file

@ -8,6 +8,26 @@ class lcScene
public:
lcScene();
void SetActiveSubmodelInstance(lcPiece* ActiveSubmodelInstance)
{
mActiveSubmodelInstance = ActiveSubmodelInstance;
}
lcPiece* GetActiveSubmodelInstance() const
{
return mActiveSubmodelInstance;
}
void SetDrawInterface(bool DrawInterface)
{
mDrawInterface = DrawInterface;
}
bool GetDrawInterface() const
{
return mDrawInterface;
}
void Begin(const lcMatrix44& ViewMatrix);
void End();
void AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State, int Flags);
@ -24,6 +44,9 @@ protected:
void DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool EnableNormals, bool DrawTranslucent, bool DrawTextured) const;
lcMatrix44 mViewMatrix;
lcPiece* mActiveSubmodelInstance;
bool mDrawInterface;
lcArray<lcRenderMesh> mRenderMeshes;
lcArray<int> mOpaqueMeshes;
lcArray<int> mTranslucentMeshes;

View file

@ -350,7 +350,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], false, false, false, false, nullptr);
mMinifig.Parts[PieceIdx]->AddRenderMeshes(Scene, mMinifig.Matrices[PieceIdx], mMinifig.Colors[PieceIdx], lcRenderMeshState::NORMAL, true);
Scene.End();

View file

@ -646,46 +646,55 @@ void lcPiece::RemoveKeyFrames()
ChangeKey(mRotationKeys, lcMatrix33(mModelWorld), 1, true);
}
void lcPiece::AddRenderMeshes(lcScene& Scene, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const
void lcPiece::AddMainModelRenderMeshes(lcScene& Scene, bool Highlight) const
{
bool Focused, Selected, Disabled;
lcRenderMeshState RenderMeshState = lcRenderMeshState::NORMAL;
bool ParentActive = false;
if (DrawInterface)
if (Scene.GetDrawInterface())
{
Focused = IsFocused();
Selected = IsSelected();
Disabled = ActiveSubmodelInstance && (ActiveSubmodelInstance != this);
}
else
{
Focused = false;
Selected = false;
Disabled = false;
}
lcPiece* ActiveSubmodelInstance = Scene.GetActiveSubmodelInstance();
if (ActiveSubmodelInstance == this)
ActiveSubmodelInstance = nullptr;
if (!ActiveSubmodelInstance)
RenderMeshState = IsFocused() ? lcRenderMeshState::FOCUSED : (IsSelected() ? lcRenderMeshState::SELECTED : lcRenderMeshState::NORMAL);
else if (ActiveSubmodelInstance == this)
ParentActive = true;
else
RenderMeshState = lcRenderMeshState::DISABLED;
}
else if (Highlight)
RenderMeshState = lcRenderMeshState::HIGHLIGHT;
if (!mMesh)
mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, Focused, Selected, Disabled, Highlight, ActiveSubmodelInstance);
mPieceInfo->AddRenderMeshes(Scene, mModelWorld, mColorIndex, RenderMeshState, ParentActive);
else
Scene.AddMesh(mMesh, mModelWorld, mColorIndex, Disabled ? LC_RENDERMESH_DISABLED : (Focused ? LC_RENDERMESH_FOCUSED : (Selected ? LC_RENDERMESH_SELECTED : LC_RENDERMESH_NONE)), mPieceInfo->mFlags);
Scene.AddMesh(mMesh, mModelWorld, mColorIndex, RenderMeshState, mPieceInfo->mFlags);
if (Selected)
if (RenderMeshState == lcRenderMeshState::FOCUSED || RenderMeshState == lcRenderMeshState::SELECTED)
Scene.AddInterfaceObject(this);
}
void lcPiece::SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected, bool Disabled, lcPiece* ActiveSubmodelInstance) 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();
if (ActiveSubmodelInstance == this)
RenderMeshState = lcRenderMeshState::NORMAL;
else if (ParentActive)
RenderMeshState = IsFocused() ? lcRenderMeshState::FOCUSED : (IsSelected() ? lcRenderMeshState::SELECTED : lcRenderMeshState::NORMAL);
if (!mMesh)
mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, Focused, Selected, Disabled, false, ActiveSubmodelInstance);
mPieceInfo->AddRenderMeshes(Scene, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, ActiveSubmodelInstance == this);
else
Scene.AddMesh(mMesh, lcMul(mModelWorld, WorldMatrix), ColorIndex, Disabled ? LC_RENDERMESH_DISABLED : (Focused ? LC_RENDERMESH_FOCUSED : (Selected ? LC_RENDERMESH_SELECTED : LC_RENDERMESH_NONE)), mPieceInfo->mFlags);
Scene.AddMesh(mMesh, lcMul(mModelWorld, WorldMatrix), ColorIndex, RenderMeshState, mPieceInfo->mFlags);
if (ParentActive && (RenderMeshState == lcRenderMeshState::FOCUSED || RenderMeshState == lcRenderMeshState::SELECTED))
Scene.AddInterfaceObject(this);
}
void lcPiece::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)

View file

@ -1,6 +1,7 @@
#pragma once
class PieceInfo;
enum class lcRenderMeshState : int;
#include "object.h"
#include "lc_colors.h"
@ -346,8 +347,8 @@ public:
virtual void DrawInterface(lcContext* Context) const override;
virtual void RemoveKeyFrames() override;
void AddRenderMeshes(lcScene& Scene, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const;
void SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected, bool Disabled, lcPiece* ActiveSubmodelInstance) const;
void AddMainModelRenderMeshes(lcScene& Scene, bool Highlight) const;
void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
void InsertTime(lcStep Start, lcStep Time);
void RemoveTime(lcStep Start, lcStep Time);

View file

@ -303,21 +303,21 @@ void PieceInfo::ZoomExtents(float FoV, float AspectRatio, lcMatrix44& Projection
void PieceInfo::AddRenderMesh(lcScene& Scene)
{
if (mMesh)
Scene.AddMesh(mMesh, lcMatrix44Identity(), gDefaultColor, LC_RENDERMESH_NONE, mFlags);
Scene.AddMesh(mMesh, lcMatrix44Identity(), gDefaultColor, lcRenderMeshState::NORMAL, mFlags);
}
void PieceInfo::AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, bool Focused, bool Selected, bool Disabled, bool Highlight, lcPiece* ActiveSubmodelInstance) const
void PieceInfo::AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const
{
if ((mMesh) || (mFlags & LC_PIECE_PLACEHOLDER))
Scene.AddMesh((mFlags & LC_PIECE_PLACEHOLDER) ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, Disabled ? LC_RENDERMESH_DISABLED : (Focused ? LC_RENDERMESH_FOCUSED : (Selected ? LC_RENDERMESH_SELECTED : (Highlight ? LC_RENDERMESH_HIGHLIGHT : LC_RENDERMESH_NONE))), mFlags);
Scene.AddMesh((mFlags & LC_PIECE_PLACEHOLDER) ? gPlaceholderMesh : mMesh, WorldMatrix, ColorIndex, RenderMeshState, mFlags);
if (mFlags & LC_PIECE_MODEL)
mModel->SubModelAddRenderMeshes(Scene, WorldMatrix, ColorIndex, Focused, Selected, Disabled, ActiveSubmodelInstance);
mModel->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);
else if (mFlags & LC_PIECE_PROJECT)
{
lcModel* Model = mProject->GetMainModel();
if (Model)
Model->SubModelAddRenderMeshes(Scene, WorldMatrix, ColorIndex, Focused, Selected, Disabled, ActiveSubmodelInstance);
Model->AddSubModelRenderMeshes(Scene, WorldMatrix, ColorIndex, RenderMeshState, ParentActive);
}
}

View file

@ -136,7 +136,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, bool Focused, bool Selected, bool Disabled, bool Highlight, lcPiece* ActiveSubmodelInstance) const;
void AddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;
void CreatePlaceholder(const char* Name);

View file

@ -1554,7 +1554,7 @@ QImage Project::CreatePartsListImage(lcModel* Model, lcStep Step)
lcScene Scene;
Scene.Begin(ViewMatrix);
Image.Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Image.ColorIndex, false, false, false, false, nullptr);
Image.Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Image.ColorIndex, lcRenderMeshState::NORMAL, true);
Scene.End();
@ -1942,7 +1942,7 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options)
lcScene Scene;
Scene.Begin(ViewMatrix);
Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Options.PartImagesColor, false, false, false, false, nullptr);
Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Options.PartImagesColor, lcRenderMeshState::NORMAL, true);
Scene.End();

View file

@ -54,7 +54,6 @@ void View::SetSelectedSubmodelActive()
{
lcModel* Model = mActiveSubmodelInstance->mPieceInfo->GetModel();
Model->SetActive(false);
Model->ClearSelection(true);
mActiveSubmodelInstance = nullptr;
}
@ -67,13 +66,11 @@ void View::SetSelectedSubmodelActive()
if (Piece->mPieceInfo->IsModel())
{
ActiveModel->ClearSelection(false);
mActiveSubmodelMatrix = lcMatrix44Identity();
mModel->GetPieceWorldMatrix(Piece, mActiveSubmodelMatrix);
mActiveSubmodelInstance = Piece;
lcModel* Model = mActiveSubmodelInstance->mPieceInfo->GetModel();
Model->SetActive(true);
Model->ClearSelection(true);
}
}
}
@ -722,7 +719,7 @@ void View::OnDraw()
PieceInfo* Info = gMainWindow->GetCurrentPieceInfo();
if (Info)
Info->AddRenderMeshes(mScene, GetPieceInsertPosition(false, gMainWindow->GetCurrentPieceInfo()), gMainWindow->mColorIndex, true, true, false, false, nullptr);
Info->AddRenderMeshes(mScene, GetPieceInsertPosition(false, gMainWindow->GetCurrentPieceInfo()), gMainWindow->mColorIndex, lcRenderMeshState::FOCUSED, true);
}
int TotalTileRows = 1;