2
0

AssetImporterPlugin.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <AssetImporterPlugin.h>
  9. #include <AssetImporterWindow.h>
  10. #include <QtViewPaneManager.h>
  11. #include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
  12. #include <SceneAPI/SceneCore/Utilities/Reporting.h>
  13. #include <LyViewPaneNames.h>
  14. #include <AzToolsFramework/API/ToolsApplicationAPI.h>
  15. AssetImporterPlugin* AssetImporterPlugin::s_instance;
  16. AssetImporterPlugin::AssetImporterPlugin(IEditor* editor)
  17. : m_editor(editor)
  18. , m_toolName(LyViewPane::SceneSettings)
  19. , m_assetBrowserContextProvider()
  20. , m_sceneSerializationHandler()
  21. {
  22. s_instance = this;
  23. m_sceneUIModule = LoadSceneLibrary("SceneUI", true);
  24. m_sceneSerializationHandler.Activate();
  25. AzToolsFramework::ViewPaneOptions opt;
  26. opt.isPreview = true;
  27. opt.showInMenu = false; // this view pane is used to display scene settings, but the user never opens it directly through the Tools menu
  28. opt.saveKeyName = "Scene Settings (PREVIEW)"; // user settings for this pane were originally saved with PREVIEW, so ensure that's how they are loaded as well, even after the PREVIEW is removed from the name
  29. AzToolsFramework::RegisterViewPane<AssetImporterWindow>(m_toolName.c_str(), LyViewPane::CategoryTools, opt);
  30. AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
  31. &AzToolsFramework::ToolsApplicationRequests::CreateAndAddEntityFromComponentTags,
  32. AZStd::vector<AZ::Crc32>({ AZ::SceneAPI::Events::AssetImportRequest::GetAssetImportRequestComponentTag() }), "AssetImportersEntity");
  33. }
  34. void AssetImporterPlugin::Release()
  35. {
  36. AzToolsFramework::UnregisterViewPane(m_toolName.c_str());
  37. m_sceneSerializationHandler.Deactivate();
  38. auto uninit = m_sceneUIModule->GetFunction<AZ::UninitializeDynamicModuleFunction>(AZ::UninitializeDynamicModuleFunctionName);
  39. if (uninit)
  40. {
  41. (*uninit)();
  42. }
  43. m_sceneUIModule.reset();
  44. }
  45. AZStd::unique_ptr<AZ::DynamicModuleHandle> AssetImporterPlugin::LoadSceneLibrary(const char* name, bool explicitInit)
  46. {
  47. using ReflectFunc = void(*)(AZ::SerializeContext*);
  48. AZStd::unique_ptr<AZ::DynamicModuleHandle> module = AZ::DynamicModuleHandle::Create(name);
  49. if (module)
  50. {
  51. module->Load(false);
  52. if (explicitInit)
  53. {
  54. // Explicitly initialize all modules. Because we're loading them twice (link time, and now-time), we need to explicitly uninit them.
  55. auto init = module->GetFunction<AZ::InitializeDynamicModuleFunction>(AZ::InitializeDynamicModuleFunctionName);
  56. if (init)
  57. {
  58. (*init)();
  59. }
  60. }
  61. ReflectFunc reflect = module->GetFunction<ReflectFunc>("Reflect");
  62. if (reflect)
  63. {
  64. (*reflect)(nullptr);
  65. }
  66. return module;
  67. }
  68. else
  69. {
  70. AZ_TracePrintf(AZ::SceneAPI::Utilities::ErrorWindow, "Failed to initialize library '%s'", name);
  71. return nullptr;
  72. }
  73. }
  74. void AssetImporterPlugin::EditImportSettings(const AZStd::string& sourceFilePath)
  75. {
  76. const QtViewPane* assetImporterPane = GetIEditor()->OpenView(m_toolName.c_str());
  77. if(!assetImporterPane)
  78. {
  79. return;
  80. }
  81. AssetImporterWindow* assetImporterWindow = qobject_cast<AssetImporterWindow*>(assetImporterPane->Widget());
  82. if (!assetImporterWindow)
  83. {
  84. return;
  85. }
  86. assetImporterWindow->OpenFile(sourceFilePath);
  87. }