@woosh/meep-engine 2.43.13 → 2.43.14
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/core/bvh2/aabb3/aabb3_detailed_volume_intersection.js +1 -1
- package/core/bvh2/traversal/__process_point_if_within_planes.js +1 -1
- package/core/geom/3d/plane/is_point_within_planes.js +1 -1
- package/core/geom/3d/plane/plane3_slerp.js +1 -1
- package/core/geom/3d/topology/computeTopoMeshVertexDuplicates.js +2 -1
- package/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.js +1 -1
- package/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +1 -1
- package/core/geom/3d/topology/weld_duplicate_vertices.js +1 -1
- package/core/geom/ConicRay.js +2 -1
- package/core/geom/Quaternion.js +2 -1
- package/core/geom/Vector3.js +5 -2
- package/core/geom/normalize_angle_rad.js +1 -1
- package/core/geom/random/randomPointInCircle.js +1 -1
- package/core/geom/random/randomPointInSphere.js +1 -1
- package/core/math/EPSILON.js +5 -0
- package/core/math/PI2.js +5 -0
- package/core/math/PI_HALF.js +5 -0
- package/core/math/bezierCurve.js +22 -0
- package/core/math/clamp.spec.js +15 -0
- package/core/math/computeGreatestCommonDivisor.js +28 -0
- package/core/math/computeIsoscelesTriangleApexAngle.js +17 -0
- package/core/math/computeWholeDivisorLow.js +30 -0
- package/core/math/computeWholeDivisorLow.spec.js +9 -0
- package/core/math/copysign.spec.js +13 -0
- package/core/math/cubicCurve.js +34 -0
- package/core/math/cubicCurve.spec.js +13 -0
- package/core/math/{MathUtils.d.ts → epsilonEquals.d.ts} +0 -0
- package/core/math/epsilonEquals.js +16 -0
- package/core/math/hash/computeHashFloat.spec.js +7 -0
- package/core/math/inverseLerp.spec.js +13 -0
- package/core/math/isValueBetween.spec.js +11 -0
- package/core/math/isValueBetweenInclusive.spec.js +16 -0
- package/core/math/lerp.spec.js +15 -0
- package/core/math/makeCubicCurve.js +15 -0
- package/core/math/makeCubicCurve.spec.js +9 -0
- package/core/math/makeSequenceLoop.js +20 -0
- package/core/math/max2.spec.js +13 -0
- package/core/math/max3.spec.js +27 -0
- package/core/math/min2.spec.js +12 -0
- package/core/math/min3.spec.js +27 -0
- package/core/math/normalizeArrayVector.js +25 -0
- package/core/math/overlap1D.spec.js +10 -0
- package/core/math/quadraticCurve.js +11 -0
- package/core/math/quadraticCurve.spec.js +13 -0
- package/core/math/sign.spec.js +13 -0
- package/core/model/stat/Stat.js +2 -1
- package/engine/EngineHarness.js +5 -23
- package/engine/achievements/AchievementManager.js +1 -1
- package/engine/animation/TransitionFunctions.js +1 -1
- package/engine/ecs/gui/position/ViewportPositionSystem.js +1 -1
- package/engine/ecs/systems/SteeringSystem.js +1 -1
- package/engine/ecs/terrain/ecs/Terrain.d.ts +7 -0
- package/engine/ecs/terrain/ecs/cling/ClingToTerrain.js +68 -0
- package/engine/ecs/terrain/ecs/cling/ClingToTerrainSerializationAdapter.js +31 -0
- package/engine/ecs/terrain/ecs/{ClingToTerrainSystem.js → cling/ClingToTerrainSystem.js} +52 -34
- package/engine/ecs/terrain/ecs/{ClingToTerrainSystem.spec.js → cling/ClingToTerrainSystem.spec.js} +1 -1
- package/engine/graphics/camera/CameraShake.js +1 -1
- package/engine/graphics/camera/testClippingPlaneComputation.js +1 -1
- package/engine/graphics/ecs/path/entity/EntityPath.js +1 -1
- package/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -1
- package/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +4 -2
- package/engine/graphics/geometry/MikkT/NotZero.js +1 -1
- package/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +14 -288
- package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +1 -1
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +1 -1
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +1 -1
- package/engine/graphics/shadows/testShadowMapRendering.js +1 -1
- package/engine/input/ecs/util/TerrainCameraTargetSampler.js +1 -1
- package/engine/sound/material/detector/terrain/TerrainSoundMaterialSurfaceDetector.js +1 -1
- package/generation/example/themes/SampleTheme0.js +2 -2
- package/generation/grid/generation/GridTaskExecuteRuleTimes.js +1 -1
- package/generation/grid/generation/grid/select/CellSupplierBestN.js +1 -1
- package/generation/markers/GridActionRuleSet.js +1 -1
- package/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.js +1 -1
- package/generation/markers/transform/MarkerNodeTransformerYRotateByFilter.js +2 -1
- package/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.js +2 -1
- package/package.json +1 -1
- package/view/elements/radial/RadialMenuElement.js +1 -1
- package/view/elements/radial/RadialText.js +1 -1
- package/view/tooltip/TooltipView.js +1 -1
- package/core/math/MathUtils.js +0 -247
- package/core/math/MathUtils.spec.js +0 -232
- package/engine/ecs/terrain/ecs/ClingToTerrain.js +0 -100
package/core/math/MathUtils.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Alex Goldring
|
|
3
|
-
* @copyright Alex Goldring 17/04/2016.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { assert } from "../assert.js";
|
|
7
|
-
import { min2 } from "./min2.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @template T
|
|
11
|
-
* @param {T[]} sequence
|
|
12
|
-
* @returns {function(): T}
|
|
13
|
-
*/
|
|
14
|
-
export function makeSequenceLoop(sequence) {
|
|
15
|
-
let i = 0;
|
|
16
|
-
|
|
17
|
-
const data = sequence.slice();
|
|
18
|
-
const n = data.length;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return function sequenceLoop() {
|
|
22
|
-
const datum = data[i % n];
|
|
23
|
-
|
|
24
|
-
i++;
|
|
25
|
-
|
|
26
|
-
return datum;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Compute lowest positive integer divisor of a given "product" value
|
|
32
|
-
* @param {number} product
|
|
33
|
-
* @param {number} limit
|
|
34
|
-
* @returns {number}
|
|
35
|
-
*/
|
|
36
|
-
export function computeWholeDivisorLow(product, limit) {
|
|
37
|
-
assert.typeOf(product, 'number', 'product');
|
|
38
|
-
assert.typeOf(limit, 'number', 'limit');
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
assert.ok(Number.isInteger(product), `expected product to be an integer, instead got '${product}'`);
|
|
42
|
-
assert.ok(Number.isInteger(limit), `expected limit to be an integer, instead got '${limit}'`);
|
|
43
|
-
|
|
44
|
-
let i = limit;
|
|
45
|
-
|
|
46
|
-
while (i > 1) {
|
|
47
|
-
|
|
48
|
-
if (product % i === 0) {
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
i--;
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return i;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* @param {Number} t
|
|
63
|
-
* @param {Number} p0
|
|
64
|
-
* @param {Number} p1
|
|
65
|
-
* @param {Number} p2
|
|
66
|
-
* @return {number}
|
|
67
|
-
*/
|
|
68
|
-
export function quadraticCurve(t, p0, p1, p2) {
|
|
69
|
-
return (1 - t) * (1 - t) * p0 + 2 * (1 - t) * t * p1 + t * t * p2;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
* @param {Number} p0
|
|
75
|
-
* @param {Number} p1
|
|
76
|
-
* @param {Number} p2
|
|
77
|
-
* @param {Number} p3
|
|
78
|
-
* @return {function(number): Number}
|
|
79
|
-
*/
|
|
80
|
-
export function makeCubicCurve(p0, p1, p2, p3) {
|
|
81
|
-
return function (v) {
|
|
82
|
-
return cubicCurve(v, p0, p1, p2, p3);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
*
|
|
88
|
-
* @param {Number} t
|
|
89
|
-
* @param {Number} p0
|
|
90
|
-
* @param {Number} p1
|
|
91
|
-
* @param {Number} p2
|
|
92
|
-
* @param {Number} p3
|
|
93
|
-
* @return {Number}
|
|
94
|
-
*/
|
|
95
|
-
export function cubicCurve(t, p0, p1, p2, p3) {
|
|
96
|
-
/**
|
|
97
|
-
*
|
|
98
|
-
* @type {number}
|
|
99
|
-
*/
|
|
100
|
-
const cX = 3 * (p1 - p0);
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
*
|
|
104
|
-
* @type {number}
|
|
105
|
-
*/
|
|
106
|
-
const bX = 3 * (p2 - p1) - cX;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
*
|
|
110
|
-
* @type {number}
|
|
111
|
-
*/
|
|
112
|
-
const aX = p3 - p0 - cX - bX;
|
|
113
|
-
|
|
114
|
-
const t_2 = t * t;
|
|
115
|
-
|
|
116
|
-
const t_3 = t_2 * t;
|
|
117
|
-
|
|
118
|
-
return (aX * t_3) + (bX * t_2) + (cX * t) + p0;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* 3-rd degree bezier curve
|
|
123
|
-
* @param {number} t
|
|
124
|
-
* @param {number} p0 start point
|
|
125
|
-
* @param {number} p1 control point
|
|
126
|
-
* @param {number} p2 control point
|
|
127
|
-
* @param {number} p3 end point
|
|
128
|
-
* @returns {number}
|
|
129
|
-
*/
|
|
130
|
-
function bezierCurve(t, p0, p1, p2, p3) {
|
|
131
|
-
const nt = 1 - t;
|
|
132
|
-
|
|
133
|
-
const nt_2 = nt * nt;
|
|
134
|
-
|
|
135
|
-
const nt_3 = nt_2 * nt;
|
|
136
|
-
|
|
137
|
-
const t_2 = t * t;
|
|
138
|
-
|
|
139
|
-
const t_3 = t_2 * t;
|
|
140
|
-
|
|
141
|
-
return nt_3 * p0 + 3 * nt_2 * t * p1 + 3 * nt * t_2 * p2 + t_3 * p3;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
*
|
|
147
|
-
* @param {number} a
|
|
148
|
-
* @param {number} b
|
|
149
|
-
* @returns {number}
|
|
150
|
-
*/
|
|
151
|
-
export function computeGreatestCommonDivisor(a, b) {
|
|
152
|
-
assert.typeOf(a, 'number', 'a');
|
|
153
|
-
assert.typeOf(b, 'number', 'b');
|
|
154
|
-
|
|
155
|
-
const start = min2(a, b);
|
|
156
|
-
|
|
157
|
-
let result = start;
|
|
158
|
-
|
|
159
|
-
while (result > 1) {
|
|
160
|
-
if (a % result === 0 && b % result === 0) {
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
result--;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return result;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
*
|
|
173
|
-
* @param {number} side length of the side
|
|
174
|
-
* @param {number} base length of the base
|
|
175
|
-
* @returns {number}
|
|
176
|
-
*/
|
|
177
|
-
export function computeIsoscelesTriangleApexAngle(side, base) {
|
|
178
|
-
const b2 = base * base;
|
|
179
|
-
const s2 = side * side;
|
|
180
|
-
|
|
181
|
-
const upper = (2 * s2 - b2);
|
|
182
|
-
const lower = (2 * s2);
|
|
183
|
-
|
|
184
|
-
const cosAlpha = upper / lower;
|
|
185
|
-
|
|
186
|
-
return Math.acos(cosAlpha);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Comparison of two numbers with a given tolerance
|
|
191
|
-
* @param {number} a
|
|
192
|
-
* @param {number} b
|
|
193
|
-
* @param {number} tolerance
|
|
194
|
-
* @returns {boolean}
|
|
195
|
-
*/
|
|
196
|
-
export function epsilonEquals(a, b, tolerance) {
|
|
197
|
-
assert.isNumber(a, 'a');
|
|
198
|
-
assert.isNumber(b, 'b');
|
|
199
|
-
assert.isNumber(tolerance, 'tolerance');
|
|
200
|
-
|
|
201
|
-
return Math.abs(a - b) <= tolerance;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Assuming the input is an N-dimension vector, normalizes the vector to magnitude of 1
|
|
206
|
-
* @param {number[]|Float32Array} result
|
|
207
|
-
* @param {number[]|Float32Array} data
|
|
208
|
-
* @param {number} [length]
|
|
209
|
-
*/
|
|
210
|
-
export function normalizeArrayVector(result, data, length = data.length) {
|
|
211
|
-
|
|
212
|
-
let magnitude2 = 0;
|
|
213
|
-
|
|
214
|
-
for (let i = 0; i < length; i++) {
|
|
215
|
-
const value = data[i];
|
|
216
|
-
|
|
217
|
-
const value2 = value * value;
|
|
218
|
-
|
|
219
|
-
magnitude2 += value2;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const magnitude_inv = 1 / Math.sqrt(magnitude2);
|
|
223
|
-
|
|
224
|
-
for (let i = 0; i < length; i++) {
|
|
225
|
-
result[i] = data[i] * magnitude_inv;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Pi*2
|
|
232
|
-
* @type {number}
|
|
233
|
-
*/
|
|
234
|
-
export const PI2 = Math.PI * 2;
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Pi/2
|
|
238
|
-
* @type {number}
|
|
239
|
-
*/
|
|
240
|
-
export const PI_HALF = Math.PI / 2;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Very small value, used for comparison when compensation for rounding error is required
|
|
244
|
-
* @type {number}
|
|
245
|
-
*/
|
|
246
|
-
export const EPSILON = 0.000001;
|
|
247
|
-
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { clamp } from "./clamp.js";
|
|
2
|
-
import { copysign } from "./copysign.js";
|
|
3
|
-
import { inverseLerp } from "./inverseLerp.js";
|
|
4
|
-
import { lerp } from "./lerp.js";
|
|
5
|
-
import { computeWholeDivisorLow, cubicCurve, makeCubicCurve, quadraticCurve } from "./MathUtils.js";
|
|
6
|
-
import { max2 } from "./max2.js";
|
|
7
|
-
import { max3 } from "./max3.js";
|
|
8
|
-
import { min2 } from "./min2.js";
|
|
9
|
-
import { min3 } from "./min3.js";
|
|
10
|
-
import { sign } from "./sign.js";
|
|
11
|
-
import { isValueBetween } from "./isValueBetween.js";
|
|
12
|
-
import { isValueBetweenInclusive } from "./isValueBetweenInclusive.js";
|
|
13
|
-
import { overlap1D } from "./overlap1D.js";
|
|
14
|
-
import { computeHashFloat } from "./hash/computeHashFloat.js";
|
|
15
|
-
|
|
16
|
-
test('min2', () => {
|
|
17
|
-
expect(min2(0, 0)).toBe(0);
|
|
18
|
-
|
|
19
|
-
expect(min2(2, 1)).toBe(1);
|
|
20
|
-
|
|
21
|
-
expect(min2(1, 2)).toBe(1);
|
|
22
|
-
|
|
23
|
-
expect(min2(-1, 1)).toBe(-1);
|
|
24
|
-
|
|
25
|
-
expect(min2(1, -1)).toBe(-1);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('max2', () => {
|
|
29
|
-
expect(max2(0, 0)).toBe(0);
|
|
30
|
-
|
|
31
|
-
expect(max2(2, 1)).toBe(2);
|
|
32
|
-
|
|
33
|
-
expect(max2(1, 2)).toBe(2);
|
|
34
|
-
|
|
35
|
-
expect(max2(-1, 1)).toBe(1);
|
|
36
|
-
|
|
37
|
-
expect(max2(1, -1)).toBe(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("max3", () => {
|
|
41
|
-
expect(max3(-1, -3, 1)).toBe(1);
|
|
42
|
-
|
|
43
|
-
expect(max3(-3, -1, 1)).toBe(1);
|
|
44
|
-
|
|
45
|
-
expect(max3(-3, 1, -1)).toBe(1);
|
|
46
|
-
|
|
47
|
-
expect(max3(-1, 1, -3)).toBe(1);
|
|
48
|
-
|
|
49
|
-
expect(max3(1, -1, -3)).toBe(1);
|
|
50
|
-
|
|
51
|
-
expect(max3(1, -3, -1)).toBe(1);
|
|
52
|
-
|
|
53
|
-
expect(max3(-3, 1, 1)).toBe(1);
|
|
54
|
-
|
|
55
|
-
expect(max3(3, 1, 1)).toBe(3);
|
|
56
|
-
|
|
57
|
-
expect(max3(3, 3, -1)).toBe(3);
|
|
58
|
-
|
|
59
|
-
expect(max3(3, 3, 4)).toBe(4);
|
|
60
|
-
|
|
61
|
-
expect(max3(3, 0, 3)).toBe(3);
|
|
62
|
-
|
|
63
|
-
expect(max3(3, 4, 3)).toBe(4);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test("min3", () => {
|
|
67
|
-
expect(min3(-1, -3, 1)).toBe(-3);
|
|
68
|
-
|
|
69
|
-
expect(min3(-3, -1, 1)).toBe(-3);
|
|
70
|
-
|
|
71
|
-
expect(min3(-1, 1, -3)).toBe(-3);
|
|
72
|
-
|
|
73
|
-
expect(min3(1, -3, -1)).toBe(-3);
|
|
74
|
-
|
|
75
|
-
expect(min3(-3, 1, -1)).toBe(-3);
|
|
76
|
-
|
|
77
|
-
expect(min3(1, -1, -3)).toBe(-3);
|
|
78
|
-
|
|
79
|
-
expect(min3(-3, 1, 1)).toBe(-3);
|
|
80
|
-
|
|
81
|
-
expect(min3(2, 1, 1)).toBe(1);
|
|
82
|
-
|
|
83
|
-
expect(min3(3, 3, -1)).toBe(-1);
|
|
84
|
-
|
|
85
|
-
expect(min3(3, 3, 4)).toBe(3);
|
|
86
|
-
|
|
87
|
-
expect(min3(3, 0, 3)).toBe(0);
|
|
88
|
-
|
|
89
|
-
expect(min3(3, 4, 3)).toBe(3);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("quadratiCurve", () => {
|
|
93
|
-
expect(quadraticCurve(2, 0.1, 0.2, 3)).toBe(11.3);
|
|
94
|
-
|
|
95
|
-
expect(quadraticCurve(1, -1, -2, -3)).toBe(-3);
|
|
96
|
-
|
|
97
|
-
expect(quadraticCurve(-1, -1, 0, 0)).toBe(-4);
|
|
98
|
-
|
|
99
|
-
expect(quadraticCurve(-1, -1, 1, 0)).toBe(-8);
|
|
100
|
-
|
|
101
|
-
expect(quadraticCurve(-1, 0, 0, 0)).toBe(0);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test("cubicCurve", () => {
|
|
105
|
-
expect(cubicCurve(0, 1, 2, 3, 4)).toBe(1);
|
|
106
|
-
|
|
107
|
-
expect(cubicCurve(0, 2, 3, 4, 5)).toBe(2);
|
|
108
|
-
|
|
109
|
-
expect(cubicCurve(1, 2, 3, 4, 5)).toBe(5);
|
|
110
|
-
|
|
111
|
-
expect(cubicCurve(1, 3, 4, 5, 6)).toBe(6);
|
|
112
|
-
|
|
113
|
-
expect(cubicCurve(2, 2, 2, 2, 3)).toBe(10);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test("makeCubicCurve", () => {
|
|
117
|
-
const f = makeCubicCurve(1, 2, 3, 4);
|
|
118
|
-
expect(f(0)).toBe(1);
|
|
119
|
-
|
|
120
|
-
expect(f(1)).toBe(4);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test("computeHashFloat", () => {
|
|
124
|
-
expect(computeHashFloat(500)).toEqual(computeHashFloat(500));
|
|
125
|
-
|
|
126
|
-
expect(computeHashFloat(500)).not.toEqual(computeHashFloat(400))
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
test('sign', () => {
|
|
131
|
-
expect(sign(1)).toBe(1);
|
|
132
|
-
|
|
133
|
-
expect(sign(-1)).toBe(-1);
|
|
134
|
-
|
|
135
|
-
expect(sign(0)).toBe(0);
|
|
136
|
-
|
|
137
|
-
expect(sign(2)).toBe(1);
|
|
138
|
-
|
|
139
|
-
expect(sign(-2)).toBe(-1);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test('lerp', () => {
|
|
143
|
-
expect(lerp(0, 5, 0.1)).toBe(0.5);
|
|
144
|
-
|
|
145
|
-
expect(lerp(-5, 5, 0.5)).toBe(0);
|
|
146
|
-
|
|
147
|
-
expect(lerp(0, 0, 0)).toBe(0);
|
|
148
|
-
|
|
149
|
-
expect(lerp(0, 0, 1)).toBe(0);
|
|
150
|
-
|
|
151
|
-
expect(lerp(1, 2, 0)).toBe(1);
|
|
152
|
-
|
|
153
|
-
expect(lerp(1, 2, 1)).toBe(2);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test('inverseLerp', () => {
|
|
157
|
-
expect(inverseLerp(0, 5, 0.5)).toBe(0.1);
|
|
158
|
-
|
|
159
|
-
expect(inverseLerp(-5, 5, 0)).toBe(0.5);
|
|
160
|
-
|
|
161
|
-
expect(inverseLerp(0, 0, 0)).toBe(0);
|
|
162
|
-
|
|
163
|
-
expect(inverseLerp(1, 2, 1)).toBe(0);
|
|
164
|
-
|
|
165
|
-
expect(inverseLerp(1, 2, 2)).toBe(1);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
test('clamp', () => {
|
|
169
|
-
expect(clamp(0, 0, 0)).toBe(0);
|
|
170
|
-
|
|
171
|
-
expect(clamp(0, 1, 1)).toBe(1);
|
|
172
|
-
|
|
173
|
-
expect(clamp(0, -1, -1)).toBe(-1);
|
|
174
|
-
|
|
175
|
-
expect(clamp(3, 1, 2)).toBe(2);
|
|
176
|
-
|
|
177
|
-
expect(clamp(0, 1, 2)).toBe(1);
|
|
178
|
-
|
|
179
|
-
expect(clamp(2, 1, 3)).toBe(2);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test('copysign', () => {
|
|
183
|
-
expect(copysign(1, 2)).toBe(1);
|
|
184
|
-
expect(copysign(2, 1)).toBe(2);
|
|
185
|
-
|
|
186
|
-
expect(copysign(2, -1)).toBe(-2);
|
|
187
|
-
expect(copysign(-2, 1)).toBe(2);
|
|
188
|
-
expect(copysign(-2, -1)).toBe(-2);
|
|
189
|
-
|
|
190
|
-
expect(copysign(3, 7)).toBe(3);
|
|
191
|
-
expect(copysign(3, -7)).toBe(-3);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test('computeWholeDivisorLow 1/1', () => {
|
|
195
|
-
expect(computeWholeDivisorLow(1, 1)).toEqual(1);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('computeWholeDivisorLow 16/5', () => {
|
|
199
|
-
expect(computeWholeDivisorLow(16, 5)).toEqual(4);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
test("isValueBetween", () => {
|
|
203
|
-
expect(isValueBetween(0, 1, 2)).toBe(false);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test("isValueBetween", () => {
|
|
207
|
-
expect(isValueBetween(1, -1, 2)).toBe(true);
|
|
208
|
-
|
|
209
|
-
expect(isValueBetween(1, 2, -1)).toBe(true);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test("isValueBetweenInclusive", () => {
|
|
213
|
-
expect(isValueBetweenInclusive(1, 1, 2)).toBe(true);
|
|
214
|
-
|
|
215
|
-
expect(isValueBetweenInclusive(2, 1, 2)).toBe(true);
|
|
216
|
-
|
|
217
|
-
expect(isValueBetweenInclusive(1.5, 1, 2)).toBe(true);
|
|
218
|
-
|
|
219
|
-
expect(isValueBetweenInclusive(0.5, 1, 2)).toBe(false);
|
|
220
|
-
|
|
221
|
-
expect(isValueBetweenInclusive(3, 1, 2)).toBe(false);
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
test('overlap1D', () => {
|
|
226
|
-
expect(overlap1D(0, 0, 0, 0)).toBe(false);
|
|
227
|
-
expect(overlap1D(-3, -1, -2, -0.5)).toBe(true);
|
|
228
|
-
expect(overlap1D(-1, 2, 1, 1)).toBe(true);
|
|
229
|
-
expect(overlap1D(1, 1, -1, 2)).toBe(true);
|
|
230
|
-
|
|
231
|
-
expect(overlap1D(1, 2, 2, 3)).toBe(false);
|
|
232
|
-
});
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 13/05/2016.
|
|
3
|
-
*/
|
|
4
|
-
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
5
|
-
import Quaternion from "../../../../core/geom/Quaternion.js";
|
|
6
|
-
import { BinaryClassSerializationAdapter } from "../../storage/binary/BinaryClassSerializationAdapter.js";
|
|
7
|
-
|
|
8
|
-
const ClingToTerrain = function (options) {
|
|
9
|
-
if (options === undefined) {
|
|
10
|
-
options = {};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @type {boolean}
|
|
15
|
-
*/
|
|
16
|
-
this.normalAlign = options.normalAlign !== undefined ? options.normalAlign : false;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Used internally for caching updates
|
|
20
|
-
* @type {Vector3}
|
|
21
|
-
*/
|
|
22
|
-
this.__lastPosition = new Vector3(0, 0, 0);
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @type {Quaternion}
|
|
26
|
-
*/
|
|
27
|
-
this.__lastRotation = new Quaternion(0, 0, 0, 1);
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Speed in Rad/s (Radians/second) by which rotation can change
|
|
31
|
-
* @type {number}
|
|
32
|
-
*/
|
|
33
|
-
this.rotationSpeed = 3;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
ClingToTerrain.typeName = "ClingToTerrain";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @param json
|
|
41
|
-
* @returns {ClingToTerrain}
|
|
42
|
-
*/
|
|
43
|
-
ClingToTerrain.fromJSON = function (json) {
|
|
44
|
-
const r = new ClingToTerrain();
|
|
45
|
-
|
|
46
|
-
r.fromJSON(json);
|
|
47
|
-
|
|
48
|
-
return r;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
ClingToTerrain.prototype.toJSON = function () {
|
|
53
|
-
return {
|
|
54
|
-
normalAlign: this.normalAlign,
|
|
55
|
-
rotationSpeed: this.rotationSpeed
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
ClingToTerrain.prototype.fromJSON = function (
|
|
60
|
-
{
|
|
61
|
-
normalAlign = false,
|
|
62
|
-
rotationSpeed = Number.POSITIVE_INFINITY
|
|
63
|
-
}
|
|
64
|
-
) {
|
|
65
|
-
this.normalAlign = normalAlign;
|
|
66
|
-
this.rotationSpeed = rotationSpeed;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
export default ClingToTerrain;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export class ClingToTerrainSerializationAdapter extends BinaryClassSerializationAdapter{
|
|
74
|
-
constructor(){
|
|
75
|
-
super();
|
|
76
|
-
|
|
77
|
-
this.klass = ClingToTerrain;
|
|
78
|
-
this.version = 0;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
*
|
|
83
|
-
* @param {BinaryBuffer} buffer
|
|
84
|
-
* @param {ClingToTerrain} value
|
|
85
|
-
*/
|
|
86
|
-
serialize(buffer, value) {
|
|
87
|
-
//TODO serialize rotation speed
|
|
88
|
-
buffer.writeUint8(value.normalAlign ? 1 : 0);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
* @param {BinaryBuffer} buffer
|
|
94
|
-
* @param {ClingToTerrain} value
|
|
95
|
-
*/
|
|
96
|
-
deserialize(buffer, value) {
|
|
97
|
-
//TODO deserialize rotation speed
|
|
98
|
-
value.normalAlign = buffer.readUint8() !== 0;
|
|
99
|
-
}
|
|
100
|
-
}
|