Controlling the Level of Detail Using a Progressive Mesh


Naturally, in some cases you only want to simplify a mesh. For example, imagine a model for a rocket you've just fired. Unless you have really bad aim, more than likely this object will not return toward you. However, a more common case is where you need to progressively lower or raise the level of detail. I'm sure you can see where the name of the progressive mesh came from.

Unlike the SimplificationMesh, the ProgressiveMesh class derives from the BaseMesh class and can be used directly to draw the mesh onscreen. The ProgressiveMesh class is created in much the same way that the SimplificationMesh is. Look at the constructor:

 public ProgressiveMesh ( Microsoft.DirectX.Direct3D.Mesh mesh ,    Microsoft.DirectX.GraphicsStream adjacency ,    Microsoft.DirectX.Direct3D.AttributeWeights vertexAttributeWeights ,    Microsoft.DirectX.GraphicsStream vertexWeights ,    System.Int32 minValue ,    Microsoft.DirectX.Direct3D.MeshFlags options ) 

Notice that here, the constructor is almost a mixture of the constructor for the SimplificationMesh object and the Simplify method. The minValue parameter is the minimum amount you want to allow this mesh to be reduced to. After the object is created, you can set the number of faces or vertices to any number of faces or vertices between that minimum value and the ProgressiveMesh.MaxFaces or ProgressiveMesh.MaxVertices, depending on what you're modifying.

Construction Cue

After the progressive mesh is created, it will be fully simplified. If you want to ensure that it is the high-resolution version of the mesh after creation, you need to use code such as the following:

 using(Mesh tempMesh = Mesh.Clean(mesh, adj, adj)) {     // Create our progressive mesh     progressiveMesh = new ProgressiveMesh(tempMesh, adj,     null, 1, MeshFlags.SimplifyVertex);     // Set the initial mesh to the max     progressiveMesh.NumberFaces = progressiveMesh.MaxFaces;     progressiveMesh.NumberVertices = progressiveMesh.MaxVertices; } 


After your progressive mesh is created, you can use it just as you would use your normal mesh, drawing it every frame. You can add and remove vertices and faces depending on how far away from the camera the object is, so you have complete control over the level of detail of your object.

Construction Cue

It's common to store multiple meshes of varying levels of details rather than have one large progressive mesh controlling the entire range of details. If you look at the progressive mesh sample that ships with the DirectX SDK, you see an example of this implementation. You can use the TRimByFaces and trimByVertices methods on the progressive mesh object to change the level of detail that any particular progressive mesh supports.




Beginning 3D Game Programming
Beginning 3D Game Programming
ISBN: 0672326612
EAN: 2147483647
Year: 2003
Pages: 191
Authors: Tom Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net