Compare commits

...

37 Commits

Author SHA1 Message Date
Syoyo Fujita
797bf0e023 Use CMake and ctest for Linux and macOS native builds
Convert manual g++/clang++ builds to CMake for consistency with
Windows builds:
- Linux x64 (GCC)
- Linux ARM64 (GCC)
- macOS ARM64 Apple Silicon (Clang)

All native builds now use:
- cmake -B build -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
- cmake --build build
- ctest --test-dir build --output-on-failure

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-06 00:52:59 +09:00
Syoyo Fujita
10ac914244 Update Linux Clang job to use Clang 21
- Install Clang 21 from LLVM apt repository
- Use CMake with clang-21/clang++-21 compilers
- Run tests with ctest

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-06 00:24:55 +09:00
Syoyo Fujita
dc6dddac98 Merge pull request #529 from syoyo/copilot/update-ci-workflow-comprehensive-builds
Add comprehensive multi-platform CI workflow with 15 build configurations
2026-02-05 05:42:31 +09:00
Syoyo Fujita
b548191e41 Use CMake and ctest for RapidJSON backend build
Convert RapidJSON backend job from manual g++ builds to CMake,
enabling ctest for running tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 05:35:46 +09:00
Syoyo Fujita
17287c7fcf Add ctest to CMake-based builds
Run ctest after build for:
- Windows x64 MSVC
- Windows x86 MSVC
- Windows MinGW MSYS2
- Linux Header-Only Mode

Cross-compile builds (Windows ARM64, Linux→Windows MinGW) are excluded
since tests cannot run on the host.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 05:19:22 +09:00
Syoyo Fujita
6c948d5bc3 Remove macOS Intel job from CI
macOS Intel runners are being deprecated. Keep only the ARM64
Apple Silicon job for macOS coverage.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 05:08:09 +09:00
Syoyo Fujita
d4a4a1b27a Fix CI: update macOS runner and remove Windows unit tests
- Change macos-13 to macos-15-large for Intel x64 (macos-13 is retired)
- Remove Windows MSVC unit tests (they have path-related issues and
  the existing c-cpp.yml workflow doesn't run tests on Windows either)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 04:54:40 +09:00
Syoyo Fujita
3d5453ecd0 Fix Windows MSVC unit tests build by setting up developer environment
The `cl` compiler was not in PATH because the Visual Studio developer
environment needs to be set up before calling MSVC tools directly.
Added `ilammy/msvc-dev-cmd@v1` action to configure the environment.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 04:54:40 +09:00
copilot-swe-agent[bot]
52a453120b Add security: restrict GITHUB_TOKEN permissions to read-only
Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
2026-02-05 04:54:40 +09:00
copilot-swe-agent[bot]
fc6d78a1b6 Add comprehensive CI workflow with multi-platform builds and tests
Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
2026-02-05 04:54:40 +09:00
copilot-swe-agent[bot]
ae0bac486c Initial plan 2026-02-05 04:54:40 +09:00
Syoyo Fujita
b19e665747 Merge pull request #530 from syoyo/add-cmake-test-target
Add CMake test target and fix Windows test failure
2026-02-05 04:52:23 +09:00
Syoyo Fujita
40f6c2b875 Add CMake test target and fix Windows test failure
- Add TINYGLTF_BUILD_TESTS option to build unit tests via CMake
- Test runs from tests/ directory so relative paths work correctly
- Fix Windows file sharing violation in images-as-is test by closing
  fstream before stbi_load attempts to open the same file

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 04:45:27 +09:00
Syoyo Fujita
e8c70dff1d Merge pull request #528 from syoyo/copilot/add-copilot-review-instructions
Add Copilot review instructions for code quality and security checks
2026-02-03 08:55:23 +09:00
copilot-swe-agent[bot]
1dc37f76ea Add Copilot review instructions for tinygltf repository
Co-authored-by: syoyo <18676+syoyo@users.noreply.github.com>
2026-02-02 23:48:15 +00:00
copilot-swe-agent[bot]
8da66b8ca1 Initial plan 2026-02-02 23:46:46 +00:00
Syoyo Fujita
81bd50c106 Merge branch 'release' of github.com:syoyo/tinygltf into release 2025-11-02 10:11:11 +09:00
Syoyo Fujita
6d8bba0d8a Update the usage code: https://github.com/syoyo/tinygltf/pull/524 2025-11-02 10:10:11 +09:00
Syoyo Fujita
2aa77e5d0a Merge pull request #525 from nyalldawson/performance
Minor performance fixes
2025-11-02 10:08:23 +09:00
Nyall Dawson
1fac6234d9 Fix some 'use of auto that causes a copy' warnings 2025-10-31 08:44:42 +10:00
Nyall Dawson
bcd666fbd4 Fix some variable copied when could be moved warnings 2025-10-31 08:44:26 +10:00
Syoyo Fujita
37250b3470 Merge pull request #517 from nepp95/release
Removed TINYGLTF_USE_CPP14 option since it is unused
2025-05-20 06:31:38 +09:00
Niels Eppenhof
7385235e29 Removed TINYGLTF_USE_CPP14 option since it is unused 2025-05-19 14:58:41 +02:00
Syoyo Fujita
3564b48760 Merge pull request #516 from DrQuackeroo/c24695-fix
Initialize Accessor::Sparse members to default values
2025-05-06 09:14:08 +09:00
Sammy Newhide
2ad433b68f Revert 1b517f2 by adding default constructor for Accessor 2025-05-05 17:04:52 -07:00
Sammy Newhide
1b517f2b23 Remove explicit default constructor for Accessor
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-05-05 16:43:20 -07:00
Sammy Newhide
bd7255e095 Initialize Accessor::Sparse members to default values 2025-05-05 15:20:30 -07:00
Syoyo Fujita
a5e653e46c Merge pull request #512 from ctrlaltf2/oob-fix
Add bounds check to images loaded from bufferviews
2025-01-22 22:45:07 +09:00
ctrlaltf2
d530cd410b Add bounds check to images loaded from bufferviews 2025-01-20 23:43:07 -05:00
Syoyo Fujita
1831424c71 Merge pull request #509 from NoirMorilec/fix-no-fs
Added NO_FS definition for std::ofstream usage
2024-12-30 22:11:09 +09:00
Leonid
5e008af65d Added NO_FS definition for std::ofstream usage 2024-12-30 03:12:20 +08:00
Syoyo Fujita
fbff1f45b5 Merge pull request #507 from thearchivalone/release
Documentation: Submodule hint added
2024-12-21 19:59:42 +09:00
Brad
d950e7cd9b Documentation: Submodule hint added 2024-12-20 17:49:51 -06:00
Syoyo Fujita
116d0030f9 Merge pull request #504 from nim65s/vendor 2024-10-16 23:27:42 +09:00
Syoyo Fujita
ff972dcf1b Merge pull request #503 from nim65s/release 2024-10-16 23:26:53 +09:00
Guilhem Saurel
8bec431699 CMake: fix export install dir 2024-10-16 15:53:48 +02:00
Guilhem Saurel
21485496b1 CMake: allow opt-out of installing vendored headers 2024-10-16 14:58:42 +02:00
6 changed files with 493 additions and 35 deletions

View File

@@ -0,0 +1,92 @@
# Copilot Review Instructions for TinyGLTF
This document provides guidelines for reviewing code changes in the TinyGLTF repository.
## Memory Safety
- **Buffer Overflows**: Check for proper bounds checking when accessing arrays, vectors, and buffers. Verify that buffer sizes are validated before read/write operations.
- **Null Pointer Dereferences**: Ensure all pointers are checked for null before dereferencing, especially when handling optional glTF fields.
- **Memory Leaks**: Verify proper resource management, including RAII patterns for file handles, image data, and dynamically allocated memory.
- **Use-After-Free**: Check for proper lifetime management of objects, especially when dealing with callbacks and asynchronous operations.
## Error Handling
- **File I/O**: Verify that all file operations have proper error checking and meaningful error messages.
- **JSON Parsing**: Ensure JSON parsing errors are caught and reported with helpful context about the location and nature of the error.
- **Resource Loading**: Check that failures in loading images, buffers, and other resources are properly handled and don't cause crashes.
- **Error Propagation**: Verify that errors are properly propagated through the call stack with appropriate error messages.
## glTF 2.0 Specification Compliance
- **Required Fields**: Ensure all required glTF fields are validated and present.
- **Data Types**: Verify that data types match the glTF specification (e.g., component types, accessor types).
- **Constraints**: Check that glTF constraints are enforced (e.g., valid ranges for enums, buffer stride requirements).
- **Extensions**: Verify proper handling of glTF extensions and that unknown extensions are handled gracefully.
- **Validation**: Ensure new features align with the glTF 2.0 specification from the Khronos Group.
## Cross-Platform Compatibility
- **Windows**: Check for proper handling of Windows-specific issues (path separators, line endings, file operations).
- **Linux**: Verify compatibility with various Linux distributions and compilers (GCC, Clang).
- **macOS**: Ensure macOS-specific considerations are addressed (case-sensitive filesystems, Clang compatibility).
- **Mobile Platforms**: Consider Android and iOS compatibility where applicable.
- **Endianness**: Verify proper handling of byte order when reading binary data.
- **Compiler Compatibility**: Ensure code compiles with C++11 standard and supported compilers (MSVC, GCC, Clang).
## Edge Cases in glTF Parsing
- **Empty/Minimal Files**: Verify handling of minimal valid glTF files.
- **Large Files**: Check for proper handling of large glTF files and buffers without memory exhaustion.
- **Malformed Data**: Ensure graceful handling of malformed or invalid glTF data.
- **Missing Optional Fields**: Verify correct behavior when optional glTF fields are absent.
- **Edge Values**: Check handling of boundary values (e.g., maximum buffer sizes, extreme floating-point values).
- **Base64 Encoding**: Verify proper handling of base64-encoded data URIs and invalid encodings.
## Backwards Compatibility
- **API Changes**: Ensure public API changes maintain backwards compatibility or are properly deprecated.
- **Breaking Changes**: Flag any breaking changes for major version updates and document migration paths.
- **Binary Compatibility**: Consider ABI stability for header-only library changes.
- **Default Behavior**: Verify that default behavior of existing functionality remains unchanged.
## Performance Considerations
- **Parsing Performance**: Check for unnecessary copies, redundant allocations, and inefficient algorithms in parsing logic.
- **Memory Usage**: Verify efficient memory usage, especially when loading large glTF files.
- **I/O Operations**: Ensure efficient file reading and minimize unnecessary disk access.
- **String Operations**: Check for efficient string handling (use of string_view, move semantics).
- **STL Usage**: Verify appropriate use of STL containers and algorithms.
## Documentation
- **Public API**: Ensure all public functions, classes, and methods have clear documentation comments.
- **Parameters**: Verify that function parameters are documented, including expected ranges and constraints.
- **Return Values**: Document return values and possible error conditions.
- **Examples**: Check that complex features include usage examples.
- **Changelog**: Verify that significant changes are documented in release notes or changelog.
## Testing
- **Test Coverage**: Ensure new features include appropriate unit tests or integration tests.
- **Edge Cases**: Verify that tests cover edge cases and error conditions.
- **Cross-Platform Tests**: Check that tests run on all supported platforms.
- **Regression Tests**: Ensure bug fixes include regression tests to prevent recurrence.
- **Sample Files**: Verify that changes are tested with various valid and invalid glTF sample files.
## Code Style Consistency
- **Header-Only Pattern**: Maintain the header-only library structure.
- **Naming Conventions**: Follow existing naming conventions (CamelCase for types, snake_case for functions where applicable).
- **Formatting**: Adhere to the existing code formatting style (check `.clang-format` if available).
- **Include Guards**: Verify proper include guards and header organization.
- **Namespace Usage**: Ensure proper use of the `tinygltf` namespace.
- **Comments**: Maintain consistent comment style with existing code.
- **C++11 Compliance**: Verify that code uses C++11 features appropriately and doesn't require newer standards unless specified.
## Additional Considerations
- **Third-Party Dependencies**: Minimize new dependencies; prefer existing dependencies (json.hpp, stb_image).
- **Warnings**: Ensure code compiles without warnings on supported compilers.
- **const Correctness**: Verify proper use of const for parameters and methods.
- **RAII**: Prefer RAII patterns for resource management over manual cleanup.
- **noexcept**: Use noexcept appropriately for move constructors and move assignment operators.

330
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,330 @@
name: Comprehensive CI
on:
push:
branches:
- master
- release
- devel
pull_request:
branches:
- master
- release
- devel
workflow_dispatch:
permissions:
contents: read
jobs:
# Linux x64 - GCC
linux-gcc-x64:
runs-on: ubuntu-latest
name: Linux x64 (GCC)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure
run: cmake -B build -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
- name: Build
run: cmake --build build
- name: Run loader_example
run: ./build/loader_example models/Cube/Cube.gltf
- name: Run tests
run: ctest --test-dir build --output-on-failure
# Linux x64 - Clang 21
linux-clang-x64:
runs-on: ubuntu-24.04
name: Linux x64 (Clang 21)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Clang 21
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 21
- name: Configure
run: |
cmake -B build -DCMAKE_C_COMPILER=clang-21 -DCMAKE_CXX_COMPILER=clang++-21 -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
- name: Build
run: cmake --build build
- name: Run loader_example
run: |
./build/loader_example models/Cube/Cube.gltf
- name: Run tests
run: ctest --test-dir build --output-on-failure
# Linux ARM64 - GCC (native)
linux-arm64:
runs-on: ubuntu-24.04-arm
name: Linux ARM64 (GCC)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure
run: cmake -B build -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
- name: Build
run: cmake --build build
- name: Run loader_example
run: ./build/loader_example models/Cube/Cube.gltf
- name: Run tests
run: ctest --test-dir build --output-on-failure
# macOS ARM64 Apple Silicon
macos-arm64:
runs-on: macos-14
name: macOS ARM64 Apple Silicon (Clang)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure
run: cmake -B build -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
- name: Build
run: cmake --build build
- name: Run loader_example
run: ./build/loader_example models/Cube/Cube.gltf
- name: Run tests
run: ctest --test-dir build --output-on-failure
# Windows x64 - MSVC
windows-msvc-x64:
runs-on: windows-latest
name: Windows x64 (MSVC)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure
run: |
mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A x64 -DTINYGLTF_BUILD_LOADER_EXAMPLE=On -DTINYGLTF_BUILD_GL_EXAMPLES=Off -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=Off ..
- name: Build
run: cmake --build build --config Release
- name: Run loader_example
run: |
.\build\Release\loader_example.exe models\Cube\Cube.gltf
- name: Run tests
run: ctest --test-dir build -C Release --output-on-failure
# Windows x86 - MSVC
windows-msvc-x86:
runs-on: windows-latest
name: Windows x86 (MSVC)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure
run: |
mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A Win32 -DTINYGLTF_BUILD_LOADER_EXAMPLE=On -DTINYGLTF_BUILD_GL_EXAMPLES=Off -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=Off ..
- name: Build
run: cmake --build build --config Release
- name: Run tests
run: ctest --test-dir build -C Release --output-on-failure
# Windows ARM64 - MSVC (cross-compile)
windows-msvc-arm64:
runs-on: windows-latest
name: Windows ARM64 (MSVC) - Cross-compile
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure
run: |
mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A ARM64 -DTINYGLTF_BUILD_LOADER_EXAMPLE=On -DTINYGLTF_BUILD_GL_EXAMPLES=Off -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=Off ..
- name: Build
run: cmake --build build --config Release
# Windows MinGW - MSYS2
windows-mingw-msys2:
runs-on: windows-latest
name: Windows x64 (MinGW MSYS2)
defaults:
run:
shell: msys2 {0}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
install: base-devel
pacboy: >-
cc:p cmake:p ninja:p
update: true
release: false
- name: Build with CMake
run: |
cmake -G"Ninja" -S . -B build
cmake --build build
- name: Run loader_example
run: |
./build/loader_example models/Cube/Cube.gltf
- name: Run tests
run: ctest --test-dir build --output-on-failure
# Linux -> Windows MinGW Cross-compile
linux-mingw-cross:
runs-on: ubuntu-latest
name: Linux→Windows (MinGW Cross) - Build Only
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install MinGW
run: |
sudo apt-get update
sudo apt-get install -y build-essential mingw-w64
- name: Build
run: |
x86_64-w64-mingw32-g++ -std=c++11 -o loader_example.exe loader_example.cc
# Special Configuration: No Exceptions
linux-noexception:
runs-on: ubuntu-latest
name: Linux x64 (GCC) - No Exceptions
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build loader_example
run: |
g++ -DTINYGLTF_NOEXCEPTION -std=c++11 -o loader_example loader_example.cc
- name: Run loader_example
run: |
./loader_example models/Cube/Cube.gltf
- name: Build and run unit tests
run: |
cd tests
g++ -DTINYGLTF_NOEXCEPTION -I../ -std=c++11 -g -O0 -o tester_noexcept tester.cc
./tester_noexcept
# Special Configuration: Header-Only Mode
linux-header-only:
runs-on: ubuntu-latest
name: Linux x64 (GCC) - Header-Only Mode
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build with CMake Header-Only
run: |
mkdir build
cmake -B build -DTINYGLTF_HEADER_ONLY=ON -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON
cmake --build build
- name: Run loader_example
run: |
./build/loader_example models/Cube/Cube.gltf
- name: Run tests
run: ctest --test-dir build --output-on-failure
# Special Configuration: RapidJSON Backend
linux-rapidjson:
runs-on: ubuntu-latest
name: Linux x64 (GCC) - RapidJSON Backend
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Clone RapidJSON
run: |
git clone https://github.com/Tencent/rapidjson
- name: Configure
run: |
cmake -B build -DTINYGLTF_USE_RAPIDJSON=ON -DTINYGLTF_BUILD_LOADER_EXAMPLE=ON -DCMAKE_PREFIX_PATH=$PWD/rapidjson
- name: Build
run: cmake --build build
- name: Run loader_example
run: |
./build/loader_example models/Cube/Cube.gltf
- name: Run tests
run: ctest --test-dir build --output-on-failure
# Special Configuration: AddressSanitizer
linux-asan:
runs-on: ubuntu-latest
name: Linux x64 (Clang) - AddressSanitizer
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build loader_example with ASan
run: |
clang++ -fsanitize=address -std=c++11 -g -O1 -o loader_example loader_example.cc
- name: Run loader_example
run: |
./loader_example models/Cube/Cube.gltf
- name: Build and run unit tests with ASan
run: |
cd tests
clang++ -fsanitize=address -I../ -std=c++11 -g -O1 -o tester tester.cc
./tester
# Special Configuration: UndefinedBehaviorSanitizer
linux-ubsan:
runs-on: ubuntu-latest
name: Linux x64 (Clang) - UndefinedBehaviorSanitizer
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build loader_example with UBSan
run: |
clang++ -fsanitize=undefined -std=c++11 -g -O1 -o loader_example loader_example.cc
- name: Run loader_example
run: |
./loader_example models/Cube/Cube.gltf
- name: Build and run unit tests with UBSan
run: |
cd tests
clang++ -fsanitize=undefined -I../ -std=c++11 -g -O1 -o tester tester.cc
./tester

View File

@@ -14,8 +14,10 @@ option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example(load glTF and dump in
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)
if (TINYGLTF_BUILD_LOADER_EXAMPLE)
add_executable(loader_example
@@ -36,6 +38,16 @@ if (TINYGLTF_BUILD_BUILDER_EXAMPLE)
add_subdirectory ( examples/build-gltf )
endif (TINYGLTF_BUILD_BUILDER_EXAMPLE)
if (TINYGLTF_BUILD_TESTS)
enable_testing()
add_executable(tester tests/tester.cc)
target_include_directories(tester PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/tests
)
add_test(NAME tester COMMAND tester WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
endif (TINYGLTF_BUILD_TESTS)
#
# for add_subdirectory and standalone build
#
@@ -61,19 +73,26 @@ endif (TINYGLTF_HEADER_ONLY)
if (TINYGLTF_INSTALL)
install(TARGETS tinygltf EXPORT tinygltfTargets)
install(EXPORT tinygltfTargets NAMESPACE tinygltf:: FILE TinyGLTFTargets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
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)
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
json.hpp
stb_image.h
stb_image_write.h
tiny_gltf.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)

View File

@@ -159,9 +159,10 @@ Model model;
TinyGLTF loader;
std::string err;
std::string warn;
std::string filename = "input.gltf";
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, argv[1]);
//bool ret = loader.LoadBinaryFromFile(&model, &err, &warn, argv[1]); // for binary glTF(.glb)
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());
@@ -172,8 +173,7 @@ if (!err.empty()) {
}
if (!ret) {
printf("Failed to parse glTF\n");
return -1;
printf("Failed to parse glTF: %s\n", filename.c_str());
}
```
@@ -194,7 +194,6 @@ if (!ret) {
* `TINYGLTF_NO_INCLUDE_STB_IMAGE `: Disable including `stb_image.h` from within `tiny_gltf.h` because it has been already included before or you want to include it using custom path before including `tiny_gltf.h`.
* `TINYGLTF_NO_INCLUDE_STB_IMAGE_WRITE `: Disable including `stb_image_write.h` from within `tiny_gltf.h` because it has been already included before or you want to include it using custom path before including `tiny_gltf.h`.
* `TINYGLTF_USE_RAPIDJSON` : Use RapidJSON as a JSON parser/serializer. RapidJSON files are not included in TinyGLTF repo. Please set an include path to RapidJSON if you enable this feature.
* `TINYGLTF_USE_CPP14` : Use C++14 feature(requires C++14 compiler). This may give better performance than C++11.
## CMake options
@@ -211,6 +210,11 @@ set(TINYGLTF_INSTALL OFF CACHE INTERNAL "" FORCE)
add_subdirectory(/path/to/tinygltf)
```
NOTE: Using tinygltf as a submodule doesn't automatically add the headers to your include path (as standard for many libraries). To get this functionality, add the following to the CMakeLists.txt file from above:
```
target_include_directories(${PROJECT_NAME} PRIVATE "/path/to/tinygltf")
```
### Saving gltTF 2.0 model

View File

@@ -1121,8 +1121,10 @@ TEST_CASE("images-as-is", "[issue-487]") {
// All the images should have been written to disk with their original data
for (const auto& image : model.images) {
// Make sure the image files exist
std::fstream file(image.uri);
CHECK(file.good());
{
std::fstream file(image.uri);
CHECK(file.good());
} // Close file before stbi_load (Windows sharing violation fix)
#ifndef TINYGLTF_NO_STB_IMAGE
// Make sure we can load the images
int w = -1, h = -1, component = -1;

View File

@@ -50,12 +50,6 @@
#include <utility>
#include <vector>
// Auto-detect C++14 standard version
#if !defined(TINYGLTF_USE_CPP14) && defined(__cplusplus) && \
(__cplusplus >= 201402L)
#define TINYGLTF_USE_CPP14
#endif
#ifdef __ANDROID__
#ifdef TINYGLTF_ANDROID_LOAD_FROM_ASSETS
#include <android/asset_manager.h>
@@ -834,20 +828,20 @@ struct Accessor {
maxValues; // optional. integer value is promoted to double
struct Sparse {
int count;
bool isSparse;
int count{0};
bool isSparse{false};
struct {
size_t byteOffset;
int bufferView;
int componentType; // a TINYGLTF_COMPONENT_TYPE_ value
size_t byteOffset{0};
int bufferView{-1};
int componentType{-1}; // a TINYGLTF_COMPONENT_TYPE_ value
Value extras;
ExtensionMap extensions;
std::string extras_json_string;
std::string extensions_json_string;
} indices;
struct {
int bufferView;
size_t byteOffset;
int bufferView{-1};
size_t byteOffset{0};
Value extras;
ExtensionMap extensions;
std::string extras_json_string;
@@ -898,11 +892,7 @@ struct Accessor {
// unreachable return 0;
}
Accessor()
{
sparse.isSparse = false;
}
Accessor() = default;
DEFAULT_METHODS(Accessor)
bool operator==(const tinygltf::Accessor &) const;
};
@@ -4362,7 +4352,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
// Just only save some information here. Loading actual image data from
// bufferView is done after this `ParseImage` function.
image->bufferView = bufferView;
image->mimeType = mime_type;
image->mimeType = std::move( mime_type );
image->width = width;
image->height = height;
@@ -5261,7 +5251,7 @@ static bool ParseNode(Node *node, std::string *err, const detail::json &o,
if (node->extensions.count("MSFT_lod") != 0) {
auto const &msft_lod_ext = node->extensions["MSFT_lod"];
if (msft_lod_ext.Has("ids")) {
auto idsArr = msft_lod_ext.Get("ids");
const auto &idsArr = msft_lod_ext.Get("ids");
for (size_t i = 0; i < idsArr.ArrayLen(); ++i) {
node->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
}
@@ -5290,7 +5280,7 @@ static bool ParseScene(Scene *scene, std::string *err, const detail::json &o,
if (scene->extensions.count("KHR_audio") != 0) {
auto const &audio_ext = scene->extensions["KHR_audio"];
if (audio_ext.Has("emitters")) {
auto emittersArr = audio_ext.Get("emitters");
const auto &emittersArr = audio_ext.Get("emitters");
for (size_t i = 0; i < emittersArr.ArrayLen(); ++i) {
scene->audioEmitters.emplace_back(emittersArr.Get(i).GetNumberAsInt());
}
@@ -5326,7 +5316,7 @@ static bool ParsePbrMetallicRoughness(
}
return false;
}
pbr->baseColorFactor = baseColorFactor;
pbr->baseColorFactor = std::move( baseColorFactor );
}
{
@@ -5478,7 +5468,7 @@ static bool ParseMaterial(Material *material, std::string *err, std::string *war
if (material->extensions.count("MSFT_lod") != 0) {
auto const &msft_lod_ext = material->extensions["MSFT_lod"];
if (msft_lod_ext.Has("ids")) {
auto idsArr = msft_lod_ext.Get("ids");
const auto &idsArr = msft_lod_ext.Get("ids");
for (size_t i = 0; i < idsArr.ArrayLen(); ++i) {
material->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
}
@@ -6453,6 +6443,15 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
return false;
}
const Buffer &buffer = model->buffers[size_t(bufferView.buffer)];
if (bufferView.byteOffset >= buffer.data.size()) {
if (err) {
std::stringstream ss;
ss << "image[" << idx << "] bufferView \"" << image.bufferView
<< "\" indexed out of bounds of its buffer." << std::endl;
(*err) += ss.str();
}
return false;
}
if (LoadImageData == nullptr) {
if (err) {
@@ -7207,6 +7206,7 @@ static void SerializeGltfBufferData(const std::vector<unsigned char> &data,
static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
const std::string &binFilename) {
#ifndef TINYGLTF_NO_FS
#ifdef _WIN32
#if defined(__GLIBCXX__) // mingw
int file_descriptor = _wopen(UTF8ToWchar(binFilename).c_str(),
@@ -7235,6 +7235,9 @@ static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
// write empty file.
}
return true;
#else
return false;
#endif
}
#if 0 // FIXME(syoyo): not used. will be removed in the future release.
@@ -8456,6 +8459,7 @@ static bool WriteGltfStream(std::ostream &stream, const std::string &content) {
static bool WriteGltfFile(const std::string &output,
const std::string &content) {
#ifndef TINYGLTF_NO_FS
#ifdef _WIN32
#if defined(_MSC_VER)
std::ofstream gltfFile(UTF8ToWchar(output).c_str());
@@ -8475,6 +8479,9 @@ static bool WriteGltfFile(const std::string &output,
if (!gltfFile.is_open()) return false;
#endif
return WriteGltfStream(gltfFile, content);
#else
return false;
#endif
}
static bool WriteBinaryGltfStream(std::ostream &stream,
@@ -8541,6 +8548,7 @@ static bool WriteBinaryGltfStream(std::ostream &stream,
static bool WriteBinaryGltfFile(const std::string &output,
const std::string &content,
const std::vector<unsigned char> &binBuffer) {
#ifndef TINYGLTF_NO_FS
#ifdef _WIN32
#if defined(_MSC_VER)
std::ofstream gltfFile(UTF8ToWchar(output).c_str(), std::ios::binary);
@@ -8557,6 +8565,9 @@ static bool WriteBinaryGltfFile(const std::string &output,
std::ofstream gltfFile(output.c_str(), std::ios::binary);
#endif
return WriteBinaryGltfStream(gltfFile, content, binBuffer);
#else
return false;
#endif
}
bool TinyGLTF::WriteGltfSceneToStream(const Model *model, std::ostream &stream,