SDK terrain2mesh()

Does anyone know why the method terrain2mesh() in the SDK intentionally offsets the navMesh in the X and Z directions by .5f?

1 Like

Maybe I should clarify this.

getTerrainSize() returns the size of the terrain.

TerrainQuads size are a power of 2, plus 1.

trans.x -= terr.getTerrainSize() / 2f; will always return 0.5f larger than the actual size of the terrain due to the plus 1, thereby offsetting the navMesh by 0.5f.

Why does the navMesh need to be offset?

1 Like

My guess would have been that x -= size / 2f would try to center something.
Like when you have a quad whose origin is the upper left corner, you can transform it to have your origin be the center of the quad.

Maybe that’s what is done?

1 Like

Yes, but if you look at the return of getTerrainSize(), its always going to move the mesh off center an additional 0.5f in the X and Z directions because of what I wrote before about not accounting for the plus 1 being added.

writing this,
trans.x -= (terr.getTerrainSize() - 1) / 2f;
trans.z -= (terr.getTerrainSize() - 1)/ 2f;

perfectly centers the mesh.

Just wasn’t sure if this was a bug or if this is intentional.