将SpotLight指向与摄像头three.js(手电筒)相同的方向 [英] Point SpotLight in same direction as camera three.js (Flashlight)

查看:339
本文介绍了将SpotLight指向与摄像头three.js(手电筒)相同的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢这个东西。我想制作一个简单的3D场景,我可以用PointerLockControls飞来飞去,但我也希望有一些手电筒。所以聚光灯应该指向与相机相同的方向。

I'm really new in this stuff. I want to make a simple 3D scene, where i can fly around with PointerLockControls, but i want also to have some kind of flashlight. So spot light should point same direction as camera does.

我已经注意到跟随相机,但它的目标是0,0,0。

I have made spotlight to follow camera but its target is bound to 0,0,0.

达到此目的的最佳方式是什么?

What is the best way to achieve this?

谢谢。

推荐答案

SpotLight 目标是 Object3D ,不是 Vector3

spotlight.target = myObject;

您的最佳解决方案是使用 PointLight 相反,并使用此模式:

The best solution in your case is to use a PointLight instead, and use this pattern:

scene.add( camera );
camera.add( pointLight );

如果您仍想使用聚光灯,请执行以下操作:

If you still want to use a spotlight, then do something like this:

scene.add( camera );
camera.add( spotLight.target );
spotLight.target.position.set( 0, 0, -1 );
spotLight.position.copy( camera.position ); // and reset spotlight position if camera moves

通常不需要将相机添加为场景的孩子,但在这种情况下需要它,因为灯光被添加为相机的孩子。

It is not generally required that the camera be added as a child of the scene, but it is required in this case because the light is added as a child of the camera.

three.js r.69

three.js r.69

这篇关于将SpotLight指向与摄像头three.js(手电筒)相同的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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