//--------------------------- String DocumentExporter::mayaNameToColladaName(const MString& str, bool removeNamespace, bool removeFirstNamespace) { // Replace characters that are supported in Maya, // but not supported in collada names if ( str == 0 ) return EMPTY_STRING; // NathanM: Strip off namespace prefixes // TODO: Should really be exposed as an option in the Exporter MString mayaName; if ( removeNamespace ) { int prefixIndex = str.rindex ( ':' ); mayaName = ( prefixIndex < 0 ) ? str : str.substring ( prefixIndex + 1, str.length() ); } else if (removeFirstNamespace) { // Keep potential '|' character at the beginning bool startsWithVerticalLine = str.index('|') == 0; int colonIndex = str.index(':'); mayaName = (colonIndex < 0) ? str : str.substring(colonIndex + 1, str.length()); if (colonIndex >= 0 && startsWithVerticalLine) { mayaName = MString("|") + mayaName; } } else mayaName = str; const char* c = mayaName.asChar(); uint length = mayaName.length(); char* buffer = new char[length+1]; // Replace offending characters by some that are supported within xml: // ':', '|' are replaced by '_'. // Ideally, these should be encoded as '%3A' for ':', etc. and decoded at import time. // for ( uint i = 0; i < length; ++i ) { char d = c[i]; if ( d == '|' || d == ':' || d == '/' || d == '\\' || d == '(' || d == ')' || d == '[' || d == ']' ) d = '_'; buffer[i] = d; } buffer[length] = '\0'; MString mayaReturnString ( buffer ); delete [] buffer; return COLLADABU::Utils::checkNCName( mayaReturnString.asChar() ); }
//--------------------------------------------------- void DagHelper::setArrayPlugSize ( MPlug& plug, uint size ) { if ( plug.node().isNull() ) return; #if MAYA_API_VERSION >= 800 MStatus status = plug.setNumElements ( size ); CHECK_STAT ( status ); #else MObject node = plug.node(); MString plugPath = plug.info(); if ( node.hasFn ( MFn::kDagNode ) ) { MFnDagNode dagFn ( node ); int dot = plugPath.index ( '.' ); plugPath = dagFn.fullPathName() + plugPath.substring ( dot, plugPath.length() ); } MString command = MString ( "setAttr -s " ) + size + " \"" + plugPath + "\";"; MGlobal::executeCommand ( command ); #endif // MAYA 8.00+ }
// ***************************************************************************** MStatus GtoIO::reader( const MFileObject &file, const MString &optionsString, MPxFileTranslator::FileAccessMode mode ) { MString filename = file.fullName(); bool readAsDifference = false; int fs = 0; int fe = 0; MStringArray args; optionsString.split( ';', args ); for( size_t i = 0; i < args.length(); ++i ) { MStringArray thisArg; args[i].split( '=', thisArg ); MString argName( thisArg[0] ); MString argValue( thisArg[1] ); if( argName == "readDiff" && argValue == "1" ) { readAsDifference = true; } else if( argName == "fs" ) { fs = argValue.asInt(); } else if( argName == "fe" ) { fe = argValue.asInt(); } } if( readAsDifference ) { MGlobal::displayInfo( "PreMunge name: " + filename ); if( filename.index( '#' ) < 0 ) { // By this point, Maya will have already appended a // ".gto" to the filename if the user didn't include it, // so we're guaranteed to find a '.' in the filename filename = filename.substring( 0, filename.index( '.' ) ) + "#.gto"; } for( int f = fs; f <= fe; ++f ) { MGlobal::viewFrame( MTime( double(f) ) ); MString fname = replaceFrameCookies( filename, f ); MGlobal::displayInfo( "Reading " + fname ); DataBase dataBase; Set *set = dataBase.set( fname.asChar() ); if( set == NULL ) { MGlobal::displayError( "Unable to open file for some " "reason. Permissions?" ); return MS::kFailure; } set->computeLocalTransforms(); set->declareMayaDiff(); dataBase.destroyAll(); } } else { DataBase dataBase; Set *set = dataBase.set( filename.asChar() ); if( set == NULL ) { MGlobal::displayError( "Unable to open file for some " "reason. Permissions?" ); return MS::kFailure; } set->computeLocalTransforms(); set->declareMaya(); set->reparentAll(); dataBase.destroyAll(); } return MS::kSuccess; }
// ***************************************************************************** MStatus GtoIO::writer( const MFileObject &file, const MString &optionsString, MPxFileTranslator::FileAccessMode mode ) { MTime fs = MAnimControl::currentTime(); MTime fe = fs; double shutter = 0.0; MString filename = file.fullName(); bool subd = false; bool normals = false; bool exportST = false; int maxRecurse = 1; bool normalize = false; bool hidden = true; bool verify = true; bool doAnim = false; bool diffPoints = false; bool diffMatrix = false; bool diffNormals = false; bool isDifferenceFile = false; bool quiet = false; bool allUserAttributes = false; bool allMayaAttributes = false; bool allXformAttributes = false; bool faceMaterials = false; bool ascii = false; if( ( mode == MPxFileTranslator::kExportAccessMode ) || ( mode == MPxFileTranslator::kSaveAccessMode ) ) { MGlobal::displayError( "The GTO plugin can only be used for Export " "Selection..."); return MS::kFailure; } MStringArray args; optionsString.split( ';', args ); for( size_t i = 0; i < args.length(); ++i ) { MStringArray thisArg; args[i].split( '=', thisArg ); MString argName( thisArg[0] ); MString argValue( thisArg[1] ); if( argName == "recurse" && argValue == "1" ) { maxRecurse = 100000; } else if( argName == "quiet" && argValue == "1" ) { quiet = true; } else if( argName == "ascii" && argValue == "1" ) { ascii = true; } else if( argName == "subd" && argValue == "1" ) { subd = true; } else if( argName == "normals" && argValue == "1" ) { normals = true; } else if( argName == "st" && argValue == "1" ) { exportST = true; } else if( argName == "faceMat" && argValue == "1" ) { faceMaterials = true; } else if( argName == "diffpositions" && argValue == "1" ) { diffPoints = true; } else if( argName == "diffmatrices" && argValue == "1" ) { diffMatrix = true; } else if( argName == "diffnormals" && argValue == "1" ) { diffNormals = true; } else if( argName == "isdifference" && argValue == "1" ) { isDifferenceFile = true; } else if( argName == "normalize" && argValue == "1" ) { normalize = true; } else if( argName == "hidden" && argValue == "0" ) { hidden = false; } else if( argName == "verify" && argValue == "0" ) { verify = false; } else if( argName == "userAttr" && argValue == "1" ) { allUserAttributes = true; } else if( argName == "mayaAttr" && argValue == "1" ) { allMayaAttributes = true; } else if( argName == "xformAttr" && argValue == "1" ) { allXformAttributes = true; } else if( argName == "anim" && argValue == "1" ) { doAnim = true; // If user didn't include a # in the filename, but // is exporting multiple frames, do it automatically if( filename.index( '#' ) < 0 ) { // By this point, Maya will have already appended a // ".gto" to the filename if the user didn't include it, // so we're guaranteed to find a '.' in the filename filename = filename.substring( 0, filename.rindex( '.' ) ) + "#.gto"; } } else if( argName == "fs" && doAnim ) { fs = MTime( argValue.asDouble(), MTime::uiUnit() ); } else if( argName == "fe" && doAnim ) { fe = MTime( argValue.asDouble(), MTime::uiUnit() ); } else if( argName == "shutter" && doAnim ) { shutter = argValue.asDouble() / 360.0; } else if( argName == "recurseLimit" ) { if( argValue.asInt() > 0 ) { maxRecurse = argValue.asInt(); } } } if( ! isDifferenceFile ) { diffPoints = false; diffMatrix = false; diffNormals = false; } // TODO: Find a more graceful way to get options to GtoExporter GtoExporter exporter( fs, fe, quiet, shutter, subd, normals, exportST, filename, maxRecurse, normalize, hidden, verify, isDifferenceFile, diffPoints, diffMatrix, diffNormals, allUserAttributes, allMayaAttributes, faceMaterials, ascii, allXformAttributes ); MStatus result = exporter.doIt(); return result; }
MString PRTAttrs::longName(const MString& attrName) { return prtu::toCleanId(attrName.substring(attrName.index('$') + 1, attrName.length())); }
// -------------------------------------- void ReferenceManager::processReference ( const MObject& referenceNode ) { MStatus status; MFnDependencyNode referenceNodeFn ( referenceNode, &status ); if (status != MStatus::kSuccess) return; #if MAYA_API_VERSION >= 600 MString referenceNodeName = MFnDependencyNode( referenceNode ).name(); Reference* reference = new Reference(); reference->referenceNode = referenceNode; mReferences.push_back ( reference ); // Get the paths of the root transforms included in this reference MObjectArray subReferences; getRootObjects ( referenceNode, reference->paths, subReferences ); uint pathCount = reference->paths.length(); // Process the sub-references first uint subReferenceCount = subReferences.length(); for (uint i = 0; i < subReferenceCount; ++i) { MObject& subReference = subReferences[i]; if ( subReference != MObject::kNullObj ) processReference ( subReference ); } // Retrieve the reference node's filename MString command = MString("reference -rfn \"") + referenceNodeFn.name() + MString("\" -q -filename;"); MString filename; status = MGlobal::executeCommand ( command, filename ); if (status != MStatus::kSuccess || filename.length() == 0) return; // Strip the filename of the multiple file token int stripIndex = filename.index('{'); if (stripIndex != -1) filename = filename.substring(0, stripIndex - 1); // Avoid transform look-ups on COLLADA references. int extLocation = filename.rindex('.'); if (extLocation > 0) { MString ext = filename.substring(extLocation + 1, filename.length() - 1).toLowerCase(); if (ext == "dae" || ext == "xml") return; } // Check for already existing file information // Otherwise create a new file information sheet with current node names for ( ReferenceFileList::iterator it = mFiles.begin(); it != mFiles.end(); ++it ) { if ((*it)->filename == filename) { reference->file = (*it); break; } } if ( reference->file == NULL ) reference->file = processReferenceFile(filename); // Get the list of the root transform's first child's unreferenced parents. // This is a list of the imported nodes! for (uint j = 0; j < pathCount; ++j) { MDagPath path = reference->paths[j]; if (path.childCount() > 0) { path.push ( path.child(0) ); MFnDagNode childNode ( path ); if (!childNode.object().hasFn(MFn::kTransform)) continue; uint parentCount = childNode.parentCount(); for (uint k = 0; k < parentCount; ++k) { MFnDagNode parentNode(childNode.parent(k)); if (parentNode.object() == MObject::kNullObj || parentNode.isFromReferencedFile()) continue; MDagPath parentPath = MDagPath::getAPathTo(parentNode.object()); if (parentPath.length() > 0) { ReferenceRootList::iterator it = reference->reroots.insert( reference->reroots.end(), ReferenceRoot() ); (*it).index = j; (*it).reroot = parentPath; } } } } #endif }
MString cgfxFindFile(const MString& name, const MString &searchpath) { struct stat statBuf; char path[MAX_PATH]; const char * psearchpath = searchpath.asChar(); OutputDebugString("File = "); OutputDebugString(name.asChar()); OutputDebugString("\n"); #ifdef _WIN32 const bool fullyQualified = name.index('/') == 0 || name.index('\\') == 0 || name.index(':') == 1; #else const bool fullyQualified = name.index('/') == 0 || name.index('\\') == 0; #endif // First we check if it is a fully qualified path... if (fullyQualified && stat(name.asChar(), &statBuf) != -1) { OutputDebugString("Returning fully qualified: "); OutputDebugString(name.asChar()); OutputDebugString("\n"); return name; } else { // Strip out any leading '/' at this point since the file has // not been found using a fully qualified path. MString resolvedName; if(name.index('/') == 0 || name.index('\\') == 0) resolvedName = name.substring(1, name.length() - 1); else resolvedName = name; while (psearchpath < searchpath.asChar() + searchpath.length()) { const char * endpath = strchr(psearchpath,';'); if (endpath) { strncpy(path,psearchpath, endpath - psearchpath); path[endpath - psearchpath] = '\0'; } else { strcpy(path,psearchpath); } psearchpath += strlen(path)+1; bool fullPath = (path[0] == '/' || path[0] == '\\'); if (strlen(path) > 2) { fullPath = fullPath || (path[1] == ':' && (path[2] == '/' || path[2] == '\\')); } // Add the path and the filename together to get the full path MString file; if(path[strlen(path) - 1] != '/') file = MString(path) + "/" + resolvedName; else file = MString(path) + resolvedName; OutputDebugString("Try File = "); OutputDebugString(file.asChar()); OutputDebugString("\n"); if (stat(file.asChar(), &statBuf) != -1) { OutputDebugString("Returning: "); OutputDebugString(file.asChar()); OutputDebugString("\n"); return file; } } OutputDebugString("Not found!\n"); return MString(); } }