Browse Source

more fixes from teedee including set_double_sided()

David Rose 14 years ago
parent
commit
b099e2d063

+ 15 - 7
panda/src/pgraph/cullPlanes.cxx

@@ -163,11 +163,13 @@ apply_state(const CullTraverser *trav, const CullTraverserData *data,
           occluder_gbv->xform(composed_transform->get_mat());
         }
 
-        int occluder_result = data->_view_frustum->contains(occluder_gbv);
-        if (occluder_result == BoundingVolume::IF_no_intersection) {
-          // This occluder is outside the view frustum; ignore it.
-          continue;
-        }
+	if (data->_view_frustum != (GeometricBoundingVolume *)NULL) {
+	  int occluder_result = data->_view_frustum->contains(occluder_gbv);
+	  if (occluder_result == BoundingVolume::IF_no_intersection) {
+	    // This occluder is outside the view frustum; ignore it.
+	    continue;
+	  }
+	}
 
         // Also check if the new occluder is completely within any of
         // our existing occluder volumes.
@@ -198,8 +200,14 @@ apply_state(const CullTraverser *trav, const CullTraverserData *data,
         
         Planef plane(points_near[0], points_near[1], points_near[2]);
         if (plane.get_normal().dot(LVector3f::forward()) >= 0.0) {
-          // This occluder is facing the wrong direction.  Ignore it.
-          continue;
+          if (occluder_node->is_double_sided()) {
+            swap(points_near[0], points_near[3]);
+            swap(points_near[1], points_near[2]);
+            plane = Planef(points_near[0], points_near[1], points_near[2]);
+          } else {
+            // This occluder is facing the wrong direction.  Ignore it.
+            continue;
+          }
         }
 
         float near_clip = scene->get_lens()->get_near();

+ 18 - 0
panda/src/pgraph/occluderNode.I

@@ -52,3 +52,21 @@ get_vertex(int n) const {
   nassertr(n >= 0 && n < (int)_vertices.size(), LPoint3f::zero());
   return _vertices[n];
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: OccluderNode::set_double_sided
+//       Access: Published
+//  Description: If true, the back-face will also be used to occlude
+////////////////////////////////////////////////////////////////////
+INLINE void OccluderNode::set_double_sided(bool value) {
+  _double_sided = value;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: OccluderNode::is_double_sided
+//       Access: Published
+//  Description: Is this occluder double-sided
+////////////////////////////////////////////////////////////////////
+INLINE bool OccluderNode::is_double_sided() {
+  return _double_sided;
+}

+ 13 - 5
panda/src/pgraph/occluderNode.cxx

@@ -61,7 +61,7 @@ OccluderNode(const string &name) :
   set_cull_callback();
   // OccluderNodes are hidden by default.
   set_overall_hidden(true);
-
+  set_double_sided(false);
   set_vertices(LPoint3f::rfu(-1.0, 0.0, -1.0),
                LPoint3f::rfu(1.0, 0.0, -1.0),
                LPoint3f::rfu(1.0, 0.0, 1.0),
@@ -76,7 +76,8 @@ OccluderNode(const string &name) :
 OccluderNode::
 OccluderNode(const OccluderNode &copy) :
   PandaNode(copy),
-  _vertices(copy._vertices)
+  _vertices(copy._vertices),
+  _double_sided(copy._double_sided)
 {
 }
 
@@ -323,12 +324,18 @@ get_occluder_viz_state(CullTraverser *trav, CullTraverserData &data) {
       (ColorAttrib::make_flat(LVecBase4f(1.0f, 1.0f, 1.0f, 0.5f)),
        TransparencyAttrib::make(TransparencyAttrib::M_alpha),
        DepthOffsetAttrib::make(),
-       CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise));
-    viz_state = viz_state->set_attrib(TextureAttrib::make(_viz_tex));
+       TextureAttrib::make(_viz_tex));
     viz_state = viz_state->adjust_all_priorities(1);
   }
 
-  return data._state->compose(viz_state);
+  CPT(RenderState) state = viz_state;
+  if (is_double_sided()) {
+    state = viz_state->set_attrib(CullFaceAttrib::make(CullFaceAttrib::M_cull_none), 1);
+  } else {
+    state = viz_state->set_attrib(CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise), 1);
+  }
+
+  return state->compose(viz_state);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -424,6 +431,7 @@ fillin(DatagramIterator &scan, BamReader *manager) {
   PandaNode::fillin(scan, manager);
 
   int num_vertices = scan.get_uint16();
+  _vertices.clear();
   _vertices.reserve(num_vertices);
   for (int i = 0; i < num_vertices; i++) {
     LPoint3f vertex;

+ 3 - 0
panda/src/pgraph/occluderNode.h

@@ -51,6 +51,8 @@ public:
   virtual void output(ostream &out) const;
 
 PUBLISHED:
+  INLINE void set_double_sided(bool value);
+  INLINE bool is_double_sided();
   INLINE void set_vertices(const LPoint3f &v0, const LPoint3f &v1,
                            const LPoint3f &v2, const LPoint3f &v3);
   INLINE int get_num_vertices() const;
@@ -67,6 +69,7 @@ protected:
   CPT(RenderState) get_frame_viz_state(CullTraverser *trav, CullTraverserData &data);
 
 private:
+  bool _double_sided;
   typedef pvector<LPoint3f> Vertices;
   Vertices _vertices;