I have written an importer script for a particular model format.
However, when i take a look at the meshes i import with the script in blender, there are large numbers of faces that are pointing the wrong way!
The model format uses triangle strips, so i had to convert them into triangles, but that shouldn't be a problem, since the format also stores vertex normals for every vertex, and therefor i would assume that they would have had a noticable affect on the meshes (aka they wouldn't be covered with faces facing the wrong way).
Here is my code :
Code: Select all
bmesh = NMesh.New() bmesh.setMode("NoVNormalsFlip","Optimal") bmesh.hasFaceUV(1) bmesh.hasVertexUV(1) bmesh.update(False) mesh.convertToTris() # Make sure we ONLY have triangles # Vertextes for vert in mesh.verts: bmesh.verts.append(NMesh.Vert(vert, vert, vert)) # Get sticky texture coords for count in range(0, len(mesh.tverts)): bmesh.verts[count].uvco = mesh.tverts[count] bmesh.verts[count].uvco = mesh.tverts[count] addMats =  for fac in mesh.primitives: verts =  # Import the face verts for vert in range(fac.firstElement, fac.firstElement+3): verts.append(bmesh.verts[mesh.indices[vert]]) bmesh.faces.append(NMesh.Face(verts)) del verts # cleanup # Normals for count in range(0, len(mesh.normals)): bmesh.verts[count].no = mesh.normals[count] bmesh.verts[count].no = mesh.normals[count] bmesh.verts[count].no = mesh.normals[count] # Finally plonk it into blender object = NMesh.PutRaw(bmesh, name, False) print "Put Mesh %s" % (name) meshCount += 1 return object
To convert the triangle strip into triangles, i simply keep going through its list of indices, incrementing the position by one and adding the triangle from that position.
e.g. 1234 -> 123 234