Panda3D
eggListTextures.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file eggListTextures.cxx
10  * @author drose
11  * @date 2005-05-23
12  */
13 
14 #include "eggListTextures.h"
15 #include "eggTextureCollection.h"
16 #include "pnmImageHeader.h"
17 
18 /**
19  *
20  */
21 EggListTextures::
22 EggListTextures() {
23  set_program_brief("list textures referenced by an .egg file");
24  set_program_description
25  ("egg-list-textures reads an egg file and writes a list of the "
26  "textures it references. It is particularly useful for building "
27  "up the textures.txa file used for egg-palettize, since the output "
28  "format is crafted to be compatible with that file's input format.");
29 }
30 
31 /**
32  *
33  */
34 void EggListTextures::
35 run() {
36  if (!do_reader_options()) {
37  exit(1);
38  }
39 
41  tc.find_used_textures(_data);
43  tc.collapse_equivalent_textures(EggTexture::E_complete_filename, treplace);
44  tc.sort_by_basename();
45 
46  EggTextureCollection::iterator ti;
47  for (ti = tc.begin(); ti != tc.end(); ++ti) {
48  Filename fullpath = (*ti)->get_fullpath();
49  PNMImageHeader header;
50  if (header.read_header(fullpath)) {
51  std::cout << fullpath.get_basename() << " : "
52  << header.get_x_size() << " " << header.get_y_size() << "\n";
53  } else {
54  std::cout << fullpath.get_basename() << " : unknown\n";
55  }
56  }
57 }
58 
59 
60 int main(int argc, char *argv[]) {
61  EggListTextures prog;
62  prog.parse_command_line(argc, argv);
63  prog.run();
64  return 0;
65 }
Reads an egg file and outputs the list of textures it uses.
This is a collection of textures by TRef name.
int find_used_textures(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by ...
int collapse_equivalent_textures(int eq, EggGroupNode *node)
Walks through the collection and collapses together any separate textures that are equivalent accordi...
void sort_by_basename()
Sorts all the textures into alphabetical order by the basename part (including extension) of the file...
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
std::string get_basename() const
Returns the basename part of the filename.
Definition: filename.I:367
std::string get_fullpath() const
Returns the entire filename: directory, basename, extension.
Definition: filename.I:338
This is the base class of PNMImage, PNMReader, and PNMWriter.
bool read_header(const Filename &filename, PNMFileType *type=nullptr, bool report_unknown_type=true)
Opens up the image file and tries to read its header information to determine its size,...
int get_x_size() const
Returns the number of pixels in the X direction.
int get_y_size() const
Returns the number of pixels in the Y direction.
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.