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

mixin with gltf-model using url path does not load #5273

Closed
kfarr opened this issue Apr 19, 2023 · 9 comments
Closed

mixin with gltf-model using url path does not load #5273

kfarr opened this issue Apr 19, 2023 · 9 comments

Comments

@kfarr
Copy link
Contributor

kfarr commented Apr 19, 2023

Description:

  • A-Frame Version: 1.4.1
  • Platform / Device: Chrome Desktop
  • Reproducible Code Snippet or URL:

When defining a gltf-model using url scheme as a mixin, the model does not load. However when using the same syntax without a mixin, the file loads.

      <a-assets>
        <a-mixin id="fire-truck-rig" gltf-model="url(https://assets.3dstreet.app/sets/vehicles-rig/gltf-exports/draco/fire-truck-pumper-rig.glb)"></a-mixin>
      </a-assets>
      <a-entity position="0 0 -9" mixin="fire-truck-rig"></a-entity>

generates console error of:

three.module.js:42746 Uncaught (in promise) TypeError: e.lastIndexOf is not a function
    at nd.extractUrlBase (three.module.js:42746:21)
    at pm.GLTFLoader.load (GLTFLoader.js:174:31)
    at gltf-model.js:44:19
e

Whereas this same syntax without using a mixin works as expected:
<a-entity gltf-model="url(https://assets.3dstreet.app/sets/vehicles-rig/gltf-exports/draco/fire-truck-pumper-rig.glb)"></a-entity>

reproducible here: https://mixin-gltf-url-error.glitch.me/
source: https://glitch.com/edit/#!/mixin-gltf-url-error

@gftruj
Copy link
Contributor

gftruj commented Apr 20, 2023

I think that when the mixin caches the properties it parses the url as {"url(https": "//rest/of/the/url)"} (fiddle)

@dmarcos
Copy link
Member

dmarcos commented Apr 20, 2023

a possible workaround. Add the model as a-asset-item instead of inline URL.

@gftruj
Copy link
Contributor

gftruj commented Apr 20, 2023

yea, it works like this:

<a-scene>
  <a-assets>
    <a-asset-item id="ftruck-model" src="https://assets.3dstreet.app/sets/vehicles-rig/gltf-exports/draco/fire-truck-pumper-rig.glb"></a-asset-item>
    <a-mixin id="fire-truck-loaded" gltf-model="#ftruck-model"></a-mixin>
  </a-assets>
  <a-entity position="-2 0 -9" mixin="fire-truck-loaded"  scale="0.1 0.1 0.1">
</a-scene>

glitch

@kfarr
Copy link
Contributor Author

kfarr commented Apr 20, 2023

Thanks @gftruj and @dmarcos yes you can use a-asset-item but in this case we already do that for most models and I am purposefully trying to lazy load some assets that are infrequently used such as fire truck.

Also @gftruj your first comment appears to be correct that for whatever reason the gltf-model attribute value is being parsed as a multi attribute instead of a single attribute string, therefore it is treating the ":" symbol in the URL as a separator between property name / value.

Here is the workaround that worked for me and accomplishes the objective of waiting to load the fire truck until it's referenced (removing the https: from the url path)

      <a-assets>
        <a-mixin id="fire-truck-rig" gltf-model="url(//assets.3dstreet.app/sets/vehicles-rig/gltf-exports/draco/fire-truck-pumper-rig.glb)"></a-mixin>
      </a-assets>
      <a-entity position="0 0 -9" mixin="fire-truck-rig"></a-entity>

https://glitch.com/edit/#!/mixin-gltf-url-error-fix?path=index.html%3A6%3A8

This workaround works great for me. Not sure how common this request is for others or if it's worth the effort to fix the behavior here, so ok if you want to close the ticket.

@dmarcos
Copy link
Member

dmarcos commented Apr 20, 2023

It's a bug, we have to fix it. PRs very welcome. I was just offering a temporary workaround.

@kfarr
Copy link
Contributor Author

kfarr commented Apr 21, 2023

Yes makes sense to fix. I dug in a bit to look and my guess so far is this is where the value is being cached, so the issue might be related to this call?
https://github.com/aframevr/aframe/blob/master/src/core/a-mixin.js#L67

it is doing naive string based chunking on :

compare to the asset parser which would be used instead without a mixin:

function assetParse (value) {

it is testing for url(...) syntax

potential other related functions:

if (hasUnclosedUrl.test(chunk)) {

@dmarcos
Copy link
Member

dmarcos commented Apr 21, 2023

Yes makes sense to fix. I dug in a bit to look and my guess so far is this is where the value is being cached, so the issue might be related to this call?

Could be. I would put a breakpoint there and check

@dmarcos
Copy link
Member

dmarcos commented Apr 21, 2023

Should be fix on master. Can you verify on master build? Thanks

@kfarr
Copy link
Contributor Author

kfarr commented Apr 22, 2023

Yes confirmed working as expected on latest build, thanks!
image

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