three.js:face4生成三角形而不是方形

时间:2013-05-11 14:45:24

标签: javascript geometry three.js

我正在尝试使用tree.js自定义几何体生成一个正方形。 但是这段代码

var cubeGeo = new THREE.Geometry();
cubeGeo.vertices.push( new THREE.Vector3( -25,  25, -25 ) );
cubeGeo.vertices.push( new THREE.Vector3(  25,  25, -25 ) );
cubeGeo.vertices.push( new THREE.Vector3( -25, -25, -25 ) );
cubeGeo.vertices.push( new THREE.Vector3(  25,  -25, -25 ) );
cubeGeo.faces.push( new THREE.Face4( 0, 1, 2, 3, new THREE.Vector3( 0,  0,  1 ), 0xffffff, 0) );

    var cube = new THREE.Mesh(
  cubeGeo,  
  //new THREE.CubeGeometry(50, 50, 50),
  new THREE.MeshPhongMaterial({color: 0x696969, emissive: 0x696969, specular:0x696969, shininess: 15})
);

生成三角形 有人能解释我为什么会这样吗?

3 个答案:

答案 0 :(得分:14)

问题出在THREE.Face4上。它已在上一版本中删除。在GitHub Three.js - Wiki - Migration我们可以阅读:

  

r59 - > R60

     

Face4已删除。使用2 Face3来模拟它。

你看到三角形而不是正方形的原因是:

THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {

    return new THREE.Face3( a, b, c, normal, color, materialIndex );

};

答案 1 :(得分:9)

Three.Face4已被弃用。

以下是使用2 Face3制作正方形的方法:

function drawSquare(x1, y1, x2, y2) { 

    var square = new THREE.Geometry(); 

    //set 4 points
    square.vertices.push( new THREE.Vector3( x1,y2,0) );
    square.vertices.push( new THREE.Vector3( x1,y1,0) );
    square.vertices.push( new THREE.Vector3( x2,y1,0) );
    square.vertices.push( new THREE.Vector3( x2,y2,0) );

    //push 1 triangle
    square.faces.push( new THREE.Face3( 0,1,2) );

    //push another triangle
    square.faces.push( new THREE.Face3( 0,3,2) );

    //return the square object with BOTH faces
    return square;
}

答案 2 :(得分:3)

实际上应该画一个像蝴蝶结的东西。顶点顺序不正确。交换最后两个顶点。