16 #include "textureImage.h"
17 #include "paletteGroup.h"
18 #include "texturePlacement.h"
19 #include "textureReference.h"
20 #include "sourceTextureImage.h"
21 #include "palettizer.h"
22 #include "filenameUnifier.h"
26 #include "eggTextureCollection.h"
27 #include "eggComment.h"
29 #include "datagramIterator.h"
30 #include "bamReader.h"
31 #include "bamWriter.h"
32 #include "executionEnvironment.h"
33 #include "dSearchPath.h"
34 #include "indirectLess.h"
48 _first_txa_match =
false;
66 const string &egg_comment) {
69 remove_backstage(_data);
76 _source_filename = source_filename;
78 _dest_filename = dest_filename;
84 _egg_comment = egg_comment;
101 return _source_filename;
115 nassertv(_data != (
EggData *)NULL);
128 EggTextureCollection::iterator eti;
129 for (eti = tc.begin(); eti != tc.end(); ++eti) {
133 ref->
from_egg(
this, _data, egg_tex);
142 new_textures.push_back(ref);
148 sort(new_textures.begin(), new_textures.end(),
153 sort(_textures.begin(), _textures.end(),
158 Textures::const_iterator ai = _textures.begin();
159 Textures::const_iterator bi = new_textures.begin();
161 while (ai != _textures.end() && bi != new_textures.end()) {
165 if ((*aref) < (*bref)) {
171 }
else if ((*bref) < (*aref)) {
174 combined_textures.push_back(bref);
184 combined_textures.push_back(aref);
189 combined_textures.push_back(bref);
197 while (bi != new_textures.end()) {
201 combined_textures.push_back(bref);
205 while (ai != _textures.end()) {
213 _textures.swap(combined_textures);
227 Textures::const_iterator ti;
228 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
229 result.insert((*ti)->get_texture());
241 _first_txa_match =
true;
253 if (_first_txa_match) {
259 _explicitly_assigned_groups.
clear();
260 _first_txa_match =
false;
263 _explicitly_assigned_groups.
make_union(_explicitly_assigned_groups, groups);
285 return _explicitly_assigned_groups;
297 return _default_group;
310 return _complete_groups;
321 _is_surprise =
false;
374 if (_explicitly_assigned_groups.
empty()) {
377 _complete_groups.
clear();
378 _complete_groups.
insert(_default_group);
385 Textures::const_iterator ti;
386 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
399 PaletteGroups::const_iterator gi;
400 for (gi = _complete_groups.
begin();
401 gi != _complete_groups.
end();
403 (*gi)->increment_egg_count();
417 Textures::const_iterator ti;
418 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
438 Textures::const_iterator ti;
439 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
456 if (groups.
empty()) {
464 if (!groups.
empty()) {
488 return (_data != (
EggData *)NULL);
511 nassertv(_data != (
EggData *)NULL);
513 Textures::iterator ti;
514 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
528 Textures::iterator ti;
529 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
550 nassertr(_data == (
EggData *)NULL,
false);
551 nassertr(!_source_filename.empty(),
false);
556 if (!_source_filename.
exists()) {
557 nout << user_source_filename <<
" does not exist.\n";
562 if (!data->read(_source_filename, user_source_filename)) {
567 if (noabs && data->original_had_absolute_pathnames()) {
569 <<
" references textures using absolute pathnames!\n";
591 data->resolve_filenames(dir);
595 data->force_filenames(_current_directory);
597 if (!data->load_externals()) {
604 remove_backstage(_data);
608 _data->insert(_data->begin(), comment);
610 if (!_textures.empty()) {
626 if (_data != (
EggData *)NULL) {
629 Textures::iterator ti;
630 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
645 nassertr(_data != (
EggData *)NULL,
false);
646 nassertr(!_dest_filename.empty(),
false);
651 if (!_data->write_egg(_dest_filename)) {
669 indent(out, indent_level) << get_name() <<
": ";
670 if (_explicitly_assigned_groups.
empty()) {
672 out << _default_group->get_name();
675 out << _explicitly_assigned_groups;
679 out <<
" (needs update)";
692 Textures::const_iterator ti;
693 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
695 reference->write(out, indent_level);
710 EggGroupNode::iterator ci;
712 while (ci != node->end()) {
714 bool remove_child =
false;
716 if (child->
is_of_type(EggGroup::get_class_type())) {
718 DCAST_INTO_V(egg_group, child);
723 ci = node->erase(ci);
725 if (child->
is_of_type(EggGroupNode::get_class_type())) {
743 nassertv(_data != (
EggData *)NULL);
753 ByTRefName by_tref_name;
754 for (Textures::const_iterator ti = _textures.begin();
755 ti != _textures.end();
761 EggTextureCollection::iterator eti;
762 for (eti = tc.begin(); eti != tc.end(); ++eti) {
765 ByTRefName::const_iterator tni = by_tref_name.find(egg_tex->get_name());
766 if (tni == by_tref_name.end()) {
769 <<
" modified during session--TRef " << egg_tex->get_name()
788 register_factory(get_class_type(), make_EggFile);
811 Textures::iterator ti;
812 for (ti = _textures.begin(); ti != _textures.end(); ++ti) {
840 _textures.reserve(_num_textures);
841 for (i = 0; i < _num_textures; i++) {
843 DCAST_INTO_R(texture, p_list[pi], pi);
844 _textures.push_back(texture);
851 DCAST_INTO_R(_default_group, p_list[pi], pi);
872 parse_params(params, scan, manager);
873 me->fillin(scan, manager);
891 if (Palettizer::_read_pi_version >= 9) {
898 _explicitly_assigned_groups.
fillin(scan, manager);
904 if (Palettizer::_read_pi_version < 11) {
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...
const PaletteGroups & get_complete_groups() const
Returns the complete set of PaletteGroups that the egg file is assigned to.
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...
bool make_dir() const
Creates all the directories in the path to the file specified in the filename, except for the basenam...
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.
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, do whatever adjustment is necessary.
void update_egg()
Updates the egg file with all the relevant information to reference the texture in its new home...
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 add_string(const string &str)
Adds a variable-length string to the datagram.
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...
bool has_data() const
Returns true if the EggData for this EggFile has been loaded, and not yet released.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
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.
Defines a texture map that may be applied to geometry.
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.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
This is the highest level of grouping for TextureImages.
void remove_egg()
Removes this egg file from all things that reference it, in preparation for removing it from the data...
iterator end() const
Returns an iterator suitable for traversing the set.
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.
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
void clear()
Empties the set.
This is a collection of textures by TRef name.
bool empty() const
Returns true if the set is empty, false otherwise.
SourceTextureImage * get_source() const
Returns the SourceTextureImage 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.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
string get_dirname() const
Returns the directory part of the filename.
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...
PN_uint32 get_uint32()
Extracts an unsigned 32-bit integer.
bool had_data() const
Returns true if the EggData for this EggFile has ever been loaded in this session.
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...
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.
An STL function object class, this is intended to be used on any ordered collection of pointers to cl...
void choose_placements()
Once all the textures have been assigned to groups (but before they may actually be placed)...
TexturePlacement * get_placement(PaletteGroup *group) const
Gets the TexturePlacement object which represents the assignment of this texture to the indicated gro...
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 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...
bool is_equivalent(const TextureReference &other) const
Returns true if all essential properties of this TextureReference are the same as that of the other...
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.
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()...
void write_texture_refs(ostream &out, int indent_level=0) const
Writes the list of texture references to the indicated output stream, one per line.
void update_egg()
Once all textures have been placed appropriately, updates the egg file with all the information to re...
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.
TextureImage * get_texture() const
Returns the TextureImage that this object refers to.
bool is_surprise() const
Returns true if this particular egg file is a 'surprise', i.e.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
const PaletteGroups & get_explicit_groups() const
Returns the set of PaletteGroups that the egg file has been explicitly assigned to in the ...
PaletteGroup * get_default_group() const
Returns the PaletteGroup that was specified as the default group on the command line at the time the ...
This corresponds to a particular assignment of a TextureImage with a PaletteGroup, and specifically describes which PaletteImage (if any), and where on the PaletteImage, the TextureImage has been assigned to.
void from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex)
Sets up the TextureReference using information extracted from an egg file.
const PaletteGroups & get_groups() const
Once assign_groups() has been called, this returns the actual set of groups the TextureImage has been...
int find_used_textures(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by ...
bool from_command_line(EggData *data, const Filename &source_filename, const Filename &dest_filename, const string &egg_comment)
Accepts the information about the egg file as supplied from the command line.
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
PaletteGroup * get_group() const
Returns the group that this placement represents.
bool has_object_type(const string &object_type) const
Returns true if the indicated object type has been added to the group, or false otherwise.
const string & get_tref_name() const
Returns the name of the EggTexture entry that references this texture.
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.
string get_basename() const
Returns the basename part of the filename.
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, in preparation for writing to a Bam file.
void add_uint32(PN_uint32 value)
Adds an unsigned 32-bit integer to the datagram.
A base class for things that may be directly added into the egg hierarchy.
This class stores a list of directories that can be searched, in order, to locate a particular file...
static Filename get_cwd()
Returns the name of the current working directory.
PaletteGroup * get_default_group()
Returns the default group to which an egg file should be assigned if it is not mentioned in the ...
const Filename & get_source_filename() const
Returns the filename this egg file was read from.
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.
void build_cross_links()
Calls TextureImage::note_egg_file() and SourceTextureImage::increment_egg_count() for each texture th...
size_type count(PaletteGroup *group) const
Returns the number of times the given group appears in the set.
void write_description(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...
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
bool is_stale() const
Returns true if the egg file needs to be updated, i.e.
bool has_uvs() const
Returns true if this TextureReference actually uses the texture on geometry, with UV's and everything...
void release_egg_data()
Called to indicate that the EggData previously passed to from_egg() is about to be deallocated...
This represents a single egg file known to the palettizer.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
TexturePlacement * get_placement() const
Returns the particular TexturePlacement that is appropriate for this egg file.
iterator begin() const
Returns an iterator suitable for traversing the set.