Hi,
I have the following situation:
1. A mesh is loaded into a D3DXMESH using D3DXLoadMeshFromX
2. A IDirect3DVertexBuffer9 is part of the mes class
3. The vertexbuffer is retrieved from the mesh to the vertexbuffer variable, by:
mMesh->GetVertexBuffer(&mVtxBuffer)
4. I access the vertex buffer to calculate boundingsphere, box etc.. Accessing the vertices is done by this code:
TVERTEX *verticesPointer;
TVERTEX *vertices = new TVERTEX[pMesh.mMesh->GetNumVertices()];
pMesh.mVtxBuffer->Lock(0, 0, (void**)&verticesPointer, D3DLOCK_READONLY); // ,0 = default
memcpy(vertices, verticesPointer, pMesh.mMesh->GetNumVertices()*D3DXGetDeclVertexSize(vtxdecl, 0));
// VERTICES ARE NOT SCALED/ROTATED/TRANSLATED, AND ARE IN MODEL SPACE
// do stuff, read only with vertices
pMesh.mVtxBuffer->Unlock();
delete[] vertices;
That's basically my current situation.
Now my goal is to transform the vertices of the meshes to their child modelspace's, instead of parent.
The only thing I don't know how to do is, how can I change the data in the vertexbuffer?
This is what I've tried to test out:
// TESTING VERTEX BUFFERS COPYING //
Crealysm_dxmath::TVERTEX *verticesPointer;
Crealysm_dxmath::TVERTEX *vertices = new Crealysm_dxmath::TVERTEX[mMesh->GetNumVertices()];
mVtxBuffer->Lock(0, 0, (void**)&verticesPointer, 0); // ,0 = default
memcpy(vertices, verticesPointer, mMesh->GetNumVertices()*D3DXGetDeclVertexSize(Crealysm_dxmath::vtxdecl, 0));
// VERTICES ARE NOT SCALED/ROTATED/TRANSLATED, AND ARE IN MODEL SPACE
for(DWORD vtx=0;vtx<mMesh->GetNumVertices();++vtx)
{
vertices[vtx].position.z = 5.0f;
}
mVtxBuffer->Unlock();
This test would make my world 'float', by giving all meshes vertices Z = 5.0.
But the result is that nothing changes at all.
Do you have any idea how to solve this?
(is it possible at all to change the data, or do I need to make a new vertexbuffer and 'link' that/ use that for rendering, instead of the one retrieved from the d3dxmesh)