html5 zoom-in,Zoom to object in ThreeJS

可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

Where can I change the zoom direction in three.js? I would like to zoom in the direction of the mouse cursor but I don't get where you can change the zoom target.

回答1:

updated wetwipe's solution to support revision 71 of Three.js, and cleaned it up a little bit, works like a charm, see http://www.tectractys.com/market_globe.html for a full usage example: mX = ( event.clientX / window.innerWidth ) * 2 - 1; mY = - ( event.clientY / window.innerHeight ) * 2 + 1; var vector = new THREE.Vector3(mX, mY, 1 ); vector.unproject(camera); vector.sub(camera.position); camera.position.addVectors(camera.position,vector.setLength(factor)); controls.target.addVectors(controls.target,vector.setLength(factor));

回答2:

OK! I solved the problem like this...just disable the zoom which is provided by THREEJS. controls.noZoom = true; $('body').on('mousewheel', function (e){ var mouseX = (e.clientX - (WIDTH/2)) * 10; var mouseY = (e.clientY - (HEIGHT/2)) * 10; if(e.originalEvent.deltaY

I know it's not perfect...but I hop it will help you a little bit....anyway...I'll work on it to make it even better.

回答3:

So I recently ran into a similar problem, but I need the zoom to apply in a broader space. I've taken the code presented by Niekes in his solution, and come up with the following: container.on('mousewheel', function ( ev ){ var factor = 10; var WIDTH = window.innerWidth; var HEIGHT = window.innerHeight; var mX = ( ev.clientX / WIDTH ) * 2 - 1; var mY = - ( ev.clientY / HEIGHT ) * 2 + 1; var vector = new THREE.Vector3(mX, mY, 1 ); projector.unprojectVector( vector, camera ); vector.sub( camera.position ).normalize(); if( ev.originalEvent.deltaY

Its not pretty, but is at least functional. Improvements are welcome :)

回答4:

If you are using trackball controls,set trackBallControls.noZoom=true;

and in mousewheel event use this code, mousewheel = function (event) { event.preventDefault(); var factor = 15; var mX = (event.clientX / jQuery(container).width()) * 2 - 1; var mY = -(event.clientY / jQuery(container).height()) * 2 + 1; var vector = new THREE.Vector3(mX, mY, 0.1); vector.unproject(Camera); vector.sub(Camera.position); if (event.deltaY

回答5:

Never heard of zoom direction,

you might want to inspect the FOV parameter of the camera,

as well as call this to apply the change: yourCam.updateProjectionMatrix();

回答6:

I am completely new to Three.js but it's.... wonderful. I am not even a good developer. I am practicing. I was facing the problem of zooming to the mouse location and I think I improved the code a little bit. Here it is. // zooming to the mouse position window.addEventListener('mousewheel', function (e) { mousewheel(e); }, false); function mousewheel(event) { orbitControl.enableZoom = false; event.preventDefault(); // the following are constants depending on the scale of the scene // they need be adjusted according to your model scale var factor = 5; // factor determines how fast the user can zoom-in/out var minTargetToCameraDistanceAllowed = 15; // this is the minimum radius the camera can orbit around a target. // calculate the mouse distance from the center of the window var mX = (event.clientX / window.innerWidth) * 2 - 1; var mY = -(event.clientY / window.innerHeight) * 2 + 1; var vector = new THREE.Vector3(mX, mY, 0.5); vector.unproject(camera); vector.sub(camera.position); if (event.deltaY the camera is approaching the scene // with OrbitControls the target is always in front of the camera (in the center of the screen) // So when the user zoom-in, the target distance from the camera decrease. // This is achieved because the camera position changes, not the target. camera.position.addVectors(camera.position, vector.setLength(factor)); } else { // zoom-out -> the camera is moving away from the scene -> the target distance increase camera.position.subVectors(camera.position, vector.setLength(factor)); } // Now camera.position is changed but not the control target. As a result: // - the distance from the camera to the target is changed, and this is ok. // - the target is no more in the center of the screen and needs to be repositioned. // The new target will be in front of the camera (in the direction of the camera.getWorldDirection() ) // at a suitable distance (no less than the value of minTargetToCameraDistanceAllowed constant). // Thus, the target is pushed a little further if the user approaches too much the target. var targetToCameraDistance = Math.max(minTargetToCameraDistanceAllowed, orbitControl.target.distanceTo(camera.position)); var newTarget = camera.getWorldDirection().setLength( targetToCameraDistance ).add(camera.position); orbitControl.target = newTarget; camera.updateProjectionMatrix(); }

Another improvement could be to set the targetToCameraDistance to the distance of an object hit by the mouse when the user starts orbiting.

If the mouse hit an object, and the distance > minTargetToCameraDistanceAllowed, then the new target is calculated and set.

... but I still don't know how to do this.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Element UI中,图标的配置是通过引入和使用Icon组件来实现的。可以在全局或局部配置中设置要使用的图标库。 以下是一些示例,展示如何在Element UI中配置el-icon-zoom-in图标: 1. 全局配置: 在Vue的入口文件(通常是main.js)中,可以通过`Vue.use(ElementUI)`来全局注册Element UI,并配置要使用的图标库。在这种情况下,可以使用`Icon`组件来显示el-icon-zoom-in图标。 ```javascript // main.js import Vue from 'vue'; import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css'; Vue.use(ElementUI, { size: 'small', iconFont: 'el-icon-zoom-in' }); // 其他代码 ``` 2. 局部配置: 在需要使用el-icon-zoom-in图标的组件中,可以通过`Icon`组件的`icon`属性来设置。在这种情况下,需要确保已经正确引入了Element UI,并在组件中使用了`Icon`组件。 ```html <template> <div> <el-button type="primary"> <i class="el-icon-zoom-in"></i> 添加 </el-button> </div> </template> <script> import { Button, Icon } from 'element-ui'; export default { components: { 'el-button': Button, 'el-icon': Icon }, // 其他代码 }; </script> ``` 在上述代码中,我们使用了Element UI的Button组件,并在按钮内部使用了`Icon`组件来显示el-icon-zoom-in图标。 请注意,上述代码中的配置和使用方法仅适用于Element UI。如果你在使用其他UI框架或自定义图标库,具体的配置和使用方法可能会有所不同。确保根据自己的情况进行相应的调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值