Tugcga / PyRecastDetour

Python navigation mesh library for Windows, based on recastnavigation. Can be used for generating navmesh and finding shortest path between points
12 stars 3 forks source link

Problem with load_navmesh #10

Open RedStorkKami opened 7 months ago

RedStorkKami commented 7 months ago

Hello, I'm trying to figure out Detour and Recast. I have the following problem: when I run the code in this form, everything is fine, and the bounding box dimensions are as they should be:

import sys
import recastdetour as rd

navmesh_obj = rd.Navmesh()
navmesh_obj.init_by_obj("adt_41_32.obj")
navmesh_obj.build_navmesh()
print("navmesh_obj.get_bounding_box():")
print(navmesh_obj.get_bounding_box())

navmesh_obj.get_bounding_box(): ((-5333.33349609375, -24.63961410522461, -533.3333129882812), (-4800.0, 175.50584411621094, 0.0))

If I try to load the Navmesh from a saved file, the box collapses for some reason, and the pathfinding doesn't work:

import sys
import recastdetour as rd

navmesh_obj = rd.Navmesh()
navmesh_obj.init_by_obj("adt_41_32.obj")
navmesh_obj.load_navmesh("adt_41_32.bin")

print("navmesh_obj.get_bounding_box():")
print(navmesh_obj.get_bounding_box())

navmesh_obj.get_bounding_box(): ((-6.0, 0.0, -6.0), (6.0, 0.0, 6.0))

adt_41_32.bin is exist. It was created with code

import sys
import recastdetour as rd

navmesh_obj = rd.Navmesh()
navmesh_obj.init_by_obj("adt_41_32.obj")
navmesh_obj.build_navmesh()
navmesh_obj.save_navmesh("adt_41_32.bin")
Tugcga commented 7 months ago

It's not a bug, it's a feature.

The method get_bounding_box() return bounding box of the level geometry, but not of the navigation mesh. When you define navmesh from *.bin file, then the geometry in fact is not defined. So, the result of getting bounding box is invalid. Under the hood when you call load_navmesh, it init the geometry by simple plane (because it required to define some inner states of the new navmesh object). That's why it return the bounding box with the size +-6.0.