@woosh/meep-engine 2.34.48 → 2.34.49

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.
@@ -59,7 +59,6 @@ const SHRINK_FACTOR = 0.5;
59
59
  */
60
60
  const RESIZE_COUNT_THRESHOLD = 128;
61
61
 
62
-
63
62
  /**
64
63
  * Dynamically sized bit field
65
64
  * @constructor
@@ -389,6 +388,7 @@ BitSet.prototype.set = function (bitIndex, value) {
389
388
  const bitIndexInc = bitIndex + 1;
390
389
 
391
390
  if (bitIndexInc > this.__length) {
391
+ // ensure capacity
392
392
  this.__setLength(bitIndexInc);
393
393
  }
394
394
 
@@ -401,6 +401,7 @@ BitSet.prototype.set = function (bitIndex, value) {
401
401
  this.__data_uint32[word_offset] &= ~word_mask;
402
402
 
403
403
  if (bitIndex === this.__length - 1) {
404
+ // trim down set size potentially
404
405
  const newLastSetBit = this.previousSetBit(bitIndex);
405
406
 
406
407
  this.__setLength(newLastSetBit + 1);
@@ -538,9 +539,13 @@ BitSet.prototype.reset = function () {
538
539
  if (current_length <= 0) {
539
540
  // no action required
540
541
  return;
542
+ } else if (current_length <= 32) {
543
+ // one word, set first word to 0 manually
544
+ this.__data_uint32[0] = 0;
545
+ } else {
546
+ this.__data_uint32.fill(0, 0, Math.ceil(current_length / 32));
541
547
  }
542
548
 
543
- this.__data_uint32.fill(0, 0, Math.ceil(current_length / 32));
544
549
  this.__length = 0;
545
550
  };
546
551
 
@@ -7,53 +7,56 @@
7
7
  * @param {number} z
8
8
  * @param {number} w
9
9
  */
10
- function array_set_plane_normalized(destination, destination_offset, x, y, z, w) {
10
+ function array_set_plane_normalized(
11
+ destination, destination_offset,
12
+ x, y, z, w
13
+ ) {
11
14
  // compute vector length
12
15
  const length = Math.hypot(x, y, z);
13
16
 
14
- const inverseNormalLength = 1.0 / length;
17
+ const inverse_length = 1.0 / length;
15
18
 
16
19
  // apply normalization
17
- destination[destination_offset] = x * inverseNormalLength;
18
- destination[destination_offset + 1] = y * inverseNormalLength;
19
- destination[destination_offset + 2] = z * inverseNormalLength;
20
- destination[destination_offset + 3] = w * inverseNormalLength;
20
+ destination[destination_offset] = x * inverse_length;
21
+ destination[destination_offset + 1] = y * inverse_length;
22
+ destination[destination_offset + 2] = z * inverse_length;
23
+ destination[destination_offset + 3] = w * inverse_length;
21
24
  }
22
25
 
23
26
  /**
24
27
  * Set frustum from projection matrix
25
28
  * @param {number[]|Float32Array} frustum_planes
26
- * @param {number[]} me
29
+ * @param {number[]} m4
27
30
  */
28
- export function frustum_from_projection_matrix_array(frustum_planes, me) {
31
+ export function frustum_from_projection_matrix_array(frustum_planes, m4) {
29
32
 
30
- const me0 = me[0];
31
- const me3 = me[3];
33
+ const me0 = m4[0];
34
+ const me3 = m4[3];
32
35
 
33
- const me4 = me[4];
34
- const me7 = me[7];
36
+ const me4 = m4[4];
37
+ const me7 = m4[7];
35
38
 
36
- const me8 = me[8];
37
- const me11 = me[11];
39
+ const me8 = m4[8];
40
+ const me11 = m4[11];
38
41
 
39
- const me12 = me[12];
40
- const me15 = me[15];
42
+ const me12 = m4[12];
43
+ const me15 = m4[15];
41
44
 
42
45
  array_set_plane_normalized(frustum_planes, 0, me3 - me0, me7 - me4, me11 - me8, me15 - me12);
43
46
  array_set_plane_normalized(frustum_planes, 4, me3 + me0, me7 + me4, me11 + me8, me15 + me12);
44
47
 
45
- const me1 = me[1];
46
- const me5 = me[5];
47
- const me9 = me[9];
48
- const me13 = me[13];
48
+ const me1 = m4[1];
49
+ const me5 = m4[5];
50
+ const me9 = m4[9];
51
+ const me13 = m4[13];
49
52
 
50
53
  array_set_plane_normalized(frustum_planes, 8, me3 + me1, me7 + me5, me11 + me9, me15 + me13);
51
54
  array_set_plane_normalized(frustum_planes, 12, me3 - me1, me7 - me5, me11 - me9, me15 - me13);
52
55
 
53
- const me2 = me[2];
54
- const me6 = me[6];
55
- const me10 = me[10];
56
- const me14 = me[14];
56
+ const me2 = m4[2];
57
+ const me6 = m4[6];
58
+ const me10 = m4[10];
59
+ const me14 = m4[14];
57
60
 
58
61
  array_set_plane_normalized(frustum_planes, 16, me3 - me2, me7 - me6, me11 - me10, me15 - me14);
59
62
  array_set_plane_normalized(frustum_planes, 20, me3 + me2, me7 + me6, me11 + me10, me15 + me14);
@@ -1,4 +1,5 @@
1
1
  import { isArrayEqualStrict } from "../../../../../core/collection/array/isArrayEqualStrict.js";
2
+ import { is_typed_array_equals } from "../../../../../core/collection/array/typed/is_typed_array_equals.js";
2
3
 
3
4
 
4
5
  /**
@@ -46,7 +47,7 @@ export function computeGeometryEquality(a, b) {
46
47
  const a_attribute = a.attributes[key];
47
48
  const b_attribute = b.attributes[key];
48
49
 
49
- if (!isArrayEqualStrict(a_attribute.array, b_attribute.array)) {
50
+ if (!is_typed_array_equals(a_attribute.array, b_attribute.array)) {
50
51
  return false;
51
52
  }
52
53
  }
@@ -76,8 +76,6 @@ export async function convert_three_object_to_micron(object, micron_cache = defa
76
76
 
77
77
  await micron_cache.set(g, micron_geometry);
78
78
 
79
- // console.log(micron_geometry);
80
-
81
79
  return micron_geometry;
82
80
  }
83
81
 
@@ -1,6 +1,6 @@
1
- import { squirrel3 } from "../../../../core/math/hash/squirrel3.js";
2
1
  import { ConicRay } from "../../../../core/geom/ConicRay.js";
3
2
  import { vec4 } from "gl-matrix";
3
+ import { assert } from "../../../../core/assert.js";
4
4
 
5
5
  /**
6
6
  * Patches are organized into a tree hierarchy
@@ -13,18 +13,11 @@ export class MicronGeometryPatch {
13
13
  */
14
14
  this.id = 0;
15
15
 
16
- /**
17
- * Continuous memory region for various pieces of data to get better memory access patterns
18
- * All pieces of data end up in a continuous piece of memory, resulting in better cache coherence
19
- * @type {ArrayBuffer}
20
- */
21
- const array_buffer = new ArrayBuffer((6 + 6 + 24) * 4);
22
-
23
16
  /**
24
17
  * Bounds are used to determine screen error and whether a patch should be subdivided or not for rendering
25
18
  * @type {number[]}
26
19
  */
27
- this.bounding_box = new Float32Array(array_buffer, 0, 6);
20
+ this.bounding_box = null;
28
21
 
29
22
  /**
30
23
  *
@@ -36,13 +29,21 @@ export class MicronGeometryPatch {
36
29
  *
37
30
  * @type {number[]|Float32Array}
38
31
  */
39
- this.group_bounding_box = new Float32Array(array_buffer, 6 * 4, 6);
32
+ this.group_bounding_box = null;
40
33
 
41
34
  /**
42
35
  *
43
36
  * @type {number[]|Float32Array}
44
37
  */
45
- this.group_bounding_box_corners = new Float32Array(array_buffer, 12 * 4, 24);
38
+ this.group_bounding_box_corners = null;
39
+
40
+ /**
41
+ * Continuous memory region for various pieces of data to get better memory access patterns
42
+ * All pieces of data end up in a continuous piece of memory, resulting in better cache coherence
43
+ * @type {ArrayBuffer}
44
+ */
45
+ const array_buffer = new ArrayBuffer(144);
46
+ this.allocate_metadata(array_buffer, 0);
46
47
 
47
48
  /**
48
49
  *
@@ -114,21 +115,25 @@ export class MicronGeometryPatch {
114
115
  }
115
116
 
116
117
  /**
117
- * @deprecated
118
+ *
119
+ * @param {ArrayBuffer} buffer
120
+ * @param {number} offset
121
+ * @returns {number}
118
122
  */
119
- get parent() {
120
- throw new Error('Single parent is no longer supported, use .parents instead');
121
- }
123
+ allocate_metadata(buffer, offset) {
124
+ assert.greaterThanOrEqual(buffer.byteLength, offset + 144, 'buffer underflow');
122
125
 
123
- /**
124
- * @deprecated
125
- */
126
- set parent(v) {
127
- throw new Error('Single parent is no longer supported, use .parents instead');
126
+ this.bounding_box = new Float32Array(buffer, offset, 6);
127
+
128
+ this.group_bounding_box = new Float32Array(buffer, offset + 24, 6);
129
+
130
+ this.group_bounding_box_corners = new Float32Array(buffer, offset + 48, 24);
131
+
132
+ return 144;
128
133
  }
129
134
 
130
135
  hash() {
131
- return squirrel3(this.id);
136
+ return this.id;
132
137
  }
133
138
 
134
139
  computeByteSize() {
@@ -136,8 +141,13 @@ export class MicronGeometryPatch {
136
141
 
137
142
  result += this.face_indices.buffer.byteLength;
138
143
 
139
- for (let i = 0; i < this.vertex_attribute_arrays.length; i++) {
140
- result += this.vertex_attribute_arrays[i].buffer.byteLength;
144
+ const attribute_arrays = this.vertex_attribute_arrays;
145
+ const attribute_count = attribute_arrays.length;
146
+
147
+ for (let i = 0; i < attribute_count; i++) {
148
+ const attribute_array = attribute_arrays[i];
149
+
150
+ result += attribute_array.buffer.byteLength;
141
151
  }
142
152
 
143
153
  return result;
@@ -79,12 +79,18 @@ export class MicronGeometryBinarySerializationAdapter extends BinaryClassSeriali
79
79
 
80
80
  const patches = [];
81
81
 
82
+ // for the sake of speed, we will allocate all metadata in the same piece of memory to make traversal of patch hierarchy faster
83
+ const md_buffer = new ArrayBuffer(patch_count * 144);
84
+ let md_buffer_offset = 0;
85
+
82
86
  // build initial patches
83
87
  for (let i = 0; i < patch_count; i++) {
84
88
  const patch = new MicronGeometryPatch();
85
89
 
86
90
  patch.id = i;
87
91
 
92
+ md_buffer_offset += patch.allocate_metadata(md_buffer, md_buffer_offset);
93
+
88
94
  patches[i] = patch;
89
95
  }
90
96
 
@@ -1,10 +1,8 @@
1
1
  import {
2
2
  AmbientLight,
3
3
  BoxBufferGeometry,
4
- CameraHelper,
5
4
  CubeTextureLoader,
6
5
  DirectionalLight,
7
- DirectionalLightHelper,
8
6
  FrontSide,
9
7
  Matrix4,
10
8
  Mesh,
@@ -64,6 +62,10 @@ metrics.create({
64
62
  name: 'adapter_update', buffer_size: METRIC_BUFFER_SIZE
65
63
  });
66
64
 
65
+ metrics.create({
66
+ name: 'debug_v0', buffer_size: METRIC_BUFFER_SIZE
67
+ });
68
+
67
69
  let container, stats;
68
70
 
69
71
  let camera, scene, renderer;
@@ -480,7 +482,7 @@ function init() {
480
482
  // gltf_sample('moicon/03_Jan_22_Demo/worker_test/model.gltf');
481
483
  // gltf_sample('moicon/A4/A4/model.gltf');
482
484
  gltf_sample('moicon/ztest_object_many_pieces/model.gltf');
483
- // gltf_grid('moicon/ztest_object_many_pieces/model.gltf', 3, 3);
485
+ // gltf_grid('moicon/ztest_object_many_pieces/model.gltf', 10, 10);
484
486
 
485
487
  document.addEventListener("mousemove", onDocumentMouseMove);
486
488
 
@@ -4,6 +4,7 @@ import { RefinementSpec } from "./refinement/RefinementSpec.js";
4
4
  import { ActivePatchList } from "./refinement/ActivePatchList.js";
5
5
  import { mat4 } from "gl-matrix";
6
6
  import { get_geometry_patch_cut } from "./refinement/get_geometry_patch_cut.js";
7
+ import { traverseThreeObject } from "../../ecs/highlight/renderer/traverseThreeObject.js";
7
8
 
8
9
  /**
9
10
  * @readonly
@@ -106,7 +107,7 @@ export class VirtualGeometryBuilder {
106
107
  }
107
108
 
108
109
  /**
109
- *
110
+ * @private
110
111
  * @param {THREE.Object3D|ThreeMicronMesh} object
111
112
  */
112
113
  buildForObject(object) {
@@ -133,15 +134,6 @@ export class VirtualGeometryBuilder {
133
134
  );
134
135
  }
135
136
  }
136
-
137
- const children = object.children;
138
- const children_count = children.length;
139
-
140
- for (let i = 0; i < children_count; i++) {
141
- const child = children[i];
142
-
143
- this.buildForObject(child);
144
- }
145
137
  }
146
138
 
147
139
  /**
@@ -211,10 +203,11 @@ export class VirtualGeometryBuilder {
211
203
  const n = this.input_scene_length;
212
204
  const input_objects = this.input_scene;
213
205
 
206
+
214
207
  for (let i = 0; i < n; i++) {
215
208
  const object3D = input_objects[i];
216
209
 
217
- this.buildForObject(object3D);
210
+ traverseThreeObject(object3D, this.buildForObject, this);
218
211
  }
219
212
 
220
213
 
@@ -50,17 +50,6 @@ export class RefinementSpec {
50
50
  * @type {Float32Array}
51
51
  */
52
52
  this.frustum_f32 = new Float32Array(array_buffer, 64, 24);
53
-
54
-
55
- /**
56
- * Object-space camera position
57
- * @type {Float32Array}
58
- */
59
- this.view_position = new Float32Array(3);
60
- }
61
-
62
- get frustum() {
63
- throw new Error('deprecated, use .frustum_f32 instead');
64
53
  }
65
54
 
66
55
  /**
@@ -40,6 +40,8 @@ export function get_geometry_patch_cut(
40
40
  const projection_matrix = spec.projection_matrix;
41
41
  const error_threshold = spec.error_threshold_normalized;
42
42
 
43
+ const geometry_id = geometry.id;
44
+
43
45
  let output_patch_cursor = destination_offset;
44
46
 
45
47
  let i;
@@ -111,7 +113,7 @@ export function get_geometry_patch_cut(
111
113
  }
112
114
 
113
115
  patch_instance.instance_id = instance_id;
114
- patch_instance.geometry_id = geometry.id;
116
+ patch_instance.geometry_id = geometry_id;
115
117
  patch_instance.patch = patch;
116
118
  patch_instance.transform = transform;
117
119
 
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.34.48",
8
+ "version": "2.34.49",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",