Browse Source

added cull_callback, added doctrings to classes, used nullptr for pointers

Ashwini Jha 5 years ago
parent
commit
37f2b568bb

+ 9 - 0
panda/src/navigation/navMesh.h

@@ -22,6 +22,9 @@
 #include "pandaSystem.h"
 #include "pandaSystem.h"
 #include "lmatrix.h"
 #include "lmatrix.h"
 
 
+/**
+ * NavMeshParams class stores all the parameters of a navigation mesh.
+ */
 class EXPCL_NAVIGATION NavMeshParams {
 class EXPCL_NAVIGATION NavMeshParams {
 PUBLISHED:
 PUBLISHED:
   int vert_count;
   int vert_count;
@@ -49,6 +52,12 @@ PUBLISHED:
 
 
 };
 };
 
 
+
+/**
+ * NavMesh class stores the navigation mesh. The navigation mesh 
+ * can be obtained using NavMeshBuilder class or can be generated 
+ * using the NavMeshParams class by the user. 
+ */
 class EXPCL_NAVIGATION NavMesh: public TypedWritableReferenceCount
 class EXPCL_NAVIGATION NavMesh: public TypedWritableReferenceCount
 {
 {
 PUBLISHED:
 PUBLISHED:

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

@@ -24,6 +24,7 @@ NavMeshNode::NavMeshNode(const std::string &name, PT(NavMesh) nav_mesh):
   PandaNode(name)
   PandaNode(name)
 {
 {
   _nav_mesh = nav_mesh;
   _nav_mesh = nav_mesh;
+  set_cull_callback();
 }
 }
 
 
 NavMeshNode::NavMeshNode(const std::string &name):
 NavMeshNode::NavMeshNode(const std::string &name):
@@ -31,6 +32,65 @@ NavMeshNode::NavMeshNode(const std::string &name):
 
 
 NavMeshNode::~NavMeshNode() {}
 NavMeshNode::~NavMeshNode() {}
 
 
+/**
+ * This function will be called during the cull traversal to perform any
+ * additional operations that should be performed at cull time.  This may
+ * include additional manipulation of render state or additional
+ * visible/invisible decisions, or any other arbitrary operation.
+ *
+ * Note that this function will *not* be called unless set_cull_callback() is
+ * called in the constructor of the derived class.  It is necessary to call
+ * set_cull_callback() to indicated that we require cull_callback() to be
+ * called.
+ *
+ * By the time this function is called, the node has already passed the
+ * bounding-volume test for the viewing frustum, and the node's transform and
+ * state have already been applied to the indicated CullTraverserData object.
+ *
+ * The return value is true if this node should be visible, or false if it
+ * should be culled.
+ */
+bool NavMeshNode::
+cull_callback(CullTraverser *trav, CullTraverserData &data) {
+  // Append our collision vizzes to the drawing, even though they're not
+  // actually part of the scene graph.
+  PT(PandaNode) node = _nav_mesh->draw_nav_mesh_geom();
+  if(node != nullptr) {
+  	CullTraverserData next_data(data, node);
+  	next_data._state = RenderState::make_empty();
+  	trav->traverse(next_data);
+  }
+  // Solids::const_iterator si;
+  // for (si = _solids.begin(); si != _solids.end(); ++si) {
+  //   CPT(CollisionSolid) solid = (*si).get_read_pointer();
+  //   PT(PandaNode) node = solid->get_viz(trav, data, false);
+  //   if (node != nullptr) {
+  //     CullTraverserData next_data(data, node);
+
+  //     // We don't want to inherit the render state from above for these guys.
+  //     next_data._state = RenderState::make_empty();
+  //     trav->traverse(next_data);
+  //   }
+  // }
+
+  
+
+  // Now carry on to render our child nodes.
+  return true;
+}
+
+/**
+ * Returns true if there is some value to visiting this particular node during
+ * the cull traversal for any camera, false otherwise.  This will be used to
+ * optimize the result of get_net_draw_show_mask(), so that any subtrees that
+ * contain only nodes for which is_renderable() is false need not be visited.
+ */
+bool NavMeshNode::
+is_renderable() const {
+  return true;
+}
+
+
 /**
 /**
  * Tells the BamReader how to create objects of type BulletTriangleMeshShape.
  * Tells the BamReader how to create objects of type BulletTriangleMeshShape.
  */
  */

+ 5 - 0
panda/src/navigation/navMeshNode.h

@@ -21,6 +21,9 @@
 #include "navMesh.h"
 #include "navMesh.h"
 #include <string>
 #include <string>
 
 
+/**
+ * NavMeshNode class is a child class of PandaNode which stores the NavMesh object.
+ */
 class EXPCL_NAVIGATION NavMeshNode: public PandaNode
 class EXPCL_NAVIGATION NavMeshNode: public PandaNode
 {
 {
 PUBLISHED:
 PUBLISHED:
@@ -47,6 +50,8 @@ public:
     return get_class_type();
     return get_class_type();
   }
   }
   virtual TypeHandle force_init_type() { init_type(); return get_class_type(); }
   virtual TypeHandle force_init_type() { init_type(); return get_class_type(); }
+  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
+  virtual bool is_renderable() const;
 
 
 private:
 private:
   static TypeHandle _type_handle;
   static TypeHandle _type_handle;

+ 5 - 0
panda/src/navigation/navMeshQuery.h

@@ -22,6 +22,11 @@
 #include "pandaSystem.h"
 #include "pandaSystem.h"
 #include "nodePath.h"
 #include "nodePath.h"
 
 
+/**
+ * NavMeshQuery class contains the functions to query the navigation mesh stored 
+ * in a NavMesh object. The queries include functions to find the paths from one 
+ * point to another over the mesh.
+ */
 class EXPCL_NAVIGATION NavMeshQuery
 class EXPCL_NAVIGATION NavMeshQuery
 {
 {
 
 

+ 6 - 17
panda/src/navmeshgen/navMeshBuilder.cxx

@@ -296,10 +296,6 @@ void NavMeshBuilder::process_vertex_data(const GeomVertexData *vdata, int &vcap)
       LVecBase3 vec = mat_to_y.xform_point(v);
       LVecBase3 vec = mat_to_y.xform_point(v);
       add_vertex(vec[0], vec[1], vec[2], vcap);
       add_vertex(vec[0], vec[1], vec[2], vcap);
       
       
-      //add_vertex(x, z, -y, vcap); //if input model is originally z-up
-      //add_vertex(x, y, z, vcap); //if input model is originally y-up
-
-      //_vertex_map[v] = index_temp++;
       LVector3 xvx = { v[0],v[2],-v[1] };
       LVector3 xvx = { v[0],v[2],-v[1] };
       _vertex_map[v] = index_temp++;
       _vertex_map[v] = index_temp++;
       _vertex_vector.push_back(v);
       _vertex_vector.push_back(v);
@@ -347,19 +343,12 @@ void NavMeshBuilder::process_geom_node(GeomNode *geomnode, int &vcap, int &tcap)
  */
  */
 void NavMeshBuilder::cleanup()
 void NavMeshBuilder::cleanup()
 {
 {
-  delete[] _triareas;
-  _triareas = 0;
-  rcFreeHeightField(_solid);
-  _solid = 0;
-  rcFreeCompactHeightfield(_chf);
-  _chf = 0;
-  rcFreeContourSet(_cset);
-  _cset = 0;
-  rcFreePolyMesh(_pmesh);
-  _pmesh = 0;
-  rcFreePolyMeshDetail(_dmesh);
-  _dmesh = 0;
-  
+  _triareas = nullptr;
+  _solid = nullptr;
+  _chf = nullptr;
+  _cset = nullptr;
+  _pmesh = nullptr;
+  _dmesh = nullptr;
 }
 }
 
 
 /**
 /**

+ 6 - 2
panda/src/navmeshgen/navMeshBuilder.h

@@ -45,8 +45,12 @@ enum SamplePolyFlags {
   SAMPLE_POLYFLAGS_ALL = 0xffff	// All abilities.
   SAMPLE_POLYFLAGS_ALL = 0xffff	// All abilities.
 };
 };
 
 
-
-
+/**
+ * NavMeshBuilder class contains all the vertices and triangles. It also 
+ * has the functions to build the navigation meshes using those vertices and 
+ * triangles. Set the properties of the actor and environment using this class 
+ * and then build it to get a NavMesh object as output.
+ */
 class EXPCL_NAVMESHGEN NavMeshBuilder {
 class EXPCL_NAVMESHGEN NavMeshBuilder {
 PUBLISHED:
 PUBLISHED:
   enum PartitionType {
   enum PartitionType {