Recast and Detour Integration in Panda3D

Hello everyone,
I am Ashwini Jha and this summer, I am participating in Google Summer of Code. I will be working on the integration of Recast and Detour tools in Panda3D.
The Recast process starts with constructing a voxel mold from level geometry and then casting a navigation mesh over it. And then, the generated Navigation Mesh can be used for static as well as dynamic pathfinding, subject to moving objects, using detour tool. The repository for the library is available here: https://github.com/recastnavigation/recastnavigation
Once these tools/libraries are successfully integrated with Panda3D, it would be possible for a Panda3D actor to move from the source to the destination avoiding collisions with the walls and inappropriate paths.
Currently, we are in the community bonding period as per the GSoC 2020 timeline. The coding period starts from June 1 and I will make sure to add weekly updates in here.
You can find my proposal for the same here.

6 Likes

Hello everyone
So we are over with the first week of coding period!
RecastDetour library classes were successfully built and I have drafted a PR for mentors to check.
I coded three more classes, namely “InputGeom”, “MeshLoaderObj” and “NavMeshSample”. These classes basically help in generating polymesh by using recast tools directly from Panda3D interface. A lot of help and some code as well has been taken from the “RecastDemo” provided by recastnavigation repository. This would help in generating polymesh (the walkable surfaces) for the geoms stored in NodePath.
Here is the output of polymesh shown in red. The 3D model is used from Panda3D’s sample roaming-ralph.
image image

Thanks. Will bring more updates next week. Till then, stay safe :smiley:

3 Likes

Hello everyone,

We are into the fourth week now, and closing into the first month. Last week, I rearranged all my functions and classes so that it becomes more readable, organised and clean. Now the main classes and the funtions involved in the integration of recast/detour into Panda3D are:

  • NavMesh
    • It stores the navigation mesh generated by NavMeshBuilder class.
    • It can called as an object, or more Panda3D specifically, as PT(NavMesh) object, which is Panda3D’s own Pointer declaration.
  • NavMeshBuilder
    • It takes the nodepath as input from the user.
    • It builds the polygon mesh, polygon detailed mesh and navigation mesh (which is then stored in class NavMesh).
    • It has a function to draw the polygon mesh generated, which may be helpful for the user for debugging purposes.
    • The user can set the properties of the actor, so that the NavMeshBuilder accounts for it while building the meshes.
  • NavMeshNode
    • This class inherits from PandaNode and hence allows handling of relative coordinate system.
  • NavMeshQuery
    • This class has the query functions.
    • Query functions are processed over the class NavMesh objects, which contain the generated navigation mesh.
    • Query functions include the following:
      • Given an input point, a function can return the point nearest to it and on the navigation mesh.
      • Given two input points, a function can return the array of points which form the path between those two points (this function is yet to be added).

Apart from these classes, the exposed functions are included as PUBLISHED. This now, I would be working on cleaning up of code for better readability and adjusting to Panda3D’s coding style. Also, changes are required in order to make the library available in python environment.

For all of this to happen, the mentors have really helped me a lot. So a huge shout out to them. Thank you @rdb and @moguri :smiley:

Meet you all next week!

Stay safe, Thank you.

1 Like

Hello everyone,

This week I worked on the PR.
The code was not exactly python ready. So I along with my mentors worked on making the code ready for use in python. Giving PUBLISHED access to exposed functions and members and especially, debugging while compiling the code was challenging. I was stuck many times while compiling the code to make it python ready.

Now we can access the recast tools from python environment. This feature especially amazes me. This is the first time I have worked on something where I am writing library in C++, but using it in Python. This felt so good after being successfully done. I wrote sample codes for debugging in both python and C++, but believe me, the experience of using python to call C++ libraries felt so good. It was so easy and smooth.

After doing this, I wrote test file in python for the functions coded till now. Also, I wrote a sample code in python to add to the panda3d repository and to explain how does it work.

Next task is to implement the query functions. Will complete this week probably. Till then, stay safe !

3 Likes

Hello everyone!
So its the beginning of the sixth week. The first evaluation results are out and fortunately, I made it till here. :smiley:
This week I implemented the query functions present in DetourNavMeshQuery class. There are primarily two query functions: findPath() and findStraightPath() . Both have their own uses. The implementation initially looked to be easy, but got real complex when I started coding. There were many other function calls I had to make in order to implement these two functions, and in process taking care of the variables involved.

Both the functions have their usecases. FindPath() returns the polygons present in the path corridor. Then, its over to us how we connect polygons to complete the path. FindStraightPath() directly returns array of vertices. Here I present an example for each path finding query:


The green line shows the path in both the above images. The first image makes the findPath() query while the second one makes the findStraightPath() query.
Though, on the basis of these two images, you might conclude that findStraightPath() is obviously better among the two, but trust me, you won’t always want to use findStraightPath(). You will know when you use it. :stuck_out_tongue:

Apart from this, I spent time in dividing the library into 2 separate libraries: navmeshgen and navigation. The navmeshgen library provides tool to generate the polygon mesh, detail polygon mesh and navmesh. The navigation library provides tool to further process the navmesh and make queries over it. Recast, NavMeshBuilder are included in navmeshgen while Detour, NavMesh, NavMeshNode, NavMeshQuery are included in navigation .

This week I plan to make BAM serialization possible and work on the reviews made by mentor @moguri over my PR at Github.

Will return next week with more exciting stuff. Till then, stay safe!

3 Likes

Hello everyone

So we are into Week #7 now. In the last week, we were done with integrating query functions and I had mentioned that next I would be working on BAM serialization.

So yes, BAM serialization took me some time to get the feel of, though finally I was able to implement in successfully with the help of mentors. BAM serialization gives the users and game developers ability to save the generated navmesh in their hard disk and load it from there whenever required. This can be really helpful in games as a lot of time and computational power required to generate navmesh will be saved and hence the games would load faster. So, as for this week, this was the major development done.

Where did I get stuck? Well, BAM serialization was a totally new concept for me and hence I was stuck in the process of understanding it. Once I understood the concept and how the functions implement it, then it was quite easy to code, though there were moments i got stuck while compiling after implementing BAM serialization. Mentors rescued me there. XD

For next week, I have few things on card: Writing Test Files for BAM, sample code and making more user friendly functions so that users do not have to dig deep into objects to use basic API functions. After that, a few more changes as per the PR review.

See you next week :slight_smile:

Stay Safe

1 Like

Hello everyone.

The is week 8 of the Google Summer of Code program. The last week wasn’t a lot of work done. I did add some BAM test files, added visualization function to NavMesh class similar to NavMeshBuilder class. So, now draw_nav_mesh_geom() in NavMesh class would work the same way as draw_poly_mesh_geom() in NavMeshBuilder class and can be accessed through even NavMeshNode class.
BAM test files can be found in the Tests folder. A BAM object is created and read over in the test functions to test against the original values. So these were two main things I added in the previous week.
Along with them, I have started working on the documentation. It uses Sphinx’s reStructured text (.rst) format. I have got familiar to it’s coding / formatting styles.
Also, I have added a new class NavMeshParams in the navigation library. So, the user can add custom vertices and faces to generate the navigation mesh without using the navmeshgen library. Or maybe, the user can get the navigation mesh generated using some other library and then write code to parse it into NavMesh class using NavMeshParams class.

This week I have my academic load in form of end semester university exams. So I would not able to do much for the GSoC project. I have informed my mentors @Moguri and @rdb regarding the same. So probably I would not have much to write about next week.

Still, lets see if I can complete some part of the documentation during my exams.
Till then, stay safe :slight_smile:

1 Like

Hello everyone

Another week passed and here I am with another blog.

The last week, unfortunately, was not productive as I did not contribute much to the panda3d project due to my university exams, which I mentioned in the last week’s blog. I had informed my mentors about this academic situation and they were really supportive to let me focus on my exams for one week. Thanks to them, my exams went well and now I am back to working on the project.
After my last blog, I had started working on the documentation and had written some part of python docs in Sphinx’s reStructured text format (.rst). I had also got a review on my PR by the mentor. This week I will work on the review, complete the Python Docs and then C++ docs as well. After that, I shall update the sample code as well.

See you all next week which should be much more productive than this one. XD
Thank you and Stay Safe!

1 Like

Well done on your exams, and, going by the sounds of it, good work thus far with this feature! :slight_smile:

1 Like

Hello everyone

I know I am late for the weekly blog. My apologies for that.
The previous week was my first week post my exams. I had mentioned in the last blog that I will be working on the documentation for panda3d.
So, just as I mentioned, I was able to complete the documentation part in one week. The documentation includes documentation for both python and c++, the languages supported by panda3d for game development. The appropriate code snippets have been included along with the screenshots of the corresponding output.
The challenges were to understand the reStructured text format by Sphinx ans write the code for documentation with proper identation and tags so as to build separate docs for python and c++.
You may find the Pull Request here: #71

This week I am working on the sample code. Some part of work has been done and hopefully it will be completed by the weekend. I will share more about the same in my next blog.

Thank you!

Stay Safe!

1 Like

Hi everyone

Now we are into the second last week of the Official Coding period for GSoC’20 ! The previous week was basically me involved in completing the sample code for navigation.
We selected a new environment for the sample with a better license. The previous code of the sample program was almost completely removed and a fresh code was written explaining a lot more features of the navigation and navmeshgen libraries.
Raycasting has been implemented in order to find the destination based on the position of a mouse click. So now if a mouse is clicked, then the two-dimensional position of the cursor is then used to find the corresponding three-dimensional position in the panda3d world coordinates, which is then set as new destination. Now the user can change the destination and find a new path even while an actor is already traveling on the previous path. The current position of the actor in the middle of the path will be set as starting point.

The GIF above shows the dynamic path-finding ability of the sample program. Yellow lines are the output of find_straight_path() while the green ones are output of find_path(). The panda has been programmed to move on the yellow line.

This was all for the previous week. This week I am focusing on the PR reviews so that we can have the PR merged as soon as possible.

Thank you. Stay Safe!

1 Like

That looks really good–nicely done! :slight_smile:

1 Like

Hello everyone

This is the final week of the GSoC 2020 Coding Period. It has been a great journey so far and more importantly, I got to learn a lot.
As mentioned in the previous blog, the last week was spent in resolving the PR reviews. I was able to resolve most of it.
I added docstrings for all the functions in the cxx files, added more properties to be set by the user for building the navigation mesh.
I also added a new function add_polygon() for the user to add extra polygons to the input geometry, which would then be processed as vertices and triangles to generate the navmesh. Two overloaded functions have been implemented for the same, one with three LPoint3 input arguments, i.e. a triangle polygon as input, while other with a PTA_LVecBase3 input argument, i.e. a polygon with more than two vertices as input.
I removed the unnecessary comments and debug statements from the code, cleaned it up. I used the Panda3d’s config to notify, like navigation_cat.error(), navigation_cat.info() etc. Also since panda3d’s world units need not be always Z-up, so the mentors suggested to implement a transformation matrix which would convert the points from Panda3D’s default coordinate system to Y-up coordinate system (Recast navigation’s coordinate system) and then back to Panda3D’s default.
This week, being the final week, I need to prepare for the code submission and resolve the remaining PR reviews.

It was a great summer!
Thank you! Stay safe always!
Ashwini

4 Likes

Oh, that’s cool. Does R&D work with Panda3D which I took from your repo? I see there are some commits means it’s integrated (?)