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

Fix disappearing models after pivot from downward-looking direction #289

Closed lasselaakkonen-congrid closed 4 years ago

lasselaakkonen-congrid commented 4 years ago

When cameraControl.pivoting = true, the canvas goes completely blank in some specific scenarios when rotating the view.

The issue can be reproduced with NavCubePlugin or without NavCubePlugin by manually setting the same camera eye/look/up values as the NavCubePlugin sets.

Reproducing with NavCubePlugin

Using macOS Chrome v80.0 and xeokit-sdk v0.9.93.

Load a model like this:

        const viewer = new Viewer({
            canvasId: "3DViewerContainer",
            transparent: true,
        });

        const model = xktLoader.load({
            src: "samplehouse.xkt",
        });            

        const cameraControl = viewer.cameraControl;
        cameraControl.pivoting = true;

        const navCube = new NavCubePlugin(viewer, {
            canvasId: "NavigationCubeContainer",
        });

Change to the Top view from the NavCube.

Try to rotate the model by clicking and dragging.

The canvas goes blank without anything in console logs.

xeokit-crash-navcube-pivoting-1

xeolabs commented 4 years ago

Solution

This bug is caused by pivoting math breaking for the case when we start pivoting while initially looking directly downwards.

I wasn't able to make the pivoting math robust for this case, however I was able to implement a UX workaround which is minimally disruptive.

As shown in the screenshot below, if we're not initially looking directly downwards, then we pivot about the position we click.

If however we are initially looking directly downwards, the first click and drag just orbits the camera about it's current point-of-interest. On a subsequent drag, since the camera is 99.99999% likely to no longer be looking directly downwards, we set the pivot point to the mouse position on the object surface, and pivot that as expected.

The UX compromise here is that if the user was planning to do a pivot about a clicked point right after selecting a downward-looking viewpoint (eg. using NavCube), then as they drag they'll notice they're not pivoting as expected, and are then likely to attempt to pick the pivot point again. Better than the model disappearing!

Animated GIF-downsized_large (32)