itowns
itowns copied to clipboard
[CameraUtils] getTransformCameraLookingAtTarget modifies the camera position when called at initialization
When calling CameraUtils.getTransformCameraLookingAtTarget(...) multiple times at the initialization of the scene, the camera is not at the state (position, tilt ...) it should be.
Context
While developping a feature, I encounter this behavior during the initialization of the scene (cf video). The camera moves by itself under the map and then come back up but in a different state.
I can pinpoint the origin of the issue to this function getTransformCameraLookingAtTarget
Screencast from 03-05-2023 16:48:12.webm
Steps to Reproduce (for bugs)
Add this line somewhere which is called multiple times:
CameraUtils.getTransformCameraLookingAtTarget(...)
For example, in preUpdate
function in src/Layer/TiledGeometryLayer.js
, add :
let temp = CameraUtils.getTransformCameraLookingAtTarget(context.view, context.view.camera.camera3D);
The result is in the screenshots (top: without the line, bottom: with it). We can see that the scene is not the same.
Expected Behavior
Same camera state with or without calling getTransformCameraLookingAtTarget
Actual Behavior
Different tilt of the camera Difficult to tilt it again
Possible Cause/Fix/Solution
Conflict in rig's value when there is multiple calls.
Comes from
setFromPositions(view, cameraPosition)
--> this.setTargetFromCoordinate
--> this.target.position.set(0, 0, altitude);