Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript THREE.js与[0]相交。object.position始终返回(0,0,0)_Javascript_Webgl_Three.js - Fatal编程技术网

Javascript THREE.js与[0]相交。object.position始终返回(0,0,0)

Javascript THREE.js与[0]相交。object.position始终返回(0,0,0),javascript,webgl,three.js,Javascript,Webgl,Three.js,我正在使用THREE.js在页面上显示一些对象。我可以单击对象,但我注意到无论单击哪个对象,都会与[0]相交。object.position始终返回x=0,y=0,z=0,而对象的实际位置无疑是不同的 你能回顾一下下面的代码并评论我做错了什么吗 function onDocumentMouseDown(event) { event.preventDefault(); var vector = new THREE.Vector3((event.clientX / window.innerW

我正在使用THREE.js在页面上显示一些对象。我可以单击对象,但我注意到无论单击哪个对象,
都会与[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);
  }
}

对象位置:与[0]相交。object.position

相交位置:相交[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].point.x;
    //not working
    camera.position.y=intersects[0].point.y;
    //working
    intersects[0].object.material.color.setHex(Math.random()*0xffffff);
  }
}

我没有找到相交[0]。position.x作为有效属性。虽然存在相交点[0]。但点。x@Gero3.. 我在if(intersects.length>0)中所做的是同时更改相交对象的位置。与[0]相交。对象。位置。z=50;现在我不知道如何在对象未单击时跟踪其原始位置,以便在单击其他对象时可以将其他单击的对象移动到其相同的旧位置。有什么想法吗?