瀏覽代碼

support egg2bam -pp properly

David Rose 23 年之前
父節點
當前提交
2fd799cf29

+ 3 - 3
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
 

+ 27 - 5
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;
 }

+ 4 - 1
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() {

+ 11 - 7
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);

+ 45 - 27
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 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 Filename &EggTexture::
-update_alpha_file() {
-  if (!has_alpha_file()) {
-    set_alpha_file(Filename());
-  }
-  return _alpha_file;
+INLINE void EggTexture::
+set_alpha_fullpath(const Filename &alpha_fullpath) {
+  _alpha_fullpath = alpha_fullpath;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 3 - 3
panda/src/egg/eggTexture.cxx

@@ -77,7 +77,7 @@ operator = (const EggTexture &copy) {
   _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 {
       << "<Scalar> envtype { " << get_env_type() << " }\n";
   }
 
-  if (has_alpha_file()) {
+  if (has_alpha_filename()) {
     indent(out, indent_level + 2)
       << "<Scalar> alpha-file { ";
-    enquote_string(out, get_alpha_file());
+    enquote_string(out, get_alpha_filename());
     out << " }\n";
   }
 

+ 10 - 7
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:

+ 1 - 1
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);

+ 12 - 4
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);
 

+ 1 - 0
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;
 }
 

+ 4 - 4
pandatool/src/egg-palettize/eggFile.h

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

+ 2 - 2
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);

+ 2 - 2
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();

+ 17 - 6
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;

+ 10 - 1
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 {

+ 10 - 1
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);
   }