I'm currently using this CSG library to subtract two solids. I chose this particular library in order to work with the .NET Framework 4.5 dependency of my project. My goal is to be able to successfully use boolean operations on two concave solids. However, when I subtract two solids, the function leaves behind some of the vertices of the subtracting shape.
Below is an example of what the subtracted image should look like, rendered in 3d: Correct Solid Subtraction
Instead, the function yields something like this: Failed Solid Subtraction
You can see that some of the vertices have been left above the subtracted solid, which causes issues in rendering, and in further operations. I've opened a GitHub issue on the repository here, and I've also created a failing unit test using NUnit.Framework
, which reads points from a .json
file (contents below):
[Test]
public void CoplanarConcave ()
{
using StreamReader r = new StreamReader ("TestCase.json");
string json = r.ReadToEnd ();
List<List<List<double>>> items = JsonConvert.DeserializeObject<List<List<List<double>>>> (json);
var vectorList = items.Select (doublesList =>
doublesList.Select (doubles => new Vector3D (doubles[0], doubles[1], doubles[2])).ToList ()).ToList ();
var texture = new Vector2D (0, 0);
var vertices = vectorList.Select (vertex => vertex.Select (vector => new Vertex (vector, texture)).ToList ())
.ToList ();
var polyArray = vertices.Select (vertex => new Polygon (vertex)).ToList ();
var solid = Solid.FromPolygons (polyArray);
var testSolid = solid.Translate (0, 0, 10);
var result = solid.Substract (testSolid);
var badPolygons =
result.Polygons.Where (polygon => polygon.Vertices.Any (vertex => vertex.Pos.Z >= 217.125));
Assert.IsEmpty (badPolygons);
}
[[[744.585, 734.575, 97.125],
[1062.208, 734.575, 97.125],
[1062.208, 276.028, 97.125],
[889.654, 276.028, 97.125],
[889.654, 504.099, 97.125],
[744.585, 504.099, 97.125]],
[[744.585, 734.575, 1297.125],
[1062.208, 734.575, 1297.125],
[1062.208, 734.575, 97.125],
[744.585, 734.575, 97.125]],
[[1062.208, 734.575, 1297.125],
[1062.208, 276.028, 1297.125],
[1062.208, 276.028, 97.125],
[1062.208, 734.575, 97.125]],
[[1062.208, 276.028, 1297.125],
[889.654, 276.028, 1297.125],
[889.654, 276.028, 97.125],
[1062.208, 276.028, 97.125]],
[[889.654, 276.028, 1297.125],
[889.654, 504.099, 1297.125],
[889.654, 504.099, 97.125],
[889.654, 276.028, 97.125]],
[[889.654, 504.099, 1297.125],
[744.585, 504.099, 1297.125],
[744.585, 504.099, 97.125],
[889.654, 504.099, 97.125]],
[[744.585, 504.099, 1297.125],
[744.585, 734.575, 1297.125],
[744.585, 734.575, 97.125],
[744.585, 504.099, 97.125]],
[[744.585, 734.575, 1297.125],
[744.585, 504.099, 1297.125],
[889.654, 504.099, 1297.125],
[889.654, 276.028, 1297.125],
[1062.208, 276.028, 1297.125],
[1062.208, 734.575, 1297.125]]]
What is the issue here? Is there a better solid geometry library that I could be using?