@woosh/meep-engine 2.110.2 → 2.110.5

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 (89) hide show
  1. package/build/meep.cjs +147 -124
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +148 -122
  4. package/package.json +1 -1
  5. package/src/core/events/signal/Signal.d.ts.map +1 -1
  6. package/src/core/events/signal/Signal.js +3 -98
  7. package/src/core/events/signal/dispatchViaProxy.d.ts +7 -0
  8. package/src/core/events/signal/dispatchViaProxy.d.ts.map +1 -0
  9. package/src/core/events/signal/dispatchViaProxy.js +60 -0
  10. package/src/core/events/signal/findSignalHandlerIndexByHandle.d.ts +9 -0
  11. package/src/core/events/signal/findSignalHandlerIndexByHandle.d.ts.map +1 -0
  12. package/src/core/events/signal/findSignalHandlerIndexByHandle.js +26 -0
  13. package/src/core/events/signal/findSignalHandlerIndexByHandleAndContext.d.ts +9 -0
  14. package/src/core/events/signal/findSignalHandlerIndexByHandleAndContext.d.ts.map +1 -0
  15. package/src/core/events/signal/findSignalHandlerIndexByHandleAndContext.js +21 -0
  16. package/src/core/fsm/simple/SimpleStateMachine.d.ts.map +1 -1
  17. package/src/core/fsm/simple/SimpleStateMachine.js +2 -1
  18. package/src/core/geom/3d/normal/octahedron/encode_unit_to_octahedron.d.ts +2 -2
  19. package/src/core/geom/3d/normal/octahedron/encode_unit_to_octahedron.d.ts.map +1 -1
  20. package/src/core/geom/3d/normal/octahedron/encode_unit_to_octahedron.js +1 -1
  21. package/src/core/geom/3d/sphere/sphere_fibonacci_point.d.ts +18 -0
  22. package/src/core/geom/3d/sphere/sphere_fibonacci_point.d.ts.map +1 -0
  23. package/src/core/geom/3d/sphere/sphere_fibonacci_point.js +51 -0
  24. package/src/core/model/object/ObjectPoolFactory.d.ts +17 -10
  25. package/src/core/model/object/ObjectPoolFactory.d.ts.map +1 -1
  26. package/src/core/model/object/ObjectPoolFactory.js +33 -16
  27. package/src/engine/animation/clip/AnimationClip.d.ts.map +1 -1
  28. package/src/engine/animation/clip/AnimationClip.js +4 -0
  29. package/src/engine/animation/clip/AnimationInterpolationKind.d.ts +7 -0
  30. package/src/engine/animation/clip/AnimationInterpolationKind.d.ts.map +1 -0
  31. package/src/engine/animation/clip/AnimationInterpolationKind.js +9 -0
  32. package/src/engine/animation/clip/AnimationTrack.d.ts +12 -0
  33. package/src/engine/animation/clip/AnimationTrack.d.ts.map +1 -1
  34. package/src/engine/animation/clip/AnimationTrack.js +20 -1
  35. package/src/engine/animation/clip/AnimationTrackBinding.d.ts.map +1 -1
  36. package/src/engine/animation/clip/AnimationTrackBinding.js +12 -0
  37. package/src/engine/animation/clip/bind_property_writer.d.ts +9 -0
  38. package/src/engine/animation/clip/bind_property_writer.d.ts.map +1 -0
  39. package/src/engine/animation/clip/bind_property_writer.js +118 -0
  40. package/src/engine/animation/clip/curve_from_track_data.d.ts +12 -0
  41. package/src/engine/animation/clip/curve_from_track_data.d.ts.map +1 -0
  42. package/src/engine/animation/clip/curve_from_track_data.js +27 -0
  43. package/src/engine/animation/clip/curve_from_track_data_cubic_tangents.d.ts +10 -0
  44. package/src/engine/animation/clip/curve_from_track_data_cubic_tangents.d.ts.map +1 -0
  45. package/src/engine/animation/clip/curve_from_track_data_cubic_tangents.js +33 -0
  46. package/src/engine/animation/clip/curve_from_track_data_discrete.d.ts +10 -0
  47. package/src/engine/animation/clip/curve_from_track_data_discrete.d.ts.map +1 -0
  48. package/src/engine/animation/clip/curve_from_track_data_discrete.js +30 -0
  49. package/src/engine/animation/clip/curve_from_track_data_linear.d.ts +10 -0
  50. package/src/engine/animation/clip/curve_from_track_data_linear.d.ts.map +1 -0
  51. package/src/engine/animation/clip/curve_from_track_data_linear.js +25 -0
  52. package/src/engine/animation/clip/ecd_bind_animation_curve.d.ts.map +1 -1
  53. package/src/engine/animation/clip/ecd_bind_animation_curve.js +14 -239
  54. package/src/engine/animation/curve/AnimationCurve.d.ts +17 -17
  55. package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
  56. package/src/engine/animation/curve/AnimationCurve.js +30 -20
  57. package/src/engine/animation/curve/Keyframe.d.ts +5 -0
  58. package/src/engine/animation/curve/Keyframe.d.ts.map +1 -1
  59. package/src/engine/animation/curve/Keyframe.js +6 -0
  60. package/src/engine/animation/curve/binding/BoundValueWriter.d.ts +7 -0
  61. package/src/engine/animation/curve/binding/BoundValueWriter.d.ts.map +1 -1
  62. package/src/engine/animation/curve/binding/BoundValueWriter.js +9 -1
  63. package/src/engine/animation/curve/compute_curve_aabb.d.ts +1 -1
  64. package/src/engine/animation/curve/compute_curve_aabb.js +1 -1
  65. package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
  66. package/src/engine/ecs/EntityComponentDataset.js +4 -3
  67. package/src/engine/ecs/parent/EntityNode.d.ts.map +1 -1
  68. package/src/engine/ecs/parent/EntityNode.js +2 -1
  69. package/src/engine/graphics/geometry/buffered/makeGeometryIndexed.d.ts +2 -1
  70. package/src/engine/graphics/geometry/buffered/makeGeometryIndexed.d.ts.map +1 -1
  71. package/src/engine/graphics/geometry/buffered/makeGeometryIndexed.js +4 -1
  72. package/src/engine/graphics/sh3/gi/material/common.glsl +3 -3
  73. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
  74. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +4 -3
  75. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts +2 -1
  76. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts.map +1 -1
  77. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js +6 -30
  78. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map_fibonacci.d.ts +13 -0
  79. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map_fibonacci.d.ts.map +1 -0
  80. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map_fibonacci.js +163 -0
  81. package/src/engine/graphics/sh3/prototypeSH3Probe.js +2 -2
  82. package/src/engine/graphics/trail/x/RibbonXMaterialSpec.d.ts.map +1 -1
  83. package/src/engine/graphics/trail/x/RibbonXMaterialSpec.js +10 -2
  84. package/src/engine/graphics/trail/x/RibbonXPlugin.d.ts.map +1 -1
  85. package/src/engine/graphics/trail/x/RibbonXPlugin.js +7 -5
  86. package/src/engine/simulation/Ticker.d.ts +9 -0
  87. package/src/core/model/object/SimpleObjectPoolFactory.d.ts +0 -25
  88. package/src/core/model/object/SimpleObjectPoolFactory.d.ts.map +0 -1
  89. package/src/core/model/object/SimpleObjectPoolFactory.js +0 -42
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Generate a spherical fibonacci point
3
+ *
4
+ * http://lgdv.cs.fau.de/publications/publication/Pub.2015.tech.IMMD.IMMD9.spheri/
5
+ *
6
+ * To generate a nearly uniform point distribution on the unit sphere of size N, do
7
+ * for (const i = 0.0; i < N; i += 1.0) {
8
+ * sphere_fibonacci_point(points, i*3, i, N);
9
+ * }
10
+ *
11
+ * The points go from z = +1 down to z = -1 in a spiral. To generate samples on the +z hemisphere, just stop before i > N/2.
12
+ * @param {number[]|Float32Array} output
13
+ * @param {number} output_offset
14
+ * @param {number} i index of a point, from 0 to n-1
15
+ * @param {number} n total number of points
16
+ */
17
+ export function sphere_fibonacci_point(output: number[] | Float32Array, output_offset: number, i: number, n: number): void;
18
+ //# sourceMappingURL=sphere_fibonacci_point.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sphere_fibonacci_point.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/sphere/sphere_fibonacci_point.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;GAeG;AACH,+CALW,MAAM,EAAE,GAAC,YAAY,iBACrB,MAAM,KACN,MAAM,KACN,MAAM,QAoBhB"}
@@ -0,0 +1,51 @@
1
+ import { assert } from "../../../assert.js";
2
+ import { clamp01 } from "../../../math/clamp01.js";
3
+
4
+ /**
5
+ *
6
+ * @param {number} a
7
+ * @param {number} b
8
+ * @return {number}
9
+ */
10
+ function multiply_add_fraction(a, b) {
11
+ const ab = a * b;
12
+ return ab - Math.floor(ab);
13
+ }
14
+
15
+ const PHI = Math.sqrt(5) * 0.5 + 0.5;
16
+
17
+ /**
18
+ * Generate a spherical fibonacci point
19
+ *
20
+ * http://lgdv.cs.fau.de/publications/publication/Pub.2015.tech.IMMD.IMMD9.spheri/
21
+ *
22
+ * To generate a nearly uniform point distribution on the unit sphere of size N, do
23
+ * for (const i = 0.0; i < N; i += 1.0) {
24
+ * sphere_fibonacci_point(points, i*3, i, N);
25
+ * }
26
+ *
27
+ * The points go from z = +1 down to z = -1 in a spiral. To generate samples on the +z hemisphere, just stop before i > N/2.
28
+ * @param {number[]|Float32Array} output
29
+ * @param {number} output_offset
30
+ * @param {number} i index of a point, from 0 to n-1
31
+ * @param {number} n total number of points
32
+ */
33
+ export function sphere_fibonacci_point(output, output_offset, i, n) {
34
+ assert.isNonNegativeInteger(i, 'i');
35
+ assert.isNonNegativeInteger(n, 'n');
36
+ assert.isNonNegativeInteger(output_offset, 'output_offset');
37
+
38
+ const phi = 2 * Math.PI * multiply_add_fraction(i, PHI - 1);
39
+
40
+ const cosTheta = 1.0 - (2.0 * i + 1.0) * (1.0 / n);
41
+
42
+ const sinTheta = Math.sqrt(clamp01(1.0 - cosTheta * cosTheta));
43
+
44
+ const x = Math.cos(phi) * sinTheta;
45
+ const y = Math.sin(phi) * sinTheta;
46
+ const z = cosTheta;
47
+
48
+ output[output_offset] = x;
49
+ output[output_offset + 1] = y;
50
+ output[output_offset + 2] = z;
51
+ }
@@ -1,4 +1,6 @@
1
1
  /**
2
+ * Object Pool pattern implementation.
3
+ * Reuse objects instead of relying on garbage collector. Useful in cases where creating or destroying an object is costly, and objects are relatively short-lived
2
4
  * @template T
3
5
  */
4
6
  export class ObjectPoolFactory<T> {
@@ -8,6 +10,15 @@ export class ObjectPoolFactory<T> {
8
10
  * @param {function(T)} resetter
9
11
  */
10
12
  constructor(creator: () => T, destroyer?: (arg0: T) => any, resetter?: (arg0: T) => any);
13
+ /**
14
+ * @private
15
+ * @type {Array<T>}
16
+ */
17
+ private pool;
18
+ /**
19
+ * @type {number}
20
+ */
21
+ maxSize: number;
11
22
  /**
12
23
  * @private
13
24
  * @type {function(): T}
@@ -23,25 +34,21 @@ export class ObjectPoolFactory<T> {
23
34
  * @type {function(T)}
24
35
  */
25
36
  private resetter;
26
- /**
27
- * @private
28
- * @type {Array<T>}
29
- */
30
- private pool;
31
- /**
32
- * @type {number}
33
- */
34
- maxSize: number;
35
37
  /**
36
38
  *
37
39
  * @returns {T}
38
40
  */
39
- create(): T;
41
+ get(): T;
40
42
  /**
41
43
  *
42
44
  * @param {T} object
43
45
  * @returns {boolean} true if object was added back to the pool, false if pool was full and object was destroyed instead
44
46
  */
45
47
  release(object: T): boolean;
48
+ /**
49
+ * @deprecated use `get` instead
50
+ * @type {function(): T}
51
+ */
52
+ create: () => T;
46
53
  }
47
54
  //# sourceMappingURL=ObjectPoolFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ObjectPoolFactory.d.ts","sourceRoot":"","sources":["../../../../../src/core/model/object/ObjectPoolFactory.js"],"names":[],"mappings":"AAIA;;GAEG;AACH;IACI;;;;OAIG;IACH,2BAJsB,CAAC,qBACH,CAAC,4BACD,CAAC,UAqCpB;IA1BG;;;OAGG;IACH,gBAAsB;IACtB;;;OAGG;IACH,kBAA0B;IAC1B;;;OAGG;IACH,iBAAwB;IAExB;;;OAGG;IACH,aAAc;IAEd;;OAEG;IACH,SAFU,MAAM,CAEE;IAGtB;;;OAGG;IACH,UAFa,CAAC,CAwBb;IAED;;;;OAIG;IACH,gBAHW,CAAC,GACC,OAAO,CAqBnB;CACJ"}
1
+ {"version":3,"file":"ObjectPoolFactory.d.ts","sourceRoot":"","sources":["../../../../../src/core/model/object/ObjectPoolFactory.js"],"names":[],"mappings":"AAIA;;;;GAIG;AACH;IAYI;;;;OAIG;IACH,2BAJsB,CAAC,qBACH,CAAC,4BACD,CAAC,UA6BpB;IA3CD;;;OAGG;IACH,aAAU;IAEV;;OAEG;IACH,SAFU,MAAM,CAEF;IAgBV;;;OAGG;IACH,gBAAsB;IAEtB;;;OAGG;IACH,kBAA0B;IAE1B;;;OAGG;IACH,iBAAwB;IAI5B;;;OAGG;IACH,OAFa,CAAC,CA2Bb;IAED;;;;OAIG;IACH,gBAHW,CAAC,GACC,OAAO,CAuBnB;IAIL;;;OAGG;IACH,cAFsB,CAAC,CAEW;CAPjC"}
@@ -3,9 +3,22 @@ import { assert } from "../../assert.js";
3
3
  import { noop } from "../../function/noop.js";
4
4
 
5
5
  /**
6
+ * Object Pool pattern implementation.
7
+ * Reuse objects instead of relying on garbage collector. Useful in cases where creating or destroying an object is costly, and objects are relatively short-lived
6
8
  * @template T
7
9
  */
8
10
  export class ObjectPoolFactory {
11
+ /**
12
+ * @private
13
+ * @type {Array<T>}
14
+ */
15
+ pool = [];
16
+
17
+ /**
18
+ * @type {number}
19
+ */
20
+ maxSize = 256;
21
+
9
22
  /**
10
23
  * @param {function():T} creator
11
24
  * @param {function(T)} destroyer
@@ -25,36 +38,31 @@ export class ObjectPoolFactory {
25
38
  * @type {function(): T}
26
39
  */
27
40
  this.creator = creator;
41
+
28
42
  /**
29
43
  * @private
30
44
  * @type {function(T)}
31
45
  */
32
46
  this.destroyer = destroyer;
47
+
33
48
  /**
34
49
  * @private
35
50
  * @type {function(T)}
36
51
  */
37
52
  this.resetter = resetter;
38
53
 
39
- /**
40
- * @private
41
- * @type {Array<T>}
42
- */
43
- this.pool = [];
44
-
45
- /**
46
- * @type {number}
47
- */
48
- this.maxSize = 256;
49
54
  }
50
55
 
51
56
  /**
52
57
  *
53
58
  * @returns {T}
54
59
  */
55
- create() {
56
- if (this.pool.length > 0) {
57
- const oldInstance = this.pool.pop();
60
+ get() {
61
+ const pool = this.pool;
62
+
63
+ if (pool.length > 0) {
64
+
65
+ const oldInstance = pool.pop();
58
66
 
59
67
  //reset the object
60
68
  this.resetter(oldInstance);
@@ -85,9 +93,11 @@ export class ObjectPoolFactory {
85
93
  assert.notNull(object, 'object');
86
94
  assert.defined(object, 'object');
87
95
 
88
- assert.arrayHasNo(this.pool, object, `Pool already contains object that is being attempted to be release`);
96
+ const pool = this.pool;
89
97
 
90
- if (this.pool.length >= this.maxSize) {
98
+ assert.arrayHasNo(pool, object, `Pool already contains object that is being attempted to be release`);
99
+
100
+ if (pool.length >= this.maxSize) {
91
101
  //pool is too large, destroy and discard the object
92
102
  if (this.destroyer !== noop) {
93
103
  this.destroyer(object);
@@ -97,8 +107,15 @@ export class ObjectPoolFactory {
97
107
  }
98
108
 
99
109
  //add it to the pool
100
- this.pool.push(object);
110
+ pool.push(object);
101
111
 
102
112
  return true;
103
113
  }
104
114
  }
115
+
116
+
117
+ /**
118
+ * @deprecated use `get` instead
119
+ * @type {function(): T}
120
+ */
121
+ ObjectPoolFactory.prototype.create = ObjectPoolFactory.prototype.get
@@ -1 +1 @@
1
- {"version":3,"file":"AnimationClip.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/AnimationClip.js"],"names":[],"mappings":"AAEA;IACI,aAAS;IACT;;;OAGG;IACH,QAFU,gBAAgB,CAEf;IAEX,uBAWC;CACJ"}
1
+ {"version":3,"file":"AnimationClip.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/AnimationClip.js"],"names":[],"mappings":"AAEA;IACI,aAAS;IACT;;;OAGG;IACH,QAFU,gBAAgB,CAEf;IAEX;;;OAGG;IACH,uBAWC;CACJ"}
@@ -8,6 +8,10 @@ export class AnimationClip {
8
8
  */
9
9
  tracks = []
10
10
 
11
+ /**
12
+ *
13
+ * @return {number}
14
+ */
11
15
  get duration() {
12
16
  let r = 0;
13
17
 
@@ -0,0 +1,7 @@
1
+ export type AnimationInterpolationKind = number;
2
+ export namespace AnimationInterpolationKind {
3
+ let Discrete: number;
4
+ let Linear: number;
5
+ let CubicTangents: number;
6
+ }
7
+ //# sourceMappingURL=AnimationInterpolationKind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnimationInterpolationKind.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/AnimationInterpolationKind.js"],"names":[],"mappings":"yCAEU,MAAM"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @enum {number}
4
+ */
5
+ export const AnimationInterpolationKind = {
6
+ Discrete: 0,
7
+ Linear: 1,
8
+ CubicTangents: 2
9
+ };
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Represents animation of a meaningful multi-variate thing, such as 3d vector or single scalar
3
+ */
1
4
  export class AnimationTrack {
2
5
  /**
3
6
  *
@@ -33,6 +36,10 @@ export class AnimationTrack {
33
36
  * @return {number}
34
37
  */
35
38
  get duration(): number;
39
+ /**
40
+ *
41
+ * @return {number}
42
+ */
36
43
  get curveCount(): number;
37
44
  /**
38
45
  *
@@ -41,5 +48,10 @@ export class AnimationTrack {
41
48
  * @param {number} time
42
49
  */
43
50
  sample(output: number[] | Float32Array | Float64Array, output_offset: number, time: number): void;
51
+ /**
52
+ * @readonly
53
+ * @type {boolean}
54
+ */
55
+ readonly isAnimationTrack: boolean;
44
56
  }
45
57
  //# sourceMappingURL=AnimationTrack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AnimationTrack.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/AnimationTrack.js"],"names":[],"mappings":"AAEA;IAkEI;;;;;OAKG;IACH,qBAJW,gBAAgB,SAChB,MAAM,GACL,cAAc,CASzB;IA9ED;;;OAGG;IACH,MAFU,MAAM,CAEP;IAET;;;OAGG;IACH,MAFU,MAAM,EAAE,CAET;IAET;;;OAGG;IACH,QAFU,gBAAgB,CAEf;IAEX;;;;;OAKG;IACH,MAFU,MAAM,CAEP;IAET;;;OAGG;IACH,uBAYC;IAED,yBAEC;IAED;;;;;OAKG;IACH,eAJW,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,iBAClC,MAAM,QACN,MAAM,QAWhB;CAgBJ"}
1
+ {"version":3,"file":"AnimationTrack.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/AnimationTrack.js"],"names":[],"mappings":"AAGA;;GAEG;AACH;IAwEI;;;;;OAKG;IACH,qBAJW,gBAAgB,SAChB,MAAM,GACL,cAAc,CAYzB;IAvFD;;;OAGG;IACH,MAFU,MAAM,CAEP;IAET;;;OAGG;IACH,MAFU,MAAM,EAAE,CAET;IAET;;;OAGG;IACH,QAFU,gBAAgB,CAEf;IAEX;;;;;OAKG;IACH,MAFU,MAAM,CAEP;IAET;;;OAGG;IACH,uBAYC;IAED;;;OAGG;IACH,yBAEC;IAED;;;;;OAKG;IACH,eAJW,MAAM,EAAE,GAAC,YAAY,GAAC,YAAY,iBAClC,MAAM,QACN,MAAM,QAahB;IAqBL;;;OAGG;IACH,2BAFU,OAAO,CAEwB;CANxC"}
@@ -1,5 +1,9 @@
1
+ import { assert } from "../../../core/assert.js";
1
2
  import { max2 } from "../../../core/math/max2.js";
2
3
 
4
+ /**
5
+ * Represents animation of a meaningful multi-variate thing, such as 3d vector or single scalar
6
+ */
3
7
  export class AnimationTrack {
4
8
  /**
5
9
  * Human-readable label
@@ -45,6 +49,10 @@ export class AnimationTrack {
45
49
  return r;
46
50
  }
47
51
 
52
+ /**
53
+ *
54
+ * @return {number}
55
+ */
48
56
  get curveCount() {
49
57
  return this.curves.length;
50
58
  }
@@ -59,6 +67,8 @@ export class AnimationTrack {
59
67
  const curves = this.curves;
60
68
  const curve_count = curves.length;
61
69
 
70
+ assert.greaterThanOrEqual(output.length, output_offset + curve_count, 'output overflow');
71
+
62
72
  for (let i = 0; i < curve_count; i++) {
63
73
  const curve = curves[i];
64
74
 
@@ -73,6 +83,9 @@ export class AnimationTrack {
73
83
  * @return {AnimationTrack}
74
84
  */
75
85
  static from(curves = [], name = "") {
86
+ assert.isString(name, 'name');
87
+ assert.isArray(curves, 'curves');
88
+
76
89
  const r = new AnimationTrack();
77
90
 
78
91
  r.curves = curves;
@@ -80,4 +93,10 @@ export class AnimationTrack {
80
93
 
81
94
  return r;
82
95
  }
83
- }
96
+ }
97
+
98
+ /**
99
+ * @readonly
100
+ * @type {boolean}
101
+ */
102
+ AnimationTrack.prototype.isAnimationTrack = true;
@@ -1 +1 @@
1
- {"version":3,"file":"AnimationTrackBinding.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/AnimationTrackBinding.js"],"names":[],"mappings":"AAEA;IAaI;;;;;OAKG;IACH,8DAFa,qBAAqB,CAWjC;IA3BD;;;OAGG;IACH,QAFU,mBAAiB,IAAI,CAElB;IAEb;;;OAGG;IACH,sBAAY;IAmBZ;;;OAGG;IACH,cAFW,MAAM,QAMhB;CACJ"}
1
+ {"version":3,"file":"AnimationTrackBinding.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/AnimationTrackBinding.js"],"names":[],"mappings":"AAIA;IAaI;;;;;OAKG;IACH,8DAFa,qBAAqB,CAqBjC;IArCD;;;OAGG;IACH,QAFU,mBAAiB,IAAI,CAElB;IAEb;;;OAGG;IACH,sBAAY;IA6BZ;;;OAGG;IACH,cAFW,MAAM,QAMhB;CACJ"}
@@ -1,3 +1,5 @@
1
+ import { assert } from "../../../core/assert.js";
2
+
1
3
  const sample = new Float64Array(1024);
2
4
 
3
5
  export class AnimationTrackBinding {
@@ -20,6 +22,16 @@ export class AnimationTrackBinding {
20
22
  * @returns {AnimationTrackBinding}
21
23
  */
22
24
  static from(writer, track) {
25
+ assert.defined(writer,'writer');
26
+ assert.isObject(writer,'writer');
27
+ assert.notNull(writer,'writer');
28
+ assert.equal(writer.isBoundValueWriter,true,'writer.isBoundValueWriter !== true');
29
+
30
+ assert.defined(track,'track');
31
+ assert.isObject(track,'track');
32
+ assert.notNull(track,'track');
33
+ assert.equal(track.isAnimationTrack,true,'track.isAnimationTrack !== true');
34
+
23
35
 
24
36
  const r = new AnimationTrackBinding();
25
37
 
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {EntityNode} node
4
+ * @param {string} path
5
+ * @returns {BoundValueWriter}
6
+ */
7
+ export function bind_property_writer(node: EntityNode, path: string): BoundValueWriter;
8
+ import { BoundValueWriter } from "../curve/binding/BoundValueWriter.js";
9
+ //# sourceMappingURL=bind_property_writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bind_property_writer.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/bind_property_writer.js"],"names":[],"mappings":"AAqFA;;;;;GAKG;AACH,6DAHW,MAAM,GACJ,gBAAgB,CA4B5B;iCAnHgC,sCAAsC"}
@@ -0,0 +1,118 @@
1
+ import Name from "../../ecs/name/Name.js";
2
+ import { BoundQuaternionWriter } from "../curve/binding/BoundQuaternionWriter.js";
3
+ import { BoundValueWriter } from "../curve/binding/BoundValueWriter.js";
4
+ import { BoundVector3Writer } from "../curve/binding/BoundVector3Writer.js";
5
+
6
+ /**
7
+ *
8
+ * @param {EntityNode} node
9
+ * @returns {string|undefined}
10
+ */
11
+ function get_node_name(node) {
12
+ /**
13
+ * @type {Name}
14
+ */
15
+ const name = node.entity.getComponent(Name);
16
+
17
+ if (name === null) {
18
+ return undefined;
19
+ }
20
+
21
+ return name.getValue();
22
+ }
23
+
24
+ /**
25
+ * Following THREE.js PropertyBinding.findNode implementation
26
+ * @param {EntityNode} root
27
+ * @param {string} nodeName
28
+ * @returns {EntityNode|undefined}
29
+ */
30
+ function find_node(root, nodeName) {
31
+
32
+ const root_name = get_node_name(root);
33
+
34
+ if (root_name === nodeName) {
35
+ return root;
36
+ }
37
+
38
+ // search into node subtree.
39
+ const children = root.children;
40
+
41
+ const child_count = children.length;
42
+
43
+
44
+ for (let j = 0; j < child_count; j++) {
45
+ /**
46
+ * @type {EntityNode}
47
+ */
48
+ const child = children[j];
49
+
50
+ const subtree_result = find_node(child, nodeName);
51
+
52
+ if (subtree_result !== undefined) {
53
+ return subtree_result;
54
+ }
55
+ }
56
+ }
57
+
58
+ /**
59
+ *
60
+ * @param {EntityNode} root
61
+ * @param {string[]} path_parts
62
+ */
63
+ function entity_node_resolve_path(root, path_parts) {
64
+
65
+ let node = root;
66
+
67
+ const part_count = path_parts.length;
68
+ for (let i = 0; i < part_count; i++) {
69
+
70
+ const part = path_parts[i];
71
+
72
+ const sub_node = find_node(node, part);
73
+
74
+ if (sub_node === undefined) {
75
+
76
+ throw new Error(`Child '${part}' not found, at index ${i} of [${path_parts.join(', ')}]. Valid names at this level: [${node.children.map(get_node_name)}]`);
77
+
78
+ }
79
+
80
+ node = sub_node;
81
+ }
82
+
83
+ return node;
84
+ }
85
+
86
+ /**
87
+ *
88
+ * @param {EntityNode} node
89
+ * @param {string} path
90
+ * @returns {BoundValueWriter}
91
+ */
92
+ export function bind_property_writer(node, path) {
93
+ const path_parts = path.split('.');
94
+
95
+ const property_name = path_parts[path_parts.length - 1];
96
+
97
+ const parent = entity_node_resolve_path(node, path_parts.slice(0, path_parts.length - 1));
98
+
99
+ let writer;
100
+
101
+ switch (property_name) {
102
+ case "position":
103
+ writer = new BoundVector3Writer(parent.transform.position);
104
+ break;
105
+ case "quaternion":
106
+ writer = new BoundQuaternionWriter(parent.transform.rotation);
107
+ break;
108
+ case "scale":
109
+ writer = new BoundVector3Writer(parent.transform.scale);
110
+ break;
111
+ default:
112
+ console.log(`Unsupported property name: ${property_name}`);
113
+ // NO-OP
114
+ writer = new BoundValueWriter();
115
+ }
116
+
117
+ return writer;
118
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ *
3
+ * @param {AnimationCurve} curve
4
+ * @param {AnimationInterpolationKind} type
5
+ * @param {number[]|Float32Array} values
6
+ * @param {number[]|Float32Array} times
7
+ * @param {number} component_count
8
+ * @param {number} component_index
9
+ */
10
+ export function curve_from_track_data(curve: AnimationCurve, type: AnimationInterpolationKind, values: number[] | Float32Array, times: number[] | Float32Array, component_count: number, component_index: number): void;
11
+ import { AnimationInterpolationKind } from "./AnimationInterpolationKind.js";
12
+ //# sourceMappingURL=curve_from_track_data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curve_from_track_data.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/curve_from_track_data.js"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,mEANW,0BAA0B,UAC1B,MAAM,EAAE,GAAC,YAAY,SACrB,MAAM,EAAE,GAAC,YAAY,mBACrB,MAAM,mBACN,MAAM,QAchB;2CA1B0C,iCAAiC"}
@@ -0,0 +1,27 @@
1
+ import { AnimationInterpolationKind } from "./AnimationInterpolationKind.js";
2
+ import { curve_from_track_data_cubic_tangents } from "./curve_from_track_data_cubic_tangents.js";
3
+ import { curve_from_track_data_discrete } from "./curve_from_track_data_discrete.js";
4
+ import { curve_from_track_data_linear } from "./curve_from_track_data_linear.js";
5
+
6
+ /**
7
+ *
8
+ * @param {AnimationCurve} curve
9
+ * @param {AnimationInterpolationKind} type
10
+ * @param {number[]|Float32Array} values
11
+ * @param {number[]|Float32Array} times
12
+ * @param {number} component_count
13
+ * @param {number} component_index
14
+ */
15
+ export function curve_from_track_data(curve, type, values, times, component_count, component_index) {
16
+ switch (type) {
17
+ case AnimationInterpolationKind.Discrete:
18
+ return curve_from_track_data_discrete(curve, values, times, component_count, component_index);
19
+ case AnimationInterpolationKind.Linear:
20
+ return curve_from_track_data_linear(curve, values, times, component_count, component_index);
21
+ case AnimationInterpolationKind.CubicTangents:
22
+ return curve_from_track_data_cubic_tangents(curve, values, times, component_count, component_index);
23
+ default:
24
+ throw new Error(`Unsupported type '${type}'`);
25
+ }
26
+
27
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {AnimationCurve} curve
4
+ * @param {number[]} values
5
+ * @param {number[]} times
6
+ * @param {number} component_count
7
+ * @param {number} component_index
8
+ */
9
+ export function curve_from_track_data_cubic_tangents(curve: AnimationCurve, values: number[], times: number[], component_count: number, component_index: number): void;
10
+ //# sourceMappingURL=curve_from_track_data_cubic_tangents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curve_from_track_data_cubic_tangents.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/curve_from_track_data_cubic_tangents.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,oFALW,MAAM,EAAE,SACR,MAAM,EAAE,mBACR,MAAM,mBACN,MAAM,QAwBhB"}
@@ -0,0 +1,33 @@
1
+ import { Keyframe } from "../curve/Keyframe.js";
2
+
3
+ /**
4
+ *
5
+ * @param {AnimationCurve} curve
6
+ * @param {number[]} values
7
+ * @param {number[]} times
8
+ * @param {number} component_count
9
+ * @param {number} component_index
10
+ */
11
+ export function curve_from_track_data_cubic_tangents(curve, values, times, component_count, component_index) {
12
+
13
+ const key_count = times.length;
14
+
15
+ for (let k = 0; k < key_count; k++) {
16
+ const component_position = k * component_count;
17
+
18
+ // 3 corresponds to 3 parts of a keyframe: inTangent, value, outTangent
19
+ const base_offset = 3 * component_position;
20
+
21
+ // Layout of keyframe output values for CUBICSPLINE animations:
22
+ // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
23
+
24
+ const inTangent = values[base_offset + component_index];
25
+ const value = values[base_offset + component_count + component_index];
26
+ const outTangent = values[base_offset + component_count * 2 + component_index];
27
+
28
+ const time = times[k];
29
+
30
+ curve.add(Keyframe.from(time, value, inTangent, outTangent));
31
+ }
32
+
33
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ *
3
+ * @param {AnimationCurve} curve
4
+ * @param {number[]} values
5
+ * @param {number[]} times
6
+ * @param {number} component_count
7
+ * @param {number} component_index
8
+ */
9
+ export function curve_from_track_data_discrete(curve: AnimationCurve, values: number[], times: number[], component_count: number, component_index: number): void;
10
+ //# sourceMappingURL=curve_from_track_data_discrete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curve_from_track_data_discrete.d.ts","sourceRoot":"","sources":["../../../../../src/engine/animation/clip/curve_from_track_data_discrete.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,8EALW,MAAM,EAAE,SACR,MAAM,EAAE,mBACR,MAAM,mBACN,MAAM,QAqBhB"}
@@ -0,0 +1,30 @@
1
+ import { Keyframe } from "../curve/Keyframe.js";
2
+
3
+ /**
4
+ *
5
+ * @param {AnimationCurve} curve
6
+ * @param {number[]} values
7
+ * @param {number[]} times
8
+ * @param {number} component_count
9
+ * @param {number} component_index
10
+ */
11
+ export function curve_from_track_data_discrete(curve, values, times, component_count, component_index) {
12
+
13
+ const key_count = times.length;
14
+
15
+ for (let k = 0; k < key_count; k++) {
16
+ const value = values[k * component_count + component_index];
17
+ const time = times[k];
18
+
19
+ curve.add(Keyframe.from(time, value));
20
+ }
21
+
22
+ const keys = curve.keys;
23
+
24
+ for (let i = key_count - 1; i > 0; i--) {
25
+ const key = keys[i];
26
+ const prev = keys[i - 1];
27
+
28
+ keys.splice(i, 0, Keyframe.from(key.time, prev.value));
29
+ }
30
+ }