From 697f2a2b672267a1f340e9f6c1b491b42c8345d7 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 29 Nov 2004 22:57:09 +0000 Subject: [PATCH] add had_absolute_pathnames() --- panda/src/egg/eggData.I | 21 +++++++++++++ panda/src/egg/eggData.cxx | 3 ++ panda/src/egg/eggData.h | 2 ++ panda/src/egg/eggGroupNode.cxx | 57 ++++++++++++++++++++++++++++++++++ panda/src/egg/eggGroupNode.h | 1 + 5 files changed, 84 insertions(+) diff --git a/panda/src/egg/eggData.I b/panda/src/egg/eggData.I index d4c9af48f0..866f69df07 100644 --- a/panda/src/egg/eggData.I +++ b/panda/src/egg/eggData.I @@ -25,6 +25,7 @@ INLINE EggData:: EggData() { _auto_resolve_externals = false; + _had_absolute_pathnames = false; _coordsys = CS_default; } @@ -38,6 +39,7 @@ INLINE EggData:: EggData(const EggData ©) : EggGroupNode(copy), _auto_resolve_externals(copy._auto_resolve_externals), + _had_absolute_pathnames(copy._had_absolute_pathnames), _coordsys(copy._coordsys), _egg_filename(copy._egg_filename) { @@ -52,6 +54,7 @@ INLINE EggData &EggData:: operator = (const EggData ©) { EggGroupNode::operator = (copy); _auto_resolve_externals = copy._auto_resolve_externals; + _had_absolute_pathnames = copy._had_absolute_pathnames; _coordsys = copy._coordsys; _egg_filename = copy._egg_filename; return *this; @@ -81,6 +84,24 @@ get_auto_resolve_externals() const { return _auto_resolve_externals; } +//////////////////////////////////////////////////////////////////// +// Function: EggData::original_had_absolute_pathnames +// Access: Public +// Description: Returns true if the data processed in the last call +// to read() contained absolute pathnames, or false if +// those pathnames were all relative. +// +// This method is necessary because if +// auto_resolve_externals() is in effect, it may modify +// the pathnames to be absolute whether or not they were +// as loaded from disk. This method can be used to +// query the state of the original egg file from disk. +//////////////////////////////////////////////////////////////////// +INLINE bool EggData:: +original_had_absolute_pathnames() const { + return _had_absolute_pathnames; +} + //////////////////////////////////////////////////////////////////// // Function: EggData::get_coordinate_system // Access: Public diff --git a/panda/src/egg/eggData.cxx b/panda/src/egg/eggData.cxx index 3dff0bff34..d9cd1f54c2 100644 --- a/panda/src/egg/eggData.cxx +++ b/panda/src/egg/eggData.cxx @@ -342,6 +342,9 @@ post_read() { set_coordinate_system(old_coordsys); } + // Fill this in before we automatically resolve pathnames. + _had_absolute_pathnames = has_absolute_pathnames(); + if (get_auto_resolve_externals()) { // Resolve filenames that are relative to the egg file. DSearchPath dir; diff --git a/panda/src/egg/eggData.h b/panda/src/egg/eggData.h index 3a7d384f11..750c5fa76a 100644 --- a/panda/src/egg/eggData.h +++ b/panda/src/egg/eggData.h @@ -62,6 +62,7 @@ PUBLISHED: INLINE void set_auto_resolve_externals(bool resolve); INLINE bool get_auto_resolve_externals() const; + INLINE bool original_had_absolute_pathnames() const; void set_coordinate_system(CoordinateSystem coordsys); INLINE CoordinateSystem get_coordinate_system() const; @@ -81,6 +82,7 @@ private: void pre_write(); bool _auto_resolve_externals; + bool _had_absolute_pathnames; CoordinateSystem _coordsys; Filename _egg_filename; diff --git a/panda/src/egg/eggGroupNode.cxx b/panda/src/egg/eggGroupNode.cxx index b8b8150a7c..ab6dde631c 100644 --- a/panda/src/egg/eggGroupNode.cxx +++ b/panda/src/egg/eggGroupNode.cxx @@ -350,6 +350,63 @@ find_child(const string &name) const { return NULL; } +//////////////////////////////////////////////////////////////////// +// Function: EggGroupNode::has_absolute_pathnames +// Access: Published +// Description: Returns true if any nodes at this level and below +// include a reference to a file via an absolute +// pathname, or false if all references are relative. +//////////////////////////////////////////////////////////////////// +bool EggGroupNode:: +has_absolute_pathnames() const { + Children::const_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); + if (!tex->get_filename().is_local()) { + if (egg_cat.is_debug()) { + egg_cat.debug() + << "Absolute pathname: " << tex->get_filename() + << "\n"; + } + return true; + } + + if (tex->has_alpha_filename()) { + if (!tex->get_alpha_filename().is_local()) { + if (egg_cat.is_debug()) { + egg_cat.debug() + << "Absolute pathname: " << tex->get_alpha_filename() + << "\n"; + } + return true; + } + } + + } else if (child->is_of_type(EggFilenameNode::get_class_type())) { + EggFilenameNode *fnode = DCAST(EggFilenameNode, child); + if (!fnode->get_filename().is_local()) { + if (egg_cat.is_debug()) { + egg_cat.debug() + << "Absolute pathname: " << fnode->get_filename() + << "\n"; + } + return true; + } + + } else if (child->is_of_type(EggGroupNode::get_class_type())) { + if (DCAST(EggGroupNode, child)->has_absolute_pathnames()) { + return true; + } + } + } + + return false; +} + //////////////////////////////////////////////////////////////////// // Function: EggGroupNode::resolve_filenames // Access: Published diff --git a/panda/src/egg/eggGroupNode.h b/panda/src/egg/eggGroupNode.h index 01e8fd86f1..a70ea4766a 100644 --- a/panda/src/egg/eggGroupNode.h +++ b/panda/src/egg/eggGroupNode.h @@ -120,6 +120,7 @@ PUBLISHED: EggNode *find_child(const string &name) const; + bool has_absolute_pathnames() const; void resolve_filenames(const DSearchPath &searchpath); void force_filenames(const Filename &directory); void reverse_vertex_ordering();