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