IDirect3DIndexBuffer9* iBuffer;
mesh->GetIndexBuffer(&iBuffer);
DWORD numVertices = mesh->GetNumVertices();
DWORD numFaces = mesh->GetNumFaces();
_terrainVertices = new neV3[numVertices];
_terrainTriangles = new neTriangle[numFaces];
_terrain.vertexCount = numVertices;
_terrain.triangleCount = numFaces;
//read in vertex data from loaded scene mesh
for (DWORD i = 0; i < numVertices; i++)
{
D3DXVECTOR3 *vTex = &mesh->vertices.position;
_terrainVertices.Set(vTex->x, vTex->y, vTex->z);
}
_terrain.vertices = _terrainVertices;
//read in triangle data (index buffer) from loaded mesh
VOID* indices;
iBuffer->Lock(0, NULL, &indices, D3DLOCK_READONLY);
WORD* index = (WORD*)indices; //16-bit index-buffer
UINT p = 0;
for (i = 0; i < numFaces; i++, p += 3)
{
_terrainTriangles.indices[0] = index;
_terrainTriangles.indices[1] = index[p+1];
_terrainTriangles.indices[2] = index[p+2];
_terrainTriangles.materialID = 0;
_terrainTriangles.flag = neTriangle::NE_TRI_TRIANGLE;
}
iBuffer->Unlock();
_terrain.triangles = _terrainTriangles;
_simulator->SetTerrainMesh(&_terrain); //crashes here!
Tokamak Terrain from a loaded mesh
I am having trouble getting my loaded .X mesh to be set as the terrain mesh in tokamak. I follow the steps in the adamdawes tutorial carefully and substitute vertices and triangles from my loade mesh. I even test everything to make sure it is correct (printing out the vertex/face data to a log) before calling SetTerrainMesh()
but when I call this method the app crashes (like a null-pointer exception). What could be the reason for this? Does tokamak not like closed terrain meshes? The SDK docs are woefully unhelpful.
Any help would be appreciated. thanks.
The following is the code I use to fill in the triange and index data:
Afraid I can't really help, since I don't use Tokamak.... I noticed one reply to your post over at the Tokamak forums, though. Did that reply help?
have you done this in the initialization:
neSimulatorSizeInfo sizeInfo;sizeInfo.terrainNodesStartCount = 200;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement