Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wilfredbtan opened this issue May 8, 2024 · 7 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@wilfredbtan
Copy link

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.

@ThomasGorisse
Copy link
Contributor

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
Copy link
Contributor

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 😉

@jacobmattsson
Copy link

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:

eb3b52d
3d39469
abafa26

that have caused this bug.

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

@jacobmattsson
Copy link

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?

@ThomasGorisse
Copy link
Contributor

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.

@wilfredbtan
Copy link
Author

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

@ThomasGorisse
Copy link
Contributor

Fixed in v2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants