mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
fixed the texture path problem on the improved mayacopy
This commit is contained in:
parent
b3f4f2588d
commit
c4c87c9f84
@ -62,16 +62,18 @@ MayaCopy() {
|
|||||||
"source filename before it is copied into the tree.",
|
"source filename before it is copied into the tree.",
|
||||||
&CVSCopy::dispatch_none, &_keep_ver);
|
&CVSCopy::dispatch_none, &_keep_ver);
|
||||||
|
|
||||||
|
/*
|
||||||
add_option
|
add_option
|
||||||
("rp", "replace_prefix", 80,
|
("rp", "replace_prefix", 80,
|
||||||
"use these prefixes when replacing reference with the recently copied file from the "
|
"use these prefixes when replacing reference with the recently copied file from the "
|
||||||
"source filename before it is copied into the tree.",
|
"source filename before it is copied into the tree.",
|
||||||
&CVSCopy::dispatch_vector_string, NULL, &_replace_prefix);
|
&CVSCopy::dispatch_vector_string, NULL, &_replace_prefix);
|
||||||
|
*/
|
||||||
|
|
||||||
add_option
|
add_option
|
||||||
("omittex", "", 0,
|
("omittex", "", 0,
|
||||||
"Character animation files do not need to copy the texures. This option omits the "
|
"Character animation files do not need to copy the texures nor its references. "
|
||||||
"textures of the models to be re-mayacopied",
|
"This option omits the textures and references of the models to be re-mayacopied",
|
||||||
&CVSCopy::dispatch_none, &_omit_tex);
|
&CVSCopy::dispatch_none, &_omit_tex);
|
||||||
|
|
||||||
add_path_replace_options();
|
add_path_replace_options();
|
||||||
@ -191,30 +193,10 @@ copy_maya_file(const Filename &source, const Filename &dest,
|
|||||||
// Finally, copy in any referenced Maya files.
|
// Finally, copy in any referenced Maya files.
|
||||||
unsigned int num_refs = refs.length();
|
unsigned int num_refs = refs.length();
|
||||||
|
|
||||||
/*
|
if (num_refs > 0) {
|
||||||
if (num_refs != 0) {
|
_omit_tex = true;
|
||||||
maya_cat.warning()
|
|
||||||
<< "External references are not yet properly supported by mayacopy!\n";
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
if (num_refs != 0) {
|
|
||||||
if (_replace_prefix.empty()) {
|
|
||||||
// try to put the first word of the file name as the replace prefix
|
|
||||||
size_t idx = source.get_basename().find("_",0);
|
|
||||||
if (idx != string::npos) {
|
|
||||||
string st = source.get_basename().substr(0, idx);
|
|
||||||
_replace_prefix.push_back(st);
|
|
||||||
maya_cat.info() << "replace_prefix = " << st << endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
maya_cat.error()
|
|
||||||
<< "External references exist: "
|
|
||||||
<< "please make sure to specify a _replace_prefix with -rp option\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unsigned int ref_index;
|
unsigned int ref_index;
|
||||||
maya_cat.info() << "num_refs = " << num_refs << endl;
|
maya_cat.info() << "num_refs = " << num_refs << endl;
|
||||||
for (ref_index = 0; ref_index < num_refs; ref_index++) {
|
for (ref_index = 0; ref_index < num_refs; ref_index++) {
|
||||||
@ -227,34 +209,51 @@ copy_maya_file(const Filename &source, const Filename &dest,
|
|||||||
// file -loadReference "mtpRN" -type "mayaBinary" -options "v=0"
|
// file -loadReference "mtpRN" -type "mayaBinary" -options "v=0"
|
||||||
// "m_t_pear_zero.mb";
|
// "m_t_pear_zero.mb";
|
||||||
string lookup = refs[ref_index].asChar();
|
string lookup = refs[ref_index].asChar();
|
||||||
|
|
||||||
|
string blah = "file -q -referenceNode \"" + lookup + "\";";
|
||||||
|
//maya_cat.info() << blah << endl;
|
||||||
|
MString result;
|
||||||
|
status = MGlobal::executeCommand(MString(blah.c_str()), result);
|
||||||
|
//maya_cat.info() << "result = " << result.asChar() << endl;
|
||||||
|
|
||||||
|
// for multiple reference of the same model. maya throws in a {#} at the end, ignore that
|
||||||
|
size_t dup = lookup.find('{');
|
||||||
|
if (dup != string::npos){
|
||||||
|
lookup.erase(dup);
|
||||||
|
}
|
||||||
|
|
||||||
Filename filename =
|
Filename filename =
|
||||||
_path_replace->convert_path(Filename::from_os_specific(refs[ref_index].asChar()));
|
_path_replace->convert_path(Filename::from_os_specific(lookup));
|
||||||
|
|
||||||
CVSSourceTree::FilePath path =
|
CVSSourceTree::FilePath path =
|
||||||
_tree.choose_directory(filename.get_basename(), dir, _force, _interactive);
|
_tree.choose_directory(filename.get_basename(), dir, _force, _interactive);
|
||||||
Filename new_filename = path.get_rel_from(dir);
|
Filename new_filename = path.get_rel_from(dir);
|
||||||
_exec_string = "file -loadReference \"" + _replace_prefix[_curr_idx++] + "RN\" -type \"mayaBinary\" -options \"v=0\" \"" + new_filename.to_os_generic() + "\";";
|
|
||||||
maya_cat.info() << "executing command: " << _exec_string << "\n";
|
//maya_cat.info() << "curr_idx " << _curr_idx << endl;
|
||||||
|
_exec_string.push_back("file -loadReference \"" + string(result.asChar()) + "\" -type \"mayaBinary\" -options \"v=0\" \"" + new_filename.to_os_generic() + "\";");
|
||||||
|
maya_cat.info() << "executing command: " << _exec_string[_curr_idx] << "\n";
|
||||||
//MGlobal::executeCommand("file -loadReference \"mtpRN\" -type \"mayaBinary\" -options \"v=0\" \"m_t_pear_zero.mb\";");
|
//MGlobal::executeCommand("file -loadReference \"mtpRN\" -type \"mayaBinary\" -options \"v=0\" \"m_t_pear_zero.mb\";");
|
||||||
status = MGlobal::executeCommand(MString(_exec_string.c_str()));
|
status = MGlobal::executeCommand(MString(_exec_string[ref_index].c_str()));
|
||||||
|
if (!status) {
|
||||||
|
status.perror("loadReference failed");
|
||||||
|
}
|
||||||
|
_curr_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_omit_tex) {
|
// Get all the shaders so we can determine the set of textures.
|
||||||
// Get all the shaders so we can determine the set of textures.
|
_shaders.clear();
|
||||||
_shaders.clear();
|
collect_shaders();
|
||||||
collect_shaders();
|
int num_shaders = _shaders.get_num_shaders();
|
||||||
int num_shaders = _shaders.get_num_shaders();
|
for (int i = 0; i < num_shaders; i++) {
|
||||||
for (int i = 0; i < num_shaders; i++) {
|
MayaShader *shader = _shaders.get_shader(i);
|
||||||
MayaShader *shader = _shaders.get_shader(i);
|
for (size_t j = 0; j < shader->_color.size(); j++) {
|
||||||
for (size_t j = 0; j < shader->_color.size(); j++) {
|
if (!extract_texture(*shader->get_color_def(j), dir)) {
|
||||||
if (!extract_texture(*shader->get_color_def(j), dir)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!extract_texture(shader->_transparency, dir)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!extract_texture(shader->_transparency, dir)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now write out the Maya file.
|
// Now write out the Maya file.
|
||||||
@ -265,19 +264,19 @@ copy_maya_file(const Filename &source, const Filename &dest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (ref_index = 0; ref_index < num_refs; ref_index++) {
|
for (ref_index = 0; ref_index < num_refs; ref_index++) {
|
||||||
//maya_cat.info() << "refs filename: " << refs[ref_index].asChar() << "\n";
|
if (1) { // we may want an option later to pull in all the referenced files
|
||||||
//maya_cat.info() << "os_specific filename: " << Filename::from_os_specific(refs[ref_index].asChar()) << "\n";
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//maya_cat.info() << "-----------exec_string = " << _exec_string << endl;
|
string lookup = refs[ref_index].asChar();
|
||||||
string original("loadReference");
|
// for multiple reference of the same model. maya throws in a {#} at the end, ignore that
|
||||||
string replace("unloadReference");
|
size_t dup = lookup.find('{');
|
||||||
size_t index = _exec_string.find("loadReference");
|
if (dup != string::npos){
|
||||||
_exec_string.replace(index, original.length(), replace, 0, replace.length());
|
lookup.erase(dup);
|
||||||
maya_cat.info() << "executing command: " << _exec_string << "\n";
|
}
|
||||||
status = MGlobal::executeCommand(MString(_exec_string.c_str()));
|
|
||||||
|
|
||||||
Filename filename =
|
Filename filename =
|
||||||
_path_replace->convert_path(Filename::from_os_specific(refs[ref_index].asChar()));
|
_path_replace->convert_path(Filename::from_os_specific(lookup));
|
||||||
|
|
||||||
maya_cat.info()
|
maya_cat.info()
|
||||||
<< "External ref: " << filename << "\n";
|
<< "External ref: " << filename << "\n";
|
||||||
@ -292,21 +291,6 @@ copy_maya_file(const Filename &source, const Filename &dest,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
for (unsigned int ref_index = 0; ref_index < num_refs; ref_index++) {
|
|
||||||
Filename filename =
|
|
||||||
_path_replace->convert_path(Filename::from_os_specific(refs[ref_index].asChar()));
|
|
||||||
status = MFileIO::reference(MString(filename.get_basename().c_str()));
|
|
||||||
if (!status) {
|
|
||||||
status.perror("MFileIO reference");
|
|
||||||
}
|
|
||||||
status = MFileIO::removeReference(refs[ref_index].asChar());
|
|
||||||
if (!status) {
|
|
||||||
status.perror("MFileIO removeReference");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,9 +74,11 @@ private:
|
|||||||
bool _keep_ver;
|
bool _keep_ver;
|
||||||
bool _omit_tex;
|
bool _omit_tex;
|
||||||
int _curr_idx;
|
int _curr_idx;
|
||||||
|
/*
|
||||||
vector_string _replace_prefix;
|
vector_string _replace_prefix;
|
||||||
|
*/
|
||||||
|
|
||||||
string _exec_string;
|
vector_string _exec_string;
|
||||||
|
|
||||||
PT(MayaApi) _maya;
|
PT(MayaApi) _maya;
|
||||||
MayaShaders _shaders;
|
MayaShaders _shaders;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user