I have a PlaneGeometry with only 2 faces (the red one in the pic). I'm trying to extrude one of them along its normal with the following function:
function extrude( mesh, amount ) {
var geometry = mesh.geometry;
//execute only on the first face
for( var f = 0; f < geometry.faces.length -1; f++){
var face = geometry.faces[ f ];
var f_normal = face.normal;
//This is the vertex used by the extrusion path//
var vertex = geometry.vertices[ face.a ];
//create extrusion path
var spline = new THREE.SplineCurve3( [
new THREE.Vector3( vertex.x, vertex.y, vertex.z ),
new THREE.Vector3( vertex.x + (f_normal.x * amount), vertex.y + (f_normal.y * amount), vertex.z + (f_normal.z * amount) )
] );
//get vertices
var v1 = geometry.vertices[ face.a ];
var v2 = geometry.vertices[ face.b ];
var v3 = geometry.vertices[ face.c ];
//draw shape
var shape = new THREE.Shape();
shape.moveTo( v1.x, v1.y, v1.z );
shape.lineTo( v2.x, v2.y, v2.z );
shape.lineTo( v3.x, v3.y, v3.z );
shape.lineTo( v1.x, v1.y, v1.z );
//extrude it
var extrudeSettings = { amount: amount, extrudePath: spline, steps: 1, bevelEnabled: false };
var extrudedGeo = new THREE.ExtrudeGeometry( shape, extrudeSettings );
var material = new THREE.MeshPhongMaterial( {color: 0x00ff00, wireframe: true} );
//create new mesh
var mesh = new THREE.Mesh( extrudedGeo, material);
scene.add( mesh);
}
}
It extrudes perfectly along its normal but the extruded mesh seems to be rotated (I'm using the face.a vertex for the extrusion path, but same happens if I switch to b or c). Why is this happening? I want the new geometry/mesh to perfectly sit on the face it was extruded from, how can I do?