Browse Source

Added node previews

flabbet 10 months ago
parent
commit
fe8d800ddf

+ 7 - 5
src/PixiEditor/Models/Rendering/MemberPreviewUpdater.cs

@@ -48,7 +48,7 @@ internal class MemberPreviewUpdater
         RenderWholeCanvasPreview();
         RenderMainPreviews(memberGuids);
         RenderMaskPreviews(maskGuids);
-        RenderNodePreviews();
+        RenderNodePreviews(); //TODO: maybe find nodes to render, instead of rendering all?
     }
 
     /// <summary>
@@ -224,9 +224,6 @@ internal class MemberPreviewUpdater
 
     private void RenderNodePreviews()
     {
-        /*using RenderContext previewContext = new(doc.AnimationHandler.ActiveFrameTime, VecI.Zero, ChunkResolution.Full,
-            doc.SizeBindable);
-
         var outputNode = internals.Tracker.Document.NodeGraph.OutputNode;
 
         if (outputNode is null)
@@ -251,7 +248,12 @@ internal class MemberPreviewUpdater
             if (nodeVm.ResultPainter == null && node is IPreviewRenderable renderable)
             {
                 nodeVm.ResultPainter = new PreviewPainter(renderable);
+                nodeVm.ResultPainter.Repaint();
+            }
+            else
+            {
+                nodeVm.ResultPainter?.Repaint();
             }
-        }*/
+        }
     }
 }

+ 1 - 0
src/PixiEditor/Styles/Templates/NodeGraphView.axaml

@@ -41,6 +41,7 @@
                                         DisplayName="{Binding NodeNameBindable}"
                                         CategoryBackgroundBrush="{Binding CategoryBackgroundBrush}"
                                         Inputs="{Binding Inputs}"
+                                        ActiveFrame="{Binding ActiveFrame, RelativeSource={RelativeSource FindAncestor, AncestorType=nodes:NodeGraphView}}"
                                         BorderBrush="{Binding InternalName, Converter={converters:NodeInternalNameToStyleConverter}, ConverterParameter='BorderBrush'}"
                                         BorderThickness="2"
                                         Outputs="{Binding Outputs}"

+ 46 - 43
src/PixiEditor/Styles/Templates/NodeView.axaml

@@ -9,7 +9,7 @@
         <Setter Property="BorderThickness" Value="1" />
         <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
         <Setter Property="Padding" Value="5" />
-        <Setter Property="ClipToBounds" Value="False"/>
+        <Setter Property="ClipToBounds" Value="False" />
         <Setter Property="Template">
             <ControlTemplate>
                 <Border Background="{TemplateBinding Background}"
@@ -23,49 +23,52 @@
                         <DropShadowEffect Opacity="0.5" BlurRadius="25"></DropShadowEffect>
                     </Border.Effect>
                     <Grid>
-                            <Grid.RowDefinitions>
-                                <RowDefinition Height="Auto" />
-                                <RowDefinition Height="Auto" />
-                                <RowDefinition Height="Auto" />
-                            </Grid.RowDefinitions>
-                            <Border Padding="{TemplateBinding Padding}" Grid.ColumnSpan="3" Grid.Row="0"
-                                    CornerRadius="4.5, 4.5, 0 ,0"
-                                    Background="{TemplateBinding CategoryBackgroundBrush}">
-                                <TextBlock ui:Translator.Key="{TemplateBinding DisplayName}"
-                                           FontWeight="Bold" />
-                            </Border>
-                            <Border Grid.Row="1" Background="{DynamicResource ThemeControlMidBrush}">
-                                <StackPanel>
-                                    <ItemsControl ItemsSource="{TemplateBinding Outputs}"
-                                                  ClipToBounds="False">
-                                        <ItemsControl.ItemContainerTheme>
-                                            <ControlTheme TargetType="ContentPresenter">
-                                                <Setter Property="DataContext" Value="." />
-                                            </ControlTheme>
-                                        </ItemsControl.ItemContainerTheme>
-                                    </ItemsControl>
-                                    <ItemsControl ItemsSource="{TemplateBinding Inputs}" ClipToBounds="False">
-                                        <ItemsControl.ItemContainerTheme>
-                                            <ControlTheme TargetType="ContentPresenter">
-                                                <Setter Property="DataContext" Value="." />
-                                            </ControlTheme>
-                                        </ItemsControl.ItemContainerTheme>
-                                    </ItemsControl>
-                                </StackPanel>
-                            </Border>
-                            <Border IsVisible="{Binding !!ResultPreview, RelativeSource={RelativeSource TemplatedParent}}"
+                        <Grid.RowDefinitions>
+                            <RowDefinition Height="Auto" />
+                            <RowDefinition Height="Auto" />
+                            <RowDefinition Height="Auto" />
+                        </Grid.RowDefinitions>
+                        <Border Padding="{TemplateBinding Padding}" Grid.ColumnSpan="3" Grid.Row="0"
+                                CornerRadius="4.5, 4.5, 0 ,0"
+                                Background="{TemplateBinding CategoryBackgroundBrush}">
+                            <TextBlock ui:Translator.Key="{TemplateBinding DisplayName}"
+                                       FontWeight="Bold" />
+                        </Border>
+                        <Border Grid.Row="1" Background="{DynamicResource ThemeControlMidBrush}">
+                            <StackPanel>
+                                <ItemsControl ItemsSource="{TemplateBinding Outputs}"
+                                              ClipToBounds="False">
+                                    <ItemsControl.ItemContainerTheme>
+                                        <ControlTheme TargetType="ContentPresenter">
+                                            <Setter Property="DataContext" Value="." />
+                                        </ControlTheme>
+                                    </ItemsControl.ItemContainerTheme>
+                                </ItemsControl>
+                                <ItemsControl ItemsSource="{TemplateBinding Inputs}" ClipToBounds="False">
+                                    <ItemsControl.ItemContainerTheme>
+                                        <ControlTheme TargetType="ContentPresenter">
+                                            <Setter Property="DataContext" Value="." />
+                                        </ControlTheme>
+                                    </ItemsControl.ItemContainerTheme>
+                                </ItemsControl>
+                            </StackPanel>
+                        </Border>
+                        <Border IsVisible="{Binding !!ResultPreview, RelativeSource={RelativeSource TemplatedParent}}"
                                 CornerRadius="0, 0, 4.5, 4.5" Grid.Row="2" ClipToBounds="True">
-                                <visuals:TextureControl Width="200" Height="200"
-                                                        Texture="{TemplateBinding ResultPreview}"
-                                                        RenderOptions.BitmapInterpolationMode="None">
-                                    <visuals:TextureControl.Background>
-                                        <ImageBrush Source="/Images/CheckerTile.png"
-                                                    TileMode="Tile" DestinationRect="0, 0, 25, 25" />
-                                    </visuals:TextureControl.Background>
-                                </visuals:TextureControl>
-                            </Border>
-                        </Grid>
-                    </Border>
+                            <Panel RenderOptions.BitmapInterpolationMode="None" Width="200" Height="200">
+                                <Panel.Background>
+                                    <ImageBrush Source="/Images/CheckerTile.png"
+                                                TileMode="Tile" DestinationRect="0, 0, 25, 25" />
+                                </Panel.Background>
+                            <visuals:PreviewPainterControl
+                                                           PreviewPainter="{TemplateBinding ResultPreview}"
+                                                           FrameToRender="{TemplateBinding ActiveFrame}"
+                                                           RenderOptions.BitmapInterpolationMode="None">
+                            </visuals:PreviewPainterControl>
+                            </Panel>
+                        </Border>
+                    </Grid>
+                </Border>
             </ControlTemplate>
         </Setter>
 

+ 1 - 0
src/PixiEditor/Views/Dock/NodeGraphDockView.axaml

@@ -16,5 +16,6 @@
         CreateNodeCommand="{xaml:Command PixiEditor.NodeGraph.CreateNode, UseProvided=True}"
         ChangeNodePosCommand="{xaml:Command PixiEditor.NodeGraph.ChangeNodePos, UseProvided=True}"
         EndChangeNodePosCommand="{xaml:Command PixiEditor.NodeGraph.EndChangeNodePos, UseProvided=True}"
+        ActiveFrame="{Binding DocumentManagerSubViewModel.ActiveDocument.AnimationDataViewModel.ActiveFrameBindable}"
         NodeGraph="{Binding DocumentManagerSubViewModel.ActiveDocument.NodeGraph}"/>
 </UserControl>

+ 7 - 0
src/PixiEditor/Views/Nodes/NodeGraphView.cs

@@ -167,6 +167,12 @@ internal class NodeGraphView : Zoombox.Zoombox
         set => SetValue(SocketDropCommandProperty, value);
     }
 
+    public int ActiveFrame
+    {
+        get { return (int)GetValue(ActiveFrameProperty); }
+        set { SetValue(ActiveFrameProperty, value); }
+    }
+
     private bool isDraggingNodes;
     private bool isDraggingConnection;
     private VecD clickPointOffset;
@@ -182,6 +188,7 @@ internal class NodeGraphView : Zoombox.Zoombox
     private NodeConnectionViewModel? _hiddenConnection;
     private Color _startingPropColor;
     private VecD _lastMouseClickPos;
+    public static readonly StyledProperty<int> ActiveFrameProperty = AvaloniaProperty.Register<NodeGraphView, int>("ActiveFrame");
 
     public NodeGraphView()
     {

+ 10 - 2
src/PixiEditor/Views/Nodes/NodeView.cs

@@ -12,6 +12,7 @@ using PixiEditor.Helpers;
 using PixiEditor.ViewModels.Nodes;
 using PixiEditor.DrawingApi.Core;
 using PixiEditor.Models.Handlers;
+using PixiEditor.Models.Rendering;
 using PixiEditor.Models.Structures;
 using PixiEditor.Views.Nodes.Properties;
 
@@ -35,7 +36,7 @@ public class NodeView : TemplatedControl
         AvaloniaProperty.Register<NodeView, ObservableRangeCollection<INodePropertyHandler>>(
             nameof(Outputs));
 
-    public static readonly StyledProperty<Texture> ResultPreviewProperty = AvaloniaProperty.Register<NodeView, Texture>(
+    public static readonly StyledProperty<PreviewPainter> ResultPreviewProperty = AvaloniaProperty.Register<NodeView, PreviewPainter>(
         nameof(ResultPreview));
 
     public static readonly StyledProperty<bool> IsSelectedProperty = AvaloniaProperty.Register<NodeView, bool>(
@@ -68,7 +69,7 @@ public class NodeView : TemplatedControl
         set => SetValue(IsSelectedProperty, value);
     }
 
-    public Texture ResultPreview
+    public PreviewPainter ResultPreview
     {
         get => GetValue(ResultPreviewProperty);
         set => SetValue(ResultPreviewProperty, value);
@@ -132,7 +133,14 @@ public class NodeView : TemplatedControl
         set => SetValue(SocketDropCommandProperty, value);
     }
 
+    public int ActiveFrame
+    {
+        get { return (int)GetValue(ActiveFrameProperty); }
+        set { SetValue(ActiveFrameProperty, value); }
+    }
+
     private bool captured;
+    public static readonly StyledProperty<int> ActiveFrameProperty = AvaloniaProperty.Register<NodeView, int>("ActiveFrame");
 
     static NodeView()
     {