leocad/common/lc_scene.h

122 lines
2.6 KiB
C
Raw Normal View History

2017-04-02 01:53:54 +02:00
#pragma once
#include "lc_mesh.h"
2019-11-23 01:47:58 +01:00
enum class lcRenderMeshState : int
{
2020-01-02 02:06:17 +01:00
Default,
Selected,
Focused,
Faded,
Highlighted
2019-11-23 01:47:58 +01:00
};
struct lcRenderMesh
{
lcMatrix44 WorldMatrix;
lcMesh* Mesh;
int ColorIndex;
int LodIndex;
lcRenderMeshState State;
};
struct lcTranslucentMeshInstance
{
const lcMeshSection* Section;
int RenderMeshIndex;
float Distance;
};
2017-04-02 01:53:54 +02:00
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;
}
2021-01-10 01:02:23 +01:00
void SetShadingMode(lcShadingMode ShadingMode)
{
2021-01-10 01:02:23 +01:00
mShadingMode = ShadingMode;
}
void SetAllowLOD(bool AllowLOD)
{
mAllowLOD = AllowLOD;
}
2020-08-16 01:16:26 +02:00
void SetLODDistance(float Distance)
{
mMeshLODDistance = Distance;
}
void SetPreTranslucentCallback(std::function<void()> Callback)
{
mPreTranslucentCallback = Callback;
}
lcMatrix44 ApplyActiveSubmodelTransform(const lcMatrix44& WorldMatrix) const
{
return !mActiveSubmodelInstance ? WorldMatrix : lcMul(WorldMatrix, mActiveSubmodelTransform);
}
2017-04-02 01:53:54 +02:00
void Begin(const lcMatrix44& ViewMatrix);
void End();
2019-07-21 17:56:37 +02:00
void AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State);
2017-04-02 01:53:54 +02:00
void AddInterfaceObject(const lcObject* Object)
{
2024-05-11 21:44:06 +02:00
mInterfaceObjects.emplace_back(Object);
2017-04-02 01:53:54 +02:00
}
void Draw(lcContext* Context) const;
void DrawInterfaceObjects(lcContext* Context) const;
protected:
2020-04-20 05:21:18 +02:00
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;
2020-03-23 04:18:52 +01:00
void DrawDebugNormals(lcContext* Context, const lcMesh* Mesh) const;
2017-04-02 01:53:54 +02:00
lcMatrix44 mViewMatrix;
lcMatrix44 mActiveSubmodelTransform;
lcPiece* mActiveSubmodelInstance;
2021-01-10 01:02:23 +01:00
lcShadingMode mShadingMode;
bool mDrawInterface;
bool mAllowLOD;
2020-08-16 01:16:26 +02:00
float mMeshLODDistance;
2020-04-25 21:16:37 +02:00
lcVector4 mFadeColor;
lcVector4 mHighlightColor;
bool mHasFadedParts;
2020-04-25 21:16:37 +02:00
bool mTranslucentFade;
std::function<void()> mPreTranslucentCallback;
2024-05-11 21:44:06 +02:00
std::vector<lcRenderMesh> mRenderMeshes;
std::vector<int> mOpaqueMeshes;
std::vector<lcTranslucentMeshInstance> mTranslucentMeshes;
std::vector<const lcObject*> mInterfaceObjects;
2017-04-02 01:53:54 +02:00
};