Game Development Reference
In-Depth Information
11.3.4 Sample Application: Progressive Mesh
The Progressive Mesh sample is similar to the XFile sample, except for
the fact that the mesh we create and render is a progressive mesh and
thus represented by the ID3DXPMesh interface. We allow the user to
change the resolution of the progressive mesh interactively via key-
board input. You can add faces to the mesh by pressing the A key, and
you can remove faces from the mesh by pressing the S key.
The global variables used in the sample are almost the same as
those used in the XFile sample, but we add an additional variable to
store the progressive mesh:
ID3DXMesh*
SourceMesh = 0;
ID3DXPMesh*
PMesh
= 0; // progressive mesh
std::vector<D3DMATERIAL9> Mtrls(0);
std::vector<IDirect3DTexture9*> Textures(0);
Recall that to generate a progressive mesh we must pass in a “source”
mesh that contains the data we want to create a progressive mesh of.
Thus, we first load the XFile data into an ID3DXMesh object
SourceMesh and then generate the progressive mesh:
bool Setup()
{
HRESULT hr = 0;
// ...Load XFile data into SourceMesh snipped.
//
// ...Extracting materials and textures snipped.
Since the code to do this is exactly the same as it was in the XFile sam-
ple, we have omitted it. Once we have a source mesh, we can generate
the progressive mesh as follows:
//
// Generate the progressive mesh.
//
hr = D3DXGeneratePMesh(
SourceMesh,
(DWORD*)adjBuffer->GetBufferPointer(), // adjacency
0, // default vertex attribute weights
0, // default vertex weights
1, // simplify as low as possible
D3DXMESHSIMP_FACE, // simplify by face count
&PMesh);
d3d::Release<ID3DXMesh*>(SourceMesh); // done w/ source mesh
d3d::Release<ID3DXBuffer*>(adjBuffer); // done w/ buffer
if(FAILED(hr))
{
Search WWH ::




Custom Search