javascript Three.js 动态改变光照强度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16319096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Three.js change light intensity dynamically
提问by Austin Best
Is there a way that i have not seen to change the light intensity of directional lights on the fly? Or even ambient light?
有没有一种我没有见过的方法可以即时改变定向灯的光强度?甚至环境光?
ambientLight = new THREE.AmbientLight(0xffffff);
scene.add(ambientLight);
directionalLightL = new THREE.DirectionalLight(0xffffff, dLight, 0);
directionalLightL.position.set(dlpX, dlpY, dlpZ);
scene.add(directionalLightL);
So that is done initially to render, but how can i change just one specific lights intensity afterwards? Remove/re-add the light? Find it in the dom and change it? Something in the API i have not noticed?
所以这最初是为了渲染而完成的,但是我之后如何只改变一个特定的灯光强度?移除/重新添加灯光?在dom中找到并更改它?我没有注意到 API 中的某些内容?
回答by WestLangley
To change the intensity for a DirectionalLight
, SpotLight
, PointLight
, or AmbientLight
, you just set it:
要更改DirectionalLight
, SpotLight
, PointLight
, 或的强度AmbientLight
,您只需设置它:
light.intensity = 0.5;
You can change the light color like so:
您可以像这样更改灯光颜色:
light.color.setHex( 0xff0000 );
See Color.js
for other ways to set a color.
有关Color.js
设置颜色的其他方法,请参阅。
three.js r.74
三.js r.74