Browse Source

Generic shape info and deserialization fallback

flabbet 1 year ago
parent
commit
66848092e1

+ 0 - 80
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/EllipseNode.cs

@@ -1,80 +0,0 @@
-using PixiEditor.ChangeableDocument.Rendering;
-using PixiEditor.DrawingApi.Core;
-using PixiEditor.DrawingApi.Core.ColorsImpl;
-using PixiEditor.DrawingApi.Core.Surfaces;
-using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
-using PixiEditor.Numerics;
-
-namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
-
-[NodeInfo("Ellipse", "ELLIPSE_NODE", Category = "SHAPE")]
-public class EllipseNode : Node
-{
-    public InputProperty<VecI> Radius { get; }
-    public InputProperty<Color> StrokeColor { get; }
-    public InputProperty<Color> FillColor { get; }
-    public InputProperty<int> StrokeWidth { get; }
-    public OutputProperty<Texture> Output { get; }
-
-    private ChunkyImage? workingImage;
-    private Texture? targetSurface;
-
-    private VecI _lastRadius = new VecI(-1, -1);
-    private Color _lastStrokeColor = new Color(0, 0, 0, 0);
-    private Color _lastFillColor = new Color(0, 0, 0, 0);
-    private int _lastStrokeWidth = -1;
-    private Paint replacingPaint = new Paint() { BlendMode = BlendMode.Src };
-
-    public EllipseNode()
-    {
-        Radius = CreateInput<VecI>("Radius", "RADIUS", new VecI(32, 32)).WithRules(
-            v => v.Min(VecI.One));
-        StrokeColor = CreateInput<Color>("StrokeColor", "STROKE_COLOR", new Color(0, 0, 0, 255));
-        FillColor = CreateInput<Color>("FillColor", "FILL_COLOR", new Color(0, 0, 0, 255));
-        StrokeWidth = CreateInput<int>("StrokeWidth", "STROKE_WIDTH", 1);
-        Output = CreateOutput<Texture?>("Output", "OUTPUT", null);
-    }
-
-    protected override Texture? OnExecute(RenderingContext context)
-    {
-        var radius = Radius.Value;
-        VecI targetDimensions = radius * 2;
-
-        if (workingImage is null || workingImage.LatestSize.X != targetDimensions.X ||
-            workingImage.LatestSize.Y != targetDimensions.Y)
-        {
-            if (targetDimensions.X <= 0 || targetDimensions.Y <= 0)
-            {
-                Output.Value = null;
-                return null;
-            }
-
-            workingImage?.Dispose();
-            workingImage = new ChunkyImage(targetDimensions);
-
-            targetSurface = RequestTexture(0, targetDimensions);
-        }
-
-        if (radius != _lastRadius || StrokeColor.Value != _lastStrokeColor || FillColor.Value != _lastFillColor ||
-            StrokeWidth.Value != _lastStrokeWidth)
-        {
-            _lastRadius = radius;
-            _lastStrokeColor = StrokeColor.Value;
-            _lastFillColor = FillColor.Value;
-            _lastStrokeWidth = StrokeWidth.Value;
-
-            RectI location = new RectI(VecI.Zero, targetDimensions);
-            workingImage.EnqueueDrawEllipse(location, StrokeColor.Value, FillColor.Value, StrokeWidth.Value);
-            workingImage.CommitChanges();
-        }
-
-        workingImage.DrawMostUpToDateChunkOn(context.ChunkToUpdate, context.ChunkResolution,
-            targetSurface.DrawingSurface, VecI.Zero,
-            replacingPaint);
-
-        Output.Value = targetSurface;
-        return targetSurface;
-    }
-
-    public override Node CreateCopy() => new EllipseNode();
-}

+ 0 - 31
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/PointList.cs

@@ -1,31 +0,0 @@
-using PixiEditor.Common;
-using PixiEditor.Numerics;
-
-namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Points;
-
-public class PointList : List<VecD>, ICacheable, ICloneable
-{
-    public required int HashValue { get; set; }
-
-    public PointList()
-    {
-    }
-
-    public PointList(IEnumerable<VecD> collection) : base(collection)
-    {
-    }
-
-    public PointList(int capacity) : base(capacity)
-    {
-    }
-
-    public static PointList Empty { get; } = new(0) { HashValue = 0 };
-
-    public int GetCacheHash() => HashValue;
-    public object Clone()
-    {
-        var clone = new PointList(this) { HashValue = HashValue };
-        clone.HashValue = HashValue;
-        return clone;
-    }
-}

+ 0 - 50
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/RasterizePointsNode.cs

@@ -1,50 +0,0 @@
-using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
-using PixiEditor.ChangeableDocument.Rendering;
-using PixiEditor.DrawingApi.Core;
-using PixiEditor.DrawingApi.Core.ColorsImpl;
-using PixiEditor.DrawingApi.Core.Shaders.Generation;
-using PixiEditor.DrawingApi.Core.Shaders.Generation.Expressions;
-using PixiEditor.DrawingApi.Core.Surfaces;
-using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
-using PixiEditor.Numerics;
-
-namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Points;
-
-[NodeInfo("RasterizePoints", "RASTERIZE_POINTS", Category = "SHAPE")]
-public class RasterizePointsNode : Node
-{
-    private Paint _paint = new() { Color = Colors.White };
-
-    public OutputProperty<Texture> Image { get; }
-
-    public InputProperty<PointList> Points { get; }
-
-
-    public RasterizePointsNode()
-    {
-        Image = CreateOutput<Texture>("Image", "IMAGE", null);
-        Points = CreateInput("Points", "POINTS", PointList.Empty);
-    }
-
-    protected override Texture? OnExecute(RenderingContext context)
-    {
-        var points = Points.Value;
-
-        if (points.Count == 0)
-            return null;
-
-        var size = context.DocumentSize;
-        var image = RequestTexture(0, size);
-
-        image.DrawingSurface.Canvas.DrawPoints(
-            PointMode.Points, 
-            points.Select(x => new Point((float)x.X * size.X, (float)x.Y * size.Y)).ToArray(),
-            _paint);
-
-        Image.Value = image;
-        
-        return image;
-    }
-
-    public override Node CreateCopy() => new RasterizePointsNode();
-}

+ 53 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/EllipseData.cs

@@ -0,0 +1,53 @@
+using PixiEditor.DrawingApi.Core.Surfaces;
+using PixiEditor.Numerics;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
+
+public class EllipseData : ShapeData
+{
+    public VecD Center { get; set; }
+    public VecD Radius { get; set; }
+
+    public EllipseData(VecD center, VecD radius)
+    {
+        Center = center;
+        Radius = radius;
+    }
+    
+    public override void Rasterize(DrawingSurface drawingSurface)
+    {
+        using ChunkyImage img = new ChunkyImage(new VecI((int)Radius.X * 2, (int)Radius.Y * 2));
+        RectI rect = new RectI((int)Center.X - (int)Radius.X, (int)Center.Y - (int)Radius.Y, (int)Radius.X * 2, (int)Radius.Y * 2);
+        
+        img.EnqueueDrawEllipse(rect, StrokeColor, FillColor, StrokeWidth);
+        img.CommitChanges();
+        
+        VecI pos = new VecI((int)(Center.X - Radius.X), (int)(Center.Y - Radius.Y));
+        img.DrawMostUpToDateRegionOn(rect, ChunkResolution.Full, drawingSurface, pos);
+    }
+
+    public override bool IsValid()
+    {
+        return Radius is { X: > 0, Y: > 0 };
+    }
+
+    public override int CalculateHash()
+    {
+        return HashCode.Combine(Center, Radius);
+    }
+
+    public override int GetCacheHash()
+    {
+        return CalculateHash();
+    }
+
+    public override object Clone()
+    {
+        return new EllipseData(Center, Radius)
+        {
+            StrokeColor = StrokeColor,
+            FillColor = FillColor,
+            StrokeWidth = StrokeWidth
+        };
+    }
+}

+ 48 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/PointsData.cs

@@ -0,0 +1,48 @@
+using PixiEditor.DrawingApi.Core.Surfaces;
+using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
+using PixiEditor.Numerics;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
+
+public class PointsData : ShapeData
+{
+    public List<VecD> Points { get; set; } = new();
+    
+    public PointsData(IEnumerable<VecD> points)
+    {
+        Points = new List<VecD>(points);
+    }
+    
+    public override void Rasterize(DrawingSurface drawingSurface)
+    {
+        using Paint paint = new Paint();
+        paint.Color = FillColor;
+        
+        drawingSurface.Canvas.DrawPoints(PointMode.Points, Points.Select(p => new Point((int)p.X, (int)p.Y)).ToArray(), paint);
+    }
+
+    public override bool IsValid()
+    {
+        return Points.Count > 0;
+    }
+
+    public override int GetCacheHash()
+    {
+        return CalculateHash();
+    }
+
+    public override int CalculateHash()
+    {
+        return Points.GetHashCode();
+    }
+
+    public override object Clone()
+    {
+        return new PointsData(Points)
+        {
+            StrokeColor = StrokeColor,
+            FillColor = FillColor,
+            StrokeWidth = StrokeWidth
+        };
+    }
+}

+ 24 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/ShapeData.cs

@@ -0,0 +1,24 @@
+using PixiEditor.Common;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Surfaces;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
+
+public abstract class ShapeData : ICacheable, ICloneable
+{
+    public Color StrokeColor { get; set; }
+    public Color FillColor { get; set; }
+    public int StrokeWidth { get; set; }
+
+    public abstract void Rasterize(DrawingSurface drawingSurface);
+    public abstract bool IsValid();
+
+    public abstract int GetCacheHash();
+    public abstract int CalculateHash();
+    public abstract object Clone();
+
+    public override int GetHashCode()
+    {
+        return CalculateHash();
+    }
+}

+ 11 - 19
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/DistributePointsNode.cs → src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/DistributePointsNode.cs

@@ -1,51 +1,43 @@
-using PixiEditor.ChangeableDocument.Rendering;
-using PixiEditor.DrawingApi.Core;
-using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
+using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.Numerics;
 using PixiEditor.Numerics;
+using ShapeData = PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data.ShapeData;
 
 
-namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Points;
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes;
 
 
 [NodeInfo("DistributePoints", "DISTRIBUTE_POINTS", Category = "SHAPE")]
 [NodeInfo("DistributePoints", "DISTRIBUTE_POINTS", Category = "SHAPE")]
-public class DistributePointsNode : Node
+public class DistributePointsNode : ShapeNode
 {
 {
-    public OutputProperty<PointList> Points { get; }
-
     public InputProperty<int> MaxPointCount { get; }
     public InputProperty<int> MaxPointCount { get; }
 
 
     public InputProperty<int> Seed { get; }
     public InputProperty<int> Seed { get; }
 
 
     public DistributePointsNode()
     public DistributePointsNode()
     {
     {
-        Points = CreateOutput(nameof(Points), "POINTS", PointList.Empty);
-
         MaxPointCount = CreateInput("MaxPointCount", "MAX_POINTS", 10).
         MaxPointCount = CreateInput("MaxPointCount", "MAX_POINTS", 10).
             WithRules(v => v.Min(1));
             WithRules(v => v.Min(1));
         Seed = CreateInput("Seed", "SEED", 0);
         Seed = CreateInput("Seed", "SEED", 0);
     }
     }
 
 
-    protected override Texture? OnExecute(RenderingContext context)
+    protected override ShapeData? GetShapeData(RenderingContext context)
     {
     {
-        Points.Value = GetPointsRandomly();
-        
-        return null;
+        return GetPointsRandomly();
     }
     }
 
 
-    private PointList GetPointsRandomly()
+    private PointsData GetPointsRandomly()
     {
     {
         var seed = Seed.Value;
         var seed = Seed.Value;
         var random = new Random(seed);
         var random = new Random(seed);
         var pointCount = MaxPointCount.Value;
         var pointCount = MaxPointCount.Value;
-        var finalPoints = new PointList(pointCount)
-        {
-            HashValue = HashCode.Combine(pointCount, seed)
-        };
 
 
+        List<VecD> finalPoints = new List<VecD>(pointCount);
         for (int i = 0; i < pointCount; i++)
         for (int i = 0; i < pointCount; i++)
         {
         {
             finalPoints.Add(new VecD(random.NextDouble(), random.NextDouble()));
             finalPoints.Add(new VecD(random.NextDouble(), random.NextDouble()));
         }
         }
         
         
-        return finalPoints;
+        var shapeData = new PointsData(finalPoints);
+        return shapeData;
     }
     }
 
 
     public override Node CreateCopy() => new DistributePointsNode();
     public override Node CreateCopy() => new DistributePointsNode();

+ 35 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/EllipseNode.cs

@@ -0,0 +1,35 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
+using PixiEditor.ChangeableDocument.Rendering;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.Numerics;
+using ShapeData = PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data.ShapeData;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes;
+
+[NodeInfo("Ellipse", "ELLIPSE_NODE", Category = "SHAPE")]
+public class EllipseNode : ShapeNode
+{
+    public InputProperty<VecD> Position { get; }
+    public InputProperty<VecD> Radius { get; }
+    public InputProperty<Color> StrokeColor { get; }
+    public InputProperty<Color> FillColor { get; }
+    public InputProperty<int> StrokeWidth { get; }
+
+    public EllipseNode()
+    {
+        Position = CreateInput<VecD>("Position", "POSITION", VecI.Zero);
+        Radius = CreateInput<VecD>("Radius", "RADIUS", new VecD(32, 32)).WithRules(
+            v => v.Min(VecI.One));
+        StrokeColor = CreateInput<Color>("StrokeColor", "STROKE_COLOR", new Color(0, 0, 0, 255));
+        FillColor = CreateInput<Color>("FillColor", "FILL_COLOR", new Color(0, 0, 0, 255));
+        StrokeWidth = CreateInput<int>("StrokeWidth", "STROKE_WIDTH", 1);
+    }
+
+    protected override ShapeData? GetShapeData(RenderingContext context)
+    {
+        return new EllipseData(Position.Value, Radius.Value)
+            { StrokeColor = StrokeColor.Value, FillColor = FillColor.Value, StrokeWidth = StrokeWidth.Value };
+    }
+
+    public override Node CreateCopy() => new EllipseNode();
+}

+ 43 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/RasterizeShape.cs

@@ -0,0 +1,43 @@
+using PixiEditor.ChangeableDocument.Rendering;
+using PixiEditor.DrawingApi.Core;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Surfaces;
+using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
+using PixiEditor.Numerics;
+using ShapeData = PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data.ShapeData;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes;
+
+[NodeInfo("RasterizeShape", "RASTERIZE_SHAPE", Category = "SHAPE")]
+public class RasterizeShape : Node
+{
+    public OutputProperty<Texture> Image { get; }
+
+    public InputProperty<ShapeData> Data { get; }
+
+
+    public RasterizeShape()
+    {
+        Image = CreateOutput<Texture>("Image", "IMAGE", null);
+        Data = CreateInput<ShapeData>("Points", "POINTS", null);
+    }
+
+    protected override Texture? OnExecute(RenderingContext context)
+    {
+        var shape = Data.Value;
+
+        if (shape == null || !shape.IsValid())
+            return null;
+
+        var size = context.DocumentSize;
+        var image = RequestTexture(0, size);
+        
+        shape.Rasterize(image.DrawingSurface);
+
+        Image.Value = image;
+        
+        return image;
+    }
+
+    public override Node CreateCopy() => new RasterizeShape();
+}

+ 26 - 20
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/RemoveClosePointsNode.cs → src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/RemoveClosePointsNode.cs

@@ -1,41 +1,46 @@
-using PixiEditor.ChangeableDocument.Rendering;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
+using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.Numerics;
 using PixiEditor.Numerics;
+using ShapeData = PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data.ShapeData;
 
 
-namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Points;
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes;
 
 
 [NodeInfo("RemoveClosePoints", "REMOVE_CLOSE_POINTS", Category = "SHAPE")]
 [NodeInfo("RemoveClosePoints", "REMOVE_CLOSE_POINTS", Category = "SHAPE")]
-public class RemoveClosePointsNode : Node
+public class RemoveClosePointsNode : ShapeNode
 {
 {
-    public OutputProperty<PointList> Output { get; }
-    
-    public InputProperty<PointList> Input { get; }
-    
+    public InputProperty<ShapeData> Input { get; }
+
     public InputProperty<double> MinDistance { get; }
     public InputProperty<double> MinDistance { get; }
 
 
     public InputProperty<int> Seed { get; }
     public InputProperty<int> Seed { get; }
 
 
     public RemoveClosePointsNode()
     public RemoveClosePointsNode()
     {
     {
-        Output = CreateOutput("Output", "POINTS", PointList.Empty);
-        Input = CreateInput("Input", "POINTS", PointList.Empty);
+        Input = CreateInput<ShapeData>("Input", "POINTS", null);
         MinDistance = CreateInput("MinDistance", "MIN_DISTANCE", 0d);
         MinDistance = CreateInput("MinDistance", "MIN_DISTANCE", 0d);
         Seed = CreateInput("Seed", "SEED", 0);
         Seed = CreateInput("Seed", "SEED", 0);
     }
     }
-    
-    protected override Texture? OnExecute(RenderingContext context)
+
+    protected override ShapeData? GetShapeData(RenderingContext context)
     {
     {
+        var data = Input.Value;
+
+        if (data is not PointsData pointsData)
+        {
+            return data;
+        }
+
         var distance = MinDistance.Value;
         var distance = MinDistance.Value;
 
 
         if (distance == 0)
         if (distance == 0)
         {
         {
-            Output.Value = Input.Value;
             return null;
             return null;
         }
         }
 
 
-        var availablePoints = Input.Value.Distinct().ToList();
-        var newPoints = new PointList(availablePoints.Count) { HashValue = HashCode.Combine(Input.Value.HashValue, MinDistance.Value, Seed.Value) };
-
+        var availablePoints = pointsData.Points.Distinct().ToList();
+        List<VecD> newPoints = new List<VecD>();
+        
         var minDistance = MinDistance.Value;
         var minDistance = MinDistance.Value;
         var documentSize = context.DocumentSize;
         var documentSize = context.DocumentSize;
 
 
@@ -54,18 +59,19 @@ public class RemoveClosePointsNode : Node
             }
             }
 
 
             continue;
             continue;
-            bool InRange(VecD other) => (other.Multiply(documentSize) - point.Multiply(documentSize)).Length <= minDistance;
+
+            bool InRange(VecD other) =>
+                (other.Multiply(documentSize) - point.Multiply(documentSize)).Length <= minDistance;
         }
         }
 
 
         if (availablePoints.Count == 1)
         if (availablePoints.Count == 1)
         {
         {
             newPoints.Add(availablePoints[0]);
             newPoints.Add(availablePoints[0]);
         }
         }
-        
-        Output.Value = newPoints;
-        
-        return null;
 
 
+        var finalData = new PointsData(newPoints);
+
+        return finalData;
     }
     }
 
 
     public override Node CreateCopy() => new RemoveClosePointsNode();
     public override Node CreateCopy() => new RemoveClosePointsNode();

+ 40 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/ShapeNode.cs

@@ -0,0 +1,40 @@
+using PixiEditor.ChangeableDocument.Rendering;
+using PixiEditor.DrawingApi.Core;
+using PixiEditor.Numerics;
+using ShapeData = PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data.ShapeData;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes;
+
+public abstract class ShapeNode : Node
+{
+    public OutputProperty<ShapeData> Output { get; }
+    private const int PreviewSize = 150;
+    
+    public ShapeNode()
+    {
+        Output = CreateOutput<ShapeData>("Output", "OUTPUT", null);
+    }
+
+    protected override Texture? OnExecute(RenderingContext context)
+    {
+        var data = GetShapeData(context);
+
+        Output.Value = data;
+        
+        if (data == null || !data.IsValid())
+            return null;
+
+        return RasterizePreview(data);
+    }
+    
+    protected abstract ShapeData? GetShapeData(RenderingContext context);
+
+    public Texture RasterizePreview(ShapeData data)
+    {
+        Texture texture = RequestTexture(0, new VecI(PreviewSize, PreviewSize));
+        
+        data.Rasterize(texture.DrawingSurface);
+        
+        return texture;
+    }
+}

+ 2 - 2
src/PixiEditor/Fonts/NodeIcons.cs

@@ -3,7 +3,7 @@ using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Animable;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Animable;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.CombineSeparate;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.CombineSeparate;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.FilterNodes;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.FilterNodes;
-using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Points;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes;
 
 
 namespace PixiEditor.Fonts;
 namespace PixiEditor.Fonts;
 
 
@@ -18,7 +18,7 @@ public static class NodeIcons
             { typeof(MergeNode), "\ue903" },
             { typeof(MergeNode), "\ue903" },
             { typeof(ModifyImageLeftNode), "\ue904" },
             { typeof(ModifyImageLeftNode), "\ue904" },
             { typeof(ImageLayerNode), "\ue905" },
             { typeof(ImageLayerNode), "\ue905" },
-            { typeof(RasterizePointsNode), "\ue906" },
+            { typeof(RasterizeShape), "\ue906" },
             { typeof(SampleImageNode), "\ue907" },
             { typeof(SampleImageNode), "\ue907" },
             { typeof(CombineColorNode), "\ue908" },
             { typeof(CombineColorNode), "\ue908" },
             { typeof(ApplyFilterNode), "\ue909" },
             { typeof(ApplyFilterNode), "\ue909" },

+ 9 - 1
src/PixiEditor/Helpers/SerializationUtil.cs

@@ -55,9 +55,17 @@ public static class SerializationUtil
             if (factory != null)
             if (factory != null)
             {
             {
                 factory.Config = config;
                 factory.Config = config;
-                return factory.Deserialize(data is Dictionary<object, object> processableDict
+                try
+                {
+                    return factory.Deserialize(data is Dictionary<object, object> processableDict
                     ? ToDictionary(processableDict)
                     ? ToDictionary(processableDict)
                     : data);
                     : data);
+                }
+                catch (Exception e)
+                {
+                    return value;
+                }
+                
             }
             }
         }
         }
 
 

+ 1 - 1
src/PixiEditor/Helpers/ServiceCollectionHelpers.cs

@@ -123,7 +123,7 @@ internal static class ServiceCollectionHelpers
             .AddSingleton<SerializationFactory, VecISerializationFactory>()
             .AddSingleton<SerializationFactory, VecISerializationFactory>()
             .AddSingleton<SerializationFactory, ColorSerializationFactory>()
             .AddSingleton<SerializationFactory, ColorSerializationFactory>()
             .AddSingleton<SerializationFactory, ColorMatrixSerializationFactory>()
             .AddSingleton<SerializationFactory, ColorMatrixSerializationFactory>()
-            .AddSingleton<SerializationFactory, PointListSerializationFactory>()
+            .AddSingleton<SerializationFactory, ShapeDataSerializationFactory>()
             .AddSingleton<SerializationFactory, VecD3SerializationFactory>()
             .AddSingleton<SerializationFactory, VecD3SerializationFactory>()
             .AddSingleton<SerializationFactory, TextureSerializationFactory>()
             .AddSingleton<SerializationFactory, TextureSerializationFactory>()
             // Palette Parsers
             // Palette Parsers

+ 0 - 27
src/PixiEditor/Models/Serialization/Factories/PointListSerializationFactory.cs

@@ -1,27 +0,0 @@
-using MessagePack;
-using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Points;
-
-namespace PixiEditor.Models.Serialization.Factories;
-
-public class PointListSerializationFactory : SerializationFactory<byte[], PointList>
-{
-    public override string DeserializationId { get; } = "PixiEditor.PointList";
-
-    public override byte[] Serialize(PointList original)
-    {
-        return MessagePackSerializer.Serialize(original);
-    }
-
-    public override bool TryDeserialize(object serialized, out PointList? original)
-    {
-        if (serialized is not byte[] buffer)
-        {
-            original = null;
-            return false;
-        }
-        
-        original = MessagePackSerializer.Deserialize<PointList>(buffer);
-
-        return true;
-    }
-}

+ 28 - 0
src/PixiEditor/Models/Serialization/Factories/ShapeDataSerializationFactory.cs

@@ -0,0 +1,28 @@
+using MessagePack;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
+
+namespace PixiEditor.Models.Serialization.Factories;
+
+public class ShapeDataSerializationFactory : SerializationFactory<byte[], ShapeData>
+{
+    public override string DeserializationId { get; } = "PixiEditor.PointList";
+
+    public override byte[] Serialize(ShapeData original)
+    {
+        return MessagePackSerializer.Serialize(original);
+    }
+
+    public override bool TryDeserialize(object serialized, out ShapeData? original)
+    {
+        if (serialized is not byte[] buffer)
+        {
+            original = null;
+            return false;
+        }
+        
+        original = MessagePackSerializer.Deserialize<ShapeData>(buffer);
+
+        return true;
+    }
+}