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

Setting the initial position of the camera does not work in v2.1.1

Open wilfredbtan opened this issue 1 year ago • 6 comments

Setting the initial position of the camera using the following code snippet used to work in v2.0.4 but when I apply it in v2.1.0 and above, it doesn't work. This was tested using the model-viewer-compose sample in the versions mentioned.

val cameraNode = rememberCameraNode(engine).apply {
    position = Position(y = 4.0f, z = 4.0f)
}

Expected Behaviour: Camera looks at the node at a 45 degree angle.

Actual Behaviour: Camera is at the default position and is not affected by the applied position.

wilfredbtan avatar May 08 '24 06:05 wilfredbtan

Good catch! It might come from the introduction of the configurable CameraManipulator. Could you please have a look at it and create a PR? Thanks

ThomasGorisse avatar May 08 '24 09:05 ThomasGorisse

Even if you should pay attention to the camera position applied on each recomposition instead of just one if the position was applied inside the remember here 😉

ThomasGorisse avatar May 08 '24 09:05 ThomasGorisse

I've also run into this problem (but with the View-based impl. instead of the Compose-based impl.). And reverting back to v2.0.4 is not an option for me because I need to be able to access entities without components (added in v2.1.0 here).

I also want the camera to be positioned at a specific angle, and I therefore apply the following transformation on the CameraNode to achieve that:

sceneView.setCameraNode(
            CameraNode(sceneView.engine).apply {
                transform = Transform(
                    position = Position(
                        modelNode.size.x * 1.8f,
                        modelNode.size.y * 2.2f,
                        modelNode.size.z * 0.7f
                    )
                )
            }
        )

When I debug this issue and compare between v2.0.4 and v2.1.1, I notice that all transformation properties of the CameraNode is the same, except for projectionTransform. In v.2.0.4 it's:

|2.3333333 0.0 0.0 0.0| |0.0 2.333333 0.0 0.0| |0.0 0.0 -1.0 -0.02| |0.0 0.0 -1.0 0.0|

but in v2.1.1 it's:

|1.0 0.0 0.0 0.0| |0.0 1.0 0.0 0.0| |0.0 0.0 1.0 0.0| |0.0 0.0 0.0 1.0|

However, I can't find where that property is set or which of the recent, related commits:

https://github.com/SceneView/sceneview-android/commit/eb3b52da43779eced033b0b67a2e9590dd61aed4 https://github.com/SceneView/sceneview-android/commit/3d39469ac994b14ccd624cd50f184fded9602f96 https://github.com/SceneView/sceneview-android/commit/abafa2662892d66be1bc579f3175a1b510c774ba

that have caused this bug.

If you point me in the right direction, I could have a look at it!

jacobmattsson avatar May 08 '24 09:05 jacobmattsson

Can it perhaps be caused by the fact the now (in v.2.1.x) the (initial) cameraNode.transform is being overwritten by the manipulator.transform before the first touch event here?

jacobmattsson avatar May 08 '24 09:05 jacobmattsson

I can't have an answer easily between versions but all the complexity around it comes from the missing of a Filament camera manipulator position setter after it has been built. Prior to 2.1.x the camera manipulator was rebuilt every time the camera transform was manually changed as a hotfix. But that was a disaster in consumption. Some double camera projections sets inherited from the AR usage have also been removed from the 3D only usage for improving it. Maybe it could help you understand the background history but can't help more right now.

ThomasGorisse avatar May 08 '24 10:05 ThomasGorisse

Good catch! It might come from the introduction of the configurable CameraManipulator. Could you please have a look at it and create a PR? Thanks

Thank you for the reply! I'll take a look at it when I have the time :D

wilfredbtan avatar May 09 '24 04:05 wilfredbtan

Fixed in v2.2.0

ThomasGorisse avatar May 29 '24 17:05 ThomasGorisse