Frustum mesh area non-manifold

When I create hundreds of nodes using a frustum mesh, my STL file has non-manifold areas. I used Meshmixer by Autodesk to repair them, and some of the features of my object disappeared. When it’s finished there are 5 areas that cannot be repaired.

I have pasted some of the code below, the rest is in a private repository on GitHub. I will add collaborators on the repository by request.

The input json file and the resulting STL file are attached.
MandelbrotFrustum.zip (232.4 KB)

Several days ago I generated an STL file using a similar method, and there were no errors in the STL file. Why when I repeat the process hundreds of times are so many areas non-manifold in the STL file? How do I save the STL with all my features and with no non-manifold areas?

// <summary>
/// Generate a Frustum mesh. Base is 2.5 x 2.5 top is 1 x 1 height is 1.
/// </summary>
/// <returns>mesh</returns>
internal static Mesh GenerateFrustumMesh()
{
    var near = -1;
    var nx = 0.5;
    var ny = 0.5;
    var far = 0;
    var fx = 1.25;
    var fy = 1.25;
    var mesh = new Mesh();

    //control points of near plane corners
    mesh.ControlPoints.Add(new Vector4(nx, ny, near));
    mesh.ControlPoints.Add(new Vector4(-nx, ny, near));
    mesh.ControlPoints.Add(new Vector4(-nx, -ny, near));
    mesh.ControlPoints.Add(new Vector4(nx, -ny, near));

    //control points of far plane corners
    mesh.ControlPoints.Add(new Vector4(fx, fy, far));
    mesh.ControlPoints.Add(new Vector4(-fx, fy, far));
    mesh.ControlPoints.Add(new Vector4(-fx, -fy, far));
    mesh.ControlPoints.Add(new Vector4(fx, -fy, far));

    mesh.CreatePolygon(0, 1, 2, 3);//near plane
    mesh.CreatePolygon(4, 5, 6, 7);//far plane
    mesh.CreatePolygon(0, 4, 5, 1);//top plane
    mesh.CreatePolygon(3, 2, 6, 7);//bottom plane
    mesh.CreatePolygon(1, 5, 6, 2);//left plane
    mesh.CreatePolygon(0, 3, 7, 4);//right plane

    return mesh;
}


var scene = new Scene();
var box = new Box();
var cutterDimensions = new SizeD(60.0, 50.0);
var cutterMargin = new SizeD(3, 3);

// "cutter" base
var tr = scene.RootNode.CreateChildNode(box).Transform;
tr.Scale = new Vector3(cutterDimensions.Width, cutterDimensions.Height, 6);

// fits in holder slot
tr = scene.RootNode.CreateChildNode(box).Transform;
tr.Scale = new Vector3(cutterDimensions.Width, 2, 2);
var objZ = 6 / -2.0 + 2 / 2.0;

tr.Translation = new Vector3(0, (cutterDimensions.Height / 2.0) + 1, objZ);

// fits in holder slot
tr = scene.RootNode.CreateChildNode(box).Transform;
tr.Scale = new Vector3(cutterDimensions.Width, 2, 2);
tr.Translation = new Vector3(0, (cutterDimensions.Height / -2.0) - 1, objZ);

// mandelbrot design base
tr = scene.RootNode.CreateChildNode(box).Transform;
tr.Scale = new Vector3(cutterDimensions.Width + cutterMargin.Width, cutterDimensions.Height + cutterMargin.Height, 2);
tr.Translation = new Vector3(0, 0, 4);

SetScaleMapping();

var initialX = ((cutterDimensions.Width + cutterMargin.Width) / -2.0) + (_request.PinDimension / 2.0) + (cutterMargin.Width / 2.0);
var designZBase = 6 / 2.0 + 2 / 2.0 + 2 / 2.0;
var x = initialX;
var y = ((cutterDimensions.Height + cutterMargin.Height) / -2.0) + (_request.PinDimension / 2.0) + (cutterMargin.Height / 2.0);
var frustumMesh = Helper.GenerateFrustumMesh();
var fid = 0;

foreach (var row in _request.PointIterations)
{
    foreach (var i in row)
    {
        var node = scene.RootNode.CreateChildNode($"frustum{fid++}", frustumMesh);
        tr = node.Transform;

        var z = (_scaleM * i) + _scaleB;
        tr.Scale = new Vector3(_request.PinDimension, _request.PinDimension, z);
        tr.Translation = new Vector3(x, y, designZBase);
        tr.Rotation = Quaternion.FromEulerAngle(Math.PI, 0, 0);

        x += _request.PinDimension;
    }
    x = initialX;
    y += _request.PinDimension;
}

var outputPath = Helper.GetOutputPath(_inputPath, ".stl");
scene.Save(outputPath, FileFormat.STLASCII);

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): THREEDNET-1327

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@ssides0123
It is possible to use Mesh.DoBoolean to merge manifold meshes into one manifold mesh and use Mesh.Optimize to remove duplicated vertices now.