gradientspace / geometry3Sharp

C# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.
http://www.gradientspace.com
Boost Software License 1.0
1.72k stars 390 forks source link

DMesh3Builder ignoring two triangles #104

Open Andreas-Moegelmose opened 5 years ago

Andreas-Moegelmose commented 5 years ago

For a unit test, I'm trying to make a simple cross shaped mesh. It consists of 8 triangles. However, even though I define all of them in my list of triangles for DMesh3Builder, two of them disappear.

Here are a couple of pictures of the resulting shape, with the two triangles clearly missing: https://imgur.com/a/m8UzUwT

I'm running this code:

public class BuilderTest
{
    [TestMethod]
    public void BuildCross()
    {
        var vertices = new List<Vector3f>
        {
            new Vector3f(0, 0, 0),
            new Vector3f(1000, 0, 0),
            new Vector3f(1000, 200, 0),
            new Vector3f(0, 200, 0),
            new Vector3f(1000, 0, 200),
            new Vector3f(0, 0, 200),
            new Vector3f(1000, 0, -200),
            new Vector3f(0, 0, -200),
            new Vector3f(1000, -200, 0),
            new Vector3f(0, -200, 0)
        };

        var triangles = new List<Index3i>
        {
            new Index3i(0, 1, 2),
            new Index3i(0, 2, 3),
            new Index3i(0, 4, 1),
            new Index3i(0, 5, 4),
            new Index3i(0, 1, 6), // Does not show
            new Index3i(0, 6, 7),
            new Index3i(0, 8, 1), // Does not show
            new Index3i(0, 9, 8)
        };

        var input = DMesh3Builder.Build<Vector3f, Index3i, Vector3f>(vertices, triangles);

        Console.WriteLine("Number of triangles: {0}", input.TriangleCount); // Outputs 6, should be 8.

        /*var writeOptions = WriteOptions.Defaults;
        writeOptions.bWriteBinary = true;
        StandardMeshWriter.WriteFile(@"C:\cross.stl", new List<WriteMesh>() { new WriteMesh(input) }, writeOptions);*/
    }
}

When I save the stl-file and inspect that, the two triangles are missing. However, if I move those particular triangles up higher in the triangles-list, they show, and two others.

Am I doing something wrong, or is there a bug in DMesh3Builder?

Thanks!

CBenghi commented 4 years ago

Hi, I've been playing with this library and the issues here depend on the manifold constraints that are enforced by default.

You can have a look at resolving this by using a DMesh3Builder instance instead, see: https://github.com/CBenghi/geometry3SharpDemos/commit/1df3ddb89659051e1a4f27b465bf919253c869af

The resulting mesh looks like the following: image

Best, Claudio