Fastest way to display Mesh Wires

Thanks.
The best explanation of the relationship between a topological and a mesh vertex I’ve found so far comes from @RIL in this post:

For anyone who is interested, here is a recursive method, I ended up using to find all mesh vertices and faces which fall within a radius of a given point:

public static void FindConnectedVertices(int mVertex)
        {
            Stack<int> verticesToCheck = new Stack<int>();
            HashSet<int> visitedTVertices = new HashSet<int>();

            // Local variables
            var _topologyVertices = Brush.initialMesh.TopologyVertices;
            var _meshVertices = Brush.mesh.Vertices;

            Point3d hitPoint = Brush.mesh.Vertices[mVertex];
            var tVertex = Brush.initialMesh.TopologyVertices.TopologyVertexIndex(mVertex);

            verticesToCheck.Push(tVertex);

            while (verticesToCheck.Count > 0)
            {
                var currentTVertex = verticesToCheck.Pop();
                if (visitedTVertices.Contains(currentTVertex))
                    continue;
                visitedTVertices.Add(currentTVertex);

                var mVertices = _topologyVertices.MeshVertexIndices(currentTVertex);
                var _point = _meshVertices[mVertices[0]];
                double distance = hitPoint.DistanceToSquared(_point);


                if (distance <= Brush.radiusSquared)
                {
                    foreach (var mV in mVertices) // One topology vertex can contain multiple mesh vertices. 
                    {
                        Brush.cursorVertices.Add(mV, _meshVertices[mV]);
                        Brush.cursorFaces.Add(mV, _topologyVertices.ConnectedFaces(currentTVertex));
                    }
                    var connectedTVertices = _topologyVertices.ConnectedTopologyVertices(currentTVertex);

                    foreach (var tV in connectedTVertices) // Mark connected topology vertices to check later
                        verticesToCheck.Push(tV);
                }
            }
        }

This way I can update normals of selected faces and vertices without recalculating these for the entire mesh. Now, I’m down to 15ms for each draw call of the 450k quad test mesh. That’s 66 FPS - more than enough to keep things interactive and so much faster than what I initially had.

EDIT: Replaced the recursive method with a while loop to prevent stack overflow exceptions.

2 Likes

To answer the original question: in my testing the by far fastest way to display Mesh Wires is to use OpenGL. We can reuse buffers used for drawing the shaded triangles and switch to line display. It’s also a good idea to slightly offset the wires along vertex normals to prevent Z-fighting.

Here is how the final result looks like:

5 Likes