BsSceneGrid.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsVector3.h"
  4. #include "BsColor.h"
  5. #include "BsMaterial.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Handles rendering of the grid in the scene view.
  10. */
  11. class SceneGrid
  12. {
  13. public:
  14. SceneGrid();
  15. /**
  16. * @brief Sets the grid origin in world coordinates.
  17. */
  18. void setOrigin(const Vector3& origin);
  19. /**
  20. * @brief Sets the total width/height of the grid in XZ plane.
  21. */
  22. void setSize(UINT32 size);
  23. /**
  24. * @brief Sets the spacing between grid lines.
  25. */
  26. void setSpacing(float spacing);
  27. /**
  28. * @brief Changes the active editor settings. Grid properties
  29. * will be updated internally when editor settings change.
  30. */
  31. void setSettings(const EditorSettingsPtr& settings);
  32. /**
  33. * @brief Triggered by the renderer when rendering the specified camera.
  34. *
  35. * @param camera Camera about to be rendered.
  36. * @param drawList Draw list we can use to queue our render commands in.
  37. *
  38. * @note Internal method.
  39. */
  40. void _render(const CameraHandlerPtr& camera, DrawList& drawList);
  41. /**
  42. * @brief Called once per frame.
  43. *
  44. * @note Internal method.
  45. */
  46. void update();
  47. private:
  48. /**
  49. * @brief Rebuilds the scene grid mesh. Call this whenever grid parameters change.
  50. */
  51. void updateGridMesh();
  52. /**
  53. * @brief Updates internal grid parameters from the attached settings object.
  54. */
  55. void updateFromEditorSettings();
  56. HMesh mGridMesh;
  57. HMaterial mGridMaterial;
  58. MaterialParamMat4 mViewProjParam;
  59. MaterialParamVec4 mWorldCameraPosParam;
  60. MaterialParamColor mGridColorParam;
  61. MaterialParamFloat mGridSpacingParam;
  62. MaterialParamFloat mGridBorderWidthParam;
  63. MaterialParamFloat mGridFadeOutStartParam;
  64. MaterialParamFloat mGridFadeOutEndParam;
  65. VertexDataDescPtr mVertexDesc;
  66. EditorSettingsPtr mSettings;
  67. UINT32 mSettingsHash = 0;
  68. Vector3 mOrigin;
  69. float mSpacing = 1.0f;
  70. UINT32 mSize = 256;
  71. UINT32 mMajorAxisSpacing = 10;
  72. UINT32 mAxisMarkerSpacing = 25;
  73. static const Color GRID_LINE_COLOR;
  74. static const float LINE_WIDTH;
  75. static const float LINE_BORDER_WIDTH;
  76. static const float MAJOR_AXIS_WIDTH;
  77. static const float MAJOR_AXIS_BORDER_WIDTH;
  78. static const float AXIS_MARKER_WIDTH;
  79. static const float AXIS_MARKER_BORDER_WIDTH;
  80. static const Color AXIS_X_MARKER_COLOR;
  81. static const Color AXIS_Z_MARKER_COLOR;
  82. static const float FADE_OUT_START;
  83. static const float FADE_OUT_END;
  84. };
  85. }