From 672b9fd956d0af3aed5711c32a269e8f0c35848c Mon Sep 17 00:00:00 2001 From: mnaumov Date: Tue, 8 Jun 2021 19:21:40 -0700 Subject: [PATCH 1/8] [ATOM-5389] MeshComponent stats --- .../Code/Source/Mesh/EditorMeshComponent.cpp | 30 ++++++++++ .../Code/Source/Mesh/EditorMeshComponent.h | 4 ++ .../Code/Source/Mesh/EditorMeshStats.cpp | 58 +++++++++++++++++++ .../Code/Source/Mesh/EditorMeshStats.h | 49 ++++++++++++++++ .../Source/Mesh/MeshComponentController.cpp | 2 +- .../Source/Mesh/MeshComponentController.h | 2 +- ...egration_commonfeatures_editor_files.cmake | 2 + 7 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp create mode 100644 Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp index e1c9026c74..2315c38095 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp @@ -25,12 +25,16 @@ namespace AZ void EditorMeshComponent::Reflect(AZ::ReflectContext* context) { BaseClass::Reflect(context); + EditorMeshStats::Reflect(context); if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) { + serializeContext->RegisterGenericType(); + serializeContext->Class() ->Version(2, ConvertToEditorRenderComponentAdapter<1>) ->Field("addMaterialComponentFlag", &EditorMeshComponent::m_addMaterialComponentFlag) + ->Field("meshStats", &EditorMeshComponent::m_stats) ; // This shouldn't be registered here, but is required to make a vector from EditorMeshComponentTypeId. This can be removed when one of the following happens: @@ -55,6 +59,8 @@ namespace AZ ->Attribute(AZ::Edit::Attributes::ButtonText, "Add Material Component") ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorMeshComponent::AddEditorMaterialComponent) ->Attribute(AZ::Edit::Attributes::Visibility, &EditorMeshComponent::GetEditorMaterialComponentVisibility) + ->DataElement(AZ::Edit::UIHandlers::Default, &EditorMeshComponent::m_stats, "Mesh Stats", "Mesh statistics.") + ->Attribute(AZ::Edit::Attributes::AutoExpand, false) ; editContext->Class( @@ -204,6 +210,25 @@ namespace AZ void EditorMeshComponent::OnModelReady(const Data::Asset& /*modelAsset*/, const Data::Instance& /*model*/) { + m_stats.m_meshStatsForLod.clear(); + if (m_controller.GetConfiguration().IsAssetSet()) + { + auto lods = m_controller.GetConfiguration().m_modelAsset->GetLodAssets(); + for (auto& lod : lods) + { + EditorMeshStatsForLod stats; + auto meshes = lod->GetMeshes(); + stats.m_meshCount = lod->GetMeshes().size(); + for (auto& mesh : meshes) + { + stats.m_vertCount += mesh.GetVertexCount(); + stats.m_triCount += mesh.GetIndexCount() / 3; + } + m_stats.m_meshStatsForLod.push_back(stats); + } + } + m_stats.UpdateStringRepresentation(); + // Refresh the tree when the model loads to update UI based on the model. AzToolsFramework::ToolsApplicationEvents::Bus::Broadcast( &AzToolsFramework::ToolsApplicationEvents::InvalidatePropertyDisplay, @@ -216,6 +241,11 @@ namespace AZ // places it in a bad state, which happens in OnConfigurationChanged base function. // This is a bug with AssetManager [LYN-2249] auto temp = m_controller.m_configuration.m_modelAsset; + + m_stats.m_meshStatsForLod.clear(); + m_stats.UpdateStringRepresentation(); + SetDirty(); + return BaseClass::OnConfigurationChanged(); } } // namespace Render diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.h index 41ea80f8d1..93966bfc74 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.h @@ -18,6 +18,7 @@ #include #include #include +#include namespace AZ { @@ -33,6 +34,7 @@ namespace AZ , private AzToolsFramework::EditorComponentSelectionRequestsBus::Handler , private AzFramework::EntityDebugDisplayEventBus::Handler , private MeshComponentNotificationBus::Handler + , private Data::AssetBus::Handler { public: using BaseClass = EditorRenderComponentAdapter; @@ -71,6 +73,8 @@ namespace AZ // Flag used for button placement bool m_addMaterialComponentFlag = false; + + EditorMeshStats m_stats; }; } // namespace Render } // namespace AZ diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp new file mode 100644 index 0000000000..4fa4364569 --- /dev/null +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp @@ -0,0 +1,58 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + void EditorMeshStats::Reflect(ReflectContext* context) + { + if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) + { + serializeContext->Class() + ->Field("stringRepresentation", &EditorMeshStats::m_stringRepresentation) + ; + + if (AZ::EditContext* editContext = serializeContext->GetEditContext()) + { + editContext->Class( + "EditorMeshStats", "") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AutoExpand, false) + ->DataElement(AZ::Edit::UIHandlers::MultiLineEdit, &EditorMeshStats::m_stringRepresentation, "Mesh Stats", "") + ->Attribute(AZ::Edit::Attributes::NameLabelOverride, "") + ->Attribute(AZ::Edit::Attributes::ReadOnly, 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 new file mode 100644 index 0000000000..baf422d984 --- /dev/null +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h @@ -0,0 +1,49 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#pragma once + +#include +#include +#include +#include + +namespace AZ +{ + namespace Render + { + struct EditorMeshStatsForLod final + { + 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; + }; + + struct EditorMeshStats final + { + AZ_RTTI(EditorMeshStats, "{68D0D3EF-17BB-46EA-B98F-51355402CCD6}"); + AZ_CLASS_ALLOCATOR(EditorMeshStats, SystemAllocator, 0); + + static void Reflect(ReflectContext* context); + + AZStd::vector m_meshStatsForLod; + + void UpdateStringRepresentation(); + + AZStd::string m_stringRepresentation = {}; + }; + } // namespace Render +} // namespace AZ diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp index e7eecd3c7f..6c9b4e6514 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp @@ -49,7 +49,7 @@ namespace AZ } } - bool MeshComponentConfig::IsAssetSet() + bool MeshComponentConfig::IsAssetSet() const { return m_modelAsset.GetId().IsValid(); } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h index 4d63e5e88d..e44fad07df 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h @@ -44,7 +44,7 @@ namespace AZ static void Reflect(AZ::ReflectContext* context); // Editor helper functions - bool IsAssetSet(); + bool IsAssetSet() const; AZStd::vector> GetLodOverrideValues(); Data::Asset m_modelAsset = { AZ::Data::AssetLoadBehavior::QueueLoad }; diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake b/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake index 9072cd54f2..6c45015e39 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake @@ -50,6 +50,8 @@ set(FILES Source/Material/MaterialThumbnail.h Source/Mesh/EditorMeshComponent.h Source/Mesh/EditorMeshComponent.cpp + Source/Mesh/EditorMeshStats.h + Source/Mesh/EditorMeshStats.cpp Source/Mesh/EditorMeshSystemComponent.cpp Source/Mesh/EditorMeshSystemComponent.h Source/Mesh/MeshThumbnail.h From 2923d8b962ff3c357a9213097e7ee7bf9d3b7054 Mon Sep 17 00:00:00 2001 From: mnaumov Date: Tue, 8 Jun 2021 19:35:40 -0700 Subject: [PATCH 2/8] some cleanup --- .../Code/Source/Mesh/EditorMeshComponent.cpp | 20 ++++++++----------- .../Code/Source/Mesh/EditorMeshComponent.h | 2 +- .../Code/Source/Mesh/EditorMeshStats.h | 5 +---- .../Source/Mesh/MeshComponentController.cpp | 2 +- .../Source/Mesh/MeshComponentController.h | 2 +- 5 files changed, 12 insertions(+), 19 deletions(-) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp index 2315c38095..474369a984 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp @@ -211,21 +211,17 @@ namespace AZ void EditorMeshComponent::OnModelReady(const Data::Asset& /*modelAsset*/, const Data::Instance& /*model*/) { m_stats.m_meshStatsForLod.clear(); - if (m_controller.GetConfiguration().IsAssetSet()) + for (auto& lod : m_controller.GetConfiguration().m_modelAsset->GetLodAssets()) { - auto lods = m_controller.GetConfiguration().m_modelAsset->GetLodAssets(); - for (auto& lod : lods) + EditorMeshStatsForLod stats; + auto meshes = lod->GetMeshes(); + stats.m_meshCount = lod->GetMeshes().size(); + for (auto& mesh : meshes) { - EditorMeshStatsForLod stats; - auto meshes = lod->GetMeshes(); - stats.m_meshCount = lod->GetMeshes().size(); - for (auto& mesh : meshes) - { - stats.m_vertCount += mesh.GetVertexCount(); - stats.m_triCount += mesh.GetIndexCount() / 3; - } - m_stats.m_meshStatsForLod.push_back(stats); + stats.m_vertCount += mesh.GetVertexCount(); + stats.m_triCount += mesh.GetIndexCount() / 3; } + m_stats.m_meshStatsForLod.push_back(stats); } m_stats.UpdateStringRepresentation(); diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.h index 93966bfc74..3397540a92 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.h @@ -34,7 +34,6 @@ namespace AZ , private AzToolsFramework::EditorComponentSelectionRequestsBus::Handler , private AzFramework::EntityDebugDisplayEventBus::Handler , private MeshComponentNotificationBus::Handler - , private Data::AssetBus::Handler { public: using BaseClass = EditorRenderComponentAdapter; @@ -74,6 +73,7 @@ namespace AZ // Flag used for button placement bool m_addMaterialComponentFlag = false; + // Stats for current mesh asset EditorMeshStats m_stats; }; } // namespace Render diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h index baf422d984..a2cca39a82 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h @@ -26,7 +26,6 @@ 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; @@ -38,11 +37,9 @@ namespace AZ AZ_CLASS_ALLOCATOR(EditorMeshStats, SystemAllocator, 0); static void Reflect(ReflectContext* context); - - AZStd::vector m_meshStatsForLod; - void UpdateStringRepresentation(); + AZStd::vector m_meshStatsForLod; AZStd::string m_stringRepresentation = {}; }; } // namespace Render diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp index 6c9b4e6514..e7eecd3c7f 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.cpp @@ -49,7 +49,7 @@ namespace AZ } } - bool MeshComponentConfig::IsAssetSet() const + bool MeshComponentConfig::IsAssetSet() { return m_modelAsset.GetId().IsValid(); } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h index e44fad07df..4d63e5e88d 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/MeshComponentController.h @@ -44,7 +44,7 @@ namespace AZ static void Reflect(AZ::ReflectContext* context); // Editor helper functions - bool IsAssetSet() const; + bool IsAssetSet(); AZStd::vector> GetLodOverrideValues(); Data::Asset m_modelAsset = { AZ::Data::AssetLoadBehavior::QueueLoad }; From e07cf79babd06eec1cc7264f6e24448492f48de3 Mon Sep 17 00:00:00 2001 From: mnaumov Date: Tue, 8 Jun 2021 19:37:43 -0700 Subject: [PATCH 3/8] removed duplicate decription --- .../CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp index 474369a984..3176bfe37b 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp @@ -59,7 +59,7 @@ namespace AZ ->Attribute(AZ::Edit::Attributes::ButtonText, "Add Material Component") ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorMeshComponent::AddEditorMaterialComponent) ->Attribute(AZ::Edit::Attributes::Visibility, &EditorMeshComponent::GetEditorMaterialComponentVisibility) - ->DataElement(AZ::Edit::UIHandlers::Default, &EditorMeshComponent::m_stats, "Mesh Stats", "Mesh statistics.") + ->DataElement(AZ::Edit::UIHandlers::Default, &EditorMeshComponent::m_stats, "Mesh Stats", "") ->Attribute(AZ::Edit::Attributes::AutoExpand, false) ; From 1f2572fe8aa589a53c8d1644e5523bf422d11ded Mon Sep 17 00:00:00 2001 From: mnaumov Date: Wed, 9 Jun 2021 13:26:42 -0700 Subject: [PATCH 4/8] 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 From 95465b18a41bbe9547c56e979fd780c3fcf42110 Mon Sep 17 00:00:00 2001 From: mnaumov Date: Wed, 9 Jun 2021 21:15:10 -0700 Subject: [PATCH 5/8] Custom serializer for mesh stats to exclude from serializetion --- .../Code/Source/Mesh/EditorMeshStats.cpp | 10 +++- .../Source/Mesh/EditorMeshStatsSerializer.cpp | 54 +++++++++++++++++++ .../Source/Mesh/EditorMeshStatsSerializer.h | 40 ++++++++++++++ ...egration_commonfeatures_editor_files.cmake | 2 + 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStatsSerializer.cpp create mode 100644 Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStatsSerializer.h diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp index 268e568179..2f65ca83df 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp @@ -10,9 +10,12 @@ * */ -#include #include #include +#include + +#include +#include namespace AZ { @@ -48,6 +51,11 @@ namespace AZ { EditorMeshStatsForLod::Reflect(context); + if (auto jsonContext = azrtti_cast(context)) + { + jsonContext->Serializer()->HandlesType(); + } + if (AZ::SerializeContext* serializeContext = azrtti_cast(context)) { serializeContext->Class() diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStatsSerializer.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStatsSerializer.cpp new file mode 100644 index 0000000000..ad32c745be --- /dev/null +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStatsSerializer.cpp @@ -0,0 +1,54 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include +#include + +namespace AZ +{ + namespace Render + { + AZ_CLASS_ALLOCATOR_IMPL(JsonEditorMeshStatsSerializer, AZ::SystemAllocator, 0); + + JsonSerializationResult::Result JsonEditorMeshStatsSerializer::Load( + [[maybe_unused]] void* outputValue, + [[maybe_unused]] const Uuid& outputValueTypeId, + [[maybe_unused]] const rapidjson::Value& inputValue, + JsonDeserializerContext& context) + { + namespace JSR = JsonSerializationResult; + + JSR::ResultCode result(JSR::Tasks::ReadField); + + return context.Report( + result, + "Successfully loaded EditorMeshStats information."); + } + + JsonSerializationResult::Result JsonEditorMeshStatsSerializer::Store( + [[maybe_unused]] rapidjson::Value& outputValue, + [[maybe_unused]] const void* inputValue, + [[maybe_unused]] const void* defaultValue, + [[maybe_unused]] const Uuid& valueTypeId, + JsonSerializerContext& context) + { + namespace JSR = JsonSerializationResult; + + JSR::ResultCode result(JSR::Tasks::WriteValue); + + return context.Report( + result, + "Successfully stored EditorMeshStats information."); + } + + } // namespace Render +} // namespace AZ diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStatsSerializer.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStatsSerializer.h new file mode 100644 index 0000000000..733fc3dc97 --- /dev/null +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStatsSerializer.h @@ -0,0 +1,40 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#pragma once + +#include +#include + +namespace AZ +{ + namespace Render + { + // Custom JSON serializer for Mesh Stats + // Mesh stats should not be serialized with EditorMeshComponent, because they are calculated based on active model, + // so the serializer simply provides empty load/store functions + class JsonEditorMeshStatsSerializer : public BaseJsonSerializer + { + public: + AZ_RTTI(JsonEditorMeshStatsSerializer, "{571290F5-98C9-45AE-BC8C-E40968B5BA6F}", BaseJsonSerializer); + AZ_CLASS_ALLOCATOR_DECL; + + JsonSerializationResult::Result Load( + void* outputValue, const Uuid& outputValueTypeId, const rapidjson::Value& inputValue, + JsonDeserializerContext& context) override; + + JsonSerializationResult::Result Store( + rapidjson::Value& outputValue, const void* inputValue, const void* defaultValue, const Uuid& valueTypeId, + JsonSerializerContext& context) override; + }; + } // namespace Render +} // namespace AZ diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake b/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake index 6c45015e39..bd50a27ccc 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/atomlyintegration_commonfeatures_editor_files.cmake @@ -54,6 +54,8 @@ set(FILES Source/Mesh/EditorMeshStats.cpp Source/Mesh/EditorMeshSystemComponent.cpp Source/Mesh/EditorMeshSystemComponent.h + Source/Mesh/EditorMeshStatsSerializer.cpp + Source/Mesh/EditorMeshStatsSerializer.h Source/Mesh/MeshThumbnail.h Source/Mesh/MeshThumbnail.cpp Source/PostProcess/EditorPostFxLayerComponent.cpp From e1d2115cabcf961d777daf9c444a728debf431c6 Mon Sep 17 00:00:00 2001 From: mnaumov Date: Thu, 10 Jun 2021 12:05:30 -0700 Subject: [PATCH 6/8] ElementName override --- .../CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp | 6 ++++++ .../CommonFeatures/Code/Source/Mesh/EditorMeshStats.h | 1 + 2 files changed, 7 insertions(+) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp index 2f65ca83df..0830b6d83f 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.cpp @@ -71,9 +71,15 @@ namespace AZ ->Attribute(AZ::Edit::Attributes::NameLabelOverride, "") ->Attribute(AZ::Edit::Attributes::ContainerCanBeModified, false) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->Attribute(AZ::Edit::Attributes::IndexedChildNameLabelOverride, &EditorMeshStats::GetLodLabel) ; } } } + + AZStd::string EditorMeshStats::GetLodLabel(int index) const + { + return AZStd::string::format("LOD %d", index); + } } // 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 111ec6d27b..6bdce7c008 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshStats.h @@ -39,6 +39,7 @@ namespace AZ AZ_CLASS_ALLOCATOR(EditorMeshStats, SystemAllocator, 0); static void Reflect(ReflectContext* context); + AZStd::string GetLodLabel(int index) const; AZStd::vector m_meshStatsForLod; }; From d53b5a0bed97d7efb48b04b599cb4d5860f96a7b Mon Sep 17 00:00:00 2001 From: mnaumov Date: Thu, 10 Jun 2021 14:37:02 -0700 Subject: [PATCH 7/8] PR feedback --- .../CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp index 3c5063a69e..a2f113f1e1 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp @@ -217,13 +217,13 @@ namespace AZ { EditorMeshStatsForLod stats; const auto& meshes = lodAsset->GetMeshes(); - stats.m_meshCount = lodAsset->GetMeshes().size(); + stats.m_meshCount = meshes.size(); for (const auto& mesh : meshes) { stats.m_vertCount += mesh.GetVertexCount(); stats.m_triCount += mesh.GetIndexCount() / 3; } - m_stats.m_meshStatsForLod.emplace_back(stats); + m_stats.m_meshStatsForLod.emplace_back(AZStd::move(stats)); } // Refresh the tree when the model loads to update UI based on the model. From 68c0989aa1a8ab164b5498f0f8d8b1ead95e389c Mon Sep 17 00:00:00 2001 From: mnaumov Date: Thu, 10 Jun 2021 17:38:13 -0700 Subject: [PATCH 8/8] MeshStats collapsed by default --- .../CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/Mesh/EditorMeshComponent.cpp index a2f113f1e1..3adcaa495b 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, true) + ->Attribute(AZ::Edit::Attributes::AutoExpand, false) ; editContext->Class(