google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.98k stars 1.22k forks source link

Can't load .gItf file from internal storage. How to load model from local storage phone and run it ? [AR Core] #961

Closed jingxuan98 closed 3 years ago

jingxuan98 commented 4 years ago

Guys, I am working on an AR app which enables the user to upload tthe model they downloaded in their phone local storage and place it on AR with Android AR Core.

In order to render in runtime, I use .gItf.

I was planning let the user to upload the file in the first activity and pass the Uri to the second activity to render and put it in AR

However, there is a problem which i wasn't able to load the model by using its Uri. I been searching online for hours but seems no answer for it

Any solutions?

My ModelRendereable code ModelRenderable.builder() .setSource(arFragment.getContext(), RenderableSource.builder().setSource( this, Uri.parse(GLTF_ASSET), RenderableSource.SourceType.GLTF2) .setScale(0.5f) // Scale the original model to 50%. .setRecenterMode(RenderableSource.RecenterMode.ROOT) .build() ) .setRegistryId(GLTF_ASSET) .build().thenAccept(renderable -> addNodeToScene(arFragment, anchor, renderable) ) .exceptionally( throwable -> { Toast.makeText(this,"Unable to load cat model", Toast.LENGTH_SHORT).show(); System.out.println(GLTF_ASSET); return null; } );

How I let the user select from internal storage ` @Override public void onClick(View v) {

            Intent intent = new Intent();
            intent.setType("*/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);

            //To start a activity that will return result
            startActivityForResult(intent,PICK_FILES);
            //startActivityForResult(Intent.createChooser(intent,"Select your .gITF"),PICK_FILES);
        }

`

` Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(requestCode==PICK_FILES && resultCode==RESULT_OK && data != null){

        //To return the Uri of the selected file

        uriList.add(data.getData());

        System.out.println(path);

    }else{
        Toast.makeText(MainActivity.this,"Please select a valid file",Toast.LENGTH_LONG);
    }
}

`

How I pass the Uri to second activity Intent intent = new Intent(MainActivity.this, Activity2.class); intent.putExtra("Uri",uriList.get(0).toString()); startActivity(intent);

How I get the Uri from the first activity GLTF_ASSET = intent.getStringExtra("Uri");

devbridie commented 3 years ago

As a part of ongoing efforts to maintain ARCore repositories, I’m closing this issue as stale. If this is still an issue, you can use the newly open-sourced Sceneform SDK sources to try to diagnose the problem, or find a community-reared fork in which the issue has been addressed.