28 int ClipPlaneAttrib::_attrib_slot;
32 class ComparePlaneNodePriorities {
38 nassertr(pa !=
nullptr && pb !=
nullptr, a < b);
40 return pa->get_priority() > pb->get_priority();
52 make(ClipPlaneAttrib::Operation op,
PlaneNode *plane) {
54 <<
"Using deprecated ClipPlaneAttrib interface.\n";
60 attrib = make_all_off();
75 nassert_raise(
"invalid operation");
89 <<
"Using deprecated ClipPlaneAttrib interface.\n";
95 attrib = make_all_off();
113 nassert_raise(
"invalid operation");
128 <<
"Using deprecated ClipPlaneAttrib interface.\n";
134 attrib = make_all_off();
155 nassert_raise(
"invalid operation");
170 <<
"Using deprecated ClipPlaneAttrib interface.\n";
176 attrib = make_all_off();
200 nassert_raise(
"invalid operation");
227 <<
"Using deprecated ClipPlaneAttrib interface.\n";
250 <<
"Using deprecated ClipPlaneAttrib interface.\n";
269 <<
"Using deprecated ClipPlaneAttrib interface.\n";
289 <<
"Using deprecated ClipPlaneAttrib interface.\n";
308 <<
"Using deprecated ClipPlaneAttrib interface.\n";
310 if (get_num_off_planes() == 0) {
311 return add_on_plane(
NodePath(plane));
313 return add_off_plane(
NodePath(plane));
327 <<
"Using deprecated ClipPlaneAttrib interface.\n";
330 return remove_on_plane(
NodePath(plane));
332 return remove_off_plane(
NodePath(plane));
343 if (_empty_attrib ==
nullptr) {
347 return _empty_attrib;
358 if (_all_off_attrib ==
nullptr) {
360 attrib->_off_all_planes =
true;
361 _all_off_attrib = return_new(attrib);
364 return _all_off_attrib;
372 add_on_plane(
const NodePath &plane)
const {
375 attrib->_on_planes.insert(plane);
376 attrib->_off_planes.erase(plane);
378 std::pair<Planes::iterator, bool> insert_result =
379 attrib->_on_planes.insert(Planes::value_type(plane));
380 if (insert_result.second) {
382 attrib->_off_planes.erase(plane);
385 return return_new(attrib);
393 remove_on_plane(
const NodePath &plane)
const {
396 attrib->_on_planes.erase(plane);
397 return return_new(attrib);
405 add_off_plane(
const NodePath &plane)
const {
408 if (!_off_all_planes) {
409 attrib->_off_planes.insert(plane);
411 attrib->_on_planes.erase(plane);
412 return return_new(attrib);
420 remove_off_plane(
const NodePath &plane)
const {
423 attrib->_off_planes.erase(plane);
424 return return_new(attrib);
433 filter_to_max(
int max_clip_planes)
const {
434 if (max_clip_planes < 0 || (
int)_on_planes.
size() <= max_clip_planes) {
443 Filtered::const_iterator fi;
444 fi = _filtered.find(max_clip_planes);
445 if (fi != _filtered.end()) {
453 Planes priority_planes = _on_planes;
456 sort(priority_planes.begin(), priority_planes.end(),
457 ComparePlaneNodePriorities());
460 priority_planes.erase(priority_planes.begin() + max_clip_planes,
461 priority_planes.end());
464 priority_planes.sort();
468 attrib->_on_planes.
swap(priority_planes);
474 ((
ClipPlaneAttrib *)
this)->_filtered[max_clip_planes] = planeNode_attrib;
475 return planeNode_attrib;
490 DCAST_INTO_R(ta, other,
nullptr);
492 if (_off_all_planes || (!ta->_off_all_planes && ta->_off_planes.
empty())) {
498 if (ta->_off_all_planes || _off_planes.
empty()) {
503 Planes::const_iterator ai = _off_planes.
begin();
504 Planes::const_iterator bi = ta->_off_planes.
begin();
508 std::back_insert_iterator<Planes> result =
509 std::back_inserter(new_attrib->_on_planes);
511 while (ai != _off_planes.
end() &&
512 bi != ta->_off_planes.
end()) {
520 }
else if ((*bi) < (*ai)) {
536 while (ai != _off_planes.
end()) {
542 while (bi != ta->_off_planes.
end()) {
548 return return_new(new_attrib);
554 void ClipPlaneAttrib::
555 output(std::ostream &out)
const {
556 out << get_type() <<
":";
557 if (_off_planes.
empty()) {
558 if (_on_planes.
empty()) {
559 if (_off_all_planes) {
565 if (_off_all_planes) {
574 Planes::const_iterator fi;
575 for (fi = _off_planes.
begin(); fi != _off_planes.
end(); ++fi) {
580 if (!_on_planes.
empty()) {
585 Planes::const_iterator li;
586 for (li = _on_planes.
begin(); li != _on_planes.
end(); ++li) {
604 int ClipPlaneAttrib::
607 DCAST_INTO_R(ta, other, 0);
609 if (_off_all_planes != ta->_off_all_planes) {
610 return (
int)_off_all_planes - (int)ta->_off_all_planes;
613 Planes::const_iterator li = _on_planes.
begin();
614 Planes::const_iterator oli = ta->_on_planes.
begin();
616 while (li != _on_planes.
end() && oli != ta->_on_planes.
end()) {
629 if (li != _on_planes.
end()) {
632 if (oli != ta->_on_planes.
end()) {
636 Planes::const_iterator fi = _off_planes.
begin();
637 Planes::const_iterator ofi = ta->_off_planes.
begin();
639 while (fi != _off_planes.
end() && ofi != ta->_off_planes.
end()) {
652 if (fi != _off_planes.
end()) {
655 if (ofi != ta->_off_planes.
end()) {
668 size_t ClipPlaneAttrib::
669 get_hash_impl()
const {
672 Planes::const_iterator li;
673 for (li = _on_planes.
begin(); li != _on_planes.
end(); ++li) {
682 for (li = _off_planes.
begin(); li != _off_planes.
end(); ++li) {
704 DCAST_INTO_R(ta, other,
nullptr);
706 if (ta->_off_all_planes) {
714 Planes::const_iterator ai = _on_planes.
begin();
715 Planes::const_iterator bi = ta->_on_planes.
begin();
716 Planes::const_iterator ci = ta->_off_planes.
begin();
720 std::back_insert_iterator<Planes> result =
721 std::back_inserter(new_attrib->_on_planes);
723 while (ai != _on_planes.
end() &&
724 bi != ta->_on_planes.
end() &&
725 ci != ta->_off_planes.
end()) {
734 }
else if ((*ci) < (*ai)) {
746 }
else if ((*bi) < (*ai)) {
762 while (ai != _on_planes.
end() && bi != ta->_on_planes.
end()) {
770 }
else if ((*bi) < (*ai)) {
786 while (ai != _on_planes.
end() && ci != ta->_off_planes.
end()) {
794 }
else if ((*ci) < (*ai)) {
807 while (ai != _on_planes.
end()) {
813 while (bi != ta->_on_planes.
end()) {
819 return return_new(new_attrib);
841 void ClipPlaneAttrib::
869 Planes::const_iterator fi;
871 for (fi = _off_planes.
begin(); fi != _off_planes.
end(); ++fi) {
875 for (fi = _off_planes.
begin(); fi != _off_planes.
end(); ++fi) {
876 (*fi).write_datagram(manager, dg);
884 Planes::const_iterator nti;
886 for (nti = _on_planes.
begin(); nti != _on_planes.
end(); ++nti) {
890 for (nti = _on_planes.
begin(); nti != _on_planes.
end(); ++nti) {
891 (*nti).write_datagram(manager, dg);
905 for (
size_t i = 0; i < _off_planes.
size(); ++i) {
906 pi += _off_planes[i].complete_pointers(p_list + pi, manager);
909 for (
size_t i = 0; i < _on_planes.
size(); ++i) {
910 pi += _on_planes[i].complete_pointers(p_list + pi, manager);
915 nassertr(aux !=
nullptr, pi);
918 aux->_off_list.reserve(aux->_num_off_planes);
919 for (i = 0; i < aux->_num_off_planes; ++i) {
921 DCAST_INTO_R(node, p_list[pi++], pi);
922 aux->_off_list.push_back(node);
925 aux->_on_list.reserve(aux->_num_on_planes);
926 for (i = 0; i < aux->_num_on_planes; ++i) {
928 DCAST_INTO_R(node, p_list[pi++], pi);
929 aux->_on_list.push_back(node);
948 for (
size_t i = 0; i < _off_planes.
size(); ++i) {
956 for (
size_t i = 0; i < _on_planes.
size(); ++i) {
967 nassertv(aux !=
nullptr);
968 nassertv(aux->_num_off_planes == (
int)aux->_off_list.size());
969 nassertv(aux->_num_on_planes == (
int)aux->_on_list.size());
973 _off_planes.
reserve(aux->_off_list.size());
974 NodeList::iterator ni;
975 for (ni = aux->_off_list.begin(); ni != aux->_off_list.end(); ++ni) {
977 int n = areg->find_node(node->get_type(), node->get_name());
980 _off_planes.
push_back(areg->get_node(n));
987 _on_planes.
reserve(aux->_on_list.size());
988 for (ni = aux->_on_list.begin(); ni != aux->_on_list.end(); ++ni) {
990 int n = areg->find_node(node->get_type(), node->get_name());
1019 attrib->fillin(scan, manager);
1030 void ClipPlaneAttrib::
1032 RenderAttrib::fillin(scan, manager);
1038 for (
size_t i = 0; i < _off_planes.
size(); ++i) {
1039 _off_planes[i].fillin(scan, manager);
1043 for (
size_t i = 0; i < _on_planes.
size(); ++i) {
1044 _on_planes[i].fillin(scan, manager);
1047 BamAuxData *aux =
new BamAuxData;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 has_off_plane(const NodePath &plane) const
Returns true if the indicated plane is disabled by the attrib, false otherwise.
AuxData * get_aux_data(TypedWritable *obj, const std::string &name) const
Returns the pointer previously associated with the bam reader by a previous call to set_aux_data(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
size_type_0 size() const
Returns the number of elements in the ordered vector.
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...
bool has_all_off() const
Returns true if this attrib disables all planes (although it may also enable some).
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 ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This functions similarly to a LightAttrib.
reference back()
Returns a reference to the first element.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
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.
void reserve(size_type_0 n)
Informs the vector of a planned change in size; ensures that the capacity of the vector is greater th...
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
void swap(ordered_vector< Key, Compare, Vector > &other)
Exchanges the contents of this vector and the other vector, in constant time (e.g....
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
get_off_plane
Returns the nth plane disabled by the attribute, sorted in arbitrary (pointer) order.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
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...
CPT(RenderAttrib) ClipPlaneAttrib
Constructs a new ClipPlaneAttrib object that enables (or disables, according to op) the indicated pla...
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().
get_num_off_planes
Returns the number of planes that are disabled by the attribute.
get_num_on_planes
Returns the number of planes that are enabled by the attribute.
void read_pointers(DatagramIterator &scan, int count)
A convenience function to read a contiguous list of pointers.
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...
bool has_on_plane(const NodePath &plane) const
Returns true if the indicated plane is enabled by the attrib, false otherwise.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
void set_aux_data(TypedWritable *obj, const std::string &name, AuxData *data)
Associates an arbitrary block of data with the indicated object (or NULL), and the indicated name.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
PandaNode * node() const
Returns the referenced node of the path.
get_on_plane
Returns the nth plane enabled by the attribute, sorted in render order.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
get_node
Returns the nth NodePath recorded in the registry.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.