Archive for January, 2009

UV Correction From Active

Posted in Blender Python Scripts with tags , , , on January 22, 2009 by 4museman

Description

This script can copy the UV map from one object to another, while these two objects doesn’t need to be exactly the same. It will copy the UV coordinates of only those parts, that match each other in both models, ignoring the rest. It proceeds per vertex, so it can correct only some vertices within a single face and leave some other as they are.

It can become very handy for correcting UV maps, when reducing polycount of already textured models (e.g. during making of LODs), or other modifications on models with already finished UV mapped textures. The only precondition for use of this functionality is to have the original model with unbroken UV map(s) available.

So, if you need just to reduce a polycount on a single model, make a copy and reduce it. Then use this script to “copy” UVs from the original model.

Note: Unfortunately, Blender is still not capable (2008-09-21) to handle UV maps correctly while eliminating vertices and edges with some tools, so the UVs will remain unedited and broken. These tools are mainly from the menu Merge (except the Collapse function, that takes care of UVs) and the function Edge Loop from the menu Erase. These functions don’t correct UVs while transforming at the time.
separator

Download

Download the ZIP file “object_uv_correction.zip“.
separator

Installation

Unpack content of ZIP file to your Blender script folder (under Windows typically something like: “C:\Program Files\Blender Foundation\Blender\.blender\scripts\”) or to the user defined path specified in your Blender in User Preferences under bookmark File Paths in the text input field titled “Python:“. Run (or restart) your Blender and you’ll find the new script in menu “Object –> Scripts –> UV Correction from Active“.

Note: It is possible to install scripts while Blender is running without the need of its restarting by extracting script files to one of the above mentioned locations and then pressing the Re-evaluation button, which you can find in user preferences under bookmark File Paths at the end of path input field labeled “Python:“. That will cause reloading of all available scripts into menus within whole Blender.
separator

Usage

First create a copy of the model (Shift-D) and reduce the copy. Now we have two models – original with undisturbed UV Map and the copy with damaged UV Map.
original model with UV map
reduced model with broken UV map

Chose the reduced model and then the original (the original have to become the active object – displayed with lighter color) and run the script.

Run the script...

UV maps should be corrected in reduced model.

corrected UV Map in reduced model

In some cases the script goes wrong and mix up the indexes of the face vertices (maybe some error of the Blender Python API). I’ll try to correct this flaw someday, but even with this the script can help oftentimes. It can markedly reduce annoying job on large models.
separator

LOG

(+ = added, = changed, = removed)

2007-12-13 - version 0.1
+ basic functionality

separator

ToDo

correct the cases when the vertices are moved to incorrect positions (wrong vertex indexes)
add the custom tolerance for compared vertices (maybe it could even help to solve the previous problem)