Mesh.ToPolySurface node produces a faulty polysurface (some triangles are missing)

Hello all,

I am trying to create a script which creates a civil3d tinsurface from a .2dm mesh file. The 2dm file offers only the vertices positions and the faces indices (faces could be made of 3 or 4 points).

I managed to create the script which does the following:

  1. Read the file, get the points and the indices (IndexGroups)
  2. Create a Mesh.ByPointsFaceIndices
  3. Convert the mesh to a polysurface (Mesh.ToPolySurface)
  4. create perimeter curves (Surface.PerimeterCurves)
  5. Group these curves because the mesh has internal holes. So I need to have external boundary (Outer) and internal boundaries (Hide).
  6. Create the TinSurface, create the polylines → Add those polylines to the surface and Done!

This script works fine for a .2dm file with about 100k faces but with bigger and more complicated meshes, it takes forever and never finishes execution. I did some digging and I think know where the problem is. The problem is with the node “Mesh.ToPolySurface”. The node sometimes produce a faulty Polysurface where it ignores some of the original mesh triangles because it fails to combine them. This results in so many empty triangles (holes) which makes the execution time for the following node (Group Curves) much higher due to the number of lines produced as polysurface perimeters.

The selected node is “Mesh.ToPolySurface”. The grey shows where the triangles are missing.

This will result in a very high number of curves which I am guessing making the task for the next node to be very difficult.

I am attaching the script and a sample file from the ones causing me trouble.

I am running in circles now and any advice or suggestion would be great!.

Thanks in advance.

P.S: I tried the following:

  1. I managed to extract the boundaries in QGIS easily and bring them to Dynamo but this is not optimal because I would like to do the whole thing in Dynamo only.
  2. I tried all the algorithms to find a Convex Hull of a set of points but none of them give the internal holes. Also the resulting outer boundary is far from accurate.
  3. I tried moving the points closer to null point but the problem was the same, the new polysurface had some triangles missing.
  4. I tried to group the points according to the indices and then create many surfaces from them. This worked but joining the surfaces into one polysurface did not work and it took so much time before it failed. If I make Dynamo geometry scale extra large, it gives me the error “points are coincident”, if I leave the scale to medium, it simply does not return anything.

I am attaching the script I made and two .2dm test files. One is working (no problem.2dm) and one is not working (problem.2dm).

https://drive.google.com/drive/folders/15h9m7wFzbRPPnoqRhTtQUhdoD_zHxxsz?usp=sharing

DGMFrom2dm_DynamoForum.dyn (70.2 KB)