@woosh/meep-engine 2.62.0 → 2.63.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.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.62.0",
8
+ "version": "2.63.0",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,58 +1,22 @@
1
+ import { BiMap } from "../collection/map/BiMap.js";
1
2
  import { BinaryBuffer } from "./BinaryBuffer.js";
2
3
 
3
- class Dictionary {
4
- constructor() {
5
- this.forward = new Map();
6
- this.backward = new Map();
7
- }
8
-
9
- /**
10
- *
11
- * @param {*} value
12
- * @param {number} address
13
- */
14
- add(value, address) {
15
- this.forward.set(address, value);
16
- this.backward.set(value, address);
17
- }
18
-
19
- /**
20
- *
21
- * @param {*} value
22
- * @returns {number|undefined}
23
- */
24
- getAddress(value) {
25
- return this.backward.get(value);
26
- }
27
-
28
- /**
29
- *
30
- * @param {number} address
31
- * @returns {*}
32
- */
33
- getValue(address) {
34
- return this.forward.get(address);
35
- }
36
- }
4
+ export class EncodingBinaryBuffer extends BinaryBuffer {
37
5
 
6
+ __dictionary = new BiMap();
38
7
 
39
- export class EncodingBinaryBuffer extends BinaryBuffer {
40
- constructor() {
41
- super();
42
- this.__dictionary = new Dictionary();
43
- }
44
8
 
45
9
  writeUTF8String(value) {
46
- const address = this.__dictionary.getAddress(value);
10
+ const address = this.__dictionary.getKeyByValue(value);
47
11
 
48
12
  if (address === undefined) {
49
13
  this.writeUint8(0); //mark as complete value
50
14
 
51
- const address1 = this.position;
15
+ const current_address = this.position;
52
16
 
53
17
  super.writeUTF8String(value);
54
18
 
55
- this.__dictionary.add(value, address1);
19
+ this.__dictionary.add(value, current_address);
56
20
  } else {
57
21
  //write as reference
58
22
  this.writeUint32LE(1 | (address << 1));
@@ -72,7 +36,7 @@ export class EncodingBinaryBuffer extends BinaryBuffer {
72
36
 
73
37
  const address = header >> 1;
74
38
 
75
- let value = this.__dictionary.getValue(address);
39
+ let value = this.__dictionary.getValueByKey(address);
76
40
 
77
41
  if (value === undefined) {
78
42
  //remember position
@@ -0,0 +1,16 @@
1
+ import { EncodingBinaryBuffer } from "./EncodingBinaryBuffer.js";
2
+
3
+ test("read/write strings", () => {
4
+
5
+ const buffer = new EncodingBinaryBuffer();
6
+
7
+ buffer.writeUTF8String("hello world");
8
+ buffer.writeUTF8String("cat");
9
+ buffer.writeUTF8String("hello world");
10
+
11
+ buffer.position = 0;
12
+
13
+ expect(buffer.readUTF8String()).toEqual("hello world");
14
+ expect(buffer.readUTF8String()).toEqual("cat");
15
+ expect(buffer.readUTF8String()).toEqual("hello world");
16
+ });
@@ -50,8 +50,10 @@ export class EBBVHLeafProxy {
50
50
  unlink() {
51
51
  assert.equal(this.is_linked, true, 'not linked');
52
52
 
53
- this.#tree.remove_leaf(this.#node_id);
54
- this.#tree.release_node(this.#node_id);
53
+ const node_id = this.#node_id;
54
+
55
+ this.#tree.remove_leaf(node_id);
56
+ this.#tree.release_node(node_id);
55
57
 
56
58
  this.#node_id = -1;
57
59
  this.#tree = null;
@@ -1,7 +1,8 @@
1
1
  //
2
2
 
3
- import { Cache } from "./Cache.js";
3
+ import { assert } from "../assert.js";
4
4
  import { current_time_in_seconds } from "../time/current_time_in_seconds.js";
5
+ import { Cache } from "./Cache.js";
5
6
 
6
7
  /**
7
8
  * @template R
@@ -79,6 +80,8 @@ export class LoadingCache {
79
80
  retryFailed = true
80
81
  }) {
81
82
 
83
+ assert.isFunction(load, 'load');
84
+
82
85
  this.#internal = new Cache({
83
86
  maxWeight,
84
87
  keyWeigher,
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Bi-directional map
3
+ * @template K,V
4
+ */
5
+ export class BiMap {
6
+
7
+ /**
8
+ *
9
+ * @type {Map<K, V>}
10
+ */
11
+ forward = new Map();
12
+ /**
13
+ *
14
+ * @type {Map<V, K>}
15
+ */
16
+ backward = new Map();
17
+
18
+
19
+ /**
20
+ *
21
+ * @param {K} key
22
+ * @param {V} value
23
+ */
24
+ add(key, value) {
25
+ this.forward.set(value, key);
26
+ this.backward.set(key, value);
27
+ }
28
+
29
+ /**
30
+ *
31
+ * @param {V} value
32
+ * @returns {K|undefined}
33
+ */
34
+ getKeyByValue(value) {
35
+ return this.backward.get(value);
36
+ }
37
+
38
+ /**
39
+ *
40
+ * @param {K} address
41
+ * @returns {V|undefined}
42
+ */
43
+ getValueByKey(address) {
44
+ return this.forward.get(address);
45
+ }
46
+ }
47
+
48
+ BiMap.prototype.get = BiMap.prototype.getValueByKey;
49
+ BiMap.prototype.set = BiMap.prototype.add;
@@ -17,6 +17,8 @@ export class Tag {
17
17
 
18
18
  containsOneOf(values: string[]): boolean
19
19
 
20
+ hash(): number
21
+
20
22
  equals(other: Tag): boolean
21
23
 
22
24
  static find(tags: string[], ecd: EntityComponentDataset): number[]
@@ -3,8 +3,9 @@
3
3
  */
4
4
 
5
5
 
6
- import { computeStringHash } from "../../../core/primitives/strings/computeStringHash.js";
7
6
  import { assert } from "../../../core/assert.js";
7
+ import { isArrayEqualStrict } from "../../../core/collection/array/isArrayEqualStrict.js";
8
+ import { computeStringHash } from "../../../core/primitives/strings/computeStringHash.js";
8
9
 
9
10
  /**
10
11
  * Stores textual tags, useful for marking entities
@@ -12,7 +13,7 @@ import { assert } from "../../../core/assert.js";
12
13
  export class Tag {
13
14
  /**
14
15
  * @private
15
- * @type {String[]}
16
+ * @type {string[]}
16
17
  */
17
18
  values = [];
18
19
 
@@ -194,41 +195,31 @@ export class Tag {
194
195
  * @return {boolean}
195
196
  */
196
197
  equals(other) {
197
-
198
- const s0 = this.values;
199
-
200
- const s1 = other.values;
201
-
202
- const n0 = s0.length;
203
- const n1 = s1.length;
204
-
205
- if (n0 !== n1) {
206
- //wrong length
207
- return false;
208
- }
209
-
210
- for (let i = 0; i < n0; i++) {
211
- const v0 = s0[i];
212
- const v1 = s1[i];
213
-
214
- if (v0 !== v1) {
215
- return false;
216
- }
217
- }
218
-
219
- return true;
198
+ return isArrayEqualStrict(this.values, other.values);
220
199
  }
221
200
 
222
201
  toJSON() {
223
202
  return this.values;
224
203
  }
225
204
 
205
+ /**
206
+ *
207
+ * @param {string[]|string} json
208
+ */
226
209
  fromJSON(json) {
210
+
211
+ this.clear();
212
+
227
213
  if (typeof json === "string") {
228
- this.clear();
229
214
  this.add(json);
230
- } else if (Array.isArray(json)) {
231
- this.values = json;
215
+ } else {
216
+ assert.isArray(json, 'json');
217
+
218
+ const n = json.length;
219
+
220
+ for (let i = 0; i < n; i++) {
221
+ this.add(json[i]);
222
+ }
232
223
  }
233
224
  }
234
225
 
@@ -0,0 +1,47 @@
1
+ import Tag from "./Tag.js";
2
+
3
+ test("constructor", () => {
4
+ new Tag();
5
+ });
6
+
7
+ test("containsOneOf", () => {
8
+
9
+ const tag = Tag.fromJSON(['a', 'b']);
10
+
11
+ expect(tag.containsOneOf([])).toBe(false);
12
+ expect(tag.containsOneOf(['c'])).toBe(false);
13
+ expect(tag.containsOneOf(['a'])).toBe(true);
14
+ expect(tag.containsOneOf(['b'])).toBe(true);
15
+ expect(tag.containsOneOf(['a', 'b'])).toBe(true);
16
+
17
+ });
18
+
19
+ test("hash", () => {
20
+
21
+ const tag = Tag.fromJSON(['a', 'b']);
22
+
23
+ const hash = tag.hash();
24
+
25
+ expect(tag.hash()).toEqual(hash);
26
+
27
+ expect(typeof hash).toBe("number");
28
+ expect(Number.isInteger(hash)).toBe(true);
29
+ });
30
+
31
+ test("equals", () => {
32
+
33
+
34
+ const a = Tag.fromJSON(['a', 'b']);
35
+ const b = Tag.fromJSON([]);
36
+ const c = Tag.fromJSON(['a']);
37
+ const d = Tag.fromJSON(['b']);
38
+ const e = Tag.fromJSON(['a', 'b']);
39
+ const f = Tag.fromJSON(['a', 'c']);
40
+
41
+ expect(a.equals(b)).toBe(false);
42
+ expect(a.equals(c)).toBe(false);
43
+ expect(a.equals(d)).toBe(false);
44
+ expect(a.equals(e)).toBe(true);
45
+ expect(a.equals(f)).toBe(false);
46
+
47
+ });
@@ -208,6 +208,10 @@ export class FogOfWar {
208
208
  this.textureNeedsUpdate = true;
209
209
  }
210
210
 
211
+ concealAll(){
212
+ this.clear();
213
+ }
214
+
211
215
  /**
212
216
  *
213
217
  * @param {number} x
@@ -6,6 +6,9 @@ export class FogOfWarEditor extends ObjectEditor {
6
6
  properties: {
7
7
  revealAll: {
8
8
  type: Function
9
+ },
10
+ concealAll: {
11
+ type: Function
9
12
  }
10
13
  }
11
14
  };
@@ -1,66 +1,67 @@
1
1
  import Vector2 from "../../../core/geom/Vector2.js";
2
2
 
3
- export function TerrainPreview() {
3
+ export class TerrainPreview {
4
4
  /**
5
5
  *
6
6
  * @type {String}
7
7
  */
8
- this.url = "";
8
+ url = "";
9
9
 
10
10
  /**
11
11
  *
12
12
  * @type {Vector2}
13
13
  */
14
- this.offset = new Vector2(0, 0);
14
+ offset = new Vector2(0, 0);
15
15
  /**
16
16
  *
17
17
  * @type {Vector2}
18
18
  */
19
- this.scale = new Vector2(1, 1);
20
- }
19
+ scale = new Vector2(1, 1);
20
+
21
+ /**
22
+ *
23
+ * @param {TerrainPreview} other
24
+ */
25
+ copy(other) {
26
+ this.url = other.url;
27
+ this.scale.copy(other.scale);
28
+ this.offset.copy(other.offset);
29
+ }
21
30
 
22
- /**
23
- *
24
- * @param {TerrainPreview} other
25
- */
26
- TerrainPreview.prototype.copy = function (other) {
27
- this.url = other.url;
28
- this.scale.copy(other.scale);
29
- this.offset.copy(other.offset);
30
- };
31
+ toJSON() {
32
+ return {
33
+ url: this.url,
34
+ offset: this.offset.toJSON(),
35
+ scale: this.scale.toJSON()
36
+ };
37
+ }
31
38
 
32
- TerrainPreview.prototype.toJSON = function () {
33
- return {
34
- url: this.url,
35
- offset: this.offset.toJSON(),
36
- scale: this.scale.toJSON()
37
- };
38
- };
39
+ fromJSON(obj) {
40
+ this.url = obj.url;
41
+ this.offset.fromJSON(obj.offset);
42
+ this.scale.fromJSON(obj.scale);
43
+ }
39
44
 
40
- TerrainPreview.prototype.fromJSON = function (obj) {
41
- this.url = obj.url;
42
- this.offset.fromJSON(obj.offset);
43
- this.scale.fromJSON(obj.scale);
44
- };
45
+ /**
46
+ *
47
+ * @param {BinaryBuffer} buffer
48
+ */
49
+ toBinaryBuffer(buffer) {
50
+ buffer.writeUTF8String(this.url);
45
51
 
46
- /**
47
- *
48
- * @param {BinaryBuffer} buffer
49
- */
50
- TerrainPreview.prototype.toBinaryBuffer = function (buffer) {
51
- buffer.writeUTF8String(this.url);
52
+ this.offset.toBinaryBuffer(buffer);
53
+ this.scale.toBinaryBuffer(buffer);
54
+ }
52
55
 
53
- this.offset.toBinaryBuffer(buffer);
54
- this.scale.toBinaryBuffer(buffer);
55
- };
56
+ /**
57
+ *
58
+ * @param {BinaryBuffer} buffer
59
+ */
60
+ fromBinaryBuffer(buffer) {
61
+ this.url = buffer.readUTF8String();
56
62
 
57
- /**
58
- *
59
- * @param {BinaryBuffer} buffer
60
- */
61
- TerrainPreview.prototype.fromBinaryBuffer = function (buffer) {
62
- this.url = buffer.readUTF8String();
63
+ this.offset.fromBinaryBuffer(buffer);
64
+ this.scale.fromBinaryBuffer(buffer);
65
+ }
66
+ }
63
67
 
64
- this.offset.fromBinaryBuffer(buffer);
65
- this.scale.fromBinaryBuffer(buffer);
66
- };
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Created by Alex on 13/05/2016.
3
3
  */
4
- import Vector3 from "../../../../../core/geom/Vector3.js";
5
4
  import Quaternion from "../../../../../core/geom/Quaternion.js";
5
+ import Vector3 from "../../../../../core/geom/Vector3.js";
6
6
 
7
7
  class ClingToTerrain {
8
8
  /**
@@ -13,12 +13,12 @@ class ClingToTerrain {
13
13
  * Used internally for caching updates
14
14
  * @type {Vector3}
15
15
  */
16
- __lastPosition=new Vector3(0, 0, 0);
16
+ __lastPosition = new Vector3(0, 0, 0);
17
17
  /**
18
18
  *
19
19
  * @type {Quaternion}
20
20
  */
21
- __lastRotation=new Quaternion(0, 0, 0, 1);
21
+ __lastRotation = new Quaternion(0, 0, 0, 1);
22
22
  /**
23
23
  * Speed in Rad/s (Radians/second) by which rotation can change
24
24
  * @type {number}
@@ -26,11 +26,29 @@ class ClingToTerrain {
26
26
  rotationSpeed = 3;
27
27
 
28
28
  constructor(opt) {
29
- if(opt !== undefined){
29
+ if (opt !== undefined) {
30
30
  throw new Error("constructor options deprecated");
31
31
  }
32
32
  }
33
33
 
34
+ /**
35
+ *
36
+ * @param {ClingToTerrain} other
37
+ * @returns {boolean}
38
+ */
39
+ equals(other) {
40
+ return this.normalAlign === other.normalAlign
41
+ && this.rotationSpeed === other.rotationSpeed;
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @returns {number}
47
+ */
48
+ hash() {
49
+ return this.normalAlign ? 1 : 0;
50
+ }
51
+
34
52
  toJSON() {
35
53
  return {
36
54
  normalAlign: this.normalAlign,
@@ -3,31 +3,36 @@
3
3
  */
4
4
 
5
5
 
6
+ import { mat4 } from "gl-matrix";
6
7
  import {
7
8
  Box3 as ThreeBox3,
8
9
  BufferAttribute as ThreeBufferAttribute,
9
10
  BufferGeometry as ThreeBufferGeometry,
11
+ MeshBasicMaterial,
10
12
  Sphere as ThreeSphere,
11
13
  Vector3 as ThreeVector3
12
14
  } from 'three';
13
- import Vector2 from '../../../../core/geom/Vector2.js';
14
- import Vector3 from '../../../../core/geom/Vector3.js';
15
15
 
16
- import ThreeFactory from '../../../graphics/three/ThreeFactory.js';
16
+ import IndexedBinaryBVH from '../../../../core/bvh2/binary/IndexedBinaryBVH.js';
17
17
 
18
18
 
19
19
  import { LeafNode } from '../../../../core/bvh2/LeafNode.js';
20
-
21
- import IndexedBinaryBVH from '../../../../core/bvh2/binary/IndexedBinaryBVH.js';
22
- import { BVHGeometryRaycaster } from "../../../graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js";
23
- import ObservedInteger from "../../../../core/model/ObservedInteger.js";
24
- import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
20
+ import { array_copy } from "../../../../core/collection/array/array_copy.js";
25
21
  import Signal from "../../../../core/events/signal/Signal.js";
26
- import { mat4 } from "gl-matrix";
22
+ import { passThrough } from "../../../../core/function/Functions.js";
27
23
  import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
24
+ import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
25
+ import Vector2 from '../../../../core/geom/Vector2.js';
26
+ import Vector3 from '../../../../core/geom/Vector3.js';
28
27
  import { NumericInterval } from "../../../../core/math/interval/NumericInterval.js";
29
- import { array_copy } from "../../../../core/collection/array/array_copy.js";
30
- import { passThrough } from "../../../../core/function/Functions.js";
28
+ import ObservedInteger from "../../../../core/model/ObservedInteger.js";
29
+ import { BVHGeometryRaycaster } from "../../../graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js";
30
+
31
+ import ThreeFactory from '../../../graphics/three/ThreeFactory.js';
32
+
33
+
34
+ const EMPTY_GEOMETRY = new ThreeBufferGeometry();
35
+ const DEFAULT_MATERIAL = new MeshBasicMaterial();
31
36
 
32
37
  /**
33
38
  * terrain tile is a part of a 2d array
@@ -44,7 +49,7 @@ class TerrainTile {
44
49
  * @type {Material}
45
50
  */
46
51
  material = null;
47
- mesh = ThreeFactory.createMesh();
52
+ mesh = ThreeFactory.createMesh(EMPTY_GEOMETRY, DEFAULT_MATERIAL);
48
53
 
49
54
 
50
55
  /**
@@ -5,10 +5,6 @@ import {LeafNode} from "../../../../core/bvh2/LeafNode";
5
5
  export default class Mesh {
6
6
  url: string
7
7
  mesh: Object3D
8
- /**
9
- * Managed by MeshSystem, do not change
10
- */
11
- bvh: LeafNode<Object3D>
12
8
 
13
9
  castShadow: boolean
14
10
  receiveShadow: boolean
@@ -51,12 +51,6 @@ class Mesh {
51
51
  */
52
52
  this.mesh = null;
53
53
 
54
- /**
55
- * Override Mesh data, if available. Typically set via plugins
56
- * @type {Object3D|null}
57
- */
58
- this.override_mesh = null;
59
-
60
54
  /**
61
55
  * @transient
62
56
  * @type {Asset|null}
@@ -129,11 +123,6 @@ class Mesh {
129
123
  aabb3_matrix4_project(this.__bvh_leaf.bounds, this.boundingBox, _t.matrix);
130
124
 
131
125
  this.__bvh_leaf.write_bounds();
132
-
133
- // override
134
- if (this.override_mesh !== null) {
135
- applyTransformToThreeObject(this.override_mesh, _t);
136
- }
137
126
  }
138
127
 
139
128
  /**