From 81b84484205b66bfdabf796e4b6374eb003e4d49 Mon Sep 17 00:00:00 2001 From: BenMcLean Date: Sun, 10 Nov 2024 21:26:46 -0600 Subject: [PATCH] Added "final" (after outline) upscaling to SpriteMaker --- Voxel2Pixel.Web/Pages/Render.razor | 5 +++++ Voxel2Pixel/Render/SpriteMaker.cs | 34 ++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Voxel2Pixel.Web/Pages/Render.razor b/Voxel2Pixel.Web/Pages/Render.razor index 4e0dc03..0561633 100644 --- a/Voxel2Pixel.Web/Pages/Render.razor +++ b/Voxel2Pixel.Web/Pages/Render.razor @@ -201,6 +201,11 @@ } +
+ + + + Generate Single Image diff --git a/Voxel2Pixel/Render/SpriteMaker.cs b/Voxel2Pixel/Render/SpriteMaker.cs index 21e97fa..893c9c5 100644 --- a/Voxel2Pixel/Render/SpriteMaker.cs +++ b/Voxel2Pixel/Render/SpriteMaker.cs @@ -71,6 +71,30 @@ public ushort ScaleY } } private ushort scaleY = 1; + public ushort FinalScaleX + { + get => finalScaleX; + set + { + if (value < 1) + throw new InvalidDataException(); + else + finalScaleX = value; + } + } + private ushort finalScaleX = 1; + public ushort FinalScaleY + { + get => finalScaleY; + set + { + if (value < 1) + throw new InvalidDataException(); + else + finalScaleY = value; + } + } + private ushort finalScaleY = 1; public bool Shadow { get; set; } = false; public IVoxelColor ShadowColor { get; set; } = DefaultShadowVoxelColor; public bool Outline { get; set; } = false; @@ -95,6 +119,8 @@ public SpriteMaker(SpriteMaker maker) CuboidOrientation = maker.CuboidOrientation; ScaleX = maker.ScaleX; ScaleY = maker.ScaleY; + FinalScaleX = maker.FinalScaleX; + FinalScaleY = maker.FinalScaleY; Shadow = maker.Shadow; ShadowColor = maker.ShadowColor; Outline = maker.Outline; @@ -116,6 +142,8 @@ public SpriteMaker(SpriteMaker maker) public SpriteMaker Set(CuboidOrientation cuboidOrientation) { CuboidOrientation = cuboidOrientation; return this; } public SpriteMaker SetScaleX(ushort scaleX) { ScaleX = scaleX; return this; } public SpriteMaker SetScaleY(ushort scaleY) { ScaleY = scaleY; return this; } + public SpriteMaker SetFinalScaleX(ushort finalScaleX) { FinalScaleX = finalScaleX; return this; } + public SpriteMaker SetFinalScaleY(ushort finalScaleY) { FinalScaleY = finalScaleY; return this; } public SpriteMaker SetShadow(bool shadow) { Shadow = shadow; return this; } public SpriteMaker ToggleShadow() => SetShadow(!Shadow); public SpriteMaker SetShadowColor(IVoxelColor shadowColor) { ShadowColor = shadowColor; return this; } @@ -298,8 +326,10 @@ Point Point(Point3D point3D) Y: point.Y * maker.ScaleY + (maker.Outline ? 1 : 0)); } sprite.SetRange(points.Select(point => new KeyValuePair(point.Key, Point(point.Value)))); - return maker.Crop ? - sprite.Crop2Content(maker.Threshold) + if (maker.Crop) + sprite = sprite.Crop2Content(maker.Threshold); + return maker.FinalScaleX > 1 || maker.FinalScaleY > 1 ? + sprite.Upscale(maker.FinalScaleX, maker.FinalScaleY) : sprite; } public static IEnumerable Make(params SpriteMaker[] spriteMakers) => spriteMakers.Make();