@woosh/meep-engine 3.40.0 → 3.41.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 (203) hide show
  1. package/package.json +1 -1
  2. package/src/core/geom/3d/quaternion/swing_twist_clamp.d.ts +24 -0
  3. package/src/core/geom/3d/quaternion/swing_twist_clamp.d.ts.map +1 -0
  4. package/src/core/geom/3d/quaternion/swing_twist_clamp.js +62 -0
  5. package/src/core/geom/3d/quaternion/swing_twist_compose.d.ts +15 -0
  6. package/src/core/geom/3d/quaternion/swing_twist_compose.d.ts.map +1 -0
  7. package/src/core/geom/3d/quaternion/swing_twist_compose.js +36 -0
  8. package/src/core/geom/3d/quaternion/swing_twist_error.d.ts +39 -0
  9. package/src/core/geom/3d/quaternion/swing_twist_error.d.ts.map +1 -0
  10. package/src/core/geom/3d/quaternion/swing_twist_error.js +85 -0
  11. package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.d.ts +11 -6
  12. package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.d.ts.map +1 -1
  13. package/src/core/geom/vec3/v3_rigid_align_paired_unit_vectors.js +27 -13
  14. package/src/core/math/linalg/eigen/matrix_symmetric_4x4_eigen.d.ts +25 -0
  15. package/src/core/math/linalg/eigen/matrix_symmetric_4x4_eigen.d.ts.map +1 -0
  16. package/src/core/math/linalg/eigen/matrix_symmetric_4x4_eigen.js +166 -0
  17. package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.d.ts +5 -3
  18. package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.d.ts.map +1 -1
  19. package/src/core/math/linalg/eigen/matrix_top_eigenvector_power_iteration.js +5 -3
  20. package/src/engine/animation/curve/AnimationCurve.d.ts +3 -0
  21. package/src/engine/animation/curve/AnimationCurve.d.ts.map +1 -1
  22. package/src/engine/animation/curve/AnimationCurve.js +6 -1
  23. package/src/engine/ecs/EntityManager.d.ts +9 -1
  24. package/src/engine/ecs/EntityManager.d.ts.map +1 -1
  25. package/src/engine/ecs/EntityManager.js +26 -27
  26. package/src/engine/ecs/gpu/GPUStateAuthority.d.ts +20 -0
  27. package/src/engine/ecs/gpu/GPUStateAuthority.d.ts.map +1 -1
  28. package/src/engine/ecs/gpu/GPUStateAuthority.js +21 -0
  29. package/src/engine/ecs/gpu/GPU_AUTHORITY_EVENT_HOLD_CHANGE.d.ts +13 -0
  30. package/src/engine/ecs/gpu/GPU_AUTHORITY_EVENT_HOLD_CHANGE.d.ts.map +1 -0
  31. package/src/engine/ecs/gpu/GPU_AUTHORITY_EVENT_HOLD_CHANGE.js +12 -0
  32. package/src/engine/ecs/gpu/gpu_authority_grant.d.ts +6 -0
  33. package/src/engine/ecs/gpu/gpu_authority_grant.d.ts.map +1 -1
  34. package/src/engine/ecs/gpu/gpu_authority_grant.js +7 -1
  35. package/src/engine/ecs/gpu/gpu_authority_held.d.ts +14 -0
  36. package/src/engine/ecs/gpu/gpu_authority_held.d.ts.map +1 -0
  37. package/src/engine/ecs/gpu/gpu_authority_held.js +23 -0
  38. package/src/engine/ecs/gpu/gpu_authority_hold.d.ts +23 -0
  39. package/src/engine/ecs/gpu/gpu_authority_hold.d.ts.map +1 -0
  40. package/src/engine/ecs/gpu/gpu_authority_hold.js +41 -0
  41. package/src/engine/ecs/gpu/gpu_authority_unhold.d.ts +14 -0
  42. package/src/engine/ecs/gpu/gpu_authority_unhold.d.ts.map +1 -0
  43. package/src/engine/ecs/gpu/gpu_authority_unhold.js +32 -0
  44. package/src/engine/ecs/ik/IKGoal.d.ts +59 -0
  45. package/src/engine/ecs/ik/IKGoal.d.ts.map +1 -0
  46. package/src/engine/ecs/ik/IKGoal.js +83 -0
  47. package/src/engine/ecs/ik/IKGoalSystem.d.ts +75 -0
  48. package/src/engine/ecs/ik/IKGoalSystem.d.ts.map +1 -0
  49. package/src/engine/ecs/ik/IKGoalSystem.js +1456 -0
  50. package/src/engine/ecs/ik/PLAN.md +179 -0
  51. package/src/engine/ecs/speaker/VoiceSystem.d.ts +2 -2
  52. package/src/engine/ecs/speaker/VoiceSystem.d.ts.map +1 -1
  53. package/src/engine/ecs/storage/BinaryBufferSerializer.d.ts.map +1 -1
  54. package/src/engine/ecs/storage/BinaryBufferSerializer.js +4 -5
  55. package/src/engine/ecs/storage/binary/SERIALIZATION_COVERAGE.md +7 -3
  56. package/src/engine/ecs/storage/populateEngineSerializationRegistry.d.ts.map +1 -1
  57. package/src/engine/ecs/storage/populateEngineSerializationRegistry.js +1 -2
  58. package/src/engine/ecs/system/orderSystemsByDeclaredAccess.d.ts +33 -0
  59. package/src/engine/ecs/system/orderSystemsByDeclaredAccess.d.ts.map +1 -0
  60. package/src/engine/ecs/system/orderSystemsByDeclaredAccess.js +282 -0
  61. package/src/engine/ecs/transform/T64WorldCache.js +139 -139
  62. package/src/engine/ecs/transform/t64_evaluate_local.d.ts +25 -0
  63. package/src/engine/ecs/transform/t64_evaluate_local.d.ts.map +1 -0
  64. package/src/engine/ecs/transform/t64_evaluate_local.js +35 -0
  65. package/src/engine/ecs/transform/t64_evaluate_world.d.ts +5 -3
  66. package/src/engine/ecs/transform/t64_evaluate_world.d.ts.map +1 -1
  67. package/src/engine/ecs/transform/t64_evaluate_world.js +128 -126
  68. package/src/engine/graphics3/AnimationGraphSystem.d.ts +2 -0
  69. package/src/engine/graphics3/AnimationGraphSystem.d.ts.map +1 -1
  70. package/src/engine/graphics3/AnimationGraphSystem.js +337 -329
  71. package/src/engine/graphics3/AnimationSystem.d.ts +2 -0
  72. package/src/engine/graphics3/AnimationSystem.d.ts.map +1 -1
  73. package/src/engine/graphics3/AnimationSystem.js +360 -352
  74. package/src/engine/physics/cloth/MEASUREMENTS.md +130 -0
  75. package/src/engine/physics/cloth/PLAN.md +16 -1
  76. package/src/engine/physics/cloth/ecs/ClothColliderSystem.d.ts +5 -6
  77. package/src/engine/physics/cloth/ecs/ClothColliderSystem.d.ts.map +1 -1
  78. package/src/engine/physics/cloth/ecs/ClothColliderSystem.js +5 -6
  79. package/src/engine/physics/cloth/ecs/ClothInstance.d.ts +4 -7
  80. package/src/engine/physics/cloth/ecs/ClothInstance.d.ts.map +1 -1
  81. package/src/engine/physics/cloth/ecs/ClothInstance.js +4 -7
  82. package/src/engine/physics/cloth/ecs/ClothSystem.d.ts +4 -3
  83. package/src/engine/physics/cloth/ecs/ClothSystem.d.ts.map +1 -1
  84. package/src/engine/physics/cloth/ecs/ClothSystem.js +4 -3
  85. package/src/engine/physics/cloth/ecs/ClothWorld.d.ts.map +1 -1
  86. package/src/engine/physics/cloth/ecs/ClothWorld.js +10 -0
  87. package/src/engine/physics/cloth/ecs/cloth_seed_rig.d.ts +24 -24
  88. package/src/engine/physics/cloth/ecs/cloth_seed_rig.d.ts.map +1 -1
  89. package/src/engine/physics/cloth/ecs/cloth_seed_rig.js +46 -43
  90. package/src/engine/physics/cloth/ecs/cloth_write_back.d.ts +1 -1
  91. package/src/engine/physics/cloth/ecs/cloth_write_back.js +1 -1
  92. package/src/engine/physics/constraint/solve_constraints.d.ts +0 -35
  93. package/src/engine/physics/constraint/solve_constraints.d.ts.map +1 -1
  94. package/src/engine/physics/constraint/solve_constraints.js +1 -83
  95. package/src/engine/physics/ecs/ContactProbe.d.ts +73 -0
  96. package/src/engine/physics/ecs/ContactProbe.d.ts.map +1 -0
  97. package/src/engine/physics/ecs/ContactProbe.js +103 -0
  98. package/src/engine/physics/ecs/ContactProbeSystem.d.ts +44 -0
  99. package/src/engine/physics/ecs/ContactProbeSystem.d.ts.map +1 -0
  100. package/src/engine/physics/ecs/ContactProbeSystem.js +397 -0
  101. package/src/engine/physics/fluid/ecs/FluidComponent.d.ts +1 -1
  102. package/src/engine/physics/fluid/ecs/FluidComponent.js +1 -1
  103. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  104. package/src/engine/physics/inverse_kinematics/frame_fabrik/FrameFabrikProblem.d.ts +205 -0
  105. package/src/engine/physics/inverse_kinematics/frame_fabrik/FrameFabrikProblem.d.ts.map +1 -0
  106. package/src/engine/physics/inverse_kinematics/frame_fabrik/FrameFabrikProblem.js +245 -0
  107. package/src/engine/physics/inverse_kinematics/frame_fabrik/frame_fabrik_limit_from_joint.d.ts +21 -0
  108. package/src/engine/physics/inverse_kinematics/frame_fabrik/frame_fabrik_limit_from_joint.d.ts.map +1 -0
  109. package/src/engine/physics/inverse_kinematics/frame_fabrik/frame_fabrik_limit_from_joint.js +63 -0
  110. package/src/engine/physics/inverse_kinematics/frame_fabrik/frame_fabrik_solve.d.ts +33 -0
  111. package/src/engine/physics/inverse_kinematics/frame_fabrik/frame_fabrik_solve.d.ts.map +1 -0
  112. package/src/engine/physics/inverse_kinematics/frame_fabrik/frame_fabrik_solve.js +874 -0
  113. package/src/engine/physics/inverse_kinematics/joint_hinge_mid_axis.d.ts +27 -0
  114. package/src/engine/physics/inverse_kinematics/joint_hinge_mid_axis.d.ts.map +1 -0
  115. package/src/engine/physics/inverse_kinematics/joint_hinge_mid_axis.js +77 -0
  116. package/src/engine/physics/inverse_kinematics/two_bone_path_solve.d.ts +36 -0
  117. package/src/engine/physics/inverse_kinematics/two_bone_path_solve.d.ts.map +1 -0
  118. package/src/engine/physics/inverse_kinematics/two_bone_path_solve.js +97 -0
  119. package/src/engine/physics/inverse_kinematics/two_joint_ik.d.ts +33 -11
  120. package/src/engine/physics/inverse_kinematics/two_joint_ik.d.ts.map +1 -1
  121. package/src/engine/physics/inverse_kinematics/two_joint_ik.js +158 -67
  122. package/src/shade/renderer/animation/ANIMATION_TRACK_BINDING_STRUCT.d.ts.map +1 -1
  123. package/src/shade/renderer/animation/ANIMATION_TRACK_BINDING_STRUCT.js +10 -1
  124. package/src/shade/renderer/animation/GPUAnimationManager.d.ts +10 -4
  125. package/src/shade/renderer/animation/GPUAnimationManager.d.ts.map +1 -1
  126. package/src/shade/renderer/animation/GPUAnimationManager.js +251 -23
  127. package/src/shade/renderer/animation/POSE_ACCUMULATOR_LAYOUT.d.ts +12 -4
  128. package/src/shade/renderer/animation/POSE_ACCUMULATOR_LAYOUT.d.ts.map +1 -1
  129. package/src/shade/renderer/animation/POSE_ACCUMULATOR_LAYOUT.js +12 -4
  130. package/src/shade/renderer/animation/chunk_pose_accumulator.d.ts.map +1 -1
  131. package/src/shade/renderer/animation/chunk_pose_accumulator.js +14 -1
  132. package/src/shade/renderer/animation/pose/PoseChannelIndex.d.ts +78 -0
  133. package/src/shade/renderer/animation/pose/PoseChannelIndex.d.ts.map +1 -0
  134. package/src/shade/renderer/animation/pose/PoseChannelIndex.js +274 -0
  135. package/src/shade/renderer/animation/pose/PosePlayback.d.ts +40 -3
  136. package/src/shade/renderer/animation/pose/PosePlayback.d.ts.map +1 -1
  137. package/src/shade/renderer/animation/pose/PosePlayback.js +77 -3
  138. package/src/shade/renderer/animation/pose/pose_evaluate_local.d.ts +21 -3
  139. package/src/shade/renderer/animation/pose/pose_evaluate_local.d.ts.map +1 -1
  140. package/src/shade/renderer/animation/pose/pose_evaluate_local.js +79 -11
  141. package/src/shade/renderer/animation/shader_animation_apply.js +1 -1
  142. package/src/shade/renderer/animation/shader_animation_pose_resolve.d.ts +3 -2
  143. package/src/shade/renderer/animation/shader_animation_pose_resolve.d.ts.map +1 -1
  144. package/src/shade/renderer/animation/shader_animation_pose_resolve.js +187 -176
  145. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
  146. package/src/shade/renderer/object_property/chunk_write_object_property.d.ts +3 -1
  147. package/src/shade/renderer/object_property/chunk_write_object_property.d.ts.map +1 -1
  148. package/src/shade/renderer/object_property/chunk_write_object_property.js +5 -2
  149. package/src/shade/renderer/object_property/chunk_write_object_property_node3d.d.ts +4 -0
  150. package/src/shade/renderer/object_property/chunk_write_object_property_node3d.d.ts.map +1 -1
  151. package/src/shade/renderer/object_property/chunk_write_object_property_node3d.js +6 -1
  152. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  153. package/src/shade/renderer/scene/optimization/geometry/geometry_deduplicate.d.ts +1 -1
  154. package/src/shade/renderer/scene/optimization/geometry/geometry_deduplicate.d.ts.map +1 -1
  155. package/src/shade/renderer/scene/optimization/geometry/geometry_deduplicate.js +135 -73
  156. package/src/shade/renderer/scene/optimization/geometry/internal/cover_greedy.d.ts +7 -0
  157. package/src/shade/renderer/scene/optimization/geometry/internal/cover_greedy.d.ts.map +1 -1
  158. package/src/shade/renderer/scene/optimization/geometry/internal/cover_greedy.js +29 -1
  159. package/src/shade/renderer/scene/optimization/geometry/internal/face_neighbourhood_hash.d.ts +19 -0
  160. package/src/shade/renderer/scene/optimization/geometry/internal/face_neighbourhood_hash.d.ts.map +1 -0
  161. package/src/shade/renderer/scene/optimization/geometry/internal/face_neighbourhood_hash.js +167 -0
  162. package/src/shade/renderer/scene/optimization/geometry/internal/neighbourhood_anchor_index.d.ts +25 -0
  163. package/src/shade/renderer/scene/optimization/geometry/internal/neighbourhood_anchor_index.d.ts.map +1 -0
  164. package/src/shade/renderer/scene/optimization/geometry/internal/neighbourhood_anchor_index.js +124 -0
  165. package/src/shade/renderer/scene/optimization/geometry/internal/seed_correspondence_from_face_pair.d.ts +19 -0
  166. package/src/shade/renderer/scene/optimization/geometry/internal/seed_correspondence_from_face_pair.d.ts.map +1 -0
  167. package/src/shade/renderer/scene/optimization/geometry/internal/seed_correspondence_from_face_pair.js +48 -0
  168. package/src/shade/renderer/scene/rows/GPUSceneRows.d.ts +17 -1
  169. package/src/shade/renderer/scene/rows/GPUSceneRows.d.ts.map +1 -1
  170. package/src/shade/renderer/scene/rows/GPUSceneRows.js +29 -3
  171. package/src/engine/ecs/ik/IKConstraint.d.ts +0 -52
  172. package/src/engine/ecs/ik/IKConstraint.d.ts.map +0 -1
  173. package/src/engine/ecs/ik/IKConstraint.js +0 -95
  174. package/src/engine/ecs/ik/IKProblem.d.ts +0 -45
  175. package/src/engine/ecs/ik/IKProblem.d.ts.map +0 -1
  176. package/src/engine/ecs/ik/IKProblem.js +0 -58
  177. package/src/engine/ecs/ik/IKSolver.d.ts +0 -8
  178. package/src/engine/ecs/ik/IKSolver.d.ts.map +0 -1
  179. package/src/engine/ecs/ik/IKSolver.js +0 -9
  180. package/src/engine/ecs/ik/InverseKinematics.d.ts +0 -48
  181. package/src/engine/ecs/ik/InverseKinematics.d.ts.map +0 -1
  182. package/src/engine/ecs/ik/InverseKinematics.js +0 -119
  183. package/src/engine/ecs/ik/InverseKinematicsSerializationAdapter.d.ts +0 -19
  184. package/src/engine/ecs/ik/InverseKinematicsSerializationAdapter.d.ts.map +0 -1
  185. package/src/engine/ecs/ik/InverseKinematicsSerializationAdapter.js +0 -72
  186. package/src/engine/ecs/ik/InverseKinematicsSystem.d.ts +0 -54
  187. package/src/engine/ecs/ik/InverseKinematicsSystem.d.ts.map +0 -1
  188. package/src/engine/ecs/ik/InverseKinematicsSystem.js +0 -212
  189. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.d.ts +0 -8
  190. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.d.ts.map +0 -1
  191. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +0 -153
  192. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.d.ts +0 -5
  193. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.d.ts.map +0 -1
  194. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +0 -120
  195. package/src/engine/ecs/ik/ik_bone_chain.d.ts +0 -64
  196. package/src/engine/ecs/ik/ik_bone_chain.d.ts.map +0 -1
  197. package/src/engine/ecs/ik/ik_bone_chain.js +0 -142
  198. package/src/engine/ecs/ik/ik_probe_terrain_contact.d.ts +0 -42
  199. package/src/engine/ecs/ik/ik_probe_terrain_contact.d.ts.map +0 -1
  200. package/src/engine/ecs/ik/ik_probe_terrain_contact.js +0 -123
  201. package/src/engine/ecs/ik/ik_write_local_rotation.d.ts +0 -18
  202. package/src/engine/ecs/ik/ik_write_local_rotation.d.ts.map +0 -1
  203. package/src/engine/ecs/ik/ik_write_local_rotation.js +0 -32
@@ -1,329 +1,337 @@
1
- import { assert } from "../../core/assert.js";
2
- import { PosePlayback } from "../../shade/renderer/animation/pose/PosePlayback.js";
3
- import { System } from "../ecs/System.js";
4
- import { SGMesh } from "../graphics/ecs/mesh-v2/aggregate/SGMesh.js";
5
- import { AnimationGraphController } from "./animation/AnimationGraphController.js";
6
- import { write_graph_playback } from "./animation/write_graph_playback.js";
7
- import {
8
- register_instance_clips,
9
- unregister_instance_clips
10
- } from "./register_instance_animation.js";
11
-
12
- /**
13
- * Drives every entity's {@link AnimationGraphController}: runs its clock, and tells the renderer
14
- * what its clips weigh and where they are playing.
15
- *
16
- * **It is the CPU that plays the animation and the GPU that draws it.** Shade can advance a clip
17
- * itself, and this never asks it to — `AnimationClipFlags.Playing` is left clear and every audible
18
- * clip's time is written down each frame from the controller's own clock. That is I-4: the pose
19
- * gameplay reads (sockets, effect anchors, projectile spawns) and the pose on the screen have to be
20
- * the same pose, and they cannot be if two clocks are running.
21
- *
22
- * **Nothing here is culled.** The legacy system skipped entities smaller than 32 px², which let
23
- * camera framing decide whether a footstep effect or an ability release ever happened. The clock and
24
- * its notifications are gameplay and run for every entity whose model has arrived; what may be
25
- * culled is drawing, and drawing is Shade's to cull.
26
- */
27
- export class AnimationGraphSystem extends System {
28
- /**
29
- * @type {GraphicsEngine}
30
- */
31
- #graphics;
32
-
33
- /**
34
- * The system that owns the scene, the model instances, and the ids the animation manager issued
35
- * for them.
36
- *
37
- * @type {MeshSystem}
38
- */
39
- #meshes;
40
-
41
- /**
42
- * @type {Map<number, {controller: AnimationGraphController, instance: PrefabInstance|null, clip_registration: InstanceClipRegistration|null, slots: Int32Array, played_slots: Int32Array, clip_ids: Int32Array, weights: Float32Array, poses: PosePlayback[]}>}
43
- */
44
- #entries = new Map();
45
-
46
- /**
47
- * @param {GraphicsEngine} graphics
48
- * @param {MeshSystem} meshes
49
- */
50
- constructor(graphics, meshes) {
51
- super();
52
-
53
- assert.defined(graphics, 'graphics');
54
- assert.defined(meshes, 'meshes');
55
-
56
- this.#graphics = graphics;
57
- this.#meshes = meshes;
58
-
59
- this.dependencies = [AnimationGraphController, SGMesh];
60
- }
61
-
62
- /**
63
- * @param {AnimationGraphController} controller
64
- * @param {SGMesh} model
65
- * @param {number} entity
66
- */
67
- link(controller, model, entity) {
68
- this.#entries.set(entity, {
69
- controller,
70
- instance: null,
71
- clip_registration: null,
72
- slots: new Int32Array(0),
73
- played_slots: new Int32Array(0),
74
- clip_ids: new Int32Array(0),
75
- weights: new Float32Array(0),
76
- poses: []
77
- });
78
- }
79
-
80
- /**
81
- * What the entity's model is playing, in the form the CPU pose evaluator takes: one entry per
82
- * clip **this graph names**, at the weight and the time the renderer has been given.
83
- *
84
- * **The clips the graph does not name are not here, because they are not registered** (D37).
85
- * The GPU's accumulator marks a joint dirty for every bound clip that writes to it, weight and
86
- * all — so a bound clip at weight zero resolves the joints only it drives to zero rather than
87
- * leaving them at rest. The answer is not to hand those clips to the evaluator so it can make
88
- * the same mistake; it is not to bind them. What the graph never names, nothing plays, and the
89
- * joints it alone would have driven stay where the model rests.
90
- *
91
- * A clip the graph names but is not currently playing **is** here, at weight zero, because it is
92
- * bound and the accumulator does see it.
93
- *
94
- * The entries are this system's own and are rewritten by the next call, which is what keeps a
95
- * query on a per-frame path from allocating.
96
- *
97
- * @param {PosePlayback[]} target appended to
98
- * @param {number} entity
99
- * @returns {boolean} whether this system is driving the entity — `false` for one with no
100
- * {@link AnimationGraphController}, and for one whose model has not arrived
101
- */
102
- write_pose_playbacks(target, entity) {
103
- const entry = this.#entries.get(entity);
104
-
105
- if (entry === undefined || entry.instance === null) {
106
- return false;
107
- }
108
-
109
- const clips = entry.instance.clips;
110
- const poses = entry.poses;
111
- const played = entry.played_slots;
112
-
113
- for (let i = 0; i < played.length; i++) {
114
- const slot = played[i];
115
- const pose = poses[slot];
116
-
117
- pose.clip = clips[slot];
118
- pose.weight = 0;
119
- pose.time = 0;
120
- }
121
-
122
- const controller = entry.controller;
123
- const slots = entry.slots;
124
- const weights = controller.blendState.weights;
125
-
126
- for (let i = 0; i < slots.length; i++) {
127
- const pose = poses[slots[i]];
128
- const weight = weights[i];
129
-
130
- // assignment rather than accumulation, and it matters only where two of the graph's
131
- // clips are one clip of the model: the renderer is written to in this order too, so the
132
- // last of them is what it holds
133
- pose.weight = weight;
134
-
135
- if (weight > 0) {
136
- pose.time = controller.clip_time(i);
137
- }
138
- }
139
-
140
- // once each, however many of the graph's clips named it — the renderer holds one row for it
141
- for (let i = 0; i < played.length; i++) {
142
- target.push(poses[played[i]]);
143
- }
144
-
145
- return true;
146
- }
147
-
148
- /**
149
- * @param {AnimationGraphController} controller
150
- * @param {SGMesh} model
151
- * @param {number} entity
152
- */
153
- unlink(controller, model, entity) {
154
- controller.unlink();
155
-
156
- const entry = this.#entries.get(entity);
157
-
158
- if (entry !== undefined) {
159
- this.#release_clips(entry);
160
- }
161
-
162
- this.#entries.delete(entity);
163
- }
164
-
165
- async shutdown(entityManager) {
166
- for (const entry of this.#entries.values()) {
167
- entry.controller.unlink();
168
-
169
- this.#release_clips(entry);
170
- }
171
-
172
- this.#entries.clear();
173
- }
174
-
175
- /**
176
- * Give this entity's clips back, if the manager that issued them is still the one running.
177
- *
178
- * **An id may only be handed back to the manager that issued it.** A renderer restart replaces
179
- * the GPU scene context and voids every id it gave out, so a registration stamped with a context
180
- * that is no longer current is forgotten rather than returned — returning it would corrupt a
181
- * stranger's table. Same rule as {@link unregister_instance_animation}, same `===`.
182
- *
183
- * @param {object} entry
184
- */
185
- #release_clips(entry) {
186
- const registration = entry.clip_registration;
187
-
188
- if (registration === null) {
189
- return;
190
- }
191
-
192
- if (registration.context === this.#graphics.scene_context(this.#meshes.scene)) {
193
- unregister_instance_clips(registration);
194
- }
195
-
196
- entry.clip_registration = null;
197
- }
198
-
199
- /**
200
- * @param {number} time_delta_seconds
201
- */
202
- update(time_delta_seconds) {
203
- const ecd = this.entityManager.dataset;
204
-
205
- const context = this.#graphics.scene_context(this.#meshes.scene);
206
-
207
- // No device — before the first start, and again after a stop. The clocks still run: a unit
208
- // that fires an ability while the renderer is being replaced still fires it.
209
- const manager = context === null ? null : context.animation_manager;
210
-
211
- for (const [entity, entry] of this.#entries) {
212
- const instance = this.#meshes.instance_of(entity);
213
-
214
- if (instance === null) {
215
- // the model has not arrived, and its clips are what say how long they run
216
- continue;
217
- }
218
-
219
- if (instance !== entry.instance) {
220
- this.#bind_model(entry, entity, instance, ecd);
221
- }
222
-
223
- entry.controller.tick(time_delta_seconds);
224
-
225
- if (context === null) {
226
- continue;
227
- }
228
-
229
- /*
230
- Registered against the context that is running now. A renderer restart builds a new one
231
- and voids every id the old gave out, and the stamp on the registration is how that is
232
- noticed — in one comparison, without depending on when anything last ran.
233
- */
234
- if (entry.clip_registration === null || entry.clip_registration.context !== context) {
235
- this.#bind_gpu(entry, instance, context);
236
- }
237
-
238
- write_graph_playback(manager, entry.controller, entry.clip_ids, entry.weights);
239
- }
240
- }
241
-
242
- /**
243
- * Bind the graph to a model: work out which of the model's clips each of the graph's clips is,
244
- * how long each of them runs, and start the graph on that.
245
- *
246
- * @param {object} entry
247
- * @param {number} entity
248
- * @param {PrefabInstance} instance
249
- * @param {EntityComponentDataset} ecd
250
- */
251
- #bind_model(entry, entity, instance, ecd) {
252
- const clip_index = entry.controller.def.clipIndex;
253
- const clip_count = clip_index.length;
254
-
255
- const slots = new Int32Array(clip_count);
256
- const durations = new Float64Array(clip_count);
257
-
258
- for (let i = 0; i < clip_count; i++) {
259
- const name = clip_index[i].name;
260
-
261
- const slot = instance.clips.findIndex(clip => clip.name === name);
262
-
263
- if (slot === -1) {
264
- throw new Error(`Animation clip '${name}' is not in the model`);
265
- }
266
-
267
- slots[i] = slot;
268
- durations[i] = instance.clips[slot].duration;
269
- }
270
-
271
- entry.controller.unlink();
272
- entry.controller.link(entity, ecd, durations);
273
-
274
- entry.instance = instance;
275
- entry.slots = slots;
276
-
277
- /*
278
- The distinct clips of the model this graph plays. Two states can name one clip — an idle a
279
- hurt returns to, say — and it is one row on the GPU either way, so it is one entry here:
280
- registered once, reported to the pose evaluator once.
281
- */
282
- const played = [];
283
-
284
- for (let i = 0; i < clip_count; i++) {
285
- if (played.indexOf(slots[i]) === -1) {
286
- played.push(slots[i]);
287
- }
288
- }
289
-
290
- entry.played_slots = Int32Array.from(played);
291
-
292
- entry.clip_ids = new Int32Array(clip_count);
293
- entry.weights = new Float32Array(clip_count).fill(-1);
294
- entry.poses = instance.clips.map(() => new PosePlayback());
295
-
296
- // ids the manager issued for the model that was here before name clips this one does not
297
- // have
298
- this.#release_clips(entry);
299
- }
300
-
301
- /**
302
- * Make this graph's clips playable, and take up the ids that come back.
303
- *
304
- * **Only the clips the graph names are registered** (D37), so there is nothing to silence: a
305
- * clip of the model no state plays is never bound, never marks a joint, and leaves the joints
306
- * only it would have driven at rest. What this used to do instead — register everything and then
307
- * write a zero weight over the surplus — kept them bound, and a bound clip at weight zero
308
- * resolves its joints to zero rather than to the model's own pose.
309
- *
310
- * @param {object} entry
311
- * @param {PrefabInstance} instance
312
- * @param {GPUSceneContext} context
313
- */
314
- #bind_gpu(entry, instance, context) {
315
- const registration = register_instance_clips(context, instance, entry.played_slots);
316
-
317
- const slots = entry.slots;
318
- const clip_ids = entry.clip_ids;
319
-
320
- for (let i = 0; i < slots.length; i++) {
321
- clip_ids[i] = registration.ids[slots[i]];
322
- }
323
-
324
- entry.clip_registration = registration;
325
-
326
- // whatever the last renderer was told is not what this one knows
327
- entry.weights.fill(-1);
328
- }
329
- }
1
+ import { assert } from "../../core/assert.js";
2
+ import { ResourceAccessKind } from "../../core/model/ResourceAccessKind.js";
3
+ import { ResourceAccessSpecification } from "../../core/model/ResourceAccessSpecification.js";
4
+ import { PosePlayback } from "../../shade/renderer/animation/pose/PosePlayback.js";
5
+ import { System } from "../ecs/System.js";
6
+ import { SGMesh } from "../graphics/ecs/mesh-v2/aggregate/SGMesh.js";
7
+ import { AnimationGraphController } from "./animation/AnimationGraphController.js";
8
+ import { write_graph_playback } from "./animation/write_graph_playback.js";
9
+ import {
10
+ register_instance_clips,
11
+ unregister_instance_clips
12
+ } from "./register_instance_animation.js";
13
+
14
+ /**
15
+ * Drives every entity's {@link AnimationGraphController}: runs its clock, and tells the renderer
16
+ * what its clips weigh and where they are playing.
17
+ *
18
+ * **It is the CPU that plays the animation and the GPU that draws it.** Shade can advance a clip
19
+ * itself, and this never asks it to — `AnimationClipFlags.Playing` is left clear and every audible
20
+ * clip's time is written down each frame from the controller's own clock. That is I-4: the pose
21
+ * gameplay reads (sockets, effect anchors, projectile spawns) and the pose on the screen have to be
22
+ * the same pose, and they cannot be if two clocks are running.
23
+ *
24
+ * **Nothing here is culled.** The legacy system skipped entities smaller than 32 px², which let
25
+ * camera framing decide whether a footstep effect or an ability release ever happened. The clock and
26
+ * its notifications are gameplay and run for every entity whose model has arrived; what may be
27
+ * culled is drawing, and drawing is Shade's to cull.
28
+ */
29
+ export class AnimationGraphSystem extends System {
30
+ /**
31
+ * @type {GraphicsEngine}
32
+ */
33
+ #graphics;
34
+
35
+ /**
36
+ * The system that owns the scene, the model instances, and the ids the animation manager issued
37
+ * for them.
38
+ *
39
+ * @type {MeshSystem}
40
+ */
41
+ #meshes;
42
+
43
+ /**
44
+ * @type {Map<number, {controller: AnimationGraphController, instance: PrefabInstance|null, clip_registration: InstanceClipRegistration|null, slots: Int32Array, played_slots: Int32Array, clip_ids: Int32Array, weights: Float32Array, poses: PosePlayback[]}>}
45
+ */
46
+ #entries = new Map();
47
+
48
+ /**
49
+ * @param {GraphicsEngine} graphics
50
+ * @param {MeshSystem} meshes
51
+ */
52
+ constructor(graphics, meshes) {
53
+ super();
54
+
55
+ assert.defined(graphics, 'graphics');
56
+ assert.defined(meshes, 'meshes');
57
+
58
+ this.#graphics = graphics;
59
+ this.#meshes = meshes;
60
+
61
+ this.dependencies = [AnimationGraphController, SGMesh];
62
+
63
+ // this tick's clip times are this system's to set: whatever evaluates a pose from them
64
+ // (exact queries, IK's base pose) reads AnimationGraphController and so runs after it
65
+ this.components_used = [
66
+ ResourceAccessSpecification.from(AnimationGraphController, ResourceAccessKind.Read | ResourceAccessKind.Write),
67
+ ];
68
+ }
69
+
70
+ /**
71
+ * @param {AnimationGraphController} controller
72
+ * @param {SGMesh} model
73
+ * @param {number} entity
74
+ */
75
+ link(controller, model, entity) {
76
+ this.#entries.set(entity, {
77
+ controller,
78
+ instance: null,
79
+ clip_registration: null,
80
+ slots: new Int32Array(0),
81
+ played_slots: new Int32Array(0),
82
+ clip_ids: new Int32Array(0),
83
+ weights: new Float32Array(0),
84
+ poses: []
85
+ });
86
+ }
87
+
88
+ /**
89
+ * What the entity's model is playing, in the form the CPU pose evaluator takes: one entry per
90
+ * clip **this graph names**, at the weight and the time the renderer has been given.
91
+ *
92
+ * **The clips the graph does not name are not here, because they are not registered** (D37).
93
+ * The GPU's accumulator marks a joint dirty for every bound clip that writes to it, weight and
94
+ * all — so a bound clip at weight zero resolves the joints only it drives to zero rather than
95
+ * leaving them at rest. The answer is not to hand those clips to the evaluator so it can make
96
+ * the same mistake; it is not to bind them. What the graph never names, nothing plays, and the
97
+ * joints it alone would have driven stay where the model rests.
98
+ *
99
+ * A clip the graph names but is not currently playing **is** here, at weight zero, because it is
100
+ * bound and the accumulator does see it.
101
+ *
102
+ * The entries are this system's own and are rewritten by the next call, which is what keeps a
103
+ * query on a per-frame path from allocating.
104
+ *
105
+ * @param {PosePlayback[]} target appended to
106
+ * @param {number} entity
107
+ * @returns {boolean} whether this system is driving the entity — `false` for one with no
108
+ * {@link AnimationGraphController}, and for one whose model has not arrived
109
+ */
110
+ write_pose_playbacks(target, entity) {
111
+ const entry = this.#entries.get(entity);
112
+
113
+ if (entry === undefined || entry.instance === null) {
114
+ return false;
115
+ }
116
+
117
+ const clips = entry.instance.clips;
118
+ const poses = entry.poses;
119
+ const played = entry.played_slots;
120
+
121
+ for (let i = 0; i < played.length; i++) {
122
+ const slot = played[i];
123
+ const pose = poses[slot];
124
+
125
+ pose.clip = clips[slot];
126
+ pose.weight = 0;
127
+ pose.time = 0;
128
+ }
129
+
130
+ const controller = entry.controller;
131
+ const slots = entry.slots;
132
+ const weights = controller.blendState.weights;
133
+
134
+ for (let i = 0; i < slots.length; i++) {
135
+ const pose = poses[slots[i]];
136
+ const weight = weights[i];
137
+
138
+ // assignment rather than accumulation, and it matters only where two of the graph's
139
+ // clips are one clip of the model: the renderer is written to in this order too, so the
140
+ // last of them is what it holds
141
+ pose.weight = weight;
142
+
143
+ if (weight > 0) {
144
+ pose.time = controller.clip_time(i);
145
+ }
146
+ }
147
+
148
+ // once each, however many of the graph's clips named it — the renderer holds one row for it
149
+ for (let i = 0; i < played.length; i++) {
150
+ target.push(poses[played[i]]);
151
+ }
152
+
153
+ return true;
154
+ }
155
+
156
+ /**
157
+ * @param {AnimationGraphController} controller
158
+ * @param {SGMesh} model
159
+ * @param {number} entity
160
+ */
161
+ unlink(controller, model, entity) {
162
+ controller.unlink();
163
+
164
+ const entry = this.#entries.get(entity);
165
+
166
+ if (entry !== undefined) {
167
+ this.#release_clips(entry);
168
+ }
169
+
170
+ this.#entries.delete(entity);
171
+ }
172
+
173
+ async shutdown(entityManager) {
174
+ for (const entry of this.#entries.values()) {
175
+ entry.controller.unlink();
176
+
177
+ this.#release_clips(entry);
178
+ }
179
+
180
+ this.#entries.clear();
181
+ }
182
+
183
+ /**
184
+ * Give this entity's clips back, if the manager that issued them is still the one running.
185
+ *
186
+ * **An id may only be handed back to the manager that issued it.** A renderer restart replaces
187
+ * the GPU scene context and voids every id it gave out, so a registration stamped with a context
188
+ * that is no longer current is forgotten rather than returned — returning it would corrupt a
189
+ * stranger's table. Same rule as {@link unregister_instance_animation}, same `===`.
190
+ *
191
+ * @param {object} entry
192
+ */
193
+ #release_clips(entry) {
194
+ const registration = entry.clip_registration;
195
+
196
+ if (registration === null) {
197
+ return;
198
+ }
199
+
200
+ if (registration.context === this.#graphics.scene_context(this.#meshes.scene)) {
201
+ unregister_instance_clips(registration);
202
+ }
203
+
204
+ entry.clip_registration = null;
205
+ }
206
+
207
+ /**
208
+ * @param {number} time_delta_seconds
209
+ */
210
+ update(time_delta_seconds) {
211
+ const ecd = this.entityManager.dataset;
212
+
213
+ const context = this.#graphics.scene_context(this.#meshes.scene);
214
+
215
+ // No device — before the first start, and again after a stop. The clocks still run: a unit
216
+ // that fires an ability while the renderer is being replaced still fires it.
217
+ const manager = context === null ? null : context.animation_manager;
218
+
219
+ for (const [entity, entry] of this.#entries) {
220
+ const instance = this.#meshes.instance_of(entity);
221
+
222
+ if (instance === null) {
223
+ // the model has not arrived, and its clips are what say how long they run
224
+ continue;
225
+ }
226
+
227
+ if (instance !== entry.instance) {
228
+ this.#bind_model(entry, entity, instance, ecd);
229
+ }
230
+
231
+ entry.controller.tick(time_delta_seconds);
232
+
233
+ if (context === null) {
234
+ continue;
235
+ }
236
+
237
+ /*
238
+ Registered against the context that is running now. A renderer restart builds a new one
239
+ and voids every id the old gave out, and the stamp on the registration is how that is
240
+ noticed — in one comparison, without depending on when anything last ran.
241
+ */
242
+ if (entry.clip_registration === null || entry.clip_registration.context !== context) {
243
+ this.#bind_gpu(entry, instance, context);
244
+ }
245
+
246
+ write_graph_playback(manager, entry.controller, entry.clip_ids, entry.weights);
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Bind the graph to a model: work out which of the model's clips each of the graph's clips is,
252
+ * how long each of them runs, and start the graph on that.
253
+ *
254
+ * @param {object} entry
255
+ * @param {number} entity
256
+ * @param {PrefabInstance} instance
257
+ * @param {EntityComponentDataset} ecd
258
+ */
259
+ #bind_model(entry, entity, instance, ecd) {
260
+ const clip_index = entry.controller.def.clipIndex;
261
+ const clip_count = clip_index.length;
262
+
263
+ const slots = new Int32Array(clip_count);
264
+ const durations = new Float64Array(clip_count);
265
+
266
+ for (let i = 0; i < clip_count; i++) {
267
+ const name = clip_index[i].name;
268
+
269
+ const slot = instance.clips.findIndex(clip => clip.name === name);
270
+
271
+ if (slot === -1) {
272
+ throw new Error(`Animation clip '${name}' is not in the model`);
273
+ }
274
+
275
+ slots[i] = slot;
276
+ durations[i] = instance.clips[slot].duration;
277
+ }
278
+
279
+ entry.controller.unlink();
280
+ entry.controller.link(entity, ecd, durations);
281
+
282
+ entry.instance = instance;
283
+ entry.slots = slots;
284
+
285
+ /*
286
+ The distinct clips of the model this graph plays. Two states can name one clip — an idle a
287
+ hurt returns to, say — and it is one row on the GPU either way, so it is one entry here:
288
+ registered once, reported to the pose evaluator once.
289
+ */
290
+ const played = [];
291
+
292
+ for (let i = 0; i < clip_count; i++) {
293
+ if (played.indexOf(slots[i]) === -1) {
294
+ played.push(slots[i]);
295
+ }
296
+ }
297
+
298
+ entry.played_slots = Int32Array.from(played);
299
+
300
+ entry.clip_ids = new Int32Array(clip_count);
301
+ entry.weights = new Float32Array(clip_count).fill(-1);
302
+ entry.poses = instance.clips.map(() => new PosePlayback());
303
+
304
+ // ids the manager issued for the model that was here before name clips this one does not
305
+ // have
306
+ this.#release_clips(entry);
307
+ }
308
+
309
+ /**
310
+ * Make this graph's clips playable, and take up the ids that come back.
311
+ *
312
+ * **Only the clips the graph names are registered** (D37), so there is nothing to silence: a
313
+ * clip of the model no state plays is never bound, never marks a joint, and leaves the joints
314
+ * only it would have driven at rest. What this used to do instead — register everything and then
315
+ * write a zero weight over the surplus — kept them bound, and a bound clip at weight zero
316
+ * resolves its joints to zero rather than to the model's own pose.
317
+ *
318
+ * @param {object} entry
319
+ * @param {PrefabInstance} instance
320
+ * @param {GPUSceneContext} context
321
+ */
322
+ #bind_gpu(entry, instance, context) {
323
+ const registration = register_instance_clips(context, instance, entry.played_slots);
324
+
325
+ const slots = entry.slots;
326
+ const clip_ids = entry.clip_ids;
327
+
328
+ for (let i = 0; i < slots.length; i++) {
329
+ clip_ids[i] = registration.ids[slots[i]];
330
+ }
331
+
332
+ entry.clip_registration = registration;
333
+
334
+ // whatever the last renderer was told is not what this one knows
335
+ entry.weights.fill(-1);
336
+ }
337
+ }