BehaviorsImportGroup.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <AzCore/Serialization/SerializeContext.h>
  9. #include <AzCore/std/smart_ptr/make_shared.h>
  10. #include <SceneAPI/SceneCore/Containers/Scene.h>
  11. #include <SceneAPI/SceneCore/Containers/SceneGraph.h>
  12. #include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
  13. #include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.h>
  14. #include <SceneAPI/SceneCore/Containers/Views/PairIterator.h>
  15. #include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
  16. #include <SceneAPI/SceneCore/Containers/Views/SceneGraphChildIterator.h>
  17. #include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.h>
  18. #include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
  19. #include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
  20. #include <SceneAPI/SceneData/Groups/ImportGroup.h>
  21. #include <SceneAPI/SceneData/Behaviors/ImportGroup.h>
  22. namespace AZ::SceneAPI::Behaviors
  23. {
  24. // This is set to an extremely low number to help ensure that it appears first in the list of tabs
  25. // in the FBX Settings panel. Since these settings are applied before any of the other settings, they
  26. // seem like the first ones that the user should be presented with.
  27. const int ImportGroup::s_importGroupPreferredTabOrder = -1000000;
  28. void ImportGroup::Activate()
  29. {
  30. Events::ManifestMetaInfoBus::Handler::BusConnect();
  31. Events::AssetImportRequestBus::Handler::BusConnect();
  32. }
  33. void ImportGroup::Deactivate()
  34. {
  35. Events::AssetImportRequestBus::Handler::BusDisconnect();
  36. Events::ManifestMetaInfoBus::Handler::BusDisconnect();
  37. }
  38. void ImportGroup::Reflect(ReflectContext* context)
  39. {
  40. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  41. if (serializeContext)
  42. {
  43. serializeContext->Class<ImportGroup, BehaviorComponent>()->Version(1);
  44. }
  45. }
  46. void ImportGroup::GetCategoryAssignments(
  47. [[maybe_unused]] CategoryRegistrationList& categories, [[maybe_unused]] const Containers::Scene& scene)
  48. {
  49. // The Import Group settings can be made visible and editable in the Asset Browser Inspector by uncommenting
  50. // the following line. However, it is currently disabled because changing the settings causes things to break.
  51. // Specifically, in the Mesh Group and the PhysX Group, the settings rely on a list of selected and unselected
  52. // nodes. Changing the Import optimizations settings will change what nodes exist in the scene, so those lists
  53. // will no longer be valid and need to be reset. Also, the various UX widgets for those groups builds up lists
  54. // of nodes to populate the dropdown lists with. Those will all need to get refreshed. Finally, if Proc Prefabs
  55. // are enabled, the set of mesh groups to export for the Proc Prefab will also need to change to match the new
  56. // list of meshes.
  57. //categories.emplace_back("Import", SceneData::ImportGroup::TYPEINFO_Uuid(), s_importGroupPreferredTabOrder);
  58. }
  59. void ImportGroup::InitializeObject(
  60. [[maybe_unused]] const Containers::Scene& scene, [[maybe_unused]] DataTypes::IManifestObject& target)
  61. {
  62. if (!target.RTTI_IsTypeOf(SceneData::ImportGroup::TYPEINFO_Uuid()))
  63. {
  64. return;
  65. }
  66. }
  67. Events::ProcessingResult ImportGroup::UpdateManifest(
  68. Containers::Scene& scene, [[maybe_unused]] ManifestAction action,
  69. [[maybe_unused]] RequestingApplication requester)
  70. {
  71. // ignore empty scenes (i.e. only has the root node)
  72. if (scene.GetGraph().GetNodeCount() == 1)
  73. {
  74. return Events::ProcessingResult::Ignored;
  75. }
  76. // If there's already an ImportGroup in the manifest, leave it there and return.
  77. size_t count = scene.GetManifest().GetEntryCount();
  78. for (size_t index = 0; index < count; index++)
  79. {
  80. if (auto* importGroup = azrtti_cast<DataTypes::IImportGroup*>(scene.GetManifest().GetValue(index).get()); importGroup)
  81. {
  82. return Events::ProcessingResult::Success;
  83. }
  84. }
  85. // There's no ImportGroup yet, so add one.
  86. auto importGroup = AZStd::make_shared<SceneData::ImportGroup>();
  87. scene.GetManifest().AddEntry(importGroup);
  88. return Events::ProcessingResult::Success;
  89. }
  90. } // namespace AZ::SceneAPI::Behaviors