Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

three.js - how to limit the zooming so that object does not break due to camera

I am creating three.js application. I have loaded my STL objects. I have used 'OrbitControls'. When I start zoom my object with middle scroll button of mouse, it breaks at certain point.

My camera and controls code is as below:

camera = new THREE.PerspectiveCamera( 55, window.innerWidth / window.innerHeight, 1, 15 );
                //camera.position.set( 3, 0.15, 3 );
                // position and point the camera to the center of the scene
                camera.position.x = -3;
                camera.position.y = 4;
                camera.position.z = 5;
                camera.lookAt(new THREE.Vector3(0, 0, 0));

controls = new THREE.OrbitControls( camera,  renderer.domElement  );
                controls.damping = 0.2;
                //controls.minZoom = 0;
                //              controls.maxZoom = 1;
                //controls .noZoom = true;

                controls.addEventListener( 'change', render );

I tried with controls minZoom and maxZoom but it does not work.

Can anyone please tell me how should I limit the zoom so that beyond certain point my object does not break?

like image 336
kiran Avatar asked Feb 26 '16 12:02

kiran


1 Answers

If you are using a PerspectiveCamera with OrbitControls, you can limit the camera distance like so:

controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.minDistance = 10;
controls.maxDistance = 50;

Look at the source code OrbitControls.js for additional settings.

three.js r.74

like image 89
WestLangley Avatar answered Sep 18 '22 17:09

WestLangley