Python API 2.0 colorSets and uvSets

Python API 2.0 colorSets and uvSets

Anonymous
Not applicable
1,648 Views
4 Replies
Message 1 of 5

Python API 2.0 colorSets and uvSets

Anonymous
Not applicable

Hey guys in API 1.0 there seem to be some methods (albeit undocumented) on MFnMesh

 

createColorSetWithNameDataMesh
createUVSetDataMeshWithName

Which seem to allow you to create colorSets and UVSets within the compute of your nodes (without needing a handle to a maya mesh node).

 

These methods seem to be missing from API 2.0 - any plans for them to come over?

 

Im porting some plugins over to API 2.0 for the performance goodness and would love these methods.

 

Bonus question: Why are they undocumented in the first place? is their use discouraged?

 

Appreciate any help!

Phil

0 Likes
1,649 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

I'm upping this thread cause I have the same need, I'm creating a deformer node that must create an arbitrary number of colorSet, it seem I can create a colorset using "createColorSetDataMesh" but then I cannot use the 'setCurrentColorSetName' to define which color set to work with in the compute() method, I can only set color for the first ColorSet I created.

 

any though ?

 

Thanks !

0 Likes
Message 3 of 5

Anonymous
Not applicable

I think we have slightly different needs, the method createColorSetDataMesh doesnt even exist in OpenMaya api 2.0...

 

Setting colors on a named colorSet _is_ possible though, just a little convoluted. You need to create "colorID"s - kind of an indexed list of colors - then assign IDs per vertex per face. The following code will set all verts on a mesh named "pSphereShape3" to blue, only for the color set "colorSet2".

 

mesh_name = "pSphereShape3"
color_set_name = "colorSet2"

sel_list = om.MSelectionList()
sel_list.add(mesh_name)

dag_path = sel_list.getDagPath(0)
mesh = om.MFnMesh(dag_path)

# create a color per vertex (CPV)
colors = [om.MColor([0, 0, 1]) for _ in range(mesh.numVertices)]
color_ids = [i for i in range(mesh.numVertices)]

color_id_assignments = []  # sequence of ints
# assign a CPV index to each face vertex
for polygon_id in range(mesh.numPolygons):
    polygon_vertex_ids = mesh.getPolygonVertices(polygon_id)
    for vertex_id in polygon_vertex_ids:
        color_id_assignments.append(vertex_id)

mesh.setSomeColors(color_ids, colors, color_set_name)
mesh.assignColors(color_id_assignments, color_set_name)

Hope that helps!

Message 4 of 5

Anonymous
Not applicable

yes I'm sorry, I noticed you was asking for the python api, I was using the C++ api, which still have the "createColorSetDataMesh"

I did find out about the setColors() and assignColors() (thanks to the alembic plugin source code exemple), I could finally generate as much colorSet as I wanted for my node.

 

Thanks

0 Likes
Message 5 of 5

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

It was logged in our system and I've added your input to the case. Our enigneers will look on it.

 

Yours,

Li

0 Likes