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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With