Fix the mangled faces.

I /did/ see the warning about vertex index 0 in the obj importer script,
but I didn't take it seriously enough. This fixes both the twisted texture
on a couple of faces, and the truly mangled tris when exporting (using
invisibl.mdl for testing).
This commit is contained in:
Bill Currie 2011-09-24 09:00:14 +09:00
parent a1d9e752cd
commit bd840726c2
2 changed files with 15 additions and 8 deletions

View file

@ -96,8 +96,11 @@ def build_tris(mesh):
vertmap = [] # map mdl vert num to blender vert num (for 3d verts)
uvdict = {}
for face, uvface in map(lambda a,b: (a,b), mesh.faces, uvfaces):
fv = tuple(face.vertices)
uv = tuple(uvface.uv)
fv = list(face.vertices)
uv = list(uvface.uv)
# blender's and quake's vertex order seem to be opposed
fv.reverse()
uv.reverse()
tv = []
for v, u in map(lambda a,b: (a,b), fv, uv):
k = tuple(u)
@ -106,8 +109,6 @@ def build_tris(mesh):
vertmap.append(v)
stverts.append(u)
tv.append(uvdict[k])
# blender's and quake's vertex order seem to be opposed
tv.reverse()
tris.append(MDL.Tri(tv))
return tris, stverts, vertmap

View file

@ -48,9 +48,7 @@ def make_faces(mdl):
faces = []
uvs = []
for tri in mdl.tris:
tv = tri.verts
tv = tv[2], tv[1], tv[0] # flip the normal by reversing the winding
faces.append (tv)
tv = list(tri.verts)
sts = []
for v in tri.verts:
stv = mdl.stverts[v]
@ -61,7 +59,15 @@ def make_faces(mdl):
# quake textures are top to bottom, but blender images
# are bottom to top
sts.append((s * 1.0 / mdl.skinwidth, 1 - t * 1.0 / mdl.skinheight))
sts = sts[2], sts[1], sts[0] # to match face vert reversal
# blender's and quake's vertex order seem to be opposed
tv.reverse()
sts.reverse()
# annoyingly, blender can't have 0 in the final vertex, so rotate the
# face vertices and uvs
if not tv[2]:
tv = [tv[2]] + tv[:2]
sts = [sts[2]] + sts[:2]
faces.append (tv)
uvs.append(sts)
return faces, uvs