mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
python toggle switch allows the portal culling to be on/off
This commit is contained in:
parent
5b24209a3d
commit
4a24b121b0
@ -53,6 +53,31 @@ get_auto_flip() const {
|
||||
return _auto_flip;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GraphicsEngine::set_portal_cull
|
||||
// Access: Published
|
||||
// Description: Set this flag true to indicate the GraphicsEngine
|
||||
// should start portal culling
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void GraphicsEngine::
|
||||
set_portal_cull(bool value) {
|
||||
// We don't bother with the mutex here. It's just a bool, after
|
||||
// all.
|
||||
_portal_enabled = value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GraphicsEngine::get_portal_cull
|
||||
// Access: Published
|
||||
// Description: Returns the current setting for the portal culling flag.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool GraphicsEngine::
|
||||
get_portal_cull() const {
|
||||
// We don't bother with the mutex here. It's just a bool, after
|
||||
// all.
|
||||
return _portal_enabled;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GraphicsEngine::make_gsg
|
||||
// Access: Published
|
||||
|
@ -87,6 +87,7 @@ GraphicsEngine(Pipeline *pipeline) :
|
||||
<< "Using threading model " << _threading_model << "\n";
|
||||
}
|
||||
_auto_flip = auto_flip;
|
||||
_portal_enabled = false;
|
||||
_flip_state = FS_flip;
|
||||
}
|
||||
|
||||
@ -1026,7 +1027,7 @@ do_cull(CullHandler *cull_handler, SceneSetup *scene_setup,
|
||||
trav.set_depth_offset_decals(gsg->depth_offset_decals());
|
||||
trav.set_scene(scene_setup);
|
||||
trav.set_camera_mask(scene_setup->get_camera_node()->get_camera_mask());
|
||||
|
||||
|
||||
if (view_frustum_cull) {
|
||||
// If we're to be performing view-frustum culling, determine the
|
||||
// bounding volume associated with the current viewing frustum.
|
||||
@ -1049,7 +1050,7 @@ do_cull(CullHandler *cull_handler, SceneSetup *scene_setup,
|
||||
}
|
||||
}
|
||||
|
||||
trav.traverse(scene_setup->get_scene_root());
|
||||
trav.traverse(scene_setup->get_scene_root(), get_portal_cull());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -69,6 +69,9 @@ PUBLISHED:
|
||||
INLINE void set_auto_flip(bool auto_flip);
|
||||
INLINE bool get_auto_flip() const;
|
||||
|
||||
INLINE void set_portal_cull(bool value);
|
||||
INLINE bool get_portal_cull() const;
|
||||
|
||||
INLINE PT(GraphicsStateGuardian) make_gsg(GraphicsPipe *pipe);
|
||||
PT(GraphicsStateGuardian) make_gsg(GraphicsPipe *pipe,
|
||||
const FrameBufferProperties &properties,
|
||||
@ -226,6 +229,7 @@ private:
|
||||
FrameBufferProperties _frame_buffer_properties;
|
||||
GraphicsThreadingModel _threading_model;
|
||||
bool _auto_flip;
|
||||
bool _portal_enabled; //toggle to portal culling on/off
|
||||
|
||||
enum FlipState {
|
||||
FS_draw, // Still drawing.
|
||||
|
@ -69,6 +69,7 @@
|
||||
pandaNode.I pandaNode.h \
|
||||
planeNode.I planeNode.h \
|
||||
pointLight.I pointLight.h \
|
||||
portalNode.I portalNode.h \
|
||||
portalClipper.I portalClipper.h \
|
||||
renderAttrib.I renderAttrib.h \
|
||||
renderEffect.I renderEffect.h \
|
||||
@ -154,6 +155,7 @@
|
||||
pandaNode.cxx \
|
||||
planeNode.cxx \
|
||||
pointLight.cxx \
|
||||
portalNode.cxx \
|
||||
portalClipper.cxx \
|
||||
renderAttrib.cxx \
|
||||
renderEffect.cxx \
|
||||
@ -235,6 +237,7 @@
|
||||
pandaNode.I pandaNode.h \
|
||||
planeNode.I planeNode.h \
|
||||
pointLight.I pointLight.h \
|
||||
portalNode.I portalNode.h \
|
||||
portalClipper.I portalClipper.h \
|
||||
renderAttrib.I renderAttrib.h \
|
||||
renderEffect.I renderEffect.h \
|
||||
|
@ -73,13 +73,14 @@ CullTraverser(const CullTraverser ©) :
|
||||
// Description: Begins the traversal from the indicated node.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CullTraverser::
|
||||
traverse(const NodePath &root) {
|
||||
traverse(const NodePath &root, bool python_cull_control) {
|
||||
nassertv(_cull_handler != (CullHandler *)NULL);
|
||||
nassertv(_scene_setup != (SceneSetup *)NULL);
|
||||
|
||||
if (allow_portal_cull) {
|
||||
if (1) {
|
||||
// This _view_frustum is in cull_center space
|
||||
PT(GeometricBoundingVolume) vf = _view_frustum;
|
||||
pgraph_cat.spam() << "_view_frustum is " << *_view_frustum << "\n";
|
||||
pgraph_cat.debug() << "_view_frustum is " << *_view_frustum << "\n";
|
||||
|
||||
GeometricBoundingVolume *local_frustum = NULL;
|
||||
PT(BoundingVolume) bv = _scene_setup->get_lens()->make_bounds();
|
||||
@ -88,26 +89,32 @@ traverse(const NodePath &root) {
|
||||
|
||||
local_frustum = DCAST(GeometricBoundingVolume, bv);
|
||||
}
|
||||
pgraph_cat.spam() << "local_frustum is " << *local_frustum << "\n";
|
||||
pgraph_cat.debug() << "local_frustum is " << *local_frustum << "\n";
|
||||
|
||||
// This local_frustum is in camera space
|
||||
PortalClipper portal_viewer(local_frustum, _scene_setup);
|
||||
portal_viewer.draw_camera_frustum();
|
||||
|
||||
// for each portal draw its frustum
|
||||
for (int portal_idx=1; portal_idx<2; ++portal_idx) {
|
||||
PT(BoundingVolume) reduced_frustum;
|
||||
|
||||
portal_viewer.prepare_portal(portal_idx);
|
||||
portal_viewer.clip_portal(portal_idx);
|
||||
if ((reduced_frustum = portal_viewer.get_reduced_frustum(portal_idx))) {
|
||||
pgraph_cat.debug() << "got reduced frustum " << reduced_frustum << endl;
|
||||
vf = DCAST(GeometricBoundingVolume, reduced_frustum);
|
||||
CPT(TransformState) cull_center_transform =
|
||||
_scene_setup->get_cull_center().get_transform(_scene_setup->get_scene_root());
|
||||
vf->xform(cull_center_transform->get_mat());
|
||||
if (allow_portal_cull || python_cull_control) {
|
||||
// for each portal draw its frustum
|
||||
for (int portal_idx=1; portal_idx<2; ++portal_idx) {
|
||||
PT(BoundingVolume) reduced_frustum;
|
||||
|
||||
portal_viewer.prepare_portal(portal_idx);
|
||||
portal_viewer.clip_portal(portal_idx);
|
||||
if ((reduced_frustum = portal_viewer.get_reduced_frustum(portal_idx))) {
|
||||
// This reduced frustum is in camera space
|
||||
pgraph_cat.debug() << "got reduced frustum " << reduced_frustum << endl;
|
||||
vf = DCAST(GeometricBoundingVolume, reduced_frustum);
|
||||
|
||||
// trasform it to cull_center space
|
||||
CPT(TransformState) cull_center_transform =
|
||||
_scene_setup->get_cull_center().get_transform(_scene_setup->get_scene_root());
|
||||
vf->xform(cull_center_transform->get_mat());
|
||||
}
|
||||
}
|
||||
}
|
||||
pgraph_cat.spam() << "vf is " << *vf << "\n";
|
||||
pgraph_cat.debug() << "vf is " << *vf << "\n";
|
||||
|
||||
CullTraverserData data(root, get_render_transform(),
|
||||
TransformState::make_identity(),
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
INLINE void set_cull_handler(CullHandler *cull_handler);
|
||||
INLINE CullHandler *get_cull_handler() const;
|
||||
|
||||
void traverse(const NodePath &root);
|
||||
void traverse(const NodePath &root, bool python_cull_control=false);
|
||||
void traverse(CullTraverserData &data);
|
||||
void traverse_below(CullTraverserData &data);
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "pandaNode.cxx"
|
||||
#include "planeNode.cxx"
|
||||
#include "pointLight.cxx"
|
||||
#include "portalNode.cxx"
|
||||
#include "portalClipper.cxx"
|
||||
#include "renderAttrib.cxx"
|
||||
#include "renderEffect.cxx"
|
||||
|
@ -94,7 +94,7 @@ draw_to(float x, float y, float z) {
|
||||
// Description: Draw the current camera frustum in white color
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void PortalClipper::
|
||||
INLINE void PortalClipper::
|
||||
draw_camera_frustum()
|
||||
{
|
||||
_color = Colorf(1,1,1,1);
|
||||
@ -107,13 +107,13 @@ draw_camera_frustum()
|
||||
// Description: checks if the _coords that forms the plane is
|
||||
// facing the camera
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool PortalClipper::
|
||||
INLINE bool PortalClipper::
|
||||
is_facing_camera()
|
||||
{
|
||||
Planef portal_plane(_coords[0], _coords[1], _coords[2]);
|
||||
Planef camera_plane(_hex_frustum->get_point(4), _hex_frustum->get_point(5), _hex_frustum->get_point(6));
|
||||
|
||||
float direction = portal_plane.get_normal().dot(camera_plane.get_normal());
|
||||
pgraph_cat.debug() << portal_plane.get_normal() << "; " << -camera_plane.get_normal() << endl;
|
||||
float direction = portal_plane.get_normal().dot(-camera_plane.get_normal());
|
||||
pgraph_cat.debug() << "Found direction of " << direction << endl;
|
||||
return (direction > 0);
|
||||
return (direction < _FACING_THRESHOLD);
|
||||
}
|
||||
|
@ -44,6 +44,10 @@ class CullTraverserData;
|
||||
class CullableObject;
|
||||
class NodePath;
|
||||
|
||||
//#define _FACING_THRESHOLD -0.7 //about 45 degrees with the camera
|
||||
//#define _FACING_THRESHOLD -0.5 //about 60 degrees with the camera
|
||||
#define _FACING_THRESHOLD 0.0 //about 90 degrees with the camera
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : PortalClipper
|
||||
// Description : This object performs a depth-first traversal of the
|
||||
|
Loading…
x
Reference in New Issue
Block a user