mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-07-23 22:48:54 +00:00
Compare commits
28 Commits
image-pars
...
Selmar-gen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b0bbc6570 | ||
|
|
9eae110946 | ||
|
|
fa7022f364 | ||
|
|
6c67da478f | ||
|
|
b97d34cfee | ||
|
|
142aed7499 | ||
|
|
ca80a591e0 | ||
|
|
dc4bb86bf1 | ||
|
|
ef151a4fed | ||
|
|
0894de77f9 | ||
|
|
642a343684 | ||
|
|
719d7e4a74 | ||
|
|
13fd7152ee | ||
|
|
30c5347afe | ||
|
|
841c858bfd | ||
|
|
faa2722f45 | ||
|
|
ae751c4882 | ||
|
|
6a04c87807 | ||
|
|
5210f1539e | ||
|
|
35c798ed28 | ||
|
|
5e379693cb | ||
|
|
a403cd8736 | ||
|
|
d1f8bae89c | ||
|
|
85b3cbc44d | ||
|
|
d5b0244e2c | ||
|
|
2a15f387bc | ||
|
|
7d8cbba8e4 | ||
|
|
09d2ff12d8 |
21
README.md
21
README.md
@@ -50,7 +50,9 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
|||||||
## Projects using TinyGLTF
|
## Projects using TinyGLTF
|
||||||
|
|
||||||
* Physical based rendering with Vulkan using glTF 2.0 models https://github.com/SaschaWillems/Vulkan-glTF-PBR
|
* Physical based rendering with Vulkan using glTF 2.0 models https://github.com/SaschaWillems/Vulkan-glTF-PBR
|
||||||
* Your projects here!(Plese send PR)
|
* 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.
|
||||||
|
* Your projects here! (Please send PR)
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
|
|
||||||
@@ -70,12 +72,13 @@ TinyGLTF uses the following third party libraries.
|
|||||||
|
|
||||||
* json.hpp : Copyright (c) 2013-2017 Niels Lohmann. MIT license.
|
* json.hpp : Copyright (c) 2013-2017 Niels Lohmann. MIT license.
|
||||||
* base64 : Copyright (C) 2004-2008 René Nyffenegger
|
* base64 : Copyright (C) 2004-2008 René Nyffenegger
|
||||||
* stb_image.h : v2.08 - public domain image loader - http://nothings.org/stb_image.h
|
* 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)
|
||||||
|
|
||||||
|
|
||||||
## Build and example
|
## Build and example
|
||||||
|
|
||||||
Copy `stb_image.h`, `json.hpp` and `tiny_gltf.h` to your project.
|
Copy `stb_image.h`, `stb_image_write.h`, `json.hpp` and `tiny_gltf.h` to your project.
|
||||||
|
|
||||||
### Loading glTF 2.0 model
|
### Loading glTF 2.0 model
|
||||||
|
|
||||||
@@ -83,6 +86,7 @@ Copy `stb_image.h`, `json.hpp` and `tiny_gltf.h` to your project.
|
|||||||
// Define these only in *one* .cc file.
|
// Define these only in *one* .cc file.
|
||||||
#define TINYGLTF_IMPLEMENTATION
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
// #define TINYGLTF_NOEXCEPTION // optional. disable exception handling.
|
// #define TINYGLTF_NOEXCEPTION // optional. disable exception handling.
|
||||||
#include "tiny_gltf.h"
|
#include "tiny_gltf.h"
|
||||||
|
|
||||||
@@ -108,10 +112,17 @@ 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_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` : 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.
|
||||||
|
|
||||||
### Saving gltTF 2.0 model
|
### Saving gltTF 2.0 model
|
||||||
|
* [ ] Buffers.
|
||||||
T.B.W.
|
* [x] To file
|
||||||
|
* [x] Embedded
|
||||||
|
* [ ] Draco compressed?
|
||||||
|
* [x] Images
|
||||||
|
* [x] To file
|
||||||
|
* [x] Embedded
|
||||||
|
* [ ] Binary(.glb)
|
||||||
|
|
||||||
## Running tests.
|
## Running tests.
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory> // c++11
|
#include <memory> // c++11
|
||||||
#define TINYGLTF_IMPLEMENTATION
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
|
#define TINYGLTF_NO_STB_IMAGE_WRITE
|
||||||
#include <tiny_gltf.h>
|
#include <tiny_gltf.h>
|
||||||
|
|
||||||
namespace example {
|
namespace example {
|
||||||
|
|||||||
@@ -3,11 +3,21 @@
|
|||||||
|
|
||||||
#define TINYGLTF_IMPLEMENTATION
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
|
||||||
|
//#define TINYGLTF_NO_STB_IMAGE_WRITE
|
||||||
|
|
||||||
|
#ifndef TINYGLTF_NO_STB_IMAGE_WRITE
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// If using a modern Microsoft Compiler, this define supress compilation
|
||||||
|
// warnings in stb_image_write
|
||||||
|
//#define STBI_MSC_SECURE_CRT
|
||||||
|
|
||||||
#include "tiny_gltf.h"
|
#include "tiny_gltf.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) {
|
||||||
{
|
if (argc != 3) {
|
||||||
if (argc != 3) {
|
|
||||||
std::cout << "Needs input.gltf output.gltf" << std::endl;
|
std::cout << "Needs input.gltf output.gltf" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
@@ -17,6 +27,8 @@ int main(int argc, char *argv[])
|
|||||||
std::string err;
|
std::string err;
|
||||||
std::string input_filename(argv[1]);
|
std::string input_filename(argv[1]);
|
||||||
std::string output_filename(argv[2]);
|
std::string output_filename(argv[2]);
|
||||||
|
std::string embedded_filename =
|
||||||
|
output_filename.substr(0, output_filename.size() - 5) + "-Embedded.gltf";
|
||||||
|
|
||||||
// assume ascii glTF.
|
// assume ascii glTF.
|
||||||
bool ret = loader.LoadASCIIFromFile(&model, &err, input_filename.c_str());
|
bool ret = loader.LoadASCIIFromFile(&model, &err, input_filename.c_str());
|
||||||
@@ -28,6 +40,10 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
loader.WriteGltfSceneToFile(&model, output_filename);
|
loader.WriteGltfSceneToFile(&model, output_filename);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
// Embedd buffers and images
|
||||||
|
#ifndef TINYGLTF_NO_STB_IMAGE_WRITE
|
||||||
|
loader.WriteGltfSceneToFile(&model, embedded_filename, true, true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#define TINYGLTF_IMPLEMENTATION
|
#define TINYGLTF_IMPLEMENTATION
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include "tiny_gltf.h"
|
#include "tiny_gltf.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -210,6 +211,19 @@ static std::string PrintParameterValue(const tinygltf::Parameter ¶m) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static std::string PrintParameterMap(const tinygltf::ParameterMap &pmap) {
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << pmap.size() << std::endl;
|
||||||
|
for (auto &kv : pmap) {
|
||||||
|
ss << kv.first << " : " << PrintParameterValue(kv.second) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static std::string PrintValue(const std::string &name,
|
static std::string PrintValue(const std::string &name,
|
||||||
const tinygltf::Value &value, const int indent) {
|
const tinygltf::Value &value, const int indent) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@@ -287,6 +301,15 @@ static void DumpPrimitive(const tinygltf::Primitive &primitive, int indent) {
|
|||||||
<< PrintValue("extras", primitive.extras, indent + 1) << std::endl;
|
<< PrintValue("extras", primitive.extras, indent + 1) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void DumpExtensions(const tinygltf::ExtensionMap &extension, const int indent)
|
||||||
|
{
|
||||||
|
// TODO(syoyo): Print extensions
|
||||||
|
for (auto &e : extension) {
|
||||||
|
std::cout << Indent(indent) << e.first << std::endl;
|
||||||
|
//std::cout << Indent(indent+1) << PrintParameterMap(e.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void Dump(const tinygltf::Model &model) {
|
static void Dump(const tinygltf::Model &model) {
|
||||||
std::cout << "=== Dump glTF ===" << std::endl;
|
std::cout << "=== Dump glTF ===" << std::endl;
|
||||||
std::cout << "asset.copyright : " << model.asset.copyright
|
std::cout << "asset.copyright : " << model.asset.copyright
|
||||||
@@ -307,6 +330,7 @@ static void Dump(const tinygltf::Model &model) {
|
|||||||
for (size_t i = 0; i < model.scenes.size(); i++) {
|
for (size_t i = 0; i < model.scenes.size(); i++) {
|
||||||
std::cout << Indent(1) << "scene[" << i
|
std::cout << Indent(1) << "scene[" << i
|
||||||
<< "] name : " << model.scenes[i].name << std::endl;
|
<< "] name : " << model.scenes[i].name << std::endl;
|
||||||
|
DumpExtensions(model.scenes[i].extensions, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,6 +554,12 @@ static void Dump(const tinygltf::Model &model) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toplevel extensions
|
||||||
|
{
|
||||||
|
std::cout << "extensions(items=" << model.extensions.size() << ")" << std::endl;
|
||||||
|
DumpExtensions(model.extensions, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|||||||
1831
stb_image_write.h
Normal file
1831
stb_image_write.h
Normal file
File diff suppressed because it is too large
Load Diff
844
tiny_gltf.h
844
tiny_gltf.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user