2014-11-06 248 views
1

我试图在Three.js中为不同的顶点使用不同的颜色绘制一条线,使用THREE.LineTHREE.LineBasicMaterialvertexColors设置为THREE.VertexColors。我宁愿在相邻顶点的颜色之间没有插值(例如,颜色在两个顶点之间的中间点处不连续地变化)。THREE.Line中的顶点颜色

我想对材料设置shading: THREE.FlatShading,但现在我意识到,这不是一个选项,LineBasicMaterialhttp://jsfiddle.net/214huf0a/

是否有一个内置的(或易)的方式来防止点之间的颜色的平滑上线在Three.js中,还是我需要编写自己的着色器?

回答

7

通过使用THREE.LineSegments和设置vertexColors = THREE.VertexColors,您可以在three.js中为每个段创建一行颜色的行;

for (var i = 0; i < geometry.vertices.length; i+=2) { 
    geometry.colors[ i ] = new THREE.Color(Math.random(), Math.random(), Math.random()); 
    geometry.colors[ i + 1 ] = geometry.colors[ i ]; 
} 

var material = new THREE.LineBasicMaterial({ 
    color: 0xffffff, 
    vertexColors: THREE.VertexColors 
}); 

var line = new THREE.LineSegments(geometry, material); 

three.js所r.85

+0

正是我一直在寻找。我们的好奇心是与THREE.LinePieces不同的行为,这是Three.js用于呈现'LineBasicMaterial'的特定着色器的结果,或者将模式设置为'THREE.LinePieces'的事实会触发' GL_LINES'而不是'GL_LINE_STRIP'? – caseygrun 2014-11-07 01:56:56

+0

第二个。 – WestLangley 2014-11-07 02:24:33