Additional preview renderer checks
Preventing multiple preview renderers from being created with multiple catalog loaded notifications Purging material preview images reaching a maximum number of stored images Purging material previews if entity gets destroyed Signed-off-by: Guthrie Adams <guthadam@amazon.com>
This commit is contained in:
+5
-2
@@ -63,8 +63,11 @@ namespace AtomToolsFramework
|
||||
void PreviewRendererSystemComponent::OnCatalogLoaded([[maybe_unused]] const char* catalogFile)
|
||||
{
|
||||
AZ::TickBus::QueueFunction([this](){
|
||||
m_previewRenderer.reset(aznew AtomToolsFramework::PreviewRenderer(
|
||||
"PreviewRendererSystemComponent Preview Scene", "PreviewRendererSystemComponent Preview Pipeline"));
|
||||
if (!m_previewRenderer)
|
||||
{
|
||||
m_previewRenderer.reset(aznew AtomToolsFramework::PreviewRenderer(
|
||||
"PreviewRendererSystemComponent Preview Scene", "PreviewRendererSystemComponent Preview Pipeline"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+11
-5
@@ -216,11 +216,17 @@ namespace AZ
|
||||
using namespace LyIntegration;
|
||||
|
||||
ThumbnailerRequestsBus::Broadcast(
|
||||
&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(SharedThumbnailCache),
|
||||
ThumbnailContext::DefaultContext);
|
||||
&ThumbnailerRequests::RegisterThumbnailProvider, MAKE_TCACHE(SharedThumbnailCache), ThumbnailContext::DefaultContext);
|
||||
|
||||
m_renderer = AZStd::make_unique<AZ::LyIntegration::SharedThumbnailRenderer>();
|
||||
m_previewerFactory = AZStd::make_unique<LyIntegration::SharedPreviewerFactory>();
|
||||
if (!m_thumbnailRenderer)
|
||||
{
|
||||
m_thumbnailRenderer = AZStd::make_unique<AZ::LyIntegration::SharedThumbnailRenderer>();
|
||||
}
|
||||
|
||||
if (!m_previewerFactory)
|
||||
{
|
||||
m_previewerFactory = AZStd::make_unique<LyIntegration::SharedPreviewerFactory>();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorCommonFeaturesSystemComponent::TeardownThumbnails()
|
||||
@@ -232,7 +238,7 @@ namespace AZ
|
||||
&ThumbnailerRequests::UnregisterThumbnailProvider, SharedThumbnailCache::ProviderName,
|
||||
ThumbnailContext::DefaultContext);
|
||||
|
||||
m_renderer.reset();
|
||||
m_thumbnailRenderer.reset();
|
||||
m_previewerFactory.reset();
|
||||
}
|
||||
} // namespace Render
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ namespace AZ
|
||||
AZStd::string m_atomLevelDefaultAssetPath{ "LevelAssets/default.slice" };
|
||||
float m_envProbeHeight{ 200.0f };
|
||||
|
||||
AZStd::unique_ptr<AZ::LyIntegration::SharedThumbnailRenderer> m_renderer;
|
||||
AZStd::unique_ptr<AZ::LyIntegration::SharedThumbnailRenderer> m_thumbnailRenderer;
|
||||
AZStd::unique_ptr<LyIntegration::SharedPreviewerFactory> m_previewerFactory;
|
||||
};
|
||||
} // namespace Render
|
||||
|
||||
+24
-1
@@ -185,7 +185,7 @@ namespace AZ
|
||||
materialAssignmentId);
|
||||
|
||||
previewRenderer->AddCaptureRequest(
|
||||
{ 128,
|
||||
{ m_materialPreviewResolution,
|
||||
AZStd::make_shared<AZ::LyIntegration::SharedPreviewContent>(
|
||||
previewRenderer->GetScene(), previewRenderer->GetView(), previewRenderer->GetEntityContextId(),
|
||||
AZ::RPI::AssetUtils::GetAssetIdForProductPath(DefaultModelPath), materialAssetId,
|
||||
@@ -220,11 +220,17 @@ namespace AZ
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
void EditorMaterialSystemComponent::OnEntityDestroyed(const AZ::EntityId& entityId)
|
||||
{
|
||||
m_materialPreviews.erase(entityId);
|
||||
}
|
||||
|
||||
void EditorMaterialSystemComponent::OnRenderMaterialPreviewComplete(
|
||||
[[maybe_unused]] const AZ::EntityId& entityId,
|
||||
[[maybe_unused]] const AZ::Render::MaterialAssignmentId& materialAssignmentId,
|
||||
[[maybe_unused]] const QPixmap& pixmap)
|
||||
{
|
||||
PurgePreviews();
|
||||
m_materialPreviews[entityId][materialAssignmentId] = pixmap;
|
||||
}
|
||||
|
||||
@@ -281,5 +287,22 @@ namespace AZ
|
||||
}
|
||||
return AzToolsFramework::AssetBrowser::SourceFileDetails();
|
||||
}
|
||||
|
||||
void EditorMaterialSystemComponent::PurgePreviews()
|
||||
{
|
||||
size_t materialPreviewCount = 0;
|
||||
for (const auto& [entityId, previews] : m_materialPreviews)
|
||||
{
|
||||
for (const auto& [assignmentId, images] : previews)
|
||||
{
|
||||
materialPreviewCount += previews.size();
|
||||
}
|
||||
}
|
||||
|
||||
if (materialPreviewCount > m_materialPreviewLimit)
|
||||
{
|
||||
m_materialPreviews.clear();
|
||||
}
|
||||
}
|
||||
} // namespace Render
|
||||
} // namespace AZ
|
||||
|
||||
+10
-1
@@ -11,6 +11,7 @@
|
||||
#include <AtomLyIntegration/CommonFeatures/Material/EditorMaterialSystemComponentRequestBus.h>
|
||||
#include <AzCore/Asset/AssetCommon.h>
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzCore/Component/EntityBus.h>
|
||||
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
|
||||
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
|
||||
#include <AzToolsFramework/Viewport/ActionBus.h>
|
||||
@@ -24,6 +25,7 @@ namespace AZ
|
||||
//! System component that manages launching and maintaining connections with the material editor.
|
||||
class EditorMaterialSystemComponent final
|
||||
: public AZ::Component
|
||||
, public AZ::EntitySystemBus::Handler
|
||||
, public EditorMaterialSystemComponentNotificationBus::Handler
|
||||
, public EditorMaterialSystemComponentRequestBus::Handler
|
||||
, public AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler
|
||||
@@ -54,9 +56,12 @@ namespace AZ
|
||||
QPixmap GetRenderedMaterialPreview(
|
||||
const AZ::EntityId& entityId, const AZ::Render::MaterialAssignmentId& materialAssignmentId) const override;
|
||||
|
||||
// AZ::EntitySystemBus::Handler overrides...
|
||||
void OnEntityDestroyed(const AZ::EntityId& entityId) override;
|
||||
|
||||
//! EditorMaterialSystemComponentNotificationBus::Handler overrides...
|
||||
void OnRenderMaterialPreviewComplete(
|
||||
const AZ::EntityId& entityId, const AZ::Render::MaterialAssignmentId& materialAssignmentId, const QPixmap& pixmap)override;
|
||||
const AZ::EntityId& entityId, const AZ::Render::MaterialAssignmentId& materialAssignmentId, const QPixmap& pixmap) override;
|
||||
|
||||
//! AssetBrowserInteractionNotificationBus::Handler overrides...
|
||||
AzToolsFramework::AssetBrowser::SourceFileDetails GetSourceFileDetails(const char* fullSourceFileName) override;
|
||||
@@ -68,9 +73,13 @@ namespace AZ
|
||||
// AztoolsFramework::EditorEvents::Bus::Handler overrides...
|
||||
void NotifyRegisterViews() override;
|
||||
|
||||
void PurgePreviews();
|
||||
|
||||
QAction* m_openMaterialEditorAction = nullptr;
|
||||
AZStd::unique_ptr<MaterialBrowserInteractions> m_materialBrowserInteractions;
|
||||
AZStd::unordered_map<AZ::EntityId, AZStd::unordered_map<AZ::Render::MaterialAssignmentId, QPixmap>> m_materialPreviews;
|
||||
static constexpr const size_t m_materialPreviewLimit = 100;
|
||||
static constexpr const int m_materialPreviewResolution = 128;
|
||||
};
|
||||
} // namespace Render
|
||||
} // namespace AZ
|
||||
|
||||
Reference in New Issue
Block a user