ソースを参照

Added support for bam-relative texture paths

Josh Yelon 20 年 前
コミット
6b82426994

+ 5 - 0
panda/src/gobj/texture.cxx

@@ -1455,9 +1455,14 @@ make_Texture(const FactoryParams &params) {
 
     } else {
       // This texture does have a filename, so try to load it from disk.
+      VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+      if (!manager->get_filename().empty())
+        vfs->resolve_filename(filename,manager->get_filename().get_dirname());
       if (alpha_filename.empty()) {
         me = TexturePool::load_texture(filename, primary_file_num_channels);
       } else {
+        if (!manager->get_filename().empty())
+          vfs->resolve_filename(alpha_filename, manager->get_filename().get_dirname());
         me = TexturePool::load_texture(filename, alpha_filename, 
                                        primary_file_num_channels, alpha_file_channel);
       }

+ 1 - 1
panda/src/pgraph/bamFile.cxx

@@ -404,7 +404,7 @@ continue_open_read(const string &bam_filename, bool report_errors) {
     return false;
   }
 
-  _reader = new BamReader(&_din);
+  _reader = new BamReader(&_din, bam_filename);
   if (!_reader->init()) {
     close();
     return false;

+ 15 - 2
panda/src/putil/bamReader.cxx

@@ -43,8 +43,8 @@ const int BamReader::_cur_minor = _bam_minor_ver;
 //  Description:
 ////////////////////////////////////////////////////////////////////
 BamReader::
-BamReader(DatagramGenerator *generator)
-  : _source(generator)
+BamReader(DatagramGenerator *generator, const Filename &name)
+  : _source(generator), _filename(name)
 {
   _num_extra_objects = 0;
   _now_creating = _created_objs.end();
@@ -169,6 +169,19 @@ get_aux_data(const string &name) const {
   return NULL;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: BamReader::get_filename
+//       Access: Public
+//  Description: If a BAM is a file, then the BamReader should
+//               contain the name of the file.  This enables the
+//               reader to interpret pathnames in the BAM as relative
+//               to the directory containing the BAM.
+////////////////////////////////////////////////////////////////////
+const Filename &BamReader::
+get_filename(void) const {
+  return _filename;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: BamReader::read_object
 //       Access: Public

+ 6 - 3
panda/src/putil/bamReader.h

@@ -94,14 +94,15 @@ public:
   static WritableFactory *const NullFactory;
 
   // The primary interface for a caller.
-  BamReader(DatagramGenerator *generator);
+  BamReader(DatagramGenerator *generator, const Filename &name="");
   ~BamReader();
 
   bool init();
 
   void set_aux_data(const string &name, void *data);
   void *get_aux_data(const string &name) const;
-
+  const Filename &get_filename() const;
+  
   TypedWritable *read_object();
   INLINE bool is_eof() const;
   bool resolve();
@@ -142,7 +143,6 @@ public:
 
   TypeHandle read_handle(DatagramIterator &scan);
 
-
 public:
   INLINE static WritableFactory *get_factory();
 private:
@@ -172,6 +172,9 @@ private:
   typedef phash_map<int, TypeHandle, int_hash> IndexMap;
   IndexMap _index_map;
 
+  // This is the filename of the BAM, or null string if not in a file.
+  Filename _filename;
+
   // This maps the object ID numbers encountered within the Bam file
   // to the actual pointers of the corresponding generated objects.
   class CreatedObj {