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,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