|
@@ -25,49 +25,7 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
}
|
|
|
|
|
|
private IReadOnlyDocument Document { get; }
|
|
|
- //public Texture OnionSkinTexture { get; set; }
|
|
|
|
|
|
- /*public Texture RenderDocument(KeyFrameTime frameTime, ChunkResolution resolution, Texture toDrawOn = null,
|
|
|
- Paint paint = null)
|
|
|
- {
|
|
|
- VecI sizeInChunks = Document.Size / resolution.PixelSize();
|
|
|
-
|
|
|
- sizeInChunks = new VecI(
|
|
|
- Math.Max(1, sizeInChunks.X),
|
|
|
- Math.Max(1, sizeInChunks.Y));
|
|
|
-
|
|
|
- if (toDrawOn is null)
|
|
|
- {
|
|
|
- VecI size = new VecI(
|
|
|
- Math.Min(Document.Size.X, resolution.PixelSize() * sizeInChunks.X),
|
|
|
- Math.Min(Document.Size.Y, resolution.PixelSize() * sizeInChunks.Y));
|
|
|
- toDrawOn = new Texture(size);
|
|
|
- }
|
|
|
-
|
|
|
- for (int x = 0; x < sizeInChunks.X; x++)
|
|
|
- {
|
|
|
- for (int y = 0; y < sizeInChunks.Y; y++)
|
|
|
- {
|
|
|
- VecI chunkPos = new(x, y);
|
|
|
- OneOf<Chunk, EmptyChunk> chunk = RenderChunk(chunkPos, resolution, frameTime);
|
|
|
- if (chunk.IsT0)
|
|
|
- {
|
|
|
- toDrawOn.DrawingSurface.Canvas.DrawSurface(
|
|
|
- chunk.AsT0.Surface.DrawingSurface,
|
|
|
- chunkPos.Multiply(new VecI(resolution.PixelSize())), paint);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var pos = chunkPos * resolution.PixelSize();
|
|
|
- toDrawOn.DrawingSurface.Canvas.DrawRect(pos.X, pos.Y, resolution.PixelSize(),
|
|
|
- resolution.PixelSize(), ClearPaint);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return toDrawOn;
|
|
|
- }*/
|
|
|
-
|
|
|
public void RenderChunk(VecI chunkPos, ChunkResolution resolution, KeyFrameTime frameTime)
|
|
|
{
|
|
|
try
|
|
@@ -85,34 +43,6 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public OneOf<Chunk, EmptyChunk> RenderChunk(VecI chunkPos, ChunkResolution resolution,
|
|
|
- IReadOnlyNode node, KeyFrameTime frameTime, RectI? globalClippingRect = null)
|
|
|
- {
|
|
|
- //using RenderingContext context = new(frameTime, chunkPos, resolution, Document.Size);
|
|
|
- try
|
|
|
- {
|
|
|
- /*RectI? transformedClippingRect = TransformClipRect(globalClippingRect, resolution, chunkPos);
|
|
|
-
|
|
|
- Texture? evaluated = node.Execute(context);
|
|
|
- if (evaluated is null)
|
|
|
- {
|
|
|
- return new EmptyChunk();
|
|
|
- }
|
|
|
-
|
|
|
- var result = ChunkFromResult(resolution, transformedClippingRect, evaluated.DrawingSurface.Snapshot(),
|
|
|
- context);
|
|
|
- evaluated.Dispose();
|
|
|
-
|
|
|
- return result;*/
|
|
|
- return new EmptyChunk();
|
|
|
- }
|
|
|
- catch (ObjectDisposedException)
|
|
|
- {
|
|
|
- return new EmptyChunk();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
private static RectI? TransformClipRect(RectI? globalClippingRect, ChunkResolution resolution, VecI chunkPos)
|
|
|
{
|
|
|
if (globalClippingRect is not RectI rect)
|
|
@@ -140,99 +70,20 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
}
|
|
|
|
|
|
|
|
|
- public Texture? RenderLayer(Guid nodeId, ChunkResolution resolution, KeyFrameTime frameTime)
|
|
|
+ public void RenderLayer(DrawingSurface renderOn, Guid nodeId, ChunkResolution resolution, KeyFrameTime frameTime)
|
|
|
{
|
|
|
var node = Document.FindNode(nodeId);
|
|
|
|
|
|
if (node is null)
|
|
|
{
|
|
|
- return null;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- VecI sizeInChunks = Document.Size / resolution.PixelSize();
|
|
|
-
|
|
|
- sizeInChunks = new VecI(
|
|
|
- Math.Max(1, sizeInChunks.X),
|
|
|
- Math.Max(1, sizeInChunks.Y));
|
|
|
-
|
|
|
- VecI size = new VecI(
|
|
|
- Math.Min(Document.Size.X, resolution.PixelSize() * sizeInChunks.X),
|
|
|
- Math.Min(Document.Size.Y, resolution.PixelSize() * sizeInChunks.Y));
|
|
|
-
|
|
|
- Texture texture = new(size);
|
|
|
-
|
|
|
- for (int x = 0; x < sizeInChunks.X; x++)
|
|
|
- {
|
|
|
- for (int y = 0; y < sizeInChunks.Y; y++)
|
|
|
- {
|
|
|
- VecI chunkPos = new(x, y);
|
|
|
- RectI globalClippingRect = new(0, 0, Document.Size.X, Document.Size.Y);
|
|
|
- OneOf<Chunk, EmptyChunk> chunk = RenderChunk(chunkPos, resolution, node, frameTime, globalClippingRect);
|
|
|
- if (chunk.IsT0)
|
|
|
- {
|
|
|
- VecI pos = chunkPos * resolution.PixelSize();
|
|
|
- texture.DrawingSurface.Canvas.DrawSurface(
|
|
|
- chunk.AsT0.Surface.DrawingSurface,
|
|
|
- pos.X, pos.Y, null);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ using RenderContext context = new(renderOn, frameTime, resolution, Document.Size);
|
|
|
+ context.IsExportRender = true;
|
|
|
|
|
|
- return texture;
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- private static OneOf<Chunk, EmptyChunk> RenderChunkOnGraph(VecI chunkPos, ChunkResolution resolution,
|
|
|
- RectI? globalClippingRect,
|
|
|
- IReadOnlyNodeGraph graph, RenderingContext context)
|
|
|
- {
|
|
|
- RectI? transformedClippingRect = TransformClipRect(globalClippingRect, resolution, chunkPos);
|
|
|
-
|
|
|
- Texture? evaluated = graph.Execute(context);
|
|
|
- if (evaluated is null)
|
|
|
- {
|
|
|
- return new EmptyChunk();
|
|
|
- }
|
|
|
-
|
|
|
- Chunk chunk = Chunk.Create(resolution);
|
|
|
-
|
|
|
- chunk.Surface.DrawingSurface.Canvas.Save();
|
|
|
- chunk.Surface.DrawingSurface.Canvas.Clear();
|
|
|
-
|
|
|
- if (transformedClippingRect is not null)
|
|
|
- {
|
|
|
- chunk.Surface.DrawingSurface.Canvas.ClipRect((RectD)transformedClippingRect);
|
|
|
- }
|
|
|
-
|
|
|
- VecD pos = chunkPos;
|
|
|
- int x = (int)(pos.X * ChunkyImage.FullChunkSize * resolution.Multiplier());
|
|
|
- int y = (int)(pos.Y * ChunkyImage.FullChunkSize * resolution.Multiplier());
|
|
|
- int width = (int)(ChunkyImage.FullChunkSize * resolution.Multiplier());
|
|
|
- int height = (int)(ChunkyImage.FullChunkSize * resolution.Multiplier());
|
|
|
-
|
|
|
- RectD sourceRect = new(x, y, width, height);
|
|
|
-
|
|
|
- RectD availableRect = new(0, 0, evaluated.Size.X, evaluated.Size.Y);
|
|
|
-
|
|
|
- sourceRect = sourceRect.Intersect(availableRect);
|
|
|
-
|
|
|
- if (sourceRect.IsZeroOrNegativeArea)
|
|
|
- {
|
|
|
- chunk.Dispose();
|
|
|
- return new EmptyChunk();
|
|
|
- }
|
|
|
-
|
|
|
- using var chunkSnapshot = evaluated.DrawingSurface.Snapshot((RectI)sourceRect);
|
|
|
-
|
|
|
- if (context.IsDisposed) return new EmptyChunk();
|
|
|
-
|
|
|
- chunk.Surface.DrawingSurface.Canvas.DrawImage(chunkSnapshot, 0, 0, context.ReplacingPaintWithOpacity);
|
|
|
-
|
|
|
- chunk.Surface.DrawingSurface.Canvas.Restore();
|
|
|
-
|
|
|
- return chunk;
|
|
|
+ node.Execute(context);
|
|
|
}
|
|
|
- */
|
|
|
|
|
|
public static IReadOnlyNodeGraph ConstructMembersOnlyGraph(IReadOnlyNodeGraph fullGraph)
|
|
|
{
|
|
@@ -272,34 +123,6 @@ public class DocumentRenderer : IPreviewRenderable
|
|
|
return membersOnlyGraph;
|
|
|
}
|
|
|
|
|
|
- private static OneOf<Chunk, EmptyChunk> ChunkFromResult(
|
|
|
- ChunkResolution resolution,
|
|
|
- RectI? transformedClippingRect, Image evaluated,
|
|
|
- RenderContext context)
|
|
|
- {
|
|
|
- Chunk chunk = Chunk.Create(resolution);
|
|
|
-
|
|
|
- chunk.Surface.DrawingSurface.Canvas.Save();
|
|
|
- chunk.Surface.DrawingSurface.Canvas.Clear();
|
|
|
-
|
|
|
- int x = 0;
|
|
|
- int y = 0;
|
|
|
-
|
|
|
- if (transformedClippingRect is not null)
|
|
|
- {
|
|
|
- chunk.Surface.DrawingSurface.Canvas.ClipRect((RectD)transformedClippingRect);
|
|
|
- x = transformedClippingRect.Value.X;
|
|
|
- y = transformedClippingRect.Value.Y;
|
|
|
- }
|
|
|
-
|
|
|
- chunk.Surface.DrawingSurface.Canvas.DrawImage(evaluated, x, y,
|
|
|
- context.ReplacingPaintWithOpacity);
|
|
|
-
|
|
|
- chunk.Surface.DrawingSurface.Canvas.Restore();
|
|
|
-
|
|
|
- return chunk;
|
|
|
- }
|
|
|
-
|
|
|
public RectD? GetPreviewBounds(int frame, string elementNameToRender = "") =>
|
|
|
new(0, 0, Document.Size.X, Document.Size.Y);
|
|
|
|