From 389d5016ad7a5d509bfbc506916eccf9a33b5a91 Mon Sep 17 00:00:00 2001 From: Jeff McGlynn Date: Thu, 2 May 2019 22:48:13 -0700 Subject: [PATCH 01/10] Add "asset" section to BoundsChecking test models These test assets were trimmed down and erroneously didn't have an "asset" section or version number, which is required by the glTF spec. This fixes test failures with pull request #162. --- models/BoundsChecking/invalid-buffer-index.gltf | 5 ++++- models/BoundsChecking/invalid-buffer-view-index.gltf | 5 ++++- models/BoundsChecking/invalid-primitive-indices.gltf | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/models/BoundsChecking/invalid-buffer-index.gltf b/models/BoundsChecking/invalid-buffer-index.gltf index 88386ef..d3dd923 100644 --- a/models/BoundsChecking/invalid-buffer-index.gltf +++ b/models/BoundsChecking/invalid-buffer-index.gltf @@ -46,5 +46,8 @@ "max": [2], "min": [0] } - ] + ], + "asset": { + "version": "2.0" + } } diff --git a/models/BoundsChecking/invalid-buffer-view-index.gltf b/models/BoundsChecking/invalid-buffer-view-index.gltf index 687fe85..b43c207 100644 --- a/models/BoundsChecking/invalid-buffer-view-index.gltf +++ b/models/BoundsChecking/invalid-buffer-view-index.gltf @@ -29,5 +29,8 @@ "max": [2], "min": [0] } - ] + ], + "asset": { + "version": "2.0" + } } diff --git a/models/BoundsChecking/invalid-primitive-indices.gltf b/models/BoundsChecking/invalid-primitive-indices.gltf index 6dab589..5cde694 100644 --- a/models/BoundsChecking/invalid-primitive-indices.gltf +++ b/models/BoundsChecking/invalid-primitive-indices.gltf @@ -29,5 +29,8 @@ "max": [2], "min": [0] } - ] + ], + "asset": { + "version": "2.0" + } } From b7f2473225020aaebcbe0efa83dc5d3c96bfd713 Mon Sep 17 00:00:00 2001 From: DiligentGraphics Date: Wed, 8 May 2019 18:33:26 -0700 Subject: [PATCH 02/10] Updated readme: added link to Diligent Engine --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7a347f1..3d5dc79 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,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 From fbc429577031f29f1fa0a93503ae1438fc8c918e Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 16 May 2019 16:54:28 +0900 Subject: [PATCH 03/10] Remove CATMULLROMSPLINE, which was removed in the final glTF 2.0 spec. --- tiny_gltf.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 3c1015a..d7d59fb 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -437,8 +437,7 @@ struct AnimationChannel { struct AnimationSampler { int input; // required int output; // required - std::string interpolation; // in ["LINEAR", "STEP", "CATMULLROMSPLINE", - // "CUBICSPLINE"], default "LINEAR" + std::string interpolation; // "LINEAR", "STEP","CUBICSPLINE" or user defined string. default "LINEAR" Value extras; AnimationSampler() : input(-1), output(-1), interpolation("LINEAR") {} From f29ae1a65332a979a5e6af18c74a54af390a79db Mon Sep 17 00:00:00 2001 From: "Arthur Brianville (Ybalrid)" Date: Sat, 25 May 2019 22:30:55 +0200 Subject: [PATCH 04/10] Remove Mesh::targets, as targets only exists inside `Primitive` --- tiny_gltf.h | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index b49a134..2af0a27 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -708,7 +708,6 @@ struct Mesh { std::string name; std::vector primitives; std::vector weights; // weights to be applied to the Morph Targets - std::vector > targets; ExtensionMap extensions; Value extras; @@ -1304,8 +1303,7 @@ bool Material::operator==(const Material &other) const { } bool Mesh::operator==(const Mesh &other) const { return this->extensions == other.extensions && this->extras == other.extras && - this->name == other.name && this->primitives == other.primitives && - this->targets == other.targets && Equals(this->weights, other.weights); + this->name == other.name && this->primitives == other.primitives; } bool Model::operator==(const Model &other) const { return this->accessors == other.accessors && @@ -3383,24 +3381,6 @@ static bool ParseMesh(Mesh *mesh, Model *model, std::string *err, } } - // Look for morph targets - json::const_iterator targetsObject = o.find("targets"); - if ((targetsObject != o.end()) && targetsObject.value().is_array()) { - for (json::const_iterator i = targetsObject.value().begin(); - i != targetsObject.value().end(); i++) { - std::map targetAttribues; - - const json &dict = i.value(); - json::const_iterator dictIt(dict.begin()); - json::const_iterator dictItEnd(dict.end()); - - for (; dictIt != dictItEnd; ++dictIt) { - targetAttribues[dictIt.key()] = static_cast(dictIt.value()); - } - mesh->targets.push_back(targetAttribues); - } - } - // Should probably check if has targets and if dimensions fit ParseNumberArrayProperty(&mesh->weights, err, o, "weights", false); @@ -4912,14 +4892,13 @@ static void SerializeGltfBufferView(BufferView &bufferView, json &o) { } static void SerializeGltfImage(Image &image, json &o) { - // if uri empty, the mimeType and bufferview should be set + // if uri empty, the mimeType and bufferview should be set if (image.uri.empty()) { - SerializeStringProperty("mimeType", image.mimeType, o); - SerializeNumberProperty("bufferView", image.bufferView, o); - } - else { - SerializeStringProperty("uri", image.uri, o); - } + SerializeStringProperty("mimeType", image.mimeType, o); + SerializeNumberProperty("bufferView", image.bufferView, o); + } else { + SerializeStringProperty("uri", image.uri, o); + } if (image.name.size()) { SerializeStringProperty("name", image.name, o); From 811e1d3899f41d3396736a12b5dbb071049d6b2e Mon Sep 17 00:00:00 2001 From: "Arthur Brainville (Ybalrid)" Date: Sat, 15 Jun 2019 07:32:38 +0200 Subject: [PATCH 05/10] Fix C4267 warning (size_t -> int) convertion --- tiny_gltf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 89525bc..d1d22e7 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -3094,7 +3094,7 @@ static bool ParseAccessor(Accessor *accessor, std::string *err, const json &o) { if (componentType >= TINYGLTF_COMPONENT_TYPE_BYTE && componentType <= TINYGLTF_COMPONENT_TYPE_DOUBLE) { // OK - accessor->componentType = componentType; + accessor->componentType = int(componentType); } else { std::stringstream ss; ss << "Invalid `componentType` in accessor. Got " << componentType From dab0daaedfd7b89538ee2a294e3b2ae61eeb6708 Mon Sep 17 00:00:00 2001 From: "Arthur Brainville (Ybalrid)" Date: Sun, 23 Jun 2019 21:50:10 +0200 Subject: [PATCH 06/10] Material names are stored once in material.name, then duplicated in "additionalValues" This patch prevent this duplication --- tiny_gltf.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index d1d22e7..1c2f1fd 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -3457,7 +3457,9 @@ static bool ParseMaterial(Material *material, std::string *err, const json &o) { } else { Parameter param; if (ParseParameterProperty(¶m, err, o, it.key(), false)) { - material->additionalValues[it.key()] = param; + // names of materials have already been parsed. Putting it in this map + // doesn't correctly reflext the glTF specification + if (it.key() != "name") material->additionalValues[it.key()] = param; } } } From d6b0d0a61f4bd922107bc005de70ee2007fe91d8 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sat, 29 Jun 2019 17:31:13 +0900 Subject: [PATCH 07/10] Explicitly define copy constructor and copy assignment operator for Model an Node. --- tiny_gltf.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tiny_gltf.h b/tiny_gltf.h index 1c2f1fd..83ededc 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -717,6 +717,7 @@ class Node { public: Node() : camera(-1), skin(-1), mesh(-1) {} + // TODO(syoyo): Could use `default` Node(const Node &rhs) { camera = rhs.camera; @@ -734,6 +735,9 @@ class Node { extras = rhs.extras; } ~Node() {} + + Node &operator=(const Node &rhs) = default; + bool operator==(const Node &) const; int camera; // the index of the camera referenced by this node @@ -794,7 +798,12 @@ struct Light { class Model { public: Model() {} + + Model(const Model &) = default; + Model &operator=(const Model &) = default; + ~Model() {} + bool operator==(const Model &) const; std::vector accessors; From 820ede87dbab18dcb74960c213914755309e2e13 Mon Sep 17 00:00:00 2001 From: Christophe Date: Thu, 4 Jul 2019 15:21:21 +0900 Subject: [PATCH 08/10] Adding texture scale reading (for normal maps) + asset copyright and texture names to the export --- tiny_gltf.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tiny_gltf.h b/tiny_gltf.h index 83ededc..92ee878 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -393,6 +393,17 @@ struct Parameter { return 0; } + /// Return the scale of a texture if this Parameter is a normal texture map. + /// Returned value is only valid if the parameter represent a normal texture + /// from a material + double TextureScale() const { + const auto it = json_double_value.find("scale"); + if (it != std::end(json_double_value)) { + return it->second; + } + return -1; + } + /// Material factor, like the roughness or metalness of a material /// Returned value is only valid if the parameter represent a texture from a /// material @@ -4838,6 +4849,10 @@ static void SerializeGltfAsset(Asset &asset, json &o) { SerializeStringProperty("generator", asset.generator, o); } + if (!asset.copyright.empty()) { + SerializeStringProperty("copyright", asset.copyright, o); + } + if (!asset.version.empty()) { SerializeStringProperty("version", asset.version, o); } @@ -5135,6 +5150,9 @@ static void SerializeGltfTexture(Texture &texture, json &o) { if (texture.source > -1) { SerializeNumberProperty("source", texture.source, o); } + if (texture.name.size()) { + SerializeStringProperty("name", texture.name, o); + } if (texture.extras.Type() != NULL_TYPE) { SerializeValue("extras", texture.extras, o); } From 8a98d98cd96340043298aac55236471c5286b5ea Mon Sep 17 00:00:00 2001 From: Arthur Brainville Date: Fri, 5 Jul 2019 00:26:02 +0200 Subject: [PATCH 09/10] Add Paramter::TextureStrength(). Precise default values. The default values on these methods as been set to what is described [here](https://github.com/KhronosGroup/glTF/tree/master/specification/2.0?ts=4#normaltextureinfo) and [here](https://github.com/KhronosGroup/glTF/tree/master/specification/2.0?ts=4#occlusiontextureinfo). This is to keep consistent with the API behavior from #144 --- tiny_gltf.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 92ee878..f7090cf 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -390,6 +390,7 @@ struct Parameter { if (it != std::end(json_double_value)) { return int(it->second); } + // As per the spec, if texCoord is ommited, this parameter is 0 return 0; } @@ -401,7 +402,20 @@ struct Parameter { if (it != std::end(json_double_value)) { return it->second; } - return -1; + // As per the spec, if scale is ommited, this paramter is 1 + return 1; + } + + /// Return the strength of a texture if this Parameter is a an occlusion map. + /// Returned value is only valid if the parameter represent an occlusion map + /// from a material + double TextureStrength() const { + const auto it = json_double_value.find("strength"); + if (it != std::end(json_double_value)) { + return it->second; + } + // As per the spec, if strenghth is ommited, this parameter is 1 + return 1; } /// Material factor, like the roughness or metalness of a material From 2a9d9deb679490bc9fdba68457e6a03e7498db08 Mon Sep 17 00:00:00 2001 From: "Arthur Brianville (Ybalrid)" Date: Fri, 5 Jul 2019 00:30:47 +0200 Subject: [PATCH 10/10] Applied clang-format --- tiny_gltf.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index f7090cf..4a5e2d8 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -405,7 +405,7 @@ struct Parameter { // As per the spec, if scale is ommited, this paramter is 1 return 1; } - + /// Return the strength of a texture if this Parameter is a an occlusion map. /// Returned value is only valid if the parameter represent an occlusion map /// from a material @@ -462,7 +462,8 @@ struct AnimationChannel { struct AnimationSampler { int input; // required int output; // required - std::string interpolation; // "LINEAR", "STEP","CUBICSPLINE" or user defined string. default "LINEAR" + std::string interpolation; // "LINEAR", "STEP","CUBICSPLINE" or user defined + // string. default "LINEAR" Value extras; AnimationSampler() : input(-1), output(-1), interpolation("LINEAR") {}