Browse Source

more interface for egg-palettize

David Rose 22 years ago
parent
commit
7620dff858

+ 9 - 5
panda/src/egg/eggData.cxx

@@ -86,21 +86,25 @@ resolve_egg_filename(Filename &egg_filename, const DSearchPath &searchpath) {
 //               messages.
 ////////////////////////////////////////////////////////////////////
 bool EggData::
-read(Filename filename) {
+read(Filename filename, string display_name) {
   filename.set_text();
   set_egg_filename(filename);
 
+  if (display_name.empty()) {
+    display_name = filename;
+  }
+
   if (use_vfs) {
     VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
     
     istream *file = vfs->open_read_file(filename);
     if (file == (istream *)NULL) {
-      egg_cat.error() << "Unable to open " << filename << "\n";
+      egg_cat.error() << "Unable to open " << display_name << "\n";
       return false;
     }
     
     egg_cat.info()
-      << "Reading " << filename << "\n";
+      << "Reading " << display_name << "\n";
 
     bool read_ok = read(*file);
     delete file;
@@ -109,12 +113,12 @@ read(Filename filename) {
   } else {
     ifstream file;
     if (!filename.open_read(file)) {
-      egg_cat.error() << "Unable to open " << filename << "\n";
+      egg_cat.error() << "Unable to open " << display_name << "\n";
       return false;
     }
     
     egg_cat.info()
-      << "Reading " << filename << "\n";
+      << "Reading " << display_name << "\n";
     
     return read(file);
   }

+ 1 - 1
panda/src/egg/eggData.h

@@ -52,7 +52,7 @@ public:
   static bool resolve_egg_filename(Filename &egg_filename,
                                    const DSearchPath &searchpath = DSearchPath());
 
-  bool read(Filename filename);
+  bool read(Filename filename, string display_name = string());
   bool read(istream &in);
   void merge(EggData &other);
 

+ 42 - 0
panda/src/egg/eggGroupNode.cxx

@@ -348,6 +348,48 @@ resolve_filenames(const DSearchPath &searchpath) {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggGroupNode::force_filenames
+//       Access: Public
+//  Description: Similar to resolve_filenames, but each non-absolute
+//               filename encountered is arbitrarily taken to be in
+//               the indicated directory, whether or not the so-named
+//               filename exists.
+////////////////////////////////////////////////////////////////////
+void EggGroupNode::
+force_filenames(const Filename &directory) {
+  Children::iterator ci;
+  for (ci = _children.begin();
+       ci != _children.end();
+       ++ci) {
+    EggNode *child = *ci;
+    if (child->is_of_type(EggTexture::get_class_type())) {
+      EggTexture *tex = DCAST(EggTexture, child);
+      Filename tex_filename = tex->get_filename();
+      if (tex_filename.is_local()) {
+        tex->set_filename(Filename(directory, tex_filename));
+      }
+
+      if (tex->has_alpha_filename()) {
+        Filename alpha_filename = tex->get_alpha_filename();
+        if (alpha_filename.is_local()) {
+          tex->set_alpha_filename(Filename(directory, alpha_filename));
+        }
+      }
+
+    } else if (child->is_of_type(EggFilenameNode::get_class_type())) {
+      EggFilenameNode *fnode = DCAST(EggFilenameNode, child);
+      Filename filename = fnode->get_filename();
+      if (filename.is_local()) {
+        fnode->set_filename(Filename(directory, filename));
+      }
+
+    } else if (child->is_of_type(EggGroupNode::get_class_type())) {
+      DCAST(EggGroupNode, child)->force_filenames(directory);
+    }
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: EggGroupNode::reverse_vertex_ordering
 //       Access: Public

+ 1 - 0
panda/src/egg/eggGroupNode.h

@@ -112,6 +112,7 @@ public:
   EggNode *find_child(const string &name) const;
 
   void resolve_filenames(const DSearchPath &searchpath);
+  void force_filenames(const Filename &directory);
   void reverse_vertex_ordering();
 
   void recompute_vertex_normals(double threshold, CoordinateSystem cs = CS_default);