I am working on coloring my 3D object using Three.js. I have a variable called j
. When I use alert(j)
, it works fine. However, when I try to use the variable as an index in my array (colormap), it doesn't work.
colormap=[[0,0,0.5625],[0,0,0.625],[0,0,0.6875],[0,0,0.75],[0,0,0.8125],[0,0,0.875],[0,0,0.9375],[0,0,1],[0,0.0625,1],[0,0.125,1],[0,0.1875,1],[0,0.25,1],[0,0.3125,1],[0,0.375,1],[0,0.4375,1],[0,0.5,1],[0,0.5625,1],[0,0.625,1],[0,0.6875,1],[0,0.75,1],[0,0.8125,1],[0,0.875,1],[0,0.9375,1],[0,1,1],[0.0625,1,0...
j = 0;// index of color in the matrix
var callbackMale = function ( geometry, materials )
{
// surf contains surface
var cmin=surf.min(), cmax=surf.max(), colorLength=colormap.length;
for ( var i = 0, l = geometry.vertices.length; i < l; i ++ )
{
var face = geometry.faces[ i ];
j = Math.round(((surf[i]-cmin)/(cmax-cmin)*colorLength));
if(j < 0)
j=0;
else if( j >= colorLength)
j=colorLength;
alert(j)
var ind = colormap[j]; // issue with j being undefined
for(var k = 0 ; k < 3 ; k++)
{
face.vertexColors[ k ] = new THREE.Color().setRGB(ind[0],ind[1],ind[2]);
}//end of inner loop
}//end of outer loop
}