Hi.
I've got a half-baked implementation of recast in my
level editor. I'm not using OgreRecast or any wrapper libraries, so I'm not sure how helpful this will be for you, but if it helps then it helps. I'm still using 2.1 but that shouldn't be a problem for you as I get hold of the height values from terra's height array, not downloaded from the gpu.
Pretty much to include the terrain I just loop over the height data in terra and shovel them into a buffer to give to recast.
Code: Select all
void Terra::writeVertexDataToBuffer(float* bufferStart) const {
for(int y = 0; y < m_depth; y++){
for(int x = 0; x < m_width; x++){
*bufferStart++ = x * m_xzRelativeSize.x;
*bufferStart++ = m_heightMap[x + y * m_width] - (m_height / 2);
*bufferStart++ = y * m_xzRelativeSize.y;
}
}
}
void Terra::writeTriangleDataToBuffer(int offset, int* bufferStart) const {
int newWidth = m_width - 1;
int newDepth = m_depth - 1;
for(int y = 0; y < newDepth; y++){
for(int x = 0; x < newWidth; x++){
//Write out two triangles
*bufferStart++ = offset + x + y * newWidth;
*bufferStart++ = offset + x + 1 + (y+1) * newWidth;
*bufferStart++ = offset + x + 1 + y * newWidth;
*bufferStart++ = offset + x + y * newWidth;
*bufferStart++ = offset + x + 1 + (y+1) * newWidth;
*bufferStart++ = offset + x + (y+1) * newWidth;
}
}
}
Link
I'm using quite an unorthodox solution because I only include physics shapes for the nav mesh, but if terrain is the important bit then that should be fine. Please don't judge me too hard on some of this code base
, I had to de-prioritise nav meshes due to time limits so it's not exactly done yet.