@mcolabs/threebox-plugin 4.0.3 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcolabs/threebox-plugin",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "type": "module",
5
5
  "description": "A Three.js plugin for Mapbox GL JS, using the CustomLayerInterface feature. Provides convenient methods to manage objects in lnglat coordinates, and to synchronize the map and scene cameras.",
6
6
  "main": "dist/threebox.cjs",
@@ -58,6 +58,17 @@ CameraSync.prototype = {
58
58
 
59
59
  const t = this.map.transform;
60
60
  this.camera.aspect = t.width / t.height; //bug fixed, if aspect is not reset raycast will fail on map resize
61
+
62
+ // Check if canvas size changed and update renderer for correct raycasting
63
+ if (this.map.tb && this.map.tb.renderer) {
64
+ const canvas = this.map.getCanvas();
65
+ if (this._lastCanvasWidth !== canvas.clientWidth || this._lastCanvasHeight !== canvas.clientHeight) {
66
+ this._lastCanvasWidth = canvas.clientWidth;
67
+ this._lastCanvasHeight = canvas.clientHeight;
68
+ this.map.tb.renderer.setSize(canvas.clientWidth, canvas.clientHeight);
69
+ }
70
+ }
71
+
61
72
  const offset = t.centerOffset || new THREE.Vector3(); //{ x: t.width / 2, y: t.height / 2 };
62
73
  let farZ = 0;
63
74
  let furthestDistance = 0;
@@ -112,6 +123,8 @@ CameraSync.prototype = {
112
123
  }
113
124
  this.camera.projectionMatrix.elements[8] = -offset.x * 2 / t.width;
114
125
  this.camera.projectionMatrix.elements[9] = offset.y * 2 / t.height;
126
+ // Update inverse projection matrix for raycasting
127
+ this.camera.projectionMatrixInverse.copy(this.camera.projectionMatrix).invert();
115
128
 
116
129
  // Unlike the Mapbox GL JS camera, separate camera translation and rotation out into its world matrix
117
130
  // If this is applied directly to the projection matrix, it will work OK but break raycasting