[英]three.js : face4 generates triangle instead of square
i'm trying to generate a square with tree.js custom Geometry. 我正在尝试使用tree.js自定义几何生成一个正方形。 but this code
但这段代码
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})
);
generates triangle can somebody explain me why it happens? 生成三角形可以有人解释为什么会发生吗?
The problem is with the THREE.Face4. 问题出在THREE.Face4上。 It has been removed in the last version.
它已在上一版本中删除。 In GitHub Three.js - Wiki - Migration we can read:
在GitHub Three.js - Wiki - Migration我们可以读到:
r59 -> r60
r59 - > r60
Face4 is removed.
Face4已删除。 Use 2 Face3 to emulate it.
使用2 Face3来模拟它。
And the reason why you see a triangle instead of a square is that: 你看到三角形而不是正方形的原因是:
THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
return new THREE.Face3( a, b, c, normal, color, materialIndex );
};
Three.Face4 is deprecated. Three.Face4已弃用。
Here's how you use 2 Face3
to make a square: 以下是使用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;
}
Actually it should be drawing something like a bow-tie. 实际上应该画一个像蝴蝶结的东西。 The vertex order is not correct.
顶点顺序不正确。 Swap the last two vertices.
交换最后两个顶点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.