Hi,
im making the move from managed dx to proper dx with c++ and I have run into a bit of trouble when it comes to turning the mesh data I have read in into a proper mesh.
Im sure the problem is at the final level where i lock the buffers and copy in the data because all the attributes, vertexs and indices are correct.
Bellow is the mesh create code and the vertex structure im using, any help or a point in the right direction would be excellent. Cheers,
-Dave
Vertex Struct
[SOURCE]
struct Vertex{
float x, y, z, u, v;
DWORD color;
enum FVF{
FVF_Flags = D3DFVF_XYZ | D3DFVF_TEX2 | D3DFVF_DIFFUSE
};
};
[/SOURCE]
[SOURCE]
Vertex* verts;
int i, indicesPos;
short* indices;
short* attribs;
const int geomPos = 0;
verts = new Vertex[clump.geometryList.geometry[geomPos].vertexCount];
//color
for(i=0; i<clump.geometryList.geometry[geomPos].vertexCount; i++)
verts.color = 0xffffff00;
//mapping info
for(i=0; i<clump.geometryList.geometry[geomPos].vertexCount; i++){
verts.u = clump.geometryList.geometry[geomPos].mappinginfo.u;
verts.v = clump.geometryList.geometry[geomPos].mappinginfo.v;
}
//vertex info
for(i=0; i<clump.geometryList.geometry[geomPos].vertexCount; i++){
verts.x = clump.geometryList.geometry[geomPos].vertexInfo.x;
verts.y = clump.geometryList.geometry[geomPos].vertexInfo.y;
verts.z = clump.geometryList.geometry[geomPos].vertexInfo.z;
}
//indices & attributes
indices = new short[clump.geometryList.geometry[geomPos].triangleCount * 3];
attribs = new short[clump.geometryList.geometry[geomPos].triangleCount];
indicesPos = 0;
for(i=0; i<clump.geometryList.geometry->triangleCount; i++){
indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo.vertex2;
indicesPos++;
indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo.vertex1;
indicesPos++;
indices[indicesPos] = clump.geometryList.geometry[geomPos].faceinfo.vertex3;
indicesPos++;
attribs = clump.geometryList.geometry[geomPos].faceinfo.flags;
}
D3DXCreateMeshFVF(clump.geometryList.geometry[geomPos].materialsplit.faceCount, clump.geometryList.geometry[geomPos].vertexCount, D3DXMESH_MANAGED, Vertex::FVF_Flags, *ptrDevice, &clump.geometryList.geometry[geomPos].mesh);
LPVOID data;
DWORD* aData;
clump.geometryList.geometry[geomPos].mesh->LockIndexBuffer(0, &data);
memcpy(data, indices, 2 * (clump.geometryList.geometry[geomPos].triangleCount * 3));
clump.geometryList.geometry[geomPos].mesh->UnlockIndexBuffer();
clump.geometryList.geometry[geomPos].mesh->LockVertexBuffer(0, &data);
memcpy(data, verts, sizeof(Vertex) * clump.geometryList.geometry[geomPos].vertexCount);
clump.geometryList.geometry[geomPos].mesh->UnlockVertexBuffer();
clump.geometryList.geometry[geomPos].mesh->LockAttributeBuffer(0, &aData);
memcpy(aData, attribs, 2 * clump.geometryList.geometry[geomPos].triangleCount);
clump.geometryList.geometry[geomPos].mesh->UnlockAttributeBuffer();
//delete aData;
delete [] verts;
delete [] indices;
delete [] attribs;
[/SOURCE]