fix problem with -copytex in conjunction with -pr

This commit is contained in:
David Rose 2011-11-01 23:44:38 +00:00
parent 1e80e3d39d
commit a9862a4450
16 changed files with 145 additions and 126 deletions

View File

@ -40,7 +40,7 @@
// relevant shader properties. // relevant shader properties.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
MayaShader:: MayaShader::
MayaShader(MObject engine, bool texture_copy, Filename tout_dir, bool legacy_shader) { MayaShader(MObject engine, bool legacy_shader) {
MFnDependencyNode engine_fn(engine); MFnDependencyNode engine_fn(engine);
set_name(engine_fn.name().asChar()); 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() maya_cat.debug()
<< "Reading shading engine " << get_name() << "\n"; << "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; _legacy_mode = false;
_flat_color.set(1,1,1,1); _flat_color.set(1,1,1,1);
@ -228,29 +225,29 @@ find_textures_modern(MObject shader) {
string n = shader_fn.name().asChar(); 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) { 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) { 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) { 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) { 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) { 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) { 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(); collect_maps();
@ -484,7 +481,7 @@ find_textures_legacy(MObject shader) {
MayaShaderColorDef *color_p = new MayaShaderColorDef; MayaShaderColorDef *color_p = new MayaShaderColorDef;
for (size_t i = 0; i < color_pa.length(); i++) { for (size_t i = 0; i < color_pa.length(); i++) {
maya_cat.spam() << "color_pa[" << i << "]:" << color_pa[i].name().asChar() << endl; 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) { if (color_pa.length() < 1) {
@ -506,7 +503,7 @@ find_textures_legacy(MObject shader) {
for (size_t i = 0; i < trans_pa.length(); i++) { for (size_t i = 0; i < trans_pa.length(); i++) {
maya_cat.spam() << "read a transparency texture" << endl; 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);
} }
} }

View File

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

View File

@ -266,7 +266,7 @@ get_panda_uvset_name() {
// properties. // properties.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void MayaShaderColorDef:: 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; LRGBColor color_gain;
if (get_vec3_attribute(color, "colorGain", color_gain)) { if (get_vec3_attribute(color, "colorGain", color_gain)) {
color_gain[0] = color_gain[0] > 1.0 ? 1.0 : color_gain[0]; 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; _has_texture = false;
set_string_attribute(color, "fileTextureName", ""); 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); 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); image_plug.connectedTo(image_pa, true, false);
for (size_t i = 0; i < image_pa.length(); i++) { 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; maya_cat.debug() << pl.name().asChar() << " next:connectedTo: " << pla_name << endl;
} }
MayaShaderColorDef *color_p = new MayaShaderColorDef; 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; color_p->_blend_type = bt;
size_t loc = color_p->_texture_name.find('.',0); size_t loc = color_p->_texture_name.find('.',0);
if (loc != string::npos) { if (loc != string::npos) {
@ -477,7 +460,7 @@ find_textures_legacy(MayaShader *shader, MObject color, bool _texture_copy, File
if (maya_cat.is_debug()) { if (maya_cat.is_debug()) {
maya_cat.debug() << pl.name().asChar() << " first:connectedTo: " << pla_name << endl; 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()); _texture_name.assign(pla[j].name().asChar());
_blend_type = bt; _blend_type = bt;
size_t loc = _texture_name.find('.',0); 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. // to the provided MayaShaderColorList.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void MayaShaderColorDef:: 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; MPlugArray outplugs;
inplug.connectedTo(outplugs, true, false); 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->_color_object = new MObject(source);
def->_texture_filename = Filename::from_os_specific(filename); 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(); def->_texture_name = sourceFn.name().asChar();
get_vec2_attribute(source, "coverage", def->_coverage); 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); image_plug.connectedTo(image_pa, true, false);
for (size_t i = 0; i < image_pa.length(); i++) { 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; return;
} }
size_t before = list.size(); 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; int blendValue;
blend.getValue(blendValue); blend.getValue(blendValue);
for (size_t sub=before; sub<list.size(); sub++) { 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) { if (source.apiType() == MFn::kReverse) {
MPlug input_plug = sourceFn.findPlug("input"); 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; return;
} }

View File

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

View File

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

View File

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

View File

@ -100,7 +100,6 @@ MayaToEggConverter(const string &program_name) :
_always_show_vertex_color = maya_default_vertex_color; _always_show_vertex_color = maya_default_vertex_color;
_keep_all_uvsets = false; _keep_all_uvsets = false;
_round_uvs = false; _round_uvs = false;
_texture_copy = false;
_legacy_shader = false; _legacy_shader = false;
_transform_type = TT_model; _transform_type = TT_model;
@ -128,7 +127,6 @@ MayaToEggConverter(const MayaToEggConverter &copy) :
_always_show_vertex_color(copy._always_show_vertex_color), _always_show_vertex_color(copy._always_show_vertex_color),
_keep_all_uvsets(copy._keep_all_uvsets), _keep_all_uvsets(copy._keep_all_uvsets),
_round_uvs(copy._round_uvs), _round_uvs(copy._round_uvs),
_texture_copy(copy._texture_copy),
_legacy_shader(copy._legacy_shader), _legacy_shader(copy._legacy_shader),
_transform_type(copy._transform_type) _transform_type(copy._transform_type)
{ {
@ -833,9 +831,6 @@ convert_hierarchy(EggGroupNode *egg_root) {
mayaegg_cat.info() << "will keep_all_uvsets" << endl; mayaegg_cat.info() << "will keep_all_uvsets" << endl;
} }
// give some feedback about whether special options are on // 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) { if (_legacy_shader) {
mayaegg_cat.info() << "will disable modern Phong shader path. using legacy" << endl; 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() << surface.numSpansInV()
<< "\n"; << "\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 (_polygon_output) {
// If we want polygon output only, tesselate the NURBS and 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)); 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) { if (shader != (MayaShader *)NULL) {
set_shader_attributes(*egg_curve, *shader); 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()); nassertv(shader_index >= 0 && shader_index < (int)shaders.length());
MObject engine = shaders[shader_index]; MObject engine = shaders[shader_index];
shader = 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? //does this mean if we didn't find a Maya shader give it a default value anyway?
} else if (default_shader != (MayaShader *)NULL) { } else if (default_shader != (MayaShader *)NULL) {
shader = default_shader; shader = default_shader;

View File

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

View File

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

View File

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

View File

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

View File

@ -90,12 +90,6 @@ MayaToEggServer() :
"0.0; 0.444 becomes 0.44; 0.778 becomes 0.78.", "0.0; 0.444 becomes 0.44; 0.778 becomes 0.78.",
&MayaToEggServer::dispatch_none, &_round_uvs); &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 add_option
("trans", "type", 0, ("trans", "type", 0,
"Specifies which transforms in the Maya file should be converted to " "Specifies which transforms in the Maya file should be converted to "
@ -223,16 +217,9 @@ run() {
// directory. // directory.
if (_got_output_filename) { if (_got_output_filename) {
_output_filename.make_absolute(); _output_filename.make_absolute();
//conjunct the relative output path with output file's dir weifengh _path_replace->_path_directory.make_absolute();
if (_texture_out_dir.is_local()) {
Filename tempdir = _output_filename.get_dirname() + "/";
_texture_out_dir = tempdir + _texture_out_dir;
}
} }
// So our relative path names come out correctly
_path_replace->_path_directory = get_output_filename().get_dirname();
MayaToEggConverter converter(_program_name); MayaToEggConverter converter(_program_name);
// Copy in the command-line parameters. // Copy in the command-line parameters.
@ -243,8 +230,6 @@ run() {
converter._keep_all_uvsets = _keep_all_uvsets; converter._keep_all_uvsets = _keep_all_uvsets;
converter._round_uvs = _round_uvs; converter._round_uvs = _round_uvs;
converter._transform_type = _transform_type; converter._transform_type = _transform_type;
converter._texture_copy = _texture_copy;
converter._texture_out_dir = _texture_out_dir;
converter._legacy_shader = _legacy_shader; converter._legacy_shader = _legacy_shader;
vector_string::const_iterator si; vector_string::const_iterator si;

View File

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

View File

@ -26,6 +26,7 @@
PathReplace:: PathReplace::
PathReplace() { PathReplace() {
_path_store = PS_keep; _path_store = PS_keep;
_copy_files = false;
_noabs = false; _noabs = false;
_exists = false; _exists = false;
_error_flag = false; _error_flag = false;
@ -168,6 +169,10 @@ store_path(const Filename &orig_filename) {
} }
Filename filename = orig_filename; Filename filename = orig_filename;
if (_copy_files) {
copy_this_file(filename);
}
switch (_path_store) { switch (_path_store) {
case PS_relative: case PS_relative:
filename.make_absolute(); filename.make_absolute();
@ -211,6 +216,10 @@ full_convert_path(const Filename &orig_filename,
const DSearchPath &additional_path, const DSearchPath &additional_path,
Filename &resolved_path, Filename &resolved_path,
Filename &output_path) { Filename &output_path) {
if (_path_directory.is_local()) {
_path_directory.make_absolute();
}
Filename match; Filename match;
bool got_match = false; bool got_match = false;
@ -311,13 +320,17 @@ full_convert_path(const Filename &orig_filename,
// depends upon the path-store mode. // depends upon the path-store mode.
calculate_output_path: calculate_output_path:
if (_copy_files) {
if (copy_this_file(resolved_path)) {
match = resolved_path;
}
}
switch (_path_store) { switch (_path_store) {
case PS_relative: case PS_relative:
if (resolved_path.empty()) if (resolved_path.empty())
output_path = resolved_path; output_path = resolved_path;
else { else {
if (_path_directory.is_local())
_path_directory.make_absolute();
output_path = resolved_path; output_path = resolved_path;
output_path.make_absolute(); output_path.make_absolute();
output_path.make_relative_to(_path_directory); output_path.make_relative_to(_path_directory);
@ -337,8 +350,6 @@ full_convert_path(const Filename &orig_filename,
if (resolved_path.empty()) if (resolved_path.empty())
output_path = resolved_path; output_path = resolved_path;
else { else {
if (_path_directory.is_local())
_path_directory.make_absolute();
output_path = resolved_path; output_path = resolved_path;
output_path.make_absolute(); output_path.make_absolute();
output_path.make_relative_to(_path_directory, false); output_path.make_relative_to(_path_directory, false);
@ -391,12 +402,76 @@ write(ostream &out, int indent_level) const {
break; break;
} }
if (_copy_files) {
indent(out, indent_level)
<< "-pc " << _copy_into_directory << "\n";
}
if (_noabs) { if (_noabs) {
indent(out, indent_level) indent(out, indent_level)
<< "-noabs\n"; << "-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 // Function: PathReplace::Entry::Constructor
// Access: Public // Access: Public

View File

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

View File

@ -700,6 +700,14 @@ add_path_store_options() {
"directory name is taken from the name of the output file.", "directory name is taken from the name of the output file.",
&ProgramBase::dispatch_filename, &_got_path_directory, &ProgramBase::dispatch_filename, &_got_path_directory,
&(_path_replace->_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));
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////