@woosh/meep-engine 2.108.2 → 2.108.4

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 (122) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +490 -193
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +490 -193
  5. package/package.json +1 -1
  6. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts +6 -0
  7. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts.map +1 -1
  8. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +15 -3
  9. package/src/core/bvh2/bvh3/build_triangle_morton_codes.js +3 -3
  10. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts.map +1 -1
  11. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +25 -14
  12. package/src/core/collection/array/arrayQuickSort.d.ts +0 -9
  13. package/src/core/collection/array/arrayQuickSort.d.ts.map +1 -1
  14. package/src/core/collection/array/arrayQuickSort.js +0 -73
  15. package/src/core/collection/array/array_quick_sort_by_comparator.d.ts +10 -0
  16. package/src/core/collection/array/array_quick_sort_by_comparator.d.ts.map +1 -0
  17. package/src/core/collection/array/array_quick_sort_by_comparator.js +75 -0
  18. package/src/core/collection/array/array_quick_sort_by_lookup.d.ts +8 -0
  19. package/src/core/collection/array/array_quick_sort_by_lookup.d.ts.map +1 -0
  20. package/src/core/collection/array/array_quick_sort_by_lookup.js +78 -0
  21. package/src/core/geom/2d/triangle2d_get_barycentric.d.ts +15 -0
  22. package/src/core/geom/2d/triangle2d_get_barycentric.d.ts.map +1 -0
  23. package/src/core/geom/2d/triangle2d_get_barycentric.js +48 -0
  24. package/src/core/geom/3d/aabb/aabb3_from_v3_array.d.ts.map +1 -1
  25. package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +2 -7
  26. package/src/core/geom/3d/aabb3_compute_from_triangle.d.ts +11 -0
  27. package/src/core/geom/3d/aabb3_compute_from_triangle.d.ts.map +1 -0
  28. package/src/core/geom/3d/aabb3_compute_from_triangle.js +43 -0
  29. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +5 -5
  30. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts +9 -0
  31. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts.map +1 -0
  32. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.js +17 -0
  33. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +6 -3
  34. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  35. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +56 -18
  36. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts +1 -1
  37. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts.map +1 -1
  38. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.js +11 -4
  39. package/src/core/geom/3d/tetrahedra/{GetDepthForTetrahedronProbe.glsl → triangle/GetDepthForTetrahedronProbe.glsl} +17 -10
  40. package/src/core/geom/3d/tetrahedra/triangle/prototype.d.ts +2 -0
  41. package/src/core/geom/3d/tetrahedra/triangle/prototype.d.ts.map +1 -0
  42. package/src/core/geom/3d/tetrahedra/triangle/prototype.js +128 -0
  43. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts +13 -0
  44. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts.map +1 -0
  45. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.js +120 -0
  46. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts +3 -0
  47. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts.map +1 -0
  48. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.js +106 -0
  49. package/src/core/math/factorial.d.ts +7 -0
  50. package/src/core/math/factorial.d.ts.map +1 -0
  51. package/src/core/math/factorial.js +15 -0
  52. package/src/core/math/factorial.spec.d.ts +2 -0
  53. package/src/core/math/factorial.spec.d.ts.map +1 -0
  54. package/src/core/math/factorial.spec.js +9 -0
  55. package/src/core/model/DebouncedObservedBoolean.d.ts +1 -1
  56. package/src/core/model/DebouncedObservedBoolean.d.ts.map +1 -1
  57. package/src/core/model/node-graph/node/NodeDescription.d.ts +6 -4
  58. package/src/engine/asset/loaders/material/computeTextureEquality.d.ts.map +1 -1
  59. package/src/engine/asset/loaders/material/computeTextureEquality.js +8 -1
  60. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.d.ts.map +1 -1
  61. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +3 -1
  62. package/src/engine/graphics/filter/sampler2d_flipY_in_place.d.ts +8 -0
  63. package/src/engine/graphics/filter/sampler2d_flipY_in_place.d.ts.map +1 -0
  64. package/src/engine/graphics/filter/{FlipArrayInPlace.js → sampler2d_flipY_in_place.js} +1 -1
  65. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.d.ts.map +1 -1
  66. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.js +5 -27
  67. package/src/engine/graphics/render/Lines.d.ts.map +1 -1
  68. package/src/engine/graphics/render/Lines.js +10 -2
  69. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts +24 -0
  70. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts.map +1 -0
  71. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.js +293 -0
  72. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.d.ts +6 -0
  73. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.d.ts.map +1 -0
  74. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.js +71 -0
  75. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.d.ts +6 -0
  76. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.d.ts.map +1 -0
  77. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.js +256 -0
  78. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.js +4 -4
  79. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts +3 -1
  80. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
  81. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +12 -1
  82. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts +2 -1
  83. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts.map +1 -1
  84. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.js +6 -6
  85. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts +8 -0
  86. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -1
  87. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +3 -2
  88. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
  89. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +9 -4
  90. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +3 -3
  91. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  92. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +2 -2
  93. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.d.ts +2 -2
  94. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.d.ts.map +1 -1
  95. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.js +18 -8
  96. package/src/engine/graphics/sh3/prototypeSH3Probe.js +51 -22
  97. package/src/engine/graphics/texture/AttributeDataTexture.d.ts.map +1 -1
  98. package/src/engine/graphics/texture/AttributeDataTexture.js +8 -2
  99. package/src/engine/graphics/texture/computeThreeTextureFormat.js +2 -1
  100. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.d.ts +7 -0
  101. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.d.ts.map +1 -0
  102. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.js +13 -0
  103. package/src/engine/graphics/texture/formatToChannelCount.d.ts.map +1 -1
  104. package/src/engine/graphics/texture/formatToChannelCount.js +8 -1
  105. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.d.ts +9 -0
  106. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.d.ts.map +1 -0
  107. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.js +31 -0
  108. package/src/engine/graphics/texture/sampler/Sampler2D.js +2 -2
  109. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
  110. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +47 -19
  111. package/src/engine/graphics/texture/sampler/debug/prototypeSamplerFiltering.js +5 -33
  112. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.d.ts +11 -0
  113. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.d.ts.map +1 -0
  114. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.js +41 -0
  115. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts +0 -4
  116. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts.map +1 -1
  117. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.js +19 -30
  118. package/src/engine/graphics/filter/FlipArrayInPlace.d.ts +0 -8
  119. package/src/engine/graphics/filter/FlipArrayInPlace.d.ts.map +0 -1
  120. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts +0 -3
  121. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts.map +0 -1
  122. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.js +0 -3
@@ -0,0 +1,17 @@
1
+ import { factorial } from "../../../../math/factorial.js";
2
+
3
+ /**
4
+ * computes K(m,l) normalization constant
5
+ * @see "Deringing Spherical Harmonics" by Peter-Pike Sloan
6
+ * @param {number} m
7
+ * @param {number} l
8
+ * @returns {number}
9
+ */
10
+ export function sh_compute_K(m, l) {
11
+
12
+ const a = (2 * l + 1) * factorial(l - Math.abs(m))
13
+
14
+ const b = 4 * Math.PI * factorial(l + Math.abs(m))
15
+
16
+ return Math.sqrt(a / b);
17
+ }
@@ -209,11 +209,14 @@ export class TetrahedralMesh {
209
209
  removeTetrasConnectedToPoints(range_start: number, range_end: number): void;
210
210
  /**
211
211
  *
212
- * @param {number[]} points
213
- * @param {number} index
212
+ * @param {number} x
213
+ * @param {number} y
214
+ * @param {number} z
215
+ * @param {number[]} points Positions of vertices of tetrahedrons
216
+ * @param {number} [hint_tetrahedron]
214
217
  * @returns {number} index of tetra or -1 if no containing tetra found
215
218
  */
216
- findTetraContainingPoint(points: number[], index: number): number;
219
+ findTetraContainingPoint(x: number, y: number, z: number, points: number[], hint_tetrahedron?: number): number;
217
220
  /**
218
221
  * Relocate tetrahedron in memory, patches neighbourhood links as well
219
222
  * NOTE: The destination slot will be overwritten. This is a dangerous method that can break the topology, make sure you fully understand what you are doing when using it
@@ -1 +1 @@
1
- {"version":3,"file":"TetrahedralMesh.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/tetrahedra/TetrahedralMesh.js"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,qCAFU,MAAM,CAEkD;AAElE;;;GAGG;AACH,gCAFU,MAAM,CAE4B;AAE5C;;;GAGG;AACH,4BAFU,MAAM,CAEwB;AAoBxC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IACI;;;OAGG;IACH,2BAFW,MAAM,EAqDhB;IAhDG;;;;OAIG;IACH,iBAAsE;IAEtE;;;;OAIG;IACH,sBAAmD;IAEnD;;;;OAIG;IACH,eAAyC;IAEzC;;;;OAIG;IACH,mBAA8B;IAE9B;;;;OAIG;IACH,mBAAmB;IAEnB;;;;OAIG;IACH,eAAgB;IAEhB;;;;OAIG;IACH,uBAAuB;IAG3B;;;OAGG;IACH,oBAEC;IAED;;;OAGG;IACH,2BAEC;IAED;;;;OAIG;IACH,2CAQC;IAED;;OAEG;IACH,cAWC;IAED;;;OAGG;IACH,sBAFW,MAAM,QA8BhB;IAED;;;OAGG;IACH,eAFY,MAAM,CAIjB;IAED;;;OAGG;IACH,QAFY,MAAM,CAIjB;IAED;;;OAGG;IACH,uBAFW,MAAM,QAchB;IAED;;;OAGG;IACH,yBAFW,MAAM,QAShB;IAED;;;;OAIG;IACH,YAHW,MAAM,GACL,OAAO,CAiBlB;IAED;;;;;OAKG;IACH,0BAJW,MAAM,mBACN,MAAM,GACJ,MAAM,CAYlB;IAED;;;;;OAKG;IACH,0BAJW,MAAM,mBACN,MAAM,aACN,MAAM,QAchB;IAGD;;;;;OAKG;IACH,0BAJW,MAAM,eACN,MAAM,GACJ,MAAM,CAYlB;IAED;;;;;OAKG;IACH,0BAJW,MAAM,eACN,MAAM,UACN,MAAM,QAiBhB;IAED;;;;;OAKG;IACH,uBAJW,MAAM,UACN,MAAM,GACL,OAAO,CAUlB;IAGD;;;;OAIG;IACH,YAFY,MAAM,CA4BjB;IAED;;;;;;;;OAQG;IACH,eAPW,MAAM,EAAE,GAAC,YAAY,KACrB,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CAqBlB;IAED;;;;OAIG;IACH,wBAFW,MAAM,QAmBhB;IAED;;;;OAIG;IACH,oBAFW,MAAM,QAmBhB;IAED;;;;;OAKG;IACH,2CAHW,MAAM,aACN,MAAM,QAwBhB;IAED;;;;;OAKG;IACH,iCAJW,MAAM,EAAE,SACR,MAAM,GACJ,MAAM,CAsBlB;IAGD;;;;;OAKG;IACH,uBAHW,MAAM,qBACN,MAAM,QA6BhB;IAED;;;;OAIG;IACH,WAFa,MAAM,CA2ClB;IAED;;;OAGG;IACH,kBAFW,YAAY,QAUtB;IAED;;;OAGG;IACH,oBAFW,YAAY,QAiBtB;IAED;;;OAGG;IACH,oBAFY,MAAM,CAUjB;IAED;;;OAGG;IACH,wBAFW,MAAM,QAQhB;IAGL;;;OAGG;IACH,4BAFU,OAAO,CAE0B;CAN1C;6BArrB4B,iCAAiC"}
1
+ {"version":3,"file":"TetrahedralMesh.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/tetrahedra/TetrahedralMesh.js"],"names":[],"mappings":"AAgBA;;;;GAIG;AACH,qCAFU,MAAM,CAEkD;AAElE;;;GAGG;AACH,gCAFU,MAAM,CAE4B;AAE5C;;;GAGG;AACH,4BAFU,MAAM,CAEwB;AAoBxC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IACI;;;OAGG;IACH,2BAFW,MAAM,EAqDhB;IAhDG;;;;OAIG;IACH,iBAAsE;IAEtE;;;;OAIG;IACH,sBAAmD;IAEnD;;;;OAIG;IACH,eAAyC;IAEzC;;;;OAIG;IACH,mBAA8B;IAE9B;;;;OAIG;IACH,mBAAmB;IAEnB;;;;OAIG;IACH,eAAgB;IAEhB;;;;OAIG;IACH,uBAAuB;IAG3B;;;OAGG;IACH,oBAEC;IAED;;;OAGG;IACH,2BAEC;IAED;;;;OAIG;IACH,2CAQC;IAED;;OAEG;IACH,cAWC;IAED;;;OAGG;IACH,sBAFW,MAAM,QA8BhB;IAED;;;OAGG;IACH,eAFY,MAAM,CAIjB;IAED;;;OAGG;IACH,QAFY,MAAM,CAIjB;IAED;;;OAGG;IACH,uBAFW,MAAM,QAchB;IAED;;;OAGG;IACH,yBAFW,MAAM,QAShB;IAED;;;;OAIG;IACH,YAHW,MAAM,GACL,OAAO,CAiBlB;IAED;;;;;OAKG;IACH,0BAJW,MAAM,mBACN,MAAM,GACJ,MAAM,CAYlB;IAED;;;;;OAKG;IACH,0BAJW,MAAM,mBACN,MAAM,aACN,MAAM,QAchB;IAGD;;;;;OAKG;IACH,0BAJW,MAAM,eACN,MAAM,GACJ,MAAM,CAYlB;IAED;;;;;OAKG;IACH,0BAJW,MAAM,eACN,MAAM,UACN,MAAM,QAiBhB;IAED;;;;;OAKG;IACH,uBAJW,MAAM,UACN,MAAM,GACL,OAAO,CAUlB;IAGD;;;;OAIG;IACH,YAFY,MAAM,CA4BjB;IAED;;;;;;;;OAQG;IACH,eAPW,MAAM,EAAE,GAAC,YAAY,KACrB,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CAqBlB;IAED;;;;OAIG;IACH,wBAFW,MAAM,QAmBhB;IAED;;;;OAIG;IACH,oBAFW,MAAM,QAmBhB;IAED;;;;;OAKG;IACH,2CAHW,MAAM,aACN,MAAM,QAwBhB;IAED;;;;;;;;OAQG;IACH,4BAPW,MAAM,KACN,MAAM,KACN,MAAM,UACN,MAAM,EAAE,qBACR,MAAM,GACJ,MAAM,CAyDlB;IAGD;;;;;OAKG;IACH,uBAHW,MAAM,qBACN,MAAM,QA6BhB;IAED;;;;OAIG;IACH,WAFa,MAAM,CA2ClB;IAED;;;OAGG;IACH,kBAFW,YAAY,QAUtB;IAED;;;OAGG;IACH,oBAFW,YAAY,QAiBtB;IAED;;;OAGG;IACH,oBAFY,MAAM,CAUjB;IAED;;;OAGG;IACH,wBAFW,MAAM,QAQhB;IAGL;;;OAGG;IACH,4BAFU,OAAO,CAE0B;CAN1C;6BA1tB4B,iCAAiC"}
@@ -1,12 +1,12 @@
1
+ import { orient3d } from "robust-predicates";
1
2
  import { assert } from "../../../assert.js";
2
3
  import { Base64 } from "../../../binary/Base64.js";
3
4
  import { BinaryBuffer } from "../../../binary/BinaryBuffer.js";
4
5
  import { array_copy } from "../../../collection/array/array_copy.js";
5
- import { array_quick_sort_by_comparator } from "../../../collection/array/arrayQuickSort.js";
6
+ import { array_quick_sort_by_comparator } from "../../../collection/array/array_quick_sort_by_comparator.js";
6
7
  import { typed_array_copy } from "../../../collection/array/typed/typed_array_copy.js";
7
8
  import { max3 } from "../../../math/max3.js";
8
9
  import { number_compare_descending } from "../../../primitives/numbers/number_compare_descending.js";
9
- import { tetrahedron_contains_point } from "./tetrahedron_contains_point.js";
10
10
 
11
11
  /**
12
12
  * @readonly
@@ -523,30 +523,68 @@ export class TetrahedralMesh {
523
523
 
524
524
  /**
525
525
  *
526
- * @param {number[]} points
527
- * @param {number} index
526
+ * @param {number} x
527
+ * @param {number} y
528
+ * @param {number} z
529
+ * @param {number[]} points Positions of vertices of tetrahedrons
530
+ * @param {number} [hint_tetrahedron]
528
531
  * @returns {number} index of tetra or -1 if no containing tetra found
529
532
  */
530
- findTetraContainingPoint(points, index) {
531
- const data_view = this.__view;
533
+ findTetraContainingPoint(x, y, z, points, hint_tetrahedron = 0) {
532
534
 
533
- // TODO improve this
534
- const n = this.__used_end;
535
- for (let i = 0; i < n; i++) {
535
+ let entering_face = 4;
536
536
 
537
- const tet_address = i * LAYOUT_TETRA_BYTE_SIZE;
537
+ let cur_tet = hint_tetrahedron;
538
538
 
539
- const a = data_view.getUint32(tet_address);
540
- const b = data_view.getUint32(tet_address + 4);
541
- const c = data_view.getUint32(tet_address + 8);
542
- const d = data_view.getUint32(tet_address + 12);
539
+ let i;
540
+ while (true) {
541
+ for (i = 0; i < 4; i++) {
543
542
 
544
- if (tetrahedron_contains_point(points, a, b, c, d, index)) {
545
- return i;
543
+ // we walk whenever the volume is positive
544
+ const a_i = (i + 1) & 3;
545
+ const b_i = (i & 2) ^ 3;
546
+ const c_i = (i + 3) & 2;
547
+
548
+ const a_index = this.getVertexIndex(cur_tet, a_i);
549
+ const b_index = this.getVertexIndex(cur_tet, b_i);
550
+ const c_index = this.getVertexIndex(cur_tet, c_i);
551
+
552
+ const a3 = a_index * 3;
553
+ const b3 = b_index * 3;
554
+ const c3 = c_index * 3;
555
+
556
+ const ax = points[a3];
557
+ const ay = points[a3 + 1];
558
+ const az = points[a3 + 2];
559
+
560
+ const bx = points[b3];
561
+ const by = points[b3 + 1];
562
+ const bz = points[b3 + 2];
563
+
564
+ const cx = points[c3];
565
+ const cy = points[c3 + 1];
566
+ const cz = points[c3 + 2];
567
+
568
+ if (i !== entering_face && orient3d(ax, ay, az, bx, by, bz, cx, cy, cz, x, y, z) < 0.0) {
569
+
570
+ // point is outside the tet on the neighbour's side, move in that direction
571
+ const neighbour = this.getNeighbour(cur_tet, i);
572
+
573
+ assert.notEqual(neighbour, INVALID_NEIGHBOUR, 'walked outside of the mesh');
574
+
575
+ cur_tet = neighbour >>> 2;
576
+ entering_face = neighbour & 3;
577
+
578
+ break;
579
+
580
+ }
546
581
  }
547
- }
548
582
 
549
- return -1;
583
+ if (i === 4) {
584
+ // point is inside the tet
585
+ return cur_tet;
586
+ }
587
+ }
550
588
  }
551
589
 
552
590
 
@@ -7,7 +7,7 @@
7
7
  * @param {TetrahedralMesh} mesh
8
8
  * @param {number[]|Float32Array} points
9
9
  * @param {number} hint_tetrahedron we will start here and walk towards our target
10
- * @param {number} search_vertex_index
10
+ * @param {number} search_vertex_index resolved by indexing into {@link points} array
11
11
  * @returns {number}
12
12
  */
13
13
  export function tetrahedral_mesh_walk_towards_containing_tetrahedron(mesh: TetrahedralMesh, points: number[] | Float32Array, hint_tetrahedron: number, search_vertex_index: number): number;
@@ -1 +1 @@
1
- {"version":3,"file":"tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,oGALW,MAAM,EAAE,GAAC,YAAY,oBACrB,MAAM,uBACN,MAAM,GACJ,MAAM,CA2ClB"}
1
+ {"version":3,"file":"tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,oGALW,MAAM,EAAE,GAAC,YAAY,oBACrB,MAAM,uBACN,MAAM,GACJ,MAAM,CAkDlB"}
@@ -1,6 +1,6 @@
1
1
  import { assert } from "../../../../assert.js";
2
- import { INVALID_NEIGHBOUR } from "../TetrahedralMesh.js";
3
2
  import { orient3d_robust } from "../../plane/orient3d_robust.js";
3
+ import { INVALID_NEIGHBOUR } from "../TetrahedralMesh.js";
4
4
 
5
5
  /**
6
6
  * Walk from a given tetrahedron in the mesh towards tetrahedron that contains input point
@@ -11,18 +11,25 @@ import { orient3d_robust } from "../../plane/orient3d_robust.js";
11
11
  * @param {TetrahedralMesh} mesh
12
12
  * @param {number[]|Float32Array} points
13
13
  * @param {number} hint_tetrahedron we will start here and walk towards our target
14
- * @param {number} search_vertex_index
14
+ * @param {number} search_vertex_index resolved by indexing into {@link points} array
15
15
  * @returns {number}
16
16
  */
17
- export function tetrahedral_mesh_walk_towards_containing_tetrahedron(mesh, points, hint_tetrahedron, search_vertex_index) {
17
+ export function tetrahedral_mesh_walk_towards_containing_tetrahedron(
18
+ mesh,
19
+ points,
20
+ hint_tetrahedron,
21
+ search_vertex_index
22
+ ) {
23
+
24
+ assert.isNonNegativeInteger(search_vertex_index, 'search_vertex_index');
18
25
 
19
26
  let entering_face = 4;
20
27
 
21
28
  let cur_tet = hint_tetrahedron;
22
29
 
30
+ let i;
23
31
  while (true) {
24
32
 
25
- let i;
26
33
  for (i = 0; i < 4; i++) {
27
34
 
28
35
  // we walk whenever the volume is positive
@@ -1,40 +1,47 @@
1
1
  // Sample triangular depth map
2
2
  // see CoD SIGGRAPH 2017 "Advances in Real-Time Graphics in Games" course
3
- float GetDepthForTetrahedronProbe(float2 bary, uint4 encodedDepth)
3
+ // depth is encoded as 4 * uint32
4
+ float GetDepthForTetrahedronProbe(vec2 bary, uvec4 encodedDepth)
4
5
  {
5
6
  float sampleY = floor(bary.y * 4.0f);
6
7
  float sampleX = floor(bary.x * 4.0f);
7
8
 
8
- int baseIndex = (int)(((11.0f - sampleY) * sampleY) * 0.5f + sampleX + 0.5f);
9
- int lineLength = 5 - (int)sampleY;
9
+ int baseIndex = int((((11.0f - sampleY) * sampleY) * 0.5f + sampleX + 0.5f));
10
+ int lineLength = 5 - int(sampleY);
10
11
 
11
- float2 baseBary = float2(sampleX * 0.25f, sampleY * 0.25f);
12
+ vec2 baseBary = vec2(sampleX * 0.25f, sampleY * 0.25f);
12
13
 
13
- int3 indices = int3(baseIndex + 1, baseIndex + lineLength, baseIndex);
14
+ ivec3 indices = ivec3(baseIndex + 1, baseIndex + lineLength, baseIndex);
14
15
 
15
- float3 sampleBary;
16
+ // figure out barycentric coordinates within the triangular sample, this will be needed for bilinear interpolation
17
+ vec3 sampleBary;
16
18
  sampleBary.x = (bary.x - baseBary.x) * 4.0f;
17
19
  sampleBary.y = (bary.y - baseBary.y) * 4.0f;
18
20
 
19
21
  if (sampleBary.x + sampleBary.y > 1.0f)
20
22
  {
21
23
  // above the diagonal
22
- indices = int3(baseIndex + lineLength, baseIndex + 1, baseIndex + lineLength + 1);
24
+ indices = ivec3(baseIndex + lineLength, baseIndex + 1, baseIndex + lineLength + 1);
25
+
26
+ vec3 newSampleBary;
23
27
 
24
- float3 newSampleBary;
25
28
  newSampleBary.x = -(sampleBary.y - 1.0f);
26
29
  newSampleBary.y = -(sampleBary.x - 1.0f);
30
+
27
31
  sampleBary = newSampleBary;
28
32
  }
29
33
 
30
34
  sampleBary.z = 1.0f - sampleBary.x - sampleBary.y;
31
35
 
36
+ // perform bilinear interpolation of depth
32
37
  float result = 0.0f;
33
- for (int i=0; i<3; ++i)
38
+ for (int i = 0; i < 3; ++i)
34
39
  {
35
40
  uint currIndex = indices[i];
41
+
36
42
  int intDepth = (encodedDepth[currIndex / 4] >> ((currIndex % 4) * 8)) & 0xFF;
37
- float depth = (float)intDepth / 255.0f;
43
+
44
+ float depth = float(intDepth / 255.0f);
38
45
 
39
46
  result += sampleBary[i] * depth;
40
47
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=prototype.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prototype.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/tetrahedra/triangle/prototype.js"],"names":[],"mappings":""}
@@ -0,0 +1,128 @@
1
+ import { BoxBufferGeometry, MeshStandardMaterial } from "three";
2
+ import { Transform } from "../../../../../engine/ecs/transform/Transform.js";
3
+ import { PathTracedScene } from "../../../../../engine/graphics/sh3/path_tracer/PathTracedScene.js";
4
+ import { Sampler2D } from "../../../../../engine/graphics/texture/sampler/Sampler2D.js";
5
+ import sampler2D2Canvas from "../../../../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
6
+ import { CanvasView } from "../../../../../view/elements/CanvasView.js";
7
+ import { Color } from "../../../../color/Color.js";
8
+ import { halton_sequence } from "../../../../math/statistics/halton_sequence.js";
9
+ import { triangle2d_get_barycentric } from "../../../2d/triangle2d_get_barycentric.js";
10
+ import { trace_triangular_depth_map } from "./trace_triangular_depth_map.js";
11
+ import { triangle_decode_depth, triangle_encode_rasterized_depth } from "./triangle_encode_rasterized_depth.js";
12
+
13
+ const RESOLUTION = 512;
14
+
15
+ const v = new CanvasView();
16
+
17
+ v.size.set(RESOLUTION, RESOLUTION);
18
+
19
+ const ctx = v.context2d;
20
+
21
+ const points = [
22
+ 0, 0,
23
+ 0, RESOLUTION,
24
+ RESOLUTION, RESOLUTION
25
+ ];
26
+
27
+ function getDeterminant(
28
+ ax, ay,
29
+ bx, by,
30
+ cx, cy
31
+ ) {
32
+
33
+ const edge1_x = bx - ax;
34
+ const edge1_y = by - ay;
35
+
36
+ const edge2_x = cx - ax;
37
+ const edge2_y = cy - ay;
38
+
39
+ return edge1_y * edge2_x - edge1_x * edge2_y;
40
+ }
41
+
42
+ const sampler = Sampler2D.float32(3, RESOLUTION, RESOLUTION);
43
+
44
+ const color = new Color();
45
+
46
+ const barycentric = [];
47
+
48
+ async function main() {
49
+
50
+ const scene = new PathTracedScene();
51
+
52
+
53
+ const transform = new Transform();
54
+
55
+ transform.scale.setScalar(1.5);
56
+
57
+ scene.addMesh(
58
+ new BoxBufferGeometry(),
59
+ new MeshStandardMaterial(),
60
+ transform.matrix
61
+ );
62
+
63
+ await scene.build();
64
+
65
+ const depth_map = new Uint32Array(4);
66
+
67
+ trace_triangular_depth_map(depth_map, 0,
68
+ [
69
+ 0, 0, -2,
70
+ -1, -1, 0,
71
+ -1, 1, 0,
72
+ 1, 1, 0,
73
+ ],
74
+ 0, 1, 2, 3,
75
+ scene
76
+ );
77
+
78
+ for (let y = 0; y < sampler.height; y++) {
79
+ for (let x = 0; x < sampler.width; x++) {
80
+ const ax = points[0];
81
+ const ay = points[1];
82
+
83
+ const bx = points[2];
84
+ const by = points[3];
85
+
86
+ const cx = points[3];
87
+ const cy = points[4];
88
+
89
+ triangle2d_get_barycentric(
90
+ barycentric, 0,
91
+ ax, ay,
92
+ bx, by,
93
+ cx, cy,
94
+ x, y
95
+ );
96
+
97
+ const w0 = barycentric[0];
98
+ const w1 = barycentric[1];
99
+ const w2 = barycentric[2];
100
+
101
+ if (w0 < 0 || w1 < 0 || w2 < 0) {
102
+ // outside the triangle
103
+ continue;
104
+ }
105
+
106
+ const index = triangle_encode_rasterized_depth(w0, w1);
107
+
108
+ color.setHSL(
109
+ halton_sequence(15, index), 0.6 + halton_sequence(15, (index * 5 + 31) % 15) * 0.3, 0.5
110
+ );
111
+
112
+ const depth = 1 - triangle_decode_depth(depth_map, 0, w0, w1);
113
+
114
+ color.set(depth, depth, depth, 1);
115
+
116
+ sampler.set(x, y, color)
117
+ }
118
+ }
119
+
120
+ sampler2D2Canvas(sampler, 255, 0, v.el);
121
+
122
+ }
123
+
124
+
125
+ main();
126
+ v.link();
127
+
128
+ document.body.appendChild(v.el);
@@ -0,0 +1,13 @@
1
+ /**
2
+ *
3
+ * @param {Uint32Array} result
4
+ * @param {number} result_offset
5
+ * @param {number[]|Float32Array} points
6
+ * @param {number} source
7
+ * @param {number} a
8
+ * @param {number} b
9
+ * @param {number} c
10
+ * @param {PathTracedScene} scene
11
+ */
12
+ export function trace_triangular_depth_map(result: Uint32Array, result_offset: number, points: number[] | Float32Array, source: number, a: number, b: number, c: number, scene: PathTracedScene): void;
13
+ //# sourceMappingURL=trace_triangular_depth_map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace_triangular_depth_map.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.js"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,mDATW,WAAW,iBACX,MAAM,UACN,MAAM,EAAE,GAAC,YAAY,UACrB,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,gCAyGhB"}
@@ -0,0 +1,120 @@
1
+ import { v3_length } from "../../../vec3/v3_length.js";
2
+ import { ray3_array_compose } from "../../ray/ray3_array_compose.js";
3
+
4
+ const scratch = [];
5
+ const ray = [];
6
+
7
+ /**
8
+ *
9
+ * @param {Uint32Array} result
10
+ * @param {number} result_offset
11
+ * @param {number[]|Float32Array} points
12
+ * @param {number} source
13
+ * @param {number} a
14
+ * @param {number} b
15
+ * @param {number} c
16
+ * @param {PathTracedScene} scene
17
+ */
18
+ export function trace_triangular_depth_map(
19
+ result, result_offset,
20
+ points, source, a, b, c,
21
+ scene
22
+ ) {
23
+
24
+ const a3 = a * 3;
25
+
26
+ const a_x = points[a3];
27
+ const a_y = points[a3 + 1];
28
+ const a_z = points[a3 + 2];
29
+
30
+ const b3 = b * 3;
31
+
32
+ const b_x = points[b3];
33
+ const b_y = points[b3 + 1];
34
+ const b_z = points[b3 + 2];
35
+
36
+ const c3 = c * 3;
37
+
38
+ const c_x = points[c3];
39
+ const c_y = points[c3 + 1];
40
+ const c_z = points[c3 + 2];
41
+
42
+ const origin3 = source * 3;
43
+
44
+ const origin_x = points[origin3];
45
+ const origin_y = points[origin3 + 1];
46
+ const origin_z = points[origin3 + 2];
47
+
48
+ const edge0_x = b_x - a_x;
49
+ const edge0_y = b_y - a_y;
50
+ const edge0_z = b_z - a_z;
51
+
52
+ const edge1_x = c_x - a_x;
53
+ const edge1_y = c_y - a_y;
54
+ const edge1_z = c_z - a_z;
55
+
56
+ for (let i = 0; i < 4; i++) {
57
+ // clear
58
+ result[result_offset + i] = 0;
59
+ }
60
+
61
+
62
+ // generate samples on discrete mapping points
63
+ for (let sample_y = 4; sample_y >= 0; sample_y--) {
64
+
65
+ for (let sample_x = 0; sample_x <= (4 - sample_y); sample_x++) {
66
+
67
+ const barycentric_x = sample_x / 4;
68
+ const barycentric_y = sample_y / 4;
69
+
70
+
71
+ const target_x = a_x + barycentric_x * edge0_x + barycentric_y * edge1_x;
72
+ const target_y = a_y + barycentric_x * edge0_y + barycentric_y * edge1_y;
73
+ const target_z = a_z + barycentric_x * edge0_z + barycentric_y * edge1_z;
74
+
75
+
76
+ // convert target to direction
77
+ const relative_x = target_x - origin_x;
78
+ const relative_y = target_y - origin_y;
79
+ const relative_z = target_z - origin_z;
80
+
81
+ const distance_to_target = v3_length(relative_x, relative_y, relative_z);
82
+
83
+ const norm = 1 / distance_to_target;
84
+
85
+ const ray_direction_x = relative_x * norm;
86
+ const ray_direction_y = relative_y * norm;
87
+ const ray_direction_z = relative_z * norm;
88
+
89
+ ray3_array_compose(
90
+ ray,
91
+ origin_x, origin_y, origin_z,
92
+ ray_direction_x, ray_direction_y, ray_direction_z
93
+ );
94
+
95
+ const distance = scene.trace(scratch, ray, 0, distance_to_target);
96
+
97
+ let depth;
98
+ if (distance < 0) {
99
+ // nothing was hit
100
+ depth = distance_to_target;
101
+ } else {
102
+ depth = distance;
103
+ }
104
+
105
+ const index = ((((11 - sample_y) * sample_y)) * 0.5 + sample_x + 0.5) >>> 0;
106
+
107
+ const encoded_index_0 = index >>> 2;
108
+ const encoded_index_1 = index & 3;
109
+
110
+ const depth_normalized = depth / distance_to_target;
111
+
112
+ // depth is quantized to closer value to be conservative
113
+ const depth_quantized = Math.floor(depth_normalized / 255);
114
+
115
+ result[result_offset + encoded_index_0] |= depth_quantized << (encoded_index_1 * 8);
116
+ }
117
+
118
+ }
119
+
120
+ }
@@ -0,0 +1,3 @@
1
+ export function triangle_encode_rasterized_depth(barycentric_x: any, barycentric_y: any): number;
2
+ export function triangle_decode_depth(encodedDepth: any, input_offset: any, barycentric_x: any, barycentric_y: any): number;
3
+ //# sourceMappingURL=triangle_encode_rasterized_depth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"triangle_encode_rasterized_depth.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.js"],"names":[],"mappings":"AAEA,iGA6CC;AAkBD,4HAwCC"}
@@ -0,0 +1,106 @@
1
+ import { uint8_to_float } from "../../../../binary/uint8_to_float.js";
2
+
3
+ export function triangle_encode_rasterized_depth(barycentric_x, barycentric_y) {
4
+ const sampleY = (barycentric_y * 4.0) >>> 0;
5
+ const sampleX = (barycentric_x * 4.0) >>> 0;
6
+
7
+ const baseIndex = ((((11.0 - sampleY) * sampleY) * 0.5 + sampleX + 0.5)) >>> 0;
8
+ const lineLength = 5 - sampleY;
9
+
10
+ const baseBary_x = sampleX * 0.25;
11
+ const baseBary_y = sampleY * 0.25;
12
+
13
+ let indices_0 = baseIndex + 1;
14
+ let indices_1 = baseIndex + lineLength;
15
+ let indices_2 = baseIndex;
16
+
17
+ // figure out barycentric coordinates within the triangular sample, this will be needed for bilinear interpolation
18
+
19
+ let sampleBary_x = (barycentric_x - baseBary_x) * 4.0;
20
+ let sampleBary_y = (barycentric_y - baseBary_y) * 4.0;
21
+
22
+ const above = sampleBary_x + sampleBary_y > 1.0;
23
+
24
+ if (above) {
25
+ // above the diagonal
26
+ indices_0 = baseIndex + lineLength;
27
+ indices_1 = baseIndex + 1;
28
+ indices_2 = baseIndex + lineLength + 1;
29
+
30
+ const newSampleBary_x = -(sampleBary_y - 1.0);
31
+ const newSampleBary_y = -(sampleBary_x - 1.0);
32
+
33
+ sampleBary_x = newSampleBary_x;
34
+ sampleBary_y = newSampleBary_y;
35
+ }
36
+
37
+ const sampleBary_z = 1.0 - sampleBary_x - sampleBary_y;
38
+
39
+ return indices_0;
40
+
41
+ if (sampleBary_x > sampleBary_y && sampleBary_x > sampleBary_z) {
42
+ return above ? indices_1 : indices_0;
43
+ } else if (sampleBary_y > sampleBary_z && sampleBary_y > sampleBary_x) {
44
+ return above ? indices_0 : indices_1;
45
+ } else {
46
+ return indices_2;
47
+ }
48
+ }
49
+
50
+ /**
51
+ *
52
+ * @param {Uint32Array} encodedDepth
53
+ * @param {number} input_offset
54
+ * @param {number} index
55
+ * @return {number}
56
+ */
57
+ function decode_index(encodedDepth, input_offset, index) {
58
+ const encoded_index_0 = index >>> 2;
59
+ const encoded_index_1 = index & 3;
60
+
61
+ const uint8 = (encodedDepth[input_offset + encoded_index_0] >> ((encoded_index_1) * 8)) & 0xFF;
62
+
63
+ return uint8_to_float(uint8);
64
+ }
65
+
66
+ export function triangle_decode_depth(encodedDepth, input_offset, barycentric_x, barycentric_y) {
67
+ const sampleY = (barycentric_y * 4.0) >>> 0;
68
+ const sampleX = (barycentric_x * 4.0) >>> 0;
69
+
70
+ const baseIndex = ((((11.0 - sampleY) * sampleY) * 0.5 + sampleX + 0.5)) >>> 0;
71
+ const lineLength = 5 - sampleY;
72
+
73
+ const baseBary_x = sampleX * 0.25;
74
+ const baseBary_y = sampleY * 0.25;
75
+
76
+ let indices_0 = baseIndex + 1;
77
+ let indices_1 = baseIndex + lineLength;
78
+ let indices_2 = baseIndex;
79
+
80
+ // figure out barycentric coordinates within the triangular sample, this will be needed for bilinear interpolation
81
+
82
+ let sampleBary_x = (barycentric_x - baseBary_x) * 4.0;
83
+ let sampleBary_y = (barycentric_y - baseBary_y) * 4.0;
84
+
85
+ const above = sampleBary_x + sampleBary_y > 1.0;
86
+
87
+ if (above) {
88
+ // above the diagonal
89
+ // indices_0 = baseIndex + lineLength;
90
+ // indices_1 = baseIndex + 1;
91
+ indices_2 = baseIndex + lineLength + 1;
92
+
93
+ const newSampleBary_x = -(sampleBary_y - 1.0);
94
+ const newSampleBary_y = -(sampleBary_x - 1.0);
95
+
96
+ sampleBary_x = newSampleBary_x;
97
+ sampleBary_y = newSampleBary_y;
98
+ }
99
+
100
+ const sampleBary_z = 1.0 - sampleBary_x - sampleBary_y;
101
+
102
+ // perform bilinear interpolation of depth
103
+ return sampleBary_x * decode_index(encodedDepth, input_offset, indices_0)
104
+ + sampleBary_y * decode_index(encodedDepth, input_offset, indices_1)
105
+ + sampleBary_z * decode_index(encodedDepth, input_offset, indices_2);
106
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Compute factorial of X
3
+ * @param {number} x
4
+ * @return {number}
5
+ */
6
+ export function factorial(x: number): number;
7
+ //# sourceMappingURL=factorial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factorial.d.ts","sourceRoot":"","sources":["../../../../src/core/math/factorial.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,6BAHW,MAAM,GACL,MAAM,CAWjB"}