From 2fd799cf299380487e605a661e146757e07817a2 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 25 Feb 2003 01:13:30 +0000 Subject: [PATCH] support egg2bam -pp properly --- dtool/pptempl/Template.models.pp | 6 +- panda/src/egg/eggFilenameNode.I | 32 +++++++-- panda/src/egg/eggFilenameNode.h | 5 +- panda/src/egg/eggGroupNode.cxx | 18 +++-- panda/src/egg/eggTexture.I | 72 ++++++++++++------- panda/src/egg/eggTexture.cxx | 6 +- panda/src/egg/eggTexture.h | 17 +++-- panda/src/egg/parser.yxx | 2 +- panda/src/egg2pg/eggLoader.cxx | 16 +++-- pandatool/src/bam/eggToBam.cxx | 1 + pandatool/src/egg-palettize/eggFile.h | 8 +-- pandatool/src/egg-palettize/imageFile.cxx | 4 +- .../src/egg-palettize/textureReference.cxx | 4 +- pandatool/src/eggbase/eggBase.cxx | 23 ++++-- pandatool/src/eggbase/eggMultiBase.cxx | 11 ++- pandatool/src/eggbase/eggReader.cxx | 11 ++- 16 files changed, 162 insertions(+), 74 deletions(-) diff --git a/dtool/pptempl/Template.models.pp b/dtool/pptempl/Template.models.pp index 4c56a8217d..ca3ff19561 100644 --- a/dtool/pptempl/Template.models.pp +++ b/dtool/pptempl/Template.models.pp @@ -321,21 +321,21 @@ $[TAB]touch $[pt] #define source $[pal_egg_dir]/$[notdir $[egg]] #define target $[bam_dir]/$[notdir $[egg:%.egg=%.bam]] $[target] : $[source] $[bam_dir]/stamp -$[TAB]egg2bam -ps rel -pd $[install_dir] $[EGG2BAM_OPTS] -o $[target] $[source] +$[TAB]egg2bam -pp $[install_dir] -ps rel -pd $[install_dir] $[EGG2BAM_OPTS] -o $[target] $[source] #end egg #foreach egg $[UNPAL_SOURCES] #define source $[source_prefix]$[egg] #define target $[bam_dir]/$[notdir $[egg:%.egg=%.bam]] $[target] : $[source] $[bam_dir]/stamp -$[TAB]egg2bam -ps rel -pd $[install_dir] $[EGG2BAM_OPTS] -o $[target] $[source] +$[TAB]egg2bam $[EGG2BAM_OPTS] -o $[target] $[source] #end egg #foreach egg $[UNPAL_SOURCES_NC] #define source $[source_prefix]$[egg] #define target $[bam_dir]/$[notdir $[egg:%.egg=%.bam]] $[target] : $[source] $[bam_dir]/stamp -$[TAB]egg2bam -ps rel -pd $[install_dir] $[EGG2BAM_OPTS] -NC -o $[target] $[source] +$[TAB]egg2bam $[EGG2BAM_OPTS] -NC -o $[target] $[source] #end egg #end install_egg diff --git a/panda/src/egg/eggFilenameNode.I b/panda/src/egg/eggFilenameNode.I index 492744b06f..70df5d39fb 100644 --- a/panda/src/egg/eggFilenameNode.I +++ b/panda/src/egg/eggFilenameNode.I @@ -80,14 +80,36 @@ get_filename() const { INLINE void EggFilenameNode:: set_filename(const Filename &filename) { _filename = filename; + _fullpath = filename; } //////////////////////////////////////////////////////////////////// -// Function: EggFilenameNode::update_filename +// Function: EggFilenameNode::get_fullpath // Access: Public -// Description: Returns a modifiable reference to the filename. +// Description: Returns the full pathname to the file, if it is +// known; otherwise, returns the same thing as +// get_filename(). +// +// This function simply returns whatever was set by the +// last call to set_fullpath(). This string is not +// written to the egg file; its main purpose is to +// record the full path to a filename (for instance, a +// texture filename) if it is known, for egg structures +// that are generated in-memory and then immediately +// converted to a scene graph. //////////////////////////////////////////////////////////////////// -INLINE Filename &EggFilenameNode:: -update_filename() { - return _filename; +INLINE const Filename &EggFilenameNode:: +get_fullpath() const { + return _fullpath; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggFilenameNode::set_fullpath +// Access: Public +// Description: Records the full pathname to the file, for the +// benefit of get_fullpath(). +//////////////////////////////////////////////////////////////////// +INLINE void EggFilenameNode:: +set_fullpath(const Filename &fullpath) { + _fullpath = fullpath; } diff --git a/panda/src/egg/eggFilenameNode.h b/panda/src/egg/eggFilenameNode.h index fa74ffdded..e7dba75f71 100644 --- a/panda/src/egg/eggFilenameNode.h +++ b/panda/src/egg/eggFilenameNode.h @@ -42,10 +42,13 @@ public: INLINE const Filename &get_filename() const; INLINE void set_filename(const Filename &filename); - INLINE Filename &update_filename(); + + INLINE const Filename &get_fullpath() const; + INLINE void set_fullpath(const Filename &fullpath); private: Filename _filename; + Filename _fullpath; public: static TypeHandle get_class_type() { diff --git a/panda/src/egg/eggGroupNode.cxx b/panda/src/egg/eggGroupNode.cxx index 61a5c10b67..44d8049e92 100644 --- a/panda/src/egg/eggGroupNode.cxx +++ b/panda/src/egg/eggGroupNode.cxx @@ -290,17 +290,21 @@ resolve_filenames(const DSearchPath &searchpath) { EggNode *child = *ci; if (child->is_of_type(EggTexture::get_class_type())) { EggTexture *tex = DCAST(EggTexture, child); - tex->update_filename(). - resolve_filename(searchpath, tex->get_default_extension()); - if (tex->has_alpha_file()) { - tex->update_alpha_file(). - resolve_filename(searchpath, tex->get_default_extension()); + Filename tex_filename = tex->get_filename(); + tex_filename.resolve_filename(searchpath); + tex->set_filename(tex_filename); + + if (tex->has_alpha_filename()) { + Filename alpha_filename = tex->get_alpha_filename(); + alpha_filename.resolve_filename(searchpath); + tex->set_alpha_filename(alpha_filename); } } else if (child->is_of_type(EggFilenameNode::get_class_type())) { EggFilenameNode *fnode = DCAST(EggFilenameNode, child); - fnode->update_filename(). - resolve_filename(searchpath, fnode->get_default_extension()); + Filename filename = fnode->get_filename(); + filename.resolve_filename(searchpath, fnode->get_default_extension()); + fnode->set_filename(filename); } else if (child->is_of_type(EggGroupNode::get_class_type())) { DCAST(EggGroupNode, child)->resolve_filenames(searchpath); diff --git a/panda/src/egg/eggTexture.I b/panda/src/egg/eggTexture.I index bc67f62113..c316fc762e 100644 --- a/panda/src/egg/eggTexture.I +++ b/panda/src/egg/eggTexture.I @@ -299,7 +299,7 @@ transform_is_identity() const { } //////////////////////////////////////////////////////////////////// -// Function: EggTexture::set_alpha_file +// Function: EggTexture::set_alpha_filename // Access: Public // Description: Specifies a separate file that will be loaded in with // the 1- or 3-component texture and applied as the @@ -308,60 +308,78 @@ transform_is_identity() const { // instance jpg. //////////////////////////////////////////////////////////////////// INLINE void EggTexture:: -set_alpha_file(const Filename &alpha_file) { - _alpha_file = alpha_file; - _flags |= F_has_alpha_file; +set_alpha_filename(const Filename &alpha_filename) { + _alpha_filename = alpha_filename; + _alpha_fullpath = alpha_filename; + _flags |= F_has_alpha_filename; } //////////////////////////////////////////////////////////////////// -// Function: EggTexture::clear_alpha_file +// Function: EggTexture::clear_alpha_filename // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE void EggTexture:: -clear_alpha_file() { - _alpha_file = Filename(); - _flags &= ~F_has_alpha_file; +clear_alpha_filename() { + _alpha_filename = Filename(); + _alpha_fullpath = Filename(); + _flags &= ~F_has_alpha_filename; } //////////////////////////////////////////////////////////////////// -// Function: EggTexture::has_alpha_file +// Function: EggTexture::has_alpha_filename // Access: Public // Description: Returns true if a separate file for the alpha // component has been applied, false otherwise. See -// set_alpha_file(). +// set_alpha_filename(). //////////////////////////////////////////////////////////////////// INLINE bool EggTexture:: -has_alpha_file() const { - return (_flags & F_has_alpha_file) != 0; +has_alpha_filename() const { + return (_flags & F_has_alpha_filename) != 0; } //////////////////////////////////////////////////////////////////// -// Function: EggTexture::get_alpha_file +// Function: EggTexture::get_alpha_filename // Access: Public // Description: Returns the separate file assigned for the alpha // channel. It is an error to call this unless -// has_alpha_file() returns true. See set_alpha_file(). +// has_alpha_filename() returns true. See set_alpha_filename(). //////////////////////////////////////////////////////////////////// INLINE const Filename &EggTexture:: -get_alpha_file() const { - nassertr(has_alpha_file(), _alpha_file); - return _alpha_file; +get_alpha_filename() const { + nassertr(has_alpha_filename(), _alpha_filename); + return _alpha_filename; } //////////////////////////////////////////////////////////////////// -// Function: EggTexture::update_alpha_file +// Function: EggTexture::get_alpha_fullpath // Access: Public -// Description: Returns a modifiable reference to the separate file -// assigned for the alpha channel. If an alpha file has -// not yet been added, this adds an empty one. +// Description: Returns the full pathname to the alpha file, if it is +// known; otherwise, returns the same thing as +// get_alpha_filename(). +// +// This function simply returns whatever was set by the +// last call to set_alpha_fullpath(). This string is +// not written to the egg file; its main purpose is to +// record the full path to the alpha filename if it is +// known, for egg structures that are generated +// in-memory and then immediately converted to a scene +// graph. //////////////////////////////////////////////////////////////////// -INLINE Filename &EggTexture:: -update_alpha_file() { - if (!has_alpha_file()) { - set_alpha_file(Filename()); - } - return _alpha_file; +INLINE const Filename &EggTexture:: +get_alpha_fullpath() const { + return _alpha_fullpath; +} + +//////////////////////////////////////////////////////////////////// +// Function: EggTexture::set_alpha_fullpath +// Access: Public +// Description: Records the full pathname to the file, for the +// benefit of get_alpha_fullpath(). +//////////////////////////////////////////////////////////////////// +INLINE void EggTexture:: +set_alpha_fullpath(const Filename &alpha_fullpath) { + _alpha_fullpath = alpha_fullpath; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggTexture.cxx b/panda/src/egg/eggTexture.cxx index b5d1e61b70..5a4867bb8f 100644 --- a/panda/src/egg/eggTexture.cxx +++ b/panda/src/egg/eggTexture.cxx @@ -77,7 +77,7 @@ operator = (const EggTexture ©) { _env_type = copy._env_type; _flags = copy._flags; _transform = copy._transform; - _alpha_file = copy._alpha_file; + _alpha_filename = copy._alpha_filename; return *this; } @@ -133,10 +133,10 @@ write(ostream &out, int indent_level) const { << " envtype { " << get_env_type() << " }\n"; } - if (has_alpha_file()) { + if (has_alpha_filename()) { indent(out, indent_level + 2) << " alpha-file { "; - enquote_string(out, get_alpha_file()); + enquote_string(out, get_alpha_filename()); out << " }\n"; } diff --git a/panda/src/egg/eggTexture.h b/panda/src/egg/eggTexture.h index cb66184bb5..0ca70ecd82 100644 --- a/panda/src/egg/eggTexture.h +++ b/panda/src/egg/eggTexture.h @@ -120,11 +120,13 @@ public: INLINE LMatrix3d get_transform() const; INLINE bool transform_is_identity() const; - INLINE void set_alpha_file(const Filename &filename); - INLINE void clear_alpha_file(); - INLINE bool has_alpha_file() const; - INLINE const Filename &get_alpha_file() const; - INLINE Filename &update_alpha_file(); + INLINE void set_alpha_filename(const Filename &filename); + INLINE void clear_alpha_filename(); + INLINE bool has_alpha_filename() const; + INLINE const Filename &get_alpha_filename() const; + + INLINE void set_alpha_fullpath(const Filename &fullpath); + INLINE const Filename &get_alpha_fullpath() const; static Format string_format(const string &string); static WrapMode string_wrap_mode(const string &string); @@ -137,7 +139,7 @@ protected: private: enum Flags { F_has_transform = 0x0001, - F_has_alpha_file = 0x0002, + F_has_alpha_filename = 0x0002, F_has_anisotropic_degree = 0x0004, }; @@ -148,7 +150,8 @@ private: EnvType _env_type; int _flags; LMatrix3d _transform; - Filename _alpha_file; + Filename _alpha_filename; + Filename _alpha_fullpath; public: diff --git a/panda/src/egg/parser.yxx b/panda/src/egg/parser.yxx index 9573df107a..15e2e1d8af 100644 --- a/panda/src/egg/parser.yxx +++ b/panda/src/egg/parser.yxx @@ -394,7 +394,7 @@ texture_body: texture->set_bin(strval); } else if (cmp_nocase_uh(name, "alpha_file") == 0) { - texture->set_alpha_file(strval); + texture->set_alpha_filename(strval); } else { eggyywarning("Unsupported texture scalar: " + name); diff --git a/panda/src/egg2pg/eggLoader.cxx b/panda/src/egg2pg/eggLoader.cxx index 12e2bcf53f..3d7f18e59d 100644 --- a/panda/src/egg2pg/eggLoader.cxx +++ b/panda/src/egg2pg/eggLoader.cxx @@ -477,16 +477,24 @@ load_textures() { bool EggLoader:: load_texture(TextureDef &def, const EggTexture *egg_tex) { Texture *tex; - if (egg_tex->has_alpha_file()) { - tex = TexturePool::load_texture(egg_tex->get_filename(), - egg_tex->get_alpha_file()); + if (egg_tex->has_alpha_filename()) { + tex = TexturePool::load_texture(egg_tex->get_fullpath(), + egg_tex->get_alpha_fullpath()); } else { - tex = TexturePool::load_texture(egg_tex->get_filename()); + tex = TexturePool::load_texture(egg_tex->get_fullpath()); } if (tex == (Texture *)NULL) { return false; } + // Record the original original filenames in the textures (as loaded + // from the egg file). These filenames will be written back to the + // bam file if the bam file is written out. + tex->set_filename(egg_tex->get_filename()); + if (egg_tex->has_alpha_filename()) { + tex->set_alpha_filename(egg_tex->get_alpha_filename()); + } + apply_texture_attributes(tex, egg_tex); CPT(RenderAttrib) apply = get_texture_apply_attributes(egg_tex); diff --git a/pandatool/src/bam/eggToBam.cxx b/pandatool/src/bam/eggToBam.cxx index fe5ac177c4..3c799925c3 100644 --- a/pandatool/src/bam/eggToBam.cxx +++ b/pandatool/src/bam/eggToBam.cxx @@ -86,6 +86,7 @@ EggToBam() : "one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'. The default " "is z-up."); + _force_complete = true; _egg_flatten = 0; } diff --git a/pandatool/src/egg-palettize/eggFile.h b/pandatool/src/egg-palettize/eggFile.h index 5e4b062eec..205d27f09c 100644 --- a/pandatool/src/egg-palettize/eggFile.h +++ b/pandatool/src/egg-palettize/eggFile.h @@ -19,14 +19,14 @@ #ifndef EGGFILE_H #define EGGFILE_H -#include +#include "pandatoolbase.h" #include "paletteGroups.h" #include "textureReference.h" -#include -#include -#include +#include "filename.h" +#include "namable.h" +#include "typedWritable.h" #include "pset.h" diff --git a/pandatool/src/egg-palettize/imageFile.cxx b/pandatool/src/egg-palettize/imageFile.cxx index b97014ce1e..ca08a74e29 100644 --- a/pandatool/src/egg-palettize/imageFile.cxx +++ b/pandatool/src/egg-palettize/imageFile.cxx @@ -387,9 +387,9 @@ update_egg_tex(EggTexture *egg_tex) const { if (_properties._alpha_type != (PNMFileType *)NULL && _properties.uses_alpha() && !_alpha_filename.empty()) { - egg_tex->set_alpha_file(FilenameUnifier::make_egg_filename(_alpha_filename)); + egg_tex->set_alpha_filename(FilenameUnifier::make_egg_filename(_alpha_filename)); } else { - egg_tex->clear_alpha_file(); + egg_tex->clear_alpha_filename(); } _properties.update_egg_tex(egg_tex); diff --git a/pandatool/src/egg-palettize/textureReference.cxx b/pandatool/src/egg-palettize/textureReference.cxx index 867ae30cf0..d75d0e1a74 100644 --- a/pandatool/src/egg-palettize/textureReference.cxx +++ b/pandatool/src/egg-palettize/textureReference.cxx @@ -97,8 +97,8 @@ from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex) { Filename filename = _egg_tex->get_filename(); Filename alpha_filename; - if (_egg_tex->has_alpha_file()) { - alpha_filename = _egg_tex->get_alpha_file(); + if (_egg_tex->has_alpha_filename()) { + alpha_filename = _egg_tex->get_alpha_filename(); } _properties._format = _egg_tex->get_format(); diff --git a/pandatool/src/eggbase/eggBase.cxx b/pandatool/src/eggbase/eggBase.cxx index b8671bc53b..e6e2fd5ce6 100644 --- a/pandatool/src/eggbase/eggBase.cxx +++ b/pandatool/src/eggbase/eggBase.cxx @@ -87,15 +87,26 @@ convert_paths(EggNode *node, PathReplace *path_replace, const DSearchPath &additional_path) { if (node->is_of_type(EggTexture::get_class_type())) { EggTexture *egg_tex = DCAST(EggTexture, node); - egg_tex->set_filename(path_replace->convert_path(egg_tex->get_filename(), - additional_path)); - if (egg_tex->has_alpha_file()) { - egg_tex->set_alpha_file(path_replace->convert_path(egg_tex->get_alpha_file(), additional_path)); + Filename fullpath = + path_replace->match_path(egg_tex->get_filename(), additional_path); + egg_tex->set_filename(path_replace->store_path(fullpath)); + egg_tex->set_fullpath(fullpath); + + if (egg_tex->has_alpha_filename()) { + Filename alpha_fullpath = + path_replace->match_path(egg_tex->get_alpha_filename(), additional_path); + egg_tex->set_alpha_filename(path_replace->store_path(alpha_fullpath)); + egg_tex->set_alpha_fullpath(alpha_fullpath); } } else if (node->is_of_type(EggFilenameNode::get_class_type())) { - EggFilenameNode *egg_fname = DCAST(EggFilenameNode, node); - egg_fname->set_filename(path_replace->convert_path(egg_fname->get_filename(), additional_path)); + EggFilenameNode *egg_fnode = DCAST(EggFilenameNode, node); + + Filename fullpath = + path_replace->match_path(egg_fnode->get_filename(), additional_path); + egg_fnode->set_filename(path_replace->store_path(fullpath)); + egg_fnode->set_fullpath(fullpath); + } else if (node->is_of_type(EggGroupNode::get_class_type())) { EggGroupNode *egg_group = DCAST(EggGroupNode, node); EggGroupNode::const_iterator ci; diff --git a/pandatool/src/eggbase/eggMultiBase.cxx b/pandatool/src/eggbase/eggMultiBase.cxx index 72750d2595..ea77f2400f 100644 --- a/pandatool/src/eggbase/eggMultiBase.cxx +++ b/pandatool/src/eggbase/eggMultiBase.cxx @@ -124,7 +124,12 @@ read_egg(const Filename &filename) { DSearchPath file_path; file_path.append_directory(filename.get_dirname()); - EggBase::convert_paths(data, _path_replace, file_path); + + // We always resolve filenames first based on the source egg + // filename, since egg files almost always store relative paths. + // This is a temporary kludge around integrating the path_replace + // system with the EggData better. + data->resolve_filenames(file_path); if (_force_complete) { if (!data->load_externals()) { @@ -132,6 +137,10 @@ read_egg(const Filename &filename) { } } + // Now resolve the filenames again according to the user's + // specified _path_replace. + EggBase::convert_paths(data, _path_replace, file_path); + if (_got_coordinate_system) { data->set_coordinate_system(_coordinate_system); } else { diff --git a/pandatool/src/eggbase/eggReader.cxx b/pandatool/src/eggbase/eggReader.cxx index 310740d085..ae12a0ebcb 100644 --- a/pandatool/src/eggbase/eggReader.cxx +++ b/pandatool/src/eggbase/eggReader.cxx @@ -176,7 +176,12 @@ handle_args(ProgramBase::Args &args) { DSearchPath file_path; file_path.append_directory(filename.get_dirname()); - convert_paths(&file_data, _path_replace, file_path); + + // We always resolve filenames first based on the source egg + // filename, since egg files almost always store relative paths. + // This is a temporary kludge around integrating the path_replace + // system with the EggData better. + file_data.resolve_filenames(file_path); if (_force_complete) { if (!file_data.load_externals()) { @@ -184,6 +189,10 @@ handle_args(ProgramBase::Args &args) { } } + // Now resolve the filenames again according to the user's + // specified _path_replace. + convert_paths(&file_data, _path_replace, file_path); + _data.merge(file_data); }