@woosh/meep-engine 2.81.2 → 2.81.4

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/build/meep.cjs CHANGED
@@ -75559,6 +75559,7 @@ function planeHash(plane) {
75559
75559
  * @template T
75560
75560
  * @param {T[]} array
75561
75561
  * @param {function(T):number} elementHashFunction
75562
+ * @returns {number}
75562
75563
  */
75563
75564
  function computeHashArray(array, elementHashFunction) {
75564
75565
 
@@ -75557,6 +75557,7 @@ function planeHash(plane) {
75557
75557
  * @template T
75558
75558
  * @param {T[]} array
75559
75559
  * @param {function(T):number} elementHashFunction
75560
+ * @returns {number}
75560
75561
  */
75561
75562
  function computeHashArray(array, elementHashFunction) {
75562
75563
 
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.81.2",
8
+ "version": "2.81.4",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,9 +1,14 @@
1
+ import { assert } from "../../assert.js";
2
+
1
3
  /**
2
4
  * @template T
3
5
  * @param {T[]} array
4
6
  * @param {function(T):number} elementHashFunction
7
+ * @returns {number}
5
8
  */
6
9
  export function computeHashArray(array, elementHashFunction) {
10
+ assert.isArrayLike(array, 'array');
11
+ assert.isFunction(elementHashFunction, 'elementHashFunction');
7
12
 
8
13
  const numArguments = array.length;
9
14
  let hash = numArguments;
@@ -13,41 +13,43 @@ import { computeHashArray } from "../array/computeHashArray.js";
13
13
  import { isArrayEqualStrict } from "../array/isArrayEqualStrict.js";
14
14
 
15
15
  /**
16
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
16
17
  * @readonly
17
18
  * @enum {string}
18
19
  */
19
20
  export const DataType2DataViewReaders = {
20
- "uint8": "getUint8",
21
- "uint16": "getUint16",
22
- "uint32": "getUint32",
23
- "uint64": "getUint64",
24
-
25
- "int8": "getInt8",
26
- "int16": "getInt16",
27
- "int32": "getInt32",
28
- "int64": "getInt64",
29
-
30
- "float32": "getFloat32",
31
- "float64": "getFloat64"
21
+ [BinaryDataType.Uint8]: "getUint8",
22
+ [BinaryDataType.Uint16]: "getUint16",
23
+ [BinaryDataType.Uint32]: "getUint32",
24
+ [BinaryDataType.Uint64]: "getUint64",
25
+
26
+ [BinaryDataType.Int8]: "getInt8",
27
+ [BinaryDataType.Int16]: "getInt16",
28
+ [BinaryDataType.Int32]: "getInt32",
29
+ [BinaryDataType.Int64]: "getInt64",
30
+
31
+ [BinaryDataType.Float32]: "getFloat32",
32
+ [BinaryDataType.Float64]: "getFloat64"
32
33
  };
33
34
 
34
35
  /**
36
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
35
37
  * @readonly
36
38
  * @enum {string}
37
39
  */
38
40
  export const DataType2DataViewWriters = {
39
- "uint8": "setUint8",
40
- "uint16": "setUint16",
41
- "uint32": "setUint32",
42
- "uint64": "setUint64",
43
-
44
- "int8": "setInt8",
45
- "int16": "setInt16",
46
- "int32": "setInt32",
47
- "int64": "setInt64",
48
-
49
- "float32": "setFloat32",
50
- "float64": "setFloat64"
41
+ [BinaryDataType.Uint8]: "setUint8",
42
+ [BinaryDataType.Uint16]: "setUint16",
43
+ [BinaryDataType.Uint32]: "setUint32",
44
+ [BinaryDataType.Uint64]: "setUint64",
45
+
46
+ [BinaryDataType.Int8]: "setInt8",
47
+ [BinaryDataType.Int16]: "setInt16",
48
+ [BinaryDataType.Int32]: "setInt32",
49
+ [BinaryDataType.Int64]: "setInt64",
50
+
51
+ [BinaryDataType.Float32]: "setFloat32",
52
+ [BinaryDataType.Float64]: "setFloat64"
51
53
  };
52
54
 
53
55
  /**
@@ -67,10 +69,14 @@ function genRowReader(types, endianType = EndianType.BigEndian) {
67
69
 
68
70
  const type = types[i];
69
71
 
72
+ const reader_name = DataType2DataViewReaders[type];
73
+
74
+ assert.isString(reader_name, 'reader_name');
75
+
70
76
  const littleEndianFlag = endianType === EndianType.BigEndian ? 'false' : 'true';
71
77
 
72
78
  // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
73
- lines.push(`result[${i}] = dataView.${DataType2DataViewReaders[type]}(${offset} + byteOffset, ${littleEndianFlag});`);
79
+ lines.push(`result[${i}] = dataView.${reader_name}(${offset} + byteOffset, ${littleEndianFlag});`);
74
80
 
75
81
  offset += DataTypeByteSizes[type];
76
82
 
@@ -100,10 +106,14 @@ function genRowWriter(types, endianType = EndianType.BigEndian) {
100
106
  for (let i = 0; i < numTypes; i++) {
101
107
  const type = types[i];
102
108
 
109
+ const writer_name = DataType2DataViewWriters[type];
110
+
111
+ assert.isString(writer_name, 'writer_name');
112
+
103
113
  const littleEndianFlag = endianType === EndianType.BigEndian ? 'false' : 'true';
104
114
 
105
115
  // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
106
- lines.push(`dataView.${DataType2DataViewWriters[type]}(${offset} + byteOffset, record[${i}], ${littleEndianFlag});`);
116
+ lines.push(`dataView.${writer_name}(${offset} + byteOffset, record[${i}], ${littleEndianFlag});`);
107
117
 
108
118
  offset += DataTypeByteSizes[type];
109
119
  }
@@ -267,7 +277,7 @@ export class RowFirstTableSpec {
267
277
  }
268
278
 
269
279
  /**
270
- *
280
+ * Produces an immutable spec, either creates a new spec or retrieves a cached version
271
281
  * @param {BinaryDataType[]} types
272
282
  * @param {EndianType} [endianType]
273
283
  * @returns {RowFirstTableSpec}
@@ -276,21 +286,25 @@ export class RowFirstTableSpec {
276
286
  //compute hash
277
287
  const hash = types.join('.') + ':' + endianType;
278
288
 
279
- const cachedValue = cache.get(hash);
289
+ const cachedValue = SPEC_CACHE.get(hash);
280
290
 
281
291
  if (cachedValue !== null) {
282
292
  return cachedValue;
283
293
  }
284
294
 
285
295
  const newValue = new RowFirstTableSpec(types);
286
- cache.put(hash, newValue);
296
+ SPEC_CACHE.put(hash, newValue);
287
297
 
288
298
  return newValue;
289
299
  }
290
300
  }
291
301
 
292
302
 
293
- const cache = new Cache({
303
+ /**
304
+ * @readonly
305
+ * @type {Cache<string,RowFirstTableSpec>}
306
+ */
307
+ const SPEC_CACHE = new Cache({
294
308
  keyHashFunction: computeStringHash
295
309
  });
296
310
 
@@ -1,4 +1,3 @@
1
- import { vec3 } from "gl-matrix";
2
1
  import { v3_compute_triangle_normal } from "./v3_compute_triangle_normal.js";
3
2
 
4
3
  /**
@@ -1,15 +1,16 @@
1
- import { StaticMaterialCache } from "../../../../asset/loaders/material/StaticMaterialCache.js";
1
+ import { Group, Matrix4, Mesh } from "three";
2
+ import { mergeBufferGeometries } from "three/examples/jsm/utils/BufferGeometryUtils.js";
3
+ import { array_copy } from "../../../../../core/collection/array/array_copy.js";
2
4
  import { HashMap } from "../../../../../core/collection/map/HashMap.js";
5
+ import { m4_multiply } from "../../../../../core/geom/3d/mat4/m4_multiply.js";
6
+ import { MATRIX_4_IDENTITY } from "../../../../../core/geom/3d/mat4/MATRIX_4_IDENTITY.js";
7
+ import { StaticMaterialCache } from "../../../../asset/loaders/material/StaticMaterialCache.js";
3
8
  import { computeGeometryEquality } from "../../buffered/computeGeometryEquality.js";
4
9
  import { computeGeometryHash } from "../../buffered/computeGeometryHash.js";
5
- import { array_copy } from "../../../../../core/collection/array/array_copy.js";
6
- import { mat4 } from "gl-matrix";
7
- import { Group, Matrix4, Mesh } from "three";
8
- import { mergeBufferGeometries } from "three/examples/jsm/utils/BufferGeometryUtils.js";
9
10
 
10
11
  class GeometryContext {
11
12
  constructor() {
12
- this.matrix = new Float32Array(16);
13
+ this.matrix = new Float32Array(MATRIX_4_IDENTITY);
13
14
  this.material = null;
14
15
  this.geometry = null;
15
16
  }
@@ -51,12 +52,12 @@ function compute_transform_matrix(object, ancestor_root, result) {
51
52
  //
52
53
  path.reverse();
53
54
 
54
- mat4.identity(result);
55
+ result.set(MATRIX_4_IDENTITY);
55
56
 
56
57
  for (let i = 0; i < path.length; i++) {
57
58
  const el = path[i];
58
59
 
59
- mat4.multiply(result, result, el.matrix.elements);
60
+ m4_multiply(result, result, el.matrix.elements);
60
61
  }
61
62
 
62
63
  }
@@ -132,7 +133,6 @@ function merge_contexts(contexts) {
132
133
 
133
134
  const merged_context = new GeometryContext();
134
135
 
135
- mat4.identity(merged_context.matrix);
136
136
  merged_context.geometry = merged;
137
137
  merged_context.material = contexts[0].material;
138
138