EditorMaterialSystemComponent.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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 <Atom/RHI/Factory.h>
  9. #include <Atom/RPI.Edit/Material/MaterialSourceData.h>
  10. #include <Atom/RPI.Edit/Material/MaterialTypeSourceData.h>
  11. #include <Atom/RPI.Reflect/Asset/AssetUtils.h>
  12. #include <AtomLyIntegration/CommonFeatures/Material/EditorMaterialSystemComponentNotificationBus.h>
  13. #include <AtomLyIntegration/CommonFeatures/Material/MaterialComponentBus.h>
  14. #include <AtomLyIntegration/AtomImGuiTools/AtomImGuiToolsBus.h>
  15. #include <AtomToolsFramework/PreviewRenderer/PreviewRendererCaptureRequest.h>
  16. #include <AtomToolsFramework/PreviewRenderer/PreviewRendererInterface.h>
  17. #include <AtomToolsFramework/Util/Util.h>
  18. #include <AzCore/Serialization/EditContext.h>
  19. #include <AzCore/Serialization/EditContextConstants.inl>
  20. #include <AzCore/Serialization/SerializeContext.h>
  21. #include <AzCore/StringFunc/StringFunc.h>
  22. #include <AzCore/Utils/Utils.h>
  23. #include <AzFramework/Application/Application.h>
  24. #include <AzToolsFramework/ActionManager/Action/ActionManagerInterface.h>
  25. #include <AzToolsFramework/ActionManager/HotKey/HotKeyManager.h>
  26. #include <AzToolsFramework/ActionManager/Menu/MenuManagerInterface.h>
  27. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  28. #include <AzToolsFramework/API/ViewPaneOptions.h>
  29. #include <AzToolsFramework/Editor/ActionManagerIdentifiers/EditorContextIdentifiers.h>
  30. #include <AzToolsFramework/Editor/ActionManagerIdentifiers/EditorMenuIdentifiers.h>
  31. #include <Editor/LyViewPaneNames.h>
  32. #include <Material/EditorMaterialComponentInspector.h>
  33. #include <Material/EditorMaterialSystemComponent.h>
  34. #include <SharedPreview/SharedPreviewContent.h>
  35. // Disables warning messages triggered by the Qt library
  36. // 4251: class needs to have dll-interface to be used by clients of class
  37. // 4800: forcing value to bool 'true' or 'false' (performance warning)
  38. AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option")
  39. #include <QAction>
  40. #include <QApplication>
  41. #include <QDockWidget>
  42. #include <QImage>
  43. #include <QObject>
  44. #include <QPixmap>
  45. #include <QProcessEnvironment>
  46. AZ_POP_DISABLE_WARNING
  47. constexpr AZStd::string_view MaterialCanvasActionIdentifier = "o3de.action.tools.material_canvas";
  48. constexpr AZStd::string_view MaterialEditorActionIdentifier = "o3de.action.tools.material_editor";
  49. void InitMaterialEditorResources()
  50. {
  51. //Must register qt resources from other modules
  52. Q_INIT_RESOURCE(InspectorWidget);
  53. }
  54. namespace AZ
  55. {
  56. namespace Render
  57. {
  58. //! Main system component for the Atom Common Feature Gem's editor/tools module.
  59. void EditorMaterialSystemComponent::Reflect(AZ::ReflectContext* context)
  60. {
  61. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  62. {
  63. serialize->Class<EditorMaterialSystemComponent, AZ::Component>()
  64. ->Version(0);
  65. if (AZ::EditContext* ec = serialize->GetEditContext())
  66. {
  67. ec->Class<EditorMaterialSystemComponent>("EditorMaterialSystemComponent", "System component that manages launching and maintaining connections the material editor.")
  68. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  69. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  70. ;
  71. }
  72. }
  73. }
  74. void EditorMaterialSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  75. {
  76. provided.push_back(AZ_CRC_CE("EditorMaterialSystem"));
  77. }
  78. void EditorMaterialSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  79. {
  80. incompatible.push_back(AZ_CRC_CE("EditorMaterialSystem"));
  81. }
  82. void EditorMaterialSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  83. {
  84. required.push_back(AZ_CRC_CE("PreviewRendererSystem"));
  85. }
  86. void EditorMaterialSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  87. {
  88. AZ_UNUSED(dependent);
  89. }
  90. void EditorMaterialSystemComponent::Init()
  91. {
  92. InitMaterialEditorResources();
  93. }
  94. void EditorMaterialSystemComponent::Activate()
  95. {
  96. AZ::EntitySystemBus::Handler::BusConnect();
  97. EditorMaterialSystemComponentNotificationBus::Handler::BusConnect();
  98. EditorMaterialSystemComponentRequestBus::Handler::BusConnect();
  99. MaterialComponentNotificationBus::Router::BusRouterConnect();
  100. AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusConnect();
  101. AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
  102. AzToolsFramework::ToolsApplicationNotificationBus::Handler::BusConnect();
  103. AzFramework::AssetCatalogEventBus::Handler::BusConnect();
  104. AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler::BusConnect();
  105. // All material previews use the same model and lighting preset assets
  106. // models/sphere.azmodel
  107. m_materialPreviewModelAsset.Create(AZ::Data::AssetId("{6DE0E9A8-A1C7-5D0F-9407-4E627C1F223C}", 284780167));
  108. // lightingpresets/thumbnail.lightingpreset.azasset
  109. m_materialPreviewLightingPresetAsset.Create(AZ::Data::AssetId("{4F3761EF-E279-5FDD-98C3-EF90F924FBAC}", 0));
  110. m_materialBrowserInteractions.reset(aznew MaterialBrowserInteractions);
  111. }
  112. void EditorMaterialSystemComponent::Deactivate()
  113. {
  114. AZ::EntitySystemBus::Handler::BusDisconnect();
  115. EditorMaterialSystemComponentNotificationBus::Handler::BusDisconnect();
  116. EditorMaterialSystemComponentRequestBus::Handler::BusDisconnect();
  117. MaterialComponentNotificationBus::Router::BusRouterDisconnect();
  118. AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusDisconnect();
  119. AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
  120. AzToolsFramework::ToolsApplicationNotificationBus::Handler::BusDisconnect();
  121. AZ::SystemTickBus::Handler::BusDisconnect();
  122. AzFramework::AssetCatalogEventBus::Handler::BusDisconnect();
  123. AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler::BusDisconnect();
  124. m_materialBrowserInteractions.reset();
  125. m_materialPreviewRequests.clear();
  126. m_materialPreviewModelAsset.Release();
  127. m_materialPreviewLightingPresetAsset.Release();
  128. }
  129. void EditorMaterialSystemComponent::OpenMaterialEditor(const AZStd::string& sourcePath)
  130. {
  131. QStringList arguments;
  132. arguments.append(sourcePath.c_str());
  133. // Use the same RHI as the main editor
  134. AZ::Name apiName = AZ::RHI::Factory::Get().GetName();
  135. if (!apiName.IsEmpty())
  136. {
  137. arguments.append(QString("--rhi=%1").arg(apiName.GetCStr()));
  138. }
  139. AZ::IO::FixedMaxPathString projectPath(AZ::Utils::GetProjectPath());
  140. if (!projectPath.empty())
  141. {
  142. arguments.append(QString("--project-path=%1").arg(projectPath.c_str()));
  143. }
  144. AZ_TracePrintf("MaterialComponent", "Launching Material Editor");
  145. AtomToolsFramework::LaunchTool("MaterialEditor", arguments);
  146. }
  147. void EditorMaterialSystemComponent::OpenMaterialCanvas(const AZStd::string& sourcePath)
  148. {
  149. QStringList arguments;
  150. arguments.append(sourcePath.c_str());
  151. // Use the same RHI as the main Canvas
  152. AZ::Name apiName = AZ::RHI::Factory::Get().GetName();
  153. if (!apiName.IsEmpty())
  154. {
  155. arguments.append(QString("--rhi=%1").arg(apiName.GetCStr()));
  156. }
  157. AZ::IO::FixedMaxPathString projectPath(AZ::Utils::GetProjectPath());
  158. if (!projectPath.empty())
  159. {
  160. arguments.append(QString("--project-path=%1").arg(projectPath.c_str()));
  161. }
  162. AZ_TracePrintf("MaterialComponent", "Launching Material Canvas");
  163. AtomToolsFramework::LaunchTool("MaterialCanvas", arguments);
  164. }
  165. void EditorMaterialSystemComponent::OpenMaterialInspector(
  166. const AZ::EntityId& primaryEntityId,
  167. const AzToolsFramework::EntityIdSet& entityIdsToEdit,
  168. const AZ::Render::MaterialAssignmentId& materialAssignmentId)
  169. {
  170. auto dockWidget = AzToolsFramework::InstanceViewPane("Material Instance Editor");
  171. if (dockWidget)
  172. {
  173. auto inspector = static_cast<AZ::Render::EditorMaterialComponentInspector::MaterialPropertyInspector*>(dockWidget->widget());
  174. if (inspector)
  175. {
  176. inspector->LoadMaterial(primaryEntityId, entityIdsToEdit, materialAssignmentId);
  177. }
  178. }
  179. }
  180. void EditorMaterialSystemComponent::RenderMaterialPreview(
  181. const AZ::EntityId& entityId, const AZ::Render::MaterialAssignmentId& materialAssignmentId)
  182. {
  183. m_materialPreviewRequests.emplace(entityId, materialAssignmentId);
  184. AZ::SystemTickBus::Handler::BusConnect();
  185. }
  186. QPixmap EditorMaterialSystemComponent::GetRenderedMaterialPreview(
  187. const AZ::EntityId& entityId, const AZ::Render::MaterialAssignmentId& materialAssignmentId) const
  188. {
  189. const auto& itr1 = m_materialPreviews.find(entityId);
  190. if (itr1 != m_materialPreviews.end())
  191. {
  192. const auto& itr2 = itr1->second.find(materialAssignmentId);
  193. if (itr2 != itr1->second.end())
  194. {
  195. return itr2->second;
  196. }
  197. }
  198. return QPixmap();
  199. }
  200. void EditorMaterialSystemComponent::OnEntityDeactivated(const AZ::EntityId& entityId)
  201. {
  202. // Deleting any preview saved for an entity that is about to be deactivated
  203. m_materialPreviews.erase(entityId);
  204. }
  205. void EditorMaterialSystemComponent::OnSystemTick()
  206. {
  207. auto previewRenderer = AZ::Interface<AtomToolsFramework::PreviewRendererInterface>::Get();
  208. if (!previewRenderer || !m_materialPreviewModelAsset.IsReady() || !m_materialPreviewLightingPresetAsset.IsReady())
  209. {
  210. return;
  211. }
  212. for (const auto& materialPreviewRequestPair : m_materialPreviewRequests)
  213. {
  214. const auto& entityId = materialPreviewRequestPair.first;
  215. const auto& materialAssignmentId = materialPreviewRequestPair.second;
  216. AZ::Data::AssetId materialAssetId = {};
  217. MaterialComponentRequestBus::EventResult(
  218. materialAssetId, entityId, &MaterialComponentRequestBus::Events::GetMaterialAssetId, materialAssignmentId);
  219. AZ::Render::MaterialPropertyOverrideMap propertyOverrides;
  220. AZ::Render::MaterialComponentRequestBus::EventResult(
  221. propertyOverrides, entityId, &AZ::Render::MaterialComponentRequestBus::Events::GetPropertyValues, materialAssignmentId);
  222. // Having an invalid material asset will use the default asset on the model.
  223. AZ::Data::Asset<AZ::RPI::MaterialAsset> materialAsset;
  224. materialAsset.Create(materialAssetId);
  225. previewRenderer->AddCaptureRequest(
  226. { MaterialPreviewResolution,
  227. AZStd::make_shared<AZ::LyIntegration::SharedPreviewContent>(
  228. previewRenderer->GetScene(),
  229. previewRenderer->GetView(),
  230. previewRenderer->GetEntityContextId(),
  231. m_materialPreviewModelAsset,
  232. materialAsset,
  233. m_materialPreviewLightingPresetAsset,
  234. propertyOverrides),
  235. [entityId, materialAssignmentId]()
  236. {
  237. AZ_UNUSED(entityId);
  238. AZ_UNUSED(materialAssignmentId);
  239. AZ_Warning(
  240. "EditorMaterialSystemComponent",
  241. false,
  242. "RenderMaterialPreview capture failed for entity %s slot %s.",
  243. entityId.ToString().c_str(),
  244. materialAssignmentId.ToString().c_str());
  245. // If the capture failed to render substitute it with a black image
  246. QPixmap pixmap(1, 1);
  247. pixmap.fill(Qt::black);
  248. AZ::Render::EditorMaterialSystemComponentNotificationBus::Broadcast(
  249. &AZ::Render::EditorMaterialSystemComponentNotificationBus::Events::OnRenderMaterialPreviewRendered,
  250. entityId,
  251. materialAssignmentId,
  252. pixmap);
  253. },
  254. [entityId, materialAssignmentId](const QPixmap& pixmap)
  255. {
  256. AZ::Render::EditorMaterialSystemComponentNotificationBus::Broadcast(
  257. &AZ::Render::EditorMaterialSystemComponentNotificationBus::Events::OnRenderMaterialPreviewRendered,
  258. entityId,
  259. materialAssignmentId,
  260. pixmap);
  261. } });
  262. }
  263. m_materialPreviewRequests.clear();
  264. AZ::SystemTickBus::Handler::BusDisconnect();
  265. }
  266. void EditorMaterialSystemComponent::OnCatalogLoaded([[maybe_unused]] const char* catalogFile)
  267. {
  268. m_materialPreviewModelAsset.QueueLoad();
  269. m_materialPreviewLightingPresetAsset.QueueLoad();
  270. }
  271. void EditorMaterialSystemComponent::OnRenderMaterialPreviewRendered(
  272. [[maybe_unused]] const AZ::EntityId& entityId,
  273. [[maybe_unused]] const AZ::Render::MaterialAssignmentId& materialAssignmentId,
  274. [[maybe_unused]] const QPixmap& pixmap)
  275. {
  276. // Since the "preview rendered" event is not called on the main thread, queue
  277. // the handling code to be executed on the main thread. This prevents any non
  278. // thread-safe code, such as Qt updates, from running on alternate threads
  279. AZ::SystemTickBus::QueueFunction(
  280. [=]()
  281. {
  282. PurgePreviews();
  283. // Caching preview so the image will not have to be regenerated every time it's requested
  284. m_materialPreviews[entityId][materialAssignmentId] = pixmap;
  285. AZ::Render::EditorMaterialSystemComponentNotificationBus::Broadcast(
  286. &AZ::Render::EditorMaterialSystemComponentNotificationBus::Events::OnRenderMaterialPreviewReady,
  287. entityId,
  288. materialAssignmentId,
  289. pixmap);
  290. });
  291. }
  292. void EditorMaterialSystemComponent::OnMaterialSlotLayoutChanged()
  293. {
  294. // Deleting any preview saved for an entity whose material configuration is about to be invalidated
  295. const AZ::EntityId entityId = *MaterialComponentNotificationBus::GetCurrentBusId();
  296. m_materialPreviews.erase(entityId);
  297. }
  298. void EditorMaterialSystemComponent::NotifyRegisterViews()
  299. {
  300. AzToolsFramework::ViewPaneOptions inspectorOptions;
  301. inspectorOptions.canHaveMultipleInstances = true;
  302. inspectorOptions.preferedDockingArea = Qt::NoDockWidgetArea;
  303. inspectorOptions.paneRect = QRect(50, 50, 600, 1000);
  304. inspectorOptions.showInMenu = false;
  305. inspectorOptions.showOnToolsToolbar = false;
  306. AzToolsFramework::RegisterViewPane<AZ::Render::EditorMaterialComponentInspector::MaterialPropertyInspector>(
  307. "Material Instance Editor", LyViewPane::CategoryTools, inspectorOptions);
  308. }
  309. void EditorMaterialSystemComponent::AfterEntitySelectionChanged(const AzToolsFramework::EntityIdList& newlySelectedEntities, const AzToolsFramework::EntityIdList&)
  310. {
  311. if (newlySelectedEntities.size() == 1)
  312. {
  313. AtomImGuiTools::AtomImGuiToolsRequestBus::Broadcast(&AtomImGuiTools::AtomImGuiToolsRequests::ShowMaterialShaderDetailsForEntity, newlySelectedEntities[0], false);
  314. }
  315. else
  316. {
  317. AtomImGuiTools::AtomImGuiToolsRequestBus::Broadcast(&AtomImGuiTools::AtomImGuiToolsRequests::ShowMaterialShaderDetailsForEntity, AZ::EntityId{}, false);
  318. }
  319. }
  320. AzToolsFramework::AssetBrowser::SourceFileDetails EditorMaterialSystemComponent::GetSourceFileDetails(
  321. const char* fullSourceFileName)
  322. {
  323. const AZStd::string_view path(fullSourceFileName);
  324. if (path.ends_with("physxmaterial") || path.ends_with("physicsmaterial"))
  325. {
  326. return AzToolsFramework::AssetBrowser::SourceFileDetails(":/Icons/PhysXMaterial_80.svg");
  327. }
  328. if (path.ends_with(AZ::RPI::MaterialSourceData::Extension))
  329. {
  330. return AzToolsFramework::AssetBrowser::SourceFileDetails(":/Icons/Material_80.svg");
  331. }
  332. if (path.ends_with(AZ::RPI::MaterialTypeSourceData::Extension))
  333. {
  334. return AzToolsFramework::AssetBrowser::SourceFileDetails(":/Icons/MaterialType_80.svg");
  335. }
  336. if (path.ends_with(AZ::Render::EditorMaterialComponentUtil::MaterialGraphExtensionWithDot) ||
  337. path.ends_with(AZ::Render::EditorMaterialComponentUtil::MaterialGraphNodeExtensionWithDot) ||
  338. path.ends_with(AZ::Render::EditorMaterialComponentUtil::MaterialGraphTemplateExtensionWithDot))
  339. {
  340. return AzToolsFramework::AssetBrowser::SourceFileDetails(":/Icons/MaterialGraph_80.svg");
  341. }
  342. if (path.ends_with(AZ::RPI::BufferAsset::Extension))
  343. {
  344. return AzToolsFramework::AssetBrowser::SourceFileDetails(":/Icons/BufferAsset_80.svg");
  345. }
  346. if (path.ends_with(AZ::RPI::ShaderAsset::Extension))
  347. {
  348. return AzToolsFramework::AssetBrowser::SourceFileDetails(":/Icons/Shader_80.svg");
  349. }
  350. return AzToolsFramework::AssetBrowser::SourceFileDetails();
  351. }
  352. void EditorMaterialSystemComponent::OnActionRegistrationHook()
  353. {
  354. auto actionManagerInterface = AZ::Interface<AzToolsFramework::ActionManagerInterface>::Get();
  355. AZ_Assert(actionManagerInterface, "EditorMaterialSystemComponent - could not get ActionManagerInterface");
  356. auto hotKeyManagerInterface = AZ::Interface<AzToolsFramework::HotKeyManagerInterface>::Get();
  357. AZ_Assert(hotKeyManagerInterface, "EditorMaterialSystemComponent - could not get HotKeyManagerInterface");
  358. {
  359. AzToolsFramework::ActionProperties actionProperties;
  360. actionProperties.m_name = "Material Editor";
  361. actionProperties.m_iconPath = ":/Menu/material_editor.svg";
  362. auto outcome = actionManagerInterface->RegisterAction(
  363. EditorIdentifiers::MainWindowActionContextIdentifier,
  364. MaterialEditorActionIdentifier,
  365. actionProperties,
  366. [this]()
  367. {
  368. OpenMaterialEditor("");
  369. }
  370. );
  371. AZ_Assert(outcome.IsSuccess(), "Failed to RegisterAction %s", MaterialEditorActionIdentifier.data());
  372. hotKeyManagerInterface->SetActionHotKey(MaterialEditorActionIdentifier, "Ctrl+M");
  373. }
  374. {
  375. AzToolsFramework::ActionProperties actionProperties;
  376. actionProperties.m_name = "Material Canvas";
  377. actionProperties.m_iconPath = ":/Menu/material_canvas.svg";
  378. auto outcome = actionManagerInterface->RegisterAction(
  379. EditorIdentifiers::MainWindowActionContextIdentifier,
  380. MaterialCanvasActionIdentifier,
  381. actionProperties,
  382. [this]()
  383. {
  384. OpenMaterialCanvas("");
  385. });
  386. AZ_Assert(outcome.IsSuccess(), "Failed to RegisterAction %s", MaterialCanvasActionIdentifier.data());
  387. outcome = hotKeyManagerInterface->SetActionHotKey(MaterialCanvasActionIdentifier, "Ctrl+Shift+M");
  388. AZ_Assert(outcome.IsSuccess(), "Failed to ActionHotKey for %s", MaterialCanvasActionIdentifier.data());
  389. }
  390. }
  391. void EditorMaterialSystemComponent::OnMenuBindingHook()
  392. {
  393. auto actionManagerInterface = AZ::Interface<AzToolsFramework::ActionManagerInterface>::Get();
  394. AZ_Assert(actionManagerInterface, "EditorMaterialSystemComponent - could not get ActionManagerInterface");
  395. auto menuManagerInterface = AZ::Interface<AzToolsFramework::MenuManagerInterface>::Get();
  396. AZ_Assert(menuManagerInterface, "EditorMaterialSystemComponent - could not get MenuManagerInterface");
  397. {
  398. auto outcome = menuManagerInterface->AddActionToMenu(
  399. EditorIdentifiers::ToolsMenuIdentifier,
  400. MaterialEditorActionIdentifier,
  401. actionManagerInterface->GenerateActionAlphabeticalSortKey(MaterialEditorActionIdentifier));
  402. AZ_Assert(
  403. outcome.IsSuccess(),
  404. "Failed to AddAction %s to Menu %s",
  405. MaterialEditorActionIdentifier.data(),
  406. EditorIdentifiers::ToolsMenuIdentifier.data());
  407. }
  408. {
  409. auto outcome = menuManagerInterface->AddActionToMenu(
  410. EditorIdentifiers::ToolsMenuIdentifier,
  411. MaterialCanvasActionIdentifier,
  412. actionManagerInterface->GenerateActionAlphabeticalSortKey(MaterialCanvasActionIdentifier));
  413. AZ_Assert(
  414. outcome.IsSuccess(),
  415. "Failed to AddAction %s to Menu %s",
  416. MaterialCanvasActionIdentifier.data(),
  417. EditorIdentifiers::ToolsMenuIdentifier.data());
  418. }
  419. }
  420. void EditorMaterialSystemComponent::PurgePreviews()
  421. {
  422. // Deleting all saved previews after a certain threshold has been reached
  423. size_t materialPreviewCount = 0;
  424. for (const auto& materialPreviewPair : m_materialPreviews)
  425. {
  426. materialPreviewCount += materialPreviewPair.second.size();
  427. }
  428. if (materialPreviewCount > MaterialPreviewLimit)
  429. {
  430. m_materialPreviews.clear();
  431. }
  432. }
  433. } // namespace Render
  434. } // namespace AZ