Open Alphamplyer opened 1 year ago
I think I've localized the mean to fix this problem. The following method is the root of the problem : https://github.com/Zarbuz/FileToVox/blob/master/SchematicToVoxCore/Converter/PointCloud/PointCloudToSchematic.cs#LL24C3-L114C1 I think you tried to change all vextex positions in order to remove all negative numbers, and then apply scale, etc ... but at the end of this function, vertex that wasn't at negative postion are now. So it cause the problem with the cast in the Schematic script.
I've fixe my problem by rewriting the VoxelizeData method in the PointCloudToSchematic method. I will not make a commit because I've add some other functionnalities that broke yours but here is my solution :
protected void VoxelizeData(BodyDataDTO data)
{
mSchematic = new Schematic();
if (data.BodyVertices.Count == 0)
{
return;
}
// The following part could be optimized by iterating through the BodyVertices array once
// to get the minimum and maximum of each axis
// Get the minimum of each axis
float minX = data.BodyVertices.MinBy(t => t.X).X;
float minY = data.BodyVertices.MinBy(t => t.Y).Y;
float minZ = data.BodyVertices.MinBy(t => t.Z).Z;
// Get the maximum of each axis
float maxX = data.BodyVertices.MaxBy(t => t.X).X;
float maxY = data.BodyVertices.MaxBy(t => t.Y).Y;
float maxZ = data.BodyVertices.MaxBy(t => t.Z).Z;
Console.WriteLine("[INFO] Min X: " + minX + ", Y: " + minY + ", " + minZ);
Vector3 size = new(maxX - minX, maxY - minY, maxZ - minZ);
Console.WriteLine("[INFO] Size X: " + size.X + ", Y: " + size.Y + ", " + size.Z);
Console.WriteLine("[INFO] Started to voxelize data...");
using (ProgressBar progressbar = new())
{
for (int i = 0; i < data.BodyVertices.Count; i++)
{
// substract axis of each vertex by the minimum of each axis
// in order to restrict them to positive number
int x = (int)(data.BodyVertices[i].X - minX);
int y = (int)(data.BodyVertices[i].Y - minY);
int z = (int)(data.BodyVertices[i].Z - minZ);
mSchematic.AddVoxel(
x,
y,
z,
data.BodyColors[i].ColorToUInt()
);
progressbar.Report(i / (float)data.BodyVertices.Count);
}
}
Console.WriteLine("[INFO] Done.");
}
Indeed, I broke the scale functionality because I didn't needed it. In any case, thx for this tool.
Hello,
I have this .ply file that I use for my study project. I lost its original file but I found your tool, hoping to solve my problem. When I've open the generated file I didn't saw any voxels. So I tried to investigate and I found the line that cause this issue : https://github.com/Zarbuz/FileToVoxCore/blob/735133e150d36052a758fdc92ab2374b7940a9c6/Schematics/Schematic.cs#LL333
The cast to ushort when x, y, or z are negative numbers, falsify everything.
Here is the file that cause the problem. I've just change the extension to .txt to be able to upload it, but it's a .ply file originaly. bomb.txt
I don't have currently more time to fix it, but I just wanted to let you know what I've found,