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

Crash When Rendering Specific GLB Models Due to Missing "sheenColorIndex"

Open Mehrdadjdev opened this issue 9 months ago • 4 comments

I'm encountering a crash while rendering certain GLB models using SceneView. While most models work perfectly, some cause the app to crash with the following error:

Panic  
    in getFieldInfo:170  
    reason: uniform named "sheenColorIndex" not found  
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 15095 (.example), pid 15095 (.example)  
  Cmdline: com.example.example  
pid: 15095, tid: 15095, name: .example  >>> com.example.example <<<  
        #01 pc 00000000001dc99c  /data/app/~~MwG87CnQ4Ab2bBh-Qo23-A==/-LWYkR3orsy1RGSTfSynaZw==/base.apk!libfilament-jni.so (utils::TPanic<utils::PreconditionPanic>::panic(char const, char const, int, char const*, ...)+204) (BuildId: c1ee70bcc213bdfcce2421b7860127c85b755d6d)  

Sample code:

@Composable
fun model3DViewer() {

    val engine = rememberEngine()
    val modelLoader = rememberModelLoader(engine)
    val environmentLoader = rememberEnvironmentLoader(engine)

    val centerNode = rememberNode(engine)

    val cameraNode = rememberCameraNode(engine) {
        position = Position(x = 2f, y = 3f, z = 1.0f)
        lookAt(centerNode)
        centerNode.addChildNode(this)
    }

    // State to control camera rotation
    val isCameraRotating = remember { mutableStateOf(true) }

    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(MILLISECONDS))
        )
    )

    val environment = environmentLoader.createHDREnvironment(
        assetFileLocation = "environments/farm_field_puresky_1k.hdr"
    )!!

    val indirectLight = environment.indirectLight

    val modelNode = ModelNode(
        modelInstance = modelLoader.createModelInstance(
            assetFileLocation = "models/model_Sample.glb"
        ),
        scaleToUnits = 2f
    )

    modelNode.scale(2)

    Scene(
        modifier = Modifier.fillMaxSize(),
        engine = engine,
        modelLoader = modelLoader,
        cameraNode = cameraNode,
        cameraManipulator = rememberCameraManipulator(
            orbitHomePosition = cameraNode.worldPosition,
            targetPosition = centerNode.worldPosition
        ),
        childNodes = listOf(centerNode,
            rememberNode {
                modelNode
            }),
        environment = Environment(
            indirectLight = indirectLight,
            skybox = null,

            ),
        onFrame = {
            if (isCameraRotating.value) {
                centerNode.rotation = cameraRotation
                cameraNode.lookAt(centerNode)
            }
        },
        onGestureListener = rememberOnGestureListener(
            onDown = { _, _ ->
                // Stop camera rotation on any gesture
                isCameraRotating.value = false
            },
        ),
        isOpaque = false,
    )

}

Observations: The issue appears to stem from the sheenColorIndex uniform, which is not found in some GLB models. Filament crashes when trying to process this property. Unfortunately, I cannot re-export the problematic GLB models in Blender, as they are shared with another app (based on Sceneform: https://github.com/SceneView/sceneform-android) that renders them without issues.

Questions:

  • Is there a way to ignore unsupported properties like sheenColorIndex in SceneView without crashing the app?
  • Can a workaround be applied to handle this situation without modifying the GLB models themselves?

I would greatly appreciate any advice or guidance on how to resolve this issue. Let me know if you need additional details or if there are specific steps I should follow to debug further.

Thanks in advance!

Mehrdadjdev avatar Jan 24 '25 13:01 Mehrdadjdev