Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,57 @@
/*
* 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 <SceneAPI/SceneCore/Components/BehaviorComponent.h>
#include <SceneAPI/SceneCore/Events/ManifestMetaInfoBus.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
class AnimationGroup
: public SceneCore::BehaviorComponent
, public Events::ManifestMetaInfoBus::Handler
, public Events::AssetImportRequestBus::Handler
{
public:
AZ_COMPONENT(AnimationGroup, "{CE7FEBE4-ACA3-41B8-9154-9B9E09A95A06}", SceneCore::BehaviorComponent);
~AnimationGroup() override = default;
void Activate() override;
void Deactivate() override;
static void Reflect(ReflectContext* context);
// ManifestMetaInfo
void GetCategoryAssignments(CategoryRegistrationList& categories, const Containers::Scene& scene) override;
void InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target) override;
// AssetImportRequest
Events::ProcessingResult UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication requester) override;
private:
Events::ProcessingResult BuildDefault(Containers::Scene& scene) const;
Events::ProcessingResult UpdateAnimationGroups(Containers::Scene& scene) const;
bool SceneHasAnimationGroup(const Containers::Scene& scene) const;
static const int s_animationsPreferredTabOrder;
};
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,174 @@
/*
* 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 <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/algorithm.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/Views/SceneGraphDownwardsIterator.h>
#include <SceneAPI/SceneCore/Containers/Views/PairIterator.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IAnimationData.h>
#include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.h>
#include <SceneAPI/SceneData/Groups/AnimationGroup.h>
#include <SceneAPI/SceneData/Behaviors/AnimationGroup.h>
#include <SceneAPI/SceneData/GraphData/RootBoneData.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
const int AnimationGroup::s_animationsPreferredTabOrder = 2;
void AnimationGroup::Activate()
{
}
void AnimationGroup::Deactivate()
{
}
void AnimationGroup::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<AnimationGroup, BehaviorComponent>()->Version(1);
}
}
void AnimationGroup::GetCategoryAssignments(CategoryRegistrationList& categories, const Containers::Scene& scene)
{
if (SceneHasAnimationGroup(scene) || Utilities::DoesSceneGraphContainDataLike<DataTypes::IAnimationData>(scene, false))
{
categories.emplace_back("Animations", SceneData::AnimationGroup::TYPEINFO_Uuid(), s_animationsPreferredTabOrder);
}
}
void AnimationGroup::InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target)
{
if (!target.RTTI_IsTypeOf(SceneData::AnimationGroup::TYPEINFO_Uuid()))
{
return;
}
SceneData::AnimationGroup* group = azrtti_cast<SceneData::AnimationGroup*>(&target);
group->SetName(DataTypes::Utilities::CreateUniqueName<DataTypes::IAnimationGroup>(scene.GetName(), scene.GetManifest()));
const Containers::SceneGraph &graph = scene.GetGraph();
auto nameStorage = graph.GetNameStorage();
auto contentStorage = graph.GetContentStorage();
auto nameContentView = Containers::Views::MakePairView(nameStorage, contentStorage);
AZStd::string shallowestRootBoneName;
auto graphDownwardsView = Containers::Views::MakeSceneGraphDownwardsView<Containers::Views::BreadthFirst>(graph, graph.GetRoot(), nameContentView.begin(), true);
for (auto it = graphDownwardsView.begin(); it != graphDownwardsView.end(); ++it)
{
if (!it->second)
{
continue;
}
if (it->second->RTTI_IsTypeOf(AZ::SceneData::GraphData::RootBoneData::TYPEINFO_Uuid()))
{
shallowestRootBoneName = it->first.GetPath();
break;
}
}
group->SetSelectedRootBone(shallowestRootBoneName);
Containers::SceneGraph::ContentStorageConstData graphContent = graph.GetContentStorage();
auto animationData = AZStd::find_if(graphContent.begin(), graphContent.end(), Containers::DerivedTypeFilter<DataTypes::IAnimationData>());
if (animationData == graphContent.end())
{
return;
}
const DataTypes::IAnimationData* animation = azrtti_cast<const DataTypes::IAnimationData*>(animationData->get());
uint32_t frameCount = aznumeric_caster(animation->GetKeyFrameCount());
group->SetStartFrame(0);
group->SetEndFrame(frameCount > 0 ? frameCount - 1 : 0);
}
Events::ProcessingResult AnimationGroup::UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication /*requester*/)
{
if (action == ManifestAction::ConstructDefault)
{
return BuildDefault(scene);
}
else if (action == ManifestAction::Update)
{
return UpdateAnimationGroups(scene);
}
else
{
return Events::ProcessingResult::Ignored;
}
}
Events::ProcessingResult AnimationGroup::BuildDefault(Containers::Scene& scene) const
{
if (SceneHasAnimationGroup(scene) || !Utilities::DoesSceneGraphContainDataLike<DataTypes::IAnimationData>(scene, true))
{
return Events::ProcessingResult::Ignored;
}
// There are animations but no animation group, so add a default animation group to the manifest.
AZStd::shared_ptr<SceneData::AnimationGroup> group = AZStd::make_shared<SceneData::AnimationGroup>();
// This is a group that's generated automatically so may not be saved to disk but would need to be recreated
// in the same way again. To guarantee the same uuid, generate a stable one instead.
group->OverrideId(DataTypes::Utilities::CreateStableUuid(scene, SceneData::AnimationGroup::TYPEINFO_Uuid()));
EBUS_EVENT(Events::ManifestMetaInfoBus, InitializeObject, scene, *group);
scene.GetManifest().AddEntry(AZStd::move(group));
return Events::ProcessingResult::Success;
}
Events::ProcessingResult AnimationGroup::UpdateAnimationGroups(Containers::Scene& scene) const
{
bool updated = false;
Containers::SceneManifest& manifest = scene.GetManifest();
auto valueStorage = manifest.GetValueStorage();
auto view = Containers::MakeDerivedFilterView<SceneData::AnimationGroup>(valueStorage);
for (SceneData::AnimationGroup& group : view)
{
if (group.GetName().empty())
{
group.SetName(DataTypes::Utilities::CreateUniqueName<DataTypes::IAnimationGroup>(scene.GetName(), scene.GetManifest()));
updated = true;
}
if (group.GetId().IsNull())
{
// When the uuid is null it's likely because the manifest has been updated from an older version. Include the
// name of the group as there could be multiple groups.
group.OverrideId(DataTypes::Utilities::CreateStableUuid(scene, SceneData::AnimationGroup::TYPEINFO_Uuid(), group.GetName()));
updated = true;
}
}
return updated ? Events::ProcessingResult::Success : Events::ProcessingResult::Ignored;
}
bool AnimationGroup::SceneHasAnimationGroup(const Containers::Scene& scene) const
{
const Containers::SceneManifest& manifest = scene.GetManifest();
Containers::SceneManifest::ValueStorageConstData manifestData = manifest.GetValueStorage();
auto animationGroup = AZStd::find_if(manifestData.begin(), manifestData.end(), Containers::DerivedTypeFilter<DataTypes::IAnimationGroup>());
return animationGroup != manifestData.end();
}
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,170 @@
/*
* 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 <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/algorithm.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.h>
#include <SceneAPI/SceneCore/Containers/Views/PairIterator.h>
#include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
#include <SceneAPI/SceneCore/Containers/Views/SceneGraphChildIterator.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshData.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IBoneData.h>
#include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
#include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
#include <SceneAPI/SceneData/Groups/MeshGroup.h>
#include <SceneAPI/SceneData/Behaviors/MeshGroup.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
const int MeshGroup::s_meshGroupPreferredTabOrder = 0;
void MeshGroup::Activate()
{
Events::ManifestMetaInfoBus::Handler::BusConnect();
Events::AssetImportRequestBus::Handler::BusConnect();
}
void MeshGroup::Deactivate()
{
Events::AssetImportRequestBus::Handler::BusDisconnect();
Events::ManifestMetaInfoBus::Handler::BusDisconnect();
}
void MeshGroup::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<MeshGroup, BehaviorComponent>()->Version(1);
}
}
void MeshGroup::GetCategoryAssignments(CategoryRegistrationList& categories, const Containers::Scene& scene)
{
if (SceneHasMeshGroup(scene) || Utilities::DoesSceneGraphContainDataLike<DataTypes::IMeshData>(scene, false))
{
categories.emplace_back("Meshes", SceneData::MeshGroup::TYPEINFO_Uuid(), s_meshGroupPreferredTabOrder);
}
}
void MeshGroup::InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target)
{
if (!target.RTTI_IsTypeOf(SceneData::MeshGroup::TYPEINFO_Uuid()))
{
return;
}
SceneData::MeshGroup* group = azrtti_cast<SceneData::MeshGroup*>(&target);
group->SetName(DataTypes::Utilities::CreateUniqueName<DataTypes::IMeshGroup>(scene.GetName(), scene.GetManifest()));
Utilities::SceneGraphSelector::SelectAll(scene.GetGraph(), group->GetSceneNodeSelectionList());
const Containers::SceneGraph& graph = scene.GetGraph();
auto nameStorage = graph.GetNameStorage();
auto contentStorage = graph.GetContentStorage();
auto keyValueView = Containers::Views::MakePairView(nameStorage, contentStorage);
auto filteredView = Containers::Views::MakeFilterView(keyValueView, Containers::DerivedTypeFilter<DataTypes::IMeshData>());
for (auto it = filteredView.begin(); it != filteredView.end(); ++it)
{
AZStd::set<Crc32> types;
auto keyValueIterator = it.GetBaseIterator();
Containers::SceneGraph::NodeIndex index = graph.ConvertToNodeIndex(keyValueIterator.GetFirstIterator());
EBUS_EVENT(Events::GraphMetaInfoBus, GetVirtualTypes, types, scene, index);
if (!types.empty())
{
// Mesh is not a standard static mesh, but a special type so remove it from the selected list.
group->GetSceneNodeSelectionList().RemoveSelectedNode(it->first.GetPath());
}
}
}
Events::ProcessingResult MeshGroup::UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication /*requester*/)
{
if (action == ManifestAction::ConstructDefault)
{
return BuildDefault(scene);
}
else if (action == ManifestAction::Update)
{
return UpdateMeshGroups(scene);
}
else
{
return Events::ProcessingResult::Ignored;
}
}
Events::ProcessingResult MeshGroup::BuildDefault(Containers::Scene& scene) const
{
if (SceneHasMeshGroup(scene) || !Utilities::DoesSceneGraphContainDataLike<DataTypes::IMeshData>(scene, true) || Utilities::DoesSceneGraphContainDataLike<DataTypes::IBoneData>(scene, true))
{
return Events::ProcessingResult::Ignored;
}
// There are meshes but no mesh group, so add a default mesh group to the manifest.
AZStd::shared_ptr<SceneData::MeshGroup> group = AZStd::make_shared<SceneData::MeshGroup>();
// This is a group that's generated automatically so may not be saved to disk but would need to be recreated
// in the same way again. To guarantee the same uuid, generate a stable one instead.
group->OverrideId(DataTypes::Utilities::CreateStableUuid(scene, MeshGroup::TYPEINFO_Uuid()));
EBUS_EVENT(Events::ManifestMetaInfoBus, InitializeObject, scene, *group);
scene.GetManifest().AddEntry(AZStd::move(group));
return Events::ProcessingResult::Success;
}
Events::ProcessingResult MeshGroup::UpdateMeshGroups(Containers::Scene& scene) const
{
bool updated = false;
Containers::SceneManifest& manifest = scene.GetManifest();
auto valueStorage = manifest.GetValueStorage();
auto view = Containers::MakeDerivedFilterView<SceneData::MeshGroup>(valueStorage);
for (SceneData::MeshGroup& group : view)
{
if (group.GetName().empty())
{
group.SetName(DataTypes::Utilities::CreateUniqueName<DataTypes::IMeshGroup>(scene.GetName(), scene.GetManifest()));
}
if (group.GetId().IsNull())
{
// When the uuid it's null is likely because the manifest has been updated from an older version. Include the
// name of the group as there could be multiple groups.
group.OverrideId(DataTypes::Utilities::CreateStableUuid(scene, MeshGroup::TYPEINFO_Uuid(), group.GetName()));
}
Utilities::SceneGraphSelector::UpdateNodeSelection(scene.GetGraph(), group.GetSceneNodeSelectionList());
updated = true;
}
return updated ? Events::ProcessingResult::Success : Events::ProcessingResult::Ignored;
}
bool MeshGroup::SceneHasMeshGroup(const Containers::Scene& scene) const
{
const Containers::SceneManifest& manifest = scene.GetManifest();
Containers::SceneManifest::ValueStorageConstData manifestData = manifest.GetValueStorage();
auto meshGroup = AZStd::find_if(manifestData.begin(), manifestData.end(), Containers::DerivedTypeFilter<DataTypes::IMeshGroup>());
return meshGroup != manifestData.end();
}
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,192 @@
/*
* 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 <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/algorithm.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/Views/SceneGraphDownwardsIterator.h>
#include <SceneAPI/SceneCore/Containers/Views/PairIterator.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IBoneData.h>
#include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.h>
#include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
#include <SceneAPI/SceneData/Groups/SkeletonGroup.h>
#include <SceneAPI/SceneData/Behaviors/SkeletonGroup.h>
#include <SceneAPI/SceneData/GraphData/RootBoneData.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
const int SkeletonGroup::s_rigsPreferredTabOrder = 1;
void SkeletonGroup::Activate()
{
}
void SkeletonGroup::Deactivate()
{
}
void SkeletonGroup::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<SkeletonGroup, BehaviorComponent>()->Version(1);
}
}
void SkeletonGroup::GetCategoryAssignments(CategoryRegistrationList& categories, const Containers::Scene& scene)
{
if (SceneHasSkeletonGroup(scene) || Utilities::DoesSceneGraphContainDataLike<DataTypes::IBoneData>(scene, false))
{
categories.emplace_back("Rigs", SceneData::SkeletonGroup::TYPEINFO_Uuid(), s_rigsPreferredTabOrder);
}
}
void SkeletonGroup::InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target)
{
if (!m_isDefaultConstructing && target.RTTI_IsTypeOf(SceneData::SkeletonGroup::TYPEINFO_Uuid()))
{
SceneData::SkeletonGroup* group = azrtti_cast<SceneData::SkeletonGroup*>(&target);
group->SetName(DataTypes::Utilities::CreateUniqueName<DataTypes::ISkeletonGroup>(scene.GetName(), scene.GetManifest()));
const Containers::SceneGraph &graph = scene.GetGraph();
auto contentStorage = graph.GetContentStorage();
auto nameStorage = graph.GetNameStorage();
auto nameContentView = Containers::Views::MakePairView(nameStorage, contentStorage);
AZStd::string shallowestRootBoneName;
auto graphDownwardsView = Containers::Views::MakeSceneGraphDownwardsView<Containers::Views::BreadthFirst>(graph, graph.GetRoot(), nameContentView.begin(), true);
for (auto it = graphDownwardsView.begin(); it != graphDownwardsView.end(); ++it)
{
if (!it->second)
{
continue;
}
if (it->second->RTTI_IsTypeOf(AZ::SceneData::GraphData::RootBoneData::TYPEINFO_Uuid()))
{
shallowestRootBoneName = it->first.GetPath();
break;
}
}
group->SetSelectedRootBone(shallowestRootBoneName);
}
}
Events::ProcessingResult SkeletonGroup::UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication /*requester*/)
{
if (action == ManifestAction::ConstructDefault)
{
return BuildDefault(scene);
}
else if (action == ManifestAction::Update)
{
return UpdateSkeletonGroups(scene);
}
else
{
return Events::ProcessingResult::Ignored;
}
}
Events::ProcessingResult SkeletonGroup::BuildDefault(Containers::Scene& scene)
{
if (SceneHasSkeletonGroup(scene))
{
return Events::ProcessingResult::Ignored;
}
const Containers::SceneGraph &graph = scene.GetGraph();
auto contentStorage = graph.GetContentStorage();
auto nameStorage = graph.GetNameStorage();
auto nameContentView = Containers::Views::MakePairView(nameStorage, contentStorage);
bool hasCreatedSkeletons = false;
m_isDefaultConstructing = true;
for (auto it = nameContentView.begin(); it != nameContentView.end(); ++it)
{
if (!it->second || !it->second->RTTI_IsTypeOf(AZ::SceneData::GraphData::RootBoneData::TYPEINFO_Uuid()))
{
continue;
}
// Check if this is a virtual type. There are no known virtual types supported by skeletons so this skeleton
// pretends to be something that's not understood by this behavior, so skip it.
AZStd::set<Crc32> virtualTypes;
Events::GraphMetaInfoBus::Broadcast(&Events::GraphMetaInfoBus::Events::GetVirtualTypes, virtualTypes,
scene, graph.ConvertToNodeIndex(it.GetFirstIterator()));
if (!virtualTypes.empty())
{
continue;
}
AZStd::shared_ptr<SceneData::SkeletonGroup> group = AZStd::make_shared<SceneData::SkeletonGroup>();
AZStd::string name = DataTypes::Utilities::CreateUniqueName<DataTypes::ISkeletonGroup>(scene.GetName(), it->first.GetName(), scene.GetManifest());
// This is a group that's generated automatically so may not be saved to disk but would need to be recreated
// in the same way again. To guarantee the same uuid, generate a stable one instead.
group->OverrideId(DataTypes::Utilities::CreateStableUuid(scene, SceneData::SkeletonGroup::TYPEINFO_Uuid(), name));
group->SetName(AZStd::move(name));
group->SetSelectedRootBone(it->first.GetPath());
Events::ManifestMetaInfoBus::Broadcast(&Events::ManifestMetaInfoBus::Events::InitializeObject, scene, *group);
scene.GetManifest().AddEntry(AZStd::move(group));
hasCreatedSkeletons = true;
}
m_isDefaultConstructing = false;
return hasCreatedSkeletons ? Events::ProcessingResult::Success : Events::ProcessingResult::Ignored;
}
Events::ProcessingResult SkeletonGroup::UpdateSkeletonGroups(Containers::Scene& scene) const
{
bool updated = false;
Containers::SceneManifest& manifest = scene.GetManifest();
auto valueStorage = manifest.GetValueStorage();
auto view = Containers::MakeDerivedFilterView<SceneData::SkeletonGroup>(valueStorage);
for (SceneData::SkeletonGroup& group : view)
{
if (group.GetName().empty())
{
group.SetName(DataTypes::Utilities::CreateUniqueName<DataTypes::ISkeletonGroup>(scene.GetName(), scene.GetManifest()));
updated = true;
}
if (group.GetId().IsNull())
{
// When the uuid is null it's likely because the manifest has been updated from an older version. Include the
// name of the group as there could be multiple groups.
group.OverrideId(DataTypes::Utilities::CreateStableUuid(scene, SceneData::SkeletonGroup::TYPEINFO_Uuid(), group.GetName()));
updated = true;
}
}
return updated ? Events::ProcessingResult::Success : Events::ProcessingResult::Ignored;
}
bool SkeletonGroup::SceneHasSkeletonGroup(const Containers::Scene& scene) const
{
const Containers::SceneManifest& manifest = scene.GetManifest();
Containers::SceneManifest::ValueStorageConstData manifestData = manifest.GetValueStorage();
auto skeletonGroup = AZStd::find_if(manifestData.begin(), manifestData.end(), Containers::DerivedTypeFilter<DataTypes::ISkeletonGroup>());
return skeletonGroup != manifestData.end();
}
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,197 @@
/*
* 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 <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/algorithm.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
#include <SceneAPI/SceneCore/Containers/Views/SceneGraphChildIterator.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshData.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/ISkinWeightData.h>
#include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.h>
#include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
#include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.h>
#include <SceneAPI/SceneData/Groups/SkinGroup.h>
#include <SceneAPI/SceneData/Behaviors/SkinGroup.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
const char* SkinGroup::s_skinVirtualTypeName = "Skin";
Crc32 SkinGroup::s_skinVirtualType = AZ_CRC(SkinGroup::s_skinVirtualTypeName, 0x0279681e);
const int SkinGroup::s_rigsPreferredTabOrder = 1;
void SkinGroup::Activate()
{
}
void SkinGroup::Deactivate()
{
}
void SkinGroup::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<SkinGroup, BehaviorComponent>()->Version(1);
}
}
void SkinGroup::GetCategoryAssignments(CategoryRegistrationList& categories, const Containers::Scene& scene)
{
if (SceneHasSkinGroup(scene) || Utilities::DoesSceneGraphContainDataLike<DataTypes::ISkinWeightData>(scene, false))
{
categories.emplace_back("Rigs", SceneData::SkinGroup::TYPEINFO_Uuid(), s_rigsPreferredTabOrder);
}
}
void SkinGroup::InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target)
{
SceneData::SkinGroup* group = azrtti_cast<SceneData::SkinGroup*>(&target);
if (!group)
{
return;
}
group->SetName(DataTypes::Utilities::CreateUniqueName<DataTypes::ISkinGroup>(scene.GetName(), scene.GetManifest()));
Utilities::SceneGraphSelector::UnselectAll(scene.GetGraph(), group->GetSceneNodeSelectionList());
const Containers::SceneGraph& graph = scene.GetGraph();
Containers::SceneGraph::ContentStorageConstData graphContent = graph.GetContentStorage();
auto view = Containers::Views::MakeFilterView(graphContent, Containers::DerivedTypeFilter<DataTypes::IMeshData>());
for (auto iter = view.begin(); iter != view.end(); ++iter)
{
Containers::SceneGraph::NodeIndex nodeIndex = graph.ConvertToNodeIndex(iter.GetBaseIterator());
auto children = Containers::Views::MakeSceneGraphChildView(graph, nodeIndex, iter.GetBaseIterator(), false);
if (AZStd::find_if(children.begin(), children.end(),
Containers::DerivedTypeFilter<DataTypes::ISkinWeightData>()) != children.end())
{
group->GetSceneNodeSelectionList().AddSelectedNode(graph.GetNodeName(nodeIndex).GetPath());
}
}
Utilities::SceneGraphSelector::UpdateNodeSelection(scene.GetGraph(), group->GetSceneNodeSelectionList());
}
Events::ProcessingResult SkinGroup::UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication /*requester*/)
{
if (action == ManifestAction::ConstructDefault)
{
return BuildDefault(scene);
}
else if (action == ManifestAction::Update)
{
return UpdateGroups(scene);
}
else
{
return Events::ProcessingResult::Ignored;
}
}
void SkinGroup::GetVirtualTypes(AZStd::set<Crc32>& types, const Containers::Scene& scene,
Containers::SceneGraph::NodeIndex node)
{
if (types.find(s_skinVirtualType) != types.end())
{
// Virtual type for skins has already been added.
return;
}
const Containers::SceneGraph& graph = scene.GetGraph();
auto children = Containers::Views::MakeSceneGraphChildView(graph, node, graph.GetContentStorage().begin(), true);
if (AZStd::find_if(children.begin(), children.end(),
Containers::DerivedTypeFilter<DataTypes::ISkinWeightData>()) != children.end())
{
types.insert(s_skinVirtualType);
}
}
void SkinGroup::GetVirtualTypeName(AZStd::string& name, Crc32 type)
{
if (type == s_skinVirtualType)
{
name = s_skinVirtualTypeName;
}
}
void SkinGroup::GetAllVirtualTypes(AZStd::set<Crc32>& types)
{
if (types.find(s_skinVirtualType) == types.end())
{
types.insert(s_skinVirtualType);
}
}
Events::ProcessingResult SkinGroup::BuildDefault(Containers::Scene& scene) const
{
if (SceneHasSkinGroup(scene) || !Utilities::DoesSceneGraphContainDataLike<DataTypes::ISkinWeightData>(scene, true))
{
return Events::ProcessingResult::Ignored;
}
// There are skins but no skin group, so add a default skin group to the manifest.
AZStd::shared_ptr<SceneData::SkinGroup> group = AZStd::make_shared<SceneData::SkinGroup>();
// This is a group that's generated automatically so may not be saved to disk but would need to be recreated
// in the same way again. To guarantee the same uuid, generate a stable one instead.
group->OverrideId(DataTypes::Utilities::CreateStableUuid(scene, SceneData::SkinGroup::TYPEINFO_Uuid()));
EBUS_EVENT(Events::ManifestMetaInfoBus, InitializeObject, scene, *group);
scene.GetManifest().AddEntry(AZStd::move(group));
return Events::ProcessingResult::Success;
}
Events::ProcessingResult SkinGroup::UpdateGroups(Containers::Scene& scene) const
{
bool updated = false;
Containers::SceneManifest& manifest = scene.GetManifest();
auto valueStorage = manifest.GetValueStorage();
auto view = Containers::MakeDerivedFilterView<SceneData::SkinGroup>(valueStorage);
for (SceneData::SkinGroup& group : view)
{
if (group.GetName().empty())
{
group.SetName(DataTypes::Utilities::CreateUniqueName<DataTypes::ISkinGroup>(scene.GetName(), scene.GetManifest()));
}
if (group.GetId().IsNull())
{
// When the uuid is null it's likely because the manifest has been updated from an older version. Include the
// name of the group as there could be multiple groups.
group.OverrideId(DataTypes::Utilities::CreateStableUuid(scene, SceneData::SkinGroup::TYPEINFO_Uuid(), group.GetName()));
}
Utilities::SceneGraphSelector::UpdateNodeSelection(scene.GetGraph(), group.GetSceneNodeSelectionList());
updated = true;
}
return updated ? Events::ProcessingResult::Success : Events::ProcessingResult::Ignored;
}
bool SkinGroup::SceneHasSkinGroup(const Containers::Scene& scene) const
{
const Containers::SceneManifest& manifest = scene.GetManifest();
Containers::SceneManifest::ValueStorageConstData manifestData = manifest.GetValueStorage();
auto skinGroup = AZStd::find_if(manifestData.begin(), manifestData.end(), Containers::DerivedTypeFilter<DataTypes::ISkinGroup>());
return skinGroup != manifestData.end();
}
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,145 @@
/*
* 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 <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzToolsFramework/Debug/TraceContext.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/SceneManifest.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Containers/Views/PairIterator.h>
#include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
#include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISkinGroup.h>
#include <SceneAPI/SceneCore/DataTypes/Rules/IMaterialRule.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IBlendShapeData.h>
#include <SceneAPI/SceneData/Rules/BlendShapeRule.h>
#include <SceneAPI/SceneData/Rules/MaterialRule.h>
#include <SceneAPI/SceneData/Behaviors/BlendShapeRuleBehavior.h>
#include <SceneAPI/SceneData/ManifestBase/SceneNodeSelectionList.h>
namespace AZ
{
namespace SceneAPI
{
namespace SceneData
{
void BlendShapeRuleBehavior::Activate()
{
Events::ManifestMetaInfoBus::Handler::BusConnect();
Events::AssetImportRequestBus::Handler::BusConnect();
}
void BlendShapeRuleBehavior::Deactivate()
{
Events::AssetImportRequestBus::Handler::BusDisconnect();
Events::ManifestMetaInfoBus::Handler::BusDisconnect();
}
void BlendShapeRuleBehavior::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<BlendShapeRuleBehavior, BehaviorComponent>()->Version(1);
}
}
void BlendShapeRuleBehavior::InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target)
{
if (target.RTTI_IsTypeOf(DataTypes::ISkinGroup::TYPEINFO_Uuid()))
{
SceneData::SceneNodeSelectionList selection;
size_t blendShapeCount = SelectBlendShapes(scene, selection);
if (blendShapeCount > 0)
{
AZStd::shared_ptr<SceneData::BlendShapeRule> blendShapeRule = AZStd::make_shared<SceneData::BlendShapeRule>();
selection.CopyTo(blendShapeRule->GetNodeSelectionList());
DataTypes::ISkinGroup* skinGroup = azrtti_cast<DataTypes::ISkinGroup*>(&target);
skinGroup->GetRuleContainer().AddRule(AZStd::move(blendShapeRule));
}
}
else if (target.RTTI_IsTypeOf(SceneData::BlendShapeRule::TYPEINFO_Uuid()))
{
SceneData::BlendShapeRule* rule = azrtti_cast<SceneData::BlendShapeRule*>(&target);
SelectBlendShapes(scene, rule->GetSceneNodeSelectionList());
}
}
size_t BlendShapeRuleBehavior::SelectBlendShapes(const Containers::Scene& scene, DataTypes::ISceneNodeSelectionList& selection) const
{
Utilities::SceneGraphSelector::UnselectAll(scene.GetGraph(), selection);
size_t blendShapeCount = 0;
const Containers::SceneGraph& graph = scene.GetGraph();
auto contentStorage = graph.GetContentStorage();
auto nameStorage = graph.GetNameStorage();
auto keyValueView = Containers::Views::MakePairView(nameStorage, contentStorage);
auto filteredView = Containers::Views::MakeFilterView(keyValueView, Containers::DerivedTypeFilter<DataTypes::IBlendShapeData>());
for (auto it = filteredView.begin(); it != filteredView.end(); ++it)
{
AZStd::set<Crc32> types;
auto keyValueIterator = it.GetBaseIterator();
Containers::SceneGraph::NodeIndex index = graph.ConvertToNodeIndex(keyValueIterator.GetFirstIterator());
EBUS_EVENT(Events::GraphMetaInfoBus, GetVirtualTypes, types, scene, index);
if (types.find(Events::GraphMetaInfo::GetIgnoreVirtualType()) == types.end())
{
selection.AddSelectedNode(it->first.GetPath());
blendShapeCount++;
}
}
return blendShapeCount;
}
Events::ProcessingResult BlendShapeRuleBehavior::UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication /*requester*/)
{
if (action == ManifestAction::Update)
{
UpdateBlendShapeRules(scene);
return Events::ProcessingResult::Success;
}
else
{
return Events::ProcessingResult::Ignored;
}
}
void BlendShapeRuleBehavior::UpdateBlendShapeRules(Containers::Scene& scene) const
{
Containers::SceneManifest& manifest = scene.GetManifest();
auto valueStorage = manifest.GetValueStorage();
auto view = Containers::MakeDerivedFilterView<DataTypes::ISkinGroup>(valueStorage);
for (DataTypes::ISkinGroup& group : view)
{
AZ_TraceContext("Skin group", group.GetName());
const Containers::RuleContainer& rules = group.GetRuleContainer();
const size_t ruleCount = rules.GetRuleCount();
for (size_t index = 0; index < ruleCount; ++index)
{
SceneData::BlendShapeRule* rule = azrtti_cast<SceneData::BlendShapeRule*>(rules.GetRule(index).get());
if (rule)
{
Utilities::SceneGraphSelector::UpdateNodeSelection(scene.GetGraph(), rule->GetSceneNodeSelectionList());
}
}
}
}
} // namespace SceneData
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,55 @@
/*
* 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 <SceneAPI/SceneCore/Components/BehaviorComponent.h>
#include <AzCore/std/string/string.h>
#include <SceneAPI/SceneCore/Events/ManifestMetaInfoBus.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
namespace AZ
{
namespace SceneAPI
{
namespace DataTypes
{
class IGroup;
class ISceneNodeSelectionList;
}
namespace SceneData
{
class BlendShapeRuleBehavior
: public SceneCore::BehaviorComponent
, public Events::ManifestMetaInfoBus::Handler
, public Events::AssetImportRequestBus::Handler
{
public:
AZ_COMPONENT(BlendShapeRuleBehavior, "{D07DABE6-D731-4F4F-B55E-019EDE5B435E}", SceneCore::BehaviorComponent);
~BlendShapeRuleBehavior() override = default;
void Activate() override;
void Deactivate() override;
static void Reflect(ReflectContext* context);
void InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target) override;
Events::ProcessingResult UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication requester) override;
private:
size_t SelectBlendShapes(const Containers::Scene& scene, DataTypes::ISceneNodeSelectionList& selection) const;
void UpdateBlendShapeRules(Containers::Scene& scene) const;
};
} // namespace SceneData
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,220 @@
/*
* 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 <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzCore/std/containers/fixed_vector.h>
#include <AzToolsFramework/Debug/TraceContext.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/SceneManifest.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Containers/Views/PairIterator.h>
#include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
#include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISceneNodeGroup.h>
#include <SceneAPI/SceneCore/DataTypes/Rules/IMaterialRule.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshData.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/IMeshGroup.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISkinGroup.h>
#include <SceneAPI/SceneData/Rules/LodRule.h>
#include <SceneAPI/SceneData/Behaviors/LodRuleBehavior.h>
#include <SceneAPI/SceneData/ManifestBase/SceneNodeSelectionList.h>
namespace AZ
{
namespace SceneAPI
{
namespace SceneData
{
static AZStd::fixed_vector < AZ::Crc32, LodRule::m_maxLods > s_lodVirtualTypeKeys =
{
AZ_CRC("LODMesh1", 0xcbea988c),
AZ_CRC("LODMesh2", 0x52e3c936),
AZ_CRC("LODMesh3", 0x25e4f9a0),
AZ_CRC("LODMesh4", 0xbb806c03),
AZ_CRC("LODMesh5", 0xcc875c95)
};
void LodRuleBehavior::Activate()
{
Events::ManifestMetaInfoBus::Handler::BusConnect();
Events::AssetImportRequestBus::Handler::BusConnect();
Events::GraphMetaInfoBus::Handler::BusConnect();
}
void LodRuleBehavior::Deactivate()
{
Events::GraphMetaInfoBus::Handler::BusDisconnect();
Events::AssetImportRequestBus::Handler::BusDisconnect();
Events::ManifestMetaInfoBus::Handler::BusDisconnect();
}
void LodRuleBehavior::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<LodRuleBehavior, BehaviorComponent>()->Version(1);
}
}
void LodRuleBehavior::InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target)
{
//Initialize Mesh Groups.
if (target.RTTI_IsTypeOf(DataTypes::IMeshGroup::TYPEINFO_Uuid()) || target.RTTI_IsTypeOf(DataTypes::ISkinGroup::TYPEINFO_Uuid()))
{
AZStd::shared_ptr<LodRule> lodRule = nullptr;
for (size_t lodLevel = 0; lodLevel < LodRule::m_maxLods; ++lodLevel)
{
SceneNodeSelectionList selection;
size_t lodCount = SelectLodMeshes(scene, selection, lodLevel);
if (lodCount > 0)
{
//Only create a lodRule if we have the first lod level.
if (lodLevel == 0 && !lodRule)
{
lodRule = AZStd::make_shared<LodRule>();
}
lodRule->AddLod();
selection.CopyTo(lodRule->GetNodeSelectionList(lodLevel));
}
else
{
//Stop processing if we hit an empty lod.
break;
}
}
if(lodRule)
{
DataTypes::IGroup* group = azrtti_cast<DataTypes::IGroup*>(&target);
group->GetRuleContainer().AddRule(AZStd::move(lodRule));
}
}
else if (target.RTTI_IsTypeOf(LodRule::TYPEINFO_Uuid()))
{
LodRule* rule = azrtti_cast<LodRule*>(&target);
for (size_t lodLevel = 0; lodLevel < rule->GetLodCount(); ++lodLevel)
{
SelectLodMeshes(scene, rule->GetSceneNodeSelectionList(lodLevel), lodLevel);
}
}
}
size_t LodRuleBehavior::SelectLodMeshes(const Containers::Scene& scene, DataTypes::ISceneNodeSelectionList& selection, size_t lodLevel) const
{
Utilities::SceneGraphSelector::SelectAll(scene.GetGraph(), selection);
size_t lodMeshCount = 0;
const Containers::SceneGraph& graph = scene.GetGraph();
auto contentStorage = graph.GetContentStorage();
auto nameStorage = graph.GetNameStorage();
auto keyValueView = Containers::Views::MakePairView(nameStorage, contentStorage);
auto filteredView = Containers::Views::MakeFilterView(keyValueView, Containers::DerivedTypeFilter<DataTypes::IMeshData>());
for (auto it = filteredView.begin(); it != filteredView.end(); ++it)
{
AZStd::set<Crc32> types;
auto keyValueIterator = it.GetBaseIterator();
Containers::SceneGraph::NodeIndex index = graph.ConvertToNodeIndex(keyValueIterator.GetFirstIterator());
EBUS_EVENT(Events::GraphMetaInfoBus, GetVirtualTypes, types, scene, index);
if (types.find(Events::GraphMetaInfo::GetIgnoreVirtualType()) != types.end() ||
types.find(s_lodVirtualTypeKeys[lodLevel]) == types.end())
{
selection.RemoveSelectedNode(it->first.GetPath());
}
else
{
lodMeshCount++;
}
}
return lodMeshCount;
}
Events::ProcessingResult LodRuleBehavior::UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication /*requester*/)
{
if (action == ManifestAction::Update)
{
UpdateLodRules(scene);
return Events::ProcessingResult::Success;
}
else
{
return Events::ProcessingResult::Ignored;
}
}
void LodRuleBehavior::UpdateLodRules(Containers::Scene& scene) const
{
Containers::SceneManifest& manifest = scene.GetManifest();
//Process Mesh or Skin Groups.
auto valueStorage = manifest.GetValueStorage();
auto view = Containers::MakeDerivedFilterView<DataTypes::ISceneNodeGroup>(valueStorage);
for (DataTypes::ISceneNodeGroup& group : view)
{
AZ_TraceContext("Mesh/Skin Group", group.GetName());
const Containers::RuleContainer& rules = group.GetRuleContainer();
const size_t ruleCount = rules.GetRuleCount();
for (size_t index = 0; index < ruleCount; ++index)
{
LodRule* rule = azrtti_cast<LodRule*>(rules.GetRule(index).get());
if (rule)
{
//update existing lods.
for (size_t lodLevel = 0; lodLevel < rule->GetLodCount(); ++lodLevel)
{
Utilities::SceneGraphSelector::UpdateNodeSelection(scene.GetGraph(), rule->GetSceneNodeSelectionList(lodLevel));
}
//Check for new lods.
for (size_t lodLevel = rule->GetLodCount(); lodLevel < LodRule::m_maxLods; ++lodLevel)
{
SceneNodeSelectionList selection;
size_t lodCount = SelectLodMeshes(scene, selection, lodLevel);
if (lodCount > 0)
{
rule->AddLod();
selection.CopyTo(rule->GetNodeSelectionList(index));
}
else
{
//Stop processing if we hit an empty lod.
break;
}
}
}
}
}
}
void LodRuleBehavior::GetVirtualTypeName(AZStd::string& name, Crc32 type)
{
if (type == AZ_CRC("LODMesh1", 0xcbea988c)) { name = "LODMesh1"; }
else if (type == AZ_CRC("LODMesh2", 0x52e3c936)) { name = "LODMesh2"; }
else if (type == AZ_CRC("LODMesh3", 0x25e4f9a0)) { name = "LODMesh3"; }
else if (type == AZ_CRC("LODMesh4", 0xbb806c03)) { name = "LODMesh4"; }
else if (type == AZ_CRC("LODMesh5", 0xcc875c95)) { name = "LODMesh5"; }
}
void LodRuleBehavior::GetAllVirtualTypes(AZStd::set<Crc32>& types)
{
AZStd::copy(s_lodVirtualTypeKeys.begin(), s_lodVirtualTypeKeys.end(), AZStd::inserter(types, types.begin()));
}
} // namespace SceneData
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,62 @@
/*
* 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 <AzCore/std/string/string.h>
#include <SceneAPI/SceneCore/Components/BehaviorComponent.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
#include <SceneAPI/SceneCore/Events/ManifestMetaInfoBus.h>
namespace AZ
{
namespace SceneAPI
{
namespace DataTypes
{
class IGroup;
class ISceneNodeSelectionList;
}
namespace SceneData
{
class LodRule;
class LodRuleBehavior
: public SceneCore::BehaviorComponent
, public Events::ManifestMetaInfoBus::Handler
, public Events::AssetImportRequestBus::Handler
, public Events::GraphMetaInfoBus::Handler
{
public:
AZ_COMPONENT(LodRuleBehavior, "{D2E19864-9A4B-41FD-8ACC-DA6756728CB3}", SceneCore::BehaviorComponent);
~LodRuleBehavior() override = default;
void Activate() override;
void Deactivate() override;
static void Reflect(ReflectContext* context);
void InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target) override;
Events::ProcessingResult UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication requester) override;
void GetVirtualTypeName(AZStd::string& name, Crc32 type) override;
void GetAllVirtualTypes(AZStd::set<Crc32>& types) override;
private:
size_t SelectLodMeshes(const Containers::Scene& scene, DataTypes::ISceneNodeSelectionList& selection, size_t lodLevel) const;
void UpdateLodRules(Containers::Scene& scene) const;
};
} // namespace SceneData
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,71 @@
/*
* 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 <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISceneNodeGroup.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IMaterialData.h>
#include <SceneAPI/SceneData/Rules/MaterialRule.h>
#include <SceneAPI/SceneData/Behaviors/MaterialRuleBehavior.h>
namespace AZ
{
namespace SceneAPI
{
namespace SceneData
{
void MaterialRuleBehavior::Activate()
{
BusConnect();
}
void MaterialRuleBehavior::Deactivate()
{
BusDisconnect();
}
void MaterialRuleBehavior::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<MaterialRuleBehavior, BehaviorComponent>()->Version(1);
}
}
void MaterialRuleBehavior::InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target)
{
if (target.RTTI_IsTypeOf(DataTypes::ISceneNodeGroup::TYPEINFO_Uuid()))
{
DataTypes::ISceneNodeGroup* sceneNodeGroup = azrtti_cast<DataTypes::ISceneNodeGroup*>(&target);
// Note that other behaviors such as the physics can also add a material rule.
Containers::RuleContainer& rules = sceneNodeGroup->GetRuleContainer();
if (Utilities::DoesSceneGraphContainDataLike<DataTypes::IMaterialData>(scene, true) && !rules.ContainsRuleOfType<DataTypes::IMaterialRule>())
{
Events::ManifestMetaInfo::ModifiersList modifiers;
Events::ManifestMetaInfoBus::Broadcast(&Events::ManifestMetaInfo::GetAvailableModifiers, modifiers, scene, target);
if (AZStd::find(modifiers.begin(), modifiers.end(), azrtti_typeid<SceneData::MaterialRule>()) != modifiers.end())
{
rules.AddRule(AZStd::make_shared<SceneData::MaterialRule>());
}
}
}
}
} // namespace SceneData
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,46 @@
/*
* 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 <SceneAPI/SceneCore/Components/BehaviorComponent.h>
#include <AzCore/std/string/string.h>
#include <SceneAPI/SceneCore/Events/ManifestMetaInfoBus.h>
namespace AZ
{
namespace SceneAPI
{
namespace DataTypes
{
class IGroup;
}
namespace SceneData
{
class MaterialRuleBehavior
: public SceneCore::BehaviorComponent
, public Events::ManifestMetaInfoBus::Handler
{
public:
AZ_COMPONENT(MaterialRuleBehavior, "{14FD7ECE-195D-46A7-85AB-135F77D757DC}", SceneCore::BehaviorComponent);
~MaterialRuleBehavior() override = default;
void Activate() override;
void Deactivate() override;
static void Reflect(ReflectContext* context);
void InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target) override;
};
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,217 @@
/*
* 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 <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/algorithm.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzToolsFramework/Debug/TraceContext.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/SceneManifest.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/IMeshGroup.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISceneNodeGroup.h>
#include <SceneAPI/SceneCore/DataTypes/Groups/ISkinGroup.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshVertexUVData.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IMeshVertexColorData.h>
#include <SceneAPI/SceneData/Rules/StaticMeshAdvancedRule.h>
#include <SceneAPI/SceneData/Rules/SkinMeshAdvancedRule.h>
#include <SceneAPI/SceneData/Behaviors/MeshAdvancedRule.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
void MeshAdvancedRule::Activate()
{
Events::ManifestMetaInfoBus::Handler::BusConnect();
Events::AssetImportRequestBus::Handler::BusConnect();
}
void MeshAdvancedRule::Deactivate()
{
Events::AssetImportRequestBus::Handler::BusDisconnect();
Events::ManifestMetaInfoBus::Handler::BusDisconnect();
}
void MeshAdvancedRule::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<MeshAdvancedRule, BehaviorComponent>()->Version(1);
}
}
void MeshAdvancedRule::InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target)
{
AZStd::string firstVertexColorStream = GetFirstVertexColorStream(scene);
if (target.RTTI_IsTypeOf(DataTypes::ISceneNodeGroup::TYPEINFO_Uuid()))
{
if (!firstVertexColorStream.empty())
{
if (target.RTTI_IsTypeOf(DataTypes::ISkinGroup::TYPEINFO_Uuid()))
{
AZStd::shared_ptr<SceneData::SkinMeshAdvancedRule> rule = AZStd::make_shared<SceneData::SkinMeshAdvancedRule>();
rule->SetVertexColorStreamName(firstVertexColorStream.empty() ?
DataTypes::s_advancedDisabledString : AZStd::move(firstVertexColorStream));
DataTypes::ISceneNodeGroup* sceneNodeGroup = azrtti_cast<DataTypes::ISceneNodeGroup*>(&target);
sceneNodeGroup->GetRuleContainer().AddRule(AZStd::move(rule));
}
else if (target.RTTI_IsTypeOf(DataTypes::IMeshGroup::TYPEINFO_Uuid()))
{
AZStd::shared_ptr<SceneData::StaticMeshAdvancedRule> rule = AZStd::make_shared<SceneData::StaticMeshAdvancedRule>();
rule->SetVertexColorStreamName(firstVertexColorStream.empty() ?
DataTypes::s_advancedDisabledString : AZStd::move(firstVertexColorStream));
DataTypes::ISceneNodeGroup* sceneNodeGroup = azrtti_cast<DataTypes::ISceneNodeGroup*>(&target);
sceneNodeGroup->GetRuleContainer().AddRule(AZStd::move(rule));
}
}
}
else if (target.RTTI_IsTypeOf(SceneData::StaticMeshAdvancedRule::TYPEINFO_Uuid()))
{
SceneData::StaticMeshAdvancedRule* rule = azrtti_cast<SceneData::StaticMeshAdvancedRule*>(&target);
rule->SetVertexColorStreamName(firstVertexColorStream.empty() ?
DataTypes::s_advancedDisabledString : AZStd::move(firstVertexColorStream));
}
else if (target.RTTI_IsTypeOf(SceneData::SkinMeshAdvancedRule::TYPEINFO_Uuid()))
{
SceneData::SkinMeshAdvancedRule* rule = azrtti_cast<SceneData::SkinMeshAdvancedRule*>(&target);
rule->SetVertexColorStreamName(firstVertexColorStream.empty() ?
DataTypes::s_advancedDisabledString : AZStd::move(firstVertexColorStream));
}
}
Events::ProcessingResult MeshAdvancedRule::UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication requester)
{
AZ_UNUSED(requester);
if (action == ManifestAction::Update)
{
UpdateMeshAdvancedRules(scene);
return Events::ProcessingResult::Success;
}
else
{
return Events::ProcessingResult::Ignored;
}
}
void MeshAdvancedRule::UpdateMeshAdvancedRules(Containers::Scene& scene) const
{
Containers::SceneManifest& manifest = scene.GetManifest();
auto valueStorage = manifest.GetValueStorage();
auto view = Containers::MakeDerivedFilterView<DataTypes::ISceneNodeGroup>(valueStorage);
for (DataTypes::ISceneNodeGroup& group : view)
{
AZ_TraceContext("Scene node group", group.GetName());
Containers::RuleContainer& rules = group.GetRuleContainer();
const size_t ruleCount = rules.GetRuleCount();
// The Mesh Advanced Rules were previously invalidly applied to any group containing a vertex color stream, and should be cleaned up if unnecessarily added to existing data.
// We use a list to track indices of rules to remove in a separate pass since the RuleContainer does not have direct iterator access.
bool isValidGroupType = group.RTTI_IsTypeOf(DataTypes::IMeshGroup::TYPEINFO_Uuid()) || group.RTTI_IsTypeOf(DataTypes::ISkinGroup::TYPEINFO_Uuid());
AZStd::vector<size_t> rulesToRemove;
for (size_t index = 0; index < ruleCount; ++index)
{
DataTypes::IMeshAdvancedRule* rule = azrtti_cast<DataTypes::IMeshAdvancedRule*>(rules.GetRule(index).get());
if (rule)
{
if (isValidGroupType)
{
UpdateMeshAdvancedRule(scene, rule);
}
else
{
rulesToRemove.push_back(index);
}
}
}
// Remove in reversed order, as otherwise the indices will be wrong. For example if we remove index 3, then index 6 would really be 5 afterwards.
// By doing this in reversed order we remove items at the end of the list first so it won't impact the indices of previous ones.
for (AZStd::vector<size_t>::reverse_iterator it = rulesToRemove.rbegin(); it != rulesToRemove.rend(); ++it)
{
rules.RemoveRule(*it);
}
}
}
void MeshAdvancedRule::UpdateMeshAdvancedRule(Containers::Scene& scene, DataTypes::IMeshAdvancedRule* rule) const
{
if (!rule)
{
return;
}
SceneData::SkinMeshAdvancedRule* skinRule = azrtti_cast<SceneData::SkinMeshAdvancedRule*>(rule);
SceneData::StaticMeshAdvancedRule* meshRule = azrtti_cast<SceneData::StaticMeshAdvancedRule*>(rule);
if (!(skinRule || meshRule))
{
return;
}
const AZStd::string& vertexColorStreamName = rule->GetVertexColorStreamName();
bool foundColorStream = vertexColorStreamName == DataTypes::s_advancedDisabledString;
const Containers::SceneGraph& graph = scene.GetGraph();
Containers::SceneGraph::NameStorageConstData graphNames = graph.GetNameStorage();
for (auto it = graphNames.begin(); it != graphNames.end(); ++it)
{
if (foundColorStream)
{
break;
}
const char* nodeName = it->GetName();
if (!foundColorStream && vertexColorStreamName == nodeName)
{
foundColorStream = true;
}
}
if (!foundColorStream)
{
AZStd::string newColorStreamName = GetFirstVertexColorStream(scene);
AZ_TracePrintf(Utilities::WarningWindow, "Old vertex color stream name not found so renamed from '%s' to '%s'.",
vertexColorStreamName.c_str(), newColorStreamName.c_str());
if (skinRule)
{
skinRule->SetVertexColorStreamName(newColorStreamName.empty() ? DataTypes::s_advancedDisabledString : AZStd::move(newColorStreamName));
}
else if (meshRule)
{
meshRule->SetVertexColorStreamName(newColorStreamName.empty() ? DataTypes::s_advancedDisabledString : AZStd::move(newColorStreamName));
}
}
}
AZStd::string MeshAdvancedRule::GetFirstVertexColorStream(const Containers::Scene& scene) const
{
const Containers::SceneGraph& graph = scene.GetGraph();
Containers::SceneGraph::ContentStorageConstData graphContent = graph.GetContentStorage();
auto vertexColorData = AZStd::find_if(graphContent.begin(), graphContent.end(),
Containers::DerivedTypeFilter<DataTypes::IMeshVertexColorData>());
if (vertexColorData != graphContent.end())
{
return graph.GetNodeName(graph.ConvertToNodeIndex(vertexColorData)).GetName();
}
else
{
return AZStd::string();
}
}
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,59 @@
/*
* 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 <SceneAPI/SceneCore/Components/BehaviorComponent.h>
#include <AzCore/std/string/string.h>
#include <SceneAPI/SceneCore/Events/ManifestMetaInfoBus.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
namespace AZ
{
namespace SceneAPI
{
namespace DataTypes
{
class IMeshAdvancedRule;
}
namespace Behaviors
{
class MeshAdvancedRule
: public SceneCore::BehaviorComponent
, public Events::ManifestMetaInfoBus::Handler
, public Events::AssetImportRequestBus::Handler
{
public:
AZ_COMPONENT(MeshAdvancedRule, "{4217B46E-87A6-438E-8ACE-0397828AE889}", SceneCore::BehaviorComponent);
~MeshAdvancedRule() override = default;
void Activate() override;
void Deactivate() override;
static void Reflect(ReflectContext* context);
void InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target) override;
Events::ProcessingResult UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication requester) override;
private:
void UpdateMeshAdvancedRules(Containers::Scene& scene) const;
void UpdateMeshAdvancedRule(Containers::Scene& scene, DataTypes::IMeshAdvancedRule* rule) const;
AZStd::string GetFirstVertexColorStream(const Containers::Scene& scene) const;
};
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,54 @@
#pragma once
/*
* 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 <SceneAPI/SceneCore/Components/BehaviorComponent.h>
#include <SceneAPI/SceneCore/Events/ManifestMetaInfoBus.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
class MeshGroup
: public SceneCore::BehaviorComponent
, public Events::ManifestMetaInfoBus::Handler
, public Events::AssetImportRequestBus::Handler
{
public:
AZ_COMPONENT(MeshGroup, "{52DD90C2-81F5-4763-AC64-6DB2294BE50A}", SceneCore::BehaviorComponent);
~MeshGroup() override = default;
void Activate() override;
void Deactivate() override;
static void Reflect(ReflectContext* context);
void GetCategoryAssignments(CategoryRegistrationList& categories, const Containers::Scene& scene) override;
void InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target) override;
Events::ProcessingResult UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication requester) override;
private:
Events::ProcessingResult BuildDefault(Containers::Scene& scene) const;
Events::ProcessingResult UpdateMeshGroups(Containers::Scene& scene) const;
bool SceneHasMeshGroup(const Containers::Scene& scene) const;
static const int s_meshGroupPreferredTabOrder;
};
} // Behaviors
} // SceneAPI
} // AZ
@@ -0,0 +1,48 @@
/*
* 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 <AzCore/Component/ComponentApplicationBus.h>
#include <SceneAPI/SceneData/Behaviors/Registry.h>
#include <SceneAPI/SceneData/Behaviors/AnimationGroup.h>
#include <SceneAPI/SceneData/Behaviors/BlendShapeRuleBehavior.h>
#include <SceneAPI/SceneData/Behaviors/LodRuleBehavior.h>
#include <SceneAPI/SceneData/Behaviors/MaterialRuleBehavior.h>
#include <SceneAPI/SceneData/Behaviors/MeshAdvancedRule.h>
#include <SceneAPI/SceneData/Behaviors/MeshGroup.h>
#include <SceneAPI/SceneData/Behaviors/ScriptProcessorRuleBehavior.h>
#include <SceneAPI/SceneData/Behaviors/SkeletonGroup.h>
#include <SceneAPI/SceneData/Behaviors/SkinGroup.h>
namespace AZ
{
namespace SceneAPI
{
namespace SceneData
{
void Registry::RegisterComponents(ComponentDescriptorList& components)
{
components.insert(components.end(),
{
Behaviors::AnimationGroup::CreateDescriptor(),
BlendShapeRuleBehavior::CreateDescriptor(),
LodRuleBehavior::CreateDescriptor(),
MaterialRuleBehavior::CreateDescriptor(),
Behaviors::MeshAdvancedRule::CreateDescriptor(),
Behaviors::MeshGroup::CreateDescriptor(),
Behaviors::ScriptProcessorRuleBehavior::CreateDescriptor(),
Behaviors::SkeletonGroup::CreateDescriptor(),
Behaviors::SkinGroup::CreateDescriptor()
});
}
} // SceneData
} // SceneAPI
} // AZ
@@ -0,0 +1,37 @@
/*
* 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 <AzCore/Memory/Memory.h>
#include <AzCore/Memory/SystemAllocator.h>
namespace AZ
{
class ReflectContext;
namespace SceneAPI
{
namespace SceneData
{
class Registry
{
public:
using ComponentDescriptorList = AZStd::vector<AZ::ComponentDescriptor*>;
AZ_CLASS_ALLOCATOR(Registry, SystemAllocator, 0)
static void RegisterComponents(ComponentDescriptorList& components);
};
} // namespace SceneData
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,205 @@
/*
* 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 <SceneAPI/SceneData/Behaviors/ScriptProcessorRuleBehavior.h>
#include <AzCore/IO/FileIO.h>
#include <AzCore/IO/Path/Path.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzFramework/API/ApplicationAPI.h>
#include <AzFramework/Asset/AssetSystemComponent.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzToolsFramework/API/EditorPythonConsoleBus.h>
#include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
#include <AzToolsFramework/Debug/TraceContext.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/SceneManifest.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
#include <SceneAPI/SceneCore/Containers/Views/PairIterator.h>
#include <SceneAPI/SceneData/Rules/ScriptProcessorRule.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
// a event bus to signal during scene building
struct ScriptBuildingNotifications
: public AZ::EBusTraits
{
virtual AZStd::string OnUpdateManifest(Containers::Scene& scene) = 0;
};
using ScriptBuildingNotificationBus = AZ::EBus<ScriptBuildingNotifications>;
// a back end to handle scene builder events for a script
struct ScriptBuildingNotificationBusHandler final
: public ScriptBuildingNotificationBus::Handler
, public AZ::BehaviorEBusHandler
{
AZ_EBUS_BEHAVIOR_BINDER(
ScriptBuildingNotificationBusHandler,
"{DF2B51DE-A4D0-4139-B5D0-DF185832380D}",
AZ::SystemAllocator,
OnUpdateManifest);
virtual ~ScriptBuildingNotificationBusHandler() = default;
AZStd::string OnUpdateManifest(Containers::Scene& scene) override
{
AZStd::string result;
CallResult(result, FN_OnUpdateManifest, scene);
return result;
}
static void Reflect(AZ::ReflectContext* context)
{
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->EBus<ScriptBuildingNotificationBus>("ScriptBuildingNotificationBus")
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Automation)
->Attribute(AZ::Script::Attributes::Module, "scene")
->Handler<ScriptBuildingNotificationBusHandler>()
->Event("OnUpdateManifest", &ScriptBuildingNotificationBus::Events::OnUpdateManifest);
}
}
};
void ScriptProcessorRuleBehavior::Activate()
{
Events::AssetImportRequestBus::Handler::BusConnect();
}
void ScriptProcessorRuleBehavior::Deactivate()
{
Events::AssetImportRequestBus::Handler::BusDisconnect();
if (m_editorPythonEventsInterface)
{
const bool silenceWarnings = true;
m_editorPythonEventsInterface->StopPython(silenceWarnings);
m_editorPythonEventsInterface = nullptr;
}
}
void ScriptProcessorRuleBehavior::Reflect(ReflectContext* context)
{
ScriptBuildingNotificationBusHandler::Reflect(context);
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<ScriptProcessorRuleBehavior, BehaviorComponent>()->Version(1);
}
}
Events::ProcessingResult ScriptProcessorRuleBehavior::UpdateManifest(
Containers::Scene& scene,
Events::AssetImportRequest::ManifestAction action,
[[maybe_unused]] Events::AssetImportRequest::RequestingApplication requester)
{
using namespace AzToolsFramework;
if (action != ManifestAction::Update)
{
return Events::ProcessingResult::Ignored;
}
// get project folder
auto settingsRegistry = AZ::SettingsRegistry::Get();
AZ::IO::FixedMaxPath projectPath;
if (!settingsRegistry->Get(projectPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_SourceGameFolder))
{
return Events::ProcessingResult::Ignored;
}
auto& sceneManifest = scene.GetManifest();
auto view = Containers::MakeDerivedFilterView<DataTypes::IScriptProcessorRule>(sceneManifest.GetValueStorage());
for (const auto& scriptItem : view)
{
AZ::IO::FixedMaxPath scriptFilename(scriptItem.GetScriptFilename());
if (scriptFilename.empty())
{
AZ_Warning("scene", false, "Skipping an empty script filename in (%s)", scene.GetManifestFilename().c_str());
continue;
}
// check for file exist via absolute path
if (!IO::FileIOBase::GetInstance()->Exists(scriptFilename.c_str()))
{
// check for script in the project folder
AZ::IO::FixedMaxPath projectScriptPath = projectPath / scriptFilename;
if (!IO::FileIOBase::GetInstance()->Exists(projectScriptPath.c_str()))
{
AZ_Warning("scene", false, "Skipping a missing script (%s) in manifest file (%s)",
scriptFilename.c_str(),
scene.GetManifestFilename().c_str());
continue;
}
scriptFilename = AZStd::move(projectScriptPath);
}
// lazy load the Python interface
if (!m_editorPythonEventsInterface)
{
m_editorPythonEventsInterface = AZ::Interface<AzToolsFramework::EditorPythonEventsInterface>::Get();
const bool silenceWarnings = true;
m_editorPythonEventsInterface->StartPython(silenceWarnings);
}
if (!m_editorPythonEventsInterface && !scriptFilename.empty())
{
AZ_Warning("scene", false,
"The scene manifest (%s) attempted to use script(%s) but Python is not enabled;"
"please add the EditorPythonBinding gem & PythonAssetBuilder gem to your project.",
scene.GetManifestFilename().c_str(), scriptFilename.c_str());
return Events::ProcessingResult::Ignored;
}
AZStd::string manifestUpdate;
auto executeCallback = [&scene, &scriptFilename, &manifestUpdate]()
{
EditorPythonRunnerRequestBus::Broadcast(
&EditorPythonRunnerRequestBus::Events::ExecuteByFilename,
scriptFilename.c_str());
ScriptBuildingNotificationBus::BroadcastResult(
manifestUpdate,
&ScriptBuildingNotificationBus::Events::OnUpdateManifest,
scene);
};
m_editorPythonEventsInterface->ExecuteWithLock(executeCallback);
// attempt to load the manifest string back to a JSON-scene-manifest
auto sceneManifestLoader = AZStd::make_unique<AZ::SceneAPI::Containers::SceneManifest>();
auto loadOutcome = sceneManifestLoader->LoadFromString(manifestUpdate);
if (loadOutcome.IsSuccess())
{
sceneManifest.Clear();
for (size_t entryIndex = 0; entryIndex < sceneManifestLoader->GetEntryCount(); ++entryIndex)
{
sceneManifest.AddEntry(sceneManifestLoader->GetValue(entryIndex));
}
return Events::ProcessingResult::Success;
}
}
return Events::ProcessingResult::Ignored;
}
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -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.
*
*/
#pragma once
#include <AzCore/std/string/string.h>
#include <SceneAPI/SceneCore/Components/BehaviorComponent.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
namespace AzToolsFramework
{
class EditorPythonEventsInterface;
}
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
class ScriptProcessorRuleBehavior
: public SceneCore::BehaviorComponent
, public Events::AssetImportRequestBus::Handler
{
public:
AZ_COMPONENT(ScriptProcessorRuleBehavior, "{24054E73-1B92-43B0-AC13-174B2F0E3F66}", SceneCore::BehaviorComponent);
~ScriptProcessorRuleBehavior() override = default;
void Activate() override;
void Deactivate() override;
static void Reflect(ReflectContext* context);
// AssetImportRequestBus::Handler
Events::ProcessingResult UpdateManifest(
Containers::Scene& scene,
ManifestAction action,
RequestingApplication requester) override;
private:
AzToolsFramework::EditorPythonEventsInterface* m_editorPythonEventsInterface = nullptr;
};
} // namespace SceneData
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,55 @@
/*
* 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 <SceneAPI/SceneCore/Components/BehaviorComponent.h>
#include <SceneAPI/SceneCore/Events/ManifestMetaInfoBus.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
class SkeletonGroup
: public SceneCore::BehaviorComponent
, public Events::ManifestMetaInfoBus::Handler
, public Events::AssetImportRequestBus::Handler
{
public:
AZ_COMPONENT(SkeletonGroup, "{9243A4BA-46BD-4961-950F-DEFAE9A919E5}", SceneCore::BehaviorComponent);
~SkeletonGroup() override = default;
void Activate() override;
void Deactivate() override;
static void Reflect(ReflectContext* context);
void GetCategoryAssignments(CategoryRegistrationList& categories, const Containers::Scene& scene) override;
void InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target) override;
Events::ProcessingResult UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication requester) override;
private:
Events::ProcessingResult BuildDefault(Containers::Scene& scene);
Events::ProcessingResult UpdateSkeletonGroups(Containers::Scene& scene) const;
bool SceneHasSkeletonGroup(const Containers::Scene& scene) const;
static const int s_rigsPreferredTabOrder;
bool m_isDefaultConstructing{ false };
};
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,64 @@
/*
* 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 <SceneAPI/SceneCore/Components/BehaviorComponent.h>
#include <SceneAPI/SceneCore/Events/ManifestMetaInfoBus.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
namespace AZ
{
namespace SceneAPI
{
namespace Behaviors
{
class SkinGroup
: public SceneCore::BehaviorComponent
, public Events::ManifestMetaInfoBus::Handler
, public Events::GraphMetaInfoBus::Handler
, public Events::AssetImportRequestBus::Handler
{
public:
AZ_COMPONENT(SkinGroup, "{348566F7-7113-4CEB-ADF8-C1CC686CD3BD}", SceneCore::BehaviorComponent);
static Crc32 s_skinVirtualType;
static const char* s_skinVirtualTypeName;
~SkinGroup() override = default;
void Activate() override;
void Deactivate() override;
static void Reflect(ReflectContext* context);
void GetCategoryAssignments(CategoryRegistrationList& categories, const Containers::Scene& scene) override;
void InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target) override;
Events::ProcessingResult UpdateManifest(Containers::Scene& scene, ManifestAction action,
RequestingApplication requester) override;
void GetVirtualTypes(AZStd::set<Crc32>& types, const Containers::Scene& scene,
Containers::SceneGraph::NodeIndex node) override;
void GetAllVirtualTypes(AZStd::set<Crc32>& types) override;
void GetVirtualTypeName(AZStd::string& name, Crc32 type) override;
private:
Events::ProcessingResult BuildDefault(Containers::Scene& scene) const;
Events::ProcessingResult UpdateGroups(Containers::Scene& scene) const;
bool SceneHasSkinGroup(const Containers::Scene& scene) const;
static const int s_rigsPreferredTabOrder;
};
} // namespace Behaviors
} // namespace SceneAPI
} // namespace AZ