Skip to content

Commit

Permalink
GraphEditor NodeInput
Browse files Browse the repository at this point in the history
  • Loading branch information
Daethalus committed May 20, 2024
1 parent a1a9018 commit b4a76c9
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 31 deletions.
57 changes: 43 additions & 14 deletions Editor/Source/Fyrion/Editor/Editor/GraphEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,41 @@ namespace Fyrion
ResourceObject valueObject = Repository::Read(value);

String name = valueObject[GraphNodeValue::Input].Value<String>();
String typeName = valueObject[GraphNodeValue::Type].Value<String>();
String resourceTypeName = valueObject[GraphNodeValue::ResourceType].Value<String>();

TypeID typeId = 0;
if (valueObject.Has(GraphNodeValue::Value))
TypeID resourceTypeId = 0;

if (TypeHandler* typeHandler = Registry::FindTypeByName(typeName))
{
RID valueSuboject = valueObject.GetSubObject(GraphNodeValue::Value);
if (TypeHandler* typeHandler = Repository::GetResourceTypeHandler(valueSuboject))
{
typeId = typeHandler->GetTypeInfo().typeId;
}
typeId = typeHandler->GetTypeInfo().typeId;
}

if (TypeHandler* typeHandler = Registry::FindTypeByName(resourceTypeName))
{
resourceTypeId = typeHandler->GetTypeInfo().typeId;
}
else if (ResourceType* resourceType = Repository::GetResourceTypeByName(resourceTypeName))
{
resourceTypeId = Repository::GetResourceTypeId(resourceType);
}



GraphEditorNodePinLookup lookup = GraphEditorNodePinLookup{
.node = node->rid,
.name = name,
};

m_pins.Erase(lookup);

GraphEditorNodePin* pin = m_pins.Emplace(lookup, MakeUnique<GraphEditorNodePin>(GraphEditorNodePin{
.node = node,
.label = FormatName(name),
.name = name,
.typeId = typeId,
.kind = GraphEditorPinKind::Output,
.publicValue = valueObject[GraphNodeValue::PublicValue].Value<bool>()
.publicValue = valueObject[GraphNodeValue::PublicValue].Value<bool>(),
.resourceType = resourceTypeId
})).first->second.Get();

node->outputs.EmplaceBack(pin);
Expand Down Expand Up @@ -85,6 +95,8 @@ namespace Fyrion
{
if (param.HasAttribute<GraphInput>())
{
const GraphInput* graphInput = param.GetAttribute<GraphInput>();

RID value = {};
RID valueAsset = {};

Expand All @@ -104,7 +116,8 @@ namespace Fyrion
.typeId = param.GetFieldInfo().typeInfo.typeId,
.value = value,
.valueAsset = valueAsset,
.kind = GraphEditorPinKind::Input
.kind = GraphEditorPinKind::Input,
.resourceType = graphInput->typeId
})).first->second.Get();

graphEditorNode->inputs.EmplaceBack(pin);
Expand All @@ -115,6 +128,9 @@ namespace Fyrion
{
if (param.HasAttribute<GraphOutput>())
{
const GraphOutput* graphOutput = param.GetAttribute<GraphOutput>();


GraphEditorNodePin* pin = m_pins.Emplace(GraphEditorNodePinLookup{
.node = node,
.name = param.GetName(),
Expand All @@ -123,7 +139,8 @@ namespace Fyrion
.label = FormatName(param.GetName()),
.name = param.GetName(),
.typeId = param.GetFieldInfo().typeInfo.typeId,
.kind = GraphEditorPinKind::Output
.kind = GraphEditorPinKind::Output,
.resourceType = graphOutput->typeId
})).first->second.Get();

graphEditorNode->outputs.EmplaceBack(pin);
Expand Down Expand Up @@ -346,12 +363,20 @@ namespace Fyrion
RID valueAsset = Repository::CreateResource<GraphNodeValue>();
Repository::SetUUID(valueAsset, UUID::RandomUUID());

RID value = Repository::CreateResource(input->typeId);
Repository::SetUUID(value, UUID::RandomUUID());
//input->typeId

ResourceObject valueObject = Repository::Write(valueAsset);
valueObject[GraphNodeValue::Input] = input->name;
valueObject.SetSubObject(GraphNodeValue::Value, value);
valueObject[GraphNodeValue::Type] = Registry::FindTypeById(input->typeId)->GetName();
if (TypeHandler* resourceTypeHandler = Registry::FindTypeById(input->resourceType))
{
valueObject[GraphNodeValue::ResourceType] = resourceTypeHandler->GetName();
}
else if (ResourceType* resourceType = Repository::GetResourceTypeById(input->resourceType))
{
valueObject[GraphNodeValue::ResourceType] = Repository::GetResourceTypeName(resourceType);
}

valueObject.Commit();

ResourceObject nodeObject = Repository::Write(addOutput->node->rid);
Expand Down Expand Up @@ -411,7 +436,9 @@ namespace Fyrion
if (!input->value)
{
input->value = Repository::CreateResource(input->typeId);
Repository::SetUUID(input->value, UUID::RandomUUID());
input->valueAsset = Repository::CreateResource<GraphNodeValue>();
Repository::SetUUID(input->valueAsset, UUID::RandomUUID());

ResourceObject valueObject = Repository::Write(input->valueAsset);
valueObject[GraphNodeValue::Input] = input->name;
Expand All @@ -423,6 +450,8 @@ namespace Fyrion
nodeObject.Commit();
}
Repository::Commit(input->value, value);

m_assetTree.MarkDirty();
}

void GraphEditor::DeleteLink(RID link)
Expand Down
1 change: 1 addition & 0 deletions Editor/Source/Fyrion/Editor/Editor/GraphEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Fyrion
GraphEditorPinKind kind;
HashSet<RID> links{};
bool publicValue = false;
TypeID resourceType;
};

struct GraphEditorNodePinLookup
Expand Down
9 changes: 8 additions & 1 deletion Engine/Source/Fyrion/Assets/AssetTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ namespace Fyrion
{
constexpr static u32 Input = 0;
constexpr static u32 PublicValue = 1;
constexpr static u32 Value = 2;
constexpr static u32 Type = 2;
constexpr static u32 ResourceType = 3;
constexpr static u32 Value = 4;
};

struct GraphNodeAsset
Expand All @@ -47,4 +49,9 @@ namespace Fyrion
constexpr static u32 OutputNode = 2;
constexpr static u32 OutputPin = 3;
};

struct DCCMesh
{

};
}
5 changes: 5 additions & 0 deletions Engine/Source/Fyrion/Assets/Assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Fyrion
ResourceTypeBuilder<GraphNodeValue>::Builder()
.Value<GraphNodeValue::Input, String>("NodeType")
.Value<GraphNodeValue::PublicValue, bool>("PublicValue")
.Value<GraphNodeValue::Type, String>("Type")
.Value<GraphNodeValue::ResourceType, String>("ResourceType")
.SubObject<GraphNodeValue::Value>("Value")
.Build();

Expand All @@ -29,6 +31,9 @@ namespace Fyrion
.SubObjectSet<GraphNodeAsset::InputValues>("InputValues")
.Value<GraphNodeAsset::Label, Vec2>("Label")
.Build();

ResourceTypeBuilder<DCCMesh>::Builder()
.Build();
}

void RegisterAssets()
Expand Down
4 changes: 4 additions & 0 deletions Engine/Source/Fyrion/Core/GraphTypes.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#pragma once

#include "Fyrion/Common.hpp"

namespace Fyrion
{
struct GraphInput
{
TypeID typeId;
};

struct GraphOutput
{
TypeID typeId;
};


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "GraphNodes.hpp"

#include "Fyrion/Assets/AssetTypes.hpp"
#include "Fyrion/Core/GraphTypes.hpp"
#include "Fyrion/Core/Registry.hpp"
#include "Fyrion/Graphics/Graphics.hpp"
Expand Down Expand Up @@ -36,15 +37,14 @@ namespace Fyrion
geometryRender.Field<&GeometryRender::indexBuffer>("indexBuffer").Attribute<GraphInput>();
geometryRender.Attribute<ResourceGraphOutput>("Outputs/Geometry Render");


auto uploadGPUBuffer = Registry::Function<CreateBuffer>("Fyrion::CreateBuffer");
uploadGPUBuffer.Param<0>("data").Attribute<GraphInput>();
uploadGPUBuffer.Param<1>("usage").Attribute<GraphInput>();
uploadGPUBuffer.Param<2>("buffer").Attribute<GraphOutput>();
uploadGPUBuffer.Attribute<ResourceGraphNode>("Render/Create Buffer");

auto dccMeshLoader = Registry::Function<DCCMeshLoader>("Fyrion::DCCMeshLoader");
dccMeshLoader.Param<0>("mesh").Attribute<GraphInput>();
dccMeshLoader.Param<0>("mesh").Attribute<GraphInput>(GraphInput{.typeId = GetTypeID<DCCMesh>()});
dccMeshLoader.Param<1>("vertexData").Attribute<GraphOutput>();
dccMeshLoader.Param<2>("indexData").Attribute<GraphOutput>();
dccMeshLoader.Attribute<ResourceGraphNode>("Render/DCC Mesh Loader");
Expand Down
9 changes: 9 additions & 0 deletions Engine/Source/Fyrion/Resource/Repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ namespace Fyrion
return nullptr;
}

ResourceType* Repository::GetResourceTypeById(TypeID typeId)
{
if (const auto it = resourceTypes.Find(typeId))
{
return it->second.Get();
}
return nullptr;
}

TypeID Repository::GetResourceTypeId(ResourceType* resourceType)
{
return resourceType->typeId;
Expand Down
2 changes: 1 addition & 1 deletion Engine/Source/Fyrion/Resource/Repository.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Fyrion
{
FY_API void CreateResourceType(const ResourceTypeCreation& resourceTypeCreation);
FY_API ResourceType* GetResourceTypeByName(const StringView& typeName);
FY_API ResourceType* GetResourceTypeById(TypeID typeId);
FY_API TypeID GetResourceTypeId(ResourceType* resourceType);
FY_API StringView GetResourceTypeName(ResourceType* resourceType);
FY_API StringView GetResourceTypeSimpleName(ResourceType* resourceType);
Expand Down Expand Up @@ -70,7 +71,6 @@ namespace Fyrion
{
return *static_cast<const T*>(ReadData(rid));
}

}
}

Expand Down
23 changes: 10 additions & 13 deletions Engine/Source/Fyrion/Resource/ResourceSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,19 +779,16 @@ namespace Fyrion::ResourceSerialization
context.buffer.Append("\n");
}

if (!Repository::IsEmpty(rid))
{
context.Indent();
context.buffer.Append("_object: {\n");
context.AddIndentation();
context.AddIndentation();
WriteResource(context, rid);
context.RemoveIndentation();
context.RemoveIndentation();
context.Indent();
context.buffer.Append("}");
context.buffer.Append("\n");
}
context.Indent();
context.buffer.Append("_object: {\n");
context.AddIndentation();
context.AddIndentation();
WriteResource(context, rid);
context.RemoveIndentation();
context.RemoveIndentation();
context.Indent();
context.buffer.Append("}");
context.buffer.Append("\n");
}

void WriteResource(WriterContext& context, RID rid)
Expand Down

0 comments on commit b4a76c9

Please sign in to comment.