فهرست منبع

Make rasterize points color a func and added color evaluator nodes

CPKreuz 1 سال پیش
والد
کامیت
717ec561a8

+ 27 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Evaluator/ColorEvaluatorLeftNode.cs

@@ -0,0 +1,27 @@
+using PixiEditor.ChangeableDocument.Rendering;
+using PixiEditor.DrawingApi.Core;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.Numerics;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Evaluator;
+
+[NodeInfo("ColorEvaluatorLeft")]
+[PairNode(typeof(ColorEvaluatorRightNode), "ColorEvaluatorZone", true)]
+public class ColorEvaluatorLeftNode : Node
+{
+    public override string DisplayName { get; set; } = "BEGIN_COLOR_EVALUATOR";
+
+    public FuncOutputProperty<VecD> Position { get; }
+
+    public ColorEvaluatorLeftNode()
+    {
+        Position = CreateFuncOutput("Position", "POSITION", c => c.Position);
+    }
+    
+    protected override Surface? OnExecute(RenderingContext context)
+    {
+        return null;
+    }
+
+    public override Node CreateCopy() => new ColorEvaluatorLeftNode();
+}

+ 29 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Evaluator/ColorEvaluatorRightNode.cs

@@ -0,0 +1,29 @@
+using PixiEditor.ChangeableDocument.Rendering;
+using PixiEditor.DrawingApi.Core;
+using PixiEditor.DrawingApi.Core.ColorsImpl;
+
+namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Evaluator;
+
+[NodeInfo("ColorEvaluatorRight")]
+[PairNode(typeof(ColorEvaluatorLeftNode), "ColorEvaluatorZone")]
+public class ColorEvaluatorRightNode : Node
+{
+    public override string DisplayName { get; set; } = "FINISH_COLOR_EVALUATOR";
+    
+    public FuncOutputProperty<Color> Output { get; }
+
+    public FuncInputProperty<Color> Input { get; }
+
+    public ColorEvaluatorRightNode()
+    {
+        Output = CreateFuncOutput("Output", "COLOR", c => Input.Value(c));
+        Input = CreateFuncInput("Input", "COLOR", Colors.Black);
+    }
+    
+    protected override Surface? OnExecute(RenderingContext context)
+    {
+        return null;
+    }
+
+    public override Node CreateCopy() => new ColorEvaluatorRightNode();
+}

+ 8 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/RasterizePoints.cs → src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/RasterizePointsNode.cs

@@ -1,4 +1,5 @@
-using PixiEditor.ChangeableDocument.Rendering;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Context;
+using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
@@ -17,13 +18,13 @@ public class RasterizePointsNode : Node
 
     public InputProperty<PointList> Points { get; }
 
-    public InputProperty<Color> Color { get; }
+    public FuncInputProperty<Color> Color { get; }
 
     public RasterizePointsNode()
     {
         Image = CreateOutput<Surface>("Image", "IMAGE", null);
         Points = CreateInput("Points", "POINTS", PointList.Empty);
-        Color = CreateInput("Color", "COLOR", Colors.Black);
+        Color = CreateFuncInput("Color", "COLOR", Colors.Black);
     }
 
     protected override Surface? OnExecute(RenderingContext context)
@@ -36,9 +37,12 @@ public class RasterizePointsNode : Node
         var size = context.DocumentSize;
         var image = new Surface(size);
 
-        _paint.Color = Color.Value;
+        var colorFunc = Color.Value;
+        var funcContext = new FuncContext();
         foreach (var point in points)
         {
+            funcContext.UpdateContext(point, context.DocumentSize);
+            _paint.Color = colorFunc(funcContext);
             image.DrawingSurface.Canvas.DrawPixel((VecI)point.Multiply(size), _paint);
         }