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

Camera issue with version 2.0.3

Open dsilvera opened this issue 11 months ago • 1 comments

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 avatar Feb 29 '24 11:02 dsilvera

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.

dsilvera avatar Mar 01 '24 15:03 dsilvera

Fixed in v2.2.0

ThomasGorisse avatar May 29 '24 17:05 ThomasGorisse