Skip to content
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

Merged
merged 6 commits into from
Feb 27, 2018

Conversation

donmccurdy
Copy link
Collaborator

@donmccurdy donmccurdy commented Dec 14, 2017

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 and options.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

@takahirox
Copy link
Collaborator

how to manage the async parts

Voting for Promises.

@mrdoob mrdoob added this to the rXX milestone Feb 25, 2018
@fernandojsg
Copy link
Collaborator

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.
Btw this changes makes obsolete the proposal and changes on #13419 but I guess it will take more time to review :)

@donmccurdy donmccurdy force-pushed the feat-gltfexporter-image-bufferviews branch from 95b249b to 14c146d Compare February 26, 2018 17:26
@donmccurdy donmccurdy force-pushed the feat-gltfexporter-image-bufferviews branch from 14c146d to 9f67353 Compare February 26, 2018 17:33
@donmccurdy
Copy link
Collaborator Author

donmccurdy commented Feb 26, 2018

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.

@donmccurdy donmccurdy changed the title [WIP] GLTFExporter: Export images as binary in GLB. GLTFExporter: Export images as binary in GLB. Feb 26, 2018
* @param {Blob} blob
* @return {Promise<Integer>}
*/
function processBufferViewImage ( blob ) {
Copy link
Collaborator

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

@fernandojsg
Copy link
Collaborator

@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.

@donmccurdy
Copy link
Collaborator Author

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.

@fernandojsg
Copy link
Collaborator

Yep, so in that case 👎 to the extra params

@mrdoob
Copy link
Owner

mrdoob commented Feb 26, 2018

Is this ready to go then?


}

return new Promise( function (resolve) {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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 () {
Copy link
Collaborator

@takahirox takahirox Feb 26, 2018

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'.

Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

@mrdoob mrdoob modified the milestones: rXX, r91 Feb 27, 2018
@fernandojsg
Copy link
Collaborator

@donmccurdy looking great! 👏

@mrdoob mrdoob merged commit 851c505 into mrdoob:dev Feb 27, 2018
@mrdoob
Copy link
Owner

mrdoob commented Feb 27, 2018

Sweet! Thanks!

@donmccurdy donmccurdy deleted the feat-gltfexporter-image-bufferviews branch July 9, 2021 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants