Skip to content

Commit

Permalink
Merge branch 'feature/scale_rework'
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarbuz committed Sep 17, 2021
2 parents a2c8302 + db45f2a commit da2d5a1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
37 changes: 31 additions & 6 deletions SchematicToVoxCore/Converter/PointCloud/PointCloudToSchematic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MoreLinq;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace FileToVox.Converter.PointCloud
{
Expand Down Expand Up @@ -39,24 +40,48 @@ 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<Vector3> set = new HashSet<Vector3>();
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<Vector3> set = new HashSet<Vector3>();

min = Math.Min(minX.X, Math.Min(minY.Y, minZ.Z));

Console.WriteLine("[INFO] Started to voxelize data...");
using (ProgressBar progressbar = new ProgressBar())
{
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());
Expand Down Expand Up @@ -86,7 +111,7 @@ protected void VoxelizeData(BodyDataDTO data)
// }
//}
}


public override Schematic WriteSchematic()
{
Expand All @@ -95,6 +120,6 @@ public override Schematic WriteSchematic()
return schematic;
}


}
}
18 changes: 6 additions & 12 deletions SchematicToVoxCore/Converter/SchematicToSchematic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ namespace FileToVox.Converter
{
public class SchematicToSchematic : AbstractToSchematic
{
private readonly int mScale;

private readonly bool mExcavate;
private readonly Dictionary<Tuple<int, int>, Color> mColors = new Dictionary<Tuple<int, int>, 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();
}
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion SchematicToVoxCore/FileToVox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<ApplicationIcon />
<Authors>Zarbuz</Authors>
<Version>1.12.6</Version>
<Version>1.13</Version>
<PackageProjectUrl>https://github.com/Zarbuz/FileToVox</PackageProjectUrl>
<RepositoryUrl>https://github.com/Zarbuz/FileToVox</RepositoryUrl>
</PropertyGroup>
Expand Down
22 changes: 11 additions & 11 deletions SchematicToVoxCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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},
};

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit da2d5a1

Please sign in to comment.