16 #include "eggCoordinateSystem.h"
17 #include "eggTextureCollection.h"
18 #include "eggMaterialCollection.h"
19 #include "eggComment.h"
20 #include "eggPoolUniquifier.h"
21 #include "config_egg.h"
22 #include "config_util.h"
23 #include "config_express.h"
24 #include "string_utils.h"
25 #include "dSearchPath.h"
26 #include "virtualFileSystem.h"
27 #include "lightMutexHolder.h"
30 extern int eggyyparse();
31 #include "parserDefs.h"
32 #include "lexerDefs.h"
55 return vfs->
exists(egg_filename);
75 if (display_name.empty()) {
76 display_name = filename;
83 egg_cat.error() <<
"Could not find " << display_name <<
"\n";
88 istream *file = vfile->open_read_file(
true);
89 if (file == (istream *)NULL) {
90 egg_cat.error() <<
"Unable to open " << display_name <<
"\n";
95 <<
"Reading " << display_name <<
"\n";
97 bool read_ok =
read(*file);
98 vfile->close_read_file(file);
133 egg_cleanup_parser();
134 error_count = egg_error_count();
142 return (error_count == 0);
248 if (file == (ostream *)NULL) {
249 egg_cat.error() <<
"Unable to open " << filename <<
" for writing.\n";
280 if (new_coordsys == CS_default) {
281 new_coordsys = get_default_coordinate_system();
283 if (new_coordsys != _coordsys &&
284 (_coordsys != CS_default && _coordsys != CS_invalid)) {
289 r_transform(mat, inv, new_coordsys);
290 r_transform_vertices(mat);
297 _coordsys = new_coordsys;
307 write(ostream &out,
int indent_level)
const {
309 ecs->write(out, indent_level);
323 CoordinateSystem old_coordsys = _coordsys;
324 _coordsys = find_coordsys_entry();
326 if (_coordsys == CS_default) {
329 _coordsys = CS_yup_right;
331 }
else if (_coordsys == CS_invalid) {
333 <<
"Contradictory <CoordinateSystem> entries encountered.\n";
334 _coordsys = CS_yup_right;
337 r_mark_coordsys(_coordsys);
339 if (old_coordsys != CS_default) {
392 iterator ci = begin();
393 while (ci != end() && (*ci)->is_of_type(EggComment::get_class_type())) {
void sort_by_mref()
Sorts all the materials into alphabetical order by MRef name.
void sort_by_tref()
Sorts all the textures into alphabetical order by TRef name.
int collapse_equivalent_textures()
Removes duplicate references to the same texture image with the same properties.
static bool resolve_egg_filename(Filename &egg_filename, const DSearchPath &searchpath=DSearchPath())
Looks for the indicated filename, first along the indicated searchpath, and then along the model_path...
int collapse_equivalent_textures(int eq, EggGroupNode *node)
Walks through the collection and collapses together any separate textures that are equivalent accordi...
void uniquify_trefs()
Guarantees that each texture in the collection has a unique TRef name.
void uniquify_mrefs()
Guarantees that each material in the collection has a unique MRef name.
This is a 4-by-4 transform matrix.
The <CoordinateSystem> entry at the top of an egg file.
bool write_egg(Filename filename)
The main interface for writing complete egg files.
A base class for nodes in the hierarchy that are not leaf nodes.
This is a collection of materials by MRef name.
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
void remove_unused_textures(EggNode *node)
Removes any textures from the collection that aren't referenced by any primitives in the indicated eg...
void set_text()
Indicates that the filename represents a text file.
void set_egg_filename(const Filename &egg_filename)
Sets the filename–especially the directory part–in which the egg file is considered to reside...
This is a collection of textures by TRef name.
int collapse_equivalent_materials(int eq, EggGroupNode *node)
Walks through the collection and collapses together any separate materials that are equivalent accord...
bool is_fully_qualified() const
Returns true if the filename is fully qualified, e.g.
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...
int extract_textures(EggGroupNode *node)
Walks the egg hierarchy beginning at the indicated node, and removes any EggTextures encountered in t...
The abstract base class for a file or directory within the VirtualFileSystem.
EggGroupNode::iterator insert_materials(EggGroupNode *node)
Adds a series of EggMaterial nodes to the beginning of the indicated node to reflect each of the mate...
bool has_absolute_pathnames() const
Returns true if any nodes at this level and below include a reference to a file via an absolute pathn...
void set_coordinate_system(CoordinateSystem coordsys)
Changes the coordinate system of the EggData.
CoordinateSystem get_coordinate_system() const
Returns the coordinate system in which the egg file is defined.
This is a specialization of EggNameUniquifier to generate unique names for textures, materials, and vertex pools prior to writing out an egg file.
EggGroupNode::iterator insert_textures(EggGroupNode *node)
Adds a series of EggTexture nodes to the beginning of the indicated node to reflect each of the textu...
The name of a file, such as a texture file or an Egg file.
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
Similar to MutexHolder, but for a light mutex.
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 get_auto_resolve_externals() const
Indicates whether the EggData object will automatically resolve any external references when read() i...
void steal_children(EggGroupNode &other)
Moves all the children from the other node to this one.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
bool read(Filename filename, string display_name=string())
Opens the indicated filename and reads the egg data contents from it.
bool resolve_filename(Filename &filename, const DSearchPath &searchpath, const string &default_extension=string()) const
Searches the given search path for the filename.
int extract_materials(EggGroupNode *node)
Walks the egg hierarchy beginning at the indicated node, and removes any EggMaterials encountered in ...
void uniquify(EggNode *node)
Begins the traversal from the indicated node.
int find_used_textures(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by ...
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
void remove_unused_materials(EggNode *node)
Removes any materials from the collection that aren't referenced by any primitives in the indicated e...
bool exists(const Filename &filename) const
Convenience function; returns true if the named file exists.
static const LMatrix4d & convert_mat(CoordinateSystem from, CoordinateSystem to)
Returns a matrix that transforms from the indicated coordinate system to the indicated coordinate sys...
ostream * open_write_file(const Filename &filename, bool auto_wrap, bool truncate)
Convenience function; returns a newly allocated ostream if the file exists and can be written...
void set_egg_timestamp(time_t egg_timestamp)
Sets the timestamp of the egg file on disk, at the time it was opened for reading.
This class stores a list of directories that can be searched, in order, to locate a particular file...
bool delete_file(const Filename &filename)
Attempts to delete the indicated file or directory.
TypeHandle is the identifier used to differentiate C++ class types.
static void close_write_file(ostream *stream)
Closes a file opened by a previous call to open_write_file().
const Filename & get_egg_filename() const
Returns the directory in which the egg file is considered to reside.
int find_used_materials(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for materials that are referenced by...
int collapse_equivalent_materials()
Removes duplicate references to the same material with the same properties.
void resolve_filenames(const DSearchPath &searchpath)
Walks the tree and attempts to resolve any filenames encountered.
void merge(EggData &other)
Appends the other egg structure to the end of this one.