sceneview-android icon indicating copy to clipboard operation
sceneview-android copied to clipboard

Render VRM model

Open BlueWhaleYT opened this issue 5 months ago • 0 comments

Hello there, does the library support rendering VRM model? (commonly exported with VRoid Studio), VRM model is based on GLTF 2.0. I tried loading the VRM model by referencing the Compose sample but resulting in throwing error:

Missing texture provider for image\/png

Here's the code:

@Composable
fun ModelView() {
    val engine = rememberEngine()
    val modelLoader = rememberModelLoader(engine)

    val centerNode = rememberNode(engine)

    val cameraNode = rememberCameraNode(engine) {
        position = Position(y = -0.5f, z = 2.0f)
        lookAt(centerNode)
        centerNode.addChildNode(this)
    }

    val cameraTransition = rememberInfiniteTransition(label = "CameraTransition")
    val cameraRotation by cameraTransition.animateRotation(
        initialValue = Rotation(y = 0.0f),
        targetValue = Rotation(y = 360.0f),
        animationSpec = infiniteRepeatable(
            animation = tween(durationMillis = 7.seconds.toInt(DurationUnit.MILLISECONDS))
        )
    )

    Scene(
        modifier = Modifier.fillMaxSize(),
        engine = engine,
        modelLoader = modelLoader,
        cameraNode = cameraNode,
        cameraManipulator = rememberCameraManipulator(
            orbitHomePosition = cameraNode.worldPosition,
            targetPosition = centerNode.worldPosition
        ),
        childNodes = listOf(centerNode,
            rememberNode {
                ModelNode(
                    modelInstance = modelLoader.createModelInstance(
                        assetFileLocation = "my_model.vrm"
                    ),
                    scaleToUnits = 0.25f
                )
            }),
        onFrame = {
            centerNode.rotation = cameraRotation
            cameraNode.lookAt(centerNode)
        },
        onGestureListener = rememberOnGestureListener(
            onDoubleTap = { _, node ->
                node?.apply {
                    scale *= 2.0f
                }
            }
        )
    )
}

I know the library is using Filament internally, I have lack of knowledge with that, can you provide me a VRM impl sample of this if it is possible to do? Thanks a lot.

BlueWhaleYT avatar May 08 '25 14:05 BlueWhaleYT