BoundsTestComponent.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #pragma once
  9. #include <AzFramework/Render/GeometryIntersectionBus.h>
  10. #include <AzFramework/Visibility/BoundsBus.h>
  11. #include <AzToolsFramework/API/ComponentEntitySelectionBus.h>
  12. #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  13. namespace UnitTest
  14. {
  15. //! Basic component that implements BoundsRequestBus and EditorComponentSelectionRequestsBus to be compatible
  16. //! with the Editor visibility system.
  17. //! Note: Used for simulating selection (picking) in the viewport.
  18. class BoundsTestComponent
  19. : public AzToolsFramework::Components::EditorComponentBase
  20. , public AzFramework::BoundsRequestBus::Handler
  21. , public AzToolsFramework::EditorComponentSelectionRequestsBus::Handler
  22. {
  23. public:
  24. AZ_EDITOR_COMPONENT(
  25. BoundsTestComponent, "{E6312E9D-8489-4677-9980-C93C328BC92C}", AzToolsFramework::Components::EditorComponentBase);
  26. static void Reflect(AZ::ReflectContext* context);
  27. // AZ::Component overrides ...
  28. void Activate() override;
  29. void Deactivate() override;
  30. // EditorComponentSelectionRequestsBus overrides ...
  31. AZ::Aabb GetEditorSelectionBoundsViewport(const AzFramework::ViewportInfo& viewportInfo) override;
  32. bool EditorSelectionIntersectRayViewport(
  33. const AzFramework::ViewportInfo& viewportInfo, const AZ::Vector3& src, const AZ::Vector3& dir, float& distance) override;
  34. bool SupportsEditorRayIntersect() override;
  35. // BoundsRequestBus overrides ...
  36. AZ::Aabb GetWorldBounds() const override;
  37. AZ::Aabb GetLocalBounds() const override;
  38. AZ::Aabb m_localBounds; //!< Local bounds that can be modified for certain tests (defaults to unit cube).
  39. };
  40. class RenderGeometryIntersectionTestComponent
  41. : public BoundsTestComponent
  42. , public AzFramework::RenderGeometry::IntersectionRequestBus::Handler
  43. {
  44. public:
  45. AZ_EDITOR_COMPONENT(RenderGeometryIntersectionTestComponent, "{6F46B5BF-60DF-4BDD-9BA7-9658E85B99C2}", BoundsTestComponent);
  46. static void Reflect(AZ::ReflectContext* context);
  47. // AZ::Component overrides ...
  48. void Activate() override;
  49. void Deactivate() override;
  50. // IntersectionRequestBus overrides ...
  51. AzFramework::RenderGeometry::RayResult RenderGeometryIntersect(const AzFramework::RenderGeometry::RayRequest& ray) const override;
  52. };
  53. } // namespace UnitTest