@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
22 lines (21 loc) • 737 B
JavaScript
"use strict";
import { Raycaster, Vector3, Matrix4 } from "three";
export class MapboxRaycaster extends Raycaster {
constructor() {
super(...arguments);
this._inverseProjMat = new Matrix4();
this._camPos = new Vector3();
this._mousePos = new Vector3();
this._viewDir = new Vector3();
}
setFromCamera(mouse, camera) {
this._inverseProjMat.copy(camera.projectionMatrix);
this._inverseProjMat.invert();
this._camPos.set(0, 0, 0);
this._camPos.applyMatrix4(this._inverseProjMat);
this._mousePos.set(mouse.x, mouse.y, 1);
this._mousePos.applyMatrix4(this._inverseProjMat);
this._viewDir.copy(this._mousePos).sub(this._camPos).normalize();
this.set(this._camPos, this._viewDir);
}
}