merge from main

This commit is contained in:
greerdv
2021-05-19 12:14:25 +01:00
11816 changed files with 189923 additions and 1002401 deletions
@@ -37,4 +37,4 @@ namespace AZ
}
} // namespace SceneCore
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -41,4 +41,4 @@ namespace AZ
};
} // namespace SceneCore
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -45,4 +45,4 @@ namespace AZ
};
} // namespace SceneCore
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -44,4 +44,4 @@ namespace AZ
};
} // namespace SceneCore
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -42,4 +42,4 @@ namespace AZ
};
} // namespace SceneCore
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -37,4 +37,4 @@ namespace AZ
}
} // namespace SceneCore
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -40,4 +40,4 @@ namespace AZ
};
} // namespace SceneCore
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -13,9 +13,135 @@
#include <SceneAPI/SceneCore/Containers/GraphObjectProxy.h>
#include <AzCore/Casting/numeric_cast.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzToolsFramework/API/EditorPythonConsoleBus.h>
namespace AZ
{
namespace Python
{
static const char* const None = "None";
class PythonBehaviorInfo final
{
public:
AZ_RTTI(PythonBehaviorInfo, "{8055BD03-5B3B-490D-AEC5-1B1E2616D529}");
AZ_CLASS_ALLOCATOR(PythonBehaviorInfo, AZ::SystemAllocator, 0);
static void Reflect(AZ::ReflectContext* context);
PythonBehaviorInfo(const AZ::BehaviorClass* behaviorClass);
PythonBehaviorInfo() = delete;
protected:
bool IsMemberLike(const AZ::BehaviorMethod& method, const AZ::TypeId& typeId) const;
AZStd::string FetchPythonType(const AZ::BehaviorParameter& param) const;
void WriteMethod(AZStd::string_view methodName, const AZ::BehaviorMethod& behaviorMethod);
private:
const AZ::BehaviorClass* m_behaviorClass = nullptr;
AZStd::vector<AZStd::string> m_methodList;
};
PythonBehaviorInfo::PythonBehaviorInfo(const AZ::BehaviorClass* behaviorClass)
: m_behaviorClass(behaviorClass)
{
AZ_Assert(m_behaviorClass, "PythonBehaviorInfo requires a valid behaviorClass pointer");
for (const auto& entry : behaviorClass->m_methods)
{
WriteMethod(entry.first, *entry.second);
}
}
void PythonBehaviorInfo::Reflect(AZ::ReflectContext* context)
{
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
if (behaviorContext)
{
behaviorContext->Class<PythonBehaviorInfo>()
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Module, "scene.graph")
->Property("className", [](const PythonBehaviorInfo& self)
{ return self.m_behaviorClass->m_name; }, nullptr)
->Property("classUuid", [](const PythonBehaviorInfo& self)
{ return self.m_behaviorClass->m_typeId.ToString<AZStd::string>(); }, nullptr)
->Property("methodList", BehaviorValueGetter(&PythonBehaviorInfo::m_methodList), nullptr);
}
}
bool PythonBehaviorInfo::IsMemberLike(const AZ::BehaviorMethod& method, const AZ::TypeId& typeId) const
{
return method.IsMember() || (method.GetNumArguments() > 0 && method.GetArgument(0)->m_typeId == typeId);
}
AZStd::string PythonBehaviorInfo::FetchPythonType(const AZ::BehaviorParameter& param) const
{
using namespace AzToolsFramework;
EditorPythonConsoleInterface* editorPythonConsoleInterface = AZ::Interface<EditorPythonConsoleInterface>::Get();
if (editorPythonConsoleInterface)
{
return editorPythonConsoleInterface->FetchPythonTypeName(param);
}
return None;
}
void PythonBehaviorInfo::WriteMethod(AZStd::string_view methodName, const AZ::BehaviorMethod& behaviorMethod)
{
// if the method is a static method then it is not a part of the abstract class
const bool isMemberLike = IsMemberLike(behaviorMethod, m_behaviorClass->m_typeId);
if (isMemberLike == false)
{
return;
}
AZStd::string buffer;
AZStd::vector<AZStd::string> pythonArgs;
AzFramework::StringFunc::Append(buffer, "def ");
AzFramework::StringFunc::Append(buffer, methodName.data());
AzFramework::StringFunc::Append(buffer, "(");
pythonArgs.emplace_back("self");
AZStd::string bufferArg;
for (size_t argIndex = 1; argIndex < behaviorMethod.GetNumArguments(); ++argIndex)
{
const AZStd::string* name = behaviorMethod.GetArgumentName(argIndex);
if (!name || name->empty())
{
bufferArg = AZStd::string::format(" arg%zu", argIndex);
}
else
{
bufferArg = *name;
}
AZStd::string_view type = FetchPythonType(*behaviorMethod.GetArgument(argIndex));
if (!type.empty())
{
AzFramework::StringFunc::Append(bufferArg, ": ");
AzFramework::StringFunc::Append(bufferArg, type.data());
}
pythonArgs.push_back(bufferArg);
bufferArg.clear();
}
AZStd::string resultValue{ None };
if (behaviorMethod.HasResult() && behaviorMethod.GetResult())
{
resultValue = FetchPythonType(*behaviorMethod.GetResult());
}
AZStd::string argsList;
AzFramework::StringFunc::Join(buffer, pythonArgs.begin(), pythonArgs.end(), ",");
AzFramework::StringFunc::Append(buffer, ") -> ");
AzFramework::StringFunc::Append(buffer, resultValue.c_str());
m_methodList.emplace_back(buffer);
}
}
namespace SceneAPI
{
namespace Containers
@@ -25,11 +151,29 @@ namespace AZ
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
if (behaviorContext)
{
Python::PythonBehaviorInfo::Reflect(context);
behaviorContext->Class<DataTypes::IGraphObject>();
behaviorContext->Class<GraphObjectProxy>()
->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
->Attribute(AZ::Script::Attributes::Module, "scene.graph")
->Attribute(AZ::Script::Attributes::ExcludeFrom, AZ::Script::Attributes::ExcludeFlags::All)
->Method("CastWithTypeName", &GraphObjectProxy::CastWithTypeName)
->Method("Invoke", &GraphObjectProxy::Invoke)
->Method("GetClassInfo", [](GraphObjectProxy& self) -> Python::PythonBehaviorInfo*
{
if (self.m_pythonBehaviorInfo)
{
return self.m_pythonBehaviorInfo.get();
}
if (self.m_behaviorClass)
{
self.m_pythonBehaviorInfo = AZStd::make_shared<Python::PythonBehaviorInfo>(self.m_behaviorClass);
return self.m_pythonBehaviorInfo.get();
}
return nullptr;
})
;
}
}
@@ -16,6 +16,11 @@
namespace AZ
{
namespace Python
{
class PythonBehaviorInfo;
}
namespace SceneAPI
{
namespace Containers
@@ -44,6 +49,7 @@ namespace AZ
private:
AZStd::shared_ptr<const DataTypes::IGraphObject> m_graphObject;
const AZ::BehaviorClass* m_behaviorClass = nullptr;
AZStd::shared_ptr<Python::PythonBehaviorInfo> m_pythonBehaviorInfo;
};
} // Containers
@@ -55,4 +55,4 @@ namespace AZ
} // Containers
} // SceneAPI
} // AZ
} // AZ
@@ -72,4 +72,4 @@ namespace AZ
}
} // Containers
} // SceneAPI
} // AZ
} // AZ
@@ -139,4 +139,4 @@ namespace AZ
} // SceneAPI
} // AZ
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.inl>
#include <SceneAPI/SceneCore/Containers/Utilities/Filters.inl>
@@ -50,4 +50,4 @@ namespace AZ
} // SceneAPI
} // AZ
#include <SceneAPI/SceneCore/Containers/Utilities/ProxyPointer.inl>
#include <SceneAPI/SceneCore/Containers/Utilities/ProxyPointer.inl>
@@ -70,4 +70,4 @@ namespace AZ
} // SceneAPI
} // AZ
#include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.inl>
#include <SceneAPI/SceneCore/DataTypes/DataTypeUtilities.inl>
@@ -97,6 +97,9 @@ namespace AZ
};
} // DataTypes
} // SceneAPI
AZ_TYPE_INFO_SPECIALIZE(SceneAPI::DataTypes::Color, "{937E3BF8-5204-4D40-A8DA-C8F083C89F9F}");
} // AZ
namespace AZStd
@@ -57,4 +57,4 @@ namespace AZ
};
}
}
}
}
@@ -41,4 +41,4 @@ namespace AZ
};
} // DataTypes
} // SceneAPI
} // AZ
} // AZ
@@ -34,4 +34,4 @@ namespace AZ
};
}
}
}
}
@@ -18,6 +18,7 @@
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
#include <SceneAPI/SceneCore/Containers/RuleContainer.h>
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
#include <SceneAPI/SceneCore/Utilities/SceneGraphSelector.h>
namespace AZ
{
@@ -50,7 +51,12 @@ namespace AZ
{
AZStd::vector<AZ::Color> clothData;
const char* meshNodeName = graph.GetNodeName(meshNodeIndex).GetPath();
AZStd::string_view meshNodeName = graph.GetNodeName(meshNodeIndex).GetPath();
if (meshNodeName.ends_with(Utilities::OptimizedMeshSuffix))
{
meshNodeName.remove_suffix(Utilities::OptimizedMeshSuffix.size());
}
for (size_t ruleIndex = 0; ruleIndex < rules.GetRuleCount(); ++ruleIndex)
{
@@ -37,4 +37,4 @@ namespace AZ
}
} // namespace Events
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -26,4 +26,4 @@ namespace AZ
}
} // Events
} // SceneAPI
} // AZ
} // AZ
@@ -147,4 +147,4 @@ namespace AZ
}
} // Events
} // SceneAPI
} // AZ
} // AZ
@@ -123,4 +123,4 @@ namespace AZ
};
} // namespace Events
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -90,4 +90,4 @@ namespace AZ
} // Events
} // SceneAPI
} // AZ
} // AZ
@@ -81,4 +81,4 @@ namespace AZ
};
} // Events
} // SceneAPI
} // AZ
} // AZ
@@ -54,4 +54,4 @@ namespace AZ
}
} // Events
} // SceneAPI
} // AZ
} // AZ
@@ -55,4 +55,4 @@ namespace AZ
inline SceneSerialization::~SceneSerialization() = default;
} // namespace Events
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -92,4 +92,4 @@ namespace AZ
};
} // Events
} // SceneAPI
} // AZ
} // AZ
@@ -32,4 +32,4 @@ namespace AZ
};
using SceneBuilderDependencyBus = EBus<SceneBuilderDependencyRequests>;
} // namespace SceneAPI
} // namespace AZ
} // namespace AZ
@@ -20,6 +20,7 @@
#include <AzCore/Component/ComponentApplication.h>
#include <AzCore/Serialization/Json/RegistrationContext.h>
#include <AzCore/Serialization/Json/JsonSystemComponent.h>
#include <AzToolsFramework/API/EditorPythonConsoleBus.h>
#include <SceneAPI/SceneCore/Containers/Scene.h>
#include <SceneAPI/SceneCore/Containers/SceneGraph.h>
@@ -363,6 +364,10 @@ namespace AZ
MOCK_METHOD1(UnregisterComponentDescriptor, void(const AZ::ComponentDescriptor*));
MOCK_METHOD1(RegisterEntityAddedEventHandler, void(AZ::EntityAddedEvent::Handler&));
MOCK_METHOD1(RegisterEntityRemovedEventHandler, void(AZ::EntityRemovedEvent::Handler&));
MOCK_METHOD1(RegisterEntityActivatedEventHandler, void(AZ::EntityActivatedEvent::Handler&));
MOCK_METHOD1(RegisterEntityDeactivatedEventHandler, void(AZ::EntityDeactivatedEvent::Handler&));
MOCK_METHOD1(SignalEntityActivated, void(AZ::Entity*));
MOCK_METHOD1(SignalEntityDeactivated, void(AZ::Entity*));
MOCK_METHOD1(RemoveEntity, bool(AZ::Entity*));
MOCK_METHOD1(DeleteEntity, bool(const AZ::EntityId&));
MOCK_METHOD1(GetEntityName, AZStd::string(const AZ::EntityId&));
@@ -378,6 +383,25 @@ namespace AZ
MOCK_CONST_METHOD1(QueryApplicationType, void(AZ::ApplicationTypeQuery&));
};
class MockEditorPythonConsoleInterface final
: public AzToolsFramework::EditorPythonConsoleInterface
{
public:
MockEditorPythonConsoleInterface()
{
AZ::Interface<AzToolsFramework::EditorPythonConsoleInterface>::Register(this);
}
~MockEditorPythonConsoleInterface()
{
AZ::Interface<AzToolsFramework::EditorPythonConsoleInterface>::Unregister(this);
}
MOCK_CONST_METHOD1(GetModuleList, void(AZStd::vector<AZStd::string_view>&));
MOCK_CONST_METHOD1(GetGlobalFunctionList, void(GlobalFunctionCollection&));
MOCK_METHOD1(FetchPythonTypeName, AZStd::string(const AZ::BehaviorParameter&));
};
//
// SceneGraphBehaviorScriptTest
//
@@ -386,6 +410,7 @@ namespace AZ
{
public:
AZStd::unique_ptr<MockSceneComponentApplication> m_componentApplication;
AZStd::unique_ptr<MockEditorPythonConsoleInterface> m_editorPythonConsoleInterface;
AZStd::unique_ptr<AZ::ScriptContext> m_scriptContext;
AZStd::unique_ptr<AZ::BehaviorContext> m_behaviorContext;
AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
@@ -454,6 +479,15 @@ namespace AZ
{
return this->m_serializeContext.get();
}));
m_editorPythonConsoleInterface = AZStd::make_unique<MockEditorPythonConsoleInterface>();
}
void SetupEditorPythonConsoleInterface()
{
EXPECT_CALL(*m_editorPythonConsoleInterface, FetchPythonTypeName(::testing::_))
.Times(4)
.WillRepeatedly(::testing::Invoke([](const AZ::BehaviorParameter&) {return "int"; }));
}
void TearDown() override
@@ -562,6 +596,38 @@ namespace AZ
ExpectExecute("TestExpectEquals(value, 17)");
}
TEST_F(SceneGraphBehaviorScriptTest, GraphObjectProxy_GetClassInfo_Loads)
{
SetupEditorPythonConsoleInterface();
ExpectExecute("builder = MockBuilder()");
ExpectExecute("builder:BuildSceneGraph()");
ExpectExecute("scene = builder:GetScene()");
ExpectExecute("nodeG = scene.graph:FindWithPath('A.C.E.G')");
ExpectExecute("proxy = scene.graph:GetNodeContent(nodeG)");
ExpectExecute("TestExpectTrue(proxy:CastWithTypeName('MockIGraphObject'))");
ExpectExecute("info = proxy:GetClassInfo()");
ExpectExecute("TestExpectTrue(info ~= nil)");
}
TEST_F(SceneGraphBehaviorScriptTest, GraphObjectProxy_GetClassInfo_CorrectFormats)
{
SetupEditorPythonConsoleInterface();
ExpectExecute("builder = MockBuilder()");
ExpectExecute("builder:BuildSceneGraph()");
ExpectExecute("scene = builder:GetScene()");
ExpectExecute("nodeG = scene.graph:FindWithPath('A.C.E.G')");
ExpectExecute("proxy = scene.graph:GetNodeContent(nodeG)");
ExpectExecute("TestExpectTrue(proxy:CastWithTypeName('MockIGraphObject'))");
ExpectExecute("info = proxy:GetClassInfo()");
ExpectExecute("TestExpectTrue(info.className == 'MockIGraphObject')");
ExpectExecute("TestExpectTrue(info.classUuid == '{66A082CC-851D-4E1F-ABBD-45B58A216CFA}')");
ExpectExecute("TestExpectTrue(info.methodList[1] == 'def GetId(self) -> int')");
ExpectExecute("TestExpectTrue(info.methodList[2] == 'def SetId(self, arg1: int) -> None')");
ExpectExecute("TestExpectTrue(info.methodList[3] == 'def AddAndSet(self, arg1: int, arg2: int) -> None')");
}
//
// SceneManifestBehaviorScriptTest is meant to test the script abilities of the SceneManifest
//
@@ -296,4 +296,4 @@ TEST_F(DataObjectTest, Reflect_ReflectIsCalledMultipleTimesOnSameStoredObject_Re
AZ::SerializeContext context;
result->ReflectData(&context);
result->ReflectData(&context);
}
}
@@ -323,4 +323,4 @@ namespace AZ
} // Events
} // SceneAPI
} // AZ
} // AZ
@@ -55,4 +55,4 @@ TEST(MaterialIO, Material_SetDataFromMtl_TextureMissingMapAndFile_DoesNotGetStuc
material.SetDataFromMtl(materialXmlNode);
azdestroy(xmlDoc);
}
}
@@ -62,4 +62,4 @@ namespace AZ
}
} // SceneCore
} // SceneAPI
} // AZ
} // AZ
@@ -64,4 +64,4 @@ namespace AZ
}
}
}
}
}
@@ -30,4 +30,4 @@ namespace AZ
};
}
}
}
}
@@ -47,7 +47,7 @@ namespace AZ
Containers::SceneGraph::NodeIndex SceneGraphSelector::RemapToOptimizedMesh(const Containers::SceneGraph& graph, const Containers::SceneGraph::NodeIndex& index)
{
const auto& nodeName = graph.GetNodeName(index);
const AZStd::string optimizedName = AZStd::string(nodeName.GetPath(), nodeName.GetPathLength()) + "_optimized";
const AZStd::string optimizedName = AZStd::string(nodeName.GetPath(), nodeName.GetPathLength()).append(OptimizedMeshSuffix);
if (auto optimizedIndex = graph.Find(optimizedName); optimizedIndex.IsValid())
{
return optimizedIndex;
@@ -22,6 +22,8 @@ namespace AZ::SceneAPI::DataTypes { class ISceneNodeSelectionList; }
namespace AZ::SceneAPI::Utilities
{
inline constexpr AZStd::string_view OptimizedMeshSuffix = "_optimized";
// SceneGraphSelector provides utilities including converting selected and unselected node lists
// in the MeshGroup into the final target node list.
class SceneGraphSelector