Hardcoded ID3DXMeshes with more than 40 faces
I'm hardcoding a hockey table mesh into my code, but I've got a really weird bug... whenever I go over 120 indices (40 faces) all the faces that follow that face (in my case indexes 120 through to 192) end up horribly and wierdly corrupted.
Has anyone else had trouble harcoding meshes over 40 faces? If so how did you get around the problem?
Cheers, Duncan
Can you post the VB and IB creation code, and vertex initialization code? (You don't have to list all 120+ indices [smile]). This will be helpful, because your problem could be the result of a lot of things (memory allocation errors, ect...)
Cheers for the replies guys, the code (abridged!) is pretty textbook stuff:
Anything past face 40 (index 120) is just mangled... all triangles merge in wierd ways and go to vertex 0 without me telling them to! I can't see why, any ideas?
Cheers for any help, Duncan
hr = D3DXCreateMeshFVF(64,41,D3DXMESH_MANAGED,DuncEngineMesh::Vertex::FVF,device,&table); //FVF is D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE if(FAILED(hr)) { ::MessageBox(0, "D3DXCreateMeshFVF() - FAILED", 0, 0); return false; } DuncEngineMesh::Vertex* tableVertices = 0; table->LockVertexBuffer(0, (void**)&tableVertices); tableVertices[0] = DuncEngineMesh::Vertex(0.1f, 0.25f, 2.6f, DuncEngineUtils::BLUE); // and so on until... tableVertices[40] = DuncEngineMesh::Vertex(0.1f, 0.4f, 1.975f, DuncEngineUtils::BLUE); //scale vertices for (int i = 0; i < 41; i++) { tableVertices._x *= 10; tableVertices._y *= 10; tableVertices._z *= 10; } table->UnlockVertexBuffer(); WORD* tableIndices = 0; table->LockIndexBuffer(0, (void**)&tableIndices); tableIndices[0] = 0; tableIndices[1] = 1; tableIndices[2] = 16; //and so on until... tableIndices[190] = 0; tableIndices[191] = 15; tableIndices[192] = 40; table->UnlockIndexBuffer(); //calculate normals std::vector<DWORD> adjacencyBuffer(table->GetNumFaces() * 3); table->GenerateAdjacency(0.0f, &adjacencyBuffer[0]); D3DXComputeNormals(table,&adjacencyBuffer[0]); DWORD* attributeBuffer = 0; table->LockAttributeBuffer(0, &attributeBuffer); for(int a = 0; a < 41; a++) attributeBuffer[a] = 0; table->UnlockAttributeBuffer(); hr = table->OptimizeInplace(D3DXMESHOPT_ATTRSORT|D3DXMESHOPT_COMPACT|D3DXMESHOPT_VERTEXCACHE,&adjacencyBuffer[0],0, 0, 0);
Anything past face 40 (index 120) is just mangled... all triangles merge in wierd ways and go to vertex 0 without me telling them to! I can't see why, any ideas?
Cheers for any help, Duncan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement