Browse Source

Divided into 2 libraries

Ashwini Jha 5 years ago
parent
commit
1fdad6193f
31 changed files with 707 additions and 134 deletions
  1. 62 26
      makepanda/makepanda.py
  2. 22 16
      makepanda/makepanda.vcproj
  3. 0 1
      panda/src/navigation/config_navigation.cxx
  4. 229 4
      panda/src/navigation/navMesh.cxx
  5. 16 3
      panda/src/navigation/navMesh.h
  6. 72 0
      panda/src/navigation/navMeshNode.cxx
  7. 10 1
      panda/src/navigation/navMeshNode.h
  8. 160 5
      panda/src/navigation/navMeshQuery.cxx
  9. 17 3
      panda/src/navigation/navMeshQuery.h
  10. 0 1
      panda/src/navigation/p3navigation_composite1.cxx
  11. 0 0
      panda/src/navmeshgen/Recast/CMakeLists.txt
  12. 0 0
      panda/src/navmeshgen/Recast/Include/Recast.h
  13. 0 0
      panda/src/navmeshgen/Recast/Include/RecastAlloc.h
  14. 0 0
      panda/src/navmeshgen/Recast/Include/RecastAssert.h
  15. 0 0
      panda/src/navmeshgen/Recast/Source/Recast.cpp
  16. 0 0
      panda/src/navmeshgen/Recast/Source/RecastAlloc.cpp
  17. 0 0
      panda/src/navmeshgen/Recast/Source/RecastArea.cpp
  18. 0 0
      panda/src/navmeshgen/Recast/Source/RecastAssert.cpp
  19. 0 0
      panda/src/navmeshgen/Recast/Source/RecastContour.cpp
  20. 0 0
      panda/src/navmeshgen/Recast/Source/RecastFilter.cpp
  21. 0 0
      panda/src/navmeshgen/Recast/Source/RecastLayers.cpp
  22. 0 0
      panda/src/navmeshgen/Recast/Source/RecastMesh.cpp
  23. 0 0
      panda/src/navmeshgen/Recast/Source/RecastMeshDetail.cpp
  24. 0 0
      panda/src/navmeshgen/Recast/Source/RecastRasterization.cpp
  25. 0 0
      panda/src/navmeshgen/Recast/Source/RecastRegion.cpp
  26. 49 0
      panda/src/navmeshgen/config_navmeshgen.cxx
  27. 30 0
      panda/src/navmeshgen/config_navmeshgen.h
  28. 29 66
      panda/src/navmeshgen/navMeshBuilder.cxx
  29. 2 8
      panda/src/navmeshgen/navMeshBuilder.h
  30. 1 0
      panda/src/navmeshgen/p3navmeshgen_composite1.cxx
  31. 8 0
      panda/src/pandabase/pandasymbols.h

+ 62 - 26
makepanda/makepanda.py

@@ -95,7 +95,8 @@ PkgListSet(["PYTHON", "DIRECT",                        # Python support
   "PANDAPARTICLESYSTEM",                               # Built in particle system
   "CONTRIB",                                           # Experimental
   "SSE2", "NEON",                                      # Compiler features
-  "NAVIGATION",				       # Recast Detour Toolset
+  "NAVIGATION",				       # Detour Toolset
+  "NAVMESHGEN",                    # Recast Toolset
 ])
 
 CheckPandaSourceTree()
@@ -2642,6 +2643,8 @@ if not PkgSkip("VISION"):
     panda_modules.append('vision')
 if not PkgSkip("NAVIGATION"):
     panda_modules.append('navigation')
+if not PkgSkip("NAVMESHGEN"):
+    panda_modules.append('navmeshgen')
 if not PkgSkip("SKEL"):
     panda_modules.append('skel')
 if not PkgSkip("EGG"):
@@ -3048,8 +3051,11 @@ CopyAllHeaders('panda/src/grutil')
 if (PkgSkip("VISION")==0):
     CopyAllHeaders('panda/src/vision')
 if (PkgSkip("NAVIGATION")==0):
-    CopyAllHeaders('panda/src/navigation/Recast/Include')
     CopyAllHeaders('panda/src/navigation/Detour/Include')
+    CopyAllHeaders('panda/src/navigation')
+if (PkgSkip("NAVMESHGEN")==0):
+    CopyAllHeaders('panda/src/navmeshgen/Recast/Include')
+    CopyAllHeaders('panda/src/navmeshgen')
 if (PkgSkip("FFMPEG")==0):
     CopyAllHeaders('panda/src/ffmpeg')
 CopyAllHeaders('panda/src/tform')
@@ -4141,19 +4147,7 @@ if (PkgSkip("NAVIGATION") == 0):
   TargetAdd('p3navigation_DetourNavMeshBuilder.obj', opts=OPTS,  input='DetourNavMeshBuilder.cpp')
   TargetAdd('p3navigation_DetourNavMeshQuery.obj', opts=OPTS,  input='DetourNavMeshQuery.cpp')
   TargetAdd('p3navigation_DetourNode.obj', opts=OPTS,  input='DetourNode.cpp')
-  OPTS=['DIR:panda/src/navigation/Recast/Source', 'BUILDING:NAVIGATION']
-  TargetAdd('p3navigation_Recast.obj', opts=OPTS,  input='Recast.cpp')
-  TargetAdd('p3navigation_RecastAlloc.obj', opts=OPTS,  input='RecastAlloc.cpp')
-  TargetAdd('p3navigation_RecastArea.obj', opts=OPTS,  input='RecastArea.cpp')
-  TargetAdd('p3navigation_RecastAssert.obj', opts=OPTS,  input='RecastAssert.cpp')
-  TargetAdd('p3navigation_RecastContour.obj', opts=OPTS,  input='RecastContour.cpp')
-  TargetAdd('p3navigation_RecastFilter.obj', opts=OPTS,  input='RecastFilter.cpp')
-  TargetAdd('p3navigation_RecastLayers.obj', opts=OPTS,  input='RecastLayers.cpp')
-  TargetAdd('p3navigation_RecastMesh.obj', opts=OPTS,  input='RecastMesh.cpp')
-  TargetAdd('p3navigation_RecastMeshDetail.obj', opts=OPTS,  input='RecastMeshDetail.cpp')
-  TargetAdd('p3navigation_RecastRasterization.obj', opts=OPTS,  input='RecastRasterization.cpp')
-  TargetAdd('p3navigation_RecastRegion.obj', opts=OPTS,  input='RecastRegion.cpp')
-
+  
   TargetAdd('libp3navigation.dll', input='p3navigation_composite1.obj')
   TargetAdd('libp3navigation.dll', input='p3navigation_DetourAlloc.obj')
   TargetAdd('libp3navigation.dll', input='p3navigation_DetourAssert.obj')
@@ -4162,17 +4156,7 @@ if (PkgSkip("NAVIGATION") == 0):
   TargetAdd('libp3navigation.dll', input='p3navigation_DetourNavMeshBuilder.obj')
   TargetAdd('libp3navigation.dll', input='p3navigation_DetourNavMeshQuery.obj')
   TargetAdd('libp3navigation.dll', input='p3navigation_DetourNode.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_Recast.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastAlloc.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastArea.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastAssert.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastContour.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastFilter.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastLayers.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastMesh.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastMeshDetail.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastRasterization.obj')
-  TargetAdd('libp3navigation.dll', input='p3navigation_RecastRegion.obj')
+  
   TargetAdd('libp3navigation.dll', input=COMMON_PANDA_LIBS)
   OPTS=['DIR:panda/src/navigation', 'BUILDING:NAVIGATION']
   TargetAdd('libp3navigation.dll', opts=OPTS)
@@ -4193,6 +4177,58 @@ if (PkgSkip("NAVIGATION") == 0):
   PyTargetAdd('navigation.pyd', input='libp3interrogatedb.dll')
   PyTargetAdd('navigation.pyd', input=COMMON_PANDA_LIBS)
 
+#
+# DIRECTORY: panda/src/navmeshgen/
+#
+
+if (PkgSkip("NAVMESHGEN") == 0):
+  OPTS=['DIR:panda/src/navmeshgen', 'BUILDING:NAVMESHGEN']
+  TargetAdd('p3navmeshgen_composite1.obj', opts=OPTS, input='p3navmeshgen_composite1.cxx')
+  OPTS=['DIR:panda/src/navmeshgen/Recast/Source', 'BUILDING:NAVMESHGEN']
+  TargetAdd('p3navmeshgen_Recast.obj', opts=OPTS,  input='Recast.cpp')
+  TargetAdd('p3navmeshgen_RecastAlloc.obj', opts=OPTS,  input='RecastAlloc.cpp')
+  TargetAdd('p3navmeshgen_RecastArea.obj', opts=OPTS,  input='RecastArea.cpp')
+  TargetAdd('p3navmeshgen_RecastAssert.obj', opts=OPTS,  input='RecastAssert.cpp')
+  TargetAdd('p3navmeshgen_RecastContour.obj', opts=OPTS,  input='RecastContour.cpp')
+  TargetAdd('p3navmeshgen_RecastFilter.obj', opts=OPTS,  input='RecastFilter.cpp')
+  TargetAdd('p3navmeshgen_RecastLayers.obj', opts=OPTS,  input='RecastLayers.cpp')
+  TargetAdd('p3navmeshgen_RecastMesh.obj', opts=OPTS,  input='RecastMesh.cpp')
+  TargetAdd('p3navmeshgen_RecastMeshDetail.obj', opts=OPTS,  input='RecastMeshDetail.cpp')
+  TargetAdd('p3navmeshgen_RecastRasterization.obj', opts=OPTS,  input='RecastRasterization.cpp')
+  TargetAdd('p3navmeshgen_RecastRegion.obj', opts=OPTS,  input='RecastRegion.cpp')
+
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_composite1.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_Recast.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastAlloc.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastArea.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastAssert.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastContour.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastFilter.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastLayers.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastMesh.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastMeshDetail.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastRasterization.obj')
+  TargetAdd('libp3navmeshgen.dll', input='p3navmeshgen_RecastRegion.obj')
+  TargetAdd('libp3navmeshgen.dll', input='libp3navigation.dll')
+  TargetAdd('libp3navmeshgen.dll', input=COMMON_PANDA_LIBS)
+  OPTS=['DIR:panda/src/navmeshgen', 'BUILDING:NAVMESHGEN']
+  TargetAdd('libp3navmeshgen.dll', opts=OPTS)
+
+  OPTS=['DIR:panda/src/navmeshgen']
+  IGATEFILES=GetDirectoryContents('panda/src/navmeshgen', ["*.h", "*_composite*.cxx"])
+  TargetAdd('libp3navmeshgen.in', opts=OPTS, input=IGATEFILES)
+  TargetAdd('libp3navmeshgen.in', opts=['IMOD:panda3d.navmeshgen', 'ILIB:libp3navmeshgen', 'SRCDIR:panda/src/navmeshgen'])
+
+
+  PyTargetAdd('navmeshgen_module.obj', input='libp3navmeshgen.in')
+  PyTargetAdd('navmeshgen_module.obj', opts=OPTS)
+  PyTargetAdd('navmeshgen_module.obj', opts=['IMOD:panda3d.navmeshgen', 'ILIB:navmeshgen', 'IMPORT:panda3d.core'])
+
+  PyTargetAdd('navmeshgen.pyd', input='navmeshgen_module.obj')
+  PyTargetAdd('navmeshgen.pyd', input='libp3navmeshgen_igate.obj')
+  PyTargetAdd('navmeshgen.pyd', input='libp3navmeshgen.dll')
+  PyTargetAdd('navmeshgen.pyd', input='libp3interrogatedb.dll')
+  PyTargetAdd('navmeshgen.pyd', input=COMMON_PANDA_LIBS)
 
 #
 # DIRECTORY: panda/src/p3skel

+ 22 - 16
makepanda/makepanda.vcproj

@@ -651,8 +651,6 @@
 			<Filter Name="navigation">
 				<File RelativePath="..\panda\src\navigation\navMesh.cxx"></File>
 				<File RelativePath="..\panda\src\navigation\navMesh.h"></File>
-				<File RelativePath="..\panda\src\navigation\navMeshBuilder.cxx"></File>
-				<File RelativePath="..\panda\src\navigation\navMeshBuilder.h"></File>
 				<File RelativePath="..\panda\src\navigation\navMeshNode.cxx"></File>
 				<File RelativePath="..\panda\src\navigation\navMeshNode.h"></File>
 				<File RelativePath="..\panda\src\navigation\navMeshQuery.cxx"></File>
@@ -673,24 +671,32 @@
 				<File RelativePath="..\panda\src\navigation\Detour\Include\DetourNavMeshQuery.h"></File>
 				<File RelativePath="..\panda\src\navigation\Detour\Include\DetourNode.h"></File>
 				<File RelativePath="..\panda\src\navigation\Detour\Include\DetourStatus.h"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\Recast.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastAlloc.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastArea.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastAssert.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastContour.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastFilter.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastLayers.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastMesh.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastMeshDetail.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastRasterization.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Source\RecastRegion.cpp"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Include\Recast.h"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Include\RecastAlloc.h"></File>
-				<File RelativePath="..\panda\src\navigation\Recast\Include\RecastAssert.h"></File>
 				<File RelativePath="..\panda\src\navigation\navigation_composite1.cxx"></File>
 				<File RelativePath="..\panda\src\navigation\config_navigation.cxx"></File>
 				<File RelativePath="..\panda\src\navigation\config_navigation.h"></File>
 			</Filter>
+
+			<Filter Name="navmeshgen">
+				<File RelativePath="..\panda\src\navmeshgen\navMeshBuilder.cxx"></File>
+				<File RelativePath="..\panda\src\navmeshgen\navMeshBuilder.h"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\Recast.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastAlloc.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastArea.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastAssert.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastContour.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastFilter.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastLayers.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastMesh.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastMeshDetail.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastRasterization.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Source\RecastRegion.cpp"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Include\Recast.h"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Include\RecastAlloc.h"></File>
+				<File RelativePath="..\panda\src\navmeshgen\Recast\Include\RecastAssert.h"></File>
+				<File RelativePath="..\panda\src\navmeshgen\navmeshgen_composite1.cxx"></File>
+				<File RelativePath="..\panda\src\navmeshgen\config_navmeshgen.cxx"></File>
+				<File RelativePath="..\panda\src\navmeshgen\config_navmeshgen.h"></File>
+			</Filter>
 			<Filter Name="gobj">
 				<File RelativePath="..\panda\src\gobj\geomEnums.cxx"></File>
 				<File RelativePath="..\panda\src\gobj\geomContext.h"></File>

+ 0 - 1
panda/src/navigation/config_navigation.cxx

@@ -16,7 +16,6 @@
 #include "pandaSystem.h"
 #include "dconfig.h"
 #include "navMesh.h"
-#include "navMeshBuilder.h"
 #include "navMeshNode.h"
 #include "navMeshQuery.h"
 

+ 229 - 4
panda/src/navigation/navMesh.cxx

@@ -15,18 +15,243 @@
 #include "navMesh.h"
 #include "geom.h"
 #include "geomTrifans.h"
+#include <iostream>
 
 TypeHandle NavMesh::_type_handle;
 
-NavMesh::NavMesh() {
-
-}
+NavMesh::NavMesh():
+  _nav_mesh(0) {}
 
 NavMesh::~NavMesh() {
-  
+  dtFreeNavMesh(_nav_mesh);
+  _nav_mesh = 0;
 }
 
 NavMesh::NavMesh(dtNavMesh *nav_mesh) {
   _nav_mesh = nav_mesh;
 }
 
+bool NavMesh::init_nav_mesh() {
+	unsigned char *nav_data = 0;
+  int nav_data_size = 0;
+
+  if (!dtCreateNavMeshData(&params, &nav_data, &nav_data_size)) {
+    std::cout<<"\nCould not build Detour navmesh.\n";
+    return false;
+  }
+
+  _nav_mesh = dtAllocNavMesh();
+
+  if (!_nav_mesh) {
+    dtFree(nav_data);
+    std::cout<<"\nCould not create Detour navmesh\n";
+    return false;
+  }
+
+  dtStatus status;
+
+  status = _nav_mesh->init(nav_data, nav_data_size, DT_TILE_FREE_DATA);
+  if (dtStatusFailed(status)) {
+    dtFree(nav_data);
+    std::cout<<"\nCould not init Detour navmesh\n";
+    return false;
+  }
+}
+
+/**
+ * Tells the BamReader how to create objects of type NavMesh.
+ */
+void NavMesh::
+register_with_read_factory() {
+  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
+}
+
+/**
+ * Writes the contents of this object to the datagram for shipping out to a
+ * Bam file.
+ */
+void NavMesh::
+write_datagram(BamWriter *manager, Datagram &dg) {
+  NavMesh::write_datagram(manager, dg);
+  
+  dg.add_int32(params.vertCount);
+  dg.add_int32(params.polyCount);
+  dg.add_int32(params.nvp);
+  dg.add_int32(params.detailVertsCount);
+  dg.add_int32(params.detailTriCount);
+  dg.add_float32(params.walkableHeight);
+  dg.add_float32(params.walkableRadius);
+  dg.add_float32(params.walkableClimb);
+  dg.add_float32(params.cs);
+  dg.add_float32(params.ch);
+  dg.add_bool(params.buildBvTree);
+
+  //the bmin and bmax values
+  for(int i=0;i<3;i++) {
+    dg.add_float32(params.bmin[i]);
+  }
+  for(int i=0;i<3;i++) {
+    dg.add_float32(params.bmax[i]);
+  }
+  
+  //POLYGON MESH ATTRIBUTES
+
+  //the vertices
+  for(int i=0 ; i < (params.vertCount) * 3 ; i++) {
+    dg.add_uint16(params.verts[i]);
+  }
+
+  //the polygon data
+  for(int i=0 ; i < (params.polyCount) * 2 * (params.nvp) ;i++) {
+    dg.add_uint16(params.polys[i]);
+  }
+
+  //the polygon flags
+  for(int i=0 ; i < params.polyCount ;i++) {
+    dg.add_uint16(params.polyFlags[i]);
+  }
+
+  //the polygon area IDs
+  for(int i=0 ; i < params.polyCount ;i++) {
+    dg.add_uint8(params.polyAreas[i]);           
+  }
+  
+  //POLYGON MESH DETAIL ATTRIBUTES
+
+  //height detail sub-mesh data
+  for(int i=0 ; i < (params.polyCount) * 4 ;i++) {
+    dg.add_uint32(params.detailMeshes[i]);
+  }
+
+  //detail mesh vertices
+  for(int i=0 ; i < (params.detailVertsCount) * 3 ;i++) {
+    dg.add_float32(params.detailVerts[i]);
+  }
+
+  //detail mesh vertices
+  for(int i=0 ; i < (params.detailTriCount) * 4 ;i++) {
+    dg.add_uint8(params.detailTris[i]);
+  }
+
+}
+
+/**
+ * This function is called by the BamReader's factory when a new object of
+ * type NavMesh is encountered in the Bam file.  It should create the
+ * NavMesh and extract its information from the file.
+ */
+TypedWritable *NavMesh::
+make_from_bam(const FactoryParams &params) {
+  NavMesh *param = new NavMesh;
+  DatagramIterator scan;
+  BamReader *manager;
+
+  parse_params(params, scan, manager);
+  param->fillin(scan, manager);
+
+  return param;
+}
+
+/**
+ * This internal function is called by make_from_bam to read in all of the
+ * relevant data from the BamFile for the new NavMesh.
+ */
+void NavMesh::
+fillin(DatagramIterator &scan, BamReader *manager) {
+  NavMesh::fillin(scan, manager);
+  
+  int vert_count = scan.get_int32();
+  int poly_count = scan.get_int32();
+  int nvp = scan.get_int32();
+  int detail_vert_count = scan.get_int32();
+  int detail_tri_count = scan.get_int32();
+  float walkable_height = scan.get_float32();
+  float walkable_radius = scan.get_float32();
+  float walkable_climb = scan.get_float32();
+  float cs = scan.get_float32();
+  float ch = scan.get_float32();
+  bool build_bv_tree = scan.get_bool();
+
+  float b_min[3];
+  for(int i=0;i<3;i++) {
+    b_min[i] = scan.get_float32();
+  }
+  float b_max[3];
+  for(int i=0;i<3;i++) {
+    b_max[i] = scan.get_float32();
+  }
+
+  //POLYGON MESH ATTRIBUTES
+
+  unsigned short* verts = new unsigned short[3 * vert_count];
+  for(int i=0 ; i < 3 * vert_count ; i++) {
+    verts[i] = scan.get_uint16();
+  }
+
+  unsigned short* polys = new unsigned short[poly_count * 2 * nvp];
+  for(int i=0 ; i < poly_count * 2 * nvp ; i++) {
+    polys[i] = scan.get_uint16();
+  }
+
+  unsigned short* poly_flags = new unsigned short[poly_count];
+  for(int i=0 ; i < poly_count; i++) {
+    poly_flags[i] = scan.get_uint16();
+  }
+
+  unsigned char* poly_areas = new unsigned char[poly_count];
+  for(int i=0 ; i < poly_count; i++) {
+    poly_areas[i] = scan.get_uint8();
+  }
+
+  //POLYGON MESH DETAIL ATTRIBUTES
+
+  unsigned int* detail_meshes = new unsigned int[poly_count * 4];
+  for(int i=0 ; i < poly_count * 4 ;i++) {
+    detail_meshes[i] = scan.get_uint32();
+  }
+
+  float* detail_verts = new float[detail_vert_count * 3];
+  for(int i=0 ; i < detail_vert_count * 3 ;i++) {
+    detail_verts[i] = scan.get_float32();
+  }
+
+  unsigned char* detail_tris = new unsigned char[detail_tri_count * 4];
+  for(int i=0 ; i < detail_tri_count * 4 ;i++) {
+    detail_tris[i] = scan.get_uint8();
+  }
+
+  memset(&(params), 0, sizeof(params));
+
+  params.verts = verts;
+  params.vertCount = vert_count;
+  params.polys = polys;
+  params.polyAreas = poly_areas;
+  params.polyFlags = poly_flags;
+  params.polyCount = poly_count;
+  params.nvp = nvp;
+  params.detailMeshes = detail_meshes;
+  params.detailVerts = detail_verts;
+  params.detailVertsCount = detail_vert_count;
+  params.detailTris = detail_tris;
+  params.detailTriCount = detail_tri_count;
+
+
+  params.walkableHeight = walkable_height;
+  params.walkableRadius = walkable_radius;
+  params.walkableClimb = walkable_climb;
+
+  params.bmin[0] = b_min[0];
+  params.bmin[1] = b_min[1];
+  params.bmin[2] = b_min[2];
+  params.bmax[0] = b_max[0];
+  params.bmax[1] = b_max[1];
+  params.bmax[2] = b_max[2];
+  
+  params.cs = cs;
+  params.ch = ch;
+  params.buildBvTree = build_bv_tree;
+
+  init_nav_mesh();
+
+
+}

+ 16 - 3
panda/src/navigation/navMesh.h

@@ -15,9 +15,11 @@
 #ifndef NAVMESH_H
 #define NAVMESH_H
 
-#include "Recast.h"
 #include "DetourNavMesh.h"
+#include "DetourNavMeshBuilder.h"
 #include "typedWritableReferenceCount.h"
+#include "pandaFramework.h"
+#include "pandaSystem.h"
 
 class EXPCL_NAVIGATION NavMesh: public TypedWritableReferenceCount
 {
@@ -30,8 +32,9 @@ private:
   dtNavMesh *_nav_mesh;
   
 public:
-  
-  
+  bool init_nav_mesh();
+  dtNavMesh *get_nav_mesh() { return _nav_mesh; }
+  dtNavMeshCreateParams params;
   ~NavMesh();
   
 
@@ -51,6 +54,16 @@ public:
 
 private:
   static TypeHandle _type_handle;
+
+public:
+  static void register_with_read_factory();
+  virtual void write_datagram(BamWriter *manager, Datagram &dg);
+
+protected:
+  static TypedWritable *make_from_bam(const FactoryParams &params);
+  void fillin(DatagramIterator &scan, BamReader *manager);
 };
 
+
+
 #endif // NAVMESH_H

+ 72 - 0
panda/src/navigation/navMeshNode.cxx

@@ -22,8 +22,80 @@ NavMeshNode::NavMeshNode(const std::string &name, PT(NavMesh) nav_mesh):
   _nav_mesh = nav_mesh;
 }
 
+NavMeshNode::NavMeshNode(const std::string &name):
+ PandaNode(name) {}
+
 NavMeshNode::~NavMeshNode() {
   
 }
 
 
+/**
+ * Tells the BamReader how to create objects of type BulletTriangleMeshShape.
+ */
+void NavMeshNode::
+register_with_read_factory() {
+  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
+}
+
+/**
+ * Writes the contents of this object to the datagram for shipping out to a
+ * Bam file.
+ */
+void NavMeshNode::
+write_datagram(BamWriter *manager, Datagram &dg) {
+  PandaNode::write_datagram(manager, dg);
+
+  manager->write_pointer(dg, _nav_mesh);
+  // Write NULL pointer to indicate the end of the list.
+  manager->write_pointer(dg, nullptr);
+
+}
+
+/**
+ * Receives an array of pointers, one for each time manager->read_pointer()
+ * was called in fillin(). Returns the number of pointers processed.
+ */
+int NavMeshNode::
+complete_pointers(TypedWritable **p_list, BamReader *manager) {
+  int pi = PandaNode::complete_pointers(p_list, manager);
+
+  _nav_mesh = DCAST(NavMesh, p_list[pi++]);
+
+  return pi;
+}
+
+// /**
+//  * This function is called by the BamReader's factory when a new object of
+//  * type BulletShape is encountered in the Bam file.  It should create the
+//  * BulletShape and extract its information from the file.
+//  */
+// TypedWritable *NavMeshNode::
+// make_from_bam(const FactoryParams &params) {
+//   string s = "FromBam"
+//   NavMeshNode *param = new NavMeshNode(s);
+//   DatagramIterator scan;
+//   BamReader *manager;
+
+//   parse_params(params, scan, manager);
+//   param->fillin(scan, manager);
+
+//   return param;
+// }
+
+/**
+ * This internal function is called by make_from_bam to read in all of the
+ * relevant data from the BamFile for the new BulletTriangleMeshShape.
+ */
+void NavMeshNode::
+fillin(DatagramIterator &scan, BamReader *manager) {
+  PandaNode::fillin(scan, manager);
+
+ 
+
+  manager->read_pointer(scan);
+
+  
+}
+
+

+ 10 - 1
panda/src/navigation/navMeshNode.h

@@ -29,7 +29,7 @@ private:
   PT(NavMesh) _nav_mesh;
 
 public:
-  
+  NavMeshNode(const std::string &name);
   ~NavMeshNode();
 
 public:
@@ -49,6 +49,15 @@ public:
 private:
   static TypeHandle _type_handle;
 
+public:
+  static void register_with_read_factory();
+  virtual void write_datagram(BamWriter *manager, Datagram &dg);
+  virtual int complete_pointers(TypedWritable **plist,
+                                BamReader *manager);
+
+protected:
+  //static TypedWritable *make_from_bam(const FactoryParams &params);
+  void fillin(DatagramIterator &scan, BamReader *manager);
 
 };
 

+ 160 - 5
panda/src/navigation/navMeshQuery.cxx

@@ -13,6 +13,41 @@
 
 #include "navMeshQuery.h"
 #include "DetourNavMeshQuery.h"
+#include "lvecBase3.h"
+#include <iostream>
+
+NavMeshQuery::NavMeshQuery():
+  _nav_query(0) {
+  _nav_query = dtAllocNavMeshQuery();
+}
+
+NavMeshQuery::NavMeshQuery(PT(NavMesh) nav_mesh):
+  _nav_query(0) {
+  
+  _nav_query = dtAllocNavMeshQuery();
+  dtStatus status = _nav_query->init(nav_mesh->get_nav_mesh(), 2048);
+
+  if (dtStatusFailed(status)) {
+    std::cout<<"\nCannot set nav query!\n";
+  }
+
+}
+
+NavMeshQuery::~NavMeshQuery() {
+  dtFreeNavMeshQuery(_nav_query);
+}
+
+bool NavMeshQuery::set_nav_query(PT(NavMesh) nav_mesh) {
+
+  dtStatus status = _nav_query->init(nav_mesh->get_nav_mesh(), 2048);
+
+  if (dtStatusFailed(status)) {
+    std::cout<<"\nCannot set nav query!\n";
+    return false;
+  }
+
+  return true;
+}
 
 bool NavMeshQuery::nearest_point(LPoint3 &p) {
   if (!_nav_query) {
@@ -20,13 +55,12 @@ bool NavMeshQuery::nearest_point(LPoint3 &p) {
     return false;
   }
 
-  const float center[3] = { p[0], p[1], p[2] };
+  const float center[3] = { p[0], p[2], -p[1] };  // convert from z-up system to y-up system
   float *nearest_p = new float[3];
-  const float extents[3] = { 2 , 4 , 2 };
+  const float extents[3] = { 10 , 10 , 10 };
 
   dtQueryFilter filter;
-  filter.setIncludeFlags(RC_WALKABLE_AREA);
-  filter.setExcludeFlags(RC_NULL_AREA);
+  
   dtPolyRef nearest_poly_ref_id = 0;
 
   dtStatus status = _nav_query->findNearestPoly(center, extents, &filter, &nearest_poly_ref_id, nearest_p);
@@ -35,9 +69,130 @@ bool NavMeshQuery::nearest_point(LPoint3 &p) {
     std::cout << "\nCannot find nearest point on polymesh.\n";
     return false;
   }
-  p = LPoint3(nearest_p[0], nearest_p[1], nearest_p[2]);
+  p = LPoint3(nearest_p[0], -nearest_p[2], nearest_p[1]); // convert back from y-up system to z-up system
 
   return true;
 }
 
+PTA_LVecBase3 NavMeshQuery::find_path(LPoint3 &start, LPoint3 &end) {
+
+  PTA_LVecBase3 path_array;
+
+  dtPolyRef start_ref = 0;
+  dtPolyRef end_ref = 0;
+  const float start_pos[3] = { start[0], start[2], -start[1] }; // convert from z-up system to y-up system
+  float *nearest_start = new float[3];
+  const float end_pos[3] = { end[0], end[2], -end[1] }; // convert from z-up system to y-up system
+  float *nearest_end = new float[3];
+  dtQueryFilter filter;
+  dtPolyRef path[MAX_POLYS];
+  int path_count;
+  float *path_cost;
+  const float extents[3] = { 10, 10, 10 };
+
+  dtStatus status = _nav_query->findNearestPoly(start_pos, extents, &filter, &start_ref, nearest_start);
+  if (dtStatusFailed(status)) {
+    std::cout << "\nCannot find nearest point on polymesh for start point.\n";
+    return path_array;
+  }
+  std::cout<<"\nStart_ref: "<<start_ref<<"\n";
+  std::cout<<"\nStarting point:\t"<<nearest_start[0]<<"\t"<<-nearest_start[2]<<"\t"<<nearest_start[1]<<"\n";
+
+  status = _nav_query->findNearestPoly(end_pos, extents, &filter, &end_ref, nearest_end);
+  if (dtStatusFailed(status)) {
+    std::cout << "\nCannot find nearest point on polymesh for end point.\n";
+    return path_array;
+  }
+  std::cout<<"\nEnd_ref: "<<end_ref<<"\n";
+  std::cout<<"\nEnding point:\t"<<nearest_end[0]<<"\t"<<-nearest_end[2]<<"\t"<<nearest_end[1]<<"\n";
+  
+  status = _nav_query->findPath(start_ref, end_ref, nearest_start, nearest_end, &filter, path, &path_count, MAX_POLYS);
+  if (dtStatusFailed(status)) {
+    std::cout << "\nCannot find the path.\n";
+    return path_array;
+  }
+  std::cout<<"\nNumber of polygons included in path: "<<path_count<<"\n";
+  
+  float pos[3] = {start_pos[0], start_pos[1], start_pos[2]};
+
+  for(int i=0;i<path_count;i++) {
+    
+    float *closest = new float[3];
+    
+    status = _nav_query->closestPointOnPolyBoundary(path[i], pos, closest);
+    if (dtStatusFailed(status)) {
+      std::cout << "\nCannot find the nearest point on polygon.\n";
+      return path_array;
+    }
+
+    pos[0] = closest[0];
+    pos[1] = closest[1];
+    pos[2] = closest[2];
+    LVecBase3 point = LVecBase3(closest[0],-closest[2],closest[1]); // convert back from y-up system to z-up system
+    path_array.push_back(point);
+
+  }
+
+  return path_array;
+}
+
+PTA_LVecBase3 NavMeshQuery::find_straight_path(LPoint3 &start, LPoint3 &end, int opt) {
+
+  PTA_LVecBase3 straight_path_array;
+
+  dtPolyRef start_ref = 0;
+  dtPolyRef end_ref = 0;
+  const float start_pos[3] = { start[0], start[2], -start[1] }; // convert from z-up system to y-up system
+  float *nearest_start = new float[3];
+  const float end_pos[3] = { end[0], end[2], -end[1] }; // convert from z-up system to y-up system
+  float *nearest_end = new float[3];
+  dtQueryFilter filter;
+  dtPolyRef path[MAX_POLYS];
+  int path_count;
+  float *path_cost;
+  const float extents[3] = { 10, 10, 10 };
+
+  dtStatus status = _nav_query->findNearestPoly(start_pos, extents, &filter, &start_ref, nearest_start);
+  if (dtStatusFailed(status)) {
+    std::cout << "\nCannot find nearest point on polymesh for start point.\n";
+    return straight_path_array;
+  }
+  std::cout<<"\nStart_ref: "<<start_ref<<"\n";
+  std::cout<<"\nStarting point:\t"<<nearest_start[0]<<"\t"<<-nearest_start[2]<<"\t"<<nearest_start[1]<<"\n";
+
+  status = _nav_query->findNearestPoly(end_pos, extents, &filter, &end_ref, nearest_end);
+  if (dtStatusFailed(status)) {
+    std::cout << "\nCannot find nearest point on polymesh for end point.\n";
+    return straight_path_array;
+  }
+  std::cout<<"\nEnd_ref: "<<end_ref<<"\n";
+  std::cout<<"\nEnding point:\t"<<nearest_end[0]<<"\t"<<-nearest_end[2]<<"\t"<<nearest_end[1]<<"\n";
+  
+  status = _nav_query->findPath(start_ref, end_ref, nearest_start, nearest_end, &filter, path, &path_count, MAX_POLYS);
+  if (dtStatusFailed(status)) {
+    std::cout << "\nCannot find the path.\n";
+    return straight_path_array;
+  }
+  std::cout<<"\nNumber of polygons included in path: "<<path_count<<"\n";
+
+  float straight_path[MAX_POLYS*3];
+  unsigned char straight_path_flags[MAX_POLYS];
+  dtPolyRef straight_path_refs[MAX_POLYS];
+  int straight_path_count;
+
+  status = _nav_query->findStraightPath(nearest_start, nearest_end, path, path_count, straight_path, straight_path_flags, straight_path_refs, &straight_path_count, MAX_POLYS, opt);
+  if (dtStatusFailed(status)) {
+    std::cout << "\nCannot find the straight path.\n";
+    return straight_path_array;
+  }
+  std::cout<<"\nNumber of points included in straight path: "<<straight_path_count<<"\n";
+
+  for(int i=0;i<straight_path_count*3;i+=3) {
+    
+    LVecBase3 point = LVecBase3( straight_path[i], -straight_path[i+2], straight_path[i+1]);  // convert back from y-up system to z-up system
+    straight_path_array.push_back(point);
+
+  }
 
+  return straight_path_array;
+}

+ 17 - 3
panda/src/navigation/navMeshQuery.h

@@ -16,18 +16,32 @@
 #define NAVMESHQUERY_H
 
 #include "DetourNavMeshQuery.h"
-#include "navMeshBuilder.h"
+#include "navMesh.h"
+#include "pta_LVecBase3.h"
+#include "pandaFramework.h"
+#include "pandaSystem.h"
 
 class EXPCL_NAVIGATION NavMeshQuery
 {
+
 PUBLISHED:
-  void set_nav_query(NavMeshBuilder *nav_mesh) { _nav_query = nav_mesh->get_nav_query(); }
+  
+  NavMeshQuery();
+  NavMeshQuery(PT(NavMesh) nav_mesh);
+  bool set_nav_query(PT(NavMesh) nav_mesh);
   bool nearest_point(LPoint3 &p);
+  PTA_LVecBase3 find_path(LPoint3 &start, LPoint3 &end);
+  PTA_LVecBase3 find_straight_path(LPoint3 &start, LPoint3 &end, int opt=0);
+
 private:
-  class dtNavMeshQuery *_nav_query;
   
+  class dtNavMeshQuery *_nav_query;
+  static const int MAX_POLYS = 256;
+
 public:
   
+  ~NavMeshQuery();
+  
   
 };
 

+ 0 - 1
panda/src/navigation/p3navigation_composite1.cxx

@@ -1,4 +1,3 @@
 #include "navMesh.cxx"
-#include "navMeshBuilder.cxx"
 #include "navMeshNode.cxx"
 #include "navMeshQuery.cxx"

+ 0 - 0
panda/src/navigation/Recast/CMakeLists.txt → panda/src/navmeshgen/Recast/CMakeLists.txt


+ 0 - 0
panda/src/navigation/Recast/Include/Recast.h → panda/src/navmeshgen/Recast/Include/Recast.h


+ 0 - 0
panda/src/navigation/Recast/Include/RecastAlloc.h → panda/src/navmeshgen/Recast/Include/RecastAlloc.h


+ 0 - 0
panda/src/navigation/Recast/Include/RecastAssert.h → panda/src/navmeshgen/Recast/Include/RecastAssert.h


+ 0 - 0
panda/src/navigation/Recast/Source/Recast.cpp → panda/src/navmeshgen/Recast/Source/Recast.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastAlloc.cpp → panda/src/navmeshgen/Recast/Source/RecastAlloc.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastArea.cpp → panda/src/navmeshgen/Recast/Source/RecastArea.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastAssert.cpp → panda/src/navmeshgen/Recast/Source/RecastAssert.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastContour.cpp → panda/src/navmeshgen/Recast/Source/RecastContour.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastFilter.cpp → panda/src/navmeshgen/Recast/Source/RecastFilter.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastLayers.cpp → panda/src/navmeshgen/Recast/Source/RecastLayers.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastMesh.cpp → panda/src/navmeshgen/Recast/Source/RecastMesh.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastMeshDetail.cpp → panda/src/navmeshgen/Recast/Source/RecastMeshDetail.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastRasterization.cpp → panda/src/navmeshgen/Recast/Source/RecastRasterization.cpp


+ 0 - 0
panda/src/navigation/Recast/Source/RecastRegion.cpp → panda/src/navmeshgen/Recast/Source/RecastRegion.cpp


+ 49 - 0
panda/src/navmeshgen/config_navmeshgen.cxx

@@ -0,0 +1,49 @@
+/**
+ * PANDA 3D SOFTWARE
+ * Copyright (c) Carnegie Mellon University.  All rights reserved.
+ *
+ * All use of this software is subject to the terms of the revised BSD
+ * license.  You should have received a copy of this license along
+ * with this source code in a file named "LICENSE."
+ *
+ * @file config_navmeshgen.cxx
+ * @author ashwini
+ * @date 2020-060-21
+ */
+
+#include "config_navmeshgen.h"
+
+#include "pandaSystem.h"
+#include "dconfig.h"
+#include "navMeshBuilder.h"
+
+#if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_RECASTDETOUR)
+  #error Buildsystem error: BUILDING_NAVMESHGEN not defined
+#endif
+
+Configure(config_navmeshgen);
+NotifyCategoryDef(navmeshgen, "");
+
+ConfigureFn(config_navmeshgen) {
+  init_libnavmeshgen();
+}
+
+ConfigVariableInt navmeshgen_sample_config_variable
+("navmeshgen-sample-config-variable", 25);
+
+/**
+ * Initializes the library.  This must be called at least once before any of
+ * the functions or classes in this library can be used.  Normally it will be
+ * called by the static initializers and need not be called explicitly, but
+ * special cases exist.
+ */
+void
+init_libnavmeshgen() {
+  
+  static bool initialized = false;
+  if (initialized) {
+    return;
+  }
+  initialized = true;
+}
+

+ 30 - 0
panda/src/navmeshgen/config_navmeshgen.h

@@ -0,0 +1,30 @@
+/**
+ * PANDA 3D SOFTWARE
+ * Copyright (c) Carnegie Mellon University.  All rights reserved.
+ *
+ * All use of this software is subject to the terms of the revised BSD
+ * license.  You should have received a copy of this license along
+ * with this source code in a file named "LICENSE."
+ *
+ * @file config_navmeshgen.h
+ * @author ashwini
+ * @date 2020-060-21
+ */
+
+#ifndef CONFIG_NAVMESHGEN_H
+#define CONFIG_NAVMESHGEN_H
+
+#include "pandabase.h"
+#include "notifyCategoryProxy.h"
+#include "configVariableDouble.h"
+#include "configVariableString.h"
+#include "configVariableInt.h"
+
+NotifyCategoryDecl(navmeshgen, EXPCL_NAVMESHGEN, EXPTP_NAVMESHGEN);
+
+extern ConfigVariableInt    navmeshgen_sample_config_variable;
+
+extern EXPCL_NAVMESHGEN void init_libnavmeshgen();
+
+#endif
+

+ 29 - 66
panda/src/navigation/navMeshBuilder.cxx → panda/src/navmeshgen/navMeshBuilder.cxx

@@ -8,13 +8,12 @@
  *
  * @file navMeshBuilder.cxx
  * @author ashwini
- * @date 2020-060-21
+ * @date 2020-06-21
  */
 
 #include "navMeshBuilder.h"
 #include "Recast.h"
 #include "DetourNavMesh.h"
-#include "DetourNavMeshQuery.h"
 #include "DetourNavMeshBuilder.h"
 
 #define _USE_MATH_DEFINES
@@ -33,9 +32,6 @@
 #endif
 
 NavMeshBuilder::NavMeshBuilder() :
-  _nav_mesh(0),
-  _nav_query(0),
-  _crowd(0),
   _filter_low_hanging_obstacles(true),
   _filter_ledge_spans(true),
   _filter_walkable_low_height_spans(true),
@@ -58,7 +54,6 @@ NavMeshBuilder::NavMeshBuilder() :
   face_vector.clear();
   _ctx = new rcContext;
   reset_common_settings();
-  _nav_query = dtAllocNavMeshQuery();
   //_crowd = dtAllocCrowd();
 }
 
@@ -67,7 +62,6 @@ NavMeshBuilder::~NavMeshBuilder() {
   delete[] _normals;
   delete[] _tris;
 
-  dtFreeNavMeshQuery(_nav_query);
   //dtFreeCrowd(_crowd);
 
   cleanup();
@@ -276,8 +270,7 @@ void NavMeshBuilder::cleanup()
   _pmesh = 0;
   rcFreePolyMeshDetail(_dmesh);
   _dmesh = 0;
-  dtFreeNavMesh(_nav_mesh);
-  _nav_mesh = 0;
+  
 }
 
 void NavMeshBuilder::set_partition_type(std::string p) {
@@ -601,8 +594,7 @@ PT(NavMesh) NavMeshBuilder::build() {
   // The GUI may allow more max points per polygon than Detour can handle.
   // Only build the detour navmesh if we do not exceed the limit.
   if (_cfg.maxVertsPerPoly <= DT_VERTS_PER_POLYGON) {
-    unsigned char *nav_data = 0;
-    int nav_data_size = 0;
+    
 
     // Update poly flags from areas.
     for (int i = 0; i < _pmesh->npolys; ++i) {
@@ -620,59 +612,33 @@ PT(NavMesh) NavMeshBuilder::build() {
       }
     }
 
+    _nav_mesh_obj = new NavMesh(_nav_mesh);
+    
+    memset(&(_nav_mesh_obj->params), 0, sizeof(_nav_mesh_obj->params));
+    _nav_mesh_obj->params.verts = _pmesh->verts;
+    _nav_mesh_obj->params.vertCount = _pmesh->nverts;
+    _nav_mesh_obj->params.polys = _pmesh->polys;
+    _nav_mesh_obj->params.polyAreas = _pmesh->areas;
+    _nav_mesh_obj->params.polyFlags = _pmesh->flags;
+    _nav_mesh_obj->params.polyCount = _pmesh->npolys;
+    _nav_mesh_obj->params.nvp = _pmesh->nvp;
+    _nav_mesh_obj->params.detailMeshes = _dmesh->meshes;
+    _nav_mesh_obj->params.detailVerts = _dmesh->verts;
+    _nav_mesh_obj->params.detailVertsCount = _dmesh->nverts;
+    _nav_mesh_obj->params.detailTris = _dmesh->tris;
+    _nav_mesh_obj->params.detailTriCount = _dmesh->ntris;
 
-    dtNavMeshCreateParams params;
-    memset(&params, 0, sizeof(params));
-    params.verts = _pmesh->verts;
-    params.vertCount = _pmesh->nverts;
-    params.polys = _pmesh->polys;
-    params.polyAreas = _pmesh->areas;
-    params.polyFlags = _pmesh->flags;
-    params.polyCount = _pmesh->npolys;
-    params.nvp = _pmesh->nvp;
-    params.detailMeshes = _dmesh->meshes;
-    params.detailVerts = _dmesh->verts;
-    params.detailVertsCount = _dmesh->nverts;
-    params.detailTris = _dmesh->tris;
-    params.detailTriCount = _dmesh->ntris;
-
-
-    params.walkableHeight = _agent_height;
-    params.walkableRadius = _agent_radius;
-    params.walkableClimb = _agent_max_climb;
-    rcVcopy(params.bmin, _pmesh->bmin);
-    rcVcopy(params.bmax, _pmesh->bmax);
-    params.cs = _cfg.cs;
-    params.ch = _cfg.ch;
-    params.buildBvTree = true;
-
-    if (!dtCreateNavMeshData(&params, &nav_data, &nav_data_size)) {
-      _ctx->log(RC_LOG_ERROR, "Could not build Detour navmesh.");
-      return _nav_mesh_obj;
-    }
-
-    _nav_mesh = dtAllocNavMesh();
-
-    if (!_nav_mesh) {
-      dtFree(nav_data);
-      _ctx->log(RC_LOG_ERROR, "Could not create Detour navmesh");
-      return _nav_mesh_obj;
-    }
-
-    dtStatus status;
 
-    status = _nav_mesh->init(nav_data, nav_data_size, DT_TILE_FREE_DATA);
-    if (dtStatusFailed(status)) {
-      dtFree(nav_data);
-      _ctx->log(RC_LOG_ERROR, "Could not init Detour navmesh");
-      return _nav_mesh_obj;
-    }
+    _nav_mesh_obj->params.walkableHeight = _agent_height;
+    _nav_mesh_obj->params.walkableRadius = _agent_radius;
+    _nav_mesh_obj->params.walkableClimb = _agent_max_climb;
+    rcVcopy(_nav_mesh_obj->params.bmin, _pmesh->bmin);
+    rcVcopy(_nav_mesh_obj->params.bmax, _pmesh->bmax);
+    _nav_mesh_obj->params.cs = _cfg.cs;
+    _nav_mesh_obj->params.ch = _cfg.ch;
+    _nav_mesh_obj->params.buildBvTree = true;
 
-    status = _nav_query->init(_nav_mesh, 2048);
-    if (dtStatusFailed(status)) {
-      _ctx->log(RC_LOG_ERROR, "Could not init Detour navmesh query");
-      return _nav_mesh_obj;
-    }
+    _nav_mesh_obj->init_nav_mesh();
 
   }
 
@@ -684,11 +650,8 @@ PT(NavMesh) NavMeshBuilder::build() {
 
   _total_build_time_ms = _ctx->getAccumulatedTime(RC_TIMER_TOTAL) / 1000.0f;
 
-  //if (_tool)
-    //_tool->init(this);
-  //initToolStates(this);
-  //std::cout << "\nExiting Sample_SoloMesh::handleBuild()\n";
-  _nav_mesh_obj = new NavMesh(_nav_mesh);
+  
+  
   return _nav_mesh_obj;
 }
 

+ 2 - 8
panda/src/navigation/navMeshBuilder.h → panda/src/navmeshgen/navMeshBuilder.h

@@ -8,7 +8,7 @@
  *
  * @file navMeshBuilder.h
  * @author ashwini
- * @date 2020-060-21
+ * @date 2020-06-21
  */
 
 
@@ -62,7 +62,7 @@ struct BuildSettings {
 };
 
 
-class EXPCL_NAVIGATION NavMeshBuilder {
+class EXPCL_NAVMESHGEN NavMeshBuilder {
 PUBLISHED:
   float get_actor_radius() { return _agent_radius; }
   float get_actor_height() { return _agent_height; }
@@ -109,8 +109,6 @@ private:
 protected:
   PT(NavMesh) _nav_mesh_obj;
   class dtNavMesh *_nav_mesh;
-  class dtNavMeshQuery *_nav_query;
-  class dtCrowd *_crowd;
 
   unsigned char _nav_mesh_draw_flags;
 
@@ -155,10 +153,6 @@ public:
   void set_context(rcContext *ctx) { _ctx = ctx; }
 
   virtual void collect_settings(struct BuildSettings &settings);
-
-  
-  dtNavMeshQuery *get_nav_query() { return _nav_query; }
-
  
   unsigned char getNavMeshDrawFlags() const { return _nav_mesh_draw_flags; }
   const float *get_verts() const { return _verts; }

+ 1 - 0
panda/src/navmeshgen/p3navmeshgen_composite1.cxx

@@ -0,0 +1 @@
+#include "navMeshBuilder.cxx"

+ 8 - 0
panda/src/pandabase/pandasymbols.h

@@ -587,6 +587,14 @@
   #define EXPTP_NAVIGATION IMPORT_TEMPL
 #endif
 
+#ifdef BUILDING_NAVMESHGEN
+  #define EXPCL_NAVMESHGEN EXPORT_CLASS
+  #define EXPTP_NAVMESHGEN EXPORT_TEMPL
+#else
+  #define EXPCL_NAVMESHGEN IMPORT_CLASS
+  #define EXPTP_NAVMESHGEN IMPORT_TEMPL
+#endif
+
 #ifdef BUILDING_VRPN
   #define EXPCL_VRPN EXPORT_CLASS
   #define EXPTP_VRPN EXPORT_TEMPL