Compare commits

...

134 Commits

Author SHA1 Message Date
Syoyo Fujita
1b7994a4f4 Make lodepng optional. 2019-01-14 21:33:56 +09:00
Syoyo Fujita
c91b6468e8 Merge pull request #133 from Ybalrid/lodepng
fix ci build of example
2019-01-11 02:29:29 +09:00
Arthur Brainville (Ybalrid)
d4f8fcea10 fix ci build of example 2019-01-10 18:19:20 +00:00
Syoyo Fujita
ab069ffb40 Initial support of loading 16bit PNG using lodepng. 2019-01-07 02:27:28 +09:00
Syoyo Fujita
cbf13fef62 Merge branch 'master' into lodepng 2019-01-07 01:05:12 +09:00
Syoyo Fujita
57074aee04 Add single file version of lodepng. 2019-01-07 01:04:37 +09:00
Syoyo Fujita
af3ebb2e76 Show more expressive messages when parsing image. 2019-01-06 18:55:57 +09:00
Syoyo Fujita
105694b468 Merge pull request #129 from SaschaWillems/master
Added new compiler option for loading all gltf related files from android app asset package
2018-12-29 12:33:34 +09:00
Sascha Willems
5f9cb24245 Added new feature for loading all gltf related files (including textures, binaries, etc.) from assets packaged with an Android app 2018-12-28 20:53:41 +01:00
Syoyo Fujita
9fcd3f998e Merge pull request #127 from nyue/master
Renamed glTFConfig to TinyGLTFConfig
2018-12-28 14:31:33 +09:00
Tan Meng Yue
d96b45df06 Renamed glTFConfig to TinyGLTFConfig
This renaming is done so that the config file matches
the project name which is TinyGLTF. This is done to prevent
future name collision should the Khronos glTF project decides
to provide their own CMake configuration file.
2018-12-27 10:24:13 +11:00
Syoyo Fujita
dd7c9efbea Merge pull request #125 from nyue/master
Fix bug in handling OS X build via CMake
2018-12-25 15:06:37 +09:00
Tan Meng Yue
80a85af661 Fix bug in handling OS X build via CMake
The OS macros needs to be upper case for the
if statement to work as expected
2018-12-25 17:03:58 +11:00
Syoyo Fujita
7cf2c44ad7 Merge pull request #124 from nyue/master
Fix GLFW3 handling on CentOS
2018-12-25 11:27:33 +09:00
Nicholas Yue
f1b5bb12fd Add support for static GLFW3 library linking 2018-12-25 09:48:26 +11:00
Nicholas Yue
174334eaf4 Fix GLFW3 handling on CentOS 2018-12-25 09:15:13 +11:00
Syoyo Fujita
1212a6ee51 Update README. 2018-12-24 01:50:17 +09:00
Syoyo Fujita
8674c60781 Add document on TINYGLTF_NO_EXTERNAL_IMAGE. Fixes #123 2018-12-18 21:59:23 +09:00
Syoyo Fujita
9d89f02cf0 Merge pull request #122 from lebek/master
Fix incorrect index into bufferViews array
2018-12-09 12:23:39 +09:00
Peter Le Bek
463408c4a0 Fix incorrect index into bufferViews array 2018-12-08 16:04:42 -08:00
Syoyo Fujita
a9d862aeee Merge pull request #119 from nyue/master
Add CMake package for developer
2018-12-07 18:48:14 +09:00
Tan Meng Yue
2123da775b Add CMake package for developer
Added the glTFConfig.cmake file so that once
installed, it is easy for developers to find
all the path location for include purposes.
2018-12-07 20:45:13 +11:00
Syoyo Fujita
20806b27d7 Merge pull request #118 from nyue/master
Added more CMake support
2018-12-07 16:07:16 +09:00
Tan Meng Yue
94fcfdeb9d Added installation of headers and target binaries 2018-12-07 18:01:08 +11:00
Syoyo Fujita
d44b6e7bcc Merge pull request #117 from viperscape/master
Fill in missing bufferView targets
2018-12-06 11:20:18 +09:00
viperscape
9df05806ad find missing bufferView target types and fill them in 2018-12-05 14:11:01 -05:00
Chris Gill
93db9e20c0 Merge pull request #1 from syoyo/master
update to latest
2018-12-05 13:03:44 -05:00
Syoyo Fujita
2c5597f591 Merge pull request #115 from Selmar/serialization_fixes
some serialization fixes
2018-12-06 02:05:26 +09:00
Tan Meng Yue
2dcf79566f Add CMake configuration for glview
So that we can build more of the examples consistently
with CMake
2018-12-05 23:56:23 +11:00
Tan Meng Yue
f20888ae8b Added top level CMake configuration file 2018-12-05 23:55:53 +11:00
Selmar Kok
5892d3e3ea Set a default for sampler.wrapR, because it was serializing an uninitialized value 2018-12-04 19:55:56 +01:00
Selmar Kok
27aab61d62 Fix prettyprint to really not print pretty 2018-11-30 18:01:31 +01:00
Syoyo Fujita
d80f0f9a6c Merge pull request #111 from viperscape/master
This is a basic example I added after figuring out how to use the tinygltf library
2018-11-16 14:01:13 +09:00
Syoyo Fujita
5110820ebb Merge pull request #110 from AlvaroBarua/warnings_cleanup
Removed unreachable code and fixed ambiguity warning.
2018-11-16 14:00:33 +09:00
viperscape
c3e34c2ff7 add screenshot 2018-11-15 17:03:38 -05:00
viperscape
0ddfaead8f add basic example 2018-11-15 17:02:20 -05:00
Unknown
ae2cf8e26f Removed unreachable code and fixed ambiguity warning. 2018-11-15 18:36:59 +00:00
Syoyo Fujita
8b7cdde30c Merge pull request #109 from viperscape/master
Windows build with provided VS solution
2018-11-15 00:28:06 +09:00
viperscape
764bcb5a8a add win32 includes 2018-11-14 10:19:39 -05:00
viperscape
50ada7ff11 rework to include VS 2017 project, fully configured and tested 2018-11-14 10:15:58 -05:00
Syoyo Fujita
16fae080f9 Merge branch 'master' of github.com:syoyo/tinygltf 2018-11-10 20:08:02 +09:00
Syoyo Fujita
90c0008b0e Merge branch 'loomai-master' 2018-11-10 20:07:47 +09:00
Syoyo Fujita
b572650d26 Merge branch 'master' of https://github.com/loomai/tinygltf into loomai-master 2018-11-10 20:07:15 +09:00
Syoyo Fujita
6af9e886cd Merge pull request #107 from Selmar/serialization_fixes
Add missing serialization of `sampler.wrapR`
2018-11-10 02:32:56 +09:00
Selmar Kok
60f97325b1 Merge remote-tracking branch 'origin/master' into serialization_fixes 2018-11-09 10:34:55 +01:00
Selmar Kok
a3595488e3 Fix missing serialization: sampler.wrapR 2018-11-09 10:34:39 +01:00
Syoyo Fujita
cf60322e73 Merge pull request #105 from rapidimages/bugfix/write_image_to_disk
Fixed a reference error which cause an error when writing images to disk
2018-11-07 00:56:34 +09:00
Johan Bowald
77decfaff8 fixed a reference error which cause an error when writing images to disk 2018-11-06 14:28:20 +01:00
Syoyo Fujita
e26117e026 Merge branch 'master' of github.com:syoyo/tinygltf 2018-11-05 13:33:27 +09:00
Syoyo Fujita
33514af61a Fix logic error. Fixes #104 2018-11-05 13:32:43 +09:00
Syoyo Fujita
ba3c3c99ef Merge pull request #102 from 1div0/master
Building glview failed
2018-10-28 15:30:21 +09:00
Syoyo Fujita
8d96b4a14e Merge pull request #103 from Selmar/serialization_fixes
[serialization] handle failing buffer file writes
2018-10-26 02:12:24 +09:00
Selmar Kok
1cef6dcf33 Merge remote-tracking branch 'origin/master' into serialization_fixes 2018-10-25 16:48:14 +02:00
Selmar Kok
e46774940c fail serialization if a buffer file fails to be written (e.g. due to access rights) 2018-10-25 16:45:49 +02:00
Peter Kovář
dddaee695d Merge branch 'master' of https://github.com/1div0/tinygltf 2018-10-17 15:30:33 +02:00
Peter Kovář
a645cfc840 Added include directory ../common/ for trackball.h 2018-10-17 15:29:56 +02:00
Peter Kovář
040310e0d3 Added include direectory ../common/ for trackball.h 2018-10-17 15:24:59 +02:00
Syoyo Fujita
d9eddbfeb9 Merge pull request #101 from 1div0/master
make lint
2018-10-16 19:11:17 +09:00
Peter Kovář
10365a53ff Fixed make lint 2018-10-16 12:03:45 +02:00
Peter Kovář
d0e293fd7d Fixed typos 2018-10-16 12:00:24 +02:00
Syoyo Fujita
3b25d9130a Merge pull request #100 from Selmar/serialization_fixes
yet another serialization fix
2018-10-11 01:25:12 +09:00
Selmar Kok
db7f4e4d04 fix an issue when serializing an empty extension object would serialize as type null (and thus deserialize as type null, causing it to be ignored) 2018-10-10 18:10:58 +02:00
Syoyo Fujita
30bbe0fe3c Merge pull request #99 from Selmar/serialization_fixes
Pretty print & some (de)serialization fixes
2018-10-09 02:12:38 +09:00
Selmar Kok
ee3d06646d // pretty print as optional parameter, default true
// serialize name instead of type for camera.name
// create empy Value::Object if extension value parsing failed
2018-10-08 16:20:43 +02:00
Syoyo Fujita
924d86e362 Serialize extension with empty object. Fixes #97
Use pretty printing JSON when serializing for the readability.
2018-10-08 21:18:33 +09:00
Syoyo Fujita
68353f1b34 Merge branch 'master' of github.com:syoyo/tinygltf 2018-10-07 20:35:14 +09:00
Syoyo Fujita
05a8d0bc52 Fix premake script. 2018-10-07 20:34:45 +09:00
Syoyo Fujita
39a263c2a8 Merge branch 'master' of github.com:syoyo/tinygltf 2018-10-06 03:20:31 +09:00
Syoyo Fujita
61673a62ef Update README. 2018-10-06 03:20:11 +09:00
Syoyo Fujita
fdf105645b Merge pull request #96 from Selmar/serialization_fixes
Serialization & comparison fixes
2018-10-06 01:36:27 +09:00
Selmar Kok
440cb1e66b tabs to spaces 2018-10-05 16:30:50 +02:00
Selmar Kok
c884e5827e better implementation for bin file name checking 2018-10-05 16:25:54 +02:00
Selmar Kok
7cb31e4e23 - support writing multiple bin files
- use existing buffer.uri as filename if not empty and not a data uri
2018-10-05 16:02:29 +02:00
Selmar Kok
2bda71c8fb - always check Parameter::number_value to catch user errors, e.g. setting number_value without setting has_number_value, which will cause it to serialize as a bool but read back in as a float anyway 2018-10-05 14:36:05 +02:00
Selmar Kok
13b6402388 Merge branch 'master' of github.com:syoyo/tinygltf into serialization_fixes 2018-10-05 14:30:16 +02:00
Selmar Kok
8eb3904de2 - Parse image extras property
- Optionally serialize texture.source (it is not required in the current spec)
2018-10-05 14:29:35 +02:00
Syoyo Fujita
b5a72a1ba2 Remove duplicated files. 2018-10-04 15:48:17 +09:00
Syoyo Fujita
0820d83a9d Update to v2.0.1 2018-10-04 15:45:13 +09:00
Syoyo Fujita
641b3ccf8c Suppress clang warnings.
Apply clang-format.
2018-10-04 15:43:33 +09:00
Syoyo Fujita
7518334044 Merge pull request #95 from Selmar/equality_operator_and_some_additions
Equality operator and some additions
2018-10-04 13:56:35 +09:00
Syoyo Fujita
efc919c022 Merge branch 'master' into devel 2018-10-04 13:55:21 +09:00
Selmar Kok
fa0a998a8b Merge branch 'master' of github.com:syoyo/tinygltf into equality_operator_and_some_additions
# Conflicts:
#	tiny_gltf.h
2018-10-03 15:46:23 +02:00
Selmar Kok
31cb7f92d8 // equality operator for tinygltf::Model and types contained by it
// double comparison (although perhaps not necessary, as json reads/writes bytes directly? unsure..)
// initialize some variables for operator==() reliabiltiy
// change some floats to doubles
// intellisense define
// serialize accessor.name
// dont serialize some names if they're empty
// return false if writing gltf file fails
2018-10-03 15:39:05 +02:00
Syoyo Fujita
e59dd6a5c0 Update TODOs. 2018-09-25 03:03:49 +09:00
Syoyo Fujita
e66d8c992f Add as-is flag to Image. Tentative solution for issue #82 2018-09-02 16:58:43 +09:00
Syoyo Fujita
3e53feb046 Parse extensions property of Image. 2018-09-02 15:36:17 +09:00
Syoyo Fujita
9ec7109089 Bump clang version from 3.7 to 3.9 since clang-3.7 apt source is untrusted. 2018-08-30 21:27:11 +09:00
David Harmon
da9eac2fbe Enable support for writing binary glTF. 2018-08-30 08:06:05 -04:00
Syoyo Fujita
5cf22e3abc Merge branch 'master' of github.com:syoyo/tinygltf 2018-08-28 21:34:06 +09:00
Syoyo Fujita
a8f0b1c383 Suppress unknown pragma warning on clang 3.7 2018-08-28 21:33:40 +09:00
Syoyo Fujita
098dfee982 Merge pull request #92 from walf443/respect_stb_image_write_error
handling stbi_write_xxx_to_func return code
2018-08-28 21:33:07 +09:00
Keiji Yoshimi
c0cfc1ed95 handling stbi_write_xxx_to_func return code 2018-08-28 21:13:03 +09:00
Syoyo Fujita
be718436c1 Merge pull request #90 from victorbush/force_32bit_tex
Force default image loader to use 32-bit images
2018-08-23 12:51:43 +09:00
Victor Bushong
18ef338ff5 Force default image loader to use 32-bit images for Vulkan compatibility. 2018-08-22 22:03:30 -05:00
Syoyo Fujita
1d0bd6c64f Merge pull request #89 from Selmar/missing_bin_to_error_message
missing bin files are reported as warning instead of error
2018-08-23 02:16:10 +09:00
Selmar Kok
e3b3fa9eb6 add required parameter to LoadExternalFile 2018-08-22 19:04:21 +02:00
Selmar Kok
cda38e03ed change from warning to error for missing bin files 2018-08-22 18:26:10 +02:00
Syoyo Fujita
fcdfc71ba6 Merge pull request #88 from Selmar/forward_declare_dataUri_utils
forward declare DataURI helpers
2018-08-22 21:36:16 +09:00
Selmar Kok
0d0e97e8cd forward declare DataURI helper functions to allow usage outside of implementation file (in case of custom image handling) 2018-08-22 14:01:57 +02:00
Syoyo Fujita
dfc3545d79 Fix unit test.
Update README.
2018-08-22 20:35:04 +09:00
Syoyo Fujita
1898f10836 Merge branch 'devel' 2018-08-22 20:30:52 +09:00
Syoyo Fujita
96d2f314cd Merge pull request #86 from mosra/fail-when-bin-missing-from-glb
Properly fail also when external *.bin are missing from *.glb.
2018-08-17 19:52:09 +09:00
Vladimír Vondruš
fd84ceb791 Properly fail also when external *.bin are missing from *.glb.
Consistency with behavior for external *.bin files referenced from
*.gltf.
2018-08-16 21:07:56 +02:00
Syoyo Fujita
6d38ca3894 Merge branch 'devel' of github.com:syoyo/tinygltf into devel 2018-08-16 15:57:28 +09:00
Syoyo Fujita
a6802d10fb Fix typo(n2.z -> n1.z) 2018-08-16 15:56:13 +09:00
Syoyo Fujita
28dc902368 Add link to px_render. 2018-08-09 01:58:40 +09:00
Syoyo Fujita
7c8d4ed748 Added 'warning' message parameter to glTF loader API.
Asset loading failure messages(e.g. image file is missing) are now stored in `warning` message, not `error` message.
2018-07-27 16:49:10 +09:00
Syoyo Fujita
a71be9cc98 Merge pull request #80 from mosra/texture-name
Import texture names as well
2018-07-25 13:51:41 +09:00
Syoyo Fujita
8c29e35b42 Merge pull request #81 from mosra/emscripten-file-paths
Don't try to expand file paths on Emscripten.
2018-07-25 13:51:00 +09:00
Vladimír Vondruš
9f04583280 Don't try to expand file paths on Emscripten.
Since the same is done on all mobile platforms already, I think it
should not do any harm. Without this I was getting compilation/linker
errors.
2018-07-24 23:32:17 +02:00
Vladimír Vondruš
239be2c09f Import texture names as well.
Every other structure has it already.
2018-07-24 23:23:56 +02:00
Syoyo Fujita
39abfb5f91 Consider Data URI buffers in binary. Fixes #79. 2018-07-11 02:46:52 +09:00
Syoyo Fujita
81bbf86e2a Merge pull request #78 from UberLambda/devel
Added filesystem callback support (#77)
2018-07-08 15:17:13 +09:00
Paolo Jovon
b2a587af96 Fixed C++11 compliance of previous commit 2018-07-07 21:50:01 +02:00
Paolo Jovon
e6601bfb4b Added filesystem callback support
Now a library like PhysFS can be used to load files by defining custom
callbacks and disabling the builtin ones by #define TINYGLTF_NO_FS
2018-07-07 20:43:33 +02:00
Syoyo Fujita
90e2c9cc74 Merge pull request #76 from mynz/devel
parse extras on the root object
2018-06-28 20:25:23 +02:00
mynz
c0d4d1c50c parse extras on the root object 2018-06-28 23:06:00 +09:00
Syoyo Fujita
0f282f7e26 Merge pull request #75 from holzon/fix/allextras
Adding missing extras field serializaton
2018-06-04 19:07:49 +09:00
Jens Olsson
b3af2f1cf6 adding missing extras field serializaton 2018-06-04 11:56:00 +02:00
Syoyo Fujita
4769b1ca37 Apply clang-format. 2018-06-04 18:40:16 +09:00
Syoyo Fujita
0067a9e43a Support gltf-buffer mime.
Make `min` and `max` parameters in `Accessor` optional.
2018-06-04 18:26:05 +09:00
Syoyo Fujita
57f8e7ca3b Correctly handle filename containing spaces for external resources. Fixes #74. 2018-06-04 17:52:08 +09:00
Syoyo Fujita
a48f12d2fc Merge pull request #73 from holzon/fix/extras
Added missing extras serialization for nodes
2018-05-24 23:59:56 +09:00
Jens Olsson
a9718668b4 fixing typo 2018-05-24 15:48:49 +02:00
Jens Olsson
b96f6966ab added missing extras serialization for nodes 2018-05-24 15:29:54 +02:00
Syoyo Fujita
7c56f8eb9e Merge pull request #69 from benbuzbee/serialization-fixes
Serialization fixes for single-number values and integers
2018-04-26 14:06:18 +09:00
Ben Buzbee
f6af224135 Remove use of optional 2018-04-25 15:13:05 -07:00
Ben Buzbee
3b735bb878 Serialization fixes 2018-04-24 11:39:30 -07:00
Syoyo Fujita
2d17a31d3b typedef struct -> struct for enabling forward declarations of struct. 2018-04-17 15:45:42 +09:00
Syoyo Fujita
48f6db0994 Suppress clang warnings. 2018-04-15 18:40:55 +09:00
Syoyo Fujita
c89fc5f06b Describe supported VS 2015 update revision. 2018-04-12 11:52:14 +09:00
Syoyo Fujita
1e629c8efe Fix printing accessor.min and accessor.max in loader_example.
Initial support for printing extensions(no pretty printing at the moment).
Merge branch 'generic_extension_support' of https://github.com/Selmar/tinygltf into Selmar-generic_extension_support
2018-04-05 15:37:57 +09:00
Selmar Kok
341fc31aee Merge remote-tracking branch 'origin/devel' into generic_extension_support
# Conflicts:
#	tiny_gltf.h
2018-04-04 18:34:30 +02:00
Syoyo Fujita
5307850555 Update README. 2017-06-21 19:27:18 +09:00
48 changed files with 10169 additions and 812 deletions

View File

@@ -7,15 +7,15 @@ matrix:
sources:
- george-edison55-precise-backports
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.7
- llvm-toolchain-trusty-3.9
packages:
- g++-4.9
- clang-3.7
- clang-3.9
compiler: clang
env: COMPILER_VERSION=3.7 BUILD_TYPE=Debug
env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug
- addons: *1
compiler: clang
env: COMPILER_VERSION=3.7 BUILD_TYPE=Release
env: COMPILER_VERSION=3.9 BUILD_TYPE=Release
- addons: &2
apt:
sources:
@@ -30,7 +30,7 @@ matrix:
env: COMPILER_VERSION=4.9 BUILD_TYPE=Release EXTRA_CXXFLAGS="-fsanitize=address"
- addons: *1
compiler: clang
env: COMPILER_VERSION=3.7 BUILD_TYPE=Debug CFLAGS="-O0" CXXFLAGS="-O0"
env: COMPILER_VERSION=3.9 BUILD_TYPE=Debug CFLAGS="-O0" CXXFLAGS="-O0"
before_install:
- ./.travis-before-install.sh

28
CMakeLists.txt Normal file
View File

@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.6)
PROJECT (tinygltf)
SET(CMAKE_CXX_STANDARD 11)
ADD_EXECUTABLE ( loader_example
loader_example.cc
)
ADD_SUBDIRECTORY ( examples/gltfutil )
ADD_SUBDIRECTORY ( examples/glview )
ADD_SUBDIRECTORY ( examples/validator )
INSTALL ( FILES
json.hpp
stb_image.h
stb_image_write.h
tiny_gltf.h
DESTINATION
include
)
INSTALL ( FILES
cmake/TinyGLTFConfig.cmake
DESTINATION
cmake
)

21
LICENSE.lodepng Normal file
View File

@@ -0,0 +1,21 @@
Copyright (c) 2005-2018 Lode Vandevenne
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.

View File

@@ -1,9 +1,9 @@
# Use this for strict compilation check(will work on clang 3.8+)
#EXTRA_CXXFLAGS := -fsanitize=address -Wall -Werror -Weverything -Wno-c++11-long-long
#EXTRA_CXXFLAGS := -fsanitize=address -Wall -Werror -Weverything -Wno-c++11-long-long -Wno-c++98-compat
all:
clang++ $(EXTRA_CXXFLAGS) -std=c++11 -g -O0 -o loader_example loader_example.cc
lint:
./cpplint.py tiny_gltf_loader.h
deps/cpplint.py tiny_gltf.h

View File

@@ -2,13 +2,13 @@
`TinyGLTF` is a header only C++11 glTF 2.0 https://github.com/KhronosGroup/glTF library.
## Status
Work in process(`devel` branch). Very near to release, but need more tests and examples.
`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.
## Status
v2.0.0 release(22 Aug, 2018)!
## Builds
[![Build Status](https://travis-ci.org/syoyo/tinygltf.svg?branch=devel)](https://travis-ci.org/syoyo/tinygltf)
@@ -22,8 +22,9 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
* [x] iOS + clang
* [x] Linux + gcc/clang
* [x] Windows + MinGW
* [x] Windows + Visual Studio 2015 or later.
* [x] Windows + Visual Studio 2015 Update 3 or later.
* Visual Studio 2013 is not supported since they have limited C++11 support and failed to compile `json.hpp`.
* [x] Android NDK
* [x] Android + CrystaX(NDK drop-in replacement) GCC
* [x] Web using Emscripten(LLVM)
* Moderate parsing time and memory consumption.
@@ -32,15 +33,19 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
* [x] Binary glTF(GLB)
* [x] PBR material description
* Buffers
* [x] Parse BASE64 encoded embedded buffer fata(DataURI).
* [x] Parse BASE64 encoded embedded buffer data(DataURI).
* [x] Load `.bin` file.
* Image(Using stb_image)
* [x] Parse BASE64 encoded embedded image fata(DataURI).
* [x] Parse BASE64 encoded embedded image data(DataURI).
* [x] Load external image file.
* [x] PNG(8bit only)
* [x] JPEG(8bit only)
* [x] BMP
* [x] GIF
* [x] Custom Image decoder callback(e.g. for decoding OpenEXR image)
* Load from memory
* Custom callback handler
* [x] Image load
## Examples
@@ -49,6 +54,7 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
## Projects using TinyGLTF
* px_render Single header C++ Libraries for Thread Scheduling, Rendering, and so on... https://github.com/pplux/px
* Physical based rendering with Vulkan using glTF 2.0 models https://github.com/SaschaWillems/Vulkan-glTF-PBR
* GLTF loader plugin for OGRE 2.1. Support for PBR materials via HLMS/PBS https://github.com/Ybalrid/Ogre_glTF
* [TinyGltfImporter](http://doc.magnum.graphics/magnum/classMagnum_1_1Trade_1_1TinyGltfImporter.html) plugin for [Magnum](https://github.com/mosra/magnum), a lightweight and modular C++11/C++14 graphics middleware for games and data visualization.
@@ -56,13 +62,15 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
## TODOs
* [ ] Write C++ code generator from jSON schema for robust parsing.
* [x] Serialization
* [ ] Compression/decompression(Open3DGC, etc)
* [ ] Write C++ code generator which emits C++ code from JSON schema for robust parsing.
* [ ] Mesh Compression/decompression(Open3DGC, etc)
* [ ] Load Draco compressed mesh
* [ ] Support `extensions` and `extras` property
* [ ] HDR image?
* [ ] OpenEXR extension through TinyEXR.
* [ ] Write tests for `animation` and `skin`
* [ ] Write example and tests for `animation` and `skin`
* [ ] Skinning
* [ ] Morph targets
## Licenses
@@ -74,6 +82,7 @@ TinyGLTF uses the following third party libraries.
* base64 : Copyright (C) 2004-2008 René Nyffenegger
* stb_image.h : v2.08 - public domain image loader - [Github link](https://github.com/nothings/stb/blob/master/stb_image.h)
* stb_image_write.h : v1.09 - public domain image writer - [Github link](https://github.com/nothings/stb/blob/master/stb_image_write.h)
* lodepng : Copyright (c) 2005-2018 Lode Vandevenne. zlib license. https://lodev.org/lodepng/
## Build and example
@@ -95,9 +104,15 @@ using namespace tinygltf;
Model model;
TinyGLTF loader;
std::string err;
std::string warn;
bool ret = loader.LoadASCIIFromFile(&model, &err, argv[1]);
//bool ret = loader.LoadBinaryFromFile(&model, &err, argv[1]); // for binary glTF(.glb)
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, argv[1]);
//bool ret = loader.LoadBinaryFromFile(&model, &err, &warn, argv[1]); // for binary glTF(.glb)
if (!warn.empty()) {
printf("Warn: %s\n", warn.c_str());
}
if (!err.empty()) {
printf("Err: %s\n", err.c_str());
}
@@ -113,6 +128,9 @@ if (!ret) {
* `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.
* `TINYGLTF_NO_STB_IMAGE` : Do not load images with stb_image. Instead use `TinyGLTF::SetImageLoader(LoadimageDataFunction LoadImageData, void *user_data)` to set a callback for loading images.
* `TINYGLTF_NO_STB_IMAGE_WRITE` : Do not write images with stb_image_write. Instead use `TinyGLTF::SetImageWriter(WriteimageDataFunction WriteImageData, void *user_data)` to set a callback for writing images.
* `TINYGLTF_NO_EXTERNAL_IMAGE` : Do not try to load external image file. This option woulde be helpful if you do not want load image file during glTF parsing.
* `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_USE_LODEPNG` : Load 16bit PNG image with lodepng(Valid when `TINYGLTF_NO_STB_IMAGE` was **not** defined). Must defined `LODEPNG_IMPLEMENTATION` in one .cc.
### Saving gltTF 2.0 model
* [ ] Buffers.
@@ -154,4 +172,5 @@ $ ./tester_noexcept
* 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.
* lodepng : zlib license
* catch : Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. Distributed under the Boost Software License, Version 1.0.

View File

@@ -0,0 +1,15 @@
# -*- 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 ()

7
examples/basic/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
.vs
Debug
x64
packages
!*.sln
!*.vcxproj*

View File

@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2050
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "basic", "basic.vcxproj", "{0589AC44-0CF3-40D8-8D89-68393CFD40F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Debug|x64.ActiveCfg = Debug|x64
{0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Debug|x64.Build.0 = Debug|x64
{0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Debug|x86.ActiveCfg = Debug|Win32
{0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Debug|x86.Build.0 = Debug|Win32
{0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Release|x64.ActiveCfg = Release|x64
{0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Release|x64.Build.0 = Release|x64
{0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Release|x86.ActiveCfg = Release|Win32
{0589AC44-0CF3-40D8-8D89-68393CFD40F3}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {055E97C4-43DC-41B4-8D61-4FDDBC7B1EF7}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{0589AC44-0CF3-40D8-8D89-68393CFD40F3}</ProjectGuid>
<RootNamespace>basic</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.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>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</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>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\main.cpp" />
<ClCompile Include="..\shaders.cpp" />
<ClCompile Include="..\window.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\shaders.h" />
<ClInclude Include="..\window.h" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="packages\nupengl.core.redist.0.1.0.1\build\native\nupengl.core.redist.targets" Condition="Exists('packages\nupengl.core.redist.0.1.0.1\build\native\nupengl.core.redist.targets')" />
<Import Project="packages\nupengl.core.0.1.0.1\build\native\nupengl.core.targets" Condition="Exists('packages\nupengl.core.0.1.0.1\build\native\nupengl.core.targets')" />
<Import Project="packages\glm.0.9.9.200\build\native\glm.targets" Condition="Exists('packages\glm.0.9.9.200\build\native\glm.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\nupengl.core.redist.0.1.0.1\build\native\nupengl.core.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\nupengl.core.redist.0.1.0.1\build\native\nupengl.core.redist.targets'))" />
<Error Condition="!Exists('packages\nupengl.core.0.1.0.1\build\native\nupengl.core.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\nupengl.core.0.1.0.1\build\native\nupengl.core.targets'))" />
<Error Condition="!Exists('packages\glm.0.9.9.200\build\native\glm.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\glm.0.9.9.200\build\native\glm.targets'))" />
</Target>
</Project>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\window.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\shaders.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\window.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\shaders.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="glm" version="0.9.9.200" targetFramework="native" />
<package id="nupengl.core" version="0.1.0.1" targetFramework="native" />
<package id="nupengl.core.redist" version="0.1.0.1" targetFramework="native" />
</packages>

BIN
examples/basic/main.cpp Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

114
examples/basic/shaders.cpp Normal file
View File

@@ -0,0 +1,114 @@
#include "shaders.h"
#include <iostream>
#include <vector>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
std::string FragmentShaderCode =
"#version 330 core\n\
in vec3 normal;\n\
in vec3 position;\n\
in vec2 texcoord;\n\
\n\
uniform sampler2D tex;\n\
uniform vec3 sun_position; \n\
uniform vec3 sun_color; \n\
\n\
out vec4 color;\n\
void main() {\n\
float lum = max(dot(normal, normalize(sun_position)), 0.0);\n\
color = texture2D(tex, texcoord) * vec4((0.3 + 0.7 * lum) * sun_color, 1.0);\n\
}\n\
";
std::string VertexShaderCode =
"#version 330 core\n\
layout(location = 0) in vec3 in_vertex;\n\
layout(location = 1) in vec3 in_normal;\n\
layout(location = 2) in vec2 in_texcoord;\n\
\n\
uniform mat4 MVP;\n\
\n\
out vec3 normal;\n\
out vec3 position;\n\
out vec2 texcoord;\n\
\n\
void main(){\n\
gl_Position = MVP * vec4(in_vertex, 1);\n\
position = gl_Position.xyz;\n\
normal = normalize(mat3(MVP) * in_normal);\n\
position = in_vertex;\n\
texcoord = in_texcoord;\n\
}";
Shaders::Shaders()
{
// Create the shaders
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
GLint Result = GL_FALSE;
int InfoLogLength;
// Compile Vertex Shader
char const * VertexSourcePointer = VertexShaderCode.c_str();
glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
glCompileShader(VertexShaderID);
// Check Vertex Shader
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
if (InfoLogLength > 0) {
std::vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
printf("%s\n", &VertexShaderErrorMessage[0]);
}
// Compile Fragment Shader
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
glCompileShader(FragmentShaderID);
// Check Fragment Shader
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
if (InfoLogLength > 0) {
std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
printf("%s\n", &FragmentShaderErrorMessage[0]);
}
// Link the program
printf("Linking program\n");
GLuint ProgramID = glCreateProgram();
glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);
// Check the program
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
if (InfoLogLength > 0) {
std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
printf("%s\n", &ProgramErrorMessage[0]);
}
glDetachShader(ProgramID, VertexShaderID);
glDetachShader(ProgramID, FragmentShaderID);
glDeleteShader(VertexShaderID);
glDeleteShader(FragmentShaderID);
this->pid = ProgramID;
}
Shaders::~Shaders()
{
}

13
examples/basic/shaders.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
#include <GL/glew.h>
#include <GLFW/glfw3.h>
class Shaders
{
public:
GLuint pid;
Shaders();
~Shaders();
};

27
examples/basic/window.cpp Normal file
View File

@@ -0,0 +1,27 @@
#include "window.h"
Window::Window(int x, int y, const char* title)
{
GLFWwindow* window = glfwCreateWindow(x, y, title, NULL, NULL);
this->window = window;
}
Window::~Window()
{
glfwDestroyWindow(this->window);
}
void Window::Resize()
{
GLint w, h;
glfwGetWindowSize(this->window, &w, &h);
glViewport(0, 0, w, h);
}
int Window::Close()
{
return glfwWindowShouldClose(this->window);
}

15
examples/basic/window.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include <GLFW/glfw3.h>
class Window
{
public:
GLFWwindow* window;
Window(int x, int y, const char* title);
~Window();
void Resize();
int Close();
};

View File

@@ -7,3 +7,9 @@ include_directories(../../)
file(GLOB gltfutil_sources *.cc *.h)
add_executable(gltfutil ${gltfutil_sources})
install ( TARGETS
gltfutil
DESTINATION
bin
)

View File

@@ -69,13 +69,14 @@ int parse_args(int argc, char** argv) {
tinygltf::TinyGLTF loader;
tinygltf::Model model;
std::string error;
std::string warning;
bool state;
switch (detectType(config.input_path)) {
case FileType::Ascii:
state = loader.LoadASCIIFromFile(&model, &error, config.input_path);
state = loader.LoadASCIIFromFile(&model, &error, &warning, config.input_path);
break;
case FileType::Binary:
state = loader.LoadBinaryFromFile(&model, &error, config.input_path);
state = loader.LoadBinaryFromFile(&model, &error, &warning, config.input_path);
break;
case FileType::Unknown:
default:

View File

@@ -1,4 +1,5 @@
#include <iostream>
#include <algorithm>
#include "stb_image_write.h"
#include "texture_dumper.h"

7
examples/glview/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
.vs
Debug
x64
packages
!*.sln
!*.vcxproj*

View File

@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.6)
project(glview)
set ( CMAKE_PREFIX_PATH cmake )
find_package ( GLEW REQUIRED )
find_package ( GLFW3 REQUIRED )
find_package ( OpenGL REQUIRED )
if (APPLE)
find_library(COCOA_LIBRARY Cocoa)
find_library(COREVIDEO_LIBRARY CoreVideo)
find_library(IOKIT_LIBRARY IOKit)
else ()
if (NOT WIN32)
# This means it is Unices
set ( GLFW3_UNIX_LINK_LIBRARIES X11 Xxf86vm Xrandr Xi Xinerama Xcursor )
find_package (Threads)
endif()
endif (APPLE)
set(CMAKE_CXX_STANDARD 11)
include_directories(
../../
../common
# ${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${GLFW3_INCLUDE_DIR}
)
add_executable(glview
glview.cc
../common/trackball.cc
)
target_link_libraries ( glview
${GLFW3_UNIX_LINK_LIBRARIES}
${GLEW_LIBRARY}
${GLFW3_glfw_LIBRARY}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
${COCOA_LIBRARY}
${COREVIDEO_LIBRARY}
${IOKIT_LIBRARY}
${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT}
)
install ( TARGETS
glview
DESTINATION
bin
)

View File

@@ -0,0 +1,71 @@
#-*-cmake-*-
#
# yue.nicholas@gmail.com
#
# This auxiliary CMake file helps in find the glfw3 headers and libraries
#
# GLFW3_FOUND set if glfw3 is found.
# GLFW3_INCLUDE_DIR glfw3's include directory
# GLFW3_LIBRARY_DIR glfw3's library directory
# GLFW3_LIBRARIES all glfw3 libraries
FIND_PACKAGE (Threads)
FIND_PACKAGE ( PackageHandleStandardArgs )
FIND_PATH( GLFW3_LOCATION include/GLFW/glfw3.h
"$ENV{GLFW3_HOME}"
)
FIND_PACKAGE_HANDLE_STANDARD_ARGS ( GLFW3
REQUIRED_VARS GLFW3_LOCATION
)
IF (GLFW3_FOUND)
SET( GLFW3_INCLUDE_DIR "${GLFW3_LOCATION}/include" CACHE STRING "GLFW3 include path")
IF (GLFW3_USE_STATIC_LIBS)
FIND_LIBRARY ( GLFW3_glfw_LIBRARY libglfw3.a ${GLFW3_LOCATION}/lib
)
ELSE (GLFW3_USE_STATIC_LIBS)
# On windows build, we need to look for glfw3
IF (WIN32)
SET ( GLFW3_LIBRARY_NAME glfw3 )
ELSE ()
SET ( GLFW3_LIBRARY_NAME glfw )
ENDIF()
FIND_LIBRARY ( GLFW3_glfw_LIBRARY ${GLFW3_LIBRARY_NAME} ${GLFW3_LOCATION}/lib
)
ENDIF (GLFW3_USE_STATIC_LIBS)
IF (APPLE)
FIND_LIBRARY ( COCOA_LIBRARY Cocoa )
FIND_LIBRARY ( IOKIT_LIBRARY IOKit )
FIND_LIBRARY ( COREVIDEO_LIBRARY CoreVideo )
ELSEIF (UNIX AND NOT APPLE)
SET ( GLFW3_REQUIRED_X11_LIBRARIES
X11
Xi
Xrandr
Xinerama
Xcursor
Xxf86vm
m
${CMAKE_DL_LIBS}
${CMAKE_THREAD_LIBS_INIT}
)
ENDIF ()
SET ( GLFW3_LIBRARIES
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
${GLFW3_glfw_LIBRARY}
# UNIX
${GLFW3_REQUIRED_X11_LIBRARIES}
# APPLE
${COCOA_LIBRARY}
${IOKIT_LIBRARY}
${COREVIDEO_LIBRARY}
CACHE STRING "GLFW3 required libraries"
)
ENDIF ()

View File

@@ -12,11 +12,22 @@
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#ifdef _WIN32
#include "../common/trackball.h"
#else
#include "trackball.h"
#endif
#define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#ifdef _WIN32
#include "../../tiny_gltf.h"
#else
#include "tiny_gltf.h"
#endif
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
@@ -720,8 +731,8 @@ static void PrintNodes(const tinygltf::Scene &scene) {
int main(int argc, char **argv) {
if (argc < 2) {
std::cout << "glview input.gltf <scale>\n" << std::endl;
return 0;
std::cout << "glview input.gltf <scale>" << std::endl;
std::cout << "defaulting to example cube model" << std::endl;
}
float scale = 1.0f;
@@ -732,16 +743,29 @@ int main(int argc, char **argv) {
tinygltf::Model model;
tinygltf::TinyGLTF loader;
std::string err;
std::string input_filename(argv[1]);
std::string warn;
#ifdef _WIN32
#ifdef _DEBUG
std::string input_filename(argv[1] ? argv[1] : "../../../models/Cube/Cube.gltf");
#endif
#else
std::string input_filename(argv[1] ? argv[1] : "../../models/Cube/Cube.gltf");
#endif
std::string ext = GetFilePathExtension(input_filename);
bool ret = false;
if (ext.compare("glb") == 0) {
// assume binary glTF.
ret = loader.LoadBinaryFromFile(&model, &err, input_filename.c_str());
ret = loader.LoadBinaryFromFile(&model, &err, &warn, input_filename.c_str());
} else {
// assume ascii glTF.
ret = loader.LoadASCIIFromFile(&model, &err, input_filename.c_str());
ret = loader.LoadASCIIFromFile(&model, &err, &warn, input_filename.c_str());
}
if (!warn.empty()) {
printf("Warn: %s\n", warn.c_str());
}
if (!err.empty()) {
@@ -791,12 +815,24 @@ int main(int argc, char **argv) {
reshapeFunc(window, width, height);
GLuint vertId = 0, fragId = 0, progId = 0;
if (false == LoadShader(GL_VERTEX_SHADER, vertId, "shader.vert")) {
#ifdef _WIN32
#ifdef _DEBUG
const char *shader_frag_filename = "../shader.frag";
const char *shader_vert_filename = "../shader.vert";
#endif
#else
const char *shader_frag_filename = "shader.frag";
const char *shader_vert_filename = "shader.vert";
#endif
if (false == LoadShader(GL_VERTEX_SHADER, vertId, shader_vert_filename)) {
return -1;
}
CheckErrors("load vert shader");
if (false == LoadShader(GL_FRAGMENT_SHADER, fragId, "shader.frag")) {
if (false == LoadShader(GL_FRAGMENT_SHADER, fragId, shader_frag_filename)) {
return -1;
}
CheckErrors("load frag shader");

View File

@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2050
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glview", "glview\glview.vcxproj", "{D078BB24-377E-497B-8045-03AF2A0547ED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D078BB24-377E-497B-8045-03AF2A0547ED}.Debug|x64.ActiveCfg = Debug|x64
{D078BB24-377E-497B-8045-03AF2A0547ED}.Debug|x64.Build.0 = Debug|x64
{D078BB24-377E-497B-8045-03AF2A0547ED}.Debug|x86.ActiveCfg = Debug|Win32
{D078BB24-377E-497B-8045-03AF2A0547ED}.Debug|x86.Build.0 = Debug|Win32
{D078BB24-377E-497B-8045-03AF2A0547ED}.Release|x64.ActiveCfg = Release|x64
{D078BB24-377E-497B-8045-03AF2A0547ED}.Release|x64.Build.0 = Release|x64
{D078BB24-377E-497B-8045-03AF2A0547ED}.Release|x86.ActiveCfg = Release|Win32
{D078BB24-377E-497B-8045-03AF2A0547ED}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DB7C2F91-06C9-4BD8-95BF-04814E0C62DA}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{D078BB24-377E-497B-8045-03AF2A0547ED}</ProjectGuid>
<RootNamespace>glview</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.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>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</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>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib;glu32.lib</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib;glu32.lib</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib;glu32.lib</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);opengl32.lib;glu32.lib</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\common\trackball.cc" />
<ClCompile Include="..\glview.cc" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\nupengl.core.redist.0.1.0.1\build\native\nupengl.core.redist.targets" Condition="Exists('..\packages\nupengl.core.redist.0.1.0.1\build\native\nupengl.core.redist.targets')" />
<Import Project="..\packages\nupengl.core.0.1.0.1\build\native\nupengl.core.targets" Condition="Exists('..\packages\nupengl.core.0.1.0.1\build\native\nupengl.core.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\nupengl.core.redist.0.1.0.1\build\native\nupengl.core.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\nupengl.core.redist.0.1.0.1\build\native\nupengl.core.redist.targets'))" />
<Error Condition="!Exists('..\packages\nupengl.core.0.1.0.1\build\native\nupengl.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\nupengl.core.0.1.0.1\build\native\nupengl.core.targets'))" />
</Target>
</Project>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\glview.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\common\trackball.cc">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nupengl.core" version="0.1.0.1" targetFramework="native" />
<package id="nupengl.core.redist" version="0.1.0.1" targetFramework="native" />
</packages>

View File

@@ -8,9 +8,10 @@ solution "glview"
kind "ConsoleApp"
language "C++"
cppdialect "C++11"
files { "glview.cc", "trackball.cc" }
files { "glview.cc", "../common/trackball.cc" }
includedirs { "./" }
includedirs { "../../" }
includedirs { "../common/" }
configuration { "linux" }
linkoptions { "`pkg-config --libs glfw3`" }

View File

@@ -1,292 +0,0 @@
/*
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* Trackball code:
*
* Implementation of a virtual trackball.
* Implemented by Gavin Bell, lots of ideas from Thant Tessman and
* the August '88 issue of Siggraph's "Computer Graphics," pp. 121-129.
*
* Vector manip code:
*
* Original code from:
* David M. Ciemiewicz, Mark Grossman, Henry Moreton, and Paul Haeberli
*
* Much mucking with by:
* Gavin Bell
*/
#include <math.h>
#include "trackball.h"
/*
* This size should really be based on the distance from the center of
* rotation to the point on the object underneath the mouse. That
* point would then track the mouse as closely as possible. This is a
* simple example, though, so that is left as an Exercise for the
* Programmer.
*/
#define TRACKBALLSIZE (0.8)
/*
* Local function prototypes (not defined in trackball.h)
*/
static float tb_project_to_sphere(float, float, float);
static void normalize_quat(float[4]);
static void vzero(float *v) {
v[0] = 0.0;
v[1] = 0.0;
v[2] = 0.0;
}
static void vset(float *v, float x, float y, float z) {
v[0] = x;
v[1] = y;
v[2] = z;
}
static void vsub(const float *src1, const float *src2, float *dst) {
dst[0] = src1[0] - src2[0];
dst[1] = src1[1] - src2[1];
dst[2] = src1[2] - src2[2];
}
static void vcopy(const float *v1, float *v2) {
register int i;
for (i = 0; i < 3; i++)
v2[i] = v1[i];
}
static void vcross(const float *v1, const float *v2, float *cross) {
float temp[3];
temp[0] = (v1[1] * v2[2]) - (v1[2] * v2[1]);
temp[1] = (v1[2] * v2[0]) - (v1[0] * v2[2]);
temp[2] = (v1[0] * v2[1]) - (v1[1] * v2[0]);
vcopy(temp, cross);
}
static float vlength(const float *v) {
return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
}
static void vscale(float *v, float div) {
v[0] *= div;
v[1] *= div;
v[2] *= div;
}
static void vnormal(float *v) { vscale(v, 1.0 / vlength(v)); }
static float vdot(const float *v1, const float *v2) {
return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
}
static void vadd(const float *src1, const float *src2, float *dst) {
dst[0] = src1[0] + src2[0];
dst[1] = src1[1] + src2[1];
dst[2] = src1[2] + src2[2];
}
/*
* Ok, simulate a track-ball. Project the points onto the virtual
* trackball, then figure out the axis of rotation, which is the cross
* product of P1 P2 and O P1 (O is the center of the ball, 0,0,0)
* Note: This is a deformed trackball-- is a trackball in the center,
* but is deformed into a hyperbolic sheet of rotation away from the
* center. This particular function was chosen after trying out
* several variations.
*
* It is assumed that the arguments to this routine are in the range
* (-1.0 ... 1.0)
*/
void trackball(float q[4], float p1x, float p1y, float p2x, float p2y) {
float a[3]; /* Axis of rotation */
float phi; /* how much to rotate about axis */
float p1[3], p2[3], d[3];
float t;
if (p1x == p2x && p1y == p2y) {
/* Zero rotation */
vzero(q);
q[3] = 1.0;
return;
}
/*
* First, figure out z-coordinates for projection of P1 and P2 to
* deformed sphere
*/
vset(p1, p1x, p1y, tb_project_to_sphere(TRACKBALLSIZE, p1x, p1y));
vset(p2, p2x, p2y, tb_project_to_sphere(TRACKBALLSIZE, p2x, p2y));
/*
* Now, we want the cross product of P1 and P2
*/
vcross(p2, p1, a);
/*
* Figure out how much to rotate around that axis.
*/
vsub(p1, p2, d);
t = vlength(d) / (2.0 * TRACKBALLSIZE);
/*
* Avoid problems with out-of-control values...
*/
if (t > 1.0)
t = 1.0;
if (t < -1.0)
t = -1.0;
phi = 2.0 * asin(t);
axis_to_quat(a, phi, q);
}
/*
* Given an axis and angle, compute quaternion.
*/
void axis_to_quat(float a[3], float phi, float q[4]) {
vnormal(a);
vcopy(a, q);
vscale(q, sin(phi / 2.0));
q[3] = cos(phi / 2.0);
}
/*
* Project an x,y pair onto a sphere of radius r OR a hyperbolic sheet
* if we are away from the center of the sphere.
*/
static float tb_project_to_sphere(float r, float x, float y) {
float d, t, z;
d = sqrt(x * x + y * y);
if (d < r * 0.70710678118654752440) { /* Inside sphere */
z = sqrt(r * r - d * d);
} else { /* On hyperbola */
t = r / 1.41421356237309504880;
z = t * t / d;
}
return z;
}
/*
* Given two rotations, e1 and e2, expressed as quaternion rotations,
* figure out the equivalent single rotation and stuff it into dest.
*
* This routine also normalizes the result every RENORMCOUNT times it is
* called, to keep error from creeping in.
*
* NOTE: This routine is written so that q1 or q2 may be the same
* as dest (or each other).
*/
#define RENORMCOUNT 97
void add_quats(float q1[4], float q2[4], float dest[4]) {
static int count = 0;
float t1[4], t2[4], t3[4];
float tf[4];
vcopy(q1, t1);
vscale(t1, q2[3]);
vcopy(q2, t2);
vscale(t2, q1[3]);
vcross(q2, q1, t3);
vadd(t1, t2, tf);
vadd(t3, tf, tf);
tf[3] = q1[3] * q2[3] - vdot(q1, q2);
dest[0] = tf[0];
dest[1] = tf[1];
dest[2] = tf[2];
dest[3] = tf[3];
if (++count > RENORMCOUNT) {
count = 0;
normalize_quat(dest);
}
}
/*
* Quaternions always obey: a^2 + b^2 + c^2 + d^2 = 1.0
* If they don't add up to 1.0, dividing by their magnitued will
* renormalize them.
*
* Note: See the following for more information on quaternions:
*
* - Shoemake, K., Animating rotation with quaternion curves, Computer
* Graphics 19, No 3 (Proc. SIGGRAPH'85), 245-254, 1985.
* - Pletinckx, D., Quaternion calculus as a basic tool in computer
* graphics, The Visual Computer 5, 2-13, 1989.
*/
static void normalize_quat(float q[4]) {
int i;
float mag;
mag = (q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);
for (i = 0; i < 4; i++)
q[i] /= mag;
}
/*
* Build a rotation matrix, given a quaternion rotation.
*
*/
void build_rotmatrix(float m[4][4], const float q[4]) {
m[0][0] = 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2]);
m[0][1] = 2.0 * (q[0] * q[1] - q[2] * q[3]);
m[0][2] = 2.0 * (q[2] * q[0] + q[1] * q[3]);
m[0][3] = 0.0;
m[1][0] = 2.0 * (q[0] * q[1] + q[2] * q[3]);
m[1][1] = 1.0 - 2.0 * (q[2] * q[2] + q[0] * q[0]);
m[1][2] = 2.0 * (q[1] * q[2] - q[0] * q[3]);
m[1][3] = 0.0;
m[2][0] = 2.0 * (q[2] * q[0] - q[1] * q[3]);
m[2][1] = 2.0 * (q[1] * q[2] + q[0] * q[3]);
m[2][2] = 1.0 - 2.0 * (q[1] * q[1] + q[0] * q[0]);
m[2][3] = 0.0;
m[3][0] = 0.0;
m[3][1] = 0.0;
m[3][2] = 0.0;
m[3][3] = 1.0;
}

View File

@@ -1,75 +0,0 @@
/*
* (c) Copyright 1993, 1994, Silicon Graphics, Inc.
* ALL RIGHTS RESERVED
* Permission to use, copy, modify, and distribute this software for
* any purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright notice
* and this permission notice appear in supporting documentation, and that
* the name of Silicon Graphics, Inc. not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor
* clauses in the FAR or the DOD or NASA FAR Supplement.
* Unpublished-- rights reserved under the copyright laws of the
* United States. Contractor/manufacturer is Silicon Graphics,
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
*
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
*/
/*
* trackball.h
* A virtual trackball implementation
* Written by Gavin Bell for Silicon Graphics, November 1988.
*/
/*
* Pass the x and y coordinates of the last and current positions of
* the mouse, scaled so they are from (-1.0 ... 1.0).
*
* The resulting rotation is returned as a quaternion rotation in the
* first paramater.
*/
void trackball(float q[4], float p1x, float p1y, float p2x, float p2y);
void negate_quat(float *q, float *qn);
/*
* Given two quaternions, add them together to get a third quaternion.
* Adding quaternions to get a compound rotation is analagous to adding
* translations to get a compound translation. When incrementally
* adding rotations, the first argument here should be the new
* rotation, the second and third the total rotation (which will be
* over-written with the resulting new total rotation).
*/
void add_quats(float *q1, float *q2, float *dest);
/*
* A useful function, builds a rotation matrix in Matrix based on
* given quaternion.
*/
void build_rotmatrix(float m[4][4], const float q[4]);
/*
* This function computes a quaternion based on an axis (defined by
* the given vector) and an angle about which to rotate. The angle is
* expressed in radians. The result is put into the third argument.
*/
void axis_to_quat(float a[3], float phi, float q[4]);

View File

@@ -26,15 +26,20 @@ bool LoadGLTF(const std::string &filename, float scale,
tinygltf::Model model;
tinygltf::TinyGLTF loader;
std::string err;
std::string warn;
const std::string ext = GetFilePathExtension(filename);
bool ret = false;
if (ext.compare("glb") == 0) {
// assume binary glTF.
ret = loader.LoadBinaryFromFile(&model, &err, filename.c_str());
ret = loader.LoadBinaryFromFile(&model, &err, &warn, filename.c_str());
} else {
// assume ascii glTF.
ret = loader.LoadASCIIFromFile(&model, &err, filename.c_str());
ret = loader.LoadASCIIFromFile(&model, &err, &warn, filename.c_str());
}
if (!warn.empty()) {
std::cout << "glTF parse warning: " << warn << std::endl;
}
if (!err.empty()) {
@@ -293,7 +298,7 @@ bool LoadGLTF(const std::string &filename, float scale,
loadedMesh.facevarying_normals.push_back(n1.x);
loadedMesh.facevarying_normals.push_back(n1.y);
loadedMesh.facevarying_normals.push_back(n2.z);
loadedMesh.facevarying_normals.push_back(n1.z);
loadedMesh.facevarying_normals.push_back(n2.x);
loadedMesh.facevarying_normals.push_back(n2.y);
@@ -328,7 +333,7 @@ bool LoadGLTF(const std::string &filename, float scale,
loadedMesh.facevarying_normals.push_back(n1.x);
loadedMesh.facevarying_normals.push_back(n1.y);
loadedMesh.facevarying_normals.push_back(n2.z);
loadedMesh.facevarying_normals.push_back(n1.z);
loadedMesh.facevarying_normals.push_back(n2.x);
loadedMesh.facevarying_normals.push_back(n2.y);

View File

@@ -0,0 +1,6 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define LODEPNG_IMPLEMENTATION
#include "lodepng.h"

View File

@@ -1,3 +1,5 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define LODEPNG_IMPLEMENTATION
#include "lodepng.h"

View File

@@ -9,7 +9,7 @@ newoption {
}
sources = {
"stbi-impl.cc",
"img-loaders.cc",
"main.cc",
"render.cc",
"render-config.cc",

View File

@@ -25,13 +25,17 @@ int main(int argc, char *argv[]) {
tinygltf::Model model;
tinygltf::TinyGLTF loader;
std::string err;
std::string warn;
std::string input_filename(argv[1]);
std::string output_filename(argv[2]);
std::string embedded_filename =
output_filename.substr(0, output_filename.size() - 5) + "-Embedded.gltf";
// assume ascii glTF.
bool ret = loader.LoadASCIIFromFile(&model, &err, input_filename.c_str());
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, input_filename.c_str());
if (!warn.empty()) {
std::cout << "warn : " << warn << std::endl;
}
if (!ret) {
if (!err.empty()) {
std::cerr << err << std::endl;

View File

@@ -45,3 +45,9 @@ endif()
# test-zone
# enable_testing()
install ( TARGETS
tinygltf-validator
DESTINATION
bin
)

15
experimental/README.md Normal file
View File

@@ -0,0 +1,15 @@
# Python script which generates C++11 code from JSON schema.
## Requirements
* python3
* jsonref
## Generate
Run `gen.py` by specifing the path to glTF schema directory(from https://github.com/KhronosGroup/glTF.git)
```
$ python gen.py /path/to/glTF/specification/2.0/schema
```

34
experimental/gen.py Normal file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
import subprocess
import json
from pprint import pprint
import jsonref
# glTF 2.0
schema_files = [
"glTF.schema.json"
]
def main():
if len(sys.argv) < 2:
print("Requires path to glTF scheme directory.")
sys.exit(-1)
gltf_schema_dir = sys.argv[1]
gltf_schema_filepath = os.path.join(gltf_schema_dir, schema_files[0])
if not os.path.exists(gltf_schema_filepath):
print("File not found: {}".format(gltf_schema_filepath))
sys.exit(-1)
gltf_schema_uri = 'file://{}/'.format(gltf_schema_dir)
with open(gltf_schema_filepath) as schema_file:
j = jsonref.loads(schema_file.read(), base_uri=gltf_schema_uri, jsonschema=True)
pprint(j)
main()

View File

@@ -1,6 +1,10 @@
//
// TODO(syoyo): Print extensions and extras for each glTF object.
//
#define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define LODEPNG_IMPLEMENTATION
#include "tiny_gltf.h"
#include <cstdio>
@@ -225,7 +229,7 @@ static std::string PrintParameterMap(const tinygltf::ParameterMap &pmap) {
#endif
static std::string PrintValue(const std::string &name,
const tinygltf::Value &value, const int indent) {
const tinygltf::Value &value, const int indent, const bool tag = true) {
std::stringstream ss;
if (value.IsObject()) {
@@ -233,19 +237,45 @@ static std::string PrintValue(const std::string &name,
tinygltf::Value::Object::const_iterator it(o.begin());
tinygltf::Value::Object::const_iterator itEnd(o.end());
for (; it != itEnd; it++) {
ss << PrintValue(name, it->second, indent + 1);
ss << PrintValue(it->first, it->second, indent + 1) << std::endl;
}
} else if (value.IsString()) {
ss << Indent(indent) << name << " : " << value.Get<std::string>()
<< std::endl;
if (tag) {
ss << Indent(indent) << name << " : " << value.Get<std::string>();
} else {
ss << " " << value.Get<std::string>() << " ";
}
} else if (value.IsBool()) {
ss << Indent(indent) << name << " : " << value.Get<bool>() << std::endl;
if (tag) {
ss << Indent(indent) << name << " : " << value.Get<bool>();
} else {
ss << " " << value.Get<bool>() << " ";
}
} else if (value.IsNumber()) {
ss << Indent(indent) << name << " : " << value.Get<double>() << std::endl;
if (tag) {
ss << Indent(indent) << name << " : " << value.Get<double>();
} else {
ss << " " << value.Get<double>() << " ";
}
} else if (value.IsInt()) {
ss << Indent(indent) << name << " : " << value.Get<int>() << std::endl;
if (tag) {
ss << Indent(indent) << name << " : " << value.Get<int>();
} else {
ss << " " << value.Get<int>() << " ";
}
} else if (value.IsArray()) {
ss << Indent(indent) << name << " [ ";
for (size_t i = 0; i < value.Size(); i++) {
ss << PrintValue("", value.Get(int(i)), indent + 1, /* tag */false);
if (i != (value.ArrayLen()-1)) {
ss << ", ";
}
}
ss << Indent(indent) << "] ";
}
// @todo { binary, array }
// @todo { binary }
return ss.str();
}
@@ -303,10 +333,10 @@ static void DumpPrimitive(const tinygltf::Primitive &primitive, int indent) {
static void DumpExtensions(const tinygltf::ExtensionMap &extension, const int indent)
{
// TODO(syoyo): Print extensions
// TODO(syoyo): pritty print Value
for (auto &e : extension) {
std::cout << Indent(indent) << e.first << std::endl;
//std::cout << Indent(indent+1) << PrintParameterMap(e.second);
std::cout << PrintValue("extensions", e.second, indent+1) << std::endl;
}
}
@@ -368,7 +398,7 @@ static void Dump(const tinygltf::Model &model) {
std::cout << Indent(2) << "min : [";
for (size_t k = 0; k < accessor.minValues.size(); k++) {
std::cout << accessor.minValues[k]
<< ((i != accessor.minValues.size() - 1) ? ", " : "");
<< ((k != accessor.minValues.size() - 1) ? ", " : "");
}
std::cout << "]" << std::endl;
}
@@ -376,7 +406,7 @@ static void Dump(const tinygltf::Model &model) {
std::cout << Indent(2) << "max : [";
for (size_t k = 0; k < accessor.maxValues.size(); k++) {
std::cout << accessor.maxValues[k]
<< ((i != accessor.maxValues.size() - 1) ? ", " : "");
<< ((k != accessor.maxValues.size() - 1) ? ", " : "");
}
std::cout << "]" << std::endl;
}
@@ -488,6 +518,7 @@ static void Dump(const tinygltf::Model &model) {
std::cout << Indent(2) << "width : " << image.width << std::endl;
std::cout << Indent(2) << "height : " << image.height << std::endl;
std::cout << Indent(2) << "component : " << image.component << std::endl;
DumpExtensions(image.extensions, 1);
}
}
@@ -499,6 +530,7 @@ static void Dump(const tinygltf::Model &model) {
<< std::endl;
std::cout << Indent(1) << "source : " << texture.source
<< std::endl;
DumpExtensions(texture.extensions, 1);
}
}
@@ -571,6 +603,7 @@ int main(int argc, char **argv) {
tinygltf::Model model;
tinygltf::TinyGLTF gltf_ctx;
std::string err;
std::string warn;
std::string input_filename(argv[1]);
std::string ext = GetFilePathExtension(input_filename);
@@ -578,13 +611,18 @@ int main(int argc, char **argv) {
if (ext.compare("glb") == 0) {
std::cout << "Reading binary glTF" << std::endl;
// assume binary glTF.
ret = gltf_ctx.LoadBinaryFromFile(&model, &err, input_filename.c_str());
ret = gltf_ctx.LoadBinaryFromFile(&model, &err, &warn, input_filename.c_str());
} else {
std::cout << "Reading ASCII glTF" << std::endl;
// assume ascii glTF.
ret = gltf_ctx.LoadASCIIFromFile(&model, &err, input_filename.c_str());
ret = gltf_ctx.LoadASCIIFromFile(&model, &err, &warn, input_filename.c_str());
}
if (!warn.empty()) {
printf("Warn: %s\n", warn.c_str());
}
if (!err.empty()) {
printf("Err: %s\n", err.c_str());
}

7866
lodepng.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,66 @@
{
"scenes" : [
{
"nodes" : [ 0 ]
}
],
"nodes" : [
{
"mesh" : 0
}
],
"meshes" : [
{
"primitives" : [ {
"attributes" : {
"POSITION" : 0
}
} ]
}
],
"buffers" : [
{
"uri" : "data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAA",
"byteLength" : 36
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteOffset" : 0,
"byteLength" : 36,
"target" : 34962
}
],
"accessors" : [
{
"bufferView" : 0,
"byteOffset" : 0,
"componentType" : 5126,
"count" : 3,
"type" : "VEC3",
"max" : [ 1.0, 1.0, 0.0 ],
"min" : [ 0.0, 0.0, 0.0 ]
}
],
"asset" : {
"version" : "2.0"
},
"materials" : [
{ "name" : "WHITE",
"extensions": {
"VENDOR_material_some_ext" : { }
}
}
],
"extensionsUsed" : [
"VENDOR_material_some_ext"
]
}

BIN
models/box01.glb Normal file

Binary file not shown.

View File

@@ -28,7 +28,7 @@ def run(filename):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
except:
print "Failed to execute: ", cmd
print("Failed to execute: ", cmd)
raise
if p.returncode != 0:

View File

@@ -1,5 +1,6 @@
#define TINYGLTF_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "tiny_gltf.h"
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
@@ -17,10 +18,71 @@ TEST_CASE("parse-error", "[parse]") {
tinygltf::Model model;
tinygltf::TinyGLTF ctx;
std::string err;
std::string warn;
bool ret = ctx.LoadASCIIFromString(&model, &err, "bora", strlen("bora"), /* basedir*/ "");
bool ret = ctx.LoadASCIIFromString(&model, &err, &warn, "bora", strlen("bora"), /* basedir*/ "");
REQUIRE(false == ret);
}
TEST_CASE("datauri-in-glb", "[issue-79]") {
tinygltf::Model model;
tinygltf::TinyGLTF ctx;
std::string err;
std::string warn;
bool ret = ctx.LoadBinaryFromFile(&model, &err, &warn, "../models/box01.glb");
if (!err.empty()) {
std::cerr << err << std::endl;
}
REQUIRE(true == ret);
}
TEST_CASE("extension-with-empty-object", "[issue-97]") {
tinygltf::Model model;
tinygltf::TinyGLTF ctx;
std::string err;
std::string warn;
bool ret = ctx.LoadASCIIFromFile(&model, &err, &warn, "../models/Extensions-issue97/test.gltf");
if (!err.empty()) {
std::cerr << err << std::endl;
}
REQUIRE(true == ret);
REQUIRE(model.extensionsUsed.size() == 1);
REQUIRE(model.extensionsUsed[0].compare("VENDOR_material_some_ext") == 0);
REQUIRE(model.materials.size() == 1);
REQUIRE(model.materials[0].extensions.size() == 1);
REQUIRE(model.materials[0].extensions.count("VENDOR_material_some_ext") == 1);
// TODO(syoyo): create temp directory.
{
ret = ctx.WriteGltfSceneToFile(&model, "issue-97.gltf", true, true);
REQUIRE(true == ret);
tinygltf::Model m;
// read back serialized glTF
bool ret = ctx.LoadASCIIFromFile(&m, &err, &warn, "issue-97.gltf");
if (!err.empty()) {
std::cerr << err << std::endl;
}
REQUIRE(true == ret);
REQUIRE(m.extensionsUsed.size() == 1);
REQUIRE(m.extensionsUsed[0].compare("VENDOR_material_some_ext") == 0);
REQUIRE(m.materials.size() == 1);
REQUIRE(m.materials[0].extensions.size() == 1);
REQUIRE(m.materials[0].extensions.count("VENDOR_material_some_ext") == 1);
}
}

File diff suppressed because it is too large Load Diff