diff --git a/SchematicToVoxCore/Converter/PointCloud/PointCloudToSchematic.cs b/SchematicToVoxCore/Converter/PointCloud/PointCloudToSchematic.cs index 05fd57e..1f64608 100644 --- a/SchematicToVoxCore/Converter/PointCloud/PointCloudToSchematic.cs +++ b/SchematicToVoxCore/Converter/PointCloud/PointCloudToSchematic.cs @@ -5,6 +5,7 @@ using MoreLinq; using System; using System.Collections.Generic; +using System.Diagnostics; namespace FileToVox.Converter.PointCloud { @@ -39,15 +40,39 @@ protected void VoxelizeData(BodyDataDTO data) for (int i = 0; i < data.BodyVertices.Count; i++) { data.BodyVertices[i] += new Vector3(min, min, min); - 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)); + //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)); } - //HashSet set = new HashSet(); + Vector3 maxX = data.BodyVertices.MaxBy(t => t.X); + Vector3 maxY = data.BodyVertices.MaxBy(t => t.Y); + Vector3 maxZ = data.BodyVertices.MaxBy(t => t.Z); + + Console.WriteLine("[INFO] Max X: " + maxX.X + ", Y: " + maxY.Y + ", " + maxZ.Z); + + minX = data.BodyVertices.MinBy(t => t.X); + minY = data.BodyVertices.MinBy(t => t.Y); + minZ = data.BodyVertices.MinBy(t => t.Z); + + Console.WriteLine("[INFO] Min X: " + minX.X + ", Y: " + minY.Y + ", " + minZ.Z); + + Vector3 size = new Vector3(maxX.X - minX.X, maxY.Y - minY.Y, maxZ.Z - minZ.Z); + + Console.WriteLine("[INFO] Size X: " + size.X + ", Y: " + size.Y + ", " + size.Z); + + float max = Math.Max(size.X, Math.Max(size.Y, size.Z)); + float factor = Scale / max; + + for (int i = 0; i < data.BodyVertices.Count; i++) + { + 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)); + } minX = data.BodyVertices.MinBy(t => t.X); minY = data.BodyVertices.MinBy(t => t.Y); minZ = data.BodyVertices.MinBy(t => t.Z); + //HashSet set = new HashSet(); + min = Math.Min(minX.X, Math.Min(minY.Y, minZ.Z)); Console.WriteLine("[INFO] Started to voxelize data..."); @@ -55,8 +80,8 @@ protected void VoxelizeData(BodyDataDTO data) { for (int i = 0; i < data.BodyVertices.Count; i++) { - float max = Math.Max(data.BodyVertices[i].X, Math.Max(data.BodyVertices[i].Y, data.BodyVertices[i].Z)); - if (max - min >= 0) + float maxV = Math.Max(data.BodyVertices[i].X, Math.Max(data.BodyVertices[i].Y, data.BodyVertices[i].Z)); + if (maxV - min >= 0) { data.BodyVertices[i] -= new Vector3(min, min, min); 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) // } //} } - + public override Schematic WriteSchematic() { @@ -95,6 +120,6 @@ public override Schematic WriteSchematic() return schematic; } - + } } diff --git a/SchematicToVoxCore/Converter/SchematicToSchematic.cs b/SchematicToVoxCore/Converter/SchematicToSchematic.cs index 3158818..3a3255c 100644 --- a/SchematicToVoxCore/Converter/SchematicToSchematic.cs +++ b/SchematicToVoxCore/Converter/SchematicToSchematic.cs @@ -11,14 +11,11 @@ namespace FileToVox.Converter { public class SchematicToSchematic : AbstractToSchematic { - private readonly int mScale; - private readonly bool mExcavate; private readonly Dictionary, Color> mColors = new Dictionary, Color>(); - public SchematicToSchematic(string path, bool excavate, float scale) : base(path) + public SchematicToSchematic(string path, bool excavate) : base(path) { - mScale = (int)scale; mExcavate = excavate; LoadBlocks(); } @@ -125,20 +122,17 @@ private Schematic CreateSchematic(RawSchematic rawSchematic) //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. Schematic schematic = new Schematic(); - int total = (rawSchematic.Heigth * mScale) * (rawSchematic.Length * mScale) * (rawSchematic.Width * mScale); + int total = (rawSchematic.Heigth) * (rawSchematic.Length) * (rawSchematic.Width); int indexProgress = 0; using (ProgressBar progressbar = new ProgressBar()) { - for (int y = 0; y < (rawSchematic.Heigth * mScale); y++) + for (int y = 0; y < (rawSchematic.Heigth); y++) { - for (int z = 0; z < (rawSchematic.Length * mScale); z++) + for (int z = 0; z < (rawSchematic.Length); z++) { - for (int x = 0; x < (rawSchematic.Width * mScale); x++) + for (int x = 0; x < (rawSchematic.Width); x++) { - int yProgress = (y / mScale); - int zProgress = (z / mScale); - int xProgress = (x / mScale); - int index = (yProgress * rawSchematic.Length + zProgress) * rawSchematic.Width + xProgress; + int index = (y * rawSchematic.Length + z) * rawSchematic.Width + x; int blockId = rawSchematic.Blocks[index]; if (blockId != 0) { diff --git a/SchematicToVoxCore/FileToVox.csproj b/SchematicToVoxCore/FileToVox.csproj index 00ce6de..bff53c2 100644 --- a/SchematicToVoxCore/FileToVox.csproj +++ b/SchematicToVoxCore/FileToVox.csproj @@ -8,7 +8,7 @@ win-x64;linux-x64;osx-x64 Zarbuz - 1.12.6 + 1.13 https://github.com/Zarbuz/FileToVox https://github.com/Zarbuz/FileToVox diff --git a/SchematicToVoxCore/Program.cs b/SchematicToVoxCore/Program.cs index 3319517..851b68e 100644 --- a/SchematicToVoxCore/Program.cs +++ b/SchematicToVoxCore/Program.cs @@ -25,7 +25,7 @@ class Program private static bool COLOR; private static bool MESH_SKIP_CAPTURE; - private static float SCALE = 1; + private static float GRID_SIZE = 10; private static int HEIGHT_MAP = 1; private static int COLOR_LIMIT = 256; private static int MESH_SEGMENT_X = 4; @@ -52,7 +52,7 @@ public static void Main(string[] args) {"msub|mesh-subsample=", "set the number of subsample (for MeshSampler)", (int v) => MESH_SUBSAMPLE = v}, {"mskip", "skip the capturing points part and load the previous PLY (for MeshSampler)", v => MESH_SKIP_CAPTURE = v != null}, {"p|palette=", "set the palette", v => INPUT_PALETTE_FILE = v }, - {"sc|scale=", "set the scale", (float v) => SCALE = v}, + {"gs|grid-size=", "set the grid-size", (float v) => GRID_SIZE = v}, {"d|debug", "enable the debug mode", v => Schematic.DEBUG = v != null}, }; @@ -138,8 +138,8 @@ private static void CheckArguments() throw new ArgumentNullException("[ERROR] Missing required option: --i"); if (OUTPUT_PATH == null) throw new ArgumentNullException("[ERROR] Missing required option: --o"); - if (SCALE <= 0) - throw new ArgumentException("[ERROR] --scale argument must be positive"); + if (GRID_SIZE < 10 || GRID_SIZE > Schematic.MAX_WORLD_LENGTH) + throw new ArgumentException("[ERROR] --grid-size argument must be greater than 10 and smaller than " + Schematic.MAX_WORLD_LENGTH); if (HEIGHT_MAP < 1) throw new ArgumentException("[ERROR] --heightmap argument must be positive"); if (COLOR_LIMIT < 0 || COLOR_LIMIT > 256) @@ -162,8 +162,8 @@ private static void DisplayArguments() Console.WriteLine("[INFO] Specified shaders file: " + INPUT_SHADER_FILE); if (COLOR_LIMIT != 256) Console.WriteLine("[INFO] Specified color limit: " + COLOR_LIMIT); - if (SCALE != 1) - Console.WriteLine("[INFO] Specified increase size: " + SCALE); + if (GRID_SIZE != 10) + Console.WriteLine("[INFO] Specified grid size: " + GRID_SIZE); if (Schematic.CHUNK_SIZE != 128) Console.WriteLine("[INFO] Specified chunk size: " + Schematic.CHUNK_SIZE); if (EXCAVATE) @@ -247,26 +247,26 @@ private static AbstractToSchematic GetConverter(string path) case ".binvox": return new BinvoxToSchematic(path); case ".csv": - return new CSVToSchematic(path, SCALE, COLOR_LIMIT); + return new CSVToSchematic(path, GRID_SIZE, COLOR_LIMIT); case ".ply": - return new PLYToSchematic(path, SCALE, COLOR_LIMIT); + return new PLYToSchematic(path, GRID_SIZE, COLOR_LIMIT); case ".png": return new PNGToSchematic(path, INPUT_COLOR_FILE, HEIGHT_MAP, EXCAVATE, COLOR, COLOR_LIMIT); case ".qb": return new QBToSchematic(path); case ".schematic": - return new SchematicToSchematic(path, EXCAVATE, SCALE); + return new SchematicToSchematic(path, EXCAVATE); case ".tif": return new TIFtoSchematic(path, INPUT_COLOR_FILE, HEIGHT_MAP, EXCAVATE, COLOR, COLOR_LIMIT); case ".xyz": - return new XYZToSchematic(path, SCALE, COLOR_LIMIT); + return new XYZToSchematic(path, GRID_SIZE, COLOR_LIMIT); case ".json": return new JsonToSchematic(path); case ".vox": return new VoxToSchematic(path); case ".obj": case ".fbx": - return new MeshToSchematic(path, SCALE, COLOR_LIMIT, MESH_SEGMENT_X, MESH_SEGMENT_Y, MESH_SUBSAMPLE, MESH_SKIP_CAPTURE); + return new MeshToSchematic(path, GRID_SIZE, COLOR_LIMIT, MESH_SEGMENT_X, MESH_SEGMENT_Y, MESH_SUBSAMPLE, MESH_SKIP_CAPTURE); default: return null; }