4

I'm following the document at Google (https://developers.google.com/ar/develop/java/scene-viewer#ar-only).

I put glTF file in assets/models directory (as same location with Andy.obj)

and I tried to load glTF 2.0 file (from KhronosGroup Sample) but failed:

    Intent sceneViewerIntent = new Intent(Intent.ACTION_VIEW);
    Uri intentUri =
            Uri.parse("https://arvr.google.com/scene-viewer/1.0").buildUpon()
                    .appendQueryParameter("file", "models/BoxTextured.glb")
                    .appendQueryParameter("mode", "ar_preferred")
                    .appendQueryParameter("title", "Untitled")
                    .build();
    sceneViewerIntent.setData(intentUri);
    sceneViewerIntent.setPackage("com.google.ar.core");
    startActivity(sceneViewerIntent);

In document (which linked above), there is no clue how to write the code to load glTF from local.

what can I do for resolved this problem in android?

Thanks.

edit: The source is based on https://github.com/google-ar/arcore-android-sdk/tree/master/samples/hello_ar_java, and I worked HelloArActivity.java, ARCore Android SDK version is 1.17.0

Joona Yoon
  • 314
  • 3
  • 16

1 Answers1

1

I solved it by myself.

Set path for glTF to absolute path (like "/sdcard/BoxTextured.glb", not "models/BoxTextured.glb")

I think it can not find (also no convert) relative path from that function.

You have to get a path by //assets/~ or something if you want to use relative path.


EDIT:

also, there is Environment class which has method getExternalStorageDirectory().getAbsolutePath(). i might be solved above problem.

Joona Yoon
  • 314
  • 3
  • 16
  • instead of assets, do you know if it is possible to load files from the public Downloads folder ? I want to be able to download models and show them in SceneViewer. – Someone Somewhere Oct 31 '20 at 00:02
  • @SomeoneSomewhere you can do in Uri.parse(Model_URL) your Model_URL is your glb files – jake Nov 25 '20 at 00:28
  • Hi! I tried your solution but i alwas get an error with "Failed to Load Gltf url '/storage/emulated/0/FILENAME.glb' reason: /storage/emulated/0/FILENAME.glb". I recostruct my file path like this Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/IlBattente_17_glb_mesh_20.glb"), and use it like this .appendQueryParameter("file", Uri.parse(modelUrl).toString) – neo87 Mar 22 '21 at 07:45
  • This also doesn't work for me, even after requesting external storage read permission. SceneViewer can't find the file for some reason. – stackunderflows Mar 09 '23 at 14:54