From f93642c196ff43ab18b5271bc6e89b5ae4b150e2 Mon Sep 17 00:00:00 2001 From: nicolasDEROUINEAU Date: Tue, 13 Aug 2019 15:08:01 +0200 Subject: [PATCH 1/4] remove extra #endif in examples/basic app --- examples/basic/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/basic/main.cpp b/examples/basic/main.cpp index 6a4c545..11a6e9a 100644 --- a/examples/basic/main.cpp +++ b/examples/basic/main.cpp @@ -332,7 +332,6 @@ int main(int argc, char **argv) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); #ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -#endif #endif Window window = Window(800, 600, "TinyGLTF basic example"); From d9a468bbb4703b170a436c0a64e51ee8ba093582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20H=C3=A4rtl?= Date: Wed, 14 Aug 2019 14:14:07 +0200 Subject: [PATCH 2/4] Fixed saving of alphaMode if not OPAQUE Removed duplicated code for alphaCutoff --- tiny_gltf.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 54faf57..b18aed9 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -5412,14 +5412,10 @@ static void SerializeGltfMaterial(Material &material, json &o) { SerializeNumberProperty("alphaCutoff", material.alphaCutoff, o); } - if (material.alphaMode.compare("OPAQUE") == 0) { + if (material.alphaMode.compare("OPAQUE") != 0) { SerializeStringProperty("alphaMode", material.alphaMode, o); } - if (!TINYGLTF_DOUBLE_EQUAL(material.alphaCutoff, 0.5)) { - SerializeNumberProperty("alphaCutoff", material.alphaCutoff, o); - } - o["doubleSided"] = json(material.doubleSided); if (material.normalTexture.index >= -1) { From 4ebd6368fbcdf3bb7b4066674dde0b9d9dc705fc Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 15 Aug 2019 12:25:50 +0900 Subject: [PATCH 3/4] Fix inequality of texture index check when serializing texture of material. Texture info was written even if it have invalid index(-1). Fixes #189 --- tiny_gltf.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index b18aed9..36226c1 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -5382,13 +5382,13 @@ static void SerializeGltfPbrMetallicRoughness(PbrMetallicRoughness &pbr, SerializeNumberProperty("roughnessFactor", pbr.roughnessFactor, o); } - if (pbr.baseColorTexture.index >= -1) { + if (pbr.baseColorTexture.index > -1) { json texinfo; SerializeGltfTextureInfo(pbr.baseColorTexture, texinfo); o["baseColorTexture"] = texinfo; } - if (pbr.metallicRoughnessTexture.index >= -1) { + if (pbr.metallicRoughnessTexture.index > -1) { json texinfo; SerializeGltfTextureInfo(pbr.metallicRoughnessTexture, texinfo); o["metallicRoughnessTexture"] = texinfo; @@ -5418,19 +5418,19 @@ static void SerializeGltfMaterial(Material &material, json &o) { o["doubleSided"] = json(material.doubleSided); - if (material.normalTexture.index >= -1) { + if (material.normalTexture.index > -1) { json texinfo; SerializeGltfNormalTextureInfo(material.normalTexture, texinfo); o["normalTexture"] = texinfo; } - if (material.occlusionTexture.index >= -1) { + if (material.occlusionTexture.index > -1) { json texinfo; SerializeGltfOcclusionTextureInfo(material.occlusionTexture, texinfo); o["occlusionTexture"] = texinfo; } - if (material.emissiveTexture.index >= -1) { + if (material.emissiveTexture.index > -1) { json texinfo; SerializeGltfTextureInfo(material.emissiveTexture, texinfo); o["emissiveTexture"] = texinfo; From ee179b2cb67921a4642eca43d7a4e2aecf68687c Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Fri, 16 Aug 2019 13:11:30 +0900 Subject: [PATCH 4/4] Set default value of minFilter and magFilter in Sampler to -1(unset), since glTF 2.0 spec does not declare default values for it. Fixes #186 --- tiny_gltf.h | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 36226c1..a8af40e 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -26,6 +26,7 @@ // THE SOFTWARE. // Version: +// - v2.3.1 Set default value of minFilter and magFilter in Sampler to -1. // - v2.3.0 Modified Material representation according to glTF 2.0 schema // (and introduced TextureInfo class) // Change the behavior of `Value::IsNumber`. It return true either the @@ -527,20 +528,26 @@ struct Skin { struct Sampler { std::string name; - int minFilter; // ["NEAREST", "LINEAR", "NEAREST_MIPMAP_LINEAR", - // "LINEAR_MIPMAP_NEAREST", "NEAREST_MIPMAP_LINEAR", - // "LINEAR_MIPMAP_LINEAR"] - int magFilter; // ["NEAREST", "LINEAR"] - int wrapS; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default - // "REPEAT" - int wrapT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default - // "REPEAT" - int wrapR; // TinyGLTF extension + // glTF 2.0 spec does not define default value for `minFilter` and + // `magFilter`. Set -1 in TinyGLTF(issue #186) + int minFilter = + -1; // optional. -1 = no filter defined. ["NEAREST", "LINEAR", + // "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_NEAREST", + // "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_LINEAR"] + int magFilter = + -1; // optional. -1 = no filter defined. ["NEAREST", "LINEAR"] + int wrapS = + TINYGLTF_TEXTURE_WRAP_REPEAT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", + // "REPEAT"], default "REPEAT" + int wrapT = + TINYGLTF_TEXTURE_WRAP_REPEAT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", + // "REPEAT"], default "REPEAT" + int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT; // TinyGLTF extension Value extras; Sampler() - : minFilter(TINYGLTF_TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR), - magFilter(TINYGLTF_TEXTURE_FILTER_LINEAR), + : minFilter(-1), + magFilter(-1), wrapS(TINYGLTF_TEXTURE_WRAP_REPEAT), wrapT(TINYGLTF_TEXTURE_WRAP_REPEAT), wrapR(TINYGLTF_TEXTURE_WRAP_REPEAT) {} @@ -3917,19 +3924,25 @@ static bool ParseAnimation(Animation *animation, std::string *err, static bool ParseSampler(Sampler *sampler, std::string *err, const json &o) { ParseStringProperty(&sampler->name, err, o, "name", false); - int minFilter = TINYGLTF_TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR; - int magFilter = TINYGLTF_TEXTURE_FILTER_LINEAR; + int minFilter = -1; + int magFilter = -1; int wrapS = TINYGLTF_TEXTURE_WRAP_REPEAT; int wrapT = TINYGLTF_TEXTURE_WRAP_REPEAT; + int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT; ParseIntegerProperty(&minFilter, err, o, "minFilter", false); ParseIntegerProperty(&magFilter, err, o, "magFilter", false); ParseIntegerProperty(&wrapS, err, o, "wrapS", false); ParseIntegerProperty(&wrapT, err, o, "wrapT", false); + ParseIntegerProperty(&wrapR, err, o, "wrapR", false); // tinygltf extension + + // TODO(syoyo): Check the value is alloed one. + // (e.g. we allow 9728(NEAREST), but don't allow 9727) sampler->minFilter = minFilter; sampler->magFilter = magFilter; sampler->wrapS = wrapS; sampler->wrapT = wrapT; + sampler->wrapR = wrapR; ParseExtrasProperty(&(sampler->extras), o); @@ -5585,8 +5598,12 @@ static void SerializeGltfNode(Node &node, json &o) { } static void SerializeGltfSampler(Sampler &sampler, json &o) { - SerializeNumberProperty("magFilter", sampler.magFilter, o); - SerializeNumberProperty("minFilter", sampler.minFilter, o); + if (sampler.magFilter != -1) { + SerializeNumberProperty("magFilter", sampler.magFilter, o); + } + if (sampler.minFilter != -1) { + SerializeNumberProperty("minFilter", sampler.minFilter, o); + } SerializeNumberProperty("wrapR", sampler.wrapR, o); SerializeNumberProperty("wrapS", sampler.wrapS, o); SerializeNumberProperty("wrapT", sampler.wrapT, o);