| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsEditorPrerequisites.h"
- #include "Renderer/BsRendererExtension.h"
- #include "Math/BsVector2I.h"
- #include "Image/BsColor.h"
- #include "Material/BsMaterial.h"
- namespace bs
- {
- /** @addtogroup Scene-Editor-Internal
- * @{
- */
- namespace ct { class SceneGridRenderer; }
- /** Determines how is the scene grid drawn. */
- enum class GridMode
- {
- Perspective, /**< Grid is drawn in XZ plane, at Y = 0. */
- OrthoX, /**< Grid is drawn in YZ plane, always visible along positive X. */
- OrthoY, /**< Grid is drawn in XZ plane, always visible along positive Y. */
- OrthoZ, /**< Grid is drawn in XY plane, always visible along positive Z. */
- OrthoNegX, /**< Grid is drawn in YZ plane, always visible along negative X. */
- OrthoNegY, /**< Grid is drawn in XZ plane, always visible along negative Y. */
- OrthoNegZ /**< Grid is drawn in XY plane, always visible along negative Z. */
- };
- /** Handles rendering of the grid in the scene view. */
- class BS_ED_EXPORT SceneGrid
- {
- public:
- SceneGrid(const SPtr<Camera>& camera);
- ~SceneGrid();
- /** Sets the total width/height of the grid in XZ plane. */
- void setSize(UINT32 size);
-
- /** Sets the spacing between grid lines. */
- void setSpacing(float spacing);
- /** Determines in what position and orientation is the grid drawn. */
- void setMode(GridMode mode);
- /** Changes the active editor settings. Grid properties will be updated internally when editor settings change. */
- void setSettings(const SPtr<EditorSettings>& settings);
- /** Called once per frame. */
- void _update();
- private:
- /** Updates internal grid parameters from the attached settings object. */
- void updateFromEditorSettings();
- /** Rebuilds the scene grid mesh. Call this whenever grid parameters change. */
- void updateGridMesh();
- float mSpacing = 1.0f;
- UINT32 mSize = 256;
- GridMode mMode = GridMode::Perspective;
- bool mCoreDirty;
- SPtr<EditorSettings> mSettings;
- UINT32 mSettingsHash = 0;
- HMesh mGridMesh;
- SPtr<VertexDataDesc> mVertexDesc;
- SPtr<ct::SceneGridRenderer> mRenderer;
- };
- namespace ct
- {
- /** Handles scene grid rendering on the core thread. */
- class SceneGridRenderer : public RendererExtension
- {
- public:
- /** Structure used for initializing the renderer. */
- struct InitData
- {
- SPtr<Camera> camera;
- SPtr<Material> material;
- };
- SceneGridRenderer();
- private:
- friend class bs::SceneGrid;
- /** @copydoc RendererExtension::initialize */
- void initialize(const Any& data) override;
- /** @copydoc RendererExtension::check */
- RendererExtensionRequest check(const Camera& camera) override;
- /** @copydoc RendererExtension::render */
- void render(const Camera& camera, const RendererViewContext& viewContext) override;
- /**
- * Updates the grid mesh to render.
- *
- * @param[in] mesh Grid mesh to render.
- * @param[in] spacing Spacing between the grid lines.
- * @param[in] fadeGrid Determines should the grid fade out at larger distances.
- * @param[in] gridPlaneNormal Normal to the plane to render the grid on. Must be one of the basis vectors
- * (can't be arbitrary).
- */
- void updateData(const SPtr<Mesh>& mesh, float spacing, bool fadeGrid, const Vector3& gridPlaneNormal);
- SPtr<Camera> mCamera;
- SPtr<Mesh> mGridMesh;
- SPtr<Material> mGridMaterial;
- SPtr<GpuParamsSet> mMaterialParams;
- float mSpacing = 1.0f;
- bool mFadeGrid = true;
- Vector3 mGridPlaneNormal = Vector3::ZERO;
- MaterialParamMat4 mViewProjParam;
- MaterialParamVec4 mWorldCameraPosParam;
- MaterialParamColor mGridColorParam;
- MaterialParamFloat mGridSpacingParam;
- MaterialParamFloat mGridBorderWidthParam;
- MaterialParamFloat mGridFadeOutStartParam;
- MaterialParamFloat mGridFadeOutEndParam;
- MaterialParamVec3 mGridPlaneNormalParam;
- static const Color GRID_LINE_COLOR;
- static const float LINE_WIDTH;
- static const float LINE_BORDER_WIDTH;
- static const float FADE_OUT_START;
- static const float FADE_OUT_END;
- };
- }
- /** @} */
- }
|