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

Question: How does assets.js work? #98

Closed
mi-skam opened this issue Jul 29, 2021 · 3 comments
Closed

Question: How does assets.js work? #98

mi-skam opened this issue Jul 29, 2021 · 3 comments

Comments

@mi-skam
Copy link

mi-skam commented Jul 29, 2021

Hi there,

I'd like to understand how the streetmix-assets component in src/assets.js does its job, but struggle to understand why it's so "complicated". Here are my questions:

  1. Why is AFRAME not in the namespace at runtime and hence window.AFRAME needed?
  2. I couldn't find a reference to the prototype property of the streetmix-assets definition. Does it mean it modifies the createdCallback and attachedCallback methods it inherited ? And what's the reason for that?
  3. Where did you find out about AFRAME.ANode.prototype ?
  4. Did you basically re-created a-assets-item ?

Thanks in advance!
Maksim

@kfarr
Copy link
Collaborator

kfarr commented Aug 10, 2021

Hi Maksim, sorry for delay, I was out on holiday.

The primary value is that the assets can be modified at runtime by the application that is using 3dstreet. The only use at the moment is the ability to set a path for the assets that can vary depending on environment (ie fetch assets locally when doing local dev, fetch assets from a specific CDN, etc.) Future use will leverage the ability to change asset packs or selectively load only specific assets required for a given scene.

As for the logic of assets.js, I would actually ask @zach-capalbo to comment on that if he's available. This was adapted from his work on a similar implementation for Vartiste. Here are docs from that project: https://vartiste.xyz/docs.html#Assets

@zach-capalbo
Copy link
Contributor

Hi Maksim,

The reason for the complexity is that street view needs to dynamically inject it's assets into the scene. This becomes tricky because a-assets gets created in the document body, after the streetmix javascript has been included in the header. This is a scheme to try to intercept the creation of a-assets and get them to wait for streetmix assets just like assets defined in the document body. It's not perfect, but seems to work. There is a stack overflow question / answer that goes into a little more detail here: https://stackoverflow.com/questions/64841550/a-frame-scene-initializes-before-assets-ready-when-dynamically-adding-a-asset-i/64868581#64868581

To answer your questions:

  1. I don't know that there's actually a good reason.
  2. The streetmix-assets prototype is here: https://github.com/3DStreet/3dstreet/blame/main/src/assets.js#L155 It inherits from the a-node prototype, and overrides the createdCallback and attachedCallback in order to 1) pose as an a-asset-item so a-assets will wait for it to load, and 2) implement similar functionality to a-assets so that it can load children elements
  3. The a-frame source code: https://github.com/aframevr/aframe/blob/v1.2.0/src/core/a-node.js
  4. Yes, but more of a mix of a-asset-item and a-assets that allows nested asset trees

@kfarr
Copy link
Collaborator

kfarr commented Sep 7, 2021

Thanks @zach-capalbo for the follow-up! I have added some of this info to the main readme and developer documentation. I will mark this issue as closed now and can re-open if any additional info is needed.

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

3 participants