28int LightAttrib::_attrib_slot;
35class 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) {
95make(LightAttrib::Operation op,
Light *light) {
97 <<
"Using deprecated LightAttrib interface.\n";
103 attrib = make_all_off();
118 nassert_raise(
"invalid operation");
129make(LightAttrib::Operation op,
Light *light1,
Light *light2) {
131 <<
"Using deprecated LightAttrib interface.\n";
137 attrib = make_all_off();
155 nassert_raise(
"invalid operation");
166make(LightAttrib::Operation op,
Light *light1,
Light *light2,
169 <<
"Using deprecated LightAttrib interface.\n";
175 attrib = make_all_off();
196 nassert_raise(
"invalid operation");
207make(LightAttrib::Operation op,
Light *light1,
Light *light2,
210 <<
"Using deprecated LightAttrib interface.\n";
216 attrib = make_all_off();
240 nassert_raise(
"invalid operation");
267 <<
"Using deprecated LightAttrib interface.\n";
290 <<
"Using deprecated LightAttrib interface.\n";
309 <<
"Using deprecated LightAttrib interface.\n";
329 <<
"Using deprecated LightAttrib interface.\n";
345add_light(
Light *light)
const {
347 <<
"Using deprecated LightAttrib interface.\n";
350 return add_on_light(
NodePath(light->as_node()));
352 return add_off_light(
NodePath(light->as_node()));
363remove_light(
Light *light)
const {
365 <<
"Using deprecated LightAttrib interface.\n";
368 return remove_on_light(
NodePath(light->as_node()));
370 return remove_off_light(
NodePath(light->as_node()));
381 if (_empty_attrib ==
nullptr) {
385 return _empty_attrib;
396 if (_all_off_attrib ==
nullptr) {
398 attrib->_off_all_lights =
true;
399 _all_off_attrib = return_new(attrib);
402 return _all_off_attrib;
410add_on_light(
const NodePath &light)
const {
413 nassertr(lobj !=
nullptr,
this);
417 std::pair<Lights::iterator, bool> insert_result =
418 attrib->_on_lights.insert(Lights::value_type(light));
419 if (insert_result.second) {
423 attrib->_off_lights.erase(light);
426 return return_new(attrib);
434remove_on_light(
const NodePath &light)
const {
437 nassertr(lobj !=
nullptr,
this);
440 if (attrib->_on_lights.erase(light)) {
443 return return_new(attrib);
452 if (source == dest) {
458 nassertr(slobj !=
nullptr,
this);
462 nassertr(dlobj !=
nullptr,
this);
466 auto it = attrib->_on_lights.find(source);
467 if (it != attrib->_on_lights.
end()) {
472 attrib->_on_lights.
sort();
474 return return_new(attrib);
482add_off_light(
const NodePath &light)
const {
485 nassertr(lobj !=
nullptr,
this);
488 if (!_off_all_lights) {
489 attrib->_off_lights.insert(light);
491 if (attrib->_on_lights.erase(light)) {
494 return return_new(attrib);
502remove_off_light(
const NodePath &light)
const {
505 attrib->_off_lights.erase(light);
506 return return_new(attrib);
515 if (source == dest) {
521 nassertr(slobj !=
nullptr,
this);
525 nassertr(dlobj !=
nullptr,
this);
529 auto it = attrib->_off_lights.find(source);
530 if (it != attrib->_off_lights.
end()) {
535 attrib->_off_lights.
sort();
537 return return_new(attrib);
546get_most_important_light()
const {
549 if (_num_non_ambient_lights > 0) {
550 return _sorted_on_lights[0];
560get_ambient_contribution()
const {
565 Lights::const_iterator li;
566 li = _sorted_on_lights.begin() + _num_non_ambient_lights;
567 for (; li != _sorted_on_lights.end(); ++li) {
572 total += light->get_color();
582output(
std::ostream &out)
const {
583 out << get_type() <<
":";
584 if (_off_lights.
empty()) {
585 if (_on_lights.
empty()) {
586 if (_off_all_lights) {
592 if (_off_all_lights) {
601 Lights::const_iterator fi;
602 for (fi = _off_lights.
begin(); fi != _off_lights.
end(); ++fi) {
611 if (!_on_lights.
empty()) {
616 Lights::const_iterator li;
617 for (li = _on_lights.
begin(); li != _on_lights.
end(); ++li) {
631write(std::ostream &out,
int indent_level)
const {
632 indent(out, indent_level) << get_type() <<
":";
633 if (_off_lights.
empty()) {
634 if (_on_lights.
empty()) {
635 if (_off_all_lights) {
641 if (_off_all_lights) {
650 Lights::const_iterator fi;
651 for (fi = _off_lights.
begin(); fi != _off_lights.
end(); ++fi) {
653 indent(out, indent_level + 2) << light <<
"\n";
656 if (!_on_lights.
empty()) {
657 indent(out, indent_level) <<
"on\n";
661 Lights::const_iterator li;
662 for (li = _on_lights.
begin(); li != _on_lights.
end(); ++li) {
664 indent(out, indent_level + 2) << light <<
"\n";
683 if (_off_all_lights != ta->_off_all_lights) {
684 return (
int)_off_all_lights - (int)ta->_off_all_lights;
687 Lights::const_iterator li = _on_lights.
begin();
688 Lights::const_iterator oli = ta->_on_lights.
begin();
690 while (li != _on_lights.
end() && oli != ta->_on_lights.
end()) {
703 if (li != _on_lights.
end()) {
706 if (oli != ta->_on_lights.
end()) {
710 Lights::const_iterator fi = _off_lights.
begin();
711 Lights::const_iterator ofi = ta->_off_lights.
begin();
713 while (fi != _off_lights.
end() && ofi != ta->_off_lights.
end()) {
726 if (fi != _off_lights.
end()) {
729 if (ofi != ta->_off_lights.
end()) {
743get_hash_impl()
const {
746 Lights::const_iterator li;
747 for (li = _on_lights.
begin(); li != _on_lights.
end(); ++li) {
756 for (li = _off_lights.
begin(); li != _off_lights.
end(); ++li) {
779 if (ta->_off_all_lights) {
787 Lights::const_iterator ai = _on_lights.
begin();
788 Lights::const_iterator bi = ta->_on_lights.
begin();
789 Lights::const_iterator ci = ta->_off_lights.
begin();
793 std::back_insert_iterator<Lights> result =
794 std::back_inserter(new_attrib->_on_lights);
796 while (ai != _on_lights.
end() &&
797 bi != ta->_on_lights.
end() &&
798 ci != ta->_off_lights.
end()) {
807 }
else if ((*ci) < (*ai)) {
819 }
else if ((*bi) < (*ai)) {
835 while (ai != _on_lights.
end() && bi != ta->_on_lights.
end()) {
843 }
else if ((*bi) < (*ai)) {
859 while (ai != _on_lights.
end() && ci != ta->_off_lights.
end()) {
867 }
else if ((*ci) < (*ai)) {
880 while (ai != _on_lights.
end()) {
886 while (bi != ta->_on_lights.
end()) {
893 Lights::const_iterator it;
894 for (it = new_attrib->_on_lights.
begin(); it != new_attrib->_on_lights.
end(); ++it) {
895 Light *lobj = (*it).node()->as_light();
896 nassertd(lobj !=
nullptr) continue;
901 new_attrib->_sort_seq =
UpdateSeq::old();
903 return return_new(new_attrib);
929 _sorted_on_lights.clear();
930 OrderedLights ambient_lights;
932 Lights::const_iterator li;
933 for (li = _on_lights.
begin(); li != _on_lights.
end(); ++li) {
937 if (!np.node()->is_ambient_light()) {
938 _sorted_on_lights.push_back(np);
940 ambient_lights.push_back(np);
946 _num_non_ambient_lights = _sorted_on_lights.size();
949 sort(_sorted_on_lights.begin(), _sorted_on_lights.end(),
950 CompareLightPriorities());
955 _sorted_on_lights.insert(_sorted_on_lights.end(),
956 ambient_lights.begin(), ambient_lights.end());
981 Lights::const_iterator fi;
983 for (fi = _off_lights.
begin(); fi != _off_lights.
end(); ++fi) {
987 for (fi = _off_lights.
begin(); fi != _off_lights.
end(); ++fi) {
988 (*fi).write_datagram(manager, dg);
995 Lights::const_iterator nti;
997 for (nti = _on_lights.
begin(); nti != _on_lights.
end(); ++nti) {
1001 for (nti = _on_lights.
begin(); nti != _on_lights.
end(); ++nti) {
1002 (*nti).write_datagram(manager, dg);
1016 for (
size_t i = 0; i < _off_lights.
size(); ++i) {
1017 pi += _off_lights[i].complete_pointers(p_list + pi, manager);
1020 for (
size_t i = 0; i < _on_lights.
size(); ++i) {
1021 pi += _on_lights[i].complete_pointers(p_list + pi, manager);
1026 nassertr(aux !=
nullptr, pi);
1029 aux->_off_list.reserve(aux->_num_off_lights);
1030 for (i = 0; i < aux->_num_off_lights; ++i) {
1032 DCAST_INTO_R(node, p_list[pi++], pi);
1033 aux->_off_list.push_back(node);
1036 aux->_on_list.reserve(aux->_num_on_lights);
1037 for (i = 0; i < aux->_num_on_lights; ++i) {
1039 DCAST_INTO_R(node, p_list[pi++], pi);
1040 aux->_on_list.push_back(node);
1059 for (
size_t i = 0; i < _off_lights.
size(); ++i) {
1060 int n = areg->
find_node(_off_lights[i]);
1063 _off_lights[i] = areg->
get_node(n);
1067 for (
size_t i = 0; i < _on_lights.
size(); ++i) {
1074 Light *lobj = _on_lights[i].node()->as_light();
1075 nassertd(lobj !=
nullptr)
continue;
1082 nassertv(aux !=
nullptr);
1083 nassertv(aux->_num_off_lights == (
int)aux->_off_list.size());
1084 nassertv(aux->_num_on_lights == (
int)aux->_on_list.size());
1088 _off_lights.
reserve(aux->_off_list.size());
1089 NodeList::iterator ni;
1090 for (ni = aux->_off_list.begin(); ni != aux->_off_list.end(); ++ni) {
1092 int n = areg->
find_node(node->get_type(), node->get_name());
1102 _on_lights.
reserve(aux->_on_list.size());
1103 for (ni = aux->_on_list.begin(); ni != aux->_on_list.end(); ++ni) {
1105 int n = areg->
find_node(node->get_type(), node->get_name());
1109 node = _on_lights.
back().node();
1116 nassertd(lobj !=
nullptr)
continue;
1138 attrib->fillin(scan, manager);
1151 RenderAttrib::fillin(scan, manager);
1157 for (
size_t i = 0; i < _off_lights.
size(); ++i) {
1158 _off_lights[i].fillin(scan, manager);
1162 for (
size_t i = 0; i < _on_lights.
size(); ++i) {
1163 _on_lights[i].fillin(scan, manager);
1166 BamAuxData *aux =
new BamAuxData;
1176 _sorted_on_lights.clear();
1177 _sort_seq = UpdateSeq::old();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This global object records NodePaths that are referenced by scene graph attribs, such as ClipPlaneAtt...
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 ...
get_node
Returns the nth NodePath recorded in the registry.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
void read_pointers(DatagramIterator &scan, int count)
A convenience function to read a contiguous list of pointers.
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.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
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(),...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
A class to retrieve the individual data elements previously stored in a Datagram.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
bool get_bool()
Extracts a boolean value.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_bool(bool value)
Adds a boolean value to the datagram.
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Indicates which set of lights should be considered "on" to illuminate geometry at this level and belo...
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_off_light
Returns the nth light turned off by the attribute, sorted in arbitrary (pointer) order.
static void register_with_read_factory()
Tells the BamReader how to create objects of type LightAttrib.
int get_num_lights() const
Returns the number of lights listed in the attribute.
bool has_all_off() const
Returns true if this attrib turns off all lights (although it may also turn some on).
get_num_off_lights
Returns the number of lights that are turned off by the attribute.
get_num_on_lights
Returns the number of lights that are turned on by the attribute.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
bool has_off_light(const NodePath &light) const
Returns true if the indicated light is turned off by the attrib, false otherwise.
bool has_light(Light *light) const
Returns true if the indicated light is listed in the attrib, false otherwise.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
bool has_on_light(const NodePath &light) const
Returns true if the indicated light is turned on by the attrib, false otherwise.
Operation get_operation() const
Returns the basic operation type of the LightAttrib.
Light * get_light(int n) const
Returns the nth light listed in the attribute.
get_on_light
Returns the nth light turned on by the attribute, sorted in render order.
The abstract interface to all kinds of lights.
virtual void attrib_ref()
This is called when the light is added to a LightAttrib.
virtual bool is_ambient_light() const
Returns true if this is an AmbientLight, false if it is some other kind of light.
static UpdateSeq get_sort_seq()
Returns a global sequence number that is incremented any time any Light in the world changes sort or ...
virtual void attrib_unref()
This is called when the light is removed from a LightAttrib.
get_priority
Returns the priority associated with this light.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
size_t add_hash(size_t hash) const
Adds the NodePath into the running hash.
bool is_empty() const
Returns true if the NodePath contains no nodes.
PandaNode * node() const
Returns the referenced node of the path.
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 ...
get_name
Returns the name of the referenced node.
A basic node of the scene graph or data graph.
virtual Light * as_light()
Cross-casts the node to a Light pointer, if it is one of the four kinds of Light nodes,...
This is the base class for a number of render attributes (other than transform) that may be set on sc...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
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 is a sequence number that increments monotonically.
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
reference back()
Returns a reference to the first element.
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...
iterator_0 begin()
Returns the iterator that marks the first element in the ordered vector.
void push_back(const value_type_0 &key)
Adds the new element to the end of the vector without regard for proper sorting.
size_type_0 size() const
Returns the number of elements in the ordered vector.
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
void sort()
Maps to sort_unique().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.