From 1f2572fe8aa589a53c8d1644e5523bf422d11ded Mon Sep 17 00:00:00 2001 From: mnaumov Date: Wed, 9 Jun 2021 13:26:42 -0700 Subject: [PATCH] PR feedback --- .../Code/Source/Mesh/EditorMeshComponent.cpp | 18 +++---- .../Code/Source/Mesh/EditorMeshStats.cpp | 53 ++++++++++++------- .../Code/Source/Mesh/EditorMeshStats.h | 10 ++-- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp index 3176bfe37b..3c5063a69e 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp @@ -60,7 +60,7 @@ namespace AZ ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorMeshComponent::AddEditorMaterialComponent) ->Attribute(AZ::Edit::Attributes::Visibility, &EditorMeshComponent::GetEditorMaterialComponentVisibility) ->DataElement(AZ::Edit::UIHandlers::Default, &EditorMeshComponent::m_stats, "Mesh Stats", "") - ->Attribute(AZ::Edit::Attributes::AutoExpand, false) + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ; editContext->Class( @@ -210,20 +210,21 @@ namespace AZ void EditorMeshComponent::OnModelReady(const Data::Asset& /*modelAsset*/, const Data::Instance& /*model*/) { + const auto& lodAssets = m_controller.GetConfiguration().m_modelAsset->GetLodAssets(); m_stats.m_meshStatsForLod.clear(); - for (auto& lod : m_controller.GetConfiguration().m_modelAsset->GetLodAssets()) + m_stats.m_meshStatsForLod.reserve(lodAssets.size()); + for (const auto& lodAsset : lodAssets) { EditorMeshStatsForLod stats; - auto meshes = lod->GetMeshes(); - stats.m_meshCount = lod->GetMeshes().size(); - for (auto& mesh : meshes) + const auto& meshes = lodAsset->GetMeshes(); + stats.m_meshCount = lodAsset->GetMeshes().size(); + for (const auto& mesh : meshes) { stats.m_vertCount += mesh.GetVertexCount(); stats.m_triCount += mesh.GetIndexCount() / 3; } - m_stats.m_meshStatsForLod.push_back(stats); + m_stats.m_meshStatsForLod.emplace_back(stats); } - m_stats.UpdateStringRepresentation(); // Refresh the tree when the model loads to update UI based on the model. AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast( @@ -238,8 +239,7 @@ namespace AZ // This is a bug with AssetManager [LYN-2249] auto temp = m_controller.m_configuration.m_modelAsset; - m_stats.m_meshStatsForLod.clear(); - m_stats.UpdateStringRepresentation(); + m_stats.m_meshStatsForLod.swap({}); SetDirty(); return BaseClass::OnConfigurationChanged(); diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp index 4fa4364569..268e568179 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp @@ -13,18 +13,45 @@ #include #include #include -#include namespace AZ { namespace Render { - void EditorMeshStats::Reflect(ReflectContext* context) + void EditorMeshStatsForLod::Reflect(ReflectContext* context) { + if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Field("meshCount", &EditorMeshStatsForLod::m_meshCount) + ->Field("vertCount", &EditorMeshStatsForLod::m_vertCount) + ->Field("triCount", &EditorMeshStatsForLod::m_triCount) + ; + + if (AZ::EditContext* editContext = serializeContext->GetEditContext()) + { + editContext->Class("EditorMeshStatsForLod", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &EditorMeshStatsForLod::m_meshCount, "Mesh Count", "") + ->Attribute(AZ::Edit::Attributes::ReadOnly, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &EditorMeshStatsForLod::m_vertCount, "Vert Count", "") + ->Attribute(AZ::Edit::Attributes::ReadOnly, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &EditorMeshStatsForLod::m_triCount, "Tri Count", "") + ->Attribute(AZ::Edit::Attributes::ReadOnly, true) + ; + } + } + } + + void EditorMeshStats::Reflect(ReflectContext* context) + { + EditorMeshStatsForLod::Reflect(context); + if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Field("stringRepresentation", &EditorMeshStats::m_stringRepresentation) + ->Field("meshStatsForLod", &EditorMeshStats::m_meshStatsForLod) ; if (AZ::EditContext* editContext = serializeContext->GetEditContext()) @@ -32,27 +59,13 @@ namespace AZ editContext->Class( "EditorMeshStats", "") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") - ->Attribute(AZ::Edit::Attributes::AutoExpand, false) - ->DataElement(AZ::Edit::UIHandlers::MultiLineEdit, &EditorMeshStats::m_stringRepresentation, "Mesh Stats", "") + ->DataElement(AZ::Edit::UIHandlers::Default, &EditorMeshStats::m_meshStatsForLod, "Mesh Stats", "") ->Attribute(AZ::Edit::Attributes::NameLabelOverride, "") - ->Attribute(AZ::Edit::Attributes::ReadOnly, true) + ->Attribute(AZ::Edit::Attributes::ContainerCanBeModified, false) + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) ; } } } - - void EditorMeshStats::UpdateStringRepresentation() - { - m_stringRepresentation = ""; - int lodIndex = 0; - for (auto& meshStatsForLod : m_meshStatsForLod) - { - m_stringRepresentation += AZStd::string::format("LOD: %d:\n", lodIndex++); - m_stringRepresentation += AZStd::string::format("\tMesh Count: %d\n", meshStatsForLod.m_meshCount); - m_stringRepresentation += AZStd::string::format("\tVert Count: %d\n", meshStatsForLod.m_vertCount); - m_stringRepresentation += AZStd::string::format("\tTriangle Count: %d\n", meshStatsForLod.m_triCount); - } - AZ::StringFunc::TrimWhiteSpace(m_stringRepresentation, true, true); - }; } // namespace Render } // namespace AZ diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h index a2cca39a82..111ec6d27b 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h @@ -26,9 +26,11 @@ namespace AZ AZ_RTTI(EditorMeshStatsForLod, "{626E3AEB-0F7A-4777-BAF1-2BBA8C1857ED}"); AZ_CLASS_ALLOCATOR(EditorMeshStatsForLod, SystemAllocator, 0); - int m_meshCount = 0; - int m_vertCount = 0; - int m_triCount = 0; + static void Reflect(ReflectContext* context); + + AZ::u32 m_meshCount = 0; + AZ::u32 m_vertCount = 0; + AZ::u32 m_triCount = 0; }; struct EditorMeshStats final @@ -37,10 +39,8 @@ namespace AZ AZ_CLASS_ALLOCATOR(EditorMeshStats, SystemAllocator, 0); static void Reflect(ReflectContext* context); - void UpdateStringRepresentation(); AZStd::vector m_meshStatsForLod; - AZStd::string m_stringRepresentation = {}; }; } // namespace Render } // namespace AZ