aframevr / aframe

:a: Web framework for building virtual reality experiences.
https://aframe.io/
MIT License
16.65k stars 3.96k forks source link

Preloading .glb models with asset system #2420

Open takahirox opened 7 years ago

takahirox commented 7 years ago

Description:

a-asset-item is for preloading and caching assets. But glTF data consists of glTF file and other files specified in the glTF file, like .bin, .glsl, image(texture) files.

<a-asset-item id="model" src="something.gltf"></a-asset-item> preloads only .glTF file.

How can we preload all the involved files?

Do we make glTF special a-asset-item in which it loads glTF with THREE.GLTFLoader ?

donmccurdy commented 7 years ago

Does this block #2378?

I think the caching is a moot point for now, GLTFLoader has a cache built in. In terms of preloading, agree, but it's the same situation as other loaders (OBJ and COLLADA won't pre-load their textures, either) except that glTF file can optionally have larger .bin resources. If someone wants to combine everything (geometry, shaders, textures, ...) into a single .glb file they can do that, and the COLLADA->GLTF converter supports it. So don't think this should be too critical, or least not enough to justify a special case for glTF.

If it is something we want to solve robustly, maybe we want a general model case for assets?

<a-asset-item type="model" gltf-model="url(...)"></a-asset-item>

And if the type is model, the asset waits for a model-loaded event rather than a particular file URL. This should work for all model types, including their textures, and the *-model components theoretically wouldn't need to change (although el.setObject3D() might break...).

takahirox commented 7 years ago

Does this block #2378?

No, different topics.

Yep, this isn't serious issue (yet) and isn't glTF specific. I agree with adding type="model" property. (Or all?) Let's keep discussing slowly to see if it's ok and there's any other better ways.

donmccurdy commented 7 years ago

Let's try to look into this with 0.7.0. As it is now, the .gltf will be cached but multiple requests get made for .bin files referenced by this. Probably this should be fixed at the three.js level, not here, but I'm not sure.

ngokevin commented 7 years ago

What about inferring from the file extension and we keep the src API?

AVGP commented 7 years ago

we could infer from the src attribute that it's a glTF and do some superficial parsing to extract the assets and preload 'em so they're at least in the browser cache when the GLTFLoader does the heavy lifting?

donmccurdy commented 7 years ago

That pre-parsing is feasible for glTF... I'm less excited about doing it for other formats like COLLADA and OBJ. Would we be comfortable only doing this for glTF? If not, and we want it to work for other types of models, I think we need some system by which <a-asset-item/> can actually invoke the appropriate loader, like:

<a-asset-item gltf-model="foo.gltf"/>
machenmusik commented 7 years ago

Seems to me that, assuming it's possible, the use of .glb (single file) should be encouraged if folks want to be able to preload as a generic single file?

If taking the approach of having asset items invoke loaders, maybe just a preload boolean in the loaders (or some other not-horrible way the components should know). If we use video as an comparative use case, if you want to preload video, you usually specify as element within a-assets, then reference by selector when you use it.

donmccurdy commented 7 years ago

Seems to me that, assuming it's possible, the use of .glb (single file) should be encouraged if folks want to be able to preload as a generic single file?

Great point. It's not possible to convert a glTF->glb directly yet, but that should be supported soon-ish. Maybe we just recommend .glb wherever possible.

donmccurdy commented 6 years ago

Even for a .glb, the asset management system isn't behaving the way i'd like:

<a-scene environment>
      <a-assets>
        <a-asset-item id="castle" src="../assets/castle/Castle.glb"></a-asset-item>
      </a-assets>
      <a-entity position="0 0 0"
                scale="3 3 3"
                gltf-model="#castle">
      </a-entity>
</a-scene>

In this example the scene starts presenting with just the environment visible, and the castle flickers in a second later. Because GLTFLoader parses asynchronously, presumably. I'm inclined to say we don't NEED to solve secondary dependencies of <a-asset-item/> .gltf files yet, but we should have a better story for loading a .glb ideally. Waiting until a .glb has parsed would probably fix the first case anyway.

donmccurdy commented 6 years ago

There are now multiple tools (https://sbtron.github.io/makeglb/, https://glb-packer.glitch.me/) for packing glTF files and their dependencies into GLB archives, so I don't think we should do anything special for .gltf here.

As mentioned above, it would be ideal if there were some way to ensure a .glb (or other model) can hold the asset system until it parses, not just until the content is downloaded, because parsing may not complete for several frames. Renaming the issue accordingly.

machenmusik commented 6 years ago

+1 for focusing on .glb now that it's easy enough to make that happen.

A suggestion:

juansho01 commented 5 years ago

I had an issue load an glb model: can load the model and the animation but this doesn’t show the textures of the model? Why happen this?

donmccurdy commented 5 years ago

@juansho01 could you file a new issue, and include enough information (demo, code, model) for others to reproduce the issue?

NVFedorov commented 3 years ago

Any progress on this? Is this available in aframe 1.0.4 release?

Sinnich commented 2 years ago

Has this been dropped?