@polygonjs/plugin-mapbox
Version:
Mapbox plugin for the 3D engine https://polygonjs.com
22 lines (21 loc) • 775 B
JavaScript
import { Raycaster, Vector3, Matrix4 } from "three";
export class MapboxRaycaster extends Raycaster {
constructor() {
super(...arguments);
this.firstHitOnly = true;
this._inverse_proj_mat = new Matrix4();
this._cam_pos = new Vector3();
this._mouse_pos = new Vector3();
this._view_dir = new Vector3();
}
setFromCamera(mouse, camera) {
this._inverse_proj_mat.copy(camera.projectionMatrix);
this._inverse_proj_mat.invert();
this._cam_pos.set(0, 0, 0);
this._cam_pos.applyMatrix4(this._inverse_proj_mat);
this._mouse_pos.set(mouse.x, mouse.y, 1);
this._mouse_pos.applyMatrix4(this._inverse_proj_mat);
this._view_dir.copy(this._mouse_pos).sub(this._cam_pos).normalize();
this.set(this._cam_pos, this._view_dir);
}
}