3
$\begingroup$

I've got a single texture that a couple dozen mesh objects are mapped to different bits of. I'd like to say, double the height of the texture so I have room to add some more things, which would require scaling the UVs on all these objects by 0.5y from the top. Is there some straightforward way to manage this automatically?

I don't want to just add an extra texture for what I'm doing since it's a relativly minor detail, and since I'm exporting this for a game I don't want the extra draw calls and two .dds files that that would involve.

$\endgroup$

1 Answer 1

1
$\begingroup$

Well, I puttered around in the python console and bashed this script together:

import bpy
for mesh in bpy.data.meshes:
    changed = 0
    usedverts = set()
    for face in mesh.polygons:
        for layer, texmap in enumerate(mesh.uv_textures):
            tex = texmap.data[face.index]
            if tex.image and tex.image.name == 'construction-facemelt.tga':
                for v in face.loop_indices:
                    if v not in usedverts:
                        uv = mesh.uv_layers[layer].data[v].uv
                        uv.y = uv.y / 2.0 + 0.5
                        changed += 1
                        usedverts.add(v)

    if changed > 0:
        print("Updated", changed, "UVs on", mesh.name)

I mostly put this together via console introspection and guesswork, so, there might be a lot of ways to do it better; I still barely understand the python blender api. But it works, and the bits to customize to make it work for another situation should be self-evident...

$\endgroup$

You must log in to answer this question.

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