pub(super) fn calculate_tangent_binormal(
    p0: Vec3,
    p1: Vec3,
    p2: Vec3,
    uv0: Vec2,
    uv1: Vec2,
    uv2: Vec2,
) -> (Vec3, Vec3) {
    let dp1 = p1 - p0;
    let dp2 = p2 - p0;

    let duv1 = uv1 - uv0;
    let duv2 = uv2 - uv0;

    let denominator = duv1.x * duv2.y - duv1.y * duv2.x;
    let (t, b) = if denominator.abs() > 0.0001 {
        let r = 1.0 / denominator;
        let t = (dp1 * duv2.y - dp2 * duv1.y) * r;
        let b = (dp2 * duv1.x - dp1 * duv2.x) * r;

        // We normalize, weighted by the size of the triangle. So we can just add all the
        // tangents/binormals and normalize it at the end
        (t, b)
    } else {
        // If not divisible, assume uv coordinates don't change and the tangent/binormal
        // won't matter
        (glam::Vec3::ZERO, glam::Vec3::ZERO)
    };
    (t, b)
}
// Calculates a tangent and binormal that are orthogonal to the polygon normal and align with the
// uv coordinate x and y axes respectively. May return zero vector if uv coordinates are the same
Calculates a tangent and binormal that are orthogonal to the polygon normal and align with the
uv coordinate x and y axes respectively. May return zero vector if uv coordinates are the same
Calculates a tangent and binormal that are orthogonal to the polygon normal and align with the uv coordinate x and y axes respectively . May return zero vector if uv coordinates are the same
pub(super) fn calculate_tangent_binormal(
    p0: Vec3,
    p1: Vec3,
    p2: Vec3,
    uv0: Vec2,
    uv1: Vec2,
    uv2: Vec2,
) -> (Vec3, Vec3) {
    let dp1 = p1 - p0;
    let dp2 = p2 - p0;
    let duv1 = uv1 - uv0;
    let duv2 = uv2 - uv0;
    let denominator = duv1.x * duv2.y - duv1.y * duv2.x;
    let (t, b) = if denominator.abs() > 0.0001 {
        let r = 1.0 / denominator;
        let t = (dp1 * duv2.y - dp2 * duv1.y) * r;
        let b = (dp2 * duv1.x - dp1 * duv2.x) * r;
        // We normalize, weighted by the size of the triangle. So we can just add all the
        // tangents/binormals and normalize it at the end
        (t, b)
    } else {
        // If not divisible, assume uv coordinates don't change and the tangent/binormal
        // won't matter
        (glam::Vec3::ZERO, glam::Vec3::ZERO)
    };
    (t, b)
}
pub ( super ) fn calculate_tangent_binormal ( p0 : Vec3 , p1 : Vec3 , p2 : Vec3 , uv0 : Vec2 , uv1 : Vec2 , uv2 : Vec2 , ) -> ( Vec3 , Vec3 ) { let dp1 = p1 - p0 ; let dp2 = p2 - p0 ; let duv1 = uv1 - uv0 ; let duv2 = uv2 - uv0 ; let denominator = duv1 . x * duv2 . y - duv1 . y * duv2 . x ; let ( t , b ) = if denominator . abs ( ) > 0.0001 { let r = 1.0 / denominator ; let t = ( dp1 * duv2 . y - dp2 * duv1 . y ) * r ; let b = ( dp2 * duv1 . x - dp1 * duv2 . x ) * r ; // We normalize, weighted by the size of the triangle. So we can just add all the // tangents/binormals and normalize it at the end ( t , b ) } else { // If not divisible, assume uv coordinates don't change and the tangent/binormal // won't matter ( glam :: Vec3 :: ZERO , glam :: Vec3 :: ZERO ) } ; ( t , b ) }
Calculates a tangent and binormal that are orthogonal to the polygon normal and align with the
uv coordinate x and y axes respectively.
Calculates a tangent and binormal that are orthogonal to the polygon normal and align with the uv coordinate x and y axes respectively .
p0
Vec3
p1
Vec3
p2
Vec3
uv0
Vec2
uv1
Vec2
uv2
Vec2
p0
Vec3
p1
Vec3
p2
Vec3
uv0
Vec2
uv1
Vec2
uv2
Vec2