maya 2008 could change working directory after ::read, specially with referenced files; this forces it back

This commit is contained in:
Asad M. Zaman 2008-05-20 22:11:29 +00:00
parent 53aa703996
commit 91147411ee
5 changed files with 99 additions and 21 deletions

View File

@ -262,8 +262,29 @@ read(const Filename &filename) {
// even on Windows. // even on Windows.
string os_filename = filename.to_os_generic(); string os_filename = filename.to_os_generic();
Filename cwd = ExecutionEnvironment::get_cwd();
string dirname = cwd.to_os_specific();
if (maya_cat.is_debug()) {
maya_cat.debug() << "cwd(read:before): " << dirname.c_str() << endl;
}
MFileIO::newFile(true); MFileIO::newFile(true);
MStatus stat = MFileIO::open(os_filename.c_str()); MStatus stat = MFileIO::open(os_filename.c_str());
// Beginning with Maya2008, the call to read seem to change
// the current directory specially if there is a refrence file! Yikes!
// Furthermore, the current directory may change during the call to
// any Maya function! Egad!
if (chdir(dirname.c_str()) < 0) {
maya_cat.warning()
<< "Unable to restore current directory after ::read to " << cwd
<< " after initializing Maya.\n";
} else {
if (maya_cat.is_debug()) {
maya_cat.debug()
<< "Restored current directory after ::read to " << cwd << "\n";
}
}
if (!stat) { if (!stat) {
stat.perror(os_filename.c_str()); stat.perror(os_filename.c_str());
return false; return false;

View File

@ -623,7 +623,7 @@ int MayaEggMesh::GetVert(EggVertex *vert, EggGroup *context)
_vertNormalIndices.append(vtx._index); _vertNormalIndices.append(vtx._index);
} }
if (vert->has_color()) { if (vert->has_color()) {
mayaloader_cat.info() << "found a vertex color\n"; mayaloader_cat.spam() << "found a vertex color\n";
_vertColorArray.append(MakeMayaColor(vert->get_color())); _vertColorArray.append(MakeMayaColor(vert->get_color()));
_vertColorIndices.append(vtx._index); _vertColorIndices.append(vtx._index);
} }
@ -823,7 +823,7 @@ void MayaEggLoader::CreateSkinCluster(MayaEggMesh *M)
for (unsigned int i=0; i<vert->_weights.size(); i++) { for (unsigned int i=0; i<vert->_weights.size(); i++) {
double strength = vert->_weights[i].first; double strength = vert->_weights[i].first;
MayaEggJoint *joint = FindJoint(vert->_weights[i].second); MayaEggJoint *joint = FindJoint(vert->_weights[i].second);
if (!joint->_inskin) { if (joint && !joint->_inskin) {
joint->_inskin = true; joint->_inskin = true;
joint->_index = joints.size(); joint->_index = joints.size();
joints.push_back(joint); joints.push_back(joint);
@ -833,7 +833,11 @@ void MayaEggLoader::CreateSkinCluster(MayaEggMesh *M)
cmd += maxInfluences; cmd += maxInfluences;
mayaloader_cat.spam() << joints.size() << " joints have weights on " << M->_pool->get_name() << endl; mayaloader_cat.spam() << joints.size() << " joints have weights on " << M->_pool->get_name() << endl;
if (joints.size() == 0) {
// no need to cluster; there are no weights
return;
}
for (unsigned int i=0; i<joints.size(); i++) { for (unsigned int i=0; i<joints.size(); i++) {
MFnDependencyNode joint(joints[i]->_joint); MFnDependencyNode joint(joints[i]->_joint);
cmd = cmd + " "; cmd = cmd + " ";
@ -1097,16 +1101,39 @@ bool MayaEggLoader::ConvertEggData(EggData *data, bool merge, bool model, bool a
mayaloader_cat.debug() << "mesh's parent (null) : " << endl; mayaloader_cat.debug() << "mesh's parent (null) : " << endl;
} }
} }
if (mayaloader_cat.is_spam()) {
mayaloader_cat.spam() << "mesh pointer : " << mesh << " and parent_ponter: " << &parent << endl;
mayaloader_cat.spam() << "mesh vert_count : " << mesh->_vert_count << endl;
mayaloader_cat.spam() << "mesh face_count : " << mesh->_face_count << endl;
mayaloader_cat.spam() << "mesh vertexArray : " << mesh->_vertexArray << endl;
mayaloader_cat.spam() << "mesh polygonCounts : " << mesh->_polygonCounts << endl;
mayaloader_cat.spam() << "mesh polygonConnects : " << mesh->_polygonConnects << endl;
mayaloader_cat.spam() << "mesh uarray : " << mesh->_uarray << endl;
mayaloader_cat.spam() << "mesh varray : " << mesh->_varray << endl;
}
mesh->_transNode = mfn.create(mesh->_vert_count, mesh->_face_count, mesh->_transNode = mfn.create(mesh->_vert_count, mesh->_face_count,
mesh->_vertexArray, mesh->_polygonCounts, mesh->_polygonConnects, mesh->_vertexArray, mesh->_polygonCounts, mesh->_polygonConnects,
mesh->_uarray, mesh->_varray, mesh->_uarray, mesh->_varray,
parent, &status); parent, &status);
if (mayaloader_cat.is_spam()) {
mayaloader_cat.spam() << "transNode created." << endl;
}
mesh->_shapeNode = mfn.object(); mesh->_shapeNode = mfn.object();
mfn.getPath(mesh->_shape_dag_path); mfn.getPath(mesh->_shape_dag_path);
mesh->ConnectTextures(); mesh->ConnectTextures();
if (mayaloader_cat.is_spam()) {
mayaloader_cat.spam() << "textures connected." << endl;
}
mfn.getCurrentUVSetName(cset); mfn.getCurrentUVSetName(cset);
mfn.assignUVs(mesh->_polygonCounts, mesh->_uvIds, &cset); mfn.assignUVs(mesh->_polygonCounts, mesh->_uvIds, &cset);
if (mayaloader_cat.is_spam()) {
mayaloader_cat.spam() << "uvs assigned." << endl;
}
// lets try to set normals per vertex // lets try to set normals per vertex
if (respect_normals) { if (respect_normals) {
status = mfn.setVertexNormals(mesh->_normalArray, mesh->_vertNormalIndices, MSpace::kTransform); status = mfn.setVertexNormals(mesh->_normalArray, mesh->_vertNormalIndices, MSpace::kTransform);
@ -1114,6 +1141,10 @@ bool MayaEggLoader::ConvertEggData(EggData *data, bool merge, bool model, bool a
status.perror("setVertexNormals failed!"); status.perror("setVertexNormals failed!");
} }
} }
if (mayaloader_cat.is_spam()) {
mayaloader_cat.spam() << "vertex normals set." << endl;
}
// lets try to set colors per vertex // lets try to set colors per vertex
/* /*

View File

@ -77,6 +77,7 @@
#include <maya/MSelectionList.h> #include <maya/MSelectionList.h>
#include "post_maya_include.h" #include "post_maya_include.h"
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: MayaToEggConverter::Constructor // Function: MayaToEggConverter::Constructor
// Access: Public // Access: Public

View File

@ -196,7 +196,7 @@ copy_maya_file(const Filename &source, const Filename &dest,
// Get the set of externally referenced Maya files. // Get the set of externally referenced Maya files.
MStringArray refs; MStringArray refs;
MStatus status = MFileIO::getReferences(refs); MStatus status = MFileIO::getReferences(refs);
if (!status) { if (status != MStatus::kSuccess) {
status.perror("MItDag constructor"); status.perror("MItDag constructor");
return false; return false;
} }
@ -207,21 +207,13 @@ copy_maya_file(const Filename &source, const Filename &dest,
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++) {
// one thing we need to do is rename the path to the base file maya_cat.info() << "curr_idx " << _curr_idx << endl;
// that it is referencing to. This will guarantee that the
// refencing will stay in the copied directory. Only way I could
// make it work properly is through following MEL command. the
// pear character is used as an example. The maya API calls of
// removeReference and reference didn't work for the animations
// file -loadReference "mtpRN" -type "mayaBinary" -options "v=0"
// "m_t_pear_zero.mb";
string lookup = refs[ref_index].asChar(); string lookup = refs[ref_index].asChar();
string blah = "file -q -referenceNode \"" + lookup + "\";"; string blah = "file -q -referenceNode \"" + lookup + "\";";
//maya_cat.info() << blah << endl; maya_cat.info() << blah << endl;
MString result; MString result;
status = MGlobal::executeCommand(MString(blah.c_str()), result); status = MGlobal::executeCommand(MString(blah.c_str()), result);
//maya_cat.info() << "result = " << result.asChar() << endl; maya_cat.info() << "result = " << result.asChar() << endl;
// for multiple reference of the same model. maya throws in a {#} at the end, ignore that // for multiple reference of the same model. maya throws in a {#} at the end, ignore that
size_t dup = lookup.find('{'); size_t dup = lookup.find('{');
@ -236,14 +228,46 @@ copy_maya_file(const Filename &source, const Filename &dest,
_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);
//maya_cat.info() << "curr_idx " << _curr_idx << endl; if (maya_cat.is_spam()) {
maya_cat.spam() << "cvs dir " << dir->get_fullpath().to_os_generic() << endl;
maya_cat.spam() << "cvs path " << path.get_fullpath().to_os_generic() << endl;
}
MString result2;
if (maya_cat.is_debug()) {
string cmdStr = "pwd";
MString result3;
status = MGlobal::executeCommand(MString(cmdStr.c_str()), result3);
maya_cat.debug() << "result = " << result3.asChar() << "\n";
}
_exec_string.push_back("file -loadReference \"" + string(result.asChar()) + "\" -type \"mayaBinary\" -options \"v=0\" \"" + new_filename.to_os_generic() + "\";"); _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\";");
maya_cat.info() << "executing command: " << _exec_string[_curr_idx] << "\n";
status = MGlobal::executeCommand(MString(_exec_string[ref_index].c_str())); status = MGlobal::executeCommand(MString(_exec_string[ref_index].c_str()));
if (!status) { if (status != MStatus::kSuccess) {
status.perror("loadReference failed"); status.perror("loadReference failed");
} }
/*
Filename filename =
_path_replace->convert_path(Filename::from_os_specific(lookup));
CVSSourceTree::FilePath path =
_tree.choose_directory(filename.get_basename(), dir, _force, _interactive);
Filename new_filename = path.get_rel_from(dir);
maya_cat.info() << "lookup filename: " << filename.to_os_generic() << "\n";
string cmdStr = "chdir " + string(dir->get_fullpath().to_os_generic().c_str()) + ";";
maya_cat.info() << "new filename (relative): " << new_filename.to_os_generic() << "\n";
//maya_cat.info() << "new filename (absolute): " << path.get_fullpath().to_os_generic() << "\n";
MString loadedFilename = MFileIO::loadReference(MString(new_filename.to_os_generic().c_str()), &status);
//MString loadedFilename = MFileIO::loadReference(MString(path.get_fullpath().to_os_generic().c_str()), &status);
//MString loadedFilename = MFileIO::loadReferenceByNode(result, &status);
maya_cat.info() << "loaded filename: " << loadedFilename << "\n";
if (status != MStatus::kSuccess) {
status.perror("loadReference failed");
}
*/
_curr_idx++; _curr_idx++;
} }
@ -362,7 +386,7 @@ collect_shaders() {
MStatus status; MStatus status;
MItDag dag_iterator(MItDag::kDepthFirst, MFn::kTransform, &status); MItDag dag_iterator(MItDag::kDepthFirst, MFn::kTransform, &status);
if (!status) { if (status != MStatus::kSuccess) {
status.perror("MItDag constructor"); status.perror("MItDag constructor");
return false; return false;
} }
@ -374,7 +398,7 @@ collect_shaders() {
while (!dag_iterator.isDone()) { while (!dag_iterator.isDone()) {
MDagPath dag_path; MDagPath dag_path;
status = dag_iterator.getPath(dag_path); status = dag_iterator.getPath(dag_path);
if (!status) { if (status != MStatus::kSuccess) {
status.perror("MItDag::getPath"); status.perror("MItDag::getPath");
} else { } else {
if (!collect_shader_for_node(dag_path)) { if (!collect_shader_for_node(dag_path)) {
@ -403,7 +427,7 @@ bool MayaCopy::
collect_shader_for_node(const MDagPath &dag_path) { collect_shader_for_node(const MDagPath &dag_path) {
MStatus status; MStatus status;
MFnDagNode dag_node(dag_path, &status); MFnDagNode dag_node(dag_path, &status);
if (!status) { if (status != MStatus::kSuccess) {
status.perror("MFnDagNode constructor"); status.perror("MFnDagNode constructor");
return false; return false;
} }

View File

@ -51,6 +51,7 @@ main(int argc, char *argv[]) {
// Now look up $MAYA_LOCATION. We insist that it be set and // Now look up $MAYA_LOCATION. We insist that it be set and
// pointing to an actual Maya installation. // pointing to an actual Maya installation.
Filename maya_location = Filename::expand_from("$MAYA_LOCATION"); Filename maya_location = Filename::expand_from("$MAYA_LOCATION");
cerr << "MAYA_LOCATION: " << maya_location << endl;
if (maya_location.empty()) { if (maya_location.empty()) {
cerr << "$MAYA_LOCATION is not set!\n"; cerr << "$MAYA_LOCATION is not set!\n";
exit(1); exit(1);