代码之家  ›  专栏  ›  技术社区  ›  Ullas Hunka

更改使用面3创建的网格的颜色

  •  0
  • Ullas Hunka  · 技术社区  · 8 年前

    var geometry = new THREE.Geometry();
    var f = 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);
        geometry.faces.push(new THREE.Face3(f, f + 1, f + 2));
        face.materials = [ new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } ) ];
    
        geometry.faces.push(new THREE.Face3(f, f + 3, f + 2));
    }
    var material = new THREE.MeshPhongMaterial({
        color : new THREE.Color(0x008000),
        side : THREE.DoubleSide,
        transparent : true,
        opacity : 0.5
    });
    var object = new THREE.Mesh(geometry, material);
    object.position.set(0, 0, 0);
    this.plot = object;
    this.tb.scene.add(object);
    this.tb.render();
    
    3 回复  |  直到 8 年前
        1
  •  0
  •   Mugen87    8 年前

    face.materials = [ new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } ) ];
    

    var faces = geometry.faces;
    
    for ( var i = 0, l = faces.length; i < l; i ++ ) {
    
        var face = faces[ i ];
        face.color = new THREE.Color( Math.random() * 0xffffff );
    
    }
    

    vertexColors THREE.FaceColors https://jsfiddle.net/f2Lommf5/8539/

        2
  •  0
  •   Brakebein    8 年前

    Face3 docs

    //the face normals and vertex normals can be calculated automatically if not supplied above
    geometry.computeFaceNormals();
    geometry.computeVertexNormals();
    
        3
  •  0
  •   Ullas Hunka    8 年前

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