@woosh/meep-engine 2.134.4 → 2.135.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/build/bundle-worker-image-decoder.js +1 -1
- package/build/bundle-worker-terrain.js +1 -1
- package/editor/tools/v2/TransformControlsGizmo.js +1 -1
- package/editor/view/node-graph/NodeGraphEditorView.js +2 -2
- package/package.json +1 -1
- package/src/core/assert.d.ts +0 -2
- package/src/core/assert.d.ts.map +1 -1
- package/src/core/assert.js +0 -6
- package/src/core/color/Color.d.ts +0 -5
- package/src/core/color/Color.d.ts.map +1 -1
- package/src/core/color/Color.js +1 -7
- package/src/core/geom/2d/hash-grid/SpatialHashGrid.js +386 -386
- package/src/core/geom/2d/line/line_segment_compute_line_segment_intersection_2d.js +1 -1
- package/src/core/geom/2d/quad-tree-binary/QuadTree.js +714 -714
- package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +160 -160
- package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +96 -96
- package/src/core/geom/packing/max-rect/MaxRectanglesPacker.js +1 -1
- package/src/core/geom/packing/max-rect/findBestContainer.js +4 -4
- package/src/core/geom/packing/max-rect/packOneBox.js +2 -2
- package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.d.ts +23 -0
- package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.js +96 -0
- package/src/core/graph/layout/box/BoxLayouter.js +7 -7
- package/src/core/graph/layout/box/position_box_next_to_box.js +6 -6
- package/src/core/math/computeWholeDivisorLow.js +33 -33
- package/src/core/math/linalg/eigen/eigen_values_find_spectral_gap.d.ts.map +1 -0
- package/src/core/math/linalg/eigen/matrix_eigenvalues_in_place.d.ts +10 -0
- package/src/core/math/linalg/eigen/matrix_eigenvalues_in_place.d.ts.map +1 -0
- package/src/core/{graph → math/linalg}/eigen/matrix_eigenvalues_in_place.js +8 -7
- package/src/core/math/linalg/eigen/matrix_householder_in_place.d.ts.map +1 -0
- package/src/core/{graph → math/linalg}/eigen/matrix_householder_in_place.js +11 -5
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts +15 -0
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts.map +1 -0
- package/src/core/{graph → math/linalg}/eigen/matrix_qr_in_place.js +8 -2
- package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.d.ts +17 -0
- package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.d.ts.map +1 -0
- package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.js +107 -0
- package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.d.ts +19 -0
- package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_complex_roots_aberth_ehrlich.js +161 -0
- package/src/core/math/linalg/polynomial_real_roots_in_interval.d.ts +15 -0
- package/src/core/math/linalg/polynomial_real_roots_in_interval.d.ts.map +1 -0
- package/src/core/math/linalg/polynomial_real_roots_in_interval.js +200 -0
- package/src/core/math/solveCubic.d.ts +15 -0
- package/src/core/math/solveCubic.d.ts.map +1 -0
- package/src/core/math/solveCubic.js +82 -0
- package/src/core/math/spline/spline3_hermite_bounds_t.d.ts +23 -0
- package/src/core/math/spline/spline3_hermite_bounds_t.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_bounds_t.js +109 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts +25 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite.js +44 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.d.ts +16 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_1d.js +120 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts +11 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_2d.js +451 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts +12 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersection_spline3_hermite_nd.js +339 -0
- package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.d.ts +15 -0
- package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_intersects_spline3_hermite.js +21 -0
- package/src/core/math/spline/spline3_hermite_to_monomial.d.ts +24 -0
- package/src/core/math/spline/spline3_hermite_to_monomial.d.ts.map +1 -0
- package/src/core/math/spline/spline3_hermite_to_monomial.js +37 -0
- package/src/core/math/spline/v3_computeCatmullRomSplineUniformDistance.js +1 -1
- package/src/core/model/node-graph/visual/NodeGraphVisualData.js +1 -1
- package/src/core/model/reactive/model/util/createRandomReactiveExpression.js +185 -185
- package/src/core/process/delay.js +16 -16
- package/src/engine/animation/async/TimeSeries.js +300 -300
- package/src/engine/animation/curve/AnimationCurve.d.ts +3 -2
- package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
- package/src/engine/animation/curve/AnimationCurve.js +3 -2
- package/src/engine/animation/curve/draw/position_canvas_to_curve.js +2 -2
- package/src/engine/animation/curve/draw/position_curve_to_canvas.js +2 -2
- package/src/engine/ecs/fow/shader/FogOfWarRenderer.js +145 -145
- package/src/engine/ecs/gui/position/ViewportPositionSystem.js +2 -2
- package/src/engine/ecs/parent/entity_node_compute_bounding_box.js +1 -1
- package/src/engine/ecs/transform/Transform.d.ts +0 -10
- package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
- package/src/engine/ecs/transform/Transform.js +0 -12
- package/src/engine/graphics/composit/CompositLayer.js +254 -254
- package/src/engine/graphics/ecs/mesh-v2/sg_hierarchy_compute_bounding_box_via_parent_entity.js +1 -1
- package/src/engine/graphics/ecs/path/tube/build/build_geometry_linear.js +2 -2
- package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +3 -3
- package/src/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +201 -201
- package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
- package/src/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.js +2 -2
- package/src/engine/graphics/render/forward_plus/LightManager.js +1226 -1226
- package/src/engine/graphics/render/forward_plus/model/PointLight.js +1 -1
- package/src/engine/graphics/sh3/lpv/lpv_obtain_storage_cached_volume.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +2 -2
- package/src/engine/graphics/texture/atlas/TextureAtlasDebugger.js +1 -1
- package/src/engine/graphics/texture/sampler/HarmonicDiffusionGrid.js +145 -145
- package/src/engine/graphics/texture/sampler/serialization/TextureBinaryBufferSerializer.js +2 -2
- package/src/engine/intelligence/behavior/ecs/BehaviorComponent.d.ts +2 -6
- package/src/engine/intelligence/behavior/ecs/BehaviorComponent.d.ts.map +1 -1
- package/src/engine/intelligence/behavior/ecs/BehaviorComponent.js +0 -10
- package/src/engine/intelligence/mcts/MonteCarlo.js +275 -275
- package/src/engine/navigation/ecs/path_following/PathFollower.js +222 -222
- package/src/generation/grid/GridData.js +220 -220
- package/src/generation/grid/generation/GridTaskDensityMarkerDistribution.js +385 -385
- package/src/view/elements/image/SvgImageView.js +1 -1
- package/src/view/elements/windrose/WindRoseDiagram.js +369 -369
- package/src/view/minimap/gl/MinimapFogOfWar.js +3 -3
- package/src/view/util/DomSizeObserver.js +1 -1
- package/src/core/binary/clz32.d.ts +0 -6
- package/src/core/binary/clz32.d.ts.map +0 -1
- package/src/core/binary/clz32.js +0 -5
- package/src/core/binary/type/dataTypeFromTypedArray.d.ts +0 -8
- package/src/core/binary/type/dataTypeFromTypedArray.d.ts.map +0 -1
- package/src/core/binary/type/dataTypeFromTypedArray.js +0 -11
- package/src/core/collection/array/computeHashIntegerArray.d.ts +0 -1
- package/src/core/collection/array/computeHashIntegerArray.d.ts.map +0 -1
- package/src/core/collection/array/computeHashIntegerArray.js +0 -7
- package/src/core/collection/array/typed/typedArrayToDataType.d.ts +0 -6
- package/src/core/collection/array/typed/typedArrayToDataType.d.ts.map +0 -1
- package/src/core/collection/array/typed/typedArrayToDataType.js +0 -6
- package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.d.ts +0 -6
- package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.d.ts.map +0 -1
- package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.js +0 -7
- package/src/core/graph/eigen/eigen_values_find_spectral_gap.d.ts.map +0 -1
- package/src/core/graph/eigen/matrix_eigenvalues_in_place.d.ts +0 -8
- package/src/core/graph/eigen/matrix_eigenvalues_in_place.d.ts.map +0 -1
- package/src/core/graph/eigen/matrix_householder_in_place.d.ts.map +0 -1
- package/src/core/graph/eigen/matrix_qr_in_place.d.ts +0 -9
- package/src/core/graph/eigen/matrix_qr_in_place.d.ts.map +0 -1
- package/src/core/math/spline/cubicCurve.d.ts +0 -6
- package/src/core/math/spline/cubicCurve.d.ts.map +0 -1
- package/src/core/math/spline/cubicCurve.js +0 -6
- package/src/core/math/spline/spline_bezier2.d.ts +0 -6
- package/src/core/math/spline/spline_bezier2.d.ts.map +0 -1
- package/src/core/math/spline/spline_bezier2.js +0 -6
- package/src/core/math/spline/spline_bezier3.d.ts +0 -6
- package/src/core/math/spline/spline_bezier3.d.ts.map +0 -1
- package/src/core/math/spline/spline_bezier3.js +0 -6
- package/src/core/math/spline/spline_bezier3_bounds.d.ts +0 -6
- package/src/core/math/spline/spline_bezier3_bounds.d.ts.map +0 -1
- package/src/core/math/spline/spline_bezier3_bounds.js +0 -6
- package/src/core/math/spline/spline_hermite3.d.ts +0 -6
- package/src/core/math/spline/spline_hermite3.d.ts.map +0 -1
- package/src/core/math/spline/spline_hermite3.js +0 -6
- package/src/core/math/spline/spline_hermite3_bounds.d.ts +0 -6
- package/src/core/math/spline/spline_hermite3_bounds.d.ts.map +0 -1
- package/src/core/math/spline/spline_hermite3_bounds.js +0 -6
- package/src/core/math/spline/spline_hermite3_to_bezier.d.ts +0 -2
- package/src/core/math/spline/spline_hermite3_to_bezier.d.ts.map +0 -1
- package/src/core/math/spline/spline_hermite3_to_bezier.js +0 -6
- package/src/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.d.ts +0 -37
- package/src/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.d.ts.map +0 -1
- package/src/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.js +0 -70
- /package/src/core/{graph → math/linalg}/eigen/eigen_values_find_spectral_gap.d.ts +0 -0
- /package/src/core/{graph → math/linalg}/eigen/eigen_values_find_spectral_gap.js +0 -0
- /package/src/core/{graph → math/linalg}/eigen/matrix_householder_in_place.d.ts +0 -0
|
@@ -1,160 +1,160 @@
|
|
|
1
|
-
import { v3_dot } from "../../vec3/v3_dot.js";
|
|
2
|
-
import { assert } from "../../../assert.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* NOTE: adapted from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
|
|
6
|
-
* @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)
|
|
7
|
-
* @param {SurfacePoint3} result
|
|
8
|
-
* @param {number} origin_x
|
|
9
|
-
* @param {number} origin_y
|
|
10
|
-
* @param {number} origin_z
|
|
11
|
-
* @param {number} direction_x
|
|
12
|
-
* @param {number} direction_y
|
|
13
|
-
* @param {number} direction_z
|
|
14
|
-
* @param {number} ax
|
|
15
|
-
* @param {number} ay
|
|
16
|
-
* @param {number} az
|
|
17
|
-
* @param {number} bx
|
|
18
|
-
* @param {number} by
|
|
19
|
-
* @param {number} bz
|
|
20
|
-
* @param {number} cx
|
|
21
|
-
* @param {number} cy
|
|
22
|
-
* @param {number} cz
|
|
23
|
-
* @returns {boolean}
|
|
24
|
-
*/
|
|
25
|
-
export function computeTriangleRayIntersection(
|
|
26
|
-
result,
|
|
27
|
-
origin_x, origin_y, origin_z,
|
|
28
|
-
direction_x, direction_y, direction_z,
|
|
29
|
-
ax, ay, az,
|
|
30
|
-
bx, by, bz,
|
|
31
|
-
cx, cy, cz
|
|
32
|
-
) {
|
|
33
|
-
assert.isNumber(ax, 'ax');
|
|
34
|
-
assert.isNumber(ay, 'ay');
|
|
35
|
-
assert.isNumber(az, 'az');
|
|
36
|
-
|
|
37
|
-
assert.isNumber(bx, 'bx');
|
|
38
|
-
assert.isNumber(by, 'by');
|
|
39
|
-
assert.isNumber(bz, 'bz');
|
|
40
|
-
|
|
41
|
-
assert.isNumber(cx, 'cx');
|
|
42
|
-
assert.isNumber(cy, 'cy');
|
|
43
|
-
assert.isNumber(cz, 'cz');
|
|
44
|
-
|
|
45
|
-
// nan checks
|
|
46
|
-
assert.notNaN(ax, 'ax');
|
|
47
|
-
assert.notNaN(ay, 'ay');
|
|
48
|
-
assert.notNaN(az, 'az');
|
|
49
|
-
|
|
50
|
-
assert.notNaN(bx, 'bx');
|
|
51
|
-
assert.notNaN(by, 'by');
|
|
52
|
-
assert.notNaN(bz, 'bz');
|
|
53
|
-
|
|
54
|
-
assert.notNaN(cx, 'cx');
|
|
55
|
-
assert.notNaN(cy, 'cy');
|
|
56
|
-
assert.notNaN(cz, 'cz');
|
|
57
|
-
|
|
58
|
-
// finate number check
|
|
59
|
-
assert.
|
|
60
|
-
assert.
|
|
61
|
-
assert.
|
|
62
|
-
|
|
63
|
-
assert.
|
|
64
|
-
assert.
|
|
65
|
-
assert.
|
|
66
|
-
|
|
67
|
-
assert.
|
|
68
|
-
assert.
|
|
69
|
-
assert.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// edge1 = a - b
|
|
73
|
-
const edge1_x = bx - ax;
|
|
74
|
-
const edge1_y = by - ay;
|
|
75
|
-
const edge1_z = bz - az;
|
|
76
|
-
|
|
77
|
-
// edge2 = c - a
|
|
78
|
-
const edge2_x = cx - ax;
|
|
79
|
-
const edge2_y = cy - ay;
|
|
80
|
-
const edge2_z = cz - az;
|
|
81
|
-
|
|
82
|
-
// Compute triangle normal
|
|
83
|
-
|
|
84
|
-
// normal = edge1 x edge2
|
|
85
|
-
const normal_x = edge1_y * edge2_z - edge1_z * edge2_y;
|
|
86
|
-
const normal_y = edge1_z * edge2_x - edge1_x * edge2_z;
|
|
87
|
-
const normal_z = edge1_x * edge2_y - edge1_y * edge2_x
|
|
88
|
-
|
|
89
|
-
let DdN = v3_dot(direction_x, direction_y, direction_z, normal_x, normal_y, normal_z);
|
|
90
|
-
let sign = 1;
|
|
91
|
-
|
|
92
|
-
if (DdN === 0) {
|
|
93
|
-
// ray and the triangle normal are orthogonal, means that the ray can not pass penetrate triangle
|
|
94
|
-
return false;
|
|
95
|
-
} else if (DdN < 0) {
|
|
96
|
-
sign = -1;
|
|
97
|
-
DdN = -DdN;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// diff = origin - a
|
|
101
|
-
const diff_x = origin_x - ax;
|
|
102
|
-
const diff_y = origin_y - ay;
|
|
103
|
-
const diff_z = origin_z - az;
|
|
104
|
-
|
|
105
|
-
// edge3 = diff x edge2
|
|
106
|
-
const edge3_x = diff_y * edge2_z - diff_z * edge2_y;
|
|
107
|
-
const edge3_y = diff_z * edge2_x - diff_x * edge2_z;
|
|
108
|
-
const edge3_z = diff_x * edge2_y - diff_y * edge2_x;
|
|
109
|
-
|
|
110
|
-
// DdQxE2 = sign * ( direction . edge3)
|
|
111
|
-
const DdQxE2 = sign * v3_dot(direction_x, direction_y, direction_z, edge3_x, edge3_y, edge3_z);
|
|
112
|
-
|
|
113
|
-
if (DdQxE2 < 0) {
|
|
114
|
-
// b1 < 0, no intersection
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const edge4_x = edge1_y * diff_z - edge1_z * diff_y;
|
|
119
|
-
const edge4_y = edge1_z * diff_x - edge1_x * diff_z;
|
|
120
|
-
const edge4_z = edge1_x * diff_y - edge1_y * diff_x;
|
|
121
|
-
|
|
122
|
-
const DdE1xQ = sign * v3_dot(direction_x, direction_y, direction_z, edge4_x, edge4_y, edge4_z);
|
|
123
|
-
|
|
124
|
-
if (DdE1xQ < 0) {
|
|
125
|
-
// b2 < 0, no intersection
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (DdQxE2 + DdE1xQ > DdN) {
|
|
130
|
-
// b1+b2 > 1, no intersection
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Line intersects triangle, check if ray does.
|
|
135
|
-
const QdN = -sign * v3_dot(diff_x, diff_y, diff_z, normal_x, normal_y, normal_z);
|
|
136
|
-
|
|
137
|
-
if (QdN < 0) {
|
|
138
|
-
// t < 0, no intersection
|
|
139
|
-
return false;
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Ray intersects triangle.
|
|
144
|
-
const t = QdN / DdN;
|
|
145
|
-
|
|
146
|
-
result.normal.set(
|
|
147
|
-
normal_x,
|
|
148
|
-
normal_y,
|
|
149
|
-
normal_z
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
result.position.set(
|
|
153
|
-
direction_x * t + origin_x,
|
|
154
|
-
direction_y * t + origin_y,
|
|
155
|
-
direction_z * t + origin_z,
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
|
|
1
|
+
import { v3_dot } from "../../vec3/v3_dot.js";
|
|
2
|
+
import { assert } from "../../../assert.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* NOTE: adapted from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
|
|
6
|
+
* @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)
|
|
7
|
+
* @param {SurfacePoint3} result
|
|
8
|
+
* @param {number} origin_x
|
|
9
|
+
* @param {number} origin_y
|
|
10
|
+
* @param {number} origin_z
|
|
11
|
+
* @param {number} direction_x
|
|
12
|
+
* @param {number} direction_y
|
|
13
|
+
* @param {number} direction_z
|
|
14
|
+
* @param {number} ax
|
|
15
|
+
* @param {number} ay
|
|
16
|
+
* @param {number} az
|
|
17
|
+
* @param {number} bx
|
|
18
|
+
* @param {number} by
|
|
19
|
+
* @param {number} bz
|
|
20
|
+
* @param {number} cx
|
|
21
|
+
* @param {number} cy
|
|
22
|
+
* @param {number} cz
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
export function computeTriangleRayIntersection(
|
|
26
|
+
result,
|
|
27
|
+
origin_x, origin_y, origin_z,
|
|
28
|
+
direction_x, direction_y, direction_z,
|
|
29
|
+
ax, ay, az,
|
|
30
|
+
bx, by, bz,
|
|
31
|
+
cx, cy, cz
|
|
32
|
+
) {
|
|
33
|
+
assert.isNumber(ax, 'ax');
|
|
34
|
+
assert.isNumber(ay, 'ay');
|
|
35
|
+
assert.isNumber(az, 'az');
|
|
36
|
+
|
|
37
|
+
assert.isNumber(bx, 'bx');
|
|
38
|
+
assert.isNumber(by, 'by');
|
|
39
|
+
assert.isNumber(bz, 'bz');
|
|
40
|
+
|
|
41
|
+
assert.isNumber(cx, 'cx');
|
|
42
|
+
assert.isNumber(cy, 'cy');
|
|
43
|
+
assert.isNumber(cz, 'cz');
|
|
44
|
+
|
|
45
|
+
// nan checks
|
|
46
|
+
assert.notNaN(ax, 'ax');
|
|
47
|
+
assert.notNaN(ay, 'ay');
|
|
48
|
+
assert.notNaN(az, 'az');
|
|
49
|
+
|
|
50
|
+
assert.notNaN(bx, 'bx');
|
|
51
|
+
assert.notNaN(by, 'by');
|
|
52
|
+
assert.notNaN(bz, 'bz');
|
|
53
|
+
|
|
54
|
+
assert.notNaN(cx, 'cx');
|
|
55
|
+
assert.notNaN(cy, 'cy');
|
|
56
|
+
assert.notNaN(cz, 'cz');
|
|
57
|
+
|
|
58
|
+
// finate number check
|
|
59
|
+
assert.isFinite(ax, 'ax');
|
|
60
|
+
assert.isFinite(ay, 'ay');
|
|
61
|
+
assert.isFinite(az, 'az');
|
|
62
|
+
|
|
63
|
+
assert.isFinite(bx, 'bx');
|
|
64
|
+
assert.isFinite(by, 'by');
|
|
65
|
+
assert.isFinite(bz, 'bz');
|
|
66
|
+
|
|
67
|
+
assert.isFinite(cx, 'cx');
|
|
68
|
+
assert.isFinite(cy, 'cy');
|
|
69
|
+
assert.isFinite(cz, 'cz');
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// edge1 = a - b
|
|
73
|
+
const edge1_x = bx - ax;
|
|
74
|
+
const edge1_y = by - ay;
|
|
75
|
+
const edge1_z = bz - az;
|
|
76
|
+
|
|
77
|
+
// edge2 = c - a
|
|
78
|
+
const edge2_x = cx - ax;
|
|
79
|
+
const edge2_y = cy - ay;
|
|
80
|
+
const edge2_z = cz - az;
|
|
81
|
+
|
|
82
|
+
// Compute triangle normal
|
|
83
|
+
|
|
84
|
+
// normal = edge1 x edge2
|
|
85
|
+
const normal_x = edge1_y * edge2_z - edge1_z * edge2_y;
|
|
86
|
+
const normal_y = edge1_z * edge2_x - edge1_x * edge2_z;
|
|
87
|
+
const normal_z = edge1_x * edge2_y - edge1_y * edge2_x
|
|
88
|
+
|
|
89
|
+
let DdN = v3_dot(direction_x, direction_y, direction_z, normal_x, normal_y, normal_z);
|
|
90
|
+
let sign = 1;
|
|
91
|
+
|
|
92
|
+
if (DdN === 0) {
|
|
93
|
+
// ray and the triangle normal are orthogonal, means that the ray can not pass penetrate triangle
|
|
94
|
+
return false;
|
|
95
|
+
} else if (DdN < 0) {
|
|
96
|
+
sign = -1;
|
|
97
|
+
DdN = -DdN;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// diff = origin - a
|
|
101
|
+
const diff_x = origin_x - ax;
|
|
102
|
+
const diff_y = origin_y - ay;
|
|
103
|
+
const diff_z = origin_z - az;
|
|
104
|
+
|
|
105
|
+
// edge3 = diff x edge2
|
|
106
|
+
const edge3_x = diff_y * edge2_z - diff_z * edge2_y;
|
|
107
|
+
const edge3_y = diff_z * edge2_x - diff_x * edge2_z;
|
|
108
|
+
const edge3_z = diff_x * edge2_y - diff_y * edge2_x;
|
|
109
|
+
|
|
110
|
+
// DdQxE2 = sign * ( direction . edge3)
|
|
111
|
+
const DdQxE2 = sign * v3_dot(direction_x, direction_y, direction_z, edge3_x, edge3_y, edge3_z);
|
|
112
|
+
|
|
113
|
+
if (DdQxE2 < 0) {
|
|
114
|
+
// b1 < 0, no intersection
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const edge4_x = edge1_y * diff_z - edge1_z * diff_y;
|
|
119
|
+
const edge4_y = edge1_z * diff_x - edge1_x * diff_z;
|
|
120
|
+
const edge4_z = edge1_x * diff_y - edge1_y * diff_x;
|
|
121
|
+
|
|
122
|
+
const DdE1xQ = sign * v3_dot(direction_x, direction_y, direction_z, edge4_x, edge4_y, edge4_z);
|
|
123
|
+
|
|
124
|
+
if (DdE1xQ < 0) {
|
|
125
|
+
// b2 < 0, no intersection
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (DdQxE2 + DdE1xQ > DdN) {
|
|
130
|
+
// b1+b2 > 1, no intersection
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Line intersects triangle, check if ray does.
|
|
135
|
+
const QdN = -sign * v3_dot(diff_x, diff_y, diff_z, normal_x, normal_y, normal_z);
|
|
136
|
+
|
|
137
|
+
if (QdN < 0) {
|
|
138
|
+
// t < 0, no intersection
|
|
139
|
+
return false;
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Ray intersects triangle.
|
|
144
|
+
const t = QdN / DdN;
|
|
145
|
+
|
|
146
|
+
result.normal.set(
|
|
147
|
+
normal_x,
|
|
148
|
+
normal_y,
|
|
149
|
+
normal_z
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
result.position.set(
|
|
153
|
+
direction_x * t + origin_x,
|
|
154
|
+
direction_y * t + origin_y,
|
|
155
|
+
direction_z * t + origin_z,
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
|
|
@@ -1,96 +1,96 @@
|
|
|
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.
|
|
62
|
-
assert.
|
|
63
|
-
assert.
|
|
64
|
-
|
|
65
|
-
assert.
|
|
66
|
-
assert.
|
|
67
|
-
assert.
|
|
68
|
-
|
|
69
|
-
assert.
|
|
70
|
-
assert.
|
|
71
|
-
assert.
|
|
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(
|
|
87
|
-
result,
|
|
88
|
-
origin_x, origin_y, origin_z,
|
|
89
|
-
direction_x, direction_y, direction_z,
|
|
90
|
-
ax, ay, az,
|
|
91
|
-
edge1_x, edge1_y, edge1_z,
|
|
92
|
-
edge2_x, edge2_y, edge2_z
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
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.isFinite(ax, 'ax');
|
|
62
|
+
assert.isFinite(ay, 'ay');
|
|
63
|
+
assert.isFinite(az, 'az');
|
|
64
|
+
|
|
65
|
+
assert.isFinite(bx, 'bx');
|
|
66
|
+
assert.isFinite(by, 'by');
|
|
67
|
+
assert.isFinite(bz, 'bz');
|
|
68
|
+
|
|
69
|
+
assert.isFinite(cx, 'cx');
|
|
70
|
+
assert.isFinite(cy, 'cy');
|
|
71
|
+
assert.isFinite(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(
|
|
87
|
+
result,
|
|
88
|
+
origin_x, origin_y, origin_z,
|
|
89
|
+
direction_x, direction_y, direction_z,
|
|
90
|
+
ax, ay, az,
|
|
91
|
+
edge1_x, edge1_y, edge1_z,
|
|
92
|
+
edge2_x, edge2_y, edge2_z
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
@@ -140,7 +140,7 @@ export class MaxRectanglesPacker {
|
|
|
140
140
|
*/
|
|
141
141
|
function scoreBoxByMinSide(boxIndex) {
|
|
142
142
|
const box = boxes[boxIndex];
|
|
143
|
-
return -Math.min(box.
|
|
143
|
+
return -Math.min(box.width, box.height);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
const heap = new BinaryHeap(scoreBoxByMinSide);
|
|
@@ -30,12 +30,12 @@ export function findBestContainer(
|
|
|
30
30
|
*/
|
|
31
31
|
function visitor(node){
|
|
32
32
|
|
|
33
|
-
if (node.
|
|
33
|
+
if (node.width < width) {
|
|
34
34
|
//too small, don't traverse deeper
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
if (node.
|
|
38
|
+
if (node.height < height) {
|
|
39
39
|
//too small, don't traverse deeper
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
@@ -46,14 +46,14 @@ export function findBestContainer(
|
|
|
46
46
|
for (let i = 0; i < box_count; i++) {
|
|
47
47
|
const box = data[i];
|
|
48
48
|
|
|
49
|
-
const bW = box.
|
|
49
|
+
const bW = box.width;
|
|
50
50
|
|
|
51
51
|
if (bW < width) {
|
|
52
52
|
//too small
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const bH = box.
|
|
56
|
+
const bH = box.height;
|
|
57
57
|
|
|
58
58
|
if (bH < height) {
|
|
59
59
|
//too small
|
|
@@ -10,8 +10,8 @@ import { findBestContainer } from "./findBestContainer.js";
|
|
|
10
10
|
* @returns {boolean}
|
|
11
11
|
*/
|
|
12
12
|
export function packOneBox(box, free) {
|
|
13
|
-
const w = box.
|
|
14
|
-
const h = box.
|
|
13
|
+
const w = box.width;
|
|
14
|
+
const h = box.height;
|
|
15
15
|
|
|
16
16
|
const container = findBestContainer(w, h, free, costByRemainingArea);
|
|
17
17
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Closed-form solution for the rotation that best aligns two sets of unit
|
|
3
|
+
* vectors, via Horn (1987) "Closed-form solution of absolute orientation using
|
|
4
|
+
* unit quaternions".
|
|
5
|
+
*
|
|
6
|
+
* Given paired unit vectors {a_i} and {b_i}, finds the unit quaternion q such
|
|
7
|
+
* that rotating each b_i by q minimizes Σ |a_i − R(q)·b_i|².
|
|
8
|
+
*
|
|
9
|
+
* The matrix N is built so that the eigenvector of its largest eigenvalue
|
|
10
|
+
* IS the optimal rotation quaternion (in scalar-last form, matching meep's
|
|
11
|
+
* `Quaternion`).
|
|
12
|
+
*
|
|
13
|
+
* Inputs are unit vectors so no centroid subtraction is needed — the rotation
|
|
14
|
+
* is recovered from the cross-correlations alone.
|
|
15
|
+
*
|
|
16
|
+
* @param {Float32Array|number[]} a_xyz Source vectors — Length: count*3, unit length per triple
|
|
17
|
+
* @param {Float32Array|number[]} b_xyz Target vectors — Length: count*3, unit length per triple
|
|
18
|
+
* @param {number} count
|
|
19
|
+
* @param {Float32Array|number[]} out_quaternion Length 4 (x, y, z, w)
|
|
20
|
+
* @returns {number} The maximum eigenvalue ≈ Σ a_i · R·b_i. For a perfect alignment this equals `count`.
|
|
21
|
+
*/
|
|
22
|
+
export function v3_rigid_align_paired_unit_vectors(a_xyz: Float32Array | number[], b_xyz: Float32Array | number[], count: number, out_quaternion: Float32Array | number[]): number;
|
|
23
|
+
//# sourceMappingURL=v3_rigid_align_paired_unit_vectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v3_rigid_align_paired_unit_vectors.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,0DANW,YAAY,GAAC,MAAM,EAAE,SACrB,YAAY,GAAC,MAAM,EAAE,SACrB,MAAM,kBACN,YAAY,GAAC,MAAM,EAAE,GACnB,MAAM,CAsElB"}
|