   Changing mesh vertices at runtime
  Hi. I need to change a mesh container vertex format in order to add the things I need in the vertex. But for some reason I don't know, when I use the following code to achieve this result, the mesh container is not drawn. I was asking why...vertCount = pCont->MeshData.pPMesh->GetNumVertices();// Check vertex validityDWORD flags = 0;if (!(desc & D3DFVF_DIFFUSE)) flags |= D3DFVF_DIFFUSE;if (!(desc & D3DFVF_XYZ) && !(desc & D3DFVF_XYZRHW)) flags |= D3DFVF_XYZ;if (!(desc & D3DFVF_TEX1) flags |= D3DFVF_TEX1;if (flags){LPD3DXPMESH pPMesh;pCont->MeshData.pPMesh->ClonePMeshFVF(D3DXMESH_MANAGED, desc|flags, dev.pD3Ddevice, &pPMesh);pCont->MeshData.pPMesh->Release();pCont->MeshData.pPMesh = pPMesh;desc = pCont->MeshData.pPMesh->GetFVF();}pCont->MeshData.pPMesh->LockVertexBuffer(0, (LPVOID*)&VerPtr);pCont->MeshData.pPMesh->LockIndexBuffer(D3DLOCK_READONLY, (LPVOID*)&IndPtr);bytes = pCont->MeshData.pPMesh->GetNumBytesPerVertex();facesCount = pCont->MeshData.pPMesh->GetNumFaces();vertCount = pCont->MeshData.pPMesh->GetNumVertices();   ...   // Change vertex data   ...pCont->MeshData.pPMesh->UnlockVertexBuffer();pCont->MeshData.pPMesh->UnlockIndexBuffer(); Any ideas of what is wrong?Thanks a lot[Edited by - Adriano on May 25, 2006 4:15:23 AM]
  Does the original mesh render? Does the cloned mesh render if you don't do all the locking and whatever changes you do there?   ;  Good point ET3D. I found out that the problem wasn't actually make room for the vertices, but it was how I access them. I fixed the code:BYTE* pVertex = (BYTE*)vertices;BYTE* pBytes;// Get info from verticesfor(size_t i=0; i<verticesCount; ++i){pBytes = pVertex;// Positionif (description & D3DFVF_XYZ){pVertexPosArray = (D3DXVECTOR3*)(pBytes+0);pBytes += 3*sizeof(float);// RHWif ((description & D3DFVF_XYZRHW) && !(description & D3DFVF_XYZ))pBytes += sizeof(float);// Blending weightsif (description & D3DFVF_XYZB5)pBytes += 8*sizeof(float);if ((description & (D3DFVF_XYZB5|D3DFVF_LASTBETA_UBYTE4) ||description & (D3DFVF_XYZB5|D3DFVF_LASTBETA_D3DCOLOR)) &&!(description & D3DFVF_XYZ))pBytes += 7*sizeof(float) + sizeof(DWORD);if ((description & D3DFVF_XYZB4) && !(description & D3DFVF_XYZ))pBytes += 7*sizeof(float);if ((description & (D3DFVF_XYZB4|D3DFVF_LASTBETA_UBYTE4) ||description & (D3DFVF_XYZB4|D3DFVF_LASTBETA_D3DCOLOR)) &&!(description & D3DFVF_XYZ))pBytes += 6*sizeof(float) + sizeof(DWORD);if ((description & D3DFVF_XYZB3) && !(description & D3DFVF_XYZ))pBytes += 6*sizeof(float);if ((description & (D3DFVF_XYZB3|D3DFVF_LASTBETA_UBYTE4) ||description & (D3DFVF_XYZB3|D3DFVF_LASTBETA_D3DCOLOR)) &&!(description & D3DFVF_XYZ))pBytes += 5*sizeof(float) + sizeof(DWORD);if ((description & D3DFVF_XYZB2) && !(description & D3DFVF_XYZ))pBytes += 5*sizeof(float);if ((description & (D3DFVF_XYZB2|D3DFVF_LASTBETA_UBYTE4) ||description & (D3DFVF_XYZB2|D3DFVF_LASTBETA_D3DCOLOR)) &&!(description & D3DFVF_XYZ))pBytes += 4*sizeof(float) + sizeof(DWORD);if ((description & D3DFVF_XYZB1) && !(description & D3DFVF_XYZ))pBytes += 4*sizeof(float);if ((description & (D3DFVF_XYZB1|D3DFVF_LASTBETA_UBYTE4) ||description & (D3DFVF_XYZB1|D3DFVF_LASTBETA_D3DCOLOR)) && !(description & D3DFVF_XYZ))pBytes += 3*sizeof(float) + sizeof(DWORD);}// Normalif (description & D3DFVF_NORMAL)pBytes += 3*sizeof(float);// Vertex point sizeif (description & D3DFVF_PSIZE)pBytes += sizeof(float);// Diffuseif (description & D3DFVF_DIFFUSE){pVertexDifArray = (D3DCOLOR*)(pBytes);pBytes += sizeof(D3DCOLOR);}// Specularif (description & D3DFVF_SPECULAR)pBytes += sizeof(D3DCOLOR);// Texture coordinates set 0if ((description & D3DFVF_TEX1)){pVertexTUArray = (float*)(pBytes);pBytes += sizeof(float);pVertexTVArray = (float*)(pBytes);pBytes += sizeof(float);}// Skip to next vertexpVertex += bytesPerVertex;}Now the weird thing is that if I attempt to change the vertex position i retrieve it works fine, but when it comes to changing the vertex diffuse color nothing happens...[Edited by - Adriano on May 25, 2006 8:12:16 AM]