Skip to content

Commit

Permalink
Fix disappearing models after pivot from downward-looking direction #289
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Nov 12, 2020
1 parent 518e68c commit 19c881e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
20 changes: 17 additions & 3 deletions src/viewer/scene/CameraControl/lib/controllers/PivotController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {math} from "../../../math/math.js";

const tempVec3a = math.vec3();
const tempVec3b = math.vec3();

/** @private */
class PivotController {

Expand Down Expand Up @@ -82,11 +85,14 @@ class PivotController {
*
* @param {Number[]} worldPos The World-space pivot position.
*/
startPivot(worldPos) {
startPivot() {

const camera = this._scene.camera;
if (this._cameraLookingDownwards()) {
this._pivoting = false;
return false;
}

this.setPivotPos(worldPos || camera.look);
const camera = this._scene.camera;

let lookat = math.lookAtMat4v(camera.eye, camera.look, camera.worldUp);
math.transformPoint3(lookat, this._pivotWorldPos, this._cameraOffset);
Expand All @@ -113,6 +119,14 @@ class PivotController {
this._pivoting = true;
}

_cameraLookingDownwards() { // Returns true if angle between camera viewing direction and World-space "up" axis is too small
const camera = this._scene.camera;
const forwardAxis = math.normalizeVec3(math.subVec3(camera.look, camera.eye, tempVec3a));
const rightAxis = math.cross3Vec3(forwardAxis, camera.worldUp, tempVec3b);
let rightAxisLen = math.sqLenVec3(rightAxis);
return (rightAxisLen <= 0.0001);
}

/**
* Returns true if we are currently pivoting.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class KeyboardAxisViewHandler {
}

if ((!configs.firstPerson) && configs.followPointer) {
controllers.pivotController.startPivot(center);
controllers.pivotController.setPivotPos(center);
}

if (controllers.cameraFlight.duration > 0) {
Expand Down
24 changes: 17 additions & 7 deletions src/viewer/scene/CameraControl/lib/handlers/MousePickHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ class MousePickHandler {

if (e.which === 1) {// Left button
if (pickController.pickResult) {
pivotController.startPivot(pickController.pickResult.worldPos);
pivotController.setPivotPos(pickController.pickResult.worldPos);
pivotController.startPivot();
} else {
pivotController.setPivotPos(scene.camera.look);
pivotController.startPivot(); // Continue to use last pivot point
}
}
Expand Down Expand Up @@ -245,8 +247,10 @@ class MousePickHandler {
cameraControl.fire("pickedSurface", pickController.pickResult, true);

if ((!configs.firstPerson) && configs.followPointer) {
controllers.pivotController.startPivot(pickController.pickResult.worldPos);
controllers.pivotController.showPivot();
controllers.pivotController.setPivotPos(pickController.pickResult.worldPos);
if (controllers.pivotController.startPivot()) {
controllers.pivotController.showPivot();
}
}
}
} else {
Expand Down Expand Up @@ -288,8 +292,11 @@ class MousePickHandler {
const pickedEntityAABB = pickController.pickResult.entity.aabb;
const pickedEntityCenterPos = math.getAABB3Center(pickedEntityAABB);

controllers.pivotController.startPivot(pickedEntityCenterPos);
controllers.pivotController.showPivot();
controllers.pivotController.setPivotPos(pickedEntityCenterPos);

if (controllers.pivotController.startPivot()) {
controllers.pivotController.showPivot();
}
}
}

Expand All @@ -308,8 +315,11 @@ class MousePickHandler {
const sceneAABB = scene.aabb;
const sceneCenterPos = math.getAABB3Center(sceneAABB);

controllers.pivotController.startPivot(sceneCenterPos);
controllers.pivotController.showPivot();
controllers.pivotController.setPivotPos(sceneCenterPos);

if (controllers.pivotController.startPivot()) {
controllers.pivotController.showPivot();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ class TouchPanRotateAndDollyHandler {
pickController.update();

if (!configs.planView) {
if (pickController.picked && pickController.pickedSurface && pickController.pickResult) {
if (pickController.picked && pickController.pickedSurface && pickController.pickResult && pickController.pickResult.worldPos) {

pivotController.startPivot(pickController.pickResult.worldPos);
pivotController.showPivot();
pivotController.setPivotPos(pickController.pickResult.worldPos);

if (pivotController.startPivot()) {
pivotController.showPivot();
}

} else {
pivotController.startPivot(); // Continue to use last pivot point
pivotController.showPivot();
if (pivotController.startPivot()) { // Continue to use last pivot point
pivotController.showPivot();
}
}
}
}
Expand Down

0 comments on commit 19c881e

Please sign in to comment.