Instead of relying on trackball controls to rotate the camera, it is recommended to rotate the mesh based on quaternion. This can help prevent strange rotation behavior after panning.
trackBallControls.noRotate = true;
if (isDragging === true) {
var deltaMove = {
x: event.offsetX -previousMousePosition.x,
y: event.offsetY -previousMousePosition.y
};
var deltaRotationQuaternion = new THREE.Quaternion()
.setFromEuler(new THREE.Euler(toRadians(deltaMove.y * 0.3),
toRadians(deltaMove.x * 0.3),
0,
'XYZ'
));
if (event.which === 1) {
mesh.quaternion.multiplyQuaternions(deltaRotationQuaternion, mesh.quaternion);
}
}
previousMousePosition = {
x: event.offsetX,
y: event.offsetY
};
To set isDragging to false in mouse up event, and to true in mousedown event.
function toRadians(angle) {
return angle * (Math.PI / 180);
}