This ProgressiveMesh sample shows how an application can use the D3DX progressive mesh functionality to simplify meshes for faster rendering. A progressive mesh is a specialized mesh object that can increase or decrease its geometry complexity, thereby providing flexibility when drawing the mesh so that performance can be maintained at a steady level. This feature is useful when providing LOD support.
Note The simplification algorithm used to generate progressive meshes is based on Hugues Hoppe's SIGGRAPH papers.
Source: | (SDK root)\Samples\C++\Direct3D\Meshes\ProgressiveMesh |
Executable: | (SDK root)\Samples\C++\Direct3D\Bin\x86 or x64\ProgressiveMesh.exe |
The functionalities of progressive meshes are provided by ID3DXPMesh. This mesh interface is similar to ID3DXMesh with additional methods for managing the mesh's complexity. To generate a progressive mesh, call D3DXGeneratePMesh. The progressive mesh can be used just like a regular mesh. To render it, the sample loops through its materials and calls ID3DXBaseMesh::DrawSubset to send the geometry subset to the device. To adjust the progressive mesh's level of detail (LOD), the sample calls ID3DXPMesh::SetNumVertices passing it the desired number of vertices. A progressive mesh will simplify or enhance its geometry to match the number of vertices as closely as possible.
The sample also shows an optimization technique for progressive meshes by trimming multiple progressive meshes. Trimming limits the maximum and minimum number of vertices or faces a progressive mesh can have. The sample divides the range (maximum - minimum) of the progressive mesh vertices into ten sub-ranges. After the sub-ranges are computed, the sample creates ten progressive meshes by calling ID3DXPMesh::ClonePMeshFVF on the original mesh. Then the sample calls ID3DXPMesh::TrimByVertices on each progressive mesh using a different sub-range. After setting the range of vertices, the sample calls ID3DXPMesh::OptimizeBaseLOD to optimize the mesh's vertex and index buffers. Whenever the user changes the vertex count, the new vertex count is checked against the range of the optimized progressive mesh set, and the mesh whose range contains the desired vertex count is selected by calling ID3DXPMesh::SetNumVertices.
The advantage of using multiple meshes is that adjusting LOD is more efficient than using a single progressive mesh. The performance load of changing LOD is directly proportional to the difference in complexity (represented by vertex count in this sample). Simplifying a mesh by reducing the number of vertices by ten takes less time than reducing the vertex count by 100. That is why this sample achieves better performance by trimming several progressive meshes, each of which covers a smaller LOD range.