View Image Node and custom editors allowed
This commit is contained in:
parent
a3d79f09b2
commit
b1b129c8c1
@ -10,6 +10,13 @@ namespace ImageProcessingGraph.Editor
|
|||||||
{
|
{
|
||||||
public FieldInfo fieldInfo;
|
public FieldInfo fieldInfo;
|
||||||
private VisualElement _exposedPropertyContainer;
|
private VisualElement _exposedPropertyContainer;
|
||||||
|
|
||||||
|
public delegate void OnPortConnectedEvent();
|
||||||
|
public OnPortConnectedEvent OnPortConnected;
|
||||||
|
|
||||||
|
public delegate void OnPortDisconnectedEvent();
|
||||||
|
public OnPortDisconnectedEvent OnPortDisconnected;
|
||||||
|
|
||||||
public VisualElement ExposedPropertyContainer
|
public VisualElement ExposedPropertyContainer
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
@ -27,6 +34,24 @@ namespace ImageProcessingGraph.Editor
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Connect(Edge edge)
|
||||||
|
{
|
||||||
|
base.Connect(edge);
|
||||||
|
OnPortConnected?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Disconnect(Edge edge)
|
||||||
|
{
|
||||||
|
base.Disconnect(edge);
|
||||||
|
OnPortDisconnected?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void PublicOnConnected(Port obj)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public static IPTPort Create(IEdgeConnectorListener connectorListener, bool isInput, Type type)
|
public static IPTPort Create(IEdgeConnectorListener connectorListener, bool isInput, Type type)
|
||||||
{
|
{
|
||||||
var port = new IPTPort(Orientation.Horizontal, isInput ? Direction.Input : Direction.Output,
|
var port = new IPTPort(Orientation.Horizontal, isInput ? Direction.Input : Direction.Output,
|
||||||
|
@ -53,8 +53,7 @@ namespace ImageProcessingGraph.Editor
|
|||||||
Stopwatch stopwatch = new Stopwatch();
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
|
|
||||||
if (runOrder == null)
|
runOrder = GetExecutionOrder(this.nodes, this.connections);
|
||||||
runOrder = GetExecutionOrder(this.nodes, this.connections);
|
|
||||||
|
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
|
|
||||||
@ -67,6 +66,12 @@ namespace ImageProcessingGraph.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var VARIABLE in runOrder)
|
||||||
|
{
|
||||||
|
if(!VARIABLE.RunCleanUp())
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Stop the stopwatch after running the nodes
|
// Stop the stopwatch after running the nodes
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
|
|
||||||
|
@ -125,6 +125,26 @@ namespace ImageProcessingGraph.Editor
|
|||||||
Debug.Log("Uppies");
|
Debug.Log("Uppies");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool RunCleanUp()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.CleanUp();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
onFailed?.Invoke();
|
||||||
|
Debug.LogError(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void CleanUp()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void SetPosition(Rect position) => this.position = position;
|
public void SetPosition(Rect position) => this.position = position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows;
|
||||||
|
|
||||||
namespace ImageProcessingGraph.Editor.Nodes.NodeAttributes
|
namespace ImageProcessingGraph.Editor.Nodes.NodeAttributes
|
||||||
{
|
{
|
||||||
@ -8,16 +9,19 @@ namespace ImageProcessingGraph.Editor.Nodes.NodeAttributes
|
|||||||
private string name;
|
private string name;
|
||||||
private string menuItem;
|
private string menuItem;
|
||||||
private string ussPath;
|
private string ussPath;
|
||||||
|
private Type editorType;
|
||||||
|
|
||||||
public string Title => name;
|
public string Title => name;
|
||||||
public string MenuItem => menuItem;
|
public string MenuItem => menuItem;
|
||||||
public string UssPath => ussPath;
|
public string UssPath => ussPath;
|
||||||
|
public Type EditorType => editorType;
|
||||||
|
|
||||||
public NodeInfoAttribute(string name, string menuItem = "", bool requiresImage = false, string ussPath = null)
|
public NodeInfoAttribute(string name, string menuItem = "", bool requiresImage = false, string ussPath = null, Type editorType = null)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.menuItem = menuItem;
|
this.menuItem = menuItem;
|
||||||
this.ussPath = ussPath;
|
this.ussPath = ussPath;
|
||||||
|
this.editorType = editorType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace ImageProcessingGraph.Editor.Nodes.Import_Nodes
|
namespace ImageProcessingGraph.Editor.Nodes.Import_Nodes
|
||||||
{
|
{
|
||||||
[NodeInfo("Texture Import", "Imports/Import Texture", true)]
|
[NodeInfo("Texture Import", "Imports/Import Texture")]
|
||||||
public class Texture2DImport : BaseImageNode
|
public class Texture2DImport : BaseImageNode
|
||||||
{
|
{
|
||||||
[NodeAttributes.Input("")]
|
[NodeAttributes.Input("")]
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b462f37a291b49a696e3b4b554d26868
|
||||||
|
timeCreated: 1745899248
|
@ -0,0 +1,34 @@
|
|||||||
|
using ImageProcessingGraph.Editor.Nodes.NodeAttributes;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace ImageProcessingGraph.Editor.Nodes.Types.Image.Utilities.ViewNode
|
||||||
|
{
|
||||||
|
[NodeInfo("View Texture", "Utility/View Texture", false, null ,typeof(ViewTextureNodeEditor))]
|
||||||
|
public class ViewTextureNode : BaseImageNode
|
||||||
|
{
|
||||||
|
[NodeAttributes.Input("Texture")] public Texture2D texture;
|
||||||
|
[NodeAttributes.Input("Image Data")] public ImageData imageData;
|
||||||
|
|
||||||
|
public delegate void OnImageUpdated();
|
||||||
|
public OnImageUpdated onImageUpdated;
|
||||||
|
|
||||||
|
public override void Process()
|
||||||
|
{
|
||||||
|
if (texture == null)
|
||||||
|
{
|
||||||
|
texture = imageData.ToTexture2D();
|
||||||
|
}
|
||||||
|
|
||||||
|
//CHANGE NPOT SETTING
|
||||||
|
|
||||||
|
|
||||||
|
onImageUpdated?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void CleanUp()
|
||||||
|
{
|
||||||
|
texture = null;
|
||||||
|
imageData = default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 461687d0e0d346ac9dd5960b76db7538
|
||||||
|
timeCreated: 1745899335
|
@ -0,0 +1,99 @@
|
|||||||
|
using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
|
namespace ImageProcessingGraph.Editor.Nodes.Types.Image.Utilities.ViewNode
|
||||||
|
{
|
||||||
|
public class ViewTextureNodeEditor : ImageProcessingGraphNodeVisual
|
||||||
|
{
|
||||||
|
private UnityEngine.UIElements.Image viewableImage;
|
||||||
|
private Foldout foldout;
|
||||||
|
private VisualElement buttonRow;
|
||||||
|
|
||||||
|
public ViewTextureNodeEditor(BaseImageNode node, ImageProcessingGraphViewWindow window) : base(node, window)
|
||||||
|
{
|
||||||
|
//Port 0 is Texture2D
|
||||||
|
//Port 1 is ImageData
|
||||||
|
|
||||||
|
IPTPort tex2DPort = InputPorts[0] as IPTPort;
|
||||||
|
IPTPort imageDataPort = InputPorts[1] as IPTPort;
|
||||||
|
|
||||||
|
tex2DPort.OnPortConnected += () =>
|
||||||
|
{
|
||||||
|
imageDataPort.style.display = DisplayStyle.None;
|
||||||
|
};
|
||||||
|
|
||||||
|
tex2DPort.OnPortDisconnected += () =>
|
||||||
|
{
|
||||||
|
imageDataPort.style.display = DisplayStyle.Flex;
|
||||||
|
};
|
||||||
|
|
||||||
|
imageDataPort.OnPortConnected += () =>
|
||||||
|
{
|
||||||
|
tex2DPort.style.display = DisplayStyle.None;
|
||||||
|
};
|
||||||
|
|
||||||
|
imageDataPort.OnPortDisconnected += () =>
|
||||||
|
{
|
||||||
|
tex2DPort.style.display = DisplayStyle.Flex;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Q("output").style.display = DisplayStyle.None;
|
||||||
|
|
||||||
|
ViewTextureNode viewImageNode = node as ViewTextureNode;
|
||||||
|
|
||||||
|
foldout = new Foldout
|
||||||
|
{
|
||||||
|
text = "Texture Viewer",
|
||||||
|
value = true
|
||||||
|
};
|
||||||
|
foldout.style.backgroundColor = new Color(63f / 255f, 63f / 255f, 63f / 255f, 205f / 255f);
|
||||||
|
foldout.contentContainer.style.justifyContent = Justify.Center;
|
||||||
|
Add(foldout);
|
||||||
|
|
||||||
|
viewableImage = new UnityEngine.UIElements.Image
|
||||||
|
{
|
||||||
|
scaleMode = ScaleMode.ScaleToFit
|
||||||
|
};
|
||||||
|
viewableImage.style.width = 256;
|
||||||
|
viewableImage.style.height = 256;
|
||||||
|
viewableImage.style.backgroundColor = Color.black;
|
||||||
|
foldout.Add(viewableImage);
|
||||||
|
|
||||||
|
viewImageNode.onImageUpdated += () =>
|
||||||
|
{
|
||||||
|
viewableImage.image = viewImageNode.texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
buttonRow = new VisualElement
|
||||||
|
{
|
||||||
|
style =
|
||||||
|
{
|
||||||
|
flexDirection = FlexDirection.Row,
|
||||||
|
justifyContent = Justify.SpaceBetween,
|
||||||
|
alignItems = Align.Center,
|
||||||
|
marginTop = 8,
|
||||||
|
marginBottom = 8,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
string[] channels = { "RGB", "R", "G", "B", "A" };
|
||||||
|
foreach (var channel in channels)
|
||||||
|
{
|
||||||
|
var btn = new Button(() => OnChannelClicked(viewImageNode, channel))
|
||||||
|
{
|
||||||
|
text = channel
|
||||||
|
};
|
||||||
|
btn.style.flexGrow = 1;
|
||||||
|
buttonRow.Add(btn);
|
||||||
|
}
|
||||||
|
|
||||||
|
foldout.Add(buttonRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnChannelClicked(ViewTextureNode viewNode, string channel)
|
||||||
|
{
|
||||||
|
Debug.Log($"[ViewTextureNodeEditor] Channel Selected: {channel}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 83fd847c22794f0a92efbecd18c528c0
|
||||||
|
timeCreated: 1745899443
|
@ -29,12 +29,13 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
|||||||
{
|
{
|
||||||
this.AddToClassList("image-node-visual");
|
this.AddToClassList("image-node-visual");
|
||||||
this.window = window;
|
this.window = window;
|
||||||
|
|
||||||
graphNode = node;
|
graphNode = node;
|
||||||
Type typeInfo = node.GetType();
|
|
||||||
|
|
||||||
|
|
||||||
|
Type typeInfo = node.GetType();
|
||||||
NodeInfoAttribute info = typeInfo.GetCustomAttribute<NodeInfoAttribute>();
|
NodeInfoAttribute info = typeInfo.GetCustomAttribute<NodeInfoAttribute>();
|
||||||
title = info.Title;
|
title = info.Title;
|
||||||
|
this.name = typeInfo.Name;
|
||||||
|
|
||||||
string[] depths = info.MenuItem.Split('/');
|
string[] depths = info.MenuItem.Split('/');
|
||||||
foreach (var depth in depths)
|
foreach (var depth in depths)
|
||||||
@ -70,16 +71,6 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
|||||||
CreateInputPorts(inputFieldInfo);
|
CreateInputPorts(inputFieldInfo);
|
||||||
CreateOutputPorts(outputFieldInfo);
|
CreateOutputPorts(outputFieldInfo);
|
||||||
|
|
||||||
foreach (Port input in InputPorts)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Port input in OutputPorts)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
defaaStyleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Unity Image Processing/Node.uss");
|
defaaStyleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Unity Image Processing/Node.uss");
|
||||||
if (defaaStyleSheet == null)
|
if (defaaStyleSheet == null)
|
||||||
{
|
{
|
||||||
@ -103,9 +94,6 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
|||||||
if (styleSheets.Contains(errorStyleSheet))
|
if (styleSheets.Contains(errorStyleSheet))
|
||||||
styleSheets.Remove(errorStyleSheet);
|
styleSheets.Remove(errorStyleSheet);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
this.name = typeInfo.Name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateInputPorts(List<FieldInfo> fields)
|
private void CreateInputPorts(List<FieldInfo> fields)
|
||||||
@ -120,6 +108,7 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
|||||||
port.portName = label;
|
port.portName = label;
|
||||||
InputPorts.Add(port);
|
InputPorts.Add(port);
|
||||||
|
|
||||||
|
|
||||||
inputContainer.Add(port);
|
inputContainer.Add(port);
|
||||||
ExposeVariableToPort(port, field);
|
ExposeVariableToPort(port, field);
|
||||||
port.fieldInfo = field;
|
port.fieldInfo = field;
|
||||||
@ -324,7 +313,6 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SavePosition() => graphNode.SetPosition(GetPosition());
|
public void SavePosition() => graphNode.SetPosition(GetPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using ImageProcessingGraph.Editor.Nodes.NodeAttributes;
|
||||||
using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows;
|
using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows;
|
||||||
using ImageProcessingGraph.Editor.Windows;
|
using ImageProcessingGraph.Editor.Windows;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@ -443,7 +446,18 @@ namespace ImageProcessingGraph.Editor
|
|||||||
{
|
{
|
||||||
node.typeName = node.GetType().AssemblyQualifiedName;
|
node.typeName = node.GetType().AssemblyQualifiedName;
|
||||||
|
|
||||||
ImageProcessingGraphNodeVisual editorNode = new ImageProcessingGraphNodeVisual(node, this);
|
var infoAttr = node.GetType().GetCustomAttribute<NodeInfoAttribute>();
|
||||||
|
|
||||||
|
ImageProcessingGraphNodeVisual editorNode = null;
|
||||||
|
if (typeof(ImageProcessingGraphNodeVisual).IsAssignableFrom(infoAttr.EditorType))
|
||||||
|
{
|
||||||
|
editorNode = (ImageProcessingGraphNodeVisual)Activator.CreateInstance(infoAttr.EditorType, node, this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
editorNode = new ImageProcessingGraphNodeVisual(node, this);
|
||||||
|
}
|
||||||
|
|
||||||
editorNode.SetPosition(node.Position);
|
editorNode.SetPosition(node.Position);
|
||||||
|
|
||||||
graphNodes.Add(editorNode);
|
graphNodes.Add(editorNode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user