@woosh/meep-engine 3.80.2 → 3.81.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 (200) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/build/bundle-worker-terrain.js +1 -1
  3. package/editor/Editor.d.ts +10 -2
  4. package/editor/Editor.d.ts.map +1 -1
  5. package/editor/Editor.js +33 -23
  6. package/editor/EditorCameraNavigation.d.ts +3 -4
  7. package/editor/EditorCameraNavigation.d.ts.map +1 -1
  8. package/editor/EditorCameraNavigation.js +29 -8
  9. package/editor/prototypeEditorShell.d.ts.map +1 -1
  10. package/editor/prototypeEditorShell.js +10 -2
  11. package/editor/tools/GridPaintTool.d.ts.map +1 -1
  12. package/editor/tools/GridPaintTool.js +12 -7
  13. package/package.json +1 -1
  14. package/src/core/geom/3d/quaternion/quat3_slerp.d.ts +25 -0
  15. package/src/core/geom/3d/quaternion/quat3_slerp.d.ts.map +1 -0
  16. package/src/core/geom/3d/quaternion/quat3_slerp.js +66 -0
  17. package/src/core/geom/3d/topology/struct/binary/query/bt_face_cluster_compute_normal_bounding_cone.d.ts.map +1 -1
  18. package/src/core/geom/3d/topology/struct/binary/query/bt_face_cluster_compute_normal_bounding_cone.js +9 -5
  19. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_compute_bounding_sphere.d.ts +3 -3
  20. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_compute_bounding_sphere.d.ts.map +1 -1
  21. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_compute_bounding_sphere.js +5 -14
  22. package/src/core/geom/packing/miniball/Miniball.d.ts +8 -181
  23. package/src/core/geom/packing/miniball/Miniball.d.ts.map +1 -1
  24. package/src/core/geom/packing/miniball/Miniball.js +10 -452
  25. package/src/core/geom/packing/miniball/PointSet.d.ts +13 -39
  26. package/src/core/geom/packing/miniball/PointSet.d.ts.map +1 -1
  27. package/src/core/geom/packing/miniball/PointSet.js +14 -54
  28. package/src/core/geom/packing/sphere_compute_bounding_of_points.d.ts +20 -0
  29. package/src/core/geom/packing/sphere_compute_bounding_of_points.d.ts.map +1 -0
  30. package/src/core/geom/packing/sphere_compute_bounding_of_points.js +66 -0
  31. package/src/core/geom/packing/sphere_compute_bounding_of_spheres.d.ts.map +1 -1
  32. package/src/core/geom/packing/sphere_compute_bounding_of_spheres.js +0 -1
  33. package/src/core/math/exponential_approach.d.ts +23 -0
  34. package/src/core/math/exponential_approach.d.ts.map +1 -0
  35. package/src/core/math/exponential_approach.js +31 -0
  36. package/src/core/math/physics/spring/Spring.d.ts.map +1 -0
  37. package/src/core/math/physics/spring/criticallyDampedSpring.d.ts.map +1 -0
  38. package/src/core/math/physics/spring/dampedSpringStep.d.ts.map +1 -0
  39. package/src/engine/EngineHarness.d.ts +1 -3
  40. package/src/engine/EngineHarness.d.ts.map +1 -1
  41. package/src/engine/EngineHarness.js +13 -10
  42. package/src/engine/control/first-person/FirstPersonPlayerController.d.ts +9 -15
  43. package/src/engine/control/first-person/FirstPersonPlayerController.d.ts.map +1 -1
  44. package/src/engine/control/first-person/FirstPersonPlayerController.js +9 -10
  45. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts +68 -14
  46. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
  47. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +196 -184
  48. package/src/engine/ecs/gui/hud/testHudEdgeStick.js +4 -2
  49. package/src/engine/ecs/parent/parent_entity_root_of.d.ts +11 -0
  50. package/src/engine/ecs/parent/parent_entity_root_of.d.ts.map +1 -0
  51. package/src/engine/ecs/parent/parent_entity_root_of.js +32 -0
  52. package/src/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +130 -130
  53. package/src/engine/graphics/camera/makeOrbitalCameraController.d.ts +3 -2
  54. package/src/engine/graphics/camera/makeOrbitalCameraController.d.ts.map +1 -1
  55. package/src/engine/graphics/camera/makeOrbitalCameraController.js +18 -11
  56. package/src/engine/graphics/camera/orbital/OrbitalCameraRig.d.ts +4 -5
  57. package/src/engine/graphics/camera/orbital/OrbitalCameraRig.d.ts.map +1 -1
  58. package/src/engine/graphics/camera/orbital/OrbitalCameraRig.js +6 -6
  59. package/src/engine/graphics/camera/rig/CameraRig.d.ts +55 -0
  60. package/src/engine/graphics/camera/rig/CameraRig.d.ts.map +1 -0
  61. package/src/engine/graphics/camera/rig/CameraRig.js +65 -0
  62. package/src/engine/graphics/camera/rig/CameraRigContext.d.ts +58 -0
  63. package/src/engine/graphics/camera/rig/CameraRigContext.d.ts.map +1 -0
  64. package/src/engine/graphics/camera/rig/CameraRigContext.js +51 -0
  65. package/src/engine/graphics/camera/rig/CameraRigDriver.d.ts +36 -0
  66. package/src/engine/graphics/camera/rig/CameraRigDriver.d.ts.map +1 -0
  67. package/src/engine/graphics/camera/rig/CameraRigDriver.js +39 -0
  68. package/src/engine/graphics/camera/rig/CameraRigSystem.d.ts +30 -0
  69. package/src/engine/graphics/camera/rig/CameraRigSystem.d.ts.map +1 -0
  70. package/src/engine/graphics/camera/rig/CameraRigSystem.js +81 -0
  71. package/src/engine/graphics/camera/rig/CameraState.d.ts +59 -0
  72. package/src/engine/graphics/camera/rig/CameraState.d.ts.map +1 -0
  73. package/src/engine/graphics/camera/rig/CameraState.js +76 -0
  74. package/src/engine/graphics/camera/rig/camera_rig_output.d.ts +17 -0
  75. package/src/engine/graphics/camera/rig/camera_rig_output.d.ts.map +1 -0
  76. package/src/engine/graphics/camera/rig/camera_rig_output.js +80 -0
  77. package/src/engine/graphics/camera/rig/camera_rig_update.d.ts +38 -0
  78. package/src/engine/graphics/camera/rig/camera_rig_update.d.ts.map +1 -0
  79. package/src/engine/graphics/camera/rig/camera_rig_update.js +102 -0
  80. package/src/engine/graphics/camera/rig/camera_state_read_entity.d.ts +17 -0
  81. package/src/engine/graphics/camera/rig/camera_state_read_entity.d.ts.map +1 -0
  82. package/src/engine/graphics/camera/rig/camera_state_read_entity.js +71 -0
  83. package/src/engine/graphics/camera/rig/drivers/CameraBlendDriver.d.ts +95 -0
  84. package/src/engine/graphics/camera/rig/drivers/CameraBlendDriver.d.ts.map +1 -0
  85. package/src/engine/graphics/camera/rig/drivers/CameraBlendDriver.js +290 -0
  86. package/src/engine/graphics/camera/rig/drivers/CameraCollideDriver.d.ts +37 -0
  87. package/src/engine/graphics/camera/rig/drivers/CameraCollideDriver.d.ts.map +1 -0
  88. package/src/engine/graphics/camera/rig/drivers/CameraCollideDriver.js +158 -0
  89. package/src/engine/graphics/camera/rig/drivers/CameraFollowDriver.d.ts +28 -0
  90. package/src/engine/graphics/camera/rig/drivers/CameraFollowDriver.d.ts.map +1 -0
  91. package/src/engine/graphics/camera/rig/drivers/CameraFollowDriver.js +66 -0
  92. package/src/engine/graphics/camera/rig/drivers/CameraFovDriver.d.ts +29 -0
  93. package/src/engine/graphics/camera/rig/drivers/CameraFovDriver.d.ts.map +1 -0
  94. package/src/engine/graphics/camera/rig/drivers/CameraFovDriver.js +65 -0
  95. package/src/engine/graphics/camera/rig/drivers/CameraImpulseDriver.d.ts +113 -0
  96. package/src/engine/graphics/camera/rig/drivers/CameraImpulseDriver.d.ts.map +1 -0
  97. package/src/engine/graphics/camera/rig/drivers/CameraImpulseDriver.js +442 -0
  98. package/src/engine/graphics/camera/rig/drivers/CameraLookAtDriver.d.ts +32 -0
  99. package/src/engine/graphics/camera/rig/drivers/CameraLookAtDriver.d.ts.map +1 -0
  100. package/src/engine/graphics/camera/rig/drivers/CameraLookAtDriver.js +78 -0
  101. package/src/engine/graphics/camera/rig/drivers/CameraOffsetDriver.d.ts +36 -0
  102. package/src/engine/graphics/camera/rig/drivers/CameraOffsetDriver.d.ts.map +1 -0
  103. package/src/engine/graphics/camera/rig/drivers/CameraOffsetDriver.js +54 -0
  104. package/src/engine/graphics/camera/rig/drivers/CameraOffsetFrame.d.ts +10 -0
  105. package/src/engine/graphics/camera/rig/drivers/CameraOffsetFrame.d.ts.map +1 -0
  106. package/src/engine/graphics/camera/rig/drivers/CameraOffsetFrame.js +22 -0
  107. package/src/engine/graphics/camera/rig/drivers/CameraOrbitDriver.d.ts +182 -0
  108. package/src/engine/graphics/camera/rig/drivers/CameraOrbitDriver.d.ts.map +1 -0
  109. package/src/engine/graphics/camera/rig/drivers/CameraOrbitDriver.js +455 -0
  110. package/src/engine/graphics/camera/rig/drivers/CameraPositionDriver.d.ts +31 -0
  111. package/src/engine/graphics/camera/rig/drivers/CameraPositionDriver.d.ts.map +1 -0
  112. package/src/engine/graphics/camera/rig/drivers/CameraPositionDriver.js +57 -0
  113. package/src/engine/graphics/camera/rig/drivers/CameraShakeDriver.d.ts +62 -0
  114. package/src/engine/graphics/camera/rig/drivers/CameraShakeDriver.d.ts.map +1 -0
  115. package/src/engine/graphics/camera/rig/drivers/CameraShakeDriver.js +174 -0
  116. package/src/engine/graphics/camera/rig/drivers/CameraSmoothDriver.d.ts +29 -0
  117. package/src/engine/graphics/camera/rig/drivers/CameraSmoothDriver.d.ts.map +1 -0
  118. package/src/engine/graphics/camera/rig/drivers/CameraSmoothDriver.js +82 -0
  119. package/src/engine/graphics/camera/rig/drivers/CameraYawPitchRollDriver.d.ts +40 -0
  120. package/src/engine/graphics/camera/rig/drivers/CameraYawPitchRollDriver.d.ts.map +1 -0
  121. package/src/engine/graphics/camera/rig/drivers/CameraYawPitchRollDriver.js +66 -0
  122. package/src/engine/graphics/camera/rig/drivers/camera_state_add_offset.d.ts +22 -0
  123. package/src/engine/graphics/camera/rig/drivers/camera_state_add_offset.d.ts.map +1 -0
  124. package/src/engine/graphics/camera/rig/drivers/camera_state_add_offset.js +81 -0
  125. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts +6 -131
  126. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
  127. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +4 -378
  128. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSerializationAdapter.d.ts +4 -2
  129. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSerializationAdapter.d.ts.map +1 -1
  130. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSerializationAdapter.js +16 -27
  131. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLander.d.ts +4 -0
  132. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLander.d.ts.map +1 -1
  133. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLander.js +4 -0
  134. package/src/engine/graphics/ecs/light/Light.d.ts +10 -5
  135. package/src/engine/graphics/ecs/light/Light.d.ts.map +1 -1
  136. package/src/engine/graphics/ecs/light/Light.js +15 -24
  137. package/src/engine/graphics/geometry/computeBoundingSphereFromVertexData.d.ts +0 -4
  138. package/src/engine/graphics/geometry/computeBoundingSphereFromVertexData.d.ts.map +1 -1
  139. package/src/engine/graphics/geometry/computeBoundingSphereFromVertexData.js +12 -11
  140. package/src/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.d.ts.map +1 -1
  141. package/src/engine/graphics/impostors/octahedral/bake/compute_bounding_sphere.js +5 -5
  142. package/src/engine/graphics3/LightSystem.js +0 -3
  143. package/src/engine/input/ecs/controllers/KeyboardCameraController.d.ts +2 -2
  144. package/src/engine/input/ecs/controllers/KeyboardCameraController.d.ts.map +1 -1
  145. package/src/engine/input/ecs/controllers/KeyboardCameraController.js +3 -3
  146. package/src/engine/physics/ecs/ContactProbeSystem.d.ts.map +1 -1
  147. package/src/engine/physics/ecs/ContactProbeSystem.js +3 -25
  148. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  149. package/src/shade/playground/foliage_wind/foliage_world.d.ts.map +1 -1
  150. package/src/shade/playground/foliage_wind/foliage_world.js +0 -1
  151. package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
  152. package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +1 -1
  153. package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
  154. package/src/shade/renderer/camera/orbital/OrbitalCameraController.d.ts +4 -4
  155. package/src/shade/renderer/camera/orbital/OrbitalCameraController.d.ts.map +1 -1
  156. package/src/shade/renderer/camera/orbital/OrbitalCameraController.js +26 -11
  157. package/src/shade/renderer/geometry/Geometry.d.ts.map +1 -1
  158. package/src/shade/renderer/geometry/Geometry.js +2 -11
  159. package/src/shade/renderer/geometry/virtual/build/sphere/vgeo_bounding_sphere.d.ts.map +1 -1
  160. package/src/shade/renderer/geometry/virtual/build/sphere/vgeo_bounding_sphere.js +3 -6
  161. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
  162. package/src/core/geom/packing/miniball/Quality.d.ts +0 -92
  163. package/src/core/geom/packing/miniball/Quality.d.ts.map +0 -1
  164. package/src/core/geom/packing/miniball/Quality.js +0 -114
  165. package/src/core/geom/packing/miniball/Subspan.d.ts +0 -191
  166. package/src/core/geom/packing/miniball/Subspan.d.ts.map +0 -1
  167. package/src/core/geom/packing/miniball/Subspan.js +0 -529
  168. package/src/core/geom/packing/miniball/miniball_compute_quality.d.ts +0 -10
  169. package/src/core/geom/packing/miniball/miniball_compute_quality.d.ts.map +0 -1
  170. package/src/core/geom/packing/miniball/miniball_compute_quality.js +0 -60
  171. package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts +0 -146
  172. package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts.map +0 -1
  173. package/src/engine/control/first-person/composer/EyeOffsetStack.js +0 -395
  174. package/src/engine/control/first-person/math/Spring.d.ts.map +0 -1
  175. package/src/engine/control/first-person/math/criticallyDampedSpring.d.ts.map +0 -1
  176. package/src/engine/control/first-person/math/dampedSpringStep.d.ts.map +0 -1
  177. package/src/engine/graphics/camera/CameraShake.d.ts +0 -32
  178. package/src/engine/graphics/camera/CameraShake.d.ts.map +0 -1
  179. package/src/engine/graphics/camera/CameraShake.js +0 -68
  180. package/src/engine/graphics/camera/CameraShakeBehavior.d.ts +0 -41
  181. package/src/engine/graphics/camera/CameraShakeBehavior.d.ts.map +0 -1
  182. package/src/engine/graphics/camera/CameraShakeBehavior.js +0 -91
  183. package/src/engine/graphics/camera/CameraShakeTraumaBehavior.d.ts +0 -19
  184. package/src/engine/graphics/camera/CameraShakeTraumaBehavior.d.ts.map +0 -1
  185. package/src/engine/graphics/camera/CameraShakeTraumaBehavior.js +0 -37
  186. package/src/engine/graphics/ecs/camera/filter/setup_filtered_camera_controller.d.ts +0 -21
  187. package/src/engine/graphics/ecs/camera/filter/setup_filtered_camera_controller.d.ts.map +0 -1
  188. package/src/engine/graphics/ecs/camera/filter/setup_filtered_camera_controller.js +0 -79
  189. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.d.ts +0 -28
  190. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.d.ts.map +0 -1
  191. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js +0 -100
  192. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.d.ts +0 -36
  193. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.d.ts.map +0 -1
  194. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.js +0 -160
  195. /package/src/{engine/control/first-person/math → core/math/physics/spring}/Spring.d.ts +0 -0
  196. /package/src/{engine/control/first-person/math → core/math/physics/spring}/Spring.js +0 -0
  197. /package/src/{engine/control/first-person/math → core/math/physics/spring}/criticallyDampedSpring.d.ts +0 -0
  198. /package/src/{engine/control/first-person/math → core/math/physics/spring}/criticallyDampedSpring.js +0 -0
  199. /package/src/{engine/control/first-person/math → core/math/physics/spring}/dampedSpringStep.d.ts +0 -0
  200. /package/src/{engine/control/first-person/math → core/math/physics/spring}/dampedSpringStep.js +0 -0
@@ -0,0 +1,442 @@
1
+ import { assert } from "../../../../../core/assert.js";
2
+ import { quat3_multiply } from "../../../../../core/geom/3d/quaternion/quat3_multiply.js";
3
+ import Vector3 from "../../../../../core/geom/Vector3.js";
4
+ import { clamp } from "../../../../../core/math/clamp.js";
5
+ import { Spring } from "../../../../../core/math/physics/spring/Spring.js";
6
+ import { CameraRigDriver } from "../CameraRigDriver.js";
7
+ import { CAMERA_STATE_ROTATION } from "../CameraState.js";
8
+ import { camera_state_add_offset } from "./camera_state_add_offset.js";
9
+ import { CameraOffsetFrame } from "./CameraOffsetFrame.js";
10
+ import { camera_yaw_pitch_roll_rotation } from "./CameraYawPitchRollDriver.js";
11
+
12
+ /** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
13
+
14
+ /**
15
+ * A channel is settled when its squared displacement, and its squared velocity times the square of
16
+ * `max(half_life, MIN_SETTLE_TIMESCALE)`, are both below `(1 µm)²` (or `(1 µrad)²` for rotation), so a
17
+ * slow channel is not dropped before it reaches its peak.
18
+ */
19
+ const SETTLE_SQR = 1e-12;
20
+ const MIN_SETTLE_TIMESCALE = 0.1;
21
+
22
+ const MIN_HALF_LIFE = 1e-6;
23
+ const MIN_ZETA = 1e-3;
24
+ const MAX_ZETA = 10.0;
25
+ const DEFAULT_HALF_LIFE = 0.08;
26
+ const DEFAULT_KICK_ZETA = 0.7;
27
+ const DEFAULT_DISPLACE_ZETA = 1.0;
28
+
29
+ const scratch_q = new Float64Array(4);
30
+
31
+ /**
32
+ * One named impulse: six damped springs, three for the offset and pitch, yaw and roll, decaying to rest
33
+ * together.
34
+ */
35
+ class CameraImpulseChannel {
36
+ /** @type {string} */
37
+ source = "";
38
+
39
+ x = new Spring();
40
+ y = new Spring();
41
+ z = new Spring();
42
+
43
+ pitch = new Spring();
44
+ yaw = new Spring();
45
+ roll = new Spring();
46
+
47
+ half_life = DEFAULT_HALF_LIFE;
48
+
49
+ zeta = DEFAULT_DISPLACE_ZETA;
50
+
51
+ reset() {
52
+ this.source = "";
53
+
54
+ this.x.settle(0);
55
+ this.y.settle(0);
56
+ this.z.settle(0);
57
+
58
+ this.pitch.settle(0);
59
+ this.yaw.settle(0);
60
+ this.roll.settle(0);
61
+
62
+ this.half_life = DEFAULT_HALF_LIFE;
63
+ this.zeta = DEFAULT_DISPLACE_ZETA;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * @param {number} half_life
69
+ */
70
+ function assert_half_life(half_life) {
71
+ if (half_life !== undefined) {
72
+ assert.ok(
73
+ Number.isFinite(half_life) && half_life >= MIN_HALF_LIFE,
74
+ `half_life must be finite and >= ${MIN_HALF_LIFE}`,
75
+ );
76
+ }
77
+ }
78
+
79
+ /**
80
+ * @param {number} zeta
81
+ */
82
+ function assert_zeta(zeta) {
83
+ if (zeta !== undefined) {
84
+ assert.ok(
85
+ Number.isFinite(zeta) && zeta >= MIN_ZETA && zeta <= MAX_ZETA,
86
+ `zeta must be in [${MIN_ZETA}, ${MAX_ZETA}]`,
87
+ );
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Adds impulses to the camera: recoil, knockback, a landing, an explosion. Anyone may add one at any
93
+ * time, from a fixed step or a render frame, and it shows from the next update.
94
+ *
95
+ * - {@link kick} / {@link kickRotation}: a velocity on a named channel's damped springs, which rise and
96
+ * decay back to rest.
97
+ * - {@link displace} / {@link displaceRotation}: a displacement on a named channel, decaying back to
98
+ * rest.
99
+ * - {@link push} / {@link pushRotation}: a contribution to the next update only.
100
+ *
101
+ * Kicks and displacements on one channel name add onto that channel and keep its half life and damping
102
+ * unless new ones are given. A settled channel is recycled. The offset is in {@link frame}; rotation is
103
+ * always about the camera's own axes, pitch, yaw and roll as {@link CameraYawPitchRollDriver} reads them.
104
+ * A cut does not cancel them; {@link clear} does.
105
+ *
106
+ * @author Alex Goldring
107
+ * @copyright Company Named Limited (c) 2026
108
+ */
109
+ export class CameraImpulseDriver extends CameraRigDriver {
110
+ /**
111
+ * The axes offsets are in, see {@link CameraOffsetFrame}.
112
+ * @type {number}
113
+ */
114
+ frame = CameraOffsetFrame.Local;
115
+
116
+ /**
117
+ * The offset the last update added, in {@link frame}, for inspection.
118
+ * @readonly
119
+ * @type {Vector3}
120
+ */
121
+ offset = new Vector3();
122
+
123
+ /**
124
+ * The pitch, yaw and roll the last update added, radians, for inspection.
125
+ * @readonly
126
+ * @type {Vector3}
127
+ */
128
+ rotation = new Vector3();
129
+
130
+ /**
131
+ * Pushed for the next update: x, y, z, pitch, yaw, roll.
132
+ * @type {Float64Array}
133
+ */
134
+ #pushed = new Float64Array(6);
135
+
136
+ /**
137
+ * @type {CameraImpulseChannel[]}
138
+ */
139
+ #channels = [];
140
+
141
+ /**
142
+ * @type {CameraImpulseChannel[]}
143
+ */
144
+ #pool = [];
145
+
146
+ /**
147
+ * Channels currently active.
148
+ * @returns {number}
149
+ */
150
+ get channel_count() {
151
+ return this.#channels.length;
152
+ }
153
+
154
+ /**
155
+ * A cut leaves impulses alone: they are events others added, not this driver's history.
156
+ */
157
+ reset() {
158
+ }
159
+
160
+ /**
161
+ * Drop every channel and everything pushed.
162
+ */
163
+ clear() {
164
+ const channels = this.#channels;
165
+ const pool = this.#pool;
166
+
167
+ for (let i = channels.length - 1; i >= 0; i--) {
168
+ const channel = channels[i];
169
+ channel.reset();
170
+ pool.push(channel);
171
+ }
172
+
173
+ channels.length = 0;
174
+
175
+ this.#pushed.fill(0);
176
+ }
177
+
178
+ /**
179
+ * An offset for the next update only. `source` names it for debugging; the sum does not use it.
180
+ *
181
+ * @param {string} source
182
+ * @param {number} x
183
+ * @param {number} y
184
+ * @param {number} z
185
+ */
186
+ push(source, x, y, z) {
187
+ assert.ok(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z), "push: offset must be finite");
188
+
189
+ const pushed = this.#pushed;
190
+
191
+ pushed[0] += x;
192
+ pushed[1] += y;
193
+ pushed[2] += z;
194
+ }
195
+
196
+ /**
197
+ * A rotation for the next update only, radians.
198
+ *
199
+ * @param {string} source
200
+ * @param {number} pitch
201
+ * @param {number} yaw
202
+ * @param {number} roll
203
+ */
204
+ pushRotation(source, pitch, yaw, roll) {
205
+ assert.ok(Number.isFinite(pitch) && Number.isFinite(yaw) && Number.isFinite(roll), "pushRotation: angles must be finite");
206
+
207
+ const pushed = this.#pushed;
208
+
209
+ pushed[3] += pitch;
210
+ pushed[4] += yaw;
211
+ pushed[5] += roll;
212
+ }
213
+
214
+ /**
215
+ * A velocity on the offset springs of channel `source`, units per second.
216
+ *
217
+ * @param {string} source
218
+ * @param {number} vx
219
+ * @param {number} vy
220
+ * @param {number} vz
221
+ * @param {number} [half_life] seconds for the envelope to halve, 0.08 on a new channel
222
+ * @param {number} [zeta] damping ratio in (0, 10], 1 critical, below 1 rings; 0.7 on a new channel
223
+ */
224
+ kick(source, vx, vy, vz, half_life, zeta) {
225
+ assert.ok(Number.isFinite(vx) && Number.isFinite(vy) && Number.isFinite(vz), "kick: velocity must be finite");
226
+
227
+ if (vx === 0 && vy === 0 && vz === 0) {
228
+ return;
229
+ }
230
+
231
+ const channel = this.#channel(source, half_life, zeta, DEFAULT_KICK_ZETA);
232
+
233
+ channel.x.kick(vx);
234
+ channel.y.kick(vy);
235
+ channel.z.kick(vz);
236
+ }
237
+
238
+ /**
239
+ * An angular velocity on the rotation springs of channel `source`, radians per second.
240
+ *
241
+ * @param {string} source
242
+ * @param {number} pitch
243
+ * @param {number} yaw
244
+ * @param {number} roll
245
+ * @param {number} [half_life]
246
+ * @param {number} [zeta]
247
+ */
248
+ kickRotation(source, pitch, yaw, roll, half_life, zeta) {
249
+ assert.ok(Number.isFinite(pitch) && Number.isFinite(yaw) && Number.isFinite(roll), "kickRotation: velocity must be finite");
250
+
251
+ if (pitch === 0 && yaw === 0 && roll === 0) {
252
+ return;
253
+ }
254
+
255
+ const channel = this.#channel(source, half_life, zeta, DEFAULT_KICK_ZETA);
256
+
257
+ channel.pitch.kick(pitch);
258
+ channel.yaw.kick(yaw);
259
+ channel.roll.kick(roll);
260
+ }
261
+
262
+ /**
263
+ * A displacement on the offset springs of channel `source`.
264
+ *
265
+ * @param {string} source
266
+ * @param {number} x
267
+ * @param {number} y
268
+ * @param {number} z
269
+ * @param {number} [half_life] 0.08 on a new channel
270
+ * @param {number} [zeta] 1 on a new channel
271
+ */
272
+ displace(source, x, y, z, half_life, zeta) {
273
+ assert.ok(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z), "displace: displacement must be finite");
274
+
275
+ if (x === 0 && y === 0 && z === 0) {
276
+ return;
277
+ }
278
+
279
+ const channel = this.#channel(source, half_life, zeta, DEFAULT_DISPLACE_ZETA);
280
+
281
+ channel.x.value += x;
282
+ channel.y.value += y;
283
+ channel.z.value += z;
284
+ }
285
+
286
+ /**
287
+ * A rotation displacement on channel `source`, radians.
288
+ *
289
+ * @param {string} source
290
+ * @param {number} pitch
291
+ * @param {number} yaw
292
+ * @param {number} roll
293
+ * @param {number} [half_life]
294
+ * @param {number} [zeta]
295
+ */
296
+ displaceRotation(source, pitch, yaw, roll, half_life, zeta) {
297
+ assert.ok(Number.isFinite(pitch) && Number.isFinite(yaw) && Number.isFinite(roll), "displaceRotation: angles must be finite");
298
+
299
+ if (pitch === 0 && yaw === 0 && roll === 0) {
300
+ return;
301
+ }
302
+
303
+ const channel = this.#channel(source, half_life, zeta, DEFAULT_DISPLACE_ZETA);
304
+
305
+ channel.pitch.value += pitch;
306
+ channel.yaw.value += yaw;
307
+ channel.roll.value += roll;
308
+ }
309
+
310
+ /**
311
+ * @param {Float64Array} state
312
+ * @param {CameraRigContext} context
313
+ */
314
+ update(state, context) {
315
+ const dt = context.dt;
316
+
317
+ const pushed = this.#pushed;
318
+
319
+ let ox = pushed[0], oy = pushed[1], oz = pushed[2];
320
+ let rp = pushed[3], ry = pushed[4], rr = pushed[5];
321
+
322
+ pushed.fill(0);
323
+
324
+ const channels = this.#channels;
325
+ const pool = this.#pool;
326
+
327
+ for (let i = channels.length - 1; i >= 0; i--) {
328
+ const channel = channels[i];
329
+
330
+ const half_life = Math.max(channel.half_life, MIN_HALF_LIFE);
331
+ const zeta = clamp(channel.zeta, MIN_ZETA, MAX_ZETA);
332
+
333
+ if (dt > 0) {
334
+ channel.x.stepTo(0, half_life, zeta, dt);
335
+ channel.y.stepTo(0, half_life, zeta, dt);
336
+ channel.z.stepTo(0, half_life, zeta, dt);
337
+
338
+ channel.pitch.stepTo(0, half_life, zeta, dt);
339
+ channel.yaw.stepTo(0, half_life, zeta, dt);
340
+ channel.roll.stepTo(0, half_life, zeta, dt);
341
+ }
342
+
343
+ const x = channel.x, y = channel.y, z = channel.z;
344
+ const p = channel.pitch, w = channel.yaw, r = channel.roll;
345
+
346
+ const value_sqr = x.value * x.value + y.value * y.value + z.value * z.value
347
+ + p.value * p.value + w.value * w.value + r.value * r.value;
348
+
349
+ const velocity_sqr = x.velocity * x.velocity + y.velocity * y.velocity + z.velocity * z.velocity
350
+ + p.velocity * p.velocity + w.velocity * w.velocity + r.velocity * r.velocity;
351
+
352
+ const timescale = Math.max(half_life, MIN_SETTLE_TIMESCALE);
353
+
354
+ const future_sqr = velocity_sqr * timescale * timescale;
355
+
356
+ if (!Number.isFinite(value_sqr)
357
+ || !Number.isFinite(future_sqr)
358
+ || (value_sqr < SETTLE_SQR && future_sqr < SETTLE_SQR)) {
359
+
360
+ const last = channels.length - 1;
361
+
362
+ if (i !== last) {
363
+ channels[i] = channels[last];
364
+ }
365
+
366
+ channels.pop();
367
+ channel.reset();
368
+ pool.push(channel);
369
+
370
+ continue;
371
+ }
372
+
373
+ ox += x.value;
374
+ oy += y.value;
375
+ oz += z.value;
376
+
377
+ rp += p.value;
378
+ ry += w.value;
379
+ rr += r.value;
380
+ }
381
+
382
+ this.offset.set(ox, oy, oz);
383
+ this.rotation.set(rp, ry, rr);
384
+
385
+ if (ox !== 0 || oy !== 0 || oz !== 0) {
386
+ camera_state_add_offset(state, ox, oy, oz, this.frame);
387
+ }
388
+
389
+ if (rp !== 0 || ry !== 0 || rr !== 0) {
390
+ camera_yaw_pitch_roll_rotation(scratch_q, 0, ry, rp, rr);
391
+
392
+ quat3_multiply(
393
+ state, CAMERA_STATE_ROTATION,
394
+ state[CAMERA_STATE_ROTATION], state[CAMERA_STATE_ROTATION + 1],
395
+ state[CAMERA_STATE_ROTATION + 2], state[CAMERA_STATE_ROTATION + 3],
396
+ scratch_q[0], scratch_q[1], scratch_q[2], scratch_q[3]
397
+ );
398
+ }
399
+ }
400
+
401
+ /**
402
+ * The channel named `source`, made if there is none, with its half life and damping set where given.
403
+ *
404
+ * @param {string} source
405
+ * @param {number|undefined} half_life
406
+ * @param {number|undefined} zeta
407
+ * @param {number} default_zeta for a new channel
408
+ * @returns {CameraImpulseChannel}
409
+ */
410
+ #channel(source, half_life, zeta, default_zeta) {
411
+ assert_half_life(half_life);
412
+ assert_zeta(zeta);
413
+
414
+ const channels = this.#channels;
415
+
416
+ for (let i = 0; i < channels.length; i++) {
417
+ const channel = channels[i];
418
+
419
+ if (channel.source === source) {
420
+ if (half_life !== undefined) {
421
+ channel.half_life = Math.max(half_life, MIN_HALF_LIFE);
422
+ }
423
+
424
+ if (zeta !== undefined) {
425
+ channel.zeta = clamp(zeta, MIN_ZETA, MAX_ZETA);
426
+ }
427
+
428
+ return channel;
429
+ }
430
+ }
431
+
432
+ const channel = this.#pool.length > 0 ? this.#pool.pop() : new CameraImpulseChannel();
433
+
434
+ channel.source = source;
435
+ channel.half_life = half_life !== undefined ? Math.max(half_life, MIN_HALF_LIFE) : DEFAULT_HALF_LIFE;
436
+ channel.zeta = zeta !== undefined ? clamp(zeta, MIN_ZETA, MAX_ZETA) : default_zeta;
437
+
438
+ channels.push(channel);
439
+
440
+ return channel;
441
+ }
442
+ }
@@ -0,0 +1,32 @@
1
+ /** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
2
+ /**
3
+ * Turns the camera to face an entity, plus an offset in world axes, keeping world up as close to the
4
+ * camera's up as it can. The pivot moves to the point looked at.
5
+ *
6
+ * @author Alex Goldring
7
+ * @copyright Company Named Limited (c) 2026
8
+ */
9
+ export class CameraLookAtDriver extends CameraRigDriver {
10
+ /**
11
+ * The entity looked at; -1, or an entity that is gone, leaves the state as it is.
12
+ * @type {number}
13
+ */
14
+ entity: number;
15
+ /**
16
+ * Added to the entity's position, world axes.
17
+ * @type {number}
18
+ */
19
+ offset_x: number;
20
+ /**
21
+ * @type {number}
22
+ */
23
+ offset_y: number;
24
+ /**
25
+ * @type {number}
26
+ */
27
+ offset_z: number;
28
+ #private;
29
+ }
30
+ export type CameraRigContext = import("../CameraRigContext.js").CameraRigContext;
31
+ import { CameraRigDriver } from "../CameraRigDriver.js";
32
+ //# sourceMappingURL=CameraLookAtDriver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CameraLookAtDriver.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/camera/rig/drivers/CameraLookAtDriver.js"],"names":[],"mappings":"AAUA,oFAAoF;AAEpF;;;;;;GAMG;AACH;IACI;;;OAGG;IACH,QAFU,MAAM,CAEJ;IAEZ;;;OAGG;IACH,UAFU,MAAM,CAEH;IAEb;;OAEG;IACH,UAFU,MAAM,CAEH;IAEb;;OAEG;IACH,UAFU,MAAM,CAEH;;CAqChB;+BAnEa,OAAO,wBAAwB,EAAE,gBAAgB;gCAT/B,uBAAuB"}
@@ -0,0 +1,78 @@
1
+ import { quat3_look_rotation } from "../../../../../core/geom/3d/quaternion/quat3_look_rotation.js";
2
+ import { CameraRigDriver } from "../CameraRigDriver.js";
3
+ import {
4
+ CAMERA_STATE_PIVOT,
5
+ CAMERA_STATE_POSITION,
6
+ CAMERA_STATE_ROTATION,
7
+ CAMERA_STATE_SIZE
8
+ } from "../CameraState.js";
9
+ import { camera_state_read_entity } from "../camera_state_read_entity.js";
10
+
11
+ /** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
12
+
13
+ /**
14
+ * Turns the camera to face an entity, plus an offset in world axes, keeping world up as close to the
15
+ * camera's up as it can. The pivot moves to the point looked at.
16
+ *
17
+ * @author Alex Goldring
18
+ * @copyright Company Named Limited (c) 2026
19
+ */
20
+ export class CameraLookAtDriver extends CameraRigDriver {
21
+ /**
22
+ * The entity looked at; -1, or an entity that is gone, leaves the state as it is.
23
+ * @type {number}
24
+ */
25
+ entity = -1;
26
+
27
+ /**
28
+ * Added to the entity's position, world axes.
29
+ * @type {number}
30
+ */
31
+ offset_x = 0;
32
+
33
+ /**
34
+ * @type {number}
35
+ */
36
+ offset_y = 0;
37
+
38
+ /**
39
+ * @type {number}
40
+ */
41
+ offset_z = 0;
42
+
43
+ /**
44
+ * @type {Float64Array}
45
+ */
46
+ #scratch = new Float64Array(CAMERA_STATE_SIZE);
47
+
48
+ /**
49
+ * @param {Float64Array} state
50
+ * @param {CameraRigContext} context
51
+ */
52
+ update(state, context) {
53
+ const target = this.#scratch;
54
+
55
+ if (!camera_state_read_entity(target, context, this.entity)) {
56
+ return;
57
+ }
58
+
59
+ const tx = target[CAMERA_STATE_POSITION] + this.offset_x;
60
+ const ty = target[CAMERA_STATE_POSITION + 1] + this.offset_y;
61
+ const tz = target[CAMERA_STATE_POSITION + 2] + this.offset_z;
62
+
63
+ const fx = tx - state[CAMERA_STATE_POSITION];
64
+ const fy = ty - state[CAMERA_STATE_POSITION + 1];
65
+ const fz = tz - state[CAMERA_STATE_POSITION + 2];
66
+
67
+ if (fx === 0 && fy === 0 && fz === 0) {
68
+ // standing on the target, there is no direction to face
69
+ return;
70
+ }
71
+
72
+ quat3_look_rotation(state, CAMERA_STATE_ROTATION, fx, fy, fz, 0, 1, 0);
73
+
74
+ state[CAMERA_STATE_PIVOT] = tx;
75
+ state[CAMERA_STATE_PIVOT + 1] = ty;
76
+ state[CAMERA_STATE_PIVOT + 2] = tz;
77
+ }
78
+ }
@@ -0,0 +1,36 @@
1
+ /** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
2
+ /**
3
+ * Moves the camera by an offset in world axes, the camera's heading, or its own axes. A shoulder
4
+ * offset, an eye height above a body.
5
+ *
6
+ * @author Alex Goldring
7
+ * @copyright Company Named Limited (c) 2026
8
+ */
9
+ export class CameraOffsetDriver extends CameraRigDriver {
10
+ /**
11
+ * @type {number}
12
+ */
13
+ x: number;
14
+ /**
15
+ * @type {number}
16
+ */
17
+ y: number;
18
+ /**
19
+ * @type {number}
20
+ */
21
+ z: number;
22
+ /**
23
+ * The axes {@link x}, {@link y} and {@link z} are in, see {@link CameraOffsetFrame}.
24
+ * @type {number}
25
+ */
26
+ frame: number;
27
+ /**
28
+ * @param {number} x
29
+ * @param {number} y
30
+ * @param {number} z
31
+ */
32
+ set(x: number, y: number, z: number): void;
33
+ }
34
+ export type CameraRigContext = import("../CameraRigContext.js").CameraRigContext;
35
+ import { CameraRigDriver } from "../CameraRigDriver.js";
36
+ //# sourceMappingURL=CameraOffsetDriver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CameraOffsetDriver.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/camera/rig/drivers/CameraOffsetDriver.js"],"names":[],"mappings":"AAIA,oFAAoF;AAEpF;;;;;;GAMG;AACH;IACI;;OAEG;IACH,GAFU,MAAM,CAEV;IAEN;;OAEG;IACH,GAFU,MAAM,CAEV;IAEN;;OAEG;IACH,GAFU,MAAM,CAEV;IAEN;;;OAGG;IACH,OAFU,MAAM,CAEgB;IAEhC;;;;OAIG;IACH,OAJW,MAAM,KACN,MAAM,KACN,MAAM,QAMhB;CASJ;+BAjDa,OAAO,wBAAwB,EAAE,gBAAgB;gCAJ/B,uBAAuB"}
@@ -0,0 +1,54 @@
1
+ import { CameraRigDriver } from "../CameraRigDriver.js";
2
+ import { camera_state_add_offset } from "./camera_state_add_offset.js";
3
+ import { CameraOffsetFrame } from "./CameraOffsetFrame.js";
4
+
5
+ /** @typedef {import("../CameraRigContext.js").CameraRigContext} CameraRigContext */
6
+
7
+ /**
8
+ * Moves the camera by an offset in world axes, the camera's heading, or its own axes. A shoulder
9
+ * offset, an eye height above a body.
10
+ *
11
+ * @author Alex Goldring
12
+ * @copyright Company Named Limited (c) 2026
13
+ */
14
+ export class CameraOffsetDriver extends CameraRigDriver {
15
+ /**
16
+ * @type {number}
17
+ */
18
+ x = 0;
19
+
20
+ /**
21
+ * @type {number}
22
+ */
23
+ y = 0;
24
+
25
+ /**
26
+ * @type {number}
27
+ */
28
+ z = 0;
29
+
30
+ /**
31
+ * The axes {@link x}, {@link y} and {@link z} are in, see {@link CameraOffsetFrame}.
32
+ * @type {number}
33
+ */
34
+ frame = CameraOffsetFrame.Local;
35
+
36
+ /**
37
+ * @param {number} x
38
+ * @param {number} y
39
+ * @param {number} z
40
+ */
41
+ set(x, y, z) {
42
+ this.x = x;
43
+ this.y = y;
44
+ this.z = z;
45
+ }
46
+
47
+ /**
48
+ * @param {Float64Array} state
49
+ * @param {CameraRigContext} context
50
+ */
51
+ update(state, context) {
52
+ camera_state_add_offset(state, this.x, this.y, this.z, this.frame);
53
+ }
54
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The axes an offset is given in.
3
+ */
4
+ export type CameraOffsetFrame = number;
5
+ export namespace CameraOffsetFrame {
6
+ let World: number;
7
+ let Heading: number;
8
+ let Local: number;
9
+ }
10
+ //# sourceMappingURL=CameraOffsetFrame.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CameraOffsetFrame.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/camera/rig/drivers/CameraOffsetFrame.js"],"names":[],"mappings":";;;gCAIU,MAAM"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The axes an offset is given in.
3
+ *
4
+ * @readonly
5
+ * @enum {number}
6
+ */
7
+ export const CameraOffsetFrame = {
8
+ /**
9
+ * World axes.
10
+ */
11
+ World: 0,
12
+ /**
13
+ * The camera's current rotation with its pitch and roll taken out: +Y is world up and +Z the
14
+ * horizontal direction the camera faces. A body's frame, for a head that bobs and breathes the same
15
+ * way whether it looks up or down.
16
+ */
17
+ Heading: 1,
18
+ /**
19
+ * The camera's current rotation: +Z where it looks, +Y its up.
20
+ */
21
+ Local: 2,
22
+ };