3
0

WhiteBoxEditorDrawUtil.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "Util/WhiteBoxEditorDrawUtil.h"
  9. #include "ViewportSelection/EditorSelectionUtil.h"
  10. #include "WhiteBox/WhiteBoxToolApi.h"
  11. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  12. #include <Viewport/WhiteBoxViewportConstants.h>
  13. namespace WhiteBox
  14. {
  15. void DrawFace(
  16. AzFramework::DebugDisplayRequests& debugDisplay, WhiteBoxMesh* mesh, const Api::PolygonHandle& polygon, const AZ::Color& color)
  17. {
  18. AZStd::vector<AZ::Vector3> triangles = Api::PolygonFacesPositions(*mesh, polygon);
  19. const AZ::Vector3 normal = Api::PolygonNormal(*mesh, polygon);
  20. if (!triangles.empty())
  21. {
  22. // draw selected polygon
  23. debugDisplay.PushMatrix(AZ::Transform::CreateTranslation(normal * ed_whiteBoxPolygonViewOverlapOffset));
  24. debugDisplay.SetColor(color);
  25. debugDisplay.DrawTriangles(triangles, color);
  26. debugDisplay.PopMatrix();
  27. }
  28. }
  29. void DrawOutline(
  30. AzFramework::DebugDisplayRequests& debugDisplay, WhiteBoxMesh* mesh, const Api::PolygonHandle& polygon, const AZ::Color& color)
  31. {
  32. Api::VertexPositionsCollection outlines = Api::PolygonBorderVertexPositions(*mesh, polygon);
  33. if (!outlines.empty())
  34. {
  35. // draw outline
  36. debugDisplay.SetColor(color);
  37. debugDisplay.SetLineWidth(cl_whiteBoxEdgeVisualWidth);
  38. for (const auto& outline : outlines)
  39. {
  40. debugDisplay.DrawPolyLine(outline.data(), aznumeric_caster(outline.size()));
  41. }
  42. }
  43. }
  44. void DrawEdge(AzFramework::DebugDisplayRequests& debugDisplay, WhiteBoxMesh* mesh, const Api::EdgeHandle& edge, const AZ::Color& color)
  45. {
  46. auto vertexEdgePosition = Api::EdgeVertexPositions(*mesh, edge);
  47. debugDisplay.SetColor(color);
  48. debugDisplay.SetLineWidth(cl_whiteBoxEdgeVisualWidth);
  49. debugDisplay.DrawLine(vertexEdgePosition[0], vertexEdgePosition[1]);
  50. }
  51. void DrawPoints(
  52. AzFramework::DebugDisplayRequests& debugDisplay,
  53. WhiteBoxMesh* mesh,
  54. const AZ::Transform& worldFromLocal,
  55. const AzFramework::ViewportInfo& viewportInfo,
  56. const AZStd::span<Api::VertexHandle>& verts,
  57. const AZ::Color& color)
  58. {
  59. debugDisplay.SetColor(color);
  60. for (auto& vert : verts)
  61. {
  62. const auto vertPos = Api::VertexPosition(*mesh, vert);
  63. const AzFramework::CameraState cameraState = AzToolsFramework::GetCameraState(viewportInfo.m_viewportId);
  64. const float radius =
  65. cl_whiteBoxVertexManipulatorSize * AzToolsFramework::CalculateScreenToWorldMultiplier(worldFromLocal.TransformPoint(vertPos), cameraState);
  66. debugDisplay.DrawBall(vertPos, radius);
  67. }
  68. }
  69. } // namespace WhiteBox