sceneview-android: GLB model not displayed in Jetpack Compose

I’ve written the following Kotlin code (Jetpack Compose), and it doesn’t display any glb model. Not sure why. Any help is greatly appreciated!

val nodes = remember { mutableStateListOf<Node>() }

Scene(
    nodes = nodes,
    modifier = Modifier
        .fillMaxSize(),
    onCreate = { sceneView ->
        sceneView.modelLoader.loadModelAsync(
            fileLocation = "https://test-aorist-bucket.s3.amazonaws.com/models/artwork/187.1.glb",
            onResult = { model ->
                model?.let { model ->
                    val node = ModelNode(
                        sceneView,
                        model
                    )
                    nodes.add(node)
                }
            }
        )
    },
)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 34 (7 by maintainers)

Most upvoted comments

This has been resolved due to the help of @ThomasGorisse and @NohaSamir , Thank you so much! Would be completely lost if it wasn’t for you 😊, and thanks to all the others for their great input! Kind regards.

How about replacing nodes = nodes to nodes = nodes.toList()?

I found that comparing sceneViewNodes and nodes inside Scene composable does not work as expected when passing nodes (with = remember { mutableStateListOf()) directly and then using nodes.add() for new node, because those are already the same. I’m not sure this is the best way, but it works for me.

Might need to change Compose usage of README, or add some comments on it

I am not using jetpack compose based sceneview so I dont know whether it helps or not but this is how I did it:

  • For centering the model, there is method implemented in sceneview itself. Try using this method on modelnode that you have created modelNode.centerModel(). This centered the model for me.

  • As for background, I also faced a similar issue. For me creating a skybox fixed the issue. Try applying a skybox and you can pass in a color to skybox. I used the below implementation. But color needs to be passed in linear color format. Check the filament documentation on how to convert hexcode to linear color format. sceneview.skybox = Skybox.Builder().color(colors).build(Filament.engine)