-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
GLTFExporter: Export images as binary in GLB. #12877
GLTFExporter: Export images as binary in GLB. #12877
Conversation
Voting for Promises. |
I'd vote for promises too. I'd also add an option to define the behaviour for the images if the user wants to export then as data URIs or bufferView. |
95b249b
to
14c146d
Compare
14c146d
to
9f67353
Compare
Rebased and switched to Promises, thanks! I don't think we want an option for data URIs instead of bufferView; they use 25–30% more space in a GLB with no benefit I'm aware of. |
* @param {Blob} blob | ||
* @return {Promise<Integer>} | ||
*/ | ||
function processBufferViewImage ( blob ) { |
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.
You don't need an space after function name
@donmccurdy regading the data uri option I was thinking on engines that doesn't have implemented bufferview for images, but I'm not aware of the current state of most of the engines so you may know more about it. |
It is part of the core spec, engines should consider it a requirement and I'm not aware of any that don't support this. Inclined to avoid the extra API surface unless the issue is brought up. |
Yep, so in that case 👎 to the extra params |
Is this ready to go then? |
|
||
} | ||
|
||
return new Promise( function (resolve) { |
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.
Need spaces before and after resolve
.
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.
Done ✅
|
||
var reader = new window.FileReader(); | ||
reader.readAsArrayBuffer( blob ); | ||
reader.addEventListener('loadend', function () { |
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.
Need a space before 'loadend'
.
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.
And how about using .onloadend
for the consistency with other parts in the exporter?
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.
Done ✅
@donmccurdy looking great! 👏 |
Sweet! Thanks! |
Work in progress, I'd like to (1) get feedback and (2) test this a bit more.The main change here is that when
options.binary === true
andoptions.embedImages === true
, the images will be written to bufferViews instead of Data URIs, taking up less space. For the example scene, it's a ~25% file size difference.I wasn't sure how to manage the async parts, since the processing so far hasn't needed as much of that. Didn't want to add callbacks to everything, and wasn't sure it was worth it to add Promises just for this change, but I could imagine the
next()
counters I'm using here might be confusing to read... Any preferences?/cc @fernandojsg