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,262 @@
/*
* 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/Module/DynamicModuleHandle.h>
#include <AzCore/Serialization/EditContext.h>
#include <Source/SceneProcessingModule.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/IAnimationData.h>
#include <Config/SettingsObjects/NodeSoftNameSetting.h>
#include <Config/SettingsObjects/FileSoftNameSetting.h>
#include <Config/Components/SceneProcessingConfigSystemComponent.h>
#include <Config/Widgets/GraphTypeSelector.h>
namespace AZ
{
namespace SceneProcessingConfig
{
void SceneProcessingConfigSystemComponentSerializationEvents::OnWriteBegin(void* classPtr)
{
SceneProcessingConfigSystemComponent* component = reinterpret_cast<SceneProcessingConfigSystemComponent*>(classPtr);
component->Clear();
}
SceneProcessingConfigSystemComponent::SceneProcessingConfigSystemComponent()
{
using namespace AZ::SceneAPI::SceneCore;
ActivateSceneModule(SceneProcessing::s_sceneCoreModule);
ActivateSceneModule(SceneProcessing::s_sceneDataModule);
ActivateSceneModule(SceneProcessing::s_fbxSceneBuilderModule);
// Defaults in case there's no config setup in the Project Configurator.
m_softNames.push_back(aznew NodeSoftNameSetting("_lod1", PatternMatcher::MatchApproach::PostFix, "LODMesh1", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_lod2", PatternMatcher::MatchApproach::PostFix, "LODMesh2", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_lod3", PatternMatcher::MatchApproach::PostFix, "LODMesh3", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_lod4", PatternMatcher::MatchApproach::PostFix, "LODMesh4", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_lod5", PatternMatcher::MatchApproach::PostFix, "LODMesh5", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_phys", PatternMatcher::MatchApproach::PostFix, "PhysicsMesh", true));
m_softNames.push_back(aznew NodeSoftNameSetting("_ignore", PatternMatcher::MatchApproach::PostFix, "Ignore", false));
// If the filename ends with "_anim" this will mark all nodes as "Ignore" unless they're derived from IAnimationData. This will
// cause only animations to be exported from the .fbx file even if there's other data available.
m_softNames.push_back(aznew FileSoftNameSetting("_anim", PatternMatcher::MatchApproach::PostFix, "Ignore", false,
{ FileSoftNameSetting::GraphType(SceneAPI::DataTypes::IAnimationData::TYPEINFO_Name()) }));
m_UseCustomNormals = true;
}
void SceneProcessingConfigSystemComponent::Activate()
{
SceneProcessingConfigRequestBus::Handler::BusConnect();
AZ::SceneAPI::Events::AssetImportRequestBus::Handler::BusConnect();
SceneProcessingConfig::GraphTypeSelector::Register();
}
void SceneProcessingConfigSystemComponent::Deactivate()
{
SceneProcessingConfig::GraphTypeSelector::Unregister();
AZ::SceneAPI::Events::AssetImportRequestBus::Handler::BusDisconnect();
SceneProcessingConfigRequestBus::Handler::BusDisconnect();
}
SceneProcessingConfigSystemComponent::~SceneProcessingConfigSystemComponent()
{
DeactivateSceneModule(SceneProcessing::s_fbxSceneBuilderModule);
DeactivateSceneModule(SceneProcessing::s_sceneDataModule);
DeactivateSceneModule(SceneProcessing::s_sceneCoreModule);
}
void SceneProcessingConfigSystemComponent::Clear()
{
m_softNames.clear();
m_softNames.shrink_to_fit();
m_UseCustomNormals = true;
}
const AZStd::vector<SoftNameSetting*>* SceneProcessingConfigSystemComponent::GetSoftNames()
{
return &m_softNames;
}
bool SceneProcessingConfigSystemComponent::AddSoftName(SoftNameSetting* newSoftname)
{
bool success = true;
Crc32 newHash = newSoftname->GetVirtualTypeHash();
for (SoftNameSetting* softName : m_softNames)
{
//First check whether an item with the same CRC value already exists.
if (newHash == softName->GetVirtualTypeHash())
{
AZ_Error("SceneProcessing", false, "newSoftname(%s) and existing softName(%s) have the same hash: 0x%X",
newSoftname->GetVirtualType().c_str(), softName->GetVirtualType().c_str(), newHash);
success = false;
break;
}
}
if (success)
{
m_softNames.push_back(newSoftname);
}
return success;
}
bool SceneProcessingConfigSystemComponent::AddNodeSoftName(const char* pattern,
SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool includeChildren)
{
SoftNameSetting* newSoftname = aznew NodeSoftNameSetting(pattern, approach, virtualType, includeChildren);
bool success = AddSoftName(newSoftname);
if (!success)
{
delete newSoftname;
}
return success;
}
bool SceneProcessingConfigSystemComponent::AddFileSoftName(const char* pattern,
SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool inclusive, const AZStd::string& graphObjectTypeName)
{
SoftNameSetting* newSoftname = aznew FileSoftNameSetting(pattern, approach, virtualType, inclusive,
{ FileSoftNameSetting::GraphType(graphObjectTypeName) });
bool success = AddSoftName(newSoftname);
if (!success)
{
delete newSoftname;
}
return success;
}
void SceneProcessingConfigSystemComponent::AreCustomNormalsUsed(bool &value)
{
value = m_UseCustomNormals;
}
void SceneProcessingConfigSystemComponent::Reflect(AZ::ReflectContext* context)
{
ReflectSceneModule(context, SceneProcessing::s_sceneCoreModule);
ReflectSceneModule(context, SceneProcessing::s_sceneDataModule);
ReflectSceneModule(context, SceneProcessing::s_fbxSceneBuilderModule);
SoftNameSetting::Reflect(context);
NodeSoftNameSetting::Reflect(context);
FileSoftNameSetting::Reflect(context);
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
if (serialize)
{
serialize->Class<SceneProcessingConfigSystemComponent, AZ::Component>()
->Version(2)
->EventHandler<SceneProcessingConfigSystemComponentSerializationEvents>()
->Field("softNames", &SceneProcessingConfigSystemComponent::m_softNames)
->Field("useCustomNormals", &SceneProcessingConfigSystemComponent::m_UseCustomNormals);
if (AZ::EditContext* ec = serialize->GetEditContext())
{
ec->Class<SceneProcessingConfigSystemComponent>("Scene Processing Config", "Use this component to fine tune the defaults for processing of scene files like Fbx.")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Category, "Assets")
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System", 0xc94d118b))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
->DataElement(AZ::Edit::UIHandlers::Default, &SceneProcessingConfigSystemComponent::m_softNames,
"Soft naming conventions", "Update the naming conventions to suit your project.")
->Attribute(AZ::Edit::Attributes::AutoExpand, false)
->DataElement(AZ::Edit::UIHandlers::Default, &SceneProcessingConfigSystemComponent::m_UseCustomNormals,
"Use Custom Normals", "When enabled, Lumberyard will use the DCC assets custom or tangent space normals. When disabled, the normals will be averaged. This setting can be overridden on individual FBX asset settings.")
->Attribute(AZ::Edit::Attributes::AutoExpand, false);
}
}
}
void SceneProcessingConfigSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("SceneProcessingConfigService", 0x7b333b47));
}
void SceneProcessingConfigSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("SceneProcessingConfigService", 0x7b333b47));
}
void SceneProcessingConfigSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
AZ_UNUSED(required);
}
void SceneProcessingConfigSystemComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
{
AZ_UNUSED(dependent);
}
void SceneProcessingConfigSystemComponent::ReflectSceneModule(AZ::ReflectContext* context,
const AZStd::unique_ptr<AZ::DynamicModuleHandle>& module)
{
using ReflectFunc = void(*)(AZ::SerializeContext*);
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
if (serialize)
{
if (module)
{
ReflectFunc reflect = module->GetFunction<ReflectFunc>("Reflect");
if (reflect)
{
(*reflect)(serialize);
}
}
}
using ReflectBehaviorFunc = void(*)(AZ::BehaviorContext*);
AZ::BehaviorContext* behavior = azrtti_cast<AZ::BehaviorContext*>(context);
if (behavior)
{
if (module)
{
ReflectBehaviorFunc reflectBehavior = module->GetFunction<ReflectBehaviorFunc>("ReflectBehavior");
if (reflectBehavior)
{
(*reflectBehavior)(behavior);
}
}
}
}
void SceneProcessingConfigSystemComponent::ActivateSceneModule(const AZStd::unique_ptr<AZ::DynamicModuleHandle>& module)
{
using ActivateFunc = void(*)();
if (module)
{
ActivateFunc activate = module->GetFunction<ActivateFunc>("Activate");
if (activate)
{
(*activate)();
}
}
}
void SceneProcessingConfigSystemComponent::DeactivateSceneModule(const AZStd::unique_ptr<AZ::DynamicModuleHandle>& module)
{
using DeactivateFunc = void(*)();
if (module)
{
DeactivateFunc deactivate = module->GetFunction<DeactivateFunc>("Deactivate");
if (deactivate)
{
(*deactivate)();
}
}
}
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,85 @@
/*
* 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/Component/Component.h>
#include <AzCore/std/smart_ptr/unique_ptr.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <SceneAPI/SceneCore/Components/SceneSystemComponent.h>
#include <Config/SceneProcessingConfigBus.h>
#include <Config/SettingsObjects/SoftNameSetting.h>
#include <SceneAPI/SceneCore/Events/AssetImportRequest.h>
namespace AZ
{
class DynamicModuleHandle;
namespace SceneProcessingConfig
{
class SceneProcessingConfigSystemComponentSerializationEvents
: public SerializeContext::IEventHandler
{
public:
AZ_CLASS_ALLOCATOR(SceneProcessingConfigSystemComponentSerializationEvents, SystemAllocator, 0);
void OnWriteBegin(void* classPtr) override;
};
class SceneProcessingConfigSystemComponent
: public AZ::SceneAPI::SceneCore::SceneSystemComponent
, protected SceneProcessingConfigRequestBus::Handler
, public AZ::SceneAPI::Events::AssetImportRequestBus::Handler
{
public:
AZ_COMPONENT(SceneProcessingConfigSystemComponent, "{80FE1130-91B4-44D4-869F-859BB996161A}", AZ::SceneAPI::SceneCore::SceneSystemComponent);
SceneProcessingConfigSystemComponent();
~SceneProcessingConfigSystemComponent();
void Activate() override;
void Deactivate() override;
void Clear();
// SceneProcessingConfigRequestBus START
const AZStd::vector<SoftNameSetting*>* GetSoftNames() override;
bool AddNodeSoftName(const char* pattern,
SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool includeChildren) override;
bool AddFileSoftName(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool inclusive, const AZStd::string& graphObjectTypeName) override;
// SceneProcessingConfigRequestBus END
void AreCustomNormalsUsed(bool &value) override;
static void Reflect(AZ::ReflectContext* context);
static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible);
static void GetRequiredServices(ComponentDescriptor::DependencyArrayType& required);
static void GetDependentServices(ComponentDescriptor::DependencyArrayType& dependent);
private:
/// It is the responsibility of the caller to delete newSoftname if this method returns
/// false.
bool AddSoftName(SoftNameSetting* newSoftname);
static void ReflectSceneModule(ReflectContext* context, const AZStd::unique_ptr<DynamicModuleHandle>& module);
static void ActivateSceneModule(const AZStd::unique_ptr<DynamicModuleHandle>& module);
static void DeactivateSceneModule(const AZStd::unique_ptr<DynamicModuleHandle>& module);
AZStd::vector<SoftNameSetting*> m_softNames;
bool m_UseCustomNormals;
};
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,82 @@
/*
* 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 <Config/SceneProcessingConfigBus.h>
#include <Config/Components/SoftNameBehavior.h>
#include <Config/SettingsObjects/SoftNameSetting.h>
namespace AZ
{
namespace SceneProcessingConfig
{
void SoftNameBehavior::Activate()
{
SceneAPI::Events::GraphMetaInfoBus::Handler::BusConnect();
}
void SoftNameBehavior::Deactivate()
{
SceneAPI::Events::GraphMetaInfoBus::Handler::BusDisconnect();
}
void SoftNameBehavior::GetVirtualTypes(AZStd::set<Crc32>& types, const SceneAPI::Containers::Scene& scene,
SceneAPI::Containers::SceneGraph::NodeIndex node)
{
const AZStd::vector<SoftNameSetting*>* softNames = nullptr;
SceneProcessingConfigRequestBus::BroadcastResult(softNames, &SceneProcessingConfigRequestBus::Events::GetSoftNames);
if (softNames)
{
for (const SoftNameSetting* softName : *softNames)
{
if (types.find(softName->GetVirtualTypeHash()) != types.end())
{
// This type has already been added.
continue;
}
if (softName->IsVirtualType(scene, node))
{
types.insert(softName->GetVirtualTypeHash());
}
}
}
}
void SoftNameBehavior::GetVirtualTypeName(AZStd::string& name, Crc32 type)
{
if (type == AZ_CRC("Ignore", 0x0d88d6e2))
{
name = "Ignore";
}
}
void SoftNameBehavior::GetAllVirtualTypes(AZStd::set<Crc32>& types)
{
// Add types that aren't handled by one specific behavior and have a more global utility.
if (types.find(AZ_CRC("Ignore", 0x0d88d6e2)) == types.end())
{
types.insert(AZ_CRC("Ignore", 0x0d88d6e2));
}
}
void SoftNameBehavior::Reflect(ReflectContext* context)
{
SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<SoftNameBehavior, BehaviorComponent>()->Version(1);
}
}
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,42 @@
/*
* 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/GraphMetaInfoBus.h>
namespace AZ
{
namespace SceneProcessingConfig
{
class SoftNameBehavior
: public SceneAPI::SceneCore::BehaviorComponent
, protected SceneAPI::Events::GraphMetaInfoBus::Handler
{
public:
AZ_COMPONENT(SoftNameBehavior, "{C2A9D207-485F-4752-B37B-388B0A52A956}", SceneAPI::SceneCore::BehaviorComponent);
~SoftNameBehavior() override = default;
void Activate() override;
void Deactivate() override;
void GetVirtualTypes(AZStd::set<Crc32>& types, const SceneAPI::Containers::Scene& scene,
SceneAPI::Containers::SceneGraph::NodeIndex node) override;
void GetVirtualTypeName(AZStd::string& name, Crc32 type) override;
void GetAllVirtualTypes(AZStd::set<Crc32>& types) override;
static void Reflect(ReflectContext* context);
};
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,198 @@
/*
* 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 <AzCore/Serialization/EditContext.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/DataTypes/IGraphObject.h>
#include <SceneAPI/SceneCore/Utilities/PatternMatcher.h>
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
#include <Config/SettingsObjects/FileSoftNameSetting.h>
namespace AZ
{
namespace SceneProcessingConfig
{
FileSoftNameSetting::GraphType::GraphType()
: m_cachedId(Uuid::CreateNull())
{
}
FileSoftNameSetting::GraphType::GraphType(const AZStd::string& name)
: m_name(name)
, m_cachedId(Uuid::CreateNull())
{
}
FileSoftNameSetting::GraphType::GraphType(AZStd::string&& name)
: m_name(AZStd::move(name))
, m_cachedId(Uuid::CreateNull())
{
}
const AZStd::string& FileSoftNameSetting::GraphType::GetName() const
{
return m_name;
}
const Uuid& FileSoftNameSetting::GraphType::GetId() const
{
if (m_cachedId.IsNull())
{
SerializeContext* context = nullptr;
ComponentApplicationBus::BroadcastResult(context, &ComponentApplicationBus::Events::GetSerializeContext);
AZ_Assert(context, "Unable to find valid serialize context.");
context->EnumerateDerived<SceneAPI::DataTypes::IGraphObject>(
[this](const SerializeContext::ClassData* data, const Uuid& typeId) -> bool
{
AZ_UNUSED(typeId);
if (AzFramework::StringFunc::Equal(data->m_name, m_name.c_str()))
{
m_cachedId = data->m_typeId;
return false;
}
return true;
});
if (m_cachedId.IsNull())
{
AZ_TracePrintf(SceneAPI::Utilities::WarningWindow, "Unable to find '%s' in the serialize context.", m_name.c_str());
}
}
return m_cachedId;
}
void FileSoftNameSetting::GraphType::Reflect(ReflectContext* context)
{
SerializeContext* serialize = azrtti_cast<SerializeContext*>(context);
if (serialize)
{
serialize->Class<GraphType>()
->Version(1)
->Field("name", &GraphType::m_name);
}
}
FileSoftNameSetting::GraphTypeContainer::GraphTypeContainer(std::initializer_list<GraphType> graphTypes)
: m_types(graphTypes)
{
}
AZStd::vector<FileSoftNameSetting::GraphType>& FileSoftNameSetting::GraphTypeContainer::GetGraphTypes()
{
return m_types;
}
const AZStd::vector<FileSoftNameSetting::GraphType>& FileSoftNameSetting::GraphTypeContainer::GetGraphTypes() const
{
return m_types;
}
void FileSoftNameSetting::GraphTypeContainer::Reflect(ReflectContext* context)
{
SerializeContext* serialize = azrtti_cast<SerializeContext*>(context);
if (serialize)
{
serialize->Class<GraphTypeContainer>()
->Version(1)
->Field("types", &GraphTypeContainer::m_types);
}
}
FileSoftNameSetting::FileSoftNameSetting(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool inclusive, std::initializer_list<GraphType> graphTypes)
: SoftNameSetting(pattern, approach, virtualType)
, m_inclusiveList(inclusive)
, m_graphTypes(graphTypes)
, m_cachedScene(nullptr)
{
}
bool FileSoftNameSetting::IsVirtualType(const SceneAPI::Containers::Scene& scene, SceneAPI::Containers::SceneGraph::NodeIndex node) const
{
bool nameMatch = false;
if (m_cachedScene == &scene)
{
nameMatch = m_cachedNameMatch;
}
else
{
switch (m_pattern.GetMatchApproach())
{
case SceneAPI::SceneCore::PatternMatcher::MatchApproach::PreFix:
nameMatch = m_pattern.MatchesPattern(scene.GetName());
break;
case SceneAPI::SceneCore::PatternMatcher::MatchApproach::PostFix:
nameMatch = m_pattern.MatchesPattern(scene.GetName());
break;
case SceneAPI::SceneCore::PatternMatcher::MatchApproach::Regex:
nameMatch = m_pattern.MatchesPattern(scene.GetSourceFilename());
break;
default:
AZ_Assert(false, "Unknown option '%i' for pattern matcher.", m_pattern.GetMatchApproach());
nameMatch = false;
}
m_cachedNameMatch = nameMatch;
m_cachedScene = &scene;
}
if (nameMatch)
{
AZStd::shared_ptr<const SceneAPI::DataTypes::IGraphObject> object = scene.GetGraph().GetNodeContent(node);
for (const GraphType& type : m_graphTypes.GetGraphTypes())
{
if (object->RTTI_IsTypeOf(type.GetId()))
{
return m_inclusiveList;
}
}
return !m_inclusiveList;
}
else
{
return false;
}
}
void FileSoftNameSetting::Reflect(ReflectContext* context)
{
GraphType::Reflect(context);
GraphTypeContainer::Reflect(context);
SerializeContext* serialize = azrtti_cast<SerializeContext*>(context);
if (serialize)
{
serialize->Class<FileSoftNameSetting, SoftNameSetting>()
->Version(1)
->Field("graphTypes", &FileSoftNameSetting::m_graphTypes)
->Field("inclusiveList", &FileSoftNameSetting::m_inclusiveList);
EditContext* editContext = serialize->GetEditContext();
if (editContext)
{
editContext->Class<FileSoftNameSetting>("File name setting", "Applies the pattern to the name of the scene file.")
->ClassElement(Edit::ClassElements::EditorData, "")
->Attribute(Edit::Attributes::AutoExpand, true)
->DataElement(AZ_CRC("GraphTypeSelector", 0x362ac245), &FileSoftNameSetting::m_graphTypes, "Graph type",
"The graph types that are the soft name applies to.")
->Attribute(Edit::Attributes::AutoExpand, true)
->DataElement(Edit::UIHandlers::Default, &FileSoftNameSetting::m_inclusiveList, "Inclusive",
"If true the types in the list will marked as the virtual type, otherwise any types that are NOT in the list.");
}
}
}
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,87 @@
/*
* 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 <initializer_list>
#include <Config/SettingsObjects/SoftNameSetting.h>
namespace AZ
{
namespace SceneProcessingConfig
{
class FileSoftNameSetting : public SoftNameSetting
{
public:
class GraphType
{
public:
AZ_CLASS_ALLOCATOR(GraphType, AZ::SystemAllocator, 0);
AZ_RTTI(GraphType, "{368E85F4-4FF5-4708-82A1-FCDC993D4C34}");
GraphType();
explicit GraphType(const AZStd::string& name);
explicit GraphType(AZStd::string&& name);
virtual ~GraphType() = default;
const AZStd::string& GetName() const;
const Uuid& GetId() const;
static void Reflect(AZ::ReflectContext* context);
private:
AZStd::string m_name;
mutable Uuid m_cachedId;
};
// Wrapper around AZStd::vector<GraphType> for the sole purpose of forcing the reflected
// property editor to not use a container view.
class GraphTypeContainer
{
public:
AZ_CLASS_ALLOCATOR(GraphTypeContainer, AZ::SystemAllocator, 0);
AZ_RTTI(GraphTypeContainer, "{35E70739-CD31-43C2-A024-769755A26CAE}");
GraphTypeContainer() = default;
explicit GraphTypeContainer(std::initializer_list<GraphType> graphTypes);
virtual ~GraphTypeContainer() = default;
AZStd::vector<GraphType>& GetGraphTypes();
const AZStd::vector<GraphType>& GetGraphTypes() const;
static void Reflect(AZ::ReflectContext* context);
private:
AZStd::vector<GraphType> m_types;
};
AZ_CLASS_ALLOCATOR(FileSoftNameSetting, AZ::SystemAllocator, 0);
AZ_RTTI(FileSoftNameSetting, "{CED5FBF7-F74A-49E2-9FE0-DFF7EDA274CE}", SoftNameSetting);
FileSoftNameSetting() = default;
FileSoftNameSetting(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool inclusive, std::initializer_list<GraphType> graphTypes);
~FileSoftNameSetting() override = default;
bool IsVirtualType(const SceneAPI::Containers::Scene& scene, SceneAPI::Containers::SceneGraph::NodeIndex node) const;
static void Reflect(AZ::ReflectContext* context);
private:
GraphTypeContainer m_graphTypes;
bool m_inclusiveList;
mutable const SceneAPI::Containers::Scene* m_cachedScene;
mutable bool m_cachedNameMatch;
};
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,88 @@
/*
* 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/EditContext.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/Views/SceneGraphUpwardsIterator.h>
#include <Config/SettingsObjects/NodeSoftNameSetting.h>
namespace AZ
{
namespace SceneProcessingConfig
{
NodeSoftNameSetting::NodeSoftNameSetting(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool includeChildren)
: SoftNameSetting(pattern, approach, virtualType)
, m_includeChildren(includeChildren)
{
}
void NodeSoftNameSetting::Reflect(ReflectContext* context)
{
SerializeContext* serialize = azrtti_cast<SerializeContext*>(context);
if (serialize)
{
serialize->Class<NodeSoftNameSetting, SoftNameSetting>()
->Version(1)
->Field("includeChildren", &NodeSoftNameSetting::m_includeChildren);
EditContext* editContext = serialize->GetEditContext();
if (editContext)
{
editContext->Class<NodeSoftNameSetting>("Node name setting", "Applies the pattern to the name of the node.")
->ClassElement(Edit::ClassElements::EditorData, "")
->Attribute(Edit::Attributes::AutoExpand, true)
->DataElement(Edit::UIHandlers::Default, &NodeSoftNameSetting::m_includeChildren,
"Include child nodes", "Whether or not the soft name only applies to the matching node or propagated to all its children as well.");
}
}
}
bool NodeSoftNameSetting::IsVirtualType(const SceneAPI::Containers::Scene& scene, SceneAPI::Containers::SceneGraph::NodeIndex node) const
{
const SceneAPI::Containers::SceneGraph& graph = scene.GetGraph();
if (m_includeChildren)
{
auto upwardsView = SceneAPI::Containers::Views::MakeSceneGraphUpwardsView(graph, node, graph.GetNameStorage().begin(), true);
for (const SceneAPI::Containers::SceneGraph::Name& name : upwardsView)
{
if (MatchesPattern(name))
{
return true;
}
}
return false;
}
else
{
return MatchesPattern(graph.GetNodeName(node));
}
}
bool NodeSoftNameSetting::MatchesPattern(const SceneAPI::Containers::SceneGraph::Name& name) const
{
switch (m_pattern.GetMatchApproach())
{
case SceneAPI::SceneCore::PatternMatcher::MatchApproach::PreFix:
return m_pattern.MatchesPattern(name.GetName(), name.GetNameLength());
case SceneAPI::SceneCore::PatternMatcher::MatchApproach::PostFix:
return m_pattern.MatchesPattern(name.GetPath(), name.GetPathLength());
case SceneAPI::SceneCore::PatternMatcher::MatchApproach::Regex:
return m_pattern.MatchesPattern(name.GetPath(), name.GetPathLength());
default:
AZ_Assert(false, "Unknown option '%i' for pattern matcher.", m_pattern.GetMatchApproach());
return false;
}
}
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,43 @@
/*
* 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 <Config/SettingsObjects/SoftNameSetting.h>
namespace AZ
{
namespace SceneProcessingConfig
{
class NodeSoftNameSetting : public SoftNameSetting
{
public:
AZ_CLASS_ALLOCATOR(NodeSoftNameSetting, SystemAllocator, 0);
AZ_RTTI(NodeSoftNameSetting, "{74629DAE-641A-4BCE-B6D5-3F7DD9F647FA}", SoftNameSetting);
NodeSoftNameSetting() = default;
NodeSoftNameSetting(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType, bool includeChildren);
~NodeSoftNameSetting() override = default;
bool IsVirtualType(const SceneAPI::Containers::Scene& scene, SceneAPI::Containers::SceneGraph::NodeIndex node) const override;
static void Reflect(AZ::ReflectContext* context);
private:
bool MatchesPattern(const SceneAPI::Containers::SceneGraph::Name& name) const;
bool m_includeChildren = false;
};
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,94 @@
/*
* 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/EditContext.h>
#include <AzCore/std/sort.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
#include <Config/SettingsObjects/SoftNameSetting.h>
namespace AZ
{
namespace SceneProcessingConfig
{
SoftNameSetting::SoftNameSetting(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType)
: m_pattern(pattern, approach)
, m_virtualType(virtualType)
{
}
SoftNameSetting::~SoftNameSetting() = default;
Crc32 SoftNameSetting::GetVirtualTypeHash() const
{
if (m_virtualTypeHash == Crc32())
{
m_virtualTypeHash = Crc32(m_virtualType.c_str());
}
return m_virtualTypeHash;
}
const AZStd::string& SoftNameSetting::GetVirtualType() const
{
return m_virtualType;
}
void SoftNameSetting::Reflect(ReflectContext* context)
{
SerializeContext* serialize = azrtti_cast<SerializeContext*>(context);
if (serialize)
{
serialize->Class<SoftNameSetting>()
->Version(1)
->Field("pattern", &SoftNameSetting::m_pattern)
->Field("virtualType", &SoftNameSetting::m_virtualType);
EditContext* editContext = serialize->GetEditContext();
if (editContext)
{
editContext->Class<SoftNameSetting>("Soft name setting", "A pattern matcher to setup project specific naming conventions.")
->ClassElement(Edit::ClassElements::EditorData, "")
->Attribute(Edit::Attributes::AutoExpand, true)
->Attribute(Edit::Attributes::Visibility, AZ_CRC("PropertyVisibility_ShowChildrenOnly", 0xef428f20))
->DataElement(Edit::UIHandlers::Default, &SoftNameSetting::m_pattern, "Pattern",
"The pattern the matcher will check against.")
->Attribute(Edit::Attributes::Visibility, AZ_CRC("PropertyVisibility_ShowChildrenOnly", 0xef428f20))
->DataElement(Edit::UIHandlers::ComboBox, &SoftNameSetting::m_virtualType, "Virtual Type",
"The node(s) will be converted to this type after their pattern matches.")
->Attribute(Edit::Attributes::StringList, &SoftNameSetting::GetAllVirtualTypes);
}
}
}
AZStd::vector<AZStd::string> SoftNameSetting::GetAllVirtualTypes() const
{
using namespace SceneAPI::Events;
AZStd::set<Crc32> virtualTypes;
GraphMetaInfoBus::Broadcast(&GraphMetaInfoBus::Events::GetAllVirtualTypes, virtualTypes);
AZStd::vector<AZStd::string> result;
for (Crc32 virtualType : virtualTypes)
{
AZStd::string virtualTypeName;
GraphMetaInfoBus::Broadcast(&GraphMetaInfoBus::Events::GetVirtualTypeName, virtualTypeName, virtualType);
AZ_Assert(!virtualTypeName.empty(), "No name found for virtual type with hash %i.", static_cast<u32>(virtualType));
result.emplace_back(AZStd::move(virtualTypeName));
}
AZStd::sort(result.begin(), result.end());
return result;
}
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,60 @@
/*
* 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/Math/Crc.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/string/string.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Utilities/PatternMatcher.h>
namespace AZ
{
namespace SceneAPI
{
namespace Containers
{
class Scene;
}
}
namespace SceneProcessingConfig
{
class SoftNameSetting
{
public:
AZ_CLASS_ALLOCATOR(SoftNameSetting, SystemAllocator, 0);
AZ_RTTI(SoftNameSetting, "{FE7AAAF6-8BA5-4599-B9A6-CC28026A6FFE}");
SoftNameSetting() = default;
SoftNameSetting(const char* pattern, SceneAPI::SceneCore::PatternMatcher::MatchApproach approach,
const char* virtualType);
virtual ~SoftNameSetting() = 0;
virtual const AZStd::string& GetVirtualType() const;
virtual Crc32 GetVirtualTypeHash() const;
virtual bool IsVirtualType(const SceneAPI::Containers::Scene& scene, SceneAPI::Containers::SceneGraph::NodeIndex node) const = 0;
static void Reflect(ReflectContext* context);
protected:
AZStd::vector<AZStd::string> GetAllVirtualTypes() const;
SceneAPI::SceneCore::PatternMatcher m_pattern;
AZStd::string m_virtualType;
mutable Crc32 m_virtualTypeHash;
};
} // namespace SceneProcessingConfig
} // namespace AZ
@@ -0,0 +1,167 @@
/*
* 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 <QMenu>
#include <QEvent>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <SceneAPI/SceneCore/DataTypes/IGraphObject.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
#include <Config/Widgets/GraphTypeSelector.h>
namespace AZ
{
namespace SceneProcessingConfig
{
AZ_CLASS_ALLOCATOR_IMPL(GraphTypeSelector, SystemAllocator, 0)
GraphTypeSelector* GraphTypeSelector::s_instance = nullptr;
QWidget* GraphTypeSelector::CreateGUI(QWidget* parent)
{
QPushButton* base = new QPushButton("Select required graph types", parent);
QMenu* menu = new QMenu(base);
menu->setLayoutDirection(Qt::LeftToRight);
menu->setStyleSheet("border: none; background-color: #333333;");
SerializeContext* context = nullptr;
ComponentApplicationBus::BroadcastResult(context, &ComponentApplicationBus::Events::GetSerializeContext);
AZ_Assert(context, "Unable to find valid serialize context.");
context->EnumerateDerived<SceneAPI::DataTypes::IGraphObject>(
[menu](const SerializeContext::ClassData* data, const Uuid& typeId) -> bool
{
AZ_UNUSED(typeId);
QAction* action = menu->addAction(data->m_name);
action->setCheckable(true);
return true;
});
base->setMenu(menu);
base->installEventFilter(this);
return base;
}
bool GraphTypeSelector::eventFilter(QObject* object, QEvent* event)
{
// Using FocusIn instead of FocusOut because after pressing the button the menu gets focus but after
// a selection is made the focus goes back to the button, so at that point saving needs to happen.
if (event->type() == QEvent::FocusIn)
{
AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast(
&AzToolsFramework::PropertyEditorGUIMessages::Bus::Events::RequestWrite, qobject_cast<QPushButton*>(object));
}
else if (event->type() == QEvent::Show)
{
QPushButton* button = qobject_cast<QPushButton*>(object);
button->menu()->setFixedWidth(button->width());
}
else if (event->type() == QEvent::Resize)
{
QPushButton* button = qobject_cast<QPushButton*>(object);
button->menu()->setFixedWidth(button->width());
}
return QObject::eventFilter(object, event);
}
u32 GraphTypeSelector::GetHandlerName() const
{
return AZ_CRC("GraphTypeSelector", 0x362ac245);
}
bool GraphTypeSelector::AutoDelete() const
{
return false;
}
bool GraphTypeSelector::IsDefaultHandler() const
{
return false;
}
void GraphTypeSelector::ConsumeAttribute(QPushButton* widget, u32 attrib,
AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName)
{
AZ_UNUSED(widget);
AZ_UNUSED(attrib);
AZ_UNUSED(attrValue);
AZ_UNUSED(debugName);
}
void GraphTypeSelector::WriteGUIValuesIntoProperty(size_t index, QPushButton* GUI,
property_t& instance, AzToolsFramework::InstanceDataNode* node)
{
AZ_UNUSED(index);
AZ_UNUSED(node);
instance.GetGraphTypes().clear();
QMenu* menu = GUI->menu();
for (QAction* action : menu->actions())
{
if (action->isChecked())
{
instance.GetGraphTypes().emplace_back(action->text().toUtf8().constData());
}
}
}
bool GraphTypeSelector::ReadValuesIntoGUI(size_t index, QPushButton* GUI, const property_t& instance,
AzToolsFramework::InstanceDataNode* node)
{
AZ_UNUSED(index);
AZ_UNUSED(node);
QMenu* menu = GUI->menu();
for (const auto& it : instance.GetGraphTypes())
{
for (QAction* action : menu->actions())
{
if (AzFramework::StringFunc::Equal(action->text().toUtf8().constData(), it.GetName().c_str()))
{
action->setChecked(true);
break;
}
}
}
return true;
}
void GraphTypeSelector::Register()
{
using namespace AzToolsFramework;
if (!s_instance)
{
s_instance = aznew GraphTypeSelector();
PropertyTypeRegistrationMessages::Bus::Broadcast(&PropertyTypeRegistrationMessages::Bus::Events::RegisterPropertyType, s_instance);
}
}
void GraphTypeSelector::Unregister()
{
using namespace AzToolsFramework;
if (s_instance)
{
PropertyTypeRegistrationMessages::Bus::Broadcast(&PropertyTypeRegistrationMessages::Bus::Events::UnregisterPropertyType, s_instance);
delete s_instance;
s_instance = nullptr;
}
}
} // namespace SceneProcessingConfig
} // namespace AZ
#include <Source/Config/Widgets/moc_GraphTypeSelector.cpp>
@@ -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
#if !defined(Q_MOC_RUN)
#include <QPushButton>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/std/containers/vector.h>
#include <AzToolsFramework/UI/PropertyEditor/PropertyEditorAPI.h>
#include <Config/SettingsObjects/FileSoftNameSetting.h>
#endif
class QWidget;
namespace AZ
{
namespace SceneProcessingConfig
{
class GraphTypeSelector
: public QObject
, public AzToolsFramework::PropertyHandler<FileSoftNameSetting::GraphTypeContainer, QPushButton>
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR_DECL
QWidget* CreateGUI(QWidget* parent) override;
u32 GetHandlerName() const override;
bool AutoDelete() const;
bool IsDefaultHandler() const override;
void ConsumeAttribute(QPushButton* widget, u32 attrib,
AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override;
void WriteGUIValuesIntoProperty(size_t index, QPushButton* GUI, property_t& instance,
AzToolsFramework::InstanceDataNode* node) override;
bool ReadValuesIntoGUI(size_t index, QPushButton* GUI, const property_t& instance,
AzToolsFramework::InstanceDataNode* node) override;
static void Register();
static void Unregister();
private:
bool eventFilter(QObject* object, QEvent* event) override;
static GraphTypeSelector* s_instance;
};
} // namespace SceneProcessingConfig
} // namespace AZ