diff --git a/pandatool/src/maya/mayaApi.cxx b/pandatool/src/maya/mayaApi.cxx index c4cdbeea2d..cfd8965e4a 100644 --- a/pandatool/src/maya/mayaApi.cxx +++ b/pandatool/src/maya/mayaApi.cxx @@ -262,8 +262,29 @@ read(const Filename &filename) { // even on Windows. 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); 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) { stat.perror(os_filename.c_str()); return false; diff --git a/pandatool/src/mayaegg/mayaEggLoader.cxx b/pandatool/src/mayaegg/mayaEggLoader.cxx index e582aa3435..4f5b4a0227 100755 --- a/pandatool/src/mayaegg/mayaEggLoader.cxx +++ b/pandatool/src/mayaegg/mayaEggLoader.cxx @@ -623,7 +623,7 @@ int MayaEggMesh::GetVert(EggVertex *vert, EggGroup *context) _vertNormalIndices.append(vtx._index); } 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())); _vertColorIndices.append(vtx._index); } @@ -823,7 +823,7 @@ void MayaEggLoader::CreateSkinCluster(MayaEggMesh *M) for (unsigned int i=0; i_weights.size(); i++) { double strength = vert->_weights[i].first; MayaEggJoint *joint = FindJoint(vert->_weights[i].second); - if (!joint->_inskin) { + if (joint && !joint->_inskin) { joint->_inskin = true; joint->_index = joints.size(); joints.push_back(joint); @@ -833,7 +833,11 @@ void MayaEggLoader::CreateSkinCluster(MayaEggMesh *M) cmd += maxInfluences; 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_joint); 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; } } + 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->_vertexArray, mesh->_polygonCounts, mesh->_polygonConnects, mesh->_uarray, mesh->_varray, parent, &status); + + if (mayaloader_cat.is_spam()) { + mayaloader_cat.spam() << "transNode created." << endl; + } mesh->_shapeNode = mfn.object(); mfn.getPath(mesh->_shape_dag_path); mesh->ConnectTextures(); + + if (mayaloader_cat.is_spam()) { + mayaloader_cat.spam() << "textures connected." << endl; + } + mfn.getCurrentUVSetName(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 if (respect_normals) { 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!"); } } + + if (mayaloader_cat.is_spam()) { + mayaloader_cat.spam() << "vertex normals set." << endl; + } // lets try to set colors per vertex /* diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 896242f0ff..6d8a9e9197 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -77,6 +77,7 @@ #include #include "post_maya_include.h" + //////////////////////////////////////////////////////////////////// // Function: MayaToEggConverter::Constructor // Access: Public diff --git a/pandatool/src/mayaprogs/mayaCopy.cxx b/pandatool/src/mayaprogs/mayaCopy.cxx index 9295838a9b..a21ca0ecf8 100644 --- a/pandatool/src/mayaprogs/mayaCopy.cxx +++ b/pandatool/src/mayaprogs/mayaCopy.cxx @@ -196,7 +196,7 @@ copy_maya_file(const Filename &source, const Filename &dest, // Get the set of externally referenced Maya files. MStringArray refs; MStatus status = MFileIO::getReferences(refs); - if (!status) { + if (status != MStatus::kSuccess) { status.perror("MItDag constructor"); return false; } @@ -207,21 +207,13 @@ copy_maya_file(const Filename &source, const Filename &dest, unsigned int ref_index; maya_cat.info() << "num_refs = " << num_refs << endl; for (ref_index = 0; ref_index < num_refs; ref_index++) { - // one thing we need to do is rename the path to the base file - // 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"; + maya_cat.info() << "curr_idx " << _curr_idx << endl; string lookup = refs[ref_index].asChar(); - string blah = "file -q -referenceNode \"" + lookup + "\";"; - //maya_cat.info() << blah << endl; + maya_cat.info() << blah << endl; MString 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 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); 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() + "\";"); - 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\";"); + maya_cat.info() << "executing command: " << _exec_string[_curr_idx] << "\n"; status = MGlobal::executeCommand(MString(_exec_string[ref_index].c_str())); - if (!status) { + if (status != MStatus::kSuccess) { 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++; } @@ -362,7 +386,7 @@ collect_shaders() { MStatus status; MItDag dag_iterator(MItDag::kDepthFirst, MFn::kTransform, &status); - if (!status) { + if (status != MStatus::kSuccess) { status.perror("MItDag constructor"); return false; } @@ -374,7 +398,7 @@ collect_shaders() { while (!dag_iterator.isDone()) { MDagPath dag_path; status = dag_iterator.getPath(dag_path); - if (!status) { + if (status != MStatus::kSuccess) { status.perror("MItDag::getPath"); } else { if (!collect_shader_for_node(dag_path)) { @@ -403,7 +427,7 @@ bool MayaCopy:: collect_shader_for_node(const MDagPath &dag_path) { MStatus status; MFnDagNode dag_node(dag_path, &status); - if (!status) { + if (status != MStatus::kSuccess) { status.perror("MFnDagNode constructor"); return false; } diff --git a/pandatool/src/mayaprogs/mayapath.cxx b/pandatool/src/mayaprogs/mayapath.cxx index 2ec5f54fa7..312b54f03b 100755 --- a/pandatool/src/mayaprogs/mayapath.cxx +++ b/pandatool/src/mayaprogs/mayapath.cxx @@ -51,6 +51,7 @@ main(int argc, char *argv[]) { // Now look up $MAYA_LOCATION. We insist that it be set and // pointing to an actual Maya installation. Filename maya_location = Filename::expand_from("$MAYA_LOCATION"); + cerr << "MAYA_LOCATION: " << maya_location << endl; if (maya_location.empty()) { cerr << "$MAYA_LOCATION is not set!\n"; exit(1);