@woosh/meep-engine 2.33.4 → 2.33.9

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 (145) hide show
  1. package/core/binary/BinaryBuffer.js +26 -2
  2. package/core/bvh2/LeafNode.js +6 -1
  3. package/core/bvh2/aabb3/AABB3.js +21 -1
  4. package/core/collection/RingBuffer.js +40 -10
  5. package/core/collection/array/copyArray.js +2 -2
  6. package/core/collection/array/typed/typed_array_copy.js +2 -2
  7. package/core/collection/set/compute_set_difference.js +32 -0
  8. package/core/collection/set/compute_set_intersection.js +22 -0
  9. package/core/collection/set/set_remove.js +15 -0
  10. package/core/collection/table/DataType2TypedArrayConstructorMapping.js +2 -0
  11. package/core/collection/table/DataTypeByteSizes.js +21 -0
  12. package/core/collection/table/RowFirstTable.js +1 -88
  13. package/core/collection/table/RowFirstTable.spec.js +3 -1
  14. package/core/collection/table/RowFirstTableSpec.js +9 -19
  15. package/core/collection/table/computeDataTypeByIndex.js +21 -0
  16. package/core/collection/table/deserializeRowFirstTable.js +48 -0
  17. package/core/collection/table/serializeRowFirstTable.js +27 -0
  18. package/core/color/Color.js +1 -0
  19. package/core/color/ColorUtils.js +12 -3
  20. package/core/geom/3d/aabb/aabb3_compute_projected_area.js +6 -4
  21. package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
  22. package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
  23. package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
  24. package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -0
  25. package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +96 -0
  26. package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
  27. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
  28. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
  29. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
  30. package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
  31. package/core/geom/3d/frustum/array_normalize_plane.js +25 -0
  32. package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +60 -0
  33. package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
  34. package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
  35. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
  36. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
  37. package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
  38. package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
  39. package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
  40. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
  41. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
  42. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
  43. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
  44. package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
  45. package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
  46. package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
  47. package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
  48. package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
  49. package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
  50. package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
  51. package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
  52. package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
  53. package/core/process/undo/ActionProcessor.d.ts +2 -0
  54. package/core/process/undo/ActionProcessor.js +59 -1
  55. package/core/process/undo/ActionProcessor.spec.js +59 -0
  56. package/core/process/undo/Mark.js +2 -1
  57. package/engine/Engine.d.ts +2 -0
  58. package/engine/EngineHarness.js +4 -4
  59. package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
  60. package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
  61. package/engine/ecs/foliage/InstancedFoliage.js +3 -5
  62. package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
  63. package/engine/ecs/transform/Transform.js +2 -1
  64. package/engine/graphics/GraphicsEngine.js +9 -116
  65. package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
  66. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
  67. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
  68. package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
  69. package/engine/graphics/filter/FlipArrayInPlace.js +25 -0
  70. package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
  71. package/engine/graphics/filter/ImageFilter.js +20 -51
  72. package/engine/graphics/{micron → geometry}/aabb3_to_buffer_geometry.js +0 -0
  73. package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
  74. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
  75. package/engine/graphics/material/SplatMaterial.js +4 -97
  76. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +2 -6
  77. package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
  78. package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
  79. package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
  80. package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
  81. package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
  82. package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
  83. package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
  84. package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
  85. package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
  86. package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
  87. package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
  88. package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
  89. package/engine/graphics/micron/format/MicronGeometry.js +12 -0
  90. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +2 -2
  91. package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -9
  92. package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
  93. package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
  94. package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
  95. package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
  96. package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
  97. package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
  98. package/engine/graphics/micron/prototypeVirtualGeometry.js +1 -1
  99. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +27 -23
  100. package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
  101. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +3 -5
  102. package/engine/graphics/micron/render/refinement/ActivePatchList.js +38 -49
  103. package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
  104. package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
  105. package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
  106. package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
  107. package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
  108. package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
  109. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
  110. package/engine/graphics/render/forward_plus/LightManager.js +5 -7
  111. package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
  112. package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
  113. package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
  114. package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
  115. package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
  116. package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
  117. package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
  118. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  119. package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
  120. package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
  121. package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
  122. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
  123. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +440 -0
  124. package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
  125. package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
  126. package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
  127. package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
  128. package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
  129. package/engine/graphics/texture/cubemap/load_environment_map.js +163 -0
  130. package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
  131. package/engine/graphics/texture/sampler/TextureBinaryBufferSerializer.js +1 -1
  132. package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +3 -2
  133. package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
  134. package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
  135. package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
  136. package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
  137. package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
  138. package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
  139. package/engine/network/convertPathToURL.js +6 -0
  140. package/engine/plugin/EnginePluginManager.d.ts +9 -0
  141. package/engine/reference/v2/Reference.d.ts +7 -0
  142. package/package.json +1 -1
  143. package/view/minimap/gl/MinimapMarkersGL.js +2 -2
  144. package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
  145. package/engine/graphics/micron/render/RefinementSpec.js +0 -181
@@ -342,7 +342,7 @@ BinaryBuffer.prototype.readInt32Array = function (destination, destination_offse
342
342
  *
343
343
  * @param {number} destination_offset starting index in the destination array
344
344
  * @param {number} length number of elements to read
345
- * @param {Float32Array} destination
345
+ * @param {Float32Array|number[]} destination
346
346
  */
347
347
  BinaryBuffer.prototype.readFloat32Array = function (destination, destination_offset, length) {
348
348
  for (let i = 0; i < length; i++) {
@@ -366,7 +366,7 @@ BinaryBuffer.prototype.readFloat64Array = function (destination, destination_off
366
366
  *
367
367
  * @param {number} source_offset starting index in the source array
368
368
  * @param {number} length number of elements to read
369
- * @param {Float32Array} source
369
+ * @param {Float32Array|number[]} source
370
370
  */
371
371
  BinaryBuffer.prototype.writeFloat32Array = function (source, source_offset, length) {
372
372
  for (let i = 0; i < length; i++) {
@@ -452,6 +452,18 @@ BinaryBuffer.prototype.writeUint8 = function (value) {
452
452
  this.position = end;
453
453
  };
454
454
 
455
+ /**
456
+ *
457
+ * @param {Uint8Array|number[]} source
458
+ * @param {number} source_offset
459
+ * @param {number} length
460
+ */
461
+ BinaryBuffer.prototype.writeUint8Array = function (source, source_offset, length) {
462
+ for (let i = 0; i < length; i++) {
463
+ this.writeUint8(source[source_offset + i]);
464
+ }
465
+ }
466
+
455
467
  /**
456
468
  *
457
469
  * @param {number} value
@@ -491,6 +503,18 @@ BinaryBuffer.prototype.writeUint16LE = function (value) {
491
503
  this.position = end;
492
504
  };
493
505
 
506
+ /**
507
+ *
508
+ * @param {Uint16Array|number[]} source
509
+ * @param {number} source_offset
510
+ * @param {number} length
511
+ */
512
+ BinaryBuffer.prototype.writeUint16Array = function (source, source_offset, length) {
513
+ for (let i = 0; i < length; i++) {
514
+ this.writeUint16(source[source_offset + i]);
515
+ }
516
+ }
517
+
494
518
  /**
495
519
  *
496
520
  * @param {number} value
@@ -83,10 +83,15 @@ LeafNode.prototype.move = function (dx, dy, dz) {
83
83
  LeafNode.prototype.resize = function (x0, y0, z0, x1, y1, z1) {
84
84
  this.setBounds(x0, y0, z0, x1, y1, z1);
85
85
 
86
+ this.bubbleRefit();
87
+ };
88
+
89
+ LeafNode.prototype.bubbleRefit = function (){
90
+
86
91
  if (this.parentNode !== null) {
87
92
  this.parentNode.bubbleRefit();
88
93
  }
89
- };
94
+ }
90
95
 
91
96
  /**
92
97
  *
@@ -8,6 +8,7 @@ import { computeAABB3PlaneSide } from "../../geom/3d/aabb/computeAABB3PlaneSide.
8
8
  import computeMortonCode from "../../geom/3d/morton/Morton.js";
9
9
  import { _boxSurfaceArea2, intersectRay, intersectSegment } from "./AABB3Math.js";
10
10
  import { aabb3_build_corners } from "../../geom/3d/aabb/aabb3_build_corners.js";
11
+ import { assert } from "../../assert.js";
11
12
 
12
13
 
13
14
  /**
@@ -724,7 +725,9 @@ AABB3.prototype.getCorners = function (result) {
724
725
  * @param {number} offset
725
726
  */
726
727
  AABB3.prototype.writeToArray = function (result, offset) {
727
- result[offset + 0] = this.x0;
728
+ assert.isNonNegativeInteger(offset, 'offset');
729
+
730
+ result[offset] = this.x0;
728
731
  result[offset + 1] = this.y0;
729
732
  result[offset + 2] = this.z0;
730
733
 
@@ -733,6 +736,23 @@ AABB3.prototype.writeToArray = function (result, offset) {
733
736
  result[offset + 5] = this.z1;
734
737
  };
735
738
 
739
+ /**
740
+ *
741
+ * @param {number[]|Float32Array|Float64Array} source
742
+ * @param {number} offset
743
+ */
744
+ AABB3.prototype.readFromArray = function (source, offset) {
745
+ assert.isNonNegativeInteger(offset, 'offset');
746
+
747
+ this.x0 = source[offset];
748
+ this.y0 = source[offset + 1];
749
+ this.z0 = source[offset + 2];
750
+
751
+ this.x1 = source[offset + 3];
752
+ this.y1 = source[offset + 4];
753
+ this.z1 = source[offset + 5];
754
+ };
755
+
736
756
  /**
737
757
  * @param {THREE.Plane} plane
738
758
  * @returns {int} 2,0,or -2; 2: above, -2 : below, 0 : intersects plane
@@ -7,14 +7,32 @@ export class RingBuffer {
7
7
  * @constructor
8
8
  */
9
9
  constructor(size) {
10
- assert.equal(typeof size, "number", `Type of 'size' must be 'number', was '${typeof size}' instead`);
10
+ assert.isNumber(size, 'size');
11
11
  assert.greaterThan(size, 0, `size`);
12
+ assert.isNonNegativeInteger(size, 'size');
12
13
 
14
+ /**
15
+ *
16
+ * @type {number}
17
+ */
13
18
  this.size = size;
14
19
 
20
+ /**
21
+ *
22
+ * @type {number}
23
+ */
15
24
  this.head = 0;
25
+
26
+ /**
27
+ *
28
+ * @type {number}
29
+ */
16
30
  this.tail = 0;
17
31
 
32
+ /**
33
+ *
34
+ * @type {number}
35
+ */
18
36
  this.count = 0;
19
37
 
20
38
  /**
@@ -62,13 +80,15 @@ export class RingBuffer {
62
80
 
63
81
  this.data[head] = element;
64
82
 
65
- const newHead = (head + 1) % this.size;
83
+ const size = this.size;
84
+
85
+ const newHead = (head + 1) % size;
66
86
 
67
87
  this.head = newHead;
68
88
 
69
- if (this.count === this.size) {
89
+ if (this.count === size) {
70
90
  //update tail
71
- this.tail = (this.tail + 1) % this.size;
91
+ this.tail = (this.tail + 1) % size;
72
92
  } else {
73
93
  this.count++;
74
94
  }
@@ -130,11 +150,15 @@ export class RingBuffer {
130
150
  * @returns {V|undefined}
131
151
  */
132
152
  removeIf(condition, thisArg) {
153
+ const count = this.count;
154
+ const size = this.size;
133
155
 
134
- for (let i = 0; i < this.count; i++) {
135
- const index = (this.tail + i) % this.size;
156
+ const tail = this.tail;
157
+ const data = this.data;
136
158
 
137
- const el = this.data[index];
159
+ for (let i = 0; i < count; i++) {
160
+ const index = (tail + i) % size;
161
+ const el = data[index];
138
162
 
139
163
  if (condition.call(thisArg, el)) {
140
164
 
@@ -151,10 +175,16 @@ export class RingBuffer {
151
175
  * @param {*} [thisArg]
152
176
  */
153
177
  forEach(visitor, thisArg) {
154
- for (let i = 0; i < this.count; i++) {
155
- const index = (this.tail + i) % this.size;
178
+ const count = this.count;
179
+ const size = this.size;
180
+
181
+ const tail = this.tail;
182
+ const data = this.data;
183
+
184
+ for (let i = 0; i < count; i++) {
156
185
 
157
- const el = this.data[index];
186
+ const index = (tail + i) % size;
187
+ const el = data[index];
158
188
 
159
189
  visitor.call(thisArg, el);
160
190
  }
@@ -25,9 +25,9 @@ export function copyArray(source, target) {
25
25
  * Follows Java System.arraycopy interface
26
26
  * Copy data from one array to another
27
27
  * @template T
28
- * @param {T[]|ArrayLike<T>|TypedArray} source The source array
28
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} source The source array
29
29
  * @param {number} source_position Starting position where to copy from inside the source array
30
- * @param {T[]|ArrayLike<T>|TypedArray} destination The destination array
30
+ * @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} destination The destination array
31
31
  * @param {number} destination_position Starting position where to copy to inside the destination array
32
32
  * @param {number} length How many elements should be copied
33
33
  */
@@ -3,8 +3,8 @@ import { array_copy } from "../copyArray.js";
3
3
 
4
4
  /**
5
5
  *
6
- * @param {TypedArray} source
7
- * @param {TypedArray} destination
6
+ * @param {TypedArray|Float32Array} source
7
+ * @param {TypedArray|Float32Array} destination
8
8
  */
9
9
  export function typed_array_copy(source, destination) {
10
10
  const destination_size = destination.length;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @template T
3
+ * @returns Set<T>
4
+ * @param {Set<T>} a
5
+ * @param {Set<T>} b
6
+ */
7
+ export function compute_set_difference(a, b) {
8
+ const result = new Set();
9
+
10
+ const a_array = Array.from(a);
11
+ const a_count = a_array.length;
12
+ for (let i = 0; i < a_count; i++) {
13
+ const t = a_array[i];
14
+
15
+ if (!b.has(t)) {
16
+ result.add(t);
17
+ }
18
+ }
19
+
20
+ const b_array = Array.from(b);
21
+ const b_count = b_array.length;
22
+ for (let i = 0; i < b_count; i++) {
23
+ const t = b_array[i];
24
+
25
+ if (!a.has(t)) {
26
+ result.add(t);
27
+ }
28
+ }
29
+
30
+
31
+ return result;
32
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @template T
3
+ * @returns Set<T>
4
+ * @param {Set<T>} a
5
+ * @param {Set<T>} b
6
+ */
7
+ export function compute_set_intersection(a, b) {
8
+ const result = new Set();
9
+
10
+ const a_array = Array.from(a);
11
+
12
+ const n = a_array.length;
13
+ for (let i = 0; i < n; i++) {
14
+ const t = a_array[i];
15
+
16
+ if (b.has(t)) {
17
+ result.add(t);
18
+ }
19
+ }
20
+
21
+ return result;
22
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @template T
3
+ * @param {Set<T>} a
4
+ * @param {Set<T>} b
5
+ */
6
+ export function set_remove(a, b) {
7
+ const bs = Array.from(b);
8
+
9
+ const n = bs.length;
10
+ for (let i = 0; i < n; i++) {
11
+ const t = bs[i];
12
+
13
+ a.delete(t);
14
+ }
15
+ }
@@ -12,6 +12,8 @@ export const DataType2TypedArrayConstructorMapping = {
12
12
  [DataType.Int8]: Int8Array,
13
13
  [DataType.Int16]: Int16Array,
14
14
  [DataType.Int32]: Int32Array,
15
+ // No float16 array type, using uint16 as a backing instead
16
+ [DataType.Float16]: Uint16Array,
15
17
  [DataType.Float32]: Float32Array,
16
18
  [DataType.Float64]: Float64Array,
17
19
  }
@@ -0,0 +1,21 @@
1
+ import { DataType } from "./DataType.js";
2
+
3
+ /**
4
+ * @readonly
5
+ * @enum {number}
6
+ */
7
+ export const DataTypeByteSizes = {
8
+ [DataType.Uint8]: 1,
9
+ [DataType.Uint16]: 2,
10
+ [DataType.Uint32]: 4,
11
+ [DataType.Uint64]: 8,
12
+
13
+ [DataType.Int8]: 1,
14
+ [DataType.Int16]: 2,
15
+ [DataType.Int32]: 4,
16
+ [DataType.Int64]: 8,
17
+
18
+ [DataType.Float16]: 2,
19
+ [DataType.Float32]: 4,
20
+ [DataType.Float64]: 8
21
+ };
@@ -6,7 +6,6 @@
6
6
  import { assert } from "../../assert.js";
7
7
  import Signal from "../../events/signal/Signal.js";
8
8
  import { max2 } from "../../math/max2.js";
9
- import { DataTypeIndices } from "./DataTypeIndices.js";
10
9
  import { RowFirstTableSpec } from "./RowFirstTableSpec.js";
11
10
 
12
11
 
@@ -439,92 +438,6 @@ RowFirstTable.prototype.printToConsole = function () {
439
438
  console.table(rows);
440
439
  };
441
440
 
442
- /**
443
- *
444
- * @param {BinaryBuffer} buffer
445
- * @param {RowFirstTable} table
446
- */
447
- function serializeRowFirstTable(buffer, table) {
448
- //write types
449
- buffer.writeUint16(table.types.length);
450
- table.types.forEach(function (type) {
451
- const typeIndex = DataTypeIndices[type];
452
- buffer.writeUint8(typeIndex);
453
- });
454
-
455
- //write record length
456
- buffer.writeUint32(table.bytesPerRecord);
457
-
458
- //write number of records
459
- buffer.writeUint32(table.length);
460
-
461
- //write data
462
- const numDataBytes = table.length * table.bytesPerRecord;
463
- buffer.writeBytes(new Uint8Array(table.data), 0, numDataBytes);
464
- }
465
-
466
- /**
467
- *
468
- * @param {BinaryBuffer} buffer
469
- * @param {RowFirstTable} table
470
- */
471
- function deserializeRowFirstTable(buffer, table) {
472
- /**
473
- *
474
- * @param {number} index
475
- * @returns {DataType|null}
476
- */
477
- function typeByIndex(index) {
478
- for (let type in DataTypeIndices) {
479
- if (!DataTypeIndices.hasOwnProperty(type)) {
480
- continue;
481
- }
482
-
483
- const typeIndex = DataTypeIndices[type];
484
- if (typeIndex === index) {
485
- return type;
486
- }
487
- }
488
-
489
- return null;
490
- }
491
-
492
- //read types
493
- const numTypes = buffer.readUint16();
494
- const types = [];
495
- for (let i = 0; i < numTypes; i++) {
496
- const typeIndex = buffer.readUint8();
497
- const type = typeByIndex(typeIndex);
498
- if (type === null) {
499
- throw new Error(`Unknown DataType index ${typeIndex}`);
500
- }
501
- types[i] = type;
502
- }
503
-
504
- //record size
505
- const bytesPerRecord = buffer.readUint32();
506
-
507
- //read number of records
508
- const numRecords = buffer.readUint32();
509
-
510
- const numDataBytes = bytesPerRecord * numRecords;
511
- const data = new Uint8Array(numDataBytes);
512
-
513
- //read data
514
- buffer.readBytes(data, 0, numDataBytes);
515
-
516
- //update table
517
- table.spec = RowFirstTableSpec.get(types);
518
- table.length = numRecords;
519
- table.capacity = numRecords;
520
- table.data = data.buffer;
521
- table.dataView = new DataView(table.data);
522
-
523
- table.initialize();
524
- }
525
-
526
441
  export {
527
- RowFirstTable,
528
- serializeRowFirstTable,
529
- deserializeRowFirstTable
442
+ RowFirstTable
530
443
  };
@@ -1,7 +1,9 @@
1
1
  import { BinaryBuffer } from "../../binary/BinaryBuffer.js";
2
2
  import { DataType } from "./DataType.js";
3
- import { deserializeRowFirstTable, RowFirstTable, serializeRowFirstTable } from "./RowFirstTable.js";
3
+ import { RowFirstTable } from "./RowFirstTable.js";
4
4
  import { RowFirstTableSpec } from "./RowFirstTableSpec.js";
5
+ import { serializeRowFirstTable } from "./serializeRowFirstTable.js";
6
+ import { deserializeRowFirstTable } from "./deserializeRowFirstTable.js";
5
7
 
6
8
  test("constructor doesn't throw", () => {
7
9
  new RowFirstTable(new RowFirstTableSpec([]));
@@ -8,6 +8,7 @@ import { FunctionCompiler } from "../../function/FunctionCompiler.js";
8
8
  import { computeStringHash } from "../../primitives/strings/computeStringHash.js";
9
9
  import { isArrayEqualStrict } from "../array/isArrayEqualStrict.js";
10
10
  import { DataType } from "./DataType.js";
11
+ import { DataTypeByteSizes } from "./DataTypeByteSizes.js";
11
12
 
12
13
  /**
13
14
  * @readonly
@@ -47,25 +48,6 @@ export const DataType2DataViewWriters = {
47
48
  "float64": "setFloat64"
48
49
  };
49
50
 
50
- /**
51
- * @readonly
52
- * @enum {number}
53
- */
54
- export const DataTypeByteSizes = {
55
- [DataType.Uint8]: 1,
56
- [DataType.Uint16]: 2,
57
- [DataType.Uint32]: 4,
58
- [DataType.Uint64]: 8,
59
-
60
- [DataType.Int8]: 1,
61
- [DataType.Int16]: 2,
62
- [DataType.Int32]: 4,
63
- [DataType.Int64]: 8,
64
-
65
- [DataType.Float32]: 4,
66
- [DataType.Float64]: 8
67
- };
68
-
69
51
  /**
70
52
  *
71
53
  * @param {DataType[]} types
@@ -234,6 +216,14 @@ export function RowFirstTableSpec(types, endianType = EndianType.BigEndian) {
234
216
  }
235
217
  }
236
218
 
219
+ /**
220
+ *
221
+ * @return {number}
222
+ */
223
+ RowFirstTableSpec.prototype.getColumnCount = function () {
224
+ return this.types.length;
225
+ }
226
+
237
227
  /**
238
228
  *
239
229
  * @param {RowFirstTableSpec} other
@@ -0,0 +1,21 @@
1
+ import { DataTypeIndices } from "./DataTypeIndices.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number} index
6
+ * @returns {DataType|undefined}
7
+ */
8
+ export function computeDataTypeByIndex(index) {
9
+ for (let type in DataTypeIndices) {
10
+ if (!DataTypeIndices.hasOwnProperty(type)) {
11
+ continue;
12
+ }
13
+
14
+ const typeIndex = DataTypeIndices[type];
15
+ if (typeIndex === index) {
16
+ return type;
17
+ }
18
+ }
19
+
20
+ return undefined;
21
+ }
@@ -0,0 +1,48 @@
1
+ import { RowFirstTableSpec } from "./RowFirstTableSpec.js";
2
+ import { computeDataTypeByIndex } from "./computeDataTypeByIndex.js";
3
+
4
+ /**
5
+ *
6
+ * @param {BinaryBuffer} buffer
7
+ * @param {RowFirstTable} table
8
+ */
9
+ function deserializeRowFirstTable(buffer, table) {
10
+
11
+
12
+ //read types
13
+ const numTypes = buffer.readUint16();
14
+ const types = [];
15
+ for (let i = 0; i < numTypes; i++) {
16
+ const typeIndex = buffer.readUint8();
17
+
18
+ const type = computeDataTypeByIndex(typeIndex);
19
+
20
+ if (type === undefined) {
21
+ throw new Error(`Unknown DataType index ${typeIndex}`);
22
+ }
23
+ types[i] = type;
24
+ }
25
+
26
+ //record size
27
+ const bytesPerRecord = buffer.readUint32();
28
+
29
+ //read number of records
30
+ const numRecords = buffer.readUint32();
31
+
32
+ const numDataBytes = bytesPerRecord * numRecords;
33
+ const data = new Uint8Array(numDataBytes);
34
+
35
+ //read data
36
+ buffer.readBytes(data, 0, numDataBytes);
37
+
38
+ //update table
39
+ table.spec = RowFirstTableSpec.get(types);
40
+ table.length = numRecords;
41
+ table.capacity = numRecords;
42
+ table.data = data.buffer;
43
+ table.dataView = new DataView(table.data);
44
+
45
+ table.initialize();
46
+ }
47
+
48
+ export { deserializeRowFirstTable };
@@ -0,0 +1,27 @@
1
+ import { DataTypeIndices } from "./DataTypeIndices.js";
2
+
3
+ /**
4
+ *
5
+ * @param {BinaryBuffer} buffer
6
+ * @param {RowFirstTable} table
7
+ */
8
+ function serializeRowFirstTable(buffer, table) {
9
+ //write types
10
+ buffer.writeUint16(table.types.length);
11
+ table.types.forEach(function (type) {
12
+ const typeIndex = DataTypeIndices[type];
13
+ buffer.writeUint8(typeIndex);
14
+ });
15
+
16
+ //write record length
17
+ buffer.writeUint32(table.bytesPerRecord);
18
+
19
+ //write number of records
20
+ buffer.writeUint32(table.length);
21
+
22
+ //write data
23
+ const numDataBytes = table.length * table.bytesPerRecord;
24
+ buffer.writeBytes(new Uint8Array(table.data), 0, numDataBytes);
25
+ }
26
+
27
+ export { serializeRowFirstTable };
@@ -407,6 +407,7 @@ Color.fromRGB = function (r, g, b) {
407
407
 
408
408
  Color.parse = function (str) {
409
409
  const r = new Color();
410
+
410
411
  r.parse(str);
411
412
 
412
413
  return r;
@@ -146,18 +146,21 @@ function int2rgb(value) {
146
146
  }
147
147
  }
148
148
 
149
+ const rgbRegEx = /rgb\(([0-9]+),\s*([0-9]+),\s*([0-9]+)\)/;
150
+ const hsvRegEx = /hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\)/;
151
+
149
152
  /**
150
153
  *
151
154
  * @param {string|number} c
152
155
  * @returns {number[]} Numeric array, values are in Uint range
153
156
  */
154
157
  export function parseColor(c) {
155
- const rgbRegEx = /rgb\(([0-9]+),\s*([0-9]+),\s*([0-9]+)\)/;
156
- const hsvRegEx = /hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\)/;
157
158
 
158
159
  const result = [];
159
160
 
160
- if (typeof c === "string") {
161
+ const type_of_code = typeof c;
162
+
163
+ if (type_of_code === "string") {
161
164
  const cL = c.toLowerCase();
162
165
 
163
166
  let match;
@@ -191,6 +194,12 @@ export function parseColor(c) {
191
194
  } else {
192
195
  throw new Error(`Failed to decode color string '${c}' `);
193
196
  }
197
+ } else if(type_of_code === 'number'){
198
+
199
+ result[0] = c >> 16;
200
+ result[1] = (c >> 8) & 0xFF;
201
+ result[2] = (c) & 0xFF;
202
+
194
203
  } else {
195
204
  throw new Error(`Failed to decode color '${c}'`);
196
205
  }
@@ -10,6 +10,7 @@
10
10
 
11
11
 
12
12
  /**
13
+ * NOTE: Consider using an optimized aabb projection method based on Jim Arvo's Graphics Gems algorithm: https://stackoverflow.com/a/58630206/3973586
13
14
  * Almost everything is inlined for speed
14
15
  * @param {number[]} aabb_corners
15
16
  * @param {number[]|mat4|Float32Array} projection_matrix
@@ -55,7 +56,7 @@ export function aabb3_project_to_2d(aabb_corners, projection_matrix) {
55
56
  const t_w = a3 * _x + b3 * _y + c3 * _z + d3;
56
57
 
57
58
  // perspective divide and normalization (-1,1 space projected to -0.5,0.5)
58
- const d = 0.5 / Math.abs(t_w);
59
+ const d = 0.5 / t_w;
59
60
 
60
61
  // finally compute screen-space coordinates of the corner
61
62
  const x = t_x * d;
@@ -64,13 +65,14 @@ export function aabb3_project_to_2d(aabb_corners, projection_matrix) {
64
65
  if (x0 > x) {
65
66
  x0 = x;
66
67
  }
67
- if (y0 > y) {
68
- y0 = y;
69
- }
70
68
 
71
69
  if (x1 < x) {
72
70
  x1 = x;
73
71
  }
72
+
73
+ if (y0 > y) {
74
+ y0 = y;
75
+ }
74
76
  if (y1 < y) {
75
77
  y1 = y;
76
78
  }