From 6b82426994b2f33afe9cd1608a36b1f2efdf4042 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Thu, 11 Aug 2005 06:12:32 +0000 Subject: [PATCH] Added support for bam-relative texture paths --- panda/src/gobj/texture.cxx | 5 +++++ panda/src/pgraph/bamFile.cxx | 2 +- panda/src/putil/bamReader.cxx | 17 +++++++++++++++-- panda/src/putil/bamReader.h | 9 ++++++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 6a8b3e5da6..94fe4dc758 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -1455,9 +1455,14 @@ make_Texture(const FactoryParams ¶ms) { } 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); } diff --git a/panda/src/pgraph/bamFile.cxx b/panda/src/pgraph/bamFile.cxx index 002e16b041..aa1c6cf7f1 100644 --- a/panda/src/pgraph/bamFile.cxx +++ b/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; diff --git a/panda/src/putil/bamReader.cxx b/panda/src/putil/bamReader.cxx index cf6fc4bb17..d606915772 100644 --- a/panda/src/putil/bamReader.cxx +++ b/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 diff --git a/panda/src/putil/bamReader.h b/panda/src/putil/bamReader.h index d3567a16b0..837287384b 100644 --- a/panda/src/putil/bamReader.h +++ b/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 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 {