12

I asked this question on Code Review, mistakenly thinking it was the proper place to review buggy code.

Is this question a good fit for Stack Overflow?


I am attempting to write a tangent-basis generation script. The input file is an obj, and the data is read into separate lists for each data type (verts, normals, tex-coords). Can you spot where the script is going wrong? The values I should be getting are not coming up (for a cude shaped object, the "tangents" are not perpendicular to the corresponding normals).

vertices gets filled with tuples of the format: (x,y,z) vertice_Tex_Coords gets filled with tuples of the format: (coord_X, coord_Y) vertices_Normals gets filled with tuples of the format: (norm_X,norm_Y,norm_Z) faces gets filled with tuples of the format: (vert1,vert2,vert3)

Faces holds the vertex indices from the object file. This entire data set is parsed pretty much the same way a obj file is generated actually.

vertices = []
converted_Vertices = []

vertice_Tex_Coords = []
converted_Vertice_Tex_Coords = []

vertice_Normals = []
converted_Vertice_Normals = []

tangent_Space_Matrices = [] # Probably going to remove this and replace with 'Tangents'/'Bi-Tangents'
# tangents = []
# bi_tangents = []

faces = []

# parse_Type = input("Type of file to parse? \n\n 0=Verts \n\n 1=Verts+Normals \n\n 2=Verts+Normals+UV's \n\n\n")
parse_Type = 2

#------------------------------------------------------------------------------#
#                        PARSE DATA TO SEPARATE LISTS                          #
#------------------------------------------------------------------------------#

for line in file_In:
    line = line.split()

    if len(line) !=0 and line[0] == 'v':
        vertices.append( tuple( [float(line[1]), float(line[2]), float(line[3])] ) )

    elif len(line) !=0 and line[0] == 'vt':
        vertice_Tex_Coords.append( tuple( [float(line[1]), float(line[2])] ) )

    elif len(line) !=0 and line[0] == 'vn':
        vertice_Normals.append( [float(line[1]), float(line[2]), float(line[3]) ] )

    # This set of rules determines which way to split faces
    elif len(line) !=0 and line[0] == 'f':

        if parse_Type == 0: # Handles Vertex-only format exports
            face_Pairs = []
            for pair in line[1:]:
                pair = pair.split('//')
                face_Pairs.append( [int(pair[0]),int(pair[1])] )
            faces.append(tuple(face_Pairs))

        elif parse_Type == 1: # Handles Vertex+Normals format exports
            face_Pairs = []
            for pair in line[1:]:
                pair = pair.split('//')
                face_Pairs.append( [int(pair[0]),int(pair[1])] )
            faces.append(tuple(face_Pairs))

        elif parse_Type == 2: # Handles Vertex+Normals+Tex-Coords format exports
            face_Pairs = []
            for pair in line[1:]:
                pair = pair.split('/')
                face_Pairs.append( [int(pair[0]),int(pair[1]),int(pair[2])] )
            faces.append(tuple(face_Pairs))

        elif parse_Type == 3:
            face_Pairs = []
            for pair in line[1:]:
                pair = pair.split('//')
                face_Pairs.append( [int(pair[0]),int(pair[1])] )
            faces.append(tuple(face_Pairs))


print "Length of list data: "
print len(vertices)
print len(vertice_Tex_Coords)
print len(vertice_Normals)

The following is the actual code which is supposed to generate the tangent vector (which gets cross-prod multiplied to get the bi-tangent.

def calc_Tangent_Space(vertices, converted_Vertices, vertice_Tex_Coords, converted_Vertice_Tex_Coords, vertice_Normals, converted_Vertice_Normals, faces):

    from numpy import array, cross, dot, where
    from numpy.linalg import norm, det
    from math import sqrt
    from decimal import *

    # Following sets precision of Decimal class operations
    setcontext(ExtendedContext)
    getcontext().prec = 6

    tangent_Space_Matrices = []

    # Convert vertice elements to Decimal class for accuracy (Is there a better way of handling this?)
    for elem in vertices:
        temp_List = []
        for f in elem:
            temp_List.append(Decimal(f))
        converted_Vertices.append(tuple(temp_List))

    for elem in vertice_Tex_Coords:
        temp_List = []
        for f in elem:
            temp_List.append(Decimal(f))
        converted_Vertice_Tex_Coords.append(temp_List)

    for elem in vertice_Normals:
        temp_List = []
        for f in elem:
            temp_List.append(Decimal(f))
        converted_Vertice_Normals.append(temp_List)

    counter = 0
    for vert in vertices:

        counter +=1
        index_Val = 0
        faces_Connected = []
        face_Positions = []

    # Find which faces use the current vert, and record the face (faces_Connected) it's position within each (face_Positions)
        for face in faces:
            if converted_Vertices.index(vert) == face[0][0]-1:
                # print "connected: ", face
                faces_Connected.append(face)
                face_Positions.append(0)

            elif converted_Vertices.index(vert) == face[1][0]-1:
                faces_Connected.append(face)
                face_Positions.append(1)

            elif converted_Vertices.index(vert) == face[2][0]-1:
                faces_Connected.append(face)
                face_Positions.append(2)


        vert_0 = () # Vert_0 will always be the current vert. It's the pivot, and gets SUBTRACTED from the other two to form the vectors.
        vert_1 = ()
        vert_2 = ()
        vector_1 = ()
        vector_2 = ()
        texCoordsVector_1 = ()
        texCoordsVector_2 = ()
        quotient = 0
        vectors_To_Avg = []

        for f in faces_Connected:
            print "\nConnected Face: ", f

        for f in faces_Connected:
            tangent_Vec_Matrix = [[Decimal(0.0), Decimal(0.0), Decimal(0.0)], [Decimal(0.0), Decimal(0.0), Decimal(0.0)]]

            if face_Positions[faces_Connected.index(f)] == 0:
                # Assign the verts based on current verts position in tri
                vert_0 = converted_Vertices[f[0][0]-1]
                vert_1 = converted_Vertices[f[1][0]-1]
                vert_2 = converted_Vertices[f[2][0]-1]

        # Create tex Coord Vectors
                texCoordsVector_1 = tuple( [converted_Vertice_Tex_Coords[f[1][2]-1][0] - converted_Vertice_Tex_Coords[f[0][2]-1][0],
                                            converted_Vertice_Tex_Coords[f[1][2]-1][1] - converted_Vertice_Tex_Coords[f[0][2]-1][1]] )

                texCoordsVector_2 = tuple( [converted_Vertice_Tex_Coords[f[2][2]-1][0] - converted_Vertice_Tex_Coords[f[0][2]-1][0],
                                            converted_Vertice_Tex_Coords[f[2][2]-1][1] - converted_Vertice_Tex_Coords[f[0][2]-1][1]] )

            elif face_Positions[faces_Connected.index(f)] == 1:
        # Assign the verts based on current verts position in tri
                vert_0 = converted_Vertices[f[1][0]-1]
                vert_1 = converted_Vertices[f[2][0]-1]
                vert_2 = converted_Vertices[f[0][0]-1]

        # Create tex Coord Vectors
                texCoordsVector_1 = tuple( [converted_Vertice_Tex_Coords[f[0][2]-1][0] - converted_Vertice_Tex_Coords[f[1][2]-1][0],
                                            converted_Vertice_Tex_Coords[f[0][2]-1][1] - converted_Vertice_Tex_Coords[f[1][2]-1][1]] )

                texCoordsVector_2 = tuple( [converted_Vertice_Tex_Coords[f[2][2]-1][0] - converted_Vertice_Tex_Coords[f[0][2]-1][0],
                                            converted_Vertice_Tex_Coords[f[2][2]-1][1] - converted_Vertice_Tex_Coords[f[0][2]-1][1]] )

            elif face_Positions[faces_Connected.index(f)] == 2:
        # Assign the verts based on current verts position in tri
                vert_0 = converted_Vertices[f[2][0]-1]
                vert_1 = converted_Vertices[f[0][0]-1]
            vert_2 = converted_Vertices[f[1][0]-1]

        # Create tex Coord Vectors
                texCoordsVector_1 = tuple( [converted_Vertice_Tex_Coords[f[1][2]-1][0] - converted_Vertice_Tex_Coords[f[2][2]-1][0],
                                            converted_Vertice_Tex_Coords[f[1][2]-1][1] - converted_Vertice_Tex_Coords[f[2][2]-1][1]] )

                texCoordsVector_2 = tuple( [converted_Vertice_Tex_Coords[f[0][2]-1][0] - converted_Vertice_Tex_Coords[f[2][2]-1][0],
                                            converted_Vertice_Tex_Coords[f[0][2]-1][1] - converted_Vertice_Tex_Coords[f[2][2]-1][1]] )

        # Create vertex Vectors
            vector_1 = tuple([(vert_1[0]-vert_0[0]), (vert_1[1]-vert_0[1]), (vert_1[2]-vert_0[2])])

            vector_2 = tuple([(vert_2[0]-vert_0[0]), (vert_2[1]-vert_0[1]), (vert_2[2]-vert_0[2])])

            # Create Quotient
            quotient = Decimal(1.0)/((texCoordsVector_1[0]*texCoordsVector_2[1]) - (texCoordsVector_2[0]*texCoordsVector_1[1]))

            # Create the determinant for the inverse tex coord matrix
            determinant = det([texCoordsVector_1,texCoordsVector_2])

        # Create the inverse tex coord matrix using the determinant
            inverse_Tex_Coord_Matrix = [ [ texCoordsVector_2[1]/Decimal(determinant), -texCoordsVector_1[1]/Decimal(determinant)],
                                         [-texCoordsVector_2[0]/Decimal(determinant), texCoordsVector_1[0]/Decimal(determinant)] ]

            tangent_Vec_Matrix[0][0] = quotient * ((inverse_Tex_Coord_Matrix[0][0] * vector_1[0]) + (inverse_Tex_Coord_Matrix[1][0] * vector_2[0]))
            tangent_Vec_Matrix[0][1] = quotient * ((inverse_Tex_Coord_Matrix[0][0] * vector_1[1]) + (inverse_Tex_Coord_Matrix[1][0] * vector_2[1]))
            tangent_Vec_Matrix[0][2] = quotient * ((inverse_Tex_Coord_Matrix[0][0] * vector_1[2]) + (inverse_Tex_Coord_Matrix[1][0] * vector_2[2]))

            tangent_Vec_Matrix[1][0] = quotient * ((inverse_Tex_Coord_Matrix[1][0] * vector_1[0]) + (inverse_Tex_Coord_Matrix[1][1] * vector_2[0]))
            tangent_Vec_Matrix[1][1] = quotient * ((inverse_Tex_Coord_Matrix[1][0] * vector_1[1]) + (inverse_Tex_Coord_Matrix[1][1] * vector_2[1]))
            tangent_Vec_Matrix[1][2] = quotient * ((inverse_Tex_Coord_Matrix[1][0] * vector_1[2]) + (inverse_Tex_Coord_Matrix[1][1] * vector_2[2]))

        # Normalize the vectors here
            magnitude = norm(tangent_Vec_Matrix[0])
            tangent_Vec_Matrix[0][0] /= magnitude
            tangent_Vec_Matrix[0][1] /= magnitude
            tangent_Vec_Matrix[0][2] /= magnitude
            magnitude = norm(tangent_Vec_Matrix[1])
            tangent_Vec_Matrix[1][0] /= magnitude
            tangent_Vec_Matrix[1][1] /= magnitude
            tangent_Vec_Matrix[1][2] /= magnitude

            vectors_To_Avg.append(tangent_Vec_Matrix)

        # Begin averaging all the vectors just like you would the normals
        matrix_Map = [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2)]
        consolidated_Matrix = array([ [Decimal(0.0), Decimal(0.0), Decimal(0.0)], [Decimal(0.0), Decimal(0.0), Decimal(0.0)] ])

        for mat in vectors_To_Avg:
            consolidated_Matrix += array(mat)

        consolidated_Matrix /= len(vectors_To_Avg)

        consolidated_Matrix = array([consolidated_Matrix[0], consolidated_Matrix[1], cross(consolidated_Matrix[0], consolidated_Matrix[1])])

        temp_Matrix =[]
        temp_Vec = []

        mag = norm(consolidated_Matrix[0])
        for elem in consolidated_Matrix[0]:
            elem_ID = where(elem)
            consolidated_Matrix[0][elem_ID] /= mag

        mag = norm(consolidated_Matrix[1])
        for elem in consolidated_Matrix[1]:
            elem_ID = where(elem)
            consolidated_Matrix[1][elem_ID] /= mag

        mag = norm(consolidated_Matrix[2])
        for elem in consolidated_Matrix[2]:
            elem_ID = where(elem)
            consolidated_Matrix[2][elem_ID] /= mag

        tangent_Space_Matrices.append(consolidated_Matrix)

    # for each vector set in the list:
    #   grab each vectorand make them orthogonal, assign to the first vector and store the winding order as the "W" component
    #
    # Gram-Schmidt orthogonalize:
        #   tangent[a] = (t - n * Dot(n, t)).Normalize();

    return tangent_Space_Matrices

A copy of the obj file:

# Blender v2.70 (sub 0) OBJ File: ''
# www.blender.org

o Cube
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
v -1.194667 0.000000 1.194667
v -1.194667 1.194667 0.000000
v -1.194667 0.000000 -1.194667
v -1.194667 -1.194667 0.000000
v 0.000000 1.194667 -1.194667
v 1.194667 0.000000 -1.194667
v 0.000000 -1.194667 -1.194667
v 1.194667 1.194667 0.000000
v 1.194667 0.000000 1.194667
v 1.194667 -1.194667 0.000000
v 0.000000 1.194667 1.194667
v 0.000000 -1.194667 1.194667
v -1.543509 0.000000 0.000000
v 0.000000 0.000000 -1.543509
v 1.543509 0.000000 0.000000
v 0.000000 0.000000 1.543509
v 0.000000 -1.543509 0.000000
v 0.000000 1.543509 0.000000
vt 0.854079 0.521961
vt 0.805523 0.654757
vt 0.664129 0.654982
vt 0.310049 0.333551
vt 0.451444 0.333775
vt 0.500000 0.466571
vt 0.664128 0.987142
vt 0.536081 0.940552
vt 0.532186 0.798731
vt 0.310049 0.984442
vt 0.182002 0.937853
vt 0.178107 0.796032
vt 0.368058 0.009068
vt 0.500000 0.061219
vt 0.500000 0.197479
vt 0.854079 0.195874
vt 0.805523 0.328669
vt 0.664129 0.328894
vt 0.532186 0.466571
vt 0.689643 0.489283
vt 0.722137 0.333551
vt 0.854079 0.385702
vt 0.368058 0.654982
vt 0.335564 0.499250
vt 0.178107 0.521961
vt 0.182002 0.380140
vt 0.722137 0.665711
vt 0.689643 0.821443
vt 0.854079 0.854122
vt 0.805523 0.986917
vt 0.368058 0.663011
vt 0.335564 0.818743
vt 0.500000 0.851422
vt 0.451444 0.984218
vt 0.310049 0.330499
vt 0.335564 0.164800
vt 0.178107 0.142088
vt 0.230559 0.014854
vt 0.532187 0.140483
vt 0.689643 0.163195
vt 0.722137 0.007463
vt 0.854079 0.059614
vt 0.536081 0.608392
vt 0.584638 0.339337
vt 0.500000 0.602830
vt 0.230559 0.649195
vt 0.584638 0.671497
vt 0.854079 0.717862
vt 0.230558 0.668798
vt 0.500000 0.715163
vt 0.451444 0.330274
vt 0.182002 0.283909
vt 0.536081 0.282305
vt 0.584638 0.013249
vn -0.965392 0.000000 -0.260804
vn -0.681744 -0.681744 -0.265426
vn -0.707083 -0.707083 0.000000
vn 0.707083 0.000000 -0.707083
vn 0.577350 -0.577350 -0.577350
vn 0.000000 -0.260804 -0.965392
vn 0.707083 0.000000 0.707083
vn 0.577350 -0.577350 0.577350
vn 0.707083 -0.707083 0.000000
vn -0.260804 0.000000 0.965392
vn -0.228726 -0.228727 0.946239
vn 0.000000 -0.260804 0.965392
vn 0.000000 -0.965392 -0.260804
vn -0.000000 0.965392 -0.260804
vn -0.681744 0.681744 -0.265426
vn -0.707083 0.707083 0.000000
vn -0.965392 -0.000000 0.260804
vn -1.000000 0.000000 0.000000
vn -0.260804 -0.000000 -0.965392
vn 0.000000 0.000000 -1.000000
vn 0.000000 0.260804 -0.965392
vn 0.681744 0.265426 -0.681744
vn 1.000000 0.000000 0.000000
vn 0.965392 0.260804 0.000000
vn 0.681744 0.265426 0.681744
vn 0.000000 0.000000 1.000000
vn -0.000000 0.260804 0.965392
vn -0.228726 0.228727 0.946239
vn -0.000000 -0.965392 0.260804
vn 0.000000 -1.000000 0.000000
vn 0.000000 0.965392 0.260804
vn 0.000000 1.000000 0.000000
vn 0.260804 0.965392 0.000000
vn 0.228727 0.946239 -0.228726
vn -0.681744 -0.681744 0.265426
vn -0.681744 0.681744 0.265426
vn -0.228726 -0.228727 -0.946239
vn -0.228726 0.228727 -0.946239
vn 0.228727 0.946239 0.228726
usemtl None
s 1
f 11/1/1 2/2/2 12/3/3
f 14/4/4 3/5/5 15/6/6
f 17/7/7 4/8/8 18/9/9
f 9/10/10 1/11/11 20/12/12
f 15/13/13 3/14/5 18/15/9
f 13/16/14 6/17/15 10/18/16
f 9/19/17 21/20/18 12/3/3
f 10/21/16 21/20/18 9/19/17
f 10/21/16 6/22/15 11/1/1
f 11/23/19 22/24/20 15/6/6
f 13/25/21 22/24/20 11/23/19
f 13/25/21 7/26/22 14/4/4
f 14/27/4 23/28/23 18/9/9
f 16/29/24 23/28/23 14/27/4
f 16/29/24 8/30/25 17/7/7
f 17/31/7 24/32/26 20/12/12
f 19/33/27 24/32/26 17/31/7
f 19/33/27 5/34/28 9/10/10
f 20/35/29 25/36/30 18/15/9
f 12/37/3 25/36/30 20/35/29
f 12/37/3 2/38/2 15/13/13
f 19/39/31 26/40/32 10/18/16
f 16/41/33 26/40/32 19/39/31
f 16/41/33 7/42/34 13/16/14
f 21/20/18 11/1/1 12/3/3
f 22/24/20 14/4/4 15/6/6
f 23/28/23 17/7/7 18/9/9
f 24/32/26 9/10/10 20/12/12
f 25/36/30 15/13/13 18/15/9
f 26/40/32 13/16/14 10/18/16
f 1/43/35 9/19/17 12/3/3
f 5/44/36 10/21/16 9/19/17
f 21/20/18 10/21/16 11/1/1
f 2/45/37 11/23/19 15/6/6
f 6/46/38 13/25/21 11/23/19
f 22/24/20 13/25/21 14/4/4
f 3/47/5 14/27/4 18/9/9
f 7/48/22 16/29/24 14/27/4
f 23/28/23 16/29/24 17/7/7
f 4/49/8 17/31/7 20/12/12
f 8/50/25 19/33/27 17/31/7
f 24/32/26 19/33/27 9/10/10
f 4/51/8 20/35/29 18/15/9
f 1/52/35 12/37/3 20/35/29
f 25/36/30 12/37/3 15/13/13
f 5/53/36 19/39/31 10/18/16
f 8/54/39 16/41/33 19/39/31
f 26/40/32 16/41/33 13/16/14

A copy of the outputted Tangent_Space_Matrices:

[[Decimal('-1.71863') Decimal('0.436203') Decimal('-0.00356367')]
 [Decimal('5.17739') Decimal('0.0262889') Decimal('0.113778')]
 [Decimal('5.53967') Decimal('0.0550711') Decimal('-0.194126')]]

[[Decimal('-0.893424') Decimal('0.53703') Decimal('0.330398')]
 [Decimal('3.12530') Decimal('-0.233673') Decimal('0.144461')]
 [Decimal('5.88255') Decimal('0.236697') Decimal('-0.092097')]]

[[Decimal('-3.92581') Decimal('0.00338467') Decimal('0.210698')]
 [Decimal('1.30546') Decimal('-0.196836') Decimal('-0.487913')]
 [Decimal('233.266') Decimal('0.0380384') Decimal('0.00668408')]]

[[Decimal('1.10141') Decimal('0.105360') Decimal('0.222156')]
 [Decimal('0.374179') Decimal('0.470633') Decimal('-0.459993')]
 [Decimal('-39.9670') Decimal('0.0322965') Decimal('-0.00396433')]]

[[Decimal('3.63704') Decimal('0.059916') Decimal('0.274198')]
 [Decimal('-0.844737') Decimal('-0.624593') Decimal('0.215930')]
 [Decimal('4.92071') Decimal('-0.180000') Decimal('-0.213479')]]

[[Decimal('-12.4175') Decimal('-0.152201') Decimal('0.078841')]
 [Decimal('-5.26066') Decimal('-0.269853') Decimal('-0.0181329')]
 [Decimal('898.268') Decimal('-0.0169986') Decimal('-0.0052866')]]

[[Decimal('1.47515') Decimal('-0.316216') Decimal('-0.0901863')]
 [Decimal('1.16518') Decimal('-0.00368167') Decimal('0.523723')]
 [Decimal('-26.3244') Decimal('-0.0474518') Decimal('0.0658484')]]

[[Decimal('-10.5317') Decimal('0.0619627') Decimal('-0.118149')]
 [Decimal('1.61942') Decimal('0.084988') Decimal('-0.478947')]
 [Decimal('-4.18692') Decimal('-0.160955') Decimal('-0.0415415')]]

[[Decimal('-0.744823') Decimal('-0.182531') Decimal('-0.23390')]
 [Decimal('-2.61680') Decimal('0.37657') Decimal('0.071616')]
 [Decimal('53.5092') Decimal('0.0623191') Decimal('-0.0549116')]]

[[Decimal('2.56020') Decimal('-0.188995') Decimal('-0.338066')]
 [Decimal('0.782069') Decimal('0.344924') Decimal('0.123135')]
 [Decimal('32.8582') Decimal('-0.0450337') Decimal('0.0965270')]]

[[Decimal('3.00188') Decimal('-0.356844') Decimal('0.029567')]
 [Decimal('5.17998') Decimal('-0.223486') Decimal('-0.0739466')]
 [Decimal('300.374') Decimal('0.0208984') Decimal('-0.0277167')]]

[[Decimal('3.20561') Decimal('-0.279892') Decimal('0.171362')]
 [Decimal('8.32054') Decimal('-0.0193308') Decimal('-0.192476')]
 [Decimal('146.933') Decimal('0.0417765') Decimal('0.0177536')]]

[[Decimal('1.87810') Decimal('-0.394379') Decimal('-0.0753646')]
 [Decimal('5.03821') Decimal('-0.114146') Decimal('-0.0610071')]
 [Decimal('4.61085') Decimal('-0.0223741') Decimal('0.147173')]]

[[Decimal('10.9217') Decimal('-0.153599') Decimal('0.107657')]
 [Decimal('-7.82668') Decimal('-0.179895') Decimal('-0.127484')]
 [Decimal('194.460') Decimal('0.0013918') Decimal('-0.0436388')]]

[[Decimal('-1.14915') Decimal('-0.267789') Decimal('0.276414')]
 [Decimal('-9.70081') Decimal('0.155311') Decimal('0.0281595')]
 [Decimal('-33.9198') Decimal('-0.0669974') Decimal('-0.0774431')]]

[[Decimal('-0.515017') Decimal('0.176061') Decimal('0.417142')]
 [Decimal('5.90286') Decimal('-0.0289631') Decimal('-0.252752')]
 [Decimal('-96.8026') Decimal('0.0551345') Decimal('-0.0270499')]]

[[Decimal('-3.23047') Decimal('-0.28732') Decimal('-0.00698838')]
 [Decimal('2.33777') Decimal('0.0559616') Decimal('0.124631')]
 [Decimal('-688.674') Decimal('0.0108797') Decimal('-0.00318628')]]

[[Decimal('0.502196') Decimal('0.116836') Decimal('0.747486')]
 [Decimal('-15.5062') Decimal('-0.0638302') Decimal('-0.137219')]
 [Decimal('556.324') Decimal('-0.0204466') Decimal('-0.00764613')]]

[[Decimal('0.209075') Decimal('-0.387024') Decimal('0.179379')]
 [Decimal('-4.35057') Decimal('0.24733') Decimal('0.141904')]
 [Decimal('-26.7169') Decimal('-0.0534034') Decimal('-0.106219')]]

[[Decimal('1.29200') Decimal('-0.257231') Decimal('-0.178968')]
 [Decimal('-5.72240') Decimal('0.00422338') Decimal('-0.111968')]
 [Decimal('13.6006') Decimal('0.0751484') Decimal('-0.101278')]]

[[Decimal('5.60942') Decimal('0.0444642') Decimal('0.248025')]
 [Decimal('3.05805') Decimal('-0.351908') Decimal('0.0449598')]
 [Decimal('31.0427') Decimal('0.0506420') Decimal('-0.0984297')]]

[[Decimal('-4.09833') Decimal('-0.144532') Decimal('0.265408')]
 [Decimal('1.26981') Decimal('0.45041') Decimal('0.0672595')]
 [Decimal('-38.5617') Decimal('0.0478609') Decimal('-0.0582978')]]

[[Decimal('0.427084') Decimal('0.188040') Decimal('0.345115')]
 [Decimal('1.10737') Decimal('-0.422318') Decimal('-0.241098')]
 [Decimal('56.3329') Decimal('0.0561973') Decimal('-0.0382132')]]

[[Decimal('1.93299') Decimal('0.368665') Decimal('-0.246565')]
 [Decimal('-1.07242') Decimal('-0.223065') Decimal('-0.296902')]
 [Decimal('-22.4639') Decimal('0.0951676') Decimal('-0.0400012')]]

[[Decimal('1.45521') Decimal('0.0426258') Decimal('0.460932')]
 [Decimal('-6.87113') Decimal('0.00734925') Decimal('-0.206597')]
 [Decimal('-20.4614') Decimal('0.0829523') Decimal('0.00720732')]]

[[Decimal('3.66955') Decimal('0.290382') Decimal('-0.143062')]
 [Decimal('7.98748') Decimal('0.0173328') Decimal('0.218166')]
 [Decimal('52.3476') Decimal('-0.0723939') Decimal('-0.0455665')]]

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

I know it is quite a long piece, but I am seriously stuck...I looked over the math and I am not sure wth could be wrong. Is this ok to post? If not, could someone recommend a suitable place for me to get help with fixing this algorithm? I'll probably end up using assimp to generate the TBN's, but I would like to know what I missed here... :/

12
  • 4
    This question appears to be off-topic because it is about getting an answer for the original question, not about any meta clarification/discussion reasons. Commented Sep 7, 2014 at 16:07
  • Why did this get downvoted? Can someone at least reply and let me know why? Commented Sep 7, 2014 at 16:07
  • @πάντα ῥεῖ Sorry...hadn't refreshed the page so your comment wasn't visible yet. Commented Sep 7, 2014 at 16:09
  • 1
    I am not sure where to ask this...I AM technically asking how this should be classified: Is it suitable for SO, or does it belong on another portion of StackExchange? Commented Sep 7, 2014 at 16:11
  • 1
    They'll tell you at SO, if that's a suitable question. This site is for asking when you don't get why they wont! Commented Sep 7, 2014 at 16:11
  • @πάντα ῥεῖ Ok. I was just trying to avoid uneccessary down-votes over there...before I delete this, do you think this will succeed there? Commented Sep 7, 2014 at 16:15
  • 41
    @πάνταῥεῖ I disagree. This OP comes here to ask if this question fits on SO. That is one of the goals of meta. If the OP posts this on SO it will get downvoted into oblivion and I don't want to get the credits for that. At best this question is a duplicate of Are there legitimate “fix my code” questions?
    – rene
    Commented Sep 7, 2014 at 16:30
  • 5
    @JRFerrell This is the proper place to ask such questions. You can certainly consult Meta to see whether a question is on-topic before posting it on the main site.
    – AstroCB
    Commented Sep 7, 2014 at 16:48
  • @AstroCB Ok. lol....getting mixed feelings from everyone here. TY for your input. Commented Sep 7, 2014 at 18:19
  • @JRFerrell No worries: the votes on rene's comment should give you an idea of the general sentiment.
    – AstroCB
    Commented Sep 7, 2014 at 18:20
  • 5
    On topic or not, you won't get very far unless you can slim that down to a much smaller problem. Very few people are going to be bothered with wading through that much code. You might get lucky, but I wouldn't count on it. Commented Sep 8, 2014 at 20:54
  • @Matt Burland Acknowledged. :P Commented Sep 11, 2014 at 23:41

1 Answer 1

48

If your only question is to debug your code, it is off-topic.

If you did run it and can't explain why your code behaves strange at a particular line it might be on topic.

Reading your question for the third time I see you ask Can you spot where the script is going wrong? That is more something for you to do. And if you have spotted it we can help out because you can clearly explain what the input is and what you expected as output for one or two functions.

Check the How to ask and Minimal, Complete, and Verifiable example pages in the helpcentre.

You might find the answer of Robert Harvey useful as well.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .