1 #pragma once 2 3 #include "lc_mesh.h" 4 #include "lc_array.h" 5 6 enum class lcRenderMeshState : int 7 { 8 Default, 9 Selected, 10 Focused, 11 Faded, 12 Highlighted 13 }; 14 15 struct lcRenderMesh 16 { 17 lcMatrix44 WorldMatrix; 18 lcMesh* Mesh; 19 int ColorIndex; 20 int LodIndex; 21 lcRenderMeshState State; 22 }; 23 24 struct lcTranslucentMeshInstance 25 { 26 const lcMeshSection* Section; 27 int RenderMeshIndex; 28 float Distance; 29 }; 30 31 class lcScene 32 { 33 public: 34 lcScene(); 35 SetActiveSubmodelInstance(lcPiece * ActiveSubmodelInstance,const lcMatrix44 & ActiveSubmodelTransform)36 void SetActiveSubmodelInstance(lcPiece* ActiveSubmodelInstance, const lcMatrix44& ActiveSubmodelTransform) 37 { 38 mActiveSubmodelInstance = ActiveSubmodelInstance; 39 mActiveSubmodelTransform = ActiveSubmodelTransform; 40 } 41 GetActiveSubmodelInstance()42 lcPiece* GetActiveSubmodelInstance() const 43 { 44 return mActiveSubmodelInstance; 45 } 46 GetViewMatrix()47 const lcMatrix44& GetViewMatrix() const 48 { 49 return mViewMatrix; 50 } 51 SetDrawInterface(bool DrawInterface)52 void SetDrawInterface(bool DrawInterface) 53 { 54 mDrawInterface = DrawInterface; 55 } 56 GetDrawInterface()57 bool GetDrawInterface() const 58 { 59 return mDrawInterface; 60 } 61 SetShadingMode(lcShadingMode ShadingMode)62 void SetShadingMode(lcShadingMode ShadingMode) 63 { 64 mShadingMode = ShadingMode; 65 } 66 SetAllowLOD(bool AllowLOD)67 void SetAllowLOD(bool AllowLOD) 68 { 69 mAllowLOD = AllowLOD; 70 } 71 SetLODDistance(float Distance)72 void SetLODDistance(float Distance) 73 { 74 mMeshLODDistance = Distance; 75 } 76 SetPreTranslucentCallback(std::function<void ()> Callback)77 void SetPreTranslucentCallback(std::function<void()> Callback) 78 { 79 mPreTranslucentCallback = Callback; 80 } 81 ApplyActiveSubmodelTransform(const lcMatrix44 & WorldMatrix)82 lcMatrix44 ApplyActiveSubmodelTransform(const lcMatrix44& WorldMatrix) const 83 { 84 return !mActiveSubmodelInstance ? WorldMatrix : lcMul(WorldMatrix, mActiveSubmodelTransform); 85 } 86 87 void Begin(const lcMatrix44& ViewMatrix); 88 void End(); 89 void AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State); 90 AddInterfaceObject(const lcObject * Object)91 void AddInterfaceObject(const lcObject* Object) 92 { 93 mInterfaceObjects.Add(Object); 94 } 95 96 void Draw(lcContext* Context) const; 97 void DrawInterfaceObjects(lcContext* Context) const; 98 99 protected: 100 void DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTypes, bool DrawFaded, bool DrawNonFaded) const; 101 void DrawTranslucentMeshes(lcContext* Context, bool DrawLit, bool DrawFadePrepass, bool DrawFaded, bool DrawNonFaded) const; 102 void DrawDebugNormals(lcContext* Context, const lcMesh* Mesh) const; 103 104 lcMatrix44 mViewMatrix; 105 lcMatrix44 mActiveSubmodelTransform; 106 lcPiece* mActiveSubmodelInstance; 107 lcShadingMode mShadingMode; 108 bool mDrawInterface; 109 bool mAllowLOD; 110 float mMeshLODDistance; 111 112 lcVector4 mFadeColor; 113 lcVector4 mHighlightColor; 114 bool mHasFadedParts; 115 bool mTranslucentFade; 116 117 std::function<void()> mPreTranslucentCallback; 118 lcArray<lcRenderMesh> mRenderMeshes; 119 lcArray<int> mOpaqueMeshes; 120 lcArray<lcTranslucentMeshInstance> mTranslucentMeshes; 121 lcArray<const lcObject*> mInterfaceObjects; 122 }; 123