@woosh/meep-engine 2.43.15 → 2.43.17
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.js +4 -0
- package/engine/ecs/terrain/tiles/TerrainTile.js +15 -10
- package/engine/graphics/ecs/path/PathDisplaySystem.d.ts +3 -0
- package/engine/graphics/ecs/path/PathDisplaySystem.js +10 -0
- package/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +44 -4
- package/package.json +1 -1
|
@@ -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,15 +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";
|
|
30
|
+
import { passThrough } from "../../../../core/function/Functions.js";
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/**
|
|
33
|
+
* terrain tile is a part of a 2d array
|
|
34
|
+
*/
|
|
34
35
|
class TerrainTile {
|
|
35
|
-
/**
|
|
36
|
-
* terrain tile is a part of a 2d array
|
|
37
|
-
*/
|
|
38
36
|
constructor() {
|
|
39
37
|
this.gridPosition = new Vector2();
|
|
40
38
|
this.scale = new Vector2(1, 1);
|
|
@@ -101,6 +99,7 @@ class TerrainTile {
|
|
|
101
99
|
this.onDestroyed = new Signal();
|
|
102
100
|
|
|
103
101
|
/**
|
|
102
|
+
* Encodes whether stitching has been performed on per-neighbour basis
|
|
104
103
|
* @private
|
|
105
104
|
* @type {{bottomLeft: boolean, top: boolean, left: boolean, bottom: boolean, bottomRight: boolean, topLeft: boolean, topRight: boolean, right: boolean}}
|
|
106
105
|
*/
|
|
@@ -127,7 +126,7 @@ class TerrainTile {
|
|
|
127
126
|
|
|
128
127
|
this.raycaster = new BVHGeometryRaycaster();
|
|
129
128
|
//Binary BVH form doesn't have distinct leaf objects and stores face indices directly, this requires a special face index extractor that treats leaves as indices directly.
|
|
130
|
-
this.raycaster.extractFaceIndexFromLeaf =
|
|
129
|
+
this.raycaster.extractFaceIndexFromLeaf = passThrough;
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
/**
|
|
@@ -143,8 +142,11 @@ class TerrainTile {
|
|
|
143
142
|
* @param {number[]|Float32Array|mat4} m4
|
|
144
143
|
*/
|
|
145
144
|
set transform(m4) {
|
|
146
|
-
|
|
145
|
+
array_copy(m4, 0, this.mesh.matrixWorld.elements, 0, 16);
|
|
147
146
|
this.computeBoundingBox();
|
|
147
|
+
|
|
148
|
+
// raycaster needs to store transform as well
|
|
149
|
+
array_copy(m4, 0, this.raycaster.transform, 0, 16);
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
/**
|
|
@@ -182,7 +184,10 @@ class TerrainTile {
|
|
|
182
184
|
* @return {boolean}
|
|
183
185
|
*/
|
|
184
186
|
raycastFirstSync(result, originX, originY, originZ, directionX, directionY, directionZ) {
|
|
185
|
-
|
|
187
|
+
|
|
188
|
+
const r = this.raycaster.raycast(result, originX, originY, originZ, directionX, directionY, directionZ);
|
|
189
|
+
|
|
190
|
+
return r;
|
|
186
191
|
}
|
|
187
192
|
|
|
188
193
|
getVertexNormal(index, result) {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import Engine from "../../../Engine";
|
|
2
2
|
import {System} from "../../../ecs/System";
|
|
3
3
|
import {PathDisplay} from "./PathDisplay";
|
|
4
|
+
import Signal from "../../../../core/events/signal/Signal";
|
|
4
5
|
|
|
5
6
|
export class PathDisplaySystem extends System<PathDisplay> {
|
|
6
7
|
constructor(engine: Engine)
|
|
8
|
+
|
|
9
|
+
readonly onWorkDone: Signal<void>
|
|
7
10
|
}
|
|
@@ -12,6 +12,7 @@ import { PathEvents } from "../../../navigation/ecs/components/PathEvents.js";
|
|
|
12
12
|
import { assert } from "../../../../core/assert.js";
|
|
13
13
|
import { TubePathBuilder } from "./tube/build/TubePathBuilder.js";
|
|
14
14
|
import { Deque } from "../../../../core/collection/queue/Deque.js";
|
|
15
|
+
import Signal from "../../../../core/events/signal/Signal.js";
|
|
15
16
|
|
|
16
17
|
const builders = {
|
|
17
18
|
[PathDisplayType.None]: function (style, path, result) {
|
|
@@ -274,6 +275,12 @@ export class PathDisplaySystem extends AbstractContextSystem {
|
|
|
274
275
|
* @private
|
|
275
276
|
*/
|
|
276
277
|
this.__rebuild_queue = new Deque();
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
*
|
|
281
|
+
* @type {Signal}
|
|
282
|
+
*/
|
|
283
|
+
this.onWorkDone = new Signal();
|
|
277
284
|
}
|
|
278
285
|
|
|
279
286
|
/**
|
|
@@ -340,5 +347,8 @@ export class PathDisplaySystem extends AbstractContextSystem {
|
|
|
340
347
|
ctx.rebuild();
|
|
341
348
|
|
|
342
349
|
} while ((performance.now() - t0) < UPDATE_PROCESSING_BUDGET_MS && !queue.isEmpty());
|
|
350
|
+
|
|
351
|
+
// notify that some work was done
|
|
352
|
+
this.onWorkDone.send0();
|
|
343
353
|
}
|
|
344
354
|
}
|
|
@@ -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.17",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|