6

I would like to display any MeshElement3D (for example BoxVisual3d) in helix-toolkit as wireframe. How can this be accomplished?

EDIT:

Thanks to Erno de Weerd's answer I was able to write the following code

  1. Class that extends BoxVisual3D

    public class GeometryBoxVisual3D : BoxVisual3D
    {
    
      public MeshGeometry3D Geometry()
      {
        return Tessellate();
      }
    }
    
  2. Add the instance of box to the Viewport:

        GeometryBoxVisual3D box = new GeometryBoxVisual3D();
        box.Fill = new SolidColorBrush(Colors.Red);
        Viewport3D.Children.Add(box);
        MeshGeometry3D geometry3 = box.Geometry();
        LinesVisual3D lines = new LinesVisual3D();
        lines.Thickness = 3;
        lines.Points = geometry3.Positions;
        lines.Transform = new TranslateTransform3D(3,1,1);
        Viewport3D.Children.Add(lines);
    

This results in the following display:

enter image description here

If I hide the original box and place LinesVisual3D on top of the box, I can get the wirefrime displayed as if it was original object, but it is still missing the edges on the side.

Dan
  • 11,077
  • 20
  • 84
  • 119

1 Answers1

6

By calling MeshElement3D.Tesselate() you can get the MeshGeometry3D (mesh).

Next create a LinesVisual3D object.

Copy the Points of the mesh to the Points of the LinesVisual3D.

This will create the internal mesh (see the sources: LinesVisual3D.cs in helix toolkit)

Finally, make sure you set the thickness of the LinesVisual3D and add it to the scene.

DIF
  • 2,470
  • 6
  • 35
  • 49
Emond
  • 50,210
  • 11
  • 84
  • 115
  • thank you. A few questions: 1. Tesselate method is protected in MeshElement, does this mean I necessarily need to extend BoxVisual3d? 2. When I extend BoxVisual3d and use Tesselate on it to obtain positions for LinesVisual3D and I display it, I get only to top squares displayed, but not the whole wireframe. How can I create the complete wireframe, including the lines on the side? – Dan Feb 23 '15 at 15:30
  • 1. Yes it appears to be the only way to get the mesh. 2. There might be bugs in the tesselation code or the algorithm accounts for backface culling. Just print out the points and check by hand. – Emond Feb 23 '15 at 20:45
  • @Dan - the reason you see only a part of the faces is that the Positions collection in general contains each point only once. The Indices collection contains the relationship between these points to create the triangles. So you need to loop through the indices (the first 3 are the indices of the points of the first triangle) and add all the sides of all the triangles to the Points collection. Let me know if you need help – Emond Feb 28 '15 at 06:33