SceneGraphUtilities.inl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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/std/algorithm.h>
  9. #include <AzCore/std/typetraits/is_base_of.h>
  10. #include <SceneAPI/SceneCore/Containers/Scene.h>
  11. #include <SceneAPI/SceneCore/Containers/SceneGraph.h>
  12. #include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
  13. #include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
  14. #include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
  15. namespace AZ
  16. {
  17. namespace SceneAPI
  18. {
  19. namespace Utilities
  20. {
  21. template<typename T>
  22. bool DoesSceneGraphContainDataLike(const Containers::Scene& scene, bool checkVirtualTypes)
  23. {
  24. static_assert(AZStd::is_base_of<DataTypes::IGraphObject, T>::value, "Specified type T is not derived from IGraphObject.");
  25. const Containers::SceneGraph& graph = scene.GetGraph();
  26. if (checkVirtualTypes)
  27. {
  28. auto contentStorage = graph.GetContentStorage();
  29. auto view = Containers::Views::MakeFilterView(contentStorage, Containers::DerivedTypeFilter<T>());
  30. for (auto it = view.begin(); it != view.end(); ++it)
  31. {
  32. Events::GraphMetaInfo::VirtualTypesSet types;
  33. Events::GraphMetaInfoBus::Broadcast(
  34. &Events::GraphMetaInfoBus::Events::GetVirtualTypes,
  35. types,
  36. scene,
  37. graph.ConvertToNodeIndex(it.GetBaseIterator()));
  38. // Check if the type is not a virtual type. If it is, this isn't a valid type for T.
  39. if (types.empty())
  40. {
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. else
  47. {
  48. Containers::SceneGraph::ContentStorageConstData graphContent = graph.GetContentStorage();
  49. auto data = AZStd::find_if(graphContent.begin(), graphContent.end(), Containers::DerivedTypeFilter<T>());
  50. return data != graphContent.end();
  51. }
  52. }
  53. } // Utilities
  54. } // SceneAPI
  55. } // AZ