-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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 lazy option to GLTFLoader. #14492
Conversation
|
||
return; | ||
|
||
} |
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.
Would you want to also return the json
object here? I imagine users will want to use that to access extensions
data, or to list the available materials.
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.
The json
object is available via parser.json
. I think this lines up well with the non-lazy method.
When specifying lazy
:
onLoad( { parser: parser } )
When using the default non-lazy method:
onLoad( {
scene: scene,
scenes: scenes,
cameras: cameras,
animations: animations,
asset: json.asset,
parser: parser,
userData: {}
} )
@@ -172,6 +180,14 @@ THREE.GLTFLoader = ( function () { | |||
|
|||
} ); | |||
|
|||
if ( this.lazy ) { |
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.
There is also some pre-processing in parser.parse()
that still needs to happen here — specifically parser.markDefs()
.
Doesn't this work for
Update: Oops, Update2: Oops, we need to expose a method converting from binary to json for binary glTF. |
This extension could perhaps be implemented without the |
I agree, I think the Another example of something we will use this for in Hubs: We need to rewrite URLs for our file proxy using an asynchronous API after downloading the glTF json but before calling |
First, I agree with having hook points for handling user-defined extensions. My concern for Before we go forward for further discussion, I have one question. How do you expect user uses |
In addition to the case of implementing extensions, note that the glTF spec says:
For users who want to do this, manually downloading the JSON file and then "parsing" the entire thing doesn't seem like the right API. Even if you already had the JSON downloaded, I think you'd want a Or maybe the file contains multiple scenes, one for each zone in the world, and you only want to download each zone as the user reaches it. This is preferable to having separate Out of scope for this PR, but we could make this even more user-friendly with a simple helper method that does lookups by name instead of by index: tl;dr — I do think having a convenient way of getting dependencies out of a glTF file one by one is a good thing. But if there are better APIs for it than a
|
I agree with @donmccurdy, being able to get dependencies out of a glTF file is important and one of the nice things about this API. I'd like to see the ability to modify the JSON after loading a GLTF/GLB's JSON. Ideally the loader handles both formats and hands me a JSON object so I don't have to check the response content type and magic integer and call I'd also like to have the ability to pull images, bufferViews, specific nodes, etc out of the glTF asset. This will be useful for packing additional assets into a glTF file. However, if there's a better API than |
Agreed with providing APIs to access the dependencies. Wondering which one do custom-extension developers want before parsing entire glTF, dependent Three.js object or dependent json content. I suppose json content rather than Three.js object? I think one of the major use cases where to handle custom-extension before parsing entire glTF is to prevent downloading/loading/parsing unnecessary assets. For example, material's custom extension chooses lower resolution one for mobile use. In that case with parser's |
Adding assets? Can you give me some examples? |
That's OK I think — the material and its dependencies should be fully loaded, just as long as we're only loading the textures needed for that material and no more. There are a few places in GLTFLoader where we use getDependencies (plural), and we should try to remove those, but that can be another PR. |
I meant, for example, a glTF material refers to large size textures and the material's custom extension refers to small size textures for mobile use. For mobile use, user doesn't want to download the large textures and instead wants to download the small textures. But I think the purpose of providing a hook point to custom extension developers before parsing entire glTF is providing a way to prevent unnecessary downloading/parsing data. But I don't think |
I see two use cases here:
Technically both cases work with On the other hand, (2) is not possible without the |
|
Except that all available scenes will be loaded eagerly. The content author would need to be sure nothing is referenced by any scene, or that there are no scenes in the asset at all. For most users I think that would involve hand edits to the file, so an API for lazy-loading does still seem simpler. |
Now I have some ideas/thoughts. Let me share after I'm back to home next week. |
Sorry I'm late. I suggest to add I'll write the reason this weekend, time to sleep now. |
I think there're three use cases in glTF loader.
For 1., users use And IIRC returning For 2. and 3., users can use Parser is the core of I speculate one of the reasons why you suggested |
This use case is not temporary — users should be able to implement custom extensions without hacking the loader, at least for basic use cases. How do you suggest var loader = new THREE.GLTFLoader();
loader.setDRACOLoader( dracoLoader );
loader.createParser( 'foo.gltf', async function ( parser ) {
var mesh = await parser.getDependency( 'mesh', 0 );
}, undefined, function ( e ) {
console.error( e );
} ) |
I agree with providing a way to process their custom extension in user side without hacking (I specified it as 3. above) I meant, returning
Yes, something like that. I meant |
With #14779 merged I think it would be a reasonable time to revisit this, if you are still interested. I'm still not sure of the right API here though. |
I still prefer separating |
I think we can close this PR. I'm in favor in the |
This PR adds the ability to lazily load or load parts of a glTF model. This can also be used to modify the glTF before calling
parser.parse()
. We intend to implement theMOZ_alt_materials
extension in this way (see #14470).This was previously discussed in: #11682