diff --git a/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.cpp b/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.cpp index 61506ee28..7ba915a58 100644 --- a/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.cpp +++ b/Gems/ROS2/Code/Source/RobotImporter/ROS2RobotImporterEditorSystemComponent.cpp @@ -7,18 +7,20 @@ */ #include "ROS2RobotImporterEditorSystemComponent.h" -#include -#include -#include #include "RobotImporterWidget.h" -#include #include +#include #include #include +#include #include -#include +#include #include - +#include +#include +#include +#include +#include #include @@ -32,7 +34,16 @@ namespace ROS2 { if (auto serializeContext = azrtti_cast(context)) { - serializeContext->Class()->Version(0); + const auto& importerHookCamera = ROS2::SDFormat::ROS2SensorHooks::ROS2CameraSensor(); + const auto& importerHookGNSS = ROS2::SDFormat::ROS2SensorHooks::ROS2GNSSSensor(); + const auto& importerHookImu = ROS2::SDFormat::ROS2SensorHooks::ROS2ImuSensor(); + const auto& importerHookLidar = ROS2::SDFormat::ROS2SensorHooks::ROS2LidarSensor(); + serializeContext->Class()->Version(0)->Attribute( + "SensorImporterHooks", + AZStd::vector{ AZStd::move(importerHookCamera), + AZStd::move(importerHookGNSS), + AZStd::move(importerHookImu), + AZStd::move(importerHookLidar) }); } if (AZ::BehaviorContext* behaviorContext = azrtti_cast(context)) @@ -111,8 +122,7 @@ namespace ROS2 { const AZStd::string log = Utils::JoinSdfErrorsToString(parsedUrdfOutcome.GetSdfErrors()); - AZ_Warning("ROS2RobotImporterEditorSystemComponent", false, "URDF parsing failed with errors:\nRefer to %s", - log.c_str()); + AZ_Warning("ROS2RobotImporterEditorSystemComponent", false, "URDF parsing failed with errors:\nRefer to %s", log.c_str()); return false; } @@ -195,14 +205,12 @@ namespace ROS2 // Use the name of the first model tag in the SDF for the prefab // Otherwise use the name of the first world tag in the SDF AZStd::string prefabName; - if (const sdf::Model* model = parsedUrdfRoot.Model(); - model != nullptr) + if (const sdf::Model* model = parsedUrdfRoot.Model(); model != nullptr) { prefabName = AZStd::string(model->Name().c_str(), model->Name().size()) + ".prefab"; } - if (uint64_t urdfWorldCount = parsedUrdfRoot.WorldCount(); - prefabName.empty() && urdfWorldCount > 0) + if (uint64_t urdfWorldCount = parsedUrdfRoot.WorldCount(); prefabName.empty() && urdfWorldCount > 0) { const sdf::World* parsedUrdfWorld = parsedUrdfRoot.WorldByIndex(0); prefabName = AZStd::string(parsedUrdfWorld->Name().c_str(), parsedUrdfWorld->Name().size()) + ".prefab"; @@ -210,15 +218,19 @@ namespace ROS2 if (prefabName.empty()) { - AZ_Error("ROS2RobotImporterEditorSystemComponent", false, "URDF file converted to SDF %.*s contains no worlds." - " O3DE Prefab cannot be created", AZ_STRING_ARG(filePath)); + AZ_Error( + "ROS2RobotImporterEditorSystemComponent", + false, + "URDF file converted to SDF %.*s contains no worlds." + " O3DE Prefab cannot be created", + AZ_STRING_ARG(filePath)); return false; } - const AZ::IO::Path prefabPathRelative(AZ::IO::Path("Assets") / "Importer" / prefabName); const AZ::IO::Path prefabPath(AZ::IO::Path(AZ::Utils::GetProjectPath()) / prefabPathRelative); - AZStd::unique_ptr prefabMaker = AZStd::make_unique(filePath, &parsedUrdfRoot, prefabPath.String(), urdfAssetsMapping, useArticulation); + AZStd::unique_ptr prefabMaker = + AZStd::make_unique(filePath, &parsedUrdfRoot, prefabPath.String(), urdfAssetsMapping, useArticulation); auto prefabOutcome = prefabMaker->CreatePrefabFromURDF(); diff --git a/Gems/ROS2/Code/Source/RobotImporter/RobotImporterWidget.cpp b/Gems/ROS2/Code/Source/RobotImporter/RobotImporterWidget.cpp index d65980cff..59ee24c29 100644 --- a/Gems/ROS2/Code/Source/RobotImporter/RobotImporterWidget.cpp +++ b/Gems/ROS2/Code/Source/RobotImporter/RobotImporterWidget.cpp @@ -165,7 +165,7 @@ namespace ROS2 { report += " - " + QString::fromUtf8(modifiedTag.data(), static_cast(modifiedTag.size())) + "\n"; } - report += "\n# "+tr("The modified URDF code:") + "\n"; + report += "\n# " + tr("The modified URDF code:") + "\n"; report += "```\n" + QString::fromStdString(parsedUrdfOutcome.m_modifiedURDFContent) + "```\n"; } else diff --git a/Gems/ROS2/Code/Source/RobotImporter/URDF/SensorsMaker.cpp b/Gems/ROS2/Code/Source/RobotImporter/URDF/SensorsMaker.cpp index 1eff65f77..b0f610a56 100644 --- a/Gems/ROS2/Code/Source/RobotImporter/URDF/SensorsMaker.cpp +++ b/Gems/ROS2/Code/Source/RobotImporter/URDF/SensorsMaker.cpp @@ -9,6 +9,7 @@ #include "SensorsMaker.h" #include +#include #include #include @@ -25,22 +26,25 @@ namespace ROS2 serializeContext->EnumerateAll( [&](const AZ::SerializeContext::ClassData* classData, const AZ::Uuid& typeId) -> bool { - auto* attribute = AZ::FindAttribute(AZ::Crc32("SDFormatSensorImporter"), classData->m_attributes); + auto* attribute = AZ::FindAttribute(AZ::Crc32("SensorImporterHooks"), classData->m_attributes); if (attribute == nullptr) { return true; } AZ::AttributeReader reader(nullptr, attribute); - SDFormat::SensorImporterHook sensorHook; - if (reader.Read(sensorHook)) + AZStd::vector sensorHooks; + if (reader.Read>(sensorHooks)) { - for (const auto& t : sensorHook.m_sensorTypes) + for (const auto& hook : sensorHooks) { - if (sensor->Type() == t) + for (const auto& t : hook.m_sensorTypes) { - sensorHook.m_sdfSensorToComponentCallback(*entity, *sensor); - return false; + if (sensor->Type() == t) + { + hook.m_sdfSensorToComponentCallback(*entity, *sensor); + return false; + } } } }