Isotropix Forums

detect UDIM (or uv tile or uv range) on an object

Clarisse Scripting related topics

detect UDIM (or uv tile or uv range) on an object

Unread postby bvz2000 » Wed Apr 05, 2017 9:26 pm

I am trying to script up an automatic baking system that will write out one map per UDIM on an object.

Specifically, I intend the tool to work like this (written in python):

Select a number of objects.
Run the tool.
It will create one image node per selected object, and set the 3D layer on that image node to be a UV Bake node, have the appropriate object as its bake object, set the UV range to match the UDIM tile that that object is using, and to name the image node with the appropriate UDIM value.

I can see how to do almost all of this, except for the bit where I detect the UV range being used for the selected object.

I have found some documentation on GeometryUvMapData, but I don't understand exactly what it does, or how to use it if it helps me solve my issue.

So, my question is this:

Is there a way, given a piece of geo, to find the UV range that that geo occupies? From there I can figure out the UDIM's and so on quite easily.
bvz2000
 
Posts: 311
Joined: Thu Nov 13, 2014 7:05 pm

Re: detect UDIM (or uv tile or uv range) on an object

Unread postby anemoff » Thu Apr 06, 2017 11:03 am

Hi,

Here is a script example that shows the different UV map information you can get from a geometry object.

python code

object = ix.selection[0] # Just for demo purpose, get the first object in the selection

if object.is_kindof("Geometry"):
# Get the geometry: use True to get the deformed/animated geometry (default value), False otherwise
geometry = object.get_module().get_geometry(False)

# Check UV map count
if geometry.get_uv_map_count() > 0:
# You can get an UV map by its index (range: 0 to count - 1)
first_uv_map = ix.api.GeometryUvMap()
geometry.get_uv_map(0, first_uv_map)

# Or get all of them
uv_maps = ix.api.GeometryUvMapArray()
geometry.get_uv_maps(uv_maps)
for uv_map in uv_maps:
print "UV map name:", uv_map.name

# Get the UV range of the current UV map
# (there's a variant that takes an UV map index instead too)
uv_range = geometry.get_uv_range(uv_map)

# Get all the non-empty UV tiles for the current UV map
uv_tiles = ix.api.GeometryUvTileArray()
geometry.get_uv_tiles(uv_map, uv_tiles)

valid_udims = []
for uv_tile in uv_tiles:
# An UDIM index is valid only for positive U and V values
if (uv_tile.tu >= 0) and (uv_tile.tv >= 0):
valid_udims.append(uv_tile.get_udim())

print "Non-empty UDIM tiles:", valid_udims
for udim in valid_udims:
print "Doing something with UDIM", udim, "..."


I guess the last part, where we fetch the UDIM tile indices, is what you were looking for.

Cheers.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 49
Joined: Wed Jan 13, 2016 11:10 am

Re: detect UDIM (or uv tile or uv range) on an object

Unread postby bvz2000 » Thu Apr 06, 2017 6:44 pm

This is better than I had hoped for! Thank you.
bvz2000
 
Posts: 311
Joined: Thu Nov 13, 2014 7:05 pm


Return to Scripting