Skip to content

Commit

Permalink
Raise a warning when encountering emissiveFactor with array length
Browse files Browse the repository at this point in the history
of 4 instead of aborting the model loading

Submitted upstream as syoyo/tinygltf#445
  • Loading branch information
nyalldawson committed Aug 24, 2023
1 parent 95f0ace commit ed4889d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions external/tinygltf/tiny_gltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -5192,15 +5192,23 @@ static bool ParsePbrMetallicRoughness(
return true;
}

static bool ParseMaterial(Material *material, std::string *err,
static bool ParseMaterial(Material *material, std::string *err, std::string *warn,
const detail::json &o,
bool store_original_json_for_extras_and_extensions) {
ParseStringProperty(&material->name, err, o, "name", /* required */ false);

if (ParseNumberArrayProperty(&material->emissiveFactor, err, o,
"emissiveFactor",
/* required */ false)) {
if (material->emissiveFactor.size() != 3) {
if (material->emissiveFactor.size() == 4) {
if (warn) {
(*warn) +=
"Array length of `emissiveFactor` parameter in "
"material must be 3, but got 4\n";
}
material->emissiveFactor.resize(3);
}
else if (material->emissiveFactor.size() != 3) {
if (err) {
(*err) +=
"Array length of `emissiveFactor` parameter in "
Expand Down Expand Up @@ -6198,7 +6206,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
Material material;
ParseStringProperty(&material.name, err, o, "name", false);

if (!ParseMaterial(&material, err, o,
if (!ParseMaterial(&material, err, warn, o,
store_original_json_for_extras_and_extensions_)) {
return false;
}
Expand Down

0 comments on commit ed4889d

Please sign in to comment.