@haiyue/extensions 0.1.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 (293) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/dist/animation/Animation2DComponent.d.ts +46 -0
  4. package/dist/animation/Animation2DExtensionRegistry.d.ts +27 -0
  5. package/dist/animation/Animation2DRenderSystem.d.ts +89 -0
  6. package/dist/animation/Animation2DRuntime.d.ts +99 -0
  7. package/dist/animation/Animation2DStateMachine.d.ts +13 -0
  8. package/dist/animation/Animation2DStateMachineComponent.d.ts +54 -0
  9. package/dist/animation/Animation2DStateMachineRuntime.d.ts +30 -0
  10. package/dist/animation/Animation2DStateMachineSystem.d.ts +14 -0
  11. package/dist/animation/Animation2DStateMachineVisualRuntime.d.ts +27 -0
  12. package/dist/animation/Animation2DSystem.d.ts +14 -0
  13. package/dist/animation/AnimationAssetLoader.d.ts +9 -0
  14. package/dist/animation/AnimationAudioClip.d.ts +26 -0
  15. package/dist/animation/AnimationPathTessellator.d.ts +52 -0
  16. package/dist/animation/AnimationTextRasterizer.d.ts +21 -0
  17. package/dist/animation/AnimationVisual2D.d.ts +68 -0
  18. package/dist/animation/HyaAnimation2DClipAdapter.d.ts +16 -0
  19. package/dist/animation/Particle2DDescriptorAdapter.d.ts +5 -0
  20. package/dist/animation/runtime/mixer/Action.d.ts +150 -0
  21. package/dist/animation/runtime/mixer/Mixer.d.ts +54 -0
  22. package/dist/animation/runtime/mixer/PoseBuffer.d.ts +23 -0
  23. package/dist/animation/runtime/mixer/Sampler.d.ts +17 -0
  24. package/dist/animation/runtime/mixer/Types.d.ts +101 -0
  25. package/dist/animation/runtime/mixer/index.d.ts +6 -0
  26. package/dist/animation-state-machine/AnimationStateMachine.d.ts +111 -0
  27. package/dist/animation-state-machine/AnimationStateMachineChannels.d.ts +23 -0
  28. package/dist/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.d.ts +51 -0
  29. package/dist/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.d.ts +14 -0
  30. package/dist/animation-state-machine/runtime/AnimationStateMachineCompiler.d.ts +109 -0
  31. package/dist/animation-state-machine/runtime/AnimationStateMachineController.d.ts +103 -0
  32. package/dist/animation-state-machine/runtime/AnimationStateMachineMixerPort.d.ts +35 -0
  33. package/dist/animation-state-machine/runtime/index.d.ts +7 -0
  34. package/dist/animation.d.ts +15 -0
  35. package/dist/animation.js +1171 -0
  36. package/dist/animation3d/Animation3DAction.d.ts +46 -0
  37. package/dist/animation3d/Animation3DBinding.d.ts +85 -0
  38. package/dist/animation3d/Animation3DClip.d.ts +20 -0
  39. package/dist/animation3d/Animation3DError.d.ts +13 -0
  40. package/dist/animation3d/Animation3DMixer.d.ts +27 -0
  41. package/dist/animation3d/Animation3DPose.d.ts +40 -0
  42. package/dist/animation3d/Animation3DPoseBuffer.d.ts +24 -0
  43. package/dist/animation3d/Animation3DResource.d.ts +28 -0
  44. package/dist/animation3d/Animation3DStateMachine.d.ts +95 -0
  45. package/dist/animation3d/Animation3DStateMachineRuntime.d.ts +70 -0
  46. package/dist/animation3d/Animation3DTrack.d.ts +19 -0
  47. package/dist/animation3d/hya/HyaAnimation3DRuntime.d.ts +73 -0
  48. package/dist/animation3d/hya/HyaAnimation3DStateMachineRuntime.d.ts +65 -0
  49. package/dist/animation3d/hya/HyaAnimation3DTypes.d.ts +170 -0
  50. package/dist/animation3d/hya/index.d.ts +4 -0
  51. package/dist/animation3d/index.d.ts +14 -0
  52. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.d.ts +81 -0
  53. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.d.ts +39 -0
  54. package/dist/animation3d/runtime/integration/index.d.ts +2 -0
  55. package/dist/animation3d/runtime/mixer/Action.d.ts +150 -0
  56. package/dist/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.d.ts +6 -0
  57. package/dist/animation3d/runtime/mixer/Mixer.d.ts +59 -0
  58. package/dist/animation3d/runtime/mixer/PoseBuffer.d.ts +1 -0
  59. package/dist/animation3d/runtime/mixer/TrackSampler.d.ts +24 -0
  60. package/dist/animation3d/runtime/mixer/index.d.ts +4 -0
  61. package/dist/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.d.ts +1 -0
  62. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.d.ts +1 -0
  63. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineController.d.ts +1 -0
  64. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.d.ts +1 -0
  65. package/dist/animation3d/runtime/state-machine/index.d.ts +6 -0
  66. package/dist/animation3d.d.ts +5 -0
  67. package/dist/animation3d.js +1708 -0
  68. package/dist/benchmark.d.ts +30 -0
  69. package/dist/benchmark.js +119 -0
  70. package/dist/canvas-text/CanvasText2DRenderSystem.d.ts +24 -0
  71. package/dist/canvas-text/CanvasTextComponent.d.ts +18 -0
  72. package/dist/canvas-text.d.ts +4 -0
  73. package/dist/canvas-text.js +276 -0
  74. package/dist/chunks/2d-ui-animation-2d.generated-D4aHzFU2.js +4 -0
  75. package/dist/chunks/2d-ui-canvas-text-2d.generated-C0Eaej2m.js +4 -0
  76. package/dist/chunks/2d-ui-spine2d.generated-CUUi8xjl.js +4 -0
  77. package/dist/chunks/2d-ui-tilemap2d.generated-gebw4mX7.js +4 -0
  78. package/dist/chunks/Animation2DStateMachine-9IonguNa.js +3245 -0
  79. package/dist/chunks/AnimationStateMachineController-BIcAh-sT.js +1438 -0
  80. package/dist/chunks/GltfAnimation3DAdapter-Cu3rQQsW.js +2240 -0
  81. package/dist/chunks/GltfAnimationRuntime-CRHsLycN.js +631 -0
  82. package/dist/chunks/RenderSystem2DBase-DDT61dAu.js +227 -0
  83. package/dist/chunks/Spine2DRuntime-D9M9LAQR.js +3056 -0
  84. package/dist/chunks/SpineAssetParser-BSDmPge1.js +378 -0
  85. package/dist/chunks/gltfLoader-Dm22jLYB.js +2085 -0
  86. package/dist/chunks/pluginUtils-CvwroRMd.js +33 -0
  87. package/dist/experimental-gltf-worker.d.ts +4 -0
  88. package/dist/experimental-gltf-worker.js +138 -0
  89. package/dist/experimental-spine-worker.d.ts +4 -0
  90. package/dist/experimental-spine-worker.js +110 -0
  91. package/dist/gltf/GltfAccessorReader.d.ts +7 -0
  92. package/dist/gltf/GltfAnimation3DAdapter.d.ts +47 -0
  93. package/dist/gltf/GltfAnimationRuntime.d.ts +10 -0
  94. package/dist/gltf/GltfAssetWorkerClient.d.ts +20 -0
  95. package/dist/gltf/GltfCompatibilityReport.d.ts +70 -0
  96. package/dist/gltf/GltfConservativeBounds.d.ts +18 -0
  97. package/dist/gltf/GltfDracoDecoder.d.ts +4 -0
  98. package/dist/gltf/GltfExtensionAdapter.d.ts +54 -0
  99. package/dist/gltf/GltfLoaderContract.d.ts +249 -0
  100. package/dist/gltf/GltfLoaderErrors.d.ts +4 -0
  101. package/dist/gltf/GltfMaterialDescriptor.d.ts +23 -0
  102. package/dist/gltf/GltfMaterialEncoder.d.ts +20 -0
  103. package/dist/gltf/GltfMaterialLoader.d.ts +6 -0
  104. package/dist/gltf/GltfModelComponent.d.ts +72 -0
  105. package/dist/gltf/GltfModelSystem.d.ts +37 -0
  106. package/dist/gltf/GltfPlugin.d.ts +6 -0
  107. package/dist/gltf/GltfSchema.d.ts +225 -0
  108. package/dist/gltf/GltfUvSemanticPlanner.d.ts +33 -0
  109. package/dist/gltf/gltfLoader.d.ts +9 -0
  110. package/dist/gltf-animation3d.d.ts +3 -0
  111. package/dist/gltf-animation3d.js +8 -0
  112. package/dist/gltf-worker-runtime.d.ts +7 -0
  113. package/dist/gltf-worker-runtime.js +6981 -0
  114. package/dist/gltf.d.ts +12 -0
  115. package/dist/gltf.js +517 -0
  116. package/dist/grid/Grid2DComponent.d.ts +25 -0
  117. package/dist/grid.d.ts +2 -0
  118. package/dist/grid.js +56 -0
  119. package/dist/hya-state-machine.d.ts +7 -0
  120. package/dist/hya-state-machine.js +2934 -0
  121. package/dist/index.d.ts +2 -0
  122. package/dist/index.js +7 -0
  123. package/dist/internal/2d-ui-shader-artifact.js +870 -0
  124. package/dist/plugins/pluginUtils.d.ts +20 -0
  125. package/dist/plugins.d.ts +6 -0
  126. package/dist/shaders/generated/2d-ui-artifact.generated.d.ts +658 -0
  127. package/dist/spine/Spine2DComponent.d.ts +116 -0
  128. package/dist/spine/Spine2DGpuRenderer.d.ts +65 -0
  129. package/dist/spine/Spine2DRenderSystem.d.ts +27 -0
  130. package/dist/spine/Spine2DRuntime.d.ts +103 -0
  131. package/dist/spine/SpineAnimationBoneTimelines.d.ts +8 -0
  132. package/dist/spine/SpineAssetParser.d.ts +18 -0
  133. package/dist/spine/SpineAssetWorkerClient.d.ts +19 -0
  134. package/dist/spine/SpineAssetWorkerContract.d.ts +6 -0
  135. package/dist/spine/SpineAtlasParser.d.ts +21 -0
  136. package/dist/spine/SpineFloatBuilder.d.ts +15 -0
  137. package/dist/spine/SpinePathConstraintSolver.d.ts +32 -0
  138. package/dist/spine/SpinePlugin.d.ts +8 -0
  139. package/dist/spine/SpineSkeletonRuntime.d.ts +185 -0
  140. package/dist/spine/SpineSlotAnimation.d.ts +17 -0
  141. package/dist/spine/SpineTimelineRuntime.d.ts +25 -0
  142. package/dist/spine/SpineVertexBuilder.d.ts +61 -0
  143. package/dist/spine.d.ts +7 -0
  144. package/dist/spine.js +578 -0
  145. package/dist/tilemap/Tilemap2DComponent.d.ts +110 -0
  146. package/dist/tilemap/Tilemap2DRenderSystem.d.ts +11 -0
  147. package/dist/tilemap/Tilemap2DRenderer.d.ts +24 -0
  148. package/dist/tilemap/TilemapPlugin.d.ts +8 -0
  149. package/dist/tilemap.d.ts +6 -0
  150. package/dist/tilemap.js +535 -0
  151. package/dist/tween/Tween2DComponent.d.ts +70 -0
  152. package/dist/tween/Tween2DSystem.d.ts +12 -0
  153. package/dist/tween.d.ts +4 -0
  154. package/dist/tween.js +138 -0
  155. package/dist/utils/RenderSystem2DBase.d.ts +42 -0
  156. package/dist/utils/arrayAccess.d.ts +4 -0
  157. package/dist/utils/camera2d.d.ts +12 -0
  158. package/dist/utils/render2dGpu.d.ts +32 -0
  159. package/package.json +124 -0
  160. package/src/animation/Animation2DComponent.ts +135 -0
  161. package/src/animation/Animation2DExtensionRegistry.ts +52 -0
  162. package/src/animation/Animation2DRenderSystem.ts +1026 -0
  163. package/src/animation/Animation2DRuntime.ts +1326 -0
  164. package/src/animation/Animation2DStateMachine.ts +39 -0
  165. package/src/animation/Animation2DStateMachineComponent.ts +228 -0
  166. package/src/animation/Animation2DStateMachineRuntime.ts +141 -0
  167. package/src/animation/Animation2DStateMachineSystem.ts +60 -0
  168. package/src/animation/Animation2DStateMachineVisualRuntime.ts +282 -0
  169. package/src/animation/Animation2DSystem.ts +72 -0
  170. package/src/animation/AnimationAssetLoader.ts +84 -0
  171. package/src/animation/AnimationAudioClip.ts +140 -0
  172. package/src/animation/AnimationPathTessellator.ts +691 -0
  173. package/src/animation/AnimationTextRasterizer.ts +340 -0
  174. package/src/animation/AnimationVisual2D.ts +153 -0
  175. package/src/animation/HyaAnimation2DClipAdapter.ts +845 -0
  176. package/src/animation/Particle2DDescriptorAdapter.ts +35 -0
  177. package/src/animation/runtime/mixer/Action.ts +876 -0
  178. package/src/animation/runtime/mixer/Mixer.ts +505 -0
  179. package/src/animation/runtime/mixer/PoseBuffer.ts +105 -0
  180. package/src/animation/runtime/mixer/Sampler.ts +252 -0
  181. package/src/animation/runtime/mixer/Types.ts +138 -0
  182. package/src/animation/runtime/mixer/index.ts +31 -0
  183. package/src/animation-state-machine/AnimationStateMachine.ts +146 -0
  184. package/src/animation-state-machine/AnimationStateMachineChannels.ts +116 -0
  185. package/src/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.ts +197 -0
  186. package/src/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.ts +503 -0
  187. package/src/animation-state-machine/runtime/AnimationStateMachineCompiler.ts +763 -0
  188. package/src/animation-state-machine/runtime/AnimationStateMachineController.ts +987 -0
  189. package/src/animation-state-machine/runtime/AnimationStateMachineMixerPort.ts +54 -0
  190. package/src/animation-state-machine/runtime/index.ts +47 -0
  191. package/src/animation.ts +33 -0
  192. package/src/animation3d/Animation3DAction.ts +73 -0
  193. package/src/animation3d/Animation3DBinding.ts +116 -0
  194. package/src/animation3d/Animation3DClip.ts +22 -0
  195. package/src/animation3d/Animation3DError.ts +34 -0
  196. package/src/animation3d/Animation3DMixer.ts +82 -0
  197. package/src/animation3d/Animation3DPose.ts +100 -0
  198. package/src/animation3d/Animation3DPoseBuffer.ts +85 -0
  199. package/src/animation3d/Animation3DResource.ts +49 -0
  200. package/src/animation3d/Animation3DStateMachine.ts +126 -0
  201. package/src/animation3d/Animation3DStateMachineRuntime.ts +191 -0
  202. package/src/animation3d/Animation3DTrack.ts +29 -0
  203. package/src/animation3d/hya/HyaAnimation3DRuntime.ts +756 -0
  204. package/src/animation3d/hya/HyaAnimation3DStateMachineRuntime.ts +618 -0
  205. package/src/animation3d/hya/HyaAnimation3DTypes.ts +168 -0
  206. package/src/animation3d/hya/index.ts +10 -0
  207. package/src/animation3d/index.ts +76 -0
  208. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.ts +325 -0
  209. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.ts +158 -0
  210. package/src/animation3d/runtime/integration/index.ts +9 -0
  211. package/src/animation3d/runtime/mixer/Action.ts +833 -0
  212. package/src/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.ts +26 -0
  213. package/src/animation3d/runtime/mixer/Mixer.ts +562 -0
  214. package/src/animation3d/runtime/mixer/PoseBuffer.ts +1 -0
  215. package/src/animation3d/runtime/mixer/TrackSampler.ts +399 -0
  216. package/src/animation3d/runtime/mixer/index.ts +8 -0
  217. package/src/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.ts +4 -0
  218. package/src/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.ts +1 -0
  219. package/src/animation3d/runtime/state-machine/Animation3DStateMachineController.ts +1 -0
  220. package/src/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.ts +1 -0
  221. package/src/animation3d/runtime/state-machine/index.ts +45 -0
  222. package/src/animation3d.ts +5 -0
  223. package/src/benchmark.ts +168 -0
  224. package/src/canvas-text/CanvasText2DRenderSystem.ts +292 -0
  225. package/src/canvas-text/CanvasTextComponent.ts +47 -0
  226. package/src/canvas-text.ts +4 -0
  227. package/src/experimental-gltf-worker.ts +18 -0
  228. package/src/experimental-spine-worker.ts +9 -0
  229. package/src/gltf/GltfAccessorReader.ts +271 -0
  230. package/src/gltf/GltfAnimation3DAdapter.ts +680 -0
  231. package/src/gltf/GltfAnimationRuntime.ts +392 -0
  232. package/src/gltf/GltfAssetWorkerClient.ts +136 -0
  233. package/src/gltf/GltfCompatibilityReport.ts +214 -0
  234. package/src/gltf/GltfConservativeBounds.ts +219 -0
  235. package/src/gltf/GltfDracoDecoder.ts +251 -0
  236. package/src/gltf/GltfExtensionAdapter.ts +340 -0
  237. package/src/gltf/GltfLoaderContract.ts +333 -0
  238. package/src/gltf/GltfLoaderErrors.ts +59 -0
  239. package/src/gltf/GltfMaterialDescriptor.ts +134 -0
  240. package/src/gltf/GltfMaterialEncoder.ts +173 -0
  241. package/src/gltf/GltfMaterialLoader.ts +293 -0
  242. package/src/gltf/GltfModelComponent.ts +115 -0
  243. package/src/gltf/GltfModelSystem.ts +208 -0
  244. package/src/gltf/GltfPlugin.ts +84 -0
  245. package/src/gltf/GltfSchema.ts +229 -0
  246. package/src/gltf/GltfUvSemanticPlanner.ts +166 -0
  247. package/src/gltf/gltfLoader.ts +910 -0
  248. package/src/gltf-animation3d.ts +10 -0
  249. package/src/gltf-worker-runtime.ts +10 -0
  250. package/src/gltf.ts +56 -0
  251. package/src/grid/Grid2DComponent.ts +69 -0
  252. package/src/grid.ts +2 -0
  253. package/src/hya-state-machine.ts +19 -0
  254. package/src/index.ts +2 -0
  255. package/src/plugins/pluginUtils.ts +50 -0
  256. package/src/plugins.ts +6 -0
  257. package/src/shaders/generated/2d-ui-animation-2d.generated.wgsl +242 -0
  258. package/src/shaders/generated/2d-ui-artifact.generated.ts +867 -0
  259. package/src/shaders/generated/2d-ui-canvas-text-2d.generated.wgsl +38 -0
  260. package/src/shaders/generated/2d-ui-spine2d.generated.wgsl +41 -0
  261. package/src/shaders/generated/2d-ui-tilemap2d.generated.wgsl +36 -0
  262. package/src/spine/Spine2DComponent.ts +168 -0
  263. package/src/spine/Spine2DGpuRenderer.ts +449 -0
  264. package/src/spine/Spine2DRenderSystem.ts +199 -0
  265. package/src/spine/Spine2DRuntime.ts +1529 -0
  266. package/src/spine/SpineAnimationBoneTimelines.ts +30 -0
  267. package/src/spine/SpineAssetParser.ts +20 -0
  268. package/src/spine/SpineAssetWorkerClient.ts +112 -0
  269. package/src/spine/SpineAssetWorkerContract.ts +4 -0
  270. package/src/spine/SpineAtlasParser.ts +127 -0
  271. package/src/spine/SpineFloatBuilder.ts +66 -0
  272. package/src/spine/SpinePathConstraintSolver.ts +582 -0
  273. package/src/spine/SpinePlugin.ts +76 -0
  274. package/src/spine/SpineSkeletonRuntime.ts +521 -0
  275. package/src/spine/SpineSlotAnimation.ts +195 -0
  276. package/src/spine/SpineTimelineRuntime.ts +453 -0
  277. package/src/spine/SpineVertexBuilder.ts +686 -0
  278. package/src/spine.ts +7 -0
  279. package/src/tilemap/Tilemap2DComponent.ts +232 -0
  280. package/src/tilemap/Tilemap2DRenderSystem.ts +58 -0
  281. package/src/tilemap/Tilemap2DRenderer.ts +289 -0
  282. package/src/tilemap/TilemapPlugin.ts +75 -0
  283. package/src/tilemap.ts +6 -0
  284. package/src/tween/Tween2DComponent.ts +83 -0
  285. package/src/tween/Tween2DSystem.ts +78 -0
  286. package/src/tween.ts +4 -0
  287. package/src/types/earcut.d.ts +7 -0
  288. package/src/types/wgsl.d.ts +4 -0
  289. package/src/utils/RenderSystem2DBase.ts +164 -0
  290. package/src/utils/arrayAccess.ts +17 -0
  291. package/src/utils/camera2d.ts +68 -0
  292. package/src/utils/render2dGpu.ts +132 -0
  293. package/test/fixtures/gltf/animation-characterization.gltf +344 -0
@@ -0,0 +1,631 @@
1
+ import { Transform3D } from '@haiyue/engine/components';
2
+ import { mat4 } from 'wgpu-matrix';
3
+ import { EngineError, EngineErrorCode } from '@haiyue/engine';
4
+ import { ErrorRecovery, ErrorDomain } from '@haiyue/engine/core';
5
+ import { createAbortError } from '@haiyue/engine/experimental/async';
6
+
7
+ function throwIfGltfLoadAborted(signal) {
8
+ if (!signal?.aborted)
9
+ return;
10
+ throw createAbortError('glTF load aborted.', signal.reason);
11
+ }
12
+ function attachGltfSource(error, src) {
13
+ if (error instanceof Error && error.name === 'AbortError')
14
+ return error;
15
+ if (error instanceof EngineError) {
16
+ return new EngineError(error.code, error.message, {
17
+ domain: error.domain,
18
+ recoverable: error.recoverable,
19
+ recovery: error.recovery,
20
+ context: { url: src, resourceType: 'model/gltf', ...error.context },
21
+ ...(error.path === undefined ? {} : { path: error.path }),
22
+ ...(error.hint === undefined ? {} : { hint: error.hint }),
23
+ ...(error.docsPath === undefined ? {} : { docsPath: error.docsPath }),
24
+ cause: error,
25
+ });
26
+ }
27
+ return gltfDataError(error instanceof Error ? error.message : String(error), { url: src }, undefined, error);
28
+ }
29
+ function gltfDataError(message, context = {}, path, cause) {
30
+ const accessor = /[Aa]ccessor\s+(\d+)/.exec(message)?.[1];
31
+ const bufferView = /bufferView\s+(\d+)/i.exec(message)?.[1];
32
+ const buffer = /buffer\s+(\d+)/i.exec(message)?.[1];
33
+ const failedLoad = /^Failed to load/.test(message);
34
+ const resolvedPath = path
35
+ ?? (accessor === undefined ? undefined : `gltf.accessors[${accessor}]`)
36
+ ?? (bufferView === undefined ? undefined : `gltf.bufferViews[${bufferView}]`)
37
+ ?? (buffer === undefined ? undefined : `gltf.buffers[${buffer}]`)
38
+ ?? 'gltf';
39
+ return new EngineError(failedLoad ? EngineErrorCode.AssetLoadFailed : EngineErrorCode.AssetInvalidData, message, {
40
+ domain: ErrorDomain.Component,
41
+ recovery: failedLoad ? ErrorRecovery.Retry : ErrorRecovery.ReleaseResource,
42
+ context: {
43
+ resourceType: 'model/gltf',
44
+ ...context,
45
+ ...(accessor === undefined ? {} : { accessor: Number(accessor) }),
46
+ ...(bufferView === undefined ? {} : { bufferView: Number(bufferView) }),
47
+ ...(buffer === undefined ? {} : { buffer: Number(buffer) }),
48
+ },
49
+ path: resolvedPath,
50
+ cause,
51
+ });
52
+ }
53
+
54
+ const COMPONENT_BYTE_SIZE = {
55
+ 5120: 1,
56
+ 5121: 1,
57
+ 5122: 2,
58
+ 5123: 2,
59
+ 5125: 4,
60
+ 5126: 4,
61
+ };
62
+ const TYPE_SIZE = {
63
+ SCALAR: 1,
64
+ VEC2: 2,
65
+ VEC3: 3,
66
+ VEC4: 4,
67
+ MAT2: 4,
68
+ MAT3: 9,
69
+ MAT4: 16,
70
+ };
71
+ function readAccessorFloat(gltf, buffers, accessorIndex, expectedSize) {
72
+ const accessor = getAccessor(gltf, accessorIndex);
73
+ const itemSize = TYPE_SIZE[accessor.type];
74
+ if (itemSize < expectedSize)
75
+ throw gltfDataError(`Accessor ${accessorIndex} has ${itemSize} components, expected ${expectedSize}.`);
76
+ const out = new Float32Array(accessor.count * expectedSize);
77
+ readAccessorValues(gltf, buffers, accessor, (values, index) => {
78
+ for (let i = 0; i < expectedSize; i++)
79
+ out[index * expectedSize + i] = values[i] ?? 0;
80
+ });
81
+ return out;
82
+ }
83
+ function readAccessorMat4(gltf, buffers, accessorIndex) {
84
+ const accessor = getAccessor(gltf, accessorIndex);
85
+ if (TYPE_SIZE[accessor.type] !== 16)
86
+ throw gltfDataError(`Accessor ${accessorIndex} is not MAT4.`);
87
+ const out = [];
88
+ readAccessorValues(gltf, buffers, accessor, values => {
89
+ const matrix = new Float32Array(16);
90
+ for (let i = 0; i < 16; i++)
91
+ matrix[i] = values[i] ?? 0;
92
+ out.push(matrix);
93
+ });
94
+ return out;
95
+ }
96
+ function readAccessorUnsigned(gltf, buffers, accessorIndex, expectedSize) {
97
+ const accessor = getAccessor(gltf, accessorIndex);
98
+ const itemSize = TYPE_SIZE[accessor.type];
99
+ if (itemSize < expectedSize)
100
+ throw gltfDataError(`Accessor ${accessorIndex} has ${itemSize} components, expected ${expectedSize}.`);
101
+ const out = accessor.componentType === 5125
102
+ ? new Uint32Array(accessor.count * expectedSize)
103
+ : new Uint16Array(accessor.count * expectedSize);
104
+ readAccessorValues(gltf, buffers, accessor, (values, index) => {
105
+ for (let i = 0; i < expectedSize; i++)
106
+ out[index * expectedSize + i] = values[i] ?? 0;
107
+ });
108
+ return out;
109
+ }
110
+ function readAccessorIndices(gltf, buffers, accessorIndex) {
111
+ const accessor = getAccessor(gltf, accessorIndex);
112
+ const out = accessor.componentType === 5125 ? new Uint32Array(accessor.count) : new Uint16Array(accessor.count);
113
+ readAccessorValues(gltf, buffers, accessor, (values, index) => {
114
+ out[index] = values[0] ?? 0;
115
+ });
116
+ return out;
117
+ }
118
+ function generateFlatNormals(positions, indices) {
119
+ const normals = new Float32Array(positions.length);
120
+ const triangleCount = indices ? indices.length / 3 : positions.length / 9;
121
+ for (let tri = 0; tri < triangleCount; tri++) {
122
+ const ia = indices ? indices[tri * 3] : tri * 3;
123
+ const ib = indices ? indices[tri * 3 + 1] : tri * 3 + 1;
124
+ const ic = indices ? indices[tri * 3 + 2] : tri * 3 + 2;
125
+ if (ia === undefined || ib === undefined || ic === undefined)
126
+ continue;
127
+ const ax = requiredFiniteArrayValue(positions, ia * 3, 'POSITION');
128
+ const ay = requiredFiniteArrayValue(positions, ia * 3 + 1, 'POSITION');
129
+ const az = requiredFiniteArrayValue(positions, ia * 3 + 2, 'POSITION');
130
+ const bx = requiredFiniteArrayValue(positions, ib * 3, 'POSITION');
131
+ const by = requiredFiniteArrayValue(positions, ib * 3 + 1, 'POSITION');
132
+ const bz = requiredFiniteArrayValue(positions, ib * 3 + 2, 'POSITION');
133
+ const cx = requiredFiniteArrayValue(positions, ic * 3, 'POSITION');
134
+ const cy = requiredFiniteArrayValue(positions, ic * 3 + 1, 'POSITION');
135
+ const cz = requiredFiniteArrayValue(positions, ic * 3 + 2, 'POSITION');
136
+ const abx = bx - ax, aby = by - ay, abz = bz - az;
137
+ const acx = cx - ax, acy = cy - ay, acz = cz - az;
138
+ const nx = aby * acz - abz * acy;
139
+ const ny = abz * acx - abx * acz;
140
+ const nz = abx * acy - aby * acx;
141
+ const len = Math.sqrt(nx * nx + ny * ny + nz * nz) || 1;
142
+ const nnx = nx / len;
143
+ const nny = ny / len;
144
+ const nnz = nz / len;
145
+ addNormal(normals, ia, nnx, nny, nnz);
146
+ addNormal(normals, ib, nnx, nny, nnz);
147
+ addNormal(normals, ic, nnx, nny, nnz);
148
+ }
149
+ for (let i = 0; i < normals.length; i += 3) {
150
+ const nx = requiredFiniteArrayValue(normals, i, 'generated normals');
151
+ const ny = requiredFiniteArrayValue(normals, i + 1, 'generated normals');
152
+ const nz = requiredFiniteArrayValue(normals, i + 2, 'generated normals');
153
+ const len = Math.sqrt(nx * nx + ny * ny + nz * nz) || 1;
154
+ normals[i] = nx / len;
155
+ normals[i + 1] = ny / len;
156
+ normals[i + 2] = nz / len;
157
+ }
158
+ return normals;
159
+ }
160
+ function readAccessorValues(gltf, buffers, accessor, write) {
161
+ const itemSize = TYPE_SIZE[accessor.type];
162
+ const componentSize = COMPONENT_BYTE_SIZE[accessor.componentType];
163
+ const values = new Float64Array(itemSize);
164
+ if (accessor.bufferView !== undefined) {
165
+ const view = getBufferView(gltf, accessor.bufferView);
166
+ const dataView = new DataView(getBuffer(buffers, view.buffer));
167
+ const stride = view.byteStride ?? itemSize * componentSize;
168
+ const start = (view.byteOffset ?? 0) + (accessor.byteOffset ?? 0);
169
+ for (let index = 0; index < accessor.count; index++) {
170
+ readAccessorTuple(dataView, start + index * stride, itemSize, componentSize, accessor.componentType, Boolean(accessor.normalized), values);
171
+ write(values, index);
172
+ }
173
+ }
174
+ else {
175
+ values.fill(0);
176
+ for (let index = 0; index < accessor.count; index++)
177
+ write(values, index);
178
+ }
179
+ if (accessor.sparse?.count)
180
+ readSparseAccessorValues(gltf, buffers, accessor, values, write);
181
+ }
182
+ function readSparseAccessorValues(gltf, buffers, accessor, values, write) {
183
+ const sparse = accessor.sparse;
184
+ if (!sparse)
185
+ return;
186
+ const itemSize = TYPE_SIZE[accessor.type];
187
+ const componentSize = COMPONENT_BYTE_SIZE[accessor.componentType];
188
+ const indexComponentSize = COMPONENT_BYTE_SIZE[sparse.indices.componentType];
189
+ const indicesView = getBufferView(gltf, sparse.indices.bufferView);
190
+ const valuesView = getBufferView(gltf, sparse.values.bufferView);
191
+ const indicesData = new DataView(getBuffer(buffers, indicesView.buffer));
192
+ const valuesData = new DataView(getBuffer(buffers, valuesView.buffer));
193
+ const indicesStart = (indicesView.byteOffset ?? 0) + (sparse.indices.byteOffset ?? 0);
194
+ const valuesStart = (valuesView.byteOffset ?? 0) + (sparse.values.byteOffset ?? 0);
195
+ for (let sparseIndex = 0; sparseIndex < sparse.count; sparseIndex++) {
196
+ const index = readSparseIndex(indicesData, indicesStart + sparseIndex * indexComponentSize, sparse.indices.componentType);
197
+ if (index < 0 || index >= accessor.count)
198
+ throw gltfDataError(`Sparse accessor index ${index} is out of bounds.`);
199
+ readAccessorTuple(valuesData, valuesStart + sparseIndex * itemSize * componentSize, itemSize, componentSize, accessor.componentType, Boolean(accessor.normalized), values);
200
+ write(values, index);
201
+ }
202
+ }
203
+ function readAccessorTuple(dataView, offset, itemSize, componentSize, componentType, normalized, out) {
204
+ for (let component = 0; component < itemSize; component++) {
205
+ out[component] = readComponent(dataView, offset + component * componentSize, componentType, normalized);
206
+ }
207
+ }
208
+ function readSparseIndex(view, offset, componentType) {
209
+ switch (componentType) {
210
+ case 5121: return view.getUint8(offset);
211
+ case 5123: return view.getUint16(offset, true);
212
+ case 5125: return view.getUint32(offset, true);
213
+ }
214
+ }
215
+ function getBufferView(gltf, bufferViewIndex) {
216
+ const view = gltf.bufferViews?.[bufferViewIndex];
217
+ if (!view)
218
+ throw gltfDataError(`Missing bufferView ${bufferViewIndex}.`);
219
+ return view;
220
+ }
221
+ function getBuffer(buffers, bufferIndex) {
222
+ const buffer = buffers[bufferIndex];
223
+ if (!buffer)
224
+ throw gltfDataError(`Missing buffer ${bufferIndex}.`);
225
+ return buffer;
226
+ }
227
+ function getAccessor(gltf, accessorIndex) {
228
+ const accessor = gltf.accessors?.[accessorIndex];
229
+ if (!accessor)
230
+ throw gltfDataError(`Missing accessor ${accessorIndex}.`);
231
+ return accessor;
232
+ }
233
+ function readComponent(view, offset, componentType, normalized) {
234
+ switch (componentType) {
235
+ case 5120: {
236
+ const value = view.getInt8(offset);
237
+ return normalized ? Math.max(value / 127, -1) : value;
238
+ }
239
+ case 5121: {
240
+ const value = view.getUint8(offset);
241
+ return normalized ? value / 255 : value;
242
+ }
243
+ case 5122: {
244
+ const value = view.getInt16(offset, true);
245
+ return normalized ? Math.max(value / 32767, -1) : value;
246
+ }
247
+ case 5123: {
248
+ const value = view.getUint16(offset, true);
249
+ return normalized ? value / 65535 : value;
250
+ }
251
+ case 5125: return view.getUint32(offset, true);
252
+ case 5126: return view.getFloat32(offset, true);
253
+ }
254
+ }
255
+ function addNormal(normals, index, x, y, z) {
256
+ const offset = index * 3;
257
+ if (offset < 0 || offset + 2 >= normals.length) {
258
+ throw gltfDataError(`Triangle index ${index} is outside the POSITION accessor.`);
259
+ }
260
+ normals[offset] = (normals[offset] ?? 0) + x;
261
+ normals[offset + 1] = (normals[offset + 1] ?? 0) + y;
262
+ normals[offset + 2] = (normals[offset + 2] ?? 0) + z;
263
+ }
264
+ function requiredFiniteArrayValue(values, index, label) {
265
+ const value = values[index];
266
+ if (value === undefined || !Number.isFinite(value)) {
267
+ throw gltfDataError(`${label} is missing a finite value at index ${index}.`);
268
+ }
269
+ return value;
270
+ }
271
+
272
+ const conservativeBoundsByGeometry = new WeakMap();
273
+ function registerGltfConservativeBounds(geometry, bounds) {
274
+ conservativeBoundsByGeometry.set(geometry, bounds);
275
+ }
276
+ function createAnimationClips(gltf, buffers, targets, skinnedPrimitives) {
277
+ return (gltf.animations ?? []).map((animation, index) => {
278
+ const channels = [];
279
+ let duration = 0;
280
+ for (const channel of animation.channels ?? []) {
281
+ const sampler = animation.samplers?.[channel.sampler];
282
+ const nodeIndex = channel.target.node;
283
+ const path = channel.target.path;
284
+ if (!sampler || nodeIndex === undefined || !isAnimationPath(path))
285
+ continue;
286
+ const target = targets.get(nodeIndex);
287
+ if (!target)
288
+ continue;
289
+ const input = readAccessorFloat(gltf, buffers, sampler.input, 1);
290
+ const outputSize = path === 'weights' ? Math.max(target.weights.length, target.morphPrimitives[0]?.positionTargets.length ?? 0, 1) : path === 'rotation' ? 4 : 3;
291
+ const output = path === 'weights'
292
+ ? readAccessorFloat(gltf, buffers, sampler.output, 1)
293
+ : readAccessorFloat(gltf, buffers, sampler.output, outputSize);
294
+ duration = Math.max(duration, input[input.length - 1] ?? 0);
295
+ channels.push({
296
+ target,
297
+ path,
298
+ interpolation: sampler.interpolation ?? 'LINEAR',
299
+ valueSize: outputSize,
300
+ input,
301
+ output,
302
+ sampleA: new Float32Array(outputSize),
303
+ sampleB: new Float32Array(outputSize),
304
+ sampleOut: new Float32Array(outputSize),
305
+ quatScratch: new Float32Array(4),
306
+ });
307
+ }
308
+ return {
309
+ name: animation.name || `Animation ${index + 1}`,
310
+ duration,
311
+ channels,
312
+ skinnedPrimitives,
313
+ stateCache: new Map(),
314
+ activeStates: [],
315
+ };
316
+ });
317
+ }
318
+ function isAnimationPath(path) {
319
+ return path === 'translation' || path === 'rotation' || path === 'scale' || path === 'weights';
320
+ }
321
+ function applyGltfAnimationClip(clip, time) {
322
+ if (clip.duration <= 0)
323
+ return;
324
+ const localTime = ((time % clip.duration) + clip.duration) % clip.duration;
325
+ const states = clip.stateCache;
326
+ const activeStates = clip.activeStates;
327
+ activeStates.length = 0;
328
+ for (const channel of clip.channels) {
329
+ const value = sampleAnimationChannel(channel, localTime, channel.sampleOut);
330
+ if (channel.path === 'weights') {
331
+ applyMorphWeights(channel.target, value);
332
+ continue;
333
+ }
334
+ let state = states.get(channel.target);
335
+ if (!state) {
336
+ state = {
337
+ target: channel.target,
338
+ translation: new Float32Array(3),
339
+ rotation: new Float32Array(4),
340
+ scale: new Float32Array(3),
341
+ matrix: new Float32Array(16),
342
+ active: false,
343
+ };
344
+ states.set(channel.target, state);
345
+ }
346
+ if (!state.active) {
347
+ state.translation.set(channel.target.translation);
348
+ state.rotation.set(channel.target.rotation);
349
+ state.scale.set(channel.target.scale);
350
+ state.active = true;
351
+ activeStates.push(state);
352
+ }
353
+ if (channel.path === 'translation')
354
+ copyComponents(value, state.translation, 3);
355
+ else if (channel.path === 'scale')
356
+ copyComponents(value, state.scale, 3);
357
+ else
358
+ normalizeQuat(value, state.rotation);
359
+ }
360
+ for (const state of activeStates) {
361
+ state.target.transform.localMatrix = composeTrsMatrix(state.translation, state.rotation, state.scale, state.matrix);
362
+ state.active = false;
363
+ }
364
+ for (const skinnedPrimitive of clip.skinnedPrimitives) {
365
+ updateSkinnedPrimitive(skinnedPrimitive);
366
+ }
367
+ }
368
+ function sampleAnimationChannel(channel, time, out) {
369
+ const times = channel.input;
370
+ const count = times.length;
371
+ const componentCount = channel.valueSize;
372
+ if (count === 0) {
373
+ fillDefaultAnimationValue(out, componentCount);
374
+ return out;
375
+ }
376
+ const firstTime = requiredFiniteArrayValue(times, 0, 'animation input');
377
+ const lastTime = requiredFiniteArrayValue(times, count - 1, 'animation input');
378
+ if (time <= firstTime)
379
+ return readAnimationValue(channel, 0, componentCount, out);
380
+ if (time >= lastTime)
381
+ return readAnimationValue(channel, count - 1, componentCount, out);
382
+ let frame = 0;
383
+ while (frame + 1 < count && requiredFiniteArrayValue(times, frame + 1, 'animation input') < time)
384
+ frame++;
385
+ const t0 = requiredFiniteArrayValue(times, frame, 'animation input');
386
+ const t1 = requiredFiniteArrayValue(times, frame + 1, 'animation input');
387
+ const alpha = channel.interpolation === 'STEP' ? 0 : (time - t0) / Math.max(0.000001, t1 - t0);
388
+ const a = readAnimationValue(channel, frame, componentCount, channel.sampleA);
389
+ if (channel.interpolation === 'STEP') {
390
+ copyComponents(a, out, componentCount);
391
+ return out;
392
+ }
393
+ const b = readAnimationValue(channel, frame + 1, componentCount, channel.sampleB);
394
+ if (channel.path === 'rotation')
395
+ return slerpQuat(a, b, alpha, out, channel.quatScratch);
396
+ return lerpArray(a, b, alpha, out, componentCount);
397
+ }
398
+ function readAnimationValue(channel, frame, componentCount, out) {
399
+ const cubic = channel.interpolation === 'CUBICSPLINE';
400
+ const stride = cubic ? componentCount * 3 : componentCount;
401
+ const offset = frame * stride + (cubic ? componentCount : 0);
402
+ for (let i = 0; i < componentCount; i++)
403
+ out[i] = channel.output[offset + i] ?? (i === 3 ? 1 : 0);
404
+ return out;
405
+ }
406
+ function fillDefaultAnimationValue(out, componentCount) {
407
+ for (let i = 0; i < componentCount; i++)
408
+ out[i] = i === 3 ? 1 : 0;
409
+ }
410
+ function copyComponents(source, target, count) {
411
+ for (let i = 0; i < count; i++)
412
+ target[i] = source[i] ?? 0;
413
+ }
414
+ function lerpArray(a, b, alpha, out, componentCount) {
415
+ for (let i = 0; i < componentCount; i++) {
416
+ const value = a[i] ?? 0;
417
+ out[i] = value + ((b[i] ?? value) - value) * alpha;
418
+ }
419
+ return out;
420
+ }
421
+ function normalizeQuat(q, out) {
422
+ const qx = q[0] ?? 0;
423
+ const qy = q[1] ?? 0;
424
+ const qz = q[2] ?? 0;
425
+ const qw = q[3] ?? 1;
426
+ const len = Math.hypot(qx, qy, qz, qw) || 1;
427
+ out[0] = qx / len;
428
+ out[1] = qy / len;
429
+ out[2] = qz / len;
430
+ out[3] = qw / len;
431
+ return out;
432
+ }
433
+ function slerpQuat(aRaw, bRaw, alpha, out, scratch) {
434
+ const a = normalizeQuat(aRaw, out);
435
+ const b = normalizeQuat(bRaw, scratch);
436
+ let bx = b[0] ?? 0;
437
+ let by = b[1] ?? 0;
438
+ let bz = b[2] ?? 0;
439
+ let bw = b[3] ?? 1;
440
+ const ax = a[0] ?? 0;
441
+ const ay = a[1] ?? 0;
442
+ const az = a[2] ?? 0;
443
+ const aw = a[3] ?? 1;
444
+ let dot = ax * bx + ay * by + az * bz + aw * bw;
445
+ if (dot < 0) {
446
+ dot = -dot;
447
+ bx = -bx;
448
+ by = -by;
449
+ bz = -bz;
450
+ bw = -bw;
451
+ }
452
+ if (dot > 0.9995) {
453
+ out[0] = ax + (bx - ax) * alpha;
454
+ out[1] = ay + (by - ay) * alpha;
455
+ out[2] = az + (bz - az) * alpha;
456
+ out[3] = aw + (bw - aw) * alpha;
457
+ return normalizeQuat(out, out);
458
+ }
459
+ const theta0 = Math.acos(Math.min(1, Math.max(-1, dot)));
460
+ const sinTheta0 = Math.sin(theta0);
461
+ const theta = theta0 * alpha;
462
+ const sinTheta = Math.sin(theta);
463
+ const s0 = Math.cos(theta) - dot * sinTheta / sinTheta0;
464
+ const s1 = sinTheta / sinTheta0;
465
+ out[0] = ax * s0 + bx * s1;
466
+ out[1] = ay * s0 + by * s1;
467
+ out[2] = az * s0 + bz * s1;
468
+ out[3] = aw * s0 + bw * s1;
469
+ return normalizeQuat(out, out);
470
+ }
471
+ function composeTrsMatrix(translation, rotation, scale, out = new Float32Array(16)) {
472
+ const rx = rotation[0] ?? 0;
473
+ const ry = rotation[1] ?? 0;
474
+ const rz = rotation[2] ?? 0;
475
+ const rw = rotation[3] ?? 1;
476
+ const len = Math.hypot(rx, ry, rz, rw) || 1;
477
+ const x = rx / len;
478
+ const y = ry / len;
479
+ const z = rz / len;
480
+ const w = rw / len;
481
+ const sx = scale[0] ?? 1;
482
+ const sy = scale[1] ?? 1;
483
+ const sz = scale[2] ?? 1;
484
+ const x2 = x + x;
485
+ const y2 = y + y;
486
+ const z2 = z + z;
487
+ const xx = x * x2;
488
+ const xy = x * y2;
489
+ const xz = x * z2;
490
+ const yy = y * y2;
491
+ const yz = y * z2;
492
+ const zz = z * z2;
493
+ const wx = w * x2;
494
+ const wy = w * y2;
495
+ const wz = w * z2;
496
+ out[0] = (1 - (yy + zz)) * sx;
497
+ out[1] = (xy + wz) * sx;
498
+ out[2] = (xz - wy) * sx;
499
+ out[3] = 0;
500
+ out[4] = (xy - wz) * sy;
501
+ out[5] = (1 - (xx + zz)) * sy;
502
+ out[6] = (yz + wx) * sy;
503
+ out[7] = 0;
504
+ out[8] = (xz + wy) * sz;
505
+ out[9] = (yz - wx) * sz;
506
+ out[10] = (1 - (xx + yy)) * sz;
507
+ out[11] = 0;
508
+ out[12] = translation[0] ?? 0;
509
+ out[13] = translation[1] ?? 0;
510
+ out[14] = translation[2] ?? 0;
511
+ out[15] = 1;
512
+ return out;
513
+ }
514
+ function applyMorphWeights(target, weights) {
515
+ if (target.morphPrimitives.length === 0)
516
+ return;
517
+ target.weights.length = weights.length;
518
+ for (let i = 0; i < weights.length; i++)
519
+ target.weights[i] = weights[i] ?? 0;
520
+ for (const morph of target.morphPrimitives) {
521
+ morph.geometry.setMorphWeights(target.weights);
522
+ updateConservativeMorphBounds(morph.geometry, target.weights);
523
+ if (morph.geometry.morphUseGpu)
524
+ continue;
525
+ const positions = morph.geometry.positions;
526
+ positions.set(morph.geometry.morphBasePositions ?? morph.basePositions);
527
+ for (let targetIndex = 0; targetIndex < morph.positionTargets.length; targetIndex++) {
528
+ const weight = weights[targetIndex] ?? 0;
529
+ if (weight === 0)
530
+ continue;
531
+ const delta = morph.positionTargets[targetIndex];
532
+ if (!delta || delta.length !== positions.length) {
533
+ throw gltfDataError('Morph POSITION target does not match the base position count.');
534
+ }
535
+ for (let i = 0; i < positions.length; i++) {
536
+ positions[i] = requiredFiniteArrayValue(positions, i, 'morph positions')
537
+ + requiredFiniteArrayValue(delta, i, 'morph POSITION target') * weight;
538
+ }
539
+ }
540
+ const normals = morph.geometry.normals;
541
+ const baseNormals = morph.geometry.morphBaseNormals ?? morph.baseNormals;
542
+ if (normals && baseNormals) {
543
+ normals.set(baseNormals);
544
+ for (let targetIndex = 0; targetIndex < morph.normalTargets.length; targetIndex++) {
545
+ const weight = weights[targetIndex] ?? 0;
546
+ if (weight === 0)
547
+ continue;
548
+ const delta = morph.normalTargets[targetIndex];
549
+ if (!delta || delta.length !== normals.length) {
550
+ throw gltfDataError('Morph NORMAL target does not match the base normal count.');
551
+ }
552
+ for (let i = 0; i < normals.length; i++) {
553
+ normals[i] = requiredFiniteArrayValue(normals, i, 'morph normals')
554
+ + requiredFiniteArrayValue(delta, i, 'morph NORMAL target') * weight;
555
+ }
556
+ }
557
+ }
558
+ morph.geometry.markDirty();
559
+ }
560
+ }
561
+ function updateSkinnedPrimitive(runtime) {
562
+ const meshWorldMatrix = updateEntityWorldMatrix(runtime.meshEntity);
563
+ const meshTransform = runtime.meshEntity.getComponent(Transform3D);
564
+ let dirty = runtime.lastMeshWorldVersion !== (meshTransform?.worldVersion ?? 0)
565
+ || runtime.lastGeometryVersion !== runtime.geometry.version;
566
+ for (let jointIndex = 0; jointIndex < runtime.jointTargets.length; jointIndex++) {
567
+ const target = runtime.jointTargets[jointIndex];
568
+ if (!target)
569
+ continue;
570
+ updateEntityWorldMatrix(target.entity);
571
+ const worldVersion = target.transform.worldVersion;
572
+ if (runtime.lastJointWorldVersions[jointIndex] !== worldVersion)
573
+ dirty = true;
574
+ }
575
+ if (!dirty)
576
+ return;
577
+ const inverseMeshWorld = mat4.inverse(meshWorldMatrix, runtime.inverseMeshWorldScratch);
578
+ for (let jointIndex = 0; jointIndex < runtime.jointTargets.length; jointIndex++) {
579
+ const jointTarget = runtime.jointTargets[jointIndex];
580
+ const inverseBind = runtime.inverseBindMatrices[jointIndex];
581
+ if (!jointTarget || !inverseBind) {
582
+ runtime.jointMatrices.set(IDENTITY_MATRIX, jointIndex * 16);
583
+ continue;
584
+ }
585
+ mat4.multiply(jointTarget.transform.worldMatrix, inverseBind, runtime.jointMatrixScratch);
586
+ mat4.multiply(inverseMeshWorld, runtime.jointMatrixScratch, runtime.skinMatrixScratch);
587
+ runtime.jointMatrices.set(runtime.skinMatrixScratch, jointIndex * 16);
588
+ }
589
+ runtime.geometry.updateSkinningMatrices(runtime.jointMatrices);
590
+ updateConservativeSkinBounds(runtime.geometry);
591
+ runtime.lastMeshWorldVersion = meshTransform?.worldVersion ?? 0;
592
+ runtime.lastGeometryVersion = runtime.geometry.version;
593
+ for (let jointIndex = 0; jointIndex < runtime.jointTargets.length; jointIndex++) {
594
+ runtime.lastJointWorldVersions[jointIndex] = runtime.jointTargets[jointIndex]?.transform.worldVersion ?? -1;
595
+ }
596
+ }
597
+ function updateConservativeMorphBounds(geometry, weights) {
598
+ const bounds = conservativeBoundsByGeometry.get(geometry);
599
+ if (!bounds)
600
+ return;
601
+ bounds.updateMorphWeights(weights);
602
+ geometry.setLocalBounds(geometry.skinning
603
+ ? bounds.getSkinnedBounds(geometry.skinning.jointMatrices, geometry.skinning.joints, geometry.skinning.weights)
604
+ : bounds.getSourceBounds());
605
+ }
606
+ function updateConservativeSkinBounds(geometry) {
607
+ const bounds = conservativeBoundsByGeometry.get(geometry);
608
+ if (!bounds || !geometry.skinning)
609
+ return;
610
+ geometry.setLocalBounds(bounds.getSkinnedBounds(geometry.skinning.jointMatrices, geometry.skinning.joints, geometry.skinning.weights));
611
+ }
612
+ const IDENTITY_MATRIX = mat4.identity();
613
+ function updateEntityWorldMatrix(entity) {
614
+ const transform = entity.getComponent(Transform3D);
615
+ const parent = entity.parent;
616
+ const parentWorld = parent ? updateEntityWorldMatrix(parent) : null;
617
+ if (transform) {
618
+ if (parent) {
619
+ const parentTransform = parent.getComponent(Transform3D);
620
+ transform.updateWorldMatrix(parentTransform?.worldMatrix ?? parentWorld ?? undefined, parentTransform?.worldVersion ?? 0);
621
+ }
622
+ else {
623
+ transform.updateWorldMatrix(undefined, 0);
624
+ }
625
+ return transform.worldMatrix;
626
+ }
627
+ return parentWorld ?? IDENTITY_MATRIX;
628
+ }
629
+
630
+ export { applyGltfAnimationClip as a, applyMorphWeights as b, composeTrsMatrix as c, attachGltfSource as d, createAnimationClips as e, readAccessorIndices as f, gltfDataError as g, generateFlatNormals as h, readAccessorUnsigned as i, registerGltfConservativeBounds as j, readAccessorMat4 as k, readAccessorFloat as r, throwIfGltfLoadAborted as t, updateSkinnedPrimitive as u };
631
+ //# sourceMappingURL=GltfAnimationRuntime-CRHsLycN.js.map