17 #include "eggGroupNode.h"
18 #include "eggTexture.h"
19 #include "eggFilenameNode.h"
20 #include "eggComment.h"
22 #include "string_utils.h"
32 (
"cs",
"coordinate-system", 80,
33 "Specify the coordinate system to operate in. This may be one of "
34 "'y-up', 'z-up', 'y-up-left', or 'z-up-left'.",
35 &EggBase::dispatch_coordinate_system,
36 &_got_coordinate_system, &_coordinate_system);
38 _normals_mode = NM_preserve;
39 _normals_threshold = 0.0;
45 _got_transform =
false;
48 _got_coordinate_system =
false;
49 _coordinate_system = CS_yup_right;
64 static NormalsMode strip = NM_strip;
65 static NormalsMode polygon = NM_polygon;
66 static NormalsMode vertex = NM_vertex;
67 static NormalsMode preserve = NM_preserve;
72 &EggBase::dispatch_normals, NULL, &strip);
76 "Strip existing normals and redefine polygon normals.",
77 &EggBase::dispatch_normals, NULL, &polygon);
80 (
"nv",
"threshold", 48,
81 "Strip existing normals and redefine vertex normals. Consider an edge "
82 "between adjacent polygons to be smooth if the angle between them "
83 "is less than threshold degrees.",
84 &EggBase::dispatch_normals, NULL, &vertex);
88 "Preserve normals exactly as they are. This is the default.",
89 &EggBase::dispatch_normals, NULL, &preserve);
93 "Compute tangent and binormal for the named texture coordinate "
94 "set(s). The name may include wildcard characters such as * and ?. "
95 "The normal must already exist or have been computed via one of the "
96 "above options. The tangent and binormal are used to implement "
97 "bump mapping and related texture-based lighting effects. This option "
98 "may be repeated as necessary to name multiple texture coordinate sets.",
99 &EggBase::dispatch_vector_string, NULL, &_tbn_names);
103 "Compute tangent and binormal for all texture coordinate "
104 "sets. This is equivalent to -tbn \"*\".",
105 &EggBase::dispatch_none, &_got_tbnall);
109 "Compute tangent and binormal for all normal maps. ",
110 &EggBase::dispatch_none, &_got_tbnauto);
122 "Construct <PointLight> entries for any unreferenced vertices, to make them visible.",
123 &EggBase::dispatch_none, &_make_points);
137 (
"TS",
"sx[,sy,sz]", 49,
138 "Scale the model uniformly by the given factor (if only one number "
139 "is given) or in each axis by sx, sy, sz (if three numbers are given).",
140 &EggBase::dispatch_scale, &_got_transform, &_transform);
144 "Rotate the model x degrees about the x axis, then y degrees about the "
145 "y axis, and then z degrees about the z axis.",
146 &EggBase::dispatch_rotate_xyz, &_got_transform, &_transform);
149 (
"TA",
"angle,x,y,z", 49,
150 "Rotate the model angle degrees counterclockwise about the given "
152 &EggBase::dispatch_rotate_axis, &_got_transform, &_transform);
156 "Translate the model by the indicated amount.\n\n"
157 "All transformation options (-TS, -TR, -TA, -TT) are cumulative and are "
158 "applied in the order they are encountered on the command line.",
159 &EggBase::dispatch_translate, &_got_transform, &_transform);
172 if (node->
is_of_type(EggTexture::get_class_type())) {
177 egg_tex->set_filename(outpath);
181 Filename alpha_fullpath, alpha_outpath;
183 alpha_fullpath, alpha_outpath);
188 }
else if (node->
is_of_type(EggFilenameNode::get_class_type())) {
194 egg_fnode->set_filename(outpath);
197 }
else if (node->
is_of_type(EggGroupNode::get_class_type())) {
199 EggGroupNode::const_iterator ci;
200 for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) {
218 append_command_comment(
EggData *data) {
234 append_command_comment(
EggData *data,
const string &comment) {
235 data->insert(data->begin(),
new EggComment(
"", comment));
247 dispatch_normals(
ProgramBase *
self,
const string &opt,
const string &arg,
void *mode) {
249 return base->ns_dispatch_normals(opt, arg, mode);
261 ns_dispatch_normals(
const string &opt,
const string &arg,
void *mode) {
262 _normals_mode = *(NormalsMode *)mode;
264 if (_normals_mode == NM_vertex) {
265 if (!string_to_double(arg, _normals_threshold)) {
266 nout <<
"Invalid numeric parameter for -" << opt <<
": "
282 dispatch_scale(
const string &opt,
const string &arg,
void *var) {
286 tokenize(arg, words,
",");
291 if (words.size() == 3) {
293 string_to_double(words[0], sx) &&
294 string_to_double(words[1], sy) &&
295 string_to_double(words[2], sz);
297 }
else if (words.size() == 1) {
299 string_to_double(words[0], sx);
305 <<
" requires one or three numbers separated by commas.\n";
321 dispatch_rotate_xyz(
ProgramBase *
self,
const string &opt,
const string &arg,
void *var) {
323 return base->ns_dispatch_rotate_xyz(opt, arg, var);
333 ns_dispatch_rotate_xyz(
const string &opt,
const string &arg,
void *var) {
337 tokenize(arg, words,
",");
342 if (words.size() == 3) {
344 string_to_double(words[0], xyz[0]) &&
345 string_to_double(words[1], xyz[1]) &&
346 string_to_double(words[2], xyz[2]);
351 <<
" requires three numbers separated by commas.\n";
360 *transform = (*transform) * mat;
372 dispatch_rotate_axis(
ProgramBase *
self,
const string &opt,
const string &arg,
void *var) {
374 return base->ns_dispatch_rotate_axis(opt, arg, var);
384 ns_dispatch_rotate_axis(
const string &opt,
const string &arg,
void *var) {
388 tokenize(arg, words,
",");
394 if (words.size() == 4) {
396 string_to_double(words[0], angle) &&
397 string_to_double(words[1], axis[0]) &&
398 string_to_double(words[2], axis[1]) &&
399 string_to_double(words[3], axis[2]);
404 <<
" requires four numbers separated by commas.\n";
420 dispatch_translate(
const string &opt,
const string &arg,
void *var) {
424 tokenize(arg, words,
",");
429 if (words.size() == 3) {
431 string_to_double(words[0], trans[0]) &&
432 string_to_double(words[1], trans[1]) &&
433 string_to_double(words[2], trans[2]);
438 <<
" requires three numbers separated by commas.\n";
void set_fullpath(const Filename &fullpath)
Records the full pathname to the file, for the benefit of get_fullpath().
This is intended to be the base class for most general-purpose utility programs in the PANDATOOL tree...
This is a 4-by-4 transform matrix.
static LMatrix4d rotate_mat(double angle, const LVecBase3d &axis, CoordinateSystem cs=CS_default)
Returns a matrix that rotates by the given angle in degrees counterclockwise about the indicated vect...
This is an egg node that contains a filename.
A base class for nodes in the hierarchy that are not leaf nodes.
Defines a texture map that may be applied to geometry.
void add_normals_options()
Adds -no, -np, etc.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
static LMatrix4d scale_mat(const LVecBase3d &scale)
Returns a matrix that applies the indicated scale in each of the three axes.
void full_convert_path(const Filename &orig_filename, const DSearchPath &additional_path, Filename &resolved_path, Filename &output_path)
Converts the input path into two different forms: A resolved path, and an output path.
void set_alpha_fullpath(const Filename &fullpath)
Records the full pathname to the file, for the benefit of get_alpha_fullpath().
static LMatrix4d translate_mat(const LVecBase3d &trans)
Returns a matrix that applies the indicated translation.
This is the primary interface into all the egg data, and the root of the egg file structure...
static void convert_paths(EggNode *node, PathReplace *path_replace, const DSearchPath &additional_path)
Recursively walks the egg hierarchy.
void set_alpha_filename(const Filename &filename)
Specifies a separate file that will be loaded in with the 1- or 3-component texture and applied as th...
The name of a file, such as a texture file or an Egg file.
bool has_alpha_filename() const
Returns true if a separate file for the alpha component has been applied, false otherwise.
static const LMatrix4d & ident_mat()
Returns an identity matrix.
const Filename & get_filename() const
Returns a nonmodifiable reference to the filename.
This is the base class for all three-component vectors and points.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
string get_exec_command() const
Returns the command that invoked this program, as a shell-friendly string, suitable for pasting into ...
const Filename & get_alpha_filename() const
Returns the separate file assigned for the alpha channel.
This encapsulates the user's command-line request to replace existing, incorrect pathnames to models ...
A base class for things that may be directly added into the egg hierarchy.
void add_transform_options()
Adds -TS, -TT, etc.
This is a base class for both EggSingleBase and EggMultiBase.
void add_points_options()
Adds -points as a valid option for this program.
This class stores a list of directories that can be searched, in order, to locate a particular file...