From 95465b18a41bbe9547c56e979fd780c3fcf42110 Mon Sep 17 00:00:00 2001 From: mnaumov Date: Wed, 9 Jun 2021 21:15:10 -0700 Subject: [PATCH] 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