ManifestMetaInfoBus.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. /*
  3. * Copyright (c) Contributors to the Open 3D Engine Project.
  4. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. #include <limits>
  10. #include <AzCore/EBus/EBus.h>
  11. #include <AzCore/Math/Uuid.h>
  12. #include <AzCore/std/string/string.h>
  13. #include <AzCore/std/smart_ptr/shared_ptr.h>
  14. #include <AzCore/std/containers/vector.h>
  15. #include <SceneAPI/SceneCore/SceneCoreConfiguration.h>
  16. namespace AZ
  17. {
  18. namespace SceneAPI
  19. {
  20. namespace Containers
  21. {
  22. class Scene;
  23. }
  24. namespace DataTypes
  25. {
  26. class IManifestObject;
  27. }
  28. namespace Events
  29. {
  30. class SCENE_CORE_API ManifestMetaInfo
  31. : public AZ::EBusTraits
  32. {
  33. public:
  34. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
  35. struct CategoryRegistration
  36. {
  37. AZStd::string m_categoryName;
  38. AZ::Uuid m_categoryTargetGroupId;
  39. int m_preferredOrder;
  40. CategoryRegistration(const char* categoryName, const AZ::Uuid& categoryTargetId, int preferredOrder = std::numeric_limits<int>::max())
  41. : m_categoryName(categoryName)
  42. , m_categoryTargetGroupId(categoryTargetId)
  43. , m_preferredOrder(preferredOrder)
  44. {
  45. }
  46. };
  47. using CategoryRegistrationList = AZStd::vector<CategoryRegistration>;
  48. using ModifiersList = AZStd::vector<AZ::Uuid>;
  49. ManifestMetaInfo();
  50. virtual ~ManifestMetaInfo() = 0;
  51. //! Gets a list of all the categories and the class identifiers that are listed for that category.
  52. virtual void GetCategoryAssignments(CategoryRegistrationList& categories, const Containers::Scene& scene);
  53. //! Gets the path to the icon associated with the given object.
  54. virtual void GetIconPath(AZStd::string& iconPath, const DataTypes::IManifestObject& target);
  55. //! Gets a list of a the modifiers (such as rules for groups) that the target accepts.
  56. //! Note that updates to the target may change what modifiers can be accepted. For instance
  57. //! if a group only accepts a single rule of a particular type, calling this function a second time
  58. //! will not include the uuid of that rule.
  59. //! This method is called when the "Add Modifier" button is pressed in the FBX Settings Editor.
  60. virtual void GetAvailableModifiers(ModifiersList& modifiers, const Containers::Scene& scene,
  61. const DataTypes::IManifestObject& target);
  62. //! Initialized the given manifest object based on the scene. Depending on what other entries have been added
  63. //! to the manifest, an implementation of this function may decided that certain values should or shouldn't
  64. //! be added, such as not adding meshes to a group that already belong to another group.
  65. //! This method is always called each time a Group type of object is created in memory (e.g. When the user
  66. //! clicks the "Add another Mesh" or "Add another Actor" in the FBX Settings Editor). Overriders of this method
  67. //! should check the type of the \p target to decide to take action (e.g. add a Modifier) or do nothing.
  68. virtual void InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target);
  69. //! Called when an existing object is updated. This is not called when an object is initialized, which is handled,
  70. //! by InitializeObject, but a parent may still get the update. For instance adding or removing a rule will
  71. //! have this called for the parent group.
  72. //! @param scene The scene the object belongs to.
  73. //! @param target The object that's being updated. If this is null it refers to an update to the entire manifest, for
  74. //! when a group is deleted for instance.
  75. //! @param sender An optional argument to keep track of the object that called this function. This can be used if the
  76. //! same object that sends a message also handles the callback to avoid recursively updating.
  77. virtual void ObjectUpdated(const Containers::Scene& scene, const DataTypes::IManifestObject* target, void* sender = nullptr);
  78. //! Manifest management is two phases: The UI for editing scene settings tends to work in the manifest objects directly,
  79. //! updating the actual scene. If the scene is directly edited as a response to InitializeObject or ObjectUpdated
  80. //! (with the scene made non-const), then the UI won't actually refresh, because it's operating on stale data.
  81. //! The intended flow here is, if a listener on this bus wants to add aditional objects to the scene manifest in the UI:
  82. //! 1) Listen to the InitializeObject or ObjectUpdated command. 2) Create the vector of new manifest objects that should
  83. //! be created in response to that command. 3) Emit this message, so the UI can respond and update/add those objects.
  84. //! This shouldn't be called during asset processing, it won't be as functional.
  85. virtual void AddObjects([[maybe_unused]] AZStd::vector<AZStd::shared_ptr<DataTypes::IManifestObject>>& objects) {}
  86. };
  87. inline ManifestMetaInfo::~ManifestMetaInfo() = default;
  88. using ManifestMetaInfoBus = AZ::EBus<ManifestMetaInfo>;
  89. } // namespace Events
  90. } // namespace SceneAPI
  91. } // namespace AZ