@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.
- package/editor/ecs/component/editors/three/BufferGeometryEditor.js +1 -1
- package/editor/ecs/component/editors/three/MeshEditor.js +1 -1
- package/editor/tools/GridPaintTool.js +1 -1
- package/editor/tools/SelectionTool.js +1 -1
- package/editor/tools/paint/TerrainPaintTool.js +1 -1
- package/editor/view/GridPickCoordinateView.js +1 -1
- package/editor/view/library/MeshLibraryView.js +1 -1
- package/package.json +1 -1
- package/src/core/UUID.js +2 -0
- package/src/core/assert.js +4 -1
- package/src/core/binary/32BitEncoder.js +1 -1
- package/src/core/binary/ctz32.js +1 -1
- package/src/core/binary/operations/bitCount.spec.js +19 -0
- package/src/core/binary/uint82float.spec.js +7 -0
- package/src/core/bvh2/LeafNode.js +2 -2
- package/src/core/bvh2/Node.d.ts +1 -1
- package/src/core/bvh2/Node.js +1 -1
- package/src/core/bvh2/NodeValidator.js +1 -1
- package/src/core/bvh2/bvh3/EBBVHLeafProxy.js +3 -0
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +5 -4
- package/src/core/bvh2/serialization/deserializeBinaryNode.js +1 -1
- package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +2 -2
- package/src/core/bvh2/serialization/serializeBinaryNode.js +1 -1
- package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +2 -2
- package/src/core/bvh2/transform/RotationOptimizer.spec.js +161 -155
- package/src/core/cache/Cache.js +4 -2
- package/src/core/codegen/LineBuilder.js +15 -3
- package/src/core/codegen/LineBuilder.spec.js +7 -0
- package/src/core/collection/HashMap.js +491 -236
- package/src/core/collection/HashMap.spec.js +110 -1
- package/src/core/collection/array/{typedArrayToDataType.js → typed/typedArrayToDataType.js} +1 -1
- package/src/core/collection/array/weightedRandomFromArray.spec.js +20 -0
- package/src/core/collection/heap/Uint32Heap.js +1 -0
- package/src/core/debug/matchers/AnyOf.js +1 -2
- package/src/core/events/signal/Signal.js +7 -5
- package/src/core/events/signal/SignalBinding.js +56 -54
- package/src/core/events/signal/SignalFlags.js +7 -0
- package/src/core/function/Functions.js +1 -1
- package/src/core/geom/{Rectangle.js → 2d/Rectangle.js} +5 -5
- package/src/core/geom/{AABB2.js → 2d/aabb/AABB2.js} +10 -78
- package/src/core/geom/2d/aabb/aabb2_compute_center_from_multiple.js +19 -0
- package/src/core/geom/2d/aabb/aabb2_compute_overlap.js +42 -0
- package/src/core/geom/2d/aabb/aabb2_contains.js +23 -0
- package/src/core/geom/2d/aabb/aabb2_distance_sqr_to_point.js +25 -0
- package/src/core/geom/2d/aabb/aabb2_distance_to_point.js +17 -0
- package/src/core/geom/2d/aabb/aabb2_distance_to_point.spec.js +17 -0
- package/src/core/geom/2d/aabb/aabb2_overlap_exists.js +18 -0
- package/src/core/geom/2d/aabb/aabb2_signed_distance_sqr_to_point.js +45 -0
- package/src/core/geom/2d/aabb/aabb2_signed_distance_sqr_to_point.spec.js +40 -0
- package/src/core/geom/2d/aabb/aabb2_signed_distance_to_point.js +27 -0
- package/src/core/geom/2d/convex-hull/fixed_convex_hull_humus.js +4 -0
- package/src/core/geom/2d/quad-tree/PointQuadTree.js +3 -0
- package/src/core/geom/2d/quad-tree/QuadTreeDatum.js +1 -1
- package/src/core/geom/2d/quad-tree/QuadTreeNode.js +3 -3
- package/src/core/geom/2d/quad-tree/qt_collect_by_circle.js +6 -8
- package/src/core/geom/2d/quad-tree/qt_match_data_by_circle.js +3 -3
- package/src/core/geom/2d/quad-tree/qt_query_data_nearest_to_point.js +8 -10
- package/src/core/{bvh2/aabb3 → geom/3d/aabb}/AABB3.d.ts +1 -1
- package/src/core/{bvh2/aabb3 → geom/3d/aabb}/AABB3.js +13 -13
- package/src/core/{bvh2/aabb3 → geom/3d/aabb}/AABB3.spec.js +1 -1
- package/src/core/geom/3d/aabb/aabb3_compute_plane_side.js +17 -15
- package/src/core/geom/3d/aabb/aabb3_compute_plane_side.spec.js +25 -0
- package/src/core/geom/3d/aabb/aabb3_detailed_volume_intersection.js +1 -1
- package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +3 -0
- package/src/core/geom/3d/aabb/aabb3_from_v3_array.spec.js +32 -0
- package/src/core/geom/3d/aabb/aabb3_intersects_aabb3.spec.js +115 -0
- package/src/core/geom/3d/aabb/aabb3_raycast.js +6 -1
- package/src/core/geom/3d/aabb/aabb3_signed_distance_sqr_to_point.js +13 -9
- package/src/core/{bvh2/aabb3 → geom/3d/aabb}/serializeAABB3Encoded_v0.js +6 -6
- package/src/core/geom/3d/{CircleMath.js → compute_circle_bounding_box.js} +1 -1
- package/src/core/geom/3d/decompose_matrix_4_array.js +18 -19
- package/src/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +1 -1
- package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/matrix}/allocate_transform_m4.js +1 -1
- package/src/core/geom/3d/normal/hemioct/decode_hemioct_to_unit.js +26 -0
- package/src/core/geom/3d/normal/hemioct/encode_unit3_hemioct.js +0 -26
- package/src/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +2 -1
- package/src/core/geom/3d/plane/computePlaneLineIntersection.js +51 -0
- package/src/core/geom/3d/plane/computePlanePlaneIntersection.js +77 -0
- package/src/core/geom/3d/plane/computePlaneRayIntersection.js +55 -0
- package/src/core/geom/3d/plane/plane3_computeLineSegmentIntersection.js +50 -0
- package/src/core/geom/3d/plane/planeRayIntersection.js +14 -0
- package/src/core/geom/3d/{tetrahedra/in_sphere_fast.js → sphere/in_sphere3d_fast.js} +1 -1
- package/src/core/geom/3d/{tetrahedra/in_sphere_robust.js → sphere/in_sphere3d_robust.js} +1 -1
- package/src/core/geom/3d/sphere/sphere_array_intersects_point.js +2 -2
- package/src/core/geom/3d/sphere/{sphereIntersectsPoint.js → sphere_intersects_point.js} +7 -4
- package/src/core/geom/3d/sphere/sphere_intersects_point.spec.js +134 -0
- package/src/core/geom/3d/sphere/sphere_intersects_ray.spec.js +49 -0
- package/src/core/geom/3d/sphere/sphere_radius_sqr_from_v3_array_transformed.js +11 -7
- package/src/core/geom/3d/tetrahedra/delaunay/{debug_validate_mesh.js → debug/debug_validate_mesh.js} +1 -1
- package/src/core/geom/3d/tetrahedra/delaunay/{push_boundary_with_validation.js → debug/push_boundary_with_validation.js} +1 -1
- package/src/core/geom/3d/tetrahedra/delaunay/{validate_cavity_boundary.js → debug/validate_cavity_boundary.js} +2 -2
- package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_cavity.js +2 -2
- package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +0 -164
- package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +87 -0
- package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricEdge.js +81 -0
- package/src/core/geom/{GeometryMath.js → 3d/triangle/rayTriangleIntersection.js} +7 -3
- package/src/core/geom/ConicRay.js +160 -152
- package/src/core/geom/Matrix4.js +2 -0
- package/src/core/geom/Quaternion.js +19 -1
- package/src/core/geom/packing/max-rect/MaxRectangles.js +5 -215
- package/src/core/geom/packing/max-rect/cost/costByBestShortSide.js +11 -0
- package/src/core/geom/packing/max-rect/cost/costByRemainingArea.js +14 -0
- package/src/core/geom/packing/max-rect/cutArea.js +79 -0
- package/src/core/geom/packing/max-rect/findBestContainer.js +58 -0
- package/src/core/geom/packing/max-rect/packOneBox.js +49 -0
- package/src/core/geom/v3_dot.js +1 -1
- package/src/core/graph/GraphUtils.js +1 -1
- package/src/core/graph/build_face_graph_from_mesh.js +1 -3
- package/src/core/graph/layout/CircleLayout.js +3 -3
- package/src/core/graph/layout/{BoxLayouter.js → box/BoxLayouter.js} +6 -50
- package/src/core/graph/layout/box/applyCentralGravityAABB2.js +29 -0
- package/src/core/json/resolvePath.spec.js +14 -0
- package/src/core/land/reactive/{compiler/ReactiveCompiler.spec.js → compileReactiveExpression.spec.js} +17 -17
- package/src/core/math/random/MersenneTwister.spec.js +19 -0
- package/src/core/math/random/randomGaussian.spec.js +9 -0
- package/src/core/math/statistics/computeStatisticalMean.js +2 -2
- package/src/core/model/node-graph/visual/NodeVisualData.js +1 -1
- package/src/core/model/reactive/model/arithmetic/ReactiveAdd.js +1 -1
- package/src/core/model/reactive/model/arithmetic/ReactiveDivide.js +3 -1
- package/src/core/model/reactive/model/arithmetic/ReactiveMultiply.js +1 -1
- package/src/core/model/reactive/model/arithmetic/ReactiveNegate.js +3 -1
- package/src/core/model/reactive/model/arithmetic/ReactiveSubtract.js +1 -1
- package/src/core/model/reactive/model/comparative/ReactiveEquals.js +1 -1
- package/src/core/model/reactive/model/comparative/ReactiveGreaterThan.js +3 -1
- package/src/core/model/reactive/model/comparative/ReactiveGreaterThanOrEqual.js +3 -1
- package/src/core/model/reactive/model/comparative/ReactiveLessThan.js +3 -1
- package/src/core/model/reactive/model/comparative/ReactiveLessThanOrEqual.js +3 -1
- package/src/core/model/reactive/model/comparative/ReactiveNotEquals.js +1 -1
- package/src/core/model/reactive/model/logic/ReactiveAnd.js +1 -1
- package/src/core/model/reactive/model/logic/ReactiveNot.js +3 -1
- package/src/core/model/reactive/model/logic/ReactiveOr.js +1 -1
- package/src/core/primitives/numbers/computeHashFloat.spec.js +7 -0
- package/src/core/process/task/util/iteratorTask.js +3 -1
- package/src/engine/animation/curve/AnimationCurve.js +34 -5
- package/src/engine/animation/curve/AnimationCurve.spec.js +100 -0
- package/src/engine/asset/AssetTransformer.js +1 -0
- package/src/engine/asset/loaders/GLTFAssetLoader.js +1 -1
- package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +2 -2
- package/src/engine/asset/preloader/Preloader.js +3 -3
- package/src/engine/computeStridedIntegerArrayHash.js +4 -2
- package/src/engine/ecs/components/Renderable.d.ts +2 -2
- package/src/engine/ecs/components/Renderable.js +1 -1
- package/src/{ecs → engine/ecs}/grid/pick.js +4 -4
- package/src/engine/ecs/gui/position/ViewportPositionSystem.js +1 -1
- package/src/engine/ecs/parent/entity_node_compute_bounding_box.js +1 -1
- package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +1 -18
- package/src/engine/ecs/systems/MotionSystem.js +7 -1
- package/src/engine/ecs/systems/SynchronizePositionSystem.js +8 -2
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +2 -2
- package/src/engine/ecs/tooltip/TooltipComponentSystem.js +1 -1
- package/src/engine/ecs/transform/Transform.js +1 -1
- package/src/engine/graphics/camera/makeScreenScissorFrustum.d.ts +1 -1
- package/src/engine/graphics/camera/makeScreenScissorFrustum.js +3 -3
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +13 -13
- package/src/engine/graphics/ecs/camera/Camera.js +1 -1
- package/src/engine/graphics/ecs/light/LightSystem.js +1 -1
- package/src/engine/graphics/ecs/mesh/Mesh.d.ts +1 -1
- package/src/engine/graphics/ecs/mesh/Mesh.js +1 -1
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +1 -1
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +1 -1
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.d.ts +1 -1
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.js +1 -1
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshSystem.js +9 -0
- package/src/engine/graphics/ecs/mesh-v2/sg_hierarchy_compute_bounding_box_via_parent_entity.d.ts +1 -1
- package/src/engine/graphics/geometry/MikkT/MikkTSpace.js +1 -1
- package/src/engine/graphics/geometry/MikkT/STSpace.js +1 -1
- package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +1 -1
- package/src/engine/graphics/geometry/skining/computeSkinnedMeshBoundingVolumes.js +1 -1
- package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +1 -1
- package/src/engine/graphics/particles/particular/engine/MovingBoundingBox.js +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +1 -1
- package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +1 -0
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
- package/src/engine/graphics/postprocess/threejs/postprocessing/TexturePass.js +2 -2
- package/src/engine/graphics/render/forward_plus/debug/createScreenGrid.js +1 -1
- package/src/engine/graphics/render/view/CameraView.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +2 -2
- package/src/engine/graphics/texture/atlas/AtlasPatch.js +2 -2
- package/src/engine/graphics/texture/atlas/TextureAtlas.spec.js +2 -2
- package/src/engine/graphics/texture/sampler/Sampler2D.js +1 -1
- package/src/engine/graphics/texture/sampler/sampler2d_compute_texel_value_conversion_scale_to_uint8.js +1 -1
- package/src/engine/graphics/util/makeMeshPreviewScene.js +1 -1
- package/src/engine/graphics/util/renderObjectToSampler2D.js +1 -1
- package/src/engine/intelligence/behavior/Behavior.spec.js +15 -0
- package/src/engine/intelligence/mcts/MoveEdge.js +1 -1
- package/src/engine/reference/v1/ReferenceManager.js +3 -0
- package/src/engine/reference/v2/Reference.js +33 -37
- package/src/engine/sound/sopra/README.md +6 -0
- package/src/engine/ui/tiles2d/computeTileGridMove.js +3 -2
- package/src/engine/ui/tiles2d/computeTileGridMove.spec.js +1 -1
- package/src/generation/automata/CaveGeneratorCellularAutomata.js +10 -7
- package/src/generation/automata/CaveGeneratorCellularAutomata.spec.js +12 -0
- package/src/generation/automata/CellularAutomata.js +5 -4
- package/src/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +25 -9
- package/src/generation/theme/AreaMask.js +1 -1
- package/src/view/View.js +1 -1
- package/src/view/elements/progress/RectangularPieProgressView.js +1 -1
- package/src/view/minimap/Minimap.js +1 -1
- package/src/view/minimap/dom/MinimapCameraView.js +1 -1
- package/src/view/minimap/gl/MinimapFogOfWar.js +1 -1
- package/src/view/tooltip/DomTooltipObserver.js +1 -1
- package/src/view/tooltip/TooltipManager.js +1 -1
- package/src/view/tooltip/TooltipView.js +1 -1
- package/src/view/util/DomSizeObserver.js +2 -2
- package/src/core/geom/2d/AABB2Math.js +0 -40
- package/src/core/geom/2d/AABB2Math.spec.js +0 -17
- package/src/core/geom/Plane.js +0 -250
- package/src/core/land/reactive/ReactiveLexer.js +0 -158
- package/src/core/land/reactive/ReactiveLexer.ts +0 -181
- package/src/core/land/reactive/ReactiveListener.ts +0 -323
- package/src/core/land/reactive/ReactiveParser.js +0 -1573
- package/src/core/land/reactive/ReactiveParser.ts +0 -1776
- package/src/core/land/reactive/ReactiveVisitor.js +0 -1
- package/src/core/land/reactive/ReactiveVisitor.ts +0 -218
- package/src/core/land/reactive/compiler/ReactiveCompiler.js +0 -350
- package/src/core/land/reactive/compiler/ReactiveNearlyCompiler.js +0 -166
- package/src/core/land/reactive/compiler/ReactiveParser.js +0 -34
- package/src/core/land/reactive/nearley/ReactiveNearley.js +0 -187
- /package/src/core/geom/{LineSegment2.js → 2d/LineSegment2.js} +0 -0
- /package/src/core/geom/{Rectangle.spec.js → 2d/Rectangle.spec.js} +0 -0
- /package/src/core/geom/{AABB2.d.ts → 2d/aabb/AABB2.d.ts} +0 -0
- /package/src/core/geom/{AABB2.spec.js → 2d/aabb/AABB2.spec.js} +0 -0
- /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/deserializeAABB3.js +0 -0
- /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/deserializeAABB3Encoded_v0.js +0 -0
- /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/deserializeAABB3Quantized16Uint.js +0 -0
- /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/serializeAABB3.js +0 -0
- /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/serializeAABB3Quantized16Uint.js +0 -0
- /package/src/{engine/graphics/ecs/mesh-v2 → core/geom/3d/vector}/allocate_v3.js +0 -0
|
@@ -12,7 +12,7 @@ import { v3_angle_between } from "../v3_angle_between.js";
|
|
|
12
12
|
* @param {number} normalZ orientation of the circle
|
|
13
13
|
* @param {number} radius
|
|
14
14
|
*/
|
|
15
|
-
export function
|
|
15
|
+
export function compute_circle_bounding_box(
|
|
16
16
|
result,
|
|
17
17
|
centerX, centerY, centerZ,
|
|
18
18
|
normalX, normalY, normalZ,
|
|
@@ -2,34 +2,35 @@ const hypot = Math.hypot;
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
|
-
* @param {number[]}
|
|
5
|
+
* @param {number[]} mat4
|
|
6
6
|
* @param {Vector3} position
|
|
7
7
|
* @param {Quaternion} rotation
|
|
8
8
|
* @param {Vector3} scale
|
|
9
9
|
*/
|
|
10
|
-
export function decompose_matrix_4_array(
|
|
11
|
-
const m11 =
|
|
12
|
-
const m12 =
|
|
13
|
-
const m13 =
|
|
10
|
+
export function decompose_matrix_4_array(mat4, position, rotation, scale) {
|
|
11
|
+
const m11 = mat4[0];
|
|
12
|
+
const m12 = mat4[1];
|
|
13
|
+
const m13 = mat4[2];
|
|
14
14
|
|
|
15
15
|
const scale_x = hypot(m11, m12, m13);
|
|
16
16
|
|
|
17
|
-
const m21 =
|
|
18
|
-
const m22 =
|
|
19
|
-
const m23 =
|
|
17
|
+
const m21 = mat4[4];
|
|
18
|
+
const m22 = mat4[5];
|
|
19
|
+
const m23 = mat4[6];
|
|
20
20
|
|
|
21
21
|
const scale_y = hypot(m21, m22, m23);
|
|
22
22
|
|
|
23
|
-
const m31 =
|
|
24
|
-
const m32 =
|
|
25
|
-
const m33 =
|
|
23
|
+
const m31 = mat4[8];
|
|
24
|
+
const m32 = mat4[9];
|
|
25
|
+
const m33 = mat4[10];
|
|
26
26
|
|
|
27
27
|
const scale_z = hypot(m31, m32, m33);
|
|
28
28
|
|
|
29
29
|
// extract rotation matrix
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
30
|
+
// take care of potential division by 0 when scale is 0. Result is inexact, but we get don't break the system at least
|
|
31
|
+
const is1 = scale_x !== 0 ? 1 / scale_x : 1e7;
|
|
32
|
+
const is2 = scale_y !== 0 ? 1 / scale_y : 1e7;
|
|
33
|
+
const is3 = scale_z !== 0 ? 1 / scale_z : 1e7;
|
|
33
34
|
|
|
34
35
|
const sm11 = m11 * is1;
|
|
35
36
|
const sm12 = m12 * is1;
|
|
@@ -43,14 +44,12 @@ export function decompose_matrix_4_array(m, position, rotation, scale) {
|
|
|
43
44
|
const sm32 = m32 * is3;
|
|
44
45
|
const sm33 = m33 * is3;
|
|
45
46
|
|
|
46
|
-
// TODO take care of cases where scale is 0
|
|
47
|
-
|
|
48
47
|
// write out results
|
|
49
48
|
|
|
50
49
|
position.set(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
mat4[12],
|
|
51
|
+
mat4[13],
|
|
52
|
+
mat4[14]
|
|
54
53
|
);
|
|
55
54
|
|
|
56
55
|
scale.set(
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { computePlanePlaneIntersection } from "../../Plane.js";
|
|
2
1
|
import Vector3 from "../../Vector3.js";
|
|
3
2
|
import { plane3_projectPoint } from "../plane/plane3_projectPoint.js";
|
|
4
3
|
import { ray_computeNearestPointToPoint } from "../ray/ray_computeNearestPointToPoint.js";
|
|
@@ -6,6 +5,7 @@ import { v3_distance_above_plane } from "../../v3_distance_above_plane.js";
|
|
|
6
5
|
import {
|
|
7
6
|
plane_three_computeConvex3PlaneIntersection
|
|
8
7
|
} from "../plane/plane_three_compute_convex3_plane_intersection.js";
|
|
8
|
+
import { computePlanePlaneIntersection } from "../plane/computePlanePlaneIntersection.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see A Survey of Efficient Representations for Independent Unit Vectors (Journal of Computer Graphics Techniques Vol. 3, No. 2, 2014)
|
|
3
|
+
*
|
|
4
|
+
* Uses hemi-octahedron for sphere approximation
|
|
5
|
+
*
|
|
6
|
+
* @param {number[]} output
|
|
7
|
+
* @param {number} output_offset
|
|
8
|
+
* @param {number} x range [-1,1]
|
|
9
|
+
* @param {number} y range [-1,1]
|
|
10
|
+
*/
|
|
11
|
+
export function decode_hemioct_to_unit(output, output_offset, x, y) {
|
|
12
|
+
// Rotate and scale the unit square back to the center diamond
|
|
13
|
+
const t_x = (x + y) * 0.5;
|
|
14
|
+
const t_y = (x - y) * 0.5;
|
|
15
|
+
|
|
16
|
+
//
|
|
17
|
+
const v_z = 1.0 - Math.abs(t_x) - Math.abs(t_y);
|
|
18
|
+
|
|
19
|
+
// normalize
|
|
20
|
+
const l2 = (t_x * t_x + t_y * t_y + v_z * v_z);
|
|
21
|
+
const m = 1 / Math.sqrt(l2);
|
|
22
|
+
|
|
23
|
+
output[output_offset] = t_x * m;
|
|
24
|
+
output[output_offset + 1] = t_y * m;
|
|
25
|
+
output[output_offset + 2] = v_z * m;
|
|
26
|
+
}
|
|
@@ -27,29 +27,3 @@ export function encode_unit_to_hemioct(output, output_offset, x, y, z) {
|
|
|
27
27
|
output[output_offset + 1] = _y;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
/**
|
|
31
|
-
* @see A Survey of Efficient Representations for Independent Unit Vectors (Journal of Computer Graphics Techniques Vol. 3, No. 2, 2014)
|
|
32
|
-
*
|
|
33
|
-
* Uses hemi-octahedron for sphere approximation
|
|
34
|
-
*
|
|
35
|
-
* @param {number[]} output
|
|
36
|
-
* @param {number} output_offset
|
|
37
|
-
* @param {number} x range [-1,1]
|
|
38
|
-
* @param {number} y range [-1,1]
|
|
39
|
-
*/
|
|
40
|
-
export function decode_hemioct_to_unit(output, output_offset, x, y) {
|
|
41
|
-
// Rotate and scale the unit square back to the center diamond
|
|
42
|
-
const t_x = (x + y) * 0.5;
|
|
43
|
-
const t_y = (x - y) * 0.5;
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
const v_z = 1.0 - Math.abs(t_x) - Math.abs(t_y);
|
|
47
|
-
|
|
48
|
-
// normalize
|
|
49
|
-
const l2 = (t_x * t_x + t_y * t_y + v_z * v_z);
|
|
50
|
-
const m = 1 / Math.sqrt(l2);
|
|
51
|
-
|
|
52
|
-
output[output_offset] = t_x * m;
|
|
53
|
-
output[output_offset + 1] = t_y * m;
|
|
54
|
-
output[output_offset + 2] = v_z * m;
|
|
55
|
-
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { encode_unit_to_hemioct } from "./encode_unit3_hemioct.js";
|
|
2
2
|
import { v3_length } from "../../../v3_length.js";
|
|
3
|
+
import { decode_hemioct_to_unit } from "./decode_hemioct_to_unit.js";
|
|
3
4
|
|
|
4
5
|
test('encode-decode', () => {
|
|
5
6
|
const v0 = [];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { v3_dot } from "../../v3_dot.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Vector3} out Result will be written here
|
|
6
|
+
* @param {number} originX Ray origin
|
|
7
|
+
* @param {number} originY Ray origin
|
|
8
|
+
* @param {number} originZ Ray origin
|
|
9
|
+
* @param {number} directionX Ray direction
|
|
10
|
+
* @param {number} directionY Ray direction
|
|
11
|
+
* @param {number} directionZ Ray direction
|
|
12
|
+
* @param {number} normalX Plane normal
|
|
13
|
+
* @param {number} normalY Plane normal
|
|
14
|
+
* @param {number} normalZ Plane normal
|
|
15
|
+
* @param {number} dist Plane distance
|
|
16
|
+
* @returns {boolean} true if intersection is found, false otherwise
|
|
17
|
+
*/
|
|
18
|
+
export function computePlaneLineIntersection(out, originX, originY, originZ, directionX, directionY, directionZ, normalX, normalY, normalZ, dist) {
|
|
19
|
+
const denom = v3_dot(directionX, directionY, directionZ, normalX, normalY, normalZ);
|
|
20
|
+
|
|
21
|
+
const p = v3_dot(normalX, normalY, normalZ, originX, originY, originZ) + dist;
|
|
22
|
+
|
|
23
|
+
if (denom !== 0) {
|
|
24
|
+
|
|
25
|
+
const t = -p / denom;
|
|
26
|
+
|
|
27
|
+
out.set(
|
|
28
|
+
directionX * t + originX,
|
|
29
|
+
directionY * t + originY,
|
|
30
|
+
directionZ * t + originZ
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return true;
|
|
34
|
+
|
|
35
|
+
} else {
|
|
36
|
+
|
|
37
|
+
if (p === 0) {
|
|
38
|
+
|
|
39
|
+
out.set(originX, originY, originZ);
|
|
40
|
+
|
|
41
|
+
return true;
|
|
42
|
+
|
|
43
|
+
} else {
|
|
44
|
+
|
|
45
|
+
//no intersection
|
|
46
|
+
return false;
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
|
|
3
|
+
Algorithm taken from http://geomalgorithms.com/a05-_intersect-1.html. See the
|
|
4
|
+
section 'Intersection of 2 Planes' and specifically the subsection
|
|
5
|
+
(A) Direct Linear Equation
|
|
6
|
+
@param {Plane} p1
|
|
7
|
+
@param {Plane} p2
|
|
8
|
+
@param {Vector3} point
|
|
9
|
+
@param {Vector3} direction
|
|
10
|
+
@returns {boolean}
|
|
11
|
+
*/
|
|
12
|
+
export function computePlanePlaneIntersection(p1, p2, point, direction) {
|
|
13
|
+
|
|
14
|
+
// the cross product gives us the direction of the line at the intersection
|
|
15
|
+
// of the two planes, and gives us an easy way to check if the two planes
|
|
16
|
+
// are parallel - the cross product will have zero magnitude
|
|
17
|
+
|
|
18
|
+
direction.crossVectors(p1.normal, p2.normal);
|
|
19
|
+
|
|
20
|
+
const magnitude = direction.lengthSqr();
|
|
21
|
+
|
|
22
|
+
if (magnitude === 0) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// now find a point on the intersection. We use the 'Direct Linear Equation'
|
|
27
|
+
// method described in the linked page, and we choose which coordinate
|
|
28
|
+
// to set as zero by seeing which has the largest absolute value in the
|
|
29
|
+
// directional vector
|
|
30
|
+
|
|
31
|
+
const X = Math.abs(direction.x);
|
|
32
|
+
const Y = Math.abs(direction.y);
|
|
33
|
+
const Z = Math.abs(direction.z);
|
|
34
|
+
|
|
35
|
+
if (Z >= X && Z >= Y) {
|
|
36
|
+
solveIntersectingPoint('z', 'x', 'y', p1, p2, point);
|
|
37
|
+
} else if (Y >= Z && Y >= X) {
|
|
38
|
+
solveIntersectingPoint('y', 'z', 'x', p1, p2, point);
|
|
39
|
+
} else {
|
|
40
|
+
solveIntersectingPoint('x', 'y', 'z', p1, p2, point);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
|
|
48
|
+
This method helps finding a point on the intersection between two planes.
|
|
49
|
+
Depending on the orientation of the planes, the problem could solve for the
|
|
50
|
+
zero point on either the x, y or z axis
|
|
51
|
+
* @param {string} zeroCoord
|
|
52
|
+
* @param {string} A
|
|
53
|
+
* @param {string} B
|
|
54
|
+
* @param {THREE.Plane} p1
|
|
55
|
+
* @param {THREE.Plane} p2
|
|
56
|
+
* @param {Vector3} result
|
|
57
|
+
*/
|
|
58
|
+
function solveIntersectingPoint(zeroCoord, A, B, p1, p2, result) {
|
|
59
|
+
const nP1 = p1.normal;
|
|
60
|
+
|
|
61
|
+
const a1 = nP1[A];
|
|
62
|
+
const b1 = nP1[B];
|
|
63
|
+
const d1 = p1.constant;
|
|
64
|
+
|
|
65
|
+
const nP2 = p2.normal;
|
|
66
|
+
|
|
67
|
+
const a2 = nP2[A];
|
|
68
|
+
const b2 = nP2[B];
|
|
69
|
+
const d2 = p2.constant;
|
|
70
|
+
|
|
71
|
+
const A0 = ((b2 * d1) - (b1 * d2)) / ((a1 * b2 - a2 * b1));
|
|
72
|
+
const B0 = ((a1 * d2) - (a2 * d1)) / ((a1 * b2 - a2 * b1));
|
|
73
|
+
|
|
74
|
+
result[zeroCoord] = 0;
|
|
75
|
+
result[A] = A0;
|
|
76
|
+
result[B] = B0;
|
|
77
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { v3_dot } from "../../v3_dot.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Vector3} out Result will be written here
|
|
6
|
+
* @param {number} originX Ray origin
|
|
7
|
+
* @param {number} originY Ray origin
|
|
8
|
+
* @param {number} originZ Ray origin
|
|
9
|
+
* @param {number} directionX Ray direction
|
|
10
|
+
* @param {number} directionY Ray direction
|
|
11
|
+
* @param {number} directionZ Ray direction
|
|
12
|
+
* @param {number} normalX Plane normal
|
|
13
|
+
* @param {number} normalY Plane normal
|
|
14
|
+
* @param {number} normalZ Plane normal
|
|
15
|
+
* @param {number} dist Plane distance
|
|
16
|
+
* @returns {boolean} true if intersection is found, false otherwise
|
|
17
|
+
*/
|
|
18
|
+
export function computePlaneRayIntersection(out, originX, originY, originZ, directionX, directionY, directionZ, normalX, normalY, normalZ, dist) {
|
|
19
|
+
const denom = v3_dot(directionX, directionY, directionZ, normalX, normalY, normalZ);
|
|
20
|
+
|
|
21
|
+
const p = v3_dot(normalX, normalY, normalZ, originX, originY, originZ) + dist;
|
|
22
|
+
|
|
23
|
+
if (denom !== 0) {
|
|
24
|
+
|
|
25
|
+
const t = -p / denom;
|
|
26
|
+
|
|
27
|
+
if (t < 0) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
out.set(
|
|
32
|
+
directionX * t + originX,
|
|
33
|
+
directionY * t + originY,
|
|
34
|
+
directionZ * t + originZ
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return true;
|
|
38
|
+
|
|
39
|
+
} else {
|
|
40
|
+
|
|
41
|
+
if (p === 0) {
|
|
42
|
+
|
|
43
|
+
out.set(originX, originY, originZ);
|
|
44
|
+
|
|
45
|
+
return true;
|
|
46
|
+
|
|
47
|
+
} else {
|
|
48
|
+
|
|
49
|
+
//no intersection
|
|
50
|
+
return false;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { v3_dot } from "../../v3_dot.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Float32Array|number[]|vec3} result
|
|
6
|
+
* @param {number} result_offset
|
|
7
|
+
* @param {number} x0
|
|
8
|
+
* @param {number} y0
|
|
9
|
+
* @param {number} z0
|
|
10
|
+
* @param {number} x1
|
|
11
|
+
* @param {number} y1
|
|
12
|
+
* @param {number} z1
|
|
13
|
+
* @param {number} normalX
|
|
14
|
+
* @param {number} normalY
|
|
15
|
+
* @param {number} normalZ
|
|
16
|
+
* @param {number} dist
|
|
17
|
+
* @returns {boolean}
|
|
18
|
+
*/
|
|
19
|
+
export function plane3_computeLineSegmentIntersection(
|
|
20
|
+
result, result_offset,
|
|
21
|
+
x0, y0, z0,
|
|
22
|
+
x1, y1, z1,
|
|
23
|
+
normalX, normalY, normalZ, dist
|
|
24
|
+
) {
|
|
25
|
+
|
|
26
|
+
const directionX = x1 - x0;
|
|
27
|
+
const directionY = y1 - y0;
|
|
28
|
+
const directionZ = z1 - z0;
|
|
29
|
+
|
|
30
|
+
const denom = v3_dot(directionX, directionY, directionZ, normalX, normalY, normalZ);
|
|
31
|
+
|
|
32
|
+
if (denom === 0) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const p = v3_dot(normalX, normalY, normalZ, x0, y0, z0) + dist;
|
|
37
|
+
|
|
38
|
+
const t = -p / denom;
|
|
39
|
+
|
|
40
|
+
if (t < 0 || t > 1) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
result[result_offset] = directionX * t + x0;
|
|
45
|
+
result[result_offset + 1] = directionY * t + y0;
|
|
46
|
+
result[result_offset + 2] = directionZ * t + z0;
|
|
47
|
+
|
|
48
|
+
return true;
|
|
49
|
+
|
|
50
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { computePlaneRayIntersection } from "./computePlaneRayIntersection.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {Vector3} out Result will be written here
|
|
6
|
+
* @param {Vector3} origin Ray origin
|
|
7
|
+
* @param {Vector3} direction Ray direction
|
|
8
|
+
* @param {Vector3} normal Plane normal
|
|
9
|
+
* @param {number} dist Plane distance
|
|
10
|
+
* @returns {boolean} true if intersection is found, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
export function planeRayIntersection(out, origin, direction, normal, dist) {
|
|
13
|
+
return computePlaneRayIntersection(out, origin.x, origin.y, origin.z, direction.x, direction.y, direction.z, normal.x, normal.y, normal.z, dist)
|
|
14
|
+
}
|
|
@@ -12,7 +12,7 @@ import { insphere } from "robust-predicates";
|
|
|
12
12
|
* @param {number} e reference point index that we are testing against the tetrahedron
|
|
13
13
|
* @returns {number}
|
|
14
14
|
*/
|
|
15
|
-
export function
|
|
15
|
+
export function in_sphere3d_robust(
|
|
16
16
|
points,
|
|
17
17
|
a, b, c, d, e
|
|
18
18
|
) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sphere_intersects_point } from "./sphere_intersects_point.js";
|
|
2
2
|
|
|
3
3
|
//
|
|
4
4
|
|
|
@@ -11,5 +11,5 @@ import { sphereIntersectsPoint } from "./sphereIntersectsPoint.js";
|
|
|
11
11
|
* @return {boolean}
|
|
12
12
|
*/
|
|
13
13
|
export function sphere_array_intersects_point(sphere, x, y, z) {
|
|
14
|
-
return
|
|
14
|
+
return sphere_intersects_point(sphere[0], sphere[1], sphere[2], sphere[3], x, y, z);
|
|
15
15
|
}
|
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
* @param {number} center_y
|
|
5
5
|
* @param {number} center_z
|
|
6
6
|
* @param {number} radius
|
|
7
|
-
* @param {number} p_x
|
|
8
|
-
* @param {number} p_y
|
|
9
|
-
* @param {number} p_z
|
|
7
|
+
* @param {number} p_x reference point X coordinate
|
|
8
|
+
* @param {number} p_y reference point Y coordinate
|
|
9
|
+
* @param {number} p_z reference point Z coordinate
|
|
10
10
|
* @returns {boolean}
|
|
11
11
|
*/
|
|
12
|
-
export function
|
|
12
|
+
export function sphere_intersects_point(
|
|
13
|
+
center_x, center_y, center_z, radius,
|
|
14
|
+
p_x, p_y, p_z
|
|
15
|
+
) {
|
|
13
16
|
|
|
14
17
|
//compute offset vector
|
|
15
18
|
const dx = center_x - p_x;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { sphere_intersects_point } from "./sphere_intersects_point.js";
|
|
2
|
+
|
|
3
|
+
test("zero volume sphere", () => {
|
|
4
|
+
|
|
5
|
+
expect(sphere_intersects_point(
|
|
6
|
+
0, 0, 0, 0,
|
|
7
|
+
0, 0, 0
|
|
8
|
+
)).toBe(false)
|
|
9
|
+
|
|
10
|
+
expect(sphere_intersects_point(
|
|
11
|
+
0, 0, 0, 0,
|
|
12
|
+
-1, 0, 0
|
|
13
|
+
)).toBe(false)
|
|
14
|
+
|
|
15
|
+
expect(sphere_intersects_point(
|
|
16
|
+
0, 0, 0, 0,
|
|
17
|
+
1, 0, 0
|
|
18
|
+
)).toBe(false)
|
|
19
|
+
|
|
20
|
+
expect(sphere_intersects_point(
|
|
21
|
+
0, 0, 0, 0,
|
|
22
|
+
0, -1, 0
|
|
23
|
+
)).toBe(false)
|
|
24
|
+
|
|
25
|
+
expect(sphere_intersects_point(
|
|
26
|
+
0, 0, 0, 0,
|
|
27
|
+
0, 1, 0
|
|
28
|
+
)).toBe(false)
|
|
29
|
+
|
|
30
|
+
expect(sphere_intersects_point(
|
|
31
|
+
0, 0, 0, 0,
|
|
32
|
+
0, 0, -1
|
|
33
|
+
)).toBe(false)
|
|
34
|
+
|
|
35
|
+
expect(sphere_intersects_point(
|
|
36
|
+
0, 0, 0, 0,
|
|
37
|
+
0, 0, 1
|
|
38
|
+
)).toBe(false)
|
|
39
|
+
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("out of bounds, centered on origin", () => {
|
|
43
|
+
|
|
44
|
+
// X
|
|
45
|
+
expect(sphere_intersects_point(
|
|
46
|
+
0, 0, 0, 1,
|
|
47
|
+
-2, 0, 0
|
|
48
|
+
)).toBe(false)
|
|
49
|
+
|
|
50
|
+
expect(sphere_intersects_point(
|
|
51
|
+
0, 0, 0, 1,
|
|
52
|
+
2, 0, 0
|
|
53
|
+
)).toBe(false)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// Y
|
|
57
|
+
expect(sphere_intersects_point(
|
|
58
|
+
0, 0, 0, 1,
|
|
59
|
+
0, -2, 0
|
|
60
|
+
)).toBe(false)
|
|
61
|
+
|
|
62
|
+
expect(sphere_intersects_point(
|
|
63
|
+
0, 0, 0, 1,
|
|
64
|
+
0, 2, 0
|
|
65
|
+
)).toBe(false)
|
|
66
|
+
|
|
67
|
+
// Z
|
|
68
|
+
expect(sphere_intersects_point(
|
|
69
|
+
0, 0, 0, 1,
|
|
70
|
+
0, 0, -2
|
|
71
|
+
)).toBe(false)
|
|
72
|
+
|
|
73
|
+
expect(sphere_intersects_point(
|
|
74
|
+
0, 0, 0, 1,
|
|
75
|
+
0, 0, 2
|
|
76
|
+
)).toBe(false)
|
|
77
|
+
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("out of bounds with offset origin", () => {
|
|
81
|
+
|
|
82
|
+
expect(sphere_intersects_point(
|
|
83
|
+
3, -5, 7, 1,
|
|
84
|
+
1, -5, 7
|
|
85
|
+
)).toBe(false)
|
|
86
|
+
|
|
87
|
+
expect(sphere_intersects_point(
|
|
88
|
+
3, -5, 7, 1,
|
|
89
|
+
5, -5, 7
|
|
90
|
+
)).toBe(false)
|
|
91
|
+
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("in bounds", () => {
|
|
95
|
+
|
|
96
|
+
expect(sphere_intersects_point(
|
|
97
|
+
0, 0, 0, 2,
|
|
98
|
+
0, 0, 0
|
|
99
|
+
)).toBe(true)
|
|
100
|
+
|
|
101
|
+
// X
|
|
102
|
+
expect(sphere_intersects_point(
|
|
103
|
+
0, 0, 0, 2,
|
|
104
|
+
-1, 0, 0
|
|
105
|
+
)).toBe(true)
|
|
106
|
+
|
|
107
|
+
expect(sphere_intersects_point(
|
|
108
|
+
5, 5, 5, 2,
|
|
109
|
+
4, 5, 5
|
|
110
|
+
)).toBe(true)
|
|
111
|
+
|
|
112
|
+
// Y
|
|
113
|
+
expect(sphere_intersects_point(
|
|
114
|
+
0, 0, 0, 2,
|
|
115
|
+
0, -1, 0
|
|
116
|
+
)).toBe(true)
|
|
117
|
+
|
|
118
|
+
expect(sphere_intersects_point(
|
|
119
|
+
5, 5, 5, 2,
|
|
120
|
+
5, 4, 5
|
|
121
|
+
)).toBe(true)
|
|
122
|
+
|
|
123
|
+
// Z
|
|
124
|
+
expect(sphere_intersects_point(
|
|
125
|
+
0, 0, 0, 2,
|
|
126
|
+
0, 0, -1
|
|
127
|
+
)).toBe(true)
|
|
128
|
+
|
|
129
|
+
expect(sphere_intersects_point(
|
|
130
|
+
5, 5, 5, 2,
|
|
131
|
+
5, 5, 4
|
|
132
|
+
)).toBe(true)
|
|
133
|
+
|
|
134
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { sphere_intersects_ray } from "./sphere_intersects_ray.js";
|
|
2
|
+
|
|
3
|
+
test("ray from -X to +X intersects sphere", () => {
|
|
4
|
+
expect(sphere_intersects_ray(
|
|
5
|
+
0, 0, 0, 1,
|
|
6
|
+
-2, 0, 0,
|
|
7
|
+
1, 0, 0
|
|
8
|
+
)).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("ray from +X to -X intersects sphere", () => {
|
|
12
|
+
expect(sphere_intersects_ray(
|
|
13
|
+
0, 0, 0, 1,
|
|
14
|
+
2, 0, 0,
|
|
15
|
+
-1, 0, 0
|
|
16
|
+
)).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("ray from -Y to +Y intersects sphere", () => {
|
|
20
|
+
expect(sphere_intersects_ray(
|
|
21
|
+
0, 0, 0, 1,
|
|
22
|
+
0, -2, 0,
|
|
23
|
+
0, 1, 0
|
|
24
|
+
)).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("ray from +Y to -Y intersects sphere", () => {
|
|
28
|
+
expect(sphere_intersects_ray(
|
|
29
|
+
0, 0, 0, 1,
|
|
30
|
+
0, 2, 0,
|
|
31
|
+
0, -1, 0
|
|
32
|
+
)).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("ray from -Z to +Z intersects sphere", () => {
|
|
36
|
+
expect(sphere_intersects_ray(
|
|
37
|
+
0, 0, 0, 1,
|
|
38
|
+
0, 0, -2,
|
|
39
|
+
0, 0, 1
|
|
40
|
+
)).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("ray from +Z to -Z intersects sphere", () => {
|
|
44
|
+
expect(sphere_intersects_ray(
|
|
45
|
+
0, 0, 0, 1,
|
|
46
|
+
0, 0, 2,
|
|
47
|
+
0, 0, -1
|
|
48
|
+
)).toBe(true);
|
|
49
|
+
});
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Compute squared radius of bonding sphere centered on 0,0,0 from a set of points and a transform matrix that is to be applied to the points prior to calculation of bounds
|
|
3
3
|
* @param {number[]|ArrayLike<number>} input
|
|
4
|
-
* @param {number} input_length
|
|
5
|
-
* @param {ArrayLike<number>|number[]|Float32Array}
|
|
4
|
+
* @param {number} input_length length of the input array, foe example if there is just 1 vector in the input, length will be 3
|
|
5
|
+
* @param {ArrayLike<number>|number[]|Float32Array} mat4 4x4 transformation matrix
|
|
6
6
|
* @returns {number}
|
|
7
7
|
*/
|
|
8
|
-
export function sphere_radius_sqr_from_v3_array_transformed(
|
|
8
|
+
export function sphere_radius_sqr_from_v3_array_transformed(
|
|
9
|
+
input,
|
|
10
|
+
input_length,
|
|
11
|
+
mat4
|
|
12
|
+
) {
|
|
9
13
|
let result = 0;
|
|
10
14
|
|
|
11
15
|
for (let i = 0; i < input_length; i += 3) {
|
|
@@ -13,9 +17,9 @@ export function sphere_radius_sqr_from_v3_array_transformed(input, input_length,
|
|
|
13
17
|
const y = input[i + 1];
|
|
14
18
|
const z = input[i + 2];
|
|
15
19
|
|
|
16
|
-
const _x =
|
|
17
|
-
const _y =
|
|
18
|
-
const _z =
|
|
20
|
+
const _x = mat4[0] * x + mat4[4] * y + mat4[8] * z + mat4[12];
|
|
21
|
+
const _y = mat4[1] * x + mat4[5] * y + mat4[9] * z + mat4[13];
|
|
22
|
+
const _z = mat4[2] * x + mat4[6] * y + mat4[10] * z + mat4[14];
|
|
19
23
|
|
|
20
24
|
const l2 = _x * _x + _y * _y + _z * _z;
|
|
21
25
|
|