Skip to content

Commit 2204e1a

Browse files
author
Alexis Girault
committed
fix(RenderWindowInteractor): only request/cancel
1 parent 9df6777 commit 2204e1a

File tree

3 files changed

+21
-11
lines changed
  • Sources
    • Interaction/Misc/DeviceOrientationToCamera
    • Proxy/Core/ViewProxy
    • Rendering/Core/RenderWindowInteractor

3 files changed

+21
-11
lines changed

Sources/Interaction/Misc/DeviceOrientationToCamera/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function addWindowListeners() {
4343
orientation.update = true;
4444
listeners
4545
.filter((i) => !!i)
46-
.forEach((i) => i.renderWindowInteractor.requestAnimation());
46+
.forEach((i) => i.renderWindowInteractor.requestAnimation(i));
4747
}
4848

4949
function removeWindowListeners() {
@@ -60,7 +60,7 @@ function removeWindowListeners() {
6060
orientation.update = false;
6161
listeners
6262
.filter((i) => !!i)
63-
.forEach((i) => i.renderWindowInteractor.cancelAnimation());
63+
.forEach((i) => i.renderWindowInteractor.cancelAnimation(i));
6464
}
6565

6666
function addCameraToSynchronize(

Sources/Proxy/Core/ViewProxy/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ function vtkViewProxy(publicAPI, model) {
253253

254254
publicAPI.setAnimation = (enable) => {
255255
if (enable) {
256-
model.renderWindow.getInteractor().requestAnimation('proxy');
256+
model.renderWindow.getInteractor().requestAnimation(publicAPI);
257257
} else {
258-
model.renderWindow.getInteractor().cancelAnimation('proxy');
258+
model.renderWindow.getInteractor().cancelAnimation(publicAPI);
259259
}
260260
};
261261

Sources/Rendering/Core/RenderWindowInteractor/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,15 @@ function vtkRenderWindowInteractor(publicAPI, model) {
261261
};
262262

263263
publicAPI.requestAnimation = (requestor) => {
264-
model.requestAnimationCount += 1;
265-
if (model.requestAnimationCount === 1) {
264+
if (requestor === undefined) {
265+
vtkErrorMacro(`undefined requester, can not start animating`);
266+
return;
267+
}
268+
if (model.animationRequesters.has(requestor)) {
269+
return;
270+
}
271+
model.animationRequesters.add(requestor);
272+
if (model.animationRequesters.size === 1) {
266273
model.lastFrameTime = 0.1;
267274
model.lastFrameStart = new Date().getTime();
268275
model.animationRequest = requestAnimationFrame(publicAPI.handleAnimation);
@@ -274,9 +281,12 @@ function vtkRenderWindowInteractor(publicAPI, model) {
274281
model.vrAnimation || model.animationRequest !== null;
275282

276283
publicAPI.cancelAnimation = (requestor) => {
277-
model.requestAnimationCount -= 1;
278-
279-
if (model.animationRequest && model.requestAnimationCount === 0) {
284+
if (!model.animationRequesters.has(requestor)) {
285+
vtkWarningMacro(`${requestor} did not request an animation`);
286+
return;
287+
}
288+
model.animationRequesters.delete(requestor);
289+
if (model.animationRequest && model.animationRequesters.size === 0) {
280290
cancelAnimationFrame(model.animationRequest);
281291
model.animationRequest = null;
282292
publicAPI.endAnimationEvent();
@@ -622,7 +632,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
622632
// do not want extra renders as the make the apparent interaction
623633
// rate slower.
624634
publicAPI.render = () => {
625-
if (model.requestAnimationCount === 0) {
635+
if (model.animationRequest === null) {
626636
publicAPI.forceRender();
627637
}
628638
};
@@ -858,7 +868,7 @@ const DEFAULT_VALUES = {
858868
recognizeGestures: true,
859869
currentGesture: 'Start',
860870
animationRequest: null,
861-
requestAnimationCount: 0,
871+
animationRequesters: new Set(),
862872
lastFrameTime: 0.1,
863873
wheelTimeoutID: 0,
864874
moveTimeoutID: 0,

0 commit comments

Comments
 (0)