mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -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;
|
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
|
// Function: GraphicsEngine::make_gsg
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -87,6 +87,7 @@ GraphicsEngine(Pipeline *pipeline) :
|
|||||||
<< "Using threading model " << _threading_model << "\n";
|
<< "Using threading model " << _threading_model << "\n";
|
||||||
}
|
}
|
||||||
_auto_flip = auto_flip;
|
_auto_flip = auto_flip;
|
||||||
|
_portal_enabled = false;
|
||||||
_flip_state = FS_flip;
|
_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_depth_offset_decals(gsg->depth_offset_decals());
|
||||||
trav.set_scene(scene_setup);
|
trav.set_scene(scene_setup);
|
||||||
trav.set_camera_mask(scene_setup->get_camera_node()->get_camera_mask());
|
trav.set_camera_mask(scene_setup->get_camera_node()->get_camera_mask());
|
||||||
|
|
||||||
if (view_frustum_cull) {
|
if (view_frustum_cull) {
|
||||||
// If we're to be performing view-frustum culling, determine the
|
// If we're to be performing view-frustum culling, determine the
|
||||||
// bounding volume associated with the current viewing frustum.
|
// 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 void set_auto_flip(bool auto_flip);
|
||||||
INLINE bool get_auto_flip() const;
|
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);
|
INLINE PT(GraphicsStateGuardian) make_gsg(GraphicsPipe *pipe);
|
||||||
PT(GraphicsStateGuardian) make_gsg(GraphicsPipe *pipe,
|
PT(GraphicsStateGuardian) make_gsg(GraphicsPipe *pipe,
|
||||||
const FrameBufferProperties &properties,
|
const FrameBufferProperties &properties,
|
||||||
@ -226,6 +229,7 @@ private:
|
|||||||
FrameBufferProperties _frame_buffer_properties;
|
FrameBufferProperties _frame_buffer_properties;
|
||||||
GraphicsThreadingModel _threading_model;
|
GraphicsThreadingModel _threading_model;
|
||||||
bool _auto_flip;
|
bool _auto_flip;
|
||||||
|
bool _portal_enabled; //toggle to portal culling on/off
|
||||||
|
|
||||||
enum FlipState {
|
enum FlipState {
|
||||||
FS_draw, // Still drawing.
|
FS_draw, // Still drawing.
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
pandaNode.I pandaNode.h \
|
pandaNode.I pandaNode.h \
|
||||||
planeNode.I planeNode.h \
|
planeNode.I planeNode.h \
|
||||||
pointLight.I pointLight.h \
|
pointLight.I pointLight.h \
|
||||||
|
portalNode.I portalNode.h \
|
||||||
portalClipper.I portalClipper.h \
|
portalClipper.I portalClipper.h \
|
||||||
renderAttrib.I renderAttrib.h \
|
renderAttrib.I renderAttrib.h \
|
||||||
renderEffect.I renderEffect.h \
|
renderEffect.I renderEffect.h \
|
||||||
@ -154,6 +155,7 @@
|
|||||||
pandaNode.cxx \
|
pandaNode.cxx \
|
||||||
planeNode.cxx \
|
planeNode.cxx \
|
||||||
pointLight.cxx \
|
pointLight.cxx \
|
||||||
|
portalNode.cxx \
|
||||||
portalClipper.cxx \
|
portalClipper.cxx \
|
||||||
renderAttrib.cxx \
|
renderAttrib.cxx \
|
||||||
renderEffect.cxx \
|
renderEffect.cxx \
|
||||||
@ -235,6 +237,7 @@
|
|||||||
pandaNode.I pandaNode.h \
|
pandaNode.I pandaNode.h \
|
||||||
planeNode.I planeNode.h \
|
planeNode.I planeNode.h \
|
||||||
pointLight.I pointLight.h \
|
pointLight.I pointLight.h \
|
||||||
|
portalNode.I portalNode.h \
|
||||||
portalClipper.I portalClipper.h \
|
portalClipper.I portalClipper.h \
|
||||||
renderAttrib.I renderAttrib.h \
|
renderAttrib.I renderAttrib.h \
|
||||||
renderEffect.I renderEffect.h \
|
renderEffect.I renderEffect.h \
|
||||||
|
@ -73,13 +73,14 @@ CullTraverser(const CullTraverser ©) :
|
|||||||
// Description: Begins the traversal from the indicated node.
|
// Description: Begins the traversal from the indicated node.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CullTraverser::
|
void CullTraverser::
|
||||||
traverse(const NodePath &root) {
|
traverse(const NodePath &root, bool python_cull_control) {
|
||||||
nassertv(_cull_handler != (CullHandler *)NULL);
|
nassertv(_cull_handler != (CullHandler *)NULL);
|
||||||
nassertv(_scene_setup != (SceneSetup *)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;
|
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;
|
GeometricBoundingVolume *local_frustum = NULL;
|
||||||
PT(BoundingVolume) bv = _scene_setup->get_lens()->make_bounds();
|
PT(BoundingVolume) bv = _scene_setup->get_lens()->make_bounds();
|
||||||
@ -88,26 +89,32 @@ traverse(const NodePath &root) {
|
|||||||
|
|
||||||
local_frustum = DCAST(GeometricBoundingVolume, bv);
|
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);
|
PortalClipper portal_viewer(local_frustum, _scene_setup);
|
||||||
portal_viewer.draw_camera_frustum();
|
portal_viewer.draw_camera_frustum();
|
||||||
|
|
||||||
// for each portal draw its frustum
|
if (allow_portal_cull || python_cull_control) {
|
||||||
for (int portal_idx=1; portal_idx<2; ++portal_idx) {
|
// for each portal draw its frustum
|
||||||
PT(BoundingVolume) reduced_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);
|
portal_viewer.prepare_portal(portal_idx);
|
||||||
if ((reduced_frustum = portal_viewer.get_reduced_frustum(portal_idx))) {
|
portal_viewer.clip_portal(portal_idx);
|
||||||
pgraph_cat.debug() << "got reduced frustum " << reduced_frustum << endl;
|
if ((reduced_frustum = portal_viewer.get_reduced_frustum(portal_idx))) {
|
||||||
vf = DCAST(GeometricBoundingVolume, reduced_frustum);
|
// This reduced frustum is in camera space
|
||||||
CPT(TransformState) cull_center_transform =
|
pgraph_cat.debug() << "got reduced frustum " << reduced_frustum << endl;
|
||||||
_scene_setup->get_cull_center().get_transform(_scene_setup->get_scene_root());
|
vf = DCAST(GeometricBoundingVolume, reduced_frustum);
|
||||||
vf->xform(cull_center_transform->get_mat());
|
|
||||||
|
// 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(),
|
CullTraverserData data(root, get_render_transform(),
|
||||||
TransformState::make_identity(),
|
TransformState::make_identity(),
|
||||||
|
@ -75,7 +75,7 @@ public:
|
|||||||
INLINE void set_cull_handler(CullHandler *cull_handler);
|
INLINE void set_cull_handler(CullHandler *cull_handler);
|
||||||
INLINE CullHandler *get_cull_handler() const;
|
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(CullTraverserData &data);
|
||||||
void traverse_below(CullTraverserData &data);
|
void traverse_below(CullTraverserData &data);
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "pandaNode.cxx"
|
#include "pandaNode.cxx"
|
||||||
#include "planeNode.cxx"
|
#include "planeNode.cxx"
|
||||||
#include "pointLight.cxx"
|
#include "pointLight.cxx"
|
||||||
|
#include "portalNode.cxx"
|
||||||
#include "portalClipper.cxx"
|
#include "portalClipper.cxx"
|
||||||
#include "renderAttrib.cxx"
|
#include "renderAttrib.cxx"
|
||||||
#include "renderEffect.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
|
// Description: Draw the current camera frustum in white color
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void PortalClipper::
|
INLINE void PortalClipper::
|
||||||
draw_camera_frustum()
|
draw_camera_frustum()
|
||||||
{
|
{
|
||||||
_color = Colorf(1,1,1,1);
|
_color = Colorf(1,1,1,1);
|
||||||
@ -107,13 +107,13 @@ draw_camera_frustum()
|
|||||||
// Description: checks if the _coords that forms the plane is
|
// Description: checks if the _coords that forms the plane is
|
||||||
// facing the camera
|
// facing the camera
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool PortalClipper::
|
INLINE bool PortalClipper::
|
||||||
is_facing_camera()
|
is_facing_camera()
|
||||||
{
|
{
|
||||||
Planef portal_plane(_coords[0], _coords[1], _coords[2]);
|
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));
|
Planef camera_plane(_hex_frustum->get_point(4), _hex_frustum->get_point(5), _hex_frustum->get_point(6));
|
||||||
|
pgraph_cat.debug() << portal_plane.get_normal() << "; " << -camera_plane.get_normal() << endl;
|
||||||
float direction = portal_plane.get_normal().dot(camera_plane.get_normal());
|
float direction = portal_plane.get_normal().dot(-camera_plane.get_normal());
|
||||||
pgraph_cat.debug() << "Found direction of " << direction << endl;
|
pgraph_cat.debug() << "Found direction of " << direction << endl;
|
||||||
return (direction > 0);
|
return (direction < _FACING_THRESHOLD);
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,10 @@ class CullTraverserData;
|
|||||||
class CullableObject;
|
class CullableObject;
|
||||||
class NodePath;
|
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
|
// Class : PortalClipper
|
||||||
// Description : This object performs a depth-first traversal of the
|
// Description : This object performs a depth-first traversal of the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user