-
-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to disable image loading #494
Conversation
@@ -1213,6 +1213,9 @@ class Model { | |||
|
|||
bool operator==(const Model &) const; | |||
|
|||
// The base directory of the glTF model file | |||
std::string baseDir; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to find the model's image files
Question is if operator== for Model should honor this or not? Compare only the contents of the model, or also where it was loaded from?
std::string decoded_uri; | ||
if (!image.uri.empty()) { | ||
// If image has uri, use it as a filename if it is not a data uri | ||
if (!IsDataURI(image.uri)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to handle data URI here, as we leave images with data URIs as is, instead of loading the data and clearing their URI.
bool sourceIsTarget = false; | ||
if (!decoded_uri.empty() && imageToWrite.image.empty()) { | ||
std::string sourceFilePath; | ||
if (LoadExternalFile(&imageToWrite.image, &sourceFilePath, nullptr, nullptr, decoded_uri, sourceBaseDir, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Load the source image, and if able to do so write it to target directory.
@@ -2522,6 +2586,10 @@ static bool LoadExternalFile(std::vector<unsigned char> *out, std::string *err, | |||
return false; | |||
} | |||
|
|||
if (foundFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return the filepath that was actually found
d7607a9
to
dd25e77
Compare
I recommend to use your own image load/save handler to control image loading for a while. |
I tried that, but having my own image loader and writer is not sufficient to solve the problem. Loading works with my own image loader, but writing doesn't. Images that do not hold any data are not passed to the image writer routine. Moreover, images that use data URIs are also not possible to handle, because their URIs are wiped outside of the image loader, so one loses their data. Only images that have their data in buffers are handled correctly. I can try to come up with a minimal changeset to fix those deficiencies, so that I can skip image loading, if I use custom image loaders and writers. |
You are better first file a github issue. |
Hi. This is a PR which allows to completely disable image loading. This is important if one has glTF models with gigabytes of external images, or a huge GLB where most of the data is images.
Image saving is still correctly handled, by looking for the source model's image files, and copying them over to the directory where the target glTF is written.