旋转相机以查看three.js中的Selected对象 [英] Rotate camera to look at Selected object in three.js

查看:111
本文介绍了旋转相机以查看three.js中的Selected对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设计地图。因此,当我选择任何几何图形时,我希望对象位于视口的中心,而相机要对其进行观察。我已经花了很多时间在网上无处不在,但找不到答案。请注意,我不想旋转对象。我只想更新相机。我试图在此示例中获得类似的信息,当我们单击该数字时,它会出现在中心: https://sketchfab.com/3d-models/jurassic-aquarium-diorama-with-annotations-d82bea156a1c4176b5d09b82b176e84c

$ >这是我尝试过的并且最接近给我任何输出的方法:

 `camera.position.x = select。 position.x; 
camera.position.y = select.position.y;
camera.position.z = select.position.z;
camera.Translate(0,0,-1);
camera.updateProjectionMatrix();`

select具有选定的对象。
虽然上面的代码确实旋转了相机,但是它无法查看所选对象。



我也尝试过 lookAT(select .position)也不起作用。



请帮助我。

解决方案

如果您在项目中使用Orbit或Trackball控件,仅更改相机的lookAt便无法使用。您还需要更改控件的目标。要进行实验,只需尝试禁用控件,然后更改Camera的外观即可。


I am trying to design a map. So, when I select any geometry, I want the object to come at the centre of the viewport and the camera to be looking at it. I have spent quite a lot of time looking everywhere on the web but failed to find the answer. Please note that I don't want to rotate the object. I just want to update the camera. I am trying to get something like in this example where when we click the number, it comes to the centre : https://sketchfab.com/3d-models/jurassic-aquarium-diorama-with-annotations-d82bea156a1c4176b5d09b82b176e84c

Here is what I have tried and has been closest to giving me any output:

       `camera.position.x = select.position.x;
        camera.position.y = select.position.y;
        camera.position.z = select.position.z;
        camera.Translate(0,0,-1);
        camera.updateProjectionMatrix ();`

select has the selected object. Although the above code does rotate the camera but it fails to look at the selected object.

I have also tried lookAT(select.position) and that didn't work either.

Please help me with this.

解决方案

If you are using Orbit or Trackball controls in your project it won't work by just changing lookAt of the camera. You need to change the target of the controls as well. To experiment, just try to disable the controls and then change look at for Camera.

这篇关于旋转相机以查看three.js中的Selected对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆