model-viewer icon indicating copy to clipboard operation
model-viewer copied to clipboard

AR is not working on Android devices (couldn't load object)

Open bankey1443 opened this issue 7 years ago • 30 comments

Description

Attempting to use the model-viewer in our project, and it works wonderfully on desktop and iOS. However, I am unable to get the AR aspect to work on our android devices. Displaying the 3d-objects works fine, but when we tap on the AR button it seems like it attempts to load the Scene Viewer but just displays "Couldn't load object".

For the model-viewer src, I have tried using both https://... paths and relative paths to the directory that contains the .gltf file. We currently have three separate 3d-models for testing purposes, and they all have the same issue. Right now we are using the bundled build and adding script tags to the page we want to display the 3d-models.

Live Demo

The following demo is pretty close to what we have on our test page. We have been removing the 'optional' js (and required webcomponents-loader.js pertaining to Edge/Firefox support) but decided to leave it in for the demo.

Note that we are in the early stages of implemented 3d-model functionality on our website, and the .bin, .gltf, and .usdz files we currently have are rather large (the model in the demo has a .usdz file that is around 15MB and the .bin file is around 10MB, so at its current state can eat up data plans pretty quickly):

https://entertaining-bosworth.glitch.me/

Browser Affected

  • [ ] Chrome
  • [ ] Edge
  • [ ] Firefox
  • [ ] Helios
  • [ ] IE
  • [ ] Safari

OS

  • [x] Android (Galaxy S7 and S10, both Android 8.0+)
  • [ ] iOS
  • [ ] Linux
  • [ ] MacOS
  • [ ] Windows

Versions

  • model-viewer: 0.7.1, although we couldn't get it to work using 0.7.0 as well

bankey1443 avatar Oct 24 '19 15:10 bankey1443

@bankey1443 thanks for reporting, and for the test case. It looks like this is probably a Scene Viewer compatibility bug of some kind. I will report to the Scene Viewer team and update this thread as I learn more.

cdata avatar Oct 24 '19 16:10 cdata

@cdata thank you for getting to this so quickly. As a follow-up, I cloned the repository and added my 3d-model files for testing purposes. I made a bare-bones test page

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, user-scalable=no,minimum-scale=1.0, maximum-scale=1.0">
    </head>
    <body>
        <model-viewer src="assets/ChromeHandle/NEW_Chrome_handle.gltf"
                      ios-src="assets/ChromeHandle/NEW_Chrome_handle.usdz" ar auto-rotate camera-controls
                      quick-look-browsers="safari chrome" background-color="#222">
        </model-viewer>

        <!-- Loads <model-viewer> for modern browsers: -->
        <script type="module" src="https://unpkg.com/@google/[email protected]/dist/model-viewer.js"></script>

        <!-- Loads <model-viewer> for old browsers like IE11: -->
        <script nomodule src="https://unpkg.com/@google/[email protected]/dist/model-viewer-legacy.js"></script>
    </body>
</html> 

I ran npm run serve and exposed my local so I can access it with my mobile test devices. Following these steps I was able to get the AR working on my Android devices. Am I missing some dependencies? I'm not sure why it would work this way and not in the glitch.me demo.

bankey1443 avatar Oct 24 '19 17:10 bankey1443

@bankey1443 that's very strange, I would actually expect the opposite. Scene Viewer is supposed to have trouble with localhost origins.

I filed this bug internally with the Scene Viewer team. Meanwhile, you can use this web-based Scene Viewer test tool (currently in beta) to get some feedback on the model: https://vr.google.com/scene-viewer-preview

I noticed it outputs some warnings with the test model you provided above: image

cdata avatar Oct 25 '19 18:10 cdata

@cdata As a minor follow-up, I did use the test tool on the model and I received the same warning about the maximum number of triangles. The other sample models that we have came back with no errors. Unfortunately that's all I have to provide at this point; I'll continue to keep trying on my end.

abyra-cjpony avatar Oct 28 '19 11:10 abyra-cjpony

@abyra-cjpony are you also experiencing problems displaying your models in Scene Viewer?

For those of you with issues, do the models render in the web-based Scene Viewer test tool?

cdata avatar Oct 28 '19 16:10 cdata

@cdata Oh my fault, was using a separate account outside of my work account. Both accounts are mine; sorry for the confusion. The web-based Scene Viewer I tried three different models on, and 2/3 returned no errors (I tested a sample Khronos file as well and it did not return any errors), but none of them rendered in the browser. I just assumed that since it was in beta that it was not showing the model in the browser, but if it is supposed to display the file, then it did not work.

Edit: accidentally closed issue.

bankey1443 avatar Oct 28 '19 16:10 bankey1443

@bankey1443 oh, thanks for clearing that up 😅

Scene Viewer and <model-viewer> currently use different model loading and rendering backends. The web based tool I linked you to uses a backend that is very similar to Scene Viewer, so if it doesn't render there it probably won't render in Scene Viewer either.

Thanks for confirming the issue. The Scene Viewer team has prioritized this bug, so hopefully we will have some feedback for you soon (although they are a different team and I cannot make promises about when they will get to it).

cdata avatar Oct 28 '19 17:10 cdata

@cdata sounds good, thank you for the quick replies. Let me know if I'm able to help out in any way.

bankey1443 avatar Oct 28 '19 17:10 bankey1443

@cdata I'm continuing to try to find a fix, although I am running out of ideas to try. Have others reported a similar issue, or is it just me that is having issues with Android devices? I figure that if others also had issue that they would be reported, although I haven't seen any other reports about this.

Edit: Although undocumented, I went and tried simply calling [Model].activateAR() and I get the same error when using an Android device Couldn't load object. Looks like there's something wrong with this object.Works fine on iOS. Added this comment in case it helps with figuring out the issue or at least narrowing it down to whether it is Scene Viewer or not.

bankey1443 avatar Oct 30 '19 13:10 bankey1443

@bankey1443 unfortunately, I believe this is an isolated incident and probably related to the specific details of your models. That doesn't necessarily mean your models are wrong or broken, it just means that something about them is incompatible with Scene Viewer (and it could even be a Scene Viewer bug).

My best recommendation at this point would be to incrementally simplify your models, working to a point where you don't see warnings in the test tool. Other than that, maybe try building a model back up from primitives until it fails to render in the test tool.

It is interesting to note that iOS works, but ultimately it is an Apples 😅and oranges comparison because iOS uses a completely different file format (USDZ) and a completely different native app viewer (Quick Look).

cdata avatar Oct 30 '19 16:10 cdata

@cdata If it wasn't for other sample Khronos examples also not working I would be inclined to think that it would be a problem with the models we are using (tried using the Khronos DamagedHelmet which also does not render in the test tool).

I'm not familiar with how Scene Viewer works, but currently on our dev site we are using src="https://hostname.com/path/to/gltf/file" which has Cloudflare on it. Reading up on Scene Viewer I see that it should use local files over a secure connection which is what it seems like we are doing. Doing a curl on the https://... path goes through Cloudflare which may or may not be blocking the files needed for the Scene Viewer.

bankey1443 avatar Oct 30 '19 18:10 bankey1443

@bankey1443 Sorry, I may have missed an important detail. When you say the other Khronos models do not work, that doesn't match our expectations. Do those models work in the web-based test tool?

cdata avatar Oct 30 '19 19:10 cdata

@cdata so I did not know that you can simultaneously drag and drop multiple files into the test tool. 2/3 of my test models are working once I drop and drop the .gltf and their associated .bin and image files (the Khronos models also worked). On the model that I am using on the glitch live demo, I have

"buffers": [
    {
      "byteLength": 9906352,
      "name": "buffer-0",
      "uri": "NEW_Chrome_handle.bin"
    }
  ]

but Scene Viewer does not seem to be using the bin file (works on the test tool). Any thoughts?

bankey1443 avatar Oct 31 '19 11:10 bankey1443

Hey @bankey1443 is that the model that you showed us in the demo above?

cdata avatar Nov 02 '19 00:11 cdata

@cdata correct. Both .gltf and .bin files are in the same directory.

bankey1443 avatar Nov 04 '19 12:11 bankey1443

@cdata update: on our test site we have tried .glb and both .gltf types (both embedded and with separate assets in the same directory). We have verified that these are valid models by using the web-based test tool provided, along with hosting them on glitch.com and individually testing each one to make sure both 3d and AR work, which it does on glitch.com).

When we click/tap on the product image on our test site, it opens up a popup that contains the model-viewer (the popup is created when the image is clicked/tapped so the model-viewer is not on the page on page load). The AR button, on several Android devices, still displays the same 'cannot load object' error that we have been getting for some time now. We though it was an issue with Cloudflare, so we turned off Cloudflare on our site temporarily and retried, with no luck. All of the additional 'required/optional polyfill scripts are also being added to the page head.

I'm completely baffled as to why it doesn't work for us. I feel like I've tried everything, especially when it works on glitch.com.

bankey1443 avatar Nov 05 '19 17:11 bankey1443

Turns out Cloudflare was the issue. When accessing the src file via the URL, it displays on screen rather than starting the download immediately as I've seen on other websites. Once we turned off Cloudflare and waited for the changes to take into effect, it worked. Now we just need to figure out how to make the src file start downloading versus showing it in the browser.

Thank you for your help @cdata. Sorry for being such a pain with this.

bankey1443 avatar Nov 05 '19 19:11 bankey1443

Hey @bankey1443, I'm running into this same exact issue you went through, except the production app is hosted on Google Cloud.

Hooking up my Pixel phone via adb, I get an error saying "invalid json". Copying and pasting the url where the file is hosted into the web browser does successfully download the .glb though.

Were you able to get AR Scene Viewer working? I couldn't tell if you got to that result from the last post.

mattchiang777 avatar Apr 29 '20 16:04 mattchiang777

Warnings

Hello. A noob intern here.. I have the same problem. The glb file I exported won't load in AR on android device. My task was to export an animated asset in diff file types (fbx, glb and usdz) and somehow this file had these issues. I tested it from the modelviewer.. tbh it's out of my comprehension and I don't know how to solve this :(

Iforintern avatar Oct 19 '21 08:10 Iforintern

I am using Model Viewer to display 3D model in AR. My model is getting displayed on iOS but not getting displayed on android. What can be possible reason and solution to this problem?

Hemanpreet avatar Jul 15 '22 07:07 Hemanpreet