ARCore: Loading 3D models at runtime

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.

About the author
Yudiz Solutions Pvt. Ltd.Mobile app development company in India
ContactVisit website

Yudiz Solutions Pvt. Ltd. is an ISO 9001:2015 certified software development company having 9+ years of quality global exposure in IT services. We have successfully worked on 1500+ projects and served renown clients like Groupon, Nestle, NEC, Ubisoft, Havas Group, Tv18, McLaren, and Ketchapp.

You might also like