@woosh/meep-engine 2.48.22 → 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 (230) hide show
  1. package/editor/ecs/component/editors/three/BufferGeometryEditor.js +1 -1
  2. package/editor/ecs/component/editors/three/MeshEditor.js +1 -1
  3. package/editor/tools/GridPaintTool.js +1 -1
  4. package/editor/tools/SelectionTool.js +1 -1
  5. package/editor/tools/paint/TerrainPaintTool.js +1 -1
  6. package/editor/view/GridPickCoordinateView.js +1 -1
  7. package/editor/view/library/MeshLibraryView.js +1 -1
  8. package/package.json +1 -1
  9. package/src/core/UUID.js +2 -0
  10. package/src/core/assert.js +4 -1
  11. package/src/core/binary/32BitEncoder.js +1 -1
  12. package/src/core/binary/ctz32.js +1 -1
  13. package/src/core/binary/operations/bitCount.spec.js +19 -0
  14. package/src/core/binary/uint82float.spec.js +7 -0
  15. package/src/core/bvh2/LeafNode.js +2 -2
  16. package/src/core/bvh2/Node.d.ts +1 -1
  17. package/src/core/bvh2/Node.js +1 -1
  18. package/src/core/bvh2/NodeValidator.js +1 -1
  19. package/src/core/bvh2/bvh3/EBBVHLeafProxy.js +3 -0
  20. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +5 -4
  21. package/src/core/bvh2/serialization/deserializeBinaryNode.js +1 -1
  22. package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +2 -2
  23. package/src/core/bvh2/serialization/serializeBinaryNode.js +1 -1
  24. package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +2 -2
  25. package/src/core/bvh2/transform/RotationOptimizer.spec.js +161 -155
  26. package/src/core/cache/Cache.js +4 -2
  27. package/src/core/codegen/LineBuilder.js +15 -3
  28. package/src/core/codegen/LineBuilder.spec.js +7 -0
  29. package/src/core/collection/HashMap.js +491 -236
  30. package/src/core/collection/HashMap.spec.js +110 -1
  31. package/src/core/collection/array/{typedArrayToDataType.js → typed/typedArrayToDataType.js} +1 -1
  32. package/src/core/collection/array/weightedRandomFromArray.spec.js +20 -0
  33. package/src/core/collection/heap/Uint32Heap.js +1 -0
  34. package/src/core/debug/matchers/AnyOf.js +1 -2
  35. package/src/core/events/signal/Signal.js +7 -5
  36. package/src/core/events/signal/SignalBinding.js +56 -54
  37. package/src/core/events/signal/SignalFlags.js +7 -0
  38. package/src/core/function/Functions.js +1 -1
  39. package/src/core/geom/{Rectangle.js → 2d/Rectangle.js} +5 -5
  40. package/src/core/geom/{AABB2.js → 2d/aabb/AABB2.js} +10 -78
  41. package/src/core/geom/2d/aabb/aabb2_compute_center_from_multiple.js +19 -0
  42. package/src/core/geom/2d/aabb/aabb2_compute_overlap.js +42 -0
  43. package/src/core/geom/2d/aabb/aabb2_contains.js +23 -0
  44. package/src/core/geom/2d/aabb/aabb2_distance_sqr_to_point.js +25 -0
  45. package/src/core/geom/2d/aabb/aabb2_distance_to_point.js +17 -0
  46. package/src/core/geom/2d/aabb/aabb2_distance_to_point.spec.js +17 -0
  47. package/src/core/geom/2d/aabb/aabb2_overlap_exists.js +18 -0
  48. package/src/core/geom/2d/aabb/aabb2_signed_distance_sqr_to_point.js +45 -0
  49. package/src/core/geom/2d/aabb/aabb2_signed_distance_sqr_to_point.spec.js +40 -0
  50. package/src/core/geom/2d/aabb/aabb2_signed_distance_to_point.js +27 -0
  51. package/src/core/geom/2d/convex-hull/fixed_convex_hull_humus.js +4 -0
  52. package/src/core/geom/2d/quad-tree/PointQuadTree.js +3 -0
  53. package/src/core/geom/2d/quad-tree/QuadTreeDatum.js +1 -1
  54. package/src/core/geom/2d/quad-tree/QuadTreeNode.js +3 -3
  55. package/src/core/geom/2d/quad-tree/qt_collect_by_circle.js +6 -8
  56. package/src/core/geom/2d/quad-tree/qt_match_data_by_circle.js +3 -3
  57. package/src/core/geom/2d/quad-tree/qt_query_data_nearest_to_point.js +8 -10
  58. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/AABB3.d.ts +1 -1
  59. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/AABB3.js +13 -13
  60. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/AABB3.spec.js +1 -1
  61. package/src/core/geom/3d/aabb/aabb3_compute_plane_side.js +17 -15
  62. package/src/core/geom/3d/aabb/aabb3_compute_plane_side.spec.js +25 -0
  63. package/src/core/geom/3d/aabb/aabb3_detailed_volume_intersection.js +1 -1
  64. package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +3 -0
  65. package/src/core/geom/3d/aabb/aabb3_from_v3_array.spec.js +32 -0
  66. package/src/core/geom/3d/aabb/aabb3_intersects_aabb3.spec.js +115 -0
  67. package/src/core/geom/3d/aabb/aabb3_raycast.js +6 -1
  68. package/src/core/geom/3d/aabb/aabb3_signed_distance_sqr_to_point.js +13 -9
  69. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/serializeAABB3Encoded_v0.js +6 -6
  70. package/src/core/geom/3d/{CircleMath.js → compute_circle_bounding_box.js} +1 -1
  71. package/src/core/geom/3d/decompose_matrix_4_array.js +18 -19
  72. package/src/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +1 -1
  73. package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/matrix}/allocate_transform_m4.js +1 -1
  74. package/src/core/geom/3d/normal/hemioct/decode_hemioct_to_unit.js +26 -0
  75. package/src/core/geom/3d/normal/hemioct/encode_unit3_hemioct.js +0 -26
  76. package/src/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +2 -1
  77. package/src/core/geom/3d/plane/computePlaneLineIntersection.js +51 -0
  78. package/src/core/geom/3d/plane/computePlanePlaneIntersection.js +77 -0
  79. package/src/core/geom/3d/plane/computePlaneRayIntersection.js +55 -0
  80. package/src/core/geom/3d/plane/plane3_computeLineSegmentIntersection.js +50 -0
  81. package/src/core/geom/3d/plane/planeRayIntersection.js +14 -0
  82. package/src/core/geom/3d/{tetrahedra/in_sphere_fast.js → sphere/in_sphere3d_fast.js} +1 -1
  83. package/src/core/geom/3d/{tetrahedra/in_sphere_robust.js → sphere/in_sphere3d_robust.js} +1 -1
  84. package/src/core/geom/3d/sphere/sphere_array_intersects_point.js +2 -2
  85. package/src/core/geom/3d/sphere/{sphereIntersectsPoint.js → sphere_intersects_point.js} +7 -4
  86. package/src/core/geom/3d/sphere/sphere_intersects_point.spec.js +134 -0
  87. package/src/core/geom/3d/sphere/sphere_intersects_ray.spec.js +49 -0
  88. package/src/core/geom/3d/sphere/sphere_radius_sqr_from_v3_array_transformed.js +11 -7
  89. package/src/core/geom/3d/tetrahedra/delaunay/{debug_validate_mesh.js → debug/debug_validate_mesh.js} +1 -1
  90. package/src/core/geom/3d/tetrahedra/delaunay/{push_boundary_with_validation.js → debug/push_boundary_with_validation.js} +1 -1
  91. package/src/core/geom/3d/tetrahedra/delaunay/{validate_cavity_boundary.js → debug/validate_cavity_boundary.js} +2 -2
  92. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_cavity.js +2 -2
  93. package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +0 -164
  94. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +87 -0
  95. package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.js +81 -0
  96. package/src/core/geom/{GeometryMath.js → 3d/triangle/rayTriangleIntersection.js} +7 -3
  97. package/src/core/geom/ConicRay.js +160 -152
  98. package/src/core/geom/Matrix4.js +2 -0
  99. package/src/core/geom/Quaternion.js +19 -1
  100. package/src/core/geom/packing/max-rect/MaxRectangles.js +5 -215
  101. package/src/core/geom/packing/max-rect/cost/costByBestShortSide.js +11 -0
  102. package/src/core/geom/packing/max-rect/cost/costByRemainingArea.js +14 -0
  103. package/src/core/geom/packing/max-rect/cutArea.js +79 -0
  104. package/src/core/geom/packing/max-rect/findBestContainer.js +58 -0
  105. package/src/core/geom/packing/max-rect/packOneBox.js +49 -0
  106. package/src/core/geom/v3_dot.js +1 -1
  107. package/src/core/graph/GraphUtils.js +1 -1
  108. package/src/core/graph/build_face_graph_from_mesh.js +1 -3
  109. package/src/core/graph/layout/CircleLayout.js +3 -3
  110. package/src/core/graph/layout/{BoxLayouter.js → box/BoxLayouter.js} +6 -50
  111. package/src/core/graph/layout/box/applyCentralGravityAABB2.js +29 -0
  112. package/src/core/json/resolvePath.spec.js +14 -0
  113. package/src/core/land/reactive/{compiler/ReactiveCompiler.spec.js → compileReactiveExpression.spec.js} +17 -17
  114. package/src/core/math/random/MersenneTwister.spec.js +19 -0
  115. package/src/core/math/random/randomGaussian.spec.js +9 -0
  116. package/src/core/math/statistics/computeStatisticalMean.js +2 -2
  117. package/src/core/model/node-graph/visual/NodeVisualData.js +1 -1
  118. package/src/core/model/reactive/model/arithmetic/ReactiveAdd.js +1 -1
  119. package/src/core/model/reactive/model/arithmetic/ReactiveDivide.js +3 -1
  120. package/src/core/model/reactive/model/arithmetic/ReactiveMultiply.js +1 -1
  121. package/src/core/model/reactive/model/arithmetic/ReactiveNegate.js +3 -1
  122. package/src/core/model/reactive/model/arithmetic/ReactiveSubtract.js +1 -1
  123. package/src/core/model/reactive/model/comparative/ReactiveEquals.js +1 -1
  124. package/src/core/model/reactive/model/comparative/ReactiveGreaterThan.js +3 -1
  125. package/src/core/model/reactive/model/comparative/ReactiveGreaterThanOrEqual.js +3 -1
  126. package/src/core/model/reactive/model/comparative/ReactiveLessThan.js +3 -1
  127. package/src/core/model/reactive/model/comparative/ReactiveLessThanOrEqual.js +3 -1
  128. package/src/core/model/reactive/model/comparative/ReactiveNotEquals.js +1 -1
  129. package/src/core/model/reactive/model/logic/ReactiveAnd.js +1 -1
  130. package/src/core/model/reactive/model/logic/ReactiveNot.js +3 -1
  131. package/src/core/model/reactive/model/logic/ReactiveOr.js +1 -1
  132. package/src/core/primitives/numbers/computeHashFloat.spec.js +7 -0
  133. package/src/core/process/task/util/iteratorTask.js +3 -1
  134. package/src/engine/animation/curve/AnimationCurve.js +34 -5
  135. package/src/engine/animation/curve/AnimationCurve.spec.js +100 -0
  136. package/src/engine/asset/AssetTransformer.js +1 -0
  137. package/src/engine/asset/loaders/GLTFAssetLoader.js +1 -1
  138. package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +2 -2
  139. package/src/engine/asset/preloader/Preloader.js +3 -3
  140. package/src/engine/computeStridedIntegerArrayHash.js +4 -2
  141. package/src/engine/ecs/components/Renderable.d.ts +2 -2
  142. package/src/engine/ecs/components/Renderable.js +1 -1
  143. package/src/{ecs → engine/ecs}/grid/pick.js +4 -4
  144. package/src/engine/ecs/gui/position/ViewportPositionSystem.js +1 -1
  145. package/src/engine/ecs/parent/entity_node_compute_bounding_box.js +1 -1
  146. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +1 -18
  147. package/src/engine/ecs/systems/MotionSystem.js +7 -1
  148. package/src/engine/ecs/systems/SynchronizePositionSystem.js +8 -2
  149. package/src/engine/ecs/terrain/tiles/TerrainTile.js +1 -1
  150. package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +2 -2
  151. package/src/engine/ecs/tooltip/TooltipComponentSystem.js +1 -1
  152. package/src/engine/ecs/transform/Transform.js +1 -1
  153. package/src/engine/graphics/camera/makeScreenScissorFrustum.d.ts +1 -1
  154. package/src/engine/graphics/camera/makeScreenScissorFrustum.js +3 -3
  155. package/src/engine/graphics/camera/testClippingPlaneComputation.js +13 -13
  156. package/src/engine/graphics/ecs/camera/Camera.js +1 -1
  157. package/src/engine/graphics/ecs/light/LightSystem.js +1 -1
  158. package/src/engine/graphics/ecs/mesh/Mesh.d.ts +1 -1
  159. package/src/engine/graphics/ecs/mesh/Mesh.js +1 -1
  160. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +1 -1
  161. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +1 -1
  162. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.d.ts +1 -1
  163. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.js +1 -1
  164. package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +9 -0
  165. package/src/engine/graphics/ecs/mesh-v2/sg_hierarchy_compute_bounding_box_via_parent_entity.d.ts +1 -1
  166. package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +1 -1
  167. package/src/engine/graphics/geometry/MikkT/STSpace.js +1 -1
  168. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +1 -1
  169. package/src/engine/graphics/geometry/skining/computeSkinnedMeshBoundingVolumes.js +1 -1
  170. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +1 -1
  171. package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.js +1 -1
  172. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +1 -1
  173. package/src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +1 -1
  174. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +1 -0
  175. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
  176. package/src/engine/graphics/postprocess/threejs/postprocessing/TexturePass.js +2 -2
  177. package/src/engine/graphics/render/forward_plus/debug/createScreenGrid.js +1 -1
  178. package/src/engine/graphics/render/view/CameraView.js +1 -1
  179. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +2 -2
  180. package/src/engine/graphics/texture/atlas/AtlasPatch.js +2 -2
  181. package/src/engine/graphics/texture/atlas/TextureAtlas.spec.js +2 -2
  182. package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
  183. package/src/engine/graphics/texture/sampler/sampler2d_compute_texel_value_conversion_scale_to_uint8.js +1 -1
  184. package/src/engine/graphics/util/makeMeshPreviewScene.js +1 -1
  185. package/src/engine/graphics/util/renderObjectToSampler2D.js +1 -1
  186. package/src/engine/intelligence/behavior/Behavior.spec.js +15 -0
  187. package/src/engine/intelligence/mcts/MoveEdge.js +1 -1
  188. package/src/engine/reference/v1/ReferenceManager.js +3 -0
  189. package/src/engine/reference/v2/Reference.js +33 -37
  190. package/src/engine/sound/sopra/README.md +6 -0
  191. package/src/engine/ui/tiles2d/computeTileGridMove.js +3 -2
  192. package/src/engine/ui/tiles2d/computeTileGridMove.spec.js +1 -1
  193. package/src/generation/automata/CaveGeneratorCellularAutomata.js +10 -7
  194. package/src/generation/automata/CaveGeneratorCellularAutomata.spec.js +12 -0
  195. package/src/generation/automata/CellularAutomata.js +5 -4
  196. package/src/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +25 -9
  197. package/src/generation/theme/AreaMask.js +1 -1
  198. package/src/view/View.js +1 -1
  199. package/src/view/elements/progress/RectangularPieProgressView.js +1 -1
  200. package/src/view/minimap/Minimap.js +1 -1
  201. package/src/view/minimap/dom/MinimapCameraView.js +1 -1
  202. package/src/view/minimap/gl/MinimapFogOfWar.js +1 -1
  203. package/src/view/tooltip/DomTooltipObserver.js +1 -1
  204. package/src/view/tooltip/TooltipManager.js +1 -1
  205. package/src/view/tooltip/TooltipView.js +1 -1
  206. package/src/view/util/DomSizeObserver.js +2 -2
  207. package/src/core/geom/2d/AABB2Math.js +0 -40
  208. package/src/core/geom/2d/AABB2Math.spec.js +0 -17
  209. package/src/core/geom/Plane.js +0 -250
  210. package/src/core/land/reactive/ReactiveLexer.js +0 -158
  211. package/src/core/land/reactive/ReactiveLexer.ts +0 -181
  212. package/src/core/land/reactive/ReactiveListener.ts +0 -323
  213. package/src/core/land/reactive/ReactiveParser.js +0 -1573
  214. package/src/core/land/reactive/ReactiveParser.ts +0 -1776
  215. package/src/core/land/reactive/ReactiveVisitor.js +0 -1
  216. package/src/core/land/reactive/ReactiveVisitor.ts +0 -218
  217. package/src/core/land/reactive/compiler/ReactiveCompiler.js +0 -350
  218. package/src/core/land/reactive/compiler/ReactiveNearlyCompiler.js +0 -166
  219. package/src/core/land/reactive/compiler/ReactiveParser.js +0 -34
  220. package/src/core/land/reactive/nearley/ReactiveNearley.js +0 -187
  221. /package/src/core/geom/{LineSegment2.js → 2d/LineSegment2.js} +0 -0
  222. /package/src/core/geom/{Rectangle.spec.js → 2d/Rectangle.spec.js} +0 -0
  223. /package/src/core/geom/{AABB2.d.ts → 2d/aabb/AABB2.d.ts} +0 -0
  224. /package/src/core/geom/{AABB2.spec.js → 2d/aabb/AABB2.spec.js} +0 -0
  225. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/deserializeAABB3.js +0 -0
  226. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/deserializeAABB3Encoded_v0.js +0 -0
  227. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/deserializeAABB3Quantized16Uint.js +0 -0
  228. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/serializeAABB3.js +0 -0
  229. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/serializeAABB3Quantized16Uint.js +0 -0
  230. /package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/vector}/allocate_v3.js +0 -0
@@ -1,4 +1,4 @@
1
- import { validate_tetrahedral_mesh } from "../validate_tetrahedral_mesh.js";
1
+ import { validate_tetrahedral_mesh } from "../../validate_tetrahedral_mesh.js";
2
2
 
3
3
  /**
4
4
  *
@@ -1,4 +1,4 @@
1
- import { tetrahedron_compute_signed_volume } from "../tetrahedron_compute_signed_volume.js";
1
+ import { tetrahedron_compute_signed_volume } from "../../tetrahedron_compute_signed_volume.js";
2
2
 
3
3
  /**
4
4
  * Debug method that validates cavity tet before pushing it
@@ -1,5 +1,5 @@
1
- import { INVALID_NEIGHBOUR } from "../TetrahedralMesh.js";
2
- import { array_range_equal_strict } from "../../../../collection/array/array_range_equal_strict.js";
1
+ import { INVALID_NEIGHBOUR } from "../../TetrahedralMesh.js";
2
+ import { array_range_equal_strict } from "../../../../../collection/array/array_range_equal_strict.js";
3
3
 
4
4
  export function debug_validate_cavity_boundary(mesh, cavity) {
5
5
  let valid = true;
@@ -1,6 +1,6 @@
1
1
  import { assert } from "../../../../assert.js";
2
2
  import { INVALID_NEIGHBOUR } from "../TetrahedralMesh.js";
3
- import { in_sphere_robust } from "../in_sphere_robust.js";
3
+ import { in_sphere3d_robust } from "../../sphere/in_sphere3d_robust.js";
4
4
 
5
5
  /**
6
6
  *
@@ -56,7 +56,7 @@ export function tetrahedral_mesh_compute_cavity(
56
56
  continue;
57
57
  }
58
58
 
59
- if (in_sphere_robust(
59
+ if (in_sphere3d_robust(
60
60
  points,
61
61
  mesh.getVertexIndex(neighbour_index, 0),
62
62
  mesh.getVertexIndex(neighbour_index, 1),
@@ -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();
@@ -15,7 +15,11 @@ const sp3 = new SurfacePoint3();
15
15
  * @param {Vector3} c
16
16
  * @returns {boolean}
17
17
  */
18
- export function rayTriangleIntersection(result, rayOrigin, rayDirection, a, b, c) {
18
+ export function rayTriangleIntersection(
19
+ result,
20
+ rayOrigin, rayDirection,
21
+ a, b, c
22
+ ) {
19
23
 
20
24
  const hit_found = computeTriangleRayIntersection(
21
25
  sp3,