Skip to content

Commit f26926a

Browse files
committed
Optimised the conversion with a palette
1 parent 86c1247 commit f26926a

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

SchematicToVoxCore/Schematics/PaletteSchematicConverter.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,24 @@ public Schematic ConvertSchematic(Schematic schematic)
3535
{
3636
Console.WriteLine("[LOG] Started to convert all colors of blocks to match the palette");
3737
Schematic newSchematic = new Schematic(schematic.Width, schematic.Height, schematic.Length, new HashSet<Block>());
38-
foreach (Block block in schematic.Blocks)
38+
List<uint> colors = schematic.Colors;
39+
Dictionary<uint, int> paletteDictionary = new Dictionary<uint, int>();
40+
foreach (uint color in colors)
3941
{
40-
Color color = block.Color.UIntToColor();
41-
int index = ColorComparison.CompareColorAll(_colors, color);
42-
newSchematic.Blocks.Add(new Block(block.X, block.Y, block.Z, _colors[index].ColorToUInt(), index));
42+
int index = ColorComparison.CompareColorAll(_colors, color.UIntToColor());
43+
paletteDictionary[color] = index;
4344
}
45+
46+
using (ProgressBar progressbar = new ProgressBar())
47+
{
48+
int i = 0;
49+
foreach (Block block in schematic.Blocks)
50+
{
51+
newSchematic.Blocks.Add(new Block(block.X, block.Y, block.Z, _colors[paletteDictionary[block.Color]].ColorToUInt(), paletteDictionary[block.Color]));
52+
progressbar.Report(i++ / (float)schematic.Blocks.Count);
53+
}
54+
}
55+
4456
Console.WriteLine("[LOG] Done.");
4557
return newSchematic;
4658
}

SchematicToVoxCore/Schematics/Schematic.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System.Collections.Generic;
2+
using System.Drawing;
3+
using System.Linq;
24

35
namespace FileToVox.Schematics
46
{
@@ -26,7 +28,19 @@ public Schematic(ushort width, ushort height, ushort length, HashSet<Block> bloc
2628
{
2729
Blocks = blocks;
2830
}
29-
30-
31+
32+
public List<uint> Colors
33+
{
34+
get
35+
{
36+
List<uint> colors = new List<uint>();
37+
foreach (Block block in Blocks.Where(block => !colors.Contains(block.Color)))
38+
{
39+
colors.Add(block.Color);
40+
}
41+
42+
return colors;
43+
}
44+
}
3145
}
3246
}

0 commit comments

Comments
 (0)