2

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>

Kamil Kacprzak
  • 156
  • 1
  • 8

1 Answers1

9

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();
        }
    }
Kamil Kacprzak
  • 156
  • 1
  • 8
  • Too bad I found it only now.. Had same issue implemnting scene form as a UI component into RN and wasted a ton of time on it. For anyone see's it in the future you must `sceneView.resume` if you don't have `onResume` method to override in your implementation! Kamil you could have saved my life.. Sadly I stumbled on this only after figuring it out.. Anyway thanks :) – Blue Bot Sep 16 '20 at 09:19
  • very much helpful answer. – Gulnaz Ghanchi Nov 24 '20 at 13:16
  • i have tried this but this is not working for me can you please take a look at it https://stackoverflow.com/questions/65125461/sceneform-sceneview-always-black-in-fragment – Kashif Mehmood Dec 03 '20 at 11:53
  • I was having the same problem I changed the background colour to white and placed the node and it started working perfectly – Kashif Mehmood Jan 11 '21 at 07:29
  • The issue for me was that changing color didn't do anything (I placed the node as well), it remain black because sceneView wasn't loading/showing on screen at all. Since you could change the color to white and it actually worked, I'd assume it was node/camera placement problem – Kamil Kacprzak Jan 11 '21 at 11:07
  • 1
    This fixes the black screen, but the FrameLayout has a memory leak when calling ```sceneView.pause()``` – DIRTY DAVE Nov 04 '21 at 16:47