6

我正在尝试使用 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})
);

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

4

3 回答 3

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

};
于 2013-09-06T09:11:35.447 回答
10

三.Face4 已弃用。

以下是如何使用 2Face3制作正方形:

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;
}
于 2014-05-13T16:05:15.753 回答
3

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

于 2013-05-11T16:35:14.210 回答