diff options
author | 3gg <3gg@shellblade.net> | 2025-06-27 10:18:39 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-06-27 10:18:39 -0700 |
commit | bd57f345ed9dbed1d81683e48199626de2ea9044 (patch) | |
tree | 4221f2f2a7ad2244d2e93052bd68187ec91b8ea9 /contrib/cgltf-tangents/test | |
parent | 9a82ce0083437a4f9f58108b2c23b957d2249ad8 (diff) |
Restructure project
Diffstat (limited to 'contrib/cgltf-tangents/test')
-rw-r--r-- | contrib/cgltf-tangents/test/CMakeLists.txt | 11 | ||||
-rw-r--r-- | contrib/cgltf-tangents/test/main.c | 86 |
2 files changed, 97 insertions, 0 deletions
diff --git a/contrib/cgltf-tangents/test/CMakeLists.txt b/contrib/cgltf-tangents/test/CMakeLists.txt new file mode 100644 index 0000000..422c950 --- /dev/null +++ b/contrib/cgltf-tangents/test/CMakeLists.txt | |||
@@ -0,0 +1,11 @@ | |||
1 | cmake_minimum_required(VERSION 3.0) | ||
2 | |||
3 | project (cgltf-test) | ||
4 | |||
5 | add_executable(cgltf-test | ||
6 | main.c) | ||
7 | |||
8 | target_link_libraries(cgltf-test | ||
9 | cgltf | ||
10 | cgltf-tangents | ||
11 | -lm) | ||
diff --git a/contrib/cgltf-tangents/test/main.c b/contrib/cgltf-tangents/test/main.c new file mode 100644 index 0000000..0d70008 --- /dev/null +++ b/contrib/cgltf-tangents/test/main.c | |||
@@ -0,0 +1,86 @@ | |||
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 | #include <cgltf_tangents.h> | ||
26 | #define CGLTF_IMPLEMENTATION | ||
27 | #include <cgltf.h> | ||
28 | |||
29 | #include <stdio.h> | ||
30 | |||
31 | void print_tangent_buffer(const cgltfTangentBuffer* buffer, int max_vectors) { | ||
32 | printf("Tangent buffer for primitive (%p) (%lu bytes):\n", buffer->primitive, | ||
33 | buffer->size_bytes); | ||
34 | |||
35 | const float* xyzw = (const float*)buffer->data; | ||
36 | const float* end = (const float*)(buffer->data + buffer->size_bytes); | ||
37 | |||
38 | for (int i = 0; i < max_vectors && xyzw < end; ++i, xyzw += 4) { | ||
39 | printf("(%3.2f, %3.2f, %3.2f, sign: %3.2f)\n", *xyzw, *(xyzw + 1), | ||
40 | *(xyzw + 2), *(xyzw + 3)); | ||
41 | } | ||
42 | printf("--------------------"); | ||
43 | } | ||
44 | |||
45 | void usage(const char* argv0) { | ||
46 | fprintf(stderr, "Usage: %s <glTF file path>\n", argv0); | ||
47 | } | ||
48 | |||
49 | int main(int argc, const char** argv) { | ||
50 | cgltf_options options = {0}; | ||
51 | cgltf_data* data = NULL; | ||
52 | |||
53 | if (argc != 2) { | ||
54 | usage(argv[0]); | ||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | const char* filepath = argv[1]; | ||
59 | |||
60 | cgltf_result result = cgltf_parse_file(&options, filepath, &data); | ||
61 | if (result != cgltf_result_success) { | ||
62 | cgltf_free(data); | ||
63 | return 1; | ||
64 | } | ||
65 | |||
66 | // Must call cgltf_load_buffers() to load buffer data. | ||
67 | result = cgltf_load_buffers(&options, data, filepath); | ||
68 | if (result != cgltf_result_success) { | ||
69 | cgltf_free(data); | ||
70 | return 2; | ||
71 | } | ||
72 | |||
73 | cgltfTangentBuffer* tangent_buffers = 0; | ||
74 | cgltf_size num_tangent_buffers = 0; | ||
75 | cgltf_compute_tangents(&options, data, &tangent_buffers, | ||
76 | &num_tangent_buffers); | ||
77 | |||
78 | // cgltf scene not needed beyond this point. | ||
79 | cgltf_free(data); | ||
80 | |||
81 | for (cgltf_size i = 0; i < num_tangent_buffers; ++i) { | ||
82 | print_tangent_buffer(tangent_buffers, 10); | ||
83 | } | ||
84 | |||
85 | return 0; | ||
86 | } | ||