本文介绍了在threejs中使用鼠标滚轮更改相机position.z的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有人知道如何更改相机的 camera.position.z (使用鼠标滚轮)并产生滚动效果吗? Has anyone any idea how to change the camera.position.z (with mouse wheel) of the camera, and make a scroll effect? 当我尝试使用变量时,它不起作用。When I try with a variable it does not work.推荐答案 TrackballControls 或 OrbitControls 启用缩放(以及旋转和平移)。请参阅示例 https://threejs.org/examples/?q=contro#misc_controls_trackball TrackballControls or OrbitControls from examples can be used enable zoom (and rotate and pan). See example https://threejs.org/examples/?q=contro#misc_controls_trackball包括您可以在下载的软件包中找到的控件之一,该控件位于 three.js-master / examples / js / controls / :Include one of the controls that you can find in downloaded package in three.js-master/examples/js/controls/:<script src="three.js-master/examples/js/controls/OrbitControls.js"></script>并添加到您的代码中var controls = new THREE.OrbitControls( camera, renderer.domElement );controls.addEventListener( 'change', render );并且缩放应该开箱即用。And zooming should work out of the box.如果您只对缩放感兴趣,可以禁用其他功能。If you are only interested in zooming other features can be disabled.this.enableKeys = false;this.enablePan = false;this.enableRotate = false;另请参见 OrbitControls 源 OrbitControls 这篇关于在threejs中使用鼠标滚轮更改相机position.z的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-12 19:40