在三个js中用颜色填充线之间的区域

时间:2018-07-04 09:23:13

标签: javascript html three.js

我有两个顶点数据集,一个具有真实顶点,另一个具有相同顶点,但是y为零。现在,我希望它们能够连接并充满。我已经使用CatmullRomCurve3和生产线将它们连接起来,但是没有运气来填补它。

<EditText ...>
 <requestFocus />
</EditText>

enter image description here

1 个答案:

答案 0 :(得分:0)

在尝试了多种不同的几何形状之后,我使用以下代码解决了该问题。

for (var i = 0; i < data.real.length; i++, f += 4) {
        var o2 = i == data.real.length - 1 ? 0 : i + 1;
        var tl = data.real[i];
        var tr = data.real[o2];
        var bl = data.zeroAxis[i];
        var br = data.zeroAxis[o2];

        geometry.vertices.push(tl, tr, br, bl);
        var normal = new THREE.Vector3(0, 1, 0); // optional
        var color = new THREE.Color(color); // optional
        var materialIndex = 0; // optional
        geometry.faces.push(new THREE.Face3(f, f + 1, f + 2, normal, color,
                materialIndex));
        geometry.faces.push(new THREE.Face3(f, f + 2, f + 3, normal, color,
                materialIndex));

    }
    geometry.computeFaceNormals();
    var material = new THREE.MeshPhongMaterial({
        color : color,
        side : THREE.DoubleSide,
        transparent : true,
        opacity : 1
    });
    var object = new THREE.Mesh(geometry, material);
    object.position.set(0, a, 0);
    this.plot = object;

    var geo = new THREE.EdgesGeometry(object.geometry);
    // or WireframeGeometry
    var mat = new THREE.MeshPhongMaterial({
        color : 0xffffff,
        linewidth : 1,
        side : THREE.DoubleSide,
        transparent : true,
        opacity : 0.75
    });
    var wireframe = new THREE.LineSegments(geo, mat);

    object.add(wireframe);
    this.tb.scene.add(object);