ThreeJS动画浅色

时间:2016-03-24 16:37:36

标签: three.js

我制作了一个定向灯,我希望随着时间的推移改变颜色。我正在阅读the documentation,但仍然无法启动并运行。 在init之前我声明了变量:

var rmapped = 0;
var color;
var frontLight;

在我的初学者中我有:

color = "rgb(" + r + "," + g + "," + b + ")";
var frontLight = new THREE.DirectionalLight(color, 1);
frontLight.position.set(0, 0, 3000);
frontLight.castShadow = true;
frontLight.shadowDarkness = 1;
frontLight.shadowMapSoft = true;
scene.add(frontLight);

在我的更新()中,我有:

rmapped = rmapped +.1;
color.add(rmapped,1,1)

我很高兴使用HSL或使用addScalar()。我只需要一些可以改变每帧颜色的东西。 谢谢!

1 个答案:

答案 0 :(得分:1)

您可以通过frontLight.color更改灯光颜色。

https://jsfiddle.net/8qaf13nv/

// h — hue value between 0.0 and 1.0 
// s — saturation value between 0.0 and 1.0 
// l — lightness value between 0.0 and 1.0
var h = rmapped * 0.01 % 1;
var s = 0.5;
var l = 0.5;
frontLight.color.setHSL ( h, s, l );

rmapped ++;