Game Development Reference
In-Depth Information
interface and its parent ID3DXBaseMesh , we can use the following
function to generate vertex normals for any mesh:
HRESULT D3DXComputeNormals(
LPD3DXBASEMESH pMesh, // Mesh to compute normals of.
const DWORD *pAdjacency // Input adjacency info.
);
This function generates the vertex normals by using normal averaging.
If adjacency info is provided, then duplicated vertices are disregarded. If
adjacency info is not provided, then duplicated vertices have normals
averaged from the faces that reference them. It is important to realize
that the mesh we pass in for pMesh must have a vertex format that
contains the D3DFVF_NORMAL flag.
Note that if an XFile does not contain vertex normal data, the
ID3DXMesh object created from D3DXLoadMeshFromX does not have
the D3DFVF_NORMAL flag specified in its vertex format. Therefore,
before we can use D3DXComputeNormals , we have to clone the mesh
and specify a vertex format for the cloned mesh that includes
D3DFVF_NORMAL . The following example demonstrates this:
// does the mesh have a D3DFVF_NORMAL in its vertex format?
if ( !(pMesh->GetFVF() & D3DFVF_NORMAL) )
{
// no, so clone a new mesh and add D3DFVF_NORMAL to its format:
ID3DXMesh* pTempMesh = 0;
pMesh->CloneMeshFVF(
D3DXMESH_MANAGED,
pMesh->GetFVF() | D3DFVF_NORMAL, // add it here
Device,
&pTempMesh );
// compute the normals:
D3DXComputeNormals( pTempMesh, 0 );
pMesh->Release(); // get rid of the old mesh
pMesh = pTempMesh; // save the new mesh with normals
}
11.3 Progressive Meshes
Progressive meshes, represented by the ID3DXPMesh interface, allow
us to simplify a mesh by applying a sequence of edge collapse transfor-
mations (ECT). Each ECT removes one vertex and one or two faces.
Because each ECT is invertible (its inverse is called a vertex split ), we
can reverse the simplification process and restore the mesh to its exact
original state. This, of course, means that we cannot obtain a mesh
more detailed then the original; we can only simplify and then reverse
Search WWH ::




Custom Search