Thursday, February 21, 2013

Rotate Vertex Maya Api Plugin -- Part 1

This is still a work in progress, it doesnt yet do what I want. currently it only moves vertices in world y, it has no undo, it cant expect optional parameters ... But I thought this might be helpful.
(Note in includes remove the space after <, i put it so could be viewed in html) Before:


Inspired by Rick Parent (cse dot ohio-state dot edu) accessVertices.cpp

/**@file rotatePolyCmd.cpp
@brief v1.0.0 given selected polyShape it rotates all the vertices by 90 degrees
@author Nathaniel O. Anozie (ogbonnawork at gmail dot com)
@bug all functions no assert checks
@note date created: 02/19/2013
@note this has some useful info for 
@note inspired by Rick Parent (cse dot ohio-state dot edu) accessVertices.cpp

//note remove < ..> space after < , i put so could be viewed in html
#include < maya/MSimple.h>
#include < maya/MGlobal.h>
//im guessing these are needed almost always
//printing stuff, selecting stuff
#include < maya/MItSelectionList.h>

//need iterating for polygon vertex
#include < maya/MFnMesh.h>
#include < maya/MPointArray.h>

//need finding outliner polys
#include < maya/MDagpath.h>

//the name used here is the command that will be typed in Maya like PolyEdit;
DeclareSimpleCommand( PolyEdit, "Autodesk", "8.0");

/**the names here needs to match that used in DeclareSimpleCommand
@note notice no dollar signs, also we
@note need to do search manual to figure out the kind of thing that will help us find keyframes
@note the ampersand is alot different from MEL cause in MEL
@note i think only arrays are passed by reference
@note here a boolean type thing can be edited somewhere else and we can see what we got for error checking            
MStatus PolyEdit::doIt( const MArgList& )
    //i'm not sure if this is required in some cases
    MStatus stat = MS::kSuccess;
    MSelectionList selList;
    //not yet any restrictions 
    MItSelectionList polyIt(selList); //not in MGlobal
    //get poly meshes only
    //MFnMesh mesh;  //can use this and setObject(dagPath)  to print the mesh looking at
    MDagPath meshDag;
    //change poly vertex location for all selected polys
    for( polyIt.reset(); !polyIt.isDone(); )
        polyIt.getDagPath(meshDag); //saves how to find this poly from outliner
        //not using getDependNode because its not a backend node
        //get vertices of this mesh using a helper for polys
        MFnMesh fnMesh(meshDag); 
        MPointArray vtxList;
        fnMesh.getPoints( vtxList, MSpace::kObject );//getPoints and setPoints help to change our poly

        //move all vertices by 10 units up in y
        unsigned delta = 10;
        for( unsigned  i = 0; i < vtxList.length(); i++ )
            MPoint pnt = vtxList[i];
            pnt.y = pnt.y + delta;
            vtxList[i] = pnt;//i think cartesianize allows 3 places automatically for each element so can do this
        fnMesh.setPoints(vtxList); // move our poly vertices
    }//end poly loop
 return MS::kSuccess;

For a macbook this was the making of the .bundle that well use in Maya:
g++ -c rotatePolyCmd.cpp -arch i386 -DMAC_PLUGIN -DOSMac_MachO_ -DBits32_ -m32 -DUNIX -D_BOOL -DOSMac_ -DFUNCPROTO -D_GNU_SOURCE  -fPIC -fno-strict-aliasing -DREQUIRE_IOSTREAM -Wno-deprecated -Wall -Wno-multichar -Wno-comment -Wno-sign-compare -funsigned-char -Wno-reorder -fno-gnu-keywords -ftemplate-depth-25 -pthread -Wno-deprecated -fno-gnu-keywords -g   -I/Applications/Autodesk/maya2008/devkit/include -o rotatePolyCmd.o

g++ rotatePolyCmd.o -ldl -shared -L/Applications/ -lOpenMaya -lFoundation -Wl,-executable_path,/Applications/ -lFoundation -lOpenMaya -framework OpenGL -o rotatePolyCmd.bundle