Tugcga / Path-Finder

Python and AssemblyScript implementations of path finding and collision avoidance algorithms in navigation meshes
25 stars 6 forks source link

error in bake: list index out of range #17

Open lhmd opened 3 months ago

lhmd commented 3 months ago

I have met this problem in baking:

Traceback (most recent call last):
  File "test.py", line 85, in <module>
    baker.bake(
  File "/mnt/data3/home/wangweijie/miniconda3/envs/text2motion/lib/python3.8/site-packages/pathfinder/navmesh_baker/__init__.py", line 142, in bake
    is_build_contours = build_contours(chf, max_simplification_error, max_edge_len, cset)
  File "/mnt/data3/home/wangweijie/miniconda3/envs/text2motion/lib/python3.8/site-packages/pathfinder/navmesh_baker/rc_contour.py", line 814, in build_contours
    cont: Contour = cset.conts[cset.nconts]
IndexError: list index out of range

This is my code:

    baker = nmb.NavmeshBaker()
    scene.apply_transform(zup_to_shapenet)
    vert_wo_color = scene.vertices.tolist()
    vert_wo_color = [tuple(vert) for vert in vert_wo_color]
    scene_face = scene.faces.tolist()
    # print(len(vert_wo_color), len(scene_face))
    baker.add_geometry(vert_wo_color, scene_face)
    baker.bake(
        verts_per_poly=3,
        cell_size=0.05, cell_height=0.05,
        agent_radius=0.05, agent_height=0.5, 
        agent_max_climb=0.1, agent_max_slope=15.0,
        # region_min_size=8, region_merge_size=20
    )

While some scenes is ok, but a few of scenes will meet this problem, I don't understand how it occur. Can everyone help me?

Tugcga commented 3 months ago

It will be better if you send me data with vertex coordinates and polygons of your scene. May be by using simple txt-file. I will try to understand, why it happens and is you PR is solve the problem.

lhmd commented 3 months ago

Sorry for not replying to you two days ago for some other personal reasons. I am attaching the code I used and the file used to generate the navmesh so you can try to reproduce my error. I haven't analysed the exact cause yet, but I think it's due to mishandling of the conts in the rc_contour.py file. I hope you will keep me informed if you have any new developments. Thank you very much for your attention!

The .ply file in the reply email just now was too big, I put it on google drive, please check it out. https://drive.google.com/file/d/1QX8TfoTbCVgMsoNid7lzeuk_iBl_jk1E/view?usp=sharing

Tugcga @.***> 于2024年5月21日周二 23:15写道:

It will be better if you send me data with vertex coordinates and polygons of your scene. May be by using simple txt-file. I will try to understand, why it happens and is you PR is solve the problem.

— Reply to this email directly, view it on GitHub https://github.com/Tugcga/Path-Finder/issues/17#issuecomment-2122867117, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVRNIZYKJRSPLK5EPNYHF5LZDNQKRAVCNFSM6AAAAABIBQO6ICVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRSHA3DOMJRG4 . You are receiving this because you authored the thread.Message ID: @.***>

lhmd commented 3 months ago

It will be better if you send me data with vertex coordinates and polygons of your scene. May be by using simple txt-file. I will try to understand, why it happens and is you PR is solve the problem.

For privacy reasons, I've sent you the data and code I'm using using using email, so please check out. I haven't analysed the exact cause yet, but I think it's due to mishandling of the conts in the rc_contour.py file. Thank you very much for your attention!

Tugcga commented 3 months ago

Thank you very much. I need some time for research.

Tugcga commented 3 months ago

I am sorry for delay of the answer, but I finally find the time to check the bug. And I fail to reproduce it. This is your original model level_original It has some rotation and the baking process return an empty mesh.

After rotation it looks like this level_tfm

Then I bake the navmesh with your parameters:

baker.bake(verts_per_poly=3,
               cell_size=0.05,
               cell_height=0.05,
               agent_radius=0.05,
               agent_height=0.5,
               agent_max_climb=0.1,
               agent_max_slope=15.0)

and obtain the mesh without any errors (selected mesh on the screen) level_navmesh

The navmesh contains 134 vertices and 124 triangles.