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

查看:44
本文介绍了将 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.

The SpotLight target is an Object3D, not a 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天全站免登陆