GetPolygonPositions of an object created using MeshBooleanOperations.Union
Hello Andrej, 

Thank you so much for your help so far. I am finding my way around your excellent tool. I am using the following code to highlight objects on the MouseMove event. 

       private void HighlightObject(GeometryModel3D hitBoxModel3D)
           Point3DCollection polyPositions = MeshUtils.GetPolygonPositions(hitBoxModel3D);

           _multiLineVisual3D = new MultiLineVisual3D
               Positions = polyPositions,
               LineColor = Colors.Yellow,
               LineThickness = 5


It works great until the object is one generated using the MeshBooleanOperations.Union
               var testCore3D = new Ab3d.Meshes.TubeMesh3D(new Point3D(xpos + 26, ypos, zpos), new Vector3D(1, 0, 0), 6, 0, 3, 0, 13, 30);
               var conetest1 = testCore3D.Geometry;

               testCore3D = new Ab3d.Meshes.TubeMesh3D(new Point3D(xpos + 36, ypos, zpos), new Vector3D(1, 0, 0), 3, 0, 6, 0, 7, 30);
               var conetest2 = testCore3D.Geometry;

               //Lets try union to make core a single object
               var someOtherCore = Ab3d.Utilities.MeshBooleanOperations.Union(conetest1, conetest2);
               var modeltest3D = new GeometryModel3D(someOtherCore, material);
               modeltest3D.BackMaterial = material;
Before I used Union to join the 2, the individual TubeMesh objects were outlined with their yellow wire frame. Once I used Union to create a single object MeshUtils.GetPolygonPositions(hitBoxModel3D) now returns null. Is this expected? Am I doing something wrong? Can I make it work?

Using MeshUtils.GetPolygonPositions works only on models that have PolygonIndices property set. This is a custom property that is defined by the Ab3d.PowerToys library and defines the polygons that can also define the 3D model (all 3D models in WPF are defined by triangles that are needed for the graphics card - triangles are set by TriangleIndices; but some objects can be also created from polygons - for example box - and polygons better show the object when itis shown by the lines). Most of the 3D objects that are created by Ab3d.PowerToys library define the PolygonIndices. Also ReaderObj and Assimp importer set the PolygonIndices.

See more in the online help (or in the Ab3d.PowerToys help file):

But boolean objects do not have that, so you will need to get the triangles.

To get triangles use the following code:
// Get local accessors to prevent calling DependecyProperty getters in a loop
var triangleIndices = mesh.TriangleIndices;
var positions = mesh.Positions;

var triangleIndicesCount = triangleIndices.Count;

var polyPositions = new Point3DCollection();
for (var i = 0; i < triangleIndicesCount; i += 3)
    // Add 3 lines from one triangle
    polyPositions.Add(positions[triangleIndices[i + 1]]);

    polyPositions.Add(positions[triangleIndices[i + 1]]);
    polyPositions.Add(positions[triangleIndices[i + 2]]);

    polyPositions.Add(positions[triangleIndices[i + 2]]);
Andrej Benedik

Forum Jump:

Users browsing this thread:
1 Guest(s)