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.
Games and rich 3D experiences traditionally preload their assets, such as models or textures, before rendering their scenes. This makes sure that assets aren’t missing visually, and this is beneficial for performance to ensure scenes don’t try to fetch assets while rendering.
<a-asset-item> are nodes in A-Frame, they will emit
loaded event when they say they have finished loading.
|loaded||All assets were loaded, or assets timed out.|
|timeout||Assets timed out.|
<a-asset-item> invokes the three.js
FileLoader. We can use
<a-asset-item> for any file type. When finished, it will set its
member with the text response.
|error||Fetch error. Event detail contains |
|progress||Emitted on progress. Event detail contains |
|loaded||Asset pointed to by |
Images are a standard DOM element so we can listen to the standard DOM events.
|load||Image was loaded.|
Audio and video assets are
HTMLMediaElements. The browser triggers
particular events on these elements; noted here for convenience:
|error||There was an error loading the asset.|
A-Frame uses these progress events, comparing how much time the browser buffered with the duration of the asset, to detect when the asset becomes loaded.