i'm trying to generate a square with tree.js custom Geometry. 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. It has been removed in the last version. In GitHub Three.js - Wiki - Migration we can read:
r59 -> r60
Face4 is removed. Use 2 Face3 to emulate it.
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.
Here's how you use 2 Face3
to make a square:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With