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

Preloading .glb models with asset system #2420

Open
takahirox opened this issue Feb 20, 2017 · 15 comments
Open

Preloading .glb models with asset system #2420

takahirox opened this issue Feb 20, 2017 · 15 comments

Comments

@takahirox
Copy link
Collaborator

takahirox commented Feb 20, 2017

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 ?

  • A-Frame Version: 0.5.0
  • Platform / Device: Any
@donmccurdy
Copy link
Member

donmccurdy commented Feb 20, 2017

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
Copy link
Collaborator Author

takahirox commented Feb 20, 2017

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 donmccurdy added this to the 0.7.0 milestone Jun 20, 2017
@donmccurdy
Copy link
Member

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
Copy link
Member

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

@AVGP
Copy link
Contributor

AVGP commented Aug 4, 2017

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 donmccurdy modified the milestones: 0.7.0, 0.8.0 Oct 16, 2017
@donmccurdy
Copy link
Member

donmccurdy commented Oct 17, 2017

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
Copy link
Contributor

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
Copy link
Member

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 donmccurdy modified the milestones: 0.8.0, 0.9.0 Mar 21, 2018
@donmccurdy
Copy link
Member

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 donmccurdy changed the title How to preload all the involved glTF data with a-asset-item Preloading glTF models with asset system Mar 25, 2018
@donmccurdy donmccurdy changed the title Preloading glTF models with asset system Preloading .glTF/.glb models with asset system Mar 25, 2018
@donmccurdy donmccurdy changed the title Preloading .glTF/.glb models with asset system Preloading .gltf/.glb models with asset system Mar 25, 2018
@donmccurdy donmccurdy modified the milestones: 0.9.0, 0.10.0 Aug 31, 2018
@donmccurdy
Copy link
Member

donmccurdy commented Aug 31, 2018

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.

@donmccurdy donmccurdy changed the title Preloading .gltf/.glb models with asset system Preloading .glb models with asset system Aug 31, 2018
@machenmusik
Copy link
Contributor

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

A suggestion:

  • optional field for asset items identifying the event name they wait for (e.g. loaded, model-loaded, materialtextureloaded)
  • asset item types that are well known like image, video sound should have appropriate events utilized
  • model parsing should fire an event when done, if it doesn't already, so it would be simple to wait for per the above

@juansho01
Copy link

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
Copy link
Member

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

@dmarcos dmarcos removed this from the 1.0.1 milestone Dec 18, 2019
@NVFedorov
Copy link

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

@Sinnich
Copy link

Sinnich commented Jan 26, 2022

Has this been dropped?

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

No branches or pull requests

9 participants