简体   繁体   English

在threejs中调整每个顶点的线条颜色

[英]adjusting the color of a line per vertex in threejs

I have a line which passes through points of a particle cloud in threejs. 我有一条线穿过Threejs中的粒子云点。 I am using a canvas renderer. 我正在使用画布渲染器。 I would like to vary the color of the line randomly from vertex to vertex. 我想在顶点之间随机改变线条的颜色。 I saw this example: 我看到了这个例子:

http://mrdoob.github.io/three.js/examples/webgl_custom_attributes_lines.html http://mrdoob.github.io/three.js/examples/webgl_custom_attributes_lines.html

But unfortunately after a few hours of trying to adapt it to my (much simpler) scenario, I have been unable to extract the portion I need to adjust just the colors of a line. 但是不幸的是,在尝试将其调整为适合我的场景(简单得多)后,我无法提取仅调整线条颜色所需的部分。 Does anyone have a simpler explanation for how to go about this? 有人对此有一个更简单的解释吗? ThreeJS documentation for vertexMaterial is blank, and for lines it only talks about how to adjust the color of the line as a whole (line.material.color). vertexMaterial的ThreeJS文档为空白,对于线条而言,它仅讨论如何整体调整线条的颜色(line.material.color)。

This is my code currently: 这是我目前的代码:

line = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: lineColor, opacity: lineVars.lineOpacity } ) );

Thanks for any help you can provide. 感谢您的任何帮助,您可以提供。

(Example of below function: http://webblocks.nl/tests/three/waves.html ) (以下功能的示例: http : //webblocks.nl/tests/three/waves.html

This is how I ued to make axes lines in 3 colors: 这就是我用3种颜色制作轴线的方法:

THREE.Scene.prototype.makeAxes = function(length) {
    length || (length = 5000);

    function v(x,y,z) {
        return new THREE.Vector3(x,y,z);
    }

    var colors = [0xFF0000, 0x00FF00, 0x0000FF]
    for ( var axis=0; axis<3; axis++ ) {
        var lineGeo = new THREE.Geometry();
        var from = [0, 0, 0], to = [0, 0, 0];
        from[axis] = -length;
        to[axis] = length;
        lineGeo.vertices.push(v.apply(null, from), v.apply(null, to));
        var lineMat = new THREE.LineBasicMaterial({
            color: colors[axis],
            lineWidth: 1
        });
        var line = new THREE.Line(lineGeo, lineMat);
        line.type = THREE.Lines;
        this.add(line);
    }
};

Or simpler: 或更简单:

  • create material with color 用颜色创建材料
    var lineMat = new THREE.LineBasicMaterial({color: 0xFF0000, lineWidth: 1});
  • create line with material 用材料创建线
    var line = new THREE.Line(lineGeo, lineMat);
  • add line to scene 向场景添加线

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM