我正在使用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);
}
}
答案 0 :(得分:2)
对象位置:intersects [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);
}
}