Reputation: 6362
In Three.js, wow do I add or put limits on how far left/right/up/down a user can pan when using OrbitControls? I'd prefer not to be able to pan so far away that you are unable to see the objects in the scene.
Upvotes: 2
Views: 4790
Reputation: 1578
In the current version of OrbitControls.js, the position is updated with the panning changes here.
Now if you want to limit the panning to some boundaries, you can simply check if the new position of the camera lies within this boundaries, otherwise you do not update the position:
var newX = this.target.x + pan.x;
var newY = this.target.y + pan.y;
if (newX <= this.maxXPan && newX >= this.minXPan
&& newY <= this.maxYPan && newY >= this.minYPan) {
this.target.add( pan );
}
Upvotes: 1