Exporting primitives as .x files

Started by
-1 comments, last by Chem 19 years, 6 months ago
Hi, I'm trying to create a .x file from a index/vertex buffer than I'm using, here is the method. Currently its creating the file but nothing is visible when I look in mesh viewer. Any ideas? Thanks CMyD3DApplication::ExportLandscapeAsXFile() { // Declare the mesh,vertex buffer, index buffer: ID3DXMesh *m_pmesh; LPDIRECT3DVERTEXBUFFER9 pVB; LPDIRECT3DINDEXBUFFER9 pIB; int numPolygons = m_Landscape.gridSize*m_Landscape.gridSize*2; int numVertices = (m_Landscape.gridSize+1)*(m_Landscape.gridSize+1); // Create your mesh object: D3DXCreateMeshFVF( numPolygons, (DWORD)numVertices, D3DXMESH_MANAGED , D3DFVF_CUSTOMVERTEX, m_pd3dDevice, &m_pmesh); // Grab a pointer to the vertex buffer from the mesh: m_pmesh->GetVertexBuffer(&pVB); //Lock the vertex buffer: CUSTOMVERTEX *pVertices; pVB->Lock( 0, 0, (VOID**)&pVertices, 0 ); // Structure to hold pointer to landscape information CUSTOMVERTEX* pLandscapeVertices; // Lock the landscape buffer if( FAILED( m_Landscape.m_pVBforLandscape->Lock( 0, 0, (VOID**)&pLandscapeVertices, 0 ) ) ) MessageBox(NULL, "Failed to access Vertex Buffer for landscape", NULL, MB_OK); // For each row for(int i=0; i < m_Landscape.gridSize; i++) { // For each column for(int j=0; j < m_Landscape.gridSize; j++) { pVertices[i*m_Landscape.gridSize + j] = pLandscapeVertices[i*(m_Landscape.gridSize + m_Landscape.extraVerticesAcross) + j]; } } // Unlock the vertex buffer m_pmesh->UnlockVertexBuffer(); m_Landscape.m_pVBforLandscape->Unlock(); // Grab the index buffer m_pmesh->GetIndexBuffer(&pIB); // Lock the index buffer WORD *pIndices; pIB->Lock( 0, 0, (VOID**)&pIndices, 0 ); // Fill in the index buffer //for(i=0; i < (m_Landscape.gridSize+2)*m_Landscape.gridSize*3; i++) // pIndices = m_Landscape.pIndicesForExport; pIndices = m_Landscape.pIndicesForExport; // Unlock the index buffer m_pmesh->UnlockIndexBuffer(); D3DXMATERIAL* materials = new D3DXMATERIAL[numPolygons]; for(i=0; i <numPolygons; i++) { materials.MatD3D = m_Landscape.mtrl; materials.pTextureFilename = "landscape.PNG"; } DWORD* pAdjacency = new DWORD[3 * numPolygons]; m_pmesh->GenerateAdjacency( 0.0f, pAdjacency ); // Save the mesh as a .x file: D3DXSaveMeshToX( "MyXFile.x", m_pmesh, pAdjacency, materials, NULL, numPolygons, DXFILEFORMAT_BINARY); SAFE_RELEASE( m_pmesh ); SAFE_RELEASE( pVB ); SAFE_RELEASE( pIB ); }

This topic is closed to new replies.

Advertisement