Three.js效果在firefox上工作但不在chrome上工作

时间:2015-02-22 19:19:24

标签: javascript arrays three.js

我使用Half Edge数据结构递归搜索相邻的面并相应地着色它们。但是,我可以看到对Firefox的影响,但不会对chrome有效。有没有人有想法?帮助将不胜感激!

 function neighbor(color_indices){
    var color_indices_length = color_indices.length;
    for (var i = 0; i < color_indices_length; i++) {
        var adjacentFaces = heData.findAdjacentFacesToFace(color_indices[i]);
        for (var k = 0; k < 3; k++){
            if(color_indices.indexOf(adjacentFaces[k]) == -1) {
                color_indices.push(adjacentFaces[k]);
            }
        }
    }
}

function recursion(recursion_times, color_indices){
        for (var z = 1; z <= recursion_times; z++){
            neighbor(color_indices)
        }
}

function red() {
        gl_object.colorsNeedUpdate = true;
        for(var j=0; j < red_indices.length; j++){
            gl_object.children[0].geometry.faces[red_indices[j]].color = new THREE.Color(0xff0000);
        }
}

function red_color() {  
        red_indices.push(selectedFaces[0].faceIndex);
        recursion(11,red_indices);
        red();
}

另外,我也试过了这个实现!但具有相同的效果(不适用于我的铬)

//test
    var adjacentFaces = [];
    var temp = [];
    temp[0] = heData.findAdjacentFacesToFace(color_indices[i])[0];
    temp[1] = heData.findAdjacentFacesToFace(color_indices[i])[1];
    temp[2] = heData.findAdjacentFacesToFace(color_indices[i])[2];

    adjacentFaces.push(temp[0]);
    adjacentFaces.push(temp[1]);
    adjacentFaces.push(temp[2]);

1 个答案:

答案 0 :(得分:0)

这是一件简单的事情,只需改变

  for (var k = 0; k < 3; k++){
        if(color_indices.indexOf(adjacentFaces[k]) == -1) {
            color_indices.push(adjacentFaces[k]);
        }
    }

  for (var k = 0; k < adjacentFaces.length; k++){
        if(color_indices.indexOf(adjacentFaces[k]) == -1) {
            color_indices.push(adjacentFaces[k]);
        }
    }