2016-10-12 28 views
0

我有一個帶有網格的平面。當用戶雙擊網格時,我的代碼繪製一個球。這在R71中工作得很好,但是當我切換到R81時,raycaster不會返回相交。下面的代碼:RJ中的3JS光線投影不同於R71

在的init():

// Plane 
plane = new THREE.Mesh(
    new THREE.PlaneBufferGeometry(1000, 1000, 3, 3), 
    new THREE.MeshBasicMaterial({ color: 0xff0000, opacity: .5, transparent: true }) 
); 

plane.visible = false; 
scene.add(plane); 
planes.push(plane); 

在doubleClickEvent():

event.preventDefault(); 

var mouse = new THREE.Vector2((event.clientX/window.innerWidth) * 2 - 1, -(((event.clientY/window.innerHeight) * 2 - 1))); 
var directionVector = new THREE.Vector3(); 
directionVector.set(mouse.x, mouse.y, 0.1); 
directionVector.unproject(camera); 
directionVector.sub(camera.position);   
directionVector.normalize(); 
raycaster.set(camera.position, directionVector); 
intersects = raycaster.intersectObjects(planes); 
if (intersects.length) { 
    var sphereParent = new THREE.Object3D(); 
    var sphereGeometry = new THREE.SphereGeometry(.1, 16, 8); 
    var sphereMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff }); 
    var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial); 
    sphereParent.add(sphere); 
    sphereParent.position.set(intersects[0].point.x, intersects[0].point.y, 0.0); 
    scene.add(sphereParent); 
    objects.push(sphereParent); 
} 

如果我改變

intersects = raycaster.intersectObjects(planes); 

intersects = raycaster.intersectObjects(scene.children); 

球被繪製,但它被繪製在錯誤的位置上。

任何想法?

回答

2

我找到了答案。光線無法正常工作的原因是因爲飛機的可視性是錯誤的。解決方案是改變材料可視性而不是平面的可見性。