// Given unnormalized and possibly invalid tangent/binormals, produce a tangent/binormal that is
// normalized and appropriate for right-hand coordinate system.
Given unnormalized and possibly invalid tangent/binormals, produce a tangent/binormal that is
normalized and appropriate for right-hand coordinate system.
Given unnormalized and possibly invalid tangent / binormals produce a tangent / binormal that is normalized and appropriate for right - hand coordinate system .
fn fix_tangent_binormal(
    n: Vec3,
    t: Vec3,
    b: Vec3,
) -> (Vec3, Vec3) {
    let mut t = if t.length_squared() > 0.0001 {
        t.normalize()
    } else {
        // If we don't have a valid vector to normalize, just pick anything
        n.any_orthogonal_vector()
    };
    let b = if b.length_squared() > 0.0001 {
        let b = b.normalize();
        // Ensure right-handed coordinate system.. flip the tangent if it's not
        // See handedness section in
        // https://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/
        if n.cross(t).dot(b) < 0.0 {
            t = t * -1.0;
        }
        b
    } else {
        // If we don't have a valid vector to normalize, pick anything orthogonal
        // to normal and tangent
        n.cross(t).normalize()
    };
    (t, b)
}
fn fix_tangent_binormal ( n : Vec3 , t : Vec3 , b : Vec3 , ) -> ( Vec3 , Vec3 ) { let mut t = if t . length_squared ( ) > 0.0001 { t . normalize ( ) } else { // If we don't have a valid vector to normalize, just pick anything n . any_orthogonal_vector ( ) } ; let b = if b . length_squared ( ) > 0.0001 { let b = b . normalize ( ) ; // Ensure right-handed coordinate system.. flip the tangent if it's not // See handedness section in // https://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/ if n . cross ( t ) . dot ( b ) < 0.0 { t = t * - 1.0 ; } b } else { // If we don't have a valid vector to normalize, pick anything orthogonal // to normal and tangent n . cross ( t ) . normalize ( ) } ; ( t , b ) }
Given unnormalized and possibly invalid tangent/binormals, produce a tangent/binormal that is
normalized and appropriate for right-hand coordinate system.
Given unnormalized and possibly invalid tangent / binormals produce a tangent / binormal that is normalized and appropriate for right - hand coordinate system .
n
Vec3
t
Vec3
b
Vec3