ARCore: Loading 3D models at runtime

Sumeet Rukeja
Sumeet Rukeja, Android Developer at Yudiz Solutions
Published on Dec 07, 2018 in Augmented Reality Developers Resources
ARCore: Loading 3D models at runtime

This article is a practical case revolving around existing code, which you can download here.

Overview

If you are familiar with ARCore and Sceneform, I’m sure that you’ll be well aware of its major drawback: It uses only .sfb files to load a model in AR.

No doubt that Sceneform provides a tool to convert models into files with .sfb extension, but that can only be done while developing the app.

If we think about it in depth, it’s a huge limitation of ARCore as we cannot select and load models at runtime.

But no worries, Google knows about this and has provided a solution for it. It has developed a library which accepts the path of a model hosted on a remote server and loads it in AR.

This also helps us to avoid bundling models with APK, resulting in a tremendous size reduction.

I’m sure that you’ve already started wondering about the possible use cases.

A small demo will provide a deeper way to visualize apps that are possible with this library. So, let’s dive in…!

Prerequisites

  1. Basic knowledge of Sceneform (If you’re not familiar with it, please refer my blog on the same: Sceneform blog)
  2. A .gltf 3D model (can be downloaded from Google Poly)
  3. A link to that model, hosted on a server (Models can also be hosted on GitHub, as in this demo). Yudiz provides a model for you to try this out here.

Note: Don’t forget to include all the related files for the model in the model’s directory such as .bin file and texture files, if any.

I’ll use a model of Santa Claus as in the image below.

ARCore: Loading 3D models at runtime

Code

First things first, we’ll add the required dependency for the library.

ARCore: Loading 3D models at runtime

Add the following code snippets in onCreate() method of the activity.

ARCore: Loading 3D models at runtime

The above code generates a renderable from the model stored at a remote server. modelLink is a string which points the .gltf model.

ARCore: Loading 3D models at runtime

The below code snippet is for listener which listens to the tap on the plan detected and ultimately adds a transformable node, built using the renderable on the plane.

ARCore: Loading 3D models at runtime

That’s it…! Isn’t it a piece of cake?

Let’s run the code…

Liked the concept? Wanna experiment with it? Please feel free to play around with the code.

Use cases

A dynamic AR app with an API for 3D models can be imagined. The models can be managed from an admin panel without affecting app’s codebase.

Conclusion

For me, the main uses of this library are that the app size will be reduced and dynamic apps can be developed. Even though it only supports .gltf files currently, this feature can be handy in a lot of ways.

Find more top mobile app developers worldwide on AppFutura.

Looking for an app or software development company?

You can post a project on AppFutura for free and explain your needs for app or software development. You will receive quotes from qualified companies and will be able to hire the best candidate through a safe payment system.

Post a project

About the author
Sumeet RukejaAndroid Developer at Yudiz Solutions

An Android App Developer with good command over core Java and an increasing interest in Kotlin. Enthusiastic about new technologies in the Android world, including Google ARCore and neural networks. A Machine Learning admirer & in love with flutter. ...

Read more...
You might also like