add -suffix to egg-texture-cards

This commit is contained in:
David Rose 2003-05-30 21:05:37 +00:00
parent e543945dd2
commit cf5188d6ba
4 changed files with 43 additions and 0 deletions

View File

@ -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;

View File

@ -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;

View File

@ -31,6 +31,7 @@
#include "dconfig.h"
#include "config_dconfig.h"
#include "string_utils.h"
#include "vector_string.h"
#include <stdlib.h>
#include <algorithm>
@ -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

View File

@ -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);