From bd57f345ed9dbed1d81683e48199626de2ea9044 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 27 Jun 2025 10:18:39 -0700 Subject: Restructure project --- contrib/cgltf-tangents/test/CMakeLists.txt | 11 ++++ contrib/cgltf-tangents/test/main.c | 86 ++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 contrib/cgltf-tangents/test/CMakeLists.txt create mode 100644 contrib/cgltf-tangents/test/main.c (limited to 'contrib/cgltf-tangents/test') 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 @@ +cmake_minimum_required(VERSION 3.0) + +project (cgltf-test) + +add_executable(cgltf-test + main.c) + +target_link_libraries(cgltf-test + cgltf + cgltf-tangents + -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 @@ +/* +Copyright 2022 Marc Sunet + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#include +#define CGLTF_IMPLEMENTATION +#include + +#include + +void print_tangent_buffer(const cgltfTangentBuffer* buffer, int max_vectors) { + printf("Tangent buffer for primitive (%p) (%lu bytes):\n", buffer->primitive, + buffer->size_bytes); + + const float* xyzw = (const float*)buffer->data; + const float* end = (const float*)(buffer->data + buffer->size_bytes); + + for (int i = 0; i < max_vectors && xyzw < end; ++i, xyzw += 4) { + printf("(%3.2f, %3.2f, %3.2f, sign: %3.2f)\n", *xyzw, *(xyzw + 1), + *(xyzw + 2), *(xyzw + 3)); + } + printf("--------------------"); +} + +void usage(const char* argv0) { + fprintf(stderr, "Usage: %s \n", argv0); +} + +int main(int argc, const char** argv) { + cgltf_options options = {0}; + cgltf_data* data = NULL; + + if (argc != 2) { + usage(argv[0]); + return 0; + } + + const char* filepath = argv[1]; + + cgltf_result result = cgltf_parse_file(&options, filepath, &data); + if (result != cgltf_result_success) { + cgltf_free(data); + return 1; + } + + // Must call cgltf_load_buffers() to load buffer data. + result = cgltf_load_buffers(&options, data, filepath); + if (result != cgltf_result_success) { + cgltf_free(data); + return 2; + } + + cgltfTangentBuffer* tangent_buffers = 0; + cgltf_size num_tangent_buffers = 0; + cgltf_compute_tangents(&options, data, &tangent_buffers, + &num_tangent_buffers); + + // cgltf scene not needed beyond this point. + cgltf_free(data); + + for (cgltf_size i = 0; i < num_tangent_buffers; ++i) { + print_tangent_buffer(tangent_buffers, 10); + } + + return 0; +} -- cgit v1.2.3