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

[HUBS] FileLoader: HTTP Range requests support #68

Merged
merged 1 commit into from
Nov 1, 2022

Conversation

takahirox
Copy link

@takahirox takahirox commented Oct 25, 2022

This PR is a cherry-pick of upcoming Three.js PR mrdoob#24580 needed for Hubs HTTP range requests support (mainly for LOD) Hubs-Foundation/hubs#5713

We can remove this commit when mrdoob#24580 will be merged to Three.js and we will upgrade our Three.js fork.

Copy link

@netpro2k netpro2k left a comment

Choose a reason for hiding this comment

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

Not really oppoosed to shipping this as is just to wrap up LOD stuff, but this API feels kind of odd to me. I would not expect a 200 response to throw an error.

@@ -19,7 +30,10 @@ class FileLoader extends Loader {

url = this.manager.resolveURL( url );

const cached = Cache.get( url );
const isRangeRequest = this.requestHeader.Range !== undefined;

Choose a reason for hiding this comment

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

Any reason for range header to be special? Might want to just include all headers in cache key.

Copy link
Author

@takahirox takahirox Oct 25, 2022

Choose a reason for hiding this comment

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

Because we Three.js have never heard problems for other headers so far. Perhaps we may rethink if we get problem report.

Cache key must be distinguished with range headers. Otherwise FileLoader misunderstands that different range request against the same URL are the same request. The responses must be different for different range requests.

@@ -77,7 +91,7 @@ class FileLoader extends Loader {
fetch( req )
.then( response => {

if ( response.status === 200 || response.status === 0 ) {
if ( response.status === 200 || response.status === 206 || response.status === 0 ) {

Choose a reason for hiding this comment

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

I know its not new but I wonder what the 0 status is about.. Also again not new and maybe not worth changing but technically 200-299 are all "successful" responses.

Copy link
Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

wow, not sure how I missed that on the next line lol

@@ -88,6 +102,12 @@ class FileLoader extends Loader {

}

if ( isRangeRequest && response.status === 200 ) {

Choose a reason for hiding this comment

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

This was metnioned in the upstream PR as well. I think its a bit odd to throw in this case. The thing using the FileLoader should decide what they want to do in this case. Ex. The GLBRangeRequest should take that full response and pass it along to GLTFLoader so the whole glb does not need to be downloaded again.

With the above suggestion about cachekey it would also make it so this PR has nothing specific about range headers and is instead just fixing cache keys to respect headers.

Copy link
Author

@takahirox takahirox Oct 25, 2022

Choose a reason for hiding this comment

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

See

mrdoob#24580 (comment)
mrdoob#24580 (comment)

And Mugen approved.

the whole glb does not need to be downloaded again.

As I wrote somewhere else, I think disk cache can work and duplicated full range downloads can be avoided.

Choose a reason for hiding this comment

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

I forgot FileLoader does additional parsing and doesn't just pass you the response directly. Unfortunately that would make it hard to do what I was suggesting. As for browser cache.. Ideally we should be able to rely on that, but I think the browser isn't so great about honoring cache on large files.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if I understand correctly what you suggested but

The thing using the FileLoader should decide what they want to do in this case.

This is possible. See

@takahirox
Copy link
Author

Merging this Three.js upcoming feature. If you have any design feedback, better to send it to Three.js.

@takahirox takahirox merged commit 983c08c into hubs-patches-141 Nov 1, 2022
@takahirox takahirox deleted the FileLoaderRangeRequests branch November 1, 2022 01:00
takahirox added a commit that referenced this pull request Dec 7, 2022
[HUBS]
This change is needed for glTF LOD progressive loading.
This change is not merged to the official Three.js PR yet
but likely it can get in soon.

mrdoob#24580

We can remove this commit if the PR is merged to
the official Three.js and we upgrade our Three.js fork to
the one including the change.
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.

2 participants