@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
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @param {Uint8Array} input
3
+ * @param {number} width
4
+ * @param {number} height
5
+ * @param {number} channel_count
6
+ */
7
+ export function flipArrayInPlace(input, width, height, channel_count = 4) {
8
+ const rowLength = width * channel_count;
9
+ let t, x0, x1;
10
+ let i = 0;
11
+ const l = height >> 1;
12
+
13
+ for (; i < l; i++) {
14
+ //swap lines
15
+ const k = (height - i - 1) * rowLength;
16
+ const m = i * rowLength;
17
+ for (let j = 0; j < rowLength; j++) {
18
+ x0 = m + j;
19
+ x1 = k + j;
20
+ t = input[x0];
21
+ input[x0] = input[x1];
22
+ input[x1] = t;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,13 @@
1
+ function flipArrayViaCanvas(input, width, height) {
2
+ const canvas = document.createElement("canvas");
3
+ const c = canvas.getContext('2d');
4
+ const imageData = c.createImageData(width, height);
5
+ imageData.data.set(input);
6
+ c.putImageData(imageData, 0, 0);
7
+ c.translate(0, height);
8
+ c.scale(1, -1);
9
+ c.drawImage(canvas, 0, 0);
10
+ const imgd = c.getImageData(0, 0, width, height);
11
+
12
+ return imgd.data;
13
+ }
@@ -3,59 +3,25 @@
3
3
  */
4
4
 
5
5
 
6
- import {
7
- LinearFilter,
8
- Mesh,
9
- OrthographicCamera,
10
- PlaneBufferGeometry,
11
- Scene,
12
- ShaderMaterial,
13
- WebGLRenderTarget
14
- } from 'three';
15
-
16
- export function flipArrayInPlace(input, width, height) {
17
- const rowLength = width * 4;
18
- let t, x0, x1;
19
- let i = 0;
20
- const l = height >> 1;
21
- for (; i < l; i++) {
22
- //swap lines
23
- const k = (height - i - 1) * rowLength;
24
- const m = i * rowLength;
25
- for (let j = 0; j < rowLength; j++) {
26
- x0 = m + j;
27
- x1 = k + j;
28
- t = input[x0];
29
- input[x0] = input[x1];
30
- input[x1] = t;
31
- }
32
- }
33
- }
34
-
35
- function flipArrayViaCanvas(input, width, height) {
36
- const canvas = document.createElement("canvas");
37
- const c = canvas.getContext('2d');
38
- const imageData = c.createImageData(width, height);
39
- imageData.data.set(input);
40
- c.putImageData(imageData, 0, 0);
41
- c.translate(0, height);
42
- c.scale(1, -1);
43
- c.drawImage(canvas, 0, 0);
44
- const imgd = c.getImageData(0, 0, width, height);
45
-
46
- return imgd.data;
47
- }
6
+ import { LinearFilter, Mesh, OrthographicCamera, Scene, ShaderMaterial, WebGLRenderTarget } from 'three';
7
+ import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
48
8
 
49
9
  /**
50
10
  *
51
11
  * @param {WebGLRenderer} renderer
52
12
  * @param {number} width
53
13
  * @param {number} height
54
- * @param processShader
14
+ * @param {{vertexShader:string,fragmentShader:string, uniforms?:Object, defines?:Object}} processShader
55
15
  * @param {Uint8Array} [destination]
56
16
  * @return {{array: Uint8Array, renderer: WebGLRenderer}}
57
17
  */
58
- function processTexture(renderer, width, height, processShader, destination) {
18
+ function processTexture(
19
+ renderer,
20
+ width,
21
+ height,
22
+ processShader,
23
+ destination
24
+ ) {
59
25
  if (destination === undefined) {
60
26
  destination = new Uint8Array(width * height * 4);
61
27
  }
@@ -72,9 +38,10 @@ function processTexture(renderer, width, height, processShader, destination) {
72
38
  material.lights = false;
73
39
  material.fog = false;
74
40
 
75
- const quad = new Mesh(new PlaneBufferGeometry(2, 2), material);
41
+ const quad = new Mesh(FULL_SCREEN_TRIANGLE_GEOMETRY, material);
76
42
 
77
43
  scene.add(quad);
44
+
78
45
  //render
79
46
  const renderTargetOptions = {
80
47
  generateMipmaps: false,
@@ -82,28 +49,30 @@ function processTexture(renderer, width, height, processShader, destination) {
82
49
  stencilBuffer: false,
83
50
  depthBuffer: false
84
51
  };
52
+
85
53
  const renderTarget = new WebGLRenderTarget(width, height, renderTargetOptions);
86
54
 
55
+ const __rt = renderer.getRenderTarget(); // remember old renderer state
56
+
87
57
  renderer.setRenderTarget(renderTarget);
88
58
 
89
59
  renderer.render(scene, camera);
90
60
 
91
61
  const gl = renderer.getContext();
62
+
92
63
  //void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView? pixels)
93
64
  gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, destination);
94
65
 
95
- renderer.setRenderTarget(null);
66
+ // restore renderer state
67
+ renderer.setRenderTarget(__rt);
96
68
 
97
- //reorder lines in the buffer to make Y axis match
98
-
99
- //uint8Array = flipArrayViaCanvas(uint8Array, width, height);
100
- //
69
+ // cleanup resources
101
70
  renderTarget.dispose();
102
71
  material.dispose();
72
+
103
73
  return {
104
74
  array: destination,
105
75
  graphics: renderer
106
- //renderTarget: renderTarget
107
76
  };
108
77
  }
109
78
 
@@ -8,6 +8,7 @@ import {
8
8
  import ThreeFactory from "../../three/ThreeFactory.js";
9
9
  import { StaticMaterialCache } from "../../../asset/loaders/material/StaticMaterialCache.js";
10
10
  import { composeCompile } from "../../material/composeCompile.js";
11
+ import { typed_array_copy } from "../../../../core/collection/array/typed/typed_array_copy.js";
11
12
 
12
13
  /**
13
14
  *
@@ -29,14 +30,14 @@ function InstancedMeshGroup() {
29
30
  * Minimum spare capacity increase during growing
30
31
  * @type {number}
31
32
  */
32
- this.growConstant = 1;
33
+ this.growConstant = 4;
33
34
 
34
- this.shrinkFactor = 0.8;
35
+ this.shrinkFactor = 0.5;
35
36
  /**
36
37
  * Minimum capacity reduction for shrinkage to occur
37
38
  * @type {number}
38
39
  */
39
- this.shrinkConstant = 32;
40
+ this.shrinkConstant = 64;
40
41
 
41
42
  /**
42
43
  *
@@ -217,14 +218,30 @@ InstancedMeshGroup.prototype.setCapacity = function (size) {
217
218
  * @param {number} size
218
219
  */
219
220
  InstancedMeshGroup.prototype.ensureCapacity = function (size) {
221
+
220
222
  const currentCapacity = this.capacity;
223
+
221
224
  if (currentCapacity < size) {
222
- const newCapacityRaw = Math.max(size, currentCapacity * this.growFactor, currentCapacity + this.growConstant);
225
+ // grow
226
+
227
+ const newCapacityRaw = Math.max(
228
+ size,
229
+ currentCapacity * this.growFactor,
230
+ currentCapacity + this.growConstant
231
+ );
232
+
223
233
  const newCapacityInteger = Math.ceil(newCapacityRaw);
234
+
224
235
  this.setCapacity(newCapacityInteger);
225
- } else if (currentCapacity * this.shrinkFactor > size && currentCapacity - this.shrinkConstant > size) {
236
+
237
+ } else if (
238
+ currentCapacity * this.shrinkFactor > size
239
+ && currentCapacity - this.shrinkConstant > size
240
+ ) {
241
+ // shrink
226
242
  this.setCapacity(size);
227
243
  }
244
+
228
245
  };
229
246
 
230
247
  /**
@@ -375,14 +392,6 @@ InstancedMeshGroup.prototype.remove = function (reference) {
375
392
  this.setCount(this.count - 1);
376
393
  };
377
394
 
378
- /**
379
- * @param {Uint8Array|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array} source
380
- * @param {Uint8Array|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array}target
381
- */
382
- function copyArray(source, target) {
383
- target.set(source.subarray(0, Math.min(target.length, source.length)), 0)
384
- }
385
-
386
395
  InstancedMeshGroup.prototype.build = function () {
387
396
  if (this.__threeGeometry !== null) {
388
397
  // dispose old geometry's GPU memory
@@ -415,16 +424,16 @@ InstancedMeshGroup.prototype.build = function () {
415
424
  if (this.__attributePosition !== null) {
416
425
  //copy old data
417
426
  const oldPositionArray = this.__attributePosition.array;
418
- copyArray(oldPositionArray, newPositionArray);
427
+ typed_array_copy(oldPositionArray, newPositionArray);
419
428
  }
420
429
  if (this.__attributeRotation !== null) {
421
430
  //copy old data
422
431
  const oldRotationArray = this.__attributeRotation.array;
423
- copyArray(oldRotationArray, newRotationArray);
432
+ typed_array_copy(oldRotationArray, newRotationArray);
424
433
  }
425
434
  if (this.__attributeScale !== null) {
426
435
  const oldScaleArray = this.__attributeScale.array;
427
- copyArray(oldScaleArray, newScaleArray);
436
+ typed_array_copy(oldScaleArray, newScaleArray);
428
437
 
429
438
  if (newScaleArray.length > oldScaleArray.length) {
430
439
  //fill the rest of the array with scale factor of 1 as a default
@@ -4,7 +4,7 @@
4
4
  import {
5
5
  ClampToEdgeWrapping,
6
6
  Color,
7
- DoubleSide,
7
+ FrontSide,
8
8
  GLSL3,
9
9
  LinearFilter,
10
10
  NormalBlending,
@@ -15,95 +15,10 @@ import {
15
15
  Vector4 as ThreeVector4
16
16
  } from 'three';
17
17
  import TerrainShader from "../shaders/TerrainShader.js";
18
- import Vector4 from "../../../core/geom/Vector4.js";
19
18
  import { Sampler2D } from "../texture/sampler/Sampler2D.js";
20
19
  import sampler2D2Texture from "../texture/sampler/Sampler2D2Texture.js";
21
20
 
22
- /**
23
- *
24
- * @param {Vector4} tex0
25
- * @param {Vector4} tex1
26
- * @param {Vector4} tex2
27
- * @param {Vector4} tex3
28
- * @param {Vector4} splat
29
- * @param {Vector4} result
30
- */
31
- export function blendSplatTextures(tex0, tex1, tex2, tex3, splat, result) {
32
- const b0 = splat.x;
33
- const b1 = splat.y;
34
- const b2 = splat.z;
35
- const b3 = splat.w;
36
-
37
- const bT = b0 + b1 + b2 + b3;
38
-
39
-
40
- result.set(
41
- (tex0.x * b0 + tex1.x * b1 + tex2.x * b2 + tex3.x * b3) / bT,
42
- (tex0.y * b0 + tex1.y * b1 + tex2.y * b2 + tex3.y * b3) / bT,
43
- (tex0.z * b0 + tex1.z * b1 + tex2.z * b2 + tex3.z * b3) / bT,
44
- (tex0.w * b0 + tex1.w * b1 + tex2.w * b2 + tex3.w * b3) / bT
45
- );
46
- }
47
-
48
- /**
49
- *
50
- * @param {Sampler2D[]} diffuse
51
- * @param {Vector2} diffuseRepeat
52
- * @param {Sampler2D} splat
53
- * @param {Vector2} gridSize
54
- * @param {Vector2} resultTextureSize
55
- * @returns {Sampler2D}
56
- */
57
- export function buildTerrainTexture({ diffuse, diffuseRepeat, splat, gridSize, resultTextureSize }) {
58
- const texture0 = diffuse[0];
59
- const texture1 = diffuse[1];
60
- const texture2 = diffuse[2];
61
- const texture3 = diffuse[3];
62
-
63
- const resultData = new Uint8Array(resultTextureSize.x * resultTextureSize.y * 4);
64
-
65
- const result = new Sampler2D(resultData, 4, resultTextureSize.x, resultTextureSize.y);
66
-
67
- //do the splatting
68
- let x, y, u, v;
69
-
70
- const tex0 = new Vector4(0, 0, 0, 0);
71
- const tex1 = new Vector4(0, 0, 0, 0);
72
- const tex2 = new Vector4(0, 0, 0, 0);
73
- const tex3 = new Vector4(0, 0, 0, 0);
74
-
75
- const vSplat = new Vector4(0, 0, 0, 0);
76
-
77
- const vTemp = new Vector4(0, 0, 0, 0);
78
-
79
- for (x = 0; x < resultTextureSize.x; x++) {
80
-
81
- u = x / (resultTextureSize.x - 1);
82
-
83
- for (y = 0; y < resultTextureSize.y; y++) {
84
-
85
- v = y / (resultTextureSize.y - 1);
86
-
87
- const dU = (u * diffuseRepeat.x) % 1;
88
- const dV = (v * diffuseRepeat.y) % 1;
89
-
90
- texture0.sample(dU, dV, tex0);
91
- texture1.sample(dU, dV, tex1);
92
- texture2.sample(dU, dV, tex2);
93
- texture3.sample(dU, dV, tex3);
94
-
95
- splat.sample(u, v, vSplat);
96
-
97
- blendSplatTextures(tex0, tex1, tex2, tex3, vSplat, vTemp);
98
-
99
- result.set(x, y, [vTemp.x, vTemp.y, vTemp.z, 255]);
100
- }
101
- }
102
-
103
- return result;
104
- }
105
-
106
- function whitePixelTexture() {
21
+ export function whitePixelTexture() {
107
22
  const sampler = Sampler2D.uint8(4, 1, 1);
108
23
 
109
24
  for (let i = 0; i < sampler.data.length; i++) {
@@ -205,17 +120,12 @@ export function SplatMaterial(
205
120
  uniforms.gridResolution.value.set(gridResolution.x, gridResolution.y);
206
121
  }
207
122
 
208
-
209
- //this is for the water shader, so that back of the terrain reflects in the water, otherwise edges of shoreline look odd
210
- //TODO check how this can be removed, it would speed water(and ordinary) rendering if back faces could be culled
211
- const side = DoubleSide;
212
-
213
123
  const sm = new ShaderMaterial({
214
124
 
215
125
  uniforms: uniforms,
216
126
  vertexShader: TerrainShader.vertexShader,
217
127
  fragmentShader: TerrainShader.fragmentShader,
218
- side: side,
128
+ side: FrontSide,
219
129
  blending: NormalBlending,
220
130
  depthTest: true,
221
131
  depthWrite: true,
@@ -249,11 +159,8 @@ export function SplatMaterial(
249
159
  sm.aoMap = true;
250
160
  uniforms.aoMap.value = lightMap;
251
161
  uniforms.aoMapIntensity.value = 0.7;
252
- //
253
- // sm.lightMap = true;
254
- // uniforms.lightMap.value = options.lightMap;
255
- // uniforms.lightMapIntensity.value = 1;
256
162
  }
163
+
257
164
  sm.extensions.derivatives = true; //needed for rendering grid
258
165
  sm.needsUpdate = true;
259
166
 
@@ -4,7 +4,6 @@ import { MicronGeometry } from "../format/MicronGeometry.js";
4
4
  import { buildAbstractPatchHierarchy } from "./hierarchy/buildAbstractPatchHierarchy.js";
5
5
  import { MicronGeometryBufferAttributeSpec } from "../format/MicronGeometryBufferAttributeSpec.js";
6
6
  import { typedArrayToDataType } from "../../../../core/collection/array/typedArrayToDataType.js";
7
- import { RowFirstTableSpec } from "../../../../core/collection/table/RowFirstTableSpec.js";
8
7
  import { DataType } from "../../../../core/collection/table/DataType.js";
9
8
  import { MicronGeometryPatch } from "../format/MicronGeometryPatch.js";
10
9
  import { build_clustering_info } from "./debug/build_clustering_info.js";
@@ -12,7 +11,7 @@ import { build_graph_info } from "./debug/build_graph_info.js";
12
11
  import { expandConnectivityByLocality } from "../../../../core/geom/3d/topology/expandConnectivityByLocality.js";
13
12
  import { build_geometry_info } from "./build_geometry_info.js";
14
13
  import { build_leaf_patches_metis } from "./clustering/build_leaf_patches_metis.js";
15
- import { compute_buffer_geometry_byte_size } from "./compute_buffer_geometry_byte_size.js";
14
+ import { compute_buffer_geometry_byte_size } from "../../geometry/buffered/compute_buffer_geometry_byte_size.js";
16
15
 
17
16
 
18
17
  /**
@@ -202,11 +201,8 @@ export async function buildMicronGeometryFromBufferGeometry(input) {
202
201
  // console.time('build geometry');
203
202
 
204
203
  const vertex_attributes = attributes_from_buffer_geometry(input);
205
- const data_types = buildVertexDataTypeMap(vertex_attributes);
206
- const vertex_data_spec = RowFirstTableSpec.get(data_types);
207
204
 
208
- r.vertex_spec.data = vertex_data_spec;
209
- r.vertex_spec.attributes = vertex_attributes;
205
+ r.vertex_spec.setAttributes(vertex_attributes);
210
206
  r.root = compilePatchGraph(root, input, r.vertex_spec);
211
207
 
212
208
  r.initialize();
@@ -1,6 +1,6 @@
1
1
  import FastBinaryHeap from "../../../../navigation/grid/FastBinaryHeap.js";
2
- import { mn_graph_collapse_weighted_edge } from "../graph/mn_graph_collapse_weighted_edge.js";
3
- import { build_face_graph_from_mesh } from "../graph/build_face_graph_from_mesh.js";
2
+ import { mn_graph_collapse_weighted_edge } from "../../../../../core/graph/mn_graph_collapse_weighted_edge.js";
3
+ import { build_face_graph_from_mesh } from "../../../../../core/graph/build_face_graph_from_mesh.js";
4
4
 
5
5
  /**
6
6
  *
@@ -1,4 +1,4 @@
1
- import { cluster_mesh_metis } from "./cluster_mesh_metis.js";
1
+ import { cluster_mesh_metis } from "../../../../../core/graph/cluster_mesh_metis.js";
2
2
  import { MICRON_PATCH_SIZE_MAX } from "../MICRON_PATCH_SIZE_MAX.js";
3
3
  import { PatchRepresentation } from "../PatchRepresentation.js";
4
4
  import { TopoMesh } from "../../../../../core/geom/3d/topology/TopoMesh.js";
@@ -198,6 +198,8 @@ export function fill_patch_geometry_data(result, buffer_geometry, topo, vertex_d
198
198
  const micron_attributes = vertex_data_spec.attributes;
199
199
  const attribute_count = micron_attributes.length;
200
200
 
201
+ //TODO create a single ArrayBuffer for all attributes to get better cache coherence for rendering
202
+
201
203
  for (let i = 0; i < attribute_count; i++) {
202
204
  const attribute_spec = micron_attributes[i];
203
205
 
@@ -1,11 +1,11 @@
1
1
  import { Graph } from "../../../../../core/graph/v2/Graph.js";
2
- import { MultiNode } from "../graph/MultiNode.js";
2
+ import { MultiNode } from "../../../../../core/graph/MultiNode.js";
3
3
  import { merge_patches } from "./merge_patches.js";
4
- import { coarsen_graph } from "../graph/coarsen_graph.js";
4
+ import { coarsen_graph } from "../../../../../core/graph/coarsen_graph.js";
5
5
  import { build_merge_graph } from "./build_merge_graph.js";
6
6
  import { assign_patch_neighbours_from_topology } from "../clustering/assign_patch_neighbours_from_topology.js";
7
7
  import { assert } from "../../../../../core/assert.js";
8
- import { graph_create_off_mesh_links } from "../graph/build_face_graph_from_mesh.js";
8
+ import { graph_create_off_mesh_links } from "../../../../../core/graph/build_face_graph_from_mesh.js";
9
9
  import { build_vertex_quadratics } from "../../../../../core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.js";
10
10
 
11
11
  /**
@@ -2,78 +2,6 @@ import { simplifyTopoMesh } from "../../../../../core/geom/3d/topology/simplify/
2
2
  import { MICRON_PATCH_SIZE_MAX } from "../MICRON_PATCH_SIZE_MAX.js";
3
3
 
4
4
 
5
- /**
6
- * @template T
7
- * @returns Set<T>
8
- * @param {Set<T>} a
9
- * @param {Set<T>} b
10
- */
11
- export function compute_set_intersection(a, b) {
12
- const result = new Set();
13
-
14
- const a_array = Array.from(a);
15
-
16
- const n = a_array.length;
17
- for (let i = 0; i < n; i++) {
18
- const t = a_array[i];
19
-
20
- if (b.has(t)) {
21
- result.add(t);
22
- }
23
- }
24
-
25
- return result;
26
- }
27
-
28
- /**
29
- * @template T
30
- * @returns Set<T>
31
- * @param {Set<T>} a
32
- * @param {Set<T>} b
33
- */
34
- export function compute_set_difference(a, b) {
35
- const result = new Set();
36
-
37
- const a_array = Array.from(a);
38
- const a_count = a_array.length;
39
- for (let i = 0; i < a_count; i++) {
40
- const t = a_array[i];
41
-
42
- if (!b.has(t)) {
43
- result.add(t);
44
- }
45
- }
46
-
47
- const b_array = Array.from(b);
48
- const b_count = b_array.length;
49
- for (let i = 0; i < b_count; i++) {
50
- const t = b_array[i];
51
-
52
- if (!a.has(t)) {
53
- result.add(t);
54
- }
55
- }
56
-
57
-
58
- return result;
59
- }
60
-
61
- /**
62
- * @template T
63
- * @param {Set<T>} a
64
- * @param {Set<T>} b
65
- */
66
- export function set_remove(a, b) {
67
- const bs = Array.from(b);
68
-
69
- const n = bs.length;
70
- for (let i = 0; i < n; i++) {
71
- const t = bs[i];
72
-
73
- a.delete(t);
74
- }
75
- }
76
-
77
5
  /**
78
6
  *
79
7
  * @param {Set<number>} result
@@ -1,7 +1,7 @@
1
1
  import { Graph } from "../../../../../core/graph/v2/Graph.js";
2
- import { MultiNode } from "../graph/MultiNode.js";
2
+ import { MultiNode } from "../../../../../core/graph/MultiNode.js";
3
3
  import { computePatchMergeScore } from "./computePatchMergeScore.js";
4
- import { WeightedEdge } from "../graph/WeightedEdge.js";
4
+ import { WeightedEdge } from "../../../../../core/graph/WeightedEdge.js";
5
5
  import { assert } from "../../../../../core/assert.js";
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import { ConicRay } from "../../../../../core/geom/ConicRay.js";
2
- import { compute_bounding_cone_of_2_cones } from "../bounds/compute_bounding_cone_of_2_cones.js";
2
+ import { compute_bounding_cone_of_2_cones } from "../../../../../core/geom/3d/compute_bounding_cone_of_2_cones.js";
3
3
  import { compute_patches_shared_vertex_count } from "./compute_patches_shared_vertex_count.js";
4
- import { compute_bounding_sphere_of_2_spheres } from "../bounds/compute_bounding_sphere_of_2_spheres.js";
4
+ import { compute_bounding_sphere_of_2_spheres } from "../../../../../core/geom/3d/compute_bounding_sphere_of_2_spheres.js";
5
5
  import { max2 } from "../../../../../core/math/max2.js";
6
6
  import { min2 } from "../../../../../core/math/min2.js";
7
7
 
@@ -58,7 +58,7 @@ const pi_sqr = 9.86960440109;
58
58
 
59
59
  /**
60
60
  *
61
- * @param {number} r
61
+ * @param {number} r radius
62
62
  * @return {number}
63
63
  */
64
64
  function compute_sphere_volume(r) {
@@ -9,12 +9,15 @@ import { collapse_edges, extract_edge_cost } from "../../../../../core/geom/3d/t
9
9
  import { build_edge_collapse_candidates } from "../../../../../core/geom/3d/topology/simplify/build_edge_collapse_candidates.js";
10
10
  import { collapse_all_degenerate_edges } from "../../../../../core/geom/3d/topology/simplify/collapse_all_degenerate_edges.js";
11
11
  import { deep_copy_vertex_quadratics } from "../../../../../core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.js";
12
- import { SquareMatrix } from "../graph/SquareMatrix.js";
12
+ import { SquareMatrix } from "../../../../../core/graph/SquareMatrix.js";
13
13
  import { DataType } from "../../../../../core/collection/table/DataType.js";
14
- import { matrix_eigenvalues_in_place } from "../graph/eigen/eigen.js";
14
+ import { matrix_eigenvalues_in_place } from "../../../../../core/graph/eigen/eigen.js";
15
15
  import { min2 } from "../../../../../core/math/min2.js";
16
16
  import { PatchRepresentation } from "../PatchRepresentation.js";
17
- import { build_face_graph_from_mesh, graph_create_off_mesh_links } from "../graph/build_face_graph_from_mesh.js";
17
+ import {
18
+ build_face_graph_from_mesh,
19
+ graph_create_off_mesh_links
20
+ } from "../../../../../core/graph/build_face_graph_from_mesh.js";
18
21
  import { optimize_graph_partitioning_balance_detailed } from "./optimize_graph_partitioning_balance.js";
19
22
  import { patch_build_parent } from "./patch_combine.js";
20
23
  import { array_copy } from "../../../../../core/collection/array/copyArray.js";
@@ -1,6 +1,6 @@
1
1
  //
2
2
 
3
- import { metis_cluster_bs } from "../clustering/cluster_mesh_metis.js";
3
+ import { metis_cluster_bs } from "../../../../../core/graph/cluster_mesh_metis.js";
4
4
 
5
5
  /**
6
6
  *
@@ -1,4 +1,4 @@
1
- import { graph_k_means_cluster_detailed } from "../graph/graph_k_means_cluster.js";
1
+ import { graph_k_means_cluster_detailed } from "../../../../../core/graph/graph_k_means_cluster.js";
2
2
  import { array_remove_first } from "../../../../../core/collection/array/array_remove_first.js";
3
3
 
4
4
  /**
@@ -4,8 +4,8 @@ import { array_copy_unique } from "../../../../../core/collection/array/array_co
4
4
  import { array_remove_first } from "../../../../../core/collection/array/array_remove_first.js";
5
5
  import { max2 } from "../../../../../core/math/max2.js";
6
6
  import { array_push_if_unique } from "../../../../../core/collection/array/array_push_if_unique.js";
7
- import { compute_bounding_sphere_of_2_spheres } from "../bounds/compute_bounding_sphere_of_2_spheres.js";
8
- import { compute_bounding_cone_of_2_cones } from "../bounds/compute_bounding_cone_of_2_cones.js";
7
+ import { compute_bounding_sphere_of_2_spheres } from "../../../../../core/geom/3d/compute_bounding_sphere_of_2_spheres.js";
8
+ import { compute_bounding_cone_of_2_cones } from "../../../../../core/geom/3d/compute_bounding_cone_of_2_cones.js";
9
9
  import { ConicRay } from "../../../../../core/geom/ConicRay.js";
10
10
  import { passThrough } from "../../../../../core/function/Functions.js";
11
11
 
@@ -1,13 +1,14 @@
1
1
  import { array_push_if_unique } from "../../../../../core/collection/array/array_push_if_unique.js";
2
2
  import FastBinaryHeap from "../../../../navigation/grid/FastBinaryHeap.js";
3
3
  import { build_vertex_quadratics } from "../../../../../core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.js";
4
- import { compute_set_intersection, compute_set_of_border_vertex_indices } from "./build_intermediate_patch_topology.js";
4
+ import { compute_set_of_border_vertex_indices } from "./build_intermediate_patch_topology.js";
5
5
  import { compute_patches_shared_vertices } from "./compute_patches_shared_vertices.js";
6
6
  import { max2 } from "../../../../../core/math/max2.js";
7
7
  import { MICRON_PATCH_SIZE_MAX } from "../MICRON_PATCH_SIZE_MAX.js";
8
8
  import { collapse_edges, extract_edge_cost } from "../../../../../core/geom/3d/topology/simplify/simplifyTopoMesh.js";
9
9
  import { build_edge_collapse_candidates } from "../../../../../core/geom/3d/topology/simplify/build_edge_collapse_candidates.js";
10
10
  import { collapse_all_degenerate_edges } from "../../../../../core/geom/3d/topology/simplify/collapse_all_degenerate_edges.js";
11
+ import { compute_set_intersection } from "../../../../../core/collection/set/compute_set_intersection.js";
11
12
 
12
13
  /**
13
14
  * Cluster must share at least this many vertices for the vertex boundary constraint to be relaxed and allow them to be made dependent on each other
@@ -55,6 +55,18 @@ export class MicronGeometry {
55
55
  this.__proxy = null;
56
56
  }
57
57
 
58
+ get patches() {
59
+ return this.__patches;
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @param {MicronGeometryPatch[]} v
65
+ */
66
+ set patches(v) {
67
+ this.__patches = v;
68
+ }
69
+
58
70
  /**
59
71
  * @param {THREE.BufferGeometry} geometry
60
72
  */