//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ #include #include #include #include #include #include #include #include DeclareSimpleCommand( listPolyHoles, "Alias", "4.5"); MStatus listPolyHoles::doIt( const MArgList& args ) // // Description: // Implements the MEL listPolyHoles command. This command outputs a list // of all the holes in each selected polymesh. // // Arguments: // args - the argument list that was passes to the command from MEL. This // command takes no arguments. // // Return Value: // MS::kSuccess - command succeeded // MS::kFailure - command failed (returning this value will cause the // MEL script that is being run to terminate unless the // error is caught using a "catch" statement. // { MStatus stat = MS::kSuccess; MSelectionList curSel; MGlobal::getActiveSelectionList( curSel ); printf("\n"); printf("*****************\n"); printf("* listPolyHoles *\n" ); printf("*****************\n" ); // iterate through the selection list, and find holes in any selected // polygons. // int numSelected = curSel.length(); for( int s = 0; s < numSelected; s++ ) { MDagPath dagPath; MObject node; // get the selected item, figure out if it's a polymesh or not // curSel.getDagPath( s, dagPath ); if( dagPath.extendToShape() != MS::kSuccess ) { // selection does not correspond to a DAG shape // printf( " Error - object is not a polymesh\n" ); stat = MS::kFailure; return stat; } node = dagPath.node(); MFnDependencyNode fnNode( node ); printf( "\nLooking for holes in %s\n", fnNode.name().asChar() ); MStatus polyStatus; MFnMesh fnMesh( node, &polyStatus ); if( polyStatus == MS::kSuccess ) { // Retrieve the list of holes in the polymesh. // 'holeInfo' array stores 3 integers for each hole: // // [ face, numVertices, startIndex ] // // where 'face' is the index of the face in which the // hole is found, 'numVertices' is the number of vertices // that define the hole, and 'startIndex' is the starting // index of the list of hole vertices in the 'holeVertices' // array. // MIntArray holeInfo; // 'holeVertices' array contains a linear listing of the // vertices comprising all the holes in the selected polymesh. // information from the 'holeInfo' array is used to index into // this list to extract the list of vertices for each hole. // MIntArray holeVertices; MStatus holeStatus; holeInfo.clear(); holeVertices.clear(); // get the holes // int numHoles = fnMesh.getHoles( holeInfo, holeVertices, &holeStatus ); if( holeStatus == MS::kSuccess ) { printf( " Poly has %d holes\n", numHoles ); for( int h = 0; h < numHoles; h++ ) { // retrieve the hole face index, number of hole vertices, and // hole vertex list start index for the current hole. // int holeFace = holeInfo[3*h]; int holeNumVertices = holeInfo[3*h+1]; int holeStartIndex = holeInfo[3*h+2]; printf( " Hole %d:\n", h ); printf( " Face %d\n", holeFace ); printf( " Start index %d\n", holeStartIndex ); printf( " %d vertices: ", holeNumVertices ); // retrieve the hole vertex indices from the 'holeVertices' // array. The indices are a list of 'holeNumVertices' entries, // starting at index 'holeStartIndex'. // for( int v = 0; v < holeNumVertices; v++ ) { int index = holeStartIndex + v; printf( " %d ", holeVertices[index] ); } printf( "\n" ); } } else { // something went wrong trying to retrieve the poly holes // printf( " Error retrieving polygon holes\n" ); stat = MS::kFailure; } } else { // the current selection item was not a polymesh, so we can't retrieve // holes for it. // printf( " Error - object is not a polymesh\n" ); stat = MS::kFailure; } } setResult( "listPolyHoles completed." ); return stat; }