//- // ========================================================================== // 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. // ========================================================================== //+ // DISCLAIMER: THIS PLUGIN IS PROVIDED AS IS. IT IS NOT SUPPORTED BY // ALIAS, SO PLEASE USE AND MODIFY AT YOUR OWN RISK. // // PLUGIN NAME: Convert Vertices To Contained Faces Command v1.0 // FILE: convertVerticesToFacesCmd.cpp // DESCRIPTION: o MEL command that converts a selection of vertices into a selection of faces that interconnect // the original vertices (i.e. only faces whose composite vertices are contained in the original // vertex selection). The command's return value is a string array that contains the names of all // of the new contained faces. // o This MEL command has no flags, returns a string array, and operates on selected vertices. // o Example MEL usage: // select -r pCube1.vtx[0:5]; // string $convertedFaces[] = `convertVerticesToFaces`; // // Result: pCube1.f[0:1] // // AUTHOR: QT // LAST UPDATED: Oct. 11th, 2001. // TESTED ON: Maya 4.0 on Windows // STEPS TO INSTALL: 1) Unzip the file convertVerticesToFaces_v1_0_Maya4_Windows.zip to any temporary directory. // 2) Copy the file convertVerticesToFacesCmd.mll to: /AW/Maya4.0/bin/plug-ins/ // 3) Launch Maya and load the plugin from Windows->Setting/Preferences->Plugin Manager. // BEGIN PLUGIN: // ============= // HEADER FILES: #include #include #include #include #include #include #include #include #include // MAIN CLASS FOR THE MEL COMMAND: class convertVerticesToContainedFacesCommand : public MPxCommand { public: convertVerticesToContainedFacesCommand(); virtual ~convertVerticesToContainedFacesCommand(); static void* creator(); bool isUndoable() const; MStatus doIt(const MArgList&); MStatus redoIt(); MStatus undoIt(); private: MSelectionList previousSelectionList; }; // CONSTRUCTOR: convertVerticesToContainedFacesCommand::convertVerticesToContainedFacesCommand() { } // DESTRUCTOR CLEARS, AND FREES MEMORY OF THE PREVIOUS SELECTION LIST: convertVerticesToContainedFacesCommand::~convertVerticesToContainedFacesCommand() { previousSelectionList.clear(); } // FOR CREATING AN INSTANCE OF THIS COMMAND: void* convertVerticesToContainedFacesCommand::creator() { return new convertVerticesToContainedFacesCommand; } // MAKE THIS COMMAND UNDOABLE: bool convertVerticesToContainedFacesCommand::isUndoable() const { return true; } // SAVE THE PREVIOUS SELECTION, AND THEN CALL redoIt(), WHICH DOES MOST OF THE WORK: MStatus convertVerticesToContainedFacesCommand::doIt(const MArgList& args) { MGlobal::getActiveSelectionList(previousSelectionList); return redoIt(); } // CONVERTS THE SELECTED VERTICES TO "CONTAINED FACES", AND RETURN FROM THE MEL COMMAND, A STRING ARRAY OF THE NEW FACES: MStatus convertVerticesToContainedFacesCommand::redoIt() { MSelectionList finalFacesSelection; MDagPath meshDagPath; MObject multiVertexComponent, singleVertexComponent; int dummyIndex; // ITERATE THROUGH EACH "VERTEX COMPONENT" THAT IS CURRENTLY SELECTED: for (MItSelectionList vertexComponentIter(previousSelectionList, MFn::kMeshVertComponent); !vertexComponentIter.isDone(); vertexComponentIter.next()) { // STORE THE DAGPATH, COMPONENT OBJECT AND MESH NAME OF THE CURRENT VERTEX COMPONENT: vertexComponentIter.getDagPath(meshDagPath, multiVertexComponent); MString meshName = meshDagPath.fullPathName(); // VERTEX COMPONENT HAS TO CONTAIN AT LEAST ONE VERTEX: if (!multiVertexComponent.isNull()) { // ITERATE THROUGH EACH "VERTEX" IN THE CURRENT VERTEX COMPONENT: for (MItMeshVertex vertexIter(meshDagPath, multiVertexComponent); !vertexIter.isDone(); vertexIter.next()) { // FOR STORING THE FACES CONNECTED TO EACH VERTEX: MIntArray connectedFacesIndices; vertexIter.getConnectedFaces(connectedFacesIndices); // ITERATE THROUGH EACH FACE CONNECTED TO THE CURRENT VERTEX: MItMeshPolygon faceIter(meshDagPath); for (unsigned i=0; i