使用 Three.js 围绕对象旋转相机 [英] Rotate camera around object with Three.js

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

问题描述

我正在使用 WebGlRenderer 显示带有 Three.js 的 OBJ 元素,现在我想允许用户在任何方向上围绕对象旋转相机,我找到了这个答案:

I'm displaying an OBJ element with Three.js using WebGlRenderer, now I'd like to allow users to rotate the camera around the object in any direction, I've found this answer:

用鼠标在 Three.js 中旋转相机

但这两个例子都给我报错,第一个说没有定义投影仪,我不知道投影仪"是什么意思.我只有一个简单的相机、物体和一些光线.第二个代码说 undefined 不是一个函数.

But both examples return me errors, the first says that projector is not defined, and I don't know what it means with "projector". I've just a simple camera, the object and some light. The second code says that undefined is not a function.

有人知道如何获得我需要的结果吗?

Does someone know how to get the result I need?

推荐答案

这就是你想要的:http://threejs.org/examples/misc_controls_orbit.html

包括轨道控件(下载后):

Include the orbit controls (after you have downloaded them):

<script src="js/controls/OrbitControls.js"></script>

设置变量:

var controls;

将控件附加到相机并添加监听器:

Attach the controls to the camera and add a listener:

controls = new THREE.OrbitControls( camera );
controls.addEventListener( 'change', render );

并在您的动画函数中更新控件:

and in your animate function update the controls:

controls.update();

[更新] controls.autoRotate = true;(已在 v73 中测试.最新版本的 OrbitControls.js 已添加此控件.)

[Update] controls.autoRotate = true; (tested in v73. Recent versions of OrbitControls.js has added this control.)

这篇关于使用 Three.js 围绕对象旋转相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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