# cgltf-tangents A library to compute missing tangent vectors in glTF models using MikkTSpace. ## Example ``` // Load the glTF scene and buffers as usual. cgltf_result result = cgltf_parse_file(&options, filepath, &data); cgltf_load_buffers(&options, data, filepath); // Compute missing tangents. cgltfTangentBuffer* tangent_buffers = 0; cgltf_size num_tangent_buffers = 0; cgltf_compute_tangents(&options, data, &tangent_buffers, &num_tangent_buffers); ``` ## About This is a single-header/source library that combines [MikkTSpace](https://github.com/mmikk/MikkTSpace) and [cgltf](https://github.com/jkuhlmann/cgltf) to compute missing tangent vectors for models. Mesh primitives in glTF may have a normal map but not necessarily tangent vectors. An example is the [DamagedHelmet](https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/DamagedHelmet/glTF) sample. From the [spec](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#meshes): *"When tangents are not specified, client implementations SHOULD calculate tangents using default MikkTSpace algorithms with the specified vertex positions, normals, and texture coordinates associated with the normal texture."* cgltf-tangents takes an input glTF scene and scans it for mesh primitives that have a normal map but no tangents. cgltf-tangents then invokes MikkTSpace to compute tangents for those mesh primitives and outputs an array of tangent buffers. The client can then upload these buffers to GPU memory for rendering. See `test/` for a complete example. MikkTSpace is packaged here for convenience. cgltf must be obtained separately.