Fetching Models at Runtime with Sceneform and ARCore

The latest release of Sceneform (v1.5) introduces the ability to load models at runtime, this solves the problem of shipping large APKs with the models bundled at compile time.
In this quick post I’ll demonstrate how to fetch a gLTF (GL Transmission Format) model straight from Google Poly. Poly is a great website which allows you to download free to use 3D models, just be sure to credit the author. For the purposes of this demo I’ll use this Beagle model created by Google.

The problem here is that I do not have a direct URI in which I can fetch the gLTF model from. After a bit of digging through the source I was able to find the link that I will use in our code.
Update: Thanks to Stanlo Slasinski for pointing out that Poly has a REST API we can use.

Now I have the remote download link for our gLTF model I can load it on app launch. I’ve branched off of my AR Demo Repo I used when I wrote “Build your first Android AR app with ARCore and Sceneform in 5 minutes”.
Lets grab the latest version of Sceneform in our app’s build.gradle file and include the new assets library.
implementation "com.google.ar.sceneform.ux:sceneform-ux:1.5.0"
implementation 'com.google.ar.sceneform:assets:1.5.0'
And don’t for get about updating our top level gradle file.
classpath 'com.google.ar.sceneform:plugin:1.5.0'
Now swapping into the MainActivity.kt, we can replace our asset name with the new url we retrieved earlier.
addObject(Uri.parse("https://poly.googleusercontent.com/downloads/0BnDT3T1wTE/85QOHCZOvov/Mesh_Beagle.gltf"))
Then we need to modify the placeObject()
method to handle our remote resource.
And it’s as easy as that! After a short delay the model is successfully retrieved and added to the scene just as if it was bundled locally with our app.

The only downside of this approach is that so far I can’t see anyway to control the size of the model that has been downloaded. As you can see the model above takes up a significant amount of space, a solution to this would either be hosting smaller models in general or giving the user more control over scaling the model.
Update: Thanks to Tim Psiaki for pointing out the setScale()
method in RenderableSource to solve the above problem.
I think this new addition to Sceneform opens up a lot of doors for developers, now that we can host our 3D models we won’t need to ship bloated APKs and be able to serve these models only if and when our users need them.
If you want to check out this code there’s a feature/fetch-model-remotely
branch on this repo you can play around with.
Also if you have any questions or comments on this post or anything at all AR related feel free to reach out to me on Twitter, cheers!