Search code examples
android3daugmented-realitysceneform

Black screen after loading SceneView, using Scenform, into a fragment


I am working on a project that will have a 3D model viewer in one fragment. In order to do so, I decided to use sceneform. I have encountered a problem with SceneView, after trying to display it, in my tab fragment.

Everything is done according to examples and sceneform documentation, but sceneView display black screen, regardless of the colour I am assigning.

Here is scene loader

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        vw = inflater.inflate(R.layout.fragment_open_gl, container, false);
        sceneView = vw.findViewById(R.id.scene_view);
        return vw;
    }

And fragment :

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".OpenGL">

    <com.google.ar.sceneform.SceneView
        android:id="@+id/scene_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/Crimson"/>

</FrameLayout>


Solution

  • I solved the issue by adding pausing and resuming sceneview, along with the fragment:

        @Override
        public void onPause() {
            super.onPause();
            sceneView.pause();
        }
    
        @Override
        public void onResume() {
            super.onResume();
            try {
                sceneView.resume();
            } catch (CameraNotAvailableException e) {
                e.printStackTrace();
            }
        }