0

I am currently developing an Android app in Kotlin and I am using SceneView (https://github.com/SceneView/sceneview-android), since Sceneform was deprecated, to import a 3D Model to my scene. However, I am not being able to set SceneView's background color to transparent (or change it to other color besides black and white).

I have an activity that has two fragments, one of them fits to the whole size of the screen, the other is the SceneView fragment that occupies part of it. Screen

Activity XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".view.NavigationActivity">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragmentCamera"
        android:name="com.example.easier.view.CameraFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragmentSceneView"
        android:name="com.example.easier.view.SceneViewFragment"
        android:layout_width="100dp"
        android:layout_height="100dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.20" />

</androidx.constraintlayout.widget.ConstraintLayout>

Fragment XML:

<?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=".view.SceneViewFragment">

    <io.github.sceneview.SceneView
        android:id="@+id/sceneView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

In my fragment, I changed the background color to white with mSceneView.backgroundColor = colorOf(255f, 255f, 255f, 1f), but when I put the alpha = 0f, the whole fragment stays black.

I have also tried adding android:background="@android:color/transparent" to @+id/sceneView, but the whole fragment stays black.

Also, if I change mSceneView.backgroundColor to any other color, p.e., mSceneView.backgroundColor = colorOf(132f, 63f, 18f, 1f), it remains white.

SceneView Fragment:

class SceneViewFragment : Fragment() {

    private lateinit var mSceneView: SceneView

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        mViewModel = ViewModelProvider(this)[NavigationViewModel::class.java]
        return inflater.inflate(R.layout.fragment_scene_view, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        mSceneView = view.findViewById(R.id.sceneView)

        val modelNode = ModelNode()
        lifecycleScope.launchWhenCreated {
            modelNode.loadModel(
                context = requireContext(),
                lifecycle = lifecycle,
                glbFileLocation = "low_poly_arrow/scene.gltf",
                autoAnimate = true,
                autoScale = true
            )
        }

        modelNode.scale = Scale(2.5f)
        modelNode.centerModel()
        mSceneView.addChild(modelNode)
        mSceneView.backgroundColor = colorOf(255f, 255f, 255f, 1f)
    }
}

There is still too little information about sceneview-android, I would appreciate some help!

jpsf
  • 7
  • 1
  • 7
  • change background-color of your activity then do whatever with your fragment – Robin Hood Jun 08 '22 at 10:07
  • i have tried that, but it has no impact in the sceneview's background color – jpsf Jun 08 '22 at 10:41
  • if you set background-color of your activity to white and add android:background="@android:color/transparent" to @+id/sceneView, still the whole fragment stays black? – Robin Hood Jun 08 '22 at 10:44
  • yes, it remains all black. I've also tried mSceneView.backgroundColor = colorOf(255f, 255f, 255f, 0f) instead of android:background="@android:color/transparent" to @+id/sceneView – jpsf Jun 08 '22 at 10:53
  • use null for color in style app null – Robin Hood Jun 08 '22 at 10:56
  • if I did it correctly, it had no impact as well – jpsf Jun 08 '22 at 11:18

0 Answers0