三.js:给相机加光 [英] Three.js: add light to camera

查看:26
本文介绍了三.js:给相机加光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想移动和旋转相机,但将 PointLight 保持在相对于相机的相同位置.我读过很多帖子说你可以将灯光对象添加到相机而不是场景.像这样:

I want to move and rotate the camera but keep a PointLight on the same position relative to the camera. I've read a bunch of threads saying that you can add the light object to the camera instead of the scene. Like so:

pointLight = new THREE.PointLight( 0xffffff );
pointLight.position.set(1,1,2);
camera.add(pointLight);

但是这似乎对我不起作用.相反,我现在在相机更改时通过将相机 matrixWorld 应用到我想要的相对光线位置来设置灯光的位置.这可行,但将光添加到相机似乎是一个更简洁的解决方案.

However this does not seem to work for me. Instead I now when the camera changes set the light's position by applying the cameras matrixWorld to my desired relative light position. This works, but adding the light to the camera seems like a cleaner solution.

我做错了什么,或者向相机添加灯光对象已被弃用?

I'm a doing something wrong or is adding light object to the camera deprecated?

谢谢!

推荐答案

如果相机有子对象,例如`PointLight',则需要将相机添加到场景中.

You need to add the camera to the scene if the camera has a child object, such as a `PointLight'.

scene.add( camera );

three.js r.68

three.js r.68

这篇关于三.js:给相机加光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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