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,142 @@
#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 <AzCore/std/smart_ptr/shared_ptr.h>
#include <AzCore/std/typetraits/is_base_of.h>
#include <AzCore/std/typetraits/conditional.h>
#include <AzCore/std/utils.h>
#include <SceneAPI/SceneCore/DataTypes/IManifestObject.h>
#include <SceneAPI/SceneCore/DataTypes/IGraphObject.h>
#include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
#include <SceneAPI/SceneCore/Containers/Views/ConvertIterator.h>
namespace AZ
{
namespace SceneAPI
{
namespace Containers
{
// Utility classes to construct common filters for scenes. These can be used in
// algorithms such as find_if or the FilterIterator.
// Example:
// auto result = AZStd::find_if(view.begin(), view.end(), DerivedTypeFilter<IMeshData>());
namespace Internal
{
template<typename T, typename ObjectType, bool ExactType>
struct TypeFilter
{
bool operator()(const ObjectType& object) const;
bool operator()(const ObjectType* const object) const;
bool operator()(const AZStd::shared_ptr<const ObjectType>& object) const;
bool operator()(const AZStd::shared_ptr<ObjectType>& object) const;
template<typename T1>
bool operator()(const AZStd::pair<T1, AZStd::shared_ptr<const ObjectType>>& object) const;
template<typename T1>
bool operator()(const AZStd::pair<T1, AZStd::shared_ptr<ObjectType>>& object) const;
template<typename T1>
bool operator()(const AZStd::pair<T1, const AZStd::shared_ptr<const ObjectType>&>& object) const;
template<typename T1>
bool operator()(const AZStd::pair<T1, const AZStd::shared_ptr<ObjectType>&>& object) const;
template<typename T2>
bool operator()(const AZStd::pair<AZStd::shared_ptr<const ObjectType>, T2>& object) const;
template<typename T2>
bool operator()(const AZStd::pair<AZStd::shared_ptr<ObjectType>, T2>& object) const;
template<typename T2>
bool operator()(const AZStd::pair<const AZStd::shared_ptr<const ObjectType>&, T2>& object) const;
template<typename T2>
bool operator()(const AZStd::pair<const AZStd::shared_ptr<ObjectType>&, T2>& object) const;
};
template<typename T>
struct TypeFilterBaseType
{
static const bool s_isManifestObject = AZStd::is_base_of<DataTypes::IManifestObject, T>::value;
static const bool s_isGraphObject = AZStd::is_base_of<DataTypes::IGraphObject, T>::value;
static_assert(s_isManifestObject || s_isGraphObject, "Target type is not derived from IManifestObject or IGraphObject.");
using type = typename AZStd::conditional<s_isManifestObject, DataTypes::IManifestObject, DataTypes::IGraphObject>::type;
};
template<typename T> struct IsConstPayload { static const bool value = AZStd::is_const<T>::value; };
template<typename T> struct IsConstPayload<AZStd::shared_ptr<T>> { static const bool value = false; };
template<typename T> struct IsConstPayload<AZStd::unique_ptr<T>> { static const bool value = false; };
template<typename T> struct IsConstPayload<AZStd::shared_ptr<const T>> { static const bool value = true; };
template<typename T> struct IsConstPayload<AZStd::unique_ptr<const T>> { static const bool value = true; };
template<typename T, typename ViewType>
struct ConversionType
{
using type = typename AZStd::conditional<
IsConstPayload<typename AZStd::iterator_traits<typename ViewType::iterator>::value_type>::value,
const T, T>::type;
};
}
// Filter object for any type derived from the given type or the type itself. The given type must
// itself derive from either IManifestObject or IGraphObject.
// Example:
// auto result = AZStd::find_if(view.begin(), view.end(), DerivedTypeFilter<IMeshData>());
template<typename T>
struct DerivedTypeFilter
: public Internal::TypeFilter<T, typename Internal::TypeFilterBaseType<T>::type, false>
{
};
// Filter object for the given type. The given type must derive from either IManifestObject or
// IGraphObject.
// Example:
// auto view = Views::MakeFilterView(graph.GetContentStorage, ExactTypeFilter<MeshData>());
template<typename T>
struct ExactTypeFilter
: public Internal::TypeFilter<T, typename Internal::TypeFilterBaseType<T>::type, true>
{
};
// Compound view that returns all instances of the requested type and any types deriving from it.
// The given type must derive from either IManifestObject or IGraphObject.
// Example:
// auto view = MakeDerivedFilterView<IMeshData>(graph.GetContentStorage());
// for (IMeshData& mesh : view)
// {
// ...
// }
template<typename T, typename ViewType>
Views::View<Views::ConvertIterator<typename Views::FilterIterator<typename ViewType::iterator>,
typename Internal::ConversionType<T, ViewType>::type&>> MakeDerivedFilterView(ViewType& view);
template<typename T, typename ViewType>
Views::View<Views::ConvertIterator<typename Views::FilterIterator<typename ViewType::const_iterator>, const T&>> MakeDerivedFilterView(const ViewType& view);
// Compound view that returns all instances of the requested type.
// The given type must derive from either IManifestObject or IGraphObject.
// Example:
// auto view = MakeExactFilterView<MeshData>(graph.GetContentStorage());
// for (MeshData& mesh : view)
// {
// ...
// }
template<typename T, typename ViewType>
Views::View<Views::ConvertIterator<typename Views::FilterIterator<typename ViewType::iterator>,
typename Internal::ConversionType<T, ViewType>::type&>> MakeExactFilterView(ViewType& view);
template<typename T, typename ViewType>
Views::View<Views::ConvertIterator<typename Views::FilterIterator<typename ViewType::const_iterator>, const T&>> MakeExactFilterView(const ViewType& view);
} // Containers
} // SceneAPI
} // AZ
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.inl>
@@ -0,0 +1,253 @@
/*
* 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.
*
*/
namespace AZ
{
namespace SceneAPI
{
namespace Containers
{
namespace Internal
{
template<typename T, typename ObjectType, bool ExactType>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const ObjectType& object) const
{
if (ExactType)
{
return object.RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object.RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const ObjectType* const object) const
{
if (ExactType)
{
return object && object->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object && object->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::shared_ptr<const ObjectType>& object) const
{
if (ExactType)
{
return object && object->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object && object->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::shared_ptr<ObjectType>& object) const
{
if (ExactType)
{
return object && object->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object && object->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType> template<typename T1>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::pair<T1, AZStd::shared_ptr<const ObjectType>>& object) const
{
if (ExactType)
{
return object.second && object.second->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object.second && object.second->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType> template<typename T1>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::pair<T1, AZStd::shared_ptr<ObjectType>>& object) const
{
if (ExactType)
{
return object.second && object.second->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object.second && object.second->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType> template<typename T1>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::pair<T1, const AZStd::shared_ptr<const ObjectType>&>& object) const
{
if (ExactType)
{
return object.second && object.second->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object.second && object.second->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType> template<typename T1>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::pair<T1, const AZStd::shared_ptr<ObjectType>&>& object) const
{
if (ExactType)
{
return object.second && object.second->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object.second && object.second->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType> template<typename T2>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::pair<AZStd::shared_ptr<const ObjectType>, T2>& object) const
{
if (ExactType)
{
return object.first && object.first->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object.first && object.first->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType> template<typename T2>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::pair<AZStd::shared_ptr<ObjectType>, T2>& object) const
{
if (ExactType)
{
return object.first && object.first->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object.first && object.first->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType> template<typename T2>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::pair<const AZStd::shared_ptr<const ObjectType>&, T2>& object) const
{
if (ExactType)
{
return object.first && object.first->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object.first && object.first->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
template<typename T, typename ObjectType, bool ExactType> template<typename T2>
bool TypeFilter<T, ObjectType, ExactType>::operator()(const AZStd::pair<const AZStd::shared_ptr<ObjectType>&, T2>& object) const
{
if (ExactType)
{
return object.first && object.first->RTTI_GetType() == T::TYPEINFO_Uuid();
}
else
{
return object.first && object.first->RTTI_IsTypeOf(T::TYPEINFO_Uuid());
}
}
} // Internal
template<typename T, typename ViewType>
Views::View<Views::ConvertIterator<typename Views::FilterIterator<typename ViewType::iterator>,
typename Internal::ConversionType<T, ViewType>::type&>> MakeDerivedFilterView(ViewType& view)
{
auto filterView = Views::MakeFilterView(view, DerivedTypeFilter<T>());
auto convertView = Views::MakeConvertView(filterView,
// Note that by default begin() returns a reference to the value, so the argument will
// already be by-reference so an extra reference doesn't need to be added and this
// function isn't being called by value.
[](decltype(*filterView.begin()) instance) -> typename Internal::ConversionType<T, ViewType>::type&
{
AZ_Assert(instance.get(), "Null pointer encountered.");
typename Internal::ConversionType<T, ViewType>::type* result =
azrtti_cast<typename Internal::ConversionType<T, ViewType>::type*>(instance.get());
AZ_Assert(result, "Unable to cast to target type.");
return *result;
}
);
return convertView;
}
template<typename T, typename ViewType>
Views::View<Views::ConvertIterator<typename Views::FilterIterator<typename ViewType::const_iterator>, const T&>> MakeDerivedFilterView(const ViewType& view)
{
auto filterView = Views::MakeFilterView(view, DerivedTypeFilter<T>());
auto convertView = Views::MakeConvertView(filterView,
// Note that by default begin() returns a reference to the value, so the argument will
// already be by-reference so an extra reference doesn't need to be added and this
// function isn't being called by value.
[](decltype(*filterView.begin()) instance) -> const T&
{
AZ_Assert(instance.get(), "Null pointer encountered.");
const T* result = azrtti_cast<const T*>(instance.get());
AZ_Assert(result, "Unable to cast to target type.");
return *result;
}
);
return convertView;
}
template<typename T, typename ViewType>
Views::View<Views::ConvertIterator<typename Views::FilterIterator<typename ViewType::iterator>,
typename Internal::ConversionType<T, ViewType>::type&>> MakeExactFilterView(ViewType& view)
{
auto filterView = Views::MakeFilterView(view, ExactTypeFilter<T>());
auto convertView = Views::MakeConvertView(filterView,
[](decltype(*filterView.begin()) instance) -> typename Internal::ConversionType<T, ViewType>::type&
{
AZ_Assert(instance.get(), "Null pointer encountered.");
typename Internal::ConversionType<T, ViewType>::type* result =
azrtti_cast<typename Internal::ConversionType<T, ViewType>::type*>(instance.get());
AZ_Assert(result, "Unable to cast to target type.");
return *result;
}
);
return convertView;
}
template<typename T, typename ViewType>
Views::View<Views::ConvertIterator<typename Views::FilterIterator<typename ViewType::const_iterator>, const T&>> MakeExactFilterView(const ViewType& view)
{
auto filterView = Views::MakeFilterView(view, ExactTypeFilter<T>());
auto convertView = Views::MakeConvertView(filterView,
[](decltype(*filterView.begin())& instance) -> const T&
{
AZ_Assert(instance.get(), "Null pointer encountered.");
const T* result = azrtti_cast<const T*>(instance.get());
AZ_Assert(result, "Unable to cast to target type.");
return *result;
}
);
return convertView;
}
} // Containers
} // SceneAPI
} // AZ
@@ -0,0 +1,53 @@
#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.
*
*/
namespace AZ
{
namespace SceneAPI
{
namespace Containers
{
// Utility class that stores (or references if possible) the given value
// but otherwise acts as a pointer. This can be useful for functions
// that require returning a pointer but don't store a local copy to
// return.
template<typename Type>
class ProxyPointer
{
public:
ProxyPointer(const Type& value);
Type& operator*();
Type* operator->();
private:
Type m_value;
};
template<typename Type>
class ProxyPointer<Type&>
{
public:
ProxyPointer(Type& value);
Type& operator*();
Type* operator->();
private:
Type& m_value;
};
} // Containers
} // SceneAPI
} // AZ
#include <SceneAPI/SceneCore/Containers/Utilities/ProxyPointer.inl>
@@ -0,0 +1,56 @@
/*
* 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.
*
*/
namespace AZ
{
namespace SceneAPI
{
namespace Containers
{
template<typename Type>
ProxyPointer<Type>::ProxyPointer(const Type& value)
: m_value(value)
{
}
template<typename Type>
Type& ProxyPointer<Type>::operator*()
{
return m_value;
}
template<typename Type>
Type* ProxyPointer<Type>::operator->()
{
return &m_value;
}
template<typename Type>
ProxyPointer<Type&>::ProxyPointer(Type& value)
: m_value(value)
{
}
template<typename Type>
Type& ProxyPointer<Type&>::operator*()
{
return m_value;
}
template<typename Type>
Type* ProxyPointer<Type&>::operator->()
{
return &m_value;
}
} // Containers
} // SceneAPI
} // AZ
@@ -0,0 +1,69 @@
/*
* 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/Math/Matrix3x4.h>
#include <AzCore/std/algorithm.h>
#include <AzCore/std/typetraits/is_base_of.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.h>
#include <SceneAPI/SceneCore/Containers/Views/SceneGraphChildIterator.h>
#include <SceneAPI/SceneCore/DataTypes/GraphData/ITransform.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
namespace AZ
{
namespace SceneAPI
{
namespace Utilities
{
DataTypes::MatrixType BuildWorldTransform(const Containers::SceneGraph& graph, Containers::SceneGraph::NodeIndex nodeIndex)
{
DataTypes::MatrixType outTransform = DataTypes::MatrixType::Identity();
while (nodeIndex.IsValid())
{
auto view = Containers::Views::MakeSceneGraphChildView<Containers::Views::AcceptEndPointsOnly>(graph, nodeIndex,
graph.GetContentStorage().begin(), true);
auto result = AZStd::find_if(view.begin(), view.end(), Containers::DerivedTypeFilter<DataTypes::ITransform>());
if (result != view.end())
{
// Check if the node has any child transform node
const DataTypes::MatrixType& azTransform = azrtti_cast<const DataTypes::ITransform*>(result->get())->GetMatrix();
outTransform = azTransform * outTransform;
}
else
{
// Check if the node itself is a transform node.
AZStd::shared_ptr<const DataTypes::ITransform> transformData = azrtti_cast<const DataTypes::ITransform*>(graph.GetNodeContent(nodeIndex));
if (transformData)
{
outTransform = transformData->GetMatrix() * outTransform;
}
}
if (graph.HasNodeParent(nodeIndex))
{
nodeIndex = graph.GetNodeParent(nodeIndex);
}
else
{
break;
}
}
return outTransform;
}
} // Utilities
} // SceneAPI
} // AZ
@@ -0,0 +1,38 @@
#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/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/DataTypes/MatrixType.h>
namespace AZ
{
namespace SceneAPI
{
namespace Containers
{
class Scene;
}
namespace Utilities
{
// Searches for any entries in the scene graph that are derived or match the given type.
// If "checkVirtualTypes" is true, a matching entry is also checked if it's not a
// virtual type.
template<typename T>
bool DoesSceneGraphContainDataLike(const Containers::Scene& scene, bool checkVirtualTypes);
SCENE_CORE_API DataTypes::MatrixType BuildWorldTransform(const Containers::SceneGraph& graph, Containers::SceneGraph::NodeIndex nodeIndex);
} // Utilities
} // SceneAPI
} // AZ
#include <SceneAPI/SceneCore/Containers/Utilities/SceneGraphUtilities.inl>
@@ -0,0 +1,58 @@
/*
* 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/std/algorithm.h>
#include <AzCore/std/typetraits/is_base_of.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/Views/FilterIterator.h>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.h>
#include <SceneAPI/SceneCore/Events/GraphMetaInfoBus.h>
namespace AZ
{
namespace SceneAPI
{
namespace Utilities
{
template<typename T>
bool DoesSceneGraphContainDataLike(const Containers::Scene& scene, bool checkVirtualTypes)
{
static_assert(AZStd::is_base_of<DataTypes::IGraphObject, T>::value, "Specified type T is not derived from IGraphObject.");
const Containers::SceneGraph& graph = scene.GetGraph();
if (checkVirtualTypes)
{
auto contentStorage = graph.GetContentStorage();
auto view = Containers::Views::MakeFilterView(contentStorage, Containers::DerivedTypeFilter<T>());
for (auto it = view.begin(); it != view.end(); ++it)
{
AZStd::set<Crc32> types;
EBUS_EVENT(Events::GraphMetaInfoBus, GetVirtualTypes, types, scene, graph.ConvertToNodeIndex(it.GetBaseIterator()));
// Check if the type is not a virtual type. If it is, this isn't a valid type for T.
if (types.empty())
{
return true;
}
}
return false;
}
else
{
Containers::SceneGraph::ContentStorageConstData graphContent = graph.GetContentStorage();
auto data = AZStd::find_if(graphContent.begin(), graphContent.end(), Containers::DerivedTypeFilter<T>());
return data != graphContent.end();
}
}
} // Utilities
} // SceneAPI
} // AZ