### Basic CMake Project Setup Source: https://github.com/syoyo/tinygltf/blob/release/examples/dxview/CMakeLists.txt Initializes CMake version and project name. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.5) project(dxview) ``` -------------------------------- ### Install tinygltf Library and Configuration Files Source: https://github.com/syoyo/tinygltf/blob/release/CMakeLists.txt Handles the installation of the tinygltf library targets, export files, and configuration files when TINYGLTF_INSTALL is enabled. It also installs header files. ```cmake if (TINYGLTF_INSTALL) install(TARGETS tinygltf EXPORT tinygltfTargets) install(EXPORT tinygltfTargets NAMESPACE tinygltf:: FILE TinyGLTFTargets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tinygltf) configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/TinyGLTFConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/TinyGLTFConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TinyGLTFConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tinygltf) # Do not install .lib even if !TINYGLTF_HEADER_ONLY INSTALL ( FILES tiny_gltf.h tiny_gltf_v3.h tiny_gltf_v3.c tinygltf_json.h tinygltf_json_c.h ${TINYGLTF_EXTRA_SOUECES} DESTINATION include ) if(TINYGLTF_INSTALL_VENDOR) INSTALL ( FILES json.hpp stb_image.h stb_image_write.h DESTINATION include ) endif() endif(TINYGLTF_INSTALL) ``` -------------------------------- ### Installation Rule Source: https://github.com/syoyo/tinygltf/blob/release/examples/glview/CMakeLists.txt Specifies that the 'glview' executable should be installed into the 'bin' directory. ```cmake install ( TARGETS glview DESTINATION bin ) ``` -------------------------------- ### Install Option Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Configures an option to enable the installation of GLM. ```cmake option(GLM_INSTALL_ENABLE "GLM install" ON) ``` -------------------------------- ### Basic CMake Setup Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Initializes CMake, sets the project name and version, and includes necessary modules. ```cmake cmake_minimum_required(VERSION 2.6 FATAL_ERROR) cmake_policy(VERSION 2.6) if (NOT CMAKE_VERSION VERSION_LESS "3.1") cmake_policy(SET CMP0054 NEW) endif() project(glm) set(GLM_VERSION "0.9.9") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(GNUInstallDirs) include(CMakePackageConfigHelpers) enable_testing() ``` -------------------------------- ### Install Dependencies with Vcpkg Source: https://github.com/syoyo/tinygltf/blob/release/examples/dxview/README.md Installs the GLFW and spdlog libraries for Windows x64 using the vcpkg package manager. Ensure vcpkg is set up before running. ```bash vcpkg install glfw3:x64-windows vcpkg install spdlog:x64-windows ``` -------------------------------- ### Install GLM pkg-config File Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Installs the GLM pkg-config file if GLM installation is enabled. ```cmake if (GLM_INSTALL_ENABLE) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/glm.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endif() ``` -------------------------------- ### Add GL Examples Subdirectories Source: https://github.com/syoyo/tinygltf/blob/release/CMakeLists.txt Conditionally adds subdirectories for GL examples if TINYGLTF_BUILD_GL_EXAMPLES is enabled. ```cmake if (TINYGLTF_BUILD_GL_EXAMPLES) add_subdirectory( examples/gltfutil ) add_subdirectory( examples/glview ) endif (TINYGLTF_BUILD_GL_EXAMPLES) ``` -------------------------------- ### Install GLM Configuration Files Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Installs the generated GLM configuration files if GLM installation is enabled. ```cmake if (GLM_INSTALL_ENABLE) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${GLM_INSTALL_CONFIGDIR}/glmConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/glmConfigVersion.cmake" DESTINATION ${GLM_INSTALL_CONFIGDIR}) endif() ``` -------------------------------- ### GLSL Swizzle Examples Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/manual.md Illustrates GLSL swizzle syntax for selecting and assigning vector components. Note that 'D = B.rsz' is an invalid example. ```cpp vec4 A; vec2 B; B.yx = A.wy; B = A.xx; vec3 C = A.bgr; vec3 D = B.rsz; // Invalid, won't compile ``` -------------------------------- ### Add Validator Example Subdirectory Source: https://github.com/syoyo/tinygltf/blob/release/CMakeLists.txt Conditionally adds the subdirectory for the validator example if TINYGLTF_BUILD_VALIDATOR_EXAMPLE is enabled. ```cmake if (TINYGLTF_BUILD_VALIDATOR_EXAMPLE) add_subdirectory( examples/validator ) endif (TINYGLTF_BUILD_VALIDATOR_EXAMPLE) ``` -------------------------------- ### Add Builder Example Subdirectory Source: https://github.com/syoyo/tinygltf/blob/release/CMakeLists.txt Conditionally adds the subdirectory for the glTF builder example if TINYGLTF_BUILD_BUILDER_EXAMPLE is enabled. ```cmake if (TINYGLTF_BUILD_BUILDER_EXAMPLE) add_subdirectory ( examples/build-gltf ) endif (TINYGLTF_BUILD_BUILDER_EXAMPLE) ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/syoyo/tinygltf/blob/release/examples/glview/CMakeLists.txt Initializes CMake, sets the project name, and defines the prefix path for package searching. ```cmake cmake_minimum_required(VERSION 3.5) project(glview) set ( CMAKE_PREFIX_PATH cmake ) ``` -------------------------------- ### Include Directories Setup Source: https://github.com/syoyo/tinygltf/blob/release/examples/glview/CMakeLists.txt Specifies the directories where header files for the project and its dependencies can be found. ```cmake include_directories( ../../ ../common # ${OPENGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} ${GLFW3_INCLUDE_DIR} ) ``` -------------------------------- ### Configure GLM Installation Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Sets the installation directory for GLM configuration files and conditionally installs the GLM headers. ```cmake set(GLM_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/glm") if (GLM_INSTALL_ENABLE) install(DIRECTORY glm DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) endif() write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/glmConfigVersion.cmake" VERSION ${GLM_VERSION} COMPATIBILITY AnyNewerVersion) ``` -------------------------------- ### Install GLM Package Configuration Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Installs the GLM package configuration file to the specified directory. ```cmake configure_package_config_file( cmake/glmConfig.cmake.in ${GLM_INSTALL_CONFIGDIR}/glmConfig.cmake INSTALL_DESTINATION ${GLM_INSTALL_CONFIGDIR} PATH_VARS CMAKE_INSTALL_INCLUDEDIR NO_CHECK_REQUIRED_COMPONENTS_MACRO) ``` -------------------------------- ### Add Loader Example Executable Source: https://github.com/syoyo/tinygltf/blob/release/CMakeLists.txt Conditionally adds the loader_example executable if TINYGLTF_BUILD_LOADER_EXAMPLE is enabled. ```cmake if (TINYGLTF_BUILD_LOADER_EXAMPLE) add_executable(loader_example loader_example.cc ) endif (TINYGLTF_BUILD_LOADER_EXAMPLE) ``` -------------------------------- ### Open File Dialog Example Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/nativefiledialog/README.md Demonstrates how to open a native file dialog to select a single file. Handles success, cancellation, and errors. Requires freeing the output path. ```C #include #include #include int main( void ) { nfdchar_t *outPath = NULL; nfdresult_t result = NFD_OpenDialog( NULL, NULL, &outPath ); if ( result == NFD_OKAY ) { puts("Success!"); puts(outPath); free(outPath); } else if ( result == NFD_CANCEL ) { puts("User pressed cancel."); } else { printf("Error: %s\n", NFD_GetError() ); } return 0; } ``` -------------------------------- ### Include CMake Modules Source: https://github.com/syoyo/tinygltf/blob/release/CMakeLists.txt Includes standard CMake modules for installation and package configuration. ```cmake include(GNUInstallDirs) include(CMakePackageConfigHelpers) ``` -------------------------------- ### Build with Draco Integration Source: https://github.com/syoyo/tinygltf/blob/release/examples/glview/README.md Build the viewer with Draco compression support using CMake. Ensure you specify the correct path to your Draco installation. ```bash mkdir build cd build cmake -DDRACO_DIR=/path/to/draco ../ make ``` -------------------------------- ### gltfutil CMakeLists.txt Configuration Source: https://github.com/syoyo/tinygltf/blob/release/examples/gltfutil/CMakeLists.txt Configures the gltfutil project using CMake. Sets the minimum version, project name, C++ standard, includes necessary directories, finds source files, builds the executable, and specifies installation. ```cmake cmake_minimum_required(VERSION 3.6) project(gltfutil) set(CMAKE_CXX_STANDARD 11) include_directories(../../) include_directories(../common/) file(GLOB gltfutil_sources *.cc *.h) add_executable(gltfutil ${gltfutil_sources} ../common/lodepng.cpp) install ( TARGETS gltfutil DESTINATION bin ) ``` -------------------------------- ### Install Clang and LibFuzzer on Ubuntu Source: https://github.com/syoyo/tinygltf/blob/release/tests/fuzzer/README.md Installs the necessary Clang compiler and LibFuzzer development libraries on Ubuntu 18.04. Ensure you have clang 8.0 or later for fuzzer support. ```bash $ sudo apt install clang++-8 $ sudo apt install libfuzzer-8-dev ``` -------------------------------- ### GLM Example Usage: Matrix Transformation Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/manual.md Demonstrates creating a transformation matrix using GLM, including perspective projection, translation, and rotation. This snippet requires including core and extension headers. ```cpp // Include GLM core features #include #include #include #include // Include GLM extensions #include glm::mat4 transform(glm::vec2 const& Orientation, glm::vec3 const& Translate, glm::vec3 const& Up) { glm::mat4 Proj = glm::perspective(glm::radians(45.f), 1.33f, 0.1f, 10.f); glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.f), Translate); glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Orientation.y, Up); glm::mat4 View = glm::rotate(ViewRotateX, Orientation.x, Up); glm::mat4 Model = glm::mat4(1.0f); return Proj * View * Model; } ``` -------------------------------- ### Define Build Options Source: https://github.com/syoyo/tinygltf/blob/release/CMakeLists.txt Defines boolean options to control the build process, such as enabling example executables, tests, and header-only mode. ```cmake option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example(load glTF and dump infos)" ON) option(TINYGLTF_BUILD_GL_EXAMPLES "Build GL exampels(requires glfw, OpenGL, etc)" OFF) option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator exampe" OFF) option(TINYGLTF_BUILD_BUILDER_EXAMPLE "Build glTF builder example" OFF) option(TINYGLTF_BUILD_TESTS "Build unit tests" OFF) option(TINYGLTF_HEADER_ONLY "On: header-only mode. Off: create tinygltf library(No TINYGLTF_IMPLEMENTATION required in your project)" OFF) option(TINYGLTF_INSTALL "Install tinygltf files during install step. Usually set to OFF if you include tinygltf through add_subdirectory()" ON) option(TINYGLTF_INSTALL_VENDOR "Install vendored nlohmann/json and nothings/stb headers" ON) option(TINYGLTF_USE_CUSTOM_JSON "Use the built-in fast JSON parser (tinygltf_json.h) instead of nlohmann/json" OFF) ``` -------------------------------- ### Build tinygltf-validator with CMake Source: https://github.com/syoyo/tinygltf/blob/release/examples/validator/README.md Standard CMake build process for C++ projects. Ensure you have a C++11 compiler and CMake installed. ```bash $ mkdir build $ cd build $ cmake .. $ make ``` -------------------------------- ### Generate Project Files with CMake Source: https://github.com/syoyo/tinygltf/blob/release/examples/dxview/README.md Generates build project files using CMake. This command assumes you have vcpkg installed and its toolchain file path is correctly set in the VCPKG_DIR environment variable. ```bash mkdir build cmake . -B build -DCMAKE_TOOLCHAIN_FILE=${VCPKG_DIR}/script/buildsystem/vcpkg.cmake ``` -------------------------------- ### Include GLM Core Features Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/manual.md Include individual GLM headers for specific types and functions to optimize compilation times. This example shows how to include various vector, matrix, and common GLSL functions. ```cpp #include // vec2, bvec2, dvec2, ivec2 and uvec2 #include // vec3, bvec3, dvec3, ivec3 and uvec3 #include // vec4, bvec4, dvec4, ivec4 and uvec4 #include // mat2, dmat2 #include // mat2x3, dmat2x3 #include // mat2x4, dmat2x4 #include // mat3x2, dmat3x2 #include // mat3, dmat3 #include // mat3x4, dmat2 #include // mat4x2, dmat4x2 #include // mat4x3, dmat4x3 #include // mat4, dmat4 #include // all the GLSL common functions #include // all the GLSL exponential functions #include // all the GLSL geometry functions #include // all the GLSL integer functions #include // all the GLSL matrix functions #include // all the GLSL packing functions #include // all the GLSL trigonometric functions #include // all the GLSL vector relational functions ``` -------------------------------- ### Build Instructions for Windows Source: https://github.com/syoyo/tinygltf/blob/release/examples/raytrace/README.md Command to generate Visual Studio project files on Windows using premake5. ```bash premake5 vs2015 ``` -------------------------------- ### Build Instructions for Linux/macOS Source: https://github.com/syoyo/tinygltf/blob/release/examples/raytrace/README.md Commands to build the project on Linux or macOS using premake5. ```bash premake5 gmake make ``` -------------------------------- ### Compile and Run Unit Tests Source: https://github.com/syoyo/tinygltf/blob/release/README.md Navigate to the tests directory, compile the unit tests using make, and then execute the test binaries. ```bash $ cd tests $ make $ ./tester $ ./tester_noexcept ``` -------------------------------- ### Build on Linux and macOS Source: https://github.com/syoyo/tinygltf/blob/release/examples/basic/README.md Use premake5 to generate Makefiles and then build the project on Linux and macOS. ```bash $ premake5 gmake $ make ``` -------------------------------- ### Compile loader_example.cc with WASI SDK Source: https://github.com/syoyo/tinygltf/blob/release/wasm/README.md Compile the loader_example.cc file using clang++ from the WASI SDK. Ensure to use the specified flags for no RTTI and no exceptions, and include the necessary include path. ```bash $ /path/to/wasi-sdk-16.0/bin/clang++ ../loader_example.cc -fno-rtti -fno-exceptions -g -Os -I../ -o loader_example.wasi ``` -------------------------------- ### Get Vector Length Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/manual.md Demonstrates using the .length() member function to get the size of a GLM vector. The return type is typically int, but can be configured to size_t. ```cpp #include void foo(vec4 const & v) { int Length = v.length(); ... } ``` ```cpp #define GLM_FORCE_SIZE_T_LENGTH #include void foo(vec4 const & v) { glm::length_t Length = v.length(); ... } ``` -------------------------------- ### Aligned Double Precision Vectors Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00106_source.html Example of an aligned double-precision vector type. ```APIDOC ## Aligned Double Precision Vectors ### `aligned_mediump_dvec2` - **Description**: 2 components vector of medium double-precision floating-point numbers. - **Definition**: Linked from `gtc/type_aligned.hpp` ``` -------------------------------- ### Run loader_example.wasi with Wasmtime Source: https://github.com/syoyo/tinygltf/blob/release/wasm/README.md Execute the compiled WebAssembly module using Wasmtime. The `--dir` flag is used to specify a directory containing glTF files, and the path to the glTF file is provided as an argument. ```bash $ wasmtime --dir=../models loader_example.wasi ../models/Cube/Cube.gltf ``` -------------------------------- ### glm::bitfieldExtract Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00033_source.html Extracts a specified number of bits from a value starting at a given offset. ```APIDOC ## bitfieldExtract ### Description Extracts a specified number of bits from a value starting at a given offset. ### Method `bitfieldExtract(Value, Offset, Bits)` ### Parameters - **Value** (vecType) - The input vector from which to extract bits. - **Offset** (int) - The starting bit position for extraction. - **Bits** (int) - The number of bits to extract. ### Returns `vecType` - A vector containing the extracted bits. ``` -------------------------------- ### Configure Clang Alternatives on Ubuntu Source: https://github.com/syoyo/tinygltf/blob/release/tests/fuzzer/README.md Sets the default clang and clang++ commands to use clang++-8. This is an optional step if update-alternatives is not already configured. ```bash $ sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-8 10 $ sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-8 10 ``` -------------------------------- ### glm::row (get) Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00166.html Retrieves a specific row from a matrix. This function is part of the GLM_GTC_matrix_access extension. ```APIDOC ## glm::row (get) ### Description Get a specific row of a matrix. ### Method Not applicable (function signature) ### Parameters - **m** (genType const &) - The input matrix. - **index** (length_t) - The index of the row to retrieve. ### Return Value genType::row_type - The specified row of the matrix. ``` -------------------------------- ### glm::column (get) Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00166.html Retrieves a specific column from a matrix. This function is part of the GLM_GTC_matrix_access extension. ```APIDOC ## glm::column (get) ### Description Get a specific column of a matrix. ### Method Not applicable (function signature) ### Parameters - **m** (genType const &) - The input matrix. - **index** (length_t) - The index of the column to retrieve. ### Return Value genType::col_type - The specified column of the matrix. ``` -------------------------------- ### tvec4 Length Function Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00129_source.html Static function to get the dimension of the tvec4 vector, which is always 4. ```c++ GLM_FUNC_DECL static length_t [length](a00147.html#ga18d45e3d4c7705e67ccfabd99e521604)(){return 4;} ``` -------------------------------- ### Define Build Model (32/64-bit) Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00099_source.html Determines and defines the build model (32-bit or 64-bit) based on common preprocessor macros indicating the architecture. Defaults to 32-bit if no specific architecture macro is found. ```c++ #if defined(__arch64__) || defined(__LP64__) || defined(_M_X64) || defined(__ppc64__) || defined(__x86_64__) # define GLM_MODEL GLM_MODEL_64 #elif defined(__i386__) || defined(__ppc__) # define GLM_MODEL GLM_MODEL_32 #else # define GLM_MODEL GLM_MODEL_32 #endif// ``` -------------------------------- ### Integrate Tinygltf with CMake Source: https://github.com/syoyo/tinygltf/blob/release/README.md Configure Tinygltf as a header-only library and disable installation when adding it as a subdirectory to your project. ```cmake set(TINYGLTF_HEADER_ONLY ON CACHE INTERNAL "" FORCE) set(TINYGLTF_INSTALL OFF CACHE INTERNAL "" FORCE) add_subdirectory(/path/to/tinygltf) ``` -------------------------------- ### Add GLM Interface Library Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Adds an interface library for GLM and sets include directories for installation and build. ```cmake if (NOT CMAKE_VERSION VERSION_LESS "3.0") add_library(glm INTERFACE) target_include_directories(glm INTERFACE $ $) install(TARGETS glm EXPORT glmTargets) export(EXPORT glmTargets FILE "${CMAKE_CURRENT_BINARY_DIR}/glmTargets.cmake") if (GLM_INSTALL_ENABLE) install(EXPORT glmTargets FILE glmTargets.cmake DESTINATION ${GLM_INSTALL_CONFIGDIR}) endif() endif() ``` -------------------------------- ### Load a glTF File with TinyGLTF v3 Source: https://github.com/syoyo/tinygltf/blob/release/README.md Demonstrates how to load a glTF file using `tg3_parse_file`. It initializes options and error structures, parses the file, handles potential errors by printing them to stderr, and finally frees the model and error structures. ```c tg3_parse_options opts; tg3_error_stack errors; tg3_model model; tg3_parse_options_init(&opts); tg3_error_stack_init(&errors); tg3_error_code err = tg3_parse_file(&model, &errors, "scene.gltf", 10, &opts); if (err != TG3_OK) { for (uint32_t i = 0; i < errors.count; i++) { fprintf(stderr, "[%d] %s\n", (int)errors.entries[i].severity, errors.entries[i].message ? errors.entries[i].message : "(null)"); } } // ... use model ... tg3_model_free(&model); tg3_error_stack_free(&errors); ``` -------------------------------- ### Get Number of Components for tvec4 Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00091_source.html Returns the number of components for a tvec4 vector. This is used to support range-based for loops. ```cpp template inline length_t components(tvec4 const & v) { return v.length(); } ``` -------------------------------- ### Load glTF 2.0 Model from File Source: https://github.com/syoyo/tinygltf/blob/release/README.md Demonstrates how to load a glTF 2.0 model from a file using TinyGLTF. Ensure necessary headers and implementation definitions are included. This snippet shows both ASCII and binary loading options. ```c++ #define TINYGLTF_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION // #define TINYGLTF_NOEXCEPTION // optional. disable exception handling. #include "tiny_gltf.h" using namespace tinygltf; Model model; TinyGLTF loader; std::string err; std::string warn; std::string filename = "input.gltf"; bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, filename); //bool ret = loader.LoadBinaryFromFile(&model, &err, &warn, filename); // for binary glTF(.glb) if (!warn.empty()) { printf("Warn: %s\n", warn.c_str()); } if (!err.empty()) { printf("Err: %s\n", err.c_str()); } if (!ret) { printf("Failed to parse glTF: %s\n", filename.c_str()); } ``` -------------------------------- ### Get Number of Components for tvec3 Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00091_source.html Returns the number of components for a tvec3 vector. This is used to support range-based for loops. ```cpp template inline length_t components(tvec3 const & v) { return v.length(); } ``` -------------------------------- ### Get Number of Components for tvec2 Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00091_source.html Returns the number of components for a tvec2 vector. This is used to support range-based for loops. ```cpp template inline length_t components(tvec2 const & v) { return v.length(); } ``` -------------------------------- ### CMakeLists.txt Configuration for GLM Test Package Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/util/conan-package/test_package/CMakeLists.txt Sets up the CMake project, includes Conan build information, and configures compiler and linker flags using Conan variables. This is essential for building the test executable with the correct dependencies and settings provided by Conan. ```cmake project(GlmTest) cmake_minimum_required(VERSION 3.0.0) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) conan_basic_setup() set(CMAKE_C_FLAGS "${CONAN_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CONAN_CXX_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "${CONAN_SHARED_LINKER_FLAGS}") add_executable(testGlm main.cpp) TARGET_COMPILE_DEFINITIONS(testGlm PUBLIC "${CONAN_DEFINES}") TARGET_LINK_LIBRARIES(testGlm PUBLIC "${CONAN_LIBS}") SET_TARGET_PROPERTIES(testGlm PROPERTIES LINK_FLAGS "${CONAN_EXE_LINKER_FLAGS}") ``` -------------------------------- ### CMakeLists.txt for GLTF Project Source: https://github.com/syoyo/tinygltf/blob/release/examples/build-gltf/CMakeLists.txt This snippet shows a basic CMakeLists.txt file for a GLTF project. It sets include directories, defines an executable, and configures compile options and libraries. ```cmake include_directories(${CMAKE_SOURCE_DIR}) add_executable(create_triangle_gltf create_triangle_gltf.cpp) target_compile_options(create_triangle_gltf PUBLIC -Wall) target_link_libraries(create_triangle_gltf ) ``` -------------------------------- ### Get Number of Components for tvec1 Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00091_source.html Returns the number of components for a tvec1 vector. This is used to support range-based for loops. ```cpp #include "../detail/setup.hpp" #include "../gtc/type_ptr.hpp" #include "../gtc/vec1.hpp" template inline length_t components(tvec1 const & v) { return v.length(); } ``` -------------------------------- ### project Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00071.html Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. ```APIDOC ## project ### Description Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. ### Signature ```cpp template tvec3< T, P > project(tvec3< T, P > const &obj, tmat4x4< T, P > const &model, tmat4x4< T, P > const &proj, tvec4< U, P > const &viewport) ``` ### Parameters * **obj** (tvec3< T, P > const &) - Object coordinates. * **model** (tmat4x4< T, P > const &) - Model matrix. * **proj** (tmat4x4< T, P > const &) - Projection matrix. * **viewport** (tvec4< U, P > const &) - Viewport transformation. ``` -------------------------------- ### row (get) Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00062.html Retrieves a specific row from a given matrix. This function is templated to work with various matrix types. ```APIDOC ## row (get) ### Description Get a specific row of a matrix. ### Method Not applicable (function signature) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - **genType::row_type**: The type of the row vector. #### Response Example None ``` -------------------------------- ### column (get) Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00062.html Retrieves a specific column from a given matrix. This function is templated to work with various matrix types. ```APIDOC ## column (get) ### Description Get a specific column of a matrix. ### Method Not applicable (function signature) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response - **genType::col_type**: The type of the column vector. #### Response Example None ``` -------------------------------- ### Infinite Perspective Matrix with Epsilon Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00169.html Creates a symmetric perspective-view frustum matrix with an infinite far plane, useful for hardware without depth clamping. Includes an epsilon parameter. Requires GLM. ```cpp glm::mat4 tweakedInfinitePerspective( T fovy, T aspect, T near_, T ep ) ``` -------------------------------- ### Get End Iterator for Constant Types Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00091_source.html Returns a pointer to the end of the data for a GLM type. This is used for range-based for loops. ```cpp template inline typename genType::value_type const * end(genType const & v) { return begin(v) + components(v); } ``` -------------------------------- ### Add TinyGLTF V3 C Test with V1 Port and Filesystem Support Source: https://github.com/syoyo/tinygltf/blob/release/CMakeLists.txt Configures a TinyGLTF V3 C test executable, specifically for V1 port compatibility, with filesystem support enabled. Utilizes the `add_tinygltf_v3_c_test` macro. ```cmake add_tinygltf_v3_c_test(tester_v3_c_v1port tests/tester_v3_c_v1port.c tiny_gltf_v3.c) target_compile_definitions(tester_v3_c_v1port PRIVATE TINYGLTF3_ENABLE_FS) ``` -------------------------------- ### unProject Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00071.html Map the specified window coordinates (win.x, win.y, win.z) into object coordinates. ```APIDOC ## unProject ### Description Map the specified window coordinates (win.x, win.y, win.z) into object coordinates. ### Signature ```cpp template tvec3< T, P > unProject(tvec3< T, P > const &win, tmat4x4< T, P > const &model, tmat4x4< T, P > const &proj, tvec4< U, P > const &viewport) ``` ### Parameters * **win** (tvec3< T, P > const &) - Window coordinates. * **model** (tmat4x4< T, P > const &) - Model matrix. * **proj** (tmat4x4< T, P > const &) - Projection matrix. * **viewport** (tvec4< U, P > const &) - Viewport transformation. ``` -------------------------------- ### Setting Include Directories Source: https://github.com/syoyo/tinygltf/blob/release/examples/dxview/CMakeLists.txt Configures the include paths for the 'dxview' target. The PRIVATE keyword means these directories are only used for compiling the target itself. ```cmake target_include_directories(dxview PRIVATE ../../ ) ``` -------------------------------- ### Get Begin Iterator for Constant Types Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00091_source.html Returns a constant pointer to the beginning of the data for a GLM type. This is used for range-based for loops. ```cpp template inline typename genType::value_type const * begin(genType const & v) { return value_ptr(v); } ``` -------------------------------- ### Camera Matrix Calculation with GLM Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/readme.md This snippet demonstrates how to construct a camera transformation matrix using GLM. It includes translation, rotation, and scaling, along with perspective projection. Ensure GLM headers for vectors, matrices, and transformation functions are included. ```cpp #include // glm::vec3 #include // glm::vec4 #include // glm::mat4 #include // glm::translate, glm::rotate, glm::scale, glm::perspective #include // glm::pi glm::mat4 camera(float Translate, glm::vec2 const & Rotate) { glm::mat4 Projection = glm::perspective(glm::pi() * 0.25f, 4.0f / 3.0f, 0.1f, 100.f); glm::mat4 View = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate)); View = glm::rotate(View, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f)); View = glm::rotate(View, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f)); glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f)); return Projection * View * Model; } ``` -------------------------------- ### Get Number of Components for Matrix Types Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00091_source.html Returns the total number of components for a matrix type. This is used to support range-based for loops. ```cpp template inline length_t components(genType const & m) { return m.length() * m[0].length(); } ``` -------------------------------- ### Include Directories and Subdirectories Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Sets include directories for the project source and test external directories. Adds GLM and test subdirectories. ```cmake include_directories("${PROJECT_SOURCE_DIR}") include_directories("${PROJECT_SOURCE_DIR}/test/external") add_subdirectory(glm) add_subdirectory(test) ``` -------------------------------- ### Get End Iterator for Mutable Types Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00091_source.html Returns a pointer to the end of the data for a GLM type, allowing modification. This is used for range-based for loops. ```cpp template inline typename genType::value_type * end(genType& v) { return begin(v) + components(v); } ``` -------------------------------- ### Get Begin Iterator for Mutable Types Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00091_source.html Returns a pointer to the beginning of the data for a GLM type, allowing modification. This is used for range-based for loops. ```cpp template inline typename genType::value_type * begin(genType& v) { return value_ptr(v); } ``` -------------------------------- ### Include TinyGLTF v3 Header Source: https://github.com/syoyo/tinygltf/blob/release/README.md Include the main header file for the TinyGLTF v3 library. This is the first step before using any of its functionalities. ```c #include "tiny_gltf_v3.h" ``` -------------------------------- ### project Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00071_source.html Maps the specified object coordinates into window coordinates. ```APIDOC ## project ### Description Maps the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. ### Method `project(tvec3 const & obj, tmat4x4 const & model, tmat4x4 const & proj, tvec4 const & viewport)` ### Parameters - `obj` (tvec3) - Object coordinates. - `model` (tmat4x4) - Model matrix. - `proj` (tmat4x4) - Projection matrix. - `viewport` (tvec4) - Viewport transformation. ``` -------------------------------- ### glm::bitfieldExtract Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00033_source.html Extracts a specified number of bits from a value, starting at a given offset. The extracted bits are returned in the least significant positions. ```APIDOC ## glm::bitfieldExtract ### Description Extracts bits [offset, offset + bits - 1] from value, returning them in the least significant bits of the result. ### Function Signature `vecType< T, P > bitfieldExtract(vecType< T, P > const &Value, int Offset, int Bits)` ### Parameters - **Value** (vecType< T, P >) - The value from which to extract bits. - **Offset** (int) - The starting bit position for extraction (0-based). - **Bits** (int) - The number of bits to extract. ``` -------------------------------- ### Accessing Accessor and BufferView for Vertex Data Source: https://github.com/syoyo/tinygltf/wiki/Accessing-vertex-data This snippet shows how to get the accessor and bufferView for the 'POSITION' attribute of a glTF primitive. Ensure the glTF model is loaded before using this. ```c++ const tinygltf::Model& model; // Assuming you loaded the gltf model. ... for each primitive in a mesh... const tinygltf::Accessor& accessor = model.accessors[primitive.attributes["POSITION"]]; const tinygltf::BufferView& bufferView = model.bufferViews[accessor.bufferView]; ``` -------------------------------- ### macOS Specific Libraries Source: https://github.com/syoyo/tinygltf/blob/release/examples/glview/CMakeLists.txt Finds and sets up macOS-specific frameworks like Cocoa, CoreVideo, and IOKit when building on Apple platforms. ```cmake if (APPLE) find_library(COCOA_LIBRARY Cocoa) find_library(COREVIDEO_LIBRARY CoreVideo) find_library(IOKIT_LIBRARY IOKit) endif () ``` -------------------------------- ### SIMD Optimization Options Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Configures options to enable various SIMD (SSE2, SSE3, AVX, AVX2) optimizations. ```cmake option(GLM_TEST_ENABLE_SIMD_SSE2 "Enable SSE2 optimizations" OFF) option(GLM_TEST_ENABLE_SIMD_SSE3 "Enable SSE3 optimizations" OFF) option(GLM_TEST_ENABLE_SIMD_AVX "Enable AVX optimizations" OFF) option(GLM_TEST_ENABLE_SIMD_AVX2 "Enable AVX2 optimizations" OFF) option(GLM_TEST_FORCE_PURE "Force 'pure' instructions" OFF) ``` -------------------------------- ### Platform-Specific Dependencies (Linux/Unix) Source: https://github.com/syoyo/tinygltf/blob/release/examples/glview/CMakeLists.txt Sets up additional libraries required for GLFW on Linux/Unix systems, such as X11 and related extensions. ```cmake if (NOT WIN32) # This means it is Unices set (GLFW3_UNIX_LINK_LIBRARIES X11 Xxf86vm Xrandr Xi Xinerama Xcursor ) find_package (Threads) endif() ``` -------------------------------- ### Interpolation with Mixed Types Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00145.html Demonstrates that the type of the third parameter (interpolant) does not need to match the first two parameters. This example uses a double vector for the first two parameters and a float for the interpolant. ```cpp glm::dvec3 t = glm::mix([e](a00162.html#ga4b7956eb6e2fbedfc7cf2e46e85c5139), f, a); // Types of the third parameter is not required to match with the first and the second. ``` -------------------------------- ### Linking Libraries to the Executable Source: https://github.com/syoyo/tinygltf/blob/release/examples/dxview/CMakeLists.txt Links the necessary system and external libraries to the 'dxview' target. This ensures the executable has access to the required functionalities at runtime. ```cmake target_link_libraries(dxview PRIVATE dxgi d3dcompiler d3d12 glfw spdlog::spdlog ) ``` -------------------------------- ### Using glm::value_ptr for glUniform calls Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00178.html Demonstrates how to use glm::value_ptr to get a pointer to the data of a GLM vector or matrix for use with OpenGL uniform functions. Ensure GLM_GTC_type_ptr is included. ```cpp #include #include gl_uniform_type uniformLoc; gl_uniform_type uniformMatrixLoc; gl_vec3 aVector(3); gl_mat4 someMatrix(1.0); glUniform3fv(uniformLoc, 1, glm::value_ptr(aVector)); glUniformMatrix4fv(uniformMatrixLoc, 1, GL_FALSE, glm::value_ptr(someMatrix)); ``` -------------------------------- ### Infinite Perspective Matrix Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00169.html Creates a symmetric perspective-view frustum matrix with an infinite far plane, useful for hardware without depth clamping. Requires GLM. ```cpp glm::mat4 tweakedInfinitePerspective( T fovy, T aspect, T near_ ) ``` -------------------------------- ### glm::bitfieldInterleave (int16) Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00159.html Interleaves the bits of four int16 values (x, y, z, w). The interleaving process follows the same pattern as the uint8 version, starting with the least significant bit of each input. ```APIDOC ## glm::bitfieldInterleave (int16) ### Description Interleaves the bits of x, y, z and w. The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w. The other bits are interleaved following the previous sequence. ### Parameters * **x** (int16) - The first input value. * **y** (int16) - The second input value. * **z** (int16) - The third input value. * **w** (int16) - The fourth input value. ### Returns A int64 value with interleaved bits from the input parameters. ``` -------------------------------- ### Run glTF Parsing Test Source: https://github.com/syoyo/tinygltf/blob/release/README.md Execute the Python script to test glTF model parsing. Ensure the glTF Sample Models repository is cloned locally and the test runner script is configured. ```bash $ python test_runner.py ``` -------------------------------- ### Fast Math Test Option Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Configures an option to enable fast math optimizations for tests. ```cmake option(GLM_TEST_ENABLE_FAST_MATH "Enable fast math optimizations" OFF) ``` -------------------------------- ### Using glm::value_ptr for GLM Types Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/manual.md Demonstrates how to use glm::value_ptr to get pointers to GLM vectors and matrices for use with OpenGL functions like glVertex3fv and glLoadMatrixfv. Ensure is included. ```cpp #include #include void foo() { glm::vec4 v(0.0f); glm::mat4 m(1.0f); ... glVertex3fv(glm::value_ptr(v)) glLoadMatrixfv(glm::value_ptr(m)); } ``` -------------------------------- ### Unproject Window Coordinates to Object Coordinates Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00169.html Maps window coordinates (screen space) to object coordinates in 3D space using model, projection, and viewport matrices. Requires GLM. ```cpp glm::vec3 unProject( glm::vec3 const & win, glm::mat4 const & model, glm::mat4 const & proj, glm::vec4 const & viewport ) ``` -------------------------------- ### Getting a constant pointer to GLM type data Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00178.html Returns a constant pointer to the data of the input GLM vector or matrix type. This is useful for passing data to functions that require a const pointer, such as OpenGL uniform functions. ```cpp GLM_FUNC_DECL genType::value_type const* glm::value_ptr(genType const & _vec) ``` -------------------------------- ### tmat3x2 Constructors Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00116_source.html Provides various constructors for initializing a 3x2 matrix, including default, copy, scalar, and vector-based initializations. ```APIDOC ## tmat3x2 Constructors ### Description Initializes a 3x2 matrix with different options. ### Constructors - `tmat3x2()`: Default constructor. - `tmat3x2(tmat3x2 const & m)`: Copy constructor. - `template tmat3x2(tmat3x2 const & m)`: Constructor from a matrix with a different precision. - `explicit tmat3x2(ctor)`: Constructor using a specific ctor. - `explicit tmat3x2(T scalar)`: Constructor initializing all elements with a scalar value. - `tmat3x2(T x0, T y0, T x1, T y1, T x2, T y2)`: Constructor from individual scalar values for each element. - `tmat3x2(col_type const & v0, col_type const & v1, col_type const & v2)`: Constructor from column vectors. ``` -------------------------------- ### tmat2x4 Constructors Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00115_source.html Provides details on the various constructors available for initializing a tmat2x4 matrix, including default, copy, scalar, and value-based initializations. ```APIDOC ## tmat2x4 Constructors ### Description Initializes a 2x4 matrix with various methods. ### Constructors - `tmat2x4()`: Default constructor. - `tmat2x4(tmat2x4 const & m)`: Copy constructor. - `template tmat2x4(tmat2x4 const & m)`: Constructor from a matrix with a different precision. - `explicit tmat2x4(ctor)`: Constructor using a specific ctor tag. - `explicit tmat2x4(T scalar)`: Constructor initializing all elements with a scalar value. - `tmat2x4(T x0, T y0, T z0, T w0, T x1, T y1, T z1, T w1)`: Constructor from individual scalar values for each element. - `tmat2x4(col_type const & v0, col_type const & v1)`: Constructor from two column vectors. ``` -------------------------------- ### glm::bitfieldInterleave (uint8) Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00159.html Interleaves the bits of four uint8 values (x, y, z, w). The interleaving starts with the first bit of x, followed by the first bit of y, then z, and finally w. This pattern continues for all bits. ```APIDOC ## glm::bitfieldInterleave (uint8) ### Description Interleaves the bits of x, y, z and w. The first bit is the first bit of x followed by the first bit of y, the first bit of z and finally the first bit of w. The other bits are interleaved following the previous sequence. ### Parameters * **x** (uint8) - The first input value. * **y** (uint8) - The second input value. * **z** (uint8) - The third input value. * **w** (uint8) - The fourth input value. ### Returns A uint32 value with interleaved bits from the input parameters. ``` -------------------------------- ### glm::extend Function Definition and Usage Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00025_source.html Provides the definition and usage example for the glm::extend function. It extends the Origin vector using the direction from Origin to Source, up to the specified Length. Ensure GLM_ENABLE_EXPERIMENTAL is defined before including this extension. ```cpp GLM_FUNC_DECL genType extend(genType const &Origin, genType const &Source, typename genType::value_type const Length) { return Origin + normalize(Source - Origin) * Length; } ``` -------------------------------- ### make_mat3 Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/doc/api/a00123.html Builds a 3x3 matrix from a pointer to its elements. ```APIDOC ## make_mat3 ### Description Builds a 3x3 matrix from a pointer. ### Method Not applicable (C++ function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp typename T const * ptr; typename tmat3x3< T, defaultp > matrix = make_mat3(ptr); ``` ### Response #### Success Response A `tmat3x3` matrix constructed from the provided pointer. #### Response Example None (C++ return value) ``` -------------------------------- ### Configure GLM pkg-config File Source: https://github.com/syoyo/tinygltf/blob/release/examples/common/glm/CMakeLists.txt Configures the pkg-config file for GLM using a template. ```cmake configure_file("./cmake/glm.pc.in" "glm.pc" @ONLY) ```