@woosh/meep-engine 2.70.0 → 2.72.0

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.
Files changed (51) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +111 -122
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +111 -122
  5. package/package.json +1 -1
  6. package/src/core/collection/array/array_get_index_in_range.js +1 -1
  7. package/src/core/collection/array/array_swap.js +2 -2
  8. package/src/core/geom/3d/quaternion/quat_encode_to_uint32.js +2 -3
  9. package/src/core/geom/3d/v3_compute_triangle_normal.js +7 -1
  10. package/src/core/geom/vec3/v3_normalize_array.js +27 -0
  11. package/src/core/math/remap.js +5 -1
  12. package/src/core/math/statistics/computeStatisticalPartialMedian.js +1 -1
  13. package/src/core/process/task/Task.js +53 -34
  14. package/src/engine/achievements/AchievementManager.js +19 -19
  15. package/src/engine/animation/curve/compression/prototypeCurveCompression.js +6 -6
  16. package/src/engine/animation/curve/draw/build_plot_entity_from_array.js +11 -6
  17. package/src/engine/ecs/dynamic_actions/DynamicActor.js +5 -10
  18. package/src/engine/ecs/dynamic_actions/DynamicActorSystem.js +82 -89
  19. package/src/engine/ecs/dynamic_actions/RuleExecution.js +10 -12
  20. package/src/engine/ecs/gui/GUIElement.js +44 -61
  21. package/src/engine/ecs/gui/GUIElementSystem.js +26 -24
  22. package/src/engine/ecs/gui/hud/HeadsUpDisplay.js +12 -15
  23. package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +15 -15
  24. package/src/engine/ecs/gui/parallax/GuiElementParallax.js +3 -3
  25. package/src/engine/ecs/gui/parallax/GuiElementParallaxSystem.js +2 -2
  26. package/src/engine/ecs/gui/position/ViewportPosition.js +5 -50
  27. package/src/engine/ecs/gui/position/ViewportPositionSerializationAdapter.js +42 -0
  28. package/src/engine/ecs/terrain/BufferedGeometryArraysBuilder.js +2 -2
  29. package/src/engine/ecs/transform/TransformSerializationAdapter.js +5 -10
  30. package/src/engine/graphics/geometry/buffered/ComputeNormals.js +11 -26
  31. package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +20 -20
  32. package/src/engine/graphics/texture/sprite/prototypeSpriteCutoutGeometry.js +12 -12
  33. package/src/engine/graphics/texture/virtual/v2/NOTES.md +17 -0
  34. package/src/engine/graphics/texture/virtual/v2/ShaderUsage.js +49 -26
  35. package/src/engine/graphics/texture/virtual/v2/UsageDebugView.js +51 -0
  36. package/src/engine/graphics/texture/virtual/v2/UsageMetadata.js +221 -0
  37. package/src/engine/graphics/texture/virtual/v2/UsagePyramidDebugView.js +239 -0
  38. package/src/engine/graphics/texture/virtual/v2/VirtualTextureManager.js +248 -0
  39. package/src/engine/graphics/texture/virtual/v2/prototype.js +104 -31
  40. package/src/engine/navigation/ecs/components/PathSerializationAdapter.js +1 -4
  41. package/src/core/binary/ValidatingBitSetWrapper.js +0 -81
  42. package/src/core/binary/jsonToStringToByteArray.js +0 -27
  43. package/src/core/geom/2d/quad-tree/PointQuadTree.js +0 -478
  44. package/src/core/math/random/makeRangedRandom.js +0 -19
  45. package/src/engine/ecs/components/AreaOfEffect.js +0 -12
  46. package/src/engine/ecs/components/Mortality.js +0 -27
  47. package/src/engine/ecs/systems/AreaOfEffectSystem.js +0 -48
  48. package/src/engine/ecs/terrain/TerrainGeometryBuilder.js +0 -152
  49. package/src/engine/ecs/terrain/ecs/PromiseSamplerHeight.js +0 -66
  50. package/src/engine/ecs/terrain/ecs/TerrainClassifier.js +0 -125
  51. package/src/engine/graphics/texture/sampler/SampleTraverser.js +0 -165
@@ -1,478 +0,0 @@
1
- /**
2
- * Created by Alex on 31/10/2014.
3
- */
4
-
5
-
6
- import { assert } from "../../../assert.js";
7
-
8
- const maxElements = 12;
9
- const minElements = 1;
10
-
11
- /**
12
- *
13
- * @param {*} obj
14
- * @param {number} x
15
- * @param {number} y
16
- * @constructor
17
- */
18
- const Element = function (obj, x, y) {
19
- /**
20
- *
21
- * @type {number}
22
- */
23
- this.x = x;
24
- /**
25
- *
26
- * @type {number}
27
- */
28
- this.y = y;
29
-
30
- this.value = obj;
31
-
32
- /**
33
- *
34
- * @type {PointQuadTree|null}
35
- */
36
- this.parentNode = null;
37
- };
38
-
39
- /**
40
- *
41
- * @param {number} x
42
- * @param {number} y
43
- */
44
- Element.prototype.move = function (x, y) {
45
- this.x = x;
46
- this.y = y;
47
- //check if new position is outside of the parent node
48
- const parentNode = this.parentNode;
49
- let node = parentNode;
50
- while (x <= node.x0 || x > node.x1 || y <= node.y0 || y > node.y1) {
51
- if (node.parentNode === null) {
52
- //root
53
- node.resizeToFit(x, y);
54
- break;
55
- }
56
- //outside of the node
57
- node = node.parentNode;
58
- }
59
- //found containing node
60
- if (node === parentNode) {
61
- //still inside the parent node
62
- return;
63
- }
64
- parentNode.removeElement(this);
65
- node.insertElement(this);
66
- };
67
-
68
- Element.prototype.remove = function () {
69
- assert.notEqual(this.parentNode, null, 'parentNode is null');
70
-
71
- this.parentNode.removeElement(this);
72
- };
73
-
74
- /**
75
- * Prefer to use {@link QuadTreeNode} instead as that is more robust and has better performance
76
- */
77
- class PointQuadTree {
78
- /**
79
- * @param {number} [x0]
80
- * @param {number} [y0]
81
- * @param {number} [x1]
82
- * @param {number} [y1]
83
- * @constructor
84
- */
85
- constructor(x0 = 0, y0 = 0, x1 = 0, y1 = 0) {
86
- //
87
- this.x0 = x0;
88
- this.y0 = y0;
89
- this.x1 = x1;
90
- this.y1 = y1;
91
-
92
- this.parentNode = null;
93
-
94
- this.setHalfSize(this.x0, this.y0, this.x1, this.y1);
95
-
96
-
97
- this.elements = [];
98
- this.numElements = 0;
99
-
100
- this.tl = void 0;
101
- this.tr = void 0;
102
- this.bl = void 0;
103
- this.br = void 0;
104
- }
105
-
106
- reduce() {
107
- if (this.isLeaf()) {
108
- //leaf
109
- this.bubbleElementsUp();
110
- } else {
111
- const tl = this.tl;
112
- const tr = this.tr;
113
- const bl = this.bl;
114
- const br = this.br;
115
- tl.reduce();
116
- tr.reduce();
117
- bl.reduce();
118
- br.reduce();
119
- //
120
- if (tl.isLeaf() && tr.isLeaf() && bl.isLeaf() && br.isLeaf()
121
- && tl.numElements === 0 && tr.numElements === 0 && bl.numElements === 0 && br.numElements === 0) {
122
- this.tl = void 0;
123
- this.tr = void 0;
124
- this.bl = void 0;
125
- this.br = void 0;
126
- }
127
- }
128
- }
129
-
130
- insertElement(element) {
131
- if (this.numElements < maxElements) {
132
-
133
- this.numElements++;
134
- this.elements.push(element);
135
- element.parentNode = this;
136
-
137
- } else {
138
-
139
- //check for split
140
- if (this.tl === void 0) {
141
- this.split();
142
- }
143
-
144
- //find suitable child to take element
145
- const x = element.x;
146
- const y = element.y;
147
-
148
- if (x < this.hx) {
149
- if (y < this.hy) {
150
- this.tl.insertElement(element);
151
- } else {
152
- this.bl.insertElement(element);
153
- }
154
- } else {
155
- if (y < this.hy) {
156
- this.tr.insertElement(element);
157
- } else {
158
- this.br.insertElement(element);
159
- }
160
- }
161
- }
162
- }
163
-
164
- clear() {
165
- this.elemenets = [];
166
-
167
- this.tl = undefined;
168
- this.tr = undefined;
169
- this.bl = undefined;
170
- this.br = undefined;
171
- }
172
-
173
- /**
174
- *
175
- * @param {T} p
176
- * @param {number} x
177
- * @param {number} y
178
- * @return {Element}
179
- */
180
- insert(p, x, y) {
181
- assert.isNumber(x, 'x');
182
- assert.isNumber(y, 'y');
183
-
184
- const element = new Element(p, x, y);
185
-
186
- this.resizeToFit(x, y); //adjust size if needed
187
-
188
- this.insertElement(element);
189
-
190
- return element;
191
- }
192
-
193
- traversePreOrder(visitor) {
194
- const keepGoing = visitor(this);
195
- if (keepGoing !== false && this.tl !== void 0) {
196
- this.tl.traversePreOrder(visitor);
197
- this.tr.traversePreOrder(visitor);
198
- this.bl.traversePreOrder(visitor);
199
- this.br.traversePreOrder(visitor);
200
- }
201
- }
202
-
203
- absorbElement(element) {
204
- this.elements.push(element);
205
- this.numElements++;
206
- }
207
-
208
- resizeToFit(x, y) {
209
- let _x0 = this.x0,
210
- _y0 = this.y0,
211
- _x1 = this.x1,
212
- _y1 = this.y1;
213
-
214
- if (x < _x0) {
215
- _x0 = x;
216
- } else if (x > _x1) {
217
- _x1 = x;
218
- }
219
-
220
- if (y < _y0) {
221
- _y0 = y;
222
- } else if (y > _y1) {
223
- _y1 = y;
224
- }
225
-
226
- if (this.x0 !== _x0 || this.y0 !== _y0 || this.x1 !== _x1 || this.y1 !== _y1) {
227
- this.resize(_x0, _y0, _x1, _y1);
228
- }
229
-
230
- }
231
-
232
- isLeaf() {
233
- return this.tl === void 0;
234
- }
235
-
236
- setHalfSize(x0, y0, x1, y1) {
237
- this.hx = (x1 + x0) / 2;
238
- this.hy = (y1 + y0) / 2;
239
- }
240
-
241
- traverseRect(_x0, _y0, _x1, _y1, visitor) {
242
- //check elements
243
- for (let i = 0; i < this.numElements; i++) {
244
- const element = this.elements[i];
245
- const x = element.x;
246
- const y = element.y;
247
- if (x > _x0 && x < _x1 && y > _y0 && y < _y1) {
248
- visitor(element);
249
- }
250
- }
251
- if (!this.isLeaf()) {
252
- //if we have children - check them
253
- if (_x0 <= this.hx) {
254
- if (_y0 <= this.hy) {
255
- this.tl.traverseRect(_x0, _y0, _x1, _y1, visitor);
256
- }
257
- if (_y1 >= this.hy) {
258
- this.bl.traverseRect(_x0, _y0, _x1, _y1, visitor);
259
- }
260
- }
261
- if (_x1 >= this.hx) {
262
- if (_y0 <= this.hy) {
263
- this.tr.traverseRect(_x0, _y0, _x1, _y1, visitor);
264
- }
265
- if (_y1 >= this.hy) {
266
- this.br.traverseRect(_x0, _y0, _x1, _y1, visitor);
267
- }
268
- }
269
- }
270
- }
271
-
272
- traverse(visitor, thisArg) {
273
- this.elements.forEach(visitor, thisArg);
274
- if (this.tl !== void 0) {
275
- this.tl.traverse(visitor, thisArg);
276
- this.tr.traverse(visitor, thisArg);
277
- this.bl.traverse(visitor, thisArg);
278
- this.br.traverse(visitor, thisArg);
279
- }
280
- }
281
-
282
- traverseCircle(cX, cY, r, visitor) {
283
- this.traverseCircleSqr(cX, cY, r, r * r, visitor);
284
- }
285
-
286
- split() {
287
- //generate children
288
- const hx = this.hx;
289
- const hy = this.hy;
290
-
291
- this.tl = new PointQuadTree(this.x0, this.y0, hx, hy);
292
- this.tr = new PointQuadTree(hx, this.y0, this.x1, hy);
293
- this.bl = new PointQuadTree(this.x0, hy, hx, this.y1);
294
- this.br = new PointQuadTree(hx, hy, this.x1, this.y1);
295
-
296
- //set parent node
297
- this.tl.parentNode = this;
298
- this.tr.parentNode = this;
299
- this.bl.parentNode = this;
300
- this.br.parentNode = this;
301
- }
302
-
303
- merge() {
304
- //check if split at all
305
- if (this.isLeaf()) {
306
- return; //not split
307
- }
308
-
309
-
310
- //merge children
311
- this.tl.traverse(this.absorbElement, this);
312
- this.tr.traverse(this.absorbElement, this);
313
- this.bl.traverse(this.absorbElement, this);
314
- this.br.traverse(this.absorbElement, this);
315
- //
316
- this.tl = void 0;
317
- this.tr = void 0;
318
- this.bl = void 0;
319
- this.br = void 0;
320
- }
321
-
322
- validateNode() {
323
- if (this.hx !== (this.x0 + this.x1) / 2) {
324
- return false;
325
- }
326
- if (this.hy !== (this.y0 + this.y1) / 2) {
327
- return false;
328
- }
329
- if (!this.isLeaf()) {
330
- if (this.tl.parentNode !== this
331
- || this.tr.parentNode !== this
332
- || this.bl.parentNode !== this
333
- || this.br.parentNode !== this) {
334
- return false;
335
- }
336
- if (this.tl.x0 !== this.x0 || this.tl.x1 !== this.hx || this.tl.y0 !== this.y0 || this.tl.y1 !== this.hy) {
337
- return false;
338
- }
339
- if (this.tr.x0 !== this.hx || this.tr.x1 !== this.x1 || this.tr.y0 !== this.y0 || this.tr.y1 !== this.hy) {
340
- return false;
341
- }
342
- if (this.bl.x0 !== this.x0 || this.bl.x1 !== this.hx || this.bl.y0 !== this.hy || this.bl.y1 !== this.y1) {
343
- return false;
344
- }
345
- if (this.br.x0 !== this.hx || this.br.x1 !== this.x1 || this.br.y0 !== this.hy || this.br.y1 !== this.y1) {
346
- return false;
347
- }
348
- } else if (this.elements !== void 0) {
349
-
350
- //check containment of elements
351
- for (let i = 0; i < this.elements.length; i++) {
352
- const e = this.elements[i];
353
- if (e.x < this.x0 || e.x > this.x1 || e.y < this.y0 || e.y > this.y1) {
354
- return false;
355
- }
356
- }
357
-
358
- }
359
- return true;
360
- }
361
-
362
- traverseCircleSqr(cX, cY, r, r2, visitor) {
363
- for (let i = 0; i < this.numElements; i++) {
364
- const element = this.elements[i];
365
- const x = element.x;
366
- const y = element.y;
367
- const dx = cX - x;
368
- const dy = cY - y;
369
- const d2 = dx * dx + dy * dy;
370
- if (d2 < r2) {
371
- visitor(element);
372
- }
373
- }
374
-
375
- if (cX - r < this.hx) {
376
- if (cY - r < this.hy) {
377
- this.tl.traverseCircleSqr(cX, cY, r, r2, visitor);
378
- }
379
- if (cY + r >= this.hy) {
380
- this.bl.traverseCircleSqr(cX, cY, r, r2, visitor);
381
- }
382
- }
383
- if (cX + r >= this.hx) {
384
- if (cY - r < this.hy) {
385
- this.tr.traverseCircleSqr(cX, cY, r, r2, visitor);
386
- }
387
- if (cY + r >= this.hy) {
388
- this.br.traverseCircleSqr(cX, cY, r, r2, visitor);
389
- }
390
- }
391
- }
392
-
393
- resize(_x0, _y0, _x1, _y1) {
394
- const parentNode = this.parentNode;
395
- if (parentNode !== null) {
396
- const w = _x1 - _x0;
397
- const h = _y1 - _y0;
398
- if (this === parentNode.tl) {
399
- parentNode.resize(_x0, _y0, _x1 + w, _y1 + h);
400
- } else if (this === parentNode.tr) {
401
- parentNode.resize(_x0 - w, _y0, _x1, _y1 + h);
402
- } else if (this === parentNode.bl) {
403
- parentNode.resize(_x0, _y0 - h, _x1 + w, _y1);
404
- } else if (this === parentNode.br) {
405
- parentNode.resize(_x0 - w, _y0 - h, _x1, _y1);
406
- } else {
407
- throw new Error("Specified 'parent' does not own this node");
408
- }
409
- return;
410
- }
411
- this.x0 = this.x0 = _x0;
412
- this.y0 = this.y0 = _y0;
413
- this.x1 = this.x1 = _x1;
414
- this.y1 = this.y1 = _y1;
415
-
416
- this.setHalfSize(_x0, _y0, _x1, _y1);
417
-
418
- this.merge();
419
- //reinsert all elements
420
- const l = this.numElements;
421
- const els = this.elements;
422
- this.elements = [];
423
- this.numElements = 0;
424
- for (let i = 0; i < l; i++) {
425
- this.insertElement(els[i]);
426
- }
427
- }
428
-
429
- removeElement(e) {
430
-
431
- const i = this.elements.indexOf(e);
432
-
433
- this.elements.splice(i, 1);
434
-
435
- // reset parent
436
- e.parentNode = null;
437
-
438
- this.numElements--;
439
-
440
- if (this.numElements < minElements) {
441
- // number of elements in the current bucket is too small, attempt reduction
442
- this.reduce();
443
- }
444
-
445
- }
446
-
447
- bubbleElementsUp() {
448
- let targetNode = this;
449
- while (this.numElements > 0 && targetNode.parentNode !== null) {
450
- targetNode = targetNode.parentNode;
451
- const parentElements = targetNode.numElements;
452
- const capacityLeft = maxElements - parentElements;
453
- if (capacityLeft > 0) {
454
- const transferNumber = Math.min(capacityLeft, this.numElements);
455
- for (let i = this.numElements - transferNumber; i < this.numElements; i++) {
456
- const element = this.elements[i];
457
- targetNode.insertElement(element);
458
- }
459
- this.numElements -= transferNumber;
460
- }
461
- }
462
- this.elements.length = this.numElements;
463
- }
464
-
465
- validate() {
466
- let v = true;
467
- this.traversePreOrder(function (node) {
468
- let isValid = node.validateNode();
469
- if (!isValid && v !== false) {
470
- v = false;
471
- }
472
- return isValid;
473
- });
474
- return v;
475
- }
476
- }
477
-
478
- export default PointQuadTree;
@@ -1,19 +0,0 @@
1
- /**
2
- *
3
- * @param {function():number} random returns a number between 0 and 1
4
- * @param {number} min
5
- * @param {number} max
6
- * @returns {function():number} returns number between min and max
7
- */
8
- export function makeRangedRandom(random, min, max) {
9
-
10
- if (min === 0 && max === 1) {
11
- //input already returns values in correct range
12
- return random;
13
- }
14
-
15
- const scale = max - min;
16
- return function () {
17
- return random() * scale + min;
18
- };
19
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Created by Alex on 11/08/2014.
3
- */
4
-
5
-
6
- function AreaOfEffect(options) {
7
- this.tags = options.tags.slice();
8
- this.radius = options.radius || new THREE.Vector3(1, 1, 1);
9
- this.action = options.action || void 0;
10
- }
11
-
12
- export default AreaOfEffect;
@@ -1,27 +0,0 @@
1
- /**
2
- * User: Alex Goldring
3
- * Date: 17/6/2014
4
- * Time: 21:26
5
- */
6
-
7
-
8
- /**
9
- * @deprecated entirely superseded by the {@link BehaviorSystem}
10
- * @param actions
11
- * @constructor
12
- */
13
- function Mortality(actions) {
14
- if (actions === void 0) {
15
- actions = []
16
- } else if (typeof actions === "function") {
17
- actions = [actions];
18
- }
19
- this.actions = actions;
20
- }
21
-
22
- Mortality.typeName = "Mortality";
23
-
24
- Mortality.serializable = false;
25
-
26
- export default Mortality;
27
-
@@ -1,48 +0,0 @@
1
- /**
2
- * Created by Alex on 11/08/2014.
3
- */
4
- import { System } from '../System.js';
5
- import Tag from '../components/Tag.js';
6
- import { Transform } from '../transform/Transform.js';
7
- import AreaOfEffect from '../components/AreaOfEffect.js';
8
-
9
-
10
- class AreaOfEffectSystem extends System {
11
- constructor() {
12
- super();
13
-
14
- this.dependencies = [AreaOfEffect];
15
- }
16
-
17
- add(component, entity) {
18
- }
19
-
20
- remove(component) {
21
- }
22
-
23
- update(timeDelta) {
24
- const entityManager = this.entityManager;
25
- entityManager.traverseEntities([AreaOfEffect, Transform], function (aoe, transform) {
26
- const position = transform.position;
27
- const tags = aoe.tags;
28
- const radius = aoe.radius;
29
- entityManager.traverseEntities([Tag, Transform], function (tag, transform2, entity) {
30
- if (tags.indexOf(tag.name) === -1) {
31
- return; //not a tag we care about
32
- }
33
- const position2 = transform2.position;
34
- //check range, doing one component at a time makes evaluation lazy, giving us a bit of speed
35
- if (
36
- Math.abs(position2.x - position.x) < radius.x
37
- && Math.abs(position2.y - position.y) < radius.y
38
- && Math.abs(position2.z - position.z) < radius.z
39
- ) {
40
- //within box
41
- aoe.action(entityManager, timeDelta, entity);
42
- }
43
- })
44
- });
45
- }
46
- }
47
-
48
- export default AreaOfEffectSystem;