Having an issue with BufferGeometry line drawing, specifically with setting the indices and colors. Even though I set the indices as [1,2,2,3,3,4]
and the colors as
[r1,g1,b1,r1,g1,b1, r2,g2,b2,r2,g2,b2, r3,g3,b3,r3,g3]
, the colors seem to extend past the segments and blend into the next color instead of staying within their designated areas. It appears that only the first color is being applied, almost like each segment is being colored halfway through.
To better illustrate this problem, I have created a sample on JSFiddle: http://jsfiddle.net/0f1oxdjx/
var positions = new Float32Array( MAX_POINTS * 3 );
var colors = new Float32Array(2*(MAX_POINTS-1)*3);
var indices = new Uint16Array(2*(MAX_POINTS-1));
var x = y = z = index = 0;
for ( var i = 0, l = MAX_POINTS; i < l; i ++ ) {
positions[ index ++ ] = x;
positions[ index ++ ] = y;
positions[ index ++ ] = z;
x += ( Math.random() - 0.5 ) * 300;
y += ( Math.random() - 0.5 ) * 300;
z += ( Math.random() - 0.5 ) * 300;
}
var iindex = 0, cindex = 0;
for ( var i = 1, l = MAX_POINTS; i < l; i ++ ) {
indices[iindex++] = i-1;
indices[iindex++] = i;
x = ( Math.random() );
y = ( Math.random() );
z = ( Math.random() );
colors[ cindex ++ ] = x;
colors[ cindex ++ ] = y;
colors[ cindex ++ ] = z;
colors[ cindex ++ ] = x;
colors[ cindex ++ ] = y;
colors[ cindex ++ ] = z;
}
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ));
geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
geometry.setIndex(new THREE.BufferAttribute( indices, 1 ));
// material
var material = new THREE.LineBasicMaterial({vertexColors:THREE.VertexColors, linewidth:2});
I have made some edits to the fiddle to try to address the issue.