diff options
Diffstat (limited to 'contrib/cgltf-tangents/cgltf_tangents.h')
-rw-r--r-- | contrib/cgltf-tangents/cgltf_tangents.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/contrib/cgltf-tangents/cgltf_tangents.h b/contrib/cgltf-tangents/cgltf_tangents.h new file mode 100644 index 0000000..79e3502 --- /dev/null +++ b/contrib/cgltf-tangents/cgltf_tangents.h | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | Copyright 2022 Marc Sunet | ||
3 | |||
4 | Redistribution and use in source and binary forms, with or without modification, | ||
5 | are permitted provided that the following conditions are met: | ||
6 | |||
7 | 1. Redistributions of source code must retain the above copyright notice, this | ||
8 | list of conditions and the following disclaimer. | ||
9 | |||
10 | 2. Redistributions in binary form must reproduce the above copyright notice, | ||
11 | this list of conditions and the following disclaimer in the documentation and/or | ||
12 | other materials provided with the distribution. | ||
13 | |||
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
24 | */ | ||
25 | #ifndef CGLTF_TANGENTS_H_INCLUDED__ | ||
26 | #define CGLTF_TANGENTS_H_INCLUDED__ | ||
27 | |||
28 | #include <cgltf.h> | ||
29 | |||
30 | /// A buffer that holds tangent vectors. | ||
31 | /// | ||
32 | /// Tangent vectors are tightly packed in the array. | ||
33 | /// | ||
34 | /// Tangent vectors have 4 coordinates: (X,Y,Z) for the vector, W for the sign. | ||
35 | /// The usual rules of MikkTSpace apply, namely that the bitangent should be | ||
36 | /// computed as: | ||
37 | /// | ||
38 | /// bitangent = tangent.w * cross(normal, tangent.xyz); | ||
39 | /// | ||
40 | /// Refer to the MikkTSpace documentation for more details. | ||
41 | /// | ||
42 | /// The primitive pointer points to the mesh primitive for which the tangents in | ||
43 | /// this buffer were computed. When your application loads mesh primitives, it | ||
44 | /// can scan the cgltfTangetBuffer array outputed by cgltf_compute_tangents() to | ||
45 | /// see whether tangents were computed for the mesh primitive. | ||
46 | typedef struct cgltfTangentBuffer { | ||
47 | void* data; // X-coordinate of the first tangent vector. | ||
48 | cgltf_size size_bytes; // Total Size of data in bytes. | ||
49 | cgltf_primitive* primitive; // The primitive these tangents belong to. | ||
50 | } cgltfTangentBuffer; | ||
51 | |||
52 | /// Compute tangent vectors for normal-mapped mesh primitives missing them. | ||
53 | /// | ||
54 | /// cgltf_options can be zeroed out but must be non-null. | ||
55 | /// | ||
56 | /// cgltf_data is the scene previously loaded by cgltf. | ||
57 | /// | ||
58 | /// out_tangent_buffers is an output array of tangent buffers, one buffer per | ||
59 | /// mesh primitive for which tangents were computed. | ||
60 | /// | ||
61 | /// out_num_tangent_buffers is the number of tangent buffers in the output | ||
62 | /// array. | ||
63 | cgltf_result cgltf_compute_tangents(const cgltf_options*, const cgltf_data*, | ||
64 | cgltfTangentBuffer** out_tangent_buffers, | ||
65 | cgltf_size* out_num_tangent_buffers); | ||
66 | |||
67 | #endif // CGLTF_TANGENTS_H_INCLUDED__ | ||