Skip to content

Commit

Permalink
Merge pull request #12073 from EMapGIS/main
Browse files Browse the repository at this point in the history
fix: Movement handler stuck when clicking certain key combinations
  • Loading branch information
jjspace authored Aug 23, 2024
2 parents da27fe1 + b69914d commit bd61e26
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

##### Fixes :wrench:

- Update CameraEventAggregator to only trigger events for the currently held modifier while dragging. Events are canceled for all modifiers when the mouse is lifted. [#11903](https://github.com/CesiumGS/cesium/pull/11903)
- Fixed cube-mapping artifacts in image-based lighting. [#12100](https://github.com/CesiumGS/cesium/pull/12100)
- Fixed specular reflection artifact in PBR direct lighting. [#12116](https://github.com/CesiumGS/cesium/pull/12116)
- Added multiscattering terms to diffuse BRDF in image-based lighting. [#12118](https://github.com/CesiumGS/cesium/pull/12118)
Expand Down
12 changes: 11 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [T2 Software](http://t2.com.tr/)
- [Hüseyin ATEŞ](https://github.com/ateshuseyin)
- [İbrahim Furkan Aygar](https://github.com/furkanaygar)
- [EMapGis](http://emapgis.com)
- [IKangXu](https://github.com/IKangXu)
- [EMapGIS](https://github.com/EMapGIS)
- [CandyACE](https://github.com/CandyACE)

## [Individual CLA](Documentation/Contributors/CLAs/individual-contributor-license-agreement-v1.0.pdf)

Expand Down Expand Up @@ -372,7 +376,13 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Jason Summercamp](https://github.com/fullstacc)
- [Shapovalov Kirill](https://github.com/ShapovalovKL)
- [Alexander Popoff](https://github.com/aerialist7)
- [IKangXu](https://github.com/IKangXu)
- [chael Cabana](https://github.com/mikecabana)
- [Joseph Stanton](https://github.com/romejoe)
- [Zehua Hu](https://github.com/lanvada)
- [王秋艳](https://github.com/wqy224488)
- [Jason Summercamp](https://github.com/fullstacc)
- [Shapovalov Kirill](https://github.com/ShapovalovKL)
- [Alexander Popoff](https://github.com/aerialist7)
- [e3dio](https://github.com/e3dio)
- [Dphalos](https://github.com/Dphalos)
- [hongfaqiu](https://github.com/hongfaqiu)
Expand Down
54 changes: 49 additions & 5 deletions packages/engine/Source/Scene/CameraEventAggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ScreenSpaceEventType from "../Core/ScreenSpaceEventType.js";
import CameraEventType from "./CameraEventType.js";

function getKey(type, modifier) {
let key = type;
let key = `${type}`;
if (defined(modifier)) {
key += `+${modifier}`;
}
Expand Down Expand Up @@ -178,7 +178,6 @@ function listenMouseButtonDownUp(aggregator, modifier, type) {
const isDown = aggregator._isDown;
const eventStartPosition = aggregator._eventStartPosition;
const pressTime = aggregator._pressTime;
const releaseTime = aggregator._releaseTime;

isDown[key] = false;
eventStartPosition[key] = new Cartesian2();
Expand Down Expand Up @@ -219,20 +218,64 @@ function listenMouseButtonDownUp(aggregator, modifier, type) {

aggregator._eventHandler.setInputAction(
function () {
aggregator._buttonsDown = Math.max(aggregator._buttonsDown - 1, 0);
isDown[key] = false;
releaseTime[key] = new Date();
cancelMouseDownAction(getKey(type, undefined), aggregator);
for (const modifier of Object.values(KeyboardEventModifier)) {
const cancelKey = getKey(type, modifier);
cancelMouseDownAction(cancelKey, aggregator);
}
},
up,
modifier
);
}

function cancelMouseDownAction(cancelKey, aggregator) {
const releaseTime = aggregator._releaseTime;
const isDown = aggregator._isDown;
if (isDown[cancelKey]) {
aggregator._buttonsDown = Math.max(aggregator._buttonsDown - 1, 0);
}
isDown[cancelKey] = false;
releaseTime[cancelKey] = new Date();
}

function cloneMouseMovement(mouseMovement, result) {
Cartesian2.clone(mouseMovement.startPosition, result.startPosition);
Cartesian2.clone(mouseMovement.endPosition, result.endPosition);
}

function refreshMouseDownStatus(type, modifier, aggregator) {
// first: Judge if the mouse is pressed
const isDown = aggregator._isDown;
let anyButtonIsDown = false;
const currentKey = getKey(type, modifier);
for (const [downKey, downValue] of Object.entries(isDown)) {
if (downKey.startsWith(type) && downValue && downKey !== currentKey) {
anyButtonIsDown = true;
cancelMouseDownAction(downKey, aggregator);
}
}

if (!anyButtonIsDown) {
return;
}

// second: If it is pressed, it will be transferred to the current modifier.
const pressTime = aggregator._pressTime;
let lastMovement = aggregator._lastMovement[currentKey];
if (!defined(lastMovement)) {
lastMovement = aggregator._lastMovement[currentKey] = {
startPosition: new Cartesian2(),
endPosition: new Cartesian2(),
valid: false,
};
}
aggregator._buttonsDown++;
lastMovement.valid = false;
isDown[currentKey] = true;
pressTime[currentKey] = new Date();
}

function listenMouseMove(aggregator, modifier) {
const update = aggregator._update;
const movement = aggregator._movement;
Expand Down Expand Up @@ -271,6 +314,7 @@ function listenMouseMove(aggregator, modifier) {
const type = CameraEventType[typeName];
if (defined(type)) {
const key = getKey(type, modifier);
refreshMouseDownStatus(type, modifier, aggregator);
if (isDown[key]) {
if (!update[key]) {
Cartesian2.clone(
Expand Down

0 comments on commit bd61e26

Please sign in to comment.