ROS2CameraSystemComponent.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "ROS2CameraSystemComponent.h"
  9. #include <Atom/RPI.Public/Pass/PassSystemInterface.h>
  10. namespace ROS2
  11. {
  12. void ROS2SystemCameraComponent::Reflect(AZ::ReflectContext* context)
  13. {
  14. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  15. {
  16. serialize->Class<ROS2SystemCameraComponent, AZ::Component>()->Version(0);
  17. if (AZ::EditContext* ec = serialize->GetEditContext())
  18. {
  19. ec->Class<ROS2SystemCameraComponent>("ROS 2 System Camera Component", "This system component is responsible for setting a pass template for simulation of camera sensors.")
  20. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  21. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("System"))
  22. ->Attribute(AZ::Edit::Attributes::Category, "ROS2")
  23. ->Attribute(AZ::Edit::Attributes::AutoExpand, true);
  24. }
  25. }
  26. }
  27. void ROS2SystemCameraComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  28. {
  29. provided.push_back(AZ_CRC_CE("ROS2CameraSystemService"));
  30. }
  31. void ROS2SystemCameraComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  32. {
  33. incompatible.push_back(AZ_CRC_CE("ROS2CameraSystemService"));
  34. }
  35. void ROS2SystemCameraComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  36. {
  37. required.push_back(AZ_CRC_CE("ROS2Service"));
  38. required.push_back(AZ_CRC_CE("RPISystem"));
  39. }
  40. void ROS2SystemCameraComponent::InitPassTemplateMappingsHandler()
  41. {
  42. auto* passSystem = AZ::RPI::PassSystemInterface::Get();
  43. AZ_Assert(passSystem, "Cannot get the pass system.");
  44. m_loadTemplatesHandler = AZ::RPI::PassSystemInterface::OnReadyLoadTemplatesEvent::Handler(
  45. [this]()
  46. {
  47. this->LoadPassTemplateMappings();
  48. });
  49. passSystem->ConnectEvent(m_loadTemplatesHandler);
  50. }
  51. void ROS2SystemCameraComponent::Activate()
  52. {
  53. AZ::ApplicationTypeQuery appType;
  54. AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Events::QueryApplicationType, appType);
  55. if (appType.IsGame() || appType.IsEditor())
  56. {
  57. InitPassTemplateMappingsHandler();
  58. }
  59. }
  60. void ROS2SystemCameraComponent::Deactivate()
  61. {
  62. m_loadTemplatesHandler.Disconnect();
  63. }
  64. void ROS2SystemCameraComponent::LoadPassTemplateMappings()
  65. {
  66. AZ_Printf("ROS2SystemCameraComponent", "LoadPassTemplateMappings\n");
  67. auto* passSystem = AZ::RPI::PassSystemInterface::Get();
  68. AZ_Assert(passSystem, "PassSystemInterface is null");
  69. const char* passTemplatesFile = "Passes/ROSPassTemplates.azasset";
  70. [[maybe_unused]] const bool isOk = passSystem->LoadPassTemplateMappings(passTemplatesFile);
  71. AZ_Assert(isOk, "LoadPassTemplateMappings return false ");
  72. }
  73. } // namespace ROS2