@woosh/meep-engine 2.110.8 → 2.110.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 (175) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +93 -106
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +93 -106
  5. package/editor/tools/v2/TransformControls.js +11 -6
  6. package/package.json +2 -1
  7. package/src/core/UUID.d.ts +3 -0
  8. package/src/core/UUID.d.ts.map +1 -1
  9. package/src/core/UUID.js +9 -7
  10. package/src/core/collection/array/arraySetDiff.d.ts.map +1 -1
  11. package/src/core/collection/array/arraySetDiff.js +0 -1
  12. package/src/core/collection/array/binarySearchHighIndex.d.ts.map +1 -1
  13. package/src/core/collection/array/binarySearchHighIndex.js +7 -1
  14. package/src/core/collection/array/computeHashArray.d.ts.map +1 -1
  15. package/src/core/collection/array/computeHashArray.js +3 -2
  16. package/src/core/collection/array/fastArrayEquals.d.ts +1 -0
  17. package/src/core/collection/array/fastArrayEquals.d.ts.map +1 -1
  18. package/src/core/collection/array/fastArrayEquals.js +1 -0
  19. package/src/core/collection/array/isArrayEqual.d.ts.map +1 -1
  20. package/src/core/collection/array/isArrayEqual.js +9 -12
  21. package/src/core/collection/array/isArrayEqual.spec.d.ts +2 -0
  22. package/src/core/collection/array/isArrayEqual.spec.d.ts.map +1 -0
  23. package/src/core/collection/array/isArrayEqual.spec.js +25 -0
  24. package/src/core/collection/array/typed/is_typed_array_equals.d.ts.map +1 -1
  25. package/src/core/collection/array/typed/is_typed_array_equals.js +1 -0
  26. package/src/core/function/makeSequenceLoop.d.ts.map +1 -0
  27. package/src/core/geom/3d/shape/AbstractShape3D.d.ts.map +1 -1
  28. package/src/core/geom/3d/shape/AbstractShape3D.js +14 -0
  29. package/src/core/geom/3d/shape/PointShape3D.d.ts +9 -0
  30. package/src/core/geom/3d/shape/PointShape3D.d.ts.map +1 -0
  31. package/src/core/geom/3d/shape/PointShape3D.js +14 -0
  32. package/src/core/geom/3d/shape/TransformedShape3D.d.ts.map +1 -1
  33. package/src/core/geom/3d/shape/TransformedShape3D.js +26 -8
  34. package/src/core/geom/3d/shape/UnionShape3D.d.ts.map +1 -1
  35. package/src/core/geom/3d/shape/UnionShape3D.js +33 -4
  36. package/src/core/geom/3d/shape/UnitCubeShape3D.d.ts.map +1 -1
  37. package/src/core/geom/3d/shape/UnitCubeShape3D.js +13 -6
  38. package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts.map +1 -1
  39. package/src/core/geom/3d/shape/UnitSphereShape3D.js +10 -0
  40. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +15 -8
  41. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  42. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +33 -9
  43. package/src/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.d.ts +1 -1
  44. package/src/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.d.ts.map +1 -1
  45. package/src/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js +7 -7
  46. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.spec.d.ts +2 -0
  47. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.spec.d.ts.map +1 -0
  48. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.spec.js +38 -0
  49. package/src/core/geom/3d/v3_compute_triangle_normal.js +1 -1
  50. package/src/core/geom/3d/v3_negate_array.d.ts +9 -0
  51. package/src/core/geom/3d/v3_negate_array.d.ts.map +1 -0
  52. package/src/core/geom/3d/v3_negate_array.js +16 -0
  53. package/src/core/geom/Quaternion.d.ts.map +1 -1
  54. package/src/core/geom/Quaternion.js +30 -77
  55. package/src/core/geom/Vector3.d.ts +4 -0
  56. package/src/core/geom/Vector3.js +4 -4
  57. package/src/core/geom/vec3/v3_cross_array.d.ts +11 -0
  58. package/src/core/geom/vec3/v3_cross_array.d.ts.map +1 -0
  59. package/src/core/geom/vec3/v3_cross_array.js +31 -0
  60. package/src/core/geom/vec3/v3_displace_in_direction.js +3 -2
  61. package/src/core/geom/vec3/v3_displace_in_direction_array.d.ts +12 -0
  62. package/src/core/geom/vec3/v3_displace_in_direction_array.d.ts.map +1 -0
  63. package/src/core/geom/vec3/v3_displace_in_direction_array.js +22 -0
  64. package/src/core/geom/vec3/v3_dot_array_array.d.ts.map +1 -1
  65. package/src/core/geom/vec3/v3_dot_array_array.js +4 -1
  66. package/src/core/geom/vec3/v3_normalize_array.d.ts +3 -3
  67. package/src/core/geom/vec3/v3_normalize_array.d.ts.map +1 -1
  68. package/src/core/geom/vec3/v3_normalize_array.js +3 -3
  69. package/src/core/math/copysign.d.ts +1 -1
  70. package/src/core/math/copysign.js +1 -1
  71. package/src/core/math/epsilonEquals.d.ts.map +1 -1
  72. package/src/core/math/epsilonEquals.js +3 -2
  73. package/src/core/math/linalg/README.md +1 -1
  74. package/src/core/math/random/randomGaussian.spec.js +1 -1
  75. package/src/core/math/spline/spline_hermite3.d.ts +1 -1
  76. package/src/core/math/spline/spline_hermite3.js +1 -1
  77. package/src/core/process/delay.d.ts +6 -1
  78. package/src/core/process/delay.d.ts.map +1 -1
  79. package/src/core/process/delay.js +6 -1
  80. package/src/core/process/undo/Mark.d.ts +5 -5
  81. package/src/core/process/undo/Mark.d.ts.map +1 -1
  82. package/src/core/process/undo/Mark.js +6 -5
  83. package/src/core/process/worker/WorkerBuilder.d.ts +13 -2
  84. package/src/core/process/worker/WorkerBuilder.d.ts.map +1 -1
  85. package/src/core/process/worker/WorkerBuilder.js +8 -0
  86. package/src/core/process/worker/WorkerProxy.d.ts +16 -6
  87. package/src/core/process/worker/WorkerProxy.d.ts.map +1 -1
  88. package/src/core/process/worker/WorkerProxy.js +24 -5
  89. package/src/engine/EngineHarness.d.ts +7 -1
  90. package/src/engine/EngineHarness.d.ts.map +1 -1
  91. package/src/engine/EngineHarness.js +12 -1
  92. package/src/engine/animation/clip/AnimationTrack.d.ts.map +1 -1
  93. package/src/engine/animation/clip/AnimationTrack.js +3 -0
  94. package/src/engine/animation/clip/bind_property_writer.d.ts +2 -2
  95. package/src/engine/animation/clip/bind_property_writer.d.ts.map +1 -1
  96. package/src/engine/animation/clip/bind_property_writer.js +22 -13
  97. package/src/engine/animation/clip/curve_from_track_data.d.ts.map +1 -1
  98. package/src/engine/animation/clip/curve_from_track_data.js +9 -1
  99. package/src/engine/animation/clip/ecd_bind_animation_curve.d.ts.map +1 -1
  100. package/src/engine/animation/clip/ecd_bind_animation_curve.js +6 -5
  101. package/src/engine/animation/curve/AnimationCurve.d.ts +21 -0
  102. package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
  103. package/src/engine/animation/curve/AnimationCurve.js +43 -15
  104. package/src/engine/animation/curve/AnimationCurve.spec.js +67 -0
  105. package/src/engine/animation/curve/Keyframe.d.ts +24 -3
  106. package/src/engine/animation/curve/Keyframe.d.ts.map +1 -1
  107. package/src/engine/animation/curve/Keyframe.js +49 -3
  108. package/src/engine/animation/curve/Keyframe.spec.js +11 -0
  109. package/src/engine/animation/curve/animation_curve_compute_aabb.d.ts +7 -0
  110. package/src/engine/animation/curve/animation_curve_compute_aabb.d.ts.map +1 -0
  111. package/src/engine/animation/curve/{compute_curve_aabb.js → animation_curve_compute_aabb.js} +1 -1
  112. package/src/engine/animation/curve/animation_curve_optimize.d.ts +8 -0
  113. package/src/engine/animation/curve/animation_curve_optimize.d.ts.map +1 -0
  114. package/src/engine/animation/curve/animation_curve_optimize.js +89 -0
  115. package/src/engine/animation/curve/animation_curve_optimize.spec.d.ts +2 -0
  116. package/src/engine/animation/curve/animation_curve_optimize.spec.d.ts.map +1 -0
  117. package/src/engine/animation/curve/animation_curve_optimize.spec.js +50 -0
  118. package/src/engine/animation/curve/draw/build_curve_editor.js +2 -2
  119. package/src/engine/animation/curve/evaluate_two_key_curve.d.ts +9 -0
  120. package/src/engine/animation/curve/evaluate_two_key_curve.d.ts.map +1 -0
  121. package/src/engine/animation/curve/evaluate_two_key_curve.js +23 -0
  122. package/src/engine/animation/curve/prototypeGLTF.js +14 -14
  123. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleDescription.d.ts +6 -1
  124. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleDescription.d.ts.map +1 -1
  125. package/src/engine/ecs/dynamic_actions/rules/DynamicRuleDescription.js +11 -6
  126. package/src/engine/ecs/guid/GUIDSerializationAdapter.spec.js +5 -5
  127. package/src/engine/ecs/guid/{GUID.d.ts → UUID.d.ts} +17 -12
  128. package/src/engine/ecs/guid/UUID.d.ts.map +1 -0
  129. package/src/engine/ecs/guid/{GUID.js → UUID.js} +35 -12
  130. package/src/engine/ecs/guid/UUID.spec.d.ts +2 -0
  131. package/src/engine/ecs/guid/UUID.spec.d.ts.map +1 -0
  132. package/src/engine/ecs/guid/{GUID.spec.js → UUID.spec.js} +18 -12
  133. package/src/engine/ecs/guid/UUIDSerializationAdapter.d.ts +18 -0
  134. package/src/engine/ecs/guid/UUIDSerializationAdapter.d.ts.map +1 -0
  135. package/src/engine/ecs/guid/{GUIDSerializationAdapter.js → UUIDSerializationAdapter.js} +5 -5
  136. package/src/engine/ecs/ik/InverseKinematics.js +3 -3
  137. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.d.ts.map +1 -1
  138. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +1 -140
  139. package/src/engine/input/ecs/systems/InputControllerSystem.js +1 -1
  140. package/src/engine/intelligence/blackboard/BlackboardDynamicStorageAdapter.d.ts +1 -1
  141. package/src/engine/intelligence/blackboard/BlackboardDynamicStorageAdapter.js +4 -4
  142. package/src/engine/physics/gjk/expanding_polytope_algorithm.d.ts +13 -0
  143. package/src/engine/physics/gjk/expanding_polytope_algorithm.d.ts.map +1 -0
  144. package/src/engine/physics/gjk/expanding_polytope_algorithm.js +395 -0
  145. package/src/engine/physics/gjk/expanding_polytope_algorithm.spec.d.ts +2 -0
  146. package/src/engine/physics/gjk/expanding_polytope_algorithm.spec.d.ts.map +1 -0
  147. package/src/engine/physics/gjk/expanding_polytope_algorithm.spec.js +46 -0
  148. package/src/engine/physics/inverse_kinematics/fabrik/fabrik3d_solve_primitive.d.ts +18 -0
  149. package/src/engine/physics/inverse_kinematics/fabrik/fabrik3d_solve_primitive.d.ts.map +1 -0
  150. package/src/engine/physics/inverse_kinematics/fabrik/fabrik3d_solve_primitive.js +277 -0
  151. package/src/engine/physics/inverse_kinematics/fabrik/fabrik3d_solve_primitive.spec.d.ts +2 -0
  152. package/src/engine/physics/inverse_kinematics/fabrik/fabrik3d_solve_primitive.spec.d.ts.map +1 -0
  153. package/src/engine/physics/inverse_kinematics/fabrik/fabrik3d_solve_primitive.spec.js +43 -0
  154. package/src/engine/physics/inverse_kinematics/fabrik/fabrik_solve.d.ts +12 -0
  155. package/src/engine/physics/inverse_kinematics/fabrik/fabrik_solve.d.ts.map +1 -0
  156. package/src/engine/physics/inverse_kinematics/fabrik/fabrik_solve.js +100 -0
  157. package/src/engine/physics/inverse_kinematics/fabrik/prototype.d.ts +2 -0
  158. package/src/engine/physics/inverse_kinematics/fabrik/prototype.d.ts.map +1 -0
  159. package/src/engine/physics/inverse_kinematics/fabrik/prototype.js +112 -0
  160. package/src/engine/physics/inverse_kinematics/two_joint_ik.d.ts +16 -0
  161. package/src/engine/physics/inverse_kinematics/two_joint_ik.d.ts.map +1 -0
  162. package/src/engine/physics/inverse_kinematics/two_joint_ik.js +127 -0
  163. package/src/view/elements/DropDownSelectionView.js +2 -2
  164. package/src/view/elements/tiles2d/Tile.d.ts.map +1 -1
  165. package/src/view/elements/tiles2d/Tile.js +2 -3
  166. package/src/core/math/makeSequenceLoop.d.ts.map +0 -1
  167. package/src/engine/animation/curve/compute_curve_aabb.d.ts +0 -7
  168. package/src/engine/animation/curve/compute_curve_aabb.d.ts.map +0 -1
  169. package/src/engine/ecs/guid/GUID.d.ts.map +0 -1
  170. package/src/engine/ecs/guid/GUID.spec.d.ts +0 -2
  171. package/src/engine/ecs/guid/GUID.spec.d.ts.map +0 -1
  172. package/src/engine/ecs/guid/GUIDSerializationAdapter.d.ts +0 -18
  173. package/src/engine/ecs/guid/GUIDSerializationAdapter.d.ts.map +0 -1
  174. /package/src/core/{math → function}/makeSequenceLoop.d.ts +0 -0
  175. /package/src/core/{math → function}/makeSequenceLoop.js +0 -0
@@ -1,14 +1,14 @@
1
1
  import { BinaryClassSerializationAdapter } from "../storage/binary/BinaryClassSerializationAdapter.js";
2
- import { GUID } from "./GUID.js";
2
+ import { UUID } from "./UUID.js";
3
3
 
4
- export class GUIDSerializationAdapter extends BinaryClassSerializationAdapter {
5
- klass = GUID
4
+ export class UUIDSerializationAdapter extends BinaryClassSerializationAdapter {
5
+ klass = UUID
6
6
  version = 0
7
7
 
8
8
  /**
9
9
  *
10
10
  * @param buffer
11
- * @param {GUID} value
11
+ * @param {UUID} value
12
12
  */
13
13
  serialize(buffer, value) {
14
14
  buffer.writeUint8Array(value.data, 0, 16);
@@ -17,7 +17,7 @@ export class GUIDSerializationAdapter extends BinaryClassSerializationAdapter {
17
17
  /**
18
18
  *
19
19
  * @param buffer
20
- * @param {GUID} value
20
+ * @param {UUID} value
21
21
  */
22
22
  deserialize(buffer, value) {
23
23
  buffer.readUint8Array(value.data, 0, 16);
@@ -16,11 +16,11 @@ export class InverseKinematics {
16
16
  copy(other) {
17
17
  this.constraints.splice(0, this.constraints.length);
18
18
 
19
- const ikConstraints = other.constraints;
20
- const n = ikConstraints.length;
19
+ const other_constraints = other.constraints;
20
+ const n = other_constraints.length;
21
21
 
22
22
  for (let i = 0; i < n; i++) {
23
- const constraint = ikConstraints[i];
23
+ const constraint = other_constraints[i];
24
24
 
25
25
  const constraintClone = constraint.clone();
26
26
 
@@ -1 +1 @@
1
- {"version":3,"file":"TwoBoneInverseKinematicsSolver.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js"],"names":[],"mappings":"AAyLA;IAGI,0BAuIC;CACJ;yBAzTwB,eAAe"}
1
+ {"version":3,"file":"TwoBoneInverseKinematicsSolver.d.ts","sourceRoot":"","sources":["../../../../../src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js"],"names":[],"mappings":"AA8CA;IAGI,0BAuIC;CACJ;yBA9KwB,eAAe"}
@@ -5,10 +5,10 @@ import { v3_displace_in_direction } from "../../../core/geom/vec3/v3_displace_in
5
5
  import { v3_dot } from "../../../core/geom/vec3/v3_dot.js";
6
6
  import { v3_length } from "../../../core/geom/vec3/v3_length.js";
7
7
  import Vector3 from "../../../core/geom/Vector3.js";
8
- import { clamp } from "../../../core/math/clamp.js";
9
8
  import { clamp01 } from "../../../core/math/clamp01.js";
10
9
  import { inverseLerp } from "../../../core/math/inverseLerp.js";
11
10
  import { findSkeletonBoneByType } from "../../graphics/ecs/mesh/SkeletonUtils.js";
11
+ import { two_joint_ik } from "../../physics/inverse_kinematics/two_joint_ik.js";
12
12
  import { IKSolver } from "./IKSolver.js";
13
13
 
14
14
  const boneWorldPositionC = new Vector3();
@@ -28,147 +28,8 @@ const globalRotationC = new Quaternion();
28
28
  const targetLocalRotationA = new Quaternion();
29
29
  const targetLocalRotationB = new Quaternion();
30
30
 
31
-
32
- /**
33
- * Compute interior angle between tree points
34
- * @param {Vector3} a
35
- * @param {Vector3} b
36
- * @param {Vector3} c
37
- * @returns {number} angle in radians
38
- */
39
- function computeInteriorAngle(a, b, c) {
40
-
41
- //compute AB delta
42
- const d_ab_x = a.x - b.x;
43
- const d_ab_y = a.y - b.y;
44
- const d_ab_z = a.z - b.z;
45
-
46
- //normalize AB delta vector
47
- const d_ab_length = v3_length(d_ab_x, d_ab_y, d_ab_z);
48
-
49
- const nd_ab_x = d_ab_x / d_ab_length;
50
- const nd_ab_y = d_ab_y / d_ab_length;
51
- const nd_ab_z = d_ab_z / d_ab_length;
52
-
53
- //compute CB delta
54
- const d_cb_x = c.x - b.x;
55
- const d_cb_y = c.y - b.y;
56
- const d_cb_z = c.z - b.z;
57
-
58
- //normalize CB delta vector
59
- const d_cb_length = v3_length(d_cb_x, d_cb_y, d_cb_z);
60
-
61
- const nd_cb_x = d_cb_x / d_cb_length;
62
- const nd_cb_y = d_cb_y / d_cb_length;
63
- const nd_cb_z = d_cb_z / d_cb_length;
64
-
65
- //compute dot product
66
- const dot = v3_dot(nd_ab_x, nd_ab_y, nd_ab_z, nd_cb_x, nd_cb_y, nd_cb_z);
67
-
68
- //clamp value of dot product for arc cosine function
69
- const clamped_dot = clamp(dot, -1, 1);
70
-
71
- return Math.acos(clamped_dot);
72
- }
73
-
74
-
75
- const d = new Vector3();
76
- const delta_ca = new Vector3();
77
- const delta_ta = new Vector3();
78
-
79
- const axis0 = new Vector3();
80
- const axis1 = new Vector3();
81
-
82
- const inv_a_gr = new Quaternion();
83
- const inv_b_gr = new Quaternion();
84
-
85
31
  const r0 = new Quaternion();
86
32
  const r1 = new Quaternion();
87
- const r2 = new Quaternion();
88
-
89
- const axis0_la = new Vector3();
90
- const axis0_lb = new Vector3();
91
- const axis1_la = new Vector3();
92
-
93
- /**
94
- * Based on http://theorangeduck.com/page/simple-two-joint
95
- * @param {Vector3} a Root bone position
96
- * @param {Vector3} b Second bone position
97
- * @param {Vector3} c Effector position
98
- * @param {Vector3} t Target position
99
- * @param {number} eps EPSILON value, small value for rounding error compensation
100
- * @param {Quaternion} a_gr Global rotation of root bone
101
- * @param {Quaternion} b_gr Global rotation of second bone
102
- * @param {Quaternion} a_lr local rotation for root bone, this will be updated as a result
103
- * @param {Quaternion} b_lr local rotation for second bone, this will be updated as a result
104
- */
105
- function two_joint_ik(
106
- a, b, c, t, eps,
107
- a_gr, b_gr,
108
- a_lr, b_lr
109
- ) {
110
-
111
- //Compute lengths of bones
112
- const lab = b.distanceTo(a);
113
- const lcb = b.distanceTo(c);
114
-
115
- const maximum_extension = lab + lcb - eps;
116
-
117
- //clamp length to the target to maximum extension of the joint
118
- const lat = clamp(t.distanceTo(a), eps, maximum_extension);
119
-
120
- //compute current interior angles
121
- const ac_ab_0 = computeInteriorAngle(c, a, b);
122
- const ba_bc_0 = computeInteriorAngle(a, b, c);
123
- const ac_at_0 = computeInteriorAngle(c, a, t);
124
-
125
- // Using the cosine rule to compute desired interior angles
126
- const length_at_sqr = lat * lat;
127
- const length_cb_sqr = lcb * lcb;
128
- const length_ab_sqr = lab * lab;
129
-
130
- const ac_ab_1 = Math.acos(clamp((length_cb_sqr - length_ab_sqr - length_at_sqr) / (-2 * lab * lat), -1, 1));
131
- const ba_bc_1 = Math.acos(clamp((length_at_sqr - length_ab_sqr - length_cb_sqr) / (-2 * lab * lcb), -1, 1));
132
-
133
- d.copy(Vector3.back);
134
- d.applyQuaternion(b_gr);
135
-
136
- delta_ca.subVectors(c, a);
137
- delta_ta.subVectors(t, a);
138
-
139
- axis0.crossVectors(delta_ca, d);
140
- axis0.normalize();
141
-
142
- axis1.crossVectors(delta_ca, delta_ta);
143
- axis1.normalize();
144
-
145
- inv_a_gr.copyInverse(a_gr);
146
- inv_b_gr.copyInverse(b_gr);
147
-
148
- axis0_la.copy(axis0);
149
- axis0_la.applyQuaternion(inv_a_gr);
150
-
151
- const angle0 = ac_ab_1 - ac_ab_0;
152
-
153
- r0.fromAxisAngle(axis0_la, angle0);
154
-
155
- const angle1 = ba_bc_1 - ba_bc_0;
156
-
157
- axis0_lb.copy(axis0);
158
- axis0_lb.applyQuaternion(inv_b_gr);
159
-
160
- r1.fromAxisAngle(axis0_lb, angle1);
161
-
162
- axis1_la.copy(axis1);
163
- axis1_la.applyQuaternion(inv_a_gr);
164
-
165
- r2.fromAxisAngle(axis1_la, ac_at_0);
166
-
167
- r0.multiply(r2);
168
-
169
- a_lr.multiply(r0);
170
- b_lr.multiply(r1);
171
- }
172
33
 
173
34
  /**
174
35
  *
@@ -181,7 +181,7 @@ function removeBindings(mapping, devices, proxies) {
181
181
  }
182
182
 
183
183
  /**
184
- * @deprecated Use {@link InputSystem} instead
184
+ * Prefer to use {@link InputSystem} instead
185
185
  */
186
186
  class InputControllerSystem extends System {
187
187
  constructor(devices) {
@@ -38,7 +38,7 @@ export class BlackboardDynamicStorageAdapter {
38
38
  */
39
39
  private __write_timeout_handle;
40
40
  /**
41
- *
41
+ * In milliseconds
42
42
  * @type {number}
43
43
  * @private
44
44
  */
@@ -54,7 +54,7 @@ export class BlackboardDynamicStorageAdapter {
54
54
  this.__write_timeout_handle = -1;
55
55
 
56
56
  /**
57
- *
57
+ * In milliseconds
58
58
  * @type {number}
59
59
  * @private
60
60
  */
@@ -101,14 +101,14 @@ export class BlackboardDynamicStorageAdapter {
101
101
  async read() {
102
102
  const data = await this.__storage.promiseLoadBinary(this.__storage_key);
103
103
 
104
+ this.__blackboard.reset();
105
+
104
106
  if (data === undefined) {
105
107
  // no data
106
- this.__blackboard.reset();
107
108
  return;
108
109
  }
109
110
 
110
- const buffer = new BinaryBuffer();
111
- buffer.fromArrayBuffer(data);
111
+ const buffer = BinaryBuffer.fromArrayBuffer(data);
112
112
 
113
113
  const object = this.__serialization_adapter.deserialize(buffer);
114
114
 
@@ -0,0 +1,13 @@
1
+ /**
2
+ * TODO: needs to be tested thoroughly, intended to be working with GJK
3
+ * @param {number[]} result
4
+ * @param {number} result_offset
5
+ * @param {number[]} a
6
+ * @param {number[]} b
7
+ * @param {number[]} c
8
+ * @param {number[]} d
9
+ * @param {AbstractShape3D} coll1
10
+ * @param {AbstractShape3D} coll2
11
+ */
12
+ export function expanding_polytope_algorithm(result: number[], result_offset: number, a: number[], b: number[], c: number[], d: number[], coll1: AbstractShape3D, coll2: AbstractShape3D): void;
13
+ //# sourceMappingURL=expanding_polytope_algorithm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expanding_polytope_algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/engine/physics/gjk/expanding_polytope_algorithm.js"],"names":[],"mappings":"AAuFA;;;;;;;;;;GAUG;AACH,qDATW,MAAM,EAAE,iBACR,MAAM,KACN,MAAM,EAAE,KACR,MAAM,EAAE,KACR,MAAM,EAAE,KACR,MAAM,EAAE,wDAgQlB"}
@@ -0,0 +1,395 @@
1
+ import { assert } from "../../../core/assert.js";
2
+ import { array_copy } from "../../../core/collection/array/array_copy.js";
3
+ import { array_swap } from "../../../core/collection/array/array_swap.js";
4
+
5
+ import { v3_negate_array } from "../../../core/geom/3d/v3_negate_array.js";
6
+ import { v3_dot } from "../../../core/geom/vec3/v3_dot.js";
7
+ import { v3_dot_array_array } from "../../../core/geom/vec3/v3_dot_array_array.js";
8
+ import { v3_length } from "../../../core/geom/vec3/v3_length.js";
9
+ import { v3_length_sqr } from "../../../core/geom/vec3/v3_length_sqr.js";
10
+
11
+ const EPA_TOLERANCE = 0.0001;
12
+ const EPA_MAX_NUM_FACES = 64;
13
+ const EPA_MAX_NUM_LOOSE_EDGES = 32;
14
+ const EPA_MAX_NUM_ITERATIONS = 64;
15
+
16
+ const FACE_ELEMENT_COUNT = 3 * 4;
17
+
18
+ const EDGE_ELEMENT_COUNT = 2 * 3;
19
+
20
+ //Array of faces, each with 3 verts and a normal
21
+ const faces = new Float32Array(EPA_MAX_NUM_FACES * FACE_ELEMENT_COUNT);
22
+
23
+ /**
24
+ * keep track of edges we need to fix after removing faces
25
+ * @type {Float32Array}
26
+ */
27
+ const loose_edges = new Float32Array(EPA_MAX_NUM_LOOSE_EDGES * EDGE_ELEMENT_COUNT);
28
+
29
+ const scratch_v3 = new Float32Array(3);
30
+
31
+
32
+ function write_v3(target, target_index, v) {
33
+ array_copy(v, 0, faces, target_index * 3, 3);
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @param {number[]|Float32Array} faces
39
+ * @param {number} index
40
+ * @param {number[]} a
41
+ * @param {number[]} b
42
+ * @param {number[]} c
43
+ */
44
+ function write_face(faces, index, a, b, c) {
45
+ const index4 = index * 4;
46
+
47
+ write_v3(faces, index4 + 0, a);
48
+ write_v3(faces, index4 + 1, b);
49
+ write_v3(faces, index4 + 2, c);
50
+
51
+ // normalise(cross(b-a, c-a)); //ABC
52
+ const ba_x = b[0] - a[0];
53
+ const ba_y = b[1] - a[1];
54
+ const ba_z = b[2] - a[2];
55
+
56
+ const ca_x = c[0] - a[0];
57
+ const ca_y = c[1] - a[1];
58
+ const ca_z = c[2] - a[2];
59
+
60
+ // cross product
61
+
62
+ const cross_x = ba_y * ca_z - ba_z * ca_y;
63
+ const cross_y = ba_z * ca_x - ba_x * ca_z;
64
+ const cross_z = ba_x * ca_y - ba_y * ca_x;
65
+
66
+ const normal_offset = (index4 + 3) * 3;
67
+
68
+ // normalize
69
+ const length = v3_length(cross_x, cross_y, cross_z);
70
+
71
+ if (length === 0) {
72
+ // division by 0, there is no normal vector so let's provide something valid
73
+
74
+ faces[normal_offset] = 0;
75
+ faces[normal_offset + 1] = 1;
76
+ faces[normal_offset + 2] = 0;
77
+
78
+ return;
79
+ }
80
+
81
+ const length_inv = 1 / length;
82
+
83
+ faces[normal_offset] = cross_x * length_inv;
84
+ faces[normal_offset + 1] = cross_y * length_inv;
85
+ faces[normal_offset + 2] = cross_z * length_inv;
86
+ }
87
+
88
+ /**
89
+ * TODO: needs to be tested thoroughly, intended to be working with GJK
90
+ * @param {number[]} result
91
+ * @param {number} result_offset
92
+ * @param {number[]} a
93
+ * @param {number[]} b
94
+ * @param {number[]} c
95
+ * @param {number[]} d
96
+ * @param {AbstractShape3D} coll1
97
+ * @param {AbstractShape3D} coll2
98
+ */
99
+ export function expanding_polytope_algorithm(
100
+ result, result_offset,
101
+ a, b, c, d,
102
+ coll1, coll2
103
+ ) {
104
+ /*
105
+ Adapted from https://github.com/kevinmoran/GJK/blob/master/GJK.h
106
+
107
+ "GJK + Expanding Polytope Algorithm - Implementation and Visualization" https://www.youtube.com/watch?v=6rgiPrzqt9w
108
+ */
109
+
110
+ //Init with final simplex from GJK
111
+ write_face(faces, 0, a, b, c);
112
+ write_face(faces, 1, a, c, d);
113
+ write_face(faces, 2, a, d, b);
114
+ write_face(faces, 3, b, d, c);
115
+
116
+ let num_faces = 4;
117
+ let closest_face;
118
+
119
+ for (let iterations = 0; iterations < EPA_MAX_NUM_ITERATIONS; iterations++) {
120
+
121
+ //Find face that's closest to origin
122
+
123
+ let min_dist = v3_dot_array_array(faces, 0, faces, 3 * 3);
124
+ closest_face = 0;
125
+
126
+ for (let i = 1; i < num_faces; i++) {
127
+ const dist = v3_dot_array_array(faces, i * FACE_ELEMENT_COUNT, faces, i * FACE_ELEMENT_COUNT + 3 * 3);
128
+
129
+ if (dist < min_dist) {
130
+ min_dist = dist;
131
+ closest_face = i;
132
+ }
133
+
134
+ }
135
+
136
+ //search normal to face that's closest to origin
137
+ const closest_face_normal_offset = closest_face * FACE_ELEMENT_COUNT + 3 * 3;
138
+
139
+ const search_dir_x = faces[closest_face_normal_offset];
140
+ const search_dir_y = faces[closest_face_normal_offset + 1];
141
+ const search_dir_z = faces[closest_face_normal_offset + 2];
142
+
143
+ if (search_dir_x === 0 && search_dir_y === 0 && search_dir_z === 0) {
144
+ debugger;
145
+ }
146
+
147
+ // build new support point to expand polytope
148
+
149
+ coll2.support(scratch_v3, 0, search_dir_x, search_dir_y, search_dir_z);
150
+
151
+ const support2_x = scratch_v3[0];
152
+ const support2_y = scratch_v3[1];
153
+ const support2_z = scratch_v3[2];
154
+
155
+ coll1.support(scratch_v3, 0, -search_dir_x, -search_dir_y, -search_dir_z);
156
+
157
+ const support1_x = scratch_v3[0];
158
+ const support1_y = scratch_v3[1];
159
+ const support1_z = scratch_v3[2];
160
+
161
+ const p_x = support2_x - support1_x;
162
+ const p_y = support2_y - support1_y;
163
+ const p_z = support2_z - support1_z;
164
+
165
+ const dot_p_search_dir = v3_dot(p_x, p_y, p_z, search_dir_x, search_dir_y, search_dir_z);
166
+
167
+ if (dot_p_search_dir - min_dist < EPA_TOLERANCE) {
168
+ //Convergence (new point is not significantly further from origin)
169
+
170
+ result[result_offset] = search_dir_x * dot_p_search_dir;
171
+ result[result_offset + 1] = search_dir_y * dot_p_search_dir;
172
+ result[result_offset + 2] = search_dir_z * dot_p_search_dir;
173
+
174
+ return;
175
+ }
176
+
177
+ let num_loose_edges = 0;
178
+
179
+ //Find all triangles that are facing p
180
+ for (let i = 0; i < num_faces; i++) {
181
+ const face_offset = i * FACE_ELEMENT_COUNT;
182
+
183
+ const face_normal_address = face_offset + 3 * 3;
184
+ const face_a_address = face_offset;
185
+
186
+ const face_normal_x = faces[face_normal_address];
187
+ const face_normal_y = faces[face_normal_address + 1];
188
+ const face_normal_z = faces[face_normal_address + 2];
189
+
190
+ const face_a_x = faces[face_a_address];
191
+ const face_a_y = faces[face_a_address + 1];
192
+ const face_a_z = faces[face_a_address + 2];
193
+
194
+ const pa_x = p_x - face_a_x;
195
+ const pa_y = p_y - face_a_y;
196
+ const pa_z = p_z - face_a_z;
197
+
198
+ if (v3_dot(face_normal_x, face_normal_y, face_normal_z, pa_x, pa_y, pa_z) <= 0) {
199
+ continue;
200
+ }
201
+
202
+ // triangle i faces p, remove it
203
+ for (let j = 0; j < 3; j++) //Three edges per face
204
+ {
205
+ const a_offset = j * 3;
206
+
207
+ const current_edge_ax = faces[face_offset + a_offset];
208
+ const current_edge_ay = faces[face_offset + a_offset + 1];
209
+ const current_edge_az = faces[face_offset + a_offset + 2];
210
+
211
+ const b_offset = ((j + 1) % 3) * 3;
212
+
213
+ const current_edge_bx = faces[face_offset + b_offset];
214
+ const current_edge_by = faces[face_offset + b_offset + 1];
215
+ const current_edge_bz = faces[face_offset + b_offset + 2];
216
+
217
+ // vec3 current_edge[2] = { faces[i][j], faces[i][(j + 1) % 3] };
218
+
219
+ let found_edge = false;
220
+
221
+ //Check if current edge is already in list
222
+ for (let k = 0; k < num_loose_edges; k++) {
223
+ const loose_edge_offset = k * EDGE_ELEMENT_COUNT;
224
+
225
+ const loose_edge_ax = loose_edges[loose_edge_offset];
226
+ const loose_edge_ay = loose_edges[loose_edge_offset + 1];
227
+ const loose_edge_az = loose_edges[loose_edge_offset + 2];
228
+
229
+ const loose_edge_bx = loose_edges[loose_edge_offset + 3];
230
+ const loose_edge_by = loose_edges[loose_edge_offset + 4];
231
+ const loose_edge_bz = loose_edges[loose_edge_offset + 5];
232
+
233
+
234
+ // if (loose_edges[k][1] === current_edge[0] && loose_edges[k][0] === current_edge[1]) {
235
+ if (
236
+ (
237
+ loose_edge_ax === current_edge_bx
238
+ && loose_edge_ay === current_edge_by
239
+ && loose_edge_az === current_edge_bz
240
+ )
241
+ && (
242
+ loose_edge_bx === current_edge_ax
243
+ && loose_edge_by === current_edge_ay
244
+ && loose_edge_bz === current_edge_az
245
+ )
246
+ ) {
247
+ //Edge is already in the list, remove it
248
+ //THIS ASSUMES EDGE CAN ONLY BE SHARED BY 2 TRIANGLES (which should be true)
249
+ //THIS ALSO ASSUMES SHARED EDGE WILL BE REVERSED IN THE TRIANGLES (which
250
+ //should be true provided every triangle is wound CCW)
251
+
252
+ // Overwrite current edge with last edge in list
253
+ loose_edges.copyWithin(loose_edge_offset, (num_loose_edges - 1) * EDGE_ELEMENT_COUNT, (num_loose_edges) * EDGE_ELEMENT_COUNT);
254
+
255
+ num_loose_edges--;
256
+ found_edge = true;
257
+
258
+ //exit loop because edge can only be shared once
259
+ break;
260
+ }
261
+ }
262
+
263
+ if (!found_edge) { //add current edge to list
264
+ // assert(num_loose_edges<EPA_MAX_NUM_LOOSE_EDGES);
265
+
266
+ assert.lessThan(num_loose_edges, EPA_MAX_NUM_LOOSE_EDGES);
267
+
268
+ if (num_loose_edges >= EPA_MAX_NUM_LOOSE_EDGES) {
269
+ // this should not happen, but if it does it is best to be "kind of right" than to fail completely
270
+ break;
271
+ }
272
+
273
+ const last_edge_offset = num_loose_edges * EDGE_ELEMENT_COUNT;
274
+
275
+ loose_edges[last_edge_offset] = current_edge_ax;
276
+ loose_edges[last_edge_offset + 1] = current_edge_ay;
277
+ loose_edges[last_edge_offset + 2] = current_edge_az;
278
+
279
+ loose_edges[last_edge_offset + 3] = current_edge_bx;
280
+ loose_edges[last_edge_offset + 4] = current_edge_by;
281
+ loose_edges[last_edge_offset + 5] = current_edge_bz;
282
+
283
+ num_loose_edges++;
284
+ }
285
+ }
286
+
287
+ // move last face to fill the removed element
288
+ faces.copyWithin(i * FACE_ELEMENT_COUNT, (num_faces - 1) * FACE_ELEMENT_COUNT, num_faces * FACE_ELEMENT_COUNT);
289
+
290
+ num_faces--;
291
+ i--;
292
+
293
+ }
294
+
295
+ //Reconstruct polytope with p added
296
+ for (let i = 0; i < num_loose_edges; i++) {
297
+ // assert(num_faces<EPA_MAX_NUM_FACES);
298
+
299
+ assert.lessThan(num_faces, EPA_MAX_NUM_FACES);
300
+
301
+ if (num_faces >= EPA_MAX_NUM_FACES) {
302
+ // should never happen
303
+ break;
304
+ }
305
+
306
+ const face_offset = num_faces * FACE_ELEMENT_COUNT;
307
+
308
+ const loose_edge_offset = i * EDGE_ELEMENT_COUNT;
309
+
310
+ array_copy(
311
+ loose_edges, loose_edge_offset,
312
+ faces, face_offset,
313
+ EDGE_ELEMENT_COUNT
314
+ );
315
+
316
+ faces[face_offset + 3 * 2] = p_x;
317
+ faces[face_offset + 3 * 2 + 1] = p_y;
318
+ faces[face_offset + 3 * 2 + 2] = p_z;
319
+
320
+ // construct normal
321
+ const face_normal_offset = face_offset + 3 * 3;
322
+ construct_normal(face_normal_offset, i, p_x, p_y, p_z);
323
+
324
+ //Check for wrong normal to maintain CCW winding
325
+ const bias = 0.000001; //in case dot result is only slightly < 0 (because origin is on face)
326
+
327
+ const dot = v3_dot_array_array(faces, face_offset, faces, face_normal_offset)
328
+
329
+ if (dot + bias < 0) {
330
+ array_swap(faces, face_offset, faces, face_offset + 3, 3);
331
+ // invert normal
332
+ v3_negate_array(faces, face_normal_offset, faces, face_normal_offset);
333
+ }
334
+
335
+ num_faces++;
336
+ }
337
+ }
338
+
339
+ console.warn("EPA did not converge");
340
+
341
+ //Return most recent closest point
342
+ const closest_face_offset = closest_face * FACE_ELEMENT_COUNT;
343
+ const closest_face_normal_offset = closest_face_offset + 3 * 3;
344
+
345
+ const dot = v3_dot_array_array(faces, closest_face_offset, faces, closest_face_normal_offset);
346
+
347
+ result[result_offset] = faces[closest_face_normal_offset + 0] * dot;
348
+ result[result_offset + 1] = faces[closest_face_normal_offset + 1] * dot;
349
+ result[result_offset + 2] = faces[closest_face_normal_offset + 2] * dot;
350
+
351
+ }
352
+
353
+ /**
354
+ *
355
+ * @param {number} result_offset
356
+ * @param {number} edge_index
357
+ * @param {number} p_x
358
+ * @param {number} p_y
359
+ * @param {number} p_z
360
+ */
361
+ function construct_normal(result_offset, edge_index, p_x, p_y, p_z) {
362
+ const edge_offset = edge_index * EDGE_ELEMENT_COUNT;
363
+
364
+ const edge_ax = loose_edges[edge_offset];
365
+ const edge_ay = loose_edges[edge_offset + 1];
366
+ const edge_az = loose_edges[edge_offset + 2];
367
+
368
+ const edge_bx = loose_edges[edge_offset + 3];
369
+ const edge_by = loose_edges[edge_offset + 4];
370
+ const edge_bz = loose_edges[edge_offset + 5];
371
+
372
+ const v0x = edge_ax - edge_bx;
373
+ const v0y = edge_ay - edge_by;
374
+ const v0z = edge_az - edge_bz;
375
+
376
+ const v1x = edge_ax - p_x;
377
+ const v1y = edge_ay - p_y;
378
+ const v1z = edge_az - p_z;
379
+
380
+ const crossX = v0y * v1z - v0z * v1y;
381
+ const crossY = v0z * v1x - v0x * v1z;
382
+ const crossZ = v0x * v1y - v0y * v1x;
383
+
384
+ const l_sqr = v3_length_sqr(crossX, crossY, crossZ);
385
+
386
+ const l_inv = 1 / Math.sqrt(l_sqr);
387
+
388
+ const x = crossX * l_inv;
389
+ const y = crossY * l_inv;
390
+ const z = crossZ * l_inv;
391
+
392
+ faces[result_offset] = x;
393
+ faces[result_offset + 1] = y;
394
+ faces[result_offset + 2] = z;
395
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=expanding_polytope_algorithm.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expanding_polytope_algorithm.spec.d.ts","sourceRoot":"","sources":["../../../../../src/engine/physics/gjk/expanding_polytope_algorithm.spec.js"],"names":[],"mappings":""}