Normals are wrong

Hi,

I’m exporting animations in a MD2 similar manner. The vertex positions come right, but my normals are not. They all face up a lot, as if they were added ‘1’ to the vertical fraction.

My script:


...
        mesh=NMesh.GetRawFromObject(mesh_obj[0].name)
        for vert_counter in range(0, vert_count):
            vecpos = GlobalPosition(mesh.verts[vert_counter].co, mesh_obj[0])
            vecnor = GlobalPosition(mesh.verts[vert_counter].no, mesh_obj[0])
            vecnor = unify_vec3(vecnor) # they are longer than 1!?

            new_x=-vecpos[1]
            new_y= vecpos[2] # swap y/z
            new_z=-vecpos[0]

            nor_x= -vecnor[1]
            nor_y=  vecnor[2] # swap y/z
            nor_z= -vecnor[0]
            
            file.write("%.3f %.3f %.3f %.3f %.3f %.3f
" % (new_x, new_y, new_z, nor_x, nor_y, nor_z))
...

# unify a vector
def unify_vec3(v):
    l = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2])
    v[0]/=l;
    v[1]/=l;
    v[2]/=l;
    return v

# matrix(4x3) vector multiplication
def mulmatvec4x3(a, b):
    # a is vector, b is matrix
    r = [0, 0, 0]
    r[0] = a[0]*b[0][0] + a[1]*b[1][0] + a[2]*b[2][0] + b[3][0]
    r[1] = a[0]*b[0][1] + a[1]*b[1][1] + a[2]*b[2][1] + b[3][1]
    r[2] = a[0]*b[0][2] + a[1]*b[1][2] + a[2]*b[2][2] + b[3][2]
    return r

My model:
http://www.glbasic.com/beta/kitty.blend

http://www.directupload.com/thumb-26716.jpg
Here’s what I get.

Found the solution for me!! To get the final vertex and normals, I use this now:


        mesh=NMesh.GetRawFromObject(mesh_obj.name)
        mesh.transform(mesh_obj.matrix, 1)