Fetching Models at Runtime with Sceneform and ARCore

微信扫一扫,分享到朋友圈

Fetching Models at Runtime with Sceneform and ARCore

Photo by
Mitchell Orr on
Unsplash

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.

Such a good puppy

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.

Ctrl + f “gltf” seemed to do the trick!

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”.

Build your first Android AR app with ARCore and Sceneform in 5 minutes*

*your mileage may vary heartbeat.fritz.ai

cgathergood/Your-First-AR-App-with-Sceneform

Contribute to cgathergood/Your-First-AR-App-with-Sceneform development by creating an account on GitHub. github.com

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.

Downloadable Doggie

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.

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.

cgathergood/Your-First-AR-App-with-Sceneform

Contribute to cgathergood/Your-First-AR-App-with-Sceneform development by creating an account on GitHub. github.com

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!

Calum Gathergood (@cgathergood) | Twitter

The latest Tweets from Calum Gathergood (@cgathergood). Scottish Software Engineer in Sydney currently working with… twitter.com

微信扫一扫,分享到朋友圈

Fetching Models at Runtime with Sceneform and ARCore

Java编程解析—淘宝大秒杀系统设计

上一篇

Token的10大设计模式 | 粉丝模式

下一篇

你也可能喜欢

Fetching Models at Runtime with Sceneform and ARCore

长按储存图像,分享给朋友