mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-08 19:23:50 +00:00
Compare commits
402 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1831424c71 | ||
|
|
5e008af65d | ||
|
|
fbff1f45b5 | ||
|
|
d950e7cd9b | ||
|
|
116d0030f9 | ||
|
|
ff972dcf1b | ||
|
|
8bec431699 | ||
|
|
21485496b1 | ||
|
|
fda7422022 | ||
|
|
decfabd67e | ||
|
|
10b23b6af2 | ||
|
|
fe3cfbe996 | ||
|
|
3b73caa8e8 | ||
|
|
fea6786129 | ||
|
|
fb58f88a4e | ||
|
|
143ff45b61 | ||
|
|
cfbec35dc7 | ||
|
|
4ad8c82c9e | ||
|
|
2e7ba45a6c | ||
|
|
cf9767668a | ||
|
|
8a269aa5e9 | ||
|
|
38614763e9 | ||
|
|
3245906248 | ||
|
|
847df8456a | ||
|
|
6482c08cf7 | ||
|
|
e08df72575 | ||
|
|
f03fe26579 | ||
|
|
e54660fbf9 | ||
|
|
1bdd404c04 | ||
|
|
2191085580 | ||
|
|
cde43ef668 | ||
|
|
e3f9a7d8b3 | ||
|
|
f57d18ad74 | ||
|
|
ed3d1ec2f5 | ||
|
|
9b4e1eae9e | ||
|
|
cbc8e1bea6 | ||
|
|
212de904ca | ||
|
|
1f5b8f8b8c | ||
|
|
b274b34972 | ||
|
|
22dfeab315 | ||
|
|
b132612307 | ||
|
|
50d90c91ac | ||
|
|
4bfc1fc180 | ||
|
|
e0cc45e88d | ||
|
|
c3bbe97a9e | ||
|
|
f1bdf43e15 | ||
|
|
a42263bdba | ||
|
|
4fea26f6c8 | ||
|
|
c5641f2c22 | ||
|
|
6782f887bb | ||
|
|
8fdeca146e | ||
|
|
7fd75df70e | ||
|
|
77238cf23c | ||
|
|
8acf861db7 | ||
|
|
03b3a31e02 | ||
|
|
30ec815748 | ||
|
|
8387fdbd50 | ||
|
|
32198f757f | ||
|
|
1c6f6efafc | ||
|
|
d32f1fb2fb | ||
|
|
3203e1985e | ||
|
|
211f86e3f5 | ||
|
|
afcfb57898 | ||
|
|
b6e2398e1d | ||
|
|
d4ea67cae1 | ||
|
|
f32475c952 | ||
|
|
1f42c963e6 | ||
|
|
fd6c7855e7 | ||
|
|
5e8a7fd602 | ||
|
|
8098a9e8ed | ||
|
|
e0b393c695 | ||
|
|
c35819f0b7 | ||
|
|
4b9cfc8c1e | ||
|
|
c40c9c223e | ||
|
|
0067b4d941 | ||
|
|
35735bb686 | ||
|
|
4d119d7268 | ||
|
|
fe6a18269f | ||
|
|
bbc1eaeecf | ||
|
|
62cc92566e | ||
|
|
b2aca1ecef | ||
|
|
5a7b8278cd | ||
|
|
3d445cc65d | ||
|
|
51530ee500 | ||
|
|
759976e087 | ||
|
|
6e3d666cf3 | ||
|
|
bf7120f8a0 | ||
|
|
acf1e8a2b1 | ||
|
|
8c85d5e387 | ||
|
|
02e8b8da1e | ||
|
|
ddc76f7724 | ||
|
|
8e9aadf569 | ||
|
|
0eaa23fbfc | ||
|
|
2a5dc852cc | ||
|
|
f51243da48 | ||
|
|
a080377e6f | ||
|
|
69d75573f5 | ||
|
|
aaf631c984 | ||
|
|
112e3537ff | ||
|
|
cb6a707014 | ||
|
|
3e98ac4564 | ||
|
|
c704d73bd0 | ||
|
|
a64f4b4442 | ||
|
|
85b4322ade | ||
|
|
7a570c88d9 | ||
|
|
e12e0a9392 | ||
|
|
879cb473a3 | ||
|
|
c9657be1de | ||
|
|
95bbf15ce2 | ||
|
|
78864c8d3a | ||
|
|
14c86324d7 | ||
|
|
8d5d0b34be | ||
|
|
a1a34cb54d | ||
|
|
cfe64fb6c8 | ||
|
|
c201efb998 | ||
|
|
b88e9cc52a | ||
|
|
9417144f48 | ||
|
|
07616e8190 | ||
|
|
bec8a6d54f | ||
|
|
157063fa1b | ||
|
|
c164878d0f | ||
|
|
d852f50d49 | ||
|
|
22cafa1032 | ||
|
|
47208b234d | ||
|
|
5a6df34d99 | ||
|
|
147a00a601 | ||
|
|
350c296802 | ||
|
|
cc93e1fd25 | ||
|
|
59cc44ad4f | ||
|
|
1a5046e06b | ||
|
|
877d856e71 | ||
|
|
b534b6b0d8 | ||
|
|
ecfd37dee2 | ||
|
|
5c06b7d03b | ||
|
|
a75355b018 | ||
|
|
a977f7a16f | ||
|
|
5a6c55870e | ||
|
|
49caa65177 | ||
|
|
d71c6f61f3 | ||
|
|
b5d27fd151 | ||
|
|
af4456ba68 | ||
|
|
344669ddf6 | ||
|
|
967c98dd90 | ||
|
|
7658624bb4 | ||
|
|
84a83d39f5 | ||
|
|
03ad33cc8d | ||
|
|
3831802717 | ||
|
|
1f9a4b97a3 | ||
|
|
6dba104c54 | ||
|
|
b5e1b35ef1 | ||
|
|
52b73c7f0b | ||
|
|
98adbb3fb3 | ||
|
|
283b552a4e | ||
|
|
c2ca97b38b | ||
|
|
f051892c55 | ||
|
|
137a7ca999 | ||
|
|
477d977fea | ||
|
|
8cd5e759d0 | ||
|
|
a6c3945ed3 | ||
|
|
6614bddef3 | ||
|
|
385946dfd8 | ||
|
|
03bbe0921c | ||
|
|
a9121550b9 | ||
|
|
d2b0af6915 | ||
|
|
695608dd11 | ||
|
|
584f1dfbe4 | ||
|
|
a40ca4c5ab | ||
|
|
de75d87cfd | ||
|
|
cf11842e64 | ||
|
|
38003032e3 | ||
|
|
186016bf11 | ||
|
|
5ee08f9274 | ||
|
|
aa613a1f57 | ||
|
|
222454cc6d | ||
|
|
16c2d3a8bf | ||
|
|
186093657a | ||
|
|
9bdd256625 | ||
|
|
264ae4c131 | ||
|
|
091a1fcc1a | ||
|
|
3a295887d6 | ||
|
|
d9ce9eb9d2 | ||
|
|
56e1098993 | ||
|
|
9bb5806df4 | ||
|
|
1668d1ecc5 | ||
|
|
6e8a858c45 | ||
|
|
e0b625561c | ||
|
|
18450eafe7 | ||
|
|
e9fbc03e2d | ||
|
|
612e57816f | ||
|
|
a778c089d1 | ||
|
|
387fd61b83 | ||
|
|
6514490090 | ||
|
|
6b7ec9f494 | ||
|
|
c670f08a3b | ||
|
|
eec4c98862 | ||
|
|
c7e911cf11 | ||
|
|
43172238f7 | ||
|
|
0cc23356dc | ||
|
|
e413216722 | ||
|
|
4581d37bec | ||
|
|
966a9d0df7 | ||
|
|
64452bb5fa | ||
|
|
69eeea145b | ||
|
|
24e539621d | ||
|
|
f4f5c3cf3a | ||
|
|
b12a54ed15 | ||
|
|
240d993f94 | ||
|
|
46ee8b4276 | ||
|
|
3bddc09af4 | ||
|
|
9117abb45d | ||
|
|
52ff00a384 | ||
|
|
0fa56e239c | ||
|
|
5c2dd83964 | ||
|
|
1a8814d687 | ||
|
|
666ab8661c | ||
|
|
0b31543098 | ||
|
|
81f7dbe53a | ||
|
|
544969b732 | ||
|
|
3d4150419e | ||
|
|
41e1102e57 | ||
|
|
b901dd62d8 | ||
|
|
bc03ceaac1 | ||
|
|
2c9b25642b | ||
|
|
a894904f11 | ||
|
|
912856823d | ||
|
|
1a7c7d2001 | ||
|
|
fae6543b7a | ||
|
|
6ed7c39d71 | ||
|
|
5a90ab76ee | ||
|
|
0ffdc4334a | ||
|
|
53338352f2 | ||
|
|
d642c80a86 | ||
|
|
a1952053ee | ||
|
|
cbd3885049 | ||
|
|
9471517c1e | ||
|
|
e59028d68f | ||
|
|
cfab524125 | ||
|
|
9229971bcb | ||
|
|
051149311c | ||
|
|
0c7789b1e5 | ||
|
|
51b12d2546 | ||
|
|
4749b0989d | ||
|
|
0bfcb4f49e | ||
|
|
17e6e310ce | ||
|
|
07ceb4c313 | ||
|
|
e7f1ff5c59 | ||
|
|
fd904063c9 | ||
|
|
38398cc2da | ||
|
|
ed1a294bc4 | ||
|
|
b86eb6c079 | ||
|
|
e4bc6c7bd4 | ||
|
|
13803659f8 | ||
|
|
a3d5d5d1c9 | ||
|
|
9e3d1f6db5 | ||
|
|
190382aecd | ||
|
|
c6501530e3 | ||
|
|
ed48224f4b | ||
|
|
19a41d20ec | ||
|
|
0598a20cce | ||
|
|
514167b475 | ||
|
|
0f76561ebf | ||
|
|
f3dc4acaa4 | ||
|
|
1588e75e26 | ||
|
|
d1453b5e5e | ||
|
|
7e83ef9fb4 | ||
|
|
425195bf9c | ||
|
|
ce3a30e612 | ||
|
|
8a35b8f6fe | ||
|
|
f66f3bfeb3 | ||
|
|
e29ba7c49a | ||
|
|
bc753d4ac5 | ||
|
|
688ba8a60e | ||
|
|
d07b976d59 | ||
|
|
08a7dd8dad | ||
|
|
87da1e775f | ||
|
|
151495558e | ||
|
|
84e15260ba | ||
|
|
03cdef430d | ||
|
|
fb4bd82e2c | ||
|
|
3ddf8301f6 | ||
|
|
298c37a954 | ||
|
|
b702de755f | ||
|
|
58ceed1d89 | ||
|
|
d1b6b3a5aa | ||
|
|
c56d069726 | ||
|
|
d1e32865f1 | ||
|
|
869a9d273c | ||
|
|
1208f057d6 | ||
|
|
f684dde9f1 | ||
|
|
7905a5b4dc | ||
|
|
f161782001 | ||
|
|
654bcf733c | ||
|
|
001c870051 | ||
|
|
2c521b3432 | ||
|
|
a159945db9 | ||
|
|
010ee9c67b | ||
|
|
a23971c603 | ||
|
|
1923067982 | ||
|
|
68adc4ba5e | ||
|
|
42a8cd50ff | ||
|
|
0543640a83 | ||
|
|
9c59a0b64c | ||
|
|
452541a231 | ||
|
|
78fe8d9b89 | ||
|
|
51e5508fa0 | ||
|
|
91da299729 | ||
|
|
50ae8a31a8 | ||
|
|
0af0435ef1 | ||
|
|
7c342533e9 | ||
|
|
7842c1276f | ||
|
|
125e4a2033 | ||
|
|
c9d6c5b9b4 | ||
|
|
96a8b2c69b | ||
|
|
01d54380ac | ||
|
|
6cd8fdb2c8 | ||
|
|
fe01af2f01 | ||
|
|
efdd2b04dc | ||
|
|
2e642b3322 | ||
|
|
1739d025a9 | ||
|
|
39418e5728 | ||
|
|
5622d2762d | ||
|
|
3d939fd3ee | ||
|
|
fbbeb4d6a9 | ||
|
|
cef1787ef8 | ||
|
|
2f5aa9f13b | ||
|
|
28bafe4b11 | ||
|
|
34894a6325 | ||
|
|
2e7006797b | ||
|
|
d9c03d041a | ||
|
|
50a3061ddf | ||
|
|
014dce27f4 | ||
|
|
c046769054 | ||
|
|
c43266fdc9 | ||
|
|
aca196e8d3 | ||
|
|
b48c027c9a | ||
|
|
db5c3bea45 | ||
|
|
ddfa1f2f0b | ||
|
|
7b69c778fe | ||
|
|
73e73bf3c1 | ||
|
|
35d664e417 | ||
|
|
272a9dfa5f | ||
|
|
f3bf6ee78e | ||
|
|
aba57bb907 | ||
|
|
6fad7adb9c | ||
|
|
3dad303bea | ||
|
|
ff0a2e9fb4 | ||
|
|
fe77cc5cdd | ||
|
|
18f0e20a11 | ||
|
|
978adee547 | ||
|
|
73c4cce303 | ||
|
|
925b83627a | ||
|
|
92c23725ae | ||
|
|
af750a5104 | ||
|
|
ff48fa0ff4 | ||
|
|
ec45334d3d | ||
|
|
5f603c56dc | ||
|
|
063b8586f1 | ||
|
|
db855c6794 | ||
|
|
e391f6b03e | ||
|
|
5ecede71f0 | ||
|
|
40982716f9 | ||
|
|
4bdc96fb9b | ||
|
|
96ecea080a | ||
|
|
22bfc843ee | ||
|
|
eaa25a307a | ||
|
|
ab600b8e72 | ||
|
|
eb9d29c06e | ||
|
|
57356933c5 | ||
|
|
c3d6716c56 | ||
|
|
ac5e09f8c3 | ||
|
|
e2c3fe1c0b | ||
|
|
973d9b3394 | ||
|
|
28ad4ab7b8 | ||
|
|
0227ae5d9b | ||
|
|
a0a62bde1c | ||
|
|
23d1ff2880 | ||
|
|
bcf2ce586e | ||
|
|
aa3c5a1cad | ||
|
|
db2fbeec9d | ||
|
|
c4166e4c60 | ||
|
|
1cf179d377 | ||
|
|
ddc14f8ba6 | ||
|
|
72f4a55edd | ||
|
|
379bb612f1 | ||
|
|
1da4e5d633 | ||
|
|
4e47bc7799 | ||
|
|
9cc3e91968 | ||
|
|
d09788d10f | ||
|
|
a11f6e1939 | ||
|
|
8ced108571 | ||
|
|
3eb65e269a | ||
|
|
1322c7bf09 | ||
|
|
49651fe3d9 | ||
|
|
db93a87c4a | ||
|
|
7b0d81bf12 | ||
|
|
2e8a115d7e | ||
|
|
ae9364902a | ||
|
|
06d2fbdae6 | ||
|
|
d5ff5cbfb1 | ||
|
|
1d20520680 | ||
|
|
4ab0386d09 | ||
|
|
a471770f38 |
13
.github/FUNDING.yml
vendored
Normal file
13
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: syoyo
|
||||
#patreon: # Replace with a single Patreon username
|
||||
#open_collective: # Replace with a single Open Collective username
|
||||
#ko_fi: # Replace with a single Ko-fi username
|
||||
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
#liberapay: # Replace with a single Liberapay username
|
||||
#issuehunt: # Replace with a single IssueHunt username
|
||||
#otechie: # Replace with a single Otechie username
|
||||
#lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
blank_issues_enabled: false
|
||||
30
.github/ISSUE_TEMPLATE/issue-report.md
vendored
Normal file
30
.github/ISSUE_TEMPLATE/issue-report.md
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
name: Issue report
|
||||
about: Create a report
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the issue**
|
||||
|
||||
A clear and concise description of what the issue is.
|
||||
|
||||
**To Reproduce**
|
||||
|
||||
- OS
|
||||
- Compiler, compiler version, compile options
|
||||
- Please attach minimal and reproducible .glTF file if you got an issue related to .glTF data
|
||||
|
||||
**Expected behaviour**
|
||||
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
169
.github/workflows/c-cpp.yml
vendored
Normal file
169
.github/workflows/c-cpp.yml
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
name: C/C++ CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
|
||||
# gcc4.8 is too old and ubuntu-18.04 image is not supported in GitHub Actions anymore,
|
||||
# so disable this build.
|
||||
## compile with older gcc4.8
|
||||
#build-gcc48:
|
||||
|
||||
# runs-on: ubuntu-18.04
|
||||
# name: Build with gcc 4.8
|
||||
|
||||
# steps:
|
||||
# - name: Checkout
|
||||
# uses: actions/checkout@v1
|
||||
|
||||
# - name: Build
|
||||
# run: |
|
||||
# sudo apt-get update
|
||||
# sudo apt-get install -y build-essential
|
||||
# sudo apt-get install -y gcc-4.8 g++-4.8
|
||||
# g++-4.8 -std=c++11 -o loader_example loader_example.cc
|
||||
|
||||
# - name: NoexceptBuild
|
||||
# run: |
|
||||
# g++-4.8 -DTINYGLTF_NOEXCEPTION -std=c++11 -o loader_example loader_example.cc
|
||||
|
||||
# - name: RapidjsonBuild
|
||||
# run: |
|
||||
# git clone https://github.com/Tencent/rapidjson
|
||||
# g++-4.8 -DTINYGLTF_USE_RAPIDJSON -I./rapidjson/include/rapidjson -std=c++11 -o loader_example loader_example.cc
|
||||
|
||||
# compile with mingw gcc cross
|
||||
build-mingw-cross:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
name: Build with MinGW gcc cross
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential
|
||||
sudo apt-get install -y mingw-w64
|
||||
x86_64-w64-mingw32-g++ -std=c++11 -o loader_example loader_example.cc
|
||||
|
||||
# Windows(x64) + Visual Studio 2022 build
|
||||
# Assume windows-latest have VS2022 installed
|
||||
build-windows-msvc:
|
||||
|
||||
runs-on: windows-latest
|
||||
name: Build for Windows(x64, MSVC)
|
||||
|
||||
# Use system installed cmake
|
||||
# https://help.github.com/en/actions/reference/software-installed-on-github-hosted-runners
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
- name: Configure
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake --help
|
||||
cmake -G "Visual Studio 17 2022" -A x64 -DTINYGLTF_BUILD_LOADER_EXAMPLE=On -DTINYGLTF_BUILD_GL_EXAMPLES=Off -DTINYGLTF_BUILD_VALIDATOR_EXAMPLE=On ..
|
||||
cd ..
|
||||
- name: Build
|
||||
run: cmake --build build --config Release
|
||||
|
||||
|
||||
build-linux:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
name: Buld with gcc
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: build
|
||||
run: |
|
||||
g++ -std=c++11 -o loader_example loader_example.cc
|
||||
- name: test
|
||||
run: |
|
||||
./loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: tests
|
||||
run: |
|
||||
cd tests
|
||||
g++ -I../ -std=c++11 -g -O0 -o tester tester.cc
|
||||
./tester
|
||||
cd ..
|
||||
|
||||
- name: noexcept_tests
|
||||
run: |
|
||||
cd tests
|
||||
g++ -DTINYGLTF_NOEXCEPTION -I../ -std=c++11 -g -O0 -o tester_noexcept tester.cc
|
||||
./tester_noexcept
|
||||
cd ..
|
||||
|
||||
|
||||
build-rapidjson-linux:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
name: Buld with gcc + rapidjson
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: build
|
||||
run: |
|
||||
git clone https://github.com/Tencent/rapidjson
|
||||
g++ -v
|
||||
g++ -DTINYGLTF_USE_RAPIDJSON -I./rapidjson/include/rapidjson -std=c++11 -o loader_example loader_example.cc
|
||||
|
||||
- name: loader_example_test
|
||||
run: |
|
||||
./loader_example models/Cube/Cube.gltf
|
||||
|
||||
- name: tests
|
||||
run: |
|
||||
cd tests
|
||||
g++ -DTINYGLTF_USE_RAPIDJSON -I../rapidjson/include/rapidjson -I../ -std=c++11 -g -O0 -o tester tester.cc
|
||||
./tester
|
||||
cd ..
|
||||
|
||||
- name: noexcept_tests
|
||||
run: |
|
||||
cd tests
|
||||
g++ -DTINYGLTF_USE_RAPIDJSON -I../rapidjson/include/rapidjson -DTINYGLTF_NOEXCEPTION -I../ -std=c++11 -g -O0 -o tester_noexcept tester.cc
|
||||
./tester_noexcept
|
||||
cd ..
|
||||
|
||||
# Cross-compile for aarch64 linux target
|
||||
build-cross-aarch64:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
name: Build on cross aarch64
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential
|
||||
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
|
||||
|
||||
git clone https://github.com/Tencent/rapidjson
|
||||
aarch64-linux-gnu-g++ -DTINYGLTF_USE_RAPIDJSON -I./rapidjson/include/rapidjson -std=c++11 -g -O0 -o loader_example loader_example.cc
|
||||
|
||||
# macOS clang
|
||||
build-macos:
|
||||
|
||||
runs-on: macos-latest
|
||||
name: Build on macOS
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
- name: Build
|
||||
run: |
|
||||
clang++ -std=c++11 -g -O0 -o loader_example loader_example.cc
|
||||
./loader_example models/Cube/Cube.gltf
|
||||
|
||||
git clone https://github.com/Tencent/rapidjson
|
||||
clang++ -DTINYGLTF_USE_RAPIDJSON -I./rapidjson/include/rapidjson -std=c++11 -g -O0 -o loader_example loader_example.cc
|
||||
|
||||
72
.github/workflows/codeql-analysis.yml
vendored
Normal file
72
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ "master" ]
|
||||
schedule:
|
||||
- cron: '21 20 * * 5'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'cpp', 'python' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
|
||||
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||
# queries: security-extended,security-and-quality
|
||||
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
|
||||
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
||||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
||||
|
||||
# - run: |
|
||||
# echo "Run, Build Application using script"
|
||||
# ./location_of_script_within_repo/buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
45
.github/workflows/mingw-w64-msys2.yml
vendored
Normal file
45
.github/workflows/mingw-w64-msys2.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: MSYS2 MinGW-w64 Windows 64bit Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- release
|
||||
- devel
|
||||
paths:
|
||||
- 'tiny_gltf.*'
|
||||
- 'CMakeLists.txt'
|
||||
- '.github/workflows/mingw-w64-msys2.yml'
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
mingw-w64-msys2-build:
|
||||
name: MSYS2 MinGW-w64 Windows Build
|
||||
runs-on: windows-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install core & build dependencies
|
||||
uses: msys2/setup-msys2@v2
|
||||
with:
|
||||
msystem: UCRT64
|
||||
install: base-devel
|
||||
pacboy: >-
|
||||
cc:p cmake:p ninja:p
|
||||
update: true
|
||||
release: false
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake \
|
||||
-G"Ninja" \
|
||||
-S . \
|
||||
-B build
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cmake --build build
|
||||
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
@@ -24,6 +24,7 @@ premake5.tar.gz
|
||||
#binary directories
|
||||
bin/
|
||||
obj/
|
||||
out/
|
||||
|
||||
#runtime gui config
|
||||
imgui.ini
|
||||
@@ -68,4 +69,11 @@ loader_example
|
||||
tests/tester
|
||||
tests/tester_noexcept
|
||||
tests/issue-97.gltf
|
||||
tests/issue-261.gltf
|
||||
|
||||
# unignore
|
||||
!Makefile
|
||||
!examples/build-gltf/Makefile
|
||||
!examples/raytrace/cornellbox_suzanne.obj
|
||||
!tests/Makefile
|
||||
!tools/windows/premake5.exe
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$TRAVIS_OS_NAME" == "osx" ]]
|
||||
then
|
||||
brew upgrade
|
||||
curl -o premake5.tar.gz https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-macosx.tar.gz
|
||||
else
|
||||
wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-linux.tar.gz -O premake5.tar.gz
|
||||
fi
|
||||
tar xzf premake5.tar.gz
|
||||
63
.travis.yml
63
.travis.yml
@@ -1,63 +0,0 @@
|
||||
language: cpp
|
||||
sudo: false
|
||||
matrix:
|
||||
include:
|
||||
- addons: &1
|
||||
apt:
|
||||
sources:
|
||||
- george-edison55-precise-backports
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-3.9
|
||||
packages:
|
||||
- g++-4.9
|
||||
- clang-3.9
|
||||
compiler: clang
|
||||
env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug
|
||||
- addons: *1
|
||||
compiler: clang
|
||||
env: COMPILER_VERSION=3.9 BUILD_TYPE=Release
|
||||
- addons: &2
|
||||
apt:
|
||||
sources:
|
||||
- george-edison55-precise-backports
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.9
|
||||
compiler: gcc
|
||||
env: COMPILER_VERSION=4.9 BUILD_TYPE=Debug EXTRA_CXXFLAGS="-fsanitize=address"
|
||||
- addons: *2
|
||||
compiler: gcc
|
||||
env: COMPILER_VERSION=4.9 BUILD_TYPE=Release EXTRA_CXXFLAGS="-fsanitize=address"
|
||||
- addons: *1
|
||||
compiler: clang
|
||||
env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug CFLAGS="-O0" CXXFLAGS="-O0"
|
||||
- addons: &3
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.8
|
||||
compiler: gcc
|
||||
env: COMPILER_VERSION=4.8 BUILD_TYPE=Debug
|
||||
- addons: *3
|
||||
compiler: gcc
|
||||
env: COMPILER_VERSION=4.8 BUILD_TYPE=Release
|
||||
|
||||
before_install:
|
||||
- ./.travis-before-install.sh
|
||||
|
||||
|
||||
script:
|
||||
- export CC="${CC}-${COMPILER_VERSION}"
|
||||
- export CXX="${CXX}-${COMPILER_VERSION}"
|
||||
- ${CC} -v
|
||||
- ${CXX} ${EXTRA_CXXFLAGS} -std=c++11 -Wall -g -o loader_example loader_example.cc
|
||||
- ./loader_example ./models/Cube/Cube.gltf
|
||||
- cd tests
|
||||
- clang++ -v
|
||||
- make
|
||||
- ./tester
|
||||
- ./tester_noexcept
|
||||
- cd ../examples/raytrace
|
||||
- ../../premake5 gmake
|
||||
- make
|
||||
@@ -1,35 +1,87 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
PROJECT (tinygltf)
|
||||
project(tinygltf)
|
||||
|
||||
SET(CMAKE_CXX_STANDARD 11)
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
option(TINYGLTF_BUILD_EXAMPLES "Build examples" ON)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED On)
|
||||
set(CMAKE_CXX_EXTENSIONS Off)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
if (TINYGLTF_BUILD_EXAMPLES)
|
||||
ADD_EXECUTABLE ( loader_example
|
||||
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_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
|
||||
loader_example.cc
|
||||
)
|
||||
endif (TINYGLTF_BUILD_LOADER_EXAMPLE)
|
||||
|
||||
ADD_SUBDIRECTORY ( examples/gltfutil )
|
||||
ADD_SUBDIRECTORY ( examples/glview )
|
||||
ADD_SUBDIRECTORY ( examples/validator )
|
||||
endif (TINYGLTF_BUILD_EXAMPLES)
|
||||
if (TINYGLTF_BUILD_GL_EXAMPLES)
|
||||
add_subdirectory( examples/gltfutil )
|
||||
add_subdirectory( examples/glview )
|
||||
endif (TINYGLTF_BUILD_GL_EXAMPLES)
|
||||
|
||||
if (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
||||
add_subdirectory( examples/validator )
|
||||
endif (TINYGLTF_BUILD_VALIDATOR_EXAMPLE)
|
||||
|
||||
if (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||
add_subdirectory ( examples/build-gltf )
|
||||
endif (TINYGLTF_BUILD_BUILDER_EXAMPLE)
|
||||
|
||||
#
|
||||
# TinuGLTF is a header-only library, so no library build. just install header files.
|
||||
# for add_subdirectory and standalone build
|
||||
#
|
||||
INSTALL ( FILES
|
||||
json.hpp
|
||||
stb_image.h
|
||||
stb_image_write.h
|
||||
tiny_gltf.h
|
||||
DESTINATION
|
||||
include
|
||||
if (TINYGLTF_HEADER_ONLY)
|
||||
add_library(tinygltf INTERFACE)
|
||||
|
||||
target_include_directories(tinygltf
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
INSTALL ( FILES
|
||||
cmake/TinyGLTFConfig.cmake
|
||||
DESTINATION
|
||||
cmake
|
||||
)
|
||||
else (TINYGLTF_HEADER_ONLY)
|
||||
add_library(tinygltf)
|
||||
target_sources(tinygltf PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tiny_gltf.cc)
|
||||
target_include_directories(tinygltf
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
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/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
|
||||
${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)
|
||||
|
||||
91
README.md
91
README.md
@@ -2,25 +2,38 @@
|
||||
|
||||
`TinyGLTF` is a header only C++11 glTF 2.0 https://github.com/KhronosGroup/glTF library.
|
||||
|
||||
`TinyGLTF` uses Niels Lohmann's json library(https://github.com/nlohmann/json), so now it requires C++11 compiler.
|
||||
If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
||||
`TinyGLTF` uses Niels Lohmann's json library (https://github.com/nlohmann/json), so now it requires C++11 compiler.
|
||||
(Also, you can use RadpidJSON as an JSON backend)
|
||||
If you are looking for old, C++03 version, please use `devel-picojson` branch (but not maintained anymore).
|
||||
|
||||
## Status
|
||||
|
||||
Currently TinyGLTF is stable and maintenance mode. No drastic changes and feature additions planned.
|
||||
- v2.9.0 Various fixes and improvements. Filesystem callback API change.
|
||||
- v2.8.0 Add URICallbacks for custom URI handling in Buffer and Image. PR#397
|
||||
- v2.7.0 Change WriteImageDataFunction user callback function signature. PR#393
|
||||
- v2.6.0 Support serializing sparse accessor(Thanks to @fynv).
|
||||
- v2.5.0 Add SetPreserveImageChannels() option to load image data as is.
|
||||
- v2.4.0 Experimental RapidJSON support. Experimental C++14 support(C++14 may give better performance)
|
||||
- v2.3.0 Modified Material representation according to glTF 2.0 schema(and introduced TextureInfo class)
|
||||
- v2.2.0 release(Support loading 16bit PNG. Sparse accessor support)
|
||||
- v2.1.0 release(Draco support)
|
||||
- v2.1.0 release(Draco decoding support)
|
||||
- v2.0.0 release(22 Aug, 2018)!
|
||||
|
||||
### Branches
|
||||
|
||||
* `sajson` : Use sajson to parse JSON. Parsing only but faster compile time(2x reduction compared to json.hpp and RapidJson), but not well maintained.
|
||||
|
||||
## Builds
|
||||
|
||||
[](https://travis-ci.org/syoyo/tinygltf)
|
||||
|
||||
[](https://ci.appveyor.com/project/syoyo/tinygltf)
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
Probably mostly feature-complete. Last missing feature is Draco encoding: https://github.com/syoyo/tinygltf/issues/207
|
||||
|
||||
* Written in portable C++. C++-11 with STL dependency only.
|
||||
* [x] macOS + clang(LLVM)
|
||||
* [x] iOS + clang
|
||||
@@ -34,8 +47,11 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
||||
* Moderate parsing time and memory consumption.
|
||||
* glTF specification v2.0.0
|
||||
* [x] ASCII glTF
|
||||
* [x] Load
|
||||
* [x] Save
|
||||
* [x] Binary glTF(GLB)
|
||||
* [x] PBR material description
|
||||
* [x] Load
|
||||
* [x] Save(.bin embedded .glb)
|
||||
* Buffers
|
||||
* [x] Parse BASE64 encoded embedded buffer data(DataURI).
|
||||
* [x] Load `.bin` file.
|
||||
@@ -55,6 +71,7 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
||||
* [x] Image save
|
||||
* Extensions
|
||||
* [x] Draco mesh decoding
|
||||
* [ ] Draco mesh encoding
|
||||
|
||||
## Note on extension property
|
||||
|
||||
@@ -67,6 +84,13 @@ In extension(`ExtensionMap`), JSON number value is parsed as int or float(number
|
||||
* [glview](examples/glview) : Simple glTF geometry viewer.
|
||||
* [validator](examples/validator) : Simple glTF validator with JSON schema.
|
||||
* [basic](examples/basic) : Basic glTF viewer with texturing support.
|
||||
* [build-gltf](examples/build-gltf) : Build simple glTF scene from a scratch.
|
||||
|
||||
### WASI/WASM build
|
||||
|
||||
Users who want to run TinyGLTF securely and safely(e.g. need to handle malcious glTF file to serve online glTF conver),
|
||||
I recommend to build TinyGLTF for WASM target.
|
||||
WASI build example is located in [wasm](wasm) .
|
||||
|
||||
## Projects using TinyGLTF
|
||||
|
||||
@@ -79,11 +103,16 @@ In extension(`ExtensionMap`), JSON number value is parsed as int or float(number
|
||||
* [QuickLook GLTF](https://github.com/toshiks/glTF-quicklook) - quicklook plugin for macos. Also SceneKit wrapper for tinygltf.
|
||||
* [GlslViewer](https://github.com/patriciogonzalezvivo/glslViewer) - live GLSL coding for MacOS and Linux
|
||||
* [Vulkan-Samples](https://github.com/KhronosGroup/Vulkan-Samples) - The Vulkan Samples is collection of resources to help you develop optimized Vulkan applications.
|
||||
* [TDME2](https://github.com/andreasdr/tdme2) - TDME2 - ThreeDeeMiniEngine2 is a lightweight 3D engine including tools suited for 3D game development using C++11
|
||||
* [SanityEngine](https://github.com/DethRaid/SanityEngine) - A C++/D3D12 renderer focused on the personal and professional development of its developer
|
||||
* [Open3D](http://www.open3d.org/) - A Modern Library for 3D Data Processing
|
||||
* [Supernova Engine](https://github.com/supernovaengine/supernova) - Game engine for 2D and 3D projects with Lua or C++ in data oriented design.
|
||||
* [Wicked Engine<img src="https://github.com/turanszkij/WickedEngine/blob/master/Content/logo_small.png" width="28px" align="center"/>](https://github.com/turanszkij/WickedEngine) - 3D engine with modern graphics
|
||||
* Your projects here! (Please send PR)
|
||||
|
||||
## TODOs
|
||||
|
||||
* [ ] Write C++ code generator which emits C++ code from JSON schema for robust parsing.
|
||||
* [ ] Robust URI decoding/encoding. https://github.com/syoyo/tinygltf/issues/369
|
||||
* [ ] Mesh Compression/decompression(Open3DGC, etc)
|
||||
* [x] Load Draco compressed mesh
|
||||
* [ ] Save Draco compressed mesh
|
||||
@@ -94,6 +123,10 @@ In extension(`ExtensionMap`), JSON number value is parsed as int or float(number
|
||||
* [ ] 16bit PNG support in Serialization
|
||||
* [ ] Write example and tests for `animation` and `skin`
|
||||
|
||||
### Optional
|
||||
|
||||
* [ ] Write C++ code generator which emits C++ code from JSON schema for robust parsing?
|
||||
|
||||
## Licenses
|
||||
|
||||
TinyGLTF is licensed under MIT license.
|
||||
@@ -144,6 +177,10 @@ if (!ret) {
|
||||
}
|
||||
```
|
||||
|
||||
#### Loader options
|
||||
|
||||
* `TinyGLTF::SetPreserveimageChannels(bool onoff)`. `true` to preserve image channels as stored in image file for loaded image. `false` by default for backward compatibility(image channels are widen to `RGBA` 4 channels). Effective only when using builtin image loader(STB image loader).
|
||||
|
||||
## Compile options
|
||||
|
||||
* `TINYGLTF_NOEXCEPTION` : Disable C++ exception in JSON parsing. You can use `-fno-exceptions` or by defining the symbol `JSON_NOEXCEPTION` and `TINYGLTF_NOEXCEPTION` to fully remove C++ exception codes when compiling TinyGLTF.
|
||||
@@ -153,21 +190,45 @@ if (!ret) {
|
||||
* `TINYGLTF_ANDROID_LOAD_FROM_ASSETS`: Load all files from packaged app assets instead of the regular file system. **Note:** You must pass a valid asset manager from your android app to `tinygltf::asset_manager` beforehand.
|
||||
* `TINYGLTF_ENABLE_DRACO`: Enable Draco compression. User must provide include path and link correspnding libraries in your project file.
|
||||
* `TINYGLTF_NO_INCLUDE_JSON `: Disable including `json.hpp` 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_RAPIDJSON `: Disable including RapidJson's header files 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_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 featrure.
|
||||
* `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
|
||||
|
||||
You can add tinygltf using `add_subdirectory` feature.
|
||||
If you add tinygltf to your project using `add_subdirectory`, it would be better to set `TINYGLTF_HEADER_ONLY` on(just add an include path to tinygltf) and `TINYGLTF_INSTALL` off(Which does not install tinygltf files).
|
||||
|
||||
```
|
||||
// Your project's CMakeLists.txt
|
||||
...
|
||||
|
||||
set(TINYGLTF_HEADER_ONLY ON CACHE INTERNAL "" FORCE)
|
||||
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
|
||||
* [ ] Buffers.
|
||||
|
||||
* Buffers.
|
||||
* [x] To file
|
||||
* [x] Embedded
|
||||
* [ ] Draco compressed?
|
||||
* [x] Images
|
||||
* [x] To file
|
||||
* [x] Embedded
|
||||
* [ ] Binary(.glb)
|
||||
* Binary(.glb)
|
||||
* [x] .bin embedded single .glb
|
||||
* [ ] External .bin
|
||||
|
||||
## Running tests.
|
||||
|
||||
@@ -175,7 +236,7 @@ if (!ret) {
|
||||
|
||||
#### Setup
|
||||
|
||||
Python 2.6 or 2.7 required.
|
||||
Python required.
|
||||
Git clone https://github.com/KhronosGroup/glTF-Sample-Models to your local dir.
|
||||
|
||||
#### Run parsing test
|
||||
@@ -195,9 +256,17 @@ $ ./tester
|
||||
$ ./tester_noexcept
|
||||
```
|
||||
|
||||
### Fuzzing tests
|
||||
|
||||
See `tests/fuzzer` for details.
|
||||
|
||||
After running fuzzer on Ryzen9 3950X a week, at least `LoadASCIIFromString` looks safe except for out-of-memory error in Fuzzer.
|
||||
We may be better to introduce bounded memory size checking when parsing glTF data.
|
||||
|
||||
## Third party licenses
|
||||
|
||||
* json.hpp : Licensed under the MIT License <http://opensource.org/licenses/MIT>. Copyright (c) 2013-2017 Niels Lohmann <http://nlohmann.me>.
|
||||
* stb_image : Public domain.
|
||||
* catch : Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. Distributed under the Boost Software License, Version 1.0.
|
||||
* RapidJSON : Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. http://rapidjson.org/
|
||||
* dlib(uridecode, uriencode) : Copyright (C) 2003 Davis E. King Boost Software License 1.0. http://dlib.net/dlib/server/server_http.cpp.html
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
# -*- cmake -*-
|
||||
# - Find TinyGLTF
|
||||
|
||||
# TinyGLTF_INCLUDE_DIR TinyGLTF's include directory
|
||||
|
||||
|
||||
FIND_PACKAGE ( PackageHandleStandardArgs )
|
||||
|
||||
SET ( TinyGLTF_INCLUDE_DIR "${TinyGLTF_DIR}/../include" CACHE STRING "TinyGLTF include directory")
|
||||
|
||||
FIND_FILE ( TinyGLTF_HEADER tiny_gltf.h PATHS ${TinyGLTF_INCLUDE_DIR} )
|
||||
|
||||
IF (NOT TinyGLTF_HEADER)
|
||||
MESSAGE ( FATAL_ERROR "Unable to find tiny_gltf.h, TinyGLTF_INCLUDE_DIR = ${TinyGLTF_INCLUDE_DIR}")
|
||||
ENDIF ()
|
||||
3
cmake/TinyGLTFConfig.cmake.in
Normal file
3
cmake/TinyGLTFConfig.cmake.in
Normal file
@@ -0,0 +1,3 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/TinyGLTFTargets.cmake)
|
||||
1
examples/basic/.gitignore
vendored
1
examples/basic/.gitignore
vendored
@@ -1,5 +1,6 @@
|
||||
.vs
|
||||
Debug
|
||||
Release
|
||||
x64
|
||||
packages
|
||||
|
||||
|
||||
@@ -19,3 +19,7 @@ $ make
|
||||
Plese use solution file located at `basic` folder.
|
||||
|
||||
|
||||
## Limitation
|
||||
|
||||
There are so many limitations in this example(e.g. no PBR shader. the shader only shows texture of textures[0] if available).
|
||||
|
||||
|
||||
@@ -22,32 +22,32 @@
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{0589AC44-0CF3-40D8-8D89-68393CFD40F3}</ProjectGuid>
|
||||
<RootNamespace>basic</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -39,8 +39,8 @@ bool loadModel(tinygltf::Model &model, const char *filename) {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::map<int, GLuint> bindMesh(std::map<int, GLuint> vbos,
|
||||
tinygltf::Model &model, tinygltf::Mesh &mesh) {
|
||||
void bindMesh(std::map<int, GLuint>& vbos,
|
||||
tinygltf::Model &model, tinygltf::Mesh &mesh) {
|
||||
for (size_t i = 0; i < model.bufferViews.size(); ++i) {
|
||||
const tinygltf::BufferView &bufferView = model.bufferViews[i];
|
||||
if (bufferView.target == 0) { // TODO impl drawarrays
|
||||
@@ -100,56 +100,66 @@ std::map<int, GLuint> bindMesh(std::map<int, GLuint> vbos,
|
||||
std::cout << "vaa missing: " << attrib.first << std::endl;
|
||||
}
|
||||
|
||||
GLuint texid;
|
||||
glGenTextures(1, &texid);
|
||||
if (model.textures.size() > 0) {
|
||||
// fixme: Use material's baseColor
|
||||
tinygltf::Texture &tex = model.textures[0];
|
||||
|
||||
tinygltf::Texture &tex = model.textures[0];
|
||||
tinygltf::Image &image = model.images[tex.source];
|
||||
if (tex.source > -1) {
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texid);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
GLuint texid;
|
||||
glGenTextures(1, &texid);
|
||||
|
||||
GLenum format = GL_RGBA;
|
||||
tinygltf::Image &image = model.images[tex.source];
|
||||
|
||||
if (image.component == 1) {
|
||||
format = GL_RED;
|
||||
} else if (image.component == 2) {
|
||||
format = GL_RG;
|
||||
} else if (image.component == 3) {
|
||||
format = GL_RGB;
|
||||
} else {
|
||||
// ???
|
||||
glBindTexture(GL_TEXTURE_2D, texid);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
GLenum format = GL_RGBA;
|
||||
|
||||
if (image.component == 1) {
|
||||
format = GL_RED;
|
||||
} else if (image.component == 2) {
|
||||
format = GL_RG;
|
||||
} else if (image.component == 3) {
|
||||
format = GL_RGB;
|
||||
} else {
|
||||
// ???
|
||||
}
|
||||
|
||||
GLenum type = GL_UNSIGNED_BYTE;
|
||||
if (image.bits == 8) {
|
||||
// ok
|
||||
} else if (image.bits == 16) {
|
||||
type = GL_UNSIGNED_SHORT;
|
||||
} else {
|
||||
// ???
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width, image.height, 0,
|
||||
format, type, &image.image.at(0));
|
||||
}
|
||||
}
|
||||
|
||||
GLenum type = GL_UNSIGNED_BYTE;
|
||||
if (image.bits == 8) {
|
||||
// ok
|
||||
} else if (image.bits == 16) {
|
||||
type = GL_UNSIGNED_SHORT;
|
||||
} else {
|
||||
// ???
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width, image.height, 0,
|
||||
format, type, &image.image.at(0));
|
||||
}
|
||||
|
||||
return vbos;
|
||||
}
|
||||
|
||||
// bind models
|
||||
void bindModelNodes(std::map<int, GLuint> vbos, tinygltf::Model &model,
|
||||
void bindModelNodes(std::map<int, GLuint>& vbos, tinygltf::Model &model,
|
||||
tinygltf::Node &node) {
|
||||
bindMesh(vbos, model, model.meshes[node.mesh]);
|
||||
if ((node.mesh >= 0) && (node.mesh < model.meshes.size())) {
|
||||
bindMesh(vbos, model, model.meshes[node.mesh]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < node.children.size(); i++) {
|
||||
assert((node.children[i] >= 0) && (node.children[i] < model.nodes.size()));
|
||||
bindModelNodes(vbos, model, model.nodes[node.children[i]]);
|
||||
}
|
||||
}
|
||||
GLuint bindModel(tinygltf::Model &model) {
|
||||
|
||||
std::pair<GLuint, std::map<int, GLuint>> bindModel(tinygltf::Model &model) {
|
||||
std::map<int, GLuint> vbos;
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
@@ -157,23 +167,34 @@ GLuint bindModel(tinygltf::Model &model) {
|
||||
|
||||
const tinygltf::Scene &scene = model.scenes[model.defaultScene];
|
||||
for (size_t i = 0; i < scene.nodes.size(); ++i) {
|
||||
assert((scene.nodes[i] >= 0) && (scene.nodes[i] < model.nodes.size()));
|
||||
bindModelNodes(vbos, model, model.nodes[scene.nodes[i]]);
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
// cleanup vbos
|
||||
for (size_t i = 0; i < vbos.size(); ++i) {
|
||||
glDeleteBuffers(1, &vbos[i]);
|
||||
// cleanup vbos but do not delete index buffers yet
|
||||
for (auto it = vbos.cbegin(); it != vbos.cend();) {
|
||||
tinygltf::BufferView bufferView = model.bufferViews[it->first];
|
||||
if (bufferView.target != GL_ELEMENT_ARRAY_BUFFER) {
|
||||
glDeleteBuffers(1, &vbos[it->first]);
|
||||
vbos.erase(it++);
|
||||
}
|
||||
else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
return vao;
|
||||
return {vao, vbos};
|
||||
}
|
||||
|
||||
void drawMesh(tinygltf::Model &model, tinygltf::Mesh &mesh) {
|
||||
void drawMesh(const std::map<int, GLuint>& vbos,
|
||||
tinygltf::Model &model, tinygltf::Mesh &mesh) {
|
||||
for (size_t i = 0; i < mesh.primitives.size(); ++i) {
|
||||
tinygltf::Primitive primitive = mesh.primitives[i];
|
||||
tinygltf::Accessor indexAccessor = model.accessors[primitive.indices];
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos.at(indexAccessor.bufferView));
|
||||
|
||||
glDrawElements(primitive.mode, indexAccessor.count,
|
||||
indexAccessor.componentType,
|
||||
BUFFER_OFFSET(indexAccessor.byteOffset));
|
||||
@@ -181,18 +202,22 @@ void drawMesh(tinygltf::Model &model, tinygltf::Mesh &mesh) {
|
||||
}
|
||||
|
||||
// recursively draw node and children nodes of model
|
||||
void drawModelNodes(tinygltf::Model &model, tinygltf::Node &node) {
|
||||
drawMesh(model, model.meshes[node.mesh]);
|
||||
void drawModelNodes(const std::pair<GLuint, std::map<int, GLuint>>& vaoAndEbos,
|
||||
tinygltf::Model &model, tinygltf::Node &node) {
|
||||
if ((node.mesh >= 0) && (node.mesh < model.meshes.size())) {
|
||||
drawMesh(vaoAndEbos.second, model, model.meshes[node.mesh]);
|
||||
}
|
||||
for (size_t i = 0; i < node.children.size(); i++) {
|
||||
drawModelNodes(model, model.nodes[node.children[i]]);
|
||||
drawModelNodes(vaoAndEbos, model, model.nodes[node.children[i]]);
|
||||
}
|
||||
}
|
||||
void drawModel(GLuint vao, tinygltf::Model &model) {
|
||||
glBindVertexArray(vao);
|
||||
void drawModel(const std::pair<GLuint, std::map<int, GLuint>>& vaoAndEbos,
|
||||
tinygltf::Model &model) {
|
||||
glBindVertexArray(vaoAndEbos.first);
|
||||
|
||||
const tinygltf::Scene &scene = model.scenes[model.defaultScene];
|
||||
for (size_t i = 0; i < scene.nodes.size(); ++i) {
|
||||
drawModelNodes(model, model.nodes[scene.nodes[i]]);
|
||||
drawModelNodes(vaoAndEbos, model, model.nodes[scene.nodes[i]]);
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
@@ -268,7 +293,7 @@ void displayLoop(Window &window, const std::string &filename) {
|
||||
tinygltf::Model model;
|
||||
if (!loadModel(model, filename.c_str())) return;
|
||||
|
||||
GLuint vao = bindModel(model);
|
||||
std::pair<GLuint, std::map<int, GLuint>> vaoAndEbos = bindModel(model);
|
||||
// dbgModel(model); return;
|
||||
|
||||
// Model matrix : an identity matrix (model will be at the origin)
|
||||
@@ -303,10 +328,12 @@ void displayLoop(Window &window, const std::string &filename) {
|
||||
glUniform3fv(sun_position_u, 1, &sun_position[0]);
|
||||
glUniform3fv(sun_color_u, 1, &sun_color[0]);
|
||||
|
||||
drawModel(vao, model);
|
||||
drawModel(vaoAndEbos, model);
|
||||
glfwSwapBuffers(window.window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glDeleteVertexArrays(1, &vaoAndEbos.first);
|
||||
}
|
||||
|
||||
static void error_callback(int error, const char *description) {
|
||||
@@ -315,7 +342,7 @@ static void error_callback(int error, const char *description) {
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::string filename = "../../models/Cube/Cube.gltf";
|
||||
std::string filename = "../../../models/Cube/Cube.gltf";
|
||||
|
||||
if (argc > 1) {
|
||||
filename = argv[1];
|
||||
@@ -327,9 +354,12 @@ int main(int argc, char **argv) {
|
||||
|
||||
// Force create OpenGL 3.3
|
||||
// NOTE(syoyo): Linux + NVIDIA driver segfaults for some reason? commenting out glfwWindowHint will work.
|
||||
// Note (PE): On laptops with intel hd graphics card you can overcome the segfault by enabling experimental, see below (tested on lenovo thinkpad)
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glewExperimental = GL_TRUE;
|
||||
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||
#endif
|
||||
|
||||
5
examples/build-gltf/CMakeLists.txt
Normal file
5
examples/build-gltf/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
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 )
|
||||
2
examples/build-gltf/Makefile
Normal file
2
examples/build-gltf/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
all:
|
||||
$(CXX) -o create_triangle_gltf -I../../ create_triangle_gltf.cpp
|
||||
121
examples/build-gltf/create_triangle_gltf.cpp
Normal file
121
examples/build-gltf/create_triangle_gltf.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
// An example of how to generate a gltf file from scratch. This example
|
||||
// was translated from the pygltlib documentation in the pypi project page,
|
||||
// which in turn is based on the Khronos Sample Models at:
|
||||
//
|
||||
// https://github.com/KhronosGroup/glTF-Sample-Models
|
||||
//
|
||||
// This example is released under the MIT license.
|
||||
//
|
||||
// 2021-02-25 Thu
|
||||
// Dov Grobgeld <dov.grobgeld@gmail.com>
|
||||
|
||||
|
||||
// Define these only in *one* .cc file.
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
// #define TINYGLTF_NOEXCEPTION // optional. disable exception handling.
|
||||
#include "tiny_gltf.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Create a model with a single mesh and save it as a gltf file
|
||||
tinygltf::Model m;
|
||||
tinygltf::Scene scene;
|
||||
tinygltf::Mesh mesh;
|
||||
tinygltf::Primitive primitive;
|
||||
tinygltf::Node node;
|
||||
tinygltf::Buffer buffer;
|
||||
tinygltf::BufferView bufferView1;
|
||||
tinygltf::BufferView bufferView2;
|
||||
tinygltf::Accessor accessor1;
|
||||
tinygltf::Accessor accessor2;
|
||||
tinygltf::Asset asset;
|
||||
|
||||
// This is the raw data buffer.
|
||||
buffer.data = {
|
||||
// 6 bytes of indices and two bytes of padding
|
||||
0x00,0x00,0x01,0x00,0x02,0x00,0x00,0x00,
|
||||
// 36 bytes of floating point numbers
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x3f,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x3f,
|
||||
0x00,0x00,0x00,0x00};
|
||||
|
||||
// "The indices of the vertices (ELEMENT_ARRAY_BUFFER) take up 6 bytes in the
|
||||
// start of the buffer.
|
||||
bufferView1.buffer = 0;
|
||||
bufferView1.byteOffset=0;
|
||||
bufferView1.byteLength=6;
|
||||
bufferView1.target = TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER;
|
||||
|
||||
// The vertices take up 36 bytes (3 vertices * 3 floating points * 4 bytes)
|
||||
// at position 8 in the buffer and are of type ARRAY_BUFFER
|
||||
bufferView2.buffer = 0;
|
||||
bufferView2.byteOffset=8;
|
||||
bufferView2.byteLength=36;
|
||||
bufferView2.target = TINYGLTF_TARGET_ARRAY_BUFFER;
|
||||
|
||||
// Describe the layout of bufferView1, the indices of the vertices
|
||||
accessor1.bufferView = 0;
|
||||
accessor1.byteOffset = 0;
|
||||
accessor1.componentType = TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT;
|
||||
accessor1.count = 3;
|
||||
accessor1.type = TINYGLTF_TYPE_SCALAR;
|
||||
accessor1.maxValues.push_back(2);
|
||||
accessor1.minValues.push_back(0);
|
||||
|
||||
// Describe the layout of bufferView2, the vertices themself
|
||||
accessor2.bufferView = 1;
|
||||
accessor2.byteOffset = 0;
|
||||
accessor2.componentType = TINYGLTF_COMPONENT_TYPE_FLOAT;
|
||||
accessor2.count = 3;
|
||||
accessor2.type = TINYGLTF_TYPE_VEC3;
|
||||
accessor2.maxValues = {1.0, 1.0, 0.0};
|
||||
accessor2.minValues = {0.0, 0.0, 0.0};
|
||||
|
||||
// Build the mesh primitive and add it to the mesh
|
||||
primitive.indices = 0; // The index of the accessor for the vertex indices
|
||||
primitive.attributes["POSITION"] = 1; // The index of the accessor for positions
|
||||
primitive.material = 0;
|
||||
primitive.mode = TINYGLTF_MODE_TRIANGLES;
|
||||
mesh.primitives.push_back(primitive);
|
||||
|
||||
// Other tie ups
|
||||
node.mesh = 0;
|
||||
scene.nodes.push_back(0); // Default scene
|
||||
|
||||
// Define the asset. The version is required
|
||||
asset.version = "2.0";
|
||||
asset.generator = "tinygltf";
|
||||
|
||||
// Now all that remains is to tie back all the loose objects into the
|
||||
// our single model.
|
||||
m.scenes.push_back(scene);
|
||||
m.meshes.push_back(mesh);
|
||||
m.nodes.push_back(node);
|
||||
m.buffers.push_back(buffer);
|
||||
m.bufferViews.push_back(bufferView1);
|
||||
m.bufferViews.push_back(bufferView2);
|
||||
m.accessors.push_back(accessor1);
|
||||
m.accessors.push_back(accessor2);
|
||||
m.asset = asset;
|
||||
|
||||
// Create a simple material
|
||||
tinygltf::Material mat;
|
||||
mat.pbrMetallicRoughness.baseColorFactor = {1.0f, 0.9f, 0.9f, 1.0f};
|
||||
mat.doubleSided = true;
|
||||
m.materials.push_back(mat);
|
||||
|
||||
// Save it to a file
|
||||
tinygltf::TinyGLTF gltf;
|
||||
gltf.WriteGltfSceneToFile(&m, "triangle.gltf",
|
||||
true, // embedImages
|
||||
true, // embedBuffers
|
||||
true, // pretty print
|
||||
false); // write binary
|
||||
|
||||
exit(0);
|
||||
}
|
||||
36
examples/dxview/CMakeLists.txt
Normal file
36
examples/dxview/CMakeLists.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(dxview)
|
||||
|
||||
find_package(glfw3 CONFIG REQUIRED)
|
||||
find_package(spdlog CONFIG REQUIRED)
|
||||
|
||||
add_executable(dxview
|
||||
src/Viewer.h
|
||||
src/Viewer.cc
|
||||
src/dxview.cc
|
||||
)
|
||||
|
||||
target_include_directories(dxview
|
||||
PRIVATE
|
||||
../../
|
||||
)
|
||||
|
||||
target_compile_definitions(dxview
|
||||
PRIVATE
|
||||
DXVIEW_SWAP_CHAIN_BUFFER_COUNT=3
|
||||
DXVIEW_RES_DIR=L"${PROJECT_SOURCE_DIR}/res"
|
||||
)
|
||||
|
||||
target_link_libraries(dxview
|
||||
PRIVATE
|
||||
dxgi
|
||||
d3dcompiler
|
||||
d3d12
|
||||
glfw
|
||||
spdlog::spdlog
|
||||
)
|
||||
|
||||
set_target_properties(dxview
|
||||
PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
)
|
||||
37
examples/dxview/README.md
Normal file
37
examples/dxview/README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# DirectX glTF Viewer
|
||||
|
||||
## Overview
|
||||
|
||||
This project was motivated by a lack of sample code demonstrating the graphics API agnostic nature of the glTF specification. The sample code is written using modern C++ and DirectX 12 for the client application.
|
||||
|
||||
## Features
|
||||
|
||||
* [x] DirectX 12
|
||||
* [ ] Loader
|
||||
* [ ] Animation
|
||||
* [ ] Morph Target
|
||||
* [ ] Physical Base Rendering
|
||||
* [ ] Environment Map
|
||||
|
||||
## Dependencies
|
||||
|
||||
* [CMake](https://github.com/Kitware/CMake)
|
||||
* [Vcpkg](https://github.com/Microsoft/vcpkg)
|
||||
* [GLFW](https://github.com/glfw/glfw)
|
||||
* [spdlog](https://github.com/gabime/spdlog)
|
||||
|
||||
## Building
|
||||
|
||||
### Install dependencies
|
||||
|
||||
```
|
||||
vcpkg install glfw3:x64-windows
|
||||
vcpkg install spdlog:x64-windows
|
||||
```
|
||||
|
||||
### Generate Project Files
|
||||
|
||||
```
|
||||
mkdir build
|
||||
cmake . -B build -DCMAKE_TOOLCHAIN_FILE=${VCPKG_DIR}/script/buildsystem/vcpkg.cmake
|
||||
```
|
||||
3
examples/dxview/res/gray.hlsl
Normal file
3
examples/dxview/res/gray.hlsl
Normal file
@@ -0,0 +1,3 @@
|
||||
float4 main() : SV_Target {
|
||||
return float4(0.5, 0.5, 0.5, 1.0);
|
||||
}
|
||||
52
examples/dxview/res/lighting.hlsl
Normal file
52
examples/dxview/res/lighting.hlsl
Normal file
@@ -0,0 +1,52 @@
|
||||
struct RS2PS {
|
||||
float4 position : SV_POSITION;
|
||||
|
||||
#ifdef HAS_TEXCOORD_0
|
||||
float2 texcoord_0: TEXCOORD_0;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct TextureInfo {
|
||||
uint textureIndex;
|
||||
uint samplerIndex;
|
||||
};
|
||||
|
||||
struct PBRMetallicRoughness {
|
||||
float4 baseColorFactor;
|
||||
TextureInfo baseColorTexture;
|
||||
float metallicFactor;
|
||||
float roughnessFactor;
|
||||
TextureInfo metallicRoughnessTexture;
|
||||
};
|
||||
|
||||
cbuffer Material : register(b2) {
|
||||
PBRMetallicRoughness pbrMetallicRoughness;
|
||||
};
|
||||
|
||||
Texture2D textures[5] : register(t0);
|
||||
SamplerState samplerState[5] : register(s0);
|
||||
|
||||
float4 getBaseColor(float2 uv) {
|
||||
float4 baseColor = pbrMetallicRoughness.baseColorFactor;
|
||||
|
||||
#ifdef HAS_TEXCOORD_0
|
||||
TextureInfo baseColorTexture = pbrMetallicRoughness.baseColorTexture;
|
||||
if (baseColorTexture.textureIndex >= 0) {
|
||||
baseColor *= textures[baseColorTexture.textureIndex].Sample(samplerState[baseColorTexture.samplerIndex], uv);
|
||||
}
|
||||
#endif
|
||||
|
||||
return baseColor;
|
||||
}
|
||||
|
||||
float4 main(RS2PS input) : SV_Target {
|
||||
float2 uv = float2(0.0, 0.0);
|
||||
|
||||
#ifdef HAS_TEXCOORD_0
|
||||
uv = input.texcoord_0;
|
||||
#endif
|
||||
|
||||
float4 color = getBaseColor(uv);
|
||||
|
||||
return color;
|
||||
}
|
||||
46
examples/dxview/res/primitive.hlsl
Normal file
46
examples/dxview/res/primitive.hlsl
Normal file
@@ -0,0 +1,46 @@
|
||||
struct IA2VS {
|
||||
float3 position : POSITION;
|
||||
|
||||
#ifdef HAS_NORMAL
|
||||
float3 normal : NORMAL;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_TANGENT
|
||||
float4 tangent : TANGENT;
|
||||
#endif
|
||||
|
||||
#ifdef HAS_TEXCOORD_0
|
||||
float2 texcoord_0: TEXCOORD_0;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct VS2RS {
|
||||
float4 position : SV_POSITION;
|
||||
|
||||
#ifdef HAS_TEXCOORD_0
|
||||
float2 texcoord_0: TEXCOORD_0;
|
||||
#endif
|
||||
};
|
||||
|
||||
cbuffer Camera : register(b0) {
|
||||
float4x4 V;
|
||||
float4x4 P;
|
||||
float4x4 VP;
|
||||
};
|
||||
|
||||
cbuffer Node : register(b1) {
|
||||
float4x4 M;
|
||||
};
|
||||
|
||||
VS2RS main(IA2VS input) {
|
||||
VS2RS output;
|
||||
output.position = mul(float4(input.position, 1.0), M);
|
||||
output.position = mul(output.position, V);
|
||||
output.position = mul(output.position, P);
|
||||
|
||||
#ifdef HAS_TEXCOORD_0
|
||||
output.texcoord_0 = input.texcoord_0;
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
1292
examples/dxview/src/Viewer.cc
Normal file
1292
examples/dxview/src/Viewer.cc
Normal file
File diff suppressed because it is too large
Load Diff
130
examples/dxview/src/Viewer.h
Normal file
130
examples/dxview/src/Viewer.h
Normal file
@@ -0,0 +1,130 @@
|
||||
#ifndef DXVIEW_VIEWER_GUARD
|
||||
#define DXVIEW_VIEWER_GUARD
|
||||
|
||||
#include <DirectXMath.h>
|
||||
#include <d3d12.h>
|
||||
#include <dxgi1_6.h>
|
||||
#include <tiny_gltf.h>
|
||||
#include <wrl.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
enum RenderPassType { RENDER_PASS_TYPE_PRESENT = 0, RENDER_PASS_TYPE_COUNT };
|
||||
|
||||
struct RenderTarget {
|
||||
ComPtr<ID3D12Resource> pTexture;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE viewDescriptor;
|
||||
};
|
||||
|
||||
struct TextureInfo {
|
||||
int32_t textureIndex;
|
||||
int32_t samplerIndex;
|
||||
};
|
||||
|
||||
struct PBRMetallicRoughness {
|
||||
DirectX::XMFLOAT4 baseColorFactor;
|
||||
TextureInfo baseColorTexture;
|
||||
float metallicFactor;
|
||||
float roughnessFactor;
|
||||
TextureInfo metallicRoughnessTexture;
|
||||
};
|
||||
|
||||
struct Material {
|
||||
std::string name;
|
||||
D3D12_BLEND_DESC blendDesc;
|
||||
D3D12_RASTERIZER_DESC rasterizerDesc;
|
||||
ComPtr<ID3D12Resource> pBuffer;
|
||||
void* pBufferData;
|
||||
ComPtr<ID3D12DescriptorHeap> pSRVDescriptorHeap;
|
||||
ComPtr<ID3D12DescriptorHeap> pSamplerDescriptorHeap;
|
||||
};
|
||||
|
||||
struct Attribute {
|
||||
std::string name;
|
||||
DXGI_FORMAT format;
|
||||
D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
|
||||
};
|
||||
|
||||
struct Primitive {
|
||||
std::vector<Attribute> attributes;
|
||||
uint32_t vertexCount;
|
||||
D3D12_PRIMITIVE_TOPOLOGY primitiveTopology;
|
||||
D3D12_INDEX_BUFFER_VIEW indexBufferView;
|
||||
uint32_t indexCount;
|
||||
Material* pMaterial;
|
||||
ComPtr<ID3D12RootSignature> pRootSignature;
|
||||
ComPtr<ID3D12PipelineState> pPipelineState;
|
||||
};
|
||||
|
||||
struct Mesh {
|
||||
std::string name;
|
||||
std::vector<Primitive> primitives;
|
||||
};
|
||||
|
||||
struct Node {
|
||||
DirectX::XMFLOAT4X4 M;
|
||||
};
|
||||
|
||||
struct Camera {
|
||||
DirectX::XMFLOAT4X4 V;
|
||||
DirectX::XMFLOAT4X4 P;
|
||||
DirectX::XMFLOAT4X4 VP;
|
||||
};
|
||||
|
||||
class Viewer {
|
||||
public:
|
||||
Viewer(HWND window, tinygltf::Model* pModel);
|
||||
|
||||
void update(double deltaTime);
|
||||
void render(double deltaTime);
|
||||
|
||||
private:
|
||||
void initDirectX(HWND window);
|
||||
void buildRenderTargets();
|
||||
void buildResources();
|
||||
void buildBuffers(std::vector<ComPtr<ID3D12Resource> >* pStagingResources);
|
||||
void buildImages(std::vector<ComPtr<ID3D12Resource> >* pStagingResources);
|
||||
void buildSamplerDescs();
|
||||
void buildMaterials();
|
||||
void buildMeshes();
|
||||
void buildNodes();
|
||||
|
||||
void drawNode(uint64_t nodeIndex);
|
||||
|
||||
private:
|
||||
tinygltf::Model* pModel_;
|
||||
ComPtr<IDXGIFactory1> pFactory_;
|
||||
ComPtr<IDXGIAdapter1> pAdapter_;
|
||||
ComPtr<ID3D12Device> pDevice_;
|
||||
ComPtr<ID3D12CommandQueue> pDirectCommandQueue_;
|
||||
UINT64 directFenceValue_;
|
||||
ComPtr<ID3D12Fence> pDirectFence_;
|
||||
ComPtr<ID3D12CommandQueue> pCopyCommandQueue_;
|
||||
UINT64 copyFenceValue_;
|
||||
ComPtr<ID3D12Fence> pCopyFence_;
|
||||
ComPtr<IDXGISwapChain3> pSwapChain_;
|
||||
ComPtr<ID3D12Resource> pSwapChainBuffers_[DXVIEW_SWAP_CHAIN_BUFFER_COUNT];
|
||||
ComPtr<ID3D12CommandAllocator>
|
||||
pDirectCommandAllocators_[DXVIEW_SWAP_CHAIN_BUFFER_COUNT];
|
||||
ComPtr<ID3D12GraphicsCommandList> pDirectCommandList_;
|
||||
ComPtr<ID3D12CommandAllocator> pCopyCommandAllocator_;
|
||||
ComPtr<ID3D12GraphicsCommandList> pCopyCommandList_;
|
||||
UINT descriptorIncrementSize_[D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES];
|
||||
ComPtr<ID3D12DescriptorHeap>
|
||||
pRTVDescriptorHeaps_[DXVIEW_SWAP_CHAIN_BUFFER_COUNT];
|
||||
std::vector<RenderTarget> renderTargets_[DXVIEW_SWAP_CHAIN_BUFFER_COUNT];
|
||||
std::vector<ComPtr<ID3D12Resource> > pBuffers_;
|
||||
std::vector<ComPtr<ID3D12Resource> > pTextures_;
|
||||
std::vector<D3D12_SAMPLER_DESC> samplerDescs_;
|
||||
std::vector<Material> materials_;
|
||||
std::vector<Mesh> meshes_;
|
||||
std::vector<ComPtr<ID3D12Resource> > pNodeBuffers_;
|
||||
ComPtr<ID3D12Resource> pCameraBuffer_;
|
||||
};
|
||||
|
||||
#endif
|
||||
90
examples/dxview/src/dxview.cc
Normal file
90
examples/dxview/src/dxview.cc
Normal file
@@ -0,0 +1,90 @@
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define STBI_MSC_SECURE_CRT
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GLFW/glfw3native.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <tiny_gltf.h>
|
||||
|
||||
#undef GLFW_EXPOSE_NATIVE_WIN32
|
||||
#undef TINYGLTF_IMPLEMENTATION
|
||||
#undef STBI_MSC_SECURE_CRT
|
||||
#undef STB_IMAGE_IMPLEMENTATION
|
||||
#undef STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "Viewer.h"
|
||||
|
||||
static void onError(int error, const char* message) {
|
||||
spdlog::error("[{}] {}", error, message);
|
||||
}
|
||||
|
||||
static void onRender(Viewer* pViewer, double deltaTime) {
|
||||
pViewer->update(deltaTime);
|
||||
pViewer->render(deltaTime);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
tinygltf::TinyGLTF context;
|
||||
|
||||
tinygltf::Model model;
|
||||
std::string error;
|
||||
std::string warning;
|
||||
if (!context.LoadASCIIFromFile(&model, &error, &warning, argv[1])) {
|
||||
if (!error.empty()) {
|
||||
spdlog::error("{}", error);
|
||||
}
|
||||
|
||||
if (!warning.empty()) {
|
||||
spdlog::warn("{}", warning);
|
||||
}
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
GLFWwindow* pWindow;
|
||||
|
||||
glfwSetErrorCallback(onError);
|
||||
|
||||
if (!glfwInit()) {
|
||||
spdlog::error("Fail to initialize GLFW!!!");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
|
||||
pWindow = glfwCreateWindow(512, 512, "dxview", nullptr, nullptr);
|
||||
if (!pWindow) {
|
||||
spdlog::error("Fail to create GLFWwindow!!!");
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
auto pViewer = std::make_unique<Viewer>(glfwGetWin32Window(pWindow), &model);
|
||||
if (!pViewer) {
|
||||
spdlog::error("Fail to create Viewer");
|
||||
glfwDestroyWindow(pWindow);
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
auto prevTimeStamp = glfwGetTime();
|
||||
while (!glfwWindowShouldClose(pWindow)) {
|
||||
auto currTimeStamp = glfwGetTime();
|
||||
|
||||
onRender(pViewer.get(), currTimeStamp - prevTimeStamp);
|
||||
prevTimeStamp = currTimeStamp;
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwDestroyWindow(pWindow);
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ if (DEFINED DRACO_DIR)
|
||||
# TODO(syoyo): better CMake script for draco
|
||||
add_definitions(-DTINYGLTF_ENABLE_DRACO)
|
||||
include_directories(${DRACO_DIR}/include)
|
||||
|
||||
|
||||
link_directories(${DRACO_DIR}/lib)
|
||||
set(DRACO_LIBRARY draco)
|
||||
endif ()
|
||||
@@ -49,9 +49,9 @@ add_executable(glview
|
||||
)
|
||||
|
||||
target_link_libraries ( glview
|
||||
${DRACO_LIBRARY}
|
||||
${DRACO_LIBRARY}
|
||||
${GLFW3_UNIX_LINK_LIBRARIES}
|
||||
${GLEW_LIBRARY}
|
||||
${GLEW_LIBRARIES}
|
||||
${GLFW3_glfw_LIBRARY}
|
||||
${OPENGL_gl_LIBRARY}
|
||||
${OPENGL_glu_LIBRARY}
|
||||
|
||||
@@ -771,6 +771,32 @@ static void DrawCurves(tinygltf::Scene &scene, const tinygltf::Mesh &mesh) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void QuatToAngleAxis(const std::vector<double> quaternion,
|
||||
double &outAngleDegrees,
|
||||
double *axis) {
|
||||
double qx = quaternion[0];
|
||||
double qy = quaternion[1];
|
||||
double qz = quaternion[2];
|
||||
double qw = quaternion[3];
|
||||
|
||||
double angleRadians = 2 * acos(qw);
|
||||
if (angleRadians == 0.0) {
|
||||
outAngleDegrees = 0.0;
|
||||
axis[0] = 0.0;
|
||||
axis[1] = 0.0;
|
||||
axis[2] = 1.0;
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr double pi = 3.14159265358979323846;
|
||||
|
||||
double denom = sqrt(1-qw*qw);
|
||||
outAngleDegrees = angleRadians * 180.0 / pi;
|
||||
axis[0] = qx / denom;
|
||||
axis[1] = qy / denom;
|
||||
axis[2] = qz / denom;
|
||||
}
|
||||
|
||||
// Hierarchically draw nodes
|
||||
static void DrawNode(tinygltf::Model &model, const tinygltf::Node &node) {
|
||||
// Apply xform
|
||||
@@ -781,18 +807,22 @@ static void DrawNode(tinygltf::Model &model, const tinygltf::Node &node) {
|
||||
glMultMatrixd(node.matrix.data());
|
||||
} else {
|
||||
// Assume Trans x Rotate x Scale order
|
||||
if (node.scale.size() == 3) {
|
||||
glScaled(node.scale[0], node.scale[1], node.scale[2]);
|
||||
}
|
||||
|
||||
if (node.rotation.size() == 4) {
|
||||
glRotated(node.rotation[0], node.rotation[1], node.rotation[2],
|
||||
node.rotation[3]);
|
||||
}
|
||||
|
||||
if (node.translation.size() == 3) {
|
||||
glTranslated(node.translation[0], node.translation[1],
|
||||
node.translation[2]);
|
||||
}
|
||||
|
||||
if (node.rotation.size() == 4) {
|
||||
double angleDegrees;
|
||||
double axis[3];
|
||||
|
||||
QuatToAngleAxis(node.rotation, angleDegrees, axis);
|
||||
|
||||
glRotated(angleDegrees, axis[0], axis[1], axis[2]);
|
||||
}
|
||||
|
||||
if (node.scale.size() == 3) {
|
||||
glScaled(node.scale[0], node.scale[1], node.scale[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -524,7 +524,7 @@ static void Dump(const tinygltf::Model &model) {
|
||||
<< std::endl;
|
||||
|
||||
std::cout << Indent(1) << "channels : [ " << std::endl;
|
||||
for (size_t j = 0; i < animation.channels.size(); i++) {
|
||||
for (size_t j = 0; j < animation.channels.size(); j++) {
|
||||
std::cout << Indent(2)
|
||||
<< "sampler : " << animation.channels[j].sampler
|
||||
<< std::endl;
|
||||
|
||||
BIN
models/CubeImageUriSpaces/ 2x2 image has multiple spaces.png
Normal file
BIN
models/CubeImageUriSpaces/ 2x2 image has multiple spaces.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 79 B |
BIN
models/CubeImageUriSpaces/2x2 image has spaces.png
Normal file
BIN
models/CubeImageUriSpaces/2x2 image has spaces.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 79 B |
171
models/CubeImageUriSpaces/CubeImageUriMultipleSpaces.gltf
Normal file
171
models/CubeImageUriSpaces/CubeImageUriMultipleSpaces.gltf
Normal file
@@ -0,0 +1,171 @@
|
||||
{
|
||||
"asset": {
|
||||
"version": "2.0"
|
||||
},
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"scene": 0,
|
||||
"nodes": [
|
||||
{
|
||||
"mesh": 0
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"NORMAL": 2,
|
||||
"POSITION": 1,
|
||||
"TEXCOORD_0": 3
|
||||
},
|
||||
"indices": 0,
|
||||
"mode": 4,
|
||||
"material": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorTexture": {
|
||||
"index": 0,
|
||||
"texCoord": 0
|
||||
},
|
||||
"baseColorFactor": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"metallicFactor": 1,
|
||||
"roughnessFactor": 1
|
||||
},
|
||||
"emissiveFactor": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"alphaMode": "OPAQUE"
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
{
|
||||
"source": 0,
|
||||
"sampler": 0
|
||||
}
|
||||
],
|
||||
"samplers": [
|
||||
{
|
||||
"wrapS": 33071,
|
||||
"wrapT": 33071
|
||||
}
|
||||
],
|
||||
"images": [
|
||||
{
|
||||
"uri": " 2x2 image has multiple spaces.png"
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5121,
|
||||
"count": 36,
|
||||
"normalized": false,
|
||||
"max": [
|
||||
23
|
||||
],
|
||||
"min": [
|
||||
0
|
||||
],
|
||||
"type": "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"normalized": false,
|
||||
"max": [
|
||||
0.5,
|
||||
0.5,
|
||||
0.5
|
||||
],
|
||||
"min": [
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 2,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"normalized": false,
|
||||
"max": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"min": [
|
||||
-1,
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 3,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"normalized": false,
|
||||
"max": [
|
||||
1,
|
||||
1
|
||||
],
|
||||
"min": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"type": "VEC2"
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 36
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 36,
|
||||
"byteLength": 288
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 324,
|
||||
"byteLength": 288
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 612,
|
||||
"byteLength": 192
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"byteLength": 804,
|
||||
"uri": "CubeImageUriSpaces.bin"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
models/CubeImageUriSpaces/CubeImageUriSpaces.bin
Normal file
BIN
models/CubeImageUriSpaces/CubeImageUriSpaces.bin
Normal file
Binary file not shown.
171
models/CubeImageUriSpaces/CubeImageUriSpaces.gltf
Normal file
171
models/CubeImageUriSpaces/CubeImageUriSpaces.gltf
Normal file
@@ -0,0 +1,171 @@
|
||||
{
|
||||
"asset": {
|
||||
"version": "2.0"
|
||||
},
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"scene": 0,
|
||||
"nodes": [
|
||||
{
|
||||
"mesh": 0
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"NORMAL": 2,
|
||||
"POSITION": 1,
|
||||
"TEXCOORD_0": 3
|
||||
},
|
||||
"indices": 0,
|
||||
"mode": 4,
|
||||
"material": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorTexture": {
|
||||
"index": 0,
|
||||
"texCoord": 0
|
||||
},
|
||||
"baseColorFactor": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"metallicFactor": 1,
|
||||
"roughnessFactor": 1
|
||||
},
|
||||
"emissiveFactor": [
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"alphaMode": "OPAQUE"
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
{
|
||||
"source": 0,
|
||||
"sampler": 0
|
||||
}
|
||||
],
|
||||
"samplers": [
|
||||
{
|
||||
"wrapS": 33071,
|
||||
"wrapT": 33071
|
||||
}
|
||||
],
|
||||
"images": [
|
||||
{
|
||||
"uri": "2x2 image has spaces.png"
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5121,
|
||||
"count": 36,
|
||||
"normalized": false,
|
||||
"max": [
|
||||
23
|
||||
],
|
||||
"min": [
|
||||
0
|
||||
],
|
||||
"type": "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"normalized": false,
|
||||
"max": [
|
||||
0.5,
|
||||
0.5,
|
||||
0.5
|
||||
],
|
||||
"min": [
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 2,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"normalized": false,
|
||||
"max": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"min": [
|
||||
-1,
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 3,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 24,
|
||||
"normalized": false,
|
||||
"max": [
|
||||
1,
|
||||
1
|
||||
],
|
||||
"min": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"type": "VEC2"
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 36
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 36,
|
||||
"byteLength": 288
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 324,
|
||||
"byteLength": 288
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 612,
|
||||
"byteLength": 192
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"byteLength": 804,
|
||||
"uri": "CubeImageUriSpaces.bin"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
models/Extensions-overwrite-issue261/issue-261.bin
Normal file
BIN
models/Extensions-overwrite-issue261/issue-261.bin
Normal file
Binary file not shown.
376
models/Extensions-overwrite-issue261/issue-261.gltf
Normal file
376
models/Extensions-overwrite-issue261/issue-261.gltf
Normal file
@@ -0,0 +1,376 @@
|
||||
{
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"componentType": 5126,
|
||||
"count": 8,
|
||||
"max": [
|
||||
0.5,
|
||||
0.5,
|
||||
0.5
|
||||
],
|
||||
"min": [
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"componentType": 5125,
|
||||
"count": 36,
|
||||
"type": "SCALAR"
|
||||
}
|
||||
],
|
||||
"asset": {
|
||||
"copyright": "NVIDIA Corporation",
|
||||
"generator": "Iray glTF plugin",
|
||||
"version": "2.0"
|
||||
},
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 96,
|
||||
"byteStride": 12
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 144,
|
||||
"byteOffset": 96
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"byteLength": 240,
|
||||
"uri": "issue-261.bin"
|
||||
}
|
||||
],
|
||||
"cameras": [
|
||||
{
|
||||
"extensions": {
|
||||
"NV_Iray": {
|
||||
"mip_burn_highlights": 0.699999988079071,
|
||||
"mip_burn_highlights_per_component": false,
|
||||
"mip_camera_shutter": 4.0,
|
||||
"mip_cm2_factor": 1.0,
|
||||
"mip_crush_blacks": 0.5,
|
||||
"mip_f_number": 1.0,
|
||||
"mip_film_iso": 100.0,
|
||||
"mip_gamma": 2.200000047683716,
|
||||
"mip_saturation": 1.0,
|
||||
"mip_vignetting": 0.00019999999494757503,
|
||||
"mip_whitepoint": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"tm_enable_tonemapper": true,
|
||||
"tm_tonemapper": "mia_exposure_photographic"
|
||||
}
|
||||
},
|
||||
"extras": {
|
||||
"resolution": [
|
||||
640,
|
||||
480
|
||||
]
|
||||
},
|
||||
"name": "default",
|
||||
"perspective": {
|
||||
"aspectRatio": 1.3333333730697632,
|
||||
"yfov": 0.9272952079772949,
|
||||
"zfar": 1000.0,
|
||||
"znear": 0.1
|
||||
},
|
||||
"type": "perspective"
|
||||
}
|
||||
],
|
||||
"extensions": {
|
||||
"KHR_lights_punctual": {
|
||||
"lights": [
|
||||
{
|
||||
"color": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
],
|
||||
"intensity": 1000.0,
|
||||
"name": "light",
|
||||
"type": "point"
|
||||
}
|
||||
]
|
||||
},
|
||||
"NV_MDL": {
|
||||
"modules": [
|
||||
"mdl::base",
|
||||
"mdl::nvidia::core_definitions",
|
||||
"mdl::state"
|
||||
],
|
||||
"shaders": [
|
||||
{
|
||||
"definition": "mdl::base::environment_spherical(texture_2d)",
|
||||
"name": "env_shd"
|
||||
},
|
||||
{
|
||||
"arguments": {
|
||||
"base_color": [
|
||||
0.0055217444896698,
|
||||
0.36859095096588135,
|
||||
0.0041161770932376385
|
||||
],
|
||||
"normal=": 2
|
||||
},
|
||||
"definition": "mdl::nvidia::core_definitions::flex_material",
|
||||
"name": "cube_instance_material"
|
||||
},
|
||||
{
|
||||
"definition": "mdl::state::normal()",
|
||||
"name": "mdl::state::normal_341"
|
||||
},
|
||||
{
|
||||
"arguments": {
|
||||
"base_color": [
|
||||
0.0055217444896698,
|
||||
0.36859095096588135,
|
||||
0.0041161770932376385
|
||||
],
|
||||
"normal=": 4
|
||||
},
|
||||
"definition": "mdl::nvidia::core_definitions::flex_material",
|
||||
"name": "cube_instance_material"
|
||||
},
|
||||
{
|
||||
"definition": "mdl::state::normal()",
|
||||
"name": "mdl::state::normal_341"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"extensionsUsed": [
|
||||
"NV_MDL",
|
||||
"NV_Iray",
|
||||
"KHR_lights_punctual"
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"doubleSided": true,
|
||||
"extras": {
|
||||
"mdl_shader": 1
|
||||
},
|
||||
"name": "cube_instance_material",
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorFactor": [
|
||||
0.0055217444896698,
|
||||
0.36859095096588135,
|
||||
0.0041161770932376385,
|
||||
1.0
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"name": "cube",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 0
|
||||
},
|
||||
"indices": 1,
|
||||
"material": 0,
|
||||
"mode": 4
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"camera": 0,
|
||||
"extensions": {
|
||||
"NV_Iray": {
|
||||
"iview:fkey": -1,
|
||||
"iview:fov": 53.130104064941406,
|
||||
"iview:interest": [
|
||||
0.1342654824256897,
|
||||
-0.14356137812137604,
|
||||
0.037264324724674225
|
||||
],
|
||||
"iview:position": [
|
||||
0.9729073643684387,
|
||||
1.2592438459396362,
|
||||
2.4199187755584717
|
||||
],
|
||||
"iview:roll": 0.0,
|
||||
"iview:up": [
|
||||
0.0,
|
||||
1.0,
|
||||
0.0
|
||||
]
|
||||
}
|
||||
},
|
||||
"matrix": [
|
||||
0.9432751389105357,
|
||||
-1.1769874756875739e-16,
|
||||
-0.3320120665176343,
|
||||
0.0,
|
||||
-0.16119596696756341,
|
||||
0.8742297945345237,
|
||||
-0.45797175303889276,
|
||||
0.0,
|
||||
0.290254840694694,
|
||||
0.48551237507207207,
|
||||
0.8246392308792816,
|
||||
0.0,
|
||||
0.9729073377709113,
|
||||
1.2592438262175363,
|
||||
2.419918748461627,
|
||||
1.0
|
||||
],
|
||||
"name": "CamInst"
|
||||
},
|
||||
{
|
||||
"extensions": {
|
||||
"NV_Iray": {
|
||||
"caustic": true,
|
||||
"caustic_cast": true,
|
||||
"caustic_recv": true,
|
||||
"face_back": true,
|
||||
"face_front": true,
|
||||
"finalgather": true,
|
||||
"finalgather_cast": true,
|
||||
"finalgather_recv": true,
|
||||
"globillum": true,
|
||||
"globillum_cast": true,
|
||||
"globillum_recv": true,
|
||||
"material=": 3,
|
||||
"pickable": true,
|
||||
"reflection_cast": true,
|
||||
"reflection_recv": true,
|
||||
"refraction_cast": true,
|
||||
"refraction_recv": true,
|
||||
"shadow_cast": true,
|
||||
"shadow_recv": true,
|
||||
"transparency_cast": true,
|
||||
"transparency_recv": true,
|
||||
"visible": true
|
||||
}
|
||||
},
|
||||
"mesh": 0,
|
||||
"name": "cube_instance"
|
||||
},
|
||||
{
|
||||
"extensions": {
|
||||
"KHR_lights_punctual": {
|
||||
"light": 0
|
||||
},
|
||||
"NV_Iray": {
|
||||
"shadow_cast": true,
|
||||
"visible": false
|
||||
}
|
||||
},
|
||||
"matrix": [
|
||||
0.6988062355563571,
|
||||
-7.76042172309776e-17,
|
||||
-0.7153110128800992,
|
||||
-0.0,
|
||||
-0.4276881690736487,
|
||||
0.8015668284138362,
|
||||
-0.41781987700564616,
|
||||
-0.0,
|
||||
0.57336957992379,
|
||||
0.5979051928078428,
|
||||
0.5601398979107212,
|
||||
0.0,
|
||||
2.3640632834071384,
|
||||
2.465226204472449,
|
||||
2.309515908392224,
|
||||
1.0
|
||||
],
|
||||
"name": "light_inst"
|
||||
}
|
||||
],
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"extensions": {
|
||||
"NV_Iray": {
|
||||
"CP_canny_threshold1": 40,
|
||||
"CP_canny_threshold2": 120,
|
||||
"CP_color_quantization": 8,
|
||||
"IVP_color": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"TM_drago_bias": 0.8500000238418579,
|
||||
"TM_drago_gamma2": 2.200000047683716,
|
||||
"TM_drago_saturation": 1.0,
|
||||
"TM_durand_contrast": 4.0,
|
||||
"TM_durand_gamma": 2.200000047683716,
|
||||
"TM_durand_saturation": 1.0,
|
||||
"TM_durand_sigma_color": 2.0,
|
||||
"TM_durand_sigma_space": 2.0,
|
||||
"TM_linear_gamma": 2.200000047683716,
|
||||
"TM_reinhard_color_adapt": 0.8999999761581421,
|
||||
"TM_reinhard_gamma": 1.0,
|
||||
"TM_reinhard_intensity": 0.0,
|
||||
"TM_reinhard_light_adapt": 1.0,
|
||||
"TM_reye_Ywhite": 1000000.0,
|
||||
"TM_reye_bsize": 2,
|
||||
"TM_reye_bthres": 3.0,
|
||||
"TM_reye_gamma": 2.200000047683716,
|
||||
"TM_reye_key": 0.5,
|
||||
"TM_reye_saturation": 1.0,
|
||||
"TM_reye_whitebalance": [
|
||||
1.0,
|
||||
0.9965101480484009,
|
||||
0.9805564880371094,
|
||||
0.0
|
||||
],
|
||||
"environment_dome_depth": 200.0,
|
||||
"environment_dome_height": 200.0,
|
||||
"environment_dome_mode": "infinite",
|
||||
"environment_dome_position": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"environment_dome_radius": 100.0,
|
||||
"environment_dome_rotation_angle": 0.0,
|
||||
"environment_dome_width": 200.0,
|
||||
"environment_function=": 0,
|
||||
"environment_function_intensity": 1.9900000095367432,
|
||||
"iray_instancing": "off",
|
||||
"iview::inline_color": [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"iview::inline_width": 1.0,
|
||||
"iview::magnifier_size": 300,
|
||||
"iview::offset": 10.0,
|
||||
"iview::outline_color": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"iview::outline_width": 2.0,
|
||||
"iview::overview": true,
|
||||
"iview::zoom_factor": 1.0,
|
||||
"samples": 4.0,
|
||||
"shadow_cast": true,
|
||||
"shadow_recv": true
|
||||
}
|
||||
},
|
||||
"nodes": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Binary file not shown.
267
models/regression/unassigned-skeleton.gltf
Normal file
267
models/regression/unassigned-skeleton.gltf
Normal file
File diff suppressed because one or more lines are too long
BIN
models/regression/zero-sized-bin-chunk-issue-440.glb
Normal file
BIN
models/regression/zero-sized-bin-chunk-issue-440.glb
Normal file
Binary file not shown.
925
stb_image.h
925
stb_image.h
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
/* stb_image_write - v1.11 - public domain - http://nothings.org/stb/stb_image_write.h
|
||||
/* stb_image_write - v1.16 - public domain - http://nothings.org/stb
|
||||
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
|
||||
no warranty implied; use at your own risk
|
||||
|
||||
@@ -10,11 +10,6 @@
|
||||
|
||||
Will probably not work correctly with strict-aliasing optimizations.
|
||||
|
||||
If using a modern Microsoft Compiler, non-safe versions of CRT calls may cause
|
||||
compilation warnings or even errors. To avoid this, also before #including,
|
||||
|
||||
#define STBI_MSC_SECURE_CRT
|
||||
|
||||
ABOUT:
|
||||
|
||||
This header file is a library for writing images to C stdio or a callback.
|
||||
@@ -110,7 +105,7 @@ USAGE:
|
||||
|
||||
TGA supports RLE or non-RLE compressed data. To use non-RLE-compressed
|
||||
data, set the global variable 'stbi_write_tga_with_rle' to 0.
|
||||
|
||||
|
||||
JPEG does ignore alpha channels in input data; quality is between 1 and 100.
|
||||
Higher quality looks better but results in a bigger image.
|
||||
JPEG baseline (no JPEG progressive).
|
||||
@@ -118,7 +113,7 @@ USAGE:
|
||||
CREDITS:
|
||||
|
||||
|
||||
Sean Barrett - PNG/BMP/TGA
|
||||
Sean Barrett - PNG/BMP/TGA
|
||||
Baldur Karlsson - HDR
|
||||
Jean-Sebastien Guay - TGA monochrome
|
||||
Tim Kelsey - misc enhancements
|
||||
@@ -145,6 +140,7 @@ CREDITS:
|
||||
Ivan Tikhonov
|
||||
github:ignotion
|
||||
Adam Schackart
|
||||
Andrew Kensler
|
||||
|
||||
LICENSE
|
||||
|
||||
@@ -171,9 +167,9 @@ LICENSE
|
||||
#endif
|
||||
|
||||
#ifndef STB_IMAGE_WRITE_STATIC // C++ forbids static forward declarations
|
||||
extern int stbi_write_tga_with_rle;
|
||||
extern int stbi_write_png_compression_level;
|
||||
extern int stbi_write_force_png_filter;
|
||||
STBIWDEF int stbi_write_tga_with_rle;
|
||||
STBIWDEF int stbi_write_png_compression_level;
|
||||
STBIWDEF int stbi_write_force_png_filter;
|
||||
#endif
|
||||
|
||||
#ifndef STBI_WRITE_NO_STDIO
|
||||
@@ -183,7 +179,7 @@ STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const
|
||||
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
|
||||
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
|
||||
|
||||
#ifdef STBI_WINDOWS_UTF8
|
||||
#ifdef STBIW_WINDOWS_UTF8
|
||||
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
|
||||
#endif
|
||||
#endif
|
||||
@@ -252,17 +248,17 @@ STBIWDEF void stbi_flip_vertically_on_write(int flip_boolean);
|
||||
#define STBIW_UCHAR(x) (unsigned char) ((x) & 0xff)
|
||||
|
||||
#ifdef STB_IMAGE_WRITE_STATIC
|
||||
static int stbi__flip_vertically_on_write=0;
|
||||
static int stbi_write_png_compression_level = 8;
|
||||
static int stbi_write_tga_with_rle = 1;
|
||||
static int stbi_write_force_png_filter = -1;
|
||||
#else
|
||||
int stbi_write_png_compression_level = 8;
|
||||
int stbi__flip_vertically_on_write=0;
|
||||
int stbi_write_tga_with_rle = 1;
|
||||
int stbi_write_force_png_filter = -1;
|
||||
#endif
|
||||
|
||||
static int stbi__flip_vertically_on_write = 0;
|
||||
|
||||
STBIWDEF void stbi_flip_vertically_on_write(int flag)
|
||||
{
|
||||
stbi__flip_vertically_on_write = flag;
|
||||
@@ -272,6 +268,8 @@ typedef struct
|
||||
{
|
||||
stbi_write_func *func;
|
||||
void *context;
|
||||
unsigned char buffer[64];
|
||||
int buf_used;
|
||||
} stbi__write_context;
|
||||
|
||||
// initialize a callback-based context
|
||||
@@ -288,7 +286,7 @@ static void stbi__stdio_write(void *context, void *data, int size)
|
||||
fwrite(data,1,size,(FILE*) context);
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||
#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8)
|
||||
#ifdef __cplusplus
|
||||
#define STBIW_EXTERN extern "C"
|
||||
#else
|
||||
@@ -299,25 +297,25 @@ STBIW_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned in
|
||||
|
||||
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input)
|
||||
{
|
||||
return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, bufferlen, NULL, NULL);
|
||||
return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
static FILE *stbiw__fopen(char const *filename, char const *mode)
|
||||
{
|
||||
FILE *f;
|
||||
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||
#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8)
|
||||
wchar_t wMode[64];
|
||||
wchar_t wFilename[1024];
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)))
|
||||
return 0;
|
||||
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)))
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)/sizeof(*wFilename)))
|
||||
return 0;
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
if (0 != _wfopen_s(&f, wFilename, wMode))
|
||||
f = 0;
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)/sizeof(*wMode)))
|
||||
return 0;
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
if (0 != _wfopen_s(&f, wFilename, wMode))
|
||||
f = 0;
|
||||
#else
|
||||
f = _wfopen(wFilename, wMode);
|
||||
#endif
|
||||
@@ -385,16 +383,36 @@ static void stbiw__writef(stbi__write_context *s, const char *fmt, ...)
|
||||
va_end(v);
|
||||
}
|
||||
|
||||
static void stbiw__write_flush(stbi__write_context *s)
|
||||
{
|
||||
if (s->buf_used) {
|
||||
s->func(s->context, &s->buffer, s->buf_used);
|
||||
s->buf_used = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void stbiw__putc(stbi__write_context *s, unsigned char c)
|
||||
{
|
||||
s->func(s->context, &c, 1);
|
||||
}
|
||||
|
||||
static void stbiw__write1(stbi__write_context *s, unsigned char a)
|
||||
{
|
||||
if ((size_t)s->buf_used + 1 > sizeof(s->buffer))
|
||||
stbiw__write_flush(s);
|
||||
s->buffer[s->buf_used++] = a;
|
||||
}
|
||||
|
||||
static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c)
|
||||
{
|
||||
unsigned char arr[3];
|
||||
arr[0] = a, arr[1] = b, arr[2] = c;
|
||||
s->func(s->context, arr, 3);
|
||||
int n;
|
||||
if ((size_t)s->buf_used + 3 > sizeof(s->buffer))
|
||||
stbiw__write_flush(s);
|
||||
n = s->buf_used;
|
||||
s->buf_used = n+3;
|
||||
s->buffer[n+0] = a;
|
||||
s->buffer[n+1] = b;
|
||||
s->buffer[n+2] = c;
|
||||
}
|
||||
|
||||
static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, int write_alpha, int expand_mono, unsigned char *d)
|
||||
@@ -403,7 +421,7 @@ static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, in
|
||||
int k;
|
||||
|
||||
if (write_alpha < 0)
|
||||
s->func(s->context, &d[comp - 1], 1);
|
||||
stbiw__write1(s, d[comp - 1]);
|
||||
|
||||
switch (comp) {
|
||||
case 2: // 2 pixels = mono + alpha, alpha is written separately, so same as 1-channel case
|
||||
@@ -411,7 +429,7 @@ static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, in
|
||||
if (expand_mono)
|
||||
stbiw__write3(s, d[0], d[0], d[0]); // monochrome bmp
|
||||
else
|
||||
s->func(s->context, d, 1); // monochrome TGA
|
||||
stbiw__write1(s, d[0]); // monochrome TGA
|
||||
break;
|
||||
case 4:
|
||||
if (!write_alpha) {
|
||||
@@ -427,7 +445,7 @@ static void stbiw__write_pixel(stbi__write_context *s, int rgb_dir, int comp, in
|
||||
break;
|
||||
}
|
||||
if (write_alpha > 0)
|
||||
s->func(s->context, &d[comp - 1], 1);
|
||||
stbiw__write1(s, d[comp - 1]);
|
||||
}
|
||||
|
||||
static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, int x, int y, int comp, void *data, int write_alpha, int scanline_pad, int expand_mono)
|
||||
@@ -441,16 +459,18 @@ static void stbiw__write_pixels(stbi__write_context *s, int rgb_dir, int vdir, i
|
||||
if (stbi__flip_vertically_on_write)
|
||||
vdir *= -1;
|
||||
|
||||
if (vdir < 0)
|
||||
j_end = -1, j = y-1;
|
||||
else
|
||||
j_end = y, j = 0;
|
||||
if (vdir < 0) {
|
||||
j_end = -1; j = y-1;
|
||||
} else {
|
||||
j_end = y; j = 0;
|
||||
}
|
||||
|
||||
for (; j != j_end; j += vdir) {
|
||||
for (i=0; i < x; ++i) {
|
||||
unsigned char *d = (unsigned char *) data + (j*x+i)*comp;
|
||||
stbiw__write_pixel(s, rgb_dir, comp, write_alpha, expand_mono, d);
|
||||
}
|
||||
stbiw__write_flush(s);
|
||||
s->func(s->context, &zero, scanline_pad);
|
||||
}
|
||||
}
|
||||
@@ -471,16 +491,27 @@ static int stbiw__outfile(stbi__write_context *s, int rgb_dir, int vdir, int x,
|
||||
|
||||
static int stbi_write_bmp_core(stbi__write_context *s, int x, int y, int comp, const void *data)
|
||||
{
|
||||
int pad = (-x*3) & 3;
|
||||
return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad,
|
||||
"11 4 22 4" "4 44 22 444444",
|
||||
'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header
|
||||
40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header
|
||||
if (comp != 4) {
|
||||
// write RGB bitmap
|
||||
int pad = (-x*3) & 3;
|
||||
return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad,
|
||||
"11 4 22 4" "4 44 22 444444",
|
||||
'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header
|
||||
40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header
|
||||
} else {
|
||||
// RGBA bitmaps need a v4 header
|
||||
// use BI_BITFIELDS mode with 32bpp and alpha mask
|
||||
// (straight BI_RGB with alpha mask doesn't work in most readers)
|
||||
return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *)data,1,0,
|
||||
"11 4 22 4" "4 44 22 444444 4444 4 444 444 444 444",
|
||||
'B', 'M', 14+108+x*y*4, 0, 0, 14+108, // file header
|
||||
108, x,y, 1,32, 3,0,0,0,0,0, 0xff0000,0xff00,0xff,0xff000000u, 0, 0,0,0, 0,0,0, 0,0,0, 0,0,0); // bitmap V4 header
|
||||
}
|
||||
}
|
||||
|
||||
STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data)
|
||||
{
|
||||
stbi__write_context s;
|
||||
stbi__write_context s = { 0 };
|
||||
stbi__start_write_callbacks(&s, func, context);
|
||||
return stbi_write_bmp_core(&s, x, y, comp, data);
|
||||
}
|
||||
@@ -488,7 +519,7 @@ STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int x,
|
||||
#ifndef STBI_WRITE_NO_STDIO
|
||||
STBIWDEF int stbi_write_bmp(char const *filename, int x, int y, int comp, const void *data)
|
||||
{
|
||||
stbi__write_context s;
|
||||
stbi__write_context s = { 0 };
|
||||
if (stbi__start_write_file(&s,filename)) {
|
||||
int r = stbi_write_bmp_core(&s, x, y, comp, data);
|
||||
stbi__end_write_file(&s);
|
||||
@@ -561,24 +592,25 @@ static int stbi_write_tga_core(stbi__write_context *s, int x, int y, int comp, v
|
||||
|
||||
if (diff) {
|
||||
unsigned char header = STBIW_UCHAR(len - 1);
|
||||
s->func(s->context, &header, 1);
|
||||
stbiw__write1(s, header);
|
||||
for (k = 0; k < len; ++k) {
|
||||
stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin + k * comp);
|
||||
}
|
||||
} else {
|
||||
unsigned char header = STBIW_UCHAR(len - 129);
|
||||
s->func(s->context, &header, 1);
|
||||
stbiw__write1(s, header);
|
||||
stbiw__write_pixel(s, -1, comp, has_alpha, 0, begin);
|
||||
}
|
||||
}
|
||||
}
|
||||
stbiw__write_flush(s);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data)
|
||||
{
|
||||
stbi__write_context s;
|
||||
stbi__write_context s = { 0 };
|
||||
stbi__start_write_callbacks(&s, func, context);
|
||||
return stbi_write_tga_core(&s, x, y, comp, (void *) data);
|
||||
}
|
||||
@@ -586,7 +618,7 @@ STBIWDEF int stbi_write_tga_to_func(stbi_write_func *func, void *context, int x,
|
||||
#ifndef STBI_WRITE_NO_STDIO
|
||||
STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const void *data)
|
||||
{
|
||||
stbi__write_context s;
|
||||
stbi__write_context s = { 0 };
|
||||
if (stbi__start_write_file(&s,filename)) {
|
||||
int r = stbi_write_tga_core(&s, x, y, comp, (void *) data);
|
||||
stbi__end_write_file(&s);
|
||||
@@ -602,6 +634,8 @@ STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const
|
||||
|
||||
#define stbiw__max(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
#ifndef STBI_WRITE_NO_STDIO
|
||||
|
||||
static void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
||||
{
|
||||
int exponent;
|
||||
@@ -736,10 +770,10 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
|
||||
char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n";
|
||||
s->func(s->context, header, sizeof(header)-1);
|
||||
|
||||
#ifdef STBI_MSC_SECURE_CRT
|
||||
len = sprintf_s(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||
#ifdef __STDC_LIB_EXT1__
|
||||
len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||
#else
|
||||
len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||
len = snprintf(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||
#endif
|
||||
s->func(s->context, buffer, len);
|
||||
|
||||
@@ -752,15 +786,14 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
|
||||
|
||||
STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const float *data)
|
||||
{
|
||||
stbi__write_context s;
|
||||
stbi__write_context s = { 0 };
|
||||
stbi__start_write_callbacks(&s, func, context);
|
||||
return stbi_write_hdr_core(&s, x, y, comp, (float *) data);
|
||||
}
|
||||
|
||||
#ifndef STBI_WRITE_NO_STDIO
|
||||
STBIWDEF int stbi_write_hdr(char const *filename, int x, int y, int comp, const float *data)
|
||||
{
|
||||
stbi__write_context s;
|
||||
stbi__write_context s = { 0 };
|
||||
if (stbi__start_write_file(&s,filename)) {
|
||||
int r = stbi_write_hdr_core(&s, x, y, comp, (float *) data);
|
||||
stbi__end_write_file(&s);
|
||||
@@ -778,7 +811,7 @@ STBIWDEF int stbi_write_hdr(char const *filename, int x, int y, int comp, const
|
||||
|
||||
#ifndef STBIW_ZLIB_COMPRESS
|
||||
// stretchy buffer; stbiw__sbpush() == vector<>::push_back() -- stbiw__sbcount() == vector<>::size()
|
||||
#define stbiw__sbraw(a) ((int *) (a) - 2)
|
||||
#define stbiw__sbraw(a) ((int *) (void *) (a) - 2)
|
||||
#define stbiw__sbm(a) stbiw__sbraw(a)[0]
|
||||
#define stbiw__sbn(a) stbiw__sbraw(a)[1]
|
||||
|
||||
@@ -872,7 +905,7 @@ STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, i
|
||||
unsigned int bitbuf=0;
|
||||
int i,j, bitcount=0;
|
||||
unsigned char *out = NULL;
|
||||
unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(stbiw__ZHASH * sizeof(char**));
|
||||
unsigned char ***hash_table = (unsigned char***) STBIW_MALLOC(stbiw__ZHASH * sizeof(unsigned char**));
|
||||
if (hash_table == NULL)
|
||||
return NULL;
|
||||
if (quality < 5) quality = 5;
|
||||
@@ -895,7 +928,7 @@ STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, i
|
||||
for (j=0; j < n; ++j) {
|
||||
if (hlist[j]-data > i-32768) { // if entry lies within window
|
||||
int d = stbiw__zlib_countm(hlist[j], data+i, data_len-i);
|
||||
if (d >= best) best=d,bestloc=hlist[j];
|
||||
if (d >= best) { best=d; bestloc=hlist[j]; }
|
||||
}
|
||||
}
|
||||
// when hash table entry is too long, delete half the entries
|
||||
@@ -948,14 +981,31 @@ STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, i
|
||||
(void) stbiw__sbfree(hash_table[i]);
|
||||
STBIW_FREE(hash_table);
|
||||
|
||||
// store uncompressed instead if compression was worse
|
||||
if (stbiw__sbn(out) > data_len + 2 + ((data_len+32766)/32767)*5) {
|
||||
stbiw__sbn(out) = 2; // truncate to DEFLATE 32K window and FLEVEL = 1
|
||||
for (j = 0; j < data_len;) {
|
||||
int blocklen = data_len - j;
|
||||
if (blocklen > 32767) blocklen = 32767;
|
||||
stbiw__sbpush(out, data_len - j == blocklen); // BFINAL = ?, BTYPE = 0 -- no compression
|
||||
stbiw__sbpush(out, STBIW_UCHAR(blocklen)); // LEN
|
||||
stbiw__sbpush(out, STBIW_UCHAR(blocklen >> 8));
|
||||
stbiw__sbpush(out, STBIW_UCHAR(~blocklen)); // NLEN
|
||||
stbiw__sbpush(out, STBIW_UCHAR(~blocklen >> 8));
|
||||
memcpy(out+stbiw__sbn(out), data+j, blocklen);
|
||||
stbiw__sbn(out) += blocklen;
|
||||
j += blocklen;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// compute adler32 on input
|
||||
unsigned int s1=1, s2=0;
|
||||
int blocklen = (int) (data_len % 5552);
|
||||
j=0;
|
||||
while (j < data_len) {
|
||||
for (i=0; i < blocklen; ++i) s1 += data[j+i], s2 += s1;
|
||||
s1 %= 65521, s2 %= 65521;
|
||||
for (i=0; i < blocklen; ++i) { s1 += data[j+i]; s2 += s1; }
|
||||
s1 %= 65521; s2 %= 65521;
|
||||
j += blocklen;
|
||||
blocklen = 5552;
|
||||
}
|
||||
@@ -1048,13 +1098,13 @@ static void stbiw__encode_png_line(unsigned char *pixels, int stride_bytes, int
|
||||
int type = mymap[filter_type];
|
||||
unsigned char *z = pixels + stride_bytes * (stbi__flip_vertically_on_write ? height-1-y : y);
|
||||
int signed_stride = stbi__flip_vertically_on_write ? -stride_bytes : stride_bytes;
|
||||
|
||||
|
||||
if (type==0) {
|
||||
memcpy(line_buffer, z, width*n);
|
||||
return;
|
||||
}
|
||||
|
||||
// first loop isn't optimized since it's just one pixel
|
||||
// first loop isn't optimized since it's just one pixel
|
||||
for (i = 0; i < n; ++i) {
|
||||
switch (type) {
|
||||
case 1: line_buffer[i] = z[i]; break;
|
||||
@@ -1275,26 +1325,31 @@ static void stbiw__jpg_calcBits(int val, unsigned short bits[2]) {
|
||||
bits[0] = val & ((1<<bits[1])-1);
|
||||
}
|
||||
|
||||
static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt, float *CDU, float *fdtbl, int DC, const unsigned short HTDC[256][2], const unsigned short HTAC[256][2]) {
|
||||
static int stbiw__jpg_processDU(stbi__write_context *s, int *bitBuf, int *bitCnt, float *CDU, int du_stride, float *fdtbl, int DC, const unsigned short HTDC[256][2], const unsigned short HTAC[256][2]) {
|
||||
const unsigned short EOB[2] = { HTAC[0x00][0], HTAC[0x00][1] };
|
||||
const unsigned short M16zeroes[2] = { HTAC[0xF0][0], HTAC[0xF0][1] };
|
||||
int dataOff, i, diff, end0pos;
|
||||
int dataOff, i, j, n, diff, end0pos, x, y;
|
||||
int DU[64];
|
||||
|
||||
// DCT rows
|
||||
for(dataOff=0; dataOff<64; dataOff+=8) {
|
||||
for(dataOff=0, n=du_stride*8; dataOff<n; dataOff+=du_stride) {
|
||||
stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff+1], &CDU[dataOff+2], &CDU[dataOff+3], &CDU[dataOff+4], &CDU[dataOff+5], &CDU[dataOff+6], &CDU[dataOff+7]);
|
||||
}
|
||||
// DCT columns
|
||||
for(dataOff=0; dataOff<8; ++dataOff) {
|
||||
stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff+8], &CDU[dataOff+16], &CDU[dataOff+24], &CDU[dataOff+32], &CDU[dataOff+40], &CDU[dataOff+48], &CDU[dataOff+56]);
|
||||
stbiw__jpg_DCT(&CDU[dataOff], &CDU[dataOff+du_stride], &CDU[dataOff+du_stride*2], &CDU[dataOff+du_stride*3], &CDU[dataOff+du_stride*4],
|
||||
&CDU[dataOff+du_stride*5], &CDU[dataOff+du_stride*6], &CDU[dataOff+du_stride*7]);
|
||||
}
|
||||
// Quantize/descale/zigzag the coefficients
|
||||
for(i=0; i<64; ++i) {
|
||||
float v = CDU[i]*fdtbl[i];
|
||||
// DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? ceilf(v - 0.5f) : floorf(v + 0.5f));
|
||||
// ceilf() and floorf() are C99, not C89, but I /think/ they're not needed here anyway?
|
||||
DU[stbiw__jpg_ZigZag[i]] = (int)(v < 0 ? v - 0.5f : v + 0.5f);
|
||||
for(y = 0, j=0; y < 8; ++y) {
|
||||
for(x = 0; x < 8; ++x,++j) {
|
||||
float v;
|
||||
i = y*du_stride+x;
|
||||
v = CDU[i]*fdtbl[j];
|
||||
// DU[stbiw__jpg_ZigZag[j]] = (int)(v < 0 ? ceilf(v - 0.5f) : floorf(v + 0.5f));
|
||||
// ceilf() and floorf() are C99, not C89, but I /think/ they're not needed here anyway?
|
||||
DU[stbiw__jpg_ZigZag[j]] = (int)(v < 0 ? v - 0.5f : v + 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
// Encode DC
|
||||
@@ -1409,10 +1464,10 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
|
||||
37,56,68,109,103,77,24,35,55,64,81,104,113,92,49,64,78,87,103,121,120,101,72,92,95,98,112,100,103,99};
|
||||
static const int UVQT[] = {17,18,24,47,99,99,99,99,18,21,26,66,99,99,99,99,24,26,56,99,99,99,99,99,47,66,99,99,99,99,99,99,
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99};
|
||||
static const float aasf[] = { 1.0f * 2.828427125f, 1.387039845f * 2.828427125f, 1.306562965f * 2.828427125f, 1.175875602f * 2.828427125f,
|
||||
static const float aasf[] = { 1.0f * 2.828427125f, 1.387039845f * 2.828427125f, 1.306562965f * 2.828427125f, 1.175875602f * 2.828427125f,
|
||||
1.0f * 2.828427125f, 0.785694958f * 2.828427125f, 0.541196100f * 2.828427125f, 0.275899379f * 2.828427125f };
|
||||
|
||||
int row, col, i, k;
|
||||
int row, col, i, k, subsample;
|
||||
float fdtbl_Y[64], fdtbl_UV[64];
|
||||
unsigned char YTable[64], UVTable[64];
|
||||
|
||||
@@ -1421,6 +1476,7 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
|
||||
}
|
||||
|
||||
quality = quality ? quality : 90;
|
||||
subsample = quality <= 90 ? 1 : 0;
|
||||
quality = quality < 1 ? 1 : quality > 100 ? 100 : quality;
|
||||
quality = quality < 50 ? 5000 / quality : 200 - quality * 2;
|
||||
|
||||
@@ -1443,7 +1499,7 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
|
||||
static const unsigned char head0[] = { 0xFF,0xD8,0xFF,0xE0,0,0x10,'J','F','I','F',0,1,1,0,0,1,0,1,0,0,0xFF,0xDB,0,0x84,0 };
|
||||
static const unsigned char head2[] = { 0xFF,0xDA,0,0xC,3,1,0,2,0x11,3,0x11,0,0x3F,0 };
|
||||
const unsigned char head1[] = { 0xFF,0xC0,0,0x11,8,(unsigned char)(height>>8),STBIW_UCHAR(height),(unsigned char)(width>>8),STBIW_UCHAR(width),
|
||||
3,1,0x11,0,2,0x11,1,3,0x11,1,0xFF,0xC4,0x01,0xA2,0 };
|
||||
3,1,(unsigned char)(subsample?0x22:0x11),0,2,0x11,1,3,0x11,1,0xFF,0xC4,0x01,0xA2,0 };
|
||||
s->func(s->context, (void*)head0, sizeof(head0));
|
||||
s->func(s->context, (void*)YTable, sizeof(YTable));
|
||||
stbiw__putc(s, 1);
|
||||
@@ -1466,36 +1522,74 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
|
||||
// Encode 8x8 macroblocks
|
||||
{
|
||||
static const unsigned short fillBits[] = {0x7F, 7};
|
||||
const unsigned char *imageData = (const unsigned char *)data;
|
||||
int DCY=0, DCU=0, DCV=0;
|
||||
int bitBuf=0, bitCnt=0;
|
||||
// comp == 2 is grey+alpha (alpha is ignored)
|
||||
int ofsG = comp > 2 ? 1 : 0, ofsB = comp > 2 ? 2 : 0;
|
||||
const unsigned char *dataR = (const unsigned char *)data;
|
||||
const unsigned char *dataG = dataR + ofsG;
|
||||
const unsigned char *dataB = dataR + ofsB;
|
||||
int x, y, pos;
|
||||
for(y = 0; y < height; y += 8) {
|
||||
for(x = 0; x < width; x += 8) {
|
||||
float YDU[64], UDU[64], VDU[64];
|
||||
for(row = y, pos = 0; row < y+8; ++row) {
|
||||
// row >= height => use last input row
|
||||
int clamped_row = (row < height) ? row : height - 1;
|
||||
int base_p = (stbi__flip_vertically_on_write ? (height-1-clamped_row) : clamped_row)*width*comp;
|
||||
for(col = x; col < x+8; ++col, ++pos) {
|
||||
float r, g, b;
|
||||
// if col >= width => use pixel from last input column
|
||||
int p = base_p + ((col < width) ? col : (width-1))*comp;
|
||||
if(subsample) {
|
||||
for(y = 0; y < height; y += 16) {
|
||||
for(x = 0; x < width; x += 16) {
|
||||
float Y[256], U[256], V[256];
|
||||
for(row = y, pos = 0; row < y+16; ++row) {
|
||||
// row >= height => use last input row
|
||||
int clamped_row = (row < height) ? row : height - 1;
|
||||
int base_p = (stbi__flip_vertically_on_write ? (height-1-clamped_row) : clamped_row)*width*comp;
|
||||
for(col = x; col < x+16; ++col, ++pos) {
|
||||
// if col >= width => use pixel from last input column
|
||||
int p = base_p + ((col < width) ? col : (width-1))*comp;
|
||||
float r = dataR[p], g = dataG[p], b = dataB[p];
|
||||
Y[pos]= +0.29900f*r + 0.58700f*g + 0.11400f*b - 128;
|
||||
U[pos]= -0.16874f*r - 0.33126f*g + 0.50000f*b;
|
||||
V[pos]= +0.50000f*r - 0.41869f*g - 0.08131f*b;
|
||||
}
|
||||
}
|
||||
DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+0, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT);
|
||||
DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+8, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT);
|
||||
DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+128, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT);
|
||||
DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y+136, 16, fdtbl_Y, DCY, YDC_HT, YAC_HT);
|
||||
|
||||
r = imageData[p+0];
|
||||
g = imageData[p+ofsG];
|
||||
b = imageData[p+ofsB];
|
||||
YDU[pos]=+0.29900f*r+0.58700f*g+0.11400f*b-128;
|
||||
UDU[pos]=-0.16874f*r-0.33126f*g+0.50000f*b;
|
||||
VDU[pos]=+0.50000f*r-0.41869f*g-0.08131f*b;
|
||||
// subsample U,V
|
||||
{
|
||||
float subU[64], subV[64];
|
||||
int yy, xx;
|
||||
for(yy = 0, pos = 0; yy < 8; ++yy) {
|
||||
for(xx = 0; xx < 8; ++xx, ++pos) {
|
||||
int j = yy*32+xx*2;
|
||||
subU[pos] = (U[j+0] + U[j+1] + U[j+16] + U[j+17]) * 0.25f;
|
||||
subV[pos] = (V[j+0] + V[j+1] + V[j+16] + V[j+17]) * 0.25f;
|
||||
}
|
||||
}
|
||||
DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, subU, 8, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
|
||||
DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, subV, 8, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(y = 0; y < height; y += 8) {
|
||||
for(x = 0; x < width; x += 8) {
|
||||
float Y[64], U[64], V[64];
|
||||
for(row = y, pos = 0; row < y+8; ++row) {
|
||||
// row >= height => use last input row
|
||||
int clamped_row = (row < height) ? row : height - 1;
|
||||
int base_p = (stbi__flip_vertically_on_write ? (height-1-clamped_row) : clamped_row)*width*comp;
|
||||
for(col = x; col < x+8; ++col, ++pos) {
|
||||
// if col >= width => use pixel from last input column
|
||||
int p = base_p + ((col < width) ? col : (width-1))*comp;
|
||||
float r = dataR[p], g = dataG[p], b = dataB[p];
|
||||
Y[pos]= +0.29900f*r + 0.58700f*g + 0.11400f*b - 128;
|
||||
U[pos]= -0.16874f*r - 0.33126f*g + 0.50000f*b;
|
||||
V[pos]= +0.50000f*r - 0.41869f*g - 0.08131f*b;
|
||||
}
|
||||
}
|
||||
|
||||
DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
|
||||
DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
|
||||
DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
|
||||
DCY = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, Y, 8, fdtbl_Y, DCY, YDC_HT, YAC_HT);
|
||||
DCU = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, U, 8, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
|
||||
DCV = stbiw__jpg_processDU(s, &bitBuf, &bitCnt, V, 8, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1512,7 +1606,7 @@ static int stbi_write_jpg_core(stbi__write_context *s, int width, int height, in
|
||||
|
||||
STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality)
|
||||
{
|
||||
stbi__write_context s;
|
||||
stbi__write_context s = { 0 };
|
||||
stbi__start_write_callbacks(&s, func, context);
|
||||
return stbi_write_jpg_core(&s, x, y, comp, (void *) data, quality);
|
||||
}
|
||||
@@ -1521,7 +1615,7 @@ STBIWDEF int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x,
|
||||
#ifndef STBI_WRITE_NO_STDIO
|
||||
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality)
|
||||
{
|
||||
stbi__write_context s;
|
||||
stbi__write_context s = { 0 };
|
||||
if (stbi__start_write_file(&s,filename)) {
|
||||
int r = stbi_write_jpg_core(&s, x, y, comp, data, quality);
|
||||
stbi__end_write_file(&s);
|
||||
@@ -1534,8 +1628,17 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const
|
||||
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
/* Revision history
|
||||
1.16 (2021-07-11)
|
||||
make Deflate code emit uncompressed blocks when it would otherwise expand
|
||||
support writing BMPs with alpha channel
|
||||
1.15 (2020-07-13) unknown
|
||||
1.14 (2020-02-02) updated JPEG writer to downsample chroma channels
|
||||
1.13
|
||||
1.12
|
||||
1.11 (2019-08-11)
|
||||
|
||||
1.10 (2019-02-07)
|
||||
support utf8 filenames in Windows; fix warnings and platform ifdefs
|
||||
support utf8 filenames in Windows; fix warnings and platform ifdefs
|
||||
1.09 (2018-02-11)
|
||||
fix typo in zlib quality API, improve STB_I_W_STATIC in C++
|
||||
1.08 (2018-01-29)
|
||||
@@ -1566,7 +1669,7 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const
|
||||
add HDR output
|
||||
fix monochrome BMP
|
||||
0.95 (2014-08-17)
|
||||
add monochrome TGA output
|
||||
add monochrome TGA output
|
||||
0.94 (2014-05-31)
|
||||
rename private functions to avoid conflicts with stb_image.h
|
||||
0.93 (2014-05-27)
|
||||
@@ -1584,38 +1687,38 @@ This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Assume python 2.6 or 2.7
|
||||
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
46
tests/fuzzer/README.md
Normal file
46
tests/fuzzer/README.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Fuzzing test
|
||||
|
||||
Do fuzzing test for TinyGLTF API.
|
||||
|
||||
## Supported API
|
||||
|
||||
* [x] LoadASCIIFromMemory
|
||||
* [ ] LoadBinaryFromMemory
|
||||
|
||||
## Requirements
|
||||
|
||||
* meson
|
||||
* clang with fuzzer support(`-fsanitize=fuzzer`. at least clang 8.0 should work)
|
||||
|
||||
## Setup
|
||||
|
||||
### Ubuntu 18.04
|
||||
|
||||
```
|
||||
$ sudo apt install clang++-8
|
||||
$ sudo apt install libfuzzer-8-dev
|
||||
```
|
||||
|
||||
Optionally, if you didn't set `update-alternatives` you can set `clang++` to point to `clang++8`
|
||||
|
||||
```
|
||||
$ 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
|
||||
```
|
||||
|
||||
## How to compile
|
||||
|
||||
```
|
||||
$ CXX=clang++ CC=clang meson build
|
||||
$ cd build
|
||||
$ ninja
|
||||
```
|
||||
|
||||
## How to run
|
||||
|
||||
Increase memory limit. e.g. `-rss_limit_mb=50000`
|
||||
|
||||
```
|
||||
$ ./fuzz_gltf -rss_limit_mb=20000 -jobs 4
|
||||
```
|
||||
|
||||
33
tests/fuzzer/fuzz_gltf.cc
Normal file
33
tests/fuzzer/fuzz_gltf.cc
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#include "tiny_gltf.h"
|
||||
|
||||
static void parse_intCoding4(const uint8_t *data, size_t size)
|
||||
{
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
const char *str = reinterpret_cast<const char *>(data);
|
||||
|
||||
bool ret = ctx.LoadASCIIFromString(&model, &err, &warn, str, size, /* base_dir */"" );
|
||||
(void)ret;
|
||||
|
||||
}
|
||||
|
||||
extern "C"
|
||||
int LLVMFuzzerTestOneInput(std::uint8_t const* data, std::size_t size)
|
||||
{
|
||||
parse_intCoding4(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
9
tests/fuzzer/meson.build
Normal file
9
tests/fuzzer/meson.build
Normal file
@@ -0,0 +1,9 @@
|
||||
project('fuzz_tinygltf', 'cpp', default_options : ['cpp_std=c++11'])
|
||||
|
||||
incdirs = include_directories('../../')
|
||||
executable('fuzz_gltf',
|
||||
'fuzz_gltf.cc',
|
||||
include_directories : incdirs,
|
||||
cpp_args : '-fsanitize=address,fuzzer',
|
||||
link_args : '-fsanitize=address,fuzzer' )
|
||||
|
||||
1
tests/issue-416.gltf
Normal file
1
tests/issue-416.gltf
Normal file
@@ -0,0 +1 @@
|
||||
{"images":[{"uri":"%!QAAAQAAA5"}],"asset":{"version":""}}
|
||||
BIN
tests/issue-492.glb
Normal file
BIN
tests/issue-492.glb
Normal file
Binary file not shown.
928
tests/tester.cc
928
tests/tester.cc
@@ -3,6 +3,9 @@
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "tiny_gltf.h"
|
||||
|
||||
// Nlohmann json(include ../json.hpp)
|
||||
#include "json.hpp"
|
||||
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||
#include "catch.hpp"
|
||||
|
||||
@@ -13,10 +16,10 @@
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
static JsonDocument JsonConstruct(const char* str)
|
||||
static tinygltf::detail::JsonDocument JsonConstruct(const char* str)
|
||||
{
|
||||
JsonDocument doc;
|
||||
JsonParse(doc, str, strlen(str));
|
||||
tinygltf::detail::JsonDocument doc;
|
||||
tinygltf::detail::JsonParse(doc, str, strlen(str));
|
||||
return doc;
|
||||
}
|
||||
|
||||
@@ -93,6 +96,59 @@ TEST_CASE("extension-with-empty-object", "[issue-97]") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("extension-overwrite", "[issue-261]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Extensions-overwrite-issue261/issue-261.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
|
||||
REQUIRE(model.extensionsUsed.size() == 3);
|
||||
{
|
||||
bool has_ext_lights = false;
|
||||
has_ext_lights |= (model.extensionsUsed[0].compare("KHR_lights_punctual") == 0);
|
||||
has_ext_lights |= (model.extensionsUsed[1].compare("KHR_lights_punctual") == 0);
|
||||
has_ext_lights |= (model.extensionsUsed[2].compare("KHR_lights_punctual") == 0);
|
||||
|
||||
REQUIRE(true == has_ext_lights);
|
||||
}
|
||||
|
||||
{
|
||||
REQUIRE(model.extensions.size() == 2);
|
||||
REQUIRE(model.extensions.count("NV_MDL"));
|
||||
REQUIRE(model.extensions.count("KHR_lights_punctual"));
|
||||
}
|
||||
|
||||
// TODO(syoyo): create temp directory.
|
||||
{
|
||||
ret = ctx.WriteGltfSceneToFile(&model, "issue-261.gltf", true, true);
|
||||
REQUIRE(true == ret);
|
||||
|
||||
tinygltf::Model m;
|
||||
|
||||
// read back serialized glTF
|
||||
bool ret = ctx.LoadASCIIFromFile(&m, &err, &warn, "issue-261.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
|
||||
REQUIRE(m.extensionsUsed.size() == 3);
|
||||
|
||||
REQUIRE(m.extensions.size() == 2);
|
||||
REQUIRE(m.extensions.count("NV_MDL"));
|
||||
REQUIRE(m.extensions.count("KHR_lights_punctual"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("invalid-primitive-indices", "[bounds-checking]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
@@ -219,9 +275,9 @@ TEST_CASE("parse-integer", "[bounds-checking]") {
|
||||
|
||||
err.clear();
|
||||
{
|
||||
JsonDocument o;
|
||||
tinygltf::detail::JsonDocument o;
|
||||
double nan = std::numeric_limits<double>::quiet_NaN();
|
||||
tinygltf::JsonAddMember(o, "int", json(nan));
|
||||
tinygltf::detail::JsonAddMember(o, "int", tinygltf::detail::json(nan));
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(
|
||||
&result, &err, o,
|
||||
"int", true));
|
||||
@@ -265,9 +321,9 @@ TEST_CASE("parse-unsigned", "[bounds-checking]") {
|
||||
|
||||
err.clear();
|
||||
{
|
||||
JsonDocument o;
|
||||
tinygltf::detail::JsonDocument o;
|
||||
double nan = std::numeric_limits<double>::quiet_NaN();
|
||||
tinygltf::JsonAddMember(o, "int", json(nan));
|
||||
tinygltf::detail::JsonAddMember(o, "int", tinygltf::detail::json(nan));
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(
|
||||
&result, &err, o,
|
||||
"int", true));
|
||||
@@ -333,3 +389,861 @@ TEST_CASE("pbr-khr-texture-transform", "[material]") {
|
||||
REQUIRE(scale[1] == Approx(-1.0));
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("image-uri-spaces", "[issue-236]") {
|
||||
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
// Test image file with single spaces.
|
||||
{
|
||||
tinygltf::Model model;
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/CubeImageUriSpaces/CubeImageUriSpaces.gltf");
|
||||
if (!warn.empty()) {
|
||||
std::cerr << warn << std::endl;
|
||||
}
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
|
||||
REQUIRE(true == ret);
|
||||
REQUIRE(warn.empty());
|
||||
REQUIRE(err.empty());
|
||||
REQUIRE(model.images.size() == 1);
|
||||
REQUIRE(model.images[0].uri.find(' ') != std::string::npos);
|
||||
}
|
||||
|
||||
// Test image file with a beginning space, trailing space, and greater than
|
||||
// one consecutive spaces.
|
||||
tinygltf::Model model;
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/CubeImageUriSpaces/CubeImageUriMultipleSpaces.gltf");
|
||||
if (!warn.empty()) {
|
||||
std::cerr << warn << std::endl;
|
||||
}
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
|
||||
REQUIRE(true == ret);
|
||||
REQUIRE(warn.empty());
|
||||
REQUIRE(err.empty());
|
||||
REQUIRE(model.images.size() == 1);
|
||||
REQUIRE(model.images[0].uri.size() > 1);
|
||||
REQUIRE(model.images[0].uri[0] == ' ');
|
||||
|
||||
// Test the URI encoding API by saving and re-load the file, without embedding
|
||||
// the image.
|
||||
// TODO(syoyo): create temp directory.
|
||||
{
|
||||
// Encoder that only replaces spaces with "%20".
|
||||
auto uriencode = [](const std::string &in_uri,
|
||||
const std::string &object_type, std::string *out_uri,
|
||||
void *user_data) -> bool {
|
||||
(void)user_data;
|
||||
bool imageOrBuffer = object_type == "image" || object_type == "buffer";
|
||||
REQUIRE(true == imageOrBuffer);
|
||||
*out_uri = {};
|
||||
for (char c : in_uri) {
|
||||
if (c == ' ')
|
||||
*out_uri += "%20";
|
||||
else
|
||||
*out_uri += c;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
// Remove the buffer URI, so a new one is generated based on the gltf
|
||||
// filename and then encoded with the above callback.
|
||||
model.buffers[0].uri.clear();
|
||||
|
||||
tinygltf::URICallbacks uri_cb{uriencode, tinygltf::URIDecode, nullptr};
|
||||
ctx.SetURICallbacks(uri_cb);
|
||||
ret = ctx.WriteGltfSceneToFile(&model, " issue-236.gltf", false, false);
|
||||
REQUIRE(true == ret);
|
||||
|
||||
// read back serialized glTF
|
||||
tinygltf::Model saved;
|
||||
bool ret = ctx.LoadASCIIFromFile(&saved, &err, &warn, " issue-236.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
REQUIRE(err.empty());
|
||||
REQUIRE(warn.empty());
|
||||
REQUIRE(saved.images.size() == model.images.size());
|
||||
|
||||
// The image uri in CubeImageUriMultipleSpaces.gltf is not encoded and
|
||||
// should be different after encoding spaces with %20.
|
||||
REQUIRE(model.images[0].uri != saved.images[0].uri);
|
||||
|
||||
// Verify the image path remains the same after uri decoding
|
||||
std::string image_uri, image_uri_saved;
|
||||
(void)tinygltf::URIDecode(model.images[0].uri, &image_uri, nullptr);
|
||||
(void)tinygltf::URIDecode(saved.images[0].uri, &image_uri_saved, nullptr);
|
||||
REQUIRE(image_uri == image_uri_saved);
|
||||
|
||||
// Verify the buffer's generated and encoded URI
|
||||
REQUIRE(saved.buffers.size() == model.buffers.size());
|
||||
REQUIRE(saved.buffers[0].uri == "%20issue-236.bin");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-empty-material", "[issue-294]") {
|
||||
tinygltf::Model m;
|
||||
// Add default constructed material to model
|
||||
m.materials.push_back({});
|
||||
// Serialize model to output stream
|
||||
std::stringstream os;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
||||
REQUIRE(true == ret);
|
||||
// Parse serialized model
|
||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||
// Serialized materials shall hold an empty object that
|
||||
// represents the default constructed material
|
||||
REQUIRE(j.find("materials") != j.end());
|
||||
REQUIRE(j["materials"].is_array());
|
||||
REQUIRE(1 == j["materials"].size());
|
||||
CHECK(j["materials"][0].is_object());
|
||||
CHECK(j["materials"][0].empty());
|
||||
}
|
||||
|
||||
TEST_CASE("empty-skeleton-id", "[issue-321]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/regression/unassigned-skeleton.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
|
||||
REQUIRE(model.skins.size() == 1);
|
||||
REQUIRE(model.skins[0].skeleton == -1); // unassigned
|
||||
|
||||
std::stringstream os;
|
||||
|
||||
ret = ctx.WriteGltfSceneToStream(&model, os, false, false);
|
||||
REQUIRE(true == ret);
|
||||
|
||||
// use nlohmann json
|
||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||
|
||||
// Ensure `skeleton` property is not written to .gltf(was serialized as -1)
|
||||
REQUIRE(1 == j["skins"].size());
|
||||
REQUIRE(j["skins"][0].is_object());
|
||||
REQUIRE(j["skins"][0].count("skeleton") == 0);
|
||||
|
||||
}
|
||||
|
||||
#ifndef TINYGLTF_NO_FS
|
||||
TEST_CASE("expandpath-utf-8", "[pr-226]") {
|
||||
|
||||
std::string s1 = "\xe5\xaf\xb9"; // utf-8 string
|
||||
|
||||
std::string ret = tinygltf::ExpandFilePath(s1, /* userdata */nullptr);
|
||||
|
||||
// expected: E5 AF B9
|
||||
REQUIRE(3 == ret.size());
|
||||
|
||||
REQUIRE(0xe5 == static_cast<uint8_t>(ret[0]));
|
||||
REQUIRE(0xaf == static_cast<uint8_t>(ret[1]));
|
||||
REQUIRE(0xb9 == static_cast<uint8_t>(ret[2]));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("empty-bin-buffer", "[issue-382]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
tinygltf::Model model_empty;
|
||||
std::stringstream stream;
|
||||
bool ret = ctx.WriteGltfSceneToStream(&model_empty, stream, false, true);
|
||||
REQUIRE(ret == true);
|
||||
std::string str = stream.str();
|
||||
const unsigned char* bytes = (unsigned char*)str.data();
|
||||
ret = ctx.LoadBinaryFromMemory(&model, &err, &warn, bytes, str.size());
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
|
||||
err.clear();
|
||||
warn.clear();
|
||||
|
||||
tinygltf::Model model_empty_buffer;
|
||||
model_empty_buffer.buffers.push_back(tinygltf::Buffer());
|
||||
stream = std::stringstream();
|
||||
ret = ctx.WriteGltfSceneToStream(&model_empty_buffer, stream, false, true);
|
||||
REQUIRE(ret == true);
|
||||
str = stream.str();
|
||||
bytes = (unsigned char*)str.data();
|
||||
ret = ctx.LoadBinaryFromMemory(&model, &err, &warn, bytes, str.size());
|
||||
if (err.empty()) {
|
||||
std::cerr << "there should have been an error reported" << std::endl;
|
||||
}
|
||||
REQUIRE(false == ret);
|
||||
|
||||
err.clear();
|
||||
warn.clear();
|
||||
|
||||
tinygltf::Model model_single_byte_buffer;
|
||||
tinygltf::Buffer buffer;
|
||||
buffer.data.push_back(0);
|
||||
model_single_byte_buffer.buffers.push_back(buffer);
|
||||
stream = std::stringstream();
|
||||
ret = ctx.WriteGltfSceneToStream(&model_single_byte_buffer, stream, false, true);
|
||||
REQUIRE(ret == true);
|
||||
str = stream.str();
|
||||
{
|
||||
std::ofstream ofs("tmp.glb");
|
||||
ofs.write(str.data(), str.size());
|
||||
}
|
||||
|
||||
bytes = (unsigned char*)str.data();
|
||||
ret = ctx.LoadBinaryFromMemory(&model_single_byte_buffer, &err, &warn, bytes, str.size());
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
REQUIRE(true == ret);
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-const-image", "[issue-394]") {
|
||||
tinygltf::Model m;
|
||||
tinygltf::Image i;
|
||||
i.width = 1;
|
||||
i.height = 1;
|
||||
i.component = 4;
|
||||
i.bits = 8;
|
||||
i.pixel_type = TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE;
|
||||
i.image = {255, 255, 255, 255};
|
||||
i.uri = "image.png";
|
||||
m.images.push_back(i);
|
||||
|
||||
std::stringstream os;
|
||||
|
||||
tinygltf::TinyGLTF ctx;
|
||||
bool ret = ctx.WriteGltfSceneToStream(const_cast<const tinygltf::Model *>(&m), os, false,
|
||||
false);
|
||||
REQUIRE(true == ret);
|
||||
REQUIRE(m.images[0].uri == i.uri);
|
||||
|
||||
// use nlohmann json
|
||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||
|
||||
REQUIRE(1 == j["images"].size());
|
||||
REQUIRE(j["images"][0].is_object());
|
||||
REQUIRE(j["images"][0]["uri"].get<std::string>() != i.uri);
|
||||
REQUIRE(j["images"][0]["uri"].get<std::string>().rfind("data:", 0) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-image-callback", "[issue-394]") {
|
||||
tinygltf::Model m;
|
||||
tinygltf::Image i;
|
||||
i.width = 1;
|
||||
i.height = 1;
|
||||
i.bits = 32;
|
||||
i.image = {255, 255, 255, 255};
|
||||
i.uri = "foo";
|
||||
m.images.push_back(i);
|
||||
|
||||
std::stringstream os;
|
||||
|
||||
auto writer = [](const std::string *basepath, const std::string *filename,
|
||||
const tinygltf::Image *image, bool embedImages,
|
||||
const tinygltf::FsCallbacks* fs, const tinygltf::URICallbacks *uri_cb,
|
||||
std::string *out_uri, void *user_pointer) -> bool {
|
||||
(void)basepath;
|
||||
(void)image;
|
||||
(void)fs;
|
||||
(void)uri_cb;
|
||||
REQUIRE(*filename == "foo");
|
||||
REQUIRE(embedImages == true);
|
||||
REQUIRE(user_pointer == (void *)0xba5e1e55);
|
||||
*out_uri = "bar";
|
||||
return true;
|
||||
};
|
||||
|
||||
tinygltf::TinyGLTF ctx;
|
||||
ctx.SetImageWriter(writer, (void *)0xba5e1e55);
|
||||
bool result = ctx.WriteGltfSceneToStream(const_cast<const tinygltf::Model *>(&m), os, false,
|
||||
false);
|
||||
|
||||
// use nlohmann json
|
||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||
|
||||
REQUIRE(true == result);
|
||||
REQUIRE(1 == j["images"].size());
|
||||
REQUIRE(j["images"][0].is_object());
|
||||
REQUIRE(j["images"][0]["uri"].get<std::string>() == "bar");
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-image-failure", "[issue-394]") {
|
||||
tinygltf::Model m;
|
||||
tinygltf::Image i;
|
||||
// Set some data so the ImageWriter callback will be called
|
||||
i.image = {255, 255, 255, 255};
|
||||
m.images.push_back(i);
|
||||
|
||||
std::stringstream os;
|
||||
|
||||
auto writer = [](const std::string *basepath, const std::string *filename,
|
||||
const tinygltf::Image *image, bool embedImages,
|
||||
const tinygltf::FsCallbacks* fs, const tinygltf::URICallbacks *uri_cb,
|
||||
std::string *out_uri, void *user_pointer) -> bool {
|
||||
(void)basepath;
|
||||
(void)filename;
|
||||
(void)image;
|
||||
(void)embedImages;
|
||||
(void)fs;
|
||||
(void)uri_cb;
|
||||
(void)out_uri;
|
||||
(void)user_pointer;
|
||||
return false;
|
||||
};
|
||||
|
||||
tinygltf::TinyGLTF ctx;
|
||||
ctx.SetImageWriter(writer, (void *)0xba5e1e55);
|
||||
bool result = ctx.WriteGltfSceneToStream(const_cast<const tinygltf::Model *>(&m), os, false,
|
||||
false);
|
||||
|
||||
REQUIRE(false == result);
|
||||
REQUIRE(os.str().size() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("filesize-check", "[issue-416]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
ctx.SetMaxExternalFileSize(10); // 10 bytes. will fail to load texture image.
|
||||
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Cube/Cube.gltf");
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
|
||||
REQUIRE(false == ret);
|
||||
}
|
||||
|
||||
TEST_CASE("load-issue-416-model", "[issue-416]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "issue-416.gltf");
|
||||
if (!warn.empty()) {
|
||||
std::cout << "WARN:" << warn << std::endl;
|
||||
}
|
||||
if (!err.empty()) {
|
||||
std::cerr << "ERR:" << err << std::endl;
|
||||
}
|
||||
|
||||
// external file load fails, but reading glTF itself is ok.
|
||||
REQUIRE(true == ret);
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-empty-node", "[issue-457]") {
|
||||
tinygltf::Model m;
|
||||
// Add default constructed node to model
|
||||
m.nodes.push_back({});
|
||||
// Add scene to model
|
||||
m.scenes.push_back({});
|
||||
// The scene's only node is the empty node
|
||||
m.scenes.front().nodes.push_back(0);
|
||||
|
||||
// Serialize model to output stream
|
||||
std::stringstream os;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
||||
REQUIRE(true == ret);
|
||||
|
||||
// Parse serialized model
|
||||
nlohmann::json j = nlohmann::json::parse(os.str());
|
||||
|
||||
// Serialized nodes shall hold an empty object that
|
||||
// represents the default constructed node
|
||||
REQUIRE(j.find("nodes") != j.end());
|
||||
REQUIRE(j["nodes"].is_array());
|
||||
REQUIRE(1 == j["nodes"].size());
|
||||
CHECK(j["nodes"][0].is_object());
|
||||
CHECK(j["nodes"][0].empty());
|
||||
|
||||
// We also want to make sure that the serialized scene
|
||||
// is referencing the empty node.
|
||||
|
||||
// There shall be a single serialized scene
|
||||
auto scenes = j.find("scenes");
|
||||
REQUIRE(scenes != j.end());
|
||||
REQUIRE(scenes->is_array());
|
||||
REQUIRE(1 == scenes->size());
|
||||
auto scene = scenes->at(0);
|
||||
REQUIRE(scene.is_object());
|
||||
// The scene's nodes array shall hold a reference
|
||||
// to the single node
|
||||
auto nodes = scene.find("nodes");
|
||||
REQUIRE(nodes != scene.end());
|
||||
REQUIRE(nodes->is_array());
|
||||
REQUIRE(1 == nodes->size());
|
||||
auto node = nodes->at(0);
|
||||
CHECK(node.is_number_integer());
|
||||
int idx = -1;
|
||||
node.get_to(idx);
|
||||
CHECK(0 == idx);
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-light-index", "[issue-458]") {
|
||||
|
||||
// Create the light
|
||||
tinygltf::Light light;
|
||||
light.type = "point";
|
||||
light.intensity = 0.75;
|
||||
light.color = std::vector<double>{1.0, 0.8, 0.95};
|
||||
|
||||
// Stream to serialize to
|
||||
std::stringstream os;
|
||||
|
||||
{
|
||||
tinygltf::Model m;
|
||||
tinygltf::Scene scene;
|
||||
// Add the light to the model
|
||||
m.lights.push_back(light);
|
||||
// Create a node that uses the light
|
||||
tinygltf::Node node;
|
||||
node.light = 0;
|
||||
// Add the node to the model
|
||||
m.nodes.push_back(node);
|
||||
// Add the node to the scene
|
||||
scene.nodes.push_back(0);
|
||||
// Add the scene to the model
|
||||
m.scenes.push_back(scene);
|
||||
// Serialize model to output stream
|
||||
tinygltf::TinyGLTF ctx;
|
||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
||||
REQUIRE(true == ret);
|
||||
}
|
||||
|
||||
{
|
||||
tinygltf::Model m;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
// Parse the serialized model
|
||||
bool ok = ctx.LoadASCIIFromString(&m, nullptr, nullptr, os.str().c_str(), os.str().size(), "");
|
||||
REQUIRE(true == ok);
|
||||
// Check if the light was correctly serialized
|
||||
REQUIRE(1 == m.lights.size());
|
||||
CHECK(m.lights[0] == light);
|
||||
// Check that the node properly references the light
|
||||
REQUIRE(1 == m.nodes.size());
|
||||
CHECK(m.nodes[0].light == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("default-material", "[issue-459]") {
|
||||
const std::vector<double> default_emissive_factor{ 0.0, 0.0, 0.0 };
|
||||
const std::vector<double> default_base_color_factor{ 1.0, 1.0, 1.0, 1.0 };
|
||||
const std::string default_alpha_mode = "OPAQUE";
|
||||
const double default_alpha_cutoff = 0.5;
|
||||
const bool default_double_sided = false;
|
||||
const double default_metallic_factor = 1.0;
|
||||
const double default_roughness_factor = 1.0;
|
||||
// Check that default constructed material
|
||||
// holds actual default GLTF material properties
|
||||
tinygltf::Material mat;
|
||||
CHECK(mat.alphaMode == default_alpha_mode);
|
||||
CHECK(mat.alphaCutoff == default_alpha_cutoff);
|
||||
CHECK(mat.doubleSided == default_double_sided);
|
||||
CHECK(mat.emissiveFactor == default_emissive_factor);
|
||||
CHECK(mat.pbrMetallicRoughness.baseColorFactor == default_base_color_factor);
|
||||
CHECK(mat.pbrMetallicRoughness.metallicFactor == default_metallic_factor);
|
||||
CHECK(mat.pbrMetallicRoughness.roughnessFactor == default_roughness_factor);
|
||||
// None of the textures should be set
|
||||
CHECK(mat.normalTexture.index == -1);
|
||||
CHECK(mat.occlusionTexture.index == -1);
|
||||
CHECK(mat.emissiveTexture.index == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-empty-scene", "[issue-464]") {
|
||||
// Stream to serialize to
|
||||
std::stringstream os;
|
||||
|
||||
{
|
||||
tinygltf::Model m;
|
||||
// Add empty scene to the model
|
||||
m.scenes.push_back({});
|
||||
// Serialize model to output stream
|
||||
tinygltf::TinyGLTF ctx;
|
||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
||||
REQUIRE(true == ret);
|
||||
}
|
||||
|
||||
{
|
||||
tinygltf::Model m;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
// Parse the serialized model
|
||||
bool ok = ctx.LoadASCIIFromString(&m, nullptr, nullptr, os.str().c_str(), os.str().size(), "");
|
||||
REQUIRE(true == ok);
|
||||
// Make sure the empty scene is there
|
||||
REQUIRE(1 == m.scenes.size());
|
||||
tinygltf::Scene scene{};
|
||||
// Check that the scene is empty
|
||||
CHECK(m.scenes[0] == scene);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("zero-sized-bin-chunk-glb", "[issue-440]") {
|
||||
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
// Input glb has zero-sized data in bin chunk(8 bytes for BIN chunk, and chunksize == 0)
|
||||
// The spec https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#binary-buffer says
|
||||
//
|
||||
// When the binary buffer is empty or when it is stored by other means, this chunk SHOULD be omitted.
|
||||
//
|
||||
// 'SHOULD' mean 'RECOMMENDED', so we'll need to allow such zero-sized bin chunk is NOT omitted.
|
||||
bool ret = ctx.LoadBinaryFromFile(&model, &err, &warn, "../models/regression/zero-sized-bin-chunk-issue-440.glb");
|
||||
if (!warn.empty()) {
|
||||
std::cout << "WARN: " << warn << "\n";
|
||||
}
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
|
||||
REQUIRE(true == ret);
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-node-emitter", "[KHR_audio]") {
|
||||
// Stream to serialize to
|
||||
std::stringstream os;
|
||||
|
||||
{
|
||||
tinygltf::Model m;
|
||||
// Create a default audio emitter
|
||||
m.audioEmitters.resize(1);
|
||||
// Create a single node
|
||||
m.nodes.resize(1);
|
||||
// The node references the single emitter
|
||||
m.nodes[0].emitter = 0;
|
||||
// Create a single scene
|
||||
m.scenes.resize(1);
|
||||
// Make the scene reference the single node
|
||||
m.scenes[0].nodes.push_back(0);
|
||||
|
||||
// Serialize model to output stream
|
||||
tinygltf::TinyGLTF ctx;
|
||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
||||
REQUIRE(true == ret);
|
||||
}
|
||||
|
||||
{
|
||||
tinygltf::Model m;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
// Parse the serialized model
|
||||
bool ok = ctx.LoadASCIIFromString(&m, nullptr, nullptr, os.str().c_str(), os.str().size(), "");
|
||||
REQUIRE(true == ok);
|
||||
|
||||
// Make sure the single scene is there
|
||||
REQUIRE(1 == m.scenes.size());
|
||||
// Make sure all three nodes are there
|
||||
REQUIRE(1 == m.nodes.size());
|
||||
// Make sure the single root node of the scene is there
|
||||
REQUIRE(1 == m.scenes[0].nodes.size());
|
||||
REQUIRE(0 == m.scenes[0].nodes[0]);
|
||||
// Retrieve the scene root node
|
||||
const tinygltf::Node& node = m.nodes[m.scenes[0].nodes[0]];
|
||||
// Make sure the single root node has both lod nodes
|
||||
REQUIRE(0 == node.emitter);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("serialize-lods", "[lods]") {
|
||||
// Stream to serialize to
|
||||
std::stringstream os;
|
||||
|
||||
{
|
||||
tinygltf::Model m;
|
||||
|
||||
m.nodes.resize(4);
|
||||
// Add Node 1 and Node 2 as lods to Node 0
|
||||
m.nodes[0].lods.push_back(1);
|
||||
m.nodes[0].lods.push_back(2);
|
||||
|
||||
// Add Material 1 and Material 2 as lods to Material 0
|
||||
m.materials.resize(4);
|
||||
m.materials[0].lods.push_back(1);
|
||||
m.materials[0].lods.push_back(2);
|
||||
|
||||
tinygltf::Scene scene;
|
||||
// Scene uses Node 0 and 3 as root node
|
||||
scene.nodes.push_back(0);
|
||||
scene.nodes.push_back(3);
|
||||
// Add scene to the model
|
||||
m.scenes.push_back(scene);
|
||||
|
||||
// Serialize model to output stream
|
||||
tinygltf::TinyGLTF ctx;
|
||||
bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
|
||||
REQUIRE(true == ret);
|
||||
}
|
||||
|
||||
{
|
||||
tinygltf::Model m;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
// Parse the serialized model
|
||||
bool ok = ctx.LoadASCIIFromString(&m, nullptr, nullptr, os.str().c_str(), os.str().size(), "");
|
||||
REQUIRE(true == ok);
|
||||
// Make sure the model's used extensions hold MSFT_lod
|
||||
CHECK(m.extensionsUsed.size() == 1);
|
||||
CHECK(m.extensionsUsed[0].compare("MSFT_lod") == 0);
|
||||
// MSFT_lod is not a required extension
|
||||
CHECK(m.extensionsRequired.size() == 0);
|
||||
|
||||
// Make sure all four materials are there
|
||||
REQUIRE(4 == m.materials.size());
|
||||
// Make sure the first material has both lod materials
|
||||
REQUIRE(2 == m.materials[0].lods.size());
|
||||
// Make sure the order is still the same after serialization and deserialization
|
||||
CHECK(1 == m.materials[0].lods[0]);
|
||||
CHECK(2 == m.materials[0].lods[1]);
|
||||
// Make sure the material with lods exposes the MSFT_lod extension
|
||||
CHECK(m.materials[0].extensions.size() == 1);
|
||||
CHECK(m.materials[0].extensions.count("MSFT_lod") == 1);
|
||||
// Make sure the last material has no lod materials
|
||||
CHECK(0 == m.materials[3].lods.size());
|
||||
// Make sure the material without lods does not exposes the MSFT_lod extension
|
||||
CHECK(m.materials[3].extensions.size() == 0);
|
||||
CHECK(m.materials[3].extensions.count("MSFT_lod") == 0);
|
||||
|
||||
// Make sure the single scene is there
|
||||
REQUIRE(1 == m.scenes.size());
|
||||
// Make sure all four nodes are there
|
||||
REQUIRE(4 == m.nodes.size());
|
||||
// Make sure the two root nodes of the scene are there
|
||||
REQUIRE(2 == m.scenes[0].nodes.size());
|
||||
REQUIRE(0 == m.scenes[0].nodes[0]);
|
||||
REQUIRE(3 == m.scenes[0].nodes[1]);
|
||||
// Retrieve the node with lods
|
||||
const tinygltf::Node& nodeWithLods = m.nodes[m.scenes[0].nodes[0]];
|
||||
// Make sure the node has both lod nodes
|
||||
REQUIRE(2 == nodeWithLods.lods.size());
|
||||
// Make sure the order is still the same after serialization and deserialization
|
||||
CHECK(1 == nodeWithLods.lods[0]);
|
||||
CHECK(2 == nodeWithLods.lods[1]);
|
||||
// Make sure the node with lods exposes the MSFT_lod extension
|
||||
CHECK(nodeWithLods.extensions.size() == 1);
|
||||
CHECK(nodeWithLods.extensions.count("MSFT_lod") == 1);
|
||||
// Retrieve the node without lods
|
||||
const tinygltf::Node& nodeWithoutLods = m.nodes[m.scenes[0].nodes[1]];
|
||||
// Make sure the node has no lod nodes
|
||||
CHECK(0 == nodeWithoutLods.lods.size());
|
||||
// Make sure the node without lods does not exposes the MSFT_lod extension
|
||||
CHECK(nodeWithoutLods.extensions.size() == 0);
|
||||
CHECK(nodeWithoutLods.extensions.count("MSFT_lod") == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("write-image-issue", "[issue-473]") {
|
||||
std::string err;
|
||||
std::string warn;
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
bool ok = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Cube/Cube.gltf");
|
||||
REQUIRE(ok);
|
||||
REQUIRE(err.empty());
|
||||
REQUIRE(warn.empty());
|
||||
|
||||
REQUIRE(model.images.size() == 2);
|
||||
REQUIRE(model.images[0].uri == "Cube_BaseColor.png");
|
||||
REQUIRE(model.images[1].uri == "Cube_MetallicRoughness.png");
|
||||
|
||||
REQUIRE_FALSE(model.images[0].image.empty());
|
||||
REQUIRE_FALSE(model.images[1].image.empty());
|
||||
|
||||
ok = ctx.WriteGltfSceneToFile(&model, "Cube.gltf");
|
||||
REQUIRE(ok);
|
||||
|
||||
for (const auto& image : model.images) {
|
||||
std::fstream file(image.uri);
|
||||
CHECK(file.good());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("images-as-is", "[issue-487]") {
|
||||
std::string err;
|
||||
std::string warn;
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
ctx.SetImagesAsIs(true);
|
||||
bool ok = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Cube/Cube.gltf");
|
||||
REQUIRE(ok);
|
||||
REQUIRE(err.empty());
|
||||
REQUIRE(warn.empty());
|
||||
|
||||
for (const auto& image : model.images) {
|
||||
CHECK(image.as_is == true);
|
||||
CHECK_FALSE(image.uri.empty());
|
||||
CHECK_FALSE(image.image.empty());
|
||||
|
||||
#ifndef TINYGLTF_NO_STB_IMAGE
|
||||
// Make sure we can decode the images
|
||||
int w = -1, h = -1, component = -1;
|
||||
unsigned char *data = stbi_load_from_memory(image.image.data(), static_cast<int>(image.image.size()), &w, &h, &component, 0);
|
||||
CHECK(data != nullptr);
|
||||
CHECK(w == 512);
|
||||
CHECK(h == 512);
|
||||
CHECK(component >= 3);
|
||||
stbi_image_free(data);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Write glTF model to disk, and images as separate files
|
||||
{
|
||||
ok = ctx.WriteGltfSceneToFile(&model, "Cube_with_image_files.gltf");
|
||||
REQUIRE(ok);
|
||||
|
||||
// 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());
|
||||
#ifndef TINYGLTF_NO_STB_IMAGE
|
||||
// Make sure we can load the images
|
||||
int w = -1, h = -1, component = -1;
|
||||
unsigned char *data = stbi_load(image.uri.c_str(), &w, &h, &component, 0);
|
||||
CHECK(data != nullptr);
|
||||
CHECK(w == 512);
|
||||
CHECK(h == 512);
|
||||
CHECK(component >= 3);
|
||||
stbi_image_free(data);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Write glTF model to disk, and embed images as data URIs
|
||||
{
|
||||
ok = ctx.WriteGltfSceneToFile(&model, "Cube_with_embedded_images.gltf", true, false);
|
||||
REQUIRE(ok);
|
||||
|
||||
// Load above model again, and check if the images are loaded properly
|
||||
tinygltf::Model embeddedImages;
|
||||
ctx.SetImagesAsIs(false);
|
||||
bool ok = ctx.LoadASCIIFromFile(&embeddedImages, &err, &warn, "Cube_with_embedded_images.gltf");
|
||||
REQUIRE(ok);
|
||||
REQUIRE(err.empty());
|
||||
REQUIRE(warn.empty());
|
||||
|
||||
for (const auto& image : embeddedImages.images) {
|
||||
CHECK(image.as_is == false);
|
||||
CHECK_FALSE(image.mimeType.empty());
|
||||
CHECK_FALSE(image.image.empty());
|
||||
CHECK(image.width == 512);
|
||||
CHECK(image.height == 512);
|
||||
CHECK(image.component >= 3);
|
||||
}
|
||||
}
|
||||
|
||||
// Write glTF model to disk, as GLB
|
||||
{
|
||||
ok = ctx.WriteGltfSceneToFile(&model, "Cube.glb", true, true, true, true);
|
||||
REQUIRE(ok);
|
||||
|
||||
// Load above model again, and check if the images are loaded properly
|
||||
tinygltf::Model glbModel;
|
||||
ctx.SetImagesAsIs(false);
|
||||
bool ok = ctx.LoadBinaryFromFile(&glbModel, &err, &warn, "Cube.glb");
|
||||
REQUIRE(ok);
|
||||
REQUIRE(err.empty());
|
||||
REQUIRE(warn.empty());
|
||||
|
||||
for (const auto& image : glbModel.images) {
|
||||
CHECK(image.as_is == false);
|
||||
CHECK_FALSE(image.mimeType.empty());
|
||||
CHECK_FALSE(image.image.empty());
|
||||
CHECK(image.width == 512);
|
||||
CHECK(image.height == 512);
|
||||
CHECK(image.component >= 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("inverse-bind-matrices-optional", "[issue-492]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
bool ret = ctx.LoadBinaryFromFile(&model, &err, &warn, "issue-492.glb");
|
||||
if (!warn.empty()) {
|
||||
std::cout << "WARN:" << warn << std::endl;
|
||||
}
|
||||
if (!err.empty()) {
|
||||
std::cerr << "ERR:" << err << std::endl;
|
||||
}
|
||||
|
||||
REQUIRE(true == ret);
|
||||
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);
|
||||
}
|
||||
|
||||
4
tiny_gltf.cc
Normal file
4
tiny_gltf.cc
Normal file
@@ -0,0 +1,4 @@
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "tiny_gltf.h"
|
||||
4727
tiny_gltf.h
4727
tiny_gltf.h
File diff suppressed because it is too large
Load Diff
11
wasm/Makefile
Normal file
11
wasm/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
WASI_VERSION=16
|
||||
WASI_VERSION_FULL=${WASI_VERSION}.0
|
||||
|
||||
WASI_SDK_PATH=$(HOME)/local/wasi-sdk-${WASI_VERSION_FULL}
|
||||
|
||||
CC=${WASI_SDK_PATH}/bin/clang
|
||||
CXX=${WASI_SDK_PATH}/bin/clang++
|
||||
CXXFLAGS=-fno-rtti -fno-exceptions -g -Os
|
||||
|
||||
all:
|
||||
$(CXX) ../loader_example.cc $(CXXFLAGS) -I../
|
||||
31
wasm/README.md
Normal file
31
wasm/README.md
Normal file
@@ -0,0 +1,31 @@
|
||||
Experimental WASI/WASM build
|
||||
|
||||
## Build
|
||||
|
||||
Download wasi-sdk https://github.com/WebAssembly/wasi-sdk
|
||||
|
||||
Compile tinygltf without C++ exceptions and threads. See `Makefile` for details
|
||||
(NOTE: TinyGLTF itself does not use RTTI and threading feature(C++ threads, posix, win32 thread))
|
||||
|
||||
## Build examples and Run
|
||||
|
||||
Build `loader_example.cc`
|
||||
|
||||
```
|
||||
$ /path/to/wasi-sdk-16.0/bin/clang++ ../loader_example.cc -fno-rtti -fno-exceptions -g -Os -I../ -o loader_example.wasi
|
||||
```
|
||||
|
||||
Tested with wasmtime. https://github.com/bytecodealliance/wasmtime
|
||||
|
||||
|
||||
Set a folder containing .gltf file to `--dir`
|
||||
|
||||
```
|
||||
$ wasmtime --dir=../models loader_example.wasi ../models/Cube/Cube.gltf
|
||||
```
|
||||
|
||||
## Emscripen
|
||||
|
||||
T.B.W. ...
|
||||
|
||||
EoL.
|
||||
Reference in New Issue
Block a user