@woosh/meep-engine 2.33.2 → 2.33.6

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 (98) hide show
  1. package/core/bvh2/aabb3/AABB3.js +18 -0
  2. package/core/bvh2/aabb3/aabb3_intersects_frustum.js +38 -0
  3. package/core/collection/RingBuffer.js +40 -10
  4. package/core/collection/array/copyArray.js +2 -2
  5. package/core/collection/array/typed/typed_array_copy.js +2 -2
  6. package/core/collection/table/RowFirstTableSpec.js +8 -0
  7. package/core/geom/3d/aabb/aabb3_compute_projected_area.js +16 -14
  8. package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
  9. package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
  10. package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -0
  11. package/core/geom/3d/plane/plane3_lerp.js +2 -2
  12. package/core/geom/3d/topology/TopoTriangle.js +2 -2
  13. package/core/geom/AABB2.d.ts +2 -0
  14. package/core/geom/Matrix4.js +4 -4
  15. package/core/geom/Vector3.js +5 -5
  16. package/core/model/reactive/model/terminal/ReactiveReference.js +7 -1
  17. package/core/process/undo/ActionProcessor.d.ts +2 -0
  18. package/core/process/undo/ActionProcessor.js +59 -1
  19. package/core/process/undo/ActionProcessor.spec.js +59 -0
  20. package/core/process/undo/Mark.js +2 -1
  21. package/engine/asset/loaders/GLTFAssetLoader.js +3 -3
  22. package/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +11 -1
  23. package/engine/asset/loaders/material/TextureAttachment.js +12 -1
  24. package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
  25. package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
  26. package/engine/asset/loaders/material/computeTextureEquality.js +1 -1
  27. package/engine/asset/loaders/material/computeTextureHash.js +16 -14
  28. package/engine/asset/loaders/material/traverseMaterialTextures.js +2 -2
  29. package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +2 -2
  30. package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +4 -4
  31. package/engine/graphics/GraphicsEngine.d.ts +2 -2
  32. package/engine/graphics/GraphicsEngine.js +20 -62
  33. package/engine/graphics/filter/FlipArrayInPlace.js +25 -0
  34. package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
  35. package/engine/graphics/filter/ImageFilter.js +20 -51
  36. package/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +2 -2
  37. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
  38. package/engine/graphics/material/SplatMaterial.js +4 -97
  39. package/engine/graphics/material/optimization/MaterialOptimizationContext.js +598 -0
  40. package/engine/graphics/micron/build/PatchRepresentation.js +4 -43
  41. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +4 -75
  42. package/engine/graphics/micron/build/compute_buffer_geometry_byte_size.js +16 -0
  43. package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
  44. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
  45. package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -5
  46. package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
  47. package/engine/graphics/micron/prototypeVirtualGeometry.js +19 -12
  48. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +34 -27
  49. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
  50. package/engine/graphics/micron/render/instanced/PatchDataTextures.js +1 -0
  51. package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +1 -29
  52. package/engine/graphics/micron/render/refinement/ActivePatchList.js +43 -159
  53. package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
  54. package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
  55. package/engine/graphics/micron/render/refinement/array_normalize_plane.js +25 -0
  56. package/engine/graphics/micron/render/refinement/array_setFromProjectionMatrix.js +60 -0
  57. package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +43 -0
  58. package/engine/graphics/micron/render/refinement/is_patch_visible.js +37 -0
  59. package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
  60. package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
  61. package/engine/graphics/micron/util/unit_hemioct.spec.js +2 -2
  62. package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
  63. package/engine/graphics/render/buffer/buffers/NormalFrameBuffer.js +12 -2
  64. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
  65. package/engine/graphics/render/forward_plus/LightManager.js +5 -7
  66. package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
  67. package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
  68. package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
  69. package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
  70. package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
  71. package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
  72. package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
  73. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  74. package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
  75. package/engine/graphics/render/utils/ThreeBypassRenderer.js +1 -3
  76. package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
  77. package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
  78. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
  79. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +435 -0
  80. package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
  81. package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
  82. package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
  83. package/engine/graphics/texture/atlas/TextureAtlas.js +1 -1
  84. package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
  85. package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
  86. package/engine/graphics/texture/cubemap/load_environment_map.js +163 -0
  87. package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
  88. package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +8 -4
  89. package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
  90. package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
  91. package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
  92. package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
  93. package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
  94. package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
  95. package/package.json +1 -1
  96. package/view/elements/progress/segmented/SegmentedResourceBarView.js +50 -15
  97. package/view/minimap/gl/MinimapMarkersGL.js +2 -2
  98. package/engine/graphics/micron/render/RefinementSpec.js +0 -110
@@ -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