15 #include "eggReader.h" 18 #include "config_util.h" 19 #include "eggTextureCollection.h" 21 #include "eggGroupNode.h" 22 #include "eggSwitchCondition.h" 23 #include "string_utils.h" 34 add_runline(
"[opts] input.egg");
38 "Specify the coordinate system to operate in. This may be " 39 " one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'. The default " 40 "is the coordinate system of the input egg file.");
44 "Force complete loading: load up the egg file along with all of its " 45 "external references.",
46 &EggReader::dispatch_none, &_force_complete);
50 "Don't allow the input egg file to have absolute pathnames. " 51 "If it does, abort with an error. This option is designed to help " 52 "detect errors when populating or building a standalone model tree, " 53 "which should be self-contained and include only relative pathnames.",
54 &EggReader::dispatch_none, &_noabs);
59 _got_tex_dirname =
false;
60 _got_tex_extension =
false;
80 "Copy textures to the indicated directory. The copy is performed " 81 "only if the destination file does not exist or is older than the " 83 &EggReader::dispatch_filename, &_got_tex_dirname, &_tex_dirname);
87 "Rename textures to have the indicated extension. This also " 88 "automatically copies them to the new filename (possibly in a " 89 "different directory if -td is also specified), and may implicitly " 90 "convert to a different image format according to the extension.",
91 &EggReader::dispatch_string, &_got_tex_extension, &_tex_extension);
95 "Explicitly specifies the image format to convert textures to " 96 "when copying them via -td or -te. Normally, this is unnecessary as " 97 "the image format can be determined by the extension, but sometimes " 98 "the extension is insufficient to unambiguously specify an image " 100 &EggReader::dispatch_image_type, NULL, &_tex_type);
115 _delod = default_delod;
117 if (default_delod < 0) {
119 (
"delod",
"dist", 40,
120 "Eliminate LOD's by choosing the level that would be appropriate for " 121 "a camera at the indicated fixed distance from each LOD. " 122 "Use -delod -1 to keep all the LOD's as they are, which is " 124 &EggReader::dispatch_double, NULL, &_delod);
128 (
"delod",
"dist", 40,
129 "Eliminate LOD's by choosing the level that would be appropriate for " 130 "a camera at the indicated fixed distance from each LOD. " 131 "Use -delod -1 to keep all the LOD's as they are. The default value " 132 "is " + format_string(default_delod) +
".",
133 &EggReader::dispatch_double, NULL, &_delod);
175 nout <<
"You must specify the egg file(s) to read on the command line.\n";
185 Args::const_iterator ai;
186 for (ai = args.begin(); ai != args.end(); ++ai) {
190 if (!file_data.
read(filename)) {
199 <<
" includes absolute pathnames!\n";
206 if (_force_complete) {
216 _data->merge(file_data);
235 post_command_line() {
236 return EggSingleBase::post_command_line();
248 do_reader_options() {
251 if (_got_tex_dirname || _got_tex_extension) {
252 if (!copy_textures()) {
278 EggTextureCollection::const_iterator ti;
279 for (ti = textures.begin(); ti != textures.end(); ++ti) {
282 if (!orig_filename.
exists()) {
285 nout <<
"Cannot find " << orig_filename <<
"\n";
291 Filename new_filename = orig_filename;
292 if (_got_tex_dirname) {
295 if (_got_tex_extension) {
299 if (orig_filename != new_filename) {
300 tex->set_filename(new_filename);
307 nout <<
"Reading " << orig_filename <<
"\n";
309 if (!image.
read(orig_filename)) {
310 nout <<
" unable to read!\n";
313 nout <<
"Writing " << new_filename <<
"\n";
314 if (!image.
write(new_filename, _tex_type)) {
315 nout <<
" unable to write!\n";
336 if (node->
is_of_type(EggGroup::get_class_type())) {
338 if (group->has_lod()) {
340 if (cond.
is_of_type(EggSwitchConditionDistance::get_class_type())) {
343 if (_delod >= dist->_switch_out && _delod < dist->_switch_in) {
346 nout <<
"Preserving LOD " << node->get_name()
347 <<
" (" << dist->_switch_out <<
" to " << dist->_switch_in
352 nout <<
"Eliminating LOD " << node->get_name()
353 <<
" (" << dist->_switch_out <<
" to " << dist->_switch_in
362 if (node->
is_of_type(EggGroupNode::get_class_type())) {
364 EggGroupNode::iterator ci;
366 while (ci != group->end()) {
370 if (!do_delod(child)) {
371 group->remove_child(child);
string get_dirname() const
Returns the directory part of the filename.
string get_basename() const
Returns the basename part of the filename.
void set_extension(const string &s)
Replaces the file extension.
const Filename & get_filename() const
Returns a nonmodifiable reference to the filename.
void add_delod_options(double default_delod=-1.0)
Adds -delod as a valid option for this program.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
void add_texture_options()
Adds -td, -te, etc.
A base class for nodes in the hierarchy that are not leaf nodes.
Defines a texture map that may be applied to geometry.
bool read(const Filename &filename, PNMFileType *type=NULL, bool report_unknown_type=true)
Reads the indicated image filename.
This is the base class of a family of classes that represent particular image file types that PNMImag...
virtual EggReader * as_reader()
Returns this object as an EggReader pointer, if it is in fact an EggReader, or NULL if it is not...
This is a collection of textures by TRef name.
void append_directory(const Filename &directory)
Adds a new directory to the end of the search list.
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.
bool resolve_filename(const DSearchPath &searchpath, const string &default_extension=string())
Searches the given search path for the filename.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
The name of a file, such as a texture file or an Egg file.
bool load_externals(const DSearchPath &searchpath=DSearchPath())
Loads up all the egg files referenced by <File> entries within the egg structure, and inserts their c...
bool read(Filename filename, string display_name=string())
Opens the indicated filename and reads the egg data contents from it.
void set_dirname(const string &s)
Replaces the directory part of the filename.
virtual void pre_process_egg_file()
Performs any processing of the egg file that is appropriate after reading it in.
bool write(const Filename &filename, PNMFileType *type=NULL) const
Writes the image to the indicated filename.
int find_used_textures(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by ...
This is the base class for a program that reads egg files, but doesn't write an egg file...
bool original_had_absolute_pathnames() const
Returns true if the data processed in the last call to read() contained absolute pathnames, or false if those pathnames were all relative.
int compare_timestamps(const Filename &other, bool this_missing_is_old=true, bool other_missing_is_old=true) const
Returns a number less than zero if the file named by this object is older than the given file...
A base class for things that may be directly added into the egg hierarchy.
This class stores a list of directories that can be searched, in order, to locate a particular file...
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
This corresponds to a <SwitchCondition> entry within a group.
A SwitchCondition that switches the levels-of-detail based on distance from the camera's eyepoint...
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).