AssetImporterDocument.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <AssetImporterDocument.h>
  9. #include <Util/PathUtil.h>
  10. #include <SceneAPI/SceneCore/Containers/Views/PairIterator.h>
  11. #include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
  12. #include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.h>
  13. #include <SceneAPI/SceneCore/DataTypes/Rules/IMaterialRule.h>
  14. #include <SceneAPI/SceneCore/DataTypes/Groups/IMeshGroup.h>
  15. #include <SceneAPI/SceneCore/DataTypes/Groups/ISkeletonGroup.h>
  16. #include <SceneAPI/SceneCore/DataTypes/Groups/ISkinGroup.h>
  17. #include <SceneAPI/SceneCore/DataTypes/Groups/IAnimationGroup.h>
  18. #include <SceneAPI/SceneCore/DataTypes/ManifestBase/ISceneNodeSelectionList.h>
  19. #include <SceneAPI/SceneCore/Events/SceneSerializationBus.h>
  20. #include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
  21. #include <SceneAPI/SceneCore/Utilities/FileUtilities.h>
  22. #include <SceneAPI/SceneCore/Utilities/Reporting.h>
  23. #include <IEditor.h>
  24. #include <QFile>
  25. #include <QWidget>
  26. #include <QMessageBox>
  27. #include <QPushButton>
  28. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  29. #include <AzCore/Debug/Profiler.h>
  30. #include <AzCore/std/string/conversions.h>
  31. #include <AzCore/std/smart_ptr/make_shared.h>
  32. #include <ActionOutput.h>
  33. #include <AzToolsFramework/SourceControl/SourceControlAPI.h>
  34. AssetImporterDocument::AssetImporterDocument()
  35. {
  36. }
  37. bool AssetImporterDocument::LoadScene(const AZStd::string& sceneFullPath)
  38. {
  39. AZ_PROFILE_FUNCTION(Editor);
  40. namespace SceneEvents = AZ::SceneAPI::Events;
  41. SceneEvents::SceneSerializationBus::BroadcastResult(m_scene, &SceneEvents::SceneSerializationBus::Events::LoadScene, sceneFullPath, AZ::Uuid::CreateNull(), "");
  42. return !!m_scene;
  43. }
  44. void AssetImporterDocument::SaveScene(AZStd::shared_ptr<AZ::ActionOutput>& output, AZ::SaveCompleteCallback onSaveComplete)
  45. {
  46. if (!m_scene)
  47. {
  48. if (output)
  49. {
  50. output->AddError("No scene file was loaded.");
  51. }
  52. if (onSaveComplete)
  53. {
  54. onSaveComplete(false);
  55. }
  56. return;
  57. }
  58. // If a save is requested, the user is going to want to see the asset re-processed, even if they didn't actually make a change.
  59. bool fingerprintCleared = false;
  60. AzToolsFramework::AssetSystemRequestBus::BroadcastResult(
  61. fingerprintCleared, &AzToolsFramework::AssetSystemRequestBus::Events::ClearFingerprintForAsset, m_scene->GetManifestFilename());
  62. AzToolsFramework::AssetSystemRequestBus::BroadcastResult(
  63. fingerprintCleared, &AzToolsFramework::AssetSystemRequestBus::Events::ClearFingerprintForAsset, m_scene->GetSourceFilename());
  64. m_saveRunner = AZStd::make_shared<AZ::AsyncSaveRunner>();
  65. // Add a no-op saver to put the FBX into source control. The benefit of doing it this way
  66. // rather than invoking the SourceControlCommands bus directly is that we enable ourselves
  67. // to have a single callback point for fbx & the manifest.
  68. auto fbxNoOpSaver = m_saveRunner->GenerateController();
  69. fbxNoOpSaver->AddSaveOperation(m_scene->GetSourceFilename(), nullptr);
  70. // Save the manifest
  71. SaveManifest();
  72. m_saveRunner->Run(output,
  73. [this, onSaveComplete](bool success)
  74. {
  75. if (onSaveComplete)
  76. {
  77. onSaveComplete(success);
  78. }
  79. m_saveRunner = nullptr;
  80. }, AZ::AsyncSaveRunner::ControllerOrder::Sequential);
  81. }
  82. void AssetImporterDocument::ClearScene()
  83. {
  84. m_scene.reset();
  85. }
  86. void AssetImporterDocument::SaveManifest()
  87. {
  88. // Create the save controller and add the save operation for the manifest job to it
  89. AZStd::shared_ptr<AZ::SaveOperationController> saveController = m_saveRunner->GenerateController();
  90. saveController->AddSaveOperation(m_scene->GetManifestFilename(),
  91. [this](const AZStd::string& fullPath, const AZStd::shared_ptr<AZ::ActionOutput>& actionOutput) -> bool
  92. {
  93. AZ_UNUSED(actionOutput);
  94. return m_scene->GetManifest().SaveToFile(fullPath.c_str());
  95. });
  96. }
  97. AZStd::shared_ptr<AZ::SceneAPI::Containers::Scene>& AssetImporterDocument::GetScene()
  98. {
  99. return m_scene;
  100. }