0

For a school project I have to use ArCore for displaying a .obj that was given to me by a client I am doing the project for. I have tried at first with a random .obj that I have found in a license free website and it works quite well, but whenever I try with the .obj of the client, it tells me that it cannot be loaded and I don't really know what to do.

Here is the error in the logcat :

2020-04-10 21:08:28.745 28542-29004/com.example.artest E/ModelRenderable: Unable to load Renderable registryId='sebastien.sfb'
java.util.concurrent.CompletionException: java.io.FileNotFoundException: sebastien.sfb (No such file or directory)
    at com.google.ar.sceneform.utilities.SceneformBufferUtils.inputStreamToByteBuffer(SourceFile:48)

And here is my code :

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);

    createScene();
}

private void createScene() {
    mScene = arFragment.getArSceneView().getScene();

    ModelRenderable.builder()
            .setSource(this, Uri.parse("sebastien.sfb"))
            .build()
            .thenAccept(renderable -> onRenderableLoaded(renderable))
    .exceptionally(throwable -> {
        Log.i("Sceneform", "failed to load model");
        return null;
    });
}

void onRenderableLoaded(ModelRenderable model) {
   Node modelNode = new Node();
   modelNode.setRenderable(model);
   modelNode.setParent(mScene);
   modelNode.setLocalPosition(new Vector3(0, 0, 0));
   mScene.addChild(modelNode);
}

Thank you in advance for your help.

Marie
  • 1
  • 1
  • 1

2 Answers2

1

I'm not posting this as an answer but I really do want to see if I can help but do not have enough reputation points yet to add comments. I don't know how much experience you have with ARCore and loading object file. I myself have only taken up Android coding two weeks ago and jumped right into the deep end writing an ARCore app. It was a steep learning curve but very exciting. I've learned a LOT. So, even though I have 25+ years of coding experience, I'm a newbie Kotlin/Android/ARCore coder.

From your question I take it that you have tested your code using the model you downloaded and your code works fine. I am also assuming that both models are in the same folder location and that for both models the sfa- and sfb files were created, correct?

I do see from the log file "sebastien.sfb (No such file or directory)". This could mean that the .sfb file was not created or when you try to import the file, you are referencing the wrong folder. Please check the following:

  1. In your build.gradle (app) file should be the code that defines the object file as an asset, similar to the code below. When compiling our code, this will build the .sfa and .sfb file for you. It is also worthwhile to delete the sebastian.sfa & sebastian.sfb files (if they already exist) to have them recreated.

    sceneform.asset('sampledata/sebastien.obj', 
                                        // 'Source Asset Path' specified during
                                        // import. This will typically be the
                                        // app/sampledata folder since resources in
                                        // this file is not compiled into your
                                        // application
    'default',                          // 'Material Path' specified during import.
    'sampledata/sebastien.sfa',         // '.sfa Output Path' specified during import.
    'src/main/res/raw/sebastien')       // '.sfb Output Path' specified during import.
    
  2. Typicall when I load the object I use code such as below. Note that I do not make use of Uri.parse but I rather use R.raw.sebastian which directly references the resource folder (res\raw) that the sebastian.sfb file is in.

    val sebastianStage = ModelRenderable.builder().setSource(this, R.raw.sebastian).build()
    

Another couple of questions:

  1. Since you are using an .obj file it will typically be accompanied by a .mtl file. The .obj file references the .mtl file. This can be seen when opening the .obj file in a text editor. Did you perhaps rename the .obj and .mtl file since the .obj file will still reference the old file name of the .mtl file. You also have to change the reference to the .mtl file in the .obj file
  2. Are you sure that the .obj file you were given is not corrupt. If you are using Windows 10, this is easy to check by using MicrosSoft 3D builder which is relatively small easy to use and free. (https://www.microsoft.com/en-za/p/3d-builder/9wzdncrfj3t6?activetab=pivot:overviewtab)

BTW A good source for free 3D models is https://poly.google.com/

Gerhardvr
  • 101
  • 5
  • Thank you for your answer. My build.gradle was already looking like that. I have changed the way of loading the object and checked for the names. But I have this error now : "Unable to load Renderable registryId='android.resource://com.example.artest/raw/sebastien' java.util.concurrent.CompletionException: java.lang.OutOfMemoryError: Failed to allocate a 268435472 byte allocation with 25165824 free bytes and 253MB until OOM, max allowed footprint 161673592, growth limit 402653184" – Marie Apr 29 '20 at 15:17
  • The object cannot be loaded because of its size. I don't know if there is a way to make it work... – Marie Apr 29 '20 at 15:19
  • OK, at least now you have a bit of clarity as to what the issue is. Looking at the error, it looks like your object is 268.4 MB but there are only 25MB free. That being said, the rest unfortunately doesn't really make sense to me. I could figure out that OOM means Out Of Memory. So, according to the message, if your object is loaded, the OS will run our of memory. I found this "Without largeheap the app is limited to 64MB, with largeheap - 512 MB". I don't know if this is strictly true in all cases, because it seems to me that your apps limit is capped at 402MB. – Gerhardvr May 06 '20 at 18:56
  • I had a look at the andy.obj file that is typically used in sample code for AR sample projects. That file is only 162 654 bytes. Compared to that, your model must be extremely complex. I'm curious, can you open it in Microsoft 3D Builder (if you are using Windows)? – Gerhardvr May 06 '20 at 18:56
0

The main issue was the size of the file. I followed some instructions given here.

I had other warnings and errors I had to address : I added a library 'com.google.ar.sceneform:animation:1.15.0' (but I don't think this one is mandatory) I added libraries such as :

'com.google.android.gms:play-services-plus:17.0.0'
'com.google.android.gms:play-services-base:17.2.1'
'com.google.android.gms:play-services-location:17.0.0'

I don't know why these ones were requiered, but adding them made the app work...

Marie
  • 1
  • 1
  • 1