From path nodes and Variable nodes

This commit is contained in:
Chromium 2025-05-03 04:02:14 +01:00
parent 8e8a996812
commit f5c9b2833c
14 changed files with 186 additions and 1 deletions

View File

@ -5,6 +5,7 @@ using UnityEditor.Callbacks;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ImageProcessingGraph.Editor.Nodes.Types.Image.Variable_Node;
using UnityEditor.Experimental.GraphView;
using Debug = UnityEngine.Debug;
@ -47,6 +48,8 @@ namespace ImageProcessingGraph.Editor
public void RunGraph()
{
var bleh = GetAllVariableNodesWithTypes();
OnRun?.Invoke();
// Create and start the stopwatch to measure time
@ -72,7 +75,6 @@ namespace ImageProcessingGraph.Editor
failed = true;
}
// Stop the stopwatch after running the nodes
stopwatch.Stop();
// Log the elapsed time
@ -81,6 +83,30 @@ namespace ImageProcessingGraph.Editor
AssetDatabase.Refresh();
}
public List<(BaseImageNode node, System.Type type)> GetAllVariableNodesWithTypes()
{
var result = new List<(BaseImageNode node, System.Type type)>();
foreach (var node in nodes)
{
var nodeType = node.GetType();
var baseType = nodeType.BaseType;
if (baseType != null && baseType.IsGenericType)
{
if (baseType.GetGenericTypeDefinition() == typeof(VariableNode<>))
{
var genericArgument = baseType.GetGenericArguments()[0];
result.Add((node, genericArgument));
}
}
}
return result;
}
/// <summary>
/// Computes a topological execution order of nodes based on their dependencies.

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fd58cf45d01e429abcb9b8f4e3894b7a
timeCreated: 1746240608

View File

@ -0,0 +1,43 @@
using System.IO;
using ImageProcessingGraph.Editor.Nodes.NodeAttributes;
using UnityEditor;
using UnityEngine;
namespace ImageProcessingGraph.Editor.Nodes.Types.Image.From_Path_Nodes
{
public class FromPathNode<T> : BaseImageNode where T : UnityEngine.Object
{
[NodeAttributes.Input("Path")] public string path;
[NodeAttributes.Output("Output")] public T output;
public override void Process()
{
if (string.IsNullOrEmpty(path))
{
throw new System.ArgumentException("Path is empty or null. Cannot load asset.");
}
output = AssetDatabase.LoadAssetAtPath<T>(path);
if (output == null)
{
throw new System.Exception($"Failed to load asset of type {typeof(T)} at path: {path}.");
}
}
public override void CleanUp()
{
output = null;
path = null;
}
}
[NodeInfo("Load Texture2D From path", "Load From Path/Texture2D")]
public class Texture2DFromPath : FromPathNode<Texture2D> { }
[NodeInfo("Load Mesh From path", "Load From Path/Mesh")]
public class MeshFromPath : FromPathNode<Mesh> { }
[NodeInfo("Load Prefab From path", "Load From Path/Prefab")]
public class PrefabFromPath : FromPathNode<GameObject> { }
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dbdf66c38fa94127a4665bf6fd1ac011
timeCreated: 1746240631

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 899a77acab6b46d9af23756a397e7eea
timeCreated: 1746228396

View File

@ -0,0 +1,34 @@
using ImageProcessingGraph.Editor.Nodes.NodeAttributes;
using UnityEngine;
namespace ImageProcessingGraph.Editor.Nodes.Types.Image.Variable_Node
{
public class VariableNode<T> : BaseImageNode
{
public T input;
[NodeAttributes.Output("Output")] public T output;
public override void Process()
{
if(input != null)
this.output = input;
else
throw new System.NullReferenceException($"Input to VariableNode<{typeof(T).Name}> is null");
}
public override void CleanUp()
{
input = default;
output = default;
}
}
[NodeInfo("Texture2D Variable", "Variable/Texture2D")]
public class Texture2DVariableNode : VariableNode<Texture2D> { }
[NodeInfo("Mesh Variable", "Variable/Mesh")]
public class MeshVariableNode : VariableNode<Mesh> { }
[NodeInfo("Prefab Variable", "Variable/Prefab")]
public class PrefabVariableNode : VariableNode<GameObject> { }
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b10ad5cecfc74b548431deb876d3cb9a
timeCreated: 1746228592

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 024feeef7368f444696e947391b79685
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
public class ImageProcessingGraphDocumentationWindow : EditorWindow
{
[SerializeField]
private VisualTreeAsset m_VisualTreeAsset = default;
[MenuItem("Window/UI Toolkit/ImageProcessingGraphDocumentationWindow")]
public static void ShowExample()
{
ImageProcessingGraphDocumentationWindow wnd = GetWindow<ImageProcessingGraphDocumentationWindow>();
wnd.titleContent = new GUIContent("IPT Documentation");
}
public void CreateGUI()
{
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 819da168f89268440b928bc0eb32e67e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- m_VisualTreeAsset: {fileID: 9197481963319205126, guid: 880795e34c2278d49b48c227716214de, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,5 @@
.custom-label {
font-size: 20px;
-unity-font-style: bold;
color: rgb(68, 138, 255);
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a3d894085df56784383eca98ee7c9077
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0

View File

@ -0,0 +1,3 @@
<engine:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:engine="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Style src="project://database/Assets/Unity%20Image%20Processing/Editor/Scripts/Editor/Windows/Documentation/ImageProcessingGraphDocumentationWindow.uss?fileID=7433441132597879392&amp;guid=a3d894085df56784383eca98ee7c9077&amp;type=3#ImageProcessingGraphDocumentationWindow" />
</engine:UXML>

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 880795e34c2278d49b48c227716214de
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}