TessellatedShapeBuilder creates a Mesh with Slits

TessellatedShapeBuilder creates a Mesh with Slits

ankofl
Advocate Advocate
499 Views
4 Replies
Message 1 of 5

TessellatedShapeBuilder creates a Mesh with Slits

ankofl
Advocate
Advocate

Used in DirectObjLoader FileFormatWavefront according to the author's own assurance outdated, so I created a fork of DirectObjLoader and added two classes there:
MyCommand and MyUtil with the load implementation.obj file by SharpGL.Serialization as the author advised, and it works great!

edge3.jpg edge1.jpg

The loaded grid is match perfectly, as can be seen thanks to using ModelCurve, but the DirectShape created on the basis of these surfaces via TessellatedShapeBuilder has lots of gaps.
@jeremytammik  How can I fix this?
Thanks!

0 Likes
500 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Interesting error. It looks as if each face has been slightly and systematically tilted. That looks like a programming error to me. How big are the gaps? I suggest creating a lookup dictionary of all the face corners. Every time a new face is added with a vertex close to an already existing face vertex, reuse the existing vertex instead of adding a (possibly slightly offset) new one.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 5

ankofl
Advocate
Advocate

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.

error.jpg
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:

фыва.jpg

Message 4 of 5

jeremy_tammik
Alumni
Alumni

Well done! Nice solution. I suppose it only works in the special case, in which the > 3 face vertices come in a suitable order to create nice triangles from them? Wishing you a happy weekend!

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 5

jeremy_tammik
Alumni
Alumni

Could you create a pull request to share your migration to an newer release of Revit plus your handler for the slits?

  

Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes