@carbonenginejs/runtime-resource 0.8.0 → 0.9.1

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 (297) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +31 -29
  3. package/README.md +67 -548
  4. package/dist/CjsMotherLode.js +1271 -1271
  5. package/dist/CjsResMan.js +3005 -3005
  6. package/dist/CjsResManQueue.js +214 -214
  7. package/dist/CjsResource.js +566 -566
  8. package/dist/CjsResourceSource.js +68 -59
  9. package/dist/CjsResourceSource.js.map +1 -1
  10. package/dist/_virtual/_rollupPluginBabelHelpers.js +153 -153
  11. package/dist/format/CjsBlueReader.js +269 -269
  12. package/dist/format/CjsFormat.js +197 -192
  13. package/dist/format/CjsFormat.js.map +1 -1
  14. package/dist/format/CjsReader.js +18 -18
  15. package/dist/format/CjsResourceProbe.js +277 -277
  16. package/dist/format/payloadContract.js +173 -173
  17. package/dist/formats/black/CjsBlackFormat.js +278 -278
  18. package/dist/formats/black/core/CjsBlackBinaryReader.js +157 -153
  19. package/dist/formats/black/core/CjsBlackBinaryReader.js.map +1 -1
  20. package/dist/formats/black/core/CjsBlackPropertyReaders.js +387 -382
  21. package/dist/formats/black/core/CjsBlackPropertyReaders.js.map +1 -1
  22. package/dist/formats/black/core/CjsBlackReader.js +639 -639
  23. package/dist/formats/black/core/CjsBlackSchemaRegistry.js +437 -433
  24. package/dist/formats/black/core/CjsBlackSchemaRegistry.js.map +1 -1
  25. package/dist/formats/black/core/black-schema-v1-2026-07-23.json.js +4 -0
  26. package/dist/formats/black/core/black-schema-v1-2026-07-23.json.js.map +1 -0
  27. package/dist/formats/black/core/blackConstants.js +7 -7
  28. package/dist/formats/black/core/blackDefinitions.js +10 -10
  29. package/dist/formats/black/core/blackDefinitions.js.map +1 -1
  30. package/dist/formats/black/core/blackEnums.js +6 -6
  31. package/dist/formats/black/core/blackSchema.js +3 -3
  32. package/dist/formats/black/core/blackVersion.js +22 -22
  33. package/dist/formats/black/core/helpers.js +182 -182
  34. package/dist/formats/black/core/schema.js +4 -4
  35. package/dist/formats/black/index.js +2 -2
  36. package/dist/formats/bnk/CjsBnkFormat.js +125 -125
  37. package/dist/formats/bnk/core/graph.js +140 -140
  38. package/dist/formats/bnk/core/helpers.js +409 -409
  39. package/dist/formats/bnk/core/musicNodes.js +493 -489
  40. package/dist/formats/bnk/core/musicNodes.js.map +1 -1
  41. package/dist/formats/bnk/core/soundbanksInfo.js +246 -246
  42. package/dist/formats/bnk/index.js +2 -2
  43. package/dist/formats/cmf/CjsCmfFormat.js +497 -497
  44. package/dist/formats/cmf/core/binary.js +123 -118
  45. package/dist/formats/cmf/core/binary.js.map +1 -1
  46. package/dist/formats/cmf/core/buffers.js +233 -233
  47. package/dist/formats/cmf/core/constants.js +47 -47
  48. package/dist/formats/cmf/core/gr2Anim.js +453 -453
  49. package/dist/formats/cmf/core/helpers.js +287 -287
  50. package/dist/formats/cmf/core/pack.js +276 -276
  51. package/dist/formats/cmf/core/schema.js +364 -364
  52. package/dist/formats/cmf/core/shared.js +268 -268
  53. package/dist/formats/cmf/core/writer.js +517 -517
  54. package/dist/formats/cmf/index.js +2 -2
  55. package/dist/formats/dds/CjsDdsFormat.js +200 -193
  56. package/dist/formats/dds/CjsDdsFormat.js.map +1 -1
  57. package/dist/formats/dds/core/bc6h.js +288 -288
  58. package/dist/formats/dds/core/bc7.js +256 -251
  59. package/dist/formats/dds/core/bc7.js.map +1 -1
  60. package/dist/formats/dds/core/helpers.js +815 -815
  61. package/dist/formats/dds/index.js +2 -2
  62. package/dist/formats/fbx/CjsFbxFormat.js +266 -266
  63. package/dist/formats/fbx/core/helpers.js +3911 -3901
  64. package/dist/formats/fbx/core/helpers.js.map +1 -1
  65. package/dist/formats/fbx/index.js +2 -2
  66. package/dist/formats/flac/CjsFlacFormat.js +93 -87
  67. package/dist/formats/flac/CjsFlacFormat.js.map +1 -1
  68. package/dist/formats/flac/core/helpers.js +295 -295
  69. package/dist/formats/flac/index.js +2 -2
  70. package/dist/formats/gif/CjsGifFormat.js +92 -87
  71. package/dist/formats/gif/CjsGifFormat.js.map +1 -1
  72. package/dist/formats/gif/core/helpers.js +360 -360
  73. package/dist/formats/gif/index.js +2 -2
  74. package/dist/formats/gltf/CjsGltfFormat.js +290 -290
  75. package/dist/formats/gltf/core/helpers.js +292 -292
  76. package/dist/formats/gltf/core/json.js +79 -79
  77. package/dist/formats/gltf/core/parser.js +666 -666
  78. package/dist/formats/gltf/core/targets.js +163 -163
  79. package/dist/formats/gltf/index.js +2 -2
  80. package/dist/formats/gr2/CjsGr2Format.js +46 -0
  81. package/dist/formats/gr2/CjsGr2Format.js.map +1 -0
  82. package/dist/formats/gr2/core/CjsFormatGr2.js +273 -0
  83. package/dist/formats/gr2/core/CjsFormatGr2.js.map +1 -0
  84. package/dist/formats/gr2/core/bitknit2.js +280 -0
  85. package/dist/formats/gr2/core/bitknit2.js.map +1 -0
  86. package/dist/formats/gr2/core/curves.js +1047 -0
  87. package/dist/formats/gr2/core/curves.js.map +1 -0
  88. package/dist/formats/gr2/core/gsf.js +72 -0
  89. package/dist/formats/gr2/core/gsf.js.map +1 -0
  90. package/dist/formats/gr2/core/helpers.js +332 -0
  91. package/dist/formats/gr2/core/helpers.js.map +1 -0
  92. package/dist/formats/gr2/core/json.js +622 -0
  93. package/dist/formats/gr2/core/json.js.map +1 -0
  94. package/dist/formats/gr2/core/oodle1.js +388 -0
  95. package/dist/formats/gr2/core/oodle1.js.map +1 -0
  96. package/dist/formats/gr2/core/reader.js +617 -0
  97. package/dist/formats/gr2/core/reader.js.map +1 -0
  98. package/dist/formats/gr2/core/tangents.js +48 -0
  99. package/dist/formats/gr2/core/tangents.js.map +1 -0
  100. package/dist/formats/gr2/core/targets.js +351 -0
  101. package/dist/formats/gr2/core/targets.js.map +1 -0
  102. package/dist/formats/gr2/index.js +3 -0
  103. package/dist/formats/gr2/index.js.map +1 -0
  104. package/dist/formats/index.js +30 -23
  105. package/dist/formats/index.js.map +1 -1
  106. package/dist/formats/jpeg/CjsJpegFormat.js +212 -206
  107. package/dist/formats/jpeg/CjsJpegFormat.js.map +1 -1
  108. package/dist/formats/jpeg/core/helpers.js +350 -350
  109. package/dist/formats/jpeg/core/jpeg.js +387 -377
  110. package/dist/formats/jpeg/core/jpeg.js.map +1 -1
  111. package/dist/formats/jpeg/index.js +2 -2
  112. package/dist/formats/mp3/CjsMp3Format.js +197 -192
  113. package/dist/formats/mp3/CjsMp3Format.js.map +1 -1
  114. package/dist/formats/mp3/core/helpers.js +338 -338
  115. package/dist/formats/mp3/index.js +2 -2
  116. package/dist/formats/mp4/CjsMp4Format.js +197 -191
  117. package/dist/formats/mp4/CjsMp4Format.js.map +1 -1
  118. package/dist/formats/mp4/core/helpers.js +449 -449
  119. package/dist/formats/mp4/index.js +2 -2
  120. package/dist/formats/obj/CjsObjFormat.js +253 -253
  121. package/dist/formats/obj/core/helpers.js +573 -573
  122. package/dist/formats/obj/core/json.js +64 -64
  123. package/dist/formats/obj/core/parser.js +321 -321
  124. package/dist/formats/obj/index.js +2 -2
  125. package/dist/formats/ogg/CjsOggFormat.js +94 -88
  126. package/dist/formats/ogg/CjsOggFormat.js.map +1 -1
  127. package/dist/formats/ogg/core/helpers.js +387 -387
  128. package/dist/formats/ogg/core/imdct.js +178 -178
  129. package/dist/formats/ogg/core/vorbis.js +1004 -999
  130. package/dist/formats/ogg/core/vorbis.js.map +1 -1
  131. package/dist/formats/ogg/index.js +2 -2
  132. package/dist/formats/png/CjsPngFormat.js +201 -195
  133. package/dist/formats/png/CjsPngFormat.js.map +1 -1
  134. package/dist/formats/png/core/helpers.js +583 -583
  135. package/dist/formats/png/index.js +2 -2
  136. package/dist/formats/red/CjsRedFormat.js +261 -261
  137. package/dist/formats/red/core/CjsRedReader.js +194 -194
  138. package/dist/formats/red/core/blackDefinitions.js +3 -3
  139. package/dist/formats/red/core/helpers.js +139 -139
  140. package/dist/formats/red/core/redGraph.js +68 -68
  141. package/dist/formats/red/core/schema.js +4 -4
  142. package/dist/formats/red/index.js +2 -2
  143. package/dist/formats/stl/CjsStlFormat.js +365 -365
  144. package/dist/formats/stl/core/helpers.js +261 -261
  145. package/dist/formats/stl/core/json.js +51 -51
  146. package/dist/formats/stl/core/stl.js +634 -629
  147. package/dist/formats/stl/core/stl.js.map +1 -1
  148. package/dist/formats/stl/core/targets.js +163 -163
  149. package/dist/formats/stl/index.js +2 -2
  150. package/dist/formats/tga/CjsTgaFormat.js +197 -192
  151. package/dist/formats/tga/CjsTgaFormat.js.map +1 -1
  152. package/dist/formats/tga/core/helpers.js +446 -446
  153. package/dist/formats/tga/index.js +2 -2
  154. package/dist/formats/wav/CjsWavFormat.js +198 -192
  155. package/dist/formats/wav/CjsWavFormat.js.map +1 -1
  156. package/dist/formats/wav/core/helpers.js +328 -328
  157. package/dist/formats/wav/index.js +2 -2
  158. package/dist/formats/webm/CjsWebmFormat.js +197 -191
  159. package/dist/formats/webm/CjsWebmFormat.js.map +1 -1
  160. package/dist/formats/webm/core/helpers.js +537 -537
  161. package/dist/formats/webm/index.js +2 -2
  162. package/dist/formats/webp/CjsWebpFormat.js +91 -86
  163. package/dist/formats/webp/CjsWebpFormat.js.map +1 -1
  164. package/dist/formats/webp/core/helpers.js +214 -214
  165. package/dist/formats/webp/index.js +2 -2
  166. package/dist/formats/wem/CjsWemFormat.js +242 -241
  167. package/dist/formats/wem/CjsWemFormat.js.map +1 -1
  168. package/dist/formats/wem/core/bitStream.js +259 -259
  169. package/dist/formats/wem/core/codebookLibrary.js +164 -164
  170. package/dist/formats/wem/core/helpers.js +417 -417
  171. package/dist/formats/wem/core/packedCodebooksAotuv603.js +30 -30
  172. package/dist/formats/wem/core/ptadpcm.js +77 -77
  173. package/dist/formats/wem/core/resolve.js +121 -121
  174. package/dist/formats/wem/core/wemToOgg.js +485 -485
  175. package/dist/formats/wem/index.js +2 -2
  176. package/dist/formats/yaml/CjsYamlFormat.js +89 -83
  177. package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
  178. package/dist/formats/yaml/core/CjsYamlReader.js +311 -305
  179. package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
  180. package/dist/formats/yaml/core/helpers.js +160 -160
  181. package/dist/formats/yaml/index.js +2 -2
  182. package/dist/index.js +49 -48
  183. package/dist/index.js.map +1 -1
  184. package/dist/resourcePath.js +18 -18
  185. package/dist/resourceStates.js +9 -9
  186. package/dist/resources/AudioGeometryResData.js +47 -47
  187. package/dist/resources/GStateBindingCallbackData.js +31 -31
  188. package/dist/resources/MeshDecalData.js +37 -37
  189. package/dist/resources/MeshDecalLodData.js +34 -34
  190. package/dist/resources/Tr2EffectRes.js +71 -71
  191. package/dist/resources/Tr2GrannyIntersectionResult.js +60 -60
  192. package/dist/resources/Tr2GrannyStateRes.js +44 -44
  193. package/dist/resources/Tr2ImageRes.js +114 -114
  194. package/dist/resources/Tr2LightProfileRes.js +40 -40
  195. package/dist/resources/Tr2MaterialArea.js +34 -34
  196. package/dist/resources/Tr2MaterialMesh.js +31 -31
  197. package/dist/resources/Tr2MaterialRes.js +34 -34
  198. package/dist/resources/Tr2ShaderPermutation.js +43 -43
  199. package/dist/resources/Tr2TextureLodManager.js +80 -80
  200. package/dist/resources/Tr2TextureLodUpdateRequest.js +37 -37
  201. package/dist/resources/Tr2TexturePackChannel.js +37 -37
  202. package/dist/resources/Tr2TexturePipeline.js +52 -52
  203. package/dist/resources/Tr2TexturePipelineParams.js +34 -34
  204. package/dist/resources/Tr2TexturePipelineStepCompress.js +40 -40
  205. package/dist/resources/Tr2TexturePipelineStepGenerateMips.js +22 -0
  206. package/dist/resources/Tr2TexturePipelineStepGenerateMips.js.map +1 -0
  207. package/dist/resources/Tr2TexturePipelineStepLimitSize.js +34 -34
  208. package/dist/resources/Tr2TexturePipelineStepLoad.js +31 -31
  209. package/dist/resources/Tr2TexturePipelineStepPack.js +43 -43
  210. package/dist/resources/TriGeometryRes.js +239 -239
  211. package/dist/resources/TriGeometryResAreaData.js +59 -59
  212. package/dist/resources/TriGeometryResJointData.js +38 -38
  213. package/dist/resources/TriGeometryResLodData.js +88 -88
  214. package/dist/resources/TriGeometryResMeshData.js +63 -63
  215. package/dist/resources/TriGeometryResSkeletonData.js +34 -34
  216. package/dist/resources/TriGrannyRes.js +43 -43
  217. package/dist/resources/TriJointBinding.js +38 -38
  218. package/dist/resources/TriMorphTargetGeometryConstants.js +46 -46
  219. package/dist/resources/TriRtGeometryConstants.js +88 -88
  220. package/dist/resources/TriTextureRes.js +304 -304
  221. package/dist/resources/enums.js +18 -18
  222. package/dist/resources/resourceBoundary.js +47 -47
  223. package/dist/resources/texturePipelineBehavior.js +308 -308
  224. package/dist/texture/CjsTextureArrayRes.js +406 -406
  225. package/dist/texture/CjsTextureParameterProxy.js +133 -133
  226. package/docs/README.md +73 -0
  227. package/docs/architecture.md +86 -0
  228. package/docs/concepts/resource-lifecycle.md +217 -0
  229. package/docs/formats/README.md +105 -0
  230. package/docs/formats/gr2.md +161 -0
  231. package/{FORMAT-PROVENANCE.md → docs/formats/provenance.md} +173 -155
  232. package/docs/formats/stl.md +37 -0
  233. package/docs/formats/wwise.md +44 -0
  234. package/docs/reference/classes/README.md +33 -0
  235. package/docs/reference/classes/core.md +106 -0
  236. package/docs/reference/classes/dropped.md +46 -0
  237. package/docs/reference/classes/formats.md +522 -0
  238. package/docs/reference/classes/resources.md +346 -0
  239. package/docs/reference/classes/texture.md +26 -0
  240. package/docs/reference/events.md +92 -0
  241. package/docs/reference/motherlode-cache.md +244 -0
  242. package/docs/reference/queues.md +102 -0
  243. package/docs/reference/reload.md +107 -0
  244. package/docs/reference/texture-arrays.md +113 -0
  245. package/docs/reference/texture-pipeline.md +53 -0
  246. package/docs/roadmap.md +104 -0
  247. package/format-notices/black/LICENSE +21 -21
  248. package/format-notices/black/NOTICE +47 -47
  249. package/format-notices/bnk/LICENSE +21 -21
  250. package/format-notices/bnk/NOTICE +20 -20
  251. package/format-notices/cmf/LICENSE +21 -21
  252. package/format-notices/cmf/NOTICE +36 -36
  253. package/format-notices/dds/LICENSE +21 -21
  254. package/format-notices/dds/NOTICE +14 -14
  255. package/format-notices/fbx/LICENSE +21 -21
  256. package/format-notices/fbx/NOTICE +14 -14
  257. package/format-notices/flac/LICENSE +21 -21
  258. package/format-notices/flac/NOTICE +14 -14
  259. package/format-notices/gif/LICENSE +21 -21
  260. package/format-notices/gif/NOTICE +14 -14
  261. package/format-notices/gltf/LICENSE +21 -21
  262. package/format-notices/gltf/NOTICE +27 -27
  263. package/format-notices/gr2/LICENSE +21 -0
  264. package/format-notices/gr2/NOTICE +60 -0
  265. package/format-notices/gr2/THIRD-PARTY-NOTICES.md +93 -0
  266. package/format-notices/jpeg/LICENSE +21 -21
  267. package/format-notices/jpeg/NOTICE +14 -14
  268. package/format-notices/mp3/LICENSE +21 -21
  269. package/format-notices/mp3/NOTICE +14 -14
  270. package/format-notices/mp4/LICENSE +21 -21
  271. package/format-notices/mp4/NOTICE +14 -14
  272. package/format-notices/obj/LICENSE +21 -21
  273. package/format-notices/obj/NOTICE +26 -26
  274. package/format-notices/ogg/LICENSE +21 -21
  275. package/format-notices/ogg/NOTICE +28 -28
  276. package/format-notices/png/LICENSE +21 -21
  277. package/format-notices/png/NOTICE +14 -14
  278. package/format-notices/red/LICENSE +21 -21
  279. package/format-notices/red/NOTICE +31 -31
  280. package/format-notices/stl/LICENSE +21 -21
  281. package/format-notices/stl/NOTICE +21 -21
  282. package/format-notices/tga/LICENSE +21 -21
  283. package/format-notices/tga/NOTICE +14 -14
  284. package/format-notices/wav/LICENSE +21 -21
  285. package/format-notices/wav/NOTICE +14 -14
  286. package/format-notices/webm/LICENSE +21 -21
  287. package/format-notices/webm/NOTICE +14 -14
  288. package/format-notices/webp/LICENSE +21 -21
  289. package/format-notices/webp/NOTICE +14 -14
  290. package/format-notices/wem/LICENSE +57 -57
  291. package/format-notices/wem/NOTICE +33 -33
  292. package/format-notices/yaml/LICENSE +21 -21
  293. package/format-notices/yaml/NOTICE +44 -44
  294. package/package.json +52 -51
  295. package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js +0 -4
  296. package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js.map +0 -1
  297. package/resource-lifecycle.md +0 -679
@@ -0,0 +1,1047 @@
1
+ /**
2
+ * Granny animation-curve decompression helpers
3
+ * `decodeCurve(curveJson, dimension)` takes a GR2 JSON curve object in the
4
+ * shape emitted by PrintCurve2 and returns explicit knots and controls.
5
+ */
6
+
7
+ /** Format id for raw float keyframes with implicit knots. */
8
+ const FORMAT_DA_KEYFRAMES_32F = 0;
9
+
10
+ /** Format id for uncompressed float knots and float controls. */
11
+ const FORMAT_DA_K32F_C32F = 1;
12
+
13
+ /** Format id for an identity transform curve. */
14
+ const FORMAT_DA_IDENTITY = 2;
15
+
16
+ /** Format id for a constant float control vector. */
17
+ const FORMAT_DA_CONSTANT_32F = 3;
18
+
19
+ /** Format id for a constant vec3 control. */
20
+ const FORMAT_D3_CONSTANT_32F = 4;
21
+
22
+ /** Format id for a constant quaternion control. */
23
+ const FORMAT_D4_CONSTANT_32F = 5;
24
+
25
+ /** Format id for uint16 DaK packed knots and controls. */
26
+ const FORMAT_DA_K16U_C16U = 6;
27
+
28
+ /** Format id for uint8 DaK packed knots and controls. */
29
+ const FORMAT_DA_K8U_C8U = 7;
30
+
31
+ /** Format id for uint16 normalized quaternion curves with 15-bit controls. */
32
+ const FORMAT_D4N_K16U_C15U = 8;
33
+
34
+ /** Format id for uint8 normalized quaternion curves with 7-bit controls. */
35
+ const FORMAT_D4N_K8U_C7U = 9;
36
+
37
+ /** Format id for uint16 vec3 position curves. */
38
+ const FORMAT_D3_K16U_C16U = 10;
39
+
40
+ /** Format id for uint8 vec3 position curves. */
41
+ const FORMAT_D3_K8U_C8U = 11;
42
+
43
+ /** Format id for uint16 uniform scale/shear curves. */
44
+ const FORMAT_D9I1_K16U_C16U = 12;
45
+
46
+ /** Format id for uint16 per-axis scale/shear curves. */
47
+ const FORMAT_D9I3_K16U_C16U = 13;
48
+
49
+ /** Format id for uint8 uniform scale/shear curves. */
50
+ const FORMAT_D9I1_K8U_C8U = 14;
51
+
52
+ /** Format id for uint8 per-axis scale/shear curves. */
53
+ const FORMAT_D9I3_K8U_C8U = 15;
54
+
55
+ /** Format id for float D3I1 line-parameterized vec3 curves. */
56
+ const FORMAT_D3I1_K32F_C32F = 16;
57
+
58
+ /** Format id for uint16 D3I1 line-parameterized vec3 curves. */
59
+ const FORMAT_D3I1_K16U_C16U = 17;
60
+
61
+ /** Format id for uint8 D3I1 line-parameterized vec3 curves. */
62
+ const FORMAT_D3I1_K8U_C8U = 18;
63
+
64
+ /**
65
+ * Granny curve format ids keyed by descriptive uppercase names.
66
+ */
67
+ const CURVE_FORMATS = Object.freeze({
68
+ DA_KEYFRAMES_32F: FORMAT_DA_KEYFRAMES_32F,
69
+ DA_K32F_C32F: FORMAT_DA_K32F_C32F,
70
+ DA_IDENTITY: FORMAT_DA_IDENTITY,
71
+ DA_CONSTANT_32F: FORMAT_DA_CONSTANT_32F,
72
+ D3_CONSTANT_32F: FORMAT_D3_CONSTANT_32F,
73
+ D4_CONSTANT_32F: FORMAT_D4_CONSTANT_32F,
74
+ DA_K16U_C16U: FORMAT_DA_K16U_C16U,
75
+ DA_K8U_C8U: FORMAT_DA_K8U_C8U,
76
+ D4N_K16U_C15U: FORMAT_D4N_K16U_C15U,
77
+ D4N_K8U_C7U: FORMAT_D4N_K8U_C7U,
78
+ D3_K16U_C16U: FORMAT_D3_K16U_C16U,
79
+ D3_K8U_C8U: FORMAT_D3_K8U_C8U,
80
+ D9I1_K16U_C16U: FORMAT_D9I1_K16U_C16U,
81
+ D9I3_K16U_C16U: FORMAT_D9I3_K16U_C16U,
82
+ D9I1_K8U_C8U: FORMAT_D9I1_K8U_C8U,
83
+ D9I3_K8U_C8U: FORMAT_D9I3_K8U_C8U,
84
+ D3I1_K32F_C32F: FORMAT_D3I1_K32F_C32F,
85
+ D3I1_K16U_C16U: FORMAT_D3I1_K16U_C16U,
86
+ D3I1_K8U_C8U: FORMAT_D3I1_K8U_C8U
87
+ });
88
+
89
+ /**
90
+ * Float32 rounding helper used to mirror the reference curve decoders.
91
+ *
92
+ * The reference implementation stores every decoded value into Float32Array
93
+ * buffers, so this helper applies the same rounding at each write.
94
+ */
95
+ const fr = Math.fround;
96
+
97
+ /**
98
+ * Granny stores 1/knotScale as the top 16 bits of the float only
99
+ * ("OneOverKnotScaleTrunc"). Reconstruct the float32.
100
+ * @param {number} oneOverKnotScaleTrunc uint16
101
+ * @returns {number}
102
+ */
103
+ function knotScaleFromTrunc(oneOverKnotScaleTrunc) {
104
+ const u = new Uint32Array([oneOverKnotScaleTrunc << 16]);
105
+ return new Float32Array(u.buffer)[0];
106
+ }
107
+
108
+ /**
109
+ * Expand the leading `count` entries of a knotsControls array into knots.
110
+ * @param {ArrayLike<number>} knotsControls
111
+ * @param {number} count
112
+ * @param {number} scale divisor (1/knotScale)
113
+ * @returns {number[]}
114
+ */
115
+ function knotsFromControls(knotsControls, count, scale) {
116
+ const out = new Array(count);
117
+ for (let i = 0; i < count; i++) {
118
+ out[i] = fr(knotsControls[i] / scale);
119
+ }
120
+ return out;
121
+ }
122
+
123
+ /**
124
+ * Knots via the truncated knot scale.
125
+ *
126
+ * @param {ArrayLike<number>} knotsControls Packed knot/control array.
127
+ * @param {number} count Number of knots at the front of `knotsControls`.
128
+ * @param {number} oneOverKnotScaleTrunc Truncated reciprocal knot scale.
129
+ * @returns {number[]} Decoded knot times.
130
+ */
131
+ function knotsFromControlsTrunc(knotsControls, count, oneOverKnotScaleTrunc) {
132
+ return knotsFromControls(knotsControls, count, knotScaleFromTrunc(oneOverKnotScaleTrunc));
133
+ }
134
+
135
+ /**
136
+ * Identity control vector for a track dimension.
137
+ * @param {number} dimension 3 (position), 4 (quaternion) or 9 (mat3)
138
+ * @returns {number[]}
139
+ */
140
+ function identityControls(dimension) {
141
+ switch (dimension) {
142
+ case 3:
143
+ return [0, 0, 0];
144
+ case 4:
145
+ return [0, 0, 0, 1];
146
+ case 9:
147
+ return [1, 0, 0, 0, 1, 0, 0, 0, 1];
148
+ default:
149
+ throw new Error(`gr2reader: invalid curve dimension ${dimension}`);
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Ensure a divisibility relation holds; throws with a descriptive error.
155
+ *
156
+ * @param {number} numerator Value expected to divide evenly.
157
+ * @param {number} divisor Divisor to check against.
158
+ * @param {string} what Human-readable operation name for the error message.
159
+ * @returns {number} Exact quotient.
160
+ * @throws {Error} If the quotient is not an integer.
161
+ */
162
+ function exactDiv(numerator, divisor, what) {
163
+ const v = numerator / divisor;
164
+ if (!Number.isInteger(v)) {
165
+ throw new Error(`gr2reader: curve ${what}: ${numerator} is not divisible by ${divisor}`);
166
+ }
167
+ return v;
168
+ }
169
+
170
+ /**
171
+ * Decode raw keyframe controls with implicit knots `0..n-1`.
172
+ *
173
+ * @param {object} c Curve object with `controls` and optional `dimension`.
174
+ * @param {number} dimension Fallback control-vector width.
175
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
176
+ */
177
+ function decodeDaKeyframes32f(c, dimension) {
178
+ const dim = c.dimension || dimension,
179
+ controls = c.controls || [],
180
+ count = exactDiv(controls.length, dim, "DaKeyframes32f controls/dimension"),
181
+ knots = new Array(count);
182
+ for (let i = 0; i < count; i++) {
183
+ knots[i] = i;
184
+ }
185
+ return {
186
+ knots,
187
+ controls: controls.map(fr),
188
+ dimension: dim
189
+ };
190
+ }
191
+
192
+ /**
193
+ * Decode uncompressed float knots and float controls.
194
+ *
195
+ * @param {object} c Curve object with `knots` and `controls`.
196
+ * @param {number} dimension Fallback control-vector width when no knots exist.
197
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
198
+ */
199
+ function decodeDaK32fC32f(c, dimension) {
200
+ const knots = (c.knots || []).map(fr),
201
+ controls = (c.controls || []).map(fr),
202
+ dim = knots.length ? exactDiv(controls.length, knots.length, "DaK32fC32f controls/knots") : dimension;
203
+ return {
204
+ knots,
205
+ controls,
206
+ dimension: dim
207
+ };
208
+ }
209
+
210
+ /**
211
+ * Decode an identity transform curve for the requested track dimension.
212
+ *
213
+ * @param {object} c Curve object with optional `dimension`.
214
+ * @param {number} dimension Fallback control-vector width.
215
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
216
+ */
217
+ function decodeDaIdentity(c, dimension) {
218
+ const dim = c.dimension || dimension;
219
+ return {
220
+ knots: [0],
221
+ controls: identityControls(dim),
222
+ dimension: dim
223
+ };
224
+ }
225
+
226
+ /**
227
+ * Decode a constant float control vector.
228
+ *
229
+ * @param {object} c Curve object with `controls`.
230
+ * @param {number} dimension Fallback control-vector width.
231
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
232
+ */
233
+ function decodeDaConstant32f(c, dimension) {
234
+ const controls = (c.controls || []).map(fr);
235
+ return {
236
+ knots: [0],
237
+ controls,
238
+ dimension: controls.length || dimension
239
+ };
240
+ }
241
+
242
+ /**
243
+ * Decode a constant vec3 control.
244
+ *
245
+ * @param {object} c Curve object with optional `controls`.
246
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
247
+ */
248
+ function decodeD3Constant32f(c) {
249
+ const controls = (c.controls || [0, 0, 0]).slice(0, 3).map(fr);
250
+ return {
251
+ knots: [0],
252
+ controls,
253
+ dimension: 3
254
+ };
255
+ }
256
+
257
+ /**
258
+ * Decode a constant quaternion control.
259
+ *
260
+ * @param {object} c Curve object with optional `controls`.
261
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
262
+ */
263
+ function decodeD4Constant32f(c) {
264
+ const controls = (c.controls || [0, 0, 0, 1]).slice(0, 4).map(fr);
265
+ return {
266
+ knots: [0],
267
+ controls,
268
+ dimension: 4
269
+ };
270
+ }
271
+
272
+ /**
273
+ * Decode a DaK packed knot/control curve using uint16 payload values.
274
+ *
275
+ * @param {object} c Curve object with `knotsControls`, `controlScaleOffsets`,
276
+ * and `oneOverKnotScaleTrunc`.
277
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
278
+ */
279
+ function decodeDaK(c) {
280
+ const so = c.controlScaleOffsets || [],
281
+ kc = c.knotsControls || [],
282
+ dim = exactDiv(so.length, 2, "DaK controlScaleOffsets/2"),
283
+ count = exactDiv(kc.length, dim + 1, "DaK knotsControls/(dim+1)"),
284
+ knots = knotsFromControlsTrunc(kc, count, c.oneOverKnotScaleTrunc),
285
+ controls = new Array(count * dim);
286
+ for (let i = 0; i < count; i++) {
287
+ for (let x = 0; x < dim; x++) {
288
+ controls[i * dim + x] = fr(kc[count + i * dim + x] * so[x] + so[dim + x]);
289
+ }
290
+ }
291
+ return {
292
+ knots,
293
+ controls,
294
+ dimension: dim
295
+ };
296
+ }
297
+
298
+ /** Scale lookup table for D4n normalized quaternion controls. */
299
+ const D4N_SCALE_TABLE = new Float32Array([1.4142135, 0.70710677, 0.35355338, 0.35355338, 0.35355338, 0.17677669, 0.17677669, 0.17677669, -1.4142135, -0.70710677, -0.35355338, -0.35355338, -0.35355338, -0.17677669, -0.17677669, -0.17677669]);
300
+
301
+ /** Offset lookup table for D4n normalized quaternion controls. */
302
+ const D4N_OFFSET_TABLE = new Float32Array([-0.70710677, -0.35355338, -0.53033006, -0.17677669, 0.17677669, -0.17677669, -0.088388346, 0.0, 0.70710677, 0.35355338, 0.53033006, 0.17677669, -0.17677669, 0.17677669, 0.088388346, -0]);
303
+
304
+ /**
305
+ * Decode one 16-bit control triple into a quaternion (matches ccpwgl
306
+ * Gr2CurveDataD4nK16uC15u.GetQuatFromControl).
307
+ *
308
+ * @param {number[]} out Mutable quaternion output buffer.
309
+ * @param {number} a First packed control value.
310
+ * @param {number} b Second packed control value.
311
+ * @param {number} c Third packed control value.
312
+ * @param {ArrayLike<number>} scales Four scale values selected from the table.
313
+ * @param {ArrayLike<number>} offsets Four offset values selected from the table.
314
+ * @returns {number[]} The same `out` quaternion buffer.
315
+ */
316
+ function quatFromControl16(out, a, b, c, scales, offsets) {
317
+ const swizzle1 = (b & 0x8000) >> 14 | c >> 15,
318
+ swizzle2 = swizzle1 + 1 & 3,
319
+ swizzle3 = swizzle2 + 1 & 3,
320
+ swizzle4 = swizzle3 + 1 & 3;
321
+ const dataA = (a & 0x7fff) * scales[swizzle2] + offsets[swizzle2],
322
+ dataB = (b & 0x7fff) * scales[swizzle3] + offsets[swizzle3],
323
+ dataC = (c & 0x7fff) * scales[swizzle4] + offsets[swizzle4];
324
+ let dataD = Math.sqrt(Math.max(0, 1 - (dataA * dataA + dataB * dataB + dataC * dataC)));
325
+ if ((a & 0x8000) !== 0) dataD = -dataD;
326
+ out[swizzle2] = fr(dataA);
327
+ out[swizzle3] = fr(dataB);
328
+ out[swizzle4] = fr(dataC);
329
+ out[swizzle1] = fr(dataD);
330
+ return out;
331
+ }
332
+
333
+ /** Scale-table multiplier for D4n 16-bit knot / 15-bit control curves. */
334
+ const D4N_SCALE_TABLE_MULTIPLIER_16 = 0.000030518509;
335
+
336
+ /**
337
+ * Decode a D4n normalized quaternion curve using a supplied control decoder.
338
+ *
339
+ * @param {object} c Curve object with `knotsControls`, `scaleOffsetTableEntries`,
340
+ * and `oneOverKnotScale`.
341
+ * @param {Function} quatFromControl Function that expands one packed control
342
+ * triple into a quaternion.
343
+ * @param {number} scaleTableMultiplier Multiplier for selected scale table entries.
344
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
345
+ */
346
+ function decodeD4n(c, quatFromControl, scaleTableMultiplier) {
347
+ const kc = c.knotsControls || [],
348
+ count = exactDiv(kc.length, 4, "D4n knotsControls/4"),
349
+ knots = knotsFromControls(kc, count, c.oneOverKnotScale);
350
+ const selector = c.scaleOffsetTableEntries >>> 0,
351
+ scales = new Float32Array([D4N_SCALE_TABLE[selector >> 0 & 0x0f] * scaleTableMultiplier, D4N_SCALE_TABLE[selector >> 4 & 0x0f] * scaleTableMultiplier, D4N_SCALE_TABLE[selector >> 8 & 0x0f] * scaleTableMultiplier, D4N_SCALE_TABLE[selector >> 12 & 0x0f] * scaleTableMultiplier]),
352
+ offsets = new Float32Array([D4N_OFFSET_TABLE[selector >> 0 & 0x0f], D4N_OFFSET_TABLE[selector >> 4 & 0x0f], D4N_OFFSET_TABLE[selector >> 8 & 0x0f], D4N_OFFSET_TABLE[selector >> 12 & 0x0f]]);
353
+ const controls = new Array(count * 4),
354
+ quat = [0, 0, 0, 1];
355
+ for (let i = 0; i < count; i++) {
356
+ quatFromControl(quat, kc[count + i * 3], kc[count + i * 3 + 1], kc[count + i * 3 + 2], scales, offsets);
357
+ controls[i * 4] = quat[0];
358
+ controls[i * 4 + 1] = quat[1];
359
+ controls[i * 4 + 2] = quat[2];
360
+ controls[i * 4 + 3] = quat[3];
361
+ }
362
+ return {
363
+ knots,
364
+ controls,
365
+ dimension: 4
366
+ };
367
+ }
368
+
369
+ /**
370
+ * Decode a D4n curve using 16-bit knots and 15-bit quaternion controls.
371
+ *
372
+ * @param {object} c Curve object with packed quaternion data.
373
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
374
+ */
375
+ function decodeD4nK16uC15u(c) {
376
+ return decodeD4n(c, quatFromControl16, D4N_SCALE_TABLE_MULTIPLIER_16);
377
+ }
378
+
379
+ /** Scale-table multiplier for D4n 8-bit knot / 7-bit control curves. */
380
+ const D4N_SCALE_TABLE_MULTIPLIER_8 = 0.0078740157;
381
+
382
+ /**
383
+ * Decode one 8-bit control triple into a quaternion.
384
+ *
385
+ * @param {number[]} out Mutable quaternion output buffer.
386
+ * @param {number} a First packed control value.
387
+ * @param {number} b Second packed control value.
388
+ * @param {number} c Third packed control value.
389
+ * @param {ArrayLike<number>} scales Four scale values selected from the table.
390
+ * @param {ArrayLike<number>} offsets Four offset values selected from the table.
391
+ * @returns {number[]} The same `out` quaternion buffer.
392
+ */
393
+ function quatFromControl8(out, a, b, c, scales, offsets) {
394
+ const swizzle1 = (b & 0x80) >> 6 | (c & 0x80) >> 7,
395
+ swizzle2 = swizzle1 + 1 & 3,
396
+ swizzle3 = swizzle2 + 1 & 3,
397
+ swizzle4 = swizzle3 + 1 & 3;
398
+ const dataA = (a & 0x7f) * scales[swizzle2] + offsets[swizzle2],
399
+ dataB = (b & 0x7f) * scales[swizzle3] + offsets[swizzle3],
400
+ dataC = (c & 0x7f) * scales[swizzle4] + offsets[swizzle4];
401
+ let dataD = Math.sqrt(Math.max(0, 1 - (dataA * dataA + dataB * dataB + dataC * dataC)));
402
+ if ((a & 0x80) !== 0) dataD = -dataD;
403
+ out[swizzle2] = fr(dataA);
404
+ out[swizzle3] = fr(dataB);
405
+ out[swizzle4] = fr(dataC);
406
+ out[swizzle1] = fr(dataD);
407
+ return out;
408
+ }
409
+
410
+ /**
411
+ * Decode a D4n curve using 8-bit knots and 7-bit quaternion controls.
412
+ *
413
+ * @param {object} c Curve object with packed quaternion data.
414
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
415
+ */
416
+ function decodeD4nK8uC7u(c) {
417
+ return decodeD4n(c, quatFromControl8, D4N_SCALE_TABLE_MULTIPLIER_8);
418
+ }
419
+
420
+ /**
421
+ * Decode a D3K packed vec3 curve using uint16 payload values.
422
+ *
423
+ * @param {object} c Curve object with `knotsControls`, `controlScales`,
424
+ * `controlOffsets`, and `oneOverKnotScaleTrunc`.
425
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
426
+ */
427
+ function decodeD3K(c) {
428
+ const kc = c.knotsControls || [],
429
+ count = exactDiv(kc.length, 4, "D3K knotsControls/4"),
430
+ knots = knotsFromControlsTrunc(kc, count, c.oneOverKnotScaleTrunc),
431
+ scales = c.controlScales,
432
+ offsets = c.controlOffsets,
433
+ controls = new Array(count * 3);
434
+ for (let i = 0; i < count; i++) {
435
+ for (let x = 0; x < 3; x++) {
436
+ controls[i * 3 + x] = fr(kc[count + i * 3 + x] * scales[x] + offsets[x]);
437
+ }
438
+ }
439
+ return {
440
+ knots,
441
+ controls,
442
+ dimension: 3
443
+ };
444
+ }
445
+
446
+ /**
447
+ * Decode a D9I1 uniform scale/shear curve.
448
+ *
449
+ * @param {object} c Curve object with `knotsControls`, scalar scale/offset
450
+ * fields, and `oneOverKnotScaleTrunc`.
451
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
452
+ */
453
+ function decodeD9I1(c) {
454
+ const kc = c.knotsControls || [],
455
+ count = exactDiv(kc.length, 2, "D9I1 knotsControls/2"),
456
+ knots = knotsFromControlsTrunc(kc, count, c.oneOverKnotScaleTrunc);
457
+ const scale = Array.isArray(c.controlScales) ? c.controlScales[0] : c.controlScale,
458
+ offset = Array.isArray(c.controlOffsets) ? c.controlOffsets[0] : c.controlOffset,
459
+ controls = new Array(count * 9).fill(0);
460
+ for (let i = 0; i < count; i++) {
461
+ const s = fr(kc[count + i] * scale + offset);
462
+ controls[i * 9] = s;
463
+ controls[i * 9 + 4] = s;
464
+ controls[i * 9 + 8] = s;
465
+ }
466
+ return {
467
+ knots,
468
+ controls,
469
+ dimension: 9
470
+ };
471
+ }
472
+
473
+ /**
474
+ * Decode a D9I3 per-axis scale/shear curve.
475
+ *
476
+ * @param {object} c Curve object with `knotsControls`, `controlScales`,
477
+ * `controlOffsets`, and `oneOverKnotScaleTrunc`.
478
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
479
+ */
480
+ function decodeD9I3(c) {
481
+ const kc = c.knotsControls || [],
482
+ count = exactDiv(kc.length, 4, "D9I3 knotsControls/4"),
483
+ knots = knotsFromControlsTrunc(kc, count, c.oneOverKnotScaleTrunc),
484
+ scales = c.controlScales,
485
+ offsets = c.controlOffsets,
486
+ controls = new Array(count * 9).fill(0);
487
+ for (let i = 0; i < count; i++) {
488
+ controls[i * 9] = fr(kc[count + i * 3] * scales[0] + offsets[0]);
489
+ controls[i * 9 + 4] = fr(kc[count + i * 3 + 1] * scales[1] + offsets[1]);
490
+ controls[i * 9 + 8] = fr(kc[count + i * 3 + 2] * scales[2] + offsets[2]);
491
+ }
492
+ return {
493
+ knots,
494
+ controls,
495
+ dimension: 9
496
+ };
497
+ }
498
+
499
+ /**
500
+ * Expand one scalar per knot into vec3 controls for the D3I1 family.
501
+ *
502
+ * @param {ArrayLike<number>} kc Packed knots followed by scalar controls.
503
+ * @param {number} count Number of knots and scalar controls.
504
+ * @param {ArrayLike<number>} scales vec3 component scales.
505
+ * @param {ArrayLike<number>} offsets vec3 component offsets.
506
+ * @returns {number[]} Flat vec3 controls.
507
+ */
508
+ function d3I1Controls(kc, count, scales, offsets) {
509
+ const controls = new Array(count * 3);
510
+ for (let i = 0; i < count; i++) {
511
+ const v = kc[count + i];
512
+ controls[i * 3] = fr(v * scales[0] + offsets[0]);
513
+ controls[i * 3 + 1] = fr(v * scales[1] + offsets[1]);
514
+ controls[i * 3 + 2] = fr(v * scales[2] + offsets[2]);
515
+ }
516
+ return controls;
517
+ }
518
+
519
+ /**
520
+ * Decode a D3I1 curve with float knots and scalar float controls.
521
+ *
522
+ * @param {object} c Curve object with `knotsControls`, `controlScales`, and
523
+ * `controlOffsets`.
524
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
525
+ */
526
+ function decodeD3I1K32fC32f(c) {
527
+ const kc = c.knotsControls || [],
528
+ count = exactDiv(kc.length, 2, "D3I1K32f knotsControls/2"),
529
+ knots = new Array(count);
530
+ for (let i = 0; i < count; i++) {
531
+ knots[i] = fr(kc[i]);
532
+ }
533
+ return {
534
+ knots,
535
+ controls: d3I1Controls(kc, count, c.controlScales, c.controlOffsets),
536
+ dimension: 3
537
+ };
538
+ }
539
+
540
+ /**
541
+ * Decode a D3I1 curve with uint knots and scalar controls.
542
+ *
543
+ * @param {object} c Curve object with `knotsControls`, `controlScales`,
544
+ * `controlOffsets`, and `oneOverKnotScaleTrunc`.
545
+ * @returns {{knots: number[], controls: number[], dimension: number}} Decoded curve.
546
+ */
547
+ function decodeD3I1u(c) {
548
+ const kc = c.knotsControls || [],
549
+ count = exactDiv(kc.length, 2, "D3I1 knotsControls/2"),
550
+ knots = knotsFromControlsTrunc(kc, count, c.oneOverKnotScaleTrunc);
551
+ return {
552
+ knots,
553
+ controls: d3I1Controls(kc, count, c.controlScales, c.controlOffsets),
554
+ dimension: 3
555
+ };
556
+ }
557
+
558
+ /**
559
+ * Decode format 6, DaK16uC16u.
560
+ *
561
+ * @type {typeof decodeDaK}
562
+ */
563
+ const decodeDaK16uC16u = decodeDaK;
564
+
565
+ /**
566
+ * Decode format 7, DaK8uC8u.
567
+ *
568
+ * @type {typeof decodeDaK}
569
+ */
570
+ const decodeDaK8uC8u = decodeDaK;
571
+
572
+ /**
573
+ * Decode format 10, D3K16uC16u.
574
+ *
575
+ * @type {typeof decodeD3K}
576
+ */
577
+ const decodeD3K16uC16u = decodeD3K;
578
+
579
+ /**
580
+ * Decode format 11, D3K8uC8u.
581
+ *
582
+ * @type {typeof decodeD3K}
583
+ */
584
+ const decodeD3K8uC8u = decodeD3K;
585
+
586
+ /**
587
+ * Decode format 12, D9I1K16uC16u.
588
+ *
589
+ * @type {typeof decodeD9I1}
590
+ */
591
+ const decodeD9I1K16uC16u = decodeD9I1;
592
+
593
+ /**
594
+ * Decode format 14, D9I1K8uC8u.
595
+ *
596
+ * @type {typeof decodeD9I1}
597
+ */
598
+ const decodeD9I1K8uC8u = decodeD9I1;
599
+
600
+ /**
601
+ * Decode format 13, D9I3K16uC16u.
602
+ *
603
+ * @type {typeof decodeD9I3}
604
+ */
605
+ const decodeD9I3K16uC16u = decodeD9I3;
606
+
607
+ /**
608
+ * Decode format 15, D9I3K8uC8u.
609
+ *
610
+ * @type {typeof decodeD9I3}
611
+ */
612
+ const decodeD9I3K8uC8u = decodeD9I3;
613
+
614
+ /**
615
+ * Decode format 17, D3I1K16uC16u.
616
+ *
617
+ * @type {typeof decodeD3I1u}
618
+ */
619
+ const decodeD3I1K16uC16u = decodeD3I1u;
620
+
621
+ /**
622
+ * Decode format 18, D3I1K8uC8u.
623
+ *
624
+ * @type {typeof decodeD3I1u}
625
+ */
626
+ const decodeD3I1K8uC8u = decodeD3I1u;
627
+
628
+ /**
629
+ * Curve object as emitted inside GR2 JSON transform tracks.
630
+ *
631
+ * @typedef {object} CurveJson
632
+ * @property {number} format Granny animation-curve format id.
633
+ * @property {number} degree Curve degree from the Granny curve header.
634
+ * @property {number[]} [knots] Explicit knot times when already decompressed.
635
+ * @property {number[]} [controls] Explicit control values when already decoded.
636
+ * @property {number} [dimension] Control vector width.
637
+ * @property {string} [error] Emitter error marker for unsupported raw curves.
638
+ */
639
+
640
+ /**
641
+ * Explicit curve data returned by {@link decodeCurve}.
642
+ *
643
+ * controls is a flat array in knot-major order:
644
+ * controls[knotIndex * dimension + componentIndex].
645
+ *
646
+ * @typedef {object} DecodedCurve
647
+ * @property {number[]} knots Knot times, non-decreasing.
648
+ * @property {number[]} controls Flat control values.
649
+ * @property {number} degree Curve degree.
650
+ * @property {number} dimension Control vector width.
651
+ */
652
+
653
+ /**
654
+ * Track dimension accepted by Granny transform curves.
655
+ *
656
+ * @typedef {1|3|4|9} TransformCurveDimension
657
+ */
658
+
659
+ /**
660
+ * Decoder table ordered by Granny curve format id.
661
+ *
662
+ * Each entry exposes the numeric format and the function used by
663
+ * {@link decodeCurve}.
664
+ */
665
+ const CURVE_DECODERS = Object.freeze([Object.freeze({
666
+ format: FORMAT_DA_KEYFRAMES_32F,
667
+ decode: decodeDaKeyframes32f
668
+ }), Object.freeze({
669
+ format: FORMAT_DA_K32F_C32F,
670
+ decode: decodeDaK32fC32f
671
+ }), Object.freeze({
672
+ format: FORMAT_DA_IDENTITY,
673
+ decode: decodeDaIdentity
674
+ }), Object.freeze({
675
+ format: FORMAT_DA_CONSTANT_32F,
676
+ decode: decodeDaConstant32f
677
+ }), Object.freeze({
678
+ format: FORMAT_D3_CONSTANT_32F,
679
+ decode: decodeD3Constant32f
680
+ }), Object.freeze({
681
+ format: FORMAT_D4_CONSTANT_32F,
682
+ decode: decodeD4Constant32f
683
+ }), Object.freeze({
684
+ format: FORMAT_DA_K16U_C16U,
685
+ decode: decodeDaK16uC16u
686
+ }), Object.freeze({
687
+ format: FORMAT_DA_K8U_C8U,
688
+ decode: decodeDaK8uC8u
689
+ }), Object.freeze({
690
+ format: FORMAT_D4N_K16U_C15U,
691
+ decode: decodeD4nK16uC15u
692
+ }), Object.freeze({
693
+ format: FORMAT_D4N_K8U_C7U,
694
+ decode: decodeD4nK8uC7u
695
+ }), Object.freeze({
696
+ format: FORMAT_D3_K16U_C16U,
697
+ decode: decodeD3K16uC16u
698
+ }), Object.freeze({
699
+ format: FORMAT_D3_K8U_C8U,
700
+ decode: decodeD3K8uC8u
701
+ }), Object.freeze({
702
+ format: FORMAT_D9I1_K16U_C16U,
703
+ decode: decodeD9I1K16uC16u
704
+ }), Object.freeze({
705
+ format: FORMAT_D9I3_K16U_C16U,
706
+ decode: decodeD9I3K16uC16u
707
+ }), Object.freeze({
708
+ format: FORMAT_D9I1_K8U_C8U,
709
+ decode: decodeD9I1K8uC8u
710
+ }), Object.freeze({
711
+ format: FORMAT_D9I3_K8U_C8U,
712
+ decode: decodeD9I3K8uC8u
713
+ }), Object.freeze({
714
+ format: FORMAT_D3I1_K32F_C32F,
715
+ decode: decodeD3I1K32fC32f
716
+ }), Object.freeze({
717
+ format: FORMAT_D3I1_K16U_C16U,
718
+ decode: decodeD3I1K16uC16u
719
+ }), Object.freeze({
720
+ format: FORMAT_D3I1_K8U_C8U,
721
+ decode: decodeD3I1K8uC8u
722
+ })]);
723
+ for (let i = 0; i < CURVE_DECODERS.length; i++) {
724
+ if (CURVE_DECODERS[i].format !== i) {
725
+ throw new Error(`gr2reader: curve decoder table corrupt at format ${i}`);
726
+ }
727
+ }
728
+
729
+ /**
730
+ * Decode a GR2 JSON curve object into explicit knots/controls.
731
+ *
732
+ * @param {CurveJson} curveJson Curve as emitted in GR2 JSON.
733
+ * @param {TransformCurveDimension} dimension Track dimension: position = 3, orientation = 4, scaleShear = 9.
734
+ * @returns {DecodedCurve} Explicit knots and flat control values.
735
+ * @throws {Error} If the curve is missing a numeric format, the format is not
736
+ * supported, or the decoded dimension conflicts with the requested dimension.
737
+ */
738
+ function decodeCurve(curveJson, dimension) {
739
+ if (!curveJson || typeof curveJson.format !== "number") {
740
+ throw new Error("gr2reader: decodeCurve requires a curve object with a numeric format");
741
+ }
742
+ const dec = CURVE_DECODERS[curveJson.format];
743
+ if (!dec) {
744
+ throw new Error(`gr2reader: unsupported granny curve format ${curveJson.format}`);
745
+ }
746
+ const {
747
+ knots,
748
+ controls,
749
+ dimension: dim
750
+ } = dec.decode(curveJson, dimension);
751
+ if (dimension && dim && dim !== dimension) {
752
+ throw new Error(`gr2reader: curve format ${curveJson.format} decoded dimension ${dim} does not match track dimension ${dimension}`);
753
+ }
754
+ return {
755
+ knots,
756
+ controls,
757
+ degree: curveJson.degree | 0,
758
+ dimension: dim || dimension
759
+ };
760
+ }
761
+
762
+ /**
763
+ * Copy one decoded control point into an output buffer.
764
+ *
765
+ * @param {ArrayLike<number> & { [index: number]: number }} out Mutable output buffer.
766
+ * @param {DecodedCurve} curve Decoded curve.
767
+ * @param {number} index Control point index.
768
+ * @returns {ArrayLike<number>} The same output buffer.
769
+ */
770
+ function copyControl(out, curve, index) {
771
+ const dim = curve.dimension,
772
+ offset = index * dim;
773
+ for (let i = 0; i < dim; i++) {
774
+ out[i] = curve.controls[offset + i];
775
+ }
776
+ return out;
777
+ }
778
+
779
+ /**
780
+ * Locate the first knot strictly greater than time, matching the existing
781
+ * runtime curve evaluator's step/segment selection.
782
+ *
783
+ * @param {number[]} knots Decoded knot times.
784
+ * @param {number} time Sample time.
785
+ * @returns {number} Knot index.
786
+ */
787
+ function findKnotIndex(knots, time) {
788
+ let low = 0;
789
+ let high = knots.length - 1;
790
+ while (low < high) {
791
+ const mid = low + high >> 1;
792
+ if (knots[mid] > time) high = mid;else low = mid + 1;
793
+ }
794
+ return low;
795
+ }
796
+
797
+ /**
798
+ * Sample Carbon's raw keyframed Granny curves (`DaKeyframes32f`).
799
+ *
800
+ * @param {ArrayLike<number> & { [index: number]: number }} out Mutable output buffer.
801
+ * @param {DecodedCurve} curve Decoded curve.
802
+ * @param {number} time Sample time.
803
+ * @param {number} duration Animation duration.
804
+ * @returns {ArrayLike<number>} The same output buffer.
805
+ */
806
+ function sampleKeyframedCurve(out, curve, time, duration) {
807
+ const count = curve.controls.length / curve.dimension;
808
+ const frame = duration > 0 ? Math.trunc(count * time / duration) : 0;
809
+ return copyControl(out, curve, Math.max(0, Math.min(count - 1, frame)));
810
+ }
811
+
812
+ /**
813
+ * Sample a decoded degree-one curve.
814
+ *
815
+ * @param {ArrayLike<number> & { [index: number]: number }} out Mutable output buffer.
816
+ * @param {DecodedCurve} curve Decoded curve.
817
+ * @param {number} time Sample time.
818
+ * @param {boolean} cycle Whether the owning track cycles.
819
+ * @param {number} duration Animation duration.
820
+ * @param {number} knot Selected knot index.
821
+ * @returns {ArrayLike<number>} The same output buffer.
822
+ */
823
+ function sampleLinearCurve(out, curve, time, cycle, duration, knot) {
824
+ const knots = curve.knots,
825
+ count = knots.length,
826
+ dim = curve.dimension,
827
+ knot0 = cycle ? (knot + count - 1) % count : knot === 0 ? 0 : knot - 1;
828
+ let start = knots[knot0],
829
+ end = knots[knot],
830
+ localTime = time;
831
+ if (cycle && end < start) {
832
+ end += duration;
833
+ }
834
+ if (cycle && localTime < start) {
835
+ localTime += duration;
836
+ }
837
+ const t = end !== start ? (localTime - start) / (end - start) : 0;
838
+ const p0 = knot0 * dim;
839
+ const p1 = knot * dim;
840
+ for (let i = 0; i < dim; i++) {
841
+ out[i] = curve.controls[p0 + i] * (1 - t) + curve.controls[p1 + i] * t;
842
+ }
843
+ return out;
844
+ }
845
+
846
+ /**
847
+ * Sample the quadratic decoded curves emitted by modern Granny animation data.
848
+ *
849
+ * @param {ArrayLike<number> & { [index: number]: number }} out Mutable output buffer.
850
+ * @param {DecodedCurve} curve Decoded curve.
851
+ * @param {number} time Sample time.
852
+ * @param {boolean} cycle Whether the owning track cycles.
853
+ * @param {number} duration Animation duration.
854
+ * @param {number} knot Selected knot index.
855
+ * @returns {ArrayLike<number>} The same output buffer.
856
+ */
857
+ function sampleQuadraticCurve(out, curve, time, cycle, duration, knot) {
858
+ const knots = curve.knots,
859
+ count = knots.length,
860
+ dim = curve.dimension,
861
+ k2 = cycle ? (knot + count - 2) % count : knot === 0 ? 0 : Math.max(0, knot - 2),
862
+ k1 = cycle ? (knot + count - 1) % count : knot === 0 ? 0 : knot - 1;
863
+ let ti2 = knots[k2],
864
+ ti1 = knots[k1],
865
+ ti = knots[knot],
866
+ tiNext = knots[(knot + 1) % count],
867
+ localTime = time;
868
+ if (ti2 > ti) {
869
+ ti += duration;
870
+ tiNext += duration;
871
+ localTime += duration;
872
+ }
873
+ if (ti1 > ti) {
874
+ ti += duration;
875
+ tiNext += duration;
876
+ localTime += duration;
877
+ }
878
+ if (tiNext < ti) {
879
+ tiNext += duration;
880
+ }
881
+ const d0 = ti - ti1,
882
+ d1a = ti - ti2,
883
+ d1b = tiNext - ti1,
884
+ l0 = d0 !== 0 ? (localTime - ti1) / d0 : 0,
885
+ l1a = d1a !== 0 ? (localTime - ti2) / d1a : 0,
886
+ l1b = d1b !== 0 ? (localTime - ti1) / d1b : 0;
887
+ let c2 = l1a + l0 - l0 * l1a;
888
+ const ci = l0 * l1b,
889
+ c1 = c2 - ci;
890
+ c2 = 1 - c2;
891
+ const p0 = k2 * dim,
892
+ p1 = k1 * dim,
893
+ p2 = knot * dim;
894
+ for (let i = 0; i < dim; i++) {
895
+ out[i] = c2 * curve.controls[p0 + i] + c1 * curve.controls[p1 + i] + ci * curve.controls[p2 + i];
896
+ }
897
+ return out;
898
+ }
899
+
900
+ /**
901
+ * Sample a decoded Granny curve into a caller-provided output buffer.
902
+ *
903
+ * This works only on decoded `{ knots, controls, degree, dimension }` data.
904
+ * Packed Granny curve parsing remains the responsibility of `decodeCurve`.
905
+ *
906
+ * @param {ArrayLike<number> & { [index: number]: number }} out Mutable output buffer.
907
+ * @param {DecodedCurve} curve Decoded curve.
908
+ * @param {number} time Sample time.
909
+ * @param {boolean} [cycle=false] Whether the owning track cycles.
910
+ * @param {number} [duration=0] Animation duration.
911
+ * @param {{ keyframed?: boolean }} [options] Sampling options.
912
+ * @returns {ArrayLike<number>} The same output buffer.
913
+ */
914
+ function sampleDecodedCurve(out, curve, time, cycle = false, duration = 0, options = {}) {
915
+ if (!curve || !curve.knots || !curve.controls || !curve.dimension) {
916
+ return out;
917
+ }
918
+ const knots = curve.knots,
919
+ count = knots.length,
920
+ dim = curve.dimension,
921
+ controlCount = curve.controls.length / dim;
922
+ if (!count || !controlCount) {
923
+ return out;
924
+ }
925
+ if (options.keyframed) {
926
+ return sampleKeyframedCurve(out, curve, time, duration);
927
+ }
928
+ const knot = findKnotIndex(knots, time);
929
+ if (curve.degree <= 0 || count === 1 || controlCount === 1) {
930
+ return copyControl(out, curve, Math.min(knot, controlCount - 1));
931
+ }
932
+ if (curve.degree === 1) {
933
+ return sampleLinearCurve(out, curve, time, cycle, duration || knots[count - 1], knot);
934
+ }
935
+ return sampleQuadraticCurve(out, curve, time, cycle, duration || knots[count - 1], knot);
936
+ }
937
+
938
+ /**
939
+ * Decode the three curves of every transform track of a GR2 JSON object in
940
+ * place. Adds knots, controls and dimension to each curve object; all raw
941
+ * compressed fields are left untouched.
942
+ *
943
+ * @param {object} json GR2 JSON root object to mutate.
944
+ * @returns {object} The same object, for chaining.
945
+ */
946
+ function decompressAnimationCurves(json) {
947
+ for (const anim of json.animations || []) {
948
+ for (const tg of anim.trackGroups || []) {
949
+ for (const tt of tg.transformTracks || []) {
950
+ decorate(tt.orientation, 4);
951
+ decorate(tt.position, 3);
952
+ decorate(tt.scaleShear, 9);
953
+ }
954
+ }
955
+ }
956
+ return json;
957
+ }
958
+
959
+ /**
960
+ * Decode and attach explicit curve data to a transform-track curve object.
961
+ *
962
+ * @param {CurveJson|undefined|null} curve Curve object to decorate in place.
963
+ * @param {TransformCurveDimension} dimension Expected track dimension.
964
+ * @returns {void}
965
+ */
966
+ function decorate(curve, dimension) {
967
+ if (!curve || typeof curve.format !== "number" || curve.error) return;
968
+ const d = decodeCurve(curve, dimension);
969
+ curve.knots = d.knots;
970
+ curve.controls = d.controls;
971
+ curve.dimension = d.dimension;
972
+ }
973
+
974
+ /**
975
+ * Frozen convenience namespace for animation-curve decoding helpers.
976
+ *
977
+ * The same constants and functions are also exported directly from curves.js.
978
+ */
979
+ const curves = Object.freeze({
980
+ FORMAT_DA_KEYFRAMES_32F,
981
+ FORMAT_DA_K32F_C32F,
982
+ FORMAT_DA_IDENTITY,
983
+ FORMAT_DA_CONSTANT_32F,
984
+ FORMAT_D3_CONSTANT_32F,
985
+ FORMAT_D4_CONSTANT_32F,
986
+ FORMAT_DA_K16U_C16U,
987
+ FORMAT_DA_K8U_C8U,
988
+ FORMAT_D4N_K16U_C15U,
989
+ FORMAT_D4N_K8U_C7U,
990
+ FORMAT_D3_K16U_C16U,
991
+ FORMAT_D3_K8U_C8U,
992
+ FORMAT_D9I1_K16U_C16U,
993
+ FORMAT_D9I3_K16U_C16U,
994
+ FORMAT_D9I1_K8U_C8U,
995
+ FORMAT_D9I3_K8U_C8U,
996
+ FORMAT_D3I1_K32F_C32F,
997
+ FORMAT_D3I1_K16U_C16U,
998
+ FORMAT_D3I1_K8U_C8U,
999
+ FORMATS: CURVE_FORMATS,
1000
+ DECODERS: CURVE_DECODERS,
1001
+ D4N_SCALE_TABLE,
1002
+ D4N_OFFSET_TABLE,
1003
+ D4N_SCALE_TABLE_MULTIPLIER_16,
1004
+ D4N_SCALE_TABLE_MULTIPLIER_8,
1005
+ decode: decodeCurve,
1006
+ decodeCurve,
1007
+ sample: sampleDecodedCurve,
1008
+ sampleDecodedCurve,
1009
+ decompress: decompressAnimationCurves,
1010
+ decompressAnimationCurves,
1011
+ knotScaleFromTrunc,
1012
+ knotsFromControls,
1013
+ knotsFromControlsTrunc,
1014
+ identityControls,
1015
+ exactDiv,
1016
+ decodeDaKeyframes32f,
1017
+ decodeDaK32fC32f,
1018
+ decodeDaIdentity,
1019
+ decodeDaConstant32f,
1020
+ decodeD3Constant32f,
1021
+ decodeD4Constant32f,
1022
+ decodeDaK,
1023
+ decodeDaK16uC16u,
1024
+ decodeDaK8uC8u,
1025
+ quatFromControl16,
1026
+ quatFromControl8,
1027
+ decodeD4n,
1028
+ decodeD4nK16uC15u,
1029
+ decodeD4nK8uC7u,
1030
+ decodeD3K,
1031
+ decodeD3K16uC16u,
1032
+ decodeD3K8uC8u,
1033
+ decodeD9I1,
1034
+ decodeD9I1K16uC16u,
1035
+ decodeD9I1K8uC8u,
1036
+ decodeD9I3,
1037
+ decodeD9I3K16uC16u,
1038
+ decodeD9I3K8uC8u,
1039
+ d3I1Controls,
1040
+ decodeD3I1K32fC32f,
1041
+ decodeD3I1u,
1042
+ decodeD3I1K16uC16u,
1043
+ decodeD3I1K8uC8u
1044
+ });
1045
+
1046
+ export { CURVE_DECODERS, CURVE_FORMATS, D4N_OFFSET_TABLE, D4N_SCALE_TABLE, D4N_SCALE_TABLE_MULTIPLIER_16, D4N_SCALE_TABLE_MULTIPLIER_8, FORMAT_D3I1_K16U_C16U, FORMAT_D3I1_K32F_C32F, FORMAT_D3I1_K8U_C8U, FORMAT_D3_CONSTANT_32F, FORMAT_D3_K16U_C16U, FORMAT_D3_K8U_C8U, FORMAT_D4N_K16U_C15U, FORMAT_D4N_K8U_C7U, FORMAT_D4_CONSTANT_32F, FORMAT_D9I1_K16U_C16U, FORMAT_D9I1_K8U_C8U, FORMAT_D9I3_K16U_C16U, FORMAT_D9I3_K8U_C8U, FORMAT_DA_CONSTANT_32F, FORMAT_DA_IDENTITY, FORMAT_DA_K16U_C16U, FORMAT_DA_K32F_C32F, FORMAT_DA_K8U_C8U, FORMAT_DA_KEYFRAMES_32F, curves, d3I1Controls, decodeCurve, decodeD3Constant32f, decodeD3I1K16uC16u, decodeD3I1K32fC32f, decodeD3I1K8uC8u, decodeD3I1u, decodeD3K, decodeD3K16uC16u, decodeD3K8uC8u, decodeD4Constant32f, decodeD4n, decodeD4nK16uC15u, decodeD4nK8uC7u, decodeD9I1, decodeD9I1K16uC16u, decodeD9I1K8uC8u, decodeD9I3, decodeD9I3K16uC16u, decodeD9I3K8uC8u, decodeDaConstant32f, decodeDaIdentity, decodeDaK, decodeDaK16uC16u, decodeDaK32fC32f, decodeDaK8uC8u, decodeDaKeyframes32f, decompressAnimationCurves, exactDiv, fr, identityControls, knotScaleFromTrunc, knotsFromControls, knotsFromControlsTrunc, quatFromControl16, quatFromControl8, sampleDecodedCurve };
1047
+ //# sourceMappingURL=curves.js.map