Maya API: split vertex or edge

I am writing a mesh modifier node in Maya. The API, specifically the MFnMesh class, has lots of useful functions for modifying the mesh, like addPolygon, extractFaces, and setPoint. However, I can’t find any functions to split a vertex or an edge. (The MEL equivalents are polySplitVertex and polySplitEdge.) How can I split a vertex or edge in the API?

Heya Rebecca!
This functionality MAY change in 2013, but currently, there is MFnMesh::split which is the analog to the poly split tool.
It can be a bit confusing at first and it took me a little digging to figure it out.

Parameters:
[in] placements – Make this an intArray with one entry for each split in your command (MIntArray placements{ MFnMesh:: kOnEdge , MFnMesh:: kInternalPoint ,… etc
}

[in] edgeList – edge ids for each split, corresponds to the placement parameter. (MIntArray edgeList {23,45} ) in this case, edge 23 will be split on the edge and edge 45 will be split internally.

[in] edgeFactors – this is the % up the edge for the split to occur. (MFloatArray edgeFactors {0.5f,0.25f}) — here, edge 23 is split on the edge and in the middle , edge 45 is split internally, ¼ of the way along the edge.

[in] internalPoints – these are the points that are added inside the mesh for internal placements. In this case you’ll need one to go along with your internal split for edge #45. (MFloatPointArray internalPoints{MFloatPoint(19.3f, 0.0f, 22.1f)} . this will create an internal vertex for the split at (19.3f, 0.0f, 22.1f). the should obviously be a point inside the appropriate face. The split will create an edge from this point to ¼ of the way along edge 45.

HTH! GL

Hey Pete!
Thanks for the help. I will try that out and report back later on the results. :):

Well, no luck so far. The split command works fine if I go from one edge to another edge (splitting a poly). However it is unhappy if I try to use the endpoints of a single edge (or any two points on the same edge). I also tried to trick it by using different edges, by picking the endpoint of the second edge that is also the endpoint of the first edge. Every time, I got the error message:

Error: (kInvalidParameter): Cannot find item of the required type

So now I’m trying to see if I can replicate the polySplitVertex/polySplitEdge functionality through some combination of API functions: split, delete, extrude, extract, collapse, etc.

All, right. I found a workaround. It may not be the fastest or most elegant solution, but it seems to work:

  1. Start with two edges, E1 and E2, connected by a single vertex, V0.
  2. Get a list of all faces between the two edges. (That is, get all faces that are connected to V0 and form a continuous fan between E1 and E2.)
  3. Do an extrudeFaces on the listed faces. Something like meshFn.extrudeFaces(faceGroupArray, 1, zeroTranslationVector, True)
  4. The extrude operation forms a “border” of faces around the original group of faces. Find and make a list of these border faces.
  5. Now find all edges that have a border face on each side, and add them to a list of edgesToCollapse, UNLESS the edge has V0 as an endpoint.
  6. Do a collapseEdges operation on the specified edges. Something like meshFn.collapseEdges(edgesToCollapse).
  7. There should now be two remaining border faces left. These are the two faces touching V0. Find these and delete them. (Note that the mesh information changes after both collapseEdges and deleteFace. So you can’t just use the two remaining border face IDs from earlier, because they are most likely invalid.)
  8. Done!