import { buffer_geometry_generate_tangents } from "./buffer_geometry_generate_tangents.js";

/**
 *
 * @param {THREE.BufferGeometry} geo
 */
export function buffer_geometry_ensure_tangents(geo) {
    if (geo.getAttribute('tangent') !== undefined) {
        // already got tangents
        return;
    }

    if (geo.getIndex() === null) {
        // non-indexed, unsupported
        return;
    }

    if (geo.getAttribute('normal') === undefined) {
        // no normals
        return;
    }

    if (geo.getAttribute('uv') === undefined) {
        // UVs are required by the algorithm
        return;
    }

    if (geo.getAttribute('position') === undefined) {
        // positions are required as well
        return;
    }

    buffer_geometry_generate_tangents(geo);
}
