From 4a42c32a4b6b4a624aeccae26ee3a74b022162ca Mon Sep 17 00:00:00 2001 From: pereslav Date: Wed, 7 Jul 2021 00:12:30 +0100 Subject: [PATCH 1/5] LYN-4989 Fixed player spawnable index. Build fix for ScriptCanvas gem when Profiling is on Signed-off-by: pereslav --- Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp | 2 +- .../Code/Include/ScriptCanvas/Execution/RuntimeComponent.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp index 841c22aa8b..488f891e06 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp +++ b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp @@ -735,7 +735,7 @@ namespace Multiplayer NetworkEntityHandle MultiplayerSystemComponent::SpawnDefaultPlayerPrefab() { - PrefabEntityId playerPrefabEntityId(AZ::Name(static_cast(sv_defaultPlayerSpawnAsset).c_str()), 1); + PrefabEntityId playerPrefabEntityId(AZ::Name(static_cast(sv_defaultPlayerSpawnAsset).c_str())); INetworkEntityManager::EntityList entityList = m_networkEntityManager.CreateEntitiesImmediate(playerPrefabEntityId, NetEntityRole::Authority, AZ::Transform::CreateIdentity()); NetworkEntityHandle controlledEntity; diff --git a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Execution/RuntimeComponent.cpp b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Execution/RuntimeComponent.cpp index 64d6a9339e..88ada9ddb1 100644 --- a/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Execution/RuntimeComponent.cpp +++ b/Gems/ScriptCanvas/Code/Include/ScriptCanvas/Execution/RuntimeComponent.cpp @@ -60,7 +60,7 @@ namespace ScriptCanvas void RuntimeComponent::Execute() { - AZ_PROFILE_SCOPE_DYNAMIC(AZ::Debug::ProfileCategory::ScriptCanvas, "RuntimeComponent::Execute (%s)", m_runtimeAsset.GetId().ToString().c_str()); + AZ_PROFILE_SCOPE_DYNAMIC(AZ::Debug::ProfileCategory::ScriptCanvas, "RuntimeComponent::Execute (%s)", m_runtimeOverrides.m_runtimeAsset.GetId().ToString().c_str()); AZ_Assert(m_executionState, "RuntimeComponent::Execute called without an execution state"); SC_EXECUTION_TRACE_GRAPH_ACTIVATED(CreateActivationInfo()); SCRIPT_CANVAS_PERFORMANCE_SCOPE_EXECUTION(m_executionState->GetScriptCanvasId(), m_runtimeOverrides.m_runtimeAsset.GetId()); @@ -116,7 +116,7 @@ namespace ScriptCanvas AZ_Assert(m_runtimeAsset.Get(), "RuntimeComponent::m_runtimeAsset AssetId: %s was valid, but the data was not pre-loaded, so this script will not run", m_runtimeOverrides.m_runtimeAsset.GetId().ToString().data()); #endif - AZ_PROFILE_SCOPE_DYNAMIC(AZ::Debug::ProfileCategory::ScriptCanvas, "RuntimeComponent::InitializeExecution (%s)", m_runtimeAsset.GetId().ToString().c_str()); + AZ_PROFILE_SCOPE_DYNAMIC(AZ::Debug::ProfileCategory::ScriptCanvas, "RuntimeComponent::InitializeExecution (%s)", m_runtimeOverrides.m_runtimeAsset.GetId().ToString().c_str()); SCRIPT_CANVAS_PERFORMANCE_SCOPE_INITIALIZATION(m_scriptCanvasId, m_runtimeOverrides.m_runtimeAsset.GetId()); m_executionState = ExecutionState::Create(ExecutionStateConfig(m_runtimeOverrides.m_runtimeAsset, *this)); From aca8a730a69adf3b2fd29ab5a154f24b9171cfdc Mon Sep 17 00:00:00 2001 From: Ken Pruiksma Date: Tue, 6 Jul 2021 19:42:12 -0500 Subject: [PATCH 2/5] Fixing simple light types appearing back at 0,0,0 after hiding/unhiding. Signed-off-by: Ken Pruiksma --- .../Code/Source/CoreLights/LightDelegateBase.inl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/LightDelegateBase.inl b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/LightDelegateBase.inl index 36c53c8fab..a84487749f 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/LightDelegateBase.inl +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/LightDelegateBase.inl @@ -134,6 +134,11 @@ namespace AZ // For lights that get their transform from the shape bus, force an OnShapeChanged to update the transform. OnShapeChanged(ShapeChangeReasons::TransformChanged); } + else + { + // OnShapeChanged() already calls this for delegates with a shape bus + HandleShapeChanged(); + } } } From ef1f95f1d0d7830fe41dde7b3ce69c7e8939cce9 Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Wed, 7 Jul 2021 02:21:09 -0700 Subject: [PATCH 3/5] [MeshOptimizer] Determine the original vertex index based on the position (#1562) * Determine the original vertex index based on the position The Assimp library does not expose the FBX control point indices. This change causes vertices that are close enough in their position to be considered as coming from the same control point. This allows the mesh optimizer to consider vertices with the same control point index (or "original vertex index" as it is called in the code) for deduplication. Signed-off-by: Chris Burel * Use a filter view instead of reimplementing a filter view Signed-off-by: Chris Burel * Don't attempt to weld similar vertices if there's blendshapes Signed-off-by: Chris Burel * Add test for the mesh optimizer's ability to weld nearby vertices Signed-off-by: Chris Burel * Add logging call to show mesh optimizer effect on vertex count Signed-off-by: Chris Burel * Use a bunch of temporaries in order to make `position` `const` Signed-off-by: Chris Burel --- .../SceneAPI/SceneData/Groups/MeshGroup.h | 24 ++--- Gems/SceneProcessing/Code/CMakeLists.txt | 1 + .../MeshOptimizer/MeshOptimizerComponent.cpp | 56 +++++++--- .../MeshOptimizerComponentTests.cpp | 100 ++++++++++++++++++ .../sceneprocessing_editor_tests_files.cmake | 1 + 5 files changed, 158 insertions(+), 24 deletions(-) create mode 100644 Gems/SceneProcessing/Code/Tests/MeshBuilder/MeshOptimizerComponentTests.cpp diff --git a/Code/Tools/SceneAPI/SceneData/Groups/MeshGroup.h b/Code/Tools/SceneAPI/SceneData/Groups/MeshGroup.h index c06c91a808..5b4c4612ad 100644 --- a/Code/Tools/SceneAPI/SceneData/Groups/MeshGroup.h +++ b/Code/Tools/SceneAPI/SceneData/Groups/MeshGroup.h @@ -28,27 +28,27 @@ namespace AZ } namespace SceneData { - class MeshGroup + class SCENE_DATA_CLASS MeshGroup : public DataTypes::IMeshGroup { public: AZ_RTTI(MeshGroup, "{07B356B7-3635-40B5-878A-FAC4EFD5AD86}", DataTypes::IMeshGroup); AZ_CLASS_ALLOCATOR(MeshGroup, SystemAllocator, 0) - MeshGroup(); - ~MeshGroup() override = default; + SCENE_DATA_API MeshGroup(); + SCENE_DATA_API ~MeshGroup() override = default; - const AZStd::string& GetName() const override; - void SetName(const AZStd::string& name); - void SetName(AZStd::string&& name) override; - const Uuid& GetId() const override; - void OverrideId(const Uuid& id) override; + SCENE_DATA_API const AZStd::string& GetName() const override; + SCENE_DATA_API void SetName(const AZStd::string& name); + SCENE_DATA_API void SetName(AZStd::string&& name) override; + SCENE_DATA_API const Uuid& GetId() const override; + SCENE_DATA_API void OverrideId(const Uuid& id) override; - Containers::RuleContainer& GetRuleContainer() override; - const Containers::RuleContainer& GetRuleContainerConst() const override; + SCENE_DATA_API Containers::RuleContainer& GetRuleContainer() override; + SCENE_DATA_API const Containers::RuleContainer& GetRuleContainerConst() const override; - DataTypes::ISceneNodeSelectionList& GetSceneNodeSelectionList() override; - const DataTypes::ISceneNodeSelectionList& GetSceneNodeSelectionList() const override; + SCENE_DATA_API DataTypes::ISceneNodeSelectionList& GetSceneNodeSelectionList() override; + SCENE_DATA_API const DataTypes::ISceneNodeSelectionList& GetSceneNodeSelectionList() const override; static void Reflect(AZ::ReflectContext* context); static bool VersionConverter(SerializeContext& context, SerializeContext::DataElementNode& classElement); diff --git a/Gems/SceneProcessing/Code/CMakeLists.txt b/Gems/SceneProcessing/Code/CMakeLists.txt index 9aa5bc6763..6fb95d8c00 100644 --- a/Gems/SceneProcessing/Code/CMakeLists.txt +++ b/Gems/SceneProcessing/Code/CMakeLists.txt @@ -111,6 +111,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) PRIVATE Gem::SceneProcessing.Editor.Static AZ::AzTest + AZ::SceneData ) ly_add_googletest( NAME Gem::SceneProcessing.Editor.Tests diff --git a/Gems/SceneProcessing/Code/Source/Generation/Components/MeshOptimizer/MeshOptimizerComponent.cpp b/Gems/SceneProcessing/Code/Source/Generation/Components/MeshOptimizer/MeshOptimizerComponent.cpp index e3eb617601..b8ab5bc961 100644 --- a/Gems/SceneProcessing/Code/Source/Generation/Components/MeshOptimizer/MeshOptimizerComponent.cpp +++ b/Gems/SceneProcessing/Code/Source/Generation/Components/MeshOptimizer/MeshOptimizerComponent.cpp @@ -106,7 +106,7 @@ namespace AZ::SceneGenerationComponents auto* serializeContext = azrtti_cast(context); if (serializeContext) { - serializeContext->Class()->Version(2); + serializeContext->Class()->Version(3); } } @@ -192,17 +192,12 @@ namespace AZ::SceneGenerationComponents const AZStd::vector> meshes = [](const SceneGraph& graph) { AZStd::vector> meshes; - for (auto it = graph.GetContentStorage().cbegin(); it != graph.GetContentStorage().cend(); ++it) + const auto meshNodes = Containers::MakeDerivedFilterView(graph.GetContentStorage()); + for (auto it = meshNodes.cbegin(); it != meshNodes.cend(); ++it) { - // Skip anything that isn't a mesh. - const auto* mesh = azdynamic_cast(it->get()); - if (!mesh) - { - continue; - } - // Get the mesh data and node index and store them in the vector as a pair, so we can iterate over them later. - meshes.emplace_back(mesh, graph.ConvertToNodeIndex(it)); + // The sequential calls to GetBaseIterator unwrap the layers of FilterIterators from the MakeDerivedFilterView + meshes.emplace_back(&(*it), graph.ConvertToNodeIndex(it.GetBaseIterator().GetBaseIterator().GetBaseIterator())); } return meshes; }(graph); @@ -287,6 +282,12 @@ namespace AZ::SceneGenerationComponents auto [optimizedMesh, optimizedUVs, optimizedTangents, optimizedBitangents, optimizedVertexColors, optimizedSkinWeights] = OptimizeMesh(mesh, mesh, uvDatas, tangentDatas, bitangentDatas, colorDatas, skinWeightDatas, meshGroup, hasBlendShapes); + AZ_TracePrintf(AZ::SceneAPI::Utilities::LogWindow, "Base mesh: %zu vertices, optimized mesh: %zu vertices, %0.02f%% of the original", + mesh->GetUsedControlPointCount(), + optimizedMesh->GetUsedControlPointCount(), + ((float)optimizedMesh->GetUsedControlPointCount() / (float)mesh->GetUsedControlPointCount()) * 100.0f + ); + const NodeIndex optimizedMeshNodeIndex = graph.AddChild(graph.GetNodeParent(nodeIndex), name.c_str(), AZStd::move(optimizedMesh)); auto addOptimizedNodes = [&graph, &optimizedMeshNodeIndex](const auto& originalNodeIndexes, auto& optimizedNodes) @@ -433,6 +434,12 @@ namespace AZ::SceneGenerationComponents const float weightThreshold = skinRule ? skinRule->GetWeightThreshold() : 0.001f; meshBuilder.SetSkinningInfo(ExtractSkinningInfo(meshData, skinWeights, maxWeightsPerVertex, weightThreshold)); + constexpr float positionTolerance = 0.0001f; + constexpr float positionToleranceReciprocal = 1.0f / positionTolerance; + AZStd::unordered_map positionMap{}; + + AZ::u32 currentOriginalVertexIndex = 0; + // Add the vertex data to all the layers const AZ::u32 faceCount = meshData->GetFaceCount(); for (AZ::u32 faceIndex = 0; faceIndex < faceCount; ++faceIndex) @@ -440,8 +447,33 @@ namespace AZ::SceneGenerationComponents meshBuilder.BeginPolygon(baseMesh->GetFaceMaterialId(faceIndex)); for (const AZ::u32 vertexIndex : meshData->GetFaceInfo(faceIndex).vertexIndex) { - const int orgVertexNumber = meshData->GetUsedPointIndexForControlPoint(meshData->GetControlPointIndex(vertexIndex)); - AZ_Assert(orgVertexNumber >= 0, "Invalid vertex number"); + const AZ::u32 orgVertexNumber = [&meshData, &hasBlendShapes, &vertexIndex, &positionMap, ¤tOriginalVertexIndex, positionTolerance, positionToleranceReciprocal]() -> AZ::u32 + { + if (hasBlendShapes) + { + // Don't attempt to weld similar vertices if there's blendshapes + // Welding the vertices here based on position could cause the vertices of a base shape to be + // welded, and the vertices of the blendshape to not be welded, resulting in a vertex count + // mismatch between the two + return meshData->GetUsedPointIndexForControlPoint(meshData->GetControlPointIndex(vertexIndex)); + } + + // Round the vertex position so that a float comparison can be made with entires in the positionMap + // pos = floor( x * 10 + 0.5) * 0.1 + const AZ::Vector3 position = AZ::Vector3( + AZ::Simd::Vec3::Floor( + (meshData->GetPosition(vertexIndex) * positionToleranceReciprocal + AZ::Vector3(0.5f)).GetSimdValue() + ) + ) * positionTolerance; + + const auto& [iter, didInsert] = positionMap.try_emplace(position, currentOriginalVertexIndex); + if (didInsert) + { + ++currentOriginalVertexIndex; + } + return iter->second; + }(); + orgVtxLayer->SetCurrentVertexValue(orgVertexNumber); posLayer->SetCurrentVertexValue(meshData->GetPosition(vertexIndex)); diff --git a/Gems/SceneProcessing/Code/Tests/MeshBuilder/MeshOptimizerComponentTests.cpp b/Gems/SceneProcessing/Code/Tests/MeshBuilder/MeshOptimizerComponentTests.cpp new file mode 100644 index 0000000000..f374cc833c --- /dev/null +++ b/Gems/SceneProcessing/Code/Tests/MeshBuilder/MeshOptimizerComponentTests.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. + * + * SPDX-License-Identifier: Apache-2.0 OR MIT + * + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace SceneProcessing +{ + using VertexDeduplicationFixture = SceneProcessing::InitSceneAPIFixture; + + TEST_F(VertexDeduplicationFixture, CanDeduplicateVertices) + { + AZ::ComponentApplication app; + AZ::Entity* systemEntity = app.Create({}, {}); + systemEntity->AddComponent(aznew AZ::MemoryComponent()); + systemEntity->AddComponent(aznew AZ::JobManagerComponent()); + systemEntity->Init(); + systemEntity->Activate(); + + AZ::SceneAPI::Containers::Scene scene("testScene"); + AZ::SceneAPI::Containers::SceneGraph& graph = scene.GetGraph(); + + // Create a simple plane with 2 triangles, 6 total vertices, 2 shared vertices + // 0 --- 1 + // | / | + // | / | + // | / | + // 2 --- 3 + const AZStd::array planeVertexPositions = { + AZ::Vector3{0.0f, 0.0f, 0.0f}, + AZ::Vector3{0.0f, 0.0f, 1.0f}, + AZ::Vector3{1.0f, 0.0f, 1.0f}, + AZ::Vector3{1.0f, 0.0f, 1.0f}, + AZ::Vector3{1.0f, 0.0f, 0.0f}, + AZ::Vector3{0.0f, 0.0f, 0.0f}, + }; + { + auto mesh = AZStd::make_unique(); + { + int i = 0; + for (const AZ::Vector3& position : planeVertexPositions) + { + mesh->AddPosition(position); + mesh->AddNormal(AZ::Vector3::CreateAxisY()); + + // This assumes that the data coming from the import process gives a unique control point + // index to every vertex. This follows the behavior of the AssImp library. + mesh->SetVertexIndexToControlPointIndexMap(i, i); + ++i; + } + } + mesh->AddFace({0, 1, 2}, 0); + mesh->AddFace({3, 4, 5}, 0); + + // The original source mesh should have 6 vertices + EXPECT_EQ(mesh->GetVertexCount(), planeVertexPositions.size()); + + graph.AddChild(graph.GetRoot(), "testMesh", AZStd::move(mesh)); + } + + auto meshGroup = AZStd::make_unique(); + meshGroup->GetSceneNodeSelectionList().AddSelectedNode("testMesh"); + scene.GetManifest().AddEntry(AZStd::move(meshGroup)); + + AZ::SceneGenerationComponents::MeshOptimizerComponent component; + AZ::SceneAPI::Events::GenerateSimplificationEventContext context(scene, "pc"); + component.OptimizeMeshes(context); + + AZ::SceneAPI::Containers::SceneGraph::NodeIndex optimizedNodeIndex = graph.Find(AZStd::string("testMesh").append(AZ::SceneAPI::Utilities::OptimizedMeshSuffix)); + ASSERT_TRUE(optimizedNodeIndex.IsValid()) << "Mesh optimizer did not add an optimized version of the mesh"; + + const auto& optimizedMesh = AZStd::rtti_pointer_cast(graph.GetNodeContent(optimizedNodeIndex)); + ASSERT_TRUE(optimizedMesh); + + // The optimized mesh should have 4 vertices, the 2 shared vertices are welded together + EXPECT_EQ(optimizedMesh->GetVertexCount(), 4); + + systemEntity->Deactivate(); + } +} // namespace SceneProcessing diff --git a/Gems/SceneProcessing/Code/sceneprocessing_editor_tests_files.cmake b/Gems/SceneProcessing/Code/sceneprocessing_editor_tests_files.cmake index 9ebe2291a3..c06d21233d 100644 --- a/Gems/SceneProcessing/Code/sceneprocessing_editor_tests_files.cmake +++ b/Gems/SceneProcessing/Code/sceneprocessing_editor_tests_files.cmake @@ -7,6 +7,7 @@ set(FILES Tests/InitSceneAPIFixture.h + Tests/MeshBuilder/MeshOptimizerComponentTests.cpp Tests/MeshBuilder/MeshBuilderTests.cpp Tests/MeshBuilder/MeshVerticesTests.cpp Tests/MeshBuilder/SkinInfluencesTests.cpp From 23c044037145dcf4cb06e29211c78dc982be4b18 Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Wed, 7 Jul 2021 12:39:01 +0100 Subject: [PATCH 4/5] tick system while in track view batch render. (#1899) As the batch render will disable Editor idle processing which handles the tick. Signed-off-by: amzn-sean <75276488+amzn-sean@users.noreply.github.com> --- Code/Editor/TrackView/SequenceBatchRenderDialog.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Code/Editor/TrackView/SequenceBatchRenderDialog.cpp b/Code/Editor/TrackView/SequenceBatchRenderDialog.cpp index e5a51051a2..08b0c1a952 100644 --- a/Code/Editor/TrackView/SequenceBatchRenderDialog.cpp +++ b/Code/Editor/TrackView/SequenceBatchRenderDialog.cpp @@ -13,6 +13,7 @@ #include "SequenceBatchRenderDialog.h" +#include #include // Qt @@ -1215,6 +1216,18 @@ void CSequenceBatchRenderDialog::OnKickIdleTimout() // All done with our custom OnKickIdle, restore editor idle. SetEnableEditorIdleProcessing(true); } + + //When we disable the editor idle processing. system tick is no longer invoked. + //so we call it here to ensure rendering + other systems are updated. + if (!m_editorIdleProcessingEnabled) + { + AZ::ComponentApplication* componentApplication = nullptr; + AZ::ComponentApplicationBus::BroadcastResult(componentApplication, &AZ::ComponentApplicationRequests::GetApplication); + if (componentApplication) + { + componentApplication->TickSystem(); + } + } } void CSequenceBatchRenderDialog::OnKickIdle() From 2ab250333726ce1f6ea7494ac7b7a0668757d348 Mon Sep 17 00:00:00 2001 From: Benjamin Jillich <43751992+amzn-jillich@users.noreply.github.com> Date: Wed, 7 Jul 2021 05:28:53 -0700 Subject: [PATCH 5/5] Revert "[MeshOptimizer] Determine the original vertex index based on the position (#1562)" (#1902) This reverts commit ef1f95f1d0d7830fe41dde7b3ce69c7e8939cce9. Signed-off-by: Benjamin Jillich --- .../SceneAPI/SceneData/Groups/MeshGroup.h | 24 ++--- Gems/SceneProcessing/Code/CMakeLists.txt | 1 - .../MeshOptimizer/MeshOptimizerComponent.cpp | 56 +++------- .../MeshOptimizerComponentTests.cpp | 100 ------------------ .../sceneprocessing_editor_tests_files.cmake | 1 - 5 files changed, 24 insertions(+), 158 deletions(-) delete mode 100644 Gems/SceneProcessing/Code/Tests/MeshBuilder/MeshOptimizerComponentTests.cpp diff --git a/Code/Tools/SceneAPI/SceneData/Groups/MeshGroup.h b/Code/Tools/SceneAPI/SceneData/Groups/MeshGroup.h index 5b4c4612ad..c06c91a808 100644 --- a/Code/Tools/SceneAPI/SceneData/Groups/MeshGroup.h +++ b/Code/Tools/SceneAPI/SceneData/Groups/MeshGroup.h @@ -28,27 +28,27 @@ namespace AZ } namespace SceneData { - class SCENE_DATA_CLASS MeshGroup + class MeshGroup : public DataTypes::IMeshGroup { public: AZ_RTTI(MeshGroup, "{07B356B7-3635-40B5-878A-FAC4EFD5AD86}", DataTypes::IMeshGroup); AZ_CLASS_ALLOCATOR(MeshGroup, SystemAllocator, 0) - SCENE_DATA_API MeshGroup(); - SCENE_DATA_API ~MeshGroup() override = default; + MeshGroup(); + ~MeshGroup() override = default; - SCENE_DATA_API const AZStd::string& GetName() const override; - SCENE_DATA_API void SetName(const AZStd::string& name); - SCENE_DATA_API void SetName(AZStd::string&& name) override; - SCENE_DATA_API const Uuid& GetId() const override; - SCENE_DATA_API void OverrideId(const Uuid& id) override; + const AZStd::string& GetName() const override; + void SetName(const AZStd::string& name); + void SetName(AZStd::string&& name) override; + const Uuid& GetId() const override; + void OverrideId(const Uuid& id) override; - SCENE_DATA_API Containers::RuleContainer& GetRuleContainer() override; - SCENE_DATA_API const Containers::RuleContainer& GetRuleContainerConst() const override; + Containers::RuleContainer& GetRuleContainer() override; + const Containers::RuleContainer& GetRuleContainerConst() const override; - SCENE_DATA_API DataTypes::ISceneNodeSelectionList& GetSceneNodeSelectionList() override; - SCENE_DATA_API const DataTypes::ISceneNodeSelectionList& GetSceneNodeSelectionList() const override; + DataTypes::ISceneNodeSelectionList& GetSceneNodeSelectionList() override; + const DataTypes::ISceneNodeSelectionList& GetSceneNodeSelectionList() const override; static void Reflect(AZ::ReflectContext* context); static bool VersionConverter(SerializeContext& context, SerializeContext::DataElementNode& classElement); diff --git a/Gems/SceneProcessing/Code/CMakeLists.txt b/Gems/SceneProcessing/Code/CMakeLists.txt index 6fb95d8c00..9aa5bc6763 100644 --- a/Gems/SceneProcessing/Code/CMakeLists.txt +++ b/Gems/SceneProcessing/Code/CMakeLists.txt @@ -111,7 +111,6 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) PRIVATE Gem::SceneProcessing.Editor.Static AZ::AzTest - AZ::SceneData ) ly_add_googletest( NAME Gem::SceneProcessing.Editor.Tests diff --git a/Gems/SceneProcessing/Code/Source/Generation/Components/MeshOptimizer/MeshOptimizerComponent.cpp b/Gems/SceneProcessing/Code/Source/Generation/Components/MeshOptimizer/MeshOptimizerComponent.cpp index b8ab5bc961..e3eb617601 100644 --- a/Gems/SceneProcessing/Code/Source/Generation/Components/MeshOptimizer/MeshOptimizerComponent.cpp +++ b/Gems/SceneProcessing/Code/Source/Generation/Components/MeshOptimizer/MeshOptimizerComponent.cpp @@ -106,7 +106,7 @@ namespace AZ::SceneGenerationComponents auto* serializeContext = azrtti_cast(context); if (serializeContext) { - serializeContext->Class()->Version(3); + serializeContext->Class()->Version(2); } } @@ -192,12 +192,17 @@ namespace AZ::SceneGenerationComponents const AZStd::vector> meshes = [](const SceneGraph& graph) { AZStd::vector> meshes; - const auto meshNodes = Containers::MakeDerivedFilterView(graph.GetContentStorage()); - for (auto it = meshNodes.cbegin(); it != meshNodes.cend(); ++it) + for (auto it = graph.GetContentStorage().cbegin(); it != graph.GetContentStorage().cend(); ++it) { + // Skip anything that isn't a mesh. + const auto* mesh = azdynamic_cast(it->get()); + if (!mesh) + { + continue; + } + // Get the mesh data and node index and store them in the vector as a pair, so we can iterate over them later. - // The sequential calls to GetBaseIterator unwrap the layers of FilterIterators from the MakeDerivedFilterView - meshes.emplace_back(&(*it), graph.ConvertToNodeIndex(it.GetBaseIterator().GetBaseIterator().GetBaseIterator())); + meshes.emplace_back(mesh, graph.ConvertToNodeIndex(it)); } return meshes; }(graph); @@ -282,12 +287,6 @@ namespace AZ::SceneGenerationComponents auto [optimizedMesh, optimizedUVs, optimizedTangents, optimizedBitangents, optimizedVertexColors, optimizedSkinWeights] = OptimizeMesh(mesh, mesh, uvDatas, tangentDatas, bitangentDatas, colorDatas, skinWeightDatas, meshGroup, hasBlendShapes); - AZ_TracePrintf(AZ::SceneAPI::Utilities::LogWindow, "Base mesh: %zu vertices, optimized mesh: %zu vertices, %0.02f%% of the original", - mesh->GetUsedControlPointCount(), - optimizedMesh->GetUsedControlPointCount(), - ((float)optimizedMesh->GetUsedControlPointCount() / (float)mesh->GetUsedControlPointCount()) * 100.0f - ); - const NodeIndex optimizedMeshNodeIndex = graph.AddChild(graph.GetNodeParent(nodeIndex), name.c_str(), AZStd::move(optimizedMesh)); auto addOptimizedNodes = [&graph, &optimizedMeshNodeIndex](const auto& originalNodeIndexes, auto& optimizedNodes) @@ -434,12 +433,6 @@ namespace AZ::SceneGenerationComponents const float weightThreshold = skinRule ? skinRule->GetWeightThreshold() : 0.001f; meshBuilder.SetSkinningInfo(ExtractSkinningInfo(meshData, skinWeights, maxWeightsPerVertex, weightThreshold)); - constexpr float positionTolerance = 0.0001f; - constexpr float positionToleranceReciprocal = 1.0f / positionTolerance; - AZStd::unordered_map positionMap{}; - - AZ::u32 currentOriginalVertexIndex = 0; - // Add the vertex data to all the layers const AZ::u32 faceCount = meshData->GetFaceCount(); for (AZ::u32 faceIndex = 0; faceIndex < faceCount; ++faceIndex) @@ -447,33 +440,8 @@ namespace AZ::SceneGenerationComponents meshBuilder.BeginPolygon(baseMesh->GetFaceMaterialId(faceIndex)); for (const AZ::u32 vertexIndex : meshData->GetFaceInfo(faceIndex).vertexIndex) { - const AZ::u32 orgVertexNumber = [&meshData, &hasBlendShapes, &vertexIndex, &positionMap, ¤tOriginalVertexIndex, positionTolerance, positionToleranceReciprocal]() -> AZ::u32 - { - if (hasBlendShapes) - { - // Don't attempt to weld similar vertices if there's blendshapes - // Welding the vertices here based on position could cause the vertices of a base shape to be - // welded, and the vertices of the blendshape to not be welded, resulting in a vertex count - // mismatch between the two - return meshData->GetUsedPointIndexForControlPoint(meshData->GetControlPointIndex(vertexIndex)); - } - - // Round the vertex position so that a float comparison can be made with entires in the positionMap - // pos = floor( x * 10 + 0.5) * 0.1 - const AZ::Vector3 position = AZ::Vector3( - AZ::Simd::Vec3::Floor( - (meshData->GetPosition(vertexIndex) * positionToleranceReciprocal + AZ::Vector3(0.5f)).GetSimdValue() - ) - ) * positionTolerance; - - const auto& [iter, didInsert] = positionMap.try_emplace(position, currentOriginalVertexIndex); - if (didInsert) - { - ++currentOriginalVertexIndex; - } - return iter->second; - }(); - + const int orgVertexNumber = meshData->GetUsedPointIndexForControlPoint(meshData->GetControlPointIndex(vertexIndex)); + AZ_Assert(orgVertexNumber >= 0, "Invalid vertex number"); orgVtxLayer->SetCurrentVertexValue(orgVertexNumber); posLayer->SetCurrentVertexValue(meshData->GetPosition(vertexIndex)); diff --git a/Gems/SceneProcessing/Code/Tests/MeshBuilder/MeshOptimizerComponentTests.cpp b/Gems/SceneProcessing/Code/Tests/MeshBuilder/MeshOptimizerComponentTests.cpp deleted file mode 100644 index f374cc833c..0000000000 --- a/Gems/SceneProcessing/Code/Tests/MeshBuilder/MeshOptimizerComponentTests.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace SceneProcessing -{ - using VertexDeduplicationFixture = SceneProcessing::InitSceneAPIFixture; - - TEST_F(VertexDeduplicationFixture, CanDeduplicateVertices) - { - AZ::ComponentApplication app; - AZ::Entity* systemEntity = app.Create({}, {}); - systemEntity->AddComponent(aznew AZ::MemoryComponent()); - systemEntity->AddComponent(aznew AZ::JobManagerComponent()); - systemEntity->Init(); - systemEntity->Activate(); - - AZ::SceneAPI::Containers::Scene scene("testScene"); - AZ::SceneAPI::Containers::SceneGraph& graph = scene.GetGraph(); - - // Create a simple plane with 2 triangles, 6 total vertices, 2 shared vertices - // 0 --- 1 - // | / | - // | / | - // | / | - // 2 --- 3 - const AZStd::array planeVertexPositions = { - AZ::Vector3{0.0f, 0.0f, 0.0f}, - AZ::Vector3{0.0f, 0.0f, 1.0f}, - AZ::Vector3{1.0f, 0.0f, 1.0f}, - AZ::Vector3{1.0f, 0.0f, 1.0f}, - AZ::Vector3{1.0f, 0.0f, 0.0f}, - AZ::Vector3{0.0f, 0.0f, 0.0f}, - }; - { - auto mesh = AZStd::make_unique(); - { - int i = 0; - for (const AZ::Vector3& position : planeVertexPositions) - { - mesh->AddPosition(position); - mesh->AddNormal(AZ::Vector3::CreateAxisY()); - - // This assumes that the data coming from the import process gives a unique control point - // index to every vertex. This follows the behavior of the AssImp library. - mesh->SetVertexIndexToControlPointIndexMap(i, i); - ++i; - } - } - mesh->AddFace({0, 1, 2}, 0); - mesh->AddFace({3, 4, 5}, 0); - - // The original source mesh should have 6 vertices - EXPECT_EQ(mesh->GetVertexCount(), planeVertexPositions.size()); - - graph.AddChild(graph.GetRoot(), "testMesh", AZStd::move(mesh)); - } - - auto meshGroup = AZStd::make_unique(); - meshGroup->GetSceneNodeSelectionList().AddSelectedNode("testMesh"); - scene.GetManifest().AddEntry(AZStd::move(meshGroup)); - - AZ::SceneGenerationComponents::MeshOptimizerComponent component; - AZ::SceneAPI::Events::GenerateSimplificationEventContext context(scene, "pc"); - component.OptimizeMeshes(context); - - AZ::SceneAPI::Containers::SceneGraph::NodeIndex optimizedNodeIndex = graph.Find(AZStd::string("testMesh").append(AZ::SceneAPI::Utilities::OptimizedMeshSuffix)); - ASSERT_TRUE(optimizedNodeIndex.IsValid()) << "Mesh optimizer did not add an optimized version of the mesh"; - - const auto& optimizedMesh = AZStd::rtti_pointer_cast(graph.GetNodeContent(optimizedNodeIndex)); - ASSERT_TRUE(optimizedMesh); - - // The optimized mesh should have 4 vertices, the 2 shared vertices are welded together - EXPECT_EQ(optimizedMesh->GetVertexCount(), 4); - - systemEntity->Deactivate(); - } -} // namespace SceneProcessing diff --git a/Gems/SceneProcessing/Code/sceneprocessing_editor_tests_files.cmake b/Gems/SceneProcessing/Code/sceneprocessing_editor_tests_files.cmake index c06d21233d..9ebe2291a3 100644 --- a/Gems/SceneProcessing/Code/sceneprocessing_editor_tests_files.cmake +++ b/Gems/SceneProcessing/Code/sceneprocessing_editor_tests_files.cmake @@ -7,7 +7,6 @@ set(FILES Tests/InitSceneAPIFixture.h - Tests/MeshBuilder/MeshOptimizerComponentTests.cpp Tests/MeshBuilder/MeshBuilderTests.cpp Tests/MeshBuilder/MeshVerticesTests.cpp Tests/MeshBuilder/SkinInfluencesTests.cpp