three.js - Convert from string to hex code (0x000000) in Three 3dObject in JavaScript? -


i'm trying write large number of objects @ once , want color fade. however, after making string using .tostring(16), doesn't read in code says, new three.meshbasicmaterial({ color: '0x' + color, wireframe: false, opacity: 0.5 });

here's code currently:

    (var = 0; < 10; i++) {         (var j = 0; j < 10; j++) {             (var k = 0; k < 10; k++) {                 geometry = new three.cubegeometry(50, 50, 50);                 colorr = 254 / 10 * k;                 colorr = math.round(colorr);                 colorr = colorr.tostring(16);                 colorg = 254 / 10 * k;                 colorg = math.round(colorg);                 colorg = colorg.tostring(16);                 colorb = 254 / 10 * k;                 colorb = math.round(colorb);                 colorb = colorb.tostring(16);                 color = '0x' + colorr + colorg + colorb;                 material[i] = new three.meshbasicmaterial({ color: color, wireframe: false, opacity: 0.5 });                   mesh[i] = new three.mesh(geometry, material[i]);                 mesh[i].position.x = -500 + (k * 100);                 mesh[i].position.y = -500 + (j * 100);                 mesh[i].position.z = -500 + (i * 100);                 scene.add(mesh[i]);                 objects.push(mesh[i]);              }         }     } 

however, results in grayish black color.

it easier make components 0 1 , use...

var color = new three.color().setrgb(r, g, b); 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -