Get the furthest tiles covered by a UV map in Blender

Typically, a mesh’s UV map in Blender is confined to the base tile — the sector with coordinates ranging from zero to one. However, the UV map can easily be scaled so that its points extend beyond these limits. To avoid disrupting texture tiling, it is often necessary to know exactly how many tiles the map spans in each of the four directions. A simple script can be used to determine how far the map extends from the base tile.

Let’s designate the base UV tile, with coordinates (0.0, 0.0) to (1.0, 1.0), as tile number 1. Tiles along the X-axis in the positive region would then be numbered 2, 3, 4, etc., while those in the negative region would be -1, -2, etc. The same applies to the Y-axis.

We will get whether the scaled UV map extends beyond this base tile and, if so, how many sectors it covers along the X and Y axes.

The currently active object is initially in Edit Mode. To ensure accurate calculations within the script, we need to switch to Object Mode.

Get a pointer to the object’s currently active UV map.

Iterate through all the mesh polygons and compile a list of mesh loops from them.

Now, let’s write a simple function that breaks down our list of mesh loops into X and Y coordinates and finds the minimum and maximum coordinate values ​​for both axes.

Inside the function, we also round the coordinates of the points to convert the coordinate values ​​into tile indices.

Now we can call the function and pass the list of mesh loops we obtained as an argument.

The function’s output shows that, along the X-axis, the object’s UV map starts at tile index -1 and ends at tile index 2. The same by the Y-axis. Consequently, the UV map spans 3 tiles vertically and 3 tiles horizontally.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted