From af0db299816a51a45dd80ddf84b2f7a262c27d8f Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 12 Aug 2012 13:38:12 +0900 Subject: [PATCH] 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). --- tools/io_mesh_qfmdl/export_mdl.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/io_mesh_qfmdl/export_mdl.py b/tools/io_mesh_qfmdl/export_mdl.py index 91f0757ac..fafb412b3 100644 --- a/tools/io_mesh_qfmdl/export_mdl.py +++ b/tools/io_mesh_qfmdl/export_mdl.py @@ -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)