Browse Source

Vec3D and filter custom prop hiding

Krzysztof Krysiński 6 months ago
parent
commit
41c817dc21

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 31d2e6d330115f8348a3a3c2ea73e44996ccc31c
+Subproject commit 3515c3fd4993ba73886d98a78274ca173d54e786

+ 0 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/FilterNodes/GrayscaleNode.cs

@@ -15,7 +15,6 @@ public class GrayscaleNode : FilterNode
     
     public InputProperty<bool> Normalize { get; }
 
-    // TODO: Hide when Mode != Custom
     public InputProperty<Vec3D> CustomWeight { get; }
     
     private GrayscaleMode lastMode;

+ 24 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ShaderNode.cs

@@ -123,15 +123,17 @@ public class ShaderNode : RenderNode, IRenderInput, ICustomShaderNode
 
         DrawingSurface targetSurface = surface;
 
-        if(ColorSpace.Value != ColorSpaceType.Inherit)
+        if (ColorSpace.Value != ColorSpaceType.Inherit)
         {
             if (ColorSpace.Value == ColorSpaceType.Srgb && !context.ProcessingColorSpace.IsSrgb)
             {
-                targetSurface = RequestTexture(51, context.DocumentSize, Drawie.Backend.Core.Surfaces.ImageData.ColorSpace.CreateSrgb()).DrawingSurface;
+                targetSurface = RequestTexture(51, context.DocumentSize,
+                    Drawie.Backend.Core.Surfaces.ImageData.ColorSpace.CreateSrgb()).DrawingSurface;
             }
             else if (ColorSpace.Value == ColorSpaceType.LinearSrgb && context.ProcessingColorSpace.IsSrgb)
             {
-                targetSurface = RequestTexture(51, context.DocumentSize, Drawie.Backend.Core.Surfaces.ImageData.ColorSpace.CreateSrgbLinear()).DrawingSurface;
+                targetSurface = RequestTexture(51, context.DocumentSize,
+                    Drawie.Backend.Core.Surfaces.ImageData.ColorSpace.CreateSrgbLinear()).DrawingSurface;
             }
         }
 
@@ -202,7 +204,7 @@ public class ShaderNode : RenderNode, IRenderInput, ICustomShaderNode
                 InputProperty input;
                 if (uniform.DataType == UniformValueType.Float)
                 {
-                    input = CreateInput(uniform.Name, uniform.Name, 0f);
+                    input = CreateInput(uniform.Name, uniform.Name, 0d);
                 }
                 else if (uniform.DataType == UniformValueType.Shader)
                 {
@@ -216,6 +218,10 @@ public class ShaderNode : RenderNode, IRenderInput, ICustomShaderNode
                 {
                     input = CreateInput<VecD>(uniform.Name, uniform.Name, new VecD(0, 0));
                 }
+                else if (uniform.DataType == UniformValueType.Vector3)
+                {
+                    input = CreateInput<Vec3D>(uniform.Name, uniform.Name, new Vec3D(0, 0, 0));
+                }
                 else
                 {
                     continue;
@@ -269,6 +275,20 @@ public class ShaderNode : RenderNode, IRenderInput, ICustomShaderNode
                     uniforms.Add(input.Key, new Uniform(input.Key, new VecD(vecI.X, vecI.Y)));
                 }
             }
+            else if (input.Value.valueType == UniformValueType.Vector3)
+            {
+                if (value is Vec3D vector)
+                {
+                    uniforms.Add(input.Key, new Uniform(input.Key, vector));
+                }
+            }
+            else if (input.Value.valueType == UniformValueType.Vector4)
+            {
+                if (value is Vec4D vector)
+                {
+                    uniforms.Add(input.Key, new Uniform(input.Key, vector));
+                }
+            }
             else if (input.Value.valueType == UniformValueType.Color)
             {
                 if (value is Color color)

+ 2 - 0
src/PixiEditor.UI.Common/Accents/Base.axaml

@@ -53,6 +53,7 @@
             <Color x:Key="DoubleSocketColor">#efb66d</Color>
             <Color x:Key="ColorSocketColor">#8cf2dd</Color>
             <Color x:Key="VecDSocketColor">#c984ca</Color>
+            <Color x:Key="Vec3DSocketColor">#597513</Color>
             <Color x:Key="VecISocketColor">#c9b4ca</Color>
             <Color x:Key="IntSocketColor">#4C64B1</Color>
             <Color x:Key="StringSocketColor">#C9E4C6</Color>
@@ -144,6 +145,7 @@
             <SolidColorBrush x:Key="ColorSocketBrush" Color="{StaticResource ColorSocketColor}"/>
             <SolidColorBrush x:Key="Half4SocketBrush" Color="{StaticResource ColorSocketColor}"/>
             <SolidColorBrush x:Key="VecDSocketBrush" Color="{StaticResource VecDSocketColor}"/>
+            <SolidColorBrush x:Key="Vec3DSocketBrush" Color="{StaticResource Vec3DSocketColor}"/>
             <SolidColorBrush x:Key="Float2SocketBrush" Color="{StaticResource VecDSocketColor}"/>
             <SolidColorBrush x:Key="VecISocketBrush" Color="{StaticResource VecISocketColor}"/>
             <SolidColorBrush x:Key="Int2SocketBrush" Color="{StaticResource VecISocketColor}"/>

+ 1 - 0
src/PixiEditor/Models/Handlers/INodePropertyHandler.cs

@@ -5,6 +5,7 @@ namespace PixiEditor.Models.Handlers;
 
 public interface INodePropertyHandler
 {
+    public bool IsVisible { get; set; }
     public string PropertyName { get; set; }
     public string DisplayName { get; set; }
     public object Value { get; set; }

+ 19 - 1
src/PixiEditor/ViewModels/Document/Nodes/FilterNodes/GrayscaleNodeViewModel.cs

@@ -1,7 +1,25 @@
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.FilterNodes;
+using PixiEditor.Models.Events;
+using PixiEditor.Models.Handlers;
 using PixiEditor.ViewModels.Nodes;
 
 namespace PixiEditor.ViewModels.Document.Nodes.FilterNodes;
 
 [NodeViewModel("GRAYSCALE_FILTER_NODE", "FILTERS", "\ue812")]
-internal class GrayscaleNodeViewModel : NodeViewModel<GrayscaleNode>;
+internal class GrayscaleNodeViewModel : NodeViewModel<GrayscaleNode>
+{
+    private INodePropertyHandler customWeightsProp;
+    public override void OnInitialized()
+    {
+        var modeProp = Inputs.FirstOrDefault(x => x.PropertyName == "Mode");
+        customWeightsProp = Inputs.FirstOrDefault(x => x.PropertyName == "CustomWeight");
+        modeProp.ValueChanged += ModePropOnValueChanged;
+
+        customWeightsProp.IsVisible = modeProp.Value is GrayscaleNode.GrayscaleMode.Custom;
+    }
+
+    private void ModePropOnValueChanged(INodePropertyHandler property, NodePropertyValueChangedArgs args)
+    {
+        customWeightsProp.IsVisible = args.NewValue is GrayscaleNode.GrayscaleMode.Custom;
+    }
+}

+ 2 - 2
src/PixiEditor/ViewModels/Nodes/Properties/VecD3PropertyViewModel.cs → src/PixiEditor/ViewModels/Nodes/Properties/Vec3DPropertyViewModel.cs

@@ -3,9 +3,9 @@ using Drawie.Numerics;
 
 namespace PixiEditor.ViewModels.Nodes.Properties;
 
-internal class VecD3PropertyViewModel : NodePropertyViewModel<Vec3D>
+internal class Vec3DPropertyViewModel : NodePropertyViewModel<Vec3D>
 {
-    public VecD3PropertyViewModel(NodeViewModel node, Type valueType) : base(node, valueType)
+    public Vec3DPropertyViewModel(NodeViewModel node, Type valueType) : base(node, valueType)
     {
         PropertyChanged += OnPropertyChanged;
     }

+ 1 - 1
src/PixiEditor/Views/Nodes/Properties/VecD3PropertyView.axaml → src/PixiEditor/Views/Nodes/Properties/Vec3DPropertyView.axaml

@@ -7,7 +7,7 @@
                              xmlns:ui="clr-namespace:PixiEditor.Extensions.UI;assembly=PixiEditor.Extensions"
                              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
                              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
-                             x:Class="PixiEditor.Views.Nodes.Properties.VecD3PropertyView">
+                             x:Class="PixiEditor.Views.Nodes.Properties.Vec3DPropertyView">
     <StackPanel HorizontalAlignment="{Binding IsInput, Converter={converters:BoolToValueConverter FalseValue='Right', TrueValue='Stretch'}}">
         <TextBlock VerticalAlignment="Center" ui:Translator.Key="{Binding DisplayName}"/>
         <StackPanel IsVisible="{Binding ShowInputField}">

+ 2 - 2
src/PixiEditor/Views/Nodes/Properties/VecD3PropertyView.axaml.cs → src/PixiEditor/Views/Nodes/Properties/Vec3DPropertyView.axaml.cs

@@ -4,9 +4,9 @@ using Avalonia.Markup.Xaml;
 
 namespace PixiEditor.Views.Nodes.Properties;
 
-public partial class VecD3PropertyView : NodePropertyView
+public partial class Vec3DPropertyView : NodePropertyView
 {
-    public VecD3PropertyView()
+    public Vec3DPropertyView()
     {
         InitializeComponent();
     }