diff --git a/Editor/Scripts/Editor/Data Types/IPTPort.cs b/Editor/Scripts/Editor/Data Types/IPTPort.cs index 9abdf23..4c9681b 100644 --- a/Editor/Scripts/Editor/Data Types/IPTPort.cs +++ b/Editor/Scripts/Editor/Data Types/IPTPort.cs @@ -10,6 +10,13 @@ namespace ImageProcessingGraph.Editor { public FieldInfo fieldInfo; private VisualElement _exposedPropertyContainer; + + public delegate void OnPortConnectedEvent(); + public OnPortConnectedEvent OnPortConnected; + + public delegate void OnPortDisconnectedEvent(); + public OnPortDisconnectedEvent OnPortDisconnected; + public VisualElement ExposedPropertyContainer { set @@ -24,9 +31,27 @@ namespace ImageProcessingGraph.Editor protected IPTPort(Orientation portOrientation, Direction portDirection, Capacity portCapacity, Type type) : base(portOrientation, portDirection, portCapacity, type) { - + } - + + 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) { var port = new IPTPort(Orientation.Horizontal, isInput ? Direction.Input : Direction.Output, diff --git a/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs b/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs index 0c43cf0..b009911 100644 --- a/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs +++ b/Editor/Scripts/Editor/ImageProcessingGraphAsset.cs @@ -53,8 +53,7 @@ namespace ImageProcessingGraph.Editor Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); - if (runOrder == null) - runOrder = GetExecutionOrder(this.nodes, this.connections); + runOrder = GetExecutionOrder(this.nodes, this.connections); 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 stopwatch.Stop(); diff --git a/Editor/Scripts/Editor/Nodes/Base/BaseImageNode.cs b/Editor/Scripts/Editor/Nodes/Base/BaseImageNode.cs index 7271ceb..a0e2d49 100644 --- a/Editor/Scripts/Editor/Nodes/Base/BaseImageNode.cs +++ b/Editor/Scripts/Editor/Nodes/Base/BaseImageNode.cs @@ -124,6 +124,26 @@ namespace ImageProcessingGraph.Editor { 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; } diff --git a/Editor/Scripts/Editor/Nodes/NodeAttributes/NodeAttributes.cs b/Editor/Scripts/Editor/Nodes/NodeAttributes/NodeAttributes.cs index 513c39c..0ce9277 100644 --- a/Editor/Scripts/Editor/Nodes/NodeAttributes/NodeAttributes.cs +++ b/Editor/Scripts/Editor/Nodes/NodeAttributes/NodeAttributes.cs @@ -1,4 +1,5 @@ using System; +using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows; namespace ImageProcessingGraph.Editor.Nodes.NodeAttributes { @@ -8,16 +9,19 @@ namespace ImageProcessingGraph.Editor.Nodes.NodeAttributes private string name; private string menuItem; private string ussPath; - + private Type editorType; + public string Title => name; public string MenuItem => menuItem; 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.menuItem = menuItem; this.ussPath = ussPath; + this.editorType = editorType; } } diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Import/Texture2DImport.cs b/Editor/Scripts/Editor/Nodes/Types/Image/Import/Texture2DImport.cs index 498d706..5d75096 100644 --- a/Editor/Scripts/Editor/Nodes/Types/Image/Import/Texture2DImport.cs +++ b/Editor/Scripts/Editor/Nodes/Types/Image/Import/Texture2DImport.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace ImageProcessingGraph.Editor.Nodes.Import_Nodes { - [NodeInfo("Texture Import", "Imports/Import Texture", true)] + [NodeInfo("Texture Import", "Imports/Import Texture")] public class Texture2DImport : BaseImageNode { [NodeAttributes.Input("")] diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode.meta b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode.meta new file mode 100644 index 0000000..071cbd1 --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b462f37a291b49a696e3b4b554d26868 +timeCreated: 1745899248 \ No newline at end of file diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNode.cs b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNode.cs new file mode 100644 index 0000000..1fd2955 --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNode.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNode.cs.meta b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNode.cs.meta new file mode 100644 index 0000000..c0d2934 --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNode.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 461687d0e0d346ac9dd5960b76db7538 +timeCreated: 1745899335 \ No newline at end of file diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNodeEditor.cs b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNodeEditor.cs new file mode 100644 index 0000000..5ec0050 --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNodeEditor.cs @@ -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}"); + } + } +} diff --git a/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNodeEditor.cs.meta b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNodeEditor.cs.meta new file mode 100644 index 0000000..d67d46f --- /dev/null +++ b/Editor/Scripts/Editor/Nodes/Types/Image/Utilities/ViewNode/ViewImageNodeEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 83fd847c22794f0a92efbecd18c528c0 +timeCreated: 1745899443 \ No newline at end of file diff --git a/Editor/Scripts/Editor/Windows/ImageProcessingGraphNodeVisual.cs b/Editor/Scripts/Editor/Windows/ImageProcessingGraphNodeVisual.cs index 8614959..74dcd08 100644 --- a/Editor/Scripts/Editor/Windows/ImageProcessingGraphNodeVisual.cs +++ b/Editor/Scripts/Editor/Windows/ImageProcessingGraphNodeVisual.cs @@ -29,12 +29,13 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind { this.AddToClassList("image-node-visual"); this.window = window; - graphNode = node; + + Type typeInfo = node.GetType(); - NodeInfoAttribute info = typeInfo.GetCustomAttribute(); title = info.Title; + this.name = typeInfo.Name; string[] depths = info.MenuItem.Split('/'); foreach (var depth in depths) @@ -69,16 +70,6 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind CreateInputPorts(inputFieldInfo); CreateOutputPorts(outputFieldInfo); - - foreach (Port input in InputPorts) - { - - } - - foreach (Port input in OutputPorts) - { - - } defaaStyleSheet = AssetDatabase.LoadAssetAtPath("Assets/Unity Image Processing/Node.uss"); if (defaaStyleSheet == null) @@ -103,9 +94,6 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind if (styleSheets.Contains(errorStyleSheet)) styleSheets.Remove(errorStyleSheet); }; - - - this.name = typeInfo.Name; } private void CreateInputPorts(List fields) @@ -119,6 +107,7 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind if (label != "") port.portName = label; InputPorts.Add(port); + inputContainer.Add(port); ExposeVariableToPort(port, field); @@ -323,8 +312,7 @@ namespace ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Wind // Add more types as needed return null; } - - + public void SavePosition() => graphNode.SetPosition(GetPosition()); } } diff --git a/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs b/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs index 5229327..3e32cd9 100644 --- a/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs +++ b/Editor/Scripts/Editor/Windows/ImageProcessingGraphViewWindow.cs @@ -1,5 +1,8 @@ +using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; +using ImageProcessingGraph.Editor.Nodes.NodeAttributes; using ImageProcessingGraph.Editor.Unity_Image_Processing.Scripts.Editor.Windows; using ImageProcessingGraph.Editor.Windows; using UnityEditor; @@ -443,7 +446,18 @@ namespace ImageProcessingGraph.Editor { node.typeName = node.GetType().AssemblyQualifiedName; - ImageProcessingGraphNodeVisual editorNode = new ImageProcessingGraphNodeVisual(node, this); + var infoAttr = node.GetType().GetCustomAttribute(); + + 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); graphNodes.Add(editorNode);