@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
@@ -1,6 +1,6 @@
1
1
  import { DataType } from "../../../../core/collection/table/DataType.js";
2
- import { DataTypeByteSizes } from "../../../../core/collection/table/RowFirstTableSpec.js";
3
2
  import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
3
+ import { DataTypeByteSizes } from "../../../../core/collection/table/DataTypeByteSizes.js";
4
4
 
5
5
  export class MicronGeometryBufferAttributeSpec {
6
6
  constructor() {
@@ -40,8 +40,8 @@ export class MicronGeometryBufferAttributeSpec {
40
40
  equals(other) {
41
41
  return this.type === other.type
42
42
  && this.itemSize === other.itemSize
43
- && this.name === other.name
44
43
  && this.normalized === other.normalized
44
+ && this.name === other.name
45
45
  ;
46
46
  }
47
47
 
@@ -13,22 +13,36 @@ 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
+
16
23
  /**
17
24
  * Bounds are used to determine screen error and whether a patch should be subdivided or not for rendering
18
25
  * @type {number[]}
19
26
  */
20
- this.bounding_box = new Float32Array(6);
27
+ this.bounding_box = new Float32Array(array_buffer, 0, 6);
28
+
29
+ /**
30
+ *
31
+ * @type {vec4|number[]}
32
+ */
33
+ this.bounding_sphere = vec4.create()
21
34
 
22
35
  /**
23
36
  *
24
37
  * @type {number[]|Float32Array}
25
38
  */
26
- this.group_bounding_box = new Float32Array(6);
39
+ this.group_bounding_box = new Float32Array(array_buffer, 6 * 4, 6);
40
+
27
41
  /**
28
42
  *
29
43
  * @type {number[]|Float32Array}
30
44
  */
31
- this.group_bounding_box_corners = new Float32Array(24);
45
+ this.group_bounding_box_corners = new Float32Array(array_buffer, 12 * 4, 24);
32
46
 
33
47
  /**
34
48
  *
@@ -42,12 +56,6 @@ export class MicronGeometryPatch {
42
56
  */
43
57
  this.group_error = 0;
44
58
 
45
- /**
46
- *
47
- * @type {vec4}
48
- */
49
- this.bounding_sphere = vec4.create()
50
-
51
59
  /**
52
60
  *
53
61
  * @type {MicronGeometryPatch[]}
@@ -2,6 +2,8 @@ import { isArrayEqual } from "../../../../core/collection/ArrayUtils.js";
2
2
  import { computeHashArray } from "../../../../core/math/MathUtils.js";
3
3
  import { invokeObjectHash } from "../../../../core/model/object/invokeObjectHash.js";
4
4
 
5
+ const DEFAULT_HASH = 123456;
6
+
5
7
  export class MicronVertexDataSpec {
6
8
  constructor() {
7
9
  /**
@@ -12,9 +14,21 @@ export class MicronVertexDataSpec {
12
14
 
13
15
  /**
14
16
  *
15
- * @type {RowFirstTableSpec|null}
17
+ * @type {number}
18
+ * @private
16
19
  */
17
- this.data = null;
20
+ this.__hash = DEFAULT_HASH;
21
+ }
22
+
23
+ /**
24
+ *
25
+ * @param {MicronGeometryBufferAttributeSpec[]} attributes
26
+ */
27
+ setAttributes(attributes) {
28
+ this.attributes = attributes;
29
+
30
+ // reset hash to trigger hash update
31
+ this.__hash = DEFAULT_HASH;
18
32
  }
19
33
 
20
34
  /**
@@ -30,10 +44,18 @@ export class MicronVertexDataSpec {
30
44
  return isArrayEqual(this.attributes, other.attributes);
31
45
  }
32
46
 
33
- hash() {
47
+ computeHash() {
34
48
  return computeHashArray(this.attributes, invokeObjectHash);
35
49
  }
36
50
 
51
+ hash() {
52
+ if (this.__hash === DEFAULT_HASH) {
53
+ this.__hash = this.computeHash();
54
+ }
55
+
56
+ return this.__hash;
57
+ }
58
+
37
59
  /**
38
60
  *
39
61
  * @param {string} name
@@ -0,0 +1,101 @@
1
+ import { BinaryClassSerializationAdapter } from "../../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
2
+ import { MicronGeometry } from "../MicronGeometry.js";
3
+ import { MicronGeometryBufferAttributeSpec } from "../MicronGeometryBufferAttributeSpec.js";
4
+ import { MicronGeometryPatch } from "../MicronGeometryPatch.js";
5
+ import { serialize_patch } from "./serialize_patch.js";
6
+ import { deserialize_patch } from "./deserialize_patch.js";
7
+ import { serialize_attribute_spec } from "./serialize_attribute_spec.js";
8
+ import { deserialize_attribute_spec } from "./deserialize_attribute_spec.js";
9
+
10
+ export class MicronGeometryBinarySerializationAdapter extends BinaryClassSerializationAdapter {
11
+ constructor() {
12
+ super();
13
+
14
+ this.klass = MicronGeometry;
15
+ this.version = 0;
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @param {BinaryBuffer} buffer
21
+ * @param {MicronGeometry} value
22
+ */
23
+ serialize(buffer, value) {
24
+ const spec = value.vertex_spec;
25
+
26
+ // serialize vertex spec
27
+ const attributes = spec.attributes;
28
+ const attribute_count = attributes.length;
29
+ buffer.writeUintVar(attribute_count);
30
+ for (let i = 0; i < attribute_count; i++) {
31
+ const attribute = attributes[i];
32
+
33
+ serialize_attribute_spec(buffer, attribute);
34
+ }
35
+
36
+ // serialize patches
37
+
38
+ /**
39
+ *
40
+ * @type {MicronGeometryPatch[]}
41
+ */
42
+ const patches = value.patches;
43
+ const patch_count = patches.length;
44
+
45
+ const root_patch_index = patches.indexOf(value.root);
46
+
47
+ buffer.writeUintVar(root_patch_index);
48
+
49
+ buffer.writeUintVar(patch_count);
50
+
51
+ for (let i = 0; i < patch_count; i++) {
52
+ serialize_patch(buffer, patches[i], spec, patches);
53
+ }
54
+ }
55
+
56
+ /**
57
+ *
58
+ * @param {BinaryBuffer} buffer
59
+ * @param {MicronGeometry} value
60
+ */
61
+ deserialize(buffer, value) {
62
+ // read spec
63
+ const attribute_count = buffer.readUintVar();
64
+ const attributes = [];
65
+ for (let i = 0; i < attribute_count; i++) {
66
+ const spec = new MicronGeometryBufferAttributeSpec();
67
+
68
+ deserialize_attribute_spec(buffer, spec);
69
+ attributes[i] = spec;
70
+ }
71
+
72
+ const vertex_spec = value.vertex_spec;
73
+ vertex_spec.setAttributes(attributes);
74
+
75
+ // read patches
76
+ const root_patch_index = buffer.readUintVar();
77
+
78
+ const patch_count = buffer.readUintVar();
79
+
80
+ const patches = [];
81
+
82
+ // build initial patches
83
+ for (let i = 0; i < patch_count; i++) {
84
+ const patch = new MicronGeometryPatch();
85
+
86
+ patch.id = i;
87
+
88
+ patches[i] = patch;
89
+ }
90
+
91
+ //read patches
92
+ for (let i = 0; i < patch_count; i++) {
93
+ const patch = patches[i];
94
+
95
+ deserialize_patch(buffer, patch, vertex_spec, patches);
96
+ }
97
+
98
+ value.patches = patches;
99
+ value.root = patches[root_patch_index];
100
+ }
101
+ }
@@ -0,0 +1,25 @@
1
+ import { computeDataTypeByIndex } from "../../../../../core/collection/table/computeDataTypeByIndex.js";
2
+
3
+ /**
4
+ *
5
+ * @param {BinaryBuffer} buffer
6
+ * @param {MicronGeometryBufferAttributeSpec} spec
7
+ */
8
+ export function deserialize_attribute_spec(buffer, spec) {
9
+
10
+ spec.name = buffer.readUTF8String();
11
+ spec.itemSize = buffer.readUintVar();
12
+
13
+ const type_index = buffer.readUint8();
14
+ const type = computeDataTypeByIndex(type_index);
15
+
16
+ if (type === undefined) {
17
+ throw new Error(`Unknown data type marker '${type_index}'`);
18
+ }
19
+
20
+ spec.type = type;
21
+
22
+ const flags = buffer.readUint8();
23
+
24
+ spec.normalized = (flags & 0x1) !== 0;
25
+ }
@@ -0,0 +1,104 @@
1
+ import { aabb3_build_corners } from "../../../../../core/geom/3d/aabb/aabb3_build_corners.js";
2
+ import { DataTypeByteSizes } from "../../../../../core/collection/table/DataTypeByteSizes.js";
3
+ import { DataType2TypedArrayConstructorMapping } from "../../../../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
4
+
5
+ /**
6
+ *
7
+ * @param {BinaryBuffer} buffer
8
+ * @param {MicronGeometryPatch} patch
9
+ * @param {MicronVertexDataSpec} vertex_spec
10
+ * @param {MicronGeometryPatch[]} patch_array
11
+ */
12
+ export function deserialize_patch(buffer, patch, vertex_spec, patch_array) {
13
+ // METADATA
14
+ buffer.readFloat32Array(patch.bounding_box, 0, 6);
15
+ buffer.readFloat32Array(patch.bounding_sphere, 0, 4);
16
+
17
+ const gbb = patch.group_bounding_box;
18
+ buffer.readFloat32Array(gbb, 0, 6);
19
+ buffer.readFloat32Array(patch.group_bounding_sphere, 0, 4);
20
+
21
+ // reconstruct corners
22
+ aabb3_build_corners(
23
+ patch.group_bounding_box_corners,
24
+ 0,
25
+ gbb[0],
26
+ gbb[1],
27
+ gbb[2],
28
+ gbb[3],
29
+ gbb[4],
30
+ gbb[5]
31
+ );
32
+
33
+ patch.group_error = buffer.readFloat32();
34
+ patch.lod = buffer.readUintVar();
35
+ patch.polygon_count = buffer.readUintVar();
36
+ patch.vertex_count = buffer.readUintVar();
37
+
38
+ // parents
39
+ const parents = [];
40
+ const parent_count = buffer.readUintVar();
41
+
42
+ for (let i = 0; i < parent_count; i++) {
43
+ const parent_index = buffer.readUintVar();
44
+
45
+ if (patch_array.length <= parent_index || parent_index < 0) {
46
+ throw new Error(`out of bounds parent index '${parent_index}'`);
47
+ }
48
+
49
+ parents[i] = patch_array[parent_index];
50
+ }
51
+
52
+ patch.parents = parents;
53
+
54
+ // children
55
+ const children = [];
56
+ const child_count = buffer.readUintVar();
57
+
58
+ for (let i = 0; i < child_count; i++) {
59
+ const child_index = buffer.readUintVar();
60
+
61
+ if (patch_array.length <= child_index || child_index < 0) {
62
+ throw new Error(`out of bounds child index '${child_index}'`);
63
+ }
64
+
65
+ children[i] = patch_array[child_index];
66
+ }
67
+
68
+ patch.children = children;
69
+
70
+ // INDICES
71
+ const index_count = patch.polygon_count * 3;
72
+
73
+ if (patch.vertex_count <= 256) {
74
+ patch.face_indices = new Uint8Array(index_count);
75
+ buffer.readUint8Array(patch.face_indices, 0, index_count);
76
+ } else if (patch.vertex_count <= 65536) {
77
+ patch.face_indices = new Uint16Array(index_count);
78
+ buffer.readUint16Array(patch.face_indices, 0, index_count);
79
+ } else {
80
+ throw new Error(`Unsupported vertex count '${patch.vertex_count}'`);
81
+ }
82
+
83
+ // VERTICES
84
+ const attributes = vertex_spec.attributes;
85
+ const attribute_count = attributes.length;
86
+
87
+ for (let i = 0; i < attribute_count; i++) {
88
+ const spec = attributes[i];
89
+
90
+ const data_type = spec.type;
91
+ const item_size = spec.itemSize;
92
+
93
+ const byte_size = DataTypeByteSizes[data_type];
94
+
95
+ const ArrayConstructor = DataType2TypedArrayConstructorMapping[data_type];
96
+
97
+ const elment_count = item_size * patch.vertex_count;
98
+ const array = new ArrayConstructor(elment_count);
99
+
100
+ buffer.readUint8Array(new Uint8Array(array.buffer), 0, byte_size * elment_count);
101
+
102
+ patch.vertex_attribute_arrays[i] = array;
103
+ }
104
+ }
@@ -0,0 +1,18 @@
1
+ import { DataTypeIndices } from "../../../../../core/collection/table/DataTypeIndices.js";
2
+
3
+ /**
4
+ *
5
+ * @param {BinaryBuffer} buffer
6
+ * @param {MicronGeometryBufferAttributeSpec} spec
7
+ */
8
+ export function serialize_attribute_spec(buffer, spec) {
9
+ buffer.writeUTF8String(spec.name);
10
+ buffer.writeUintVar(spec.itemSize);
11
+
12
+ const dataTypeIndex = DataTypeIndices[spec.type];
13
+ buffer.writeUint8(dataTypeIndex);
14
+
15
+ const flags = spec.normalized ? 1 : 0;
16
+
17
+ buffer.writeUint8(flags);// flags
18
+ }
@@ -0,0 +1,84 @@
1
+ import { DataTypeByteSizes } from "../../../../../core/collection/table/DataTypeByteSizes.js";
2
+
3
+ /**
4
+ *
5
+ * @param {BinaryBuffer} buffer
6
+ * @param {MicronGeometryPatch} patch
7
+ * @param {MicronVertexDataSpec} vertex_spec
8
+ * @param {MicronGeometryPatch[]} patch_array
9
+ */
10
+ export function serialize_patch(buffer, patch, vertex_spec, patch_array) {
11
+ // METADATA
12
+ buffer.writeFloat32Array(patch.bounding_box, 0, 6);
13
+ buffer.writeFloat32Array(patch.bounding_sphere, 0, 4);
14
+
15
+ buffer.writeFloat32Array(patch.group_bounding_box, 0, 6);
16
+ buffer.writeFloat32Array(patch.group_bounding_sphere, 0, 4);
17
+
18
+ buffer.writeFloat32(patch.group_error);
19
+ buffer.writeUintVar(patch.lod);
20
+ buffer.writeUintVar(patch.polygon_count);
21
+ buffer.writeUintVar(patch.vertex_count);
22
+
23
+ // write parents
24
+ const parents = patch.parents;
25
+ const parent_count = parents.length;
26
+
27
+ buffer.writeUintVar(parent_count);
28
+
29
+ for (let i = 0; i < parent_count; i++) {
30
+ const parent = parents[i];
31
+
32
+ const parent_index = patch_array.indexOf(parent);
33
+
34
+ if (parent_index === -1) {
35
+ throw new Error(`Patch '${parent.id}' not found in the lookup table`);
36
+ }
37
+
38
+ buffer.writeUintVar(parent_index);
39
+ }
40
+
41
+ // write children
42
+ const children = patch.children;
43
+ const child_count = children.length;
44
+
45
+ buffer.writeUintVar(child_count);
46
+
47
+ for (let i = 0; i < child_count; i++) {
48
+ const child = children[i];
49
+
50
+ const child_index = patch_array.indexOf(child);
51
+
52
+ if (child_index === -1) {
53
+ throw new Error(`Patch '${child.id}' not found in the lookup table`);
54
+ }
55
+
56
+ buffer.writeUintVar(child_index);
57
+ }
58
+
59
+ // INDICES
60
+ if (patch.vertex_count <= 256) {
61
+ buffer.writeUint8Array(patch.face_indices, 0, patch.polygon_count * 3);
62
+ } else if (patch.vertex_count <= 65536) {
63
+ buffer.writeUint16Array(patch.face_indices, 0, patch.polygon_count * 3);
64
+ } else {
65
+ throw new Error(`Unsupported vertex count '${patch.vertex_count}'`);
66
+ }
67
+
68
+ // VERTICES
69
+ const attributes = vertex_spec.attributes;
70
+ const attribute_count = attributes.length;
71
+
72
+ for (let i = 0; i < attribute_count; i++) {
73
+ const spec = attributes[i];
74
+
75
+ const data_type = spec.type;
76
+ const item_size = spec.itemSize;
77
+
78
+ const byte_size = DataTypeByteSizes[data_type];
79
+
80
+ const attribute_values = patch.vertex_attribute_arrays[i];
81
+
82
+ buffer.writeUint8Array(new Uint8Array(attribute_values.buffer), 0, item_size * byte_size * patch.vertex_count);
83
+ }
84
+ }
@@ -535,7 +535,7 @@ function createScene(geometry, m1, scale) {
535
535
  geometry.computeVertexNormals();
536
536
 
537
537
 
538
- const grid_size = 10;
538
+ const grid_size = 100;
539
539
  const grid_spacing = 2000;
540
540
 
541
541
  for (let i = 0; i < grid_size; i++) {
@@ -2,19 +2,33 @@ import { Frustum, Matrix4 } from "three";
2
2
  import { array_copy } from "../../../../core/collection/array/copyArray.js";
3
3
  import Vector2 from "../../../../core/geom/Vector2.js";
4
4
  import { MicronGeometryPatchOccurrence } from "../format/MicronGeometryPatchOccurance.js";
5
- import { RefinementSpec } from "./RefinementSpec.js";
5
+ import { RefinementSpec } from "./refinement/RefinementSpec.js";
6
6
  import { ActivePatchList } from "./refinement/ActivePatchList.js";
7
7
  import { ActivePatchFlags } from "./refinement/ActivePatchFlags.js";
8
8
 
9
-
9
+ /**
10
+ * @readonly
11
+ * @type {RefinementSpec}
12
+ */
10
13
  const refinement_spec = new RefinementSpec();
11
14
 
12
15
  export class VirtualGeometryBuilder {
13
16
  constructor() {
14
17
  this.view_projection_matrix = new Matrix4();
15
- this.matrix_projection = new Matrix4();
18
+
19
+ /**
20
+ *
21
+ * @type {Float32Array|number[]|mat4}
22
+ */
23
+ this.matrix_projection = new Float32Array(16);
24
+
16
25
  this.matrix_projection_inverse = new Matrix4();
17
- this.matrix_world_inverse = new Matrix4();
26
+
27
+ /**
28
+ *
29
+ * @type {Float32Array|number[]|mat4}
30
+ */
31
+ this.matrix_world_inverse = new Float32Array(16);
18
32
 
19
33
  /**
20
34
  *
@@ -48,10 +62,10 @@ export class VirtualGeometryBuilder {
48
62
 
49
63
  /**
50
64
  *
51
- * @type {WeakMap<ThreeMicronMesh, ActivePatchList>}
65
+ * @type {ActivePatchList}
52
66
  * @private
53
67
  */
54
- this.__acls = new WeakMap();
68
+ this.__acl = new ActivePatchList();
55
69
 
56
70
  /**
57
71
  * How much error to accept when deciding to subdivide a cluster
@@ -76,12 +90,8 @@ export class VirtualGeometryBuilder {
76
90
  this.__flags__enforce_dependency_splits = true;
77
91
  }
78
92
 
79
- /**
80
- * Drop all cached data, forcing a complete rebuild next time
81
- * Useful for testing and debugging
82
- */
83
93
  dropCache() {
84
- this.__acls = new WeakMap();
94
+ this.__acl.clear();
85
95
  }
86
96
 
87
97
  /**
@@ -102,8 +112,10 @@ export class VirtualGeometryBuilder {
102
112
  camera.updateMatrixWorld(true);
103
113
 
104
114
  this.view_projection_matrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
105
- this.matrix_world_inverse.copy(camera.matrixWorldInverse);
106
- this.matrix_projection.copy(camera.projectionMatrix);
115
+
116
+ this.matrix_world_inverse.set(camera.matrixWorldInverse.elements);
117
+ this.matrix_projection.set(camera.projectionMatrix.elements);
118
+
107
119
  this.matrix_projection_inverse.copy(camera.projectionMatrixInverse);
108
120
 
109
121
  this.view_frustum.setFromProjectionMatrix(this.view_projection_matrix);
@@ -137,15 +149,7 @@ export class VirtualGeometryBuilder {
137
149
  const micron_geometry = object.geometry;
138
150
  if (micron_geometry !== undefined) {
139
151
  // get acl
140
-
141
- const acls = this.__acls;
142
-
143
- let acl = acls.get(object);
144
-
145
- if (acl === undefined) {
146
- acl = new ActivePatchList();
147
- acls.set(object, acl);
148
- }
152
+ const acl = this.__acl;
149
153
 
150
154
  acl.initializeFromGeometry(micron_geometry);
151
155
 
@@ -182,7 +186,7 @@ export class VirtualGeometryBuilder {
182
186
  apl
183
187
  ) {
184
188
 
185
- refinement_spec.build(transform, this.matrix_world_inverse, this.matrix_projection);
189
+ refinement_spec.build(transform.elements, this.matrix_world_inverse, this.matrix_projection);
186
190
 
187
191
  const output = this.output;
188
192
 
@@ -49,7 +49,7 @@ function buildExecutor() {
49
49
 
50
50
  const MAX_PATCH_COUNT = 60000;
51
51
 
52
- export class PathCullingSystem {
52
+ export class PatchCullingSystem {
53
53
  constructor() {
54
54
  /**
55
55
  *
@@ -2,14 +2,12 @@ import { assert } from "../../../../../core/assert.js";
2
2
  import { MICRON_PATCH_SIZE_MAX } from "../../build/MICRON_PATCH_SIZE_MAX.js";
3
3
  import { typed_array_copy } from "../../../../../core/collection/array/typed/typed_array_copy.js";
4
4
  import { channelCountToThreeTextureFormat } from "../../../texture/channelCountToThreeTextureFormat.js";
5
- import {
6
- computeThreeTextureInternalFormatFromDataType,
7
- computeThreeTextureTypeFromDataType
8
- } from "../../../render/forward_plus/TextureBackedMemoryRegion.js";
9
5
  import { DataTexture, NearestFilter } from "three";
10
- import { DataTypeByteSizes } from "../../../../../core/collection/table/RowFirstTableSpec.js";
11
6
  import { DataType } from "../../../../../core/collection/table/DataType.js";
12
7
  import { compute_micron_buffer_array_constructor } from "../../build/compute_micron_buffer_array_constructor.js";
8
+ import { computeThreeTextureTypeFromDataType } from "../../../render/forward_plus/data/computeThreeTextureTypeFromDataType.js";
9
+ import { computeThreeTextureInternalFormatFromDataType } from "../../../render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js";
10
+ import { DataTypeByteSizes } from "../../../../../core/collection/table/DataTypeByteSizes.js";
13
11
 
14
12
  /**
15
13
  *