I want to have one pixel on the UV map per square for a voxel style model. I set the texture interpolation to "closest" (rather than linear).

enter image description here

I used "Smart UV project":

enter image description here

By hand counting the UV map I got 49 rows and 49 columns. Then I changed the texture to be 49 x 49 pixels. I want to use much higher detail meshes so I'd rather not have to hand count the rows and columns in the UV map.

Any ideas about doing this? Maybe there is a plugin or script?

BTW someone asked a similar question 3 years and 8 months ago and no one responded....

Dimensions of Smart Project UV Unwrap

Edit: It would be good if it can also handle when Decimate - Planar is used with voxel like meshes and Smart UV Project - it could detect the minimum size of a square then divide it by the width and height of the UV map... (which gives 49 in this example)

enter image description here

An idea - a script/plugin could look at all of the U coordinates and all of the V coordinates and see the minimum gap between them. In my example it should be 1/49 or 0.020408 in normalized units (0 to 1 for U and V).


1 Answer 1


You can parse the uvs of your mesh and count the coordinates that are different from each other.

A naive approach using the set data structure would be :

import bpy

x_pos = set()
y_pos = set()

for loop in bpy.context.active_object.data.uv_layers.active.data:
    # We round because of floating point precision error
    x_pos.add(round(loop.uv.x, 3)) 
    y_pos.add(round(loop.uv.y, 3))

rows, columns = len(x_pos) - 1, len(y_pos) - 1
print(rows)  # u
print(columns)  # v

This may be slow to execute if you have a very dense mesh. You can use numpy utilities to speed things up.

Inspired by this Q&A

uv_layers docs

MeshUVLoopLayer docs

  • $\begingroup$ Hi the torus is 25 x 25 x 5. What I'm after involves the UV map.... for the torus it is 49 x 49. Also sometimes Smart UV Project can offset some islands by half a square so it can be things like 10.5 x 10.5. The mesh isn't necessarily the same size in X and Y though the UV map is. $\endgroup$
    – Luke Wenke
    Mar 3, 2023 at 9:55
  • $\begingroup$ Also if I delete the bottom faces of the torus (which I'd usually do) the UV map becomes 43 x 43. $\endgroup$
    – Luke Wenke
    Mar 3, 2023 at 10:01
  • $\begingroup$ As far as the density of the mesh goes - it has nothing internally - and it has 1252 faces - and 450 when the decimate planar modifier is used. $\endgroup$
    – Luke Wenke
    Mar 3, 2023 at 10:08
  • $\begingroup$ Oh sorry I read it as project from view. I'll see about updating the answer $\endgroup$
    – Gorgious
    Mar 3, 2023 at 10:31
  • $\begingroup$ Rounding to 3 sometimes doesn't give the right results but 2 does. Sometimes Smart UV Project offsets squares by fractions of a row (e.g. 5 or 10%) which is a shame. $\endgroup$
    – Luke Wenke
    Mar 3, 2023 at 23:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .