我在应用上使用Three.js,目前我遇到了对象选择问题。有些物体没有被光线交叉,但仅限于某些相机旋转。我正在尝试调试代码并绘制光线。
我在我的代码中使用此方法(canvas
是三个对象的命名空间):
C.getXY = function(e) {
var click = {};
click.x = ( e.clientX / window.innerWidth ) * 2 - 1;
click.y = - ( e.clientY / window.innerHeight ) * 2 + 1;
return click;
};
C.doPicking = function(e) {
var picked = false;
if (canvas.boundingBox !== null) {
canvas.scene.remove(canvas.boundingBox);
}
var projector = new THREE.Projector(), click = C.getXY(e);
var ray = projector.pickingRay(new THREE.Vector3(click.x, click.y, 0), canvas.camera);
ray.linePrecision = 0.00000000000000001;
ray.precision = 0.00000000000000001;
var intersects = ray.intersectObjects(canvas.scene.children);
if (intersects.length > 0) {
var i = 0;
var ids = [];
while (i < intersects.length) {
if (intersects[i].object.visible) {
//Object is picked
}
++i;
}
}
};
我的问题是......在调试过程中需要考虑的其他要点是什么?
答案 0 :(得分:0)
Ooops ...在将网格添加到场景之前忘记添加mesh.geometry.computeFaceNormals();
。现在采摘工作正常。