Cloning a mesh isn't the only way to enhance an existing mesh. Meshes can also be optimized in multiple ways. The Optimize function on a mesh is similar to the clone method, in that it can generate a new mesh with different options; however it can also perform optimizations during the generation of this new mesh. You cannot use the Optimize function to add or remove vertex data or clone to a new device though. Look at the main overload for the Optimize method: public Microsoft.DirectX.Direct3D.Mesh Optimize ( Microsoft.DirectX.Direct3D.MeshFlags flags , int[] adjacencyIn , out int[] adjacencyOut , out int[] faceRemap , out Microsoft.DirectX.Direct3D.GraphicsStream vertexRemap ) Each of the four overloads for this method takes this set of arguments, or simply the flags and adjacency in information. Note, that the adjacencyIn parameter can be used as an array of integers (as shown above), or as a GraphicsStream. The flags parameter is used to determine how the new mesh can be created. This member can be one or more flags from the MeshFlags enumeration (excluding the Use32Bit or the WriteOnly flags). However, there are numerous Optimize flags in this enumeration that can be used specifically for this function. See Table 7.1:
The adjacencyIn parameter is also required, and can either be an integer array containing three integers per face that specify the three neighbors for each face in the mesh, or a graphics stream containing this same data.
If you choose one of the two overloads that has more than those two overloads, the last three parameters are all data that will be returned to you via an out parameter. The first member of this returned data will be the new adjacency information returned to you. The second member will be the new index for each face in the mesh. The final member will be a graphics stream that contains the new index for each vertex. Many applications will not require this information, and can skip using these overloads. The following small section of code shows sorting a mesh by its attribute buffer, and ensuring that it is in managed memory: // Compact our mesh Mesh tempMesh = mesh.Optimize (MeshFlags.Managed | MeshFlags.OptimizeAttrSort | MeshFlags.OptimizeDoNotSplit, adj); mesh.Dispose(); mesh = tempMesh;
|