@woosh/meep-engine 2.134.5 → 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.js +1 -1
- 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/{graph → math/linalg}/eigen/matrix_top_eigenvector_power_iteration.d.ts +0 -3
- package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.d.ts.map +1 -0
- package/src/core/{graph → math/linalg}/eigen/matrix_top_eigenvector_power_iteration.js +0 -3
- 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 +0 -4
- package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
- package/src/engine/animation/curve/AnimationCurve.js +1 -6
- 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/graph/eigen/matrix_top_eigenvector_power_iteration.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,222 +1,222 @@
|
|
|
1
|
-
import { assert } from "../../../../core/assert.js";
|
|
2
|
-
import Vector1 from "../../../../core/geom/Vector1.js";
|
|
3
|
-
import { PathFollowerFlags } from "./PathFollowerFlags.js";
|
|
4
|
-
|
|
5
|
-
const DEFAULT_SPEED = 1;
|
|
6
|
-
const DEFAULT_ROTATION_SPEED = Infinity;
|
|
7
|
-
|
|
8
|
-
const DEFAULT_FLAGS = PathFollowerFlags.Active
|
|
9
|
-
| PathFollowerFlags.WritePositionX
|
|
10
|
-
| PathFollowerFlags.WritePositionY
|
|
11
|
-
| PathFollowerFlags.WritePositionZ
|
|
12
|
-
| PathFollowerFlags.WriteRotationX
|
|
13
|
-
| PathFollowerFlags.WriteRotationY
|
|
14
|
-
| PathFollowerFlags.WriteRotationZ
|
|
15
|
-
;
|
|
16
|
-
|
|
17
|
-
const DEFAULT_MAX_MOVE_DISTANCE = 100000;
|
|
18
|
-
|
|
19
|
-
class PathFollower {
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Movement speed along the path in world units per second
|
|
23
|
-
* @type {Vector1}
|
|
24
|
-
*/
|
|
25
|
-
speed = new Vector1(DEFAULT_SPEED);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Speed at which path follower can adjust rotation in Rad/s
|
|
29
|
-
* @type {Vector1}
|
|
30
|
-
*/
|
|
31
|
-
rotationSpeed = new Vector1(DEFAULT_ROTATION_SPEED);
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
* @type {number}
|
|
36
|
-
*/
|
|
37
|
-
flags = DEFAULT_FLAGS;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Maximum distance that the follower can move along the path in a single step
|
|
41
|
-
* @type {number}
|
|
42
|
-
*/
|
|
43
|
-
maxMoveDistance = DEFAULT_MAX_MOVE_DISTANCE;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Absolute position along the path
|
|
47
|
-
* @type {number}
|
|
48
|
-
*/
|
|
49
|
-
position = 0;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
get rotationAlignment() {
|
|
53
|
-
throw new Error(`deprecated, use relevant flag instead`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get positionWriting() {
|
|
57
|
-
throw new Error(`deprecated, use relevant flag instead`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get active() {
|
|
61
|
-
console.warn('PathFollower.active is deprecated, use flags instead');
|
|
62
|
-
return this.getFlag(PathFollowerFlags.Active);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
set active(v) {
|
|
66
|
-
console.warn('PathFollower.active is deprecated, use flags instead');
|
|
67
|
-
this.writeFlag(PathFollowerFlags.Active, v);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get lock() {
|
|
71
|
-
console.warn('PathFollower.lock is deprecated, use flags instead');
|
|
72
|
-
return this.getFlag(PathFollowerFlags.Locked);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
set lock(v) {
|
|
76
|
-
console.warn('PathFollower.lock is deprecated, use flags instead');
|
|
77
|
-
this.writeFlag(PathFollowerFlags.Locked, v);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
* @param {number|PathFollowerFlags} flag
|
|
83
|
-
* @returns {void}
|
|
84
|
-
*/
|
|
85
|
-
setFlag(flag) {
|
|
86
|
-
this.flags |= flag;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
*
|
|
91
|
-
* @param {number|PathFollowerFlags} flag
|
|
92
|
-
* @returns {void}
|
|
93
|
-
*/
|
|
94
|
-
clearFlag(flag) {
|
|
95
|
-
this.flags &= ~flag;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
*
|
|
100
|
-
* @param {number|PathFollowerFlags} flag
|
|
101
|
-
* @param {boolean} value
|
|
102
|
-
*/
|
|
103
|
-
writeFlag(flag, value) {
|
|
104
|
-
assert.isBoolean(value, 'value');
|
|
105
|
-
|
|
106
|
-
if (value) {
|
|
107
|
-
this.setFlag(flag);
|
|
108
|
-
} else {
|
|
109
|
-
this.clearFlag(flag);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
*
|
|
115
|
-
* @param {number|PathFollowerFlags} flag
|
|
116
|
-
* @returns {boolean}
|
|
117
|
-
*/
|
|
118
|
-
getFlag(flag) {
|
|
119
|
-
return (this.flags & flag) === flag;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
toJSON() {
|
|
123
|
-
return {
|
|
124
|
-
active: this.getFlag(PathFollowerFlags.Active),
|
|
125
|
-
loop: this.getFlag(PathFollowerFlags.Loop),
|
|
126
|
-
|
|
127
|
-
writePositionX: this.getFlag(PathFollowerFlags.WritePositionX),
|
|
128
|
-
writePositionY: this.getFlag(PathFollowerFlags.WritePositionY),
|
|
129
|
-
writePositionZ: this.getFlag(PathFollowerFlags.WritePositionZ),
|
|
130
|
-
|
|
131
|
-
writeRotationX: this.getFlag(PathFollowerFlags.WriteRotationX),
|
|
132
|
-
writeRotationY: this.getFlag(PathFollowerFlags.WriteRotationY),
|
|
133
|
-
writeRotationZ: this.getFlag(PathFollowerFlags.WriteRotationZ),
|
|
134
|
-
|
|
135
|
-
speed: this.speed.toJSON(),
|
|
136
|
-
rotationSpeed: this.rotationSpeed.toJSON(),
|
|
137
|
-
position: this.position,
|
|
138
|
-
maxMoveDistance: this.maxMoveDistance
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
fromJSON(json) {
|
|
143
|
-
this.flags = DEFAULT_FLAGS;
|
|
144
|
-
|
|
145
|
-
if (json.position !== undefined) {
|
|
146
|
-
|
|
147
|
-
assert.isNumber(json.position, 'position');
|
|
148
|
-
assert.
|
|
149
|
-
assert.notNaN(json.position, 'position');
|
|
150
|
-
|
|
151
|
-
this.position = json.position;
|
|
152
|
-
} else {
|
|
153
|
-
this.position = 0;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (typeof json.active === "boolean") {
|
|
157
|
-
this.writeFlag(PathFollowerFlags.Active, json.active);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (typeof json.loop === "boolean") {
|
|
161
|
-
this.writeFlag(PathFollowerFlags.Loop, json.active);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (typeof json.speed === "number") {
|
|
165
|
-
this.speed.fromJSON(json.speed);
|
|
166
|
-
} else {
|
|
167
|
-
this.speed.set(DEFAULT_SPEED);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (typeof json.rotationSpeed === "number") {
|
|
171
|
-
this.rotationSpeed.fromJSON(json.rotationSpeed);
|
|
172
|
-
} else {
|
|
173
|
-
this.rotationSpeed.set(DEFAULT_ROTATION_SPEED);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (typeof json.maxMoveDistance === "number") {
|
|
177
|
-
this.maxMoveDistance = json.maxMoveDistance;
|
|
178
|
-
} else {
|
|
179
|
-
this.maxMoveDistance = DEFAULT_MAX_MOVE_DISTANCE;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (json.writePositionX !== undefined) {
|
|
183
|
-
this.writeFlag(PathFollowerFlags.WritePositionX, json.writePositionX);
|
|
184
|
-
}
|
|
185
|
-
if (json.writePositionY !== undefined) {
|
|
186
|
-
this.writeFlag(PathFollowerFlags.WritePositionY, json.writePositionY);
|
|
187
|
-
}
|
|
188
|
-
if (json.writePositionZ !== undefined) {
|
|
189
|
-
this.writeFlag(PathFollowerFlags.WritePositionZ, json.writePositionZ);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (json.writeRotationX !== undefined) {
|
|
193
|
-
this.writeFlag(PathFollowerFlags.WriteRotationX, json.writeRotationX);
|
|
194
|
-
}
|
|
195
|
-
if (json.writeRotationY !== undefined) {
|
|
196
|
-
this.writeFlag(PathFollowerFlags.WriteRotationY, json.writeRotationY);
|
|
197
|
-
}
|
|
198
|
-
if (json.writeRotationZ !== undefined) {
|
|
199
|
-
this.writeFlag(PathFollowerFlags.WriteRotationZ, json.writeRotationZ);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
*
|
|
206
|
-
* @param json
|
|
207
|
-
* @returns {PathFollower}
|
|
208
|
-
*/
|
|
209
|
-
static fromJSON(json) {
|
|
210
|
-
const r = new PathFollower();
|
|
211
|
-
|
|
212
|
-
r.fromJSON(json);
|
|
213
|
-
|
|
214
|
-
return r;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
PathFollower.typeName = "PathFollower";
|
|
219
|
-
|
|
220
|
-
export default PathFollower;
|
|
221
|
-
|
|
222
|
-
|
|
1
|
+
import { assert } from "../../../../core/assert.js";
|
|
2
|
+
import Vector1 from "../../../../core/geom/Vector1.js";
|
|
3
|
+
import { PathFollowerFlags } from "./PathFollowerFlags.js";
|
|
4
|
+
|
|
5
|
+
const DEFAULT_SPEED = 1;
|
|
6
|
+
const DEFAULT_ROTATION_SPEED = Infinity;
|
|
7
|
+
|
|
8
|
+
const DEFAULT_FLAGS = PathFollowerFlags.Active
|
|
9
|
+
| PathFollowerFlags.WritePositionX
|
|
10
|
+
| PathFollowerFlags.WritePositionY
|
|
11
|
+
| PathFollowerFlags.WritePositionZ
|
|
12
|
+
| PathFollowerFlags.WriteRotationX
|
|
13
|
+
| PathFollowerFlags.WriteRotationY
|
|
14
|
+
| PathFollowerFlags.WriteRotationZ
|
|
15
|
+
;
|
|
16
|
+
|
|
17
|
+
const DEFAULT_MAX_MOVE_DISTANCE = 100000;
|
|
18
|
+
|
|
19
|
+
class PathFollower {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Movement speed along the path in world units per second
|
|
23
|
+
* @type {Vector1}
|
|
24
|
+
*/
|
|
25
|
+
speed = new Vector1(DEFAULT_SPEED);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Speed at which path follower can adjust rotation in Rad/s
|
|
29
|
+
* @type {Vector1}
|
|
30
|
+
*/
|
|
31
|
+
rotationSpeed = new Vector1(DEFAULT_ROTATION_SPEED);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @type {number}
|
|
36
|
+
*/
|
|
37
|
+
flags = DEFAULT_FLAGS;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Maximum distance that the follower can move along the path in a single step
|
|
41
|
+
* @type {number}
|
|
42
|
+
*/
|
|
43
|
+
maxMoveDistance = DEFAULT_MAX_MOVE_DISTANCE;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Absolute position along the path
|
|
47
|
+
* @type {number}
|
|
48
|
+
*/
|
|
49
|
+
position = 0;
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
get rotationAlignment() {
|
|
53
|
+
throw new Error(`deprecated, use relevant flag instead`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get positionWriting() {
|
|
57
|
+
throw new Error(`deprecated, use relevant flag instead`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get active() {
|
|
61
|
+
console.warn('PathFollower.active is deprecated, use flags instead');
|
|
62
|
+
return this.getFlag(PathFollowerFlags.Active);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
set active(v) {
|
|
66
|
+
console.warn('PathFollower.active is deprecated, use flags instead');
|
|
67
|
+
this.writeFlag(PathFollowerFlags.Active, v);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get lock() {
|
|
71
|
+
console.warn('PathFollower.lock is deprecated, use flags instead');
|
|
72
|
+
return this.getFlag(PathFollowerFlags.Locked);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
set lock(v) {
|
|
76
|
+
console.warn('PathFollower.lock is deprecated, use flags instead');
|
|
77
|
+
this.writeFlag(PathFollowerFlags.Locked, v);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param {number|PathFollowerFlags} flag
|
|
83
|
+
* @returns {void}
|
|
84
|
+
*/
|
|
85
|
+
setFlag(flag) {
|
|
86
|
+
this.flags |= flag;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param {number|PathFollowerFlags} flag
|
|
92
|
+
* @returns {void}
|
|
93
|
+
*/
|
|
94
|
+
clearFlag(flag) {
|
|
95
|
+
this.flags &= ~flag;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
* @param {number|PathFollowerFlags} flag
|
|
101
|
+
* @param {boolean} value
|
|
102
|
+
*/
|
|
103
|
+
writeFlag(flag, value) {
|
|
104
|
+
assert.isBoolean(value, 'value');
|
|
105
|
+
|
|
106
|
+
if (value) {
|
|
107
|
+
this.setFlag(flag);
|
|
108
|
+
} else {
|
|
109
|
+
this.clearFlag(flag);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* @param {number|PathFollowerFlags} flag
|
|
116
|
+
* @returns {boolean}
|
|
117
|
+
*/
|
|
118
|
+
getFlag(flag) {
|
|
119
|
+
return (this.flags & flag) === flag;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
toJSON() {
|
|
123
|
+
return {
|
|
124
|
+
active: this.getFlag(PathFollowerFlags.Active),
|
|
125
|
+
loop: this.getFlag(PathFollowerFlags.Loop),
|
|
126
|
+
|
|
127
|
+
writePositionX: this.getFlag(PathFollowerFlags.WritePositionX),
|
|
128
|
+
writePositionY: this.getFlag(PathFollowerFlags.WritePositionY),
|
|
129
|
+
writePositionZ: this.getFlag(PathFollowerFlags.WritePositionZ),
|
|
130
|
+
|
|
131
|
+
writeRotationX: this.getFlag(PathFollowerFlags.WriteRotationX),
|
|
132
|
+
writeRotationY: this.getFlag(PathFollowerFlags.WriteRotationY),
|
|
133
|
+
writeRotationZ: this.getFlag(PathFollowerFlags.WriteRotationZ),
|
|
134
|
+
|
|
135
|
+
speed: this.speed.toJSON(),
|
|
136
|
+
rotationSpeed: this.rotationSpeed.toJSON(),
|
|
137
|
+
position: this.position,
|
|
138
|
+
maxMoveDistance: this.maxMoveDistance
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
fromJSON(json) {
|
|
143
|
+
this.flags = DEFAULT_FLAGS;
|
|
144
|
+
|
|
145
|
+
if (json.position !== undefined) {
|
|
146
|
+
|
|
147
|
+
assert.isNumber(json.position, 'position');
|
|
148
|
+
assert.isFinite(json.position, 'position');
|
|
149
|
+
assert.notNaN(json.position, 'position');
|
|
150
|
+
|
|
151
|
+
this.position = json.position;
|
|
152
|
+
} else {
|
|
153
|
+
this.position = 0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (typeof json.active === "boolean") {
|
|
157
|
+
this.writeFlag(PathFollowerFlags.Active, json.active);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (typeof json.loop === "boolean") {
|
|
161
|
+
this.writeFlag(PathFollowerFlags.Loop, json.active);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (typeof json.speed === "number") {
|
|
165
|
+
this.speed.fromJSON(json.speed);
|
|
166
|
+
} else {
|
|
167
|
+
this.speed.set(DEFAULT_SPEED);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (typeof json.rotationSpeed === "number") {
|
|
171
|
+
this.rotationSpeed.fromJSON(json.rotationSpeed);
|
|
172
|
+
} else {
|
|
173
|
+
this.rotationSpeed.set(DEFAULT_ROTATION_SPEED);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (typeof json.maxMoveDistance === "number") {
|
|
177
|
+
this.maxMoveDistance = json.maxMoveDistance;
|
|
178
|
+
} else {
|
|
179
|
+
this.maxMoveDistance = DEFAULT_MAX_MOVE_DISTANCE;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (json.writePositionX !== undefined) {
|
|
183
|
+
this.writeFlag(PathFollowerFlags.WritePositionX, json.writePositionX);
|
|
184
|
+
}
|
|
185
|
+
if (json.writePositionY !== undefined) {
|
|
186
|
+
this.writeFlag(PathFollowerFlags.WritePositionY, json.writePositionY);
|
|
187
|
+
}
|
|
188
|
+
if (json.writePositionZ !== undefined) {
|
|
189
|
+
this.writeFlag(PathFollowerFlags.WritePositionZ, json.writePositionZ);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (json.writeRotationX !== undefined) {
|
|
193
|
+
this.writeFlag(PathFollowerFlags.WriteRotationX, json.writeRotationX);
|
|
194
|
+
}
|
|
195
|
+
if (json.writeRotationY !== undefined) {
|
|
196
|
+
this.writeFlag(PathFollowerFlags.WriteRotationY, json.writeRotationY);
|
|
197
|
+
}
|
|
198
|
+
if (json.writeRotationZ !== undefined) {
|
|
199
|
+
this.writeFlag(PathFollowerFlags.WriteRotationZ, json.writeRotationZ);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* @param json
|
|
207
|
+
* @returns {PathFollower}
|
|
208
|
+
*/
|
|
209
|
+
static fromJSON(json) {
|
|
210
|
+
const r = new PathFollower();
|
|
211
|
+
|
|
212
|
+
r.fromJSON(json);
|
|
213
|
+
|
|
214
|
+
return r;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
PathFollower.typeName = "PathFollower";
|
|
219
|
+
|
|
220
|
+
export default PathFollower;
|
|
221
|
+
|
|
222
|
+
|