Another way to simplify vertices with much less control, but at a much higher speed, is to weld similar vertices together. There is a method on the mesh class, "WeldVertices", that can be used to weld together vertices that are replicated and have equal attribute values. The method prototypes contain the following: public void WeldVertices ( Microsoft.DirectX.Direct3D.WeldEpsilonsFlags flags , Microsoft.DirectX.Direct3D.WeldEpsilons epsilons , Microsoft.DirectX.Direct3D.GraphicsStream adjacencyIn , Microsoft.DirectX.Direct3D.GraphicsStream adjacencyOut , out int[] faceRemap , Microsoft.DirectX.Direct3D.GraphicsStream vertexRemap ) The last four parameters have already been discussed at length, so we won't delve into those here once more. They are the same as they were in the clean function we've discussed previously. The first two parameters, however, control how the various vertices are welded together. The first parameter can be one or more of the values found in Table 7.2:
The WeldEpsilons structure itself is strikingly similar to the AttributeWeights structure used for simplifying a mesh. The only difference is there is a new member for this structure that controls the tessellation factor. Tessellating a mesh is the act of changing the level of detail in the model by either removing triangles, or splitting a single triangle into two or more smaller triangles. All other members remain the same. To show the effect of using this method, we'll once again modify the existing MeshFile example to weld its vertices together. Since this is really only one call that operates in place, there isn't much code we will need to add. The first time a key is pressed we will do the weld, so replace the OnKeyPress method with the following: protected override void OnKeyPress(KeyPressEventArgs e) { Console.WriteLine("Before: {0}", mesh.NumberVertices); mesh.WeldVertices(WeldEpsilonsFlags.WeldAll, new WeldEpsilons(), null, null); Console.WriteLine("After: {0}", mesh.NumberVertices); } Running the example now and pressing the space bar will result in the following text output: Before: 4432 After: 3422 Not quite the 91% reduction we got when simplifying, but it was much faster than before. However, did you notice how the texture coordinates changed when you hit the space bar? This was caused by the removal of some of the vertices in that area. Up close, it's quite noticeable, but at a distance, once again, it's hardly obvious unless you're looking for it.
|