28 int LightAttrib::_attrib_slot;
35 class CompareLightPriorities {
41 nassertr(la !=
nullptr && lb !=
nullptr, a < b);
46 return la->get_class_priority() > lb->get_class_priority();
56 _on_lights(copy._on_lights),
57 _off_lights(copy._off_lights),
58 _off_all_lights(copy._off_all_lights),
62 Lights::const_iterator it;
63 for (it = _on_lights.begin(); it != _on_lights.end(); ++it) {
64 Light *lobj = (*it).node()->as_light();
65 nassertd(lobj !=
nullptr) continue;
76 Lights::const_iterator it;
77 for (it = _on_lights.begin(); it != _on_lights.end(); ++it) {
81 if (lobj !=
nullptr) {
96 make(LightAttrib::Operation op,
Light *light) {
98 <<
"Using deprecated LightAttrib interface.\n";
104 attrib = make_all_off();
119 nassert_raise(
"invalid operation");
131 make(LightAttrib::Operation op,
Light *light1,
Light *light2) {
133 <<
"Using deprecated LightAttrib interface.\n";
139 attrib = make_all_off();
157 nassert_raise(
"invalid operation");
169 make(LightAttrib::Operation op,
Light *light1,
Light *light2,
172 <<
"Using deprecated LightAttrib interface.\n";
178 attrib = make_all_off();
199 nassert_raise(
"invalid operation");
211 make(LightAttrib::Operation op,
Light *light1,
Light *light2,
214 <<
"Using deprecated LightAttrib interface.\n";
220 attrib = make_all_off();
244 nassert_raise(
"invalid operation");
271 <<
"Using deprecated LightAttrib interface.\n";
276 }
else if (get_num_off_lights() == 0) {
294 <<
"Using deprecated LightAttrib interface.\n";
296 if (get_num_off_lights() == 0) {
297 return get_num_on_lights();
299 return get_num_off_lights();
313 <<
"Using deprecated LightAttrib interface.\n";
315 if (get_num_off_lights() == 0) {
316 return get_on_light(n).node()->as_light();
318 return get_off_light(n).node()->as_light();
333 <<
"Using deprecated LightAttrib interface.\n";
335 if (get_num_off_lights() == 0) {
336 return has_on_light(
NodePath(light->as_node()));
338 return has_off_light(
NodePath(light->as_node()));
350 add_light(
Light *light)
const {
352 <<
"Using deprecated LightAttrib interface.\n";
354 if (get_num_off_lights() == 0) {
355 return add_on_light(
NodePath(light->as_node()));
357 return add_off_light(
NodePath(light->as_node()));
369 remove_light(
Light *light)
const {
371 <<
"Using deprecated LightAttrib interface.\n";
373 if (get_num_off_lights() == 0) {
374 return remove_on_light(
NodePath(light->as_node()));
376 return remove_off_light(
NodePath(light->as_node()));
387 if (_empty_attrib ==
nullptr) {
391 return _empty_attrib;
402 if (_all_off_attrib ==
nullptr) {
404 attrib->_off_all_lights =
true;
405 _all_off_attrib = return_new(attrib);
408 return _all_off_attrib;
416 add_on_light(
const NodePath &light)
const {
419 nassertr(lobj !=
nullptr,
this);
423 std::pair<Lights::iterator, bool> insert_result =
424 attrib->_on_lights.insert(Lights::value_type(light));
425 if (insert_result.second) {
429 attrib->_off_lights.erase(light);
432 return return_new(attrib);
440 remove_on_light(
const NodePath &light)
const {
443 nassertr(lobj !=
nullptr,
this);
446 if (attrib->_on_lights.erase(light)) {
447 lobj->attrib_unref();
449 return return_new(attrib);
457 add_off_light(
const NodePath &light)
const {
460 nassertr(lobj !=
nullptr,
this);
463 if (!_off_all_lights) {
464 attrib->_off_lights.insert(light);
466 if (attrib->_on_lights.erase(light)) {
467 lobj->attrib_unref();
469 return return_new(attrib);
477 remove_off_light(
const NodePath &light)
const {
480 attrib->_off_lights.erase(light);
481 return return_new(attrib);
490 get_most_important_light()
const {
493 if (_num_non_ambient_lights > 0) {
494 return _sorted_on_lights[0];
504 get_ambient_contribution()
const {
509 Lights::const_iterator li;
510 li = _sorted_on_lights.begin() + _num_non_ambient_lights;
511 for (; li != _sorted_on_lights.end(); ++li) {
526 output(std::ostream &out)
const {
527 out << get_type() <<
":";
528 if (_off_lights.empty()) {
529 if (_on_lights.empty()) {
530 if (_off_all_lights) {
536 if (_off_all_lights) {
545 Lights::const_iterator fi;
546 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
555 if (!_on_lights.empty()) {
560 Lights::const_iterator li;
561 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
575 write(std::ostream &out,
int indent_level)
const {
576 indent(out, indent_level) << get_type() <<
":";
577 if (_off_lights.empty()) {
578 if (_on_lights.empty()) {
579 if (_off_all_lights) {
585 if (_off_all_lights) {
594 Lights::const_iterator fi;
595 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
597 indent(out, indent_level + 2) << light <<
"\n";
600 if (!_on_lights.empty()) {
601 indent(out, indent_level) <<
"on\n";
605 Lights::const_iterator li;
606 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
608 indent(out, indent_level + 2) << light <<
"\n";
627 if (_off_all_lights != ta->_off_all_lights) {
628 return (
int)_off_all_lights - (int)ta->_off_all_lights;
631 Lights::const_iterator li = _on_lights.begin();
632 Lights::const_iterator oli = ta->_on_lights.
begin();
634 while (li != _on_lights.end() && oli != ta->_on_lights.
end()) {
647 if (li != _on_lights.end()) {
650 if (oli != ta->_on_lights.
end()) {
654 Lights::const_iterator fi = _off_lights.begin();
655 Lights::const_iterator ofi = ta->_off_lights.
begin();
657 while (fi != _off_lights.end() && ofi != ta->_off_lights.
end()) {
670 if (fi != _off_lights.end()) {
673 if (ofi != ta->_off_lights.
end()) {
687 get_hash_impl()
const {
690 Lights::const_iterator li;
691 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
700 for (li = _off_lights.begin(); li != _off_lights.end(); ++li) {
723 if (ta->_off_all_lights) {
731 Lights::const_iterator ai = _on_lights.begin();
732 Lights::const_iterator bi = ta->_on_lights.
begin();
733 Lights::const_iterator ci = ta->_off_lights.
begin();
737 std::back_insert_iterator<Lights> result =
738 std::back_inserter(new_attrib->_on_lights);
740 while (ai != _on_lights.end() &&
741 bi != ta->_on_lights.
end() &&
742 ci != ta->_off_lights.
end()) {
751 }
else if ((*ci) < (*ai)) {
763 }
else if ((*bi) < (*ai)) {
779 while (ai != _on_lights.end() && bi != ta->_on_lights.
end()) {
787 }
else if ((*bi) < (*ai)) {
803 while (ai != _on_lights.end() && ci != ta->_off_lights.
end()) {
811 }
else if ((*ci) < (*ai)) {
824 while (ai != _on_lights.end()) {
830 while (bi != ta->_on_lights.
end()) {
837 Lights::const_iterator it;
838 for (it = new_attrib->_on_lights.
begin(); it != new_attrib->_on_lights.
end(); ++it) {
839 Light *lobj = (*it).node()->as_light();
840 nassertd(lobj !=
nullptr) continue;
845 new_attrib->_sort_seq =
UpdateSeq::old();
847 return return_new(new_attrib);
873 _sorted_on_lights.clear();
874 OrderedLights ambient_lights;
876 Lights::const_iterator li;
877 for (li = _on_lights.begin(); li != _on_lights.end(); ++li) {
882 _sorted_on_lights.push_back(np);
884 ambient_lights.push_back(np);
890 _num_non_ambient_lights = _sorted_on_lights.size();
893 sort(_sorted_on_lights.begin(), _sorted_on_lights.end(),
894 CompareLightPriorities());
899 _sorted_on_lights.insert(_sorted_on_lights.end(),
900 ambient_lights.begin(), ambient_lights.end());
925 Lights::const_iterator fi;
927 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
931 for (fi = _off_lights.begin(); fi != _off_lights.end(); ++fi) {
932 (*fi).write_datagram(manager, dg);
939 Lights::const_iterator nti;
941 for (nti = _on_lights.begin(); nti != _on_lights.end(); ++nti) {
945 for (nti = _on_lights.begin(); nti != _on_lights.end(); ++nti) {
946 (*nti).write_datagram(manager, dg);
960 for (
size_t i = 0; i < _off_lights.size(); ++i) {
961 pi += _off_lights[i].complete_pointers(p_list + pi, manager);
964 for (
size_t i = 0; i < _on_lights.size(); ++i) {
965 pi += _on_lights[i].complete_pointers(p_list + pi, manager);
970 nassertr(aux !=
nullptr, pi);
973 aux->_off_list.reserve(aux->_num_off_lights);
974 for (i = 0; i < aux->_num_off_lights; ++i) {
976 DCAST_INTO_R(node, p_list[pi++], pi);
977 aux->_off_list.push_back(node);
980 aux->_on_list.reserve(aux->_num_on_lights);
981 for (i = 0; i < aux->_num_on_lights; ++i) {
983 DCAST_INTO_R(node, p_list[pi++], pi);
984 aux->_on_list.push_back(node);
1003 for (
size_t i = 0; i < _off_lights.size(); ++i) {
1004 int n = areg->
find_node(_off_lights[i]);
1007 _off_lights[i] = areg->
get_node(n);
1011 for (
size_t i = 0; i < _on_lights.size(); ++i) {
1018 Light *lobj = _on_lights[i].node()->as_light();
1019 nassertd(lobj !=
nullptr)
continue;
1026 nassertv(aux !=
nullptr);
1027 nassertv(aux->_num_off_lights == (
int)aux->_off_list.size());
1028 nassertv(aux->_num_on_lights == (
int)aux->_on_list.size());
1032 _off_lights.reserve(aux->_off_list.size());
1033 NodeList::iterator ni;
1034 for (ni = aux->_off_list.begin(); ni != aux->_off_list.end(); ++ni) {
1036 int n = areg->find_node(node->get_type(), node->get_name());
1039 _off_lights.push_back(areg->get_node(n));
1042 _off_lights.push_back(
NodePath(node));
1046 _on_lights.reserve(aux->_on_list.size());
1047 for (ni = aux->_on_list.begin(); ni != aux->_on_list.end(); ++ni) {
1049 int n = areg->find_node(node->get_type(), node->get_name());
1052 _on_lights.push_back(areg->get_node(n));
1053 node = _on_lights.back().node();
1056 _on_lights.push_back(
NodePath(node));
1060 nassertd(lobj !=
nullptr)
continue;
1082 attrib->fillin(scan, manager);
1095 RenderAttrib::fillin(scan, manager);
1101 for (
size_t i = 0; i < _off_lights.size(); ++i) {
1102 _off_lights[i].fillin(scan, manager);
1106 for (
size_t i = 0; i < _on_lights.size(); ++i) {
1107 _on_lights[i].fillin(scan, manager);
1110 BamAuxData *aux =
new BamAuxData;
1120 _sorted_on_lights.clear();
1121 _sort_seq = UpdateSeq::old();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual Light * as_light()
Cross-casts the node to a Light pointer, if it is one of the four kinds of Light nodes,...
A basic node of the scene graph or data graph.
The abstract interface to all kinds of lights.
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...
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.
This global object records NodePaths that are referenced by scene graph attribs, such as ClipPlaneAtt...
bool has_light(Light *light) const
Returns true if the indicated light is listed in the attrib, false otherwise.
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.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
virtual void attrib_unref()
This is called when the light is removed from 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.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
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.
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().
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
get_name
Returns the name of the referenced node.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
void read_pointers(DatagramIterator &scan, int count)
A convenience function to read a contiguous list of pointers.
virtual bool is_ambient_light() const
Returns true if this is an AmbientLight, false if it is some other kind of light.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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.
static UpdateSeq get_sort_seq()
Returns a global sequence number that is incremented any time any Light in the world changes sort or ...
Operation get_operation() const
Returns the basic operation type of the LightAttrib.
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.
virtual bool is_ambient_light() const
Returns true if this is an AmbientLight, false if it is not a light, or it is some other kind of ligh...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Light * get_light(int n) const
Returns the nth light listed in the attribute.
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.
int get_num_lights() const
Returns the number of lights listed in the attribute.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
get_node
Returns the nth NodePath recorded in the registry.
get_color
Returns the basic color of the light.
virtual void attrib_ref()
This is called when the light is added to a LightAttrib.
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.
This is a sequence number that increments monotonically.
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 ...
static void register_with_read_factory()
Tells the BamReader how to create objects of type LightAttrib.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_priority
Returns the priority associated with this light.
Indicates which set of lights should be considered "on" to illuminate geometry at this level and belo...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
CPT(RenderAttrib) LightAttrib
Constructs a new LightAttrib object that turns on (or off, according to op) the indicated light(s).
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().