@woosh/meep-engine 2.33.5 → 2.33.10

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 (116) 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 +17 -0
  4. package/core/collection/RingBuffer.js +40 -10
  5. package/core/collection/array/typed/typed_array_copy.js +2 -2
  6. package/core/collection/set/compute_set_difference.js +32 -0
  7. package/core/collection/set/compute_set_intersection.js +22 -0
  8. package/core/collection/set/set_remove.js +15 -0
  9. package/core/collection/table/DataType2TypedArrayConstructorMapping.js +2 -0
  10. package/core/collection/table/DataTypeByteSizes.js +21 -0
  11. package/core/collection/table/RowFirstTable.js +1 -88
  12. package/core/collection/table/RowFirstTable.spec.js +3 -1
  13. package/core/collection/table/RowFirstTableSpec.js +1 -19
  14. package/core/collection/table/computeDataTypeByIndex.js +21 -0
  15. package/core/collection/table/deserializeRowFirstTable.js +48 -0
  16. package/core/collection/table/serializeRowFirstTable.js +27 -0
  17. package/core/color/Color.js +1 -0
  18. package/core/color/ColorUtils.js +12 -3
  19. package/core/geom/3d/aabb/aabb3_compute_projected_area.js +5 -4
  20. package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
  21. package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +96 -0
  22. package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
  23. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
  24. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
  25. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
  26. package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
  27. package/core/geom/3d/frustum/array_normalize_plane.js +25 -0
  28. package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +60 -0
  29. package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
  30. package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
  31. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
  32. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
  33. package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
  34. package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
  35. package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
  36. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
  37. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
  38. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
  39. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
  40. package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
  41. package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
  42. package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
  43. package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
  44. package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
  45. package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
  46. package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
  47. package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
  48. package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
  49. package/core/process/undo/ActionProcessor.d.ts +2 -0
  50. package/core/process/undo/ActionProcessor.js +59 -1
  51. package/core/process/undo/ActionProcessor.spec.js +59 -0
  52. package/core/process/undo/Mark.js +2 -1
  53. package/engine/Engine.d.ts +2 -0
  54. package/engine/EngineHarness.js +4 -4
  55. package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
  56. package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
  57. package/engine/ecs/foliage/InstancedFoliage.js +3 -5
  58. package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
  59. package/engine/ecs/transform/Transform.js +2 -1
  60. package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
  61. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
  62. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
  63. package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
  64. package/engine/graphics/{micron → geometry}/aabb3_to_buffer_geometry.js +0 -0
  65. package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
  66. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
  67. package/engine/graphics/material/SplatMaterial.js +4 -97
  68. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +2 -6
  69. package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
  70. package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
  71. package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
  72. package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
  73. package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
  74. package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
  75. package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
  76. package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
  77. package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
  78. package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
  79. package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
  80. package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
  81. package/engine/graphics/micron/format/MicronGeometry.js +12 -0
  82. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
  83. package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -9
  84. package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
  85. package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
  86. package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
  87. package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
  88. package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
  89. package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
  90. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +24 -8
  91. package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
  92. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +1 -1
  93. package/engine/graphics/micron/render/refinement/ActivePatchList.js +6 -25
  94. package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
  95. package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
  96. package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
  97. package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
  98. package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
  99. package/engine/graphics/render/forward_plus/data/TextureBackedMemoryRegion.js +1 -1
  100. package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
  101. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +11 -6
  102. package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
  103. package/engine/graphics/texture/cubemap/load_environment_map.js +29 -3
  104. package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
  105. package/engine/graphics/texture/sampler/TextureBinaryBufferSerializer.js +1 -1
  106. package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
  107. package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
  108. package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
  109. package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
  110. package/engine/network/convertPathToURL.js +7 -1
  111. package/engine/plugin/EnginePluginManager.d.ts +9 -0
  112. package/engine/reference/v2/Reference.d.ts +7 -0
  113. package/package.json +1 -1
  114. package/view/minimap/gl/MinimapMarkersGL.js +2 -2
  115. package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
  116. package/engine/graphics/micron/render/RefinementSpec.js +0 -181
@@ -3,13 +3,13 @@
3
3
  */
4
4
 
5
5
 
6
- import Vector4 from "../../../../core/geom/Vector4.js";
7
6
  import { clamp } from "../../../../core/math/clamp.js";
8
7
  import { max2 } from "../../../../core/math/max2.js";
9
8
  import { min2 } from "../../../../core/math/min2.js";
10
9
  import { mix } from "../../../../core/math/mix.js";
11
10
  import { BlendingType } from "./BlendingType.js";
12
11
  import { assert } from "../../../../core/assert.js";
12
+ import { typedArrayConstructorByInstance } from "./typedArrayConstructorByInstance.js";
13
13
 
14
14
  function v2CrossMag(ax, ay, bx, by) {
15
15
  return ax * by - ay * bx;
@@ -1319,8 +1319,8 @@ Sampler2D.prototype.fill = function (x, y, width, height, value) {
1319
1319
  * @param {number} value
1320
1320
  */
1321
1321
  Sampler2D.prototype.writeChannel = function (x, y, channel, value) {
1322
- assert.typeOf(x, "number", "x");
1323
- assert.typeOf(y, "number", "y");
1322
+ assert.isNumber(x, "x");
1323
+ assert.isNumber(y, "y");
1324
1324
 
1325
1325
  assert.greaterThanOrEqual(x, 0);
1326
1326
  assert.greaterThanOrEqual(y, 0);
@@ -1385,32 +1385,6 @@ Sampler2D.prototype.traverseCircle = function (centerX, centerY, radius, visitor
1385
1385
  }
1386
1386
  };
1387
1387
 
1388
- export function arrayConstructorByInstance(a) {
1389
- if (a instanceof Int8Array) {
1390
- return Int8Array;
1391
- } else if (a instanceof Int16Array) {
1392
- return Int16Array;
1393
- } else if (a instanceof Int32Array) {
1394
- return Int32Array;
1395
- } else if (a instanceof Uint8Array) {
1396
- return Uint8Array;
1397
- } else if (a instanceof Uint8ClampedArray) {
1398
- return Uint8ClampedArray;
1399
- } else if (a instanceof Uint16Array) {
1400
- return Uint16Array;
1401
- } else if (a instanceof Uint32Array) {
1402
- return Uint32Array;
1403
- } else if (a instanceof Float32Array) {
1404
- return Float32Array;
1405
- } else if (a instanceof Float64Array) {
1406
- return Float64Array;
1407
- } else if (Array.isArray(a)) {
1408
- return Array;
1409
- } else {
1410
- throw new TypeError(`Unsupported array type`);
1411
- }
1412
- }
1413
-
1414
1388
  /**
1415
1389
  *
1416
1390
  * @param {number} x
@@ -1419,31 +1393,40 @@ export function arrayConstructorByInstance(a) {
1419
1393
  */
1420
1394
  Sampler2D.prototype.resize = function (x, y, preserveData = true) {
1421
1395
 
1396
+ const _w = this.width;
1397
+ const _h = this.height;
1398
+
1399
+ if (_w === x && _h === y) {
1400
+ // size didn't change
1401
+ return;
1402
+ }
1403
+
1422
1404
  const itemSize = this.itemSize;
1405
+
1423
1406
  const length = x * y * itemSize;
1424
1407
 
1425
1408
  const oldData = this.data;
1426
1409
 
1427
- const Constructor = arrayConstructorByInstance(oldData);
1410
+ const Constructor = typedArrayConstructorByInstance(oldData);
1428
1411
 
1429
1412
  const newData = new Constructor(length);
1430
1413
 
1431
1414
  if (preserveData) {
1432
1415
  //copy old data
1433
- if (x === this.width) {
1416
+ if (x === _w) {
1434
1417
  // number of columns is preserved, we can just copy the old data across
1435
1418
  newData.set(oldData.subarray(0, Math.min(oldData.length, length)));
1436
1419
  } else {
1437
1420
  //we need to copy new data row-by-row
1438
- const rowCount = min2(y, this.height);
1421
+ const rowCount = min2(y, _h);
1439
1422
 
1440
- const columnCount = min2(x, this.width);
1423
+ const columnCount = min2(x, _w);
1441
1424
 
1442
1425
  for (let i = 0; i < rowCount; i++) {
1443
1426
  for (let j = 0; j < columnCount; j++) {
1444
1427
 
1445
1428
  const targetItemAddress = (i * x + j) * itemSize;
1446
- const sourceItemAddress = (i * this.width + j) * itemSize;
1429
+ const sourceItemAddress = (i * _w + j) * itemSize;
1447
1430
 
1448
1431
  for (let k = 0; k < itemSize; k++) {
1449
1432
 
@@ -1457,6 +1440,7 @@ Sampler2D.prototype.resize = function (x, y, preserveData = true) {
1457
1440
 
1458
1441
  this.width = x;
1459
1442
  this.height = y;
1443
+
1460
1444
  this.data = newData;
1461
1445
  };
1462
1446
 
@@ -1563,31 +1547,3 @@ Sampler2D.prototype.traverseOrthogonalNeighbours = function (x, y, visitor, this
1563
1547
  }
1564
1548
  };
1565
1549
 
1566
- /**
1567
- *
1568
- * @param {Sampler2D} sampler0
1569
- * @param {Sampler2D} sampler1
1570
- * @returns {Sampler2D}
1571
- */
1572
- export function differenceSampler(sampler0, sampler1) {
1573
- let v0 = new Vector4();
1574
- let v1 = new Vector4();
1575
- //
1576
- const width = sampler0.width;
1577
- const height = sampler0.height;
1578
- //
1579
- const difference = new Float32Array(width * height);
1580
- for (let y = 0; y < height; y++) {
1581
- for (let x = 0; x < width; x++) {
1582
- v0 = sampler0.get(x, y, v0);
1583
- v1 = sampler1.get(x, y, v1);
1584
- v0.normalize();
1585
- v1.normalize();
1586
- //check distance
1587
- difference[x + y * width] = 1 - v0.dot(v1);
1588
- }
1589
- }
1590
- //
1591
- const sampleD = new Sampler2D(difference, 1, width, height);
1592
- return sampleD;
1593
- }
@@ -2,8 +2,8 @@ import { DataTypeIndices } from "../../../../core/collection/table/DataTypeIndic
2
2
  import { Sampler2D } from "./Sampler2D.js";
3
3
  import { EndianType } from "../../../../core/binary/BinaryBuffer.js";
4
4
  import { DataType } from "../../../../core/collection/table/DataType.js";
5
- import { DataTypeByteSizes } from "../../../../core/collection/table/RowFirstTableSpec.js";
6
5
  import { assert } from "../../../../core/assert.js";
6
+ import { DataTypeByteSizes } from "../../../../core/collection/table/DataTypeByteSizes.js";
7
7
 
8
8
 
9
9
  /**
@@ -1,6 +1,7 @@
1
- import { arrayConstructorByInstance, Sampler2D } from "../Sampler2D.js";
1
+ import { Sampler2D } from "../Sampler2D.js";
2
2
  import { scaleSampler2D } from "../scaleSampler2D.js";
3
3
  import convertSampler2D2Canvas from "../Sampler2D2Canvas.js";
4
+ import { typedArrayConstructorByInstance } from "../typedArrayConstructorByInstance.js";
4
5
 
5
6
  /**
6
7
  *
@@ -14,7 +15,7 @@ export function paintSamplerOnHTML(s, x, y, scale, offset) {
14
15
 
15
16
  const d = 180;
16
17
 
17
- const target = new Sampler2D(arrayConstructorByInstance(s.data), s.itemSize, d, d);
18
+ const target = new Sampler2D(typedArrayConstructorByInstance(s.data), s.itemSize, d, d);
18
19
 
19
20
  scaleSampler2D(s, target);
20
21
 
@@ -0,0 +1,31 @@
1
+ import Vector4 from "../../../../core/geom/Vector4.js";
2
+ import { Sampler2D } from "./Sampler2D.js";
3
+
4
+ /**
5
+ *
6
+ * @param {Sampler2D} sampler0
7
+ * @param {Sampler2D} sampler1
8
+ * @returns {Sampler2D}
9
+ */
10
+ export function differenceSampler(sampler0, sampler1) {
11
+ let v0 = new Vector4();
12
+ let v1 = new Vector4();
13
+ //
14
+ const width = sampler0.width;
15
+ const height = sampler0.height;
16
+ //
17
+ const difference = new Float32Array(width * height);
18
+ for (let y = 0; y < height; y++) {
19
+ for (let x = 0; x < width; x++) {
20
+ v0 = sampler0.get(x, y, v0);
21
+ v1 = sampler1.get(x, y, v1);
22
+ v0.normalize();
23
+ v1.normalize();
24
+ //check distance
25
+ difference[x + y * width] = 1 - v0.dot(v1);
26
+ }
27
+ }
28
+ //
29
+ const sampleD = new Sampler2D(difference, 1, width, height);
30
+ return sampleD;
31
+ }
@@ -0,0 +1,25 @@
1
+ export function typedArrayConstructorByInstance(a) {
2
+ if (a instanceof Int8Array) {
3
+ return Int8Array;
4
+ } else if (a instanceof Int16Array) {
5
+ return Int16Array;
6
+ } else if (a instanceof Int32Array) {
7
+ return Int32Array;
8
+ } else if (a instanceof Uint8Array) {
9
+ return Uint8Array;
10
+ } else if (a instanceof Uint8ClampedArray) {
11
+ return Uint8ClampedArray;
12
+ } else if (a instanceof Uint16Array) {
13
+ return Uint16Array;
14
+ } else if (a instanceof Uint32Array) {
15
+ return Uint32Array;
16
+ } else if (a instanceof Float32Array) {
17
+ return Float32Array;
18
+ } else if (a instanceof Float64Array) {
19
+ return Float64Array;
20
+ } else if (Array.isArray(a)) {
21
+ return Array;
22
+ } else {
23
+ throw new TypeError(`Unsupported array type`);
24
+ }
25
+ }
@@ -1,6 +1,7 @@
1
- import { arrayConstructorByInstance, Sampler2D } from "../Sampler2D.js";
1
+ import { Sampler2D } from "../Sampler2D.js";
2
2
  import { scaleSampler2D } from "../scaleSampler2D.js";
3
3
  import convertSampler2D2Canvas from "../Sampler2D2Canvas.js";
4
+ import { typedArrayConstructorByInstance } from "../typedArrayConstructorByInstance.js";
4
5
 
5
6
  /**
6
7
  *
@@ -15,7 +16,7 @@ import convertSampler2D2Canvas from "../Sampler2D2Canvas.js";
15
16
  export function drawSamplerHTML(parentNode, sampler, x, y, scale, offset, size) {
16
17
 
17
18
 
18
- const target = new Sampler2D(arrayConstructorByInstance(sampler.data), sampler.itemSize, size, size);
19
+ const target = new Sampler2D(typedArrayConstructorByInstance(sampler.data), sampler.itemSize, size, size);
19
20
 
20
21
  scaleSampler2D(sampler, target);
21
22
 
@@ -11,8 +11,8 @@ function isGlobalPath(path) {
11
11
  }
12
12
 
13
13
  // *** Environment setup code ***
14
- const ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof require === 'function';
15
14
  const ENVIRONMENT_IS_WEB = typeof window === 'object';
15
+ const ENVIRONMENT_IS_NODE = typeof process === 'object' && !ENVIRONMENT_IS_WEB;
16
16
  const ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
17
17
  const ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
18
18
 
@@ -34,6 +34,12 @@ export function convertPathToURL(path) {
34
34
  scope = window;
35
35
  } else if (ENVIRONMENT_IS_WORKER) {
36
36
  scope = self;
37
+ } else if (ENVIRONMENT_IS_NODE) {
38
+ scope = {
39
+ location: new URL(import.meta.url)
40
+ };
41
+ } else {
42
+ throw new Error('Unknown environment');
37
43
  }
38
44
 
39
45
  const location = scope.location;
@@ -0,0 +1,9 @@
1
+ import {Reference} from "../reference/v2/Reference";
2
+
3
+ interface Type<T> extends Function {
4
+ new(...args: any[]): T;
5
+ }
6
+
7
+ export class EnginePluginManager {
8
+ acquire<T>(klass: Type<T>): Promise<Reference<T>>
9
+ }
@@ -0,0 +1,7 @@
1
+ export class Reference<T> {
2
+ getValue(): T | null
3
+
4
+ release(): void
5
+
6
+ bind(v: T): void
7
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "productName": "Meep",
5
5
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
6
6
  "author": "Alexander Goldring",
7
- "version": "2.33.5",
7
+ "version": "2.33.10",
8
8
  "dependencies": {
9
9
  "fast-levenshtein": "2.0.6",
10
10
  "opentype.js": "1.3.3",
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DataTexture,
3
- LinearFilter,
4
3
  LinearMipMapLinearFilter,
4
+ NearestFilter,
5
5
  NormalBlending,
6
6
  Points,
7
7
  RGBAFormat,
@@ -82,7 +82,7 @@ function buildMaterial() {
82
82
  dataTexture.flipY = false;
83
83
  dataTexture.generateMipmaps = true;
84
84
  dataTexture.minFilter = LinearMipMapLinearFilter;
85
- dataTexture.magFilter = LinearFilter;
85
+ dataTexture.magFilter = NearestFilter;
86
86
 
87
87
  const uniforms = {
88
88
  atlas: {
@@ -1,3 +0,0 @@
1
- export function cluster_mesh_vertices(mesh, max_face_count){
2
-
3
- }
@@ -1,181 +0,0 @@
1
- import Vector2 from "../../../../core/geom/Vector2.js";
2
- import { Matrix4 } from "three";
3
- import { mat4 } from "gl-matrix";
4
- import { v3_length } from "../../../../core/geom/Vector3.js";
5
-
6
- /**
7
- * Normalize a plane in-place
8
- * @param {number[]} source
9
- * @param {number} source_offset
10
- */
11
- function array_normalize_plane(source, source_offset) {
12
- const _x = source[source_offset];
13
- const _y = source[source_offset + 1];
14
- const _z = source[source_offset + 2];
15
-
16
- const length = v3_length(_x, _y, _z);
17
-
18
- const inverseNormalLength = 1.0 / length;
19
-
20
- /*
21
- By re-using values already in the registers instead of using *= we save a few extra READ ops
22
- */
23
- source[source_offset] = _x * inverseNormalLength;
24
- source[source_offset + 1] = _y * inverseNormalLength;
25
- source[source_offset + 2] = _z * inverseNormalLength;
26
-
27
- source[source_offset + 3] *= inverseNormalLength;
28
- }
29
-
30
- /**
31
- *
32
- * @param {number[]} destination
33
- * @param {number} destination_offset
34
- * @param {number} x
35
- * @param {number} y
36
- * @param {number} z
37
- * @param {number} w
38
- */
39
- function array_set_plane_normalized(destination, destination_offset, x, y, z, w) {
40
- const length = v3_length(x, y, z);
41
-
42
- const inverseNormalLength = 1.0 / length;
43
-
44
- destination[destination_offset] = x * inverseNormalLength;
45
- destination[destination_offset + 1] = y * inverseNormalLength;
46
- destination[destination_offset + 2] = z * inverseNormalLength;
47
- destination[destination_offset + 3] = w * inverseNormalLength;
48
- }
49
-
50
- /**
51
- *
52
- * @param {number[]|Float32Array} frustum_planes
53
- * @param {number[]} me
54
- */
55
- function array_setFromProjectionMatrix(frustum_planes, me) {
56
-
57
- const me0 = me[0];
58
- const me3 = me[3];
59
-
60
- const me4 = me[4];
61
- const me7 = me[7];
62
-
63
- const me8 = me[8];
64
- const me11 = me[11];
65
-
66
- const me12 = me[12];
67
- const me15 = me[15];
68
-
69
- array_set_plane_normalized(frustum_planes, 0, me3 - me0, me7 - me4, me11 - me8, me15 - me12);
70
- array_set_plane_normalized(frustum_planes, 4, me3 + me0, me7 + me4, me11 + me8, me15 + me12);
71
-
72
- const me1 = me[1];
73
- const me5 = me[5];
74
- const me9 = me[9];
75
- const me13 = me[13];
76
-
77
- array_set_plane_normalized(frustum_planes, 8, me3 + me1, me7 + me5, me11 + me9, me15 + me13);
78
- array_set_plane_normalized(frustum_planes, 12, me3 - me1, me7 - me5, me11 - me9, me15 - me13);
79
-
80
- const me2 = me[2];
81
- const me6 = me[6];
82
- const me10 = me[10];
83
- const me14 = me[14];
84
-
85
- array_set_plane_normalized(frustum_planes, 16, me3 - me2, me7 - me6, me11 - me10, me15 - me14);
86
- array_set_plane_normalized(frustum_planes, 20, me3 + me2, me7 + me6, me11 + me10, me15 + me14);
87
- }
88
-
89
- export class RefinementSpec {
90
- constructor() {
91
-
92
- /**
93
- * Viewport resolution
94
- * @type {Vector2}
95
- */
96
- this.resolution = new Vector2();
97
-
98
- /**
99
- * Number of pixels in the viewport
100
- * @type {number}
101
- */
102
- this.viewport_area = 0;
103
-
104
- /**
105
- * How much error to accept when deciding to subdivide a cluster
106
- * Measured in pixels
107
- * Higher value will result in better performance but more visible artifacts
108
- * @type {number}
109
- */
110
- this.error_threshold = 1;
111
-
112
- /**
113
- * Error threshold as a fraction of the screen area instead of pixels, derived internally from pixel value
114
- * @type {number}
115
- */
116
- this.error_threshold_normalized = 1;
117
-
118
- /**
119
- * Object-space camera frustum
120
- * Frustum planes in compact form
121
- * @type {Float32Array}
122
- */
123
- this.frustum_f32 = new Float32Array(24);
124
-
125
- /**
126
- * Model world transform
127
- * @type {Float32Array|number[]|mat4}
128
- */
129
- this.transform = new Float32Array(16);
130
-
131
- /**
132
- * Contains transformation from camera space to object space
133
- * @type {Float32Array|number[]|mat4}
134
- */
135
- this.projection_matrix = new Float32Array(16);
136
-
137
- /**
138
- * FOV in radians
139
- * @type {number}
140
- */
141
- this.focal_length = 0;
142
-
143
- /**
144
- * Object-space camera position
145
- * @type {Float32Array}
146
- */
147
- this.view_position = new Float32Array(3);
148
- }
149
-
150
- get frustum() {
151
- throw new Error('deprecated, use .frustum_f32 instead');
152
- }
153
-
154
- setResolution(x, y) {
155
- this.resolution.set(x, y);
156
-
157
- this.viewport_area = x * y;
158
-
159
- this.error_threshold_normalized = this.error_threshold / this.viewport_area;
160
- }
161
-
162
- /**
163
- *
164
- * @param {Matrix4} transform world-space object transform
165
- * @param {Matrix4} matrix_world_inverse camera's world inverse matrix
166
- * @param {Matrix4} matrix_projection camera's projection matrix
167
- */
168
- build(transform, matrix_world_inverse, matrix_projection) {
169
- const _transform = this.transform;
170
- _transform.set(transform.elements);
171
-
172
- // build projection matrix
173
- const projection_matrix = this.projection_matrix;
174
-
175
- mat4.multiply(projection_matrix, matrix_world_inverse.elements, _transform);
176
- mat4.multiply(projection_matrix, matrix_projection.elements, projection_matrix);
177
-
178
- // compute view frustum in model-space
179
- array_setFromProjectionMatrix(this.frustum_f32, projection_matrix);
180
- }
181
- }