Hy! I'm working in three js. I'm loading modells by THREE.JSONLoader. Now I'm at the part to select these objects and their faces. It is working. But now I want to get the vertices of the selected face, check the code below:
intersections = raycaster.intersectObjects( objects );
if ( intersections.length > 0 ) {
if ( intersected != intersections[ 0 ].object ) {
intersected = intersections[ 0 ].object;
/*HERE*/
console.log("Hit-face a @ " + intersections[0].face.a);
console.log("Hit-face b @ " + intersections[0].face.b);
console.log("Hit-face c @ " + intersections[0].face.c);
var faceColorMaterial = new THREE.MeshBasicMaterial(
{ color: 0xffffff, vertexColors: THREE.FaceColors } );
var sphereGeometry = new THREE.SphereGeometry( 0.1, 32, 16 );
var sphereGeometryf = new THREE.SphereGeometry( 3, 32, 16 );
var sphereGeometrys = new THREE.SphereGeometry( 3, 32, 16 );
var sphereGeometryt = new THREE.SphereGeometry( 3, 32, 16 );
var sphere = new THREE.Mesh( sphereGeometry, faceColorMaterial );
sphere.position.set(intersections[0].point.x, intersections[0].point.y, intersections[0].point.z);
var spheref = new THREE.Mesh( sphereGeometryf, faceColorMaterial );
spheref.position.set(intersections[0].object.geometry.vertices[intersections[0].face.a].x + intersections[0].object.position.x,
intersections[0].object.geometry.vertices[intersections[0].face.a].y + intersections[0].object.position.y,
intersections[0].object.geometry.vertices[intersections[0].face.a].z + intersections[0].object.position.z);
var spheres = new THREE.Mesh( sphereGeometrys, faceColorMaterial );
spheres.position.set(intersections[0].object.geometry.vertices[intersections[0].face.b].x + intersections[0].object.position.x,
intersections[0].object.geometry.vertices[intersections[0].face.b].y + intersections[0].object.position.y,
intersections[0].object.geometry.vertices[intersections[0].face.b].z + intersections[0].object.position.z);
var spheret = new THREE.Mesh( sphereGeometryt, faceColorMaterial );
spheret.position.set(intersections[0].object.geometry.vertices[intersections[0].face.c].x + intersections[0].object.position.x,
intersections[0].object.geometry.vertices[intersections[0].face.c].y + intersections[0].object.position.y,
intersections[0].object.geometry.vertices[intersections[0].face.c].z + intersections[0].object.position.z);
scene.add(sphere);
scene.add(spheref);
scene.add(spheres);
scene.add(spheret);
/*HERE*/
}
}
So in this example code, the "sphere" is the intersection point where the Ray meets with the 1st object.
spheref-spheres-spheret are the vertices visualization, but when I add theese spheres to thoose vertices, they're somewhere else(visible).
The method above working with this example,by replacing the onDocumentMouseDown event with my code above: http://stemkoski.github.io/Three.js/Mouse-Click.html
But it is not working with the loaded objects.