Skip to content

Commit

Permalink
Add Table to exclude blocks from reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
Toreole committed Jul 31, 2023
1 parent 5246709 commit 207768a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion BlazorWebAssembly/BlazorWebAssembly.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWebAssembly.Client",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWebAssembly.Shared", "Shared\BlazorWebAssembly.Shared.csproj", "{2ABAA9E5-A116-4201-88F1-2A7832267CF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TexMetadataGenerator", "TexMetadataGenerator\TexMetadataGenerator.csproj", "{7AE0A7E1-CA81-4EAB-B203-2944D40111D2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TexMetadataGenerator", "TexMetadataGenerator\TexMetadataGenerator.csproj", "{7AE0A7E1-CA81-4EAB-B203-2944D40111D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion BlazorWebAssembly/Client/Core/ImageReconstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async void ReadFile(Stream stream)
RGB col = new() { r = pixel.R, g = pixel.G, b = pixel.B };
var query = from block in blockData
from texture in block.textures
orderby texture.ColorDistance(col, ContrastBias) ascending
orderby texture.ColorDistance(block, col, ContrastBias) ascending
select (block, texture);
return query.First();
}
Expand Down
32 changes: 32 additions & 0 deletions BlazorWebAssembly/Client/Pages/Settings.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@page "/settings"

@using BlazorWebAssembly.Client.Core;
@using Img2mc.Shared;

@inject ImageReconstructor imageReconstructor

<h3>Settings</h3>

<MudTable Items="@imageReconstructor.blockData">
<HeaderContent>
<MudTh>
<MudTableSortLabel SortBy="new Func<MinecraftBlock, string>(x => x.blockName)">Block</MudTableSortLabel>
</MudTh>
<MudTh>
Exclude
</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Block">@context.blockName</MudTd>
<MudTd DataLabel="Exclude">
<MudCheckBox @bind-Checked="@context.exclude"></MudCheckBox>
</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new int[]{50, 100}" />
</PagerContent>
</MudTable>

@code {

}
5 changes: 5 additions & 0 deletions BlazorWebAssembly/Client/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<span class="oi oi-home" aria-hidden="true"></span> Home
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="settings" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> Settings
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
Expand Down
5 changes: 4 additions & 1 deletion BlazorWebAssembly/Shared/TextureMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ public TextureMetadata(string fileName, RGB avgRGB, float hueVariance, float sat

public TextureMetadata() { }

public float ColorDistance(RGB rgb, float contrastPenalty = 0f)
public float ColorDistance(MinecraftBlock blockContext, RGB rgb, float contrastPenalty = 0f)
{
if (blockContext.exclude || this.exclude)
return float.MaxValue;

float distance = averageRGB.RGBDistance(rgb);

float contrast = (1/valueVariance);
Expand Down

0 comments on commit 207768a

Please sign in to comment.