45 _first_txa_match =
false;
46 _default_group =
nullptr;
60 const std::string &egg_comment) {
63 remove_backstage(_data);
68 _current_directory = ExecutionEnvironment::get_cwd();
69 _source_filename = source_filename;
71 _dest_filename = dest_filename;
77 _egg_comment = egg_comment;
92 return _source_filename;
103 nassertv(_data !=
nullptr);
116 EggTextureCollection::iterator eti;
117 for (eti = tc.begin(); eti != tc.end(); ++eti) {
121 ref->
from_egg(
this, _data, egg_tex);
130 new_textures.push_back(ref);
136 sort(new_textures.begin(), new_textures.end(),
141 sort(_textures.begin(), _textures.end(),
146 Textures::const_iterator ai = _textures.begin();
147 Textures::const_iterator bi = new_textures.begin();
149 while (ai != _textures.end() && bi != new_textures.end()) {
153 if ((*aref) < (*bref)) {
159 }
else if ((*bref) < (*aref)) {
162 combined_textures.push_back(bref);
171 combined_textures.push_back(aref);
176 combined_textures.push_back(bref);
184 while (bi != new_textures.end()) {
188 combined_textures.push_back(bref);
192 while (ai != _textures.end()) {
200 _textures.swap(combined_textures);
211 Textures::const_iterator ti;
212 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
213 result.insert((*ti)->get_texture());
223 _first_txa_match =
true;
232 if (_first_txa_match) {
237 _explicitly_assigned_groups.
clear();
238 _first_txa_match =
false;
241 _explicitly_assigned_groups.
make_union(_explicitly_assigned_groups, groups);
258 return _explicitly_assigned_groups;
267 return _default_group;
277 return _complete_groups;
286 _is_surprise =
false;
326 if (_explicitly_assigned_groups.
empty()) {
329 _complete_groups.
clear();
330 _complete_groups.
insert(_default_group);
337 Textures::const_iterator ti;
338 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
341 nassertv(texture !=
nullptr);
350 PaletteGroups::const_iterator gi;
351 for (gi = _complete_groups.
begin();
352 gi != _complete_groups.
end();
354 (*gi)->increment_egg_count();
365 Textures::const_iterator ti;
366 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
382 Textures::const_iterator ti;
383 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
400 if (groups.
empty()) {
408 if (!groups.
empty()) {
416 nassertv(placement !=
nullptr);
430 return (_data !=
nullptr);
448 nassertv(_data !=
nullptr);
450 Textures::iterator ti;
451 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
463 Textures::iterator ti;
464 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
481 nassertr(_data ==
nullptr,
false);
482 nassertr(!_source_filename.empty(),
false);
487 if (!_source_filename.
exists()) {
488 nout << user_source_filename <<
" does not exist.\n";
493 if (!data->read(_source_filename, user_source_filename)) {
498 if (noabs && data->original_had_absolute_pathnames()) {
500 <<
" references textures using absolute pathnames!\n";
522 data->resolve_filenames(dir);
526 data->force_filenames(_current_directory);
528 if (!data->load_externals()) {
535 remove_backstage(_data);
539 _data->insert(_data->begin(), comment);
541 if (!_textures.empty()) {
554 if (_data !=
nullptr) {
557 Textures::iterator ti;
558 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
570 nassertr(_data !=
nullptr,
false);
571 nassertr(!_dest_filename.empty(),
false);
576 if (!_data->write_egg(_dest_filename)) {
592 indent(out, indent_level) << get_name() <<
": ";
593 if (_explicitly_assigned_groups.
empty()) {
594 if (_default_group !=
nullptr) {
595 out << _default_group->get_name();
598 out << _explicitly_assigned_groups;
602 out <<
" (needs update)";
613 Textures::const_iterator ti;
614 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
616 reference->write(out, indent_level);
627 EggGroupNode::iterator ci;
629 while (ci != node->end()) {
631 bool remove_child =
false;
633 if (child->
is_of_type(EggGroup::get_class_type())) {
635 DCAST_INTO_V(egg_group, child);
640 ci = node->erase(ci);
642 if (child->
is_of_type(EggGroupNode::get_class_type())) {
657 nassertv(_data !=
nullptr);
667 ByTRefName by_tref_name;
668 for (Textures::const_iterator ti = _textures.begin();
669 ti != _textures.end();
675 EggTextureCollection::iterator eti;
676 for (eti = tc.begin(); eti != tc.end(); ++eti) {
679 ByTRefName::const_iterator tni = by_tref_name.find(egg_tex->get_name());
680 if (tni == by_tref_name.end()) {
683 <<
" modified during session--TRef " << egg_tex->get_name()
699 register_factory(get_class_type(), make_EggFile);
719 Textures::iterator ti;
720 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
744 _textures.reserve(_num_textures);
745 for (i = 0; i < _num_textures; i++) {
747 DCAST_INTO_R(texture, p_list[pi], pi);
748 _textures.push_back(texture);
754 if (p_list[pi] !=
nullptr) {
755 DCAST_INTO_R(_default_group, p_list[pi], pi);
774 me->fillin(scan, manager);
789 if (Palettizer::_read_pi_version >= 9) {
796 _explicitly_assigned_groups.
fillin(scan, manager);
802 if (Palettizer::_read_pi_version < 11) {
bool is_equivalent(const TextureReference &other) const
Returns true if all essential properties of this TextureReference are the same as that of the other,...
void increment_egg_count()
Increments by one the number of egg files that are known to reference this SourceTextureImage.
void make_intersection(const PaletteGroups &a, const PaletteGroups &b)
Computes the intersection of PaletteGroups a and b, and stores the result in this object.
void from_egg_quick(const TextureReference &other)
Sets up the pointers within the TextureReference to the same egg file pointers indicated by the other...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static Filename make_bam_filename(Filename filename)
Returns a new filename that's made relative to the bam file itself, suitable for writing to the bam f...
std::string get_dirname() const
Returns the directory part of the filename.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
void set_placement(TexturePlacement *placement)
Sets the particular TexturePlacement that is appropriate for this egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void uniquify_trefs()
Guarantees that each texture in the collection has a unique TRef name.
This is our own Panda specialization on the default STL map.
void post_txa_file()
Once the egg file has been matched against all of the matching lines the .txa file,...
void update_egg()
Updates the egg file with all the relevant information to reference the texture in its new home,...
iterator end() const
Returns an iterator suitable for traversing the set.
void apply_properties_to_source()
Applies the texture properties as read from the egg file to the source image's properties.
bool get_bool()
Extracts a boolean value.
void scan_textures()
Scans the egg file for texture references and updates the _textures list appropriately.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void write_description(std::ostream &out, int indent_level=0) const
Writes a one-line description of the egg file and its group assignments to the indicated output strea...
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
This is the particular reference of a texture filename by an egg file.
A base class for nodes in the hierarchy that are not leaf nodes.
PaletteGroup * get_group() const
Returns the group that this placement represents.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a texture map that may be applied to geometry.
bool had_data() const
Returns true if the EggData for this EggFile has ever been loaded in this session.
void clear_surprise()
Removes the 'surprise' flag; this file has been successfully matched against a line in the ....
void mark_stale()
Marks this particular egg file as stale, meaning that something has changed, such as the location of ...
Base class for objects that can be written to and read from Bam files.
iterator begin() const
Returns an iterator suitable for traversing the set.
size_type count(PaletteGroup *group) const
Returns the number of times the given group appears in the set.
This is the highest level of grouping for TextureImages.
const Filename & get_source_filename() const
Returns the filename this egg file was read from.
void remove_egg()
Removes this egg file from all things that reference it, in preparation for removing it from the data...
void pre_txa_file()
Does some processing prior to scanning the .txa file.
bool read_egg(bool noabs)
Reads in the egg file from its _source_filename.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear()
Empties the set.
This is a collection of textures by TRef name.
TexturePlacement * get_placement(PaletteGroup *group) const
Gets the TexturePlacement object which represents the assignment of this texture to the indicated gro...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const PaletteGroups & get_explicit_groups() const
Returns the set of PaletteGroups that the egg file has been explicitly assigned to in the ....
void append_directory(const Filename &directory)
Adds a new directory to the end of the search list.
void apply_properties_to_source()
Calls apply_properties_to_source() for each texture reference, updating all the referenced source tex...
This is the primary interface into all the egg data, and the root of the egg file structure.
const PaletteGroups & get_complete_groups() const
Returns the complete set of PaletteGroups that the egg file is assigned to.
std::string get_string()
Extracts a variable-length string.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
SourceTextureImage * get_source() const
Returns the SourceTextureImage that this object refers to.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void note_egg_file(EggFile *egg_file)
Records that a particular egg file references this texture.
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
An STL function object class, this is intended to be used on any ordered collection of pointers to cl...
TextureImage * get_texture() const
Returns the TextureImage that this object refers to.
void get_textures(pset< TextureImage * > &result) const
Fills up the indicated set with the set of textures referenced by this egg file.
void choose_placements()
Once all the textures have been assigned to groups (but before they may actually be placed),...
const std::string & get_tref_name() const
Returns the name of the EggTexture entry that references this texture.
void release_egg_data()
Releases the memory that was loaded by a previous call to read_egg().
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
bool from_command_line(EggData *data, const Filename &source_filename, const Filename &dest_filename, const std::string &egg_comment)
Accepts the information about the egg file as supplied from the command line.
void add_bool(bool value)
Adds a boolean value to the datagram.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
static Filename make_user_filename(Filename filename)
Returns a new filename that's made relative to the current directory, suitable for reporting to the u...
void match_txa_groups(const PaletteGroups &groups)
Adds the indicated set of groups, read from the .txa file, to the set of groups to which the egg file...
bool write_egg()
Writes out the egg file to its _dest_filename.
The name of a file, such as a texture file or an Egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void update_egg()
Once all textures have been placed appropriately, updates the egg file with all the information to re...
bool has_object_type(const std::string &object_type) const
Returns true if the indicated object type has been added to the group, or false otherwise.
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.
void rebind_egg_data(EggData *data, EggTexture *egg_tex)
After an EggData has previously been released via release_egg_data(), this can be called to indicate ...
static Filename get_bam_filename(Filename filename)
Returns an absolute pathname based on the given relative pathname, presumably read from the bam file ...
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
bool has_data() const
Returns true if the EggData for this EggFile has been loaded, and not yet released.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool empty() const
Returns true if the set is empty, false otherwise.
This corresponds to a particular assignment of a TextureImage with a PaletteGroup,...
void from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex)
Sets up the TextureReference using information extracted from an egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int find_used_textures(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_basename() const
Returns the basename part of the filename.
bool is_surprise() const
Returns true if this particular egg file is a 'surprise', i.e.
bool is_stale() const
Returns true if the egg file needs to be updated, i.e.
void make_complete(const PaletteGroups &a)
Completes the set with the transitive closure of all dependencies: for each PaletteGroup already in t...
void make_absolute()
Converts the filename to a fully-qualified pathname from the root (if it is a relative pathname),...
void make_union(const PaletteGroups &a, const PaletteGroups &b)
Computes the union of PaletteGroups a and b, and stores the result in this object.
void remove_egg(TextureReference *reference)
Notes that a particular egg file is no longer using this particular TexturePlacement.
void insert(PaletteGroup *group)
Inserts a new group to the set, if it is not already there.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
A base class for things that may be directly added into the egg hierarchy.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
This class stores a list of directories that can be searched, in order, to locate a particular file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
PaletteGroup * get_default_group()
Returns the default group to which an egg file should be assigned if it is not mentioned in the ....
bool has_uvs() const
Returns true if this TextureReference actually uses the texture on geometry, with UV's and everything...
A class to retrieve the individual data elements previously stored in a Datagram.
This represents a single source texture that is referenced by one or more egg files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void build_cross_links()
Calls TextureImage::note_egg_file() and SourceTextureImage::increment_egg_count() for each texture th...
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 ...
TexturePlacement * get_placement() const
Returns the particular TexturePlacement that is appropriate for this egg file.
void release_egg_data()
Called to indicate that the EggData previously passed to from_egg() is about to be deallocated,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
void write_texture_refs(std::ostream &out, int indent_level=0) const
Writes the list of texture references to the indicated output stream, one per line.
This represents a single egg file known to the palettizer.
PaletteGroup * get_default_group() const
Returns the PaletteGroup that was specified as the default group on the command line at the time the ...
const PaletteGroups & get_groups() const
Once assign_groups() has been called, this returns the actual set of groups the TextureImage has been...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.