mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 18:15:57 +08:00
Allow parsing integer number value as double(For example, glTF-Sample-Models/2.0/Cameras/glTF has zfar
number property with integer value, which trigerred a parsing failure).
This commit is contained in:
parent
2b66c81f67
commit
1100f0f1eb
19
tiny_gltf.h
19
tiny_gltf.h
@ -2567,23 +2567,16 @@ bool GetInt(const json &o, int &val) {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool GetDouble(const json &o, double &val) {
|
||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||
bool GetDouble(const json &o, double &val) {
|
||||
if (o.IsDouble()) {
|
||||
val = o.GetDouble();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
#else
|
||||
if (o.type() == json::value_t::number_float) {
|
||||
val = static_cast<double>(o.get<double>());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
bool GetNumber(const json &o, double &val) {
|
||||
#ifdef TINYGLTF_USE_RAPIDJSON
|
||||
@ -2961,10 +2954,10 @@ static bool ParseNumberProperty(double *ret, std::string *err, const json &o,
|
||||
return false;
|
||||
}
|
||||
|
||||
double doubleValue;
|
||||
bool isDouble = GetDouble(GetValue(it), doubleValue);
|
||||
double numberValue;
|
||||
bool isNumber = GetNumber(GetValue(it), numberValue);
|
||||
|
||||
if (!isDouble) {
|
||||
if (!isNumber) {
|
||||
if (required) {
|
||||
if (err) {
|
||||
(*err) += "'" + property + "' property is not a number type.\n";
|
||||
@ -2974,7 +2967,7 @@ static bool ParseNumberProperty(double *ret, std::string *err, const json &o,
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
(*ret) = doubleValue;
|
||||
(*ret) = numberValue;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user