Currently creating a tool in the C++ api that performs vertex color operations - would like the user to be able to select a mesh, face, edge or individual vertices.
I can use MItMeshVertex to iterate over the vertices from a mesh or vertex selection, but not from a face or edge selection.
Any suggestions? I’m concerned that using MItMeshEdge and somehow extracting the vertices from each edge will perform operations on certain vertices twice as some edges will share vertices.
MItMeshPolygon may have what you’re looking for, i haven’t used it in a bit, but it does coalesce a bunch of functionality related to different component types.
hmm… I can’t seem to get MItMeshPolygon to work with an edge selection.
I’m using while iterating through the selection list, I’m using MItSelectionList::getDagPath to store the component selection as an MObject then using MItMeshVertex to iterate over the vertices in the selection.
As ‘component’ is an MObject, can I use a function set to perform vertex color operations? I tried to use MFnMesh, but that didn’t seem to work with an edge selection.
I’m fairly new to C++ and Maya API - so feel free to let me know if my code is retarded.
hmm MItGeometry looks like it might be a good start. It treats all component types as a list of points - if I select 3 edges in a row, and run MItGeometry::count() - it returns 4. Which is exactly what I want.
Guess I can add these points to a new vertex array somehow then iterate over them.
Try getting your MObject from your dagPath, wrapping a MFnComponent around it, then using componentType() method to check which component type is selected. If its, say, an edge, you can use MItMeshEdge to iterate over your selection, converting the edge’s to verts (MItMeshEdge has a point() method), and then getting those vertex ids.
The way to deal with vertex colors is using MFnMesh, but you’ll have to specifiy your particular vertices via their ids.
So if I have a point array with all selected vertices - how do I get this information to work with MFnMesh?
I think MItGeometry::allPositions() will give me the same final end result of using MItMeshEdge::Point() and adding the returned points to a point array.
You probably don’t actually want/need the position/point information of the verts at all. Get/use the indices instead.
For example, MItMeshEdge has an index() method, which gets the index number of the vertices attached to that edge. Call it twice:
index(0)
index(1)
to get each vertex index.
Now you have a list of vertex indices, you can call MFnMesh methods using those, eg:
setVertexColor, passing in each vertex index id.
sorry to bump this, as I have totally resolved everything previously asked, but to implement Undo - I presume I would have to somehow store the previous vertex colors of all the selected geometry? and reapply them?
If when iterate through the selection list, I store the vertexColors of the selection in a colorArray, can I add these to another type of array? then when undo is called, i iterate through the previous selection list and apply these colorArrays to the geo?