support egg2bam -pp properly

This commit is contained in:
David Rose 2003-02-25 01:13:30 +00:00
parent c55a23e9ea
commit 2fd799cf29
16 changed files with 162 additions and 74 deletions

View File

@ -321,21 +321,21 @@ $[TAB]touch $[pt]
#define source $[pal_egg_dir]/$[notdir $[egg]] #define source $[pal_egg_dir]/$[notdir $[egg]]
#define target $[bam_dir]/$[notdir $[egg:%.egg=%.bam]] #define target $[bam_dir]/$[notdir $[egg:%.egg=%.bam]]
$[target] : $[source] $[bam_dir]/stamp $[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 #end egg
#foreach egg $[UNPAL_SOURCES] #foreach egg $[UNPAL_SOURCES]
#define source $[source_prefix]$[egg] #define source $[source_prefix]$[egg]
#define target $[bam_dir]/$[notdir $[egg:%.egg=%.bam]] #define target $[bam_dir]/$[notdir $[egg:%.egg=%.bam]]
$[target] : $[source] $[bam_dir]/stamp $[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 #end egg
#foreach egg $[UNPAL_SOURCES_NC] #foreach egg $[UNPAL_SOURCES_NC]
#define source $[source_prefix]$[egg] #define source $[source_prefix]$[egg]
#define target $[bam_dir]/$[notdir $[egg:%.egg=%.bam]] #define target $[bam_dir]/$[notdir $[egg:%.egg=%.bam]]
$[target] : $[source] $[bam_dir]/stamp $[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 egg
#end install_egg #end install_egg

View File

@ -80,14 +80,36 @@ get_filename() const {
INLINE void EggFilenameNode:: INLINE void EggFilenameNode::
set_filename(const Filename &filename) { set_filename(const Filename &filename) {
_filename = filename; _filename = filename;
_fullpath = filename;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggFilenameNode::update_filename // Function: EggFilenameNode::get_fullpath
// Access: Public // 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:: INLINE const Filename &EggFilenameNode::
update_filename() { get_fullpath() const {
return _filename; 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;
} }

View File

@ -42,10 +42,13 @@ public:
INLINE const Filename &get_filename() const; INLINE const Filename &get_filename() const;
INLINE void set_filename(const Filename &filename); 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: private:
Filename _filename; Filename _filename;
Filename _fullpath;
public: public:
static TypeHandle get_class_type() { static TypeHandle get_class_type() {

View File

@ -290,17 +290,21 @@ resolve_filenames(const DSearchPath &searchpath) {
EggNode *child = *ci; EggNode *child = *ci;
if (child->is_of_type(EggTexture::get_class_type())) { if (child->is_of_type(EggTexture::get_class_type())) {
EggTexture *tex = DCAST(EggTexture, child); EggTexture *tex = DCAST(EggTexture, child);
tex->update_filename(). Filename tex_filename = tex->get_filename();
resolve_filename(searchpath, tex->get_default_extension()); tex_filename.resolve_filename(searchpath);
if (tex->has_alpha_file()) { tex->set_filename(tex_filename);
tex->update_alpha_file().
resolve_filename(searchpath, tex->get_default_extension()); 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())) { } else if (child->is_of_type(EggFilenameNode::get_class_type())) {
EggFilenameNode *fnode = DCAST(EggFilenameNode, child); EggFilenameNode *fnode = DCAST(EggFilenameNode, child);
fnode->update_filename(). Filename filename = fnode->get_filename();
resolve_filename(searchpath, fnode->get_default_extension()); filename.resolve_filename(searchpath, fnode->get_default_extension());
fnode->set_filename(filename);
} else if (child->is_of_type(EggGroupNode::get_class_type())) { } else if (child->is_of_type(EggGroupNode::get_class_type())) {
DCAST(EggGroupNode, child)->resolve_filenames(searchpath); DCAST(EggGroupNode, child)->resolve_filenames(searchpath);

View File

@ -299,7 +299,7 @@ transform_is_identity() const {
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTexture::set_alpha_file // Function: EggTexture::set_alpha_filename
// Access: Public // Access: Public
// Description: Specifies a separate file that will be loaded in with // Description: Specifies a separate file that will be loaded in with
// the 1- or 3-component texture and applied as the // the 1- or 3-component texture and applied as the
@ -308,60 +308,78 @@ transform_is_identity() const {
// instance jpg. // instance jpg.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void EggTexture:: INLINE void EggTexture::
set_alpha_file(const Filename &alpha_file) { set_alpha_filename(const Filename &alpha_filename) {
_alpha_file = alpha_file; _alpha_filename = alpha_filename;
_flags |= F_has_alpha_file; _alpha_fullpath = alpha_filename;
_flags |= F_has_alpha_filename;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTexture::clear_alpha_file // Function: EggTexture::clear_alpha_filename
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void EggTexture:: INLINE void EggTexture::
clear_alpha_file() { clear_alpha_filename() {
_alpha_file = Filename(); _alpha_filename = Filename();
_flags &= ~F_has_alpha_file; _alpha_fullpath = Filename();
_flags &= ~F_has_alpha_filename;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTexture::has_alpha_file // Function: EggTexture::has_alpha_filename
// Access: Public // Access: Public
// Description: Returns true if a separate file for the alpha // Description: Returns true if a separate file for the alpha
// component has been applied, false otherwise. See // component has been applied, false otherwise. See
// set_alpha_file(). // set_alpha_filename().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool EggTexture:: INLINE bool EggTexture::
has_alpha_file() const { has_alpha_filename() const {
return (_flags & F_has_alpha_file) != 0; return (_flags & F_has_alpha_filename) != 0;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTexture::get_alpha_file // Function: EggTexture::get_alpha_filename
// Access: Public // Access: Public
// Description: Returns the separate file assigned for the alpha // Description: Returns the separate file assigned for the alpha
// channel. It is an error to call this unless // 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:: INLINE const Filename &EggTexture::
get_alpha_file() const { get_alpha_filename() const {
nassertr(has_alpha_file(), _alpha_file); nassertr(has_alpha_filename(), _alpha_filename);
return _alpha_file; return _alpha_filename;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggTexture::update_alpha_file // Function: EggTexture::get_alpha_fullpath
// Access: Public // Access: Public
// Description: Returns a modifiable reference to the separate file // Description: Returns the full pathname to the alpha file, if it is
// assigned for the alpha channel. If an alpha file has // known; otherwise, returns the same thing as
// not yet been added, this adds an empty one. // 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:: INLINE const Filename &EggTexture::
update_alpha_file() { get_alpha_fullpath() const {
if (!has_alpha_file()) { return _alpha_fullpath;
set_alpha_file(Filename()); }
}
return _alpha_file; ////////////////////////////////////////////////////////////////////
// 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;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -77,7 +77,7 @@ operator = (const EggTexture &copy) {
_env_type = copy._env_type; _env_type = copy._env_type;
_flags = copy._flags; _flags = copy._flags;
_transform = copy._transform; _transform = copy._transform;
_alpha_file = copy._alpha_file; _alpha_filename = copy._alpha_filename;
return *this; return *this;
} }
@ -133,10 +133,10 @@ write(ostream &out, int indent_level) const {
<< "<Scalar> envtype { " << get_env_type() << " }\n"; << "<Scalar> envtype { " << get_env_type() << " }\n";
} }
if (has_alpha_file()) { if (has_alpha_filename()) {
indent(out, indent_level + 2) indent(out, indent_level + 2)
<< "<Scalar> alpha-file { "; << "<Scalar> alpha-file { ";
enquote_string(out, get_alpha_file()); enquote_string(out, get_alpha_filename());
out << " }\n"; out << " }\n";
} }

View File

@ -120,11 +120,13 @@ public:
INLINE LMatrix3d get_transform() const; INLINE LMatrix3d get_transform() const;
INLINE bool transform_is_identity() const; INLINE bool transform_is_identity() const;
INLINE void set_alpha_file(const Filename &filename); INLINE void set_alpha_filename(const Filename &filename);
INLINE void clear_alpha_file(); INLINE void clear_alpha_filename();
INLINE bool has_alpha_file() const; INLINE bool has_alpha_filename() const;
INLINE const Filename &get_alpha_file() const; INLINE const Filename &get_alpha_filename() const;
INLINE Filename &update_alpha_file();
INLINE void set_alpha_fullpath(const Filename &fullpath);
INLINE const Filename &get_alpha_fullpath() const;
static Format string_format(const string &string); static Format string_format(const string &string);
static WrapMode string_wrap_mode(const string &string); static WrapMode string_wrap_mode(const string &string);
@ -137,7 +139,7 @@ protected:
private: private:
enum Flags { enum Flags {
F_has_transform = 0x0001, F_has_transform = 0x0001,
F_has_alpha_file = 0x0002, F_has_alpha_filename = 0x0002,
F_has_anisotropic_degree = 0x0004, F_has_anisotropic_degree = 0x0004,
}; };
@ -148,7 +150,8 @@ private:
EnvType _env_type; EnvType _env_type;
int _flags; int _flags;
LMatrix3d _transform; LMatrix3d _transform;
Filename _alpha_file; Filename _alpha_filename;
Filename _alpha_fullpath;
public: public:

View File

@ -394,7 +394,7 @@ texture_body:
texture->set_bin(strval); texture->set_bin(strval);
} else if (cmp_nocase_uh(name, "alpha_file") == 0) { } else if (cmp_nocase_uh(name, "alpha_file") == 0) {
texture->set_alpha_file(strval); texture->set_alpha_filename(strval);
} else { } else {
eggyywarning("Unsupported texture scalar: " + name); eggyywarning("Unsupported texture scalar: " + name);

View File

@ -477,16 +477,24 @@ load_textures() {
bool EggLoader:: bool EggLoader::
load_texture(TextureDef &def, const EggTexture *egg_tex) { load_texture(TextureDef &def, const EggTexture *egg_tex) {
Texture *tex; Texture *tex;
if (egg_tex->has_alpha_file()) { if (egg_tex->has_alpha_filename()) {
tex = TexturePool::load_texture(egg_tex->get_filename(), tex = TexturePool::load_texture(egg_tex->get_fullpath(),
egg_tex->get_alpha_file()); egg_tex->get_alpha_fullpath());
} else { } else {
tex = TexturePool::load_texture(egg_tex->get_filename()); tex = TexturePool::load_texture(egg_tex->get_fullpath());
} }
if (tex == (Texture *)NULL) { if (tex == (Texture *)NULL) {
return false; 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); apply_texture_attributes(tex, egg_tex);
CPT(RenderAttrib) apply = get_texture_apply_attributes(egg_tex); CPT(RenderAttrib) apply = get_texture_apply_attributes(egg_tex);

View File

@ -86,6 +86,7 @@ EggToBam() :
"one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'. The default " "one of 'y-up', 'z-up', 'y-up-left', or 'z-up-left'. The default "
"is z-up."); "is z-up.");
_force_complete = true;
_egg_flatten = 0; _egg_flatten = 0;
} }

View File

@ -19,14 +19,14 @@
#ifndef EGGFILE_H #ifndef EGGFILE_H
#define EGGFILE_H #define EGGFILE_H
#include <pandatoolbase.h> #include "pandatoolbase.h"
#include "paletteGroups.h" #include "paletteGroups.h"
#include "textureReference.h" #include "textureReference.h"
#include <filename.h> #include "filename.h"
#include <namable.h> #include "namable.h"
#include <typedWritable.h> #include "typedWritable.h"
#include "pset.h" #include "pset.h"

View File

@ -387,9 +387,9 @@ update_egg_tex(EggTexture *egg_tex) const {
if (_properties._alpha_type != (PNMFileType *)NULL && if (_properties._alpha_type != (PNMFileType *)NULL &&
_properties.uses_alpha() && _properties.uses_alpha() &&
!_alpha_filename.empty()) { !_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 { } else {
egg_tex->clear_alpha_file(); egg_tex->clear_alpha_filename();
} }
_properties.update_egg_tex(egg_tex); _properties.update_egg_tex(egg_tex);

View File

@ -97,8 +97,8 @@ from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex) {
Filename filename = _egg_tex->get_filename(); Filename filename = _egg_tex->get_filename();
Filename alpha_filename; Filename alpha_filename;
if (_egg_tex->has_alpha_file()) { if (_egg_tex->has_alpha_filename()) {
alpha_filename = _egg_tex->get_alpha_file(); alpha_filename = _egg_tex->get_alpha_filename();
} }
_properties._format = _egg_tex->get_format(); _properties._format = _egg_tex->get_format();

View File

@ -87,15 +87,26 @@ convert_paths(EggNode *node, PathReplace *path_replace,
const DSearchPath &additional_path) { const DSearchPath &additional_path) {
if (node->is_of_type(EggTexture::get_class_type())) { if (node->is_of_type(EggTexture::get_class_type())) {
EggTexture *egg_tex = DCAST(EggTexture, node); EggTexture *egg_tex = DCAST(EggTexture, node);
egg_tex->set_filename(path_replace->convert_path(egg_tex->get_filename(), Filename fullpath =
additional_path)); path_replace->match_path(egg_tex->get_filename(), additional_path);
if (egg_tex->has_alpha_file()) { egg_tex->set_filename(path_replace->store_path(fullpath));
egg_tex->set_alpha_file(path_replace->convert_path(egg_tex->get_alpha_file(), additional_path)); 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())) { } else if (node->is_of_type(EggFilenameNode::get_class_type())) {
EggFilenameNode *egg_fname = DCAST(EggFilenameNode, node); EggFilenameNode *egg_fnode = DCAST(EggFilenameNode, node);
egg_fname->set_filename(path_replace->convert_path(egg_fname->get_filename(), additional_path));
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())) { } else if (node->is_of_type(EggGroupNode::get_class_type())) {
EggGroupNode *egg_group = DCAST(EggGroupNode, node); EggGroupNode *egg_group = DCAST(EggGroupNode, node);
EggGroupNode::const_iterator ci; EggGroupNode::const_iterator ci;

View File

@ -124,7 +124,12 @@ read_egg(const Filename &filename) {
DSearchPath file_path; DSearchPath file_path;
file_path.append_directory(filename.get_dirname()); 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 (_force_complete) {
if (!data->load_externals()) { 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) { if (_got_coordinate_system) {
data->set_coordinate_system(_coordinate_system); data->set_coordinate_system(_coordinate_system);
} else { } else {

View File

@ -176,7 +176,12 @@ handle_args(ProgramBase::Args &args) {
DSearchPath file_path; DSearchPath file_path;
file_path.append_directory(filename.get_dirname()); 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 (_force_complete) {
if (!file_data.load_externals()) { 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); _data.merge(file_data);
} }