From b099e2d063ab82fe5950d46514565e79940159e2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 18 Mar 2011 17:49:48 +0000 Subject: [PATCH] more fixes from teedee including set_double_sided() --- panda/src/pgraph/cullPlanes.cxx | 22 +++++++++++++++------- panda/src/pgraph/occluderNode.I | 18 ++++++++++++++++++ panda/src/pgraph/occluderNode.cxx | 18 +++++++++++++----- panda/src/pgraph/occluderNode.h | 3 +++ 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/panda/src/pgraph/cullPlanes.cxx b/panda/src/pgraph/cullPlanes.cxx index d74ca03596..5d234c25ef 100644 --- a/panda/src/pgraph/cullPlanes.cxx +++ b/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(); diff --git a/panda/src/pgraph/occluderNode.I b/panda/src/pgraph/occluderNode.I index 19ee1c4dbe..7e380c0f67 100644 --- a/panda/src/pgraph/occluderNode.I +++ b/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; +} diff --git a/panda/src/pgraph/occluderNode.cxx b/panda/src/pgraph/occluderNode.cxx index 0c2b66fd11..d259cd3c46 100644 --- a/panda/src/pgraph/occluderNode.cxx +++ b/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 ©) : 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; diff --git a/panda/src/pgraph/occluderNode.h b/panda/src/pgraph/occluderNode.h index 9d488b7600..f22a56dcd1 100644 --- a/panda/src/pgraph/occluderNode.h +++ b/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 Vertices; Vertices _vertices;