SceneView / sceneview-android

SceneView is a 3D and AR Android Composable and View with Google Filament and ARCore. This is a Sceneform replacement in Kotlin
Apache License 2.0
816 stars 159 forks source link

Camera issue with version 2.0.3 #429

Closed dsilvera closed 4 months ago

dsilvera commented 7 months ago

Since updating the library to version 4.3.0, I've noticed that when I background my application and return to it, the camera's position has changed. I can also reproduce it by opening an activity on top and then closing it to return to the SceneView. I didn't encounter any issues like this with previous versions. I haven't made any changes to my code, so I assume the issue stems from the library itself.

I was using version 2.0.2 before. Is there perhaps some additional code required when transitioning to version 4.3.0?

You can see that there's a zoom-out between the two images (before and after putting the app in the background). If I swipe before putting it in the background, I no longer see my model. It seems to zoom out from the point where the model was opened.

Capture d’écran 2024-02-29 à 12 51 46 Capture d’écran 2024-02-29 à 12 51 56
dsilvera commented 7 months ago

I found a temporary solution. The issue lies with the onResized method:

protected open fun onResized(width: Int, height: Int) {
        view.viewport = Viewport(0, 0, width, height)
        cameraNode.updateProjection()
        updateCameraManipulator()
    }

Upon returning from the background, the updateProjection method alters the position of my camera node. To address this, I have overridden the function as follows:

    var resizedWidth:Int? = null
    var resizedHeight:Int? = null
    override fun onResized(width: Int, height: Int) {
        if (this.resizedWidth == width && this.resizedHeight == height) return
        resizedWidth = width
        resizedHeight = height
        view.viewport = Viewport(0, 0, width, height)
        cameraNode.updateProjection()
        updateCameraManipulator()
    }

This modification resolves the issue. If you have a better solution, I'm open to it.

ThomasGorisse commented 4 months ago

Fixed in v2.2.0