Using a Simplification Mesh


Although simplifying a mesh directly as you did here is feasible in a few situations, in most cases you have to store entirely too many meshes for it to be useful in a real-world situation with many levels of detail. (Each level of detail requires a separate mesh.) What you need is a way to do something similar but without the requirement of all these mesh copies.

You can use the SimplificationMesh object to encapsulate the process of simplifying a mesh. However, you can't actually use the object to do the rendering; you must first get an actual mesh from the simplification mesh. Creating the simplification mesh is simple; here is the overload:

 public SimplificationMesh ( Microsoft.DirectX.Direct3D.Mesh mesh ,    Microsoft.DirectX.GraphicsStream adjacency ,    Microsoft.DirectX.Direct3D.AttributeWeights vertexAttributeWeights ,    Microsoft.DirectX.GraphicsStream vertexWeights ) 

If you noticed that these are the same parameters as those in the Simplify method, with the exception of the minimum value and flags, you are quite observant. The object that is created is ready to simplify the passed-in mesh, but until you call one of the reduce methods on the object, it maintains a full set of vertices and faces.

If you were interested in reducing the amount of vertices and faces in the simplified mesh, you would use two methods, ReduceVertices and ReduceFaces, which reduce the number of vertices or faces, as the names imply. If you wanted to simplify the mesh to the lowest possible detail, you would call code such as the following:

 SimplificationMesh simplifiedMesh = new SimplificationMesh(mesh, adj); simplifiedMesh.ReduceVertices(1); simplifiedMesh.ReduceFaces(1); 

Assume that mesh is a loaded mesh and adj is the adjacency information for that mesh. However, there are no drawing calls located on the SimplificationMesh object, so drawing with this object is unsupported, as mentioned earlier. Instead, you need to use the Clone method from the SimplificationMesh object to get the real mesh. The overload looks like this:

 public Microsoft.DirectX.Direct3D.Mesh Clone (    Microsoft.DirectX.Direct3D.MeshFlags options ,    Microsoft.DirectX.Direct3D.VertexFormats vertexFormat ,    Microsoft.DirectX.Direct3D.Device device ,    out int[] adjacencyOut , out int[] vertexRemap ) 

As you see here, this method returns a mesh and the mesh that is returned is the simplified version (that is, the result of any reduce calls). Although many applications don't use this overload (they use the overload without the adjacencyOut and vertexRemap parameters), the method itself is simple. An example of calling it using the preceding sample code is

 mesh.Dispose(); mesh = simplifiedMesh.Clone(simplifiedMesh.Options.Value,    simplifiedMesh.VertexFormat, device); 

Notice here that the original mesh is disposed to clean up any resources and then reassigned to the newly cloned simplification mesh.

One of the first problems you might notice with this object type is that you can't seem to regain any of the lost vertices. Sure, you can simplify the mesh just fine, but what if you want to raise the level of detail in the model? There is no RaiseVertices method, and using the ReduceVertices method and passing in a larger number of vertices has no effect. The SimplificationMesh objects are designed to simplify meshes, and that is all: there is no going back. Progressive meshes were designed to handle this case.



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