mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-07-20 13:09:11 +00:00
Compare commits
69 Commits
v2.9.2
...
copilot/op
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4e4155bf7 | ||
|
|
5dfa17d14b | ||
|
|
5b87beb373 | ||
|
|
0ab7e74933 | ||
|
|
247cb388a0 | ||
|
|
eb087e80e7 | ||
|
|
690585fa73 | ||
|
|
73d309ebfa | ||
|
|
4d16d528a5 | ||
|
|
229f2b8c88 | ||
|
|
ad531900cb | ||
|
|
9da2046cba | ||
|
|
ed13b0422a | ||
|
|
1dfcb11442 | ||
|
|
a2b55f008e | ||
|
|
fdf528f9aa | ||
|
|
ebcd8cc4ee | ||
|
|
f6c71cf88b | ||
|
|
5aaa3e4daf | ||
|
|
1117aa7191 | ||
|
|
bdba4dfb4c | ||
|
|
e379d0d60c | ||
|
|
659de95977 | ||
|
|
b1a7736249 | ||
|
|
9ab0d0d5f7 | ||
|
|
fca5da1b37 | ||
|
|
bdc37385f1 | ||
|
|
797bf0e023 | ||
|
|
10ac914244 | ||
|
|
dc6dddac98 | ||
|
|
b548191e41 | ||
|
|
17287c7fcf | ||
|
|
6c948d5bc3 | ||
|
|
d4a4a1b27a | ||
|
|
3d5453ecd0 | ||
|
|
52a453120b | ||
|
|
fc6d78a1b6 | ||
|
|
ae0bac486c | ||
|
|
b19e665747 | ||
|
|
40f6c2b875 | ||
|
|
e8c70dff1d | ||
|
|
1dc37f76ea | ||
|
|
8da66b8ca1 | ||
|
|
81bd50c106 | ||
|
|
6d8bba0d8a | ||
|
|
2aa77e5d0a | ||
|
|
1fac6234d9 | ||
|
|
bcd666fbd4 | ||
|
|
37250b3470 | ||
|
|
7385235e29 | ||
|
|
3564b48760 | ||
|
|
2ad433b68f | ||
|
|
1b517f2b23 | ||
|
|
bd7255e095 | ||
|
|
a5e653e46c | ||
|
|
d530cd410b | ||
|
|
1831424c71 | ||
|
|
5e008af65d | ||
|
|
fbff1f45b5 | ||
|
|
d950e7cd9b | ||
|
|
116d0030f9 | ||
|
|
ff972dcf1b | ||
|
|
8bec431699 | ||
|
|
21485496b1 | ||
|
|
fda7422022 | ||
|
|
decfabd67e | ||
|
|
10b23b6af2 | ||
|
|
fe3cfbe996 | ||
|
|
3b73caa8e8 |
92
.github/instructions/copilot-instructions.md
vendored
Normal file
92
.github/instructions/copilot-instructions.md
vendored
Normal 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
330
.github/workflows/ci.yml
vendored
Normal 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
|
||||||
13
.gitignore
vendored
13
.gitignore
vendored
@@ -70,6 +70,19 @@ tests/tester
|
|||||||
tests/tester_noexcept
|
tests/tester_noexcept
|
||||||
tests/issue-97.gltf
|
tests/issue-97.gltf
|
||||||
tests/issue-261.gltf
|
tests/issue-261.gltf
|
||||||
|
tests/issue-495-external.gltf
|
||||||
|
# Test-generated output files (written by tester.cc during test run)
|
||||||
|
tests/Cube.gltf
|
||||||
|
tests/Cube.bin
|
||||||
|
tests/Cube.glb
|
||||||
|
tests/Cube_BaseColor.png
|
||||||
|
tests/Cube_MetallicRoughness.png
|
||||||
|
tests/Cube_with_embedded_images.gltf
|
||||||
|
tests/Cube_with_image_files.gltf
|
||||||
|
tests/tmp.glb
|
||||||
|
tests/ issue-236.gltf
|
||||||
|
tests/ issue-236.bin
|
||||||
|
tests/ 2x2 image has multiple spaces.png
|
||||||
|
|
||||||
# unignore
|
# unignore
|
||||||
!Makefile
|
!Makefile
|
||||||
|
|||||||
@@ -14,8 +14,11 @@ 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_GL_EXAMPLES "Build GL exampels(requires glfw, OpenGL, etc)" OFF)
|
||||||
option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator exampe" OFF)
|
option(TINYGLTF_BUILD_VALIDATOR_EXAMPLE "Build validator exampe" OFF)
|
||||||
option(TINYGLTF_BUILD_BUILDER_EXAMPLE "Build glTF builder example" 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_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 "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)
|
||||||
|
|
||||||
if (TINYGLTF_BUILD_LOADER_EXAMPLE)
|
if (TINYGLTF_BUILD_LOADER_EXAMPLE)
|
||||||
add_executable(loader_example
|
add_executable(loader_example
|
||||||
@@ -36,6 +39,25 @@ if (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
|||||||
add_subdirectory ( examples/build-gltf )
|
add_subdirectory ( examples/build-gltf )
|
||||||
endif (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
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)
|
||||||
|
|
||||||
|
# Build and run tests with the custom JSON backend enabled to catch regressions
|
||||||
|
add_executable(tester_customjson tests/tester.cc)
|
||||||
|
target_include_directories(tester_customjson PRIVATE
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/tests
|
||||||
|
)
|
||||||
|
target_compile_definitions(tester_customjson PRIVATE TINYGLTF_USE_CUSTOM_JSON)
|
||||||
|
add_test(NAME tester_customjson COMMAND tester_customjson WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||||
|
endif (TINYGLTF_BUILD_TESTS)
|
||||||
|
|
||||||
#
|
#
|
||||||
# for add_subdirectory and standalone build
|
# for add_subdirectory and standalone build
|
||||||
#
|
#
|
||||||
@@ -59,21 +81,37 @@ else (TINYGLTF_HEADER_ONLY)
|
|||||||
)
|
)
|
||||||
endif (TINYGLTF_HEADER_ONLY)
|
endif (TINYGLTF_HEADER_ONLY)
|
||||||
|
|
||||||
|
if (TINYGLTF_USE_CUSTOM_JSON)
|
||||||
|
if (TINYGLTF_HEADER_ONLY)
|
||||||
|
target_compile_definitions(tinygltf INTERFACE TINYGLTF_USE_CUSTOM_JSON)
|
||||||
|
else ()
|
||||||
|
target_compile_definitions(tinygltf PUBLIC TINYGLTF_USE_CUSTOM_JSON)
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
if (TINYGLTF_INSTALL)
|
if (TINYGLTF_INSTALL)
|
||||||
install(TARGETS tinygltf EXPORT tinygltfTargets)
|
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)
|
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
|
# Do not install .lib even if !TINYGLTF_HEADER_ONLY
|
||||||
|
|
||||||
INSTALL ( FILES
|
INSTALL ( FILES
|
||||||
json.hpp
|
|
||||||
stb_image.h
|
|
||||||
stb_image_write.h
|
|
||||||
tiny_gltf.h
|
tiny_gltf.h
|
||||||
|
tinygltf_json.h
|
||||||
${TINYGLTF_EXTRA_SOUECES}
|
${TINYGLTF_EXTRA_SOUECES}
|
||||||
DESTINATION
|
DESTINATION
|
||||||
include
|
include
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(TINYGLTF_INSTALL_VENDOR)
|
||||||
|
INSTALL ( FILES
|
||||||
|
json.hpp
|
||||||
|
stb_image.h
|
||||||
|
stb_image_write.h
|
||||||
|
DESTINATION
|
||||||
|
include
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
endif(TINYGLTF_INSTALL)
|
endif(TINYGLTF_INSTALL)
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -26,8 +26,6 @@ Currently TinyGLTF is stable and maintenance mode. No drastic changes and featur
|
|||||||
|
|
||||||
## Builds
|
## Builds
|
||||||
|
|
||||||
[](https://ci.appveyor.com/project/syoyo/tinygltf)
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@@ -159,9 +157,10 @@ Model model;
|
|||||||
TinyGLTF loader;
|
TinyGLTF loader;
|
||||||
std::string err;
|
std::string err;
|
||||||
std::string warn;
|
std::string warn;
|
||||||
|
std::string filename = "input.gltf";
|
||||||
|
|
||||||
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, argv[1]);
|
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, filename);
|
||||||
//bool ret = loader.LoadBinaryFromFile(&model, &err, &warn, argv[1]); // for binary glTF(.glb)
|
//bool ret = loader.LoadBinaryFromFile(&model, &err, &warn, filename); // for binary glTF(.glb)
|
||||||
|
|
||||||
if (!warn.empty()) {
|
if (!warn.empty()) {
|
||||||
printf("Warn: %s\n", warn.c_str());
|
printf("Warn: %s\n", warn.c_str());
|
||||||
@@ -172,8 +171,7 @@ if (!err.empty()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
printf("Failed to parse glTF\n");
|
printf("Failed to parse glTF: %s\n", filename.c_str());
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -194,7 +192,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 `: 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_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_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
|
## CMake options
|
||||||
@@ -211,6 +208,11 @@ set(TINYGLTF_INSTALL OFF CACHE INTERNAL "" FORCE)
|
|||||||
add_subdirectory(/path/to/tinygltf)
|
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
|
### Saving gltTF 2.0 model
|
||||||
|
|
||||||
|
|||||||
18
appveyor.yml
18
appveyor.yml
@@ -1,18 +0,0 @@
|
|||||||
version: 0.9.{build}
|
|
||||||
|
|
||||||
image:
|
|
||||||
- Visual Studio 2015
|
|
||||||
|
|
||||||
# scripts that runs after repo cloning.
|
|
||||||
install:
|
|
||||||
- vcsetup.bat
|
|
||||||
|
|
||||||
platform: x64
|
|
||||||
configuration: Release
|
|
||||||
|
|
||||||
build:
|
|
||||||
parallel: true
|
|
||||||
project: TinyGLTFSolution.sln
|
|
||||||
|
|
||||||
after_build:
|
|
||||||
- examples.bat
|
|
||||||
@@ -1121,8 +1121,10 @@ TEST_CASE("images-as-is", "[issue-487]") {
|
|||||||
// All the images should have been written to disk with their original data
|
// All the images should have been written to disk with their original data
|
||||||
for (const auto& image : model.images) {
|
for (const auto& image : model.images) {
|
||||||
// Make sure the image files exist
|
// 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
|
#ifndef TINYGLTF_NO_STB_IMAGE
|
||||||
// Make sure we can load the images
|
// Make sure we can load the images
|
||||||
int w = -1, h = -1, component = -1;
|
int w = -1, h = -1, component = -1;
|
||||||
@@ -1199,4 +1201,51 @@ TEST_CASE("inverse-bind-matrices-optional", "[issue-492]") {
|
|||||||
|
|
||||||
REQUIRE(true == ret);
|
REQUIRE(true == ret);
|
||||||
REQUIRE(err.empty());
|
REQUIRE(err.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LoadImageData(tinygltf::Image * /* image */, const int /* image_idx */, std::string * /* err */,
|
||||||
|
std::string * /* warn */, int /* req_width */, int /* req_height */,
|
||||||
|
const unsigned char * /* bytes */, int /* size */, void * /*user_data */) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WriteImageData(const std::string * /* basepath */, const std::string * /* filename */,
|
||||||
|
const tinygltf::Image *image, bool /* embedImages */,
|
||||||
|
const tinygltf::FsCallbacks * /* fs_cb */, const tinygltf::URICallbacks * /* uri_cb */,
|
||||||
|
std::string * /* out_uri */, void * user_pointer) {
|
||||||
|
REQUIRE(user_pointer != nullptr);
|
||||||
|
auto counter = static_cast<int*>(user_pointer);
|
||||||
|
*counter = *counter + 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("empty-images-not-written", "[issue-495]") {
|
||||||
|
std::string err;
|
||||||
|
std::string warn;
|
||||||
|
tinygltf::Model model;
|
||||||
|
tinygltf::TinyGLTF ctx;
|
||||||
|
|
||||||
|
ctx.SetImageLoader(LoadImageData, nullptr);
|
||||||
|
bool ok = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Cube/Cube.gltf");
|
||||||
|
REQUIRE(ok);
|
||||||
|
REQUIRE(err.empty());
|
||||||
|
REQUIRE(warn.empty());
|
||||||
|
|
||||||
|
CHECK(model.images.size() == 2);
|
||||||
|
for (const auto& image : model.images) {
|
||||||
|
// No data loaded or decoded
|
||||||
|
CHECK(image.image.empty());
|
||||||
|
// The URI is kept
|
||||||
|
CHECK_FALSE(image.uri.empty());
|
||||||
|
// The URI should not be a data URI
|
||||||
|
CHECK(image.uri.find("data:") != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now write the loaded model
|
||||||
|
int counter = 0;
|
||||||
|
ctx.SetImageWriter(WriteImageData, &counter);
|
||||||
|
ok = ctx.WriteGltfSceneToFile(&model, "issue-495-external.gltf");
|
||||||
|
CHECK(ok);
|
||||||
|
// WriteImageData should be invoked for both images
|
||||||
|
CHECK(counter == 2);
|
||||||
|
}
|
||||||
|
|||||||
99
tiny_gltf.h
99
tiny_gltf.h
@@ -50,12 +50,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#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 __ANDROID__
|
||||||
#ifdef TINYGLTF_ANDROID_LOAD_FROM_ASSETS
|
#ifdef TINYGLTF_ANDROID_LOAD_FROM_ASSETS
|
||||||
#include <android/asset_manager.h>
|
#include <android/asset_manager.h>
|
||||||
@@ -834,20 +828,20 @@ struct Accessor {
|
|||||||
maxValues; // optional. integer value is promoted to double
|
maxValues; // optional. integer value is promoted to double
|
||||||
|
|
||||||
struct Sparse {
|
struct Sparse {
|
||||||
int count;
|
int count{0};
|
||||||
bool isSparse;
|
bool isSparse{false};
|
||||||
struct {
|
struct {
|
||||||
size_t byteOffset;
|
size_t byteOffset{0};
|
||||||
int bufferView;
|
int bufferView{-1};
|
||||||
int componentType; // a TINYGLTF_COMPONENT_TYPE_ value
|
int componentType{-1}; // a TINYGLTF_COMPONENT_TYPE_ value
|
||||||
Value extras;
|
Value extras;
|
||||||
ExtensionMap extensions;
|
ExtensionMap extensions;
|
||||||
std::string extras_json_string;
|
std::string extras_json_string;
|
||||||
std::string extensions_json_string;
|
std::string extensions_json_string;
|
||||||
} indices;
|
} indices;
|
||||||
struct {
|
struct {
|
||||||
int bufferView;
|
int bufferView{-1};
|
||||||
size_t byteOffset;
|
size_t byteOffset{0};
|
||||||
Value extras;
|
Value extras;
|
||||||
ExtensionMap extensions;
|
ExtensionMap extensions;
|
||||||
std::string extras_json_string;
|
std::string extras_json_string;
|
||||||
@@ -898,11 +892,7 @@ struct Accessor {
|
|||||||
// unreachable return 0;
|
// unreachable return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Accessor()
|
Accessor() = default;
|
||||||
|
|
||||||
{
|
|
||||||
sparse.isSparse = false;
|
|
||||||
}
|
|
||||||
DEFAULT_METHODS(Accessor)
|
DEFAULT_METHODS(Accessor)
|
||||||
bool operator==(const tinygltf::Accessor &) const;
|
bool operator==(const tinygltf::Accessor &) const;
|
||||||
};
|
};
|
||||||
@@ -1721,7 +1711,11 @@ class TinyGLTF {
|
|||||||
#endif // __GNUC__
|
#endif // __GNUC__
|
||||||
|
|
||||||
#ifndef TINYGLTF_NO_INCLUDE_JSON
|
#ifndef TINYGLTF_NO_INCLUDE_JSON
|
||||||
#ifndef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_CUSTOM_JSON
|
||||||
|
#ifndef TINYGLTF_NO_INCLUDE_CUSTOM_JSON
|
||||||
|
#include "tinygltf_json.h"
|
||||||
|
#endif
|
||||||
|
#elif !defined(TINYGLTF_USE_RAPIDJSON)
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
#else
|
#else
|
||||||
#ifndef TINYGLTF_NO_INCLUDE_RAPIDJSON
|
#ifndef TINYGLTF_NO_INCLUDE_RAPIDJSON
|
||||||
@@ -1809,7 +1803,10 @@ class TinyGLTF {
|
|||||||
|
|
||||||
namespace tinygltf {
|
namespace tinygltf {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_CUSTOM_JSON
|
||||||
|
// Types and JsonParse are provided by tinygltf_json.h (already included above)
|
||||||
|
// via 'namespace tinygltf { namespace detail { ... } }' declarations.
|
||||||
|
#elif defined(TINYGLTF_USE_RAPIDJSON)
|
||||||
|
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON_CRTALLOCATOR
|
#ifdef TINYGLTF_USE_RAPIDJSON_CRTALLOCATOR
|
||||||
// This uses the RapidJSON CRTAllocator. It is thread safe and multiple
|
// This uses the RapidJSON CRTAllocator. It is thread safe and multiple
|
||||||
@@ -1881,6 +1878,7 @@ using json_const_array_iterator = json_const_iterator;
|
|||||||
using JsonDocument = json;
|
using JsonDocument = json;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef TINYGLTF_USE_CUSTOM_JSON
|
||||||
void JsonParse(JsonDocument &doc, const char *str, size_t length,
|
void JsonParse(JsonDocument &doc, const char *str, size_t length,
|
||||||
bool throwExc = false) {
|
bool throwExc = false) {
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||||
@@ -1890,6 +1888,7 @@ void JsonParse(JsonDocument &doc, const char *str, size_t length,
|
|||||||
doc = detail::json::parse(str, str + length, nullptr, throwExc);
|
doc = detail::json::parse(str, str + length, nullptr, throwExc);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif // !TINYGLTF_USE_CUSTOM_JSON
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace tinygltf
|
} // namespace tinygltf
|
||||||
|
|
||||||
@@ -2461,9 +2460,8 @@ inline unsigned char from_hex(unsigned char ch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const std::string urldecode(const std::string &str) {
|
static const std::string urldecode(const std::string &str) {
|
||||||
using namespace std;
|
std::string result;
|
||||||
string result;
|
std::string::size_type i;
|
||||||
string::size_type i;
|
|
||||||
for (i = 0; i < str.size(); ++i) {
|
for (i = 0; i < str.size(); ++i) {
|
||||||
if (str[i] == '+') {
|
if (str[i] == '+') {
|
||||||
result += ' ';
|
result += ' ';
|
||||||
@@ -2767,6 +2765,12 @@ bool WriteImageData(const std::string *basepath, const std::string *filename,
|
|||||||
const Image *image, bool embedImages,
|
const Image *image, bool embedImages,
|
||||||
const FsCallbacks* fs_cb, const URICallbacks *uri_cb,
|
const FsCallbacks* fs_cb, const URICallbacks *uri_cb,
|
||||||
std::string *out_uri, void *) {
|
std::string *out_uri, void *) {
|
||||||
|
// Early out on empty images, report the original uri if the image was not written.
|
||||||
|
if (image->image.empty()) {
|
||||||
|
*out_uri = *filename;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string ext = GetFilePathExtension(*filename);
|
const std::string ext = GetFilePathExtension(*filename);
|
||||||
|
|
||||||
// Write image to temporary buffer
|
// Write image to temporary buffer
|
||||||
@@ -3309,11 +3313,12 @@ static bool UpdateImageObject(const Image &image, std::string &baseDir,
|
|||||||
filename = std::to_string(index) + "." + ext;
|
filename = std::to_string(index) + "." + ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If callback is set and image data exists, modify image data object. If
|
// If callback is set, modify image data object.
|
||||||
// image data does not exist, this is not considered a failure and the
|
// Note that the callback is also invoked for images without data.
|
||||||
// original uri should be maintained.
|
// The default callback implementation simply returns true for
|
||||||
|
// empty images and sets the out URI to filename.
|
||||||
bool imageWritten = false;
|
bool imageWritten = false;
|
||||||
if (WriteImageData != nullptr && !filename.empty() && !image.image.empty()) {
|
if (WriteImageData != nullptr && !filename.empty()) {
|
||||||
imageWritten = WriteImageData(&baseDir, &filename, &image, embedImages,
|
imageWritten = WriteImageData(&baseDir, &filename, &image, embedImages,
|
||||||
fs_cb, uri_cb, out_uri, user_data);
|
fs_cb, uri_cb, out_uri, user_data);
|
||||||
if (!imageWritten) {
|
if (!imageWritten) {
|
||||||
@@ -3440,6 +3445,7 @@ bool DecodeDataURI(std::vector<unsigned char> *out, std::string &mime_type,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef TINYGLTF_USE_CUSTOM_JSON
|
||||||
namespace detail {
|
namespace detail {
|
||||||
bool GetInt(const detail::json &o, int &val) {
|
bool GetInt(const detail::json &o, int &val) {
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||||
@@ -3663,6 +3669,7 @@ std::string JsonToString(const detail::json &o, int spacing = -1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
#endif // !TINYGLTF_USE_CUSTOM_JSON
|
||||||
|
|
||||||
static bool ParseJsonAsValue(Value *ret, const detail::json &o) {
|
static bool ParseJsonAsValue(Value *ret, const detail::json &o) {
|
||||||
Value val{};
|
Value val{};
|
||||||
@@ -4355,7 +4362,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
|
|||||||
// Just only save some information here. Loading actual image data from
|
// Just only save some information here. Loading actual image data from
|
||||||
// bufferView is done after this `ParseImage` function.
|
// bufferView is done after this `ParseImage` function.
|
||||||
image->bufferView = bufferView;
|
image->bufferView = bufferView;
|
||||||
image->mimeType = mime_type;
|
image->mimeType = std::move( mime_type );
|
||||||
image->width = width;
|
image->width = width;
|
||||||
image->height = height;
|
image->height = height;
|
||||||
|
|
||||||
@@ -4387,7 +4394,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Assume external file
|
// Assume external file
|
||||||
// Keep texture path (for textures that cannot be decoded)
|
// Unconditionally keep the external URI of the image
|
||||||
image->uri = uri;
|
image->uri = uri;
|
||||||
#ifdef TINYGLTF_NO_EXTERNAL_IMAGE
|
#ifdef TINYGLTF_NO_EXTERNAL_IMAGE
|
||||||
return true;
|
return true;
|
||||||
@@ -4434,6 +4441,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err,
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoadImageData(image, image_idx, err, warn, 0, 0, &img.at(0),
|
return LoadImageData(image, image_idx, err, warn, 0, 0, &img.at(0),
|
||||||
static_cast<int>(img.size()), load_image_user_data);
|
static_cast<int>(img.size()), load_image_user_data);
|
||||||
}
|
}
|
||||||
@@ -5253,7 +5261,7 @@ static bool ParseNode(Node *node, std::string *err, const detail::json &o,
|
|||||||
if (node->extensions.count("MSFT_lod") != 0) {
|
if (node->extensions.count("MSFT_lod") != 0) {
|
||||||
auto const &msft_lod_ext = node->extensions["MSFT_lod"];
|
auto const &msft_lod_ext = node->extensions["MSFT_lod"];
|
||||||
if (msft_lod_ext.Has("ids")) {
|
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) {
|
for (size_t i = 0; i < idsArr.ArrayLen(); ++i) {
|
||||||
node->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
|
node->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
|
||||||
}
|
}
|
||||||
@@ -5282,7 +5290,7 @@ static bool ParseScene(Scene *scene, std::string *err, const detail::json &o,
|
|||||||
if (scene->extensions.count("KHR_audio") != 0) {
|
if (scene->extensions.count("KHR_audio") != 0) {
|
||||||
auto const &audio_ext = scene->extensions["KHR_audio"];
|
auto const &audio_ext = scene->extensions["KHR_audio"];
|
||||||
if (audio_ext.Has("emitters")) {
|
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) {
|
for (size_t i = 0; i < emittersArr.ArrayLen(); ++i) {
|
||||||
scene->audioEmitters.emplace_back(emittersArr.Get(i).GetNumberAsInt());
|
scene->audioEmitters.emplace_back(emittersArr.Get(i).GetNumberAsInt());
|
||||||
}
|
}
|
||||||
@@ -5318,7 +5326,7 @@ static bool ParsePbrMetallicRoughness(
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pbr->baseColorFactor = baseColorFactor;
|
pbr->baseColorFactor = std::move( baseColorFactor );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -5470,7 +5478,7 @@ static bool ParseMaterial(Material *material, std::string *err, std::string *war
|
|||||||
if (material->extensions.count("MSFT_lod") != 0) {
|
if (material->extensions.count("MSFT_lod") != 0) {
|
||||||
auto const &msft_lod_ext = material->extensions["MSFT_lod"];
|
auto const &msft_lod_ext = material->extensions["MSFT_lod"];
|
||||||
if (msft_lod_ext.Has("ids")) {
|
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) {
|
for (size_t i = 0; i < idsArr.ArrayLen(); ++i) {
|
||||||
material->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
|
material->lods.emplace_back(idsArr.Get(i).GetNumberAsInt());
|
||||||
}
|
}
|
||||||
@@ -5597,7 +5605,7 @@ static bool ParseAnimation(Animation *animation, std::string *err,
|
|||||||
}
|
}
|
||||||
sampler.input = inputIndex;
|
sampler.input = inputIndex;
|
||||||
sampler.output = outputIndex;
|
sampler.output = outputIndex;
|
||||||
ParseExtrasAndExtensions(&sampler, err, o,
|
ParseExtrasAndExtensions(&sampler, err, s,
|
||||||
store_original_json_for_extras_and_extensions);
|
store_original_json_for_extras_and_extensions);
|
||||||
|
|
||||||
animation->samplers.emplace_back(std::move(sampler));
|
animation->samplers.emplace_back(std::move(sampler));
|
||||||
@@ -6445,6 +6453,15 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const Buffer &buffer = model->buffers[size_t(bufferView.buffer)];
|
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 (LoadImageData == nullptr) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -6956,6 +6973,7 @@ bool TinyGLTF::LoadBinaryFromFile(Model *model, std::string *err,
|
|||||||
///////////////////////
|
///////////////////////
|
||||||
// GLTF Serialization
|
// GLTF Serialization
|
||||||
///////////////////////
|
///////////////////////
|
||||||
|
#ifndef TINYGLTF_USE_CUSTOM_JSON
|
||||||
namespace detail {
|
namespace detail {
|
||||||
detail::json JsonFromString(const char *s) {
|
detail::json JsonFromString(const char *s) {
|
||||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||||
@@ -7028,6 +7046,7 @@ void JsonReserveArray(detail::json &o, size_t s) {
|
|||||||
(void)(s);
|
(void)(s);
|
||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
#endif // !TINYGLTF_USE_CUSTOM_JSON
|
||||||
|
|
||||||
// typedef std::pair<std::string, detail::json> json_object_pair;
|
// typedef std::pair<std::string, detail::json> json_object_pair;
|
||||||
|
|
||||||
@@ -7199,6 +7218,7 @@ static void SerializeGltfBufferData(const std::vector<unsigned char> &data,
|
|||||||
|
|
||||||
static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
|
static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
|
||||||
const std::string &binFilename) {
|
const std::string &binFilename) {
|
||||||
|
#ifndef TINYGLTF_NO_FS
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#if defined(__GLIBCXX__) // mingw
|
#if defined(__GLIBCXX__) // mingw
|
||||||
int file_descriptor = _wopen(UTF8ToWchar(binFilename).c_str(),
|
int file_descriptor = _wopen(UTF8ToWchar(binFilename).c_str(),
|
||||||
@@ -7227,6 +7247,9 @@ static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
|
|||||||
// write empty file.
|
// write empty file.
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 // FIXME(syoyo): not used. will be removed in the future release.
|
#if 0 // FIXME(syoyo): not used. will be removed in the future release.
|
||||||
@@ -8448,6 +8471,7 @@ static bool WriteGltfStream(std::ostream &stream, const std::string &content) {
|
|||||||
|
|
||||||
static bool WriteGltfFile(const std::string &output,
|
static bool WriteGltfFile(const std::string &output,
|
||||||
const std::string &content) {
|
const std::string &content) {
|
||||||
|
#ifndef TINYGLTF_NO_FS
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
std::ofstream gltfFile(UTF8ToWchar(output).c_str());
|
std::ofstream gltfFile(UTF8ToWchar(output).c_str());
|
||||||
@@ -8467,6 +8491,9 @@ static bool WriteGltfFile(const std::string &output,
|
|||||||
if (!gltfFile.is_open()) return false;
|
if (!gltfFile.is_open()) return false;
|
||||||
#endif
|
#endif
|
||||||
return WriteGltfStream(gltfFile, content);
|
return WriteGltfStream(gltfFile, content);
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool WriteBinaryGltfStream(std::ostream &stream,
|
static bool WriteBinaryGltfStream(std::ostream &stream,
|
||||||
@@ -8533,6 +8560,7 @@ static bool WriteBinaryGltfStream(std::ostream &stream,
|
|||||||
static bool WriteBinaryGltfFile(const std::string &output,
|
static bool WriteBinaryGltfFile(const std::string &output,
|
||||||
const std::string &content,
|
const std::string &content,
|
||||||
const std::vector<unsigned char> &binBuffer) {
|
const std::vector<unsigned char> &binBuffer) {
|
||||||
|
#ifndef TINYGLTF_NO_FS
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
std::ofstream gltfFile(UTF8ToWchar(output).c_str(), std::ios::binary);
|
std::ofstream gltfFile(UTF8ToWchar(output).c_str(), std::ios::binary);
|
||||||
@@ -8549,6 +8577,9 @@ static bool WriteBinaryGltfFile(const std::string &output,
|
|||||||
std::ofstream gltfFile(output.c_str(), std::ios::binary);
|
std::ofstream gltfFile(output.c_str(), std::ios::binary);
|
||||||
#endif
|
#endif
|
||||||
return WriteBinaryGltfStream(gltfFile, content, binBuffer);
|
return WriteBinaryGltfStream(gltfFile, content, binBuffer);
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TinyGLTF::WriteGltfSceneToStream(const Model *model, std::ostream &stream,
|
bool TinyGLTF::WriteGltfSceneToStream(const Model *model, std::ostream &stream,
|
||||||
|
|||||||
1907
tinygltf_json.h
Normal file
1907
tinygltf_json.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user