mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-16 17:46:00 +08:00
Code clean-up. Reviewed by @Squareeyes.
This commit is contained in:
parent
ba28ddcc9e
commit
246654a15a
60
tiny_gltf.h
60
tiny_gltf.h
@ -1671,7 +1671,7 @@ static bool ParseImage(Image *image, std::string *err, const json &o,
|
|||||||
if (hasBufferView && hasURI) {
|
if (hasBufferView && hasURI) {
|
||||||
// Should not both defined.
|
// Should not both defined.
|
||||||
if (err) {
|
if (err) {
|
||||||
(*err) += "One of `bufferView` or `uri` should be defined, but both are defined for Image.\n";
|
(*err) += "Only one of `bufferView` or `uri` should be defined, but both are defined for Image.\n";
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1685,8 +1685,8 @@ static bool ParseImage(Image *image, std::string *err, const json &o,
|
|||||||
|
|
||||||
ParseStringProperty(&image->name, err, o, "name", false);
|
ParseStringProperty(&image->name, err, o, "name", false);
|
||||||
|
|
||||||
double bufferView = -1;
|
|
||||||
if (hasBufferView) {
|
if (hasBufferView) {
|
||||||
|
double bufferView = -1;
|
||||||
if (!ParseNumberProperty(&bufferView, err, o, "bufferView", true)) {
|
if (!ParseNumberProperty(&bufferView, err, o, "bufferView", true)) {
|
||||||
if (err) {
|
if (err) {
|
||||||
(*err) += "Failed to parse `bufferView` for Image.\n";
|
(*err) += "Failed to parse `bufferView` for Image.\n";
|
||||||
@ -1713,48 +1713,46 @@ static bool ParseImage(Image *image, std::string *err, const json &o,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse URI & Load image data.
|
||||||
|
|
||||||
std::string uri;
|
std::string uri;
|
||||||
std::string tmp_err;
|
std::string tmp_err;
|
||||||
if (hasURI) {
|
if (!ParseStringProperty(&uri, &tmp_err, o, "uri", true)) {
|
||||||
if (!ParseStringProperty(&uri, &tmp_err, o, "uri", true)) {
|
if (err) {
|
||||||
if (err) {
|
(*err) += "Failed to parse `uri` for Image.\n";
|
||||||
(*err) += "Failed to parse `uri` for Image.\n";
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> img;
|
std::vector<unsigned char> img;
|
||||||
|
|
||||||
if (hasURI) {
|
if (IsDataURI(uri)) {
|
||||||
if (IsDataURI(uri)) {
|
if (!DecodeDataURI(&img, uri, 0, false)) {
|
||||||
if (!DecodeDataURI(&img, uri, 0, false)) {
|
if (err) {
|
||||||
if (err) {
|
(*err) += "Failed to decode 'uri' for image parameter.\n";
|
||||||
(*err) += "Failed to decode 'uri' for image parameter.\n";
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
return false;
|
||||||
// Assume external file
|
}
|
||||||
// Keep texture path (for textures that cannot be decoded)
|
} else {
|
||||||
image->uri = uri;
|
// Assume external file
|
||||||
|
// Keep texture path (for textures that cannot be decoded)
|
||||||
|
image->uri = uri;
|
||||||
#ifdef TINYGLTF_NO_EXTERNAL_IMAGE
|
#ifdef TINYGLTF_NO_EXTERNAL_IMAGE
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
if (!LoadExternalFile(&img, err, uri, basedir, 0, false)) {
|
if (!LoadExternalFile(&img, err, uri, basedir, 0, false)) {
|
||||||
if (err) {
|
if (err) {
|
||||||
(*err) += "Failed to load external 'uri' for image parameter\n";
|
(*err) += "Failed to load external 'uri' for image parameter\n";
|
||||||
}
|
|
||||||
// If the image cannot be loaded, keep uri as image->uri.
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
// If the image cannot be loaded, keep uri as image->uri.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (img.empty()) {
|
if (img.empty()) {
|
||||||
if (err) {
|
if (err) {
|
||||||
(*err) += "Image is empty.\n";
|
(*err) += "Image is empty.\n";
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user