我正在使用 THREE.js 在我的页面上显示一些对象。我可以点击对象,但我注意到无论我点击哪个对象,intersects[0].object.position
总是返回x=0, y=0, z=0
,而对象的实际位置无疑是不同的。
您可以查看以下代码并评论我做错了什么吗?
function onDocumentMouseDown(event) {
event.preventDefault();
var vector = new THREE.Vector3((event.clientX / window.innerWidth)*2-1, -(event.clientY / window.innerHeight)*2+1, 0.5);
projector.unprojectVector(vector, camera);
var ray = new THREE.Ray(camera.position, vector.subSelf(camera.position).normalize());
var intersects = ray.intersectObjects(teeth, true);
if (intersects.length > 0) {
//not working
camera.position.x=intersects[0].object.position.x;
//not working
camera.position.y=intersects[0].object.postion.y;
//working
intersects[0].object.material.color.setHex(Math.random()*0xffffff);
}
}