Manipulating Objects, Part 3

We’ve covered getting geometry data from an existing object and building a new object from raw data. Now we’ll start looking at non-geometry related elements of a polygon object. Continue using the cube example from the previous parts in this series lets see how to get its UV information.

Start by creating a cube called Box.

Now get Box’s shape MObject as shown in Part 1. This will be used to confirm that we’re dealing with a poly mesh object.

The function set MFnMesh is used to retrieve the UV data from the mesh.

We’ll be using a few member functions from MFnMesh to get the UV information.

  • numUVSets(), use this to get the number of UV sets applied to the object.
  • numUVs(), use this to get the number of UVs the object contains.
  • getUVs(), use this to get each UVs U and V values.

The first two are straight forward and don’t warrant a more detailed explanation. However, getUVs() does requires two parameters be passed into the function. These are both MFloatArrays with no elements which getUVs() fills with the U and V data. Elements of a MFloatArray can be accessed the same as a Python list.

Running this code on our box produces the following print out. I’ve also included a couple images showing the locations of each UV.


UV locations on the box.


UV locations on the unwrapped geometry.

Here is the complete code for this post.