xeokit / xeokit-sdk

Open source JavaScript SDK for viewing high-detail, full-precision 3D BIM and AEC models in the Web browser.
https://xeokit.io
Other
738 stars 291 forks source link

[with solution] Jitter when modifying both the Camera and the Ortho (and one unneedded render) #108

Closed tmarti closed 5 years ago

tmarti commented 5 years ago

In src/viewer/scene/camera/Ortho.js file:

https://github.com/xeokit/xeokit-sdk/blob/13dbc2956b0305d448499bc3f6e96b9c344be97d/src/viewer/scene/camera/Ortho.js#L102

https://github.com/xeokit/xeokit-sdk/blob/13dbc2956b0305d448499bc3f6e96b9c344be97d/src/viewer/scene/camera/Ortho.js#L136

https://github.com/xeokit/xeokit-sdk/blob/13dbc2956b0305d448499bc3f6e96b9c344be97d/src/viewer/scene/camera/Ortho.js#L168

Those lines mean than whenever some of the properties of the Ortho class are modified, a render will be triggered during next tick, not the current one.

This creates some jittering in some cases where we modify both the Camera properties (rendered on the current tick) and the Ortho properties (rendered on the next tick) at the same time. As a side effect, in that case two renders are triggered.

Shouldn't those lines be...

this._needUpdate(0);

... instead of...

this._needUpdate();

... so that Ortho changes are processed during the current tick (and not enqueued for the next tick)?

Did some tests with that change and the effect is that the problems are solved:

xeolabs commented 5 years ago

Oh yes, good spotting. That call should indeed be:

this._needUpdate(0);

Avoiding the double-update, when modifying view or projection matrices, is the reason for that 0 priority, yes.

xeolabs commented 5 years ago

Fixed in https://github.com/xeokit/xeokit-sdk/commit/d785a884babe74ddb7c58c8103af6f10dcafe077