//- // ========================================================================== // Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files contain unpublished // information proprietary to Autodesk, Inc. ("Autodesk") and/or its // licensors, which is protected by U.S. and Canadian federal copyright // law and by international treaties. // // The Data is provided for use exclusively by You. You have the right // to use, modify, and incorporate this Data into other products for // purposes authorized by the Autodesk software license agreement, // without fee. // // The copyright notices in the Software and this entire statement, // including the above license grant, this restriction and the // following disclaimer, must be included in all copies of the // Software, in whole or in part, and all derivative works of // the Software, unless such copies or derivative works are solely // in the form of machine-executable object code generated by a // source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. // AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED // WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF // NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR // PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR // TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS // BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, // DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK // AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY // OR PROBABILITY OF SUCH DAMAGES. // // ========================================================================== //+ // // Description: // This is an example of a command that exports smooth skin data from // maya to an alternate format. // // To use, type the command: // // exportSkinClusterData -f // // For example: // // exportSkinClusterData -f "C:/temp/skinData" // // The output format used is: // // skin_path_name vertex_count influence_count // influence_1 influence_2 influence_3 .... influence_n // vertex_index weight_1 weight_2 weight_3 ... weight_n // // Notes: // For each vertex index, a weight value is written out corresponding // to each of the n influence objects, even if the weight is 0. // // If all of the vertices in the skin are bound as skin, the vertex_count // will equal the total number of vertices in the skin object, and // the vertex_index values will be sequential. // However, if only some of the vertices were bound as skin, the vertex_count // will only reflect the count of skin vertices, and the vertex_index // values will be non-sequential. // // // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define CheckError(stat,msg) \ if ( MS::kSuccess != stat ) { \ displayError(msg); \ continue; \ } class exportSkinClusterData : public MPxCommand { public: exportSkinClusterData(); virtual ~exportSkinClusterData(); MStatus parseArgs( const MArgList& args ); MStatus doIt ( const MArgList& args ); MStatus redoIt (); MStatus undoIt (); bool isUndoable() const; static void* creator(); private: FILE* file; }; exportSkinClusterData::exportSkinClusterData(): file(NULL) { } exportSkinClusterData::~exportSkinClusterData() {} void* exportSkinClusterData::creator() { return new exportSkinClusterData; } bool exportSkinClusterData::isUndoable() const { return false; } MStatus exportSkinClusterData::undoIt() { return MS::kSuccess; } MStatus exportSkinClusterData::parseArgs( const MArgList& args ) // // There is one mandatory flag: -f/-file // { MStatus stat; MString arg; MString fileName; const MString fileFlag ("-f"); const MString fileFlagLong ("-file"); // Parse the arguments. for ( unsigned int i = 0; i < args.length(); i++ ) { arg = args.asString( i, &stat ); if (!stat) continue; if ( arg == fileFlag || arg == fileFlagLong ) { // get the file name // if (i == args.length()-1) { arg += ": must specify a file name"; displayError(arg); return MS::kFailure; } i++; args.get(i, fileName); } else { arg += ": unknown argument"; displayError(arg); return MS::kFailure; } } file = fopen(fileName.asChar(),"wb"); if (!file) { MString openError("Could not open: "); openError += fileName; displayError(openError); stat = MS::kFailure; } return stat; } MStatus exportSkinClusterData::doIt( const MArgList& args ) { // parse args to get the file name from the command-line // MStatus stat = parseArgs(args); if (stat != MS::kSuccess) { return stat; } unsigned int count = 0; // Iterate through graph and search for skinCluster nodes // MItDependencyNodes iter( MFn::kInvalid); for ( ; !iter.isDone(); iter.next() ) { MObject object = iter.item(); if (object.apiType() == MFn::kSkinClusterFilter) { count++; // For each skinCluster node, get the list of influence objects // MFnSkinCluster skinCluster(object); MDagPathArray infs; MStatus stat; unsigned int nInfs = skinCluster.influenceObjects(infs, &stat); CheckError(stat,"Error getting influence objects."); if (0 == nInfs) { stat = MS::kFailure; CheckError(stat,"Error: No influence objects found."); } // loop through the geometries affected by this cluster // unsigned int nGeoms = skinCluster.numOutputConnections(); for (unsigned int ii = 0; ii < nGeoms; ++ii) { unsigned int index = skinCluster.indexForOutputConnection(ii,&stat); CheckError(stat,"Error getting geometry index."); // get the dag path of the ii'th geometry // MDagPath skinPath; stat = skinCluster.getPathAtIndex(index,skinPath); CheckError(stat,"Error getting geometry path."); // iterate through the components of this geometry // MItGeometry gIter(skinPath); // print out the path name of the skin, vertexCount & influenceCount // fprintf(file, "%s %d %u\n",skinPath.partialPathName().asChar(), gIter.count(), nInfs); // print out the influence objects // for (unsigned int kk = 0; kk < nInfs; ++kk) { fprintf(file,"%s ",infs[kk].partialPathName().asChar()); } fprintf(file,"\n"); for ( /* nothing */ ; !gIter.isDone(); gIter.next() ) { MObject comp = gIter.component(&stat); CheckError(stat,"Error getting component."); // Get the weights for this vertex (one per influence object) // MDoubleArray wts; unsigned int infCount; stat = skinCluster.getWeights(skinPath,comp,wts,infCount); CheckError(stat,"Error getting weights."); if (0 == infCount) { stat = MS::kFailure; CheckError(stat,"Error: 0 influence objects."); } // Output the weight data for this vertex // fprintf(file,"%d ",gIter.index()); for (unsigned int jj = 0; jj < infCount ; ++jj ) { fprintf(file,"%f ",wts[jj]); } fprintf(file,"\n"); } } } } if (0 == count) { displayError("No skinClusters found in this scene."); } fclose(file); return MS::kSuccess; } MStatus exportSkinClusterData::redoIt() { clearResult(); setResult( (int) 1); return MS::kSuccess; } MStatus initializePlugin( MObject obj ) { MStatus status; MFnPlugin plugin( obj, PLUGIN_COMPANY, "3.0", "Any"); status = plugin.registerCommand( "exportSkinClusterData", exportSkinClusterData::creator ); if (!status) { status.perror("registerCommand"); return status; } return status; } MStatus uninitializePlugin( MObject obj ) { MStatus status; MFnPlugin plugin( obj ); status = plugin.deregisterCommand( "exportSkinClusterData" ); if (!status) { status.perror("deregisterCommand"); } return status; }