@woosh/meep-engine 2.75.8 → 2.75.9

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.
Files changed (77) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +784 -982
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +784 -982
  5. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +6 -3
  6. package/editor/actions/concrete/PatchTerrainTextureAction.js +6 -3
  7. package/editor/process/EditorProcess.js +12 -16
  8. package/editor/process/ProcessEngine.js +9 -10
  9. package/package.json +1 -1
  10. package/src/core/binary/dec2hex.js +1 -1
  11. package/src/{engine/ecs/ik/IKMath.js → core/geom/vec3/v3_computeOffsetVector.js} +1 -1
  12. package/src/core/math/newton_solver_1d.js +13 -4
  13. package/src/core/math/solveQuadratic.js +5 -3
  14. package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
  15. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
  16. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
  17. package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
  18. package/src/core/math/spline/interpolate_bicubic.js +12 -0
  19. package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
  20. package/src/engine/control/ControlContext.js +25 -27
  21. package/src/engine/ecs/EntityManager.js +12 -9
  22. package/src/engine/ecs/EntityObserver.js +26 -22
  23. package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
  24. package/src/engine/ecs/components/Motion.js +5 -7
  25. package/src/engine/ecs/components/SerializationMetadata.js +5 -3
  26. package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
  27. package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
  28. package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
  29. package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
  30. package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
  31. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
  32. package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
  33. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
  34. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
  35. package/src/engine/ecs/parent/EntityNode.js +39 -37
  36. package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
  37. package/src/engine/ecs/system/SystemEntityContext.js +25 -23
  38. package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
  39. package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
  40. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
  41. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
  42. package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
  43. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  44. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
  45. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
  46. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
  47. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
  48. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
  49. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
  50. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -4
  51. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -4
  52. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  53. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
  54. package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
  55. package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
  56. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
  57. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
  58. package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
  59. package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
  60. package/src/engine/navigation/ecs/components/Path.js +10 -9
  61. package/src/engine/physics/computeInterceptPoint.js +44 -0
  62. package/src/engine/plugin/EnginePlugin.js +1 -2
  63. package/src/engine/ecs/components/AlignToVelocity.js +0 -9
  64. package/src/engine/ecs/components/CharacterController.js +0 -31
  65. package/src/engine/ecs/components/PhysicalBody.js +0 -51
  66. package/src/engine/ecs/components/Steering.js +0 -111
  67. package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
  68. package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
  69. package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
  70. package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
  71. package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
  72. package/src/engine/ecs/systems/SteeringSystem.js +0 -171
  73. package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
  74. package/src/engine/ecs/systems/TagSystem.js +0 -31
  75. package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
  76. package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
  77. package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
@@ -1,89 +0,0 @@
1
- /**
2
- * Created by Alex on 01/04/2014.
3
- */
4
- import { System } from '../System.js';
5
- import PhysicalBody from '../components/PhysicalBody.js';
6
- import { Transform } from '../transform/Transform.js';
7
- import PhysicsWorld from '../../physics/ammo/World.js';
8
-
9
-
10
- class PhysicsSystem extends System {
11
- constructor() {
12
- super();
13
-
14
- this.dependencies = [PhysicalBody];
15
- }
16
-
17
- rayTest(from, to, callback) {
18
- this.physics.rayTest(from, to, callback);
19
- }
20
-
21
- startup(entityManager, readyCallback, errorCallback) {
22
- this.entityManager = entityManager;
23
- this.physics = new PhysicsWorld(readyCallback);
24
- }
25
-
26
- shutdown(entityManager, readyCallback, errorCallback) {
27
- try {
28
- this.physics = null;
29
- readyCallback();
30
- } catch (e) {
31
- errorCallback(e);
32
- }
33
- }
34
-
35
- add(component, entity) {
36
- const body = component.body;
37
- body.__entity = entity;
38
- this.physics.addBody(body);
39
- //collisions
40
- if (component.notifyCollision) {
41
- const entityManager = this.entityManager;
42
-
43
- body.onCollision(function (other) {
44
- entityManager.sendEvent(entity, "collision", other.__entity);
45
- });
46
- }
47
- }
48
-
49
- remove(component) {
50
- const body = component.body;
51
- this.physics.removeBody(body);
52
- }
53
-
54
- update(timeDelta) {
55
- const entityManager = this.entityManager;
56
- let signals = entityManager.eventManager.signals;
57
- //set position to physical body
58
- entityManager.traverseEntities([PhysicalBody, Transform], function (physicalBody, transform) {
59
- //copy position into body
60
- const body = physicalBody.body;
61
- body.position.copy(transform.position);
62
- body.rotation.copy(transform.rotation);
63
- });
64
-
65
-
66
- const stepFinishedCallback = function () {
67
- //set position from physical body
68
- entityManager.traverseEntities([PhysicalBody, Transform], function (physicalBody, transform, entity) {
69
- //copy position from body
70
- const body = physicalBody.body;
71
- const previousPosition = transform.previousPosition;
72
- const currentPosition = transform.position;
73
- if (previousPosition.x != currentPosition.x || previousPosition.y != currentPosition.y || previousPosition.z != currentPosition.z) {
74
- //write previous position is the current position is different from before
75
- previousPosition.copy(currentPosition);
76
- }
77
- currentPosition.copy(body.position);
78
- // transform.rotation.copy(body.rotation);
79
- });
80
- };
81
- this.physics.simulate(timeDelta, stepFinishedCallback);
82
- }
83
- }
84
-
85
-
86
- function collisionHandler() {
87
- }
88
-
89
- export default PhysicsSystem;
@@ -1,18 +0,0 @@
1
- /**
2
- * Created by Alex on 13/04/2017.
3
- */
4
-
5
-
6
- import { System } from '../System.js';
7
- import PropertySet from '../components/PropertySet.js';
8
-
9
- class PropertySetSystem extends System {
10
- constructor() {
11
- super();
12
-
13
- this.dependencies = [PropertySet];
14
- }
15
- }
16
-
17
-
18
- export default PropertySetSystem;
@@ -1,171 +0,0 @@
1
- /**
2
- * User: Alex Goldring
3
- * Date: 1/6/2014
4
- * Time: 08:37
5
- */
6
- import { max2 } from "../../../core/math/max2.js";
7
- import { min2 } from "../../../core/math/min2.js";
8
- import { System } from '../System.js';
9
- import PhysicalBody from '../components/PhysicalBody.js';
10
- import Motion from '../components/Motion.js';
11
- import { Transform } from '../transform/Transform.js';
12
- import Steering, { SteeringEvents, SteeringFlags } from '../components/Steering.js';
13
- import Vector3 from "../../../core/geom/Vector3.js";
14
- import { alignToVector } from "../terrain/ecs/cling/ClingToTerrainSystem.js";
15
- import { v3_dot } from "../../../core/geom/vec3/v3_dot.js";
16
- import { solveQuadratic } from "../../../core/math/solveQuadratic.js";
17
-
18
- /**
19
- *
20
- * @param {Vector3} result
21
- * @param {Vector3} source
22
- * @param {Vector3} target
23
- * @param {Vector3} targetVelocity
24
- * @param {number} sourceSpeed
25
- * @return {boolean}
26
- */
27
- function computeInterceptPoint(result, source, target, targetVelocity, sourceSpeed) {
28
- const d_ts_x = target.x - source.x;
29
- const d_ts_y = target.y - source.y;
30
- const d_ts_z = target.z - source.z;
31
-
32
- // Get quadratic equation components
33
- const a = targetVelocity.dot(targetVelocity) - sourceSpeed * sourceSpeed;
34
- const b = 2 * v3_dot(targetVelocity.x, targetVelocity.y, targetVelocity.z, d_ts_x, d_ts_y, d_ts_z);
35
-
36
- const c = v3_dot(
37
- d_ts_x, d_ts_y, d_ts_z,
38
- d_ts_x, d_ts_y, d_ts_z
39
- );
40
-
41
- // Solve quadratic
42
- const ts = [];
43
- const root_count = solveQuadratic(ts, 0, a, b, c); // See quad(), below
44
-
45
- // Find smallest positive solution
46
- if (root_count > 0) {
47
- const t0 = ts[0], t1 = ts[1];
48
- let t = Math.min(t0, t1);
49
- if (t < 0) t = Math.max(t0, t1);
50
-
51
- if (t > 0) {
52
- result.copy(targetVelocity).multiplyScalar(t).add(target);
53
- return true;
54
- }
55
-
56
- }
57
- return false;
58
- }
59
-
60
- class SteeringSystem extends System {
61
- constructor() {
62
- super();
63
-
64
- this.dependencies = [Steering];
65
- }
66
-
67
- update(timeDelta) {
68
- const entityManager = this.entityManager;
69
-
70
- const ecd = entityManager.dataset;
71
-
72
- if (ecd === null) {
73
- return;
74
- }
75
-
76
- /**
77
- *
78
- * @param {number} entity
79
- * @param {Steering} steering
80
- * @param {Transform} transform
81
- * @param {Vector3} velocity
82
- */
83
- function process(entity, steering, transform, velocity) {
84
- if (!steering.getFlag(SteeringFlags.Active)) {
85
- //steering is inactive
86
- return;
87
- }
88
-
89
- const destination = steering.destination;
90
-
91
- const delta = destination.clone().sub(transform.position);
92
- delta.normalize();
93
-
94
- const distanceWithError = computeDistanceWithError(transform.position, destination, steering.targetMargin);
95
-
96
- if (distanceWithError > 0) {
97
- //not at the target yet
98
- const d = steering.maxSpeed;
99
-
100
- const angularLimit = steering.rotationSpeed * timeDelta;
101
-
102
- alignToVector(transform.rotation, delta, angularLimit, Vector3.up, Vector3.forward);
103
-
104
- //compute forward vector
105
- const v = Vector3.forward.clone();
106
- v.applyQuaternion(transform.rotation);
107
- v.normalize();
108
-
109
-
110
- //check old velocity to avoid flying past target
111
- if (distanceWithError < d * timeDelta) {
112
- const distance = delta.length();
113
- const adjustedVelocity = min2(d, distance / timeDelta);
114
- v.multiplyScalar(adjustedVelocity);
115
- } else {
116
- v.multiplyScalar(d);
117
- }
118
-
119
- velocity.copy(v);
120
-
121
- } else {
122
- //goal is reached, de-activate
123
- steering.clearFlag(SteeringFlags.Active);
124
-
125
- //drop velocity
126
- velocity.set(0, 0, 0);
127
-
128
- //dispatch
129
- ecd.sendEvent(entity, SteeringEvents.DestinationReached, steering);
130
- }
131
- }
132
-
133
- //Make sure physical bodies exist
134
- if (ecd.isComponentTypeRegistered(PhysicalBody)) {
135
-
136
- ecd.traverseEntities([Steering, PhysicalBody, Transform], function (steering, physicalBody, transform, entity) {
137
-
138
- const body = physicalBody.body;
139
-
140
- process(entity, steering, transform, body.linearVelocity);
141
-
142
- });
143
-
144
- }
145
-
146
- ecd.traverseEntities([Steering, Motion, Transform], function (steering, motion, transform, entity) {
147
- process(entity, steering, transform, motion.velocity);
148
- });
149
- }
150
- }
151
-
152
- /**
153
- *
154
- * @param {Vector3} v0
155
- * @param {Vector3} v1
156
- * @param {Vector3} error
157
- * @return {number}
158
- */
159
- function computeDistanceWithError(v0, v1, error) {
160
- const absDelta = v0.clone().sub(v1).abs();
161
-
162
- absDelta.set(
163
- max2(absDelta.x - error.x, 0),
164
- max2(absDelta.y - error.y, 0),
165
- max2(absDelta.z - error.z, 0)
166
- );
167
-
168
- return absDelta.length();
169
- }
170
-
171
- export default SteeringSystem;
@@ -1,5 +0,0 @@
1
- import {System} from "../System";
2
-
3
- export class TagSystem extends System {
4
-
5
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * Created by Alex on 23/04/2014.
3
- */
4
- import { System } from '../System.js';
5
- import Tag from '../components/Tag.js';
6
-
7
-
8
- class TagSystem extends System {
9
-
10
- dependencies = [Tag];
11
-
12
- /**
13
- *
14
- * @param {string} tag
15
- * @param {EntityComponentDataset} ecd
16
- * @returns {number[]}
17
- */
18
- static find_entities_with_tag(tag, ecd) {
19
- const r = [];
20
- ecd.traverseComponents(Tag, (t, e) => {
21
- if (t.contains(tag)) {
22
- r.push(e);
23
- }
24
- });
25
-
26
- return r;
27
- }
28
- }
29
-
30
-
31
- export default TagSystem;
@@ -1,59 +0,0 @@
1
- /**
2
- * @see https://github.com/hughsk/bicubic/blob/master/index.js
3
- * @param {number} xf
4
- * @param {number} yf
5
- * @param {number} p00
6
- * @param {number} p01
7
- * @param {number} p02
8
- * @param {number} p03
9
- * @param {number} p10
10
- * @param {number} p11
11
- * @param {number} p12
12
- * @param {number} p13
13
- * @param {number} p20
14
- * @param {number} p21
15
- * @param {number} p22
16
- * @param {number} p23
17
- * @param {number} p30
18
- * @param {number} p31
19
- * @param {number} p32
20
- * @param {number} p33
21
- * @returns {number}
22
- */
23
- export function bicubic(
24
- xf, yf
25
- , p00, p01, p02, p03
26
- , p10, p11, p12, p13
27
- , p20, p21, p22, p23
28
- , p30, p31, p32, p33
29
- ) {
30
- var yf2 = yf * yf
31
- var xf2 = xf * xf
32
- var xf3 = xf * xf2
33
-
34
- var x00 = p03 - p02 - p00 + p01
35
- var x01 = p00 - p01 - x00
36
- var x02 = p02 - p00
37
- var x0 = x00 * xf3 + x01 * xf2 + x02 * xf + p01
38
-
39
- var x10 = p13 - p12 - p10 + p11
40
- var x11 = p10 - p11 - x10
41
- var x12 = p12 - p10
42
- var x1 = x10 * xf3 + x11 * xf2 + x12 * xf + p11
43
-
44
- var x20 = p23 - p22 - p20 + p21
45
- var x21 = p20 - p21 - x20
46
- var x22 = p22 - p20
47
- var x2 = x20 * xf3 + x21 * xf2 + x22 * xf + p21
48
-
49
- var x30 = p33 - p32 - p30 + p31
50
- var x31 = p30 - p31 - x30
51
- var x32 = p32 - p30
52
- var x3 = x30 * xf3 + x31 * xf2 + x32 * xf + p31
53
-
54
- var y0 = x3 - x2 - x0 + x1
55
- var y1 = x0 - x1 - y0
56
- var y2 = x2 - x0
57
-
58
- return y0 * yf * yf2 + y1 * yf2 + y2 * yf + x1
59
- }
@@ -1,13 +0,0 @@
1
- import { bicubic } from "./bicubic.js";
2
-
3
- test("sanity", () => {
4
-
5
- expect(bicubic(
6
- 0.5, 0.5,
7
- 3, 3, 3, 3,
8
- 3, 3, 3, 3,
9
- 3, 3, 3, 3,
10
- 3, 3, 3, 3,
11
- )).toBeCloseTo(3);
12
-
13
- });
@@ -1,242 +0,0 @@
1
- /**
2
- *
3
- * @param {number[]} p0
4
- * @param {number[]} p1
5
- * @param {number} dimensions
6
- * @param {number} half_alpha between 0..0.5
7
- * @returns {number}
8
- */
9
- function getT(p0, p1, dimensions, half_alpha) {
10
- let a = 0;
11
-
12
- for (let i = 0; i < dimensions; i++) {
13
- const dx = p0[i] - p1[i];
14
-
15
- a += dx * dx;
16
- }
17
-
18
- return Math.pow(a, half_alpha);
19
- }
20
-
21
- /**
22
- * Based on wiki article: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline#Code_example_in_Python
23
- * @param {number[]} result
24
- * @param {number[]} p0 spline point 0
25
- * @param {number[]} p1 spline point 1
26
- * @param {number[]} p2 spline point 2
27
- * @param {number[]} p3 spline point 3
28
- * @param {number} dimensions number of dimensions in the input and output vectors
29
- * @param {number} f between 0..1
30
- * @param {number} alpha between 0..1
31
- */
32
- export function computeNonuniformCatmullRomSplineSample(result, p0, p1, p2, p3, dimensions, f, alpha) {
33
- const half_alpha = alpha * 0.5;
34
-
35
- // calculate T
36
- const t0 = 0;
37
- let t_01 = getT(p0, p1, dimensions, half_alpha);
38
- let t_02 = getT(p1, p2, dimensions, half_alpha);
39
- let t_03 = getT(p2, p3, dimensions, half_alpha);
40
-
41
- // safety check for repeated points, to prevent division by 0
42
- if (t_01 < 1e-4) {
43
- t_01 = 1;
44
- }
45
- if (t_02 < 1e-4) {
46
- t_02 = t_01;
47
- }
48
- if (t_03 < 1e-4) {
49
- t_03 = t_02;
50
- }
51
-
52
- const t1 = t_01 + t0;
53
- const t2 = t_02 + t1;
54
- const t3 = t_03 + t2;
55
-
56
- /**
57
- * Interpolation between points 1 and 2
58
- * @type {number}
59
- */
60
- const t = t1 * (1 - f) + t2 * f;
61
-
62
- /*
63
- Vector2 A1 = (t1-t)/(t1-t0)*p0 + (t-t0)/(t1-t0)*p1;
64
- Vector2 A2 = (t2-t)/(t2-t1)*p1 + (t-t1)/(t2-t1)*p2;
65
- Vector2 A3 = (t3-t)/(t3-t2)*p2 + (t-t2)/(t3-t2)*p3;
66
-
67
- Vector2 B1 = (t2-t)/(t2-t0)*A1 + (t-t0)/(t2-t0)*A2;
68
- Vector2 B2 = (t3-t)/(t3-t1)*A2 + (t-t1)/(t3-t1)*A3;
69
-
70
- Vector2 C = (t2-t)/(t2-t1)*B1 + (t-t1)/(t2-t1)*B2;
71
- */
72
-
73
- const d_t1_t0 = t1 - t0;
74
-
75
- const m_A1_0 = (t1 - t) / d_t1_t0;
76
- const m_A1_1 = (t - t0) / d_t1_t0;
77
-
78
- const d_t2_t1 = t2 - t1;
79
-
80
- const m_A2_0 = (t2 - t) / d_t2_t1;
81
-
82
- const d_t_t1 = t - t1;
83
-
84
- const m_A2_1 = d_t_t1 / d_t2_t1;
85
-
86
- const d_t3_t2 = t3 - t2;
87
-
88
- const d_t3_t = t3 - t;
89
-
90
- const m_A3_0 = d_t3_t / d_t3_t2;
91
- const m_A3_1 = (t - t2) / d_t3_t2;
92
-
93
- const d_t2_t0 = t2 - t0;
94
-
95
- const m_B1_0 = (t2 - t) / d_t2_t0;
96
- const m_B1_1 = (t - t0) / d_t2_t0;
97
-
98
- const d_t3_t1 = t3 - t1;
99
-
100
- const m_B2_0 = d_t3_t / d_t3_t1;
101
- const m_B2_1 = d_t_t1 / d_t3_t1;
102
-
103
- const m_C_0 = (t2 - t) / d_t2_t1;
104
- const m_C_1 = d_t_t1 / d_t2_t1;
105
-
106
- for (let i = 0; i < dimensions; i++) {
107
- // read vector values for the dimension
108
- const v0 = p0[i];
109
- const v1 = p1[i];
110
- const v2 = p2[i];
111
- const v3 = p3[i];
112
-
113
- // compute resulting value in this dimension
114
- const A1 = m_A1_0 * v0 + m_A1_1 * v1;
115
- const A2 = m_A2_0 * v1 + m_A2_1 * v2;
116
- const A3 = m_A3_0 * v2 + m_A3_1 * v3;
117
-
118
- const B1 = m_B1_0 * A1 + m_B1_1 * A2;
119
- const B2 = m_B2_0 * A2 + m_B2_1 * A3;
120
-
121
- const C = m_C_0 * B1 + m_C_1 * B2;
122
-
123
- result[i] = C;
124
- }
125
- }
126
-
127
-
128
- /**
129
- * Alpha assumed to be 0.5
130
- * @param {number} f
131
- * @param {number} p0
132
- * @param {number} p1
133
- * @param {number} p2
134
- * @param {number} p3
135
- * @returns {number}
136
- */
137
- function catmullrom_1d(f, p0, p1, p2, p3) {
138
- const half_alpha = 0.25;
139
-
140
- /**
141
- *
142
- * @param {number} p0
143
- * @param {number} p1
144
- * @param {number} half_alpha between 0..0.5
145
- * @returns {number}
146
- */
147
- function getT(p0, p1, half_alpha) {
148
- const dx = p0 - p1;
149
-
150
- const a = dx * dx;
151
-
152
- return Math.pow(a, half_alpha);
153
- }
154
-
155
- // calculate T
156
- const t0 = 0;
157
- let t_01 = getT(p0, p1, half_alpha);
158
- let t_02 = getT(p1, p2, half_alpha);
159
- let t_03 = getT(p2, p3, half_alpha);
160
-
161
- // safety check for repeated points, to prevent division by 0
162
- if (t_01 < 1e-5) {
163
- t_01 = 1;
164
- }
165
- if (t_02 < 1e-5) {
166
- t_02 = t_01;
167
- }
168
- if (t_03 < 1e-5) {
169
- t_03 = t_02;
170
- }
171
-
172
- const t1 = t_01 + t0;
173
- const t2 = t_02 + t1;
174
- const t3 = t_03 + t2;
175
-
176
- /**
177
- * Interpolation between points 1 and 2
178
- * @type {number}
179
- */
180
- const t = t1 * (1 - f) + t2 * f;
181
-
182
- /*
183
- Vector2 A1 = (t1-t)/(t1-t0)*p0 + (t-t0)/(t1-t0)*p1;
184
- Vector2 A2 = (t2-t)/(t2-t1)*p1 + (t-t1)/(t2-t1)*p2;
185
- Vector2 A3 = (t3-t)/(t3-t2)*p2 + (t-t2)/(t3-t2)*p3;
186
-
187
- Vector2 B1 = (t2-t)/(t2-t0)*A1 + (t-t0)/(t2-t0)*A2;
188
- Vector2 B2 = (t3-t)/(t3-t1)*A2 + (t-t1)/(t3-t1)*A3;
189
-
190
- Vector2 C = (t2-t)/(t2-t1)*B1 + (t-t1)/(t2-t1)*B2;
191
- */
192
-
193
- const d_t1_t0 = t1 - t0;
194
-
195
- const m_A1_0 = (t1 - t) / d_t1_t0;
196
- const m_A1_1 = (t - t0) / d_t1_t0;
197
-
198
- const d_t2_t1 = t2 - t1;
199
-
200
- const m_A2_0 = (t2 - t) / d_t2_t1;
201
-
202
- const d_t_t1 = t - t1;
203
-
204
- const m_A2_1 = d_t_t1 / d_t2_t1;
205
-
206
- const d_t3_t2 = t3 - t2;
207
-
208
- const d_t3_t = t3 - t;
209
-
210
- const m_A3_0 = d_t3_t / d_t3_t2;
211
- const m_A3_1 = (t - t2) / d_t3_t2;
212
-
213
- const d_t2_t0 = t2 - t0;
214
-
215
- const m_B1_0 = (t2 - t) / d_t2_t0;
216
- const m_B1_1 = (t - t0) / d_t2_t0;
217
-
218
- const d_t3_t1 = t3 - t1;
219
-
220
- const m_B2_0 = d_t3_t / d_t3_t1;
221
- const m_B2_1 = d_t_t1 / d_t3_t1;
222
-
223
- const m_C_0 = (t2 - t) / d_t2_t1;
224
- const m_C_1 = d_t_t1 / d_t2_t1;
225
-
226
- // read vector values for the dimension
227
- const v0 = p0;
228
- const v1 = p1;
229
- const v2 = p2;
230
- const v3 = p3;
231
-
232
- // compute resulting value in this dimension
233
- const A1 = m_A1_0 * v0 + m_A1_1 * v1;
234
- const A2 = m_A2_0 * v1 + m_A2_1 * v2;
235
- const A3 = m_A3_0 * v2 + m_A3_1 * v3;
236
-
237
- const B1 = m_B1_0 * A1 + m_B1_1 * A2;
238
- const B2 = m_B2_0 * A2 + m_B2_1 * A3;
239
-
240
- return m_C_0 * B1 + m_C_1 * B2;
241
-
242
- }