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) {
95 make(LightAttrib::Operation op,
Light *light) {
97 <<
"Using deprecated LightAttrib interface.\n";
103 attrib = make_all_off();
118 nassert_raise(
"invalid operation");
129 make(LightAttrib::Operation op,
Light *light1,
Light *light2) {
131 <<
"Using deprecated LightAttrib interface.\n";
137 attrib = make_all_off();
155 nassert_raise(
"invalid operation");
166 make(LightAttrib::Operation op,
Light *light1,
Light *light2,
169 <<
"Using deprecated LightAttrib interface.\n";
175 attrib = make_all_off();
196 nassert_raise(
"invalid operation");
207 make(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";
345 add_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()));
363 remove_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;
410 add_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);
434 remove_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()) {
473 return return_new(attrib);
481 add_off_light(
const NodePath &light)
const {
484 nassertr(lobj !=
nullptr,
this);
487 if (!_off_all_lights) {
488 attrib->_off_lights.insert(light);
490 if (attrib->_on_lights.erase(light)) {
493 return return_new(attrib);
501 remove_off_light(
const NodePath &light)
const {
504 attrib->_off_lights.erase(light);
505 return return_new(attrib);
514 if (source == dest) {
520 nassertr(slobj !=
nullptr,
this);
524 nassertr(dlobj !=
nullptr,
this);
528 auto it = attrib->_off_lights.find(source);
529 if (it != attrib->_off_lights.
end()) {
535 return return_new(attrib);
544 get_most_important_light()
const {
547 if (_num_non_ambient_lights > 0) {
548 return _sorted_on_lights[0];
558 get_ambient_contribution()
const {
563 Lights::const_iterator li;
564 li = _sorted_on_lights.begin() + _num_non_ambient_lights;
565 for (; li != _sorted_on_lights.end(); ++li) {
570 total += light->get_color();
580 output(std::ostream &out)
const {
581 out << get_type() <<
":";
582 if (_off_lights.
empty()) {
583 if (_on_lights.
empty()) {
584 if (_off_all_lights) {
590 if (_off_all_lights) {
599 Lights::const_iterator fi;
600 for (fi = _off_lights.
begin(); fi != _off_lights.
end(); ++fi) {
609 if (!_on_lights.
empty()) {
614 Lights::const_iterator li;
615 for (li = _on_lights.
begin(); li != _on_lights.
end(); ++li) {
629 write(std::ostream &out,
int indent_level)
const {
630 indent(out, indent_level) << get_type() <<
":";
631 if (_off_lights.
empty()) {
632 if (_on_lights.
empty()) {
633 if (_off_all_lights) {
639 if (_off_all_lights) {
648 Lights::const_iterator fi;
649 for (fi = _off_lights.
begin(); fi != _off_lights.
end(); ++fi) {
651 indent(out, indent_level + 2) << light <<
"\n";
654 if (!_on_lights.
empty()) {
655 indent(out, indent_level) <<
"on\n";
659 Lights::const_iterator li;
660 for (li = _on_lights.
begin(); li != _on_lights.
end(); ++li) {
662 indent(out, indent_level + 2) << light <<
"\n";
681 if (_off_all_lights != ta->_off_all_lights) {
682 return (
int)_off_all_lights - (int)ta->_off_all_lights;
685 Lights::const_iterator li = _on_lights.
begin();
686 Lights::const_iterator oli = ta->_on_lights.
begin();
688 while (li != _on_lights.
end() && oli != ta->_on_lights.
end()) {
701 if (li != _on_lights.
end()) {
704 if (oli != ta->_on_lights.
end()) {
708 Lights::const_iterator fi = _off_lights.
begin();
709 Lights::const_iterator ofi = ta->_off_lights.
begin();
711 while (fi != _off_lights.
end() && ofi != ta->_off_lights.
end()) {
724 if (fi != _off_lights.
end()) {
727 if (ofi != ta->_off_lights.
end()) {
741 get_hash_impl()
const {
744 Lights::const_iterator li;
745 for (li = _on_lights.
begin(); li != _on_lights.
end(); ++li) {
754 for (li = _off_lights.
begin(); li != _off_lights.
end(); ++li) {
777 if (ta->_off_all_lights) {
785 Lights::const_iterator ai = _on_lights.
begin();
786 Lights::const_iterator bi = ta->_on_lights.
begin();
787 Lights::const_iterator ci = ta->_off_lights.
begin();
791 std::back_insert_iterator<Lights> result =
792 std::back_inserter(new_attrib->_on_lights);
794 while (ai != _on_lights.
end() &&
795 bi != ta->_on_lights.
end() &&
796 ci != ta->_off_lights.
end()) {
805 }
else if ((*ci) < (*ai)) {
817 }
else if ((*bi) < (*ai)) {
833 while (ai != _on_lights.
end() && bi != ta->_on_lights.
end()) {
841 }
else if ((*bi) < (*ai)) {
857 while (ai != _on_lights.
end() && ci != ta->_off_lights.
end()) {
865 }
else if ((*ci) < (*ai)) {
878 while (ai != _on_lights.
end()) {
884 while (bi != ta->_on_lights.
end()) {
891 Lights::const_iterator it;
892 for (it = new_attrib->_on_lights.
begin(); it != new_attrib->_on_lights.
end(); ++it) {
893 Light *lobj = (*it).node()->as_light();
894 nassertd(lobj !=
nullptr) continue;
899 new_attrib->_sort_seq =
UpdateSeq::old();
901 return return_new(new_attrib);
927 _sorted_on_lights.clear();
928 OrderedLights ambient_lights;
930 Lights::const_iterator li;
931 for (li = _on_lights.
begin(); li != _on_lights.
end(); ++li) {
935 if (!np.node()->is_ambient_light()) {
936 _sorted_on_lights.push_back(np);
938 ambient_lights.push_back(np);
944 _num_non_ambient_lights = _sorted_on_lights.size();
947 sort(_sorted_on_lights.begin(), _sorted_on_lights.end(),
948 CompareLightPriorities());
953 _sorted_on_lights.insert(_sorted_on_lights.end(),
954 ambient_lights.begin(), ambient_lights.end());
979 Lights::const_iterator fi;
981 for (fi = _off_lights.
begin(); fi != _off_lights.
end(); ++fi) {
985 for (fi = _off_lights.
begin(); fi != _off_lights.
end(); ++fi) {
986 (*fi).write_datagram(manager, dg);
993 Lights::const_iterator nti;
995 for (nti = _on_lights.
begin(); nti != _on_lights.
end(); ++nti) {
999 for (nti = _on_lights.
begin(); nti != _on_lights.
end(); ++nti) {
1000 (*nti).write_datagram(manager, dg);
1014 for (
size_t i = 0; i < _off_lights.
size(); ++i) {
1015 pi += _off_lights[i].complete_pointers(p_list + pi, manager);
1018 for (
size_t i = 0; i < _on_lights.
size(); ++i) {
1019 pi += _on_lights[i].complete_pointers(p_list + pi, manager);
1024 nassertr(aux !=
nullptr, pi);
1027 aux->_off_list.reserve(aux->_num_off_lights);
1028 for (i = 0; i < aux->_num_off_lights; ++i) {
1030 DCAST_INTO_R(node, p_list[pi++], pi);
1031 aux->_off_list.push_back(node);
1034 aux->_on_list.reserve(aux->_num_on_lights);
1035 for (i = 0; i < aux->_num_on_lights; ++i) {
1037 DCAST_INTO_R(node, p_list[pi++], pi);
1038 aux->_on_list.push_back(node);
1057 for (
size_t i = 0; i < _off_lights.
size(); ++i) {
1058 int n = areg->
find_node(_off_lights[i]);
1061 _off_lights[i] = areg->
get_node(n);
1065 for (
size_t i = 0; i < _on_lights.
size(); ++i) {
1072 Light *lobj = _on_lights[i].node()->as_light();
1073 nassertd(lobj !=
nullptr)
continue;
1080 nassertv(aux !=
nullptr);
1081 nassertv(aux->_num_off_lights == (
int)aux->_off_list.size());
1082 nassertv(aux->_num_on_lights == (
int)aux->_on_list.size());
1086 _off_lights.
reserve(aux->_off_list.size());
1087 NodeList::iterator ni;
1088 for (ni = aux->_off_list.begin(); ni != aux->_off_list.end(); ++ni) {
1090 int n = areg->
find_node(node->get_type(), node->get_name());
1100 _on_lights.
reserve(aux->_on_list.size());
1101 for (ni = aux->_on_list.begin(); ni != aux->_on_list.end(); ++ni) {
1103 int n = areg->
find_node(node->get_type(), node->get_name());
1107 node = _on_lights.
back().node();
1114 nassertd(lobj !=
nullptr)
continue;
1136 attrib->fillin(scan, manager);
1149 RenderAttrib::fillin(scan, manager);
1155 for (
size_t i = 0; i < _off_lights.
size(); ++i) {
1156 _off_lights[i].fillin(scan, manager);
1160 for (
size_t i = 0; i < _on_lights.
size(); ++i) {
1161 _on_lights[i].fillin(scan, manager);
1164 BamAuxData *aux =
new BamAuxData;
1174 _sorted_on_lights.clear();
1175 _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.
CPT(RenderAttrib) LightAttrib
Constructs a new LightAttrib object that turns on (or off, according to op) the indicated light(s).
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.