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,173 @@
/*
* 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.
*
*/
// AZ
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/std/smart_ptr/make_shared.h>
// Graph Model
#include <GraphModel/Model/Module/InputOutputNodes.h>
#include <GraphModel/Model/Graph.h>
#include <GraphModel/Model/Slot.h>
#include <GraphModel/Model/DataType.h>
namespace GraphModel
{
//////////////////////////////////////////////////////////////////////////////
// BaseInputOutputNode
void BaseInputOutputNode::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<BaseInputOutputNode, Node>()
->Version(0)
->Field("m_dataType", &BaseInputOutputNode::m_dataType)
;
}
}
BaseInputOutputNode::BaseInputOutputNode(GraphPtr graph, DataTypePtr dataType)
: Node(graph)
{
// Copy because m_dataType has to be non-const for use with SerializeContext, and dataType is const
m_dataType = AZStd::make_shared<DataType>(*dataType);
}
const char* BaseInputOutputNode::GetTitle() const
{
return m_title.c_str();
}
GraphModel::DataTypePtr BaseInputOutputNode::GetNodeDataType() const
{
return m_dataType;
}
AZStd::string BaseInputOutputNode::GetName() const
{
return GetSlot("name")->GetValue<AZStd::string>();
}
AZStd::string BaseInputOutputNode::GetDisplayName() const
{
return GetSlot("displayName")->GetValue<AZStd::string>();
}
AZStd::string BaseInputOutputNode::GetDescription() const
{
return GetSlot("description")->GetValue<AZStd::string>();
}
void BaseInputOutputNode::RegisterCommonSlots(AZStd::string_view directionName)
{
GraphModel::DataTypePtr stringDataType = GetGraphContext()->GetDataType<AZStd::string>();
RegisterSlot(GraphModel::SlotDefinition::CreateProperty("name", "Name", stringDataType, stringDataType->GetDefaultValue(),
AZStd::string::format("The official name for this %s", directionName.data())));
RegisterSlot(GraphModel::SlotDefinition::CreateProperty("displayName", "Display Name", stringDataType, stringDataType->GetDefaultValue(),
AZStd::string::format("The name for this %s, displayed to the user. Will use the above Name if left blank.", directionName.data())));
RegisterSlot(GraphModel::SlotDefinition::CreateProperty("description", "Description", stringDataType, stringDataType->GetDefaultValue(),
AZStd::string::format("A description of this %s, used for tooltips", directionName.data())));
}
//////////////////////////////////////////////////////////////////////////////
// GraphInputNode
void GraphInputNode::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<GraphInputNode, BaseInputOutputNode>()
->Version(0)
;
}
}
GraphInputNode::GraphInputNode(GraphModel::GraphPtr graph, DataTypePtr dataType)
: BaseInputOutputNode(graph, dataType)
{
m_title = m_dataType->GetDisplayName() + " Input";
RegisterSlots();
CreateSlotData();
}
void GraphInputNode::PostLoadSetup(GraphPtr graph, NodeId id)
{
m_title = m_dataType->GetDisplayName() + " Input";
Node::PostLoadSetup(graph, id);
}
AZStd::any GraphInputNode::GetDefaultValue() const
{
return GetSlot("defaultValue")->GetValue();
}
void GraphInputNode::RegisterSlots()
{
// Register just a single output slot for the data that is input through this node
RegisterSlot(GraphModel::SlotDefinition::CreateOutputData("value", "Value", m_dataType, "An external value provided as input to this graph"));
// Register meta-data properties
RegisterCommonSlots("input");
RegisterSlot(GraphModel::SlotDefinition::CreateProperty("defaultValue", "Default Value", m_dataType, m_dataType->GetDefaultValue(),
"The default value for this input when no data is provided externally"));
}
//////////////////////////////////////////////////////////////////////////////
// GraphOutputNode
void GraphOutputNode::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<GraphOutputNode, BaseInputOutputNode>()
->Version(0)
;
}
}
GraphOutputNode::GraphOutputNode(GraphModel::GraphPtr graph, DataTypePtr dataType)
: BaseInputOutputNode(graph, dataType)
{
m_title = m_dataType->GetDisplayName() + " Output";
RegisterSlots();
CreateSlotData();
}
void GraphOutputNode::PostLoadSetup(GraphPtr graph, NodeId id)
{
m_title = m_dataType->GetDisplayName() + " Output";
Node::PostLoadSetup(graph, id);
}
void GraphOutputNode::RegisterSlots()
{
// Register just a single input slot for the data that is output through this node
RegisterSlot(GraphModel::SlotDefinition::CreateInputData("value", "Value", m_dataType, m_dataType->GetDefaultValue(), "A value output by this graph for external use"));
// Register meta-data properties
RegisterCommonSlots("output");
}
}
@@ -0,0 +1,155 @@
/*
* 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.
*
*/
// AZ
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzCore/IO/FileIO.h>
#include <AzCore/Serialization/Utils.h>
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzCore/Component/ComponentApplicationBus.h>
// Graph Model
#include <GraphModel/Model/Graph.h>
#include <GraphModel/Model/IGraphContext.h>
#include <GraphModel/Model/Module/ModuleGraphManager.h>
namespace GraphModel
{
ModuleGraphManager::ModuleGraphManager(IGraphContextPtr graphContext, AZ::SerializeContext* serializeContext)
: m_graphContext(graphContext)
, m_moduleFileExtension(graphContext->GetModuleFileExtension())
, m_serializeContext(serializeContext)
{
if (m_serializeContext == nullptr)
{
// use the default app serialize context
AZ::ComponentApplicationBus::BroadcastResult(m_serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
if (!m_serializeContext)
{
AZ_Error(graphContext->GetSystemName(), false, "ModuleGraphManager: No serialize context provided! We will not be able to load module files.");
}
}
AzToolsFramework::AssetSystemBus::Handler::BusConnect();
}
ModuleGraphManager::~ModuleGraphManager()
{
AzToolsFramework::AssetSystemBus::Handler::BusDisconnect();
}
void ModuleGraphManager::SourceFileChanged(AZStd::string relativePath, AZStd::string scanFolder, AZ::Uuid sourceUUID)
{
AZStd::string extension;
if (AzFramework::StringFunc::Path::GetExtension(relativePath.data(), extension) && extension == m_moduleFileExtension)
{
// Force the manager to reload the graph next time GetModuleGraph() is called.
m_graphs.erase(sourceUUID);
}
}
ConstGraphPtr ModuleGraphManager::LoadGraph(AZ::IO::FileIOStream& stream)
{
GraphPtr graph = AZStd::make_shared<Graph>();
bool loadSuccess = AZ::Utils::LoadObjectFromStreamInPlace(stream, *graph, m_serializeContext);
if (loadSuccess)
{
graph->PostLoadSetup(m_graphContext.lock());
return graph;
}
else
{
return nullptr;
}
}
AZ::Outcome<ConstGraphPtr, AZStd::string> ModuleGraphManager::LoadGraph(AZ::Uuid sourceFileId)
{
bool gotSourceInfo = false;
AZ::Data::AssetInfo assetInfo;
AZStd::string watchFolder;
AzToolsFramework::AssetSystemRequestBus::BroadcastResult(gotSourceInfo, &AzToolsFramework::AssetSystem::AssetSystemRequest::GetSourceInfoBySourceUUID, sourceFileId, assetInfo, watchFolder);
if (!gotSourceInfo)
{
return AZ::Failure<AZStd::string>("Could not get source file info for [" + sourceFileId.ToString<AZStd::string>() + "]");
}
AZStd::string extension;
if (!AzFramework::StringFunc::Path::GetExtension(assetInfo.m_relativePath.data(), extension) || extension != m_moduleFileExtension)
{
return AZ::Failure<AZStd::string>("Incorrect extension [" + assetInfo.m_relativePath + "]. Must be [" + m_moduleFileExtension + "]");
}
AZStd::string fullAssetPath;
AzFramework::StringFunc::Path::Join(watchFolder.data(), assetInfo.m_relativePath.data(), fullAssetPath);
AZ::IO::FileIOStream stream;
stream.Open(fullAssetPath.data(), AZ::IO::OpenMode::ModeRead);
if (!stream.IsOpen())
{
return AZ::Failure<AZStd::string>("Could not open [" + fullAssetPath + "]");
}
ConstGraphPtr graph = LoadGraph(stream);
if (!graph)
{
return AZ::Failure<AZStd::string>("Could not load [" + fullAssetPath + "]");
}
return AZ::Success(graph);
}
AZ::Outcome<ConstGraphPtr, AZStd::string> ModuleGraphManager::GetModuleGraph(AZ::Uuid sourceFileId)
{
auto iter = m_graphs.find(sourceFileId);
// If the soure file has never been loaded, go ahead and load it now
if (iter == m_graphs.end())
{
AZ::Outcome<ConstGraphPtr, AZStd::string> graphOutcome = LoadGraph(sourceFileId);
if (!graphOutcome.IsSuccess())
{
return graphOutcome;
}
m_graphs[sourceFileId] = graphOutcome.GetValue();
return graphOutcome;
}
else
{
// If the Graph has been loaded and is still in memory, we can just return it
ConstGraphPtr graph = iter->second.lock();
if (graph)
{
return AZ::Success(graph);
}
// The Graph has been released at some point and needs to be loaded again
else
{
AZ::Outcome<ConstGraphPtr, AZStd::string> graphOutcome = LoadGraph(sourceFileId);
if (!graphOutcome.IsSuccess())
{
m_graphs.erase(iter);
return graphOutcome;
}
m_graphs[sourceFileId] = graphOutcome.GetValue();
return graphOutcome;
}
}
}
} // namespace GraphModel
@@ -0,0 +1,109 @@
/*
* 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.
*
*/
// AZ
#include <AzFramework/StringFunc/StringFunc.h>
// Graph Model
#include <GraphModel/Model/Graph.h>
#include <GraphModel/Model/Slot.h>
#include <GraphModel/Model/Module/ModuleNode.h>
#include <GraphModel/Model/Module/ModuleGraphManager.h>
#include <GraphModel/Model/Module/InputOutputNodes.h>
#include <GraphModel/Model/IGraphContext.h>
namespace GraphModel
{
void ModuleNode::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<ModuleNode, Node>()
->Version(0)
->Field("m_moduleGraphFileId", &ModuleNode::m_moduleGraphFileId)
->Field("m_nodeTitle", &ModuleNode::m_nodeTitle)
;
}
}
ModuleNode::ModuleNode(GraphPtr ownerGraph, AZ::Uuid moduleGraphFileId, AZStd::string_view moduleGraphFileName)
: Node(ownerGraph)
, m_moduleGraphFileId(moduleGraphFileId)
{
// The module file name (without extension) is the node title
if (!AzFramework::StringFunc::Path::GetFileName(moduleGraphFileName.data(), m_nodeTitle))
{
AZ_Error(ownerGraph->GetSystemName(), false, "Could not get node name from file string [%s]", moduleGraphFileName.data());
}
LoadModuleGraph(ownerGraph->GetContext()->GetModuleGraphManager());
RegisterSlots();
CreateSlotData();
}
void ModuleNode::PostLoadSetup(GraphPtr ownerGraph, NodeId id)
{
LoadModuleGraph(ownerGraph->GetContext()->GetModuleGraphManager());
Node::PostLoadSetup(ownerGraph, id);
}
const char* ModuleNode::GetTitle() const
{
return m_nodeTitle.c_str();
}
void ModuleNode::LoadModuleGraph(ModuleGraphManagerPtr moduleGraphManager)
{
auto result = moduleGraphManager->GetModuleGraph(m_moduleGraphFileId);
if (result.IsSuccess())
{
m_moduleGraph = result.GetValue();
}
else
{
AZ_Warning(GetGraph()->GetSystemName(), false, "%s (Module Node [%s])", result.GetError().data(), m_nodeTitle.data());
}
}
void ModuleNode::RegisterSlots()
{
if (m_moduleGraph)
{
for (auto iter : m_moduleGraph->GetNodes())
{
ConstNodePtr node = iter.second;
if (AZStd::shared_ptr<const GraphInputNode> inputNode = azrtti_cast<const GraphInputNode*>(node))
{
RegisterSlot(GraphModel::SlotDefinition::CreateInputData(
inputNode->GetName(),
inputNode->GetDisplayName(),
inputNode->GetNodeDataType(),
inputNode->GetDefaultValue(),
inputNode->GetDescription()));
}
else if (AZStd::shared_ptr<const GraphOutputNode> outputNode = azrtti_cast<const GraphOutputNode*>(node))
{
RegisterSlot(GraphModel::SlotDefinition::CreateOutputData(
outputNode->GetName(),
outputNode->GetDisplayName(),
outputNode->GetNodeDataType(),
outputNode->GetDescription()));
}
}
}
}
}