@woosh/meep-engine 2.43.14 → 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.
- package/core/geom/3d/SurfacePoint3.d.ts +5 -0
- package/core/geom/3d/SurfacePoint3.js +4 -0
- package/engine/ecs/terrain/tiles/TerrainTile.js +10 -3
- package/engine/ecs/terrain/tiles/TerrainTileManager.js +2 -1
- package/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +44 -4
- package/package.json +1 -1
|
@@ -4,8 +4,13 @@ import {Matrix4} from "three";
|
|
|
4
4
|
export class SurfacePoint3 {
|
|
5
5
|
normal: Vector3
|
|
6
6
|
position: Vector3
|
|
7
|
+
index: number
|
|
7
8
|
|
|
8
9
|
applyMatrix4_three(matrix4: Matrix4): void
|
|
9
10
|
|
|
11
|
+
applyMatrix4(m4: ArrayLike<number>): void
|
|
12
|
+
|
|
10
13
|
copy(other: SurfacePoint3): void
|
|
14
|
+
|
|
15
|
+
clone(): SurfacePoint3
|
|
11
16
|
}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -212,7 +219,7 @@ class TerrainTile {
|
|
|
212
219
|
* @param {TerrainTile|undefined} bottomLeft
|
|
213
220
|
* @param {TerrainTile|undefined} bottomRight
|
|
214
221
|
*/
|
|
215
|
-
|
|
222
|
+
stitchNormals(top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight) {
|
|
216
223
|
|
|
217
224
|
|
|
218
225
|
const v0 = new Vector3(),
|
|
@@ -516,6 +516,7 @@ class TerrainTileManager {
|
|
|
516
516
|
}
|
|
517
517
|
|
|
518
518
|
/**
|
|
519
|
+
* Fix normals along the seams of the tile
|
|
519
520
|
*
|
|
520
521
|
* @param {number} x
|
|
521
522
|
* @param {number} y
|
|
@@ -556,7 +557,7 @@ class TerrainTileManager {
|
|
|
556
557
|
right = self.getRaw(x + 1, y);
|
|
557
558
|
}
|
|
558
559
|
|
|
559
|
-
tile.
|
|
560
|
+
tile.stitchNormals(top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight);
|
|
560
561
|
}
|
|
561
562
|
|
|
562
563
|
/**
|
|
@@ -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(
|
|
183
|
+
raycast(
|
|
184
|
+
hit,
|
|
185
|
+
originX, originY, originZ,
|
|
186
|
+
directionX, directionY, directionZ
|
|
187
|
+
) {
|
|
168
188
|
|
|
169
|
-
|
|
170
|
-
|
|
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(
|
|
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.
|
|
8
|
+
"version": "2.43.16",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|