|
@@ -19,7 +19,7 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
};
|
|
|
|
|
|
private Texture renderTexture;
|
|
|
-
|
|
|
+
|
|
|
public DocumentRenderer(IReadOnlyDocument document)
|
|
|
{
|
|
|
Document = document;
|
|
@@ -74,12 +74,12 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
IsBusy = true;
|
|
|
|
|
|
RenderContext context = new(renderOn, frameTime, resolution, Document.Size, Document.ProcessingColorSpace);
|
|
|
context.FullRerender = true;
|
|
|
-
|
|
|
+
|
|
|
node.RenderForOutput(context, renderOn, null);
|
|
|
IsBusy = false;
|
|
|
}
|
|
@@ -89,7 +89,8 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
return ConstructMembersOnlyGraph(null, fullGraph);
|
|
|
}
|
|
|
|
|
|
- public static IReadOnlyNodeGraph ConstructMembersOnlyGraph(HashSet<Guid>? layersToCombine,
|
|
|
+ public static IReadOnlyNodeGraph ConstructMembersOnlyGraph(
|
|
|
+ HashSet<Guid>? membersToCombine,
|
|
|
IReadOnlyNodeGraph fullGraph)
|
|
|
{
|
|
|
NodeGraph membersOnlyGraph = new();
|
|
@@ -98,26 +99,40 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
|
|
|
membersOnlyGraph.AddNode(outputNode);
|
|
|
|
|
|
- List<LayerNode> layersInOrder = new();
|
|
|
+ Dictionary<Guid, Guid> nodeMapping = new();
|
|
|
|
|
|
- fullGraph.TryTraverse(node =>
|
|
|
+ fullGraph.OutputNode.TraverseBackwards((node, input) =>
|
|
|
{
|
|
|
- if (node is LayerNode layer && (layersToCombine == null || layersToCombine.Contains(layer.Id)))
|
|
|
+ if (node is StructureNode structureNode && membersToCombine != null &&
|
|
|
+ !membersToCombine.Contains(structureNode.Id))
|
|
|
{
|
|
|
- layersInOrder.Insert(0, layer);
|
|
|
+ return true;
|
|
|
}
|
|
|
- });
|
|
|
|
|
|
- IInputProperty<Painter> lastInput = outputNode.Input;
|
|
|
+ if (node is LayerNode layer)
|
|
|
+ {
|
|
|
+ LayerNode clone = (LayerNode)layer.Clone();
|
|
|
+ membersOnlyGraph.AddNode(clone);
|
|
|
+
|
|
|
+
|
|
|
+ IInputProperty targetInput = GetTargetInput(input, fullGraph, membersOnlyGraph, nodeMapping);
|
|
|
+
|
|
|
+ clone.Output.ConnectTo(targetInput);
|
|
|
+ nodeMapping[layer.Id] = clone.Id;
|
|
|
+ }
|
|
|
+ else if (node is FolderNode folder)
|
|
|
+ {
|
|
|
+ FolderNode clone = (FolderNode)folder.Clone();
|
|
|
+ membersOnlyGraph.AddNode(clone);
|
|
|
|
|
|
- foreach (var layer in layersInOrder)
|
|
|
- {
|
|
|
- var clone = (LayerNode)layer.Clone();
|
|
|
- membersOnlyGraph.AddNode(clone);
|
|
|
+ var targetInput = GetTargetInput(input, fullGraph, membersOnlyGraph, nodeMapping);
|
|
|
+
|
|
|
+ clone.Output.ConnectTo(targetInput);
|
|
|
+ nodeMapping[folder.Id] = clone.Id;
|
|
|
+ }
|
|
|
|
|
|
- clone.Output.ConnectTo(lastInput);
|
|
|
- lastInput = clone.Background;
|
|
|
- }
|
|
|
+ return true;
|
|
|
+ });
|
|
|
|
|
|
return membersOnlyGraph;
|
|
|
}
|
|
@@ -129,19 +144,19 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
string elementToRenderName)
|
|
|
{
|
|
|
IsBusy = true;
|
|
|
-
|
|
|
- if(renderTexture == null || renderTexture.Size != Document.Size)
|
|
|
+
|
|
|
+ if (renderTexture == null || renderTexture.Size != Document.Size)
|
|
|
{
|
|
|
renderTexture?.Dispose();
|
|
|
renderTexture = Texture.ForProcessing(Document.Size, Document.ProcessingColorSpace);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
renderTexture.DrawingSurface.Canvas.Clear();
|
|
|
context.RenderSurface = renderTexture.DrawingSurface;
|
|
|
Document.NodeGraph.Execute(context);
|
|
|
-
|
|
|
+
|
|
|
renderOn.Canvas.DrawSurface(renderTexture.DrawingSurface, 0, 0);
|
|
|
-
|
|
|
+
|
|
|
IsBusy = false;
|
|
|
|
|
|
return true;
|
|
@@ -150,18 +165,54 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
public void RenderDocument(DrawingSurface toRenderOn, KeyFrameTime frameTime)
|
|
|
{
|
|
|
IsBusy = true;
|
|
|
-
|
|
|
- if(renderTexture == null || renderTexture.Size != Document.Size)
|
|
|
+
|
|
|
+ if (renderTexture == null || renderTexture.Size != Document.Size)
|
|
|
{
|
|
|
renderTexture?.Dispose();
|
|
|
renderTexture = Texture.ForProcessing(Document.Size, Document.ProcessingColorSpace);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
renderTexture.DrawingSurface.Canvas.Clear();
|
|
|
- RenderContext context = new(renderTexture.DrawingSurface, frameTime, ChunkResolution.Full, Document.Size, Document.ProcessingColorSpace) { FullRerender = true };
|
|
|
+ RenderContext context =
|
|
|
+ new(renderTexture.DrawingSurface, frameTime, ChunkResolution.Full, Document.Size,
|
|
|
+ Document.ProcessingColorSpace) { FullRerender = true };
|
|
|
Document.NodeGraph.Execute(context);
|
|
|
-
|
|
|
+
|
|
|
toRenderOn.Canvas.DrawSurface(renderTexture.DrawingSurface, 0, 0);
|
|
|
IsBusy = false;
|
|
|
}
|
|
|
+
|
|
|
+ private static IInputProperty GetTargetInput(IInputProperty? input,
|
|
|
+ IReadOnlyNodeGraph sourceGraph,
|
|
|
+ NodeGraph membersOnlyGraph,
|
|
|
+ Dictionary<Guid, Guid> nodeMapping)
|
|
|
+ {
|
|
|
+ if(input == null) return membersOnlyGraph.OutputNode.Input;
|
|
|
+
|
|
|
+ if (nodeMapping.ContainsKey(input.Node?.Id ?? Guid.Empty))
|
|
|
+ {
|
|
|
+ return membersOnlyGraph.Nodes.First(x => x.Id == nodeMapping[input.Node.Id])
|
|
|
+ .GetInputProperty(input.InternalPropertyName);
|
|
|
+ }
|
|
|
+
|
|
|
+ var sourceNode = sourceGraph.AllNodes.First(x => x.Id == input.Node.Id);
|
|
|
+
|
|
|
+ IInputProperty? found = null;
|
|
|
+ sourceNode.TraverseForwards((n, input) =>
|
|
|
+ {
|
|
|
+ if (n is StructureNode structureNode)
|
|
|
+ {
|
|
|
+ if(nodeMapping.TryGetValue(structureNode.Id, out var value))
|
|
|
+ {
|
|
|
+ Node mappedNode = membersOnlyGraph.Nodes.First(x => x.Id == value);
|
|
|
+ found = mappedNode.GetInputProperty(input.InternalPropertyName);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ return found ?? membersOnlyGraph.OutputNode.Input;
|
|
|
+ }
|
|
|
}
|