Files
leocad/common/lc_scene.h
T
Leonardo Zide 78fe37515c Add selection outlines with obscured geometry fill
Render selected pieces with an outline above scene geometry and a faint selection-colored fill only over obscured portions. Preserve line-only selection colors and insertion preview tint, and suppress bounding box corners in outline mode.

Keep the existing tint and edges mode as a preference and fallback when outline rendering is unavailable. Own outline framebuffers in each view, keep OpenGL operations in lcContext, and capture selection visibility before the grid through a callback scoped to each scene draw.

Validation: debug build and desktop OpenGL checks passed for occlusion, transparency, MSAA, HiDPI, line-only selection, framebuffer fallback, grid exclusion, and widget resource cleanup.
2026-10-10 15:54:13 -07:00

179 lines
3.9 KiB
C++

#pragma once
#include "lc_mesh.h"
enum class lcSelectionRenderMode;
enum class lcRenderMeshState : int
{
Default,
Selected,
Focused,
Preview,
Faded,
Highlighted
};
struct lcRenderMesh
{
lcMatrix44 WorldMatrix;
lcMesh* Mesh;
int ColorIndex;
int LodIndex;
lcRenderMeshState State;
};
struct lcTranslucentMeshInstance
{
const lcMeshSection* Section;
int RenderMeshIndex;
float Distance;
};
class lcScene
{
public:
lcScene();
void SetActiveSubmodelInstance(lcPiece* ActiveSubmodelInstance, const lcMatrix44& ActiveSubmodelTransform)
{
mActiveSubmodelInstance = ActiveSubmodelInstance;
mActiveSubmodelTransform = ActiveSubmodelTransform;
}
lcPiece* GetActiveSubmodelInstance() const
{
return mActiveSubmodelInstance;
}
const lcMatrix44& GetViewMatrix() const
{
return mViewMatrix;
}
void SetDrawInterface(bool DrawInterface)
{
mDrawInterface = DrawInterface;
}
bool GetDrawInterface() const
{
return mDrawInterface;
}
void SetRequireCompleteAssets(bool RequireCompleteAssets)
{
mRequireCompleteAssets = RequireCompleteAssets;
}
bool GetRequireCompleteAssets() const
{
return mRequireCompleteAssets;
}
void SetRequireGeneratedMeshes(bool RequireGeneratedMeshes)
{
mRequireGeneratedMeshes = RequireGeneratedMeshes;
}
bool GetRequireGeneratedMeshes() const
{
return mRequireGeneratedMeshes;
}
void MarkMissingAssets()
{
mMissingAssets = true;
}
bool HasMissingAssets() const
{
return mMissingAssets;
}
void SetDrawInsertPreview(bool DrawInsertPreview)
{
mDrawInsertPreview = DrawInsertPreview;
}
bool GetDrawInsertPreview() const
{
return mDrawInsertPreview;
}
void SetShadingMode(lcShadingMode ShadingMode)
{
mShadingMode = ShadingMode;
}
void SetAllowLOD(bool AllowLOD)
{
mAllowLOD = AllowLOD;
}
void SetLODDistance(float Distance)
{
mMeshLODDistance = Distance;
}
lcMatrix44 ApplyActiveSubmodelTransform(const lcMatrix44& WorldMatrix) const
{
return !mActiveSubmodelInstance ? WorldMatrix : lcMul(WorldMatrix, mActiveSubmodelTransform);
}
void Begin(const lcMatrix44& ViewMatrix);
void End();
void AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State);
void AddInterfaceObject(const lcObject* Object)
{
mInterfaceObjects.emplace_back(Object);
}
void Draw(lcContext* Context, const std::function<void()>& PreTranslucentCallback) const;
bool HasSelectedMeshes() const;
bool CanReuseSceneDepth() const;
void DrawOutlineMask(lcContext* Context) const;
void DrawOutlineOccluders(lcContext* Context) const;
void SetSelectionRenderMode(lcSelectionRenderMode SelectionRenderMode)
{
mSelectionRenderMode = SelectionRenderMode;
}
lcSelectionRenderMode GetSelectionRenderMode() const
{
return mSelectionRenderMode;
}
void DrawInterfaceObjects(lcContext* Context) const;
protected:
void DrawOutlineGeometry(lcContext* Context, bool SelectedOnly) const;
void DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTypes, bool DrawFaded, bool DrawNonFaded) const;
void DrawTranslucentMeshes(lcContext* Context, bool DrawLit, bool DrawFadePrepass, bool DrawFaded, bool DrawNonFaded) const;
void DrawDebugNormals(lcContext* Context, const lcMesh* Mesh) const;
lcMatrix44 mViewMatrix;
lcMatrix44 mActiveSubmodelTransform;
lcPiece* mActiveSubmodelInstance = nullptr;
lcShadingMode mShadingMode;
bool mDrawInterface = false;
lcSelectionRenderMode mSelectionRenderMode;
bool mRequireCompleteAssets = false;
bool mRequireGeneratedMeshes = false;
bool mMissingAssets = false;
bool mDrawInsertPreview = false;
bool mAllowLOD = true;
float mMeshLODDistance;
lcVector4 mFadeColor;
lcVector4 mHighlightColor;
bool mHasFadedParts = false;
bool mTranslucentFade = false;
std::vector<lcRenderMesh> mRenderMeshes;
std::vector<int> mOpaqueMeshes;
std::vector<lcTranslucentMeshInstance> mTranslucentMeshes;
std::vector<const lcObject*> mInterfaceObjects;
};