I am using three.js r67 in Chrome Version 35.0.1916.153 m
I am attempting to intersect some custom meshes that I have created in my scene. The raycaster does not appear to be registering the meshes although they exist within scene.children .
Mesh creation code:
if (modelVertices != null && modelVertices.length >= 3) {
triangles = THREE.Shape.Utils.triangulateShape ( modelVertices, holes );
for( var i = 0; i < triangles.length; i++ ){
modelGeometry.faces.push( new THREE.Face3( triangles[i][0], triangles[i][2], triangles[i][2] ));
}
modelGeometry.computeFaceNormals();
var modelMesh = new THREE.Mesh(modelGeometry, material);
modelMesh.material.side = THREE.DoubleSide;
polyhedralzGroup.add(modelMesh)
}
Raycasting code:
var projector = new THREE.Projector();
projector.unprojectVector( vector, camera );
var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
//console.log("Work");
// See if the ray from the camera into the world hits one of our meshes
var intersects = raycaster.intersectObjects( scene.children, true );
helper.position.set( 0, 0, 0 );
//console.log(intersects.length);
if ( intersects.length > 0 ) {
if (intersects[ 0 ].face != null) {
helper.lookAt( intersects[ 0 ].face.normal );
helper.position.copy( intersects[ 0 ].point );
}
As in the code, I am using computeFaceNormals(); so this isn't the issue (see here). Oddly the scene seems to be intersecting other geometries that I constructed using simple triangles (i.e. not using THREE.Shape.Utils.triangulateShape ; just pushing triangle vertices and faces manually) perfectly fine which means this can't be an issue with not taking into account the canvas offset for intersecting. I have examined both geometries and there doesn't seem to be any fundamental differences between the two.
Does anyone have any ideas as to what the issue may be?