Add support for meshes with multiple UV maps.

One common use for a mesh having multiple UV maps is when combining several
mesh objects into one: the base UV map is the result of joining the meshes
(and will be a right mess of overlapping UV islands), but an additional UV
map is then setup as a copy of the first but with the islands re-packed so
nothing overlaps. The export script now searches for the active UV map and
uses that for both UV coordinates and the skin texture (when none is
specified).
This commit is contained in:
Bill Currie 2012-08-12 13:38:12 +09:00
parent 5b054dd98b
commit af0db29981

View file

@ -84,13 +84,19 @@ def null_skin(size):
skin.pixels = bytearray(size[0] * size[1]) # black skin
return skin
def active_uv(mesh):
for uvt in mesh.uv_textures:
if uvt.active:
return uvt
return None
def make_skin(mdl, mesh):
if (not mesh.uv_textures or not mesh.uv_textures[0].data
or not mesh.uv_textures[0].data[0].image):
uvt = active_uv(mesh)
if (not uvt or not uvt.data or not uvt.data[0].image):
mdl.skinwidth, mdl.skinheight = (4, 4)
skin = null_skin((mdl.skinwidth, mdl.skinheight))
else:
image = mesh.uv_textures[0].data[0].image
image = uvt.data[0].image
mdl.skinwidth, mdl.skinheight = image.size
skin = convert_image(image)
mdl.skins.append(skin)
@ -105,7 +111,8 @@ def build_tris(mesh):
# the layout. However, there seems to be nothing in the mdl format
# preventing the use of duplicate 3d vertices to allow complete freedom
# of the UV layout.
uvfaces = mesh.uv_layers[0].data
uvtex = active_uv(mesh)
uvfaces = mesh.uv_layers[uvtex.name].data
stverts = []
tris = []
vertmap = [] # map mdl vert num to blender vert num (for 3d verts)