15 #include "portalNode.h"
18 #include "cullTraverserData.h"
19 #include "cullTraverser.h"
20 #include "renderState.h"
21 #include "portalClipper.h"
22 #include "transformState.h"
23 #include "clipPlaneAttrib.h"
24 #include "colorScaleAttrib.h"
25 #include "transparencyAttrib.h"
27 #include "datagramIterator.h"
28 #include "bamReader.h"
29 #include "bamWriter.h"
30 #include "boundingSphere.h"
94 _from_portal_mask(copy._from_portal_mask),
95 _into_portal_mask(copy._into_portal_mask),
97 _vertices(copy._vertices),
98 _cell_in(copy._cell_in),
99 _cell_out(copy._cell_out),
100 _clip_plane(copy._clip_plane),
101 _visible(copy._visible),
103 _max_depth(copy._max_depth)
151 _bottom_plane_node =
new PlaneNode(
"bottom");
154 _left_plane_node =
new PlaneNode(
"left");
157 _right_plane_node =
new PlaneNode(
"right");
160 CPT(
RenderAttrib) plane_attrib = ClipPlaneAttrib::make();
166 _clip_state = RenderState::make(plane_attrib);
204 if (get_name() == cother->get_name()) {
234 if (
is_open() && !_cell_out.
is_empty() && portal_viewer && data._portal_depth <= _max_depth) {
235 portal_cat.debug() <<
"checking portal node " << *
this << endl;
236 portal_cat.debug() <<
"portal_depth is " << data._portal_depth << endl;
241 LPoint2 old_reduced_viewport_min, old_reduced_viewport_max;
258 CPT(TransformState) cell_transform = _cell_out.get_net_transform();
259 CPT(TransformState) frustum_transform = cell_transform ->invert_compose(portal_viewer->_scene_setup->
get_cull_center().get_net_transform());
262 new_bh->xform(frustum_transform->get_mat());
270 CPT(TransformState) temp_frustum_transform = data._node_path.
get_node_path().get_net_transform()->invert_compose(portal_viewer->_scene_setup->
get_cull_center().get_net_transform());
272 portal_cat.spam() <<
"clipping plane frustum transform " << *temp_frustum_transform << endl;
273 portal_cat.spam() <<
"frustum before transform " << *temp_bh << endl;
275 temp_bh->xform(temp_frustum_transform->get_mat());
277 portal_cat.spam() <<
"frustum after transform " << *temp_bh << endl;
279 _left_plane_node->set_plane(-temp_bh->get_plane(4));
280 _right_plane_node->set_plane(-temp_bh->get_plane(2));
281 _top_plane_node->set_plane(-temp_bh->get_plane(3));
282 _bottom_plane_node->set_plane(-temp_bh->get_plane(1));
284 portal_cat.spam() <<
"left plane " << *_left_plane_node << endl;
285 portal_cat.spam() <<
"right plane " << *_right_plane_node << endl;
286 portal_cat.spam() <<
"top plane " << *_top_plane_node << endl;
287 portal_cat.spam() <<
"bottom plane " << *_bottom_plane_node << endl;
292 if (old_clip_state) {
293 portal_cat.spam() <<
"parent clip state " << *old_clip_state << endl;
295 portal_cat.spam() <<
"parent clip state None" << endl;
297 portal_cat.spam() <<
"own clip state " << *_clip_state << endl;
298 portal_cat.spam() <<
"next state " << *next_state << endl;
301 if (old_clip_state != NULL) {
302 next_state = old_clip_state->invert_compose(next_state);
303 portal_cat.spam() <<
"next state after removing parent state " << *next_state << endl;
305 next_state = next_state->compose(_clip_state);
306 portal_cat.spam() <<
"next state after composition " << *next_state << endl;
313 next_data._portal_depth = data._portal_depth + 1;
316 portal_cat.spam() <<
"cull_callback: before traversing " << _cell_out.
get_name() << endl;
318 portal_cat.spam() <<
"cull_callback: after traversing " << _cell_out.
get_name() << endl;
359 PandaNode::output(out);
364 // Function: PortalNode::draw
366 // Description: Draws the vertices of this portal rectangle to the
367 // screen with a line
372 move_to(get_vertex(0));
373 draw_to(get_vertex(1));
374 draw_to(get_vertex(2));
375 draw_to(get_vertex(3));
389 int &internal_vertices,
391 Thread *current_thread)
const {
399 const
LPoint3 *vertices_begin = &_vertices[0];
400 const
LPoint3 *vertices_end = vertices_begin + _vertices.size();
403 gbv->around(vertices_begin, vertices_end);
405 internal_bounds = bound;
406 internal_vertices = 0;
418 get_last_pos_state() {
423 state = RenderState::make
424 (ColorScaleAttrib::make(
LVecBase4(1.0f, 1.0f, 1.0f, 0.5f)),
425 TransparencyAttrib::make(TransparencyAttrib::M_alpha));
454 for (Vertices::const_iterator vi = _vertices.begin();
455 vi != _vertices.end();
457 (*vi).write_datagram(dg);
489 parse_params(params, scan, manager);
490 node->fillin(scan, manager);
504 PandaNode::fillin(scan, manager);
507 _vertices.reserve(num_vertices);
508 for (
int i = 0; i < num_vertices; i++) {
511 _vertices.push_back(vertex);
A basic node of the scene graph or data graph.
bool is_open()
Is this portal open from current camera zone.
void get_reduced_viewport(LPoint2 &min, LPoint2 &max) const
Return the reduced viewport.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
bool prepare_portal(const NodePath &node_path)
Given the portal draw the frustum with line segs for now.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual void traverse_below(CullTraverserData &data)
Traverses all the children of the indicated node, with the given data, which has been converted into ...
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this node by the indicated matrix, if it means anything to do so...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
virtual PandaNode * combine_with(PandaNode *other)
Collapses this PandaNode with the other PandaNode, if possible, and returns a pointer to the combined...
void read_datagram(DatagramIterator &source)
Reads the vector from the Datagram using get_stdfloat().
This defines a bounding sphere, consisting of a center and a radius.
Base class for objects that can be written to and read from Bam files.
This collects together the pieces of data that are accumulated for each node while walking the scene ...
void set_reduced_frustum(BoundingHexahedron *bh)
Set the current view frustum that is being calculated by the portal clipper.
bool is_exact_type(TypeHandle handle) const
Returns true if the current object is the indicated type exactly.
PortalNode(const string &name)
Default constructor, just an empty node, no geo This is used to read portal from model.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
This functions similarly to a LightAttrib.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
static void register_with_read_factory()
Tells the BamReader how to create objects of type PortalNode.
void set_clip_state(const RenderState *clip_state)
Set the clip state of the current portal node This is done to remember the state for the child portal...
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
A node in the scene graph that can hold a Portal Polygon, which is a rectangle.
const RenderState * get_clip_state() const
Returns the stored clip state.
string get_name() const
Returns the name of the referenced node.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
NodePath get_node_path() const
Constructs and returns an actual NodePath that represents the same path we have just traversed...
This is a 4-by-4 transform matrix.
PortalClipper * get_portal_clipper() const
Returns the _portal_clipper pointer.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
virtual PandaNode * combine_with(PandaNode *other)
Collapses this node with the other node, if possible, and returns a pointer to the combined node...
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform reduced frustum culling...
const NodePath & get_cull_center() const
Returns the point from which the culling operations will be performed.
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the CullTraverser constructor.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
This is the base class for all three-component vectors and points.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A thread; that is, a lightweight process.
virtual bool preserve_name() const
Returns true if the node's name has extrinsic meaning and must be preserved across a flatten operatio...
GeometricBoundingVolume * get_view_frustum() const
Returns the bounding volume that corresponds to the view frustum, or NULL if the view frustum is not ...
bool is_empty() const
Returns true if the NodePath contains no nodes.
A class to retrieve the individual data elements previously stored in a Datagram. ...
This is a two-component point in space.
BoundingHexahedron * get_reduced_frustum() const
Return the reduced frustum.
virtual void output(ostream &out) const
Writes a brief description of the node to the indicated output stream.
TypeHandle is the identifier used to differentiate C++ class types.
void set_reduced_viewport(const LPoint2 &min, const LPoint2 &max)
Set the current viewport that is being used by the portal clipper.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
virtual void enable_clipping_planes()
initialize the clipping planes and renderstate
void add_vertex(const LPoint3 &vertex)
Adds a new vertex to the portal polygon.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
A node that contains a plane.
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
This defines a bounding convex hexahedron.
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
void set_visible(bool value)
this is set if the portal is facing camera