Skip to content

added navigation in programming #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 1.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions programming/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ manual by studying the :ref:`Reference Section <reference>`.
threading
subclassing
pandai/index
navigation/index
using-cpp/index
66 changes: 66 additions & 0 deletions programming/navigation/bam-serialization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.. _bam-serialization:

BAM serialization
=================

Panda3D provides the feature to write the Panda3D objects to the disk
using the BAM operations. In the navigation library, the BAM operations have
been implemented over the NavMeshNode class.

.. only:: python

.. code-block:: python

navmeshnode = navigation.NavMeshNode("firstnavmeshnode", navmesh)
navmeshnodepath = scene.attach_new_node(navmeshnode)

.. only:: cpp

.. code-block:: cpp

NavMeshNode navmeshnode = new NavMeshNode("firstnavmeshnode", navmesh);
NodePath navmeshnodepath = scene.attach_new_node(navmeshnode);


Write BAM
~~~~~~~~~

You can write the 'navmeshnodepath' to the disk as a BAM file.

.. only:: python

.. code-block:: python

navmeshnodepath.write_bam_file("firstnavmeshnode.bam")

.. only:: cpp

.. code-block:: cpp

navmeshnodepath.write_bam_file("firstnavmeshnode.bam");

The BAM File 'firstnavmeshnode.bam' is stored on the disk and can be used directly
in the games or the programs without building and navigation mesh again. This
helps in saving time and computation power.

Read BAM
~~~~~~~~

You can read the BAM File from the disk and load it as NodePath to NavMeshNode.

.. only:: python

.. code-block:: python

navmesh = loader.load_model("firstnavmeshnode.bam")

.. only:: cpp

.. code-block:: cpp

PandaFramework framework;
framework.open_framework(argc, argv);
framework.set_window_title("My Panda3D Window");
WindowFramework *window = framework.open_window();
NodePath navmesh = window->load_model(framework.get_models(), "firstnavmeshnode.bam");

111 changes: 111 additions & 0 deletions programming/navigation/build-mesh.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
.. _build-mesh:

Building Navigation Mesh
========================

Implementation:

Following are the steps to build a basic navigation mesh.

Step 1:

.. only:: python

To use the navmeshgen library into your game you need to import it into your game code.
The generated mesh is stored as an object of class NavMesh, which can be accessed by importing navigation.

.. code-block:: python

from panda3d import navmeshgen
from panda3d import navigation

.. only:: cpp

The headers required to be included for building mesh are navMeshBuilder and navMesh.

.. code-block:: cpp

#include "pandaFramework.h"
#include "pandaSystem.h"
#include "navMesh.h"
#include "navMeshBuilder.h"

Step 2:

Create a geom primitive or load an external model. Here we load the model called 'village.obj'

.. only:: python

.. code-block:: python

scene = loader.load_model("samples/navigation/models/village.obj")

.. only:: cpp

.. code-block:: cpp

PandaFramework framework;
framework.open_framework(argc, argv);
framework.set_window_title("My Panda3D Window");
WindowFramework *window = framework.open_window();
NodePath scene = window->load_model(framework.get_models(), "samples/navigation/models/village.obj");

Now the model is loaded in the NodePath 'scene'

Step 3:

Create an object for the class NavMeshBuilder via:

.. only:: python

.. code-block:: python

builder = navmeshgen.NavMeshBuilder()

.. only:: cpp

.. code-block:: cpp

NavMeshBuilder builder = new NavMeshBuilder()

Step 4:

Now, we shall build the navigation mesh for our model stored in NodePath 'scene'.

.. only:: python

.. code-block:: python

builder.from_node_path(scene)

.. only:: cpp

.. code-block:: cpp

builder.from_node_path(scene)

Step 5:

Finally, we build the navigation mesh using the build function.
The output mesh is stored as an object of class NavMesh.

.. only:: python

.. code-block:: python

navmesh = builder.build()

.. only:: cpp

.. code-block:: cpp

PT(NavMesh) navmesh = builder.build()

Here, 'navmesh' is the object of class NavMesh and has the generated mesh.

This is how easy it is to get a basic navigation mesh generated!

Next Step:

Now that you have a basic working program, you should proceed to the
parameters page and see how navigation mesh varies with parameters.
14 changes: 14 additions & 0 deletions programming/navigation/getting-started.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. _getting-started:

Getting Started
===============

Navigation and Navmeshgen are two libraries which can be used together to perform fast pathfinding operations on Panda3d geoms.

To use the navmeshgen library into your game you need to import it into your game
code.
The generated mesh is stored as an object of class NavMesh, which can be accessed by importing navigation.

The navmeshgen library has the class NavMeshBuilder, the main operation of which is to build the navigation mesh.
The navigation library has the class NavMesh, which stores the mesh build by NavMeshBuilder or some other library.
It has also has class NavMeshQuery, which is responsible for handling the query operations like pathfinding over the mesh.
21 changes: 21 additions & 0 deletions programming/navigation/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. _navigation:

Pathfinding using Navigation
============================

Panda3D is integrated with the Recast-Detour library as navmeshgen and navigation libraries.

Navmeshgen is an AI library for Panda3D which, for a given geom, generates a navigation mesh, a mesh containing only the walkable surfaces.

Navigation is an AI library for Panda3D which operates on an input navigation mesh. The input navigation can be generated using navmeshgen library or by the user's preferred external library. The navigation library lets us query over the navigation mesh and find the path between any two points over the mesh.


.. toctree::
:maxdepth: 2

getting-started
build-mesh
set-actor-parameters
visualize-mesh
path-query
bam-serialization
Binary file added programming/navigation/navmesh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading