@carbonenginejs/runtime-resource 0.12.2 → 0.13.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 (541) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +32 -32
  3. package/README.md +129 -108
  4. package/dist/CjsMotherLode.js +1271 -1271
  5. package/dist/CjsResMan.js +3858 -3494
  6. package/dist/CjsResMan.js.map +1 -1
  7. package/dist/CjsResManFetchProvider.js +94 -94
  8. package/dist/CjsResManWorkQueue.js +301 -301
  9. package/dist/_virtual/_rollupPluginBabelHelpers.js +150 -150
  10. package/dist/format/CjsBlueReader.js +358 -358
  11. package/dist/format/CjsByteReader.js +310 -310
  12. package/dist/format/CjsByteWriter.js +242 -242
  13. package/dist/format/CjsFormat.js +223 -223
  14. package/dist/format/CjsFormatError.js +41 -41
  15. package/dist/format/CjsReader.js +22 -22
  16. package/dist/format/CjsResourceProbe.js +279 -279
  17. package/dist/format/CjsStringTable.js +268 -268
  18. package/dist/format/carbonEffect/CjsCarbonEffectReader.js +408 -361
  19. package/dist/format/carbonEffect/CjsCarbonEffectReader.js.map +1 -1
  20. package/dist/format/carbonEffect/CjsCarbonEffectWriter.js +373 -373
  21. package/dist/format/carbonEffect/buildCarbonEffectContainer.js +182 -0
  22. package/dist/format/carbonEffect/buildCarbonEffectContainer.js.map +1 -0
  23. package/dist/format/carbonEffect/carbonEffectBackendBlock.js +321 -427
  24. package/dist/format/carbonEffect/carbonEffectBackendBlock.js.map +1 -1
  25. package/dist/format/carbonEffect/carbonEffectRecords.js +1147 -955
  26. package/dist/format/carbonEffect/carbonEffectRecords.js.map +1 -1
  27. package/dist/format/carbonEffect/carbonEffectResourceTransform.js +197 -0
  28. package/dist/format/carbonEffect/carbonEffectResourceTransform.js.map +1 -0
  29. package/dist/format/compareUtf8.js +36 -36
  30. package/dist/format/effect/effectBodyInventory.js +146 -0
  31. package/dist/format/effect/effectBodyInventory.js.map +1 -0
  32. package/dist/format/effect/effectPermutationGraph.js +257 -257
  33. package/dist/format/effect/effectPermutationGraph.js.map +1 -1
  34. package/dist/format/effect/sha256.js +114 -114
  35. package/dist/format/index.js +11 -11
  36. package/dist/format/payloadContract.js +193 -193
  37. package/dist/formats/black/CjsBlackFormat.js +310 -292
  38. package/dist/formats/black/CjsBlackFormat.js.map +1 -1
  39. package/dist/formats/black/core/CjsBlackBinaryReader.js +260 -260
  40. package/dist/formats/black/core/CjsBlackPropertyReaders.js +448 -448
  41. package/dist/formats/black/core/CjsBlackReader.js +764 -764
  42. package/dist/formats/black/core/CjsBlackSchemaRegistry.js +540 -540
  43. package/dist/formats/black/core/black-schema-v1-2026-07-23.json.js +4 -4
  44. package/dist/formats/black/core/blackConstants.js +7 -7
  45. package/dist/formats/black/core/blackDefinitions.js +10 -10
  46. package/dist/formats/black/core/blackEnums.js +6 -6
  47. package/dist/formats/black/core/blackSchema.js +3 -3
  48. package/dist/formats/black/core/blackVersion.js +22 -22
  49. package/dist/formats/black/core/helpers.js +199 -199
  50. package/dist/formats/black/core/schema.js +4 -4
  51. package/dist/formats/black/index.js +2 -2
  52. package/dist/formats/bnk/CjsBnkFormat.js +175 -156
  53. package/dist/formats/bnk/CjsBnkFormat.js.map +1 -1
  54. package/dist/formats/bnk/core/busNodes.js +252 -0
  55. package/dist/formats/bnk/core/busNodes.js.map +1 -0
  56. package/dist/formats/bnk/core/effectNodes.js +147 -0
  57. package/dist/formats/bnk/core/effectNodes.js.map +1 -0
  58. package/dist/formats/bnk/core/eventAction.js +416 -305
  59. package/dist/formats/bnk/core/eventAction.js.map +1 -1
  60. package/dist/formats/bnk/core/globalSettings.js +215 -0
  61. package/dist/formats/bnk/core/globalSettings.js.map +1 -0
  62. package/dist/formats/bnk/core/graph.js +137 -137
  63. package/dist/formats/bnk/core/helpers.js +512 -480
  64. package/dist/formats/bnk/core/helpers.js.map +1 -1
  65. package/dist/formats/bnk/core/musicNodes.js +533 -509
  66. package/dist/formats/bnk/core/musicNodes.js.map +1 -1
  67. package/dist/formats/bnk/core/nodeBase.js +553 -532
  68. package/dist/formats/bnk/core/nodeBase.js.map +1 -1
  69. package/dist/formats/bnk/core/sfxNodes.js +632 -632
  70. package/dist/formats/bnk/core/soundbanksInfo.js +209 -209
  71. package/dist/formats/bnk/index.js +2 -2
  72. package/dist/formats/cmf/CjsCmfFormat.js +497 -497
  73. package/dist/formats/cmf/core/binary.js +194 -194
  74. package/dist/formats/cmf/core/buffers.js +237 -237
  75. package/dist/formats/cmf/core/constants.js +47 -47
  76. package/dist/formats/cmf/core/gr2Anim.js +453 -453
  77. package/dist/formats/cmf/core/helpers.js +318 -318
  78. package/dist/formats/cmf/core/pack.js +276 -276
  79. package/dist/formats/cmf/core/schema.js +374 -374
  80. package/dist/formats/cmf/core/shared.js +277 -277
  81. package/dist/formats/cmf/core/writer.js +571 -571
  82. package/dist/formats/cmf/index.js +2 -2
  83. package/dist/formats/dds/CjsDdsFormat.js +200 -200
  84. package/dist/formats/dds/core/bc6h.js +298 -298
  85. package/dist/formats/dds/core/bc7.js +272 -272
  86. package/dist/formats/dds/core/helpers.js +862 -862
  87. package/dist/formats/dds/index.js +2 -2
  88. package/dist/formats/dxbc/CjsDxbcFormat.js +142 -142
  89. package/dist/formats/dxbc/core/DxbcReader.js +266 -266
  90. package/dist/formats/dxbc/core/container.js +169 -169
  91. package/dist/formats/dxbc/core/decoder.js +789 -789
  92. package/dist/formats/dxbc/core/errors.js +19 -19
  93. package/dist/formats/dxbc/core/helpers.js +220 -220
  94. package/dist/formats/dxbc/core/opcodes.js +45 -45
  95. package/dist/formats/dxbc/core/program.js +91 -91
  96. package/dist/formats/dxbc/core/signature.js +172 -172
  97. package/dist/formats/dxbc/index.js +2 -2
  98. package/dist/formats/fbx/CjsFbxFormat.js +266 -266
  99. package/dist/formats/fbx/core/helpers.js +3932 -3932
  100. package/dist/formats/fbx/index.js +2 -2
  101. package/dist/formats/flac/CjsFlacFormat.js +142 -142
  102. package/dist/formats/flac/core/helpers.js +315 -315
  103. package/dist/formats/flac/index.js +2 -2
  104. package/dist/formats/gif/CjsGifFormat.js +141 -141
  105. package/dist/formats/gif/core/helpers.js +380 -380
  106. package/dist/formats/gif/index.js +2 -2
  107. package/dist/formats/gltf/CjsGltfFormat.js +290 -290
  108. package/dist/formats/gltf/core/helpers.js +307 -307
  109. package/dist/formats/gltf/core/json.js +79 -79
  110. package/dist/formats/gltf/core/parser.js +679 -679
  111. package/dist/formats/gltf/core/targets.js +173 -173
  112. package/dist/formats/gltf/index.js +2 -2
  113. package/dist/formats/gr2/CjsGr2Format.js +289 -289
  114. package/dist/formats/gr2/core/bitknit2.js +282 -282
  115. package/dist/formats/gr2/core/curves.js +1047 -1047
  116. package/dist/formats/gr2/core/gsf.js +72 -72
  117. package/dist/formats/gr2/core/helpers.js +352 -352
  118. package/dist/formats/gr2/core/json.js +622 -622
  119. package/dist/formats/gr2/core/oodle1.js +388 -388
  120. package/dist/formats/gr2/core/tangents.js +48 -48
  121. package/dist/formats/gr2/core/targets.js +361 -361
  122. package/dist/formats/gr2/index.js +2 -2
  123. package/dist/formats/hlsl/CjsHlslFormat.js +254 -254
  124. package/dist/formats/hlsl/core/HlslBinaryUtils.js +15 -15
  125. package/dist/formats/hlsl/core/HlslEffectReadError.js +19 -19
  126. package/dist/formats/hlsl/core/HlslEffectStateManager.js +130 -130
  127. package/dist/formats/hlsl/core/HlslRenderStateSetup.js +37 -37
  128. package/dist/formats/hlsl/core/HlslResourceSetDescription.js +94 -94
  129. package/dist/formats/hlsl/core/HlslShaderBytecode.js +44 -44
  130. package/dist/formats/hlsl/core/analysis.js +51 -51
  131. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js +850 -781
  132. package/dist/formats/hlsl/core/carbonDescriptionToRuntime.js.map +1 -1
  133. package/dist/formats/hlsl/core/detailMapFamily.js +128 -0
  134. package/dist/formats/hlsl/core/detailMapFamily.js.map +1 -0
  135. package/dist/formats/hlsl/core/helpers.js +270 -270
  136. package/dist/formats/hlsl/core/json.js +284 -284
  137. package/dist/formats/hlsl/core/localLightFamily.js +133 -0
  138. package/dist/formats/hlsl/core/localLightFamily.js.map +1 -0
  139. package/dist/formats/hlsl/core/metadata.js +327 -327
  140. package/dist/formats/hlsl/core/render-states.js +280 -280
  141. package/dist/formats/hlsl/core/tr2/HlslRenderContextEnum.js +43 -43
  142. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js +320 -314
  143. package/dist/formats/hlsl/core/tr2/resources/HlslEffectRes.js.map +1 -1
  144. package/dist/formats/hlsl/core/tr2/resources/HlslShaderPermutation.js +33 -33
  145. package/dist/formats/hlsl/core/tr2/shader/HlslEffectBindingManifest.js +416 -416
  146. package/dist/formats/hlsl/core/tr2/shader/HlslEffectConstant.js +40 -40
  147. package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js +62 -742
  148. package/dist/formats/hlsl/core/tr2/shader/HlslEffectDescription.js.map +1 -1
  149. package/dist/formats/hlsl/core/tr2/shader/HlslEffectLibrary.js +52 -52
  150. package/dist/formats/hlsl/core/tr2/shader/HlslEffectParameterAnnotation.js +38 -38
  151. package/dist/formats/hlsl/core/tr2/shader/HlslEffectResource.js +50 -50
  152. package/dist/formats/hlsl/core/tr2/shader/HlslEffectStageInput.js +86 -86
  153. package/dist/formats/hlsl/core/tr2/shader/HlslEffectTechnique.js +31 -31
  154. package/dist/formats/hlsl/core/tr2/shader/HlslPass.js +42 -42
  155. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerDescription.js +55 -55
  156. package/dist/formats/hlsl/core/tr2/shader/HlslSamplerSetup.js +29 -29
  157. package/dist/formats/hlsl/core/tr2/shader/HlslShader.js +220 -220
  158. package/dist/formats/hlsl/core/tr2/shader/HlslShaderOption.js +30 -30
  159. package/dist/formats/hlsl/index.js +3 -3
  160. package/dist/formats/index.js +33 -31
  161. package/dist/formats/index.js.map +1 -1
  162. package/dist/formats/jpeg/CjsJpegFormat.js +212 -212
  163. package/dist/formats/jpeg/core/helpers.js +402 -402
  164. package/dist/formats/jpeg/core/jpeg.js +480 -480
  165. package/dist/formats/jpeg/index.js +2 -2
  166. package/dist/formats/mp3/CjsMp3Format.js +197 -197
  167. package/dist/formats/mp3/core/helpers.js +375 -375
  168. package/dist/formats/mp3/index.js +2 -2
  169. package/dist/formats/mp4/CjsMp4Format.js +197 -197
  170. package/dist/formats/mp4/core/helpers.js +484 -484
  171. package/dist/formats/mp4/index.js +2 -2
  172. package/dist/formats/obj/CjsObjFormat.js +253 -253
  173. package/dist/formats/obj/core/helpers.js +573 -573
  174. package/dist/formats/obj/core/json.js +64 -64
  175. package/dist/formats/obj/core/parser.js +321 -321
  176. package/dist/formats/obj/index.js +2 -2
  177. package/dist/formats/ogg/CjsOggFormat.js +143 -143
  178. package/dist/formats/ogg/core/helpers.js +410 -410
  179. package/dist/formats/ogg/core/imdct.js +178 -178
  180. package/dist/formats/ogg/core/vorbis.js +1017 -1017
  181. package/dist/formats/ogg/index.js +2 -2
  182. package/dist/formats/pickle/CjsPickleFormat.js +214 -0
  183. package/dist/formats/pickle/CjsPickleFormat.js.map +1 -0
  184. package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js +551 -0
  185. package/dist/formats/pickle/core/CjsPickleProtocol0Reader.js.map +1 -0
  186. package/dist/formats/pickle/index.js +2 -0
  187. package/dist/formats/pickle/index.js.map +1 -0
  188. package/dist/formats/png/CjsPngFormat.js +201 -201
  189. package/dist/formats/png/core/helpers.js +635 -635
  190. package/dist/formats/png/index.js +2 -2
  191. package/dist/formats/red/CjsRedFormat.js +263 -263
  192. package/dist/formats/red/core/CjsRedReader.js +246 -246
  193. package/dist/formats/red/core/blackDefinitions.js +3 -3
  194. package/dist/formats/red/core/helpers.js +158 -158
  195. package/dist/formats/red/core/redGraph.js +71 -68
  196. package/dist/formats/red/core/redGraph.js.map +1 -1
  197. package/dist/formats/red/core/schema.js +4 -4
  198. package/dist/formats/red/index.js +2 -2
  199. package/dist/formats/stl/CjsStlFormat.js +365 -365
  200. package/dist/formats/stl/core/helpers.js +261 -261
  201. package/dist/formats/stl/core/json.js +51 -51
  202. package/dist/formats/stl/core/stl.js +642 -642
  203. package/dist/formats/stl/core/targets.js +173 -173
  204. package/dist/formats/stl/index.js +2 -2
  205. package/dist/formats/tga/CjsTgaFormat.js +197 -197
  206. package/dist/formats/tga/core/helpers.js +493 -493
  207. package/dist/formats/tga/index.js +2 -2
  208. package/dist/formats/wav/CjsWavFormat.js +198 -198
  209. package/dist/formats/wav/core/helpers.js +365 -365
  210. package/dist/formats/wav/index.js +2 -2
  211. package/dist/formats/webgl/CjsWebglFormat.js +199 -221
  212. package/dist/formats/webgl/CjsWebglFormat.js.map +1 -1
  213. package/dist/formats/webgl/core/buildGlslEffectContainer.js +70 -0
  214. package/dist/formats/webgl/core/buildGlslEffectContainer.js.map +1 -0
  215. package/dist/formats/webgl/core/effectPackage.js +900 -792
  216. package/dist/formats/webgl/core/effectPackage.js.map +1 -1
  217. package/dist/formats/webgl/core/errors.js +27 -27
  218. package/dist/formats/webgl/core/errors.js.map +1 -1
  219. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js +2820 -2678
  220. package/dist/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
  221. package/dist/formats/webgl/core/glsl/DxbcGlslHelpers.js +89 -89
  222. package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js +486 -428
  223. package/dist/formats/webgl/core/glsl/DxbcGlslOperandFormatter.js.map +1 -1
  224. package/dist/formats/webgl/core/glsl/packedLightFixups.js +98 -0
  225. package/dist/formats/webgl/core/glsl/packedLightFixups.js.map +1 -0
  226. package/dist/formats/webgl/core/glslBackendBlock.js +552 -0
  227. package/dist/formats/webgl/core/glslBackendBlock.js.map +1 -0
  228. package/dist/formats/webgl/core/glslBackendBodySet.js +243 -0
  229. package/dist/formats/webgl/core/glslBackendBodySet.js.map +1 -0
  230. package/dist/formats/webgl/core/{cewgCompleteness.js → glslEffectCompleteness.js} +85 -81
  231. package/dist/formats/webgl/core/glslEffectCompleteness.js.map +1 -0
  232. package/dist/formats/webgl/core/helpers.js +167 -306
  233. package/dist/formats/webgl/core/helpers.js.map +1 -1
  234. package/dist/formats/webgl/core/inspectGlslEffectContainer.js +122 -0
  235. package/dist/formats/webgl/core/inspectGlslEffectContainer.js.map +1 -0
  236. package/dist/formats/webgl/core/readGlslEffectContainer.js +303 -0
  237. package/dist/formats/webgl/core/readGlslEffectContainer.js.map +1 -0
  238. package/dist/formats/webgl/index.js +2 -2
  239. package/dist/formats/webgpu/CjsWebgpuFormat.js +357 -357
  240. package/dist/formats/webgpu/CjsWebgpuFormat.js.map +1 -1
  241. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js +89 -197
  242. package/dist/formats/webgpu/core/buildCarbonEffectContainer.js.map +1 -1
  243. package/dist/formats/webgpu/core/{cewgpu/CewgpuContainer.js → carbonWebgpu/CarbonWebgpuContainer.js} +354 -368
  244. package/dist/formats/webgpu/core/carbonWebgpu/CarbonWebgpuContainer.js.map +1 -0
  245. package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/containerViews.js +355 -355
  246. package/dist/formats/webgpu/core/carbonWebgpu/containerViews.js.map +1 -0
  247. package/dist/formats/webgpu/core/{cewgpu → carbonWebgpu}/validateContainer.js +90 -90
  248. package/dist/formats/webgpu/core/carbonWebgpu/validateContainer.js.map +1 -0
  249. package/dist/formats/webgpu/core/effectAnalysis.js +82 -82
  250. package/dist/formats/webgpu/core/effectBackendBodySet.js +289 -289
  251. package/dist/formats/webgpu/core/effectBackendBodySet.js.map +1 -1
  252. package/dist/formats/webgpu/core/errors.js +20 -20
  253. package/dist/formats/webgpu/core/errors.js.map +1 -1
  254. package/dist/formats/webgpu/core/helpers.js +443 -443
  255. package/dist/formats/webgpu/core/helpers.js.map +1 -1
  256. package/dist/formats/webgpu/core/ir/analyzeRegisterValues.js +212 -212
  257. package/dist/formats/webgpu/core/ir/buildControlFlow.js +220 -220
  258. package/dist/formats/webgpu/core/ir/indexableTemps.js +137 -137
  259. package/dist/formats/webgpu/core/ir/inferValueTypes.js +449 -449
  260. package/dist/formats/webgpu/core/ir/lowerDxbcToIr.js +494 -494
  261. package/dist/formats/webgpu/core/ir/resolveRegisterFlow.js +177 -177
  262. package/dist/formats/webgpu/core/ir/sourceLanes.js +61 -61
  263. package/dist/formats/webgpu/core/packageEffect.js +381 -385
  264. package/dist/formats/webgpu/core/packageEffect.js.map +1 -1
  265. package/dist/formats/webgpu/core/packageEffectSelection.js +164 -164
  266. package/dist/formats/webgpu/core/packageEffectSelection.js.map +1 -1
  267. package/dist/formats/webgpu/core/packageMetadata.js +17 -17
  268. package/dist/formats/webgpu/core/schema.js +4 -4
  269. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js +263 -263
  270. package/dist/formats/webgpu/core/wgsl/buildResourceTransformPlan.js.map +1 -1
  271. package/dist/formats/webgpu/core/wgsl/buildWgslBindingPlan.js +172 -172
  272. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js +320 -320
  273. package/dist/formats/webgpu/core/wgsl/buildWgslSet.js.map +1 -1
  274. package/dist/formats/webgpu/core/wgsl/emitWgsl.js +356 -356
  275. package/dist/formats/webgpu/core/wgsl/hoistEscapingValues.js +77 -77
  276. package/dist/formats/webgpu/core/wgsl/lowerBindingLayout.js +451 -451
  277. package/dist/formats/webgpu/core/wgsl/lowerComputeProgram.js +735 -735
  278. package/dist/formats/webgpu/core/wgsl/lowerCreateHistogramsComputeProgram.js +457 -457
  279. package/dist/formats/webgpu/core/wgsl/lowerFragmentProgram.js +1572 -1572
  280. package/dist/formats/webgpu/core/wgsl/lowerMergeHistogramsComputeProgram.js +659 -659
  281. package/dist/formats/webgpu/core/wgsl/lowerParticleClearComputePrograms.js +734 -734
  282. package/dist/formats/webgpu/core/wgsl/lowerParticleEmitComputeProgram.js +583 -583
  283. package/dist/formats/webgpu/core/wgsl/lowerSkinVerticesComputeProgram.js +621 -621
  284. package/dist/formats/webgpu/core/wgsl/lowerSortComputeProgram.js +824 -824
  285. package/dist/formats/webgpu/core/wgsl/lowerSortInnerComputeProgram.js +697 -697
  286. package/dist/formats/webgpu/core/wgsl/lowerSortStepComputeProgram.js +559 -559
  287. package/dist/formats/webgpu/core/wgsl/lowerVertexProgram.js +1328 -1328
  288. package/dist/formats/webgpu/core/wgsl/particleEmitSemanticDigest.js +110 -110
  289. package/dist/formats/webgpu/core/wgsl/precisionControls.js +55 -55
  290. package/dist/formats/webgpu/core/wgsl/selectionPlans.js +717 -717
  291. package/dist/formats/webgpu/core/wgsl/uniformity.js +78 -78
  292. package/dist/formats/webgpu/core/wgsl/validateExactComputeIr.js +196 -196
  293. package/dist/formats/webgpu/core/wgsl/validateHandleOperand.js +37 -37
  294. package/dist/formats/webgpu/index.js +2 -2
  295. package/dist/formats/webm/CjsWebmFormat.js +197 -197
  296. package/dist/formats/webm/core/helpers.js +572 -572
  297. package/dist/formats/webm/index.js +2 -2
  298. package/dist/formats/webp/CjsWebpFormat.js +140 -140
  299. package/dist/formats/webp/core/helpers.js +237 -237
  300. package/dist/formats/webp/index.js +2 -2
  301. package/dist/formats/wem/CjsWemFormat.js +250 -250
  302. package/dist/formats/wem/core/bitStream.js +261 -261
  303. package/dist/formats/wem/core/codebookLibrary.js +164 -164
  304. package/dist/formats/wem/core/helpers.js +437 -437
  305. package/dist/formats/wem/core/packedCodebooksAotuv603.js +30 -30
  306. package/dist/formats/wem/core/ptadpcm.js +77 -77
  307. package/dist/formats/wem/core/resolve.js +121 -121
  308. package/dist/formats/wem/core/wemToOgg.js +485 -485
  309. package/dist/formats/wem/index.js +2 -2
  310. package/dist/formats/yaml/CjsYamlFormat.js +134 -134
  311. package/dist/formats/yaml/CjsYamlFormat.js.map +1 -1
  312. package/dist/formats/yaml/core/CjsYamlReader.js +400 -402
  313. package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -1
  314. package/dist/formats/yaml/core/helpers.js +196 -170
  315. package/dist/formats/yaml/core/helpers.js.map +1 -1
  316. package/dist/formats/yaml/index.js +2 -2
  317. package/dist/index.js +64 -62
  318. package/dist/index.js.map +1 -1
  319. package/dist/resource/CjsLoadingObject.js +19 -0
  320. package/dist/resource/CjsLoadingObject.js.map +1 -0
  321. package/dist/resource/CjsResource.js +801 -797
  322. package/dist/resource/CjsResource.js.map +1 -1
  323. package/dist/resource/ResourceHandlerMode.js +14 -0
  324. package/dist/resource/ResourceHandlerMode.js.map +1 -0
  325. package/dist/resource/Tr2LightProfileRes.js +32 -32
  326. package/dist/resource/audio/AudioGeometryResData.js +47 -47
  327. package/dist/resource/audio/CjsAudioBufferRes.js +86 -86
  328. package/dist/resource/audio/CjsAudioRes.js +213 -213
  329. package/dist/resource/audio/index.js +4 -4
  330. package/dist/resource/geometry/MeshDecalData.js +37 -37
  331. package/dist/resource/geometry/MeshDecalLodData.js +34 -34
  332. package/dist/resource/geometry/TriGeometryRes.js +675 -675
  333. package/dist/resource/geometry/TriGeometryResAreaData.js +59 -59
  334. package/dist/resource/geometry/TriGeometryResJointData.js +38 -38
  335. package/dist/resource/geometry/TriGeometryResLodData.js +88 -88
  336. package/dist/resource/geometry/TriGeometryResMeshData.js +63 -63
  337. package/dist/resource/geometry/TriGeometryResSkeletonData.js +34 -34
  338. package/dist/resource/geometry/TriJointBinding.js +38 -38
  339. package/dist/resource/geometry/TriMorphTargetGeometryConstants.js +46 -46
  340. package/dist/resource/geometry/TriRtGeometryConstants.js +88 -88
  341. package/dist/resource/geometry/granny/GStateBindingCallbackData.js +31 -31
  342. package/dist/resource/geometry/granny/Tr2GrannyIntersectionResult.js +60 -60
  343. package/dist/resource/geometry/granny/Tr2GrannyStateRes.js +36 -36
  344. package/dist/resource/geometry/granny/TriGrannyRes.js +35 -35
  345. package/dist/resource/geometry/granny/enums.js +10 -10
  346. package/dist/resource/geometry/granny/index.js +6 -6
  347. package/dist/resource/geometry/index.js +17 -17
  348. package/dist/resource/index.js +54 -52
  349. package/dist/resource/index.js.map +1 -1
  350. package/dist/resource/resourceBoundary.js +64 -64
  351. package/dist/resource/shader/Tr2EffectRes.js +336 -431
  352. package/dist/resource/shader/Tr2EffectRes.js.map +1 -1
  353. package/dist/resource/shader/Tr2MaterialArea.js +31 -31
  354. package/dist/resource/shader/Tr2MaterialMesh.js +27 -27
  355. package/dist/resource/shader/Tr2MaterialRes.js +31 -31
  356. package/dist/resource/shader/Tr2Shader.js +283 -261
  357. package/dist/resource/shader/Tr2Shader.js.map +1 -1
  358. package/dist/resource/shader/Tr2ShaderPermutation.js +43 -43
  359. package/dist/resource/shader/index.js +17 -17
  360. package/dist/resource/shader/reflection/Tr2EffectConstant.js +143 -135
  361. package/dist/resource/shader/reflection/Tr2EffectConstant.js.map +1 -1
  362. package/dist/resource/shader/reflection/Tr2EffectDefine.js +30 -30
  363. package/dist/resource/shader/reflection/Tr2EffectDescription.js +114 -109
  364. package/dist/resource/shader/reflection/Tr2EffectDescription.js.map +1 -1
  365. package/dist/resource/shader/reflection/Tr2EffectLibrary.js +168 -147
  366. package/dist/resource/shader/reflection/Tr2EffectLibrary.js.map +1 -1
  367. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js +125 -105
  368. package/dist/resource/shader/reflection/Tr2EffectParameterAnnotation.js.map +1 -1
  369. package/dist/resource/shader/reflection/Tr2EffectResource.js +120 -86
  370. package/dist/resource/shader/reflection/Tr2EffectResource.js.map +1 -1
  371. package/dist/resource/shader/reflection/Tr2EffectStageInput.js +372 -241
  372. package/dist/resource/shader/reflection/Tr2EffectStageInput.js.map +1 -1
  373. package/dist/resource/shader/reflection/Tr2EffectTechnique.js +78 -68
  374. package/dist/resource/shader/reflection/Tr2EffectTechnique.js.map +1 -1
  375. package/dist/resource/shader/reflection/Tr2Pass.js +168 -111
  376. package/dist/resource/shader/reflection/Tr2Pass.js.map +1 -1
  377. package/dist/resource/shader/reflection/carbonRecordFields.js +159 -0
  378. package/dist/resource/shader/reflection/carbonRecordFields.js.map +1 -0
  379. package/dist/resource/shader/reflection/shaderStage.js +22 -0
  380. package/dist/resource/shader/reflection/shaderStage.js.map +1 -0
  381. package/dist/resource/shader/sampler/Tr2SamplerSetup.js +135 -77
  382. package/dist/resource/shader/sampler/Tr2SamplerSetup.js.map +1 -1
  383. package/dist/resource/texture/CjsTextureArrayRes.js +472 -472
  384. package/dist/resource/texture/CjsTextureArrayResParameterProxy.js +179 -179
  385. package/dist/resource/texture/Tr2ImageRes.js +120 -120
  386. package/dist/resource/texture/Tr2TextureLodManager.js +82 -82
  387. package/dist/resource/texture/Tr2TextureLodUpdateRequest.js +37 -37
  388. package/dist/resource/texture/Tr2TexturePackChannel.js +37 -37
  389. package/dist/resource/texture/Tr2TexturePipeline.js +54 -54
  390. package/dist/resource/texture/Tr2TexturePipelineParams.js +34 -34
  391. package/dist/resource/texture/Tr2TexturePipelineStepCompress.js +40 -40
  392. package/dist/resource/texture/Tr2TexturePipelineStepGenerateMips.js +22 -22
  393. package/dist/resource/texture/Tr2TexturePipelineStepLimitSize.js +34 -34
  394. package/dist/resource/texture/Tr2TexturePipelineStepLoad.js +31 -31
  395. package/dist/resource/texture/Tr2TexturePipelineStepPack.js +43 -43
  396. package/dist/resource/texture/TriTextureRes.js +359 -359
  397. package/dist/resource/texture/index.js +15 -15
  398. package/dist/resource/texture/texturePipelineBehavior.js +308 -308
  399. package/dist/worker/CjsResManMainThreadLoader.js +89 -87
  400. package/dist/worker/CjsResManMainThreadLoader.js.map +1 -1
  401. package/dist/worker/CjsResManWorker.js +218 -217
  402. package/dist/worker/CjsResManWorker.js.map +1 -1
  403. package/dist/worker/CjsResManWorkerLoader.js +437 -434
  404. package/dist/worker/CjsResManWorkerLoader.js.map +1 -1
  405. package/dist/worker/protocol.js +12 -12
  406. package/docs/README.md +98 -98
  407. package/docs/architecture.md +118 -109
  408. package/docs/concepts/resource-lifecycle.md +226 -225
  409. package/docs/concepts/shader-resource-model.md +111 -114
  410. package/docs/concepts/writing-an-engine-adapter.md +115 -115
  411. package/docs/formats/README.md +138 -136
  412. package/docs/formats/carbon-effect-container.md +553 -452
  413. package/docs/formats/dxbc/README.md +68 -68
  414. package/docs/formats/dxbc/architecture.md +80 -80
  415. package/docs/formats/dxbc/reference/api.md +77 -77
  416. package/docs/formats/dxbc/reference/classes/README.md +9 -9
  417. package/docs/formats/dxbc/reference/decoded-output.md +122 -122
  418. package/docs/formats/gr2.md +160 -160
  419. package/docs/formats/hlsl/README.md +54 -54
  420. package/docs/formats/hlsl/architecture.md +65 -67
  421. package/docs/formats/hlsl/guides/hydrating-json-output.md +60 -62
  422. package/docs/formats/hlsl/guides/reading-effects.md +64 -64
  423. package/docs/formats/hlsl/reference/advanced-analysis.md +61 -66
  424. package/docs/formats/hlsl/reference/api.md +92 -98
  425. package/docs/formats/hlsl/reference/classes/README.md +11 -11
  426. package/docs/formats/hlsl/reference/json-graph.md +97 -100
  427. package/docs/formats/pickle.md +82 -0
  428. package/docs/formats/provenance.md +196 -196
  429. package/docs/formats/stl.md +37 -37
  430. package/docs/formats/webgl/README.md +115 -57
  431. package/docs/formats/webgl/architecture.md +69 -70
  432. package/docs/formats/webgl/carbon-constant-layouts.md +326 -326
  433. package/docs/formats/webgl/decl-io.md +1234 -1234
  434. package/docs/formats/webgl/memory-structured.md +890 -871
  435. package/docs/formats/webgl/reference/classes/README.md +9 -9
  436. package/docs/formats/webgl/texture-sample.md +964 -964
  437. package/docs/formats/webgpu/README.md +84 -84
  438. package/docs/formats/webgpu/architecture.md +95 -96
  439. package/docs/formats/webgpu/formats/{cewgpu.md → carbon-webgpu.md} +215 -216
  440. package/docs/formats/webgpu/guides/effect-packaging.md +189 -191
  441. package/docs/formats/webgpu/reference/api.md +196 -197
  442. package/docs/formats/webgpu/reference/classes/README.md +9 -9
  443. package/docs/formats/webgpu/reference/wgsl-compatibility.md +1546 -1543
  444. package/docs/formats/wwise.md +146 -85
  445. package/docs/reference/classes/README.md +35 -35
  446. package/docs/reference/classes/audio.md +30 -30
  447. package/docs/reference/classes/core.md +216 -206
  448. package/docs/reference/classes/dropped.md +46 -46
  449. package/docs/reference/classes/formats.md +944 -952
  450. package/docs/reference/classes/resources.md +456 -456
  451. package/docs/reference/classes/texture.md +26 -26
  452. package/docs/reference/events.md +117 -117
  453. package/docs/reference/motherlode-cache.md +275 -275
  454. package/docs/reference/queues.md +194 -110
  455. package/docs/reference/reload.md +107 -107
  456. package/docs/reference/texture-arrays.md +113 -113
  457. package/docs/reference/texture-pipeline.md +53 -53
  458. package/docs/reference/workers.md +142 -135
  459. package/docs/roadmap.md +150 -150
  460. package/format-notices/black/LICENSE +21 -21
  461. package/format-notices/black/NOTICE +47 -47
  462. package/format-notices/bnk/LICENSE +21 -21
  463. package/format-notices/bnk/NOTICE +21 -21
  464. package/format-notices/cmf/LICENSE +21 -21
  465. package/format-notices/cmf/NOTICE +36 -36
  466. package/format-notices/dds/LICENSE +21 -21
  467. package/format-notices/dds/NOTICE +14 -14
  468. package/format-notices/dxbc/LICENSE +21 -21
  469. package/format-notices/dxbc/NOTICE +20 -20
  470. package/format-notices/fbx/LICENSE +21 -21
  471. package/format-notices/fbx/NOTICE +14 -14
  472. package/format-notices/flac/LICENSE +21 -21
  473. package/format-notices/flac/NOTICE +14 -14
  474. package/format-notices/gif/LICENSE +21 -21
  475. package/format-notices/gif/NOTICE +14 -14
  476. package/format-notices/gltf/LICENSE +21 -21
  477. package/format-notices/gltf/NOTICE +27 -27
  478. package/format-notices/gr2/LICENSE +21 -21
  479. package/format-notices/gr2/NOTICE +60 -60
  480. package/format-notices/gr2/THIRD-PARTY-NOTICES.md +93 -93
  481. package/format-notices/hlsl/LICENSE +21 -21
  482. package/format-notices/hlsl/NOTICE +25 -25
  483. package/format-notices/jpeg/LICENSE +21 -21
  484. package/format-notices/jpeg/NOTICE +14 -14
  485. package/format-notices/mp3/LICENSE +21 -21
  486. package/format-notices/mp3/NOTICE +14 -14
  487. package/format-notices/mp4/LICENSE +21 -21
  488. package/format-notices/mp4/NOTICE +14 -14
  489. package/format-notices/obj/LICENSE +21 -21
  490. package/format-notices/obj/NOTICE +26 -26
  491. package/format-notices/ogg/LICENSE +21 -21
  492. package/format-notices/ogg/NOTICE +28 -28
  493. package/format-notices/png/LICENSE +21 -21
  494. package/format-notices/png/NOTICE +14 -14
  495. package/format-notices/red/LICENSE +21 -21
  496. package/format-notices/red/NOTICE +31 -31
  497. package/format-notices/stl/LICENSE +21 -21
  498. package/format-notices/stl/NOTICE +21 -21
  499. package/format-notices/tga/LICENSE +21 -21
  500. package/format-notices/tga/NOTICE +14 -14
  501. package/format-notices/wav/LICENSE +21 -21
  502. package/format-notices/wav/NOTICE +14 -14
  503. package/format-notices/webgl/LICENSE +21 -21
  504. package/format-notices/webgl/NOTICE +35 -35
  505. package/format-notices/webgpu/LICENSE +21 -21
  506. package/format-notices/webgpu/NOTICE +31 -31
  507. package/format-notices/webm/LICENSE +21 -21
  508. package/format-notices/webm/NOTICE +14 -14
  509. package/format-notices/webp/LICENSE +21 -21
  510. package/format-notices/webp/NOTICE +14 -14
  511. package/format-notices/wem/LICENSE +57 -57
  512. package/format-notices/wem/NOTICE +33 -33
  513. package/format-notices/yaml/LICENSE +21 -21
  514. package/format-notices/yaml/NOTICE +44 -44
  515. package/package.json +63 -63
  516. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js +0 -372
  517. package/dist/format/carbonEffect/carbonDescriptionFromPortable.js.map +0 -1
  518. package/dist/format/effect/effectReflectionPackage.js +0 -636
  519. package/dist/format/effect/effectReflectionPackage.js.map +0 -1
  520. package/dist/formats/hlsl/core/HlslReader.js +0 -16
  521. package/dist/formats/hlsl/core/HlslReader.js.map +0 -1
  522. package/dist/formats/hlsl/core/portableReflection.js +0 -848
  523. package/dist/formats/hlsl/core/portableReflection.js.map +0 -1
  524. package/dist/formats/hlsl/portable.js +0 -2
  525. package/dist/formats/hlsl/portable.js.map +0 -1
  526. package/dist/formats/webgl/core/cewg/CewgPackage.js +0 -340
  527. package/dist/formats/webgl/core/cewg/CewgPackage.js.map +0 -1
  528. package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js +0 -104
  529. package/dist/formats/webgl/core/cewg/CewgPackageBuilder.js.map +0 -1
  530. package/dist/formats/webgl/core/cewg/binary.js +0 -19
  531. package/dist/formats/webgl/core/cewg/binary.js.map +0 -1
  532. package/dist/formats/webgl/core/cewgCompleteness.js.map +0 -1
  533. package/dist/formats/webgl/core/effectPackageValidation.js +0 -331
  534. package/dist/formats/webgl/core/effectPackageValidation.js.map +0 -1
  535. package/dist/formats/webgpu/core/cewgpu/CewgpuContainer.js.map +0 -1
  536. package/dist/formats/webgpu/core/cewgpu/containerViews.js.map +0 -1
  537. package/dist/formats/webgpu/core/cewgpu/validateContainer.js.map +0 -1
  538. package/dist/resource/shader/portable.js +0 -33
  539. package/dist/resource/shader/portable.js.map +0 -1
  540. package/docs/formats/hlsl/reference/portable-reflection.md +0 -141
  541. package/docs/formats/webgl/effect-reflection.md +0 -127
@@ -1,1047 +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
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