我使用OBJLoader加载模型,这是加载obj文件的代码:
var loader = new THREE.OBJLoader();
loader.load('obj/teeth/teeth4_5.obj', function(object) {
model = object;
scene.add( model );
objects.push( model );
});
我正试图用raycaster找到交叉点。我在three.js中的canvas_interactive_cubes示例(http://mrdoob.github.io/three.js/examples/canvas_interactive_cubes.html)中实现了我的代码。以下是查找交集的代码:
function onDocumentMouseDown( event ){
event.preventDefault();
var mouseX = (event.clientX / window.innerWidth)*2-1;
var mouseY = -(event.clientY /window.innerHeight)*2+1;
var vector = new THREE.Vector3( mouseX, mouseY, 0.5 );
projector.unprojectVector( vector, camera );
var raycaster = new THREE.Raycaster( camera.position, vector.sub( camera.position ).normalize() );
var intersects = raycaster.intersectObjects( scene.children );
console.log( intersects[0].point);
}
不幸的是我无法获得交叉点的x,y,z坐标,无论我在哪里点击,它总是显示“TypeError:intersects [0]未定义”。
我被困在这里好几天了。有人能告诉我一个在加载的obj文件上获取交集的方法吗?感谢您的帮助。
答案 0 :(得分:8)
尝试添加递归标记,如下所示:
var intersects = raycaster.intersectObjects( objects, true );
three.js r.58