FlyControls: Introduce enabled
property.
#26154
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Recently, I came across a bug in FlyControls class. This class has a variable named "status" which controls whether the user is dragging the mouse/pointer. This variable is a counter, which is incremented on pointerDown event, and decremented on pointerUp event. On pointerMove event, the camera only rotates if this "status" variable is greater than 0 (when dragToLook is set to True).
In my application, I have an input form of file type. When the file dialog opens up, if it is above the threejs canvas, and the user selects any file by double-clicking, this dispatch only one pointerUp event to the FlyControls. As a consequence, the FlyControls remains in an invalid state, because the "status" variable is negative, and the user can never rotate the camera again.
I've seen similar issues with this missing pointer/mouse up event: example. This issue occurs in all majors browsers. So, to avoid this problem, I change this control variable to a boolean that only indicates whether the user is dragging the pointer or not. I can't see any reason for this variable to be a counter.
A JSFiddle example to reproduce the bug: just remind to reposition the file dialog over the canvas, in such a way the double click to the file is also over the canvas. After this, you are not allowed to rotate the camera.