Description: I'm not exactly sure what's going on, but filing anyway.
I load a 70+mb .obj file and get the 'loading' event long before the asset becomes visible on screen. Perhaps it's the post-processing and not loading?
There's a timeout attribute on a-assets:
https://github.com/aframevr/aframe/blob/dev/src/core/a-assets.js#L26
It has a default value of 3000ms but we should maybe remove the timeout by default. @ngokevin what do you think?
I think the issue is that the event is not firing at the right time.
Hm, I was seeing the timeout hit in the console yesterday but not today.
The problem still exists regardless.
I think it's still not clear whether there's a bug or not. The event is
emitted possibly when the asset finishes loading but before it is processed
and rendered. If that's true, maybe it means we need another event?
On Fri, Mar 11, 2016 at 10:50 AM Kevin Ngo [email protected] wrote:
I think the issue is that the event is not firing at the right time.
—
Reply to this email directly or view it on GitHub
https://github.com/aframevr/aframe/issues/1155#issuecomment-195495717.
Maybe it is cached? But I wouldn't doubt there's a bug, the assets system definitely needs to be put through its strides.
To add a bit:
In the case that all the assets are loaded from the disk cache, the "loaded" event either doesn't fire or fires so early on that it's hard to set up another event handler at such a place in the load sequence that you can actually catch the event happening.
One solution could be just to add a flag "assetsLoaded" somewhere under AFRAME. that is globally visible. That flag would be set when the "loaded" event is triggered. That way we can skip setting up listeners in case assets are already loaded.
<a-assets>
<a-asset-item id="model-obj" src="the-source..."></a-asset-item>
<a-asset-item id="model-mtl" src="another-source..."></a-asset-item>
</a-assets>
document.querySelector('#model').addEventListener('model-loaded', function() {
console.log('loaded');
});
UPDATE:
That works, according to https://github.com/aframevr/aframe/blob/master/src/components/obj-model.js#L51
The event is called 'model-loaded' not 'loaded'. And I have to listen on the entity which represents the model, not the asset.
I don't think model-loaded is the right event name. A-frame docs say it is "loaded" but the bug persists. The event is fired way before the model is loaded.
See model-loaded in https://aframe.io/docs/0.7.0/components/obj-model.html
I was using the loaded event to determine when a large image finishes loading, but users with slow internet noticed that my loading indicator disappeared before the image appeared. Triggering a loaded event before the asset has actually loaded is a little misleading. I would volunteer to fix this, if others are in agreement that this is a bug and not a feature.
@Ely-S As described in https://github.com/aframevr/aframe/issues/1155#issuecomment-195494643 you can use the timeout attribute. Set it to a very large value e.g 10 hours in ms (36,000,000) and you will be able to measure what you need.
@dmarcos Thanks for your quick response. I'm using the materialtextureloaded event on the <a-image> because it is the most accurate way to determine when an image is ready to be viewed.
I offer to fix this because it seems like a counter-intuitive behaviour. If someone were interested in waiting for a load event or a timeout event, whichever happens first, they could do that by listening for both events separately.
@Ely-S materialtextureloaded is good.
Not sure if there's a fix to be made in your case as a-assets seems to be working as intended. Is setting a high timeout value not working for you? The original bug claimed that loaded was maybe firing prematurely and not honoring the timeout value albeit never confirmed. We should probably close this issue since we haven't been able to reproduce this for a couple of years.
As described in docs the purpose of a-assets is:
A-Frame has an asset management system that allows us to place our assets in one place and to preload and cache assets for better performance. Note the asset management system is purely for preloading assets. Assets that are set on entities at runtime could be done via direct URLs to the assets
If a-assets doesn't benefit in your case you can safely skip.
@dmarcos I was confused because the load event was fired before loading was completed, but if that is the intended behaviour then it should be safe to close this.
Most helpful comment
<a-assets><a-asset-item id="model-obj" src="the-source..."></a-asset-item><a-asset-item id="model-mtl" src="another-source..."></a-asset-item></a-assets>document.querySelector('#model').addEventListener('model-loaded', function() {console.log('loaded');});UPDATE:
That works, according to https://github.com/aframevr/aframe/blob/master/src/components/obj-model.js#L51
The event is called 'model-loaded' not 'loaded'. And I have to listen on the entity which represents the model, not the asset.