Merge branch 'master' of github.com:syoyo/tinygltf

This commit is contained in:
Selmar Kok 2019-08-16 14:08:31 +02:00
commit 5d43cf8e64
2 changed files with 38 additions and 26 deletions

View File

@ -332,7 +332,6 @@ int main(int argc, char **argv) {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__ #ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
#endif #endif
Window window = Window(800, 600, "TinyGLTF basic example"); Window window = Window(800, 600, "TinyGLTF basic example");

View File

@ -26,6 +26,7 @@
// THE SOFTWARE. // THE SOFTWARE.
// Version: // 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 // - v2.3.0 Modified Material representation according to glTF 2.0 schema
// (and introduced TextureInfo class) // (and introduced TextureInfo class)
// Change the behavior of `Value::IsNumber`. It return true either the // Change the behavior of `Value::IsNumber`. It return true either the
@ -529,20 +530,26 @@ struct Skin {
struct Sampler { struct Sampler {
std::string name; std::string name;
int minFilter; // ["NEAREST", "LINEAR", "NEAREST_MIPMAP_LINEAR", // glTF 2.0 spec does not define default value for `minFilter` and
// "LINEAR_MIPMAP_NEAREST", "NEAREST_MIPMAP_LINEAR", // `magFilter`. Set -1 in TinyGLTF(issue #186)
// "LINEAR_MIPMAP_LINEAR"] int minFilter =
int magFilter; // ["NEAREST", "LINEAR"] -1; // optional. -1 = no filter defined. ["NEAREST", "LINEAR",
int wrapS; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default // "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_NEAREST",
// "REPEAT" // "NEAREST_MIPMAP_LINEAR", "LINEAR_MIPMAP_LINEAR"]
int wrapT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT", "REPEAT"], default int magFilter =
// "REPEAT" -1; // optional. -1 = no filter defined. ["NEAREST", "LINEAR"]
int wrapR; // TinyGLTF extension 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; Value extras;
Sampler() Sampler()
: minFilter(TINYGLTF_TEXTURE_FILTER_LINEAR_MIPMAP_LINEAR), : minFilter(-1),
magFilter(TINYGLTF_TEXTURE_FILTER_LINEAR), magFilter(-1),
wrapS(TINYGLTF_TEXTURE_WRAP_REPEAT), wrapS(TINYGLTF_TEXTURE_WRAP_REPEAT),
wrapT(TINYGLTF_TEXTURE_WRAP_REPEAT), wrapT(TINYGLTF_TEXTURE_WRAP_REPEAT),
wrapR(TINYGLTF_TEXTURE_WRAP_REPEAT) {} wrapR(TINYGLTF_TEXTURE_WRAP_REPEAT) {}
@ -3924,19 +3931,25 @@ static bool ParseAnimation(Animation *animation, std::string *err,
static bool ParseSampler(Sampler *sampler, std::string *err, const json &o) { static bool ParseSampler(Sampler *sampler, std::string *err, const json &o) {
ParseStringProperty(&sampler->name, err, o, "name", false); ParseStringProperty(&sampler->name, err, o, "name", false);
int minFilter = TINYGLTF_TEXTURE_FILTER_NEAREST_MIPMAP_LINEAR; int minFilter = -1;
int magFilter = TINYGLTF_TEXTURE_FILTER_LINEAR; int magFilter = -1;
int wrapS = TINYGLTF_TEXTURE_WRAP_REPEAT; int wrapS = TINYGLTF_TEXTURE_WRAP_REPEAT;
int wrapT = TINYGLTF_TEXTURE_WRAP_REPEAT; int wrapT = TINYGLTF_TEXTURE_WRAP_REPEAT;
int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT;
ParseIntegerProperty(&minFilter, err, o, "minFilter", false); ParseIntegerProperty(&minFilter, err, o, "minFilter", false);
ParseIntegerProperty(&magFilter, err, o, "magFilter", false); ParseIntegerProperty(&magFilter, err, o, "magFilter", false);
ParseIntegerProperty(&wrapS, err, o, "wrapS", false); ParseIntegerProperty(&wrapS, err, o, "wrapS", false);
ParseIntegerProperty(&wrapT, err, o, "wrapT", 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->minFilter = minFilter;
sampler->magFilter = magFilter; sampler->magFilter = magFilter;
sampler->wrapS = wrapS; sampler->wrapS = wrapS;
sampler->wrapT = wrapT; sampler->wrapT = wrapT;
sampler->wrapR = wrapR;
ParseExtrasProperty(&(sampler->extras), o); ParseExtrasProperty(&(sampler->extras), o);
@ -5393,13 +5406,13 @@ static void SerializeGltfPbrMetallicRoughness(PbrMetallicRoughness &pbr,
SerializeNumberProperty("roughnessFactor", pbr.roughnessFactor, o); SerializeNumberProperty("roughnessFactor", pbr.roughnessFactor, o);
} }
if (pbr.baseColorTexture.index >= -1) { if (pbr.baseColorTexture.index > -1) {
json texinfo; json texinfo;
SerializeGltfTextureInfo(pbr.baseColorTexture, texinfo); SerializeGltfTextureInfo(pbr.baseColorTexture, texinfo);
o["baseColorTexture"] = texinfo; o["baseColorTexture"] = texinfo;
} }
if (pbr.metallicRoughnessTexture.index >= -1) { if (pbr.metallicRoughnessTexture.index > -1) {
json texinfo; json texinfo;
SerializeGltfTextureInfo(pbr.metallicRoughnessTexture, texinfo); SerializeGltfTextureInfo(pbr.metallicRoughnessTexture, texinfo);
o["metallicRoughnessTexture"] = texinfo; o["metallicRoughnessTexture"] = texinfo;
@ -5423,29 +5436,25 @@ static void SerializeGltfMaterial(Material &material, json &o) {
SerializeNumberProperty("alphaCutoff", material.alphaCutoff, o); SerializeNumberProperty("alphaCutoff", material.alphaCutoff, o);
} }
if (material.alphaMode.compare("OPAQUE") == 0) { if (material.alphaMode.compare("OPAQUE") != 0) {
SerializeStringProperty("alphaMode", material.alphaMode, o); SerializeStringProperty("alphaMode", material.alphaMode, o);
} }
if (!TINYGLTF_DOUBLE_EQUAL(material.alphaCutoff, 0.5)) {
SerializeNumberProperty("alphaCutoff", material.alphaCutoff, o);
}
o["doubleSided"] = json(material.doubleSided); o["doubleSided"] = json(material.doubleSided);
if (material.normalTexture.index >= -1) { if (material.normalTexture.index > -1) {
json texinfo; json texinfo;
SerializeGltfNormalTextureInfo(material.normalTexture, texinfo); SerializeGltfNormalTextureInfo(material.normalTexture, texinfo);
o["normalTexture"] = texinfo; o["normalTexture"] = texinfo;
} }
if (material.occlusionTexture.index >= -1) { if (material.occlusionTexture.index > -1) {
json texinfo; json texinfo;
SerializeGltfOcclusionTextureInfo(material.occlusionTexture, texinfo); SerializeGltfOcclusionTextureInfo(material.occlusionTexture, texinfo);
o["occlusionTexture"] = texinfo; o["occlusionTexture"] = texinfo;
} }
if (material.emissiveTexture.index >= -1) { if (material.emissiveTexture.index > -1) {
json texinfo; json texinfo;
SerializeGltfTextureInfo(material.emissiveTexture, texinfo); SerializeGltfTextureInfo(material.emissiveTexture, texinfo);
o["emissiveTexture"] = texinfo; o["emissiveTexture"] = texinfo;
@ -5600,8 +5609,12 @@ static void SerializeGltfNode(Node &node, json &o) {
} }
static void SerializeGltfSampler(Sampler &sampler, json &o) { static void SerializeGltfSampler(Sampler &sampler, json &o) {
SerializeNumberProperty("magFilter", sampler.magFilter, o); if (sampler.magFilter != -1) {
SerializeNumberProperty("minFilter", sampler.minFilter, o); SerializeNumberProperty("magFilter", sampler.magFilter, o);
}
if (sampler.minFilter != -1) {
SerializeNumberProperty("minFilter", sampler.minFilter, o);
}
SerializeNumberProperty("wrapR", sampler.wrapR, o); SerializeNumberProperty("wrapR", sampler.wrapR, o);
SerializeNumberProperty("wrapS", sampler.wrapS, o); SerializeNumberProperty("wrapS", sampler.wrapS, o);
SerializeNumberProperty("wrapT", sampler.wrapT, o); SerializeNumberProperty("wrapT", sampler.wrapT, o);