渐进网格
声明变量
产生渐进网格
加载模型
hr = SourceMesh->OptimizeInplace( D3DXMESHOPT_ATTRSORT| D3DXMESHOPT_COMPACT| D3DXMESHOPT_VERTEXCACHE, (DWORD*)adjbuffer->GetBufferPointer(), (DWORD*)adjbuffer->GetBufferPointer(), 0,0 );
if (FAILED(hr)) { ::MessageBox(0, "OptimizeInplace-lost", 0, 0); return false; }
hr = D3DXGeneratePMesh( SourceMesh, (DWORD*)adjbuffer->GetBufferPointer(), 0,0,1, D3DXMESHSIMP_FACE, &PMesh );
if (FAILED(hr)) { ::MessageBox(0, "D3DXGeneratePMesh-lost", 0, 0); return false; }
adjbuffer->Release();
DWORD maxfaces = PMesh->GetMaxFaces();
PMesh->SetNumFaces(maxfaces);
|
绘制模型
for (int i = 0; i < Mtrls.size(); i++) { g_pd3dDevice->SetMaterial(&Mtrls[i]); g_pd3dDevice->SetTexture(0, Textures[i]); PMesh->DrawSubset(i); g_pd3dDevice->SetMaterial(&yellow_mtrl); g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); PMesh->DrawSubset(i); g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); }
|
调整效果
int numfaces = PMesh->GetNumFaces(); if (::GetAsyncKeyState('A')&0x8000f) { PMesh->SetNumFaces(numfaces + 10); }
if (::GetAsyncKeyState('S')&0x8000f) { PMesh->SetNumFaces(numfaces - 10); }
|
效果