peterqliu / threebox

A three.js plugin for Mapbox GL JS, with support for basic animation and advanced 3D rendering.
MIT License
526 stars 320 forks source link

Fix raycasting issues #5

Closed kronick closed 7 years ago

kronick commented 7 years ago

This should fix the raycasting issues in #2 by disentangling the camera projection matrix and camera world matrix.

Should be able to use raycasting as in the Three.js examples:

var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();

// scale mouse pixel position to a percentage of the screen's width and height
mouse.x = ( e.point.x / threebox.map.transform.width ) * 2 - 1;
mouse.y = - ( e.point.y / threebox.map.transform.height ) * 2 + 1;

raycaster.setFromCamera(mouse, threebox.camera);

// calculate objects intersecting the picking ray
var intersects = raycaster.intersectObjects(threebox.world.children);

This is demonstrated in tests/raycast-debug.html

cc/ @peterqliu