Browse Source

fix problem with -copytex in conjunction with -pr

David Rose 14 years ago
parent
commit
a9862a4450

+ 15 - 18
pandatool/src/maya/mayaShader.cxx

@@ -40,7 +40,7 @@
 //               relevant shader properties.
 ////////////////////////////////////////////////////////////////////
 MayaShader::
-MayaShader(MObject engine, bool texture_copy, Filename tout_dir, bool legacy_shader) {
+MayaShader(MObject engine, bool legacy_shader) {
   MFnDependencyNode engine_fn(engine);
 
   set_name(engine_fn.name().asChar());
@@ -49,9 +49,6 @@ MayaShader(MObject engine, bool texture_copy, Filename tout_dir, bool legacy_sha
     maya_cat.debug()
       << "Reading shading engine " << get_name() << "\n";
   }
-  // passing the output texture dir to the shader constructor
-  _texture_copy = texture_copy;
-  _texture_out_dir = tout_dir;
   _legacy_mode = false;
   _flat_color.set(1,1,1,1);
 
@@ -228,29 +225,29 @@ find_textures_modern(MObject shader) {
 
   string n = shader_fn.name().asChar();
   
-  MayaShaderColorDef::find_textures_modern(n, _color_maps,  shader_fn.findPlug("color"), _texture_copy, _texture_out_dir,false);
+  MayaShaderColorDef::find_textures_modern(n, _color_maps,  shader_fn.findPlug("color"), false);
   if (_color_maps.size() == 0) {
-    MayaShaderColorDef::find_textures_modern(n, _color_maps,  shader_fn.findPlug("colorR"),_texture_copy, _texture_out_dir, false);
+    MayaShaderColorDef::find_textures_modern(n, _color_maps,  shader_fn.findPlug("colorR"), false);
   }
-  MayaShaderColorDef::find_textures_modern(n, _trans_maps,  shader_fn.findPlug("transparency"),_texture_copy, _texture_out_dir, true);
+  MayaShaderColorDef::find_textures_modern(n, _trans_maps,  shader_fn.findPlug("transparency"), true);
   if (_trans_maps.size() == 0) {
-    MayaShaderColorDef::find_textures_modern(n, _trans_maps,  shader_fn.findPlug("transparencyR"),_texture_copy, _texture_out_dir, true);
+    MayaShaderColorDef::find_textures_modern(n, _trans_maps,  shader_fn.findPlug("transparencyR"), true);
   }
-  MayaShaderColorDef::find_textures_modern(n, _normal_maps, shader_fn.findPlug("normalCamera"),_texture_copy, _texture_out_dir, false);
+  MayaShaderColorDef::find_textures_modern(n, _normal_maps, shader_fn.findPlug("normalCamera"), false);
   if (_normal_maps.size() == 0) {
-    MayaShaderColorDef::find_textures_modern(n, _normal_maps, shader_fn.findPlug("normalCameraR"),_texture_copy, _texture_out_dir, false);
+    MayaShaderColorDef::find_textures_modern(n, _normal_maps, shader_fn.findPlug("normalCameraR"), false);
   }
-  MayaShaderColorDef::find_textures_modern(n, _gloss_maps,  shader_fn.findPlug("specularColor"),_texture_copy, _texture_out_dir, true);
+  MayaShaderColorDef::find_textures_modern(n, _gloss_maps,  shader_fn.findPlug("specularColor"), true);
   if (_gloss_maps.size() == 0) {
-    MayaShaderColorDef::find_textures_modern(n, _gloss_maps,  shader_fn.findPlug("specularColorR"),_texture_copy, _texture_out_dir, true);
+    MayaShaderColorDef::find_textures_modern(n, _gloss_maps,  shader_fn.findPlug("specularColorR"), true);
   }
-  MayaShaderColorDef::find_textures_modern(n, _glow_maps,  shader_fn.findPlug("incandescence"),_texture_copy, _texture_out_dir, true);
+  MayaShaderColorDef::find_textures_modern(n, _glow_maps,  shader_fn.findPlug("incandescence"), true);
   if (_glow_maps.size() == 0) {
-    MayaShaderColorDef::find_textures_modern(n, _glow_maps,  shader_fn.findPlug("incandescenceR"),_texture_copy, _texture_out_dir, true);
+    MayaShaderColorDef::find_textures_modern(n, _glow_maps,  shader_fn.findPlug("incandescenceR"), true);
   }
-  MayaShaderColorDef::find_textures_modern(n, _height_maps,  shader_fn.findPlug("surfaceThickness"),_texture_copy, _texture_out_dir, true);
+  MayaShaderColorDef::find_textures_modern(n, _height_maps,  shader_fn.findPlug("surfaceThickness"), true);
   if (_height_maps.size() == 0) {
-    MayaShaderColorDef::find_textures_modern(n, _height_maps,  shader_fn.findPlug("surfaceThicknessR"),_texture_copy, _texture_out_dir, true);
+    MayaShaderColorDef::find_textures_modern(n, _height_maps,  shader_fn.findPlug("surfaceThicknessR"), true);
   }
   
   collect_maps();
@@ -484,7 +481,7 @@ find_textures_legacy(MObject shader) {
     MayaShaderColorDef *color_p = new MayaShaderColorDef;
     for (size_t i = 0; i < color_pa.length(); i++) {
       maya_cat.spam() << "color_pa[" << i << "]:" << color_pa[i].name().asChar() << endl;
-      color_p->find_textures_legacy(this, color_pa[0].node(), _texture_copy, _texture_out_dir);
+      color_p->find_textures_legacy(this, color_pa[0].node());
     }
 
     if (color_pa.length() < 1) {
@@ -506,7 +503,7 @@ find_textures_legacy(MObject shader) {
 
     for (size_t i = 0; i < trans_pa.length(); i++) {
       maya_cat.spam() << "read a transparency texture" << endl;
-      _transparency.find_textures_legacy(this, trans_pa[0].node(), _texture_copy, _texture_out_dir, true);
+      _transparency.find_textures_legacy(this, trans_pa[0].node(), true);
     }
   }
 

+ 1 - 3
pandatool/src/maya/mayaShader.h

@@ -34,7 +34,7 @@ class MObject;
 ////////////////////////////////////////////////////////////////////
 class MayaShader : public Namable {
 public:
-  MayaShader(MObject engine, bool texture_copy, Filename tout_dir, bool legacy_shader);
+  MayaShader(MObject engine, bool legacy_shader);
   ~MayaShader();
 
   void output(ostream &out) const;
@@ -69,8 +69,6 @@ private:
                 MayaShaderColorDef *map2,
                 bool perfect);
   string get_file_prefix(const string &fn);
-  bool _texture_copy;
-  Filename _texture_out_dir;
   bool _legacy_shader;
 public: // relevant only to legacy mode.
   MayaShaderColorList _color;

+ 8 - 43
pandatool/src/maya/mayaShaderColorDef.cxx

@@ -266,7 +266,7 @@ get_panda_uvset_name() {
 //               properties.
 ////////////////////////////////////////////////////////////////////
 void MayaShaderColorDef::
-find_textures_legacy(MayaShader *shader, MObject color, bool _texture_copy, Filename _texture_out_dir, bool trans) {
+find_textures_legacy(MayaShader *shader, MObject color, bool trans) {
   LRGBColor color_gain;
   if (get_vec3_attribute(color, "colorGain", color_gain)) {
     color_gain[0] = color_gain[0] > 1.0 ? 1.0 : color_gain[0];
@@ -302,23 +302,6 @@ find_textures_legacy(MayaShader *shader, MObject color, bool _texture_copy, File
         _has_texture = false;
         set_string_attribute(color, "fileTextureName", "");
       }
-      // create directory, copy texture, modify texture filename
-      if (_texture_copy) {
-        if (_texture_out_dir[_texture_out_dir.length()-1] != '/')
-          _texture_out_dir+="/";
-        _texture_out_dir.make_dir();
-        Filename texture_copy_filename=Filename(_texture_out_dir, _texture_filename.get_basename());
-        if (_texture_filename.copy_to(texture_copy_filename)) {       
-          _texture_filename=texture_copy_filename;
-        }
-        else {
-          maya_cat.warning()
-              <<"unable to copy texture files from "<<_texture_filename.get_dirname()
-              <<" to "<<_texture_out_dir<<"\n"
-              <<"make sure you have the access right to the assigned directory\n"
-              <<"the output egg file will adapt to the original texture files' path\n";
-        }
-      }
     }
 
     get_vec2_attribute(color, "coverage", _coverage);
@@ -356,7 +339,7 @@ find_textures_legacy(MayaShader *shader, MObject color, bool _texture_copy, File
       image_plug.connectedTo(image_pa, true, false);
       
       for (size_t i = 0; i < image_pa.length(); i++) {
-        find_textures_legacy(shader, image_pa[0].node(), _texture_copy, _texture_out_dir);
+        find_textures_legacy(shader, image_pa[0].node());
       }
     }
 
@@ -463,7 +446,7 @@ find_textures_legacy(MayaShader *shader, MObject color, bool _texture_copy, File
             maya_cat.debug() << pl.name().asChar() << " next:connectedTo: " << pla_name << endl;
           }
           MayaShaderColorDef *color_p = new MayaShaderColorDef;
-          color_p->find_textures_legacy(shader, pla[j].node(), _texture_copy, _texture_out_dir);
+          color_p->find_textures_legacy(shader, pla[j].node());
           color_p->_blend_type = bt;
           size_t loc = color_p->_texture_name.find('.',0);
           if (loc != string::npos) {
@@ -477,7 +460,7 @@ find_textures_legacy(MayaShader *shader, MObject color, bool _texture_copy, File
           if (maya_cat.is_debug()) {
             maya_cat.debug() << pl.name().asChar() << " first:connectedTo: " << pla_name << endl;
           }
-          find_textures_legacy(shader, pla[j].node(), _texture_copy, _texture_out_dir);
+          find_textures_legacy(shader, pla[j].node());
           _texture_name.assign(pla[j].name().asChar());
           _blend_type = bt;
           size_t loc = _texture_name.find('.',0);
@@ -519,7 +502,7 @@ find_textures_legacy(MayaShader *shader, MObject color, bool _texture_copy, File
 //               to the provided MayaShaderColorList.
 ////////////////////////////////////////////////////////////////////
 void MayaShaderColorDef::
-find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug inplug,bool _texture_copy, Filename _texture_out_dir, bool is_alpha) {
+find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug inplug, bool is_alpha) {
 
   MPlugArray outplugs;
   inplug.connectedTo(outplugs, true, false);
@@ -558,24 +541,6 @@ find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug
     
     def->_color_object = new MObject(source);
     def->_texture_filename = Filename::from_os_specific(filename);
-    // create directory, copy texture, modify texture filename
-    if (_texture_copy) {
-      if (_texture_out_dir[_texture_out_dir.length()-1] != '/') {
-        _texture_out_dir+="/";
-	  }	
-      _texture_out_dir.make_dir();
-      Filename texture_copy_filename=Filename(_texture_out_dir, def->_texture_filename.get_basename());
-      if (def->_texture_filename.copy_to(texture_copy_filename)) {       
-        def->_texture_filename=texture_copy_filename;
-      }
-      else {
-        maya_cat.warning()
-          <<"unable to copy texture files from "<<def->_texture_filename.get_dirname()
-          <<" to "<<_texture_out_dir<<"\n"
-          <<"make sure you have the access right to the assigned directory\n"
-          <<"the output egg file will adapt to the original texture files' path\n";
-      }
-    }
     def->_texture_name = sourceFn.name().asChar();
 
     get_vec2_attribute(source, "coverage",       def->_coverage);
@@ -620,7 +585,7 @@ find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug
       image_plug.connectedTo(image_pa, true, false);
       
       for (size_t i = 0; i < image_pa.length(); i++) {
-        find_textures_modern(shadername, list, image_pa[0], _texture_copy, _texture_out_dir, is_alpha);
+        find_textures_modern(shadername, list, image_pa[0], is_alpha);
       }
     }
     
@@ -672,7 +637,7 @@ find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug
         return;
       }
       size_t before = list.size();
-      find_textures_modern(shadername, list, color, _texture_copy, _texture_out_dir, is_alpha);
+      find_textures_modern(shadername, list, color, is_alpha);
       int blendValue;
       blend.getValue(blendValue);
       for (size_t sub=before; sub<list.size(); sub++) {
@@ -689,7 +654,7 @@ find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug
 
   if (source.apiType() == MFn::kReverse) {
     MPlug input_plug = sourceFn.findPlug("input");
-    find_textures_modern(shadername, list, input_plug, _texture_copy, _texture_out_dir, is_alpha);
+    find_textures_modern(shadername, list, input_plug, is_alpha);
     return;
   }
   

+ 2 - 2
pandatool/src/maya/mayaShaderColorDef.h

@@ -114,8 +114,8 @@ private:
   MObject *_color_object;
   
 private:
-  static void find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug inplug, bool _texture_copy, Filename tout_dir, bool is_alpha);
-  void find_textures_legacy(MayaShader *shader, MObject color, bool _texture_copy, Filename tout_dir, bool trans=false);
+  static void find_textures_modern(const string &shadername, MayaShaderColorList &list, MPlug inplug, bool is_alpha);
+  void find_textures_legacy(MayaShader *shader, MObject color, bool trans=false);
 
   void set_projection_type(const string &type);
 

+ 4 - 9
pandatool/src/maya/mayaShaders.cxx

@@ -1,8 +1,5 @@
 // Filename: mayaShaders.cxx
 // Created by:  drose (11Feb00)
-// Modified 19Mar10 by ETC PandaSE team (add a 
-//   texture copy flag in shader -- see
-//   header comment for mayaToEgg.cxx for details)
 //
 ////////////////////////////////////////////////////////////////////
 //
@@ -56,7 +53,7 @@ MayaShaders::
 //  Description: Extracts the shader assigned to the indicated node.
 ////////////////////////////////////////////////////////////////////
 MayaShader *MayaShaders::
-find_shader_for_node(MObject node, bool _texture_copy, Filename _tout_dir, bool _legacy_shader) {
+find_shader_for_node(MObject node, bool legacy_shader) {
   MStatus status;
   MFnDependencyNode node_fn(node);
   // Look on the instObjGroups attribute for shading engines.
@@ -90,8 +87,7 @@ find_shader_for_node(MObject node, bool _texture_copy, Filename _tout_dir, bool
   for (i = 0; i < iog_pa.length(); i++) {
     MObject engine = iog_pa[i].node();
     if (engine.hasFn(MFn::kShadingEngine)) {
-      // add the texture copy flag here
-      return find_shader_for_shading_engine(engine, _texture_copy, _tout_dir, _legacy_shader);
+      return find_shader_for_shading_engine(engine, legacy_shader);
     }
   }
 
@@ -145,7 +141,7 @@ bind_uvsets(MObject mesh) {
 //               encountered the indicated engine.
 ////////////////////////////////////////////////////////////////////
 MayaShader *MayaShaders::
-find_shader_for_shading_engine(MObject engine, bool _texture_copy, Filename _tout_dir, bool _legacy_shader) {
+find_shader_for_shading_engine(MObject engine, bool legacy_shader) {
   MFnDependencyNode engine_fn(engine);
   // See if we have already decoded this engine.
   string engine_name = engine_fn.name().asChar();
@@ -156,8 +152,7 @@ find_shader_for_shading_engine(MObject engine, bool _texture_copy, Filename _tou
 
   // All right, this is a newly encountered shading engine.  Create a
   // new MayaShader object to represent it.
-  // adding texture flag as parameter
-  MayaShader *shader = new MayaShader(engine, _texture_copy, _tout_dir, _legacy_shader);
+  MayaShader *shader = new MayaShader(engine, legacy_shader);
   shader->bind_uvsets(_file_to_uvset);
   
   // Record this for the future.

+ 2 - 2
pandatool/src/maya/mayaShaders.h

@@ -33,8 +33,8 @@ class MayaShaders {
 public:
   MayaShaders();
   ~MayaShaders();
-  MayaShader *find_shader_for_node(MObject node, bool _texture_copy, Filename _tout_dir, bool _legacy_shader);
-  MayaShader *find_shader_for_shading_engine(MObject engine, bool _texture_copy, Filename _tout_dir, bool _legacy_shader);
+  MayaShader *find_shader_for_node(MObject node, bool legacy_shader);
+  MayaShader *find_shader_for_shading_engine(MObject engine, bool legacy_shader);
   
   int get_num_shaders() const;
   MayaShader *get_shader(int n) const;

+ 3 - 8
pandatool/src/mayaegg/mayaToEggConverter.cxx

@@ -100,7 +100,6 @@ MayaToEggConverter(const string &program_name) :
   _always_show_vertex_color = maya_default_vertex_color;
   _keep_all_uvsets = false;
   _round_uvs = false;
-  _texture_copy = false;
   _legacy_shader = false;
 
   _transform_type = TT_model;
@@ -128,7 +127,6 @@ MayaToEggConverter(const MayaToEggConverter &copy) :
   _always_show_vertex_color(copy._always_show_vertex_color),
   _keep_all_uvsets(copy._keep_all_uvsets),
   _round_uvs(copy._round_uvs),
-  _texture_copy(copy._texture_copy),
   _legacy_shader(copy._legacy_shader),
   _transform_type(copy._transform_type)
 {
@@ -833,9 +831,6 @@ convert_hierarchy(EggGroupNode *egg_root) {
     mayaegg_cat.info() << "will keep_all_uvsets" << endl;
   }
   // give some feedback about whether special options are on
-  if (_texture_copy) {
-    mayaegg_cat.info() << "will copy textures to" <<_texture_out_dir<< endl;
-  }
   if (_legacy_shader) {
     mayaegg_cat.info() << "will disable modern Phong shader path. using legacy" << endl;
   }
@@ -1279,7 +1274,7 @@ make_nurbs_surface(MayaNodeDesc *node_desc, const MDagPath &dag_path,
       << surface.numSpansInV()
       << "\n";
   }
-  MayaShader *shader = _shaders.find_shader_for_node(surface.object(), _texture_copy, _texture_out_dir, _legacy_shader);
+  MayaShader *shader = _shaders.find_shader_for_node(surface.object(), _legacy_shader);
 
   if (_polygon_output) {
     // If we want polygon output only, tesselate the NURBS and output
@@ -1728,7 +1723,7 @@ make_nurbs_curve(const MDagPath &, const MFnNurbsCurve &curve,
       egg_curve->add_vertex(vpool->create_unique_vertex(vert));
     }
   }
-  MayaShader *shader = _shaders.find_shader_for_node(curve.object(), _texture_copy, _texture_out_dir, _legacy_shader);
+  MayaShader *shader = _shaders.find_shader_for_node(curve.object(), _legacy_shader);
   if (shader != (MayaShader *)NULL) {
     set_shader_attributes(*egg_curve, *shader);
   }
@@ -1870,7 +1865,7 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path,
       nassertv(shader_index >= 0 && shader_index < (int)shaders.length());
       MObject engine = shaders[shader_index];
       shader =
-        _shaders.find_shader_for_shading_engine(engine, _texture_copy, _texture_out_dir, _legacy_shader); //head out to the other classes
+        _shaders.find_shader_for_shading_engine(engine, _legacy_shader); //head out to the other classes
       //does this mean if we didn't find a Maya shader give it a default value anyway?
     } else if (default_shader != (MayaShader *)NULL) { 
       shader = default_shader;

+ 0 - 2
pandatool/src/mayaegg/mayaToEggConverter.h

@@ -192,8 +192,6 @@ public:
   bool _always_show_vertex_color;
   bool _keep_all_uvsets;
   bool _round_uvs;
-  bool _texture_copy;
-  Filename _texture_out_dir;
   bool _legacy_shader;
 
 

+ 2 - 4
pandatool/src/mayaprogs/mayaCopy.cxx

@@ -434,8 +434,7 @@ collect_shader_for_node(const MDagPath &dag_path) {
   if (dag_path.hasFn(MFn::kNurbsSurface)) {
     MFnNurbsSurface surface(dag_path, &status);
     if (status) {
-      Filename dummy;
-      _shaders.find_shader_for_node(surface.object(),false,dummy,false);
+      _shaders.find_shader_for_node(surface.object(), false);
     }
 
   } else if (dag_path.hasFn(MFn::kMesh)) {
@@ -453,8 +452,7 @@ collect_shader_for_node(const MDagPath &dag_path) {
              shader_index < num_shaders; 
              shader_index++) {
           MObject engine = shaders[shader_index];
-          Filename dummy;
-          _shaders.find_shader_for_shading_engine(engine,false,dummy,false);
+          _shaders.find_shader_for_shading_engine(engine, false);
         }
       }
     }

+ 9 - 11
pandatool/src/mayaprogs/mayaToEgg.cxx

@@ -115,10 +115,9 @@ MayaToEgg() :
      &MayaToEgg::dispatch_none, &_round_uvs);
 
   add_option
-    ("copytex","dir",0,
-    "copy the textures to a ""Textures"" sub directory relative to the written out egg file."
-    """dir"" is a sub directory in the same format as those used by -pr, etc." ,
-     &MayaToEgg::dispatch_filename, &_texture_copy, &_texture_out_dir);
+    ("copytex", "dir", 41,
+     "Legacy option.  Same as -pc.",
+     &MayaToEgg::dispatch_filename, &_legacy_copytex, &_legacy_copytex_dir);
 
   add_option
     ("trans", "type", 0,
@@ -215,16 +214,17 @@ run() {
     mayaegg_cat->set_severity(NS_info);
   }
 
+  if (_legacy_copytex && !_path_replace->_copy_files) {
+    _path_replace->_copy_files = true;
+    _path_replace->_copy_into_directory = _legacy_copytex_dir;
+  }
+
   // Let's convert the output file to a full path before we initialize
   // Maya, since Maya now has a nasty habit of changing the current
   // directory.
   if (_got_output_filename) {
     _output_filename.make_absolute();
-    //conjunct the relative output path with output file's dir weifengh
-    if (_texture_out_dir.is_local()) {
-      Filename tempdir = _output_filename.get_dirname() + "/";
-      _texture_out_dir = tempdir + _texture_out_dir;
-    }
+    _path_replace->_path_directory.make_absolute();
   }
 
   nout << "Initializing Maya.\n";
@@ -244,8 +244,6 @@ run() {
   converter._keep_all_uvsets = _keep_all_uvsets;
   converter._round_uvs = _round_uvs;
   converter._transform_type = _transform_type;
-  converter._texture_copy = _texture_copy;
-  converter._texture_out_dir = _texture_out_dir;
   converter._legacy_shader = _legacy_shader;
 
   vector_string::const_iterator si;

+ 2 - 2
pandatool/src/mayaprogs/mayaToEgg.h

@@ -39,9 +39,9 @@ protected:
   bool _suppress_vertex_color;
   bool _keep_all_uvsets;
   bool _round_uvs;
-  bool _texture_copy;
-  Filename _texture_out_dir;
   bool _legacy_shader;
+  bool _legacy_copytex;
+  Filename _legacy_copytex_dir;
 
   MayaToEggConverter::TransformType _transform_type;
   vector_string _subroots; 

+ 1 - 16
pandatool/src/mayaprogs/mayaToEgg_server.cxx

@@ -90,12 +90,6 @@ MayaToEggServer() :
      "0.0; 0.444 becomes 0.44; 0.778 becomes 0.78.",
      &MayaToEggServer::dispatch_none, &_round_uvs);
 
-  add_option
-    ("copytex","dir",0,
-    "copy the textures to a ""Textures"" sub directory relative to the written out egg file."
-    """dir"" is a sub directory in the same format as those used by -pr, etc." ,
-     &MayaToEggServer::dispatch_filename, &_texture_copy, &_texture_out_dir);
-
   add_option
     ("trans", "type", 0,
      "Specifies which transforms in the Maya file should be converted to "
@@ -223,16 +217,9 @@ run() {
   // directory.
   if (_got_output_filename) {
     _output_filename.make_absolute();
-    //conjunct the relative output path with output file's dir weifengh
-    if (_texture_out_dir.is_local()) {
-      Filename tempdir = _output_filename.get_dirname() + "/";
-      _texture_out_dir = tempdir + _texture_out_dir;
-    }
+    _path_replace->_path_directory.make_absolute();
   }
 
-  // So our relative path names come out correctly
-  _path_replace->_path_directory = get_output_filename().get_dirname();
-
   MayaToEggConverter converter(_program_name);
 
   // Copy in the command-line parameters.
@@ -243,8 +230,6 @@ run() {
   converter._keep_all_uvsets = _keep_all_uvsets;
   converter._round_uvs = _round_uvs;
   converter._transform_type = _transform_type;
-  converter._texture_copy = _texture_copy;
-  converter._texture_out_dir = _texture_out_dir;
   converter._legacy_shader = _legacy_shader;
 
   vector_string::const_iterator si;

+ 0 - 2
pandatool/src/mayaprogs/mayaToEgg_server.h

@@ -56,8 +56,6 @@ protected:
   bool _suppress_vertex_color;
   bool _keep_all_uvsets;
   bool _round_uvs;
-  bool _texture_copy;
-  Filename _texture_out_dir;
   bool _legacy_shader;
 
   MayaToEggConverter::TransformType _transform_type;

+ 79 - 4
pandatool/src/pandatoolbase/pathReplace.cxx

@@ -26,6 +26,7 @@
 PathReplace::
 PathReplace() {
   _path_store = PS_keep;
+  _copy_files = false;
   _noabs = false;
   _exists = false;
   _error_flag = false;
@@ -168,6 +169,10 @@ store_path(const Filename &orig_filename) {
   }
   Filename filename = orig_filename;
 
+  if (_copy_files) {
+    copy_this_file(filename);
+  }
+
   switch (_path_store) {
   case PS_relative:
     filename.make_absolute();
@@ -211,6 +216,10 @@ full_convert_path(const Filename &orig_filename,
                   const DSearchPath &additional_path,
                   Filename &resolved_path,
                   Filename &output_path) {
+  if (_path_directory.is_local()) {
+    _path_directory.make_absolute();
+  }
+
   Filename match;
   bool got_match = false;
 
@@ -311,13 +320,17 @@ full_convert_path(const Filename &orig_filename,
   // depends upon the path-store mode.
  calculate_output_path:
 
+  if (_copy_files) {
+    if (copy_this_file(resolved_path)) {
+      match = resolved_path;
+    }
+  }
+
   switch (_path_store) {
   case PS_relative:
     if (resolved_path.empty())
       output_path = resolved_path;
     else {
-      if (_path_directory.is_local())
-        _path_directory.make_absolute();
       output_path = resolved_path;
       output_path.make_absolute();
       output_path.make_relative_to(_path_directory);
@@ -337,8 +350,6 @@ full_convert_path(const Filename &orig_filename,
     if (resolved_path.empty())
       output_path = resolved_path;
     else {
-      if (_path_directory.is_local())
-        _path_directory.make_absolute();
       output_path = resolved_path;
       output_path.make_absolute();
       output_path.make_relative_to(_path_directory, false);
@@ -391,12 +402,76 @@ write(ostream &out, int indent_level) const {
     break;
   }
 
+  if (_copy_files) {
+    indent(out, indent_level)
+      << "-pc " << _copy_into_directory << "\n";
+  }
+
   if (_noabs) {
     indent(out, indent_level)
       << "-noabs\n";
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PathReplace::copy_this_file
+//       Access: Private
+//  Description: Copies the indicated file into the
+//               copy_into_directory, and adjusts filename to
+//               reference the new location.  Returns true if the copy
+//               is made and the filename is changed, false otherwise.
+////////////////////////////////////////////////////////////////////
+bool PathReplace::
+copy_this_file(Filename &filename) {
+  if (_copy_into_directory.is_local()) {
+    _copy_into_directory = Filename(_path_directory, _copy_into_directory);
+  }
+
+  Copied::iterator ci = _orig_to_target.find(filename);
+  if (ci != _orig_to_target.end()) {
+    // This file has already been successfully copied, so we can
+    // quietly return its new target filename.
+    if (filename != (*ci).second) {
+      filename = (*ci).second;
+      return true;
+    }
+    return false;
+  }
+
+  Filename target_filename(_copy_into_directory, filename.get_basename());
+  ci = _target_to_orig.find(target_filename);
+  if (ci != _target_to_orig.end()) {
+    if ((*ci).second != filename) {
+      _error_flag = true;
+      pandatoolbase_cat.error()
+        << "Filename conflict!  Both " << (*ci).second << " and " 
+        << filename << " map to " << target_filename << "\n";
+    }
+
+    // Don't copy this one.
+    _orig_to_target[filename] = filename;
+    return false;
+  }
+
+  _orig_to_target[filename] = target_filename;
+  _target_to_orig[target_filename] = filename;
+
+  // Make the copy.
+  VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
+  vfs->make_directory_full(_copy_into_directory);
+  if (!vfs->copy_file(filename, target_filename)) {
+    _error_flag = true;
+    pandatoolbase_cat.error()
+      << "Cannot copy file from " << filename << " to " << target_filename
+      << "\n";
+    _orig_to_target[filename] = filename;
+    return false;
+  }
+
+  filename = target_filename;
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PathReplace::Entry::Constructor
 //       Access: Public

+ 9 - 0
pandatool/src/pandatoolbase/pathReplace.h

@@ -22,6 +22,7 @@
 #include "filename.h"
 #include "dSearchPath.h"
 #include "pvector.h"
+#include "pmap.h"
 
 ////////////////////////////////////////////////////////////////////
 //       Class : PathReplace
@@ -74,6 +75,8 @@ public:
   // These are used to support store_path().
   PathStore _path_store;
   Filename _path_directory;
+  bool _copy_files;
+  Filename _copy_into_directory;
 
   // If this is this true, then the error flag is set (see had_error()
   // and clear_error()) if any Filename passed to match_path() or
@@ -86,6 +89,8 @@ public:
   bool _exists;
 
 private:
+  bool copy_this_file(Filename &filename);
+
   class Component {
   public:
     INLINE Component(const string &component);
@@ -116,6 +121,10 @@ private:
   Entries _entries;
 
   bool _error_flag;
+
+  typedef pmap<Filename, Filename> Copied;
+  Copied _orig_to_target;
+  Copied _target_to_orig;
 };
 
 #include "pathReplace.I"

+ 8 - 0
pandatool/src/progbase/programBase.cxx

@@ -700,6 +700,14 @@ add_path_store_options() {
      "directory name is taken from the name of the output file.",
      &ProgramBase::dispatch_filename, &_got_path_directory, 
      &(_path_replace->_path_directory));
+
+  add_option
+    ("pc", "target_directory", 40,
+     "Copies textures and other dependent files into the indicated "
+     "directory.  If a relative pathname is specified, it is relative "
+     "to the directory specified with -pd, above.",
+     &ProgramBase::dispatch_filename, &(_path_replace->_copy_files), 
+     &(_path_replace->_copy_into_directory));
 }
 
 ////////////////////////////////////////////////////////////////////