@woosh/meep-engine 2.48.23 → 2.49.0

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 (142) hide show
  1. package/editor/tools/GridPaintTool.js +1 -1
  2. package/editor/tools/paint/TerrainPaintTool.js +1 -1
  3. package/editor/view/GridPickCoordinateView.js +1 -1
  4. package/package.json +1 -1
  5. package/src/core/UUID.js +2 -0
  6. package/src/core/assert.js +4 -1
  7. package/src/core/binary/ctz32.js +1 -1
  8. package/src/core/binary/operations/bitCount.spec.js +19 -0
  9. package/src/core/binary/uint82float.spec.js +7 -0
  10. package/src/core/bvh2/bvh3/EBBVHLeafProxy.js +3 -0
  11. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +5 -4
  12. package/src/core/bvh2/transform/RotationOptimizer.spec.js +161 -155
  13. package/src/core/codegen/LineBuilder.js +12 -3
  14. package/src/core/codegen/LineBuilder.spec.js +7 -0
  15. package/src/core/collection/HashMap.js +486 -237
  16. package/src/core/collection/HashMap.spec.js +110 -1
  17. package/src/core/collection/array/{typedArrayToDataType.js → typed/typedArrayToDataType.js} +1 -1
  18. package/src/core/collection/array/weightedRandomFromArray.spec.js +20 -0
  19. package/src/core/debug/matchers/AnyOf.js +1 -2
  20. package/src/core/geom/2d/aabb/AABB2.spec.js +1 -1
  21. package/src/core/geom/2d/aabb/aabb2_compute_center_from_multiple.js +19 -0
  22. package/src/core/geom/2d/quad-tree/qt_collect_by_circle.js +3 -3
  23. package/src/core/geom/2d/quad-tree/qt_query_data_nearest_to_point.js +7 -9
  24. package/src/core/geom/3d/aabb/aabb3_compute_plane_side.js +17 -15
  25. package/src/core/geom/3d/aabb/aabb3_compute_plane_side.spec.js +25 -0
  26. package/src/core/geom/3d/aabb/aabb3_detailed_volume_intersection.js +1 -1
  27. package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +3 -0
  28. package/src/core/geom/3d/aabb/aabb3_from_v3_array.spec.js +32 -0
  29. package/src/core/geom/3d/aabb/aabb3_intersects_aabb3.spec.js +115 -0
  30. package/src/core/geom/3d/aabb/aabb3_raycast.js +6 -1
  31. package/src/core/geom/3d/aabb/serializeAABB3Encoded_v0.js +6 -6
  32. package/src/core/geom/3d/{CircleMath.js → compute_circle_bounding_box.js} +1 -1
  33. package/src/core/geom/3d/decompose_matrix_4_array.js +18 -19
  34. package/src/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +1 -1
  35. package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/matrix}/allocate_transform_m4.js +1 -1
  36. package/src/core/geom/3d/normal/hemioct/decode_hemioct_to_unit.js +26 -0
  37. package/src/core/geom/3d/normal/hemioct/encode_unit3_hemioct.js +0 -26
  38. package/src/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +2 -1
  39. package/src/core/geom/3d/plane/computePlaneLineIntersection.js +51 -0
  40. package/src/core/geom/3d/plane/computePlanePlaneIntersection.js +77 -0
  41. package/src/core/geom/3d/plane/computePlaneRayIntersection.js +55 -0
  42. package/src/core/geom/3d/plane/plane3_computeLineSegmentIntersection.js +50 -0
  43. package/src/core/geom/3d/plane/planeRayIntersection.js +14 -0
  44. package/src/core/geom/3d/{tetrahedra/in_sphere_fast.js → sphere/in_sphere3d_fast.js} +1 -1
  45. package/src/core/geom/3d/{tetrahedra/in_sphere_robust.js → sphere/in_sphere3d_robust.js} +1 -1
  46. package/src/core/geom/3d/sphere/sphere_array_intersects_point.js +2 -2
  47. package/src/core/geom/3d/sphere/{sphereIntersectsPoint.js → sphere_intersects_point.js} +7 -4
  48. package/src/core/geom/3d/sphere/sphere_intersects_point.spec.js +134 -0
  49. package/src/core/geom/3d/sphere/sphere_intersects_ray.spec.js +49 -0
  50. package/src/core/geom/3d/sphere/sphere_radius_sqr_from_v3_array_transformed.js +11 -7
  51. package/src/core/geom/3d/tetrahedra/delaunay/{debug_validate_mesh.js → debug/debug_validate_mesh.js} +1 -1
  52. package/src/core/geom/3d/tetrahedra/delaunay/{push_boundary_with_validation.js → debug/push_boundary_with_validation.js} +1 -1
  53. package/src/core/geom/3d/tetrahedra/delaunay/{validate_cavity_boundary.js → debug/validate_cavity_boundary.js} +2 -2
  54. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_cavity.js +2 -2
  55. package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +0 -164
  56. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +87 -0
  57. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.js +81 -0
  58. package/src/core/geom/{rayTriangleIntersection.js → 3d/triangle/rayTriangleIntersection.js} +2 -2
  59. package/src/core/geom/ConicRay.js +160 -152
  60. package/src/core/geom/Matrix4.js +2 -0
  61. package/src/core/geom/Quaternion.js +19 -1
  62. package/src/core/geom/packing/max-rect/MaxRectangles.js +4 -214
  63. package/src/core/geom/packing/max-rect/cost/costByBestShortSide.js +11 -0
  64. package/src/core/geom/packing/max-rect/cost/costByRemainingArea.js +14 -0
  65. package/src/core/geom/packing/max-rect/cutArea.js +79 -0
  66. package/src/core/geom/packing/max-rect/findBestContainer.js +58 -0
  67. package/src/core/geom/packing/max-rect/packOneBox.js +49 -0
  68. package/src/core/geom/v3_dot.js +1 -1
  69. package/src/core/graph/layout/CircleLayout.js +1 -1
  70. package/src/core/graph/layout/{BoxLayouter.js → box/BoxLayouter.js} +6 -50
  71. package/src/core/graph/layout/box/applyCentralGravityAABB2.js +29 -0
  72. package/src/core/json/resolvePath.spec.js +14 -0
  73. package/src/core/land/reactive/{compiler/ReactiveCompiler.spec.js → compileReactiveExpression.spec.js} +17 -17
  74. package/src/core/math/random/MersenneTwister.spec.js +19 -0
  75. package/src/core/math/random/randomGaussian.spec.js +9 -0
  76. package/src/core/math/statistics/computeStatisticalMean.js +2 -2
  77. package/src/core/model/reactive/model/arithmetic/ReactiveAdd.js +1 -1
  78. package/src/core/model/reactive/model/arithmetic/ReactiveDivide.js +3 -1
  79. package/src/core/model/reactive/model/arithmetic/ReactiveMultiply.js +1 -1
  80. package/src/core/model/reactive/model/arithmetic/ReactiveNegate.js +3 -1
  81. package/src/core/model/reactive/model/arithmetic/ReactiveSubtract.js +1 -1
  82. package/src/core/model/reactive/model/comparative/ReactiveEquals.js +1 -1
  83. package/src/core/model/reactive/model/comparative/ReactiveGreaterThan.js +3 -1
  84. package/src/core/model/reactive/model/comparative/ReactiveGreaterThanOrEqual.js +3 -1
  85. package/src/core/model/reactive/model/comparative/ReactiveLessThan.js +3 -1
  86. package/src/core/model/reactive/model/comparative/ReactiveLessThanOrEqual.js +3 -1
  87. package/src/core/model/reactive/model/comparative/ReactiveNotEquals.js +1 -1
  88. package/src/core/model/reactive/model/logic/ReactiveAnd.js +1 -1
  89. package/src/core/model/reactive/model/logic/ReactiveNot.js +3 -1
  90. package/src/core/model/reactive/model/logic/ReactiveOr.js +1 -1
  91. package/src/core/primitives/numbers/computeHashFloat.spec.js +7 -0
  92. package/src/core/process/task/util/iteratorTask.js +3 -1
  93. package/src/engine/animation/curve/AnimationCurve.js +34 -5
  94. package/src/engine/animation/curve/AnimationCurve.spec.js +100 -0
  95. package/src/engine/asset/AssetTransformer.js +1 -0
  96. package/src/engine/computeStridedIntegerArrayHash.js +4 -2
  97. package/src/engine/ecs/components/Renderable.d.ts +1 -1
  98. package/src/{ecs → engine/ecs}/grid/pick.js +4 -4
  99. package/src/engine/ecs/parent/entity_node_compute_bounding_box.js +1 -1
  100. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +1 -18
  101. package/src/engine/ecs/systems/MotionSystem.js +7 -1
  102. package/src/engine/ecs/systems/SynchronizePositionSystem.js +8 -2
  103. package/src/engine/ecs/transform/Transform.js +1 -1
  104. package/src/engine/graphics/camera/makeScreenScissorFrustum.js +3 -3
  105. package/src/engine/graphics/camera/testClippingPlaneComputation.js +13 -13
  106. package/src/engine/graphics/ecs/camera/Camera.js +1 -1
  107. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.js +1 -1
  108. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +9 -0
  109. package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +1 -1
  110. package/src/engine/graphics/geometry/MikkT/STSpace.js +1 -1
  111. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +1 -1
  112. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +1 -1
  113. package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.js +1 -1
  114. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +1 -0
  115. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
  116. package/src/engine/graphics/postprocess/threejs/postprocessing/TexturePass.js +2 -2
  117. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +2 -2
  118. package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
  119. package/src/engine/graphics/texture/sampler/sampler2d_compute_texel_value_conversion_scale_to_uint8.js +1 -1
  120. package/src/engine/intelligence/behavior/Behavior.spec.js +15 -0
  121. package/src/engine/intelligence/mcts/MoveEdge.js +1 -1
  122. package/src/engine/reference/v1/ReferenceManager.js +3 -0
  123. package/src/engine/reference/v2/Reference.js +33 -37
  124. package/src/engine/sound/sopra/README.md +6 -0
  125. package/src/generation/automata/CaveGeneratorCellularAutomata.js +10 -7
  126. package/src/generation/automata/CaveGeneratorCellularAutomata.spec.js +12 -0
  127. package/src/generation/automata/CellularAutomata.js +5 -4
  128. package/src/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +25 -9
  129. package/src/view/minimap/dom/MinimapCameraView.js +1 -1
  130. package/src/core/geom/Plane.js +0 -250
  131. package/src/core/land/reactive/ReactiveLexer.js +0 -158
  132. package/src/core/land/reactive/ReactiveLexer.ts +0 -181
  133. package/src/core/land/reactive/ReactiveListener.ts +0 -323
  134. package/src/core/land/reactive/ReactiveParser.js +0 -1573
  135. package/src/core/land/reactive/ReactiveParser.ts +0 -1776
  136. package/src/core/land/reactive/ReactiveVisitor.js +0 -1
  137. package/src/core/land/reactive/ReactiveVisitor.ts +0 -218
  138. package/src/core/land/reactive/compiler/ReactiveCompiler.js +0 -350
  139. package/src/core/land/reactive/compiler/ReactiveNearlyCompiler.js +0 -166
  140. package/src/core/land/reactive/compiler/ReactiveParser.js +0 -34
  141. package/src/core/land/reactive/nearley/ReactiveNearley.js +0 -187
  142. /package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/vector}/allocate_v3.js +0 -0
@@ -158,167 +158,3 @@ export function computeTriangleRayIntersection(
158
158
  return true;
159
159
  }
160
160
 
161
- /**
162
- * Compute barycentric coordinates for triangle intersection
163
- * Operates on edges, this is optimized for raytracing, as same edges are required to reconstruct various attributes later on
164
- * NOTE: most of the code is inlined for speed to avoid allocation and function calls
165
- * @see https://github.com/erich666/jgt-code/blob/master/Volume_02/Number_1/Moller1997a/raytri.c
166
- * @source https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm (Möller and Trumbore, « Fast, Minimum Storage Ray-Triangle Intersection », Journal of Graphics Tools, vol. 2,‎ 1997, p. 21–28)
167
- * @param {number[]} result
168
- * @param {number} origin_x
169
- * @param {number} origin_y
170
- * @param {number} origin_z
171
- * @param {number} direction_x
172
- * @param {number} direction_y
173
- * @param {number} direction_z
174
- * @param {number} ax
175
- * @param {number} ay
176
- * @param {number} az
177
- * @param {number} edge1_x
178
- * @param {number} edge1_y
179
- * @param {number} edge1_z
180
- * @param {number} edge2_x
181
- * @param {number} edge2_y
182
- * @param {number} edge2_z
183
- * @return {boolean}
184
- */
185
- export function computeTriangleRayIntersectionBarycentricEdge(result, origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, ax, ay, az, edge1_x, edge1_y, edge1_z, edge2_x, edge2_y, edge2_z) {
186
- // begin calculating determinant - also used to calculate U parameter
187
-
188
- // CROSS(pvec, dir, edge2)
189
- const pvec_x = direction_y * edge2_z - direction_z * edge2_y;
190
- const pvec_y = direction_z * edge2_x - direction_x * edge2_z;
191
- const pvec_z = direction_x * edge2_y - direction_y * edge2_x;
192
-
193
- //if determinant is near zero, ray lies in plane of triangle
194
- const det = v3_dot(edge1_x, edge1_y, edge1_z, pvec_x, pvec_y, pvec_z);
195
-
196
- if (det <= 0) {
197
- // back-face culling
198
- return false;
199
- }
200
-
201
- // calculate distance from vert0 to ray origin (not really, but okay)
202
- const tvec_x = origin_x - ax;
203
- const tvec_y = origin_y - ay;
204
- const tvec_z = origin_z - az;
205
-
206
- // calculate u
207
- const u = v3_dot(tvec_x, tvec_y, tvec_z, pvec_x, pvec_y, pvec_z);
208
-
209
- if (u < 0 || u > det) {
210
- // outside of bounds of the triangle
211
- return false;
212
- }
213
-
214
- // prepare to test V parameter
215
- // CROSS(qvec, tvec, edge1)
216
- const qvec_x = tvec_y * edge1_z - tvec_z * edge1_y;
217
- const qvec_y = tvec_z * edge1_x - tvec_x * edge1_z;
218
- const qvec_z = tvec_x * edge1_y - tvec_y * edge1_x;
219
-
220
- // calculate V parameter
221
- const v = v3_dot(direction_x, direction_y, direction_z, qvec_x, qvec_y, qvec_z);
222
-
223
- if (v < 0 || u + v > det) {
224
- // out of bounds
225
- return false;
226
- }
227
-
228
-
229
- const inv_det = 1 / det;
230
-
231
- // calculate t, scale parameter, ray intersects triangle
232
- const t = v3_dot(edge2_x, edge2_y, edge2_z, qvec_x, qvec_y, qvec_z) * inv_det;
233
-
234
- result[0] = t;
235
- result[1] = u*inv_det;
236
- result[2] = v*inv_det;
237
-
238
- return true;
239
- }
240
-
241
- /**
242
- * Compute barycentric coordinates for triangle intersection
243
- * NOTE: most of the code is inlined for speed to avoid allocation and function calls
244
- * @see https://github.com/erich666/jgt-code/blob/master/Volume_02/Number_1/Moller1997a/raytri.c
245
- * @source https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm (Möller and Trumbore, « Fast, Minimum Storage Ray-Triangle Intersection », Journal of Graphics Tools, vol. 2,‎ 1997, p. 21–28)
246
- * @param {number[]} result [t,u,v, normal_x, normal_y, normal_z] will be written here
247
- * @param {number} origin_x
248
- * @param {number} origin_y
249
- * @param {number} origin_z
250
- * @param {number} direction_x
251
- * @param {number} direction_y
252
- * @param {number} direction_z
253
- * @param {number} ax
254
- * @param {number} ay
255
- * @param {number} az
256
- * @param {number} bx
257
- * @param {number} by
258
- * @param {number} bz
259
- * @param {number} cx
260
- * @param {number} cy
261
- * @param {number} cz
262
- * @returns {boolean}
263
- */
264
- export function computeTriangleRayIntersectionBarycentric(
265
- result,
266
- origin_x, origin_y, origin_z,
267
- direction_x, direction_y, direction_z,
268
- ax, ay, az,
269
- bx, by, bz,
270
- cx, cy, cz
271
- ) {
272
- assert.isNumber(ax, 'ax');
273
- assert.isNumber(ay, 'ay');
274
- assert.isNumber(az, 'az');
275
-
276
- assert.isNumber(bx, 'bx');
277
- assert.isNumber(by, 'by');
278
- assert.isNumber(bz, 'bz');
279
-
280
- assert.isNumber(cx, 'cx');
281
- assert.isNumber(cy, 'cy');
282
- assert.isNumber(cz, 'cz');
283
-
284
- // nan checks
285
- assert.notNaN(ax, 'ax');
286
- assert.notNaN(ay, 'ay');
287
- assert.notNaN(az, 'az');
288
-
289
- assert.notNaN(bx, 'bx');
290
- assert.notNaN(by, 'by');
291
- assert.notNaN(bz, 'bz');
292
-
293
- assert.notNaN(cx, 'cx');
294
- assert.notNaN(cy, 'cy');
295
- assert.notNaN(cz, 'cz');
296
-
297
- // finate number check
298
- assert.isFiniteNumber(ax, 'ax');
299
- assert.isFiniteNumber(ay, 'ay');
300
- assert.isFiniteNumber(az, 'az');
301
-
302
- assert.isFiniteNumber(bx, 'bx');
303
- assert.isFiniteNumber(by, 'by');
304
- assert.isFiniteNumber(bz, 'bz');
305
-
306
- assert.isFiniteNumber(cx, 'cx');
307
- assert.isFiniteNumber(cy, 'cy');
308
- assert.isFiniteNumber(cz, 'cz');
309
-
310
-
311
- // find vectors for two edges sharing vert
312
-
313
- // edge1 = a - b
314
- const edge1_x = bx - ax;
315
- const edge1_y = by - ay;
316
- const edge1_z = bz - az;
317
-
318
- // edge2 = c - a
319
- const edge2_x = cx - ax;
320
- const edge2_y = cy - ay;
321
- const edge2_z = cz - az;
322
-
323
- return computeTriangleRayIntersectionBarycentricEdge(result, origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, ax, ay, az, edge1_x, edge1_y, edge1_z, edge2_x, edge2_y, edge2_z);
324
- }
@@ -0,0 +1,87 @@
1
+ import { assert } from "../../../assert.js";
2
+ import { computeTriangleRayIntersectionBarycentricEdge } from "./computeTriangleRayIntersectionBarycentricEdge.js";
3
+
4
+ /**
5
+ * Compute barycentric coordinates for triangle intersection
6
+ * NOTE: most of the code is inlined for speed to avoid allocation and function calls
7
+ * @see https://github.com/erich666/jgt-code/blob/master/Volume_02/Number_1/Moller1997a/raytri.c
8
+ * @source https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm (Möller and Trumbore, « Fast, Minimum Storage Ray-Triangle Intersection », Journal of Graphics Tools, vol. 2,‎ 1997, p. 21–28)
9
+ * @param {number[]} result [t,u,v, normal_x, normal_y, normal_z] will be written here
10
+ * @param {number} origin_x
11
+ * @param {number} origin_y
12
+ * @param {number} origin_z
13
+ * @param {number} direction_x
14
+ * @param {number} direction_y
15
+ * @param {number} direction_z
16
+ * @param {number} ax
17
+ * @param {number} ay
18
+ * @param {number} az
19
+ * @param {number} bx
20
+ * @param {number} by
21
+ * @param {number} bz
22
+ * @param {number} cx
23
+ * @param {number} cy
24
+ * @param {number} cz
25
+ * @returns {boolean}
26
+ */
27
+ export function computeTriangleRayIntersectionBarycentric(
28
+ result,
29
+ origin_x, origin_y, origin_z,
30
+ direction_x, direction_y, direction_z,
31
+ ax, ay, az,
32
+ bx, by, bz,
33
+ cx, cy, cz
34
+ ) {
35
+ assert.isNumber(ax, 'ax');
36
+ assert.isNumber(ay, 'ay');
37
+ assert.isNumber(az, 'az');
38
+
39
+ assert.isNumber(bx, 'bx');
40
+ assert.isNumber(by, 'by');
41
+ assert.isNumber(bz, 'bz');
42
+
43
+ assert.isNumber(cx, 'cx');
44
+ assert.isNumber(cy, 'cy');
45
+ assert.isNumber(cz, 'cz');
46
+
47
+ // nan checks
48
+ assert.notNaN(ax, 'ax');
49
+ assert.notNaN(ay, 'ay');
50
+ assert.notNaN(az, 'az');
51
+
52
+ assert.notNaN(bx, 'bx');
53
+ assert.notNaN(by, 'by');
54
+ assert.notNaN(bz, 'bz');
55
+
56
+ assert.notNaN(cx, 'cx');
57
+ assert.notNaN(cy, 'cy');
58
+ assert.notNaN(cz, 'cz');
59
+
60
+ // finate number check
61
+ assert.isFiniteNumber(ax, 'ax');
62
+ assert.isFiniteNumber(ay, 'ay');
63
+ assert.isFiniteNumber(az, 'az');
64
+
65
+ assert.isFiniteNumber(bx, 'bx');
66
+ assert.isFiniteNumber(by, 'by');
67
+ assert.isFiniteNumber(bz, 'bz');
68
+
69
+ assert.isFiniteNumber(cx, 'cx');
70
+ assert.isFiniteNumber(cy, 'cy');
71
+ assert.isFiniteNumber(cz, 'cz');
72
+
73
+
74
+ // find vectors for two edges sharing vert
75
+
76
+ // edge1 = a - b
77
+ const edge1_x = bx - ax;
78
+ const edge1_y = by - ay;
79
+ const edge1_z = bz - az;
80
+
81
+ // edge2 = c - a
82
+ const edge2_x = cx - ax;
83
+ const edge2_y = cy - ay;
84
+ const edge2_z = cz - az;
85
+
86
+ return computeTriangleRayIntersectionBarycentricEdge(result, origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, ax, ay, az, edge1_x, edge1_y, edge1_z, edge2_x, edge2_y, edge2_z);
87
+ }
@@ -0,0 +1,81 @@
1
+ import { v3_dot } from "../../v3_dot.js";
2
+
3
+ /**
4
+ * Compute barycentric coordinates for triangle intersection
5
+ * Operates on edges, this is optimized for raytracing, as same edges are required to reconstruct various attributes later on
6
+ * NOTE: most of the code is inlined for speed to avoid allocation and function calls
7
+ * @see https://github.com/erich666/jgt-code/blob/master/Volume_02/Number_1/Moller1997a/raytri.c
8
+ * @source https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm (Möller and Trumbore, « Fast, Minimum Storage Ray-Triangle Intersection », Journal of Graphics Tools, vol. 2,‎ 1997, p. 21–28)
9
+ * @param {number[]} result
10
+ * @param {number} origin_x
11
+ * @param {number} origin_y
12
+ * @param {number} origin_z
13
+ * @param {number} direction_x
14
+ * @param {number} direction_y
15
+ * @param {number} direction_z
16
+ * @param {number} ax
17
+ * @param {number} ay
18
+ * @param {number} az
19
+ * @param {number} edge1_x
20
+ * @param {number} edge1_y
21
+ * @param {number} edge1_z
22
+ * @param {number} edge2_x
23
+ * @param {number} edge2_y
24
+ * @param {number} edge2_z
25
+ * @return {boolean}
26
+ */
27
+ export function computeTriangleRayIntersectionBarycentricEdge(result, origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, ax, ay, az, edge1_x, edge1_y, edge1_z, edge2_x, edge2_y, edge2_z) {
28
+ // begin calculating determinant - also used to calculate U parameter
29
+
30
+ // CROSS(pvec, dir, edge2)
31
+ const pvec_x = direction_y * edge2_z - direction_z * edge2_y;
32
+ const pvec_y = direction_z * edge2_x - direction_x * edge2_z;
33
+ const pvec_z = direction_x * edge2_y - direction_y * edge2_x;
34
+
35
+ //if determinant is near zero, ray lies in plane of triangle
36
+ const det = v3_dot(edge1_x, edge1_y, edge1_z, pvec_x, pvec_y, pvec_z);
37
+
38
+ if (det <= 0) {
39
+ // back-face culling
40
+ return false;
41
+ }
42
+
43
+ // calculate distance from vert0 to ray origin (not really, but okay)
44
+ const tvec_x = origin_x - ax;
45
+ const tvec_y = origin_y - ay;
46
+ const tvec_z = origin_z - az;
47
+
48
+ // calculate u
49
+ const u = v3_dot(tvec_x, tvec_y, tvec_z, pvec_x, pvec_y, pvec_z);
50
+
51
+ if (u < 0 || u > det) {
52
+ // outside of bounds of the triangle
53
+ return false;
54
+ }
55
+
56
+ // prepare to test V parameter
57
+ // CROSS(qvec, tvec, edge1)
58
+ const qvec_x = tvec_y * edge1_z - tvec_z * edge1_y;
59
+ const qvec_y = tvec_z * edge1_x - tvec_x * edge1_z;
60
+ const qvec_z = tvec_x * edge1_y - tvec_y * edge1_x;
61
+
62
+ // calculate V parameter
63
+ const v = v3_dot(direction_x, direction_y, direction_z, qvec_x, qvec_y, qvec_z);
64
+
65
+ if (v < 0 || u + v > det) {
66
+ // out of bounds
67
+ return false;
68
+ }
69
+
70
+
71
+ const inv_det = 1 / det;
72
+
73
+ // calculate t, scale parameter, ray intersects triangle
74
+ const t = v3_dot(edge2_x, edge2_y, edge2_z, qvec_x, qvec_y, qvec_z) * inv_det;
75
+
76
+ result[0] = t;
77
+ result[1] = u * inv_det;
78
+ result[2] = v * inv_det;
79
+
80
+ return true;
81
+ }
@@ -1,5 +1,5 @@
1
- import { SurfacePoint3 } from "./3d/SurfacePoint3.js";
2
- import { computeTriangleRayIntersection } from "./3d/triangle/computeTriangleRayIntersection.js";
1
+ import { SurfacePoint3 } from "../SurfacePoint3.js";
2
+ import { computeTriangleRayIntersection } from "./computeTriangleRayIntersection.js";
3
3
 
4
4
 
5
5
  const sp3 = new SurfacePoint3();