Dear Jeremy, Thanks for the prompt response! I did some research today and found out that TessellatedShapeBuilder.Addface() does not work correctly if the specified points in TessellatedFace do not lie in the same plane, and TessellatedShapeBuilder tries to fix this by approximating the points.

To fix this, I wrote an Extension method that allows you to add geometry to the DirectShape in which this case is handled. If more than three points came to the input, several separate surfaces consisting of separate triangles are created. It's working! Yesterday I wanted to send a PR to the Dev branch in your repository (thanks for creating it so quickly!), but now I think it will be enough to post this extension method just here. Thank you for your time!
/// <summary>
/// Create mesh-geometry in this DirectShape from obj-file.
/// </summary>
/// <param name="ds"></param>
/// <param name="pathObj">The Absolute Path</param>
public static void SetShape(this DirectShape ds, string pathObj)
{
Scene scene = new ObjFileFormat().LoadData(pathObj);
foreach (var children in scene.SceneContainer.Children)
{
var builder = new TessellatedShapeBuilder
{
LogString = children.Name
};
builder.OpenConnectedFaceSet(false);
if (children is Polygon polygon)
{
List<XYZ> vertices = new List<XYZ>();
foreach (var v in polygon.Vertices)
{
vertices.Add(new XYZ(v.X, v.Z, v.Y));
}
List<List<int>> indicesCollect = new List<List<int>>();
foreach (var face in polygon.Faces)
{
builder.AddFace(
new TessellatedFace(
new List<XYZ>
{
vertices[face.Indices[0].Vertex],
vertices[face.Indices[1].Vertex],
vertices[face.Indices[2].Vertex]
},
ElementId.InvalidElementId));
if (face.Indices.Count > 3)
{
for (int i = 2; i < face.Indices.Count && i + 1 < face.Indices.Count; i++)
{
builder.AddFace(
new TessellatedFace(
new List<XYZ>
{
vertices[face.Indices[0].Vertex],
vertices[face.Indices[i].Vertex],
vertices[face.Indices[i+1].Vertex]
},
ElementId.InvalidElementId)
);
}
}
}
}
builder.CloseConnectedFaceSet();
builder.Target = TessellatedShapeBuilderTarget.AnyGeometry;
builder.Fallback = TessellatedShapeBuilderFallback.Mesh;
builder.Build();
if (builder != null)
{
var result = builder.GetBuildResult();
var objects = result.GetGeometricalObjects();
ds.SetShape(objects);
ds.Name = builder.LogString;
}
}
}
Result now:
