2023-04-21

Add TextView on SceneView

I try to render 3D model using SceneView and I need to display text on SceneView . The problem that I am facing when viewing the 3D model is that it covers the text.

enter image description here

enter image description here

Xml code

<FrameLayout
    android:id="@+id/frameLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

    <TextView
        android:id="@+id/topView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="This view is on top of the SceneView!"
        android:textSize="24sp"
        android:textColor="#FFFFFF"
        android:background="#88000000"
        android:elevation="10dp"/>

</FrameLayout>

Java Code

ModelRenderable.builder()
            .setSource(
                activity,
                Uri.parse(file.toString())
            )
            .setIsFilamentGltf(true)
            .build(lifecycle)
            .thenAccept { modelRenderable ->
            }
            .exceptionally { throwable ->
                val toast = Toast.makeText(
                    activity,
                    "Unable to load model ".plus(name),
                    Toast.LENGTH_LONG
                )
                toast.setGravity(Gravity.CENTER, 0, 0)
                toast.show()
                null
            }
        val modelNode = ModelNode(
            position = Position(z = 0.0f),
            rotation = Rotation(x = 0.0f),
        )
        sceneView.addChild(modelNode)
        lifecycleScope.launchWhenCreated {
            modelNode.loadModel(
                context = activity,
                lifecycle = lifecycle,
                glbFileLocation = "https://sceneview.github.io/assets/models/MaterialSuite.glb",
                scaleToUnits = 1.1f,
                autoAnimate = false,
                centerOrigin = Position(x = 0.0f, y = 0.0f, z = 0f)
            )

        }

I try to use setZOrderMediaOverlay: sceneView.setZOrderMediaOverlay(true) But no make any effect. I want to keep the 3D model in SceneView under the text when zooming. Do you have any tips to achieve this؟



No comments:

Post a Comment