Skip to content

Commit da2d5a1

Browse files
committed
Merge branch 'feature/scale_rework'
2 parents a2c8302 + db45f2a commit da2d5a1

File tree

4 files changed

+49
-30
lines changed

4 files changed

+49
-30
lines changed

SchematicToVoxCore/Converter/PointCloud/PointCloudToSchematic.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using MoreLinq;
66
using System;
77
using System.Collections.Generic;
8+
using System.Diagnostics;
89

910
namespace FileToVox.Converter.PointCloud
1011
{
@@ -39,24 +40,48 @@ protected void VoxelizeData(BodyDataDTO data)
3940
for (int i = 0; i < data.BodyVertices.Count; i++)
4041
{
4142
data.BodyVertices[i] += new Vector3(min, min, min);
42-
data.BodyVertices[i] = new Vector3((float)Math.Truncate(data.BodyVertices[i].X * Scale), (float)Math.Truncate(data.BodyVertices[i].Y * Scale), (float)Math.Truncate(data.BodyVertices[i].Z * Scale));
43+
//data.BodyVertices[i] = new Vector3((float)Math.Truncate(data.BodyVertices[i].X * Scale), (float)Math.Truncate(data.BodyVertices[i].Y * Scale), (float)Math.Truncate(data.BodyVertices[i].Z * Scale));
4344
}
4445

45-
//HashSet<Vector3> set = new HashSet<Vector3>();
46+
Vector3 maxX = data.BodyVertices.MaxBy(t => t.X);
47+
Vector3 maxY = data.BodyVertices.MaxBy(t => t.Y);
48+
Vector3 maxZ = data.BodyVertices.MaxBy(t => t.Z);
49+
50+
Console.WriteLine("[INFO] Max X: " + maxX.X + ", Y: " + maxY.Y + ", " + maxZ.Z);
51+
52+
minX = data.BodyVertices.MinBy(t => t.X);
53+
minY = data.BodyVertices.MinBy(t => t.Y);
54+
minZ = data.BodyVertices.MinBy(t => t.Z);
55+
56+
Console.WriteLine("[INFO] Min X: " + minX.X + ", Y: " + minY.Y + ", " + minZ.Z);
57+
58+
Vector3 size = new Vector3(maxX.X - minX.X, maxY.Y - minY.Y, maxZ.Z - minZ.Z);
59+
60+
Console.WriteLine("[INFO] Size X: " + size.X + ", Y: " + size.Y + ", " + size.Z);
61+
62+
float max = Math.Max(size.X, Math.Max(size.Y, size.Z));
63+
float factor = Scale / max;
64+
65+
for (int i = 0; i < data.BodyVertices.Count; i++)
66+
{
67+
data.BodyVertices[i] = new Vector3((float)Math.Truncate(data.BodyVertices[i].X * factor), (float)Math.Truncate(data.BodyVertices[i].Y * factor), (float)Math.Truncate(data.BodyVertices[i].Z * factor));
68+
}
4669

4770
minX = data.BodyVertices.MinBy(t => t.X);
4871
minY = data.BodyVertices.MinBy(t => t.Y);
4972
minZ = data.BodyVertices.MinBy(t => t.Z);
5073

74+
//HashSet<Vector3> set = new HashSet<Vector3>();
75+
5176
min = Math.Min(minX.X, Math.Min(minY.Y, minZ.Z));
5277

5378
Console.WriteLine("[INFO] Started to voxelize data...");
5479
using (ProgressBar progressbar = new ProgressBar())
5580
{
5681
for (int i = 0; i < data.BodyVertices.Count; i++)
5782
{
58-
float max = Math.Max(data.BodyVertices[i].X, Math.Max(data.BodyVertices[i].Y, data.BodyVertices[i].Z));
59-
if (max - min >= 0)
83+
float maxV = Math.Max(data.BodyVertices[i].X, Math.Max(data.BodyVertices[i].Y, data.BodyVertices[i].Z));
84+
if (maxV - min >= 0)
6085
{
6186
data.BodyVertices[i] -= new Vector3(min, min, min);
6287
mSchematic.AddVoxel((int)(data.BodyVertices[i].X - minX.X), (int)(data.BodyVertices[i].Y - minY.Y), (int)(data.BodyVertices[i].Z - minZ.Z), data.BodyColors[i].ColorToUInt());
@@ -86,7 +111,7 @@ protected void VoxelizeData(BodyDataDTO data)
86111
// }
87112
//}
88113
}
89-
114+
90115

91116
public override Schematic WriteSchematic()
92117
{
@@ -95,6 +120,6 @@ public override Schematic WriteSchematic()
95120
return schematic;
96121
}
97122

98-
123+
99124
}
100125
}

SchematicToVoxCore/Converter/SchematicToSchematic.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ namespace FileToVox.Converter
1111
{
1212
public class SchematicToSchematic : AbstractToSchematic
1313
{
14-
private readonly int mScale;
15-
1614
private readonly bool mExcavate;
1715
private readonly Dictionary<Tuple<int, int>, Color> mColors = new Dictionary<Tuple<int, int>, Color>();
1816

19-
public SchematicToSchematic(string path, bool excavate, float scale) : base(path)
17+
public SchematicToSchematic(string path, bool excavate) : base(path)
2018
{
21-
mScale = (int)scale;
2219
mExcavate = excavate;
2320
LoadBlocks();
2421
}
@@ -125,20 +122,17 @@ private Schematic CreateSchematic(RawSchematic rawSchematic)
125122
//Sorted by height (bottom to top) then length then width -- the index of the block at X,Y,Z is (Y×length + Z)×width + X.
126123
Schematic schematic = new Schematic();
127124

128-
int total = (rawSchematic.Heigth * mScale) * (rawSchematic.Length * mScale) * (rawSchematic.Width * mScale);
125+
int total = (rawSchematic.Heigth) * (rawSchematic.Length) * (rawSchematic.Width);
129126
int indexProgress = 0;
130127
using (ProgressBar progressbar = new ProgressBar())
131128
{
132-
for (int y = 0; y < (rawSchematic.Heigth * mScale); y++)
129+
for (int y = 0; y < (rawSchematic.Heigth); y++)
133130
{
134-
for (int z = 0; z < (rawSchematic.Length * mScale); z++)
131+
for (int z = 0; z < (rawSchematic.Length); z++)
135132
{
136-
for (int x = 0; x < (rawSchematic.Width * mScale); x++)
133+
for (int x = 0; x < (rawSchematic.Width); x++)
137134
{
138-
int yProgress = (y / mScale);
139-
int zProgress = (z / mScale);
140-
int xProgress = (x / mScale);
141-
int index = (yProgress * rawSchematic.Length + zProgress) * rawSchematic.Width + xProgress;
135+
int index = (y * rawSchematic.Length + z) * rawSchematic.Width + x;
142136
int blockId = rawSchematic.Blocks[index];
143137
if (blockId != 0)
144138
{

SchematicToVoxCore/FileToVox.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
99
<ApplicationIcon />
1010
<Authors>Zarbuz</Authors>
11-
<Version>1.12.6</Version>
11+
<Version>1.13</Version>
1212
<PackageProjectUrl>https://github.com/Zarbuz/FileToVox</PackageProjectUrl>
1313
<RepositoryUrl>https://github.com/Zarbuz/FileToVox</RepositoryUrl>
1414
</PropertyGroup>

SchematicToVoxCore/Program.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Program
2525
private static bool COLOR;
2626
private static bool MESH_SKIP_CAPTURE;
2727

28-
private static float SCALE = 1;
28+
private static float GRID_SIZE = 10;
2929
private static int HEIGHT_MAP = 1;
3030
private static int COLOR_LIMIT = 256;
3131
private static int MESH_SEGMENT_X = 4;
@@ -52,7 +52,7 @@ public static void Main(string[] args)
5252
{"msub|mesh-subsample=", "set the number of subsample (for MeshSampler)", (int v) => MESH_SUBSAMPLE = v},
5353
{"mskip", "skip the capturing points part and load the previous PLY (for MeshSampler)", v => MESH_SKIP_CAPTURE = v != null},
5454
{"p|palette=", "set the palette", v => INPUT_PALETTE_FILE = v },
55-
{"sc|scale=", "set the scale", (float v) => SCALE = v},
55+
{"gs|grid-size=", "set the grid-size", (float v) => GRID_SIZE = v},
5656
{"d|debug", "enable the debug mode", v => Schematic.DEBUG = v != null},
5757
};
5858

@@ -138,8 +138,8 @@ private static void CheckArguments()
138138
throw new ArgumentNullException("[ERROR] Missing required option: --i");
139139
if (OUTPUT_PATH == null)
140140
throw new ArgumentNullException("[ERROR] Missing required option: --o");
141-
if (SCALE <= 0)
142-
throw new ArgumentException("[ERROR] --scale argument must be positive");
141+
if (GRID_SIZE < 10 || GRID_SIZE > Schematic.MAX_WORLD_LENGTH)
142+
throw new ArgumentException("[ERROR] --grid-size argument must be greater than 10 and smaller than " + Schematic.MAX_WORLD_LENGTH);
143143
if (HEIGHT_MAP < 1)
144144
throw new ArgumentException("[ERROR] --heightmap argument must be positive");
145145
if (COLOR_LIMIT < 0 || COLOR_LIMIT > 256)
@@ -162,8 +162,8 @@ private static void DisplayArguments()
162162
Console.WriteLine("[INFO] Specified shaders file: " + INPUT_SHADER_FILE);
163163
if (COLOR_LIMIT != 256)
164164
Console.WriteLine("[INFO] Specified color limit: " + COLOR_LIMIT);
165-
if (SCALE != 1)
166-
Console.WriteLine("[INFO] Specified increase size: " + SCALE);
165+
if (GRID_SIZE != 10)
166+
Console.WriteLine("[INFO] Specified grid size: " + GRID_SIZE);
167167
if (Schematic.CHUNK_SIZE != 128)
168168
Console.WriteLine("[INFO] Specified chunk size: " + Schematic.CHUNK_SIZE);
169169
if (EXCAVATE)
@@ -247,26 +247,26 @@ private static AbstractToSchematic GetConverter(string path)
247247
case ".binvox":
248248
return new BinvoxToSchematic(path);
249249
case ".csv":
250-
return new CSVToSchematic(path, SCALE, COLOR_LIMIT);
250+
return new CSVToSchematic(path, GRID_SIZE, COLOR_LIMIT);
251251
case ".ply":
252-
return new PLYToSchematic(path, SCALE, COLOR_LIMIT);
252+
return new PLYToSchematic(path, GRID_SIZE, COLOR_LIMIT);
253253
case ".png":
254254
return new PNGToSchematic(path, INPUT_COLOR_FILE, HEIGHT_MAP, EXCAVATE, COLOR, COLOR_LIMIT);
255255
case ".qb":
256256
return new QBToSchematic(path);
257257
case ".schematic":
258-
return new SchematicToSchematic(path, EXCAVATE, SCALE);
258+
return new SchematicToSchematic(path, EXCAVATE);
259259
case ".tif":
260260
return new TIFtoSchematic(path, INPUT_COLOR_FILE, HEIGHT_MAP, EXCAVATE, COLOR, COLOR_LIMIT);
261261
case ".xyz":
262-
return new XYZToSchematic(path, SCALE, COLOR_LIMIT);
262+
return new XYZToSchematic(path, GRID_SIZE, COLOR_LIMIT);
263263
case ".json":
264264
return new JsonToSchematic(path);
265265
case ".vox":
266266
return new VoxToSchematic(path);
267267
case ".obj":
268268
case ".fbx":
269-
return new MeshToSchematic(path, SCALE, COLOR_LIMIT, MESH_SEGMENT_X, MESH_SEGMENT_Y, MESH_SUBSAMPLE, MESH_SKIP_CAPTURE);
269+
return new MeshToSchematic(path, GRID_SIZE, COLOR_LIMIT, MESH_SEGMENT_X, MESH_SEGMENT_Y, MESH_SUBSAMPLE, MESH_SKIP_CAPTURE);
270270
default:
271271
return null;
272272
}

0 commit comments

Comments
 (0)