1
$\begingroup$

While unwrapping for Unity 3D game development "UV vertex" count is an important aspect.

I was reading this GPU: Optimizing Model Geometry It says "Try to keep the number of UV mapping seams and hard edges (doubled-up vertices) as low as possible"

ie. Every time i create a seam or split UV i double that many nulber of UV vertices. If so ...

How do i find out what is the total and individual object UV vertex count in Blender ?

Is there a script to find UV vertex count?

$\endgroup$
  • 2
    $\begingroup$ What do you mean by "UV count"? I've done extensive work in Unity for several years and I've never heard of a "UV count" $\endgroup$ – Keith M Jan 13 '16 at 6:30
  • $\begingroup$ @ Keith M, sorry i was not very clear in my question i feel. If you go by this link "GPU: Optimizing Model Geometry" docs.unity3d.com/355/Documentation/Manual/… Try to keep the number of UV mapping seams and hard edges (doubled-up vertices) as low as possible Do they mean UV vertex count? if so how to find it out? $\endgroup$ – ashwin Jan 13 '16 at 10:55
  • $\begingroup$ Working for 15 years with games his is pretty trivial stuff. You don't optimize the UV vert count, you make UVs according to your texturing needs. $\endgroup$ – kheetor Oct 11 '16 at 5:56
1
$\begingroup$

This is a little rushed, and I still need to test it a little bit more, but it seems to return the correct number of UV vertices for simple meshes. UV unwrap your mesh and run this script in object mode:

import bpy
from collections import defaultdict

mesh=bpy.context.active_object.data

uv_layer = mesh.uv_layers[0].data
verts=defaultdict(list)
loc=defaultdict(list)
count=0

for p in mesh.polygons:
    for l in p.loop_indices:
        index = mesh.loops[l].vertex_index
        uv = uv_layer[l].uv 
        co = mesh.vertices[index].co
        if (len(verts[index]) == 0):

            verts[index].append(round(uv.x,2))
            verts[index].append(round(uv.y,2))

            loc[index].append(round(co.x,2))
            loc[index].append(round(co.y,2))
            loc[index].append(round(co.z,2))

            count+=1
        else:
            uvs=verts[index]
            if(uv.x!=uvs[0] or uv.y!=uvs[1]):
                nIndex=len(verts.keys())

                while(len(verts[nIndex])>0):
                    nIndex+=1

                verts[nIndex].append(round(uv.x,2))
                verts[nIndex].append(round(uv.y,2))

                loc[nIndex].append(round(co.x,2))
                loc[nIndex].append(round(co.y,2))
                loc[nIndex].append(round(co.z,2))
                count+=1   

uvco=[]

for f, b in zip(verts.items(), loc.items()):
    uvs1 = f[1]
    locs1 = b[1]

    for j, k in zip(verts.items(), loc.items()):
        uvs2 = j[1]
        locs2 = k[1]

        if (uvs1[0] == uvs2[0] and uvs1[1] == uvs2[1] and locs1[0] == locs2[0] and locs1[1] == locs2[1] and locs1[2] == locs2[2]):
            uvco.append((uvs1[0],uvs1[1],locs1[0],locs1[1],locs1[2]))


duplicatesStripped = set(tuple(i) for i in uvco) 

print("Unique UV/Vertex coordinates: %s\n" %  duplicatesStripped)   

print("There are %d UV vertices" % len(duplicatesStripped)) 

It's a little bit very messy, but I have to go to lunch now, I'll continue testing it when I get back

$\endgroup$
0
$\begingroup$

This will print the UV vertex count of active UV layer of active object in Object Mode (does not work in edit mode):

import bpy

obj = bpy.context.active_object

# Store all UV vertex locations
uv_coords = []
for loop in obj.data.loops:
    uv_loc = obj.data.uv_layers.active.data[loop.index].uv
    uv_coords.append(tuple(map(lambda x: round(x,3), uv_loc[:])))

# Keep only the unique ones and count them
print("object {0} has {1} UV vertices".format(obj.name, len(set(uv_coords))))
$\endgroup$
  • $\begingroup$ @ Jerryno thank you. Sorry that i had not written my question clearly. Now i have added more details. I want to find count of "UV vertices" $\endgroup$ – ashwin Jan 13 '16 at 11:16
  • $\begingroup$ I think the answer you want is a (total object verts - total uv verts) $\endgroup$ – zeffii Jan 13 '16 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.