three.js - 如何限制缩放以使对象不会因相机而中断

kir*_*ran 5 javascript three.js

我正在创建three.js应用程序.我已经加载了我的STL对象.我使用过'OrbitControls'.当我用鼠标的中间滚动按钮开始缩放我的对象时,它会在某个时刻中断.

我的相机和控制代码如下:

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 );
Run Code Online (Sandbox Code Playgroud)

我尝试使用控件minZoom,maxZoom但它不起作用.

任何人都可以告诉我,我应该如何限制缩放,以便在某些时候我的对象不会破坏?

Wes*_*ley 13

如果您使用的是PerspectiveCameraOrbitControls,你可以限制像这样的相机间的距离:

controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.minDistance = 10;
controls.maxDistance = 50;
Run Code Online (Sandbox Code Playgroud)

查看OrbitControls.js其他设置的源代码.

three.js r.74