user3742929
user3742929

Reputation: 400

Loading models with ArCore in Android Studio

I'm struggling to follow the examples to load in my own model with ArCore. I found the following code:

ModelRenderable.builder()
    // To load as an asset from the 'assets' folder ('src/main/assets/andy.sfb'):
    .setSource(this, Uri.parse("andy.sfb"))

    // Instead, load as a resource from the 'res/raw' folder ('src/main/res/raw/andy.sfb'):
    //.setSource(this, R.raw.andy)

    .build()
    .thenAccept(renderable -> andyRenderable = renderable)
    .exceptionally(
        throwable -> {
          Log.e(TAG, "Unable to load Renderable.", throwable);
          return null;
    });

However I can't find the class ModelRenderable anywhere and how to import it. Also the example app I'm building app from loads models like this:

virtualObject.createOnGlThread(/*context=*/ this, "models/andy.obj", "models/andy.png");
virtualObject.setMaterialProperties(0.0f, 2.0f, 0.5f, 6.0f);

But my model has no png files, just obj and mtl. The automatic sceneform also created a sfa and sfb file. Which one is the right way to do it?

Upvotes: 2

Views: 2634

Answers (1)

stewe93
stewe93

Reputation: 103

For reference here is the official documentation about initiating a model: https://developers.google.com/ar/develop/java/sceneform#renderables

The ModelRenderable is part of the com.google.ar.sceneform:core library, you could add it by adding this dependency to your app level build.gradle:

implementation 'com.google.ar.sceneform:core:1.13.0'

Make sure every other arcore / sceneform dependency is on the same version, in this case 1.13.0 .

The sfa meaning is SceneFormAsset, it represents your your model details in a humanly readable form and wouldn't be part of your application (it should be in the samplefolder which is on the same hierarchy level as your src folder). The sfb however is SceneFormBinary, this binary is generated from the sfa descriptor every time you modify something in the sfa and build the project. The sfb file should be in your assets folder in your project. For model loading, you should use the sfb file:

ModelRenderable.builder()
        .setSource(context, Uri.parse("house.sfb"))

About your sample code: if you aren't familiar with OpenGL I don't recommend you to follow that sample, better to look for SceneForm, here is a sample app: https://github.com/google-ar/sceneform-android-sdk/tree/master/samples/solarsystem

Upvotes: 4

Related Questions