本文整理汇总了C++中LPD3DXMESH::OptimizeInplace方法的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXMESH::OptimizeInplace方法的具体用法?C++ LPD3DXMESH::OptimizeInplace怎么用?C++ LPD3DXMESH::OptimizeInplace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPD3DXMESH
的用法示例。
在下文中一共展示了LPD3DXMESH::OptimizeInplace方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _MDLOptimize
PROTECTED void _MDLOptimize(LPD3DXMESH mesh, const LPD3DXBUFFER pAdjacencyBuffer, int numInd,
LPD3DXMESH *optMesh)
{
HRESULT hr;
DWORD *rgdwAdjacencyTemp = 0;
LPD3DXMESH tempMesh;
DWORD dw32Bit = mesh->GetOptions() & D3DXMESH_32BIT;
// allocate a second adjacency buffer to store post attribute sorted adjacency
if(MemAlloc((void**)&rgdwAdjacencyTemp, sizeof(DWORD)*numInd, M_ZERO) != RETCODE_SUCCESS)
{ ASSERT_MSG(0, "Unable to allocate rgdwAdjacencyTemp", "Error in _MDLOptimize"); goto End; }
// attribute sort - the un-optimized mesh option
// remember the adjacency for the vertex cache optimization
hr = mesh->OptimizeInplace( D3DXMESHOPT_COMPACT|D3DXMESHOPT_ATTRSORT,
(DWORD*)pAdjacencyBuffer->GetBufferPointer(),
rgdwAdjacencyTemp, NULL, NULL);
if( FAILED(hr) )
goto End;
// snapshot the attribute sorted mesh, shown as the un-optimized version
hr = mesh->CloneMeshFVF( dw32Bit|D3DXMESH_MANAGED, mesh->GetFVF(),
g_p3DDevice, &tempMesh );
if( FAILED(hr) )
goto End;
// actually do the vertex cache optimization
hr = mesh->OptimizeInplace( D3DXMESHOPT_COMPACT|D3DXMESHOPT_ATTRSORT|D3DXMESHOPT_VERTEXCACHE,
rgdwAdjacencyTemp,
NULL, NULL, NULL);
if( FAILED(hr) )
goto End;
// snapshot as the optimized mesh
hr = mesh->CloneMeshFVF( dw32Bit|D3DXMESH_MANAGED, mesh->GetFVF(),
g_p3DDevice, optMesh );
if( FAILED(hr) )
goto End;
End:
if(rgdwAdjacencyTemp)
MemFree((void**)&rgdwAdjacencyTemp);
if(tempMesh)
tempMesh->Release();
}
示例2: LoadMesh
void cMyASELoader::LoadMesh(){
#ifdef _DEBUG
_ASSERT(m_bLoaded && "Data Not Loaded");
#endif
int check = 0;
for (size_t i = 0; i < m_vecASENode.size(); i++){
if (m_vecASENode[i].nRef != INT_MAX){
m_vecsubSet.push_back(m_vecASENode[i].nRef);
LPD3DXMESH pMesh = NULL;
HRESULT hr = D3DXCreateMeshFVF(m_vecASENode[i].vecVertex.size() / 3,
m_vecASENode[i].vecVertex.size(),
D3DXMESH_MANAGED,
ST_PNT_VERTEX::FVF,
g_pD3DDevice,
&pMesh);
ST_PNT_VERTEX* pV = NULL;
pMesh->LockVertexBuffer(0, (LPVOID*)&pV);
memcpy(pV, &m_vecASENode[i].vecVertex[0], m_vecASENode[i].vecVertex.size() * sizeof(ST_PNT_VERTEX));
pMesh->UnlockVertexBuffer();
WORD* pI = NULL;
pMesh->LockIndexBuffer(0, (LPVOID*)&pI);
for (size_t j = 0; j < pMesh->GetNumVertices(); ++j)
{
pI[j] = j;
}
pMesh->UnlockIndexBuffer();
DWORD* pA = NULL;
pMesh->LockAttributeBuffer(0, &pA);
for (size_t j = 0; j < pMesh->GetNumFaces(); j++){
pA[j] = m_vecASENode[i].nRef;
}
pMesh->UnlockAttributeBuffer();
std::vector<DWORD> vecAdjBuffer(m_vecASENode[i].vecVertex.size());
pMesh->GenerateAdjacency(0.0f, &vecAdjBuffer[0]);
pMesh->OptimizeInplace(
D3DXMESHOPT_ATTRSORT |
D3DXMESHOPT_COMPACT |
D3DXMESHOPT_VERTEXCACHE,
&vecAdjBuffer[0], 0, 0, 0);
m_vecMeshs.push_back(pMesh);
}
}
m_bMeshed = true;
}
示例3: CreateBox
//.........这里部分代码省略.........
offset += 4;
// fill in the top face index data
vIB.push_back( 0 + offset );
vIB.push_back( 1 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 0 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 3 + offset );
//fill in the top face vertex data
vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, 0.f + offsetZ, 0.f, 1.f, 0.f, 0.f, 1.f ) );
vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, d + offsetZ, 0.f, 1.f, 0.f, 0.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, h + offsetY, d + offsetZ, 0.f, 1.f, 0.f, 1.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, h + offsetY, 0.f + offsetZ, 0.f, 1.f, 0.f, 1.f, 1.f ) );
vAB.push_back( 2 );
vAB.push_back( 2 );
offset += 4;
// fill in the bottom face index data
vIB.push_back( 0 + offset );
vIB.push_back( 1 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 0 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 3 + offset );
// fill in the bottom face vertex data
vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, 0.f + offsetZ, 0.f, -1.f, 0.f, 0.f, 1.f ) );
vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, 0.f + offsetZ, 0.f, -1.f, 0.f, 0.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, d + offsetZ, 0.f, -1.f, 0.f, 1.f, 0.f ) );
vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, d + offsetZ, 0.f, -1.f, 0.f, 1.f, 1.f ) );
vAB.push_back( 3 );
vAB.push_back( 3 );
offset += 4;
// fill in the left face index data
vIB.push_back( 0 + offset );
vIB.push_back( 1 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 0 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 3 + offset );
// fill in the left face vertex data
vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, d + offsetZ, -1.f, 0.f, 0.f, 0.f, 1.f ) );
vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, d + offsetZ, -1.f, 0.f, 0.f, 0.f, 0.f ) );
vVB.push_back( VERTEX3( 0.f + offsetX, h + offsetY, 0.f + offsetZ, -1.f, 0.f, 0.f, 1.f, 0.f ) );
vVB.push_back( VERTEX3( 0.f + offsetX, 0.f + offsetY, 0.f + offsetZ, -1.f, 0.f, 0.f, 1.f, 1.f ) );
vAB.push_back( 4 );
vAB.push_back( 4 );
offset += 4;
// fill in the right face index data
vIB.push_back( 0 + offset );
vIB.push_back( 1 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 0 + offset );
vIB.push_back( 2 + offset );
vIB.push_back( 3 + offset );
// fill in the right face vertex data
vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, 0.f + offsetZ, 1.f, 0.f, 0.f, 0.f, 1.f ) );
vVB.push_back( VERTEX3( w + offsetX, h + offsetY, 0.f + offsetZ, 1.f, 0.f, 0.f, 0.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, h + offsetY, d + offsetZ, 1.f, 0.f, 0.f, 1.f, 0.f ) );
vVB.push_back( VERTEX3( w + offsetX, 0.f + offsetY, d + offsetZ, 1.f, 0.f, 0.f, 1.f, 1.f ) );
vAB.push_back( 5 );
vAB.push_back( 5 );
offset += 4;
D3DXCreateMeshFVF( offset / 2, offset, D3DXMESH_MANAGED | D3DXMESH_32BIT, VERTEX3::FVF, g_pEngine->core->lpd3dd9, &mesh );
VERTEX3 *pVB = nullptr;
mesh->LockVertexBuffer( D3DLOCK_DISCARD, reinterpret_cast< void** >( &pVB ) );
copy( vVB.begin(), vVB.end(), pVB );
mesh->UnlockVertexBuffer();
DWORD *pIB = nullptr;
mesh->LockIndexBuffer( D3DLOCK_DISCARD, reinterpret_cast< void** >( &pIB ) );
copy( vIB.begin(), vIB.end(), pIB );
mesh->UnlockIndexBuffer();
DWORD *pAB = nullptr;
mesh->LockAttributeBuffer( D3DLOCK_DISCARD, &pAB );
copy( vAB.begin(), vAB.end(), pAB );
mesh->UnlockAttributeBuffer();
std::vector<DWORD> adjacencyBuffer( mesh->GetNumFaces() * 3 );
mesh->GenerateAdjacency( 0.f, &adjacencyBuffer[ 0 ] );
mesh->OptimizeInplace( D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, &adjacencyBuffer[ 0 ], nullptr, nullptr, nullptr );
}
示例4: DeallocateGeometry
//------------------------------------------------------------------------------------------------
// Name: XMesh
// Desc: Constructs the subset geometry for a D3DXMesh
//------------------------------------------------------------------------------------------------
bool XMesh::buildGeometryFromD3DXMesh(LPD3DXMESH d3dxMesh, SubsetGeometry* subsetGeometry, DWORD subsets)
{
// Check parameters
if (APP_ERROR(!d3dxMesh || !subsetGeometry)("Invalid parameter to XMesh::buildGeometryFromD3DXMesh"))
return false;
// Add a reference to the mesh to counteract freeing it at the end
d3dxMesh->AddRef();
// Get the device
LPDIRECT3DDEVICE9 pd3dDevice = NULL;
d3dxMesh->GetDevice(&pd3dDevice);
// If this mesh isn't already in the correct format, have D3D do the grunt work of
// converting it.
bool generate_normals = false; // Whether or not normals need to be generated for this mesh
if ((d3dxMesh->GetFVF() != D3DFVF_GEOMETRYVERTEX) ||
(D3DFMT_GEOMETRYINDEX == D3DFMT_INDEX32) && ((d3dxMesh->GetOptions() & D3DXMESH_32BIT) == 0))
{
// Holds the mesh when its converted to the correct format
LPD3DXMESH pTemd3dxMesh = NULL;
// Duplicate the loaded mesh into the format
if (APP_ERROR(d3dxMesh->CloneMeshFVF(
D3DXMESH_SYSTEMMEM | ((D3DFMT_GEOMETRYINDEX == D3DFMT_INDEX32) ? D3DXMESH_32BIT : 0),
D3DFVF_GEOMETRYVERTEX, pd3dDevice, &pTemd3dxMesh))
("XMesh couldn't convert the source geometry format")) {
d3dxMesh->Release();
pd3dDevice->Release();
return false;
}
// Generate normals if they didn't exist
generate_normals = ((d3dxMesh->GetFVF()&D3DFVF_NORMAL)!=D3DFVF_NORMAL &&
(D3DFMT_GEOMETRYINDEX&D3DFVF_NORMAL)!=D3DFVF_NORMAL);
// Use this mesh instead
d3dxMesh->Release();
d3dxMesh = pTemd3dxMesh;
}
// The mesh must have its attributes sorted before it can be converted to single strips
{
// Allocate an adjacency buffer
DWORD faces = d3dxMesh->GetNumFaces();
DWORD* pAdjacency = new DWORD[faces * 3];
bool failed = false;
if (APP_ERROR(FAILED(d3dxMesh->GenerateAdjacency(ADJACENCY_EPSILON, pAdjacency)))("Unable to generate the mesh adjacency"))
failed = true;
{ // Clean up "bowties" in the mesh that prevent lighting from being calculated correctly
LPD3DXMESH cleaned_mesh = NULL;
DWORD* cleaned_adjacency = new DWORD[faces * 3];
LPD3DXBUFFER errors_and_warnings = NULL;
if (!failed && APP_ERROR(FAILED(D3DXCleanMesh(D3DXCLEAN_BOWTIES,
d3dxMesh,
pAdjacency,
&cleaned_mesh,
cleaned_adjacency,
&errors_and_warnings)))
("Failed to clean mesh")) {
failed = true;
if (errors_and_warnings) {
DEBUG_ERROR("Mesh cleaning error: %s", (const char*)errors_and_warnings->GetBufferPointer());
}
}
SAFE_RELEASE(errors_and_warnings);
// If we successfully cleaned the mesh, use the new mesh and new set of
// adjacencies. Otherwise, just delete anything that was allocated and
// keep the original.
if (failed) {
SAFE_DELETE_ARRAY(cleaned_adjacency);
SAFE_RELEASE(cleaned_mesh);
} else {
SAFE_DELETE_ARRAY(pAdjacency);
SAFE_RELEASE(d3dxMesh)
pAdjacency = cleaned_adjacency;
d3dxMesh = cleaned_mesh;
}
}
// Compute mesh normals, if necessary
if (!failed && generate_normals && APP_ERROR(FAILED(D3DXComputeNormals(d3dxMesh, pAdjacency)))("Couldn't generate mesh normals")) {
failed = true;
}
// Optimize the mesh
if (!failed && APP_ERROR(FAILED(d3dxMesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT,
pAdjacency,
NULL,
NULL,
NULL)))
("Couldn't optimize mesh attributes")) {
//.........这里部分代码省略.........
示例5: main
int main(int argc, char* argv[])
{
if (argc < 3)
{
puts("Usage: MeshConv meshfile rdffile");
return 1;
}
// Initialize DirectDraw
pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if (pD3D == NULL)
{
puts("Cannot init D3D");
return 1;
}
MeshMender mender;
std::vector<MeshMender::Vertex> MendVerts;
std::vector<unsigned int> MendIndices;
std::vector<unsigned int> mappingNewToOld;
HRESULT hr;
D3DDISPLAYMODE dispMode;
D3DPRESENT_PARAMETERS presentParams;
pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dispMode);
ZeroMemory(&presentParams, sizeof(presentParams));
presentParams.Windowed = TRUE;
presentParams.hDeviceWindow = GetConsoleWindow();
presentParams.SwapEffect = D3DSWAPEFFECT_COPY;
presentParams.BackBufferWidth = 8;
presentParams.BackBufferHeight = 8;
presentParams.BackBufferFormat = dispMode.Format;
hr = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParams, &pD3DDevice);
if (FAILED(hr))
{
printf("Cannot init D3D device: %08x\n", hr);
pD3D->Release();
return 1;
}
printf("Loading mesh %s: ", argv[1]);
LPD3DXBUFFER pAdjacency, pMaterials, pEffects;
DWORD n;
LPD3DXMESH pLoadMesh;
hr = D3DXLoadMeshFromX(argv[1], D3DXMESH_SYSTEMMEM, pD3DDevice, &pAdjacency, &pMaterials, &pEffects, &n, &pLoadMesh);
if (FAILED(hr))
{
printf("ERROR: %08x\n", hr);
goto mesherror;
}
pEffects->Release();
pMaterials->Release();
printf("%d faces, %d verts\n", pLoadMesh->GetNumFaces(), pLoadMesh->GetNumVertices());
LPD3DXMESH pMesh;
if (pLoadMesh->GetFVF() != MESHFVF)
{
hr = pLoadMesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM, MESHFVF, pD3DDevice, &pMesh);
pLoadMesh->Release();
if (FAILED(hr))
{
printf("CloneMesh error: %08x\n", hr);
goto mesherror;
}
}
else
pMesh = pLoadMesh;
printf("Welding verts: ");
DWORD* pAdj = new DWORD[pAdjacency->GetBufferSize() / 4];
D3DXWELDEPSILONS Eps;
memset(&Eps, 0, sizeof(Eps));
hr = D3DXWeldVertices(pMesh, D3DXWELDEPSILONS_WELDPARTIALMATCHES, &Eps, (DWORD*)pAdjacency->GetBufferPointer(), pAdj, NULL, NULL);
if (FAILED(hr))
{
printf("ERROR: %08x\n", hr);
goto mesherror;
}
hr = pMesh->OptimizeInplace(D3DXMESHOPT_VERTEXCACHE, pAdj, (DWORD*)pAdjacency->GetBufferPointer(), NULL, NULL);
if (FAILED(hr))
{
printf("ERROR: %08x\n", hr);
goto mesherror;
}
pAdjacency->Release();
delete [] pAdj;
printf("%d faces, %d verts\n", pMesh->GetNumFaces(), pMesh->GetNumVertices());
printf("Mending mesh: ");
DWORD NumVerts = pMesh->GetNumVertices();
//.........这里部分代码省略.........