用三个js中的颜色填充行之间的区域 [英] Fill Area between Lines with color in three js

查看:102
本文介绍了用三个js中的颜色填充行之间的区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have two data sets of vertices one with real vertices and second same vertices but y is zero. Now I want them to be connected and get filled. I have connected them using CatmullRomCurve3 and the line as well but having no luck to fill it.

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

推荐答案

经过多次不同几何的尝试后,我使用以下代码解决了问题。

After so many tries with different geometries, I resolved the problem using the following code.

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

这篇关于用三个js中的颜色填充行之间的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆