From ae3fa2320dbd74709fca5cb37ecb65b23ae389f2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 23 May 2005 22:30:53 +0000 Subject: [PATCH] add egg-list-textures --- pandatool/src/eggbase/eggReader.cxx | 3 + pandatool/src/eggprogs/Sources.pp | 8 +++ pandatool/src/eggprogs/eggListTextures.cxx | 73 ++++++++++++++++++++++ pandatool/src/eggprogs/eggListTextures.h | 39 ++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 pandatool/src/eggprogs/eggListTextures.cxx create mode 100644 pandatool/src/eggprogs/eggListTextures.h diff --git a/pandatool/src/eggbase/eggReader.cxx b/pandatool/src/eggbase/eggReader.cxx index e28ab951bd..816acbfc62 100644 --- a/pandatool/src/eggbase/eggReader.cxx +++ b/pandatool/src/eggbase/eggReader.cxx @@ -59,6 +59,9 @@ EggReader() { _tex_type = (PNMFileType *)NULL; _delod = -1.0; + + _got_tex_dirname = false; + _got_tex_extension = false; } //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/eggprogs/Sources.pp b/pandatool/src/eggprogs/Sources.pp index e2192794f3..f203cda68e 100644 --- a/pandatool/src/eggprogs/Sources.pp +++ b/pandatool/src/eggprogs/Sources.pp @@ -72,3 +72,11 @@ eggToC.cxx eggToC.h #end bin_target + +#begin bin_target + #define TARGET egg-list-textures + + #define SOURCES \ + eggListTextures.cxx eggListTextures.h + +#end bin_target diff --git a/pandatool/src/eggprogs/eggListTextures.cxx b/pandatool/src/eggprogs/eggListTextures.cxx new file mode 100644 index 0000000000..63431ce3bf --- /dev/null +++ b/pandatool/src/eggprogs/eggListTextures.cxx @@ -0,0 +1,73 @@ +// Filename: eggListTextures.cxx +// Created by: drose (23May05) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#include "eggListTextures.h" +#include "eggTextureCollection.h" +#include "pnmImageHeader.h" + +//////////////////////////////////////////////////////////////////// +// Function: EggListTextures::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +EggListTextures:: +EggListTextures() { + set_program_description + ("egg-list-textures reads an egg file and writes a list of the " + "textures it references. It is particularly useful for building " + "up the textures.txa file used for egg-palettize, since the output " + "format is crafted to be compatible with that file's input format."); +} + +//////////////////////////////////////////////////////////////////// +// Function: EggListTextures::run +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void EggListTextures:: +run() { + if (!do_reader_options()) { + exit(1); + } + + EggTextureCollection tc; + tc.find_used_textures(_data); + EggTextureCollection::TextureReplacement treplace; + tc.collapse_equivalent_textures(EggTexture::E_complete_filename, treplace); + tc.sort_by_basename(); + + EggTextureCollection::iterator ti; + for (ti = tc.begin(); ti != tc.end(); ++ti) { + Filename fullpath = (*ti)->get_fullpath(); + PNMImageHeader header; + if (header.read_header(fullpath)) { + cout << fullpath.get_basename() << " : " + << header.get_x_size() << " " << header.get_y_size() << "\n"; + } else { + cout << fullpath.get_basename() << " : unknown\n"; + } + } +} + + +int main(int argc, char *argv[]) { + EggListTextures prog; + prog.parse_command_line(argc, argv); + prog.run(); + return 0; +} diff --git a/pandatool/src/eggprogs/eggListTextures.h b/pandatool/src/eggprogs/eggListTextures.h new file mode 100644 index 0000000000..2ab5a34f86 --- /dev/null +++ b/pandatool/src/eggprogs/eggListTextures.h @@ -0,0 +1,39 @@ +// Filename: eggListTextures.h +// Created by: drose (23May05) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#ifndef EGGLISTTEXTURES_H +#define EGGLISTTEXTURES_H + +#include "pandatoolbase.h" + +#include "eggReader.h" + +//////////////////////////////////////////////////////////////////// +// Class : EggListTextures +// Description : Reads an egg file and outputs the list of textures it +// uses. +//////////////////////////////////////////////////////////////////// +class EggListTextures : public EggReader { +public: + EggListTextures(); + + void run(); +}; + +#endif +