EditorMeshBlockerComponent.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "EditorMeshBlockerComponent.h"
  9. #include <AzCore/Serialization/Utils.h>
  10. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  11. #include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
  12. #include <LmbrCentral/Dependency/DependencyNotificationBus.h>
  13. namespace Vegetation
  14. {
  15. void EditorMeshBlockerComponent::Reflect(AZ::ReflectContext* context)
  16. {
  17. BaseClassType::Reflect(context);
  18. AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
  19. if (serialize)
  20. {
  21. serialize->Class<EditorMeshBlockerComponent, BaseClassType>()
  22. ->Version(2, &EditorAreaComponentBaseVersionConverter<typename BaseClassType::WrappedComponentType, typename BaseClassType::WrappedConfigType>)
  23. ->Field("DrawDebugBounds", &EditorMeshBlockerComponent::m_drawDebugBounds)
  24. ;
  25. AZ::EditContext* edit = serialize->GetEditContext();
  26. if (edit)
  27. {
  28. edit->Class<EditorMeshBlockerComponent>(
  29. s_componentName, s_componentDescription)
  30. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  31. ->Attribute(AZ::Edit::Attributes::Icon, s_icon)
  32. ->Attribute(AZ::Edit::Attributes::ViewportIcon, s_viewportIcon)
  33. ->Attribute(AZ::Edit::Attributes::HelpPageURL, s_helpUrl)
  34. ->Attribute(AZ::Edit::Attributes::Category, s_categoryName)
  35. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
  36. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  37. ->DataElement(AZ::Edit::UIHandlers::CheckBox, &EditorMeshBlockerComponent::m_drawDebugBounds, "Draw Debug Bounds", "Show the settings to debug the mesh blocker")
  38. ;
  39. }
  40. }
  41. }
  42. void EditorMeshBlockerComponent::Activate()
  43. {
  44. BaseClassType::Activate();
  45. AzFramework::EntityDebugDisplayEventBus::Handler::BusConnect(GetEntityId());
  46. }
  47. void EditorMeshBlockerComponent::Deactivate()
  48. {
  49. BaseClassType::Deactivate();
  50. AzFramework::EntityDebugDisplayEventBus::Handler::BusDisconnect();
  51. }
  52. void EditorMeshBlockerComponent::DisplayEntityViewport([[maybe_unused]] const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay)
  53. {
  54. if (!m_drawDebugBounds)
  55. {
  56. return;
  57. }
  58. // draw outline of complete mesh bounds
  59. if (m_component.m_meshBounds.IsValid())
  60. {
  61. debugDisplay.SetColor(AZ::Vector4(0.8f, 0.45f, 0.2f, 0.5f));
  62. debugDisplay.DrawWireBox(
  63. m_component.m_meshBounds.GetMin(),
  64. m_component.m_meshBounds.GetMax());
  65. }
  66. // draw filled box for bounds where intersections can occur
  67. if (m_component.m_meshBoundsForIntersection.IsValid())
  68. {
  69. debugDisplay.SetColor(AZ::Vector4(1.0f, 0.45f, 0.2f, 0.3f));
  70. debugDisplay.DrawSolidBox(
  71. m_component.m_meshBoundsForIntersection.GetMin(),
  72. m_component.m_meshBoundsForIntersection.GetMax());
  73. }
  74. }
  75. }