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

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

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

 for (var i = 0; i < data.real.length; i++) {
    var o2 = i == data.real.length - 1 ? 0 : i + 1;
    var rO1 = data.real[i];
    var rO2 = data.real[o2];
    var fO1 = data.zeroAxis[i];
    var fO2 = data.zeroAxis[o2];

    var curve = new THREE.CatmullRomCurve3([ rO1, rO2, fO1, fO2 ]);

    var points = curve.getPoints(50);
    var geometry = new THREE.BufferGeometry().setFromPoints(points);



    var material = new THREE.LineBasicMaterial({
        color : 0xff0000
    });

    // Create the final object to add to the scene
    var curveObject = new THREE.Line(geometry, material);
    console.log(curveObject)
    this.tb.scene.add(curveObject);
    this.tb.render();
}


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

最佳答案

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

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);

关于javascript - 在三个js中用颜色填充线之间的区域,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51170190/

10-10 21:58