简体   繁体   English

限制场景的最大缩放 Three.js

[英]Limit maximum zoom for a scene in Three.js

I have a Three.js App and I wanna limit the zoom for the scene, because logically at some zoom the user can get inside of my 3D object, which in my oppinion is not a really good UX.我有一个 Three.js 应用程序,我想限制场景的缩放,因为从逻辑上讲,在某种缩放下,用户可以进入我的 3D object,在我看来这不是一个很好的用户体验。

I tried scene.maxZoom = number;我试过scene.maxZoom = number; but did not work.但没有用。 What can I do?我能做些什么?

Here is the code: https://github.com/AlinAlexandruPeter/code/blob/main/code.js这是代码: https://github.com/AlinAlexandruPeter/code/blob/main/code.js

You don't need Three.js to limit the range of numbers, just simple JavaScript. Use Math.min(a, b) to get the lower of the two values.不需要 Three.js 来限制数字的范围,简单的 JavaScript 就可以了。使用Math.min(a, b)得到两个值中较小的一个。

const MAX_ZOOM = 2.5;

// Clamp user input to 2.5 and below
camera.zoom = Math.min(userInput, MAX_ZOOM);

With this approach, if userInput = 3 , it will get clamped at 2.5 .使用这种方法,如果userInput = 3 ,它将被限制在2.5 There's also Math.max() if you want to clamp it on the lower range.如果你想将它限制在较低的范围内,还有Math.max()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM