15 #include "clipPlaneAttrib.h" 16 #include "pandaNode.h" 17 #include "graphicsStateGuardianBase.h" 18 #include "bamReader.h" 19 #include "bamWriter.h" 21 #include "datagramIterator.h" 22 #include "config_pgraph.h" 23 #include "attribNodeRegistry.h" 29 int ClipPlaneAttrib::_attrib_slot;
41 return pa->get_priority() > pb->get_priority();
55 make(ClipPlaneAttrib::Operation op,
PlaneNode *plane) {
57 <<
"Using deprecated ClipPlaneAttrib interface.\n";
63 attrib = make_all_off();
78 nassertr(
false, make());
94 <<
"Using deprecated ClipPlaneAttrib interface.\n";
100 attrib = make_all_off();
118 nassertr(
false, make());
135 <<
"Using deprecated ClipPlaneAttrib interface.\n";
141 attrib = make_all_off();
162 nassertr(
false, make());
179 <<
"Using deprecated ClipPlaneAttrib interface.\n";
185 attrib = make_all_off();
209 nassertr(
false, make());
244 <<
"Using deprecated ClipPlaneAttrib interface.\n";
249 }
else if (get_num_off_planes() == 0) {
270 <<
"Using deprecated ClipPlaneAttrib interface.\n";
272 if (get_num_off_planes() == 0) {
273 return get_num_on_planes();
275 return get_num_off_planes();
292 <<
"Using deprecated ClipPlaneAttrib interface.\n";
294 if (get_num_off_planes() == 0) {
295 return DCAST(
PlaneNode, get_on_plane(n).node());
297 return DCAST(
PlaneNode, get_off_plane(n).node());
315 <<
"Using deprecated ClipPlaneAttrib interface.\n";
317 if (get_num_off_planes() == 0) {
318 return has_on_plane(
NodePath(plane));
320 return has_off_plane(
NodePath(plane));
336 <<
"Using deprecated ClipPlaneAttrib interface.\n";
338 if (get_num_off_planes() == 0) {
339 return add_on_plane(
NodePath(plane));
341 return add_off_plane(
NodePath(plane));
358 <<
"Using deprecated ClipPlaneAttrib interface.\n";
360 if (get_num_off_planes() == 0) {
361 return remove_on_plane(
NodePath(plane));
363 return remove_off_plane(
NodePath(plane));
381 return _empty_attrib;
396 attrib->_off_all_planes =
true;
397 _all_off_attrib = return_new(attrib);
400 return _all_off_attrib;
411 add_on_plane(
const NodePath &plane)
const {
414 attrib->_on_planes.insert(plane);
415 attrib->_off_planes.erase(plane);
417 pair<Planes::iterator, bool> insert_result =
419 if (insert_result.second) {
421 attrib->_off_planes.erase(plane);
424 return return_new(attrib);
435 remove_on_plane(
const NodePath &plane)
const {
438 attrib->_on_planes.erase(plane);
439 return return_new(attrib);
450 add_off_plane(
const NodePath &plane)
const {
453 if (!_off_all_planes) {
454 attrib->_off_planes.insert(plane);
456 attrib->_on_planes.erase(plane);
457 return return_new(attrib);
468 remove_off_plane(
const NodePath &plane)
const {
471 attrib->_off_planes.erase(plane);
472 return return_new(attrib);
484 filter_to_max(
int max_clip_planes)
const {
485 if (max_clip_planes < 0 || (
int)_on_planes.size() <= max_clip_planes) {
494 Filtered::const_iterator fi;
495 fi = _filtered.find(max_clip_planes);
496 if (fi != _filtered.end()) {
504 Planes priority_planes = _on_planes;
507 sort(priority_planes.
begin(), priority_planes.
end(),
511 priority_planes.erase(priority_planes.
begin() + max_clip_planes,
512 priority_planes.
end());
515 priority_planes.
sort();
519 attrib->_on_planes.
swap(priority_planes);
526 ((
ClipPlaneAttrib *)
this)->_filtered[max_clip_planes] = planeNode_attrib;
527 return planeNode_attrib;
546 DCAST_INTO_R(ta, other, NULL);
548 if (_off_all_planes || (!ta->_off_all_planes && ta->_off_planes.
empty())) {
554 if (ta->_off_all_planes || _off_planes.empty()) {
559 Planes::const_iterator ai = _off_planes.begin();
560 Planes::const_iterator bi = ta->_off_planes.
begin();
564 back_insert_iterator<Planes> result =
565 back_inserter(new_attrib->_on_planes);
567 while (ai != _off_planes.end() &&
568 bi != ta->_off_planes.
end()) {
576 }
else if ((*bi) < (*ai)) {
592 while (ai != _off_planes.end()) {
598 while (bi != ta->_off_planes.
end()) {
604 return return_new(new_attrib);
612 void ClipPlaneAttrib::
613 output(ostream &out)
const {
614 out << get_type() <<
":";
615 if (_off_planes.empty()) {
616 if (_on_planes.empty()) {
617 if (_off_all_planes) {
623 if (_off_all_planes) {
632 Planes::const_iterator fi;
633 for (fi = _off_planes.begin(); fi != _off_planes.end(); ++fi) {
638 if (!_on_planes.empty()) {
643 Planes::const_iterator li;
644 for (li = _on_planes.begin(); li != _on_planes.end(); ++li) {
665 int ClipPlaneAttrib::
668 DCAST_INTO_R(ta, other, 0);
670 if (_off_all_planes != ta->_off_all_planes) {
671 return (
int)_off_all_planes - (int)ta->_off_all_planes;
674 Planes::const_iterator li = _on_planes.begin();
675 Planes::const_iterator oli = ta->_on_planes.
begin();
677 while (li != _on_planes.end() && oli != ta->_on_planes.
end()) {
690 if (li != _on_planes.end()) {
693 if (oli != ta->_on_planes.
end()) {
697 Planes::const_iterator fi = _off_planes.begin();
698 Planes::const_iterator ofi = ta->_off_planes.
begin();
700 while (fi != _off_planes.end() && ofi != ta->_off_planes.
end()) {
713 if (fi != _off_planes.end()) {
716 if (ofi != ta->_off_planes.
end()) {
733 size_t ClipPlaneAttrib::
734 get_hash_impl()
const {
737 Planes::const_iterator li;
738 for (li = _on_planes.begin(); li != _on_planes.end(); ++li) {
747 for (li = _off_planes.begin(); li != _off_planes.end(); ++li) {
775 DCAST_INTO_R(ta, other, NULL);
777 if (ta->_off_all_planes) {
786 Planes::const_iterator ai = _on_planes.begin();
787 Planes::const_iterator bi = ta->_on_planes.
begin();
788 Planes::const_iterator ci = ta->_off_planes.
begin();
792 back_insert_iterator<Planes> result =
793 back_inserter(new_attrib->_on_planes);
795 while (ai != _on_planes.end() &&
796 bi != ta->_on_planes.
end() &&
797 ci != ta->_off_planes.
end()) {
806 }
else if ((*ci) < (*ai)) {
818 }
else if ((*bi) < (*ai)) {
834 while (ai != _on_planes.end() && bi != ta->_on_planes.
end()) {
842 }
else if ((*bi) < (*ai)) {
858 while (ai != _on_planes.end() && ci != ta->_off_planes.
end()) {
866 }
else if ((*ci) < (*ai)) {
879 while (ai != _on_planes.end()) {
885 while (bi != ta->_on_planes.
end()) {
891 return return_new(new_attrib);
917 get_auto_shader_attrib_impl(
const RenderState *state)
const {
929 void ClipPlaneAttrib::
961 Planes::const_iterator fi;
962 for (fi = _off_planes.begin(); fi != _off_planes.end(); ++fi) {
974 Planes::const_iterator nti;
975 for (nti = _on_planes.begin(); nti != _on_planes.end(); ++nti) {
993 Planes::iterator ci = _off_planes.begin();
994 while (ci != _off_planes.end()) {
996 DCAST_INTO_R(node, p_list[pi++], pi);
1002 int ni = areg->
find_node(node->get_type(), node->get_name());
1012 ci = _on_planes.begin();
1013 while (ci != _on_planes.end()) {
1015 DCAST_INTO_R(node, p_list[pi++], pi);
1017 int ni = areg->
find_node(node->get_type(), node->get_name());
1059 parse_params(params, scan, manager);
1060 attrib->fillin(scan, manager);
1072 void ClipPlaneAttrib::
1074 RenderAttrib::fillin(scan, manager);
1090 _off_planes.reserve(num_off_planes);
1092 for (i = 0; i < num_off_planes; i++) {
1098 _on_planes.reserve(num_on_planes);
1099 for (i = 0; i < num_on_planes; i++) {
PlaneNode * get_plane(int n) const
Returns the nth plane listed in the attribute.
A basic node of the scene graph or data graph.
bool get_bool()
Extracts a boolean value.
This is the base class for a number of render attributes (other than transform) that may be set on sc...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
bool is_empty() const
Returns true if the NodePath contains no nodes.
int get_num_planes() const
Returns the number of planes listed in the attribute.
This global object records NodePaths that are referenced by scene graph attribs, such as ClipPlaneAtt...
int compare_to(const NodePath &other) const
Returns a number less than zero if this NodePath sorts before the other one, greater than zero if it ...
Base class for objects that can be written to and read from Bam files.
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
This functions similarly to a LightAttrib.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
void swap(ordered_vector< Key, Compare, Vector > &other)
Exchanges the contents of this vector and the other vector, in constant time (e.g., with a pointer swap).
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
void add_bool(bool value)
Adds a boolean value to the datagram.
int find_node(const NodePath &attrib_node) const
Returns the index number of the indicated NodePath in the registry (assuming its name hasn't changed ...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
static UpdateSeq get_sort_seq()
Returns a global sequence number that is incremented any time any PlaneNode in the world changes sort...
Operation get_operation() const
Returns the basic operation type of the ClipPlaneAttrib.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
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()...
void sort()
Maps to sort_unique().
An instance of this class is passed to the Factory when requesting it to do its business and construc...
virtual bool require_fully_complete() const
Some objects require all of their nested pointers to have been completed before the objects themselve...
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.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
NodePath get_node(int n) const
Returns the nth NodePath recorded in the registry.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
PandaNode * node() const
Returns the referenced node of the path.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
static void register_with_read_factory()
Tells the BamReader how to create objects of type ClipPlaneAttrib.
A class to retrieve the individual data elements previously stored in a Datagram. ...
size_t add_hash(size_t hash) const
Adds the NodePath into the running hash.
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
bool has_plane(PlaneNode *plane) const
Returns true if the indicated plane is listed in the attrib, false otherwise.
A node that contains a plane.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.