3

I want to show a 3d object in app, that you can see all sides of that with rotating in jetpack compose and I can't find a source code.

Can anyone show the codes of making it please?

I read something about sceneform but there was no documentation or library for jetpack compose.

this is what I found:

@Composable
fun MySceneformView(model: Model) {
    SceneformModel(
        model = model,
        scale = 1.0f,
        rotation = Quaternion.identity(),
        position = Vector3(0.0f, 0.0f, 0.0f)
    )
}

and I don't know if it's work.

1 Answer 1

1

Loading 3D model in Jetpack Compose app

In order to load a 3D model into an AR/VR Android app built on Jetpack Compose UI, it's best to use the SceneView library by Thomas Gorisse. To implement AR/VR SceneView, paste the following code into build.gradle.kts (Module :app) file.

dependencies {      // Virtual Reality View
    implementation("io.github.sceneview:sceneview:2.2.1")
}

dependencies {      // Augmented Reality View
    implementation("io.github.sceneview:arsceneview:2.2.1")
}

When using SceneView, .glb (GL Transmission Format Binary file) models are ideal. .glb is a binary version of .gltf format, and it can contain an hierarchy of polygonal geometry, lighting, materials, and animations in a single compressed file. You can find many .glb models on the sketchfab.com.

The Kotlin code to load a VR scene is as simple as that:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            VRSceneViewTheme {
                val engine = rememberEngine()
                val modelLoader = rememberModelLoader(engine)
                val cameraNode = rememberCameraNode(engine)
                cameraNode.position = Position(z = 2.5f)

                Scene(
                    modifier = Modifier.fillMaxSize(),
                    engine = engine,
                    modelLoader = modelLoader,
                    cameraNode = cameraNode,
                    childNodes = listOf(
                        ModelNode(
                            modelInstance = modelLoader
                                .createModelInstance("pigeon.glb"),
                            scaleToUnits = 1.25f
                        )
                    )
                )
            }
        }
    }
}

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Somehow getting Engine destroyed for this. The size is not 0. Any idea? Thanks
It would be best to address this question to Thomas Gorisse.
I hope he is active.. I see no activity by him. I will reach out via Git later on. Thanks
@thomas-gorisse, I am getting the error " getting Engine destroyed for this. The size is not 0". Any idea about this? Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.