@woosh/meep-engine 2.43.15 → 2.43.16

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.
@@ -1,5 +1,6 @@
1
1
  import Vector3 from "../Vector3.js";
2
2
  import { v3_length } from "../v3_length.js";
3
+ import { assert } from "../../assert.js";
3
4
 
4
5
  /**
5
6
  * Used for representing points on a 3D surface. Used for raycasting contacts
@@ -22,6 +23,9 @@ export class SurfacePoint3 {
22
23
  * @param {number[]|mat4|Float32Array} m
23
24
  */
24
25
  applyMatrix4(m) {
26
+ assert.defined(m, 'matrix');
27
+ assert.notNull(m, 'matrix');
28
+
25
29
  // transform position
26
30
  const p = this.position;
27
31
 
@@ -26,11 +26,13 @@ import Signal from "../../../../core/events/signal/Signal.js";
26
26
  import { mat4 } from "gl-matrix";
27
27
  import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
28
28
  import { NumericInterval } from "../../../../core/math/interval/NumericInterval.js";
29
+ import { array_copy } from "../../../../core/collection/array/copyArray.js";
29
30
 
30
31
  function extractFaceIndexFromLeaf(leaf) {
31
32
  return leaf;
32
33
  }
33
34
 
35
+
34
36
  class TerrainTile {
35
37
  /**
36
38
  * terrain tile is a part of a 2d array
@@ -143,8 +145,10 @@ class TerrainTile {
143
145
  * @param {number[]|Float32Array|mat4} m4
144
146
  */
145
147
  set transform(m4) {
146
- mat4.copy(this.mesh.matrixWorld.elements, m4);
148
+ array_copy(m4, 0, this.mesh.matrixWorld.elements, 0, 16);
147
149
  this.computeBoundingBox();
150
+
151
+ array_copy(m4, 0, this.raycaster.transform, 0, 16);
148
152
  }
149
153
 
150
154
  /**
@@ -182,7 +186,10 @@ class TerrainTile {
182
186
  * @return {boolean}
183
187
  */
184
188
  raycastFirstSync(result, originX, originY, originZ, directionX, directionY, directionZ) {
185
- return this.raycaster.raycast(result, originX, originY, originZ, directionX, directionY, directionZ);
189
+
190
+ const r = this.raycaster.raycast(result, originX, originY, originZ, directionX, directionY, directionZ);
191
+
192
+ return r;
186
193
  }
187
194
 
188
195
  getVertexNormal(index, result) {
@@ -5,6 +5,11 @@ import { rayTriangleIntersection } from "../../../../../core/geom/GeometryMath.j
5
5
  import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
6
6
  import { assert } from "../../../../../core/assert.js";
7
7
  import { v3_length } from "../../../../../core/geom/v3_length.js";
8
+ import { ray3_array_apply_matrix4 } from "../../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
9
+ import { mat4 } from "gl-matrix";
10
+ import { ray3_array_compose } from "../../../../../core/geom/3d/ray/ray3_array_compose.js";
11
+ import { array_copy } from "../../../../../core/collection/array/copyArray.js";
12
+ import { MATRIX_4_IDENTITY } from "../../../../../core/geom/3d/matrix/MATRIX_4_IDENTITY.js";
8
13
 
9
14
  const hit = new ThreeVector3();
10
15
 
@@ -12,6 +17,9 @@ const vA = new ThreeVector3(),
12
17
  vB = new ThreeVector3(),
13
18
  vC = new ThreeVector3();
14
19
 
20
+ const ray_tmp = [];
21
+ const m4_tmp = [];
22
+
15
23
  /**
16
24
  *
17
25
  * @param {number[]|Uint8Array|Uint16Array|Uint32Array} indices
@@ -119,6 +127,14 @@ export class BVHGeometryRaycaster {
119
127
  this.origin = new Vector3();
120
128
  this.direction = new Vector3();
121
129
 
130
+ /**
131
+ *
132
+ * @type {Float32Array}
133
+ */
134
+ this.transform = new Float32Array(16);
135
+
136
+ array_copy(MATRIX_4_IDENTITY, 0, this.transform, 0, 16);
137
+
122
138
  this.extractFaceIndexFromLeaf = extractFaceIndexFromLeaf_default;
123
139
  }
124
140
 
@@ -164,14 +180,36 @@ export class BVHGeometryRaycaster {
164
180
  * @param {number} directionZ
165
181
  * @returns {boolean}
166
182
  */
167
- raycast(hit, originX, originY, originZ, directionX, directionY, directionZ) {
183
+ raycast(
184
+ hit,
185
+ originX, originY, originZ,
186
+ directionX, directionY, directionZ
187
+ ) {
168
188
 
169
- this.origin.set(originX, originY, originZ);
170
- this.direction.set(directionX, directionY, directionZ);
189
+ mat4.invert(m4_tmp, this.transform);
190
+
191
+ ray3_array_compose(
192
+ ray_tmp,
193
+ originX, originY, originZ,
194
+ directionX, directionY, directionZ
195
+ );
196
+
197
+ ray3_array_apply_matrix4(ray_tmp, ray_tmp, m4_tmp);
198
+
199
+ const _originX = ray_tmp[0];
200
+ const _originY = ray_tmp[1];
201
+ const _originZ = ray_tmp[2];
202
+
203
+ const _directionX = ray_tmp[3];
204
+ const _directionY = ray_tmp[4];
205
+ const _directionZ = ray_tmp[5];
206
+
207
+ this.origin.set(_originX, _originY, _originZ);
208
+ this.direction.set(_directionX, _directionY, _directionZ);
171
209
 
172
210
  this.__bestDistance = Number.POSITIVE_INFINITY;
173
211
 
174
- this.bvh.traverseRayLeafIntersections(originX, originY, originZ, directionX, directionY, directionZ, this.visitLeafIntersection, this);
212
+ this.bvh.traverseRayLeafIntersections(_originX, _originY, _originZ, _directionX, _directionY, _directionZ, this.visitLeafIntersection, this);
175
213
 
176
214
  if (this.__bestDistance !== Number.POSITIVE_INFINITY) {
177
215
 
@@ -185,6 +223,8 @@ export class BVHGeometryRaycaster {
185
223
  hit.position.copy(this.__bestPosition);
186
224
  hit.normal.copy(vNormal);
187
225
 
226
+ hit.applyMatrix4(this.transform);
227
+
188
228
  return true;
189
229
  } else {
190
230
  //no hit
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "productName": "Meep",
6
6
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.43.15",
8
+ "version": "2.43.16",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",