Skip to main content
GameDev.net gamedev.net
🔒 Locked

Combining Meshes

Started by ShadowCoder Oct 5, 2002 at 6:25 PM 1 replies 500+ views
Original Post
ShadowCoder
ShadowCoder
I'm trying join individual smaller meshes into one large mesh. My first step was to just create a single copy of a mesh manually. (I realize that for a single mesh you'd normally just clone it, but this code is to join some meshes together.) It runs without error, but when I render I get nothing.
  // In Class Declaration

CD3DMesh       *m_pWall;     // Wall Object

CD3DMesh       *m_pWallComb; // Copied Wall Object         

//In Create

m_pWall      = new CD3DMesh; // Wall

m_pWallComb  = new CD3DMesh; // Wall Combined  

  
// In InitDeviceObjects()

// Load a wall

if( FAILED( m_pWall->Create( m_pd3dDevice, _T("wall2.x") ) ) )
  return D3DAPPERR_MEDIANOTFOUND;

// Copy Wall

LPDIRECT3DVERTEXBUFFER8 pVB;
LPDIRECT3DVERTEXBUFFER8 pVB2;
DWORD meshFVF;
UINT  uiFVFSize;
DWORD dwNumVertices = m_pWall->GetSysMemMesh()->GetNumVertices();
DWORD dwNumFaces    = m_pWall->GetSysMemMesh()->GetNumFaces();

meshFVF   = m_pWall->GetSysMemMesh()->GetFVF();
uiFVFSize = D3DXGetFVFVertexSize(meshFVF );

D3DXCreateMeshFVF(dwNumFaces, dwNumVertices, D3DXMESH_SYSTEMMEM, meshFVF,m_pd3dDevice, &m_pWallComb->m_pSysMemMesh);

if(SUCCEEDED(m_pWall->GetSysMemMesh()->GetVertexBuffer(&pVB)))
  {
  if(SUCCEEDED(m_pWallComb->GetSysMemMesh()->GetVertexBuffer(&pVB2)))
    {
    // uiFVFSize = 32 for this mesh 8*FLOAT=32 

    struct VERTEX { FLOAT x,y,z,tu,tv,a,b,c; };
    VERTEX* pVertices;
    VERTEX* pVertices2;
    pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 );
    pVB2->Lock( 0, 0, (BYTE**)&pVertices2, 0 );

    memcpy(pVertices2,pVertices,uiFVFSize*dwNumVertices);

    pVB2->Unlock();
    pVB2->Release();
    pVB->Unlock();
    }
  pVB->Release();
  }

m_pWallComb->m_dwNumMaterials = m_pWall->m_dwNumMaterials;
m_pWallComb->m_pMaterials     = new D3DMATERIAL8[m_pWallComb->m_dwNumMaterials];
m_pWallComb->m_pTextures      = new LPDIRECT3DTEXTURE8[m_pWallComb->m_dwNumMaterials];
memcpy(m_pWallComb->m_pMaterials,m_pWall->m_pMaterials,sizeof(D3DMATERIAL8)*m_pWallComb->m_dwNumMaterials);
TCHAR strTexture[MAX_PATH];
TCHAR strTextureTemp[MAX_PATH];
DXUtil_ConvertAnsiStringToGeneric( strTextureTemp, _T("wall.bmp") );
DXUtil_FindMediaFile( strTexture, strTextureTemp );
if( FAILED( D3DXCreateTextureFromFile( m_pd3dDevice, strTexture, 
                                         &m_pWallComb->m_pTextures[0] ) ) )
  m_pWallComb->m_pTextures[0] = NULL;

                    
This also doesn't render:
 
m_pWallComb->m_dwNumMaterials = m_pWall->m_dwNumMaterials;
m_pWallComb->m_pMaterials     = m_pWall->m_pMaterials;
m_pWallComb->m_pTextures      = m_pWall->m_pTextures;        
I'm sure it's either something stupid or something I don't know that I'm supposed to do. I have traced it and DrawSubset is being called, and D3DXCreateMeshFVF is not failing. Any help would be appreciated. Shad [edited by - ShadowCoder on October 5, 2002 10:06:55 PM]
ShadowCoder
ShadowCoder
I discovered the mesh had no attribute table. So I added one using:
  DWORD  *pAdjacencyTable;
pAdjacencyTable = new DWORD[3*dwNumFaces];
hr = m_pWallComb->m_pSysMemMesh->ConvertPointRepsToAdjacency(NULL,pAdjacencyTable);

// Optimize the mesh for performance

hr = m_pWallComb->m_pSysMemMesh->OptimizeInplace(
D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE,
pAdjacencyTable, NULL, NULL, NULL ) ;
SAFE_DELETE_ARRAY( pAdjacencyTable );
Still doesn''t render. @!#$%@#^%$^ Any help would be greatly appreciated.

Shad
ShadowCoder
ShadowCoder

Was thinking maybe it was an index buffer problem. I call

LPDIRECT3DINDEXBUFFER8  pNDX;
D3DINDEXBUFFER_DESC* pNDXDesc = NULL;

if( SUCCEEDED( m_pWall->GetSysMemMesh()->GetIndexBuffer(&pNDX)))
{
// Getting the IndexBuffer Succeeds
// Getting the Description Fails?!
hr = pNDX->GetDesc(pNDXDesc);
}


Any ideas why pNDX->GetDesc(pNDXDesc) fails?

hr = 0x8876086c

Shad


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.