AssImpSceneWrapper.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <SceneAPI/SDKWrapper/SceneWrapper.h>
  10. #include <SceneAPI/SceneCore/Import/SceneImportSettings.h>
  11. #include <assimp/Importer.hpp>
  12. #include <assimp/scene.h>
  13. struct aiScene;
  14. namespace AZ
  15. {
  16. namespace AssImpSDKWrapper
  17. {
  18. class AssImpSceneWrapper : public SDKScene::SceneWrapperBase
  19. {
  20. public:
  21. AZ_RTTI(AssImpSceneWrapper, "{43A61F62-DCD4-4132-B80B-F2FBC80740BC}", SDKScene::SceneWrapperBase);
  22. AssImpSceneWrapper();
  23. AssImpSceneWrapper(aiScene* aiScene);
  24. ~AssImpSceneWrapper() override = default;
  25. bool LoadSceneFromFile(const char* fileName, const AZ::SceneAPI::SceneImportSettings& importSettings) override;
  26. bool LoadSceneFromFile(const AZStd::string& fileName, const AZ::SceneAPI::SceneImportSettings& importSettings) override;
  27. const std::shared_ptr<SDKNode::NodeWrapper> GetRootNode() const override;
  28. std::shared_ptr<SDKNode::NodeWrapper> GetRootNode() override;
  29. virtual const aiScene* GetAssImpScene() const;
  30. void Clear() override;
  31. void CalculateAABBandVertices(const aiScene* scene, aiAABB& aabb, uint32_t& vertices);
  32. enum class AxisVector
  33. {
  34. X = 0,
  35. Y = 1,
  36. Z = 2,
  37. Unknown
  38. };
  39. AZStd::pair<AxisVector, int32_t> GetUpVectorAndSign() const;
  40. AZStd::pair<AxisVector, int32_t> GetFrontVectorAndSign() const;
  41. AZStd::string GetSceneFileName() const { return m_sceneFileName; }
  42. aiAABB GetAABB() const { return m_aabb; }
  43. uint32_t GetVertices() const { return m_vertices; }
  44. protected:
  45. const aiScene* m_assImpScene = nullptr;
  46. AZStd::unique_ptr<Assimp::Importer> m_importer;
  47. // FBX SDK automatically resolved relative paths to textures based on the current file location.
  48. // AssImp does not, so it needs to be specifically handled.
  49. AZStd::string m_sceneFileName;
  50. aiAABB m_aabb;
  51. uint32_t m_vertices;
  52. };
  53. } // namespace AssImpSDKWrapper
  54. } // namespace AZ