0

我正在使用 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);
  }
}
4

1 回答 1

2

对象位置:intersects[0].object.position

相交位置: intersects[0].position

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].point.x;
    //not working
    camera.position.y=intersects[0].point.y;
    //working
    intersects[0].object.material.color.setHex(Math.random()*0xffffff);
  }
}
于 2012-11-18T10:23:00.187 回答