@@ -26,15 +26,37 @@ export default class Robot {
2626 }
2727
2828 changeColor ( id , R , G , B , ambient , callback ) {
29- var r = this . scene . getObjectByName ( ROBOT_PREFIX + id ) ;
30- if ( r != undefined ) {
31- r . material . color . setRGB ( R / 256 , G / 256 , B / 265 ) ;
32- //console.log("Color> id:", id, " | R:", R, "G:", G, "B:", B);
33-
34- if ( callback != null ) callback ( 'success' ) ;
29+ var robot = this . scene . getObjectByName ( ROBOT_PREFIX + id ) ;
30+ if ( robot != undefined ) {
31+ var i = 0 ;
32+ const startColor = {
33+ r : robot . material . color . r ,
34+ g : robot . material . color . g ,
35+ b : robot . material . color . b
36+ } ;
37+ const endColor = {
38+ r : R / 256 ,
39+ g : G / 256 ,
40+ b : B / 256
41+ } ;
42+ const steps = 10 ;
43+ const interval = 500 ;
44+
45+ const intervalId = setInterval ( function ( ) {
46+ const pos = i / steps ;
47+ robot . material . color . setRGB (
48+ ( 1 - pos ) * startColor . r + pos * endColor . r ,
49+ ( 1 - pos ) * startColor . g + pos * endColor . g ,
50+ ( 1 - pos ) * startColor . b + pos * endColor . b
51+ ) ;
52+ i ++ ;
53+ if ( i === steps ) {
54+ clearInterval ( intervalId ) ;
55+ if ( callback != null ) callback ( 'success' ) ;
56+ }
57+ } , interval / steps ) ;
3558 } else if ( callback != null ) callback ( 'undefined' ) ;
36-
37- return r ;
59+ return robot ;
3860 }
3961
4062 create ( id , x , y , heading , reality = 'V' , callback ) {
0 commit comments