@automovie/ingest 0.0.0-stage → 0.0.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 (275) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -2
  3. package/lib/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.d.ts +5 -0
  4. package/lib/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.js +8 -0
  5. package/lib/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.js.map +1 -0
  6. package/lib/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.d.ts +5 -0
  7. package/lib/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.js +15 -0
  8. package/lib/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.js.map +1 -0
  9. package/lib/AutoMovieExternalModelIngestProfile.d.ts +11 -0
  10. package/lib/AutoMovieExternalModelIngestProfile.js +3 -0
  11. package/lib/AutoMovieExternalModelIngestProfile.js.map +1 -0
  12. package/lib/AutoMovieExternalMotionAdoptionDecision.d.ts +11 -0
  13. package/lib/AutoMovieExternalMotionAdoptionDecision.js +3 -0
  14. package/lib/AutoMovieExternalMotionAdoptionDecision.js.map +1 -0
  15. package/lib/AutoMovieGltfMotionInterpretationProfile.d.ts +9 -0
  16. package/lib/AutoMovieGltfMotionInterpretationProfile.js +3 -0
  17. package/lib/AutoMovieGltfMotionInterpretationProfile.js.map +1 -0
  18. package/lib/IAutoMovieExternalModelInspection.d.ts +48 -0
  19. package/lib/IAutoMovieExternalModelInspection.js +3 -0
  20. package/lib/IAutoMovieExternalModelInspection.js.map +1 -0
  21. package/lib/IAutoMovieExternalModelResource.d.ts +18 -0
  22. package/lib/IAutoMovieExternalModelResource.js +3 -0
  23. package/lib/IAutoMovieExternalModelResource.js.map +1 -0
  24. package/lib/IAutoMovieExternalMotionAdoption.d.ts +23 -0
  25. package/lib/IAutoMovieExternalMotionAdoption.js +3 -0
  26. package/lib/IAutoMovieExternalMotionAdoption.js.map +1 -0
  27. package/lib/IAutoMovieExternalMotionBoneMapping.d.ts +15 -0
  28. package/lib/IAutoMovieExternalMotionBoneMapping.js +3 -0
  29. package/lib/IAutoMovieExternalMotionBoneMapping.js.map +1 -0
  30. package/lib/IAutoMovieExternalMotionInspection.d.ts +25 -0
  31. package/lib/IAutoMovieExternalMotionInspection.js +3 -0
  32. package/lib/IAutoMovieExternalMotionInspection.js.map +1 -0
  33. package/lib/IAutoMovieExternalMotionNativeDecision.d.ts +20 -0
  34. package/lib/IAutoMovieExternalMotionNativeDecision.js +3 -0
  35. package/lib/IAutoMovieExternalMotionNativeDecision.js.map +1 -0
  36. package/lib/IAutoMovieExternalMotionNativeHandoff.d.ts +18 -0
  37. package/lib/IAutoMovieExternalMotionNativeHandoff.js +3 -0
  38. package/lib/IAutoMovieExternalMotionNativeHandoff.js.map +1 -0
  39. package/lib/IAutoMovieExternalMotionNodeInspection.d.ts +21 -0
  40. package/lib/IAutoMovieExternalMotionNodeInspection.js +3 -0
  41. package/lib/IAutoMovieExternalMotionNodeInspection.js.map +1 -0
  42. package/lib/IAutoMovieExternalMotionRetargetDecision.d.ts +24 -0
  43. package/lib/IAutoMovieExternalMotionRetargetDecision.js +3 -0
  44. package/lib/IAutoMovieExternalMotionRetargetDecision.js.map +1 -0
  45. package/lib/IAutoMovieExternalMotionRetargetHandoff.d.ts +22 -0
  46. package/lib/IAutoMovieExternalMotionRetargetHandoff.js +3 -0
  47. package/lib/IAutoMovieExternalMotionRetargetHandoff.js.map +1 -0
  48. package/lib/IAutoMovieExternalMotionSource.d.ts +18 -0
  49. package/lib/IAutoMovieExternalMotionSource.js +3 -0
  50. package/lib/IAutoMovieExternalMotionSource.js.map +1 -0
  51. package/lib/IAutoMovieIngestResult.d.ts +17 -0
  52. package/lib/IAutoMovieIngestResult.js +3 -0
  53. package/lib/IAutoMovieIngestResult.js.map +1 -0
  54. package/lib/adoptAutoMovieExternalMotion.d.ts +32 -0
  55. package/lib/adoptAutoMovieExternalMotion.js +215 -0
  56. package/lib/adoptAutoMovieExternalMotion.js.map +1 -0
  57. package/lib/audio/IAutoMovieDecodedProductionAudioAsset.d.ts +28 -0
  58. package/lib/audio/IAutoMovieDecodedProductionAudioAsset.js +3 -0
  59. package/lib/audio/IAutoMovieDecodedProductionAudioAsset.js.map +1 -0
  60. package/lib/audio/IAutoMovieProductionAudioProcessing.d.ts +18 -0
  61. package/lib/audio/IAutoMovieProductionAudioProcessing.js +3 -0
  62. package/lib/audio/IAutoMovieProductionAudioProcessing.js.map +1 -0
  63. package/lib/audio/IAutoMovieProductionWaveSourceFormat.d.ts +39 -0
  64. package/lib/audio/IAutoMovieProductionWaveSourceFormat.js +3 -0
  65. package/lib/audio/IAutoMovieProductionWaveSourceFormat.js.map +1 -0
  66. package/lib/audio/decodeProductionAudioAsset.d.ts +33 -0
  67. package/lib/audio/decodeProductionAudioAsset.js +257 -0
  68. package/lib/audio/decodeProductionAudioAsset.js.map +1 -0
  69. package/lib/audio/index.d.ts +4 -0
  70. package/lib/audio/index.js +21 -0
  71. package/lib/audio/index.js.map +1 -0
  72. package/lib/decodeAutoMoviePpmImage.d.ts +30 -0
  73. package/lib/decodeAutoMoviePpmImage.js +84 -0
  74. package/lib/decodeAutoMoviePpmImage.js.map +1 -0
  75. package/lib/humanoidSkeleton.d.ts +24 -0
  76. package/lib/humanoidSkeleton.js +80 -0
  77. package/lib/humanoidSkeleton.js.map +1 -0
  78. package/lib/index.d.ts +23 -0
  79. package/lib/index.js +40 -0
  80. package/lib/index.js.map +1 -0
  81. package/lib/ingestDocument.d.ts +23 -0
  82. package/lib/ingestDocument.js +173 -0
  83. package/lib/ingestDocument.js.map +1 -0
  84. package/lib/inspectAutoMovieExternalModelBytes.d.ts +32 -0
  85. package/lib/inspectAutoMovieExternalModelBytes.js +219 -0
  86. package/lib/inspectAutoMovieExternalModelBytes.js.map +1 -0
  87. package/lib/internal/COMPONENT_BYTES.d.ts +2 -0
  88. package/lib/internal/COMPONENT_BYTES.js +13 -0
  89. package/lib/internal/COMPONENT_BYTES.js.map +1 -0
  90. package/lib/internal/IAccessorSource.d.ts +16 -0
  91. package/lib/internal/IAccessorSource.js +3 -0
  92. package/lib/internal/IAccessorSource.js.map +1 -0
  93. package/lib/internal/IExternalModelAccessorReader.d.ts +9 -0
  94. package/lib/internal/IExternalModelAccessorReader.js +3 -0
  95. package/lib/internal/IExternalModelAccessorReader.js.map +1 -0
  96. package/lib/internal/IHumanoidSlot.d.ts +15 -0
  97. package/lib/internal/IHumanoidSlot.js +3 -0
  98. package/lib/internal/IHumanoidSlot.js.map +1 -0
  99. package/lib/internal/IParsedContainer.d.ts +16 -0
  100. package/lib/internal/IParsedContainer.js +3 -0
  101. package/lib/internal/IParsedContainer.js.map +1 -0
  102. package/lib/internal/SHAPE_COMPONENTS.d.ts +6 -0
  103. package/lib/internal/SHAPE_COMPONENTS.js +25 -0
  104. package/lib/internal/SHAPE_COMPONENTS.js.map +1 -0
  105. package/lib/internal/accessorElementByteLength.d.ts +12 -0
  106. package/lib/internal/accessorElementByteLength.js +28 -0
  107. package/lib/internal/accessorElementByteLength.js.map +1 -0
  108. package/lib/internal/accessorReader.d.ts +16 -0
  109. package/lib/internal/accessorReader.js +52 -0
  110. package/lib/internal/accessorReader.js.map +1 -0
  111. package/lib/internal/accessorValues.d.ts +18 -0
  112. package/lib/internal/accessorValues.js +38 -0
  113. package/lib/internal/accessorValues.js.map +1 -0
  114. package/lib/internal/collectExternalResources.d.ts +13 -0
  115. package/lib/internal/collectExternalResources.js +51 -0
  116. package/lib/internal/collectExternalResources.js.map +1 -0
  117. package/lib/internal/compareCodeUnits.d.ts +12 -0
  118. package/lib/internal/compareCodeUnits.js +17 -0
  119. package/lib/internal/compareCodeUnits.js.map +1 -0
  120. package/lib/internal/composeLocalTransform.d.ts +21 -0
  121. package/lib/internal/composeLocalTransform.js +53 -0
  122. package/lib/internal/composeLocalTransform.js.map +1 -0
  123. package/lib/internal/decodeDataUri.d.ts +14 -0
  124. package/lib/internal/decodeDataUri.js +61 -0
  125. package/lib/internal/decodeDataUri.js.map +1 -0
  126. package/lib/internal/decodeGlb.d.ts +13 -0
  127. package/lib/internal/decodeGlb.js +56 -0
  128. package/lib/internal/decodeGlb.js.map +1 -0
  129. package/lib/internal/decodeJson.d.ts +12 -0
  130. package/lib/internal/decodeJson.js +77 -0
  131. package/lib/internal/decodeJson.js.map +1 -0
  132. package/lib/internal/fileExtension.d.ts +12 -0
  133. package/lib/internal/fileExtension.js +21 -0
  134. package/lib/internal/fileExtension.js.map +1 -0
  135. package/lib/internal/finiteTuple.d.ts +14 -0
  136. package/lib/internal/finiteTuple.js +29 -0
  137. package/lib/internal/finiteTuple.js.map +1 -0
  138. package/lib/internal/gltfHumanoidBones.d.ts +15 -0
  139. package/lib/internal/gltfHumanoidBones.js +39 -0
  140. package/lib/internal/gltfHumanoidBones.js.map +1 -0
  141. package/lib/internal/humanoidBoneOfName.d.ts +18 -0
  142. package/lib/internal/humanoidBoneOfName.js +67 -0
  143. package/lib/internal/humanoidBoneOfName.js.map +1 -0
  144. package/lib/internal/inspectExternalModelHierarchy.d.ts +12 -0
  145. package/lib/internal/inspectExternalModelHierarchy.js +51 -0
  146. package/lib/internal/inspectExternalModelHierarchy.js.map +1 -0
  147. package/lib/internal/inspectExternalMotion.d.ts +23 -0
  148. package/lib/internal/inspectExternalMotion.js +152 -0
  149. package/lib/internal/inspectExternalMotion.js.map +1 -0
  150. package/lib/internal/inspectExternalMotionNodes.d.ts +15 -0
  151. package/lib/internal/inspectExternalMotionNodes.js +58 -0
  152. package/lib/internal/inspectExternalMotionNodes.js.map +1 -0
  153. package/lib/internal/integerIndex.d.ts +12 -0
  154. package/lib/internal/integerIndex.js +23 -0
  155. package/lib/internal/integerIndex.js.map +1 -0
  156. package/lib/internal/integerIndices.d.ts +12 -0
  157. package/lib/internal/integerIndices.js +23 -0
  158. package/lib/internal/integerIndices.js.map +1 -0
  159. package/lib/internal/nonNegativeInteger.d.ts +12 -0
  160. package/lib/internal/nonNegativeInteger.js +22 -0
  161. package/lib/internal/nonNegativeInteger.js.map +1 -0
  162. package/lib/internal/object.d.ts +12 -0
  163. package/lib/internal/object.js +21 -0
  164. package/lib/internal/object.js.map +1 -0
  165. package/lib/internal/optionalArray.d.ts +12 -0
  166. package/lib/internal/optionalArray.js +18 -0
  167. package/lib/internal/optionalArray.js.map +1 -0
  168. package/lib/internal/optionalObject.d.ts +12 -0
  169. package/lib/internal/optionalObject.js +18 -0
  170. package/lib/internal/optionalObject.js.map +1 -0
  171. package/lib/internal/optionalStringArray.d.ts +12 -0
  172. package/lib/internal/optionalStringArray.js +22 -0
  173. package/lib/internal/optionalStringArray.js.map +1 -0
  174. package/lib/internal/positiveInteger.d.ts +12 -0
  175. package/lib/internal/positiveInteger.js +22 -0
  176. package/lib/internal/positiveInteger.js.map +1 -0
  177. package/lib/internal/readMotionAccessor.d.ts +15 -0
  178. package/lib/internal/readMotionAccessor.js +41 -0
  179. package/lib/internal/readMotionAccessor.js.map +1 -0
  180. package/lib/internal/requiredArray.d.ts +12 -0
  181. package/lib/internal/requiredArray.js +21 -0
  182. package/lib/internal/requiredArray.js.map +1 -0
  183. package/lib/internal/uniqueStrings.d.ts +12 -0
  184. package/lib/internal/uniqueStrings.js +18 -0
  185. package/lib/internal/uniqueStrings.js.map +1 -0
  186. package/lib/internal/validNodeIndex.d.ts +12 -0
  187. package/lib/internal/validNodeIndex.js +20 -0
  188. package/lib/internal/validNodeIndex.js.map +1 -0
  189. package/lib/internal/validateAccessorRange.d.ts +14 -0
  190. package/lib/internal/validateAccessorRange.js +37 -0
  191. package/lib/internal/validateAccessorRange.js.map +1 -0
  192. package/lib/internal/validateHumanoidSkinning.d.ts +20 -0
  193. package/lib/internal/validateHumanoidSkinning.js +91 -0
  194. package/lib/internal/validateHumanoidSkinning.js.map +1 -0
  195. package/lib/internal/validatePayloadClosure.d.ts +21 -0
  196. package/lib/internal/validatePayloadClosure.js +74 -0
  197. package/lib/internal/validatePayloadClosure.js.map +1 -0
  198. package/lib/internal/validateSparseAccessor.d.ts +14 -0
  199. package/lib/internal/validateSparseAccessor.js +50 -0
  200. package/lib/internal/validateSparseAccessor.js.map +1 -0
  201. package/lib/internal/vrmHumanoidBones.d.ts +15 -0
  202. package/lib/internal/vrmHumanoidBones.js +132 -0
  203. package/lib/internal/vrmHumanoidBones.js.map +1 -0
  204. package/lib/isAutoMovieExternalModelIngestProfile.d.ts +18 -0
  205. package/lib/isAutoMovieExternalModelIngestProfile.js +24 -0
  206. package/lib/isAutoMovieExternalModelIngestProfile.js.map +1 -0
  207. package/package.json +45 -3
  208. package/src/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.ts +7 -0
  209. package/src/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.ts +21 -0
  210. package/src/AutoMovieExternalModelIngestProfile.ts +15 -0
  211. package/src/AutoMovieExternalMotionAdoptionDecision.ts +14 -0
  212. package/src/AutoMovieGltfMotionInterpretationProfile.ts +10 -0
  213. package/src/IAutoMovieExternalModelInspection.ts +62 -0
  214. package/src/IAutoMovieExternalModelResource.ts +20 -0
  215. package/src/IAutoMovieExternalMotionAdoption.ts +30 -0
  216. package/src/IAutoMovieExternalMotionBoneMapping.ts +17 -0
  217. package/src/IAutoMovieExternalMotionInspection.ts +32 -0
  218. package/src/IAutoMovieExternalMotionNativeDecision.ts +25 -0
  219. package/src/IAutoMovieExternalMotionNativeHandoff.ts +22 -0
  220. package/src/IAutoMovieExternalMotionNodeInspection.ts +26 -0
  221. package/src/IAutoMovieExternalMotionRetargetDecision.ts +31 -0
  222. package/src/IAutoMovieExternalMotionRetargetHandoff.ts +28 -0
  223. package/src/IAutoMovieExternalMotionSource.ts +20 -0
  224. package/src/IAutoMovieIngestResult.ts +19 -0
  225. package/src/adoptAutoMovieExternalMotion.ts +387 -0
  226. package/src/audio/IAutoMovieDecodedProductionAudioAsset.ts +35 -0
  227. package/src/audio/IAutoMovieProductionAudioProcessing.ts +21 -0
  228. package/src/audio/IAutoMovieProductionWaveSourceFormat.ts +50 -0
  229. package/src/audio/decodeProductionAudioAsset.ts +451 -0
  230. package/src/audio/index.ts +4 -0
  231. package/src/decodeAutoMoviePpmImage.ts +103 -0
  232. package/src/humanoidSkeleton.ts +105 -0
  233. package/src/index.ts +23 -0
  234. package/src/ingestDocument.ts +242 -0
  235. package/src/inspectAutoMovieExternalModelBytes.ts +346 -0
  236. package/src/internal/COMPONENT_BYTES.ts +12 -0
  237. package/src/internal/IAccessorSource.ts +18 -0
  238. package/src/internal/IExternalModelAccessorReader.ts +12 -0
  239. package/src/internal/IHumanoidSlot.ts +17 -0
  240. package/src/internal/IParsedContainer.ts +18 -0
  241. package/src/internal/SHAPE_COMPONENTS.ts +27 -0
  242. package/src/internal/accessorElementByteLength.ts +24 -0
  243. package/src/internal/accessorReader.ts +76 -0
  244. package/src/internal/accessorValues.ts +35 -0
  245. package/src/internal/collectExternalResources.ts +69 -0
  246. package/src/internal/compareCodeUnits.ts +15 -0
  247. package/src/internal/composeLocalTransform.ts +56 -0
  248. package/src/internal/decodeDataUri.ts +70 -0
  249. package/src/internal/decodeGlb.ts +70 -0
  250. package/src/internal/decodeJson.ts +76 -0
  251. package/src/internal/fileExtension.ts +18 -0
  252. package/src/internal/finiteTuple.ts +33 -0
  253. package/src/internal/gltfHumanoidBones.ts +48 -0
  254. package/src/internal/humanoidBoneOfName.ts +75 -0
  255. package/src/internal/inspectExternalModelHierarchy.ts +61 -0
  256. package/src/internal/inspectExternalMotion.ts +292 -0
  257. package/src/internal/inspectExternalMotionNodes.ts +81 -0
  258. package/src/internal/integerIndex.ts +28 -0
  259. package/src/internal/integerIndices.ts +24 -0
  260. package/src/internal/nonNegativeInteger.ts +22 -0
  261. package/src/internal/object.ts +22 -0
  262. package/src/internal/optionalArray.ts +17 -0
  263. package/src/internal/optionalObject.ts +20 -0
  264. package/src/internal/optionalStringArray.ts +22 -0
  265. package/src/internal/positiveInteger.ts +22 -0
  266. package/src/internal/readMotionAccessor.ts +60 -0
  267. package/src/internal/requiredArray.ts +19 -0
  268. package/src/internal/uniqueStrings.ts +16 -0
  269. package/src/internal/validNodeIndex.ts +19 -0
  270. package/src/internal/validateAccessorRange.ts +53 -0
  271. package/src/internal/validateHumanoidSkinning.ts +152 -0
  272. package/src/internal/validatePayloadClosure.ts +116 -0
  273. package/src/internal/validateSparseAccessor.ts +109 -0
  274. package/src/internal/vrmHumanoidBones.ts +176 -0
  275. package/src/isAutoMovieExternalModelIngestProfile.ts +28 -0
@@ -0,0 +1,17 @@
1
+ import { requiredArray } from "./requiredArray";
2
+
3
+ /**
4
+ * Read an absent optional JSON array as an empty inventory.
5
+ *
6
+ * @evidence contracts/development/implementation.md#principled-implementation Undefined alone produces an empty array; supplied values must pass the common Array.isArray gate.
7
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure The wrapper owns omission while requiredArray owns shape admission and named-path diagnostics.
8
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Null, strings and array-like objects are refused rather than being treated as missing inventories.
9
+ * @evidence contracts/development/common.md#meaningful-documentation Prose identifies the undefined case, unchanged supplied arrays and malformed-value refusal.
10
+ * @evidence contracts/development/implementation.md#efficient-algorithms One omission check and constant-time array identity test run without scanning elements.
11
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work The same required-array operation is reused for every present optional inventory.
12
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources Only omitted input creates a new empty array; valid supplied arrays remain borrowed and unretained.
13
+ */
14
+ export const optionalArray: (value: unknown, path: string) => unknown[] = (
15
+ value: unknown,
16
+ path: string,
17
+ ): unknown[] => (value === undefined ? [] : requiredArray(value, path));
@@ -0,0 +1,20 @@
1
+ import { object } from "./object";
2
+
3
+ /**
4
+ * Read an absent optional JSON object as an empty record.
5
+ *
6
+ * @evidence contracts/development/implementation.md#principled-implementation Undefined alone means omitted; a supplied value must pass the shared non-null non-array object gate.
7
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure This wrapper owns omission semantics while object identity and path diagnostics stay in the required-object helper.
8
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Null or arrays do not silently become empty optional objects, preserving malformed input distinctions.
9
+ * @evidence contracts/development/common.md#meaningful-documentation Comments state undefined-only omission and borrowed identity for supplied valid records.
10
+ * @evidence contracts/development/implementation.md#efficient-algorithms One omission test and at most one object gate require constant time without property scans.
11
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Required and optional records share the same object admission predicate instead of separate coercion logic.
12
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources Omission allocates one empty record; supplied records are borrowed with no retained handle or cache.
13
+ */
14
+ export const optionalObject: (
15
+ value: unknown,
16
+ path: string,
17
+ ) => Record<string, unknown> = (
18
+ value: unknown,
19
+ path: string,
20
+ ): Record<string, unknown> => (value === undefined ? {} : object(value, path));
@@ -0,0 +1,22 @@
1
+ import { optionalArray } from "./optionalArray";
2
+
3
+ /**
4
+ * Read an omitted or nonblank-string glTF extension inventory.
5
+ *
6
+ * @evidence contracts/development/implementation.md#principled-implementation Omission produces an empty array; supplied arrays must contain only nonblank strings with path/index diagnostics.
7
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Optional-array identity is delegated and this owner adds extension-name element admission.
8
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Names are not trimmed or case-folded, preserving exact identifiers after nonblank validation.
9
+ * @evidence contracts/development/common.md#meaningful-documentation The description explains omission, exact spelling preservation and indexed error paths.
10
+ * @evidence contracts/development/implementation.md#efficient-algorithms Cost is linear in element count plus trim scans of string lengths, with one returned array.
11
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Each name is checked once for this inventory; exact duplicate removal belongs to the downstream canonical inventory.
12
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources Only the returned string array survives; original arrays and validation metadata are not retained.
13
+ */
14
+ export const optionalStringArray: (value: unknown, path: string) => string[] = (
15
+ value: unknown,
16
+ path: string,
17
+ ): string[] =>
18
+ optionalArray(value, path).map((entry: unknown, index: number): string => {
19
+ if (typeof entry !== "string" || entry.trim().length === 0)
20
+ throw new Error(`${path}[${index}] must be a non-blank string.`);
21
+ return entry;
22
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Require a positive safe-integer glTF count or declared byte length.
3
+ *
4
+ * @evidence contracts/development/implementation.md#principled-implementation Type, safe-integer and strict-positive checks reject nonnumeric, fractional, zero and unsafe values before range arithmetic.
5
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure The scalar gate is shared by buffer lengths, view lengths and accessor counts.
6
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts A count is not rounded, clamped or silently replaced with a default value.
7
+ * @evidence contracts/development/common.md#meaningful-documentation The comment identifies safe-integer positivity, named-path errors and unchanged caller input.
8
+ * @evidence contracts/development/implementation.md#efficient-algorithms Three scalar predicates require constant time without metadata traversal or allocation.
9
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Repeated schema owners use the same positive-count predicate; no value admission cache is retained.
10
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The predicate retains no metadata and allocates only an error when refusing a value.
11
+ */
12
+ export const positiveInteger: (value: unknown, path: string) => void = (
13
+ value: unknown,
14
+ path: string,
15
+ ): void => {
16
+ if (
17
+ typeof value !== "number" ||
18
+ Number.isSafeInteger(value) === false ||
19
+ value <= 0
20
+ )
21
+ throw new Error(`${path} must be a positive safe integer.`);
22
+ };
@@ -0,0 +1,60 @@
1
+ import type { IAccessorSource } from "./IAccessorSource";
2
+ import type { IExternalModelAccessorReader } from "./IExternalModelAccessorReader";
3
+ import { SHAPE_COMPONENTS } from "./SHAPE_COMPONENTS";
4
+ import { accessorReader } from "./accessorReader";
5
+ import { object } from "./object";
6
+
7
+ /**
8
+ * Read a finite non-sparse FLOAT accessor into caller-owned motion values.
9
+ *
10
+ * The source inventories and byte ranges are already admitted. The requested SCALAR, VEC3 or VEC4 shape must match an accessor with a buffer view, FLOAT components and no sparse overrides. Every component is copied in element order and checked finite; a mismatch or non-finite value throws with the supplied path.
11
+ *
12
+ * @evidence contracts/development/implementation.md#principled-implementation Shape and FLOAT storage are checked before stride-aware component reads; every copied numeric value must be finite.
13
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Motion-specific shape admission stays here while shared reader code owns buffer view, stride and little-endian decoding.
14
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Sparse or normalized integer motion data is not coerced into the profile's exact FLOAT interpretation.
15
+ * @evidence contracts/development/common.md#meaningful-documentation Comments state source admission premises, permitted shapes, finite-value refusal and flat element/component order.
16
+ * @evidence contracts/development/implementation.md#efficient-algorithms Count times shape width drives time and output space; one reader and DataView serve the entire accessor copy.
17
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work The inspector caches this complete decoded accessor by index and expected shape within one immutable input revision.
18
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The output array belongs to its caller; the reader's borrowed payload reference ends when decoding completes.
19
+ */
20
+ export const readMotionAccessor: (
21
+ source: IAccessorSource,
22
+ accessorIndex: number,
23
+ expectedType: "SCALAR" | "VEC3" | "VEC4",
24
+ path: string,
25
+ ) => number[] = (
26
+ source: IAccessorSource,
27
+ accessorIndex: number,
28
+ expectedType: "SCALAR" | "VEC3" | "VEC4",
29
+ path: string,
30
+ ): number[] => {
31
+ const accessor: Record<string, unknown> = object(
32
+ source.accessors[accessorIndex],
33
+ `accessors[${accessorIndex}]`,
34
+ );
35
+ if (
36
+ accessor.componentType !== 5126 ||
37
+ accessor.type !== expectedType ||
38
+ accessor.bufferView === undefined ||
39
+ accessor.sparse !== undefined
40
+ )
41
+ throw new Error(
42
+ `${path} must resolve to a non-sparse FLOAT ${expectedType} accessor.`,
43
+ );
44
+ const width: number = SHAPE_COMPONENTS[expectedType]!;
45
+ const count: number = accessor.count as number;
46
+ const read: IExternalModelAccessorReader = accessorReader(
47
+ source,
48
+ accessorIndex,
49
+ `Motion accessor ${accessorIndex}`,
50
+ );
51
+ const values: number[] = new Array<number>(count * width);
52
+ for (let element: number = 0; element < count; ++element)
53
+ for (let component: number = 0; component < width; ++component) {
54
+ const value: number = read(element, component);
55
+ if (Number.isFinite(value) === false)
56
+ throw new Error(`${path} contains a non-finite value.`);
57
+ values[element * width + component] = value;
58
+ }
59
+ return values;
60
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Require an actual JSON array at a named external-document path.
3
+ *
4
+ * @evidence contracts/development/implementation.md#principled-implementation Array.isArray admits only array values; rejected inputs report their owning JSON path.
5
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One shape gate centralizes array identity for structural, motion and skin inspection.
6
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Objects, null and array-looking values are refused rather than coerced into synthetic inventories.
7
+ * @evidence contracts/development/common.md#meaningful-documentation Prose states input identity, path-named failure and that admitted arrays are borrowed unchanged.
8
+ * @evidence contracts/development/implementation.md#efficient-algorithms One Array.isArray check is constant-time without scanning or copying elements.
9
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work All optional-array handling delegates this same identity check when a value is present.
10
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The helper allocates no collection and returns the caller's existing array reference.
11
+ */
12
+ export const requiredArray: (value: unknown, path: string) => unknown[] = (
13
+ value: unknown,
14
+ path: string,
15
+ ): unknown[] => {
16
+ if (Array.isArray(value) === false)
17
+ throw new Error(`${path} must be an array.`);
18
+ return value as unknown[];
19
+ };
@@ -0,0 +1,16 @@
1
+ import { compareCodeUnits } from "./compareCodeUnits";
2
+
3
+ /**
4
+ * Return distinct strings in deterministic JavaScript code-unit order.
5
+ *
6
+ * @evidence contracts/development/implementation.md#principled-implementation A Set preserves exact string equality before the shared comparator imposes canonical ordering.
7
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Deduplication and ordering form one inventory operation used by the external-extension report.
8
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Case, whitespace and Unicode normalization are preserved rather than merging near-match extension identities.
9
+ * @evidence contracts/development/common.md#meaningful-documentation The description states exact equality, code-unit ordering and caller ownership of the result array.
10
+ * @evidence contracts/development/implementation.md#efficient-algorithms N inputs cause N expected Set operations over exact strings; U unique values need O(U log U) comparisons, each scanning the compared shared prefix, plus text-dependent string identity/hash work and O(U) collection space.
11
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work A single Set performs deduplication before sorting; mutable input arrays prevent safe retained identity caching.
12
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources One temporary Set and returned U-element array are allocated; no input collection is retained after return.
13
+ */
14
+ export const uniqueStrings: (values: string[]) => string[] = (
15
+ values: string[],
16
+ ): string[] => [...new Set<string>(values)].sort(compareCodeUnits);
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Recognize a safe integer inside a zero-based inventory.
3
+ *
4
+ * @evidence contracts/development/implementation.md#principled-implementation Number type, safe-integer identity and half-open bounds determine resolvable node or array references.
5
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure The boolean predicate separates recognition from integerIndex's field-specific throwing behavior.
6
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Nonnumeric, negative, fractional and unsafe values remain false without coercion or fallback.
7
+ * @evidence contracts/development/common.md#meaningful-documentation Prose states accepted bounds, safe precision and the nonthrowing recognition role.
8
+ * @evidence contracts/development/implementation.md#efficient-algorithms Four scalar predicates cost constant time independent of inventory size.
9
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Throwing index admission and VRM mapping reuse the same recognition semantics.
10
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The predicate retains no inventory references and acquires no resource.
11
+ */
12
+ export const validNodeIndex: (value: unknown, length: number) => boolean = (
13
+ value: unknown,
14
+ length: number,
15
+ ): boolean =>
16
+ typeof value === "number" &&
17
+ Number.isSafeInteger(value) &&
18
+ value >= 0 &&
19
+ value < length;
@@ -0,0 +1,53 @@
1
+ import { accessorElementByteLength } from "./accessorElementByteLength";
2
+ import { object } from "./object";
3
+
4
+ /**
5
+ * Admit one accessor's dense byte extent using its component shape and stride.
6
+ *
7
+ * The caller has admitted component type, shape, positive count, nonnegative offset and referenced view. Dense storage requires offset + (count - 1) * stride + paddedElementBytes to fit the view and stride to cover one element. Missing dense storage is accepted only when a sparse declaration exists, whose own gate checks its ranges; this gate does not check component alignment or payload values.
8
+ *
9
+ * @evidence contracts/development/implementation.md#principled-implementation Count, zero-default byte offset and padded element size determine final extent; validated buffer views bound the resulting range.
10
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Dense range arithmetic belongs here and shared element sizing supplies matrix-column padding without another table.
11
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts An accessor lacking both a buffer view and sparse payload is refused; no fallback data is synthesized.
12
+ * @evidence contracts/development/common.md#meaningful-documentation Comments give the dense extent formula, sparse-only allowance and prevalidated metadata premise.
13
+ * @evidence contracts/development/implementation.md#efficient-algorithms Constant-time arithmetic resolves one view and shape without visiting accessor elements.
14
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Padded element sizing is shared with sparse validation and component readers; no computed payload values are cached.
15
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The gate borrows metadata for the duration of one call and owns no reader or resident bytes.
16
+ */
17
+ export const validateAccessorRange: (
18
+ accessor: Record<string, unknown>,
19
+ index: number,
20
+ bufferViews: unknown[],
21
+ ) => void = (
22
+ accessor: Record<string, unknown>,
23
+ index: number,
24
+ bufferViews: unknown[],
25
+ ): void => {
26
+ if (accessor.bufferView === undefined) {
27
+ if (accessor.sparse === undefined)
28
+ throw new Error(
29
+ `accessors[${index}] needs a bufferView or a complete sparse payload.`,
30
+ );
31
+ return;
32
+ }
33
+ const view: Record<string, unknown> = object(
34
+ bufferViews[accessor.bufferView as number],
35
+ `bufferViews[${accessor.bufferView as number}]`,
36
+ );
37
+ const element: number = accessorElementByteLength(
38
+ accessor.componentType as number,
39
+ accessor.type as string,
40
+ );
41
+ const stride: number = (view.byteStride as number | undefined) ?? element;
42
+ if (stride < element)
43
+ throw new Error(
44
+ `accessors[${index}] element size ${element} exceeds bufferView byteStride ${stride}.`,
45
+ );
46
+ const offset: number = (accessor.byteOffset as number | undefined) ?? 0;
47
+ const count: number = accessor.count as number;
48
+ const end: number = offset + (count - 1) * stride + element;
49
+ if (end > (view.byteLength as number))
50
+ throw new Error(
51
+ `accessors[${index}] requires ${end} bytes inside a bufferView of ${String(view.byteLength)} bytes.`,
52
+ );
53
+ };
@@ -0,0 +1,152 @@
1
+ import type { IAccessorSource } from "./IAccessorSource";
2
+ import type { IExternalModelAccessorReader } from "./IExternalModelAccessorReader";
3
+ import { accessorReader } from "./accessorReader";
4
+ import { integerIndex } from "./integerIndex";
5
+ import { object } from "./object";
6
+ import { requiredArray } from "./requiredArray";
7
+
8
+ /**
9
+ * Check complete mesh/skin bindings and collect joints actually receiving positive weights.
10
+ *
11
+ * Matched VEC4 joints/weights and POSITION counts drive each vertex read. Negative components throw before a finite positive sum establishes weighted coverage. This pass reads only JOINTS_0/WEIGHTS_0; it does not enforce weight-sum normalization, uniqueness of nonzero influences or complete coverage of additional joint sets, and does not establish anatomical validity.
12
+ *
13
+ * @evidence contracts/development/implementation.md#principled-implementation Matched VEC4 joint/weight counts drive each vertex read; individual negative weights throw before a finite positive sum establishes coverage.
14
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure Mesh/skin pairs own weight admission, while the shared accessor reader owns stride, numeric decoding and resident views.
15
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Negative weights cannot be hidden by cancellation with positive weights; malformed bindings throw without guessed or clamped influences.
16
+ * @evidence contracts/development/common.md#meaningful-documentation Prose states nonnegative influence admission, positive finite total and the unresolved normalization/additional-set limits of this coverage pass.
17
+ * @evidence contracts/development/implementation.md#efficient-algorithms Cost is O(N plus unique bound mesh/skin vertex counts), with four weight reads and up to four joint-index reads per vertex, using expected constant-time membership sets.
18
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Repeated nodes binding the identical mesh/skin pair reuse completed checks within immutable synchronous inspection only.
19
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The per-call pair set and weighted-joint set scale with bindings and joints; no mesh bytes or running resources survive.
20
+ */
21
+ export const validateHumanoidSkinning: (props: {
22
+ nodes: unknown[];
23
+ meshes: unknown[];
24
+ skins: unknown[];
25
+ source: IAccessorSource;
26
+ }) => Set<number> = (props: {
27
+ nodes: unknown[];
28
+ meshes: unknown[];
29
+ skins: unknown[];
30
+ source: IAccessorSource;
31
+ }): Set<number> => {
32
+ let skinnedPrimitiveCount: number = 0;
33
+ const weightedNodes: Set<number> = new Set<number>();
34
+ // Instanced characters bind the same mesh and skin on several nodes; the
35
+ // weights are the same, so each pair is read once.
36
+ const checkedBindings: Set<string> = new Set<string>();
37
+ props.nodes.forEach((value: unknown, nodeIndex: number): void => {
38
+ const node: Record<string, unknown> = object(value, `nodes[${nodeIndex}]`);
39
+ if (node.skin === undefined) return;
40
+ if (node.mesh === undefined)
41
+ throw new Error(
42
+ `nodes[${nodeIndex}] binds a skin without a render mesh.`,
43
+ );
44
+ const skinIndex: number = node.skin as number;
45
+ const meshIndex: number = node.mesh as number;
46
+ const binding: string = `${meshIndex}:${skinIndex}`;
47
+ if (checkedBindings.has(binding)) return;
48
+ checkedBindings.add(binding);
49
+ const joints: unknown[] = requiredArray(
50
+ object(props.skins[skinIndex], `skins[${skinIndex}]`).joints,
51
+ `skins[${skinIndex}].joints`,
52
+ );
53
+ const mesh: Record<string, unknown> = object(
54
+ props.meshes[meshIndex],
55
+ `meshes[${meshIndex}]`,
56
+ );
57
+ requiredArray(mesh.primitives, `meshes[${meshIndex}].primitives`).forEach(
58
+ (primitiveValue: unknown, primitiveIndex: number): void => {
59
+ const path: string = `meshes[${meshIndex}].primitives[${primitiveIndex}]`;
60
+ const primitive: Record<string, unknown> = object(primitiveValue, path);
61
+ const attributes: Record<string, unknown> = object(
62
+ primitive.attributes,
63
+ `${path}.attributes`,
64
+ );
65
+ integerIndex(
66
+ attributes.JOINTS_0,
67
+ props.source.accessors.length,
68
+ `${path}.attributes.JOINTS_0`,
69
+ true,
70
+ );
71
+ integerIndex(
72
+ attributes.WEIGHTS_0,
73
+ props.source.accessors.length,
74
+ `${path}.attributes.WEIGHTS_0`,
75
+ true,
76
+ );
77
+ const jointIndex: number = attributes.JOINTS_0 as number;
78
+ const weightIndex: number = attributes.WEIGHTS_0 as number;
79
+ const position: Record<string, unknown> = object(
80
+ props.source.accessors[attributes.POSITION as number],
81
+ `accessors[${attributes.POSITION as number}]`,
82
+ );
83
+ const jointAccessor: Record<string, unknown> = object(
84
+ props.source.accessors[jointIndex],
85
+ `accessors[${jointIndex}]`,
86
+ );
87
+ const weightAccessor: Record<string, unknown> = object(
88
+ props.source.accessors[weightIndex],
89
+ `accessors[${weightIndex}]`,
90
+ );
91
+ if (
92
+ jointAccessor.type !== "VEC4" ||
93
+ (jointAccessor.componentType !== 5121 &&
94
+ jointAccessor.componentType !== 5123) ||
95
+ weightAccessor.type !== "VEC4" ||
96
+ (weightAccessor.componentType !== 5126 &&
97
+ weightAccessor.componentType !== 5121 &&
98
+ weightAccessor.componentType !== 5123) ||
99
+ (weightAccessor.componentType !== 5126 &&
100
+ weightAccessor.normalized !== true) ||
101
+ jointAccessor.count !== position.count ||
102
+ weightAccessor.count !== position.count
103
+ )
104
+ throw new Error(
105
+ `Skinned primitive ${meshIndex}:${primitiveIndex} needs count-matched JOINTS_0 and normalized WEIGHTS_0 VEC4 accessors.`,
106
+ );
107
+ const readWeight: IExternalModelAccessorReader = accessorReader(
108
+ props.source,
109
+ weightIndex,
110
+ `Skin accessor ${weightIndex}`,
111
+ );
112
+ const readJoint: IExternalModelAccessorReader = accessorReader(
113
+ props.source,
114
+ jointIndex,
115
+ `Skin accessor ${jointIndex}`,
116
+ );
117
+ for (
118
+ let vertex: number = 0;
119
+ vertex < (position.count as number);
120
+ ++vertex
121
+ ) {
122
+ let weightSum: number = 0;
123
+ for (let component: number = 0; component < 4; ++component) {
124
+ const weight: number = readWeight(vertex, component);
125
+ if (weight < 0)
126
+ throw new Error(
127
+ `Skinned primitive ${meshIndex}:${primitiveIndex} vertex ${vertex} component ${component} has negative skin weight ${weight}.`,
128
+ );
129
+ weightSum += weight;
130
+ if (weight > 0 === false) continue;
131
+ const joint: number = readJoint(vertex, component);
132
+ if (Number.isSafeInteger(joint) === false || joint >= joints.length)
133
+ throw new Error(
134
+ `Skinned primitive ${meshIndex}:${primitiveIndex} vertex ${vertex} cites joint ${joint} outside skin ${skinIndex}.`,
135
+ );
136
+ weightedNodes.add(joints[joint] as number);
137
+ }
138
+ if (Number.isFinite(weightSum) === false || weightSum <= 0)
139
+ throw new Error(
140
+ `Skinned primitive ${meshIndex}:${primitiveIndex} vertex ${vertex} has no positive skin weight.`,
141
+ );
142
+ }
143
+ ++skinnedPrimitiveCount;
144
+ },
145
+ );
146
+ });
147
+ if (skinnedPrimitiveCount === 0)
148
+ throw new Error(
149
+ "Humanoid profiles require at least one mesh node with a complete skin binding.",
150
+ );
151
+ return weightedNodes;
152
+ };
@@ -0,0 +1,116 @@
1
+ import { decodeDataUri } from "./decodeDataUri";
2
+ import { object } from "./object";
3
+
4
+ /**
5
+ * Bind every declared glTF buffer and image to its exact resident payload.
6
+ *
7
+ * The caller has admitted declared counts, lengths, views and URI shapes. Only buffer zero in a GLB/VRM container may borrow BIN, with at most three pad bytes; URI buffers require exact declared lengths, and views must fit declared and resident extents. Each external URI entry invokes the caller resolver independently, without network access here; data URIs decode locally and URI images need nonempty bytes. Returned buffer references live with the synchronous inspector, while image formats and sparse contents remain uninspected.
8
+ *
9
+ * @evidence contracts/development/implementation.md#principled-implementation GLB buffer zero owns BIN with at most three pad bytes; URI buffers require exact lengths and views fit declared and resident bounds.
10
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure One payload owner sequences buffer binding, orphan-BIN checks, view bounds and image presence before profile decoding.
11
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Missing sidecars throw; resolver effects occur per declared entry and are not silently deduplicated or replaced.
12
+ * @evidence contracts/development/common.md#meaningful-documentation Comments state read-only resident bytes, URI resolver responsibility, padding limits and no network fetch.
13
+ * @evidence contracts/development/implementation.md#efficient-algorithms Work follows buffer/view/image counts and encoded data-URI bytes, plus the caller's complete resolver work for each declared external URI entry; repeated URIs repeat callback effects, borrowed payloads avoid copies, and data URIs allocate decoded arrays.
14
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Each resolved buffer is reused by its accessors inside the call; callback effects prohibit caching by URI without caller guarantees.
15
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The inspector owns the temporary payload list and decoded data-URI arrays only for the call; sidecar buffers remain borrowed.
16
+ */
17
+ export const validatePayloadClosure: (props: {
18
+ format: "gltf" | "glb" | "vrm";
19
+ bin: Uint8Array | null;
20
+ buffers: unknown[];
21
+ bufferViews: unknown[];
22
+ images: unknown[];
23
+ resolveResource?: (uri: string) => Uint8Array | null;
24
+ }) => Uint8Array[] = (props: {
25
+ format: "gltf" | "glb" | "vrm";
26
+ bin: Uint8Array | null;
27
+ buffers: unknown[];
28
+ bufferViews: unknown[];
29
+ images: unknown[];
30
+ resolveResource?: (uri: string) => Uint8Array | null;
31
+ }): Uint8Array[] => {
32
+ const payloads: Uint8Array[] = props.buffers.map(
33
+ (value: unknown, index: number): Uint8Array => {
34
+ const buffer: Record<string, unknown> = object(
35
+ value,
36
+ `buffers[${index}]`,
37
+ );
38
+ const length: number = buffer.byteLength as number;
39
+ if (buffer.uri === undefined) {
40
+ if (props.format === "gltf" || index !== 0)
41
+ throw new Error(
42
+ `buffers[${index}] cannot use the GLB BIN chunk in this container.`,
43
+ );
44
+ if (props.bin === null)
45
+ throw new Error(
46
+ `buffers[${index}] declares ${length} bytes but the GLB has no BIN chunk.`,
47
+ );
48
+ if (props.bin.byteLength < length || props.bin.byteLength > length + 3)
49
+ throw new Error(
50
+ `GLB BIN chunk length ${props.bin.byteLength} does not cover buffers[${index}].byteLength ${length} with at most three padding bytes.`,
51
+ );
52
+ return props.bin;
53
+ }
54
+ const uri: string = buffer.uri as string;
55
+ if (uri.startsWith("data:")) {
56
+ const bytes: Uint8Array = decodeDataUri(uri, `buffers[${index}].uri`);
57
+ if (bytes.byteLength !== length)
58
+ throw new Error(
59
+ `buffers[${index}] data URI has ${bytes.byteLength} bytes, not declared byteLength ${length}.`,
60
+ );
61
+ return bytes;
62
+ }
63
+ const bytes: Uint8Array | null = props.resolveResource?.(uri) ?? null;
64
+ if (bytes === null)
65
+ throw new Error(
66
+ `External buffer "${uri}" has no builder-resolved resident bytes.`,
67
+ );
68
+ if (bytes.byteLength !== length)
69
+ throw new Error(
70
+ `External buffer "${uri}" has ${bytes.byteLength} bytes, not declared byteLength ${length}.`,
71
+ );
72
+ return bytes;
73
+ },
74
+ );
75
+ if (props.bin !== null && props.buffers.length === 0)
76
+ throw new Error("GLB contains a BIN chunk but declares no buffer.");
77
+ if (
78
+ props.bin !== null &&
79
+ object(props.buffers[0], "buffers[0]").uri !== undefined
80
+ )
81
+ throw new Error(
82
+ "GLB BIN chunk is orphaned because buffers[0] declares an external URI.",
83
+ );
84
+ props.bufferViews.forEach((value: unknown, index: number): void => {
85
+ const view: Record<string, unknown> = object(
86
+ value,
87
+ `bufferViews[${index}]`,
88
+ );
89
+ const bufferIndex: number = view.buffer as number;
90
+ const offset: number = (view.byteOffset as number | undefined) ?? 0;
91
+ const length: number = view.byteLength as number;
92
+ const declared: number = object(
93
+ props.buffers[bufferIndex],
94
+ `buffers[${bufferIndex}]`,
95
+ ).byteLength as number;
96
+ if (
97
+ offset + length > declared ||
98
+ offset + length > payloads[bufferIndex]!.byteLength
99
+ )
100
+ throw new Error(
101
+ `bufferViews[${index}] range ${offset}..${offset + length} exceeds buffers[${bufferIndex}].byteLength ${declared}.`,
102
+ );
103
+ });
104
+ props.images.forEach((value: unknown, index: number): void => {
105
+ const image: Record<string, unknown> = object(value, `images[${index}]`);
106
+ if (typeof image.uri !== "string") return;
107
+ const bytes: Uint8Array | null = image.uri.startsWith("data:")
108
+ ? decodeDataUri(image.uri, `images[${index}].uri`)
109
+ : (props.resolveResource?.(image.uri) ?? null);
110
+ if (bytes === null || bytes.byteLength === 0)
111
+ throw new Error(
112
+ `External image "${image.uri}" has no non-empty builder-resolved resident bytes.`,
113
+ );
114
+ });
115
+ return payloads;
116
+ };
@@ -0,0 +1,109 @@
1
+ import { COMPONENT_BYTES } from "./COMPONENT_BYTES";
2
+ import { accessorElementByteLength } from "./accessorElementByteLength";
3
+ import { integerIndex } from "./integerIndex";
4
+ import { nonNegativeInteger } from "./nonNegativeInteger";
5
+ import { object } from "./object";
6
+ import { positiveInteger } from "./positiveInteger";
7
+
8
+ /**
9
+ * Admit sparse accessor byte ranges within validated glTF buffer views.
10
+ *
11
+ * Absent sparse metadata does nothing. Present metadata needs a positive count no greater than accessor count, valid index/value views, unsigned byte/short/int indices and nonnegative zero-default offsets. Both tightly packed extents must fit their views; index ordering, index values and sparse payload values are not decoded, and skin/motion readers reject sparse accessors separately.
12
+ *
13
+ * @evidence contracts/development/implementation.md#principled-implementation Sparse count cannot exceed accessor count; unsigned index widths and padded matrix element sizes determine both payload ranges.
14
+ * @evidence contracts/development/implementation.md#clear-and-simple-structure The sparse gate owns count, index format and subview range checks while shared element sizing owns matrix padding.
15
+ * @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Sparse layout is checked structurally but skin/motion consumers explicitly refuse sparse reading rather than inventing dense values.
16
+ * @evidence contracts/development/common.md#meaningful-documentation Prose explains admitted view indices, zero-default offsets, count bounds and consumer limitations.
17
+ * @evidence contracts/development/implementation.md#efficient-algorithms One sparse accessor requires constant-size field checks and two range calculations independent of sparse element count.
18
+ * @evidence contracts/development/implementation.md#reuse-equivalent-work Subview metadata is read once per sparse payload; no byte decoding is performed or cached here.
19
+ * @evidence contracts/development/implementation.md#bound-retention-and-release-resources The range gate creates temporary metadata references only and retains no payload, reader or handle.
20
+ */
21
+ export const validateSparseAccessor: (
22
+ accessor: Record<string, unknown>,
23
+ index: number,
24
+ bufferViews: unknown[],
25
+ ) => void = (
26
+ accessor: Record<string, unknown>,
27
+ index: number,
28
+ bufferViews: unknown[],
29
+ ): void => {
30
+ if (accessor.sparse === undefined) return;
31
+ const sparse: Record<string, unknown> = object(
32
+ accessor.sparse,
33
+ `accessors[${index}].sparse`,
34
+ );
35
+ positiveInteger(sparse.count, `accessors[${index}].sparse.count`);
36
+ if ((sparse.count as number) > (accessor.count as number))
37
+ throw new Error(
38
+ `accessors[${index}].sparse.count exceeds the accessor count.`,
39
+ );
40
+ const indices: Record<string, unknown> = object(
41
+ sparse.indices,
42
+ `accessors[${index}].sparse.indices`,
43
+ );
44
+ const values: Record<string, unknown> = object(
45
+ sparse.values,
46
+ `accessors[${index}].sparse.values`,
47
+ );
48
+ integerIndex(
49
+ indices.bufferView,
50
+ bufferViews.length,
51
+ `accessors[${index}].sparse.indices.bufferView`,
52
+ true,
53
+ );
54
+ integerIndex(
55
+ values.bufferView,
56
+ bufferViews.length,
57
+ `accessors[${index}].sparse.values.bufferView`,
58
+ true,
59
+ );
60
+ if (
61
+ indices.componentType !== 5121 &&
62
+ indices.componentType !== 5123 &&
63
+ indices.componentType !== 5125
64
+ )
65
+ throw new Error(
66
+ `accessors[${index}].sparse.indices.componentType must be unsigned byte, short or int.`,
67
+ );
68
+ const count: number = sparse.count as number;
69
+ validateSubViewRange(
70
+ bufferViews,
71
+ indices.bufferView as number,
72
+ (indices.byteOffset as number | undefined) ?? 0,
73
+ count * COMPONENT_BYTES.get(indices.componentType as number)!,
74
+ `accessors[${index}].sparse.indices`,
75
+ );
76
+ validateSubViewRange(
77
+ bufferViews,
78
+ values.bufferView as number,
79
+ (values.byteOffset as number | undefined) ?? 0,
80
+ count *
81
+ accessorElementByteLength(
82
+ accessor.componentType as number,
83
+ accessor.type as string,
84
+ ),
85
+ `accessors[${index}].sparse.values`,
86
+ );
87
+ };
88
+
89
+ const validateSubViewRange: (
90
+ bufferViews: unknown[],
91
+ viewIndex: number,
92
+ offset: number,
93
+ length: number,
94
+ path: string,
95
+ ) => void = (
96
+ bufferViews: unknown[],
97
+ viewIndex: number,
98
+ offset: number,
99
+ length: number,
100
+ path: string,
101
+ ): void => {
102
+ nonNegativeInteger(offset, `${path}.byteOffset`);
103
+ const view: Record<string, unknown> = object(
104
+ bufferViews[viewIndex],
105
+ `bufferViews[${viewIndex}]`,
106
+ );
107
+ if (offset + length > (view.byteLength as number))
108
+ throw new Error(`${path} exceeds its bufferView range.`);
109
+ };