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
This commit is contained in:
Syoyo Fujita 2019-08-16 13:11:30 +09:00
parent 4ebd6368fb
commit ee179b2cb6

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
@ -527,20 +528,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) {}
@ -3917,19 +3924,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);
@ -5585,8 +5598,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);