ImportContextProvider.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "ImportContexts.h"
  10. #include <AzCore/RTTI/RTTI.h>
  11. #include <AzCore/std/smart_ptr/shared_ptr.h>
  12. #include <AzCore/std/string/string.h>
  13. #include <SceneAPI/SDKWrapper/NodeWrapper.h>
  14. #include <SceneAPI/SceneBuilder/SceneSystem.h>
  15. #include <SceneAPI/SceneCore/Containers/SceneGraph.h>
  16. namespace AZ::SDKScene
  17. {
  18. class SceneWrapperBase;
  19. }
  20. namespace AZ::SDKNode
  21. {
  22. class NodeWrapper;
  23. }
  24. namespace AZ
  25. {
  26. namespace SceneAPI
  27. {
  28. namespace Containers
  29. {
  30. class Scene;
  31. }
  32. namespace SceneBuilder
  33. {
  34. class RenamedNodesMap;
  35. struct NodeEncounteredContext;
  36. struct SceneDataPopulatedContextBase;
  37. struct SceneNodeAppendedContextBase;
  38. struct SceneAttributeDataPopulatedContextBase;
  39. struct SceneAttributeNodeAppendedContextBase;
  40. struct SceneNodeAddedAttributesContextBase;
  41. struct SceneNodeFinalizeContextBase;
  42. struct FinalizeSceneContextBase;
  43. //! @brief Abstract Factory Pattern interface for scene import context providers.
  44. //!
  45. //! The ImportContextProvider allows different scene import libraries to be integrated as Gems
  46. //! by providing a standard interface for creating scene wrapper, import contexts (@see ImportContexts.h) and handling
  47. //! file extensions. This enables the Scene API pipeline to work with multiple import libraries
  48. //! while maintaining a consistent interface.
  49. //!
  50. //! Key responsibilities:
  51. //! - Provides factory methods for creating a family of related import contexts @see ImportContexts.h and a SceneWrapper
  52. //! - Provides the list of handled file extensions
  53. //! - Offers abstraction layer between SceneAPI and import library implementations
  54. //!
  55. //! @par Usage
  56. //! Implement this interface in your custom import library Gem and register with:
  57. //! @code{.cpp}
  58. //! if (auto* registry = AZ::SceneAPI::SceneBuilder::ImportContextRegistryInterface::Get())
  59. //! {
  60. //! // Create and register the new Context Provider
  61. //! auto contextProvider = aznew AZ::SceneAPI::SceneBuilder::AwesomeLibImportContextProvider();
  62. //! registry->RegisterContextProvider(contextProvider);
  63. //! AZ_Printf("AwesomeLibImporter", "Awesome Lib import context provider registered.\n");
  64. //! }
  65. //! @endcode
  66. //!
  67. //! @note Ensure your Component inherits from SceneCore::SceneSystemComponent.
  68. //! This is a different hierarchy than regular SystemComponents.
  69. //!
  70. //! @see AssImpImportContextProvider.h for reference implementation.
  71. struct ImportContextProvider
  72. {
  73. AZ_RTTI(ImportContextProvider, "{5df22f6c-8a43-417d-b735-9d9d7d069efc}");
  74. virtual ~ImportContextProvider() = default;
  75. virtual AZStd::shared_ptr<NodeEncounteredContext> CreateNodeEncounteredContext(
  76. Containers::Scene& scene,
  77. Containers::SceneGraph::NodeIndex currentGraphPosition,
  78. const SceneSystem& sourceSceneSystem,
  79. RenamedNodesMap& nodeNameMap,
  80. SDKScene::SceneWrapperBase& sourceScene,
  81. AZ::SDKNode::NodeWrapper& sourceNode) = 0;
  82. virtual AZStd::shared_ptr<SceneDataPopulatedContextBase> CreateSceneDataPopulatedContext(
  83. NodeEncounteredContext& parent,
  84. AZStd::shared_ptr<DataTypes::IGraphObject> graphData,
  85. const AZStd::string& dataName) = 0;
  86. virtual AZStd::shared_ptr<SceneNodeAppendedContextBase> CreateSceneNodeAppendedContext(
  87. SceneDataPopulatedContextBase& parent, Containers::SceneGraph::NodeIndex newIndex) = 0;
  88. virtual AZStd::shared_ptr<SceneAttributeDataPopulatedContextBase> CreateSceneAttributeDataPopulatedContext(
  89. SceneNodeAppendedContextBase& parent,
  90. AZStd::shared_ptr<DataTypes::IGraphObject> nodeData,
  91. const Containers::SceneGraph::NodeIndex attributeNodeIndex,
  92. const AZStd::string& dataName) = 0;
  93. virtual AZStd::shared_ptr<SceneAttributeNodeAppendedContextBase> CreateSceneAttributeNodeAppendedContext(
  94. SceneAttributeDataPopulatedContextBase& parent, Containers::SceneGraph::NodeIndex newIndex) = 0;
  95. virtual AZStd::shared_ptr<SceneNodeAddedAttributesContextBase> CreateSceneNodeAddedAttributesContext(
  96. SceneNodeAppendedContextBase& parent) = 0;
  97. virtual AZStd::shared_ptr<SceneNodeFinalizeContextBase> CreateSceneNodeFinalizeContext(
  98. SceneNodeAddedAttributesContextBase& parent) = 0;
  99. virtual AZStd::shared_ptr<FinalizeSceneContextBase> CreateFinalizeSceneContext(
  100. Containers::Scene& scene,
  101. const SceneSystem& sourceSceneSystem,
  102. SDKScene::SceneWrapperBase& sourceScene,
  103. RenamedNodesMap& nodeNameMap) = 0;
  104. //! Creates an instance of the scene wrapper
  105. virtual AZStd::unique_ptr<SDKScene::SceneWrapperBase> CreateSceneWrapper() const = 0;
  106. //! Checks if this provider can handle the given file extension
  107. virtual bool CanHandleExtension(AZStd::string_view fileExtension) const = 0;
  108. //! Get a descriptive name for Context Provider
  109. virtual AZStd::string GetImporterName() const { return "Unknown Importer"; }
  110. };
  111. } // namespace SceneBuilder
  112. } // namespace SceneAPI
  113. } // namespace AZ