AssImpMeshImporter.cpp 2.3 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. #include <assimp/scene.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/std/smart_ptr/make_shared.h>
  11. #include <AzToolsFramework/Debug/TraceContext.h>
  12. #include <SceneAPI/SceneBuilder/Importers/AssImpImporterUtilities.h>
  13. #include <SceneAPI/SceneBuilder/Importers/AssImpMeshImporter.h>
  14. #include <SceneAPI/SceneBuilder/Importers/Utilities/AssImpMeshImporterUtilities.h>
  15. #include <SceneAPI/SceneData/GraphData/MeshData.h>
  16. #include <SceneAPI/SDKWrapper/AssImpNodeWrapper.h>
  17. #include <SceneAPI/SDKWrapper/AssImpSceneWrapper.h>
  18. namespace AZ
  19. {
  20. namespace SceneAPI
  21. {
  22. namespace SceneBuilder
  23. {
  24. AssImpMeshImporter::AssImpMeshImporter()
  25. {
  26. BindToCall(&AssImpMeshImporter::ImportMesh);
  27. }
  28. void AssImpMeshImporter::Reflect(ReflectContext* context)
  29. {
  30. SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
  31. if (serializeContext)
  32. {
  33. serializeContext->Class<AssImpMeshImporter, SceneCore::LoadingComponent>()->Version(3);
  34. }
  35. }
  36. Events::ProcessingResult AssImpMeshImporter::ImportMesh(AssImpNodeEncounteredContext& context)
  37. {
  38. AZ_TraceContext("Importer", "Mesh");
  39. const aiNode* currentNode = context.m_sourceNode.GetAssImpNode();
  40. const aiScene* scene = context.m_sourceScene.GetAssImpScene();
  41. if (!context.m_sourceNode.ContainsMesh() || IsSkinnedMesh(*currentNode, *scene))
  42. {
  43. return Events::ProcessingResult::Ignored;
  44. }
  45. if (BuildSceneMeshFromAssImpMesh(currentNode, scene, context.m_sourceSceneSystem, context.m_createdData, [] {
  46. return AZStd::make_shared<SceneData::GraphData::MeshData>();
  47. }))
  48. {
  49. return Events::ProcessingResult::Success;
  50. }
  51. return Events::ProcessingResult::Failure;
  52. }
  53. } // namespace SceneBuilder
  54. } // namespace SceneAPI
  55. } // namespace AZ