@woosh/meep-engine 2.49.9 → 2.50.1
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/actions/concrete/ArrayCopyAction.js +1 -1
- package/package.json +1 -1
- package/src/core/binary/BinaryBuffer.js +1 -1
- package/src/core/binary/BinaryBuffer.spec.js +128 -0
- package/src/core/binary/int32_to_binary_string.js +4 -1
- package/src/core/binary/int32_to_binary_string.spec.js +9 -0
- package/src/core/bvh2/BinaryNode.js +0 -30
- package/src/core/bvh2/binary/2/BinaryUint32BVH.js +1 -1
- package/src/core/bvh2/binary/IndexedBinaryBVH.js +1 -1
- package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +1 -1
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +1 -1
- package/src/core/cache/Cache.js +31 -29
- package/src/core/cache/Cache.spec.js +4 -1
- package/src/core/collection/HashMap.js +1 -1
- package/src/core/collection/array/{copyArray.js → array_copy.js} +1 -24
- package/src/core/collection/array/array_copy_entire.js +21 -0
- package/src/core/collection/array/typed/typed_array_copy.js +1 -1
- package/src/core/collection/queue/Deque.d.ts +4 -0
- package/src/core/collection/queue/Deque.js +5 -7
- package/src/core/collection/queue/Deque.spec.js +107 -0
- package/src/core/collection/table/RowFirstTable.js +1 -1
- package/src/core/geom/2d/aabb/AABB2.d.ts +14 -0
- package/src/core/geom/2d/aabb/AABB2.js +9 -7
- package/src/core/geom/2d/aabb/AABB2.spec.js +100 -0
- package/src/core/geom/2d/aabb/aabb2_compute_center_from_multiple.spec.js +11 -0
- package/src/core/geom/2d/aabb/aabb2_compute_overlap.spec.js +56 -0
- package/src/core/geom/2d/aabb/aabb2_contains.spec.js +40 -0
- package/src/core/geom/2d/bvh/Node2.js +1 -1
- package/src/core/geom/2d/convex-hull/fixed_convex_hull_humus.js +1 -1
- package/src/core/geom/2d/convex-hull/fixed_convex_hull_relaxation.js +1 -1
- package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_2d.js +35 -0
- package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_array_2d.js +51 -0
- package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_vectors_2d.js +15 -0
- package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_vectors_array_2d.js +30 -0
- package/src/core/geom/2d/line/line_segment_line_segment_intersection_exists_2d.js +29 -0
- package/src/core/geom/3d/aabb/AABB3.d.ts +4 -0
- package/src/core/geom/3d/aabb/AABB3.spec.js +30 -0
- package/src/core/geom/3d/aabb/aabb3_detailed_volume_intersection.js +4 -4
- package/src/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +5 -5
- package/src/core/geom/3d/matrix/m4_make_translation.js +1 -1
- package/src/core/geom/3d/plane/is_point_within_planes.js +1 -1
- package/src/core/geom/3d/plane/lerp_planes_to_array.js +2 -0
- package/src/core/geom/3d/plane/{plane_computeConvex3PlaneIntersection.js → plane3_compute_convex_3_plane_intersection.js} +1 -1
- package/src/core/geom/3d/plane/{plane3_computeLineSegmentIntersection.js → plane3_compute_line_segment_intersection.js} +1 -1
- package/src/core/geom/3d/plane/{computePlanePlaneIntersection.js → plane3_compute_plane_intersection.js} +15 -11
- package/src/core/geom/3d/plane/{computePlaneLineIntersection.js → plane3_compute_ray_intersection.js} +5 -1
- package/src/core/geom/3d/plane/plane3_intersect_plane.js +14 -0
- package/src/core/geom/3d/plane/{plane_three_compute_convex3_plane_intersection.js → plane3_three_compute_convex_3_plane_intersection.js} +7 -4
- package/src/core/geom/3d/plane/planeRayIntersection.js +2 -2
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +1 -1
- package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +1 -1
- package/src/core/geom/3d/tetrahedra/compute_bounding_simplex_3d.js +5 -5
- package/src/core/geom/3d/tetrahedra/compute_circumsphere.js +1 -1
- package/src/core/geom/3d/tetrahedra/delaunay/fill_in_a_cavity.js +1 -1
- package/src/core/geom/3d/topology/bounds/computeTriangleClusterNormalBoundingCone.js +1 -1
- package/src/core/geom/3d/topology/expandConnectivityByLocality.js +1 -1
- package/src/core/geom/3d/topology/struct/binary/BinaryTopology.js +1 -1
- package/src/core/geom/Quaternion.d.ts +11 -0
- package/src/core/geom/Quaternion.js +36 -27
- package/src/core/geom/Quaternion.spec.js +141 -0
- package/src/core/geom/Vector2.d.ts +5 -1
- package/src/core/geom/Vector2.js +24 -0
- package/src/core/geom/Vector3.d.ts +6 -0
- package/src/core/geom/Vector3.spec.js +60 -0
- package/src/core/graph/GraphUtils.js +4 -2
- package/src/core/graph/layout/CircleLayout.js +4 -2
- package/src/core/math/vector_nd_dot.js +16 -0
- package/src/core/math/{normalizeArrayVector.js → vector_nd_normalize.js} +3 -3
- package/src/core/math/{normalizeArrayVector.spec.js → vector_nd_normalize.spec.js} +3 -3
- package/src/core/process/PromiseWatcher.spec.js +1 -1
- package/src/engine/animation/curve/compression/downsample_float_array_curve_by_error.js +1 -1
- package/src/engine/ecs/EntityBlueprint.d.ts +14 -0
- package/src/engine/ecs/EntityBlueprint.js +2 -2
- package/src/engine/ecs/EntityBlueprint.spec.js +52 -0
- package/src/engine/ecs/EntityBuilder.js +8 -0
- package/src/engine/ecs/EntityManager.d.ts +1 -0
- package/src/engine/ecs/EntityManager.js +17 -213
- package/src/engine/ecs/EntityManager.spec.js +62 -1
- package/src/engine/ecs/System.js +8 -2
- package/src/engine/ecs/fow/FogOfWar.js +1 -1
- package/src/engine/ecs/guid/GUID.js +1 -1
- package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +1 -1
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +1 -1
- package/src/engine/ecs/transform/Transform.d.ts +2 -0
- package/src/engine/ecs/transform/Transform.spec.js +63 -0
- package/src/engine/ecs/transform-attachment/TransformAttachment.d.ts +17 -1
- package/src/engine/ecs/transform-attachment/TransformAttachment.js +12 -2
- package/src/engine/ecs/transform-attachment/TransformAttachment.spec.js +103 -0
- package/src/engine/graphics/ecs/camera/Camera.js +2 -2
- package/src/engine/graphics/ecs/path/entity/EntityPath.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/computeFrenetFrames.js +1 -1
- package/src/engine/graphics/geometry/MikkT/GenerateTSpaces.js +1 -1
- package/src/engine/graphics/geometry/MikkT/m_getNormal.js +1 -1
- package/src/engine/graphics/geometry/MikkT/m_getTexCoord.js +1 -1
- package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +1 -1
- package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +1 -1
- package/src/engine/graphics/geometry/optimization/merge/merge_geometry_hierarchy.js +1 -1
- package/src/engine/graphics/impostors/octahedral/util/build_cutout_from_atlas_by_alpha.js +1 -1
- package/src/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +1 -1
- package/src/engine/graphics/render/Lines.js +1 -1
- package/src/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.js +1 -1
- package/src/engine/graphics/render/forward_plus/LightManager.js +1 -1
- package/src/engine/graphics/render/forward_plus/computeFrustumCorners.js +10 -10
- package/src/engine/graphics/render/forward_plus/model/Decal.js +1 -1
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +1 -1
- package/src/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +1 -1
- package/src/engine/graphics/render/layers/RenderLayerUtils.js +3 -3
- package/src/engine/graphics/render/view/CameraView.js +1 -1
- package/src/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +1 -1
- package/src/engine/graphics/render/webgpu/sample/MeshInstance.js +1 -1
- package/src/engine/graphics/sh3/LightProbeVolume.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/make_sky_hosek.js +1 -1
- package/src/engine/graphics/sh3/prototypeSH3Probe.js +1 -1
- package/src/engine/graphics/texture/3d/scs3d_read_2d_slice.js +1 -1
- package/src/engine/graphics/texture/CanvasClone.js +5 -1
- package/src/engine/graphics/texture/sampler/Sampler2D.js +14 -75
- package/src/engine/graphics/texture/sampler/bicubic.js +19 -19
- package/src/engine/graphics/texture/sampler/convertSampler2D2DataURL.spec.js +10 -0
- package/src/engine/graphics/texture/sampler/copy_Sampler2D_channel_data.spec.js +90 -0
- package/src/engine/graphics/texture/sampler/differenceSampler.js +13 -8
- package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_Chamfer.js +140 -0
- package/src/engine/graphics/texture/sampler/distance/computeSignedDistanceField_NaiveFlood.js +130 -0
- package/src/engine/graphics/texture/sampler/distance/computeUnsignedDistanceField.js +10 -0
- package/src/engine/graphics/texture/sampler/distance/computeUnsignedDistanceField.spec.js +183 -0
- package/src/engine/graphics/texture/sampler/distance/computeUnsignedDistanceField_Chamfer.js +133 -0
- package/src/engine/graphics/texture/sampler/filter/mitchell.js +4 -0
- package/src/engine/graphics/texture/sampler/loadSampler2D.js +5 -2
- package/src/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.js +8 -3
- package/src/engine/graphics/texture/sampler/resize/sampler2d_downsample_mipmap.spec.js +13 -0
- package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min_indices.js +58 -0
- package/src/engine/graphics/trail/TemporalPath.js +0 -36
- package/src/engine/intelligence/behavior/composite/ParallelBehavior.spec.js +12 -12
- package/src/engine/intelligence/behavior/composite/SequenceBehavior.spec.js +17 -0
- package/src/engine/intelligence/behavior/primitive/SucceedingBehavior.js +3 -1
- package/src/engine/knowledge/database/StaticKnowledgeDataTable.d.ts +7 -1
- package/src/engine/knowledge/database/StaticKnowledgeDataTable.spec.js +21 -0
- package/src/engine/knowledge/database/StaticKnowledgeDataTableDescriptor.d.ts +2 -2
- package/src/engine/logging/ConsoleLoggerBackend.js +4 -0
- package/src/engine/logging/VoidLoggerBackend.js +12 -0
- package/src/engine/navigation/ecs/components/computeCatmullRomSpline.js +1 -1
- package/src/engine/navigation/ecs/components/computeCatmullRomSplineUniformDistance.js +1 -1
- package/src/engine/physics/cannon/CannonJSPhysicsSystem.js +1 -1
- package/src/engine/save/GameStateLoader.js +1 -1
- package/src/engine/scene/Scene.d.ts +2 -0
- package/src/engine/scene/Scene.js +2 -2
- package/src/engine/scene/Scene.spec.js +20 -0
- package/src/engine/scene/SceneManager.d.ts +4 -0
- package/src/engine/scene/SceneManager.js +46 -23
- package/src/engine/scene/SceneManager.spec.js +131 -0
- package/src/engine/sound/material/detector/terrain/TerrainSoundMaterialSurfaceDetector.js +2 -2
- package/src/engine/ui/GUIEngine.js +1 -1
- package/src/generation/grid/GridData.js +8 -2
- package/src/generation/grid/GridData.spec.js +5 -0
- package/src/generation/grid/generation/util/buildUnsignedDistanceField.js +3 -1
- package/src/generation/markers/MarkerNode.js +2 -2
- package/src/generation/markers/actions/MarkerNodeActionEntityPlacement.js +1 -1
- package/src/generation/theme/AreaMask.js +3 -1
- package/src/view/elements/progress/RectangularPieProgressView.js +8 -6
- package/src/view/minimap/dom/MinimapCameraView.js +3 -3
- package/src/core/geom/2d/LineSegment2.js +0 -175
- package/src/core/geom/3d/plane/computePlaneRayIntersection.js +0 -55
- package/src/core/geom/Matrix4.js +0 -275
- package/src/engine/graphics/texture/sampler/distanceField.js +0 -411
- package/src/engine/graphics/texture/sampler/distanceField.spec.js +0 -184
- package/src/engine/physics/cannon/cannon.min.js +0 -27
- package/src/generation/grid/MarkerMatchCounter.js +0 -25
- /package/src/engine/physics/spring/{Spring.js → computeHookeForce.js} +0 -0
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 2-D line Mathematics
|
|
3
|
-
* @author Alex Goldring 2019
|
|
4
|
-
* @copyright Alex Goldring 2019
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
function LineSegment2() {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {Vector2} p0
|
|
17
|
-
* @param {Vector2} p1
|
|
18
|
-
* @param {Vector2} p2
|
|
19
|
-
* @param {Vector2} p3
|
|
20
|
-
* @returns {[number,number]}
|
|
21
|
-
*/
|
|
22
|
-
export function computeLine2Intersection(p0, p1, p2, p3) {
|
|
23
|
-
const p0_x = p0.x;
|
|
24
|
-
const p0_y = p0.y;
|
|
25
|
-
const p1_x = p1.x;
|
|
26
|
-
const p1_y = p1.y;
|
|
27
|
-
const p2_x = p2.x;
|
|
28
|
-
const p2_y = p2.y;
|
|
29
|
-
const p3_x = p3.x;
|
|
30
|
-
const p3_y = p3.y;
|
|
31
|
-
|
|
32
|
-
const result = [];
|
|
33
|
-
|
|
34
|
-
if (line2_line2_intersection(result, p0_x, p0_y, p1_x, p1_y, p2_x, p2_y, p3_x, p3_y)) {
|
|
35
|
-
return result;
|
|
36
|
-
} else {
|
|
37
|
-
return null; // No collision
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @param {number[]} result
|
|
45
|
-
* @param {number} a0_x
|
|
46
|
-
* @param {number} a0_y
|
|
47
|
-
* @param {number} a1_x
|
|
48
|
-
* @param {number} a1_y
|
|
49
|
-
* @param {number} b2_x
|
|
50
|
-
* @param {number} b2_y
|
|
51
|
-
* @param {number} b3_x
|
|
52
|
-
* @param {number} b3_y
|
|
53
|
-
* @return {boolean}
|
|
54
|
-
*/
|
|
55
|
-
export function line2_line2_intersection(result, a0_x, a0_y, a1_x, a1_y, b2_x, b2_y, b3_x, b3_y) {
|
|
56
|
-
|
|
57
|
-
const s1_x = a1_x - a0_x;
|
|
58
|
-
const s1_y = a1_y - a0_y;
|
|
59
|
-
const s2_x = b3_x - b2_x;
|
|
60
|
-
const s2_y = b3_y - b2_y;
|
|
61
|
-
|
|
62
|
-
const dy_02 = a0_y - b2_y;
|
|
63
|
-
const dx_02 = a0_x - b2_x;
|
|
64
|
-
|
|
65
|
-
const denom = -s2_x * s1_y + s1_x * s2_y;
|
|
66
|
-
|
|
67
|
-
const s = (-s1_y * dx_02 + s1_x * dy_02) / denom;
|
|
68
|
-
const t = (s2_x * dy_02 - s2_y * dx_02) / denom;
|
|
69
|
-
|
|
70
|
-
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
|
|
71
|
-
// Collision detected
|
|
72
|
-
|
|
73
|
-
const intX = a0_x + (t * s1_x);
|
|
74
|
-
const intY = a0_y + (t * s1_y);
|
|
75
|
-
|
|
76
|
-
result[0] = intX;
|
|
77
|
-
result[1] = intY;
|
|
78
|
-
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return false; // No collision
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Adapted from answer by iMalc from stackoverflow.com "how do you detect where two line segments intersect"
|
|
87
|
-
* @link https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
|
|
88
|
-
* @param {Vector2} a0 start of first segment
|
|
89
|
-
* @param {Vector2} a1 end of first segment
|
|
90
|
-
* @param {Vector2} b0 start of second segment
|
|
91
|
-
* @param {Vector2} b1 end of second segment
|
|
92
|
-
* @param {Vector2} result resulting intersection point will be stored here if intersection exists
|
|
93
|
-
* @returns {boolean} True if segments intersect, False otherwise
|
|
94
|
-
*/
|
|
95
|
-
function intersectionPoint(a0, a1, b0, b1, result) {
|
|
96
|
-
return intersectionPointRaw(a0.x, a0.y, a1.x, a1.y, b0.x, b0.y, b1.x, b1.y, result);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
* @param {number} a0_x
|
|
102
|
-
* @param {number} a0_y
|
|
103
|
-
* @param {number} a1_x
|
|
104
|
-
* @param {number} a1_y
|
|
105
|
-
* @param {number} b0_x
|
|
106
|
-
* @param {number} b0_y
|
|
107
|
-
* @param {number} b1_x
|
|
108
|
-
* @param {number} b1_y
|
|
109
|
-
* @returns {boolean} True if segments intersect, False otherwise
|
|
110
|
-
* @public
|
|
111
|
-
*/
|
|
112
|
-
export function line2SegmentsIntersect(a0_x, a0_y, a1_x, a1_y, b0_x, b0_y, b1_x, b1_y) {
|
|
113
|
-
const s1_x = a1_x - a0_x;
|
|
114
|
-
const s1_y = a1_y - a0_y;
|
|
115
|
-
const s2_x = b1_x - b0_x;
|
|
116
|
-
const s2_y = b1_y - b0_y;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const denom = (-s2_x * s1_y + s1_x * s2_y);
|
|
120
|
-
|
|
121
|
-
const dy0_ab = a0_y - b0_y;
|
|
122
|
-
const dx0_ab = a0_x - b0_x;
|
|
123
|
-
|
|
124
|
-
const s = (-s1_y * dx0_ab + s1_x * dy0_ab) / denom;
|
|
125
|
-
const t = (s2_x * dy0_ab - s2_y * dx0_ab) / denom;
|
|
126
|
-
|
|
127
|
-
return s >= 0 && s <= 1 && t >= 0 && t <= 1;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
*
|
|
133
|
-
* @param {number} a0_x
|
|
134
|
-
* @param {number} a0_y
|
|
135
|
-
* @param {number} a1_x
|
|
136
|
-
* @param {number} a1_y
|
|
137
|
-
* @param {number} b0_x
|
|
138
|
-
* @param {number} b0_y
|
|
139
|
-
* @param {number} b1_x
|
|
140
|
-
* @param {number} b1_y
|
|
141
|
-
* @param {Vector2} result resulting intersection point will be stored here if intersection exists
|
|
142
|
-
* @returns {boolean} True if segments intersect, False otherwise
|
|
143
|
-
* @public
|
|
144
|
-
*/
|
|
145
|
-
function intersectionPointRaw(a0_x, a0_y, a1_x, a1_y, b0_x, b0_y, b1_x, b1_y, result) {
|
|
146
|
-
const s1_x = a1_x - a0_x;
|
|
147
|
-
const s1_y = a1_y - a0_y;
|
|
148
|
-
const s2_x = b1_x - b0_x;
|
|
149
|
-
const s2_y = b1_y - b0_y;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const denom = (-s2_x * s1_y + s1_x * s2_y);
|
|
153
|
-
|
|
154
|
-
const s = (-s1_y * (a0_x - b0_x) + s1_x * (a0_y - b0_y)) / denom;
|
|
155
|
-
const t = (s2_x * (a0_y - b0_y) - s2_y * (a0_x - b0_x)) / denom;
|
|
156
|
-
|
|
157
|
-
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
|
|
158
|
-
// Collision detected
|
|
159
|
-
|
|
160
|
-
const i_x = a0_x + (t * s1_x);
|
|
161
|
-
const i_y = a0_y + (t * s1_y);
|
|
162
|
-
|
|
163
|
-
result.set(i_x, i_y);
|
|
164
|
-
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
LineSegment2.intersectionPoint = intersectionPoint;
|
|
173
|
-
LineSegment2.intersectionPointRaw = intersectionPointRaw;
|
|
174
|
-
|
|
175
|
-
export default LineSegment2;
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
}
|
package/src/core/geom/Matrix4.js
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
import Vector3 from "./Vector3.js";
|
|
2
|
-
|
|
3
|
-
const _z = new Vector3();
|
|
4
|
-
const _x = new Vector3();
|
|
5
|
-
const _y = new Vector3();
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated use arrays instead or mat4 from gl-matrix
|
|
9
|
-
*/
|
|
10
|
-
export class Matrix4 {
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @constructor
|
|
14
|
-
* @class
|
|
15
|
-
*/
|
|
16
|
-
constructor() {
|
|
17
|
-
console.warn("deprecated, use plain arrays or Float32Array instead")
|
|
18
|
-
|
|
19
|
-
this.a0 = 1;
|
|
20
|
-
this.a1 = 0;
|
|
21
|
-
this.a2 = 0;
|
|
22
|
-
this.a3 = 0;
|
|
23
|
-
|
|
24
|
-
this.b0 = 0;
|
|
25
|
-
this.b1 = 1;
|
|
26
|
-
this.b2 = 0;
|
|
27
|
-
this.b3 = 0;
|
|
28
|
-
|
|
29
|
-
this.c0 = 0;
|
|
30
|
-
this.c1 = 0;
|
|
31
|
-
this.c2 = 1;
|
|
32
|
-
this.c3 = 0;
|
|
33
|
-
|
|
34
|
-
this.d0 = 0;
|
|
35
|
-
this.d1 = 0;
|
|
36
|
-
this.d2 = 0;
|
|
37
|
-
this.d3 = 1;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
* @param {Vector3} eye
|
|
43
|
-
* @param {Vector3} target
|
|
44
|
-
* @param {Vector3} up
|
|
45
|
-
*/
|
|
46
|
-
lookAt(eye, target, up) {
|
|
47
|
-
// compute direction vector
|
|
48
|
-
_z.subVectors(eye, target);
|
|
49
|
-
|
|
50
|
-
const delta_length_sqr = _z.lengthSqr();
|
|
51
|
-
|
|
52
|
-
if (delta_length_sqr === 0) {
|
|
53
|
-
// eye and target are at the same place
|
|
54
|
-
_z.set(0, 0, 1);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
_z.normalize();
|
|
58
|
-
_x.crossVectors(up, _z);
|
|
59
|
-
|
|
60
|
-
if (_x.lengthSqr() === 0) {
|
|
61
|
-
// up and direction are parallel
|
|
62
|
-
|
|
63
|
-
// jitter direction a little
|
|
64
|
-
if (Math.abs(up.z) === 1) {
|
|
65
|
-
_z.x += 0.0001;
|
|
66
|
-
} else {
|
|
67
|
-
_z.z += 0.0001;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// recompute normalized direction and cross product
|
|
71
|
-
_z.normalize();
|
|
72
|
-
|
|
73
|
-
_x.crossVectors(up, _z);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
_x.normalize();
|
|
77
|
-
|
|
78
|
-
_y.crossVectors(_z, _x);
|
|
79
|
-
|
|
80
|
-
this.a0 = _x.x;
|
|
81
|
-
this.a1 = _x.y;
|
|
82
|
-
this.a2 = _x.z;
|
|
83
|
-
|
|
84
|
-
this.b0 = _y.x;
|
|
85
|
-
this.b1 = _y.y;
|
|
86
|
-
this.b2 = _y.z;
|
|
87
|
-
|
|
88
|
-
this.c0 = _z.x;
|
|
89
|
-
this.c1 = _z.y;
|
|
90
|
-
this.c2 = _z.z;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
* @returns {number}
|
|
96
|
-
*/
|
|
97
|
-
determinant() {
|
|
98
|
-
|
|
99
|
-
const n11 = this.a0;
|
|
100
|
-
const n12 = this.b0;
|
|
101
|
-
const n13 = this.c0;
|
|
102
|
-
const n14 = this.d0;
|
|
103
|
-
|
|
104
|
-
const n21 = this.a1;
|
|
105
|
-
const n22 = this.b1;
|
|
106
|
-
const n23 = this.c1;
|
|
107
|
-
const n24 = this.d1;
|
|
108
|
-
|
|
109
|
-
const n31 = this.a2;
|
|
110
|
-
const n32 = this.b2;
|
|
111
|
-
const n33 = this.c2;
|
|
112
|
-
const n34 = this.d2;
|
|
113
|
-
|
|
114
|
-
const n41 = this.a3;
|
|
115
|
-
const n42 = this.b3;
|
|
116
|
-
const n43 = this.c3;
|
|
117
|
-
const n44 = this.d3;
|
|
118
|
-
|
|
119
|
-
//TODO: make this more efficient
|
|
120
|
-
//( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
n41 * (
|
|
124
|
-
+n14 * n23 * n32
|
|
125
|
-
- n13 * n24 * n32
|
|
126
|
-
- n14 * n22 * n33
|
|
127
|
-
+ n12 * n24 * n33
|
|
128
|
-
+ n13 * n22 * n34
|
|
129
|
-
- n12 * n23 * n34
|
|
130
|
-
) +
|
|
131
|
-
n42 * (
|
|
132
|
-
+n11 * n23 * n34
|
|
133
|
-
- n11 * n24 * n33
|
|
134
|
-
+ n14 * n21 * n33
|
|
135
|
-
- n13 * n21 * n34
|
|
136
|
-
+ n13 * n24 * n31
|
|
137
|
-
- n14 * n23 * n31
|
|
138
|
-
) +
|
|
139
|
-
n43 * (
|
|
140
|
-
+n11 * n24 * n32
|
|
141
|
-
- n11 * n22 * n34
|
|
142
|
-
- n14 * n21 * n32
|
|
143
|
-
+ n12 * n21 * n34
|
|
144
|
-
+ n14 * n22 * n31
|
|
145
|
-
- n12 * n24 * n31
|
|
146
|
-
) +
|
|
147
|
-
n44 * (
|
|
148
|
-
-n13 * n22 * n31
|
|
149
|
-
- n11 * n23 * n32
|
|
150
|
-
+ n11 * n22 * n33
|
|
151
|
-
+ n13 * n21 * n32
|
|
152
|
-
- n12 * n21 * n33
|
|
153
|
-
+ n12 * n23 * n31
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
* @param {Vector3} position
|
|
163
|
-
* @param {Quaternion} rotation
|
|
164
|
-
* @param {Vector3} scale
|
|
165
|
-
*/
|
|
166
|
-
compose(position, rotation, scale) {
|
|
167
|
-
var x = rotation.x, y = rotation.y, z = rotation.z, w = rotation.w;
|
|
168
|
-
|
|
169
|
-
var x2 = x + x, y2 = y + y, z2 = z + z;
|
|
170
|
-
var xx = x * x2, xy = x * y2, xz = x * z2;
|
|
171
|
-
var yy = y * y2, yz = y * z2, zz = z * z2;
|
|
172
|
-
var wx = w * x2, wy = w * y2, wz = w * z2;
|
|
173
|
-
|
|
174
|
-
var sx = scale.x, sy = scale.y, sz = scale.z;
|
|
175
|
-
|
|
176
|
-
this.a0 = (1 - (yy + zz)) * sx;
|
|
177
|
-
this.a1 = (xy + wz) * sx;
|
|
178
|
-
this.a2 = (xz - wy) * sx;
|
|
179
|
-
this.a3 = 0;
|
|
180
|
-
|
|
181
|
-
this.b0 = (xy - wz) * sy;
|
|
182
|
-
this.b1 = (1 - (xx + zz)) * sy;
|
|
183
|
-
this.b2 = (yz + wx) * sy;
|
|
184
|
-
this.b3 = 0;
|
|
185
|
-
|
|
186
|
-
this.c0 = (xz + wy) * sz;
|
|
187
|
-
this.c1 = (yz - wx) * sz;
|
|
188
|
-
this.c2 = (1 - (xx + yy)) * sz;
|
|
189
|
-
this.c3 = 0;
|
|
190
|
-
|
|
191
|
-
this.d0 = position.x;
|
|
192
|
-
this.d1 = position.y;
|
|
193
|
-
this.d2 = position.z;
|
|
194
|
-
this.d3 = 1;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
decompose(position, rotation, scale) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
let sx = Math.hypot(this.a0, this.a1, this.a2);
|
|
201
|
-
const sy = Math.hypot(this.b0, this.b1, this.b2);
|
|
202
|
-
const sz = Math.hypot(this.c0, this.c1, this.c2);
|
|
203
|
-
|
|
204
|
-
// if determine is negative, we need to invert one scale
|
|
205
|
-
const det = this.determinant();
|
|
206
|
-
if (det < 0) sx = -sx;
|
|
207
|
-
|
|
208
|
-
position.set(
|
|
209
|
-
this.d0,
|
|
210
|
-
this.d1,
|
|
211
|
-
this.d2
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
// scale the rotation part
|
|
215
|
-
const invSX = 1 / sx;
|
|
216
|
-
const invSY = 1 / sy;
|
|
217
|
-
const invSZ = 1 / sz;
|
|
218
|
-
|
|
219
|
-
const i_a0 = this.a0 * invSX;
|
|
220
|
-
const i_a1 = this.a1 * invSX;
|
|
221
|
-
const i_a2 = this.a2 * invSX;
|
|
222
|
-
|
|
223
|
-
const i_b0 = this.b0 * invSY;
|
|
224
|
-
const i_b1 = this.b1 * invSY;
|
|
225
|
-
const i_b2 = this.b2 * invSY;
|
|
226
|
-
|
|
227
|
-
const i_c0 = this.c0 * invSZ;
|
|
228
|
-
const i_c1 = this.c1 * invSZ;
|
|
229
|
-
const i_c2 = this.c2 * invSZ;
|
|
230
|
-
|
|
231
|
-
rotation.__setFromRotationMatrix(i_a0, i_b0, i_c0, i_a1, i_b1, i_c1, i_a2, i_b2, i_c2);
|
|
232
|
-
|
|
233
|
-
scale.set(sx, sy, sz);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
*
|
|
238
|
-
* @param {Matrix4} a
|
|
239
|
-
* @param {Matrix4} b
|
|
240
|
-
*/
|
|
241
|
-
multiplyMatrices(a, b) {
|
|
242
|
-
|
|
243
|
-
const a11 = a.a0, a12 = a.b0, a13 = a.c0, a14 = a.d0;
|
|
244
|
-
const a21 = a.a1, a22 = a.b1, a23 = a.c1, a24 = a.d1;
|
|
245
|
-
const a31 = a.a2, a32 = a.b2, a33 = a.c2, a34 = a.d2;
|
|
246
|
-
const a41 = a.a3, a42 = a.b3, a43 = a.c3, a44 = a.d3;
|
|
247
|
-
|
|
248
|
-
const b11 = b.a0, b12 = b.b0, b13 = b.c0, b14 = b.d0;
|
|
249
|
-
const b21 = b.a1, b22 = b.b1, b23 = b.c1, b24 = b.d1;
|
|
250
|
-
const b31 = b.a2, b32 = b.b2, b33 = b.c2, b34 = b.d2;
|
|
251
|
-
const b41 = b.a3, b42 = b.b3, b43 = b.c3, b44 = b.d3;
|
|
252
|
-
|
|
253
|
-
this.a0 = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
|
|
254
|
-
this.b0 = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
|
|
255
|
-
this.c0 = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
|
|
256
|
-
this.d0 = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
|
|
257
|
-
|
|
258
|
-
this.a1 = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
|
|
259
|
-
this.b1 = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
|
260
|
-
this.c1 = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
|
261
|
-
this.d1 = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
|
262
|
-
|
|
263
|
-
this.a2 = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
|
264
|
-
this.b2 = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
|
265
|
-
this.c2 = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
|
266
|
-
this.d2 = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
|
267
|
-
|
|
268
|
-
this.a3 = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
|
269
|
-
this.b3 = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
|
270
|
-
this.c3 = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
|
271
|
-
this.d3 = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
}
|