mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-07-06 02:25:11 +08:00
Improve error messsage a bit.
This commit is contained in:
parent
f91a3b7f0e
commit
0614eb8fa6
@ -346,8 +346,7 @@ class Scene {
|
|||||||
Asset asset;
|
Asset asset;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SectionCheck
|
enum SectionCheck {
|
||||||
{
|
|
||||||
NO_REQUIRE = 0x00,
|
NO_REQUIRE = 0x00,
|
||||||
REQUIRE_SCENE = 0x01,
|
REQUIRE_SCENE = 0x01,
|
||||||
REQUIRE_SCENES = 0x02,
|
REQUIRE_SCENES = 0x02,
|
||||||
@ -937,14 +936,20 @@ static bool ParseNumberArrayProperty(std::vector<double> *ret, std::string *err,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ParseStringProperty(std::string *ret, std::string *err,
|
static bool ParseStringProperty(
|
||||||
const picojson::object &o,
|
std::string *ret, std::string *err, const picojson::object &o,
|
||||||
const std::string &property, bool required) {
|
const std::string &property, bool required,
|
||||||
|
const std::string &parent_node = std::string()) {
|
||||||
picojson::object::const_iterator it = o.find(property);
|
picojson::object::const_iterator it = o.find(property);
|
||||||
if (it == o.end()) {
|
if (it == o.end()) {
|
||||||
if (required) {
|
if (required) {
|
||||||
if (err) {
|
if (err) {
|
||||||
(*err) += "'" + property + "' property is missing.\n";
|
(*err) += "'" + property + "' property is missing";
|
||||||
|
if (parent_node.empty()) {
|
||||||
|
(*err) += ".\n";
|
||||||
|
} else {
|
||||||
|
(*err) += " in `" + parent_node + "'.\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -1480,7 +1485,8 @@ static bool ParseAccessor(Accessor *accessor, std::string *err,
|
|||||||
|
|
||||||
static bool ParsePrimitive(Primitive *primitive, std::string *err,
|
static bool ParsePrimitive(Primitive *primitive, std::string *err,
|
||||||
const picojson::object &o) {
|
const picojson::object &o) {
|
||||||
if (!ParseStringProperty(&primitive->material, err, o, "material", true)) {
|
if (!ParseStringProperty(&primitive->material, err, o, "material", true,
|
||||||
|
"mesh.primitive")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1501,10 +1507,7 @@ static bool ParsePrimitive(Primitive *primitive, std::string *err,
|
|||||||
primitive->indices = "";
|
primitive->indices = "";
|
||||||
ParseStringProperty(&primitive->indices, err, o, "indices", false);
|
ParseStringProperty(&primitive->indices, err, o, "indices", false);
|
||||||
|
|
||||||
if (!ParseStringMapProperty(&primitive->attributes, err, o, "attributes",
|
ParseStringMapProperty(&primitive->attributes, err, o, "attributes", false);
|
||||||
true)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1671,7 +1674,7 @@ static bool ParseShader(Shader *shader, std::string *err,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Load shader source from data uri
|
// Load shader source from data uri
|
||||||
// TODO: Support ascii or utf-8 data uris.
|
// TODO(syoyo): Support ascii or utf-8 data uris.
|
||||||
if (IsDataURI(uri)) {
|
if (IsDataURI(uri)) {
|
||||||
if (!DecodeDataURI(&shader->source, uri, 0, false)) {
|
if (!DecodeDataURI(&shader->source, uri, 0, false)) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -2328,7 +2331,6 @@ bool TinyGLTFLoader::LoadASCIIFromFile(Scene *scene, std::string *err,
|
|||||||
static_cast<unsigned int>(buf.size()), basedir,
|
static_cast<unsigned int>(buf.size()), basedir,
|
||||||
check_sections);
|
check_sections);
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user