Skip to content

Commit

Permalink
Added "final" (after outline) upscaling to SpriteMaker
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMcLean committed Nov 11, 2024
1 parent d8327ad commit 81b8448
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Voxel2Pixel.Web/Pages/Render.razor
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@
<MudColorPicker @bind-Value="OutlineMudColor" Label="Outline Color" Style=@($"color: {OutlineMudColor.ToString()};") />
}
</MudElement>
<br />
<MudElement Class="d-inline-flex flex-wrap gap-2">
<MudNumericField T="ushort" @bind-Value="SpriteMaker.FinalScaleX" Label="Final (after outline) Scale X" Variant="Variant.Text" Min="1" />
<MudNumericField T="ushort" @bind-Value="SpriteMaker.FinalScaleY" Label="Final (after outline) Scale Y" Variant="Variant.Text" Min="1" />
</MudElement>
</MudTabPanel>
<MudTabPanel Text="Export" Disabled="Model is null">
<MudButton Variant="Variant.Filled" Color="MudBlazor.Color.Primary" name="SingleImage" @onclick="SingleImage">Generate Single Image</MudButton>
Expand Down
34 changes: 32 additions & 2 deletions Voxel2Pixel/Render/SpriteMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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; }
Expand Down Expand Up @@ -298,8 +326,10 @@ Point Point(Point3D point3D)
Y: point.Y * maker.ScaleY + (maker.Outline ? 1 : 0));
}
sprite.SetRange(points.Select(point => new KeyValuePair<string, Point>(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<Sprite> Make(params SpriteMaker[] spriteMakers) => spriteMakers.Make();
Expand Down

0 comments on commit 81b8448

Please sign in to comment.