From 91de09cff532b066938d34c832afd3306c1188c2 Mon Sep 17 00:00:00 2001 From: Benjamin Jillich <43751992+amzn-jillich@users.noreply.github.com> Date: Mon, 12 Jul 2021 23:32:35 -0700 Subject: [PATCH] EMotion FX: Root bone not initialized without opening Scene Settings (#2088) * User provided model was exporting correctly with an .assetinfo while it was not when just placing the .fbx file in the project folder. * Turned out that the best matching root bone was set by opening the Scene Settings for the first time, so after saving it again it worked correctly. * We're now chosing the best matching root bone when initializing the actor group, which fixes the issue. Signed-off-by: Benjamin Jillich --- .../Behaviors/ActorGroupBehavior.cpp | 1 + .../SceneAPIExt/Groups/ActorGroup.cpp | 20 +++++++++++++++++++ .../Pipeline/SceneAPIExt/Groups/ActorGroup.h | 2 +- .../Pipeline/SceneAPIExt/Groups/IActorGroup.h | 6 ++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Behaviors/ActorGroupBehavior.cpp b/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Behaviors/ActorGroupBehavior.cpp index c3202398b4..1e9c14d2e0 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Behaviors/ActorGroupBehavior.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Behaviors/ActorGroupBehavior.cpp @@ -143,6 +143,7 @@ namespace EMotionFX Group::ActorGroup* group = azrtti_cast(&target); group->SetName(AZ::SceneAPI::DataTypes::Utilities::CreateUniqueName(scene.GetName(), scene.GetManifest())); + group->SetBestMatchingRootBone(scene.GetGraph()); // LOD Rule need to be built first in the actor, so we know which mesh and bone belongs to LOD. // After this call, LOD rule will be populated with all the LOD bones diff --git a/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/ActorGroup.cpp b/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/ActorGroup.cpp index e4065f58e0..b623086bc1 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/ActorGroup.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/ActorGroup.cpp @@ -9,10 +9,14 @@ #include #include #include +#include +#include +#include #include #include #include #include +#include #include #include #include @@ -76,6 +80,22 @@ namespace EMotionFX m_selectedRootBone = selectedRootBone; } + void ActorGroup::SetBestMatchingRootBone(const AZ::SceneAPI::Containers::SceneGraph& sceneGraph) + { + auto nameContentView = AZ::SceneAPI::Containers::Views::MakePairView(sceneGraph.GetNameStorage(), sceneGraph.GetContentStorage()); + auto graphDownwardsView = AZ::SceneAPI::Containers::Views::MakeSceneGraphDownwardsView( + sceneGraph, sceneGraph.GetRoot(), nameContentView.begin(), true); + + for (auto it = graphDownwardsView.begin(); it != graphDownwardsView.end(); ++it) + { + if (it->second && it->second->RTTI_IsTypeOf(AZ::SceneData::GraphData::RootBoneData::TYPEINFO_Uuid())) + { + SetSelectedRootBone(it->first.GetPath()); + return; + } + } + } + void ActorGroup::Reflect(AZ::ReflectContext* context) { AZ::SerializeContext* serializeContext = azrtti_cast(context); diff --git a/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/ActorGroup.h b/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/ActorGroup.h index fddb0d6afc..0725b3e88b 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/ActorGroup.h +++ b/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/ActorGroup.h @@ -45,8 +45,8 @@ namespace EMotionFX // IActorGroup overrides const AZStd::string& GetSelectedRootBone() const override; - void SetSelectedRootBone(const AZStd::string& selectedRootBone) override; + void SetBestMatchingRootBone(const AZ::SceneAPI::Containers::SceneGraph& sceneGraph) override; static void Reflect(AZ::ReflectContext* context); static bool IActorGroupVersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement); diff --git a/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/IActorGroup.h b/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/IActorGroup.h index 398ec2c559..b57a9dfb13 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/IActorGroup.h +++ b/Gems/EMotionFX/Code/EMotionFX/Pipeline/SceneAPIExt/Groups/IActorGroup.h @@ -10,6 +10,11 @@ #include #include +namespace AZ::SceneAPI::Containers +{ + class SceneGraph; +} + namespace EMotionFX { namespace Pipeline @@ -26,6 +31,7 @@ namespace EMotionFX virtual const AZStd::string& GetSelectedRootBone() const = 0; virtual void SetSelectedRootBone(const AZStd::string& selectedRootBone) = 0; + virtual void SetBestMatchingRootBone(const AZ::SceneAPI::Containers::SceneGraph& sceneGraph) = 0; }; } }