From cf5188d6baa164bc655a2ec05fd1789bcbbc5e9d Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 30 May 2003 21:05:37 +0000 Subject: [PATCH] add -suffix to egg-texture-cards --- pandatool/src/eggprogs/eggTextureCards.cxx | 19 +++++++++++++++++++ pandatool/src/eggprogs/eggTextureCards.h | 2 ++ pandatool/src/progbase/programBase.cxx | 21 +++++++++++++++++++++ pandatool/src/progbase/programBase.h | 1 + 4 files changed, 43 insertions(+) diff --git a/pandatool/src/eggprogs/eggTextureCards.cxx b/pandatool/src/eggprogs/eggTextureCards.cxx index ded79979c1..5342545200 100644 --- a/pandatool/src/eggprogs/eggTextureCards.cxx +++ b/pandatool/src/eggprogs/eggTextureCards.cxx @@ -69,6 +69,15 @@ EggTextureCards() : EggWriter(true, true) { "given proportionately larger polygons.", &EggTextureCards::dispatch_double_pair, &_got_pixel_scale, &_pixel_scale[0]); + add_option + ("suffix", "string", 0, + "Normally, each polygon is given a name based on the basename of its " + "corresponding texture's filename (without the filename extension). " + "This option specifies an ignorable suffix in the texture filename(s); " + "if this suffix is present, it is not included in the polygon's name. " + "This option may be repeated multiple times.", + &EggTextureCards::dispatch_vector_string, NULL, &_suffixes); + add_option ("c", "r,g,b[,a]", 0, "Specifies the color of each polygon. The default is white: 1,1,1,1.", @@ -306,6 +315,16 @@ run() { Filename filename = (*ti); string name = filename.get_basename_wo_extension(); + // Strip off any suffixes from the name. + vector_string::const_iterator si; + for (si = _suffixes.begin(); si != _suffixes.end(); ++si) { + const string &suffix = (*si); + int prefix = (int)name.length() - (int)suffix.length(); + if (prefix > 0 && name.substr(prefix) == suffix) { + name = name.substr(0, prefix); + } + } + // Read in the texture header and determine its size. LVecBase4d geometry; int num_channels; diff --git a/pandatool/src/eggprogs/eggTextureCards.h b/pandatool/src/eggprogs/eggTextureCards.h index 6e9c580dc7..69dcfd23f1 100644 --- a/pandatool/src/eggprogs/eggTextureCards.h +++ b/pandatool/src/eggprogs/eggTextureCards.h @@ -24,6 +24,7 @@ #include "eggWriter.h" #include "eggTexture.h" #include "luse.h" +#include "vector_string.h" class EggVertexPool; class EggVertex; @@ -56,6 +57,7 @@ public: LVecBase4d _polygon_geometry; LVecBase2d _pixel_scale; bool _got_pixel_scale; + vector_string _suffixes; Colorf _polygon_color; vector_string _texture_names; EggTexture::WrapMode _wrap_mode; diff --git a/pandatool/src/progbase/programBase.cxx b/pandatool/src/progbase/programBase.cxx index e576488d9e..5d23149b46 100644 --- a/pandatool/src/progbase/programBase.cxx +++ b/pandatool/src/progbase/programBase.cxx @@ -31,6 +31,7 @@ #include "dconfig.h" #include "config_dconfig.h" #include "string_utils.h" +#include "vector_string.h" #include #include @@ -994,6 +995,26 @@ dispatch_string(const string &, const string &arg, void *var) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: ProgramBase::dispatch_vector_string +// Access: Protected, Static +// Description: Standard dispatch function for an option that takes +// one parameter, which is to be interpreted as a +// string. This is different from dispatch_string in +// that the parameter may be repeated multiple times, +// and each time the string value is appended to a +// vector. +// +// The data pointer is to a vector_string variable. +//////////////////////////////////////////////////////////////////// +bool ProgramBase:: +dispatch_vector_string(const string &, const string &arg, void *var) { + vector_string *ip = (vector_string *)var; + (*ip).push_back(arg); + + return true; +} + //////////////////////////////////////////////////////////////////// // Function: ProgramBase::dispatch_filename // Access: Protected, Static diff --git a/pandatool/src/progbase/programBase.h b/pandatool/src/progbase/programBase.h index 4ee2adcbae..cea4897a30 100644 --- a/pandatool/src/progbase/programBase.h +++ b/pandatool/src/progbase/programBase.h @@ -97,6 +97,7 @@ protected: static bool dispatch_double_quad(const string &opt, const string &arg, void *var); static bool dispatch_color(const string &opt, const string &arg, void *var); static bool dispatch_string(const string &opt, const string &arg, void *var); + static bool dispatch_vector_string(const string &opt, const string &arg, void *var); static bool dispatch_filename(const string &opt, const string &arg, void *var); static bool dispatch_search_path(const string &opt, const string &arg, void *var); static bool dispatch_coordinate_system(const string &opt, const string &arg, void *var);