@woosh/meep-engine 2.75.8 → 2.76.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.
Files changed (107) 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/{engine/graphics → core/math/random}/generate_halton_jitter.js +2 -2
  14. package/src/core/math/solveQuadratic.js +5 -3
  15. package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
  16. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
  17. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
  18. package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
  19. package/src/core/math/spline/interpolate_bicubic.js +12 -0
  20. package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
  21. package/src/engine/control/ControlContext.js +25 -27
  22. package/src/engine/ecs/EntityManager.js +12 -9
  23. package/src/engine/ecs/EntityObserver.js +26 -22
  24. package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
  25. package/src/engine/ecs/components/Motion.js +5 -7
  26. package/src/engine/ecs/components/SerializationMetadata.js +5 -3
  27. package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
  28. package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
  29. package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
  30. package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
  31. package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
  32. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
  33. package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
  34. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
  35. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
  36. package/src/engine/ecs/parent/EntityNode.js +39 -37
  37. package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
  38. package/src/engine/ecs/system/SystemEntityContext.js +25 -23
  39. package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
  40. package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
  41. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
  42. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
  43. package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
  44. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  45. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
  46. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
  47. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
  48. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
  49. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
  50. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
  51. package/src/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.js +1 -1
  52. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -4
  53. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -4
  54. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  55. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
  56. package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
  57. package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
  58. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
  59. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
  60. package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
  61. package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
  62. package/src/engine/graphics/texture/virtual/VirtualTextureUsageUpdater.js +1 -1
  63. package/src/engine/navigation/ecs/components/Path.js +10 -9
  64. package/src/engine/physics/computeInterceptPoint.js +44 -0
  65. package/src/engine/plugin/EnginePlugin.js +1 -2
  66. package/src/engine/ecs/components/AlignToVelocity.js +0 -9
  67. package/src/engine/ecs/components/CharacterController.js +0 -31
  68. package/src/engine/ecs/components/PhysicalBody.js +0 -51
  69. package/src/engine/ecs/components/Steering.js +0 -111
  70. package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
  71. package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
  72. package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
  73. package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
  74. package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
  75. package/src/engine/ecs/systems/SteeringSystem.js +0 -171
  76. package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
  77. package/src/engine/ecs/systems/TagSystem.js +0 -31
  78. package/src/engine/graphics/CanvasBlur.js +0 -599
  79. package/src/engine/graphics/material/LoadMaterial.js +0 -199
  80. package/src/engine/graphics/material/getTextureImmediate.js +0 -21
  81. package/src/engine/graphics/render/buffer/RenderGraph.js +0 -177
  82. package/src/engine/graphics/render/buffer/RenderGraphUtils.js +0 -32
  83. package/src/engine/graphics/render/buffer/buffers/DepthFrameBuffer.js +0 -101
  84. package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnection.js +0 -43
  85. package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnectionEndpoint.js +0 -39
  86. package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnectionValidator.js +0 -30
  87. package/src/engine/graphics/render/buffer/executor/FrameBufferPool.js +0 -127
  88. package/src/engine/graphics/render/buffer/executor/RenderGraphExecutor.js +0 -261
  89. package/src/engine/graphics/render/buffer/executor/RenderProgramCommandType.js +0 -5
  90. package/src/engine/graphics/render/buffer/node/DeferredRenderProgramDefinition.js +0 -142
  91. package/src/engine/graphics/render/buffer/node/RenderProgramDefinition.js +0 -21
  92. package/src/engine/graphics/render/buffer/node/RenderProgramInstance.js +0 -30
  93. package/src/engine/graphics/render/buffer/node/ScreenSpaceRenderProgramDefinition.js +0 -118
  94. package/src/engine/graphics/render/staged/PostProcessingEffect.js +0 -32
  95. package/src/engine/graphics/render/staged/PostProcessingEffectInputCoupling.js +0 -41
  96. package/src/engine/graphics/render/staged/PostProcessingStack.js +0 -29
  97. package/src/engine/graphics/render/staged/StagedRenderer.js +0 -161
  98. package/src/engine/graphics/render/staged/StandardRenderOutputs.js +0 -20
  99. package/src/engine/graphics/texture/CanvasClone.js +0 -28
  100. package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
  101. package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
  102. package/src/engine/graphics/texture/sampler/differenceSampler.js +0 -36
  103. package/src/engine/graphics/texture/sampler/loadSampler2D.js +0 -41
  104. package/src/engine/graphics/texture/sampler/mergeSampler2D.js +0 -96
  105. package/src/engine/graphics/texture/sampler/rgbaData2valueSampler2D.js +0 -38
  106. package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
  107. /package/src/{engine/graphics/texture → core/math/noise}/noise_octaves.js +0 -0
@@ -1,5 +1,8 @@
1
1
  import { Action } from "../../../src/core/process/undo/Action.js";
2
2
  import { Sampler2D } from "../../../src/engine/graphics/texture/sampler/Sampler2D.js";
3
+ import {
4
+ sampler2d_sub_copy_same_item_size
5
+ } from "../../../src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js";
3
6
 
4
7
  export class ModifyPatchSampler2DAction extends Action {
5
8
  /**
@@ -95,12 +98,12 @@ export class ModifyPatchSampler2DAction extends Action {
95
98
  //store old data from the patch
96
99
  const patch_old = this.__patch_old;
97
100
 
98
- patch_old.copy_sameItemSize(source, this.x, this.y, 0, 0, patch_old.width, patch_old.height);
101
+ sampler2d_sub_copy_same_item_size(patch_old,source, this.x, this.y, 0, 0, patch_old.width, patch_old.height);
99
102
 
100
103
  const patch_new = this.__patch_new;
101
104
 
102
105
  //apply the patch
103
- source.copy_sameItemSize(patch_new, 0, 0, this.x, this.y, patch_new.width, patch_new.height);
106
+ sampler2d_sub_copy_same_item_size(source,patch_new, 0, 0, this.x, this.y, patch_new.width, patch_new.height);
104
107
  }
105
108
 
106
109
  async revert(context) {
@@ -113,6 +116,6 @@ export class ModifyPatchSampler2DAction extends Action {
113
116
  const patch_old = this.__patch_old;
114
117
 
115
118
  //apply the patch
116
- source.copy_sameItemSize(patch_old, 0, 0, this.x, this.y, patch_old.width, patch_old.height);
119
+ sampler2d_sub_copy_same_item_size(source,patch_old, 0, 0, this.x, this.y, patch_old.width, patch_old.height);
117
120
  }
118
121
  }
@@ -2,6 +2,9 @@ import { max2 } from "../../../src/core/math/max2.js";
2
2
  import { min2 } from "../../../src/core/math/min2.js";
3
3
  import { Action } from "../../../src/core/process/undo/Action.js";
4
4
  import { Sampler2D } from "../../../src/engine/graphics/texture/sampler/Sampler2D.js";
5
+ import {
6
+ sampler2d_sub_copy_same_item_size
7
+ } from "../../../src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js";
5
8
 
6
9
  export class PatchTerrainTextureAction extends Action {
7
10
 
@@ -115,13 +118,13 @@ export class PatchTerrainTextureAction extends Action {
115
118
  splat.readWeightData(this.__oldPatchWeight, this.x, this.y, this.width, this.height);
116
119
 
117
120
  const oldPatchMaterial = this.__oldPatchMaterial;
118
- oldPatchMaterial.copy_sameItemSize(samplerMaterials, this.x, this.y, 0, 0, oldPatchMaterial.width, oldPatchMaterial.height);
121
+ sampler2d_sub_copy_same_item_size(oldPatchMaterial,samplerMaterials, this.x, this.y, 0, 0, oldPatchMaterial.width, oldPatchMaterial.height);
119
122
 
120
123
  //apply the patch
121
124
  splat.writeWeightData(this.patchWeight, this.x, this.y, this.width, this.height);
122
125
 
123
126
  const patchMaterial = this.patchMaterial;
124
- samplerMaterials.copy_sameItemSize(patchMaterial, 0, 0, this.x, this.y, patchMaterial.width, patchMaterial.height);
127
+ sampler2d_sub_copy_same_item_size(samplerMaterials,patchMaterial, 0, 0, this.x, this.y, patchMaterial.width, patchMaterial.height);
125
128
 
126
129
  this.updateTerrain();
127
130
  }
@@ -142,7 +145,7 @@ export class PatchTerrainTextureAction extends Action {
142
145
  splat.writeWeightData(this.__oldPatchWeight, this.x, this.y, this.width, this.height);
143
146
 
144
147
  const patchMaterial = this.__oldPatchMaterial;
145
- samplerMaterials.copy_sameItemSize(patchMaterial, 0, 0, this.x, this.y, patchMaterial.width, patchMaterial.height);
148
+ sampler2d_sub_copy_same_item_size(samplerMaterials,patchMaterial, 0, 0, this.x, this.y, patchMaterial.width, patchMaterial.height);
146
149
 
147
150
 
148
151
  this.updateTerrain();
@@ -1,30 +1,26 @@
1
- import { BaseProcess } from "../../src/core/process/BaseProcess.js";
2
1
  import { assert } from "../../src/core/assert.js";
2
+ import { BaseProcess } from "../../src/core/process/BaseProcess.js";
3
3
 
4
4
 
5
5
  class EditorProcess extends BaseProcess {
6
6
 
7
- constructor() {
8
- super();
9
-
10
- /**
11
- *
12
- * @type {string}
13
- */
14
- this.name = "unnamed";
15
- /**
16
- *
17
- * @type {Editor|null}
18
- */
19
- this.editor = null;
20
- }
7
+ /**
8
+ *
9
+ * @type {string}
10
+ */
11
+ name = "unnamed";
12
+ /**
13
+ *
14
+ * @type {Editor|null}
15
+ */
16
+ editor = null;
21
17
 
22
18
  /**
23
19
  *
24
20
  * @param {Editor} editor
25
21
  */
26
22
  initialize(editor) {
27
- assert.defined(editor,'editor');
23
+ assert.defined(editor, 'editor');
28
24
 
29
25
  this.editor = editor;
30
26
 
@@ -1,6 +1,6 @@
1
- import { EditorProcess } from "./EditorProcess.js";
2
1
  import List from "../../src/core/collection/list/List.js";
3
2
  import { ProcessState } from "../../src/core/process/ProcessState.js";
3
+ import { EditorProcess } from "./EditorProcess.js";
4
4
 
5
5
  /**
6
6
  *
@@ -21,15 +21,14 @@ function tryInitialize(editor, process) {
21
21
  }
22
22
 
23
23
  class ProcessEngine extends EditorProcess {
24
- constructor() {
25
- super();
26
- /**
27
- * @type {List.<EditorProcess>}
28
- */
29
- this.processes = new List();
30
-
31
- this.__suspendedList = new List();
32
- }
24
+
25
+ /**
26
+ * @type {List.<EditorProcess>}
27
+ */
28
+ processes = new List();
29
+
30
+ __suspendedList = new List();
31
+
33
32
 
34
33
  startup() {
35
34
  super.startup();
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.75.8",
8
+ "version": "2.76.0",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Convert a decimal value to hex
3
3
  * @param {number} c generally expects b byte value, 0-255
4
- * @returns {string}
4
+ * @returns {string} zero-padded value, for example instead of "0", will return "00" and instead of "F" will return "0F"
5
5
  */
6
6
  export function dec2hex(c) {
7
7
  const hex = Math.round(c).toString(16);
@@ -31,4 +31,4 @@ export function v3_computeOffsetVector(
31
31
  const z = sourceZ + directionZ * m;
32
32
 
33
33
  result.set(x, y, z);
34
- }
34
+ }
@@ -1,20 +1,29 @@
1
1
  /**
2
2
  * Newtonian solver, works by moving along the curve in the direction of gradient
3
- * @template T
4
- * @param {function(T):number} f
3
+ * @param {function(number):number} f Function for which we are trying to solve
5
4
  * @param {number} xStart
6
5
  * @param {number} [max_steps]
7
6
  * @param {number} [eps]
8
7
  * @returns {number}
9
8
  */
10
- export function newton_solver_1d(f, xStart, max_steps = 1000, eps = 0.00000001) {
9
+ export function newton_solver_1d(
10
+ f,
11
+ xStart,
12
+ max_steps = 1000,
13
+ eps = 0.00000001
14
+ ) {
11
15
  let x = xStart, fx;
12
16
 
13
17
  let remaining_steps = max_steps;
14
18
 
15
19
  while ((remaining_steps--) && Math.abs(fx = f(x)) > eps) {
16
- const dfdx = (f(x + eps) - fx) / eps;
20
+
21
+ const fx_eps = f(x + eps);
22
+
23
+ const dfdx = (fx_eps - fx) / eps;
24
+
17
25
  x = x - fx / dfdx;
26
+
18
27
  }
19
28
 
20
29
  return x;
@@ -1,5 +1,5 @@
1
- import { assert } from "../../core/assert.js";
2
- import { halton_sequence } from "../../core/math/statistics/halton_sequence.js";
1
+ import { assert } from "../../assert.js";
2
+ import { halton_sequence } from "../statistics/halton_sequence.js";
3
3
 
4
4
  /**
5
5
  * Generates a number of 2d jitter offsets in range -1...1
@@ -1,3 +1,5 @@
1
+ import { EPSILON } from "./EPSILON.js";
2
+
1
3
  /**
2
4
  * Return solutions for a quadratic equation
3
5
  * @param {number} a
@@ -9,9 +11,9 @@
9
11
  */
10
12
  export function solveQuadratic(result, result_offset, a, b, c) {
11
13
 
12
- if (Math.abs(a) < 1e-6) {
13
- if (Math.abs(b) < 1e-6) {
14
- if (Math.abs(c) < 1e-6) {
14
+ if (Math.abs(a) < EPSILON) {
15
+ if (Math.abs(b) < EPSILON) {
16
+ if (Math.abs(c) < EPSILON) {
15
17
 
16
18
  result[result_offset] = 0;
17
19
  result[result_offset + 1] = 0;
@@ -0,0 +1,19 @@
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
+ export function catmull_rom_compute_T(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
+ }
@@ -1,6 +1,6 @@
1
- import { assert } from "../../../../core/assert.js";
2
- import { clamp } from "../../../../core/math/clamp.js";
3
- import { array_copy } from "../../../../core/collection/array/array_copy.js";
1
+ import { assert } from "../../assert.js";
2
+ import { array_copy } from "../../collection/array/array_copy.js";
3
+ import { clamp } from "../clamp.js";
4
4
  import { computeNonuniformCatmullRomSplineSample } from "./computeNonuniformCatmullRomSplineSample.js";
5
5
 
6
6
  /**
@@ -1,7 +1,7 @@
1
- import { clamp } from "../../../../core/math/clamp.js";
2
- import { array_copy } from "../../../../core/collection/array/array_copy.js";
1
+ import { assert } from "../../assert.js";
2
+ import { array_copy } from "../../collection/array/array_copy.js";
3
+ import { clamp } from "../clamp.js";
3
4
  import { computeNonuniformCatmullRomSplineSample } from "./computeNonuniformCatmullRomSplineSample.js";
4
- import { assert } from "../../../../core/assert.js";
5
5
 
6
6
  /**
7
7
  *
@@ -0,0 +1,109 @@
1
+ import { catmull_rom_compute_T } from "./catmull_rom_compute_T.js";
2
+
3
+ /**
4
+ * Based on wiki article: https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline#Code_example_in_Python
5
+ * @param {number[]} result
6
+ * @param {number[]} p0 spline point 0
7
+ * @param {number[]} p1 spline point 1
8
+ * @param {number[]} p2 spline point 2
9
+ * @param {number[]} p3 spline point 3
10
+ * @param {number} dimensions number of dimensions in the input and output vectors
11
+ * @param {number} f between 0..1
12
+ * @param {number} alpha between 0..1
13
+ */
14
+ export function computeNonuniformCatmullRomSplineSample(result, p0, p1, p2, p3, dimensions, f, alpha) {
15
+ const half_alpha = alpha * 0.5;
16
+
17
+ // calculate T
18
+ const t0 = 0;
19
+ let t_01 = catmull_rom_compute_T(p0, p1, dimensions, half_alpha);
20
+ let t_02 = catmull_rom_compute_T(p1, p2, dimensions, half_alpha);
21
+ let t_03 = catmull_rom_compute_T(p2, p3, dimensions, half_alpha);
22
+
23
+ // safety check for repeated points, to prevent division by 0
24
+ if (t_01 < 1e-4) {
25
+ t_01 = 1;
26
+ }
27
+ if (t_02 < 1e-4) {
28
+ t_02 = t_01;
29
+ }
30
+ if (t_03 < 1e-4) {
31
+ t_03 = t_02;
32
+ }
33
+
34
+ const t1 = t_01 + t0;
35
+ const t2 = t_02 + t1;
36
+ const t3 = t_03 + t2;
37
+
38
+ /**
39
+ * Interpolation between points 1 and 2
40
+ * @type {number}
41
+ */
42
+ const t = t1 * (1 - f) + t2 * f;
43
+
44
+ /*
45
+ Vector2 A1 = (t1-t)/(t1-t0)*p0 + (t-t0)/(t1-t0)*p1;
46
+ Vector2 A2 = (t2-t)/(t2-t1)*p1 + (t-t1)/(t2-t1)*p2;
47
+ Vector2 A3 = (t3-t)/(t3-t2)*p2 + (t-t2)/(t3-t2)*p3;
48
+
49
+ Vector2 B1 = (t2-t)/(t2-t0)*A1 + (t-t0)/(t2-t0)*A2;
50
+ Vector2 B2 = (t3-t)/(t3-t1)*A2 + (t-t1)/(t3-t1)*A3;
51
+
52
+ Vector2 C = (t2-t)/(t2-t1)*B1 + (t-t1)/(t2-t1)*B2;
53
+ */
54
+
55
+ const d_t1_t0 = t1 - t0;
56
+
57
+ const m_A1_0 = (t1 - t) / d_t1_t0;
58
+ const m_A1_1 = (t - t0) / d_t1_t0;
59
+
60
+ const d_t2_t1 = t2 - t1;
61
+
62
+ const m_A2_0 = (t2 - t) / d_t2_t1;
63
+
64
+ const d_t_t1 = t - t1;
65
+
66
+ const m_A2_1 = d_t_t1 / d_t2_t1;
67
+
68
+ const d_t3_t2 = t3 - t2;
69
+
70
+ const d_t3_t = t3 - t;
71
+
72
+ const m_A3_0 = d_t3_t / d_t3_t2;
73
+ const m_A3_1 = (t - t2) / d_t3_t2;
74
+
75
+ const d_t2_t0 = t2 - t0;
76
+
77
+ const m_B1_0 = (t2 - t) / d_t2_t0;
78
+ const m_B1_1 = (t - t0) / d_t2_t0;
79
+
80
+ const d_t3_t1 = t3 - t1;
81
+
82
+ const m_B2_0 = d_t3_t / d_t3_t1;
83
+ const m_B2_1 = d_t_t1 / d_t3_t1;
84
+
85
+ const m_C_0 = (t2 - t) / d_t2_t1;
86
+ const m_C_1 = d_t_t1 / d_t2_t1;
87
+
88
+ for (let i = 0; i < dimensions; i++) {
89
+ // read vector values for the dimension
90
+ const v0 = p0[i];
91
+ const v1 = p1[i];
92
+ const v2 = p2[i];
93
+ const v3 = p3[i];
94
+
95
+ // compute resulting value in this dimension
96
+ const A1 = m_A1_0 * v0 + m_A1_1 * v1;
97
+ const A2 = m_A2_0 * v1 + m_A2_1 * v2;
98
+ const A3 = m_A3_0 * v2 + m_A3_1 * v3;
99
+
100
+ const B1 = m_B1_0 * A1 + m_B1_1 * A2;
101
+ const B2 = m_B2_0 * A2 + m_B2_1 * A3;
102
+
103
+ const C = m_C_0 * B1 + m_C_1 * B2;
104
+
105
+ result[i] = C;
106
+ }
107
+ }
108
+
109
+
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Based on code from reddit https://www.reddit.com/r/javascript/comments/jxa8x/bicubic_interpolation/
3
+ * @param {number} t ratio
4
+ * @param {number} a position -2
5
+ * @param {number} b position -1
6
+ * @param {number} c position +1
7
+ * @param {number} d position +2
8
+ * @returns {number}
9
+ */
10
+ export function interpolate_bicubic(t, a, b, c, d) {
11
+ return 0.5 * (c - a + (2.0 * a - 5.0 * b + 4.0 * c - d + (3.0 * (b - c) + d - a) * t) * t) * t + b;
12
+ }
@@ -0,0 +1,120 @@
1
+
2
+ /**
3
+ *
4
+ * @param {number} p0
5
+ * @param {number} p1
6
+ * @param {number} half_alpha between 0..0.5
7
+ * @returns {number}
8
+ */
9
+ function getT(p0, p1, half_alpha) {
10
+ const dx = p0 - p1;
11
+
12
+ const a = dx * dx;
13
+
14
+ return Math.pow(a, half_alpha);
15
+ }
16
+
17
+
18
+ /**
19
+ * Alpha assumed to be 0.5
20
+ * @param {number} f
21
+ * @param {number} p0
22
+ * @param {number} p1
23
+ * @param {number} p2
24
+ * @param {number} p3
25
+ * @returns {number}
26
+ */
27
+ export function spline_catmullrom_1d(
28
+ f,
29
+ p0, p1, p2, p3
30
+ ) {
31
+ const half_alpha = 0.25;
32
+
33
+ // calculate T
34
+ const t0 = 0;
35
+ let t_01 = getT(p0, p1, half_alpha);
36
+ let t_02 = getT(p1, p2, half_alpha);
37
+ let t_03 = getT(p2, p3, half_alpha);
38
+
39
+ // safety check for repeated points, to prevent division by 0
40
+ if (t_01 < 1e-5) {
41
+ t_01 = 1;
42
+ }
43
+ if (t_02 < 1e-5) {
44
+ t_02 = t_01;
45
+ }
46
+ if (t_03 < 1e-5) {
47
+ t_03 = t_02;
48
+ }
49
+
50
+ const t1 = t_01 + t0;
51
+ const t2 = t_02 + t1;
52
+ const t3 = t_03 + t2;
53
+
54
+ /**
55
+ * Interpolation between points 1 and 2
56
+ * @type {number}
57
+ */
58
+ const t = t1 * (1 - f) + t2 * f;
59
+
60
+ /*
61
+ Vector2 A1 = (t1-t)/(t1-t0)*p0 + (t-t0)/(t1-t0)*p1;
62
+ Vector2 A2 = (t2-t)/(t2-t1)*p1 + (t-t1)/(t2-t1)*p2;
63
+ Vector2 A3 = (t3-t)/(t3-t2)*p2 + (t-t2)/(t3-t2)*p3;
64
+
65
+ Vector2 B1 = (t2-t)/(t2-t0)*A1 + (t-t0)/(t2-t0)*A2;
66
+ Vector2 B2 = (t3-t)/(t3-t1)*A2 + (t-t1)/(t3-t1)*A3;
67
+
68
+ Vector2 C = (t2-t)/(t2-t1)*B1 + (t-t1)/(t2-t1)*B2;
69
+ */
70
+
71
+ const d_t1_t0 = t1 - t0;
72
+
73
+ const m_A1_0 = (t1 - t) / d_t1_t0;
74
+ const m_A1_1 = (t - t0) / d_t1_t0;
75
+
76
+ const d_t2_t1 = t2 - t1;
77
+
78
+ const m_A2_0 = (t2 - t) / d_t2_t1;
79
+
80
+ const d_t_t1 = t - t1;
81
+
82
+ const m_A2_1 = d_t_t1 / d_t2_t1;
83
+
84
+ const d_t3_t2 = t3 - t2;
85
+
86
+ const d_t3_t = t3 - t;
87
+
88
+ const m_A3_0 = d_t3_t / d_t3_t2;
89
+ const m_A3_1 = (t - t2) / d_t3_t2;
90
+
91
+ const d_t2_t0 = t2 - t0;
92
+
93
+ const m_B1_0 = (t2 - t) / d_t2_t0;
94
+ const m_B1_1 = (t - t0) / d_t2_t0;
95
+
96
+ const d_t3_t1 = t3 - t1;
97
+
98
+ const m_B2_0 = d_t3_t / d_t3_t1;
99
+ const m_B2_1 = d_t_t1 / d_t3_t1;
100
+
101
+ const m_C_0 = (t2 - t) / d_t2_t1;
102
+ const m_C_1 = d_t_t1 / d_t2_t1;
103
+
104
+ // read vector values for the dimension
105
+ const v0 = p0;
106
+ const v1 = p1;
107
+ const v2 = p2;
108
+ const v3 = p3;
109
+
110
+ // compute resulting value in this dimension
111
+ const A1 = m_A1_0 * v0 + m_A1_1 * v1;
112
+ const A2 = m_A2_0 * v1 + m_A2_1 * v2;
113
+ const A3 = m_A3_0 * v2 + m_A3_1 * v3;
114
+
115
+ const B1 = m_B1_0 * A1 + m_B1_1 * A2;
116
+ const B2 = m_B2_0 * A2 + m_B2_1 * A3;
117
+
118
+ return m_C_0 * B1 + m_C_1 * B2;
119
+
120
+ }
@@ -1,36 +1,34 @@
1
- import Entity from "../ecs/Entity.js";
2
- import { ControlContextState } from "./ControlContextState.js";
3
1
  import { IllegalStateException } from "../../core/fsm/exceptions/IllegalStateException.js";
4
2
  import { SerializationMetadata } from "../ecs/components/SerializationMetadata.js";
3
+ import Entity from "../ecs/Entity.js";
5
4
  import { EntityFlags } from "../ecs/EntityFlags.js";
5
+ import { ControlContextState } from "./ControlContextState.js";
6
6
 
7
7
  export class ControlContext {
8
- constructor() {
9
- /**
10
- * @private
11
- * @type {EntityComponentDataset}
12
- */
13
- this.ecd = null;
8
+ /**
9
+ * @private
10
+ * @type {EntityComponentDataset}
11
+ */
12
+ ecd = null;
14
13
 
15
- /**
16
- * @private
17
- * @type {Entity[]}
18
- */
19
- this.entities = [];
20
-
21
- /**
22
- * @private
23
- * @type {ControlContextState|number}
24
- */
25
- this.state = ControlContextState.Initial;
26
-
27
- /**
28
- * Should entities be made transient or not, transient entities do not get persisted
29
- * @private
30
- * @type {boolean}
31
- */
32
- this.transientEntities = true;
33
- }
14
+ /**
15
+ * @private
16
+ * @type {Entity[]}
17
+ */
18
+ entities = [];
19
+
20
+ /**
21
+ * @private
22
+ * @type {ControlContextState|number}
23
+ */
24
+ state = ControlContextState.Initial;
25
+
26
+ /**
27
+ * Should entities be made transient or not, transient entities do not get persisted
28
+ * @private
29
+ * @type {boolean}
30
+ */
31
+ transientEntities = true;
34
32
 
35
33
  /**
36
34
  *
@@ -2,16 +2,16 @@
2
2
  * Created by Alex on 01/04/2014.
3
3
  */
4
4
 
5
- import {assert} from "../../core/assert.js";
6
- import {array_copy_unique} from "../../core/collection/array/array_copy_unique.js";
5
+ import { assert } from "../../core/assert.js";
6
+ import { array_copy_unique } from "../../core/collection/array/array_copy_unique.js";
7
7
  import Signal from "../../core/events/signal/Signal.js";
8
- import {IllegalStateException} from "../../core/fsm/exceptions/IllegalStateException.js";
9
- import {noop} from "../../core/function/Functions.js";
10
- import {ResourceAccessKind} from "../../core/model/ResourceAccessKind.js";
11
- import {EntityObserver} from "./EntityObserver.js";
12
- import {computeSystemName, System, SystemState} from "./System.js";
13
- import {computeSystemComponentDependencyGraph} from "./system/computeSystemComponentDependencyGraph.js";
14
- import {validateSystem} from "./validateSystem.js";
8
+ import { IllegalStateException } from "../../core/fsm/exceptions/IllegalStateException.js";
9
+ import { noop } from "../../core/function/Functions.js";
10
+ import { ResourceAccessKind } from "../../core/model/ResourceAccessKind.js";
11
+ import { EntityObserver } from "./EntityObserver.js";
12
+ import { computeSystemName, System, SystemState } from "./System.js";
13
+ import { computeSystemComponentDependencyGraph } from "./system/computeSystemComponentDependencyGraph.js";
14
+ import { validateSystem } from "./validateSystem.js";
15
15
 
16
16
  /**
17
17
  *
@@ -63,6 +63,9 @@ export class EntityManager {
63
63
  on = {
64
64
  systemStarted: new Signal(),
65
65
  systemStopped: new Signal(),
66
+ /**
67
+ * @type {Signal<System>}
68
+ */
66
69
  systemAdded: new Signal(),
67
70
  systemRemoved: new Signal(),
68
71
  };