diff --git a/pandatool/src/egg-palettize/Sources.pp b/pandatool/src/egg-palettize/Sources.pp index fda5508f7c..6dc0f8b25f 100644 --- a/pandatool/src/egg-palettize/Sources.pp +++ b/pandatool/src/egg-palettize/Sources.pp @@ -15,12 +15,13 @@ eggFile.cxx eggFile.h eggPalettize.cxx eggPalettize.h \ filenameUnifier.cxx filenameUnifier.h \ imageFile.cxx imageFile.h omitReason.cxx omitReason.h \ + pal_string_utils.cxx pal_string_utils.h \ paletteGroup.h paletteGroup.cxx \ paletteGroups.h paletteGroups.cxx paletteImage.h paletteImage.cxx \ palettePage.cxx palettePage.h \ palettizer.cxx palettizer.h \ - sourceTextureImage.cxx sourceTextureImage.h string_utils.cxx \ - string_utils.h textureImage.cxx textureImage.h \ + sourceTextureImage.cxx sourceTextureImage.h \ + textureImage.cxx textureImage.h \ texturePlacement.cxx texturePlacement.h \ texturePosition.cxx texturePosition.h \ textureProperties.cxx textureProperties.h textureReference.cxx \ diff --git a/pandatool/src/egg-palettize/eggFile.cxx b/pandatool/src/egg-palettize/eggFile.cxx index 7ea240b300..025be09201 100644 --- a/pandatool/src/egg-palettize/eggFile.cxx +++ b/pandatool/src/egg-palettize/eggFile.cxx @@ -92,7 +92,15 @@ scan_textures() { TextureReference *ref = new TextureReference; ref->from_egg(this, _data, egg_tex); - _textures.push_back(ref); + if (!ref->has_uvs()) { + // This texture isn't *really* referenced. (Usually this + // happens if the texture is only referenced by "backstage" + // geometry, which we don't care about.) + delete ref; + + } else { + _textures.push_back(ref); + } } } diff --git a/pandatool/src/egg-palettize/eggPalettize.cxx b/pandatool/src/egg-palettize/eggPalettize.cxx index 187099f783..b1876d38ea 100644 --- a/pandatool/src/egg-palettize/eggPalettize.cxx +++ b/pandatool/src/egg-palettize/eggPalettize.cxx @@ -6,7 +6,7 @@ #include "eggPalettize.h" #include "palettizer.h" #include "eggFile.h" -#include "string_utils.h" +#include "pal_string_utils.h" #include "filenameUnifier.h" #include @@ -252,8 +252,17 @@ describe_input_file() { "to groups; instead, it is more useful to assign the egg files " "they appear on to groups; see below.\n\n"); + show_text(" cont", 10, + "Normally, a texture file (or egg file) scans the lines in the " + "attributes file from the top, and stops on the first line that " + "matches its name. If the keyword 'cont' is included on the " + "line, however, the texture will apply the properties given " + "on the line, and then continue scanning. This trick may be " + "used to specify general parameters for all files while still " + "allowing the texture to match a more specific line below.\n\n"); + nout << - "The attributes file may also assign certain egg files into various " + "The attributes file may also assign egg files to various " "named palette groups. The syntax is similar to the above:\n\n" " car-blue.egg : main\n" @@ -263,7 +272,7 @@ describe_input_file() { "Any number of egg files may be named on one line, and the group of " "egg files may be simultaneously assigned to one or more groups. " - "The groups are defined using the :group command (see below). " + "The valid set of groups are defined using the :group command (see below). " "Each texture that is referenced by a given egg file will be palettized " "into at least one of the groups assigned to the egg file.\n\n" @@ -304,6 +313,31 @@ describe_input_file() { "also be overridden for a particular texture using the 'coverage' " "keyword on the texture line.\n\n"); + show_text(" :imagetype type[,alpha_type]", 10, + "This specifies the default type of image file that should be " + "generated for each palette image and for each unplaced texture " + "copied into the install directory. This may be overridden for " + "a particular texture by specifying the image type on the " + "texture line.\n\n" + + "If two image type names separate by a comma are given, it means " + "to generate a second file of the second type for the alpha " + "channel, for images that require an alpha channel. This allows " + "support for image file formats that do not support alpha " + "(for instance, JPEG).\n\n"); + + show_text(" :shadowtype type[,alpha_type]", 10, + "When generating palette images, egg-palettize sometimes has to " + "read and write the same palette image repeatedly. If the " + "palette image is stored in a lossy file format (like JPEG, see " + ":imagetype), this can eventually lead to degradation of the " + "palette images. As a workaround, egg-palettize can store " + "its working copies of the palette images in lossless shadow " + "images. Specify this to enable this feature; give it the " + "name of a lossless image file format. The shadow images will " + "be written to the directory specified by -ds on the command " + "line.\n\n"); + show_text(" :group groupname [dir dirname] [with group1 group2 ...]", 10, "This defines a palette group, a logical division of textures. " "Each texture is assigned to one or more palette groups before " @@ -369,6 +403,9 @@ run() { // Read the Palettizer object from the Bam file written // previously. This will recover all of the state saved from the // past session. + nout << "Reading " << FilenameUnifier::make_user_filename(state_filename) + << "\n"; + if (!state_file.open_read(state_filename)) { nout << FilenameUnifier::make_user_filename(state_filename) << " exists, but cannot be read. Perhaps you should remove it so a new one can be created.\n"; diff --git a/pandatool/src/egg-palettize/filenameUnifier.cxx b/pandatool/src/egg-palettize/filenameUnifier.cxx index 72dd7c8f25..373633aff4 100644 --- a/pandatool/src/egg-palettize/filenameUnifier.cxx +++ b/pandatool/src/egg-palettize/filenameUnifier.cxx @@ -11,6 +11,8 @@ Filename FilenameUnifier::_txa_filename; Filename FilenameUnifier::_txa_dir; Filename FilenameUnifier::_rel_dirname; +FilenameUnifier::CanonicalFilenames FilenameUnifier::_canonical_filenames; + //////////////////////////////////////////////////////////////////// // Function: FilenameUnifier::set_txa_filename // Access: Public, Static @@ -28,7 +30,7 @@ set_txa_filename(const Filename &txa_filename) { if (_txa_dir.empty()) { _txa_dir = "."; } - _txa_dir.make_canonical(); + make_canonical(_txa_dir); } //////////////////////////////////////////////////////////////////// @@ -47,7 +49,7 @@ void FilenameUnifier:: set_rel_dirname(const Filename &rel_dirname) { _rel_dirname = rel_dirname; if (!_rel_dirname.empty()) { - _rel_dirname.make_canonical(); + make_canonical(_rel_dirname); } } @@ -59,7 +61,7 @@ set_rel_dirname(const Filename &rel_dirname) { //////////////////////////////////////////////////////////////////// Filename FilenameUnifier:: make_bam_filename(Filename filename) { - filename.make_canonical(); + make_canonical(filename); filename.make_relative_to(_txa_dir); return filename; } @@ -89,7 +91,7 @@ get_bam_filename(Filename filename) { Filename FilenameUnifier:: make_egg_filename(Filename filename) { if (!filename.empty()) { - filename.make_canonical(); + make_canonical(filename); filename.make_relative_to(_rel_dirname); } return filename; @@ -105,8 +107,36 @@ make_egg_filename(Filename filename) { Filename FilenameUnifier:: make_user_filename(Filename filename) { if (!filename.empty()) { - filename.make_canonical(); + make_canonical(filename); filename.make_relative_to(ExecutionEnvironment::get_cwd()); } return filename; } + +//////////////////////////////////////////////////////////////////// +// Function: FilenameUnifier::make_canonical +// Access: Private, Static +// Description: Does the same thing as Filename::make_canonical()--it +// converts the filename to its canonical form--but +// caches the operation so that repeated calls to +// filenames in the same directory will tend to be +// faster. +//////////////////////////////////////////////////////////////////// +void FilenameUnifier:: +make_canonical(Filename &filename) { + if (filename.empty()) { + return; + } + + string dirname = filename.get_dirname(); + + CanonicalFilenames::iterator fi; + fi = _canonical_filenames.find(dirname); + if (fi != _canonical_filenames.end()) { + filename.set_dirname((*fi).second); + return; + } + + filename.make_canonical(); + _canonical_filenames.insert(CanonicalFilenames::value_type(dirname, filename.get_dirname())); +} diff --git a/pandatool/src/egg-palettize/filenameUnifier.h b/pandatool/src/egg-palettize/filenameUnifier.h index 8b8da5ad5a..a7db57aafd 100644 --- a/pandatool/src/egg-palettize/filenameUnifier.h +++ b/pandatool/src/egg-palettize/filenameUnifier.h @@ -10,6 +10,8 @@ #include +#include + //////////////////////////////////////////////////////////////////// // Class : FilenameUnifier // Description : This static class does the job of converting @@ -31,9 +33,14 @@ public: static Filename make_user_filename(Filename filename); private: + static void make_canonical(Filename &filename); + static Filename _txa_filename; static Filename _txa_dir; static Filename _rel_dirname; + + typedef map CanonicalFilenames; + static CanonicalFilenames _canonical_filenames; }; #endif diff --git a/pandatool/src/egg-palettize/string_utils.cxx b/pandatool/src/egg-palettize/pal_string_utils.cxx similarity index 98% rename from pandatool/src/egg-palettize/string_utils.cxx rename to pandatool/src/egg-palettize/pal_string_utils.cxx index 4f2cddc8b7..a0372da377 100644 --- a/pandatool/src/egg-palettize/string_utils.cxx +++ b/pandatool/src/egg-palettize/pal_string_utils.cxx @@ -1,9 +1,9 @@ -// Filename: string_utils.cxx +// Filename: pal_string_utils.cxx // Created by: drose (30Nov00) // //////////////////////////////////////////////////////////////////// -#include "string_utils.h" +#include "pal_string_utils.h" #include #include diff --git a/pandatool/src/egg-palettize/string_utils.h b/pandatool/src/egg-palettize/pal_string_utils.h similarity index 89% rename from pandatool/src/egg-palettize/string_utils.h rename to pandatool/src/egg-palettize/pal_string_utils.h index 240ae99455..c743791765 100644 --- a/pandatool/src/egg-palettize/string_utils.h +++ b/pandatool/src/egg-palettize/pal_string_utils.h @@ -1,10 +1,10 @@ -// Filename: string_utils.h +// Filename: pal_string_utils.h // Created by: drose (30Nov00) // //////////////////////////////////////////////////////////////////// -#ifndef STRING_UTILS_H -#define STRING_UTILS_H +#ifndef PAL_STRING_UTILS_H +#define PAL_STRING_UTILS_H #include #include diff --git a/pandatool/src/egg-palettize/paletteImage.cxx b/pandatool/src/egg-palettize/paletteImage.cxx index 2e76acd187..786057195f 100644 --- a/pandatool/src/egg-palettize/paletteImage.cxx +++ b/pandatool/src/egg-palettize/paletteImage.cxx @@ -601,6 +601,7 @@ get_image() { if (pal->_shadow_color_type != (PNMFileType *)NULL) { if (_shadow_image.read(_image)) { _got_image = true; + return; } } else { if (read(_image)) { diff --git a/pandatool/src/egg-palettize/palettizer.cxx b/pandatool/src/egg-palettize/palettizer.cxx index 49f3c507b2..09a6112feb 100644 --- a/pandatool/src/egg-palettize/palettizer.cxx +++ b/pandatool/src/egg-palettize/palettizer.cxx @@ -6,7 +6,7 @@ #include "palettizer.h" #include "eggFile.h" #include "textureImage.h" -#include "string_utils.h" +#include "pal_string_utils.h" #include "paletteGroup.h" #include "filenameUnifier.h" diff --git a/pandatool/src/egg-palettize/textureImage.cxx b/pandatool/src/egg-palettize/textureImage.cxx index f0e46c982b..42441aa2e3 100644 --- a/pandatool/src/egg-palettize/textureImage.cxx +++ b/pandatool/src/egg-palettize/textureImage.cxx @@ -374,6 +374,12 @@ get_margin() const { //////////////////////////////////////////////////////////////////// bool TextureImage:: is_surprise() const { + if (_placement.empty()) { + // A texture that is not actually placed anywhere is not + // considered a surprise. + return false; + } + return _is_surprise; } diff --git a/pandatool/src/egg-palettize/textureReference.cxx b/pandatool/src/egg-palettize/textureReference.cxx index a8fa421aa7..f8120411d7 100644 --- a/pandatool/src/egg-palettize/textureReference.cxx +++ b/pandatool/src/egg-palettize/textureReference.cxx @@ -16,12 +16,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include @@ -394,11 +396,21 @@ write(ostream &out, int indent_level) const { //////////////////////////////////////////////////////////////////// void TextureReference:: get_uv_range(EggGroupNode *group) { - EggGroupNode::iterator ci; + if (group->is_of_type(EggGroup::get_class_type())) { + EggGroup *egg_group; + DCAST_INTO_V(egg_group, group); + if (egg_group->has_objecttype() && + cmp_nocase_uh(egg_group->get_objecttype(), "backstage") == 0) { + // If we reach a node with the "backstage" flag set, + // ignore it and everything under it. + return; + } + } bool group_any_uvs = false; TexCoordd group_min_uv, group_max_uv; + EggGroupNode::iterator ci; for (ci = group->begin(); ci != group->end(); ci++) { EggNode *child = (*ci); if (child->is_of_type(EggNurbsSurface::get_class_type())) { @@ -473,11 +485,21 @@ get_uv_range(EggGroupNode *group) { //////////////////////////////////////////////////////////////////// void TextureReference:: update_uv_range(EggGroupNode *group) { - EggGroupNode::iterator ci; + if (group->is_of_type(EggGroup::get_class_type())) { + EggGroup *egg_group; + DCAST_INTO_V(egg_group, group); + if (egg_group->has_objecttype() && + cmp_nocase_uh(egg_group->get_objecttype(), "backstage") == 0) { + // If we reach a node with the "backstage" flag set, + // ignore it and everything under it. + return; + } + } bool group_any_uvs = false; TexCoordd group_min_uv, group_max_uv; + EggGroupNode::iterator ci; for (ci = group->begin(); ci != group->end(); ci++) { EggNode *child = (*ci); if (child->is_of_type(EggNurbsSurface::get_class_type())) { diff --git a/pandatool/src/egg-palettize/txaFile.cxx b/pandatool/src/egg-palettize/txaFile.cxx index ff5e42c149..5c0bd312d6 100644 --- a/pandatool/src/egg-palettize/txaFile.cxx +++ b/pandatool/src/egg-palettize/txaFile.cxx @@ -4,7 +4,7 @@ //////////////////////////////////////////////////////////////////// #include "txaFile.h" -#include "string_utils.h" +#include "pal_string_utils.h" #include "palettizer.h" #include "paletteGroup.h" #include "textureImage.h" diff --git a/pandatool/src/egg-palettize/txaLine.cxx b/pandatool/src/egg-palettize/txaLine.cxx index fdb52ce7ef..98cfb7fbc0 100644 --- a/pandatool/src/egg-palettize/txaLine.cxx +++ b/pandatool/src/egg-palettize/txaLine.cxx @@ -4,7 +4,7 @@ //////////////////////////////////////////////////////////////////// #include "txaLine.h" -#include "string_utils.h" +#include "pal_string_utils.h" #include "eggFile.h" #include "palettizer.h" #include "textureImage.h"