@woosh/meep-engine 2.118.11 → 2.118.12

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.
@@ -52062,6 +52062,8 @@ function array_buffer_copy(
52062
52062
  target, target_offset,
52063
52063
  byte_length
52064
52064
  ) {
52065
+ // assert.ok(source instanceof ArrayBuffer || source instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
52066
+ // assert.ok(target instanceof ArrayBuffer || target instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
52065
52067
 
52066
52068
  /**
52067
52069
  * @type {Uint8Array|Uint16Array|Uint32Array}
@@ -61391,10 +61393,25 @@ function typed_array_copy(source, destination) {
61391
61393
  const destination_size = destination.length;
61392
61394
 
61393
61395
  if (destination_size >= source.length) {
61396
+
61394
61397
  destination.set(source, 0);
61398
+
61399
+ } else if (source.constructor === destination.constructor) {
61400
+
61401
+ // same type
61402
+ array_buffer_copy(
61403
+ source.buffer,
61404
+ source.byteOffset,
61405
+ destination.buffer,
61406
+ destination.byteOffset,
61407
+ Math.min(source.byteLength, destination.byteLength)
61408
+ );
61409
+
61395
61410
  } else {
61411
+
61396
61412
  // destination is smaller than source, crop source data
61397
61413
  array_copy(source, 0, destination, 0, destination_size);
61414
+
61398
61415
  }
61399
61416
  }
61400
61417
 
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.118.11",
8
+ "version": "2.118.12",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,6 +1,6 @@
1
1
  import { assert } from "../../assert.js";
2
- import { array_copy } from "../../collection/array/array_copy.js";
3
2
  import { array_quick_sort_by_lookup_uint } from "../../collection/array/array_quick_sort_by_lookup_uint.js";
3
+ import { typed_array_copy } from "../../collection/array/typed/typed_array_copy.js";
4
4
  import { AABB3 } from "../../geom/3d/aabb/AABB3.js";
5
5
  import { aabb3_from_v3_array } from "../../geom/3d/aabb/aabb3_from_v3_array.js";
6
6
  import { aabb3_compute_from_triangle } from "../../geom/3d/aabb3_compute_from_triangle.js";
@@ -56,7 +56,6 @@ export function ebvh_build_for_geometry_morton(
56
56
  bvh.__size = node_total_count;
57
57
 
58
58
 
59
-
60
59
  // indices of triangles, but sorted by morton codes
61
60
  const sorted_triangle_order = new Uint32Array(tri_count);
62
61
 
@@ -128,8 +127,9 @@ export function ebvh_build_for_geometry_morton(
128
127
 
129
128
  // record newly generated nodes as "unprocessed"
130
129
  const unprocessed_nodes = new Uint32Array(tri_count);
131
- array_copy(nodes, 0, unprocessed_nodes, 0, tri_count);
130
+
131
+ typed_array_copy(nodes, unprocessed_nodes);
132
132
 
133
133
  // assign root
134
- bvh.root = ebvh_build_hierarchy(bvh, unprocessed_nodes, tri_count, nodes, tri_count, quality );
134
+ bvh.root = ebvh_build_hierarchy(bvh, unprocessed_nodes, tri_count, nodes, tri_count, quality);
135
135
  }
@@ -18,8 +18,8 @@ export function array_buffer_copy(
18
18
  assert.isNonNegativeInteger(source_offset, 'source_offset');
19
19
  assert.isNonNegativeInteger(target_offset, 'target_offset');
20
20
  assert.isNonNegativeInteger(byte_length, 'byte_length');
21
- assert.ok(source instanceof ArrayBuffer || source instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
22
- assert.ok(target instanceof ArrayBuffer || target instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
21
+ // assert.ok(source instanceof ArrayBuffer || source instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
22
+ // assert.ok(target instanceof ArrayBuffer || target instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
23
23
 
24
24
  /**
25
25
  * @type {Uint8Array|Uint16Array|Uint32Array}
@@ -1 +1 @@
1
- {"version":3,"file":"typed_array_copy.d.ts","sourceRoot":"","sources":["../../../../../../src/core/collection/array/typed/typed_array_copy.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,yCAHW,aAAW,YAAY,GAAC,UAAU,GAAC,WAAW,eAC9C,aAAW,YAAY,GAAC,UAAU,GAAC,WAAW,QAWxD"}
1
+ {"version":3,"file":"typed_array_copy.d.ts","sourceRoot":"","sources":["../../../../../../src/core/collection/array/typed/typed_array_copy.js"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,yCAHW,aAAW,YAAY,GAAC,UAAU,GAAC,WAAW,eAC9C,aAAW,YAAY,GAAC,UAAU,GAAC,WAAW,QA0BxD"}
@@ -1,4 +1,5 @@
1
1
  import { array_copy } from "../array_copy.js";
2
+ import { array_buffer_copy } from "./array_buffer_copy.js";
2
3
 
3
4
 
4
5
  /**
@@ -10,9 +11,24 @@ export function typed_array_copy(source, destination) {
10
11
  const destination_size = destination.length;
11
12
 
12
13
  if (destination_size >= source.length) {
14
+
13
15
  destination.set(source, 0);
16
+
17
+ } else if (source.constructor === destination.constructor) {
18
+
19
+ // same type
20
+ array_buffer_copy(
21
+ source.buffer,
22
+ source.byteOffset,
23
+ destination.buffer,
24
+ destination.byteOffset,
25
+ Math.min(source.byteLength, destination.byteLength)
26
+ );
27
+
14
28
  } else {
29
+
15
30
  // destination is smaller than source, crop source data
16
31
  array_copy(source, 0, destination, 0, destination_size);
32
+
17
33
  }
18
34
  }
@@ -8,11 +8,9 @@
8
8
  * @param {number} z1
9
9
  * @returns {number}
10
10
  */
11
- function aabb3_compute_surface_area(x0, y0, z0, x1, y1, z1) {
11
+ export function aabb3_compute_surface_area(x0, y0, z0, x1, y1, z1) {
12
12
  const dx = x1 - x0;
13
13
  const dy = y1 - y0;
14
14
  const dz = z1 - z0;
15
15
  return (dy * (dx + dz) + dz * dx) * 2; //2 of each side
16
16
  }
17
-
18
- export { aabb3_compute_surface_area };
@@ -1 +1 @@
1
- {"version":3,"file":"VertexCacheOptimizer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/optimization/VertexCacheOptimizer.js"],"names":[],"mappings":"AAgaA;;;;;;GAMG;AACH,yDALW,MAAM,EAAE,GAAC,WAAW,WACpB,MAAM,EAAE,GAAC,WAAW,eACpB,MAAM,gBACN,MAAM,QAIhB;AAED;;;;;;GAMG;AACH,8DALW,MAAM,EAAE,GAAC,WAAW,WACpB,MAAM,EAAE,GAAC,WAAW,eACpB,MAAM,gBACN,MAAM,QAIhB"}
1
+ {"version":3,"file":"VertexCacheOptimizer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/optimization/VertexCacheOptimizer.js"],"names":[],"mappings":"AA8aA;;;;;;GAMG;AACH,yDALW,MAAM,EAAE,GAAC,WAAW,WACpB,MAAM,EAAE,GAAC,WAAW,eACpB,MAAM,gBACN,MAAM,QAIhB;AAED;;;;;;GAMG;AACH,8DALW,MAAM,EAAE,GAAC,WAAW,WACpB,MAAM,EAAE,GAAC,WAAW,eACpB,MAAM,gBACN,MAAM,QAIhB"}
@@ -8,10 +8,9 @@ const kCacheSizeMax = 16;
8
8
  const kValenceMax = 8;
9
9
 
10
10
  class VertexScoreTable {
11
- constructor() {
12
- this.cache = new Float32Array(1 + kCacheSizeMax);
13
- this.live = new Float32Array(1 + kValenceMax);
14
- }
11
+
12
+ cache = new Float32Array(1 + kCacheSizeMax);
13
+ live = new Float32Array(1 + kValenceMax);
15
14
 
16
15
  /**
17
16
  *
@@ -42,11 +41,10 @@ const kVertexScoreTableStrip = VertexScoreTable.from(
42
41
  );
43
42
 
44
43
  class TriangleAdjacency {
45
- constructor() {
46
- this.counts = new Uint32Array(1);
47
- this.offsets = new Uint32Array(1);
48
- this.data = new Uint32Array(1);
49
- }
44
+
45
+ counts = new Uint32Array(1);
46
+ offsets = new Uint32Array(1);
47
+ data = new Uint32Array(1);
50
48
 
51
49
  /**
52
50
  *
@@ -76,42 +74,48 @@ function buildTriangleAdjacency(adjacency, indices, index_count, vertex_count) {
76
74
  // fill triangle counts
77
75
  // adjacency.counts.fill(0);// unnecessary, new arrays are already zero-filled
78
76
 
77
+ const adjacency_counts = adjacency.counts;
78
+
79
79
  for (let i = 0; i < index_count; ++i) {
80
80
  const index = indices[i];
81
81
 
82
82
  assert.lessThan(index, vertex_count);
83
83
 
84
- adjacency.counts[index]++;
84
+ adjacency_counts[index]++;
85
85
  }
86
86
 
87
87
  // fill offset table
88
88
  let offset = 0;
89
89
 
90
+ const adjacency_offsets = adjacency.offsets;
91
+
90
92
  for (let i = 0; i < vertex_count; ++i) {
91
- adjacency.offsets[i] = offset;
92
- offset += adjacency.counts[i];
93
+ adjacency_offsets[i] = offset;
94
+ offset += adjacency_counts[i];
93
95
  }
94
96
 
95
97
  assert.equal(offset, index_count);
96
98
 
99
+ const adjacency_data = adjacency.data;
100
+
97
101
  // fill triangle data
98
102
  for (let i = 0; i < face_count; ++i) {
99
103
  const i3 = i * 3;
100
104
 
101
- const a = indices[i3 + 0];
105
+ const a = indices[i3];
102
106
  const b = indices[i3 + 1];
103
107
  const c = indices[i3 + 2];
104
108
 
105
- adjacency.data[adjacency.offsets[a]++] = i;
106
- adjacency.data[adjacency.offsets[b]++] = i;
107
- adjacency.data[adjacency.offsets[c]++] = i;
109
+ adjacency_data[adjacency_offsets[a]++] = i;
110
+ adjacency_data[adjacency_offsets[b]++] = i;
111
+ adjacency_data[adjacency_offsets[c]++] = i;
108
112
  }
109
113
 
110
114
  // fix offsets that have been disturbed by the previous pass
111
115
  for (let i = 0; i < vertex_count; ++i) {
112
116
  // assert(adjacency.offsets[i] >= adjacency.counts[i]);
113
117
 
114
- adjacency.offsets[i] -= adjacency.counts[i];
118
+ adjacency_offsets[i] -= adjacency_counts[i];
115
119
  }
116
120
  }
117
121
 
@@ -236,8 +240,9 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
236
240
  assert.equal(index_count % 3, 0);
237
241
 
238
242
  // guard for empty meshes
239
- if (index_count === 0 || vertex_count === 0)
243
+ if (index_count === 0 || vertex_count === 0) {
240
244
  return;
245
+ }
241
246
 
242
247
  // support in-place optimization
243
248
  if (destination === indices) {
@@ -273,9 +278,10 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
273
278
  const triangle_scores = new Float32Array(face_count);
274
279
 
275
280
  for (let i = 0; i < face_count; ++i) {
281
+
276
282
  const i3 = i * 3;
277
283
 
278
- const a = indices[i3 + 0];
284
+ const a = indices[i3];
279
285
  const b = indices[i3 + 1];
280
286
  const c = indices[i3 + 2];
281
287
 
@@ -296,16 +302,17 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
296
302
 
297
303
  const in_tri_3 = current_triangle * 3;
298
304
 
299
- const a = indices[in_tri_3 + 0];
305
+ const a = indices[in_tri_3];
300
306
  const b = indices[in_tri_3 + 1];
301
307
  const c = indices[in_tri_3 + 2];
302
308
 
303
309
  // output indices
304
310
  const out_tri_3 = output_triangle * 3;
305
311
 
306
- destination[out_tri_3 + 0] = a;
312
+ destination[out_tri_3] = a;
307
313
  destination[out_tri_3 + 1] = b;
308
314
  destination[out_tri_3 + 2] = c;
315
+
309
316
  output_triangle++;
310
317
 
311
318
  // update emitted flags
@@ -327,8 +334,11 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
327
334
  }
328
335
  }
329
336
 
337
+ // swap caches
330
338
  const cache_temp = cache;
331
- cache = cache_new, cache_new = cache_temp;
339
+ cache = cache_new;
340
+ cache_new = cache_temp;
341
+
332
342
  cache_count = cache_write > cache_size ? cache_size : cache_write;
333
343
 
334
344
  // update live triangle counts
@@ -346,13 +356,17 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
346
356
  const neighbours_size = adjacency.counts[index];
347
357
 
348
358
  for (let i = 0; i < neighbours_size; ++i) {
359
+
349
360
  const tri = neighbours[i + neighbour_offset];
350
361
 
351
362
  if (tri === current_triangle) {
363
+
352
364
  neighbours[neighbour_offset + i] = neighbours[neighbour_offset + neighbours_size - 1];
353
365
  adjacency.counts[index]--;
354
366
  break;
367
+
355
368
  }
369
+
356
370
  }
357
371
  }
358
372