mirror of
https://github.com/syoyo/tinygltf.git
synced 2026-06-08 11:13:50 +00:00
Compare commits
50 Commits
v2.2.0
...
KHR_materi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
131b4ed32d | ||
|
|
f68d5e1f2a | ||
|
|
1c84fc22a5 | ||
|
|
150f243b1b | ||
|
|
0ee273fdfa | ||
|
|
046400b17f | ||
|
|
89fd93f815 | ||
|
|
e940337796 | ||
|
|
1b5f476d95 | ||
|
|
52936a00e0 | ||
|
|
f3ef880029 | ||
|
|
1af7c1d784 | ||
|
|
c0b79afecc | ||
|
|
c49461b7c2 | ||
|
|
051f4be2f1 | ||
|
|
4557b6aa22 | ||
|
|
b2d7d88dbc | ||
|
|
b7ca7c9381 | ||
|
|
0ffedcbe79 | ||
|
|
80faac5238 | ||
|
|
2a9d9deb67 | ||
|
|
8a98d98cd9 | ||
|
|
689edcbef6 | ||
|
|
820ede87db | ||
|
|
d6b0d0a61f | ||
|
|
5f180aaf74 | ||
|
|
dab0daaedf | ||
|
|
0ccc8dc262 | ||
|
|
811e1d3899 | ||
|
|
f65e06c5ca | ||
|
|
f29ae1a653 | ||
|
|
3bf16e4be5 | ||
|
|
fbc4295770 | ||
|
|
edf8d5cae1 | ||
|
|
b7f2473225 | ||
|
|
ed7bf66255 | ||
|
|
caa36dd050 | ||
|
|
389d5016ad | ||
|
|
d02ad0dede | ||
|
|
8f67121deb | ||
|
|
62be8d04cf | ||
|
|
d11a4c4d71 | ||
|
|
19b806e052 | ||
|
|
e0ab69cb31 | ||
|
|
8915252407 | ||
|
|
9446f65667 | ||
|
|
fb9f709166 | ||
|
|
a63cc6373d | ||
|
|
b3c1471317 | ||
|
|
9056aee823 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -67,4 +67,5 @@ imgui.ini
|
||||
loader_example
|
||||
tests/tester
|
||||
tests/tester_noexcept
|
||||
tests/issue-97.gltf
|
||||
|
||||
|
||||
@@ -42,6 +42,10 @@ script:
|
||||
- ${CC} -v
|
||||
- ${CXX} ${EXTRA_CXXFLAGS} -std=c++11 -Wall -g -o loader_example loader_example.cc
|
||||
- ./loader_example ./models/Cube/Cube.gltf
|
||||
- cd examples/raytrace
|
||||
- cd tests
|
||||
- make
|
||||
- ./tester
|
||||
- ./tester_noexcept
|
||||
- cd ../examples/raytrace
|
||||
- ../../premake5 gmake
|
||||
- make
|
||||
|
||||
10
README.md
10
README.md
@@ -7,6 +7,7 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
||||
|
||||
## Status
|
||||
|
||||
- v2.3.0 Modified Material representation according to glTF 2.0 schema(and introduced TextureInfo class)
|
||||
- v2.2.0 release(Support loading 16bit PNG. Sparse accessor support)
|
||||
- v2.1.0 release(Draco support)
|
||||
- v2.0.0 release(22 Aug, 2018)!
|
||||
@@ -54,6 +55,12 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
||||
* Extensions
|
||||
* [x] Draco mesh decoding
|
||||
|
||||
## Note on extension property
|
||||
|
||||
In extension(`ExtensionMap`), JSON number value is parsed as int or float(number) and stored as `tinygltf::Value` object. If you want a floating point value from `tinygltf::Value`, use `GetNumberAsDouble()` method.
|
||||
|
||||
`IsNumber()` returns true if the underlying value is an int value or a floating point value.
|
||||
|
||||
## Examples
|
||||
|
||||
* [glview](examples/glview) : Simple glTF geometry viewer.
|
||||
@@ -66,6 +73,7 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
||||
* 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.
|
||||
* [Diligent Engine](https://github.com/DiligentGraphics/DiligentEngine) - A modern cross-platform low-level graphics library and rendering framework
|
||||
* Your projects here! (Please send PR)
|
||||
|
||||
## TODOs
|
||||
@@ -75,7 +83,7 @@ If you are looking for old, C++03 version, please use `devel-picojson` branch.
|
||||
* [x] Load Draco compressed mesh
|
||||
* [ ] Save Draco compressed mesh
|
||||
* [ ] Open3DGC?
|
||||
* [ ] Support `extensions` and `extras` property
|
||||
* [x] Support `extensions` and `extras` property
|
||||
* [ ] HDR image?
|
||||
* [ ] OpenEXR extension through TinyEXR.
|
||||
* [ ] 16bit PNG support in Serialization
|
||||
|
||||
@@ -175,7 +175,10 @@ static std::string PrintIntArray(const std::vector<int> &arr) {
|
||||
std::stringstream ss;
|
||||
ss << "[ ";
|
||||
for (size_t i = 0; i < arr.size(); i++) {
|
||||
ss << arr[i] << ((i != arr.size() - 1) ? ", " : "");
|
||||
ss << arr[i];
|
||||
if (i != arr.size() - 1) {
|
||||
ss << ", ";
|
||||
}
|
||||
}
|
||||
ss << " ]";
|
||||
|
||||
@@ -190,7 +193,10 @@ static std::string PrintFloatArray(const std::vector<double> &arr) {
|
||||
std::stringstream ss;
|
||||
ss << "[ ";
|
||||
for (size_t i = 0; i < arr.size(); i++) {
|
||||
ss << arr[i] << ((i != arr.size() - 1) ? ", " : "");
|
||||
ss << arr[i];
|
||||
if (i != arr.size() - 1) {
|
||||
ss << ", ";
|
||||
}
|
||||
}
|
||||
ss << " ]";
|
||||
|
||||
@@ -243,35 +249,36 @@ static std::string PrintValue(const std::string &name,
|
||||
if (tag) {
|
||||
ss << Indent(indent) << name << " : " << value.Get<std::string>();
|
||||
} else {
|
||||
ss << " " << value.Get<std::string>() << " ";
|
||||
ss << Indent(indent) << value.Get<std::string>() << " ";
|
||||
}
|
||||
} else if (value.IsBool()) {
|
||||
if (tag) {
|
||||
ss << Indent(indent) << name << " : " << value.Get<bool>();
|
||||
} else {
|
||||
ss << " " << value.Get<bool>() << " ";
|
||||
ss << Indent(indent) << value.Get<bool>() << " ";
|
||||
}
|
||||
} else if (value.IsNumber()) {
|
||||
if (tag) {
|
||||
ss << Indent(indent) << name << " : " << value.Get<double>();
|
||||
} else {
|
||||
ss << " " << value.Get<double>() << " ";
|
||||
ss << Indent(indent) << value.Get<double>() << " ";
|
||||
}
|
||||
} else if (value.IsInt()) {
|
||||
if (tag) {
|
||||
ss << Indent(indent) << name << " : " << value.Get<int>();
|
||||
} else {
|
||||
ss << " " << value.Get<int>() << " ";
|
||||
ss << Indent(indent) << value.Get<int>() << " ";
|
||||
}
|
||||
} else if (value.IsArray()) {
|
||||
ss << Indent(indent) << name << " [ ";
|
||||
// TODO(syoyo): Better pretty printing of array item
|
||||
ss << Indent(indent) << name << " [ \n";
|
||||
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 << ", \n";
|
||||
}
|
||||
}
|
||||
ss << Indent(indent) << "] ";
|
||||
ss << "\n" << Indent(indent) << "] ";
|
||||
}
|
||||
|
||||
// @todo { binary }
|
||||
@@ -339,6 +346,114 @@ static void DumpExtensions(const tinygltf::ExtensionMap &extension,
|
||||
}
|
||||
}
|
||||
|
||||
static void DumpKHRTextureTransform(const tinygltf::KHRTextureTransform &texform,
|
||||
const int indent) {
|
||||
assert(texform.offset.size() == 2);
|
||||
|
||||
std::cout << Indent(indent) << "offset : [" << texform.offset[0] << ", " << texform.offset[1] << "]\n";
|
||||
std::cout << Indent(indent) << "rotation : " << texform.rotation << "\n";
|
||||
std::cout << Indent(indent) << "scale : [" << texform.scale[0] << ", " << texform.scale[1] << "]\n";
|
||||
if (texform.texCoord >= 0) {
|
||||
std::cout << Indent(indent) << "texCoord : TEXCOORD_" << texform.texCoord << "\n";
|
||||
}
|
||||
|
||||
std::cout << Indent(indent) << "extensions(items=" << texform.extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(texform.extensions, indent + 1);
|
||||
std::cout << PrintValue("extras", texform.extras, indent + 1) << "\n";
|
||||
}
|
||||
|
||||
static void DumpTextureInfo(const tinygltf::TextureInfo &texinfo,
|
||||
const int indent) {
|
||||
std::cout << Indent(indent) << "index : " << texinfo.index << "\n";
|
||||
std::cout << Indent(indent) << "texCoord : TEXCOORD_" << texinfo.texCoord
|
||||
<< "\n";
|
||||
if (texinfo.KHR_textureTransform.enabled) {
|
||||
std::cout << Indent(indent) << "KHR_texture_transform\n";
|
||||
DumpKHRTextureTransform(texinfo.KHR_textureTransform, indent + 1);
|
||||
}
|
||||
|
||||
std::cout << Indent(indent) << "extensions(items=" << texinfo.extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(texinfo.extensions, indent + 1);
|
||||
std::cout << PrintValue("extras", texinfo.extras, indent + 1) << "\n";
|
||||
}
|
||||
|
||||
static void DumpNormalTextureInfo(const tinygltf::NormalTextureInfo &texinfo,
|
||||
const int indent) {
|
||||
std::cout << Indent(indent) << "index : " << texinfo.index << "\n";
|
||||
std::cout << Indent(indent) << "texCoord : TEXCOORD_" << texinfo.texCoord
|
||||
<< "\n";
|
||||
std::cout << Indent(indent) << "scale : " << texinfo.scale << "\n";
|
||||
|
||||
if (texinfo.KHR_textureTransform.enabled) {
|
||||
std::cout << Indent(indent) << "KHR_texture_transform\n";
|
||||
DumpKHRTextureTransform(texinfo.KHR_textureTransform, indent + 1);
|
||||
}
|
||||
|
||||
std::cout << Indent(indent) << "extensions(items=" << texinfo.extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(texinfo.extensions, indent + 1);
|
||||
std::cout << PrintValue("extras", texinfo.extras, indent + 1) << "\n";
|
||||
}
|
||||
|
||||
static void DumpOcclusionTextureInfo(
|
||||
const tinygltf::OcclusionTextureInfo &texinfo, const int indent) {
|
||||
std::cout << Indent(indent) << "index : " << texinfo.index << "\n";
|
||||
std::cout << Indent(indent) << "texCoord : TEXCOORD_" << texinfo.texCoord
|
||||
<< "\n";
|
||||
std::cout << Indent(indent) << "strength : " << texinfo.strength << "\n";
|
||||
|
||||
std::cout << Indent(indent) << "extensions(items=" << texinfo.extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(texinfo.extensions, indent + 1);
|
||||
std::cout << PrintValue("extras", texinfo.extras, indent + 1) << "\n";
|
||||
}
|
||||
|
||||
static void DumpPbrMetallicRoughness(const tinygltf::PbrMetallicRoughness &pbr,
|
||||
const int indent) {
|
||||
std::cout << Indent(indent)
|
||||
<< "baseColorFactor : " << PrintFloatArray(pbr.baseColorFactor)
|
||||
<< "\n";
|
||||
std::cout << Indent(indent) << "baseColorTexture :\n";
|
||||
DumpTextureInfo(pbr.baseColorTexture, indent + 1);
|
||||
|
||||
std::cout << Indent(indent) << "metallicFactor : " << pbr.metallicFactor
|
||||
<< "\n";
|
||||
std::cout << Indent(indent) << "roughnessFactor : " << pbr.roughnessFactor
|
||||
<< "\n";
|
||||
|
||||
std::cout << Indent(indent) << "metallicRoughnessTexture :\n";
|
||||
DumpTextureInfo(pbr.metallicRoughnessTexture, indent + 1);
|
||||
|
||||
std::cout << Indent(indent) << "extensions(items=" << pbr.extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(pbr.extensions, indent + 1);
|
||||
std::cout << PrintValue("extras", pbr.extras, indent + 1) << "\n";
|
||||
}
|
||||
|
||||
static void DumpKHRPbrMetallicRoughness(const tinygltf::KHRPbrSpecularGlossiness &pbr,
|
||||
const int indent) {
|
||||
std::cout << Indent(indent)
|
||||
<< "diffuseFactor : " << PrintFloatArray(pbr.diffuseFactor)
|
||||
<< "\n";
|
||||
std::cout << Indent(indent) << "diffuseTexture :\n";
|
||||
DumpTextureInfo(pbr.diffuseTexture, indent + 1);
|
||||
|
||||
std::cout << Indent(indent) << "specularFactor : " << PrintFloatArray(pbr.specularFactor) << "\n";
|
||||
std::cout << Indent(indent) << "glossinessFactor : " << pbr.glossinessFactor
|
||||
<< "\n";
|
||||
|
||||
std::cout << Indent(indent) << "specularGlossinessTexture :\n";
|
||||
DumpTextureInfo(pbr.specularGlossinessTexture, indent + 1);
|
||||
|
||||
std::cout << Indent(indent) << "extensions(items=" << pbr.extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(pbr.extensions, indent + 1);
|
||||
std::cout << PrintValue("extras", pbr.extras, indent + 1) << "\n";
|
||||
}
|
||||
|
||||
|
||||
static void Dump(const tinygltf::Model &model) {
|
||||
std::cout << "=== Dump glTF ===" << std::endl;
|
||||
std::cout << "asset.copyright : " << model.asset.copyright
|
||||
@@ -359,6 +474,9 @@ static void Dump(const tinygltf::Model &model) {
|
||||
for (size_t i = 0; i < model.scenes.size(); i++) {
|
||||
std::cout << Indent(1) << "scene[" << i
|
||||
<< "] name : " << model.scenes[i].name << std::endl;
|
||||
|
||||
std::cout << Indent(1) << "extensions(items=" << model.scenes[i].extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(model.scenes[i].extensions, 1);
|
||||
}
|
||||
}
|
||||
@@ -509,16 +627,55 @@ static void Dump(const tinygltf::Model &model) {
|
||||
<< std::endl;
|
||||
for (size_t i = 0; i < model.materials.size(); i++) {
|
||||
const tinygltf::Material &material = model.materials[i];
|
||||
std::cout << Indent(1) << "name : " << material.name << std::endl;
|
||||
std::cout << Indent(1) << "values(items=" << material.values.size() << ")"
|
||||
std::cout << Indent(1) << "name : " << material.name
|
||||
<< std::endl;
|
||||
|
||||
std::cout << Indent(1) << "alphaMode : " << material.alphaMode
|
||||
<< std::endl;
|
||||
std::cout << Indent(1)
|
||||
<< "alphaCutoff : " << material.alphaCutoff
|
||||
<< std::endl;
|
||||
std::cout << Indent(1) << "doubleSided : "
|
||||
<< (material.doubleSided ? "true" : "false") << std::endl;
|
||||
std::cout << Indent(1) << "emissiveFactor : "
|
||||
<< PrintFloatArray(material.emissiveFactor) << std::endl;
|
||||
|
||||
std::cout << Indent(1) << "pbrMetallicRoughness :\n";
|
||||
DumpPbrMetallicRoughness(material.pbrMetallicRoughness, 2);
|
||||
|
||||
std::cout << Indent(1) << "normalTexture :\n";
|
||||
DumpNormalTextureInfo(material.normalTexture, 2);
|
||||
|
||||
std::cout << Indent(1) << "occlusionTexture :\n";
|
||||
DumpOcclusionTextureInfo(material.occlusionTexture, 2);
|
||||
|
||||
std::cout << Indent(1) << "emissiveTexture :\n";
|
||||
DumpTextureInfo(material.emissiveTexture, 2);
|
||||
|
||||
if (material.KHR_materials_unlit) {
|
||||
std::cout << Indent(1) << "KHR_materials_unlit : true\n";
|
||||
}
|
||||
|
||||
if (material.KHR_pbrSpecularGlossiness.enabled) {
|
||||
std::cout << Indent(1) << "KHR_materials_pbrSpecularGlossinesst\n";
|
||||
DumpKHRPbrMetallicRoughness(material.KHR_pbrSpecularGlossiness, 2);
|
||||
}
|
||||
|
||||
std::cout << Indent(1) << "---- legacy material parameter ----\n";
|
||||
std::cout << Indent(1) << "values(items=" << material.values.size() << ")"
|
||||
<< std::endl;
|
||||
tinygltf::ParameterMap::const_iterator p(material.values.begin());
|
||||
tinygltf::ParameterMap::const_iterator pEnd(material.values.end());
|
||||
for (; p != pEnd; p++) {
|
||||
std::cout << Indent(2) << p->first << ": "
|
||||
<< PrintParameterValue(p->second) << std::endl;
|
||||
}
|
||||
std::cout << Indent(1) << "-------------------------------------\n";
|
||||
|
||||
std::cout << Indent(1) << "extensions(items=" << material.extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(material.extensions, 2);
|
||||
std::cout << PrintValue("extras", material.extras, 2) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,6 +698,9 @@ 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;
|
||||
|
||||
std::cout << Indent(1) << "extensions(items=" << image.extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(image.extensions, 1);
|
||||
}
|
||||
}
|
||||
@@ -553,7 +713,11 @@ static void Dump(const tinygltf::Model &model) {
|
||||
<< std::endl;
|
||||
std::cout << Indent(1) << "source : " << texture.source
|
||||
<< std::endl;
|
||||
|
||||
std::cout << Indent(1) << "extensions(items=" << texture.extensions.size() << ")"
|
||||
<< std::endl;
|
||||
DumpExtensions(texture.extensions, 1);
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
67
models/BoundsChecking/integer-out-of-bounds.gltf
Normal file
67
models/BoundsChecking/integer-out-of-bounds.gltf
Normal file
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [0]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"mesh": 0
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"POSITION": 1
|
||||
},
|
||||
"indices": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"uri": "simpleTriangle.bin",
|
||||
"byteLength": 44
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 1e300,
|
||||
"target": 34963
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 8,
|
||||
"byteLength": 36,
|
||||
"target": 34962
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5123,
|
||||
"count": 3,
|
||||
"type": "SCALAR",
|
||||
"max": [2],
|
||||
"min": [0]
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 3,
|
||||
"type": "VEC3",
|
||||
"max": [1, 1, 0],
|
||||
"min": [0, 0, 0]
|
||||
}
|
||||
],
|
||||
"asset": {
|
||||
"version": "2.0"
|
||||
}
|
||||
}
|
||||
53
models/BoundsChecking/invalid-buffer-index.gltf
Normal file
53
models/BoundsChecking/invalid-buffer-index.gltf
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"scenes": [],
|
||||
"nodes": [],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {},
|
||||
"indices": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"uri": "simpleTriangle.bin",
|
||||
"byteLength": 44
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 6,
|
||||
"target": 34963
|
||||
},
|
||||
{
|
||||
"buffer": 1,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 6,
|
||||
"target": 34963
|
||||
}
|
||||
],
|
||||
"images": [
|
||||
{
|
||||
"bufferView": 1,
|
||||
"mimeType": "image/png"
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"componentType": 5123,
|
||||
"count": 3,
|
||||
"type": "SCALAR",
|
||||
"max": [2],
|
||||
"min": [0]
|
||||
}
|
||||
],
|
||||
"asset": {
|
||||
"version": "2.0"
|
||||
}
|
||||
}
|
||||
36
models/BoundsChecking/invalid-buffer-view-index.gltf
Normal file
36
models/BoundsChecking/invalid-buffer-view-index.gltf
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"scenes": [],
|
||||
"nodes": [],
|
||||
"buffers": [],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {},
|
||||
"indices": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 6,
|
||||
"target": 34963
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 1,
|
||||
"componentType": 5123,
|
||||
"count": 3,
|
||||
"type": "SCALAR",
|
||||
"max": [2],
|
||||
"min": [0]
|
||||
}
|
||||
],
|
||||
"asset": {
|
||||
"version": "2.0"
|
||||
}
|
||||
}
|
||||
36
models/BoundsChecking/invalid-primitive-indices.gltf
Normal file
36
models/BoundsChecking/invalid-primitive-indices.gltf
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"scenes": [],
|
||||
"nodes": [],
|
||||
"buffers": [],
|
||||
"meshes": [
|
||||
{
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {},
|
||||
"indices": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteOffset": 0,
|
||||
"byteLength": 6,
|
||||
"target": 34963
|
||||
}
|
||||
],
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 1,
|
||||
"componentType": 5123,
|
||||
"count": 3,
|
||||
"type": "SCALAR",
|
||||
"max": [2],
|
||||
"min": [0]
|
||||
}
|
||||
],
|
||||
"asset": {
|
||||
"version": "2.0"
|
||||
}
|
||||
}
|
||||
BIN
models/BoundsChecking/simpleTriangle.bin
Normal file
BIN
models/BoundsChecking/simpleTriangle.bin
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 B |
224
models/Cube-texture-ext/Cube-textransform.gltf
Normal file
224
models/Cube-texture-ext/Cube-textransform.gltf
Normal file
@@ -0,0 +1,224 @@
|
||||
{
|
||||
"accessors": [
|
||||
{
|
||||
"bufferView": 0,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5123,
|
||||
"count": 36,
|
||||
"max": [
|
||||
35
|
||||
],
|
||||
"min": [
|
||||
0
|
||||
],
|
||||
"type": "SCALAR"
|
||||
},
|
||||
{
|
||||
"bufferView": 1,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 36,
|
||||
"max": [
|
||||
1,
|
||||
1,
|
||||
1.000001
|
||||
],
|
||||
"min": [
|
||||
-1,
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 2,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 36,
|
||||
"max": [
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"min": [
|
||||
-1,
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
"type": "VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView": 3,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 36,
|
||||
"max": [
|
||||
1,
|
||||
-0,
|
||||
-0,
|
||||
1
|
||||
],
|
||||
"min": [
|
||||
0,
|
||||
-0,
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
"type": "VEC4"
|
||||
},
|
||||
{
|
||||
"bufferView": 4,
|
||||
"byteOffset": 0,
|
||||
"componentType": 5126,
|
||||
"count": 36,
|
||||
"max": [
|
||||
1,
|
||||
1
|
||||
],
|
||||
"min": [
|
||||
-1,
|
||||
-1
|
||||
],
|
||||
"type": "VEC2"
|
||||
}
|
||||
],
|
||||
"asset": {
|
||||
"generator": "VKTS glTF 2.0 exporter",
|
||||
"version": "2.0"
|
||||
},
|
||||
"bufferViews": [
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 72,
|
||||
"byteOffset": 0,
|
||||
"target": 34963
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 432,
|
||||
"byteOffset": 72,
|
||||
"target": 34962
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 432,
|
||||
"byteOffset": 504,
|
||||
"target": 34962
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 576,
|
||||
"byteOffset": 936,
|
||||
"target": 34962
|
||||
},
|
||||
{
|
||||
"buffer": 0,
|
||||
"byteLength": 288,
|
||||
"byteOffset": 1512,
|
||||
"target": 34962
|
||||
}
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"byteLength": 1800,
|
||||
"uri": "Cube.bin"
|
||||
}
|
||||
],
|
||||
"images": [
|
||||
{
|
||||
"0comment": "Use Cube_MetallicRoughness.png to reduce scene filesize",
|
||||
"uri": "Cube_MetallicRoughness.png"
|
||||
},
|
||||
{
|
||||
"uri": "Cube_MetallicRoughness.png"
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"emissiveTexture": {
|
||||
"index": 0,
|
||||
"extensions": {
|
||||
"KHR_texture_transform": {
|
||||
"offset": [
|
||||
0,
|
||||
1
|
||||
],
|
||||
"scale": [
|
||||
1,
|
||||
-1
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Cube",
|
||||
"pbrMetallicRoughness": {
|
||||
"baseColorTexture": {
|
||||
"index": 0
|
||||
},
|
||||
"metallicRoughnessTexture": {
|
||||
"index": 1,
|
||||
"extensions": {
|
||||
"KHR_texture_transform": {
|
||||
"offset": [
|
||||
0,
|
||||
1
|
||||
],
|
||||
"rotation": 1.57079632679,
|
||||
"scale": [
|
||||
0.5,
|
||||
0.5
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"meshes": [
|
||||
{
|
||||
"name": "Cube",
|
||||
"primitives": [
|
||||
{
|
||||
"attributes": {
|
||||
"NORMAL": 2,
|
||||
"POSITION": 1,
|
||||
"TANGENT": 3,
|
||||
"TEXCOORD_0": 4
|
||||
},
|
||||
"indices": 0,
|
||||
"material": 0,
|
||||
"mode": 4
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"mesh": 0,
|
||||
"name": "Cube"
|
||||
}
|
||||
],
|
||||
"samplers": [
|
||||
{}
|
||||
],
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures": [
|
||||
{
|
||||
"sampler": 0,
|
||||
"source": 0
|
||||
},
|
||||
{
|
||||
"sampler": 0,
|
||||
"source": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
models/Cube-texture-ext/Cube.bin
Normal file
BIN
models/Cube-texture-ext/Cube.bin
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
BIN
models/Cube-texture-ext/Cube_MetallicRoughness.png
Normal file
BIN
models/Cube-texture-ext/Cube_MetallicRoughness.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 319 B |
6
models/Cube-texture-ext/README.md
Normal file
6
models/Cube-texture-ext/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
Added KHR_texture_transform property to Cube scene.
|
||||
|
||||
License: Donated by Norbert Nopper for glTF testing.
|
||||
|
||||
https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Cube
|
||||
|
||||
233
tests/tester.cc
233
tests/tester.cc
@@ -37,7 +37,7 @@ TEST_CASE("datauri-in-glb", "[issue-79]") {
|
||||
if (!err.empty()) {
|
||||
std::cerr << err << std::endl;
|
||||
}
|
||||
|
||||
|
||||
REQUIRE(true == ret);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,236 @@ TEST_CASE("extension-with-empty-object", "[issue-97]") {
|
||||
REQUIRE(m.materials[0].extensions.size() == 1);
|
||||
REQUIRE(m.materials[0].extensions.count("VENDOR_material_some_ext") == 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("invalid-primitive-indices", "[bounds-checking]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
// Loading is expected to fail, but not crash.
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/BoundsChecking/invalid-primitive-indices.gltf");
|
||||
REQUIRE_THAT(err,
|
||||
Catch::Contains("primitive indices accessor out of bounds"));
|
||||
REQUIRE_FALSE(ret);
|
||||
}
|
||||
|
||||
TEST_CASE("invalid-buffer-view-index", "[bounds-checking]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
// Loading is expected to fail, but not crash.
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/BoundsChecking/invalid-buffer-view-index.gltf");
|
||||
REQUIRE_THAT(err, Catch::Contains("accessor[0] invalid bufferView"));
|
||||
REQUIRE_FALSE(ret);
|
||||
}
|
||||
|
||||
TEST_CASE("invalid-buffer-index", "[bounds-checking]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
// Loading is expected to fail, but not crash.
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/BoundsChecking/invalid-buffer-index.gltf");
|
||||
REQUIRE_THAT(
|
||||
err, Catch::Contains("image[0] buffer \"1\" not found in the scene."));
|
||||
REQUIRE_FALSE(ret);
|
||||
}
|
||||
|
||||
TEST_CASE("glb-invalid-length", "[bounds-checking]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
// This glb has a much longer length than the provided data and should fail
|
||||
// initial range checks.
|
||||
const unsigned char glb_invalid_length[] = "glTF"
|
||||
"\x20\x00\x00\x00" "\x6c\x66\x00\x00" //
|
||||
// | version | length |
|
||||
"\x02\x00\x00\x00" "\x4a\x53\x4f\x4e{}"; //
|
||||
// | model length | model format |
|
||||
|
||||
bool ret = ctx.LoadBinaryFromMemory(&model, &err, &warn, glb_invalid_length,
|
||||
sizeof(glb_invalid_length));
|
||||
REQUIRE_THAT(err, Catch::Contains("Invalid glTF binary."));
|
||||
REQUIRE_FALSE(ret);
|
||||
}
|
||||
|
||||
TEST_CASE("integer-out-of-bounds", "[bounds-checking]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
// Loading is expected to fail, but not crash.
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/BoundsChecking/integer-out-of-bounds.gltf");
|
||||
REQUIRE_THAT(err, Catch::Contains("not a positive integer"));
|
||||
REQUIRE_FALSE(ret);
|
||||
}
|
||||
|
||||
TEST_CASE("parse-integer", "[bounds-checking]") {
|
||||
SECTION("parses valid numbers") {
|
||||
std::string err;
|
||||
int result = 123;
|
||||
CHECK(tinygltf::ParseIntegerProperty(&result, &err, {{"zero", 0}}, "zero",
|
||||
true));
|
||||
REQUIRE(err == "");
|
||||
REQUIRE(result == 0);
|
||||
|
||||
CHECK(tinygltf::ParseIntegerProperty(&result, &err, {{"int", -1234}}, "int",
|
||||
true));
|
||||
REQUIRE(err == "");
|
||||
REQUIRE(result == -1234);
|
||||
}
|
||||
|
||||
SECTION("detects missing properties") {
|
||||
std::string err;
|
||||
int result = -1;
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(&result, &err, {}, "int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("'int' property is missing"));
|
||||
REQUIRE(result == -1);
|
||||
}
|
||||
|
||||
SECTION("handled missing but not required properties") {
|
||||
std::string err;
|
||||
int result = -1;
|
||||
CHECK_FALSE(
|
||||
tinygltf::ParseIntegerProperty(&result, &err, {}, "int", false));
|
||||
REQUIRE(err == "");
|
||||
REQUIRE(result == -1);
|
||||
}
|
||||
|
||||
SECTION("invalid integers") {
|
||||
std::string err;
|
||||
int result = -1;
|
||||
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(&result, &err, {{"int", 0.5}},
|
||||
"int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not an integer type"));
|
||||
|
||||
// Excessively large values and NaN aren't allowed either.
|
||||
err.clear();
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(&result, &err, {{"int", 1e300}},
|
||||
"int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not an integer type"));
|
||||
|
||||
err.clear();
|
||||
CHECK_FALSE(tinygltf::ParseIntegerProperty(
|
||||
&result, &err, {{"int", std::numeric_limits<double>::quiet_NaN()}},
|
||||
"int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not an integer type"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("parse-unsigned", "[bounds-checking]") {
|
||||
SECTION("parses valid unsigned integers") {
|
||||
// Use string-based parsing here, using the initializer list syntax doesn't
|
||||
// parse 0 as unsigned.
|
||||
json zero_obj = json::parse("{\"zero\": 0}");
|
||||
|
||||
std::string err;
|
||||
size_t result = 123;
|
||||
CHECK(
|
||||
tinygltf::ParseUnsignedProperty(&result, &err, zero_obj, "zero", true));
|
||||
REQUIRE(err == "");
|
||||
REQUIRE(result == 0);
|
||||
}
|
||||
|
||||
SECTION("invalid integers") {
|
||||
std::string err;
|
||||
size_t result = -1;
|
||||
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(&result, &err, {{"int", -1234}},
|
||||
"int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not a positive integer"));
|
||||
|
||||
err.clear();
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(&result, &err, {{"int", 0.5}},
|
||||
"int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not a positive integer"));
|
||||
|
||||
// Excessively large values and NaN aren't allowed either.
|
||||
err.clear();
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(&result, &err, {{"int", 1e300}},
|
||||
"int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not a positive integer"));
|
||||
|
||||
err.clear();
|
||||
CHECK_FALSE(tinygltf::ParseUnsignedProperty(
|
||||
&result, &err, {{"int", std::numeric_limits<double>::quiet_NaN()}},
|
||||
"int", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not a positive integer"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("parse-integer-array", "[bounds-checking]") {
|
||||
SECTION("parses valid integers") {
|
||||
std::string err;
|
||||
std::vector<int> result;
|
||||
CHECK(tinygltf::ParseIntegerArrayProperty(&result, &err,
|
||||
{{"x", {-1, 2, 3}}}, "x", true));
|
||||
REQUIRE(err == "");
|
||||
REQUIRE(result.size() == 3);
|
||||
REQUIRE(result[0] == -1);
|
||||
REQUIRE(result[1] == 2);
|
||||
REQUIRE(result[2] == 3);
|
||||
}
|
||||
|
||||
SECTION("invalid integers") {
|
||||
std::string err;
|
||||
std::vector<int> result;
|
||||
CHECK_FALSE(tinygltf::ParseIntegerArrayProperty(
|
||||
&result, &err, {{"x", {-1, 1e300, 3}}}, "x", true));
|
||||
REQUIRE_THAT(err, Catch::Contains("not an integer type"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("pbr-khr-texture-transform", "[material]") {
|
||||
tinygltf::Model model;
|
||||
tinygltf::TinyGLTF ctx;
|
||||
std::string err;
|
||||
std::string warn;
|
||||
|
||||
// Loading is expected to fail, but not crash.
|
||||
bool ret = ctx.LoadASCIIFromFile(
|
||||
&model, &err, &warn,
|
||||
"../models/Cube-texture-ext/Cube-textransform.gltf");
|
||||
REQUIRE(ret == true);
|
||||
|
||||
REQUIRE(model.materials.size() == 2);
|
||||
REQUIRE(model.materials[0].emissiveTexture.extensions.count("KHR_texture_transform") == 1);
|
||||
REQUIRE(model.materials[0].emissiveTexture.extensions["KHR_texture_transform"].IsObject());
|
||||
|
||||
tinygltf::Value::Object &texform = model.materials[0].emissiveTexture.extensions["KHR_texture_transform"].Get<tinygltf::Value::Object>();
|
||||
|
||||
REQUIRE(texform.count("scale"));
|
||||
|
||||
REQUIRE(texform["scale"].IsArray());
|
||||
|
||||
// Note: It looks json.hpp parse integer JSON number as integer, not floating point.
|
||||
// IsNumber return true either value is int or floating point.
|
||||
REQUIRE(texform["scale"].Get(0).IsNumber());
|
||||
REQUIRE(texform["scale"].Get(1).IsNumber());
|
||||
|
||||
double scale[2];
|
||||
scale[0] = texform["scale"].Get(0).GetNumberAsDouble();
|
||||
scale[1] = texform["scale"].Get(1).GetNumberAsDouble();
|
||||
|
||||
REQUIRE(scale[0] == Approx(1.0));
|
||||
REQUIRE(scale[1] == Approx(-1.0));
|
||||
|
||||
}
|
||||
|
||||
1977
tiny_gltf.h
1977
tiny_gltf.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user