@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.
- package/LICENSE +21 -0
- package/README.md +37 -2
- package/lib/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.d.ts +5 -0
- package/lib/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.js +8 -0
- package/lib/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.js.map +1 -0
- package/lib/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.d.ts +5 -0
- package/lib/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.js +15 -0
- package/lib/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.js.map +1 -0
- package/lib/AutoMovieExternalModelIngestProfile.d.ts +11 -0
- package/lib/AutoMovieExternalModelIngestProfile.js +3 -0
- package/lib/AutoMovieExternalModelIngestProfile.js.map +1 -0
- package/lib/AutoMovieExternalMotionAdoptionDecision.d.ts +11 -0
- package/lib/AutoMovieExternalMotionAdoptionDecision.js +3 -0
- package/lib/AutoMovieExternalMotionAdoptionDecision.js.map +1 -0
- package/lib/AutoMovieGltfMotionInterpretationProfile.d.ts +9 -0
- package/lib/AutoMovieGltfMotionInterpretationProfile.js +3 -0
- package/lib/AutoMovieGltfMotionInterpretationProfile.js.map +1 -0
- package/lib/IAutoMovieExternalModelInspection.d.ts +48 -0
- package/lib/IAutoMovieExternalModelInspection.js +3 -0
- package/lib/IAutoMovieExternalModelInspection.js.map +1 -0
- package/lib/IAutoMovieExternalModelResource.d.ts +18 -0
- package/lib/IAutoMovieExternalModelResource.js +3 -0
- package/lib/IAutoMovieExternalModelResource.js.map +1 -0
- package/lib/IAutoMovieExternalMotionAdoption.d.ts +23 -0
- package/lib/IAutoMovieExternalMotionAdoption.js +3 -0
- package/lib/IAutoMovieExternalMotionAdoption.js.map +1 -0
- package/lib/IAutoMovieExternalMotionBoneMapping.d.ts +15 -0
- package/lib/IAutoMovieExternalMotionBoneMapping.js +3 -0
- package/lib/IAutoMovieExternalMotionBoneMapping.js.map +1 -0
- package/lib/IAutoMovieExternalMotionInspection.d.ts +25 -0
- package/lib/IAutoMovieExternalMotionInspection.js +3 -0
- package/lib/IAutoMovieExternalMotionInspection.js.map +1 -0
- package/lib/IAutoMovieExternalMotionNativeDecision.d.ts +20 -0
- package/lib/IAutoMovieExternalMotionNativeDecision.js +3 -0
- package/lib/IAutoMovieExternalMotionNativeDecision.js.map +1 -0
- package/lib/IAutoMovieExternalMotionNativeHandoff.d.ts +18 -0
- package/lib/IAutoMovieExternalMotionNativeHandoff.js +3 -0
- package/lib/IAutoMovieExternalMotionNativeHandoff.js.map +1 -0
- package/lib/IAutoMovieExternalMotionNodeInspection.d.ts +21 -0
- package/lib/IAutoMovieExternalMotionNodeInspection.js +3 -0
- package/lib/IAutoMovieExternalMotionNodeInspection.js.map +1 -0
- package/lib/IAutoMovieExternalMotionRetargetDecision.d.ts +24 -0
- package/lib/IAutoMovieExternalMotionRetargetDecision.js +3 -0
- package/lib/IAutoMovieExternalMotionRetargetDecision.js.map +1 -0
- package/lib/IAutoMovieExternalMotionRetargetHandoff.d.ts +22 -0
- package/lib/IAutoMovieExternalMotionRetargetHandoff.js +3 -0
- package/lib/IAutoMovieExternalMotionRetargetHandoff.js.map +1 -0
- package/lib/IAutoMovieExternalMotionSource.d.ts +18 -0
- package/lib/IAutoMovieExternalMotionSource.js +3 -0
- package/lib/IAutoMovieExternalMotionSource.js.map +1 -0
- package/lib/IAutoMovieIngestResult.d.ts +17 -0
- package/lib/IAutoMovieIngestResult.js +3 -0
- package/lib/IAutoMovieIngestResult.js.map +1 -0
- package/lib/adoptAutoMovieExternalMotion.d.ts +32 -0
- package/lib/adoptAutoMovieExternalMotion.js +215 -0
- package/lib/adoptAutoMovieExternalMotion.js.map +1 -0
- package/lib/audio/IAutoMovieDecodedProductionAudioAsset.d.ts +28 -0
- package/lib/audio/IAutoMovieDecodedProductionAudioAsset.js +3 -0
- package/lib/audio/IAutoMovieDecodedProductionAudioAsset.js.map +1 -0
- package/lib/audio/IAutoMovieProductionAudioProcessing.d.ts +18 -0
- package/lib/audio/IAutoMovieProductionAudioProcessing.js +3 -0
- package/lib/audio/IAutoMovieProductionAudioProcessing.js.map +1 -0
- package/lib/audio/IAutoMovieProductionWaveSourceFormat.d.ts +39 -0
- package/lib/audio/IAutoMovieProductionWaveSourceFormat.js +3 -0
- package/lib/audio/IAutoMovieProductionWaveSourceFormat.js.map +1 -0
- package/lib/audio/decodeProductionAudioAsset.d.ts +33 -0
- package/lib/audio/decodeProductionAudioAsset.js +257 -0
- package/lib/audio/decodeProductionAudioAsset.js.map +1 -0
- package/lib/audio/index.d.ts +4 -0
- package/lib/audio/index.js +21 -0
- package/lib/audio/index.js.map +1 -0
- package/lib/decodeAutoMoviePpmImage.d.ts +30 -0
- package/lib/decodeAutoMoviePpmImage.js +84 -0
- package/lib/decodeAutoMoviePpmImage.js.map +1 -0
- package/lib/humanoidSkeleton.d.ts +24 -0
- package/lib/humanoidSkeleton.js +80 -0
- package/lib/humanoidSkeleton.js.map +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +40 -0
- package/lib/index.js.map +1 -0
- package/lib/ingestDocument.d.ts +23 -0
- package/lib/ingestDocument.js +173 -0
- package/lib/ingestDocument.js.map +1 -0
- package/lib/inspectAutoMovieExternalModelBytes.d.ts +32 -0
- package/lib/inspectAutoMovieExternalModelBytes.js +219 -0
- package/lib/inspectAutoMovieExternalModelBytes.js.map +1 -0
- package/lib/internal/COMPONENT_BYTES.d.ts +2 -0
- package/lib/internal/COMPONENT_BYTES.js +13 -0
- package/lib/internal/COMPONENT_BYTES.js.map +1 -0
- package/lib/internal/IAccessorSource.d.ts +16 -0
- package/lib/internal/IAccessorSource.js +3 -0
- package/lib/internal/IAccessorSource.js.map +1 -0
- package/lib/internal/IExternalModelAccessorReader.d.ts +9 -0
- package/lib/internal/IExternalModelAccessorReader.js +3 -0
- package/lib/internal/IExternalModelAccessorReader.js.map +1 -0
- package/lib/internal/IHumanoidSlot.d.ts +15 -0
- package/lib/internal/IHumanoidSlot.js +3 -0
- package/lib/internal/IHumanoidSlot.js.map +1 -0
- package/lib/internal/IParsedContainer.d.ts +16 -0
- package/lib/internal/IParsedContainer.js +3 -0
- package/lib/internal/IParsedContainer.js.map +1 -0
- package/lib/internal/SHAPE_COMPONENTS.d.ts +6 -0
- package/lib/internal/SHAPE_COMPONENTS.js +25 -0
- package/lib/internal/SHAPE_COMPONENTS.js.map +1 -0
- package/lib/internal/accessorElementByteLength.d.ts +12 -0
- package/lib/internal/accessorElementByteLength.js +28 -0
- package/lib/internal/accessorElementByteLength.js.map +1 -0
- package/lib/internal/accessorReader.d.ts +16 -0
- package/lib/internal/accessorReader.js +52 -0
- package/lib/internal/accessorReader.js.map +1 -0
- package/lib/internal/accessorValues.d.ts +18 -0
- package/lib/internal/accessorValues.js +38 -0
- package/lib/internal/accessorValues.js.map +1 -0
- package/lib/internal/collectExternalResources.d.ts +13 -0
- package/lib/internal/collectExternalResources.js +51 -0
- package/lib/internal/collectExternalResources.js.map +1 -0
- package/lib/internal/compareCodeUnits.d.ts +12 -0
- package/lib/internal/compareCodeUnits.js +17 -0
- package/lib/internal/compareCodeUnits.js.map +1 -0
- package/lib/internal/composeLocalTransform.d.ts +21 -0
- package/lib/internal/composeLocalTransform.js +53 -0
- package/lib/internal/composeLocalTransform.js.map +1 -0
- package/lib/internal/decodeDataUri.d.ts +14 -0
- package/lib/internal/decodeDataUri.js +61 -0
- package/lib/internal/decodeDataUri.js.map +1 -0
- package/lib/internal/decodeGlb.d.ts +13 -0
- package/lib/internal/decodeGlb.js +56 -0
- package/lib/internal/decodeGlb.js.map +1 -0
- package/lib/internal/decodeJson.d.ts +12 -0
- package/lib/internal/decodeJson.js +77 -0
- package/lib/internal/decodeJson.js.map +1 -0
- package/lib/internal/fileExtension.d.ts +12 -0
- package/lib/internal/fileExtension.js +21 -0
- package/lib/internal/fileExtension.js.map +1 -0
- package/lib/internal/finiteTuple.d.ts +14 -0
- package/lib/internal/finiteTuple.js +29 -0
- package/lib/internal/finiteTuple.js.map +1 -0
- package/lib/internal/gltfHumanoidBones.d.ts +15 -0
- package/lib/internal/gltfHumanoidBones.js +39 -0
- package/lib/internal/gltfHumanoidBones.js.map +1 -0
- package/lib/internal/humanoidBoneOfName.d.ts +18 -0
- package/lib/internal/humanoidBoneOfName.js +67 -0
- package/lib/internal/humanoidBoneOfName.js.map +1 -0
- package/lib/internal/inspectExternalModelHierarchy.d.ts +12 -0
- package/lib/internal/inspectExternalModelHierarchy.js +51 -0
- package/lib/internal/inspectExternalModelHierarchy.js.map +1 -0
- package/lib/internal/inspectExternalMotion.d.ts +23 -0
- package/lib/internal/inspectExternalMotion.js +152 -0
- package/lib/internal/inspectExternalMotion.js.map +1 -0
- package/lib/internal/inspectExternalMotionNodes.d.ts +15 -0
- package/lib/internal/inspectExternalMotionNodes.js +58 -0
- package/lib/internal/inspectExternalMotionNodes.js.map +1 -0
- package/lib/internal/integerIndex.d.ts +12 -0
- package/lib/internal/integerIndex.js +23 -0
- package/lib/internal/integerIndex.js.map +1 -0
- package/lib/internal/integerIndices.d.ts +12 -0
- package/lib/internal/integerIndices.js +23 -0
- package/lib/internal/integerIndices.js.map +1 -0
- package/lib/internal/nonNegativeInteger.d.ts +12 -0
- package/lib/internal/nonNegativeInteger.js +22 -0
- package/lib/internal/nonNegativeInteger.js.map +1 -0
- package/lib/internal/object.d.ts +12 -0
- package/lib/internal/object.js +21 -0
- package/lib/internal/object.js.map +1 -0
- package/lib/internal/optionalArray.d.ts +12 -0
- package/lib/internal/optionalArray.js +18 -0
- package/lib/internal/optionalArray.js.map +1 -0
- package/lib/internal/optionalObject.d.ts +12 -0
- package/lib/internal/optionalObject.js +18 -0
- package/lib/internal/optionalObject.js.map +1 -0
- package/lib/internal/optionalStringArray.d.ts +12 -0
- package/lib/internal/optionalStringArray.js +22 -0
- package/lib/internal/optionalStringArray.js.map +1 -0
- package/lib/internal/positiveInteger.d.ts +12 -0
- package/lib/internal/positiveInteger.js +22 -0
- package/lib/internal/positiveInteger.js.map +1 -0
- package/lib/internal/readMotionAccessor.d.ts +15 -0
- package/lib/internal/readMotionAccessor.js +41 -0
- package/lib/internal/readMotionAccessor.js.map +1 -0
- package/lib/internal/requiredArray.d.ts +12 -0
- package/lib/internal/requiredArray.js +21 -0
- package/lib/internal/requiredArray.js.map +1 -0
- package/lib/internal/uniqueStrings.d.ts +12 -0
- package/lib/internal/uniqueStrings.js +18 -0
- package/lib/internal/uniqueStrings.js.map +1 -0
- package/lib/internal/validNodeIndex.d.ts +12 -0
- package/lib/internal/validNodeIndex.js +20 -0
- package/lib/internal/validNodeIndex.js.map +1 -0
- package/lib/internal/validateAccessorRange.d.ts +14 -0
- package/lib/internal/validateAccessorRange.js +37 -0
- package/lib/internal/validateAccessorRange.js.map +1 -0
- package/lib/internal/validateHumanoidSkinning.d.ts +20 -0
- package/lib/internal/validateHumanoidSkinning.js +91 -0
- package/lib/internal/validateHumanoidSkinning.js.map +1 -0
- package/lib/internal/validatePayloadClosure.d.ts +21 -0
- package/lib/internal/validatePayloadClosure.js +74 -0
- package/lib/internal/validatePayloadClosure.js.map +1 -0
- package/lib/internal/validateSparseAccessor.d.ts +14 -0
- package/lib/internal/validateSparseAccessor.js +50 -0
- package/lib/internal/validateSparseAccessor.js.map +1 -0
- package/lib/internal/vrmHumanoidBones.d.ts +15 -0
- package/lib/internal/vrmHumanoidBones.js +132 -0
- package/lib/internal/vrmHumanoidBones.js.map +1 -0
- package/lib/isAutoMovieExternalModelIngestProfile.d.ts +18 -0
- package/lib/isAutoMovieExternalModelIngestProfile.js +24 -0
- package/lib/isAutoMovieExternalModelIngestProfile.js.map +1 -0
- package/package.json +45 -3
- package/src/AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE.ts +7 -0
- package/src/AUTO_MOVIE_EXTERNAL_MODEL_INGEST_PROFILES.ts +21 -0
- package/src/AutoMovieExternalModelIngestProfile.ts +15 -0
- package/src/AutoMovieExternalMotionAdoptionDecision.ts +14 -0
- package/src/AutoMovieGltfMotionInterpretationProfile.ts +10 -0
- package/src/IAutoMovieExternalModelInspection.ts +62 -0
- package/src/IAutoMovieExternalModelResource.ts +20 -0
- package/src/IAutoMovieExternalMotionAdoption.ts +30 -0
- package/src/IAutoMovieExternalMotionBoneMapping.ts +17 -0
- package/src/IAutoMovieExternalMotionInspection.ts +32 -0
- package/src/IAutoMovieExternalMotionNativeDecision.ts +25 -0
- package/src/IAutoMovieExternalMotionNativeHandoff.ts +22 -0
- package/src/IAutoMovieExternalMotionNodeInspection.ts +26 -0
- package/src/IAutoMovieExternalMotionRetargetDecision.ts +31 -0
- package/src/IAutoMovieExternalMotionRetargetHandoff.ts +28 -0
- package/src/IAutoMovieExternalMotionSource.ts +20 -0
- package/src/IAutoMovieIngestResult.ts +19 -0
- package/src/adoptAutoMovieExternalMotion.ts +387 -0
- package/src/audio/IAutoMovieDecodedProductionAudioAsset.ts +35 -0
- package/src/audio/IAutoMovieProductionAudioProcessing.ts +21 -0
- package/src/audio/IAutoMovieProductionWaveSourceFormat.ts +50 -0
- package/src/audio/decodeProductionAudioAsset.ts +451 -0
- package/src/audio/index.ts +4 -0
- package/src/decodeAutoMoviePpmImage.ts +103 -0
- package/src/humanoidSkeleton.ts +105 -0
- package/src/index.ts +23 -0
- package/src/ingestDocument.ts +242 -0
- package/src/inspectAutoMovieExternalModelBytes.ts +346 -0
- package/src/internal/COMPONENT_BYTES.ts +12 -0
- package/src/internal/IAccessorSource.ts +18 -0
- package/src/internal/IExternalModelAccessorReader.ts +12 -0
- package/src/internal/IHumanoidSlot.ts +17 -0
- package/src/internal/IParsedContainer.ts +18 -0
- package/src/internal/SHAPE_COMPONENTS.ts +27 -0
- package/src/internal/accessorElementByteLength.ts +24 -0
- package/src/internal/accessorReader.ts +76 -0
- package/src/internal/accessorValues.ts +35 -0
- package/src/internal/collectExternalResources.ts +69 -0
- package/src/internal/compareCodeUnits.ts +15 -0
- package/src/internal/composeLocalTransform.ts +56 -0
- package/src/internal/decodeDataUri.ts +70 -0
- package/src/internal/decodeGlb.ts +70 -0
- package/src/internal/decodeJson.ts +76 -0
- package/src/internal/fileExtension.ts +18 -0
- package/src/internal/finiteTuple.ts +33 -0
- package/src/internal/gltfHumanoidBones.ts +48 -0
- package/src/internal/humanoidBoneOfName.ts +75 -0
- package/src/internal/inspectExternalModelHierarchy.ts +61 -0
- package/src/internal/inspectExternalMotion.ts +292 -0
- package/src/internal/inspectExternalMotionNodes.ts +81 -0
- package/src/internal/integerIndex.ts +28 -0
- package/src/internal/integerIndices.ts +24 -0
- package/src/internal/nonNegativeInteger.ts +22 -0
- package/src/internal/object.ts +22 -0
- package/src/internal/optionalArray.ts +17 -0
- package/src/internal/optionalObject.ts +20 -0
- package/src/internal/optionalStringArray.ts +22 -0
- package/src/internal/positiveInteger.ts +22 -0
- package/src/internal/readMotionAccessor.ts +60 -0
- package/src/internal/requiredArray.ts +19 -0
- package/src/internal/uniqueStrings.ts +16 -0
- package/src/internal/validNodeIndex.ts +19 -0
- package/src/internal/validateAccessorRange.ts +53 -0
- package/src/internal/validateHumanoidSkinning.ts +152 -0
- package/src/internal/validatePayloadClosure.ts +116 -0
- package/src/internal/validateSparseAccessor.ts +109 -0
- package/src/internal/vrmHumanoidBones.ts +176 -0
- package/src/isAutoMovieExternalModelIngestProfile.ts +28 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AutoMovieHumanoidBone } from "@automovie/interface";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One normalized humanoid slot referencing an inspected glTF node index.
|
|
5
|
+
*
|
|
6
|
+
* @evidence contracts/development/design.md#principled-representation The semantic slot union and zero-based node index join metadata conventions to the same admitted node inventory.
|
|
7
|
+
* @evidence contracts/development/design.md#minimal-and-owned-surface One compact relation is shared by glTF name mapping and explicit VRM declarations.
|
|
8
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts A slot declaration does not establish positive skin weight; the separate coverage pass supplies that fact.
|
|
9
|
+
* @evidence contracts/development/common.md#meaningful-documentation Member comments identify normalized semantic meaning and index provenance, excluding weight certification.
|
|
10
|
+
*/
|
|
11
|
+
export interface IHumanoidSlot {
|
|
12
|
+
/** Normalized humanoid semantic slot declared or resolved by the current profile. */
|
|
13
|
+
bone: AutoMovieHumanoidBone;
|
|
14
|
+
|
|
15
|
+
/** Zero-based node index admitted against the current source document inventory. */
|
|
16
|
+
node: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One decoded glTF/GLB container with parsed JSON and optional borrowed BIN view.
|
|
3
|
+
*
|
|
4
|
+
* @evidence contracts/development/design.md#principled-representation JSON owns parsed values while the optional BIN aliases the validated resident GLB chunk.
|
|
5
|
+
* @evidence contracts/development/design.md#minimal-and-owned-surface One framing result separates logical document facts from binary bytes before structural admission.
|
|
6
|
+
* @evidence contracts/development/design.md#prohibited-design-shortcuts A suffix-provided VRM label does not certify VRM metadata; the humanoid profile checks it separately.
|
|
7
|
+
* @evidence contracts/development/common.md#meaningful-documentation Members describe parsed JSON, container family and read-only optional BIN aliasing.
|
|
8
|
+
*/
|
|
9
|
+
export interface IParsedContainer {
|
|
10
|
+
/** Strictly parsed JSON document awaiting structural/profile admission. */
|
|
11
|
+
json: unknown;
|
|
12
|
+
|
|
13
|
+
/** Container family selected from the supported path suffix; metadata is checked separately. */
|
|
14
|
+
format: "gltf" | "glb" | "vrm";
|
|
15
|
+
|
|
16
|
+
/** Read-only view of the optional validated GLB BIN chunk, or null for absent binary payload. */
|
|
17
|
+
bin: Uint8Array | null;
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component counts of glTF scalar, vector and matrix accessor shapes.
|
|
3
|
+
*
|
|
4
|
+
* The fixed glTF shape vocabulary defines scalar/vector width and square-matrix component counts used after shape admission. Dense ranges, motion arity and element sizing share this fixed seven-entry table; logical matrix counts do not replace physical column-padding rules.
|
|
5
|
+
*/
|
|
6
|
+
export const SHAPE_COMPONENTS: Readonly<Record<string, number>> = {
|
|
7
|
+
/** One logical scalar component. */
|
|
8
|
+
SCALAR: 1,
|
|
9
|
+
|
|
10
|
+
/** Two logical vector components. */
|
|
11
|
+
VEC2: 2,
|
|
12
|
+
|
|
13
|
+
/** Three logical vector components. */
|
|
14
|
+
VEC3: 3,
|
|
15
|
+
|
|
16
|
+
/** Four logical vector components. */
|
|
17
|
+
VEC4: 4,
|
|
18
|
+
|
|
19
|
+
/** Four logical matrix components, independent of byte-column padding. */
|
|
20
|
+
MAT2: 4,
|
|
21
|
+
|
|
22
|
+
/** Nine logical matrix components, independent of byte-column padding. */
|
|
23
|
+
MAT3: 9,
|
|
24
|
+
|
|
25
|
+
/** Sixteen logical matrix components. */
|
|
26
|
+
MAT4: 16,
|
|
27
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { COMPONENT_BYTES } from "./COMPONENT_BYTES";
|
|
2
|
+
import { SHAPE_COMPONENTS } from "./SHAPE_COMPONENTS";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Compute glTF accessor element storage including matrix-column padding.
|
|
6
|
+
*
|
|
7
|
+
* @evidence contracts/development/implementation.md#principled-implementation Component byte width and logical shape count define dense size; MAT2/MAT3 narrow components pad each column to four bytes.
|
|
8
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One sizing owner serves dense, sparse and reader stride defaults so storage alignment rules have one representation.
|
|
9
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Padded matrix cases are glTF layout contracts rather than fixture corrections; shape/type admission is a required caller premise.
|
|
10
|
+
* @evidence contracts/development/common.md#meaningful-documentation Prose distinguishes logical component count from physical bytes and names the column-alignment cases.
|
|
11
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Fixed shape lookup and at most three padding branches require constant time without reading elements.
|
|
12
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work All accessor consumers reuse equivalent storage sizing from the same two fixed vocabulary tables.
|
|
13
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The function owns no arrays, byte views or retained state and returns one scalar size.
|
|
14
|
+
*/
|
|
15
|
+
export const accessorElementByteLength: (
|
|
16
|
+
componentType: number,
|
|
17
|
+
shape: string,
|
|
18
|
+
) => number = (componentType: number, shape: string): number => {
|
|
19
|
+
const component: number = COMPONENT_BYTES.get(componentType)!;
|
|
20
|
+
if (shape === "MAT2" && component === 1) return 8;
|
|
21
|
+
if (shape === "MAT3" && component === 1) return 12;
|
|
22
|
+
if (shape === "MAT3" && component === 2) return 24;
|
|
23
|
+
return component * SHAPE_COMPONENTS[shape]!;
|
|
24
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { COMPONENT_BYTES } from "./COMPONENT_BYTES";
|
|
2
|
+
import type { IAccessorSource } from "./IAccessorSource";
|
|
3
|
+
import type { IExternalModelAccessorReader } from "./IExternalModelAccessorReader";
|
|
4
|
+
import { accessorElementByteLength } from "./accessorElementByteLength";
|
|
5
|
+
import { object } from "./object";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Resolve one admitted accessor's resident component reader.
|
|
9
|
+
*
|
|
10
|
+
* The caller has already checked buffer indices, dense ranges and vector/scalar layout. Sparse storage and formats other than unsigned byte, unsigned short or FLOAT throw with the supplied role. Element and component indices are caller-owned bounds; the closure borrows the payload and decodes little-endian components, scaling normalized integers by 255 or 65535.
|
|
11
|
+
*
|
|
12
|
+
* @evidence contracts/development/implementation.md#principled-implementation Validated offsets/stride and unsigned byte/short or FLOAT formats define little-endian reads; normalized integers scale by their exact maximum.
|
|
13
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One closure owns DataView and addressing, shared by weight coverage and motion FLOAT decoding.
|
|
14
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Sparse overrides and unsupported component formats throw instead of being treated as dense data of another type.
|
|
15
|
+
* @evidence contracts/development/common.md#meaningful-documentation Comments give admitted formats, normalized scaling, element/component arguments and borrowed payload lifetime.
|
|
16
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Reader setup is constant time; each requested component costs one address calculation and one scalar DataView read.
|
|
17
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work One resolved view/stride/DataView serves every component of this accessor, avoiding repeated metadata resolution.
|
|
18
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The returned closure borrows one payload until its owning profile finishes; it retains no global reader cache or handle.
|
|
19
|
+
*/
|
|
20
|
+
export const accessorReader: (
|
|
21
|
+
source: IAccessorSource,
|
|
22
|
+
accessorIndex: number,
|
|
23
|
+
role: string,
|
|
24
|
+
) => IExternalModelAccessorReader = (
|
|
25
|
+
source: IAccessorSource,
|
|
26
|
+
accessorIndex: number,
|
|
27
|
+
role: string,
|
|
28
|
+
): IExternalModelAccessorReader => {
|
|
29
|
+
const accessor: Record<string, unknown> = object(
|
|
30
|
+
source.accessors[accessorIndex],
|
|
31
|
+
`accessors[${accessorIndex}]`,
|
|
32
|
+
);
|
|
33
|
+
if (accessor.sparse !== undefined)
|
|
34
|
+
throw new Error(
|
|
35
|
+
`${role} may not use sparse overrides at the production ingest boundary.`,
|
|
36
|
+
);
|
|
37
|
+
const viewIndex: number = accessor.bufferView as number;
|
|
38
|
+
const bufferView: Record<string, unknown> = object(
|
|
39
|
+
source.bufferViews[viewIndex],
|
|
40
|
+
`bufferViews[${viewIndex}]`,
|
|
41
|
+
);
|
|
42
|
+
const type: number = accessor.componentType as number;
|
|
43
|
+
if (type !== 5121 && type !== 5123 && type !== 5126)
|
|
44
|
+
throw new Error(
|
|
45
|
+
`${role} uses componentType ${type}, which this profile does not read.`,
|
|
46
|
+
);
|
|
47
|
+
const size: number = COMPONENT_BYTES.get(type)!;
|
|
48
|
+
const stride: number =
|
|
49
|
+
(bufferView.byteStride as number | undefined) ??
|
|
50
|
+
accessorElementByteLength(type, accessor.type as string);
|
|
51
|
+
const base: number =
|
|
52
|
+
((bufferView.byteOffset as number | undefined) ?? 0) +
|
|
53
|
+
((accessor.byteOffset as number | undefined) ?? 0);
|
|
54
|
+
const bytes: Uint8Array = source.payloads[bufferView.buffer as number]!;
|
|
55
|
+
const data: DataView = new DataView(
|
|
56
|
+
bytes.buffer,
|
|
57
|
+
bytes.byteOffset,
|
|
58
|
+
bytes.byteLength,
|
|
59
|
+
);
|
|
60
|
+
const scale: number =
|
|
61
|
+
accessor.normalized === true && type !== 5126
|
|
62
|
+
? type === 5121
|
|
63
|
+
? 1 / 255
|
|
64
|
+
: 1 / 65535
|
|
65
|
+
: 1;
|
|
66
|
+
return (element: number, component: number): number => {
|
|
67
|
+
const offset: number = base + element * stride + component * size;
|
|
68
|
+
const value: number =
|
|
69
|
+
type === 5121
|
|
70
|
+
? data.getUint8(offset)
|
|
71
|
+
: type === 5123
|
|
72
|
+
? data.getUint16(offset, true)
|
|
73
|
+
: data.getFloat32(offset, true);
|
|
74
|
+
return scale === 1 ? value : value * scale;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Accessor } from "@gltf-transform/core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read a parsed glTF accessor as plain numbers in the values it means.
|
|
5
|
+
*
|
|
6
|
+
* A normalized integer accessor stores `round(value * max)`, which glTF allows for animation outputs (rotation and weights) and, under `KHR_mesh_quantization`, for positions and morph deltas. Copying its raw array would hand consumers 32767 where the file means 1, so such an accessor is decoded element by element through `Accessor.getElement`, which applies glTF's decoding (`max(c / max, -1)` for signed and `c / max` for unsigned components). Every other accessor, including non-normalized quantized integers whose scale lives in the node transform, is copied verbatim.
|
|
7
|
+
*
|
|
8
|
+
* @param accessor Accessor whose data is resident in the parsed document.
|
|
9
|
+
* @returns A new flat array in element order, or `null` when the accessor holds no array data; the caller supplies a valid accessor layout.
|
|
10
|
+
*
|
|
11
|
+
* @evidence contracts/development/implementation.md#principled-implementation glTF defines normalized integer decoding per component type, and `Accessor.getElement` applies exactly that, so the helper delegates normalized accessors to it and copies any other accessor verbatim with `Array.from`.
|
|
12
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One helper serves node animation import and face template import, the two places that copy accessor data into plain number arrays.
|
|
13
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Non-normalized quantized integers are deliberately copied raw because their scale lives in the node transform, and no component type is special-cased beyond glTF's own normalization flag.
|
|
14
|
+
* @evidence contracts/development/common.md#meaningful-documentation The documentation states which accessors glTF lets be normalized, the decoding formulas, the raw-copy case and its reason, the result layout, and what `null` means.
|
|
15
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Linear in count times element size, with one plain-number result array and one reused element buffer for normalized data; Array.from copies the resident typed array into plain numbers for the non-normalized path.
|
|
16
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Each call creates an independent array; shared animation samplers are deliberately read again per track, and mutable Document data prevents a retained cache without a caller-owned invalidation contract.
|
|
17
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The element buffer is released on return; the result array, proportional to the accessor's component count, is owned by the caller and nothing is retained by the helper.
|
|
18
|
+
*/
|
|
19
|
+
export const accessorValues: (accessor: Accessor) => number[] | null = (
|
|
20
|
+
accessor: Accessor,
|
|
21
|
+
): number[] | null => {
|
|
22
|
+
const array: ReturnType<Accessor["getArray"]> = accessor.getArray();
|
|
23
|
+
if (array === null) return null;
|
|
24
|
+
if (accessor.getNormalized() === false) return Array.from(array);
|
|
25
|
+
const width: number = accessor.getElementSize();
|
|
26
|
+
const count: number = accessor.getCount();
|
|
27
|
+
const values: number[] = new Array<number>(count * width);
|
|
28
|
+
const element: number[] = new Array<number>(width);
|
|
29
|
+
for (let index: number = 0; index < count; ++index) {
|
|
30
|
+
accessor.getElement(index, element);
|
|
31
|
+
for (let component: number = 0; component < width; ++component)
|
|
32
|
+
values[index * width + component] = element[component]!;
|
|
33
|
+
}
|
|
34
|
+
return values;
|
|
35
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { IAutoMovieExternalModelResource } from "../IAutoMovieExternalModelResource";
|
|
2
|
+
import { compareCodeUnits } from "./compareCodeUnits";
|
|
3
|
+
import { object } from "./object";
|
|
4
|
+
|
|
5
|
+
const externalUri: (value: unknown, path: string) => string | null = (
|
|
6
|
+
value: unknown,
|
|
7
|
+
path: string,
|
|
8
|
+
): string | null => {
|
|
9
|
+
if (value === undefined) return null;
|
|
10
|
+
if (typeof value !== "string" || value.length === 0)
|
|
11
|
+
throw new Error(`${path} must be a non-empty URI string.`);
|
|
12
|
+
return value.startsWith("data:") ? null : value;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Collect exact sidecar URI identities without decoding their payloads.
|
|
17
|
+
*
|
|
18
|
+
* @evidence contracts/development/implementation.md#principled-implementation Buffers preserve declared byte lengths; images carry null lengths, while repeated URIs must agree on role and buffer extent.
|
|
19
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One URI-keyed map owns conflict detection and deterministic resource ordering shared by every ingest profile.
|
|
20
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Data URIs are excluded, conflicting roles/lengths throw, and URI spelling is preserved rather than normalized into aliases.
|
|
21
|
+
* @evidence contracts/development/common.md#meaningful-documentation Prose identifies exact URI ownership, buffer/image length meaning, conflict behavior and code-unit ordering.
|
|
22
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms B buffers and I images cause B+I expected map operations over exact URI strings; U distinct resources require O(U log U) comparisons, each scanning at most the compared shared prefix, with string identity/hash work dependent on URI text.
|
|
23
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work One map coordinates exact URI conflict checks and the final unique inventory; repeated declarations replace their scalar row, while byte resolution remains a separate effectful payload owner.
|
|
24
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Only U scalar resource records survive in the result; the temporary map retains no resident sidecar bytes.
|
|
25
|
+
*/
|
|
26
|
+
export const collectExternalResources: (
|
|
27
|
+
buffers: unknown[],
|
|
28
|
+
images: unknown[],
|
|
29
|
+
) => IAutoMovieExternalModelResource[] = (
|
|
30
|
+
buffers: unknown[],
|
|
31
|
+
images: unknown[],
|
|
32
|
+
): IAutoMovieExternalModelResource[] => {
|
|
33
|
+
const byUri: Map<string, IAutoMovieExternalModelResource> = new Map<
|
|
34
|
+
string,
|
|
35
|
+
IAutoMovieExternalModelResource
|
|
36
|
+
>();
|
|
37
|
+
buffers.forEach((value: unknown, index: number): void => {
|
|
38
|
+
const buffer: Record<string, unknown> = object(value, `buffers[${index}]`);
|
|
39
|
+
const uri: string | null = externalUri(buffer.uri, `buffers[${index}].uri`);
|
|
40
|
+
if (uri === null) return;
|
|
41
|
+
const byteLength: number = buffer.byteLength as number;
|
|
42
|
+
const prior: IAutoMovieExternalModelResource | undefined = byUri.get(uri);
|
|
43
|
+
if (
|
|
44
|
+
prior !== undefined &&
|
|
45
|
+
(prior.kind !== "buffer" || prior.byteLength !== byteLength)
|
|
46
|
+
)
|
|
47
|
+
throw new Error(
|
|
48
|
+
`External URI "${uri}" is declared with conflicting resource roles or lengths.`,
|
|
49
|
+
);
|
|
50
|
+
byUri.set(uri, { uri, kind: "buffer", byteLength });
|
|
51
|
+
});
|
|
52
|
+
images.forEach((value: unknown, index: number): void => {
|
|
53
|
+
const image: Record<string, unknown> = object(value, `images[${index}]`);
|
|
54
|
+
const uri: string | null = externalUri(image.uri, `images[${index}].uri`);
|
|
55
|
+
if (uri === null) return;
|
|
56
|
+
const prior: IAutoMovieExternalModelResource | undefined = byUri.get(uri);
|
|
57
|
+
if (prior !== undefined && prior.kind !== "image")
|
|
58
|
+
throw new Error(
|
|
59
|
+
`External URI "${uri}" is declared as both a buffer and an image.`,
|
|
60
|
+
);
|
|
61
|
+
byUri.set(uri, { uri, kind: "image", byteLength: null });
|
|
62
|
+
});
|
|
63
|
+
return [...byUri.values()].sort(
|
|
64
|
+
(
|
|
65
|
+
left: IAutoMovieExternalModelResource,
|
|
66
|
+
right: IAutoMovieExternalModelResource,
|
|
67
|
+
): number => compareCodeUnits(left.uri, right.uri),
|
|
68
|
+
);
|
|
69
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compare two exact strings in deterministic JavaScript code-unit order.
|
|
3
|
+
*
|
|
4
|
+
* @evidence contracts/development/implementation.md#principled-implementation Relational string comparison produces negative, zero or positive ordering without locale-dependent collation.
|
|
5
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One shared comparator serves canonical resource, extension and semantic-mapping inventories.
|
|
6
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No locale, case folding or numeric-suffix convention changes identifier identity.
|
|
7
|
+
* @evidence contracts/development/common.md#meaningful-documentation The description defines exact code-unit order and equality semantics for canonical sorting.
|
|
8
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Comparison scans at most the shared prefix length with constant extra space.
|
|
9
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work All ingest inventory sorts reuse the same ordering rule rather than different locale comparators.
|
|
10
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The comparator allocates no retained arrays, collation handles or comparison cache.
|
|
11
|
+
*/
|
|
12
|
+
export const compareCodeUnits: (left: string, right: string) => number = (
|
|
13
|
+
left: string,
|
|
14
|
+
right: string,
|
|
15
|
+
): number => Number(left > right) - Number(left < right);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { IAutoMovieTransform } from "@automovie/interface";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compose a parent-local TRS over a child-local TRS into one local transform.
|
|
5
|
+
*
|
|
6
|
+
* Folding a skipped helper node into the bone beneath it needs this, so the emitted rest stays relative to the nearest kept ancestor. The result is the standard rig decomposition `t = t_p + R_p (s_p * t_c)`, `r = r_p r_c`, `s = s_p * s_c` with component-wise scale products. With unit quaternions, translation follows affine composition and rotation and scale match its TRS representation when the parent scale commutes with the child rotation, as a uniform parent scale or an identity child rotation does. Otherwise the product contains shear that this TRS representation drops. Floating-point rounding remains, and a non-unit parent quaternion invalidates the rotation formula rather than applying a uniform scale.
|
|
7
|
+
*
|
|
8
|
+
* The arithmetic order is fixed, so the same inputs produce bit-identical output, which lets an external-motion source rig be compared with exact equality against the inspected basis.
|
|
9
|
+
*
|
|
10
|
+
* @param parent Transform of the node nearer the root.
|
|
11
|
+
* @param child Transform expressed in `parent`'s space.
|
|
12
|
+
* @returns A new transform expressing `child` in the space `parent` lives in.
|
|
13
|
+
*
|
|
14
|
+
* @evidence contracts/development/implementation.md#principled-implementation Translation applies parent scale, unit-quaternion rotation through `v + w t + q x t` with `t = 2 q x v`, then offset; rotation uses the Hamilton product and scale is component-wise. In real arithmetic this represents the affine product when parent scale commutes with child rotation; binary64 rounding remains, and other products discard shear.
|
|
15
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Humanoid import and motion adoption share one composition function, with callers responsible for the unit-quaternion premise.
|
|
16
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The fixed scalar arithmetic permits exact recomputation of an inspected basis within this pipeline; it neither normalizes quaternions nor repairs shear or non-finite inputs.
|
|
17
|
+
* @evidence contracts/development/common.md#meaningful-documentation The documentation states why helpers are folded, the formula, when it is exact and what it drops, the unit-rotation premise, and that fixed arithmetic order makes exact comparison reproducible.
|
|
18
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Fixed scalar arithmetic allocates one transform with three component records and no intermediate vectors, independent of rig size.
|
|
19
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work A constant-time pure function has nothing worth caching; callers fold each helper once per bone.
|
|
20
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources The function retains nothing; its single result object belongs to the caller.
|
|
21
|
+
*/
|
|
22
|
+
export const composeLocalTransform: (
|
|
23
|
+
parent: IAutoMovieTransform,
|
|
24
|
+
child: IAutoMovieTransform,
|
|
25
|
+
) => IAutoMovieTransform = (
|
|
26
|
+
parent: IAutoMovieTransform,
|
|
27
|
+
child: IAutoMovieTransform,
|
|
28
|
+
): IAutoMovieTransform => {
|
|
29
|
+
const q: IAutoMovieTransform["rotation"] = parent.rotation;
|
|
30
|
+
const vx: number = parent.scale.x * child.translation.x;
|
|
31
|
+
const vy: number = parent.scale.y * child.translation.y;
|
|
32
|
+
const vz: number = parent.scale.z * child.translation.z;
|
|
33
|
+
// v' = v + w t + q x t with t = 2 (q x v), the unit-quaternion rotation.
|
|
34
|
+
const tx: number = 2 * (q.y * vz - q.z * vy);
|
|
35
|
+
const ty: number = 2 * (q.z * vx - q.x * vz);
|
|
36
|
+
const tz: number = 2 * (q.x * vy - q.y * vx);
|
|
37
|
+
const r: IAutoMovieTransform["rotation"] = child.rotation;
|
|
38
|
+
return {
|
|
39
|
+
translation: {
|
|
40
|
+
x: parent.translation.x + (vx + q.w * tx + (q.y * tz - q.z * ty)),
|
|
41
|
+
y: parent.translation.y + (vy + q.w * ty + (q.z * tx - q.x * tz)),
|
|
42
|
+
z: parent.translation.z + (vz + q.w * tz + (q.x * ty - q.y * tx)),
|
|
43
|
+
},
|
|
44
|
+
rotation: {
|
|
45
|
+
x: q.w * r.x + q.x * r.w + q.y * r.z - q.z * r.y,
|
|
46
|
+
y: q.w * r.y - q.x * r.z + q.y * r.w + q.z * r.x,
|
|
47
|
+
z: q.w * r.z + q.x * r.y - q.y * r.x + q.z * r.w,
|
|
48
|
+
w: q.w * r.w - q.x * r.x - q.y * r.y - q.z * r.z,
|
|
49
|
+
},
|
|
50
|
+
scale: {
|
|
51
|
+
x: parent.scale.x * child.scale.x,
|
|
52
|
+
y: parent.scale.y * child.scale.y,
|
|
53
|
+
z: parent.scale.z * child.scale.z,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode an RFC 2397 data URI into exact payload octets.
|
|
3
|
+
*
|
|
4
|
+
* Canonical base64 spelling includes zero unused padding bits under RFC 4648 section 3.5 (https://www.rfc-editor.org/rfc/rfc4648.html#section-3.5); complete percent-octet escapes determine bytes, and literal Unicode chunks are encoded as UTF-8.
|
|
5
|
+
*
|
|
6
|
+
* @evidence contracts/development/implementation.md#principled-implementation Base64 terminal sextets have four zero low bits before two padding characters or two zero low bits before one; the terminal alphabet subsets encode those RFC 4648 canonical conditions. Complete percent-octet escapes and UTF-8 literal chunks define the other payload lane.
|
|
7
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One decoder owns both data-URI payload lanes shared by buffer and image closure.
|
|
8
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Malformed base64 and incomplete escapes throw with the field path instead of permissive byte repair.
|
|
9
|
+
* @evidence contracts/development/common.md#meaningful-documentation Prose explains metadata/base64 selection, percent octets, Unicode literals and caller-owned output.
|
|
10
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Metadata and payload text drive O(N) work over URI length; percent chunks plus final concatenation retain O(N) temporary bytes, while base64 also creates an intermediate binary string.
|
|
11
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Each declared data URI is decoded during its own payload admission; resolver effects and mutable sources are not cached.
|
|
12
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Decoded arrays transfer to the inspector's call-local payload owner; chunk arrays and encoded literals die on return.
|
|
13
|
+
*/
|
|
14
|
+
export const decodeDataUri: (uri: string, path: string) => Uint8Array = (
|
|
15
|
+
uri: string,
|
|
16
|
+
path: string,
|
|
17
|
+
): Uint8Array => {
|
|
18
|
+
const comma: number = uri.indexOf(",");
|
|
19
|
+
if (comma < 5) throw new Error(`${path} is not a complete data URI.`);
|
|
20
|
+
const metadata: string = uri.slice(5, comma);
|
|
21
|
+
const payload: string = uri.slice(comma + 1);
|
|
22
|
+
try {
|
|
23
|
+
if (metadata.split(";").includes("base64")) {
|
|
24
|
+
if (
|
|
25
|
+
payload.length % 4 !== 0 ||
|
|
26
|
+
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/][AQgw]==|[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=)?$/u.test(
|
|
27
|
+
payload,
|
|
28
|
+
) === false
|
|
29
|
+
)
|
|
30
|
+
throw new Error("base64 payload is not canonical");
|
|
31
|
+
const binary: string = atob(payload);
|
|
32
|
+
const bytes: Uint8Array = new Uint8Array(binary.length);
|
|
33
|
+
for (let index: number = 0; index < binary.length; ++index)
|
|
34
|
+
bytes[index] = binary.charCodeAt(index);
|
|
35
|
+
return bytes;
|
|
36
|
+
}
|
|
37
|
+
const encoder: InstanceType<typeof TextEncoder> = new TextEncoder();
|
|
38
|
+
const chunks: Uint8Array[] = [];
|
|
39
|
+
let literal: number = 0;
|
|
40
|
+
for (let index: number = 0; index < payload.length; ++index) {
|
|
41
|
+
if (payload.charCodeAt(index) !== 0x25) continue;
|
|
42
|
+
const hex: string = payload.slice(index + 1, index + 3);
|
|
43
|
+
if (/^[0-9A-Fa-f]{2}$/u.test(hex) === false)
|
|
44
|
+
throw new Error("percent escape is incomplete");
|
|
45
|
+
chunks.push(
|
|
46
|
+
encoder.encode(payload.slice(literal, index)),
|
|
47
|
+
Uint8Array.of(Number.parseInt(hex, 16)),
|
|
48
|
+
);
|
|
49
|
+
index += 2;
|
|
50
|
+
literal = index + 1;
|
|
51
|
+
}
|
|
52
|
+
chunks.push(encoder.encode(payload.slice(literal)));
|
|
53
|
+
const output: Uint8Array = new Uint8Array(
|
|
54
|
+
chunks.reduce(
|
|
55
|
+
(total: number, chunk: Uint8Array): number => total + chunk.byteLength,
|
|
56
|
+
0,
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
let offset: number = 0;
|
|
60
|
+
for (const chunk of chunks) {
|
|
61
|
+
output.set(chunk, offset);
|
|
62
|
+
offset += chunk.byteLength;
|
|
63
|
+
}
|
|
64
|
+
return output;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`${path} has an invalid data payload: ${(error as Error).message}.`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { IParsedContainer } from "./IParsedContainer";
|
|
2
|
+
import { decodeJson } from "./decodeJson";
|
|
3
|
+
|
|
4
|
+
const GLB_MAGIC: number = 0x46546c67;
|
|
5
|
+
|
|
6
|
+
const GLB_JSON_CHUNK: number = 0x4e4f534a;
|
|
7
|
+
|
|
8
|
+
const GLB_BIN_CHUNK: number = 0x004e4942;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Decode one GLB 2.0 container's mandatory JSON and optional BIN chunk.
|
|
12
|
+
*
|
|
13
|
+
* @evidence contracts/development/implementation.md#principled-implementation Magic, version, exact length, four-byte chunk alignment and JSON-first ordering establish the container; BIN remains a read-only input view.
|
|
14
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Container framing belongs here while strict JSON and duplicate-member checks belong to the shared JSON decoder.
|
|
15
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Unexpected or repeated trailing chunks and invalid extents throw rather than truncating or guessing a payload.
|
|
16
|
+
* @evidence contracts/development/common.md#meaningful-documentation Comments give version/alignment rules, optional BIN aliasing and suffix-provided VRM container identity.
|
|
17
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Header/chunk scanning is O(chunk count); JSON decoding is O(JSON bytes), and BIN bytes are not copied.
|
|
18
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work The same decoded JSON owner serves both GLB and plain glTF; one BIN view is reused by downstream payload readers.
|
|
19
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The parsed result borrows BIN bytes only during synchronous inspection; JSON objects and view references are call-local.
|
|
20
|
+
*/
|
|
21
|
+
export const decodeGlb: (
|
|
22
|
+
bytes: Uint8Array,
|
|
23
|
+
vrmExtension: boolean,
|
|
24
|
+
) => IParsedContainer = (
|
|
25
|
+
bytes: Uint8Array,
|
|
26
|
+
vrmExtension: boolean,
|
|
27
|
+
): IParsedContainer => {
|
|
28
|
+
if (bytes.byteLength < 20)
|
|
29
|
+
throw new Error("GLB/VRM container is shorter than its mandatory header.");
|
|
30
|
+
const view: DataView = new DataView(
|
|
31
|
+
bytes.buffer,
|
|
32
|
+
bytes.byteOffset,
|
|
33
|
+
bytes.byteLength,
|
|
34
|
+
);
|
|
35
|
+
if (view.getUint32(0, true) !== GLB_MAGIC)
|
|
36
|
+
throw new Error("GLB/VRM container has an invalid magic value.");
|
|
37
|
+
if (view.getUint32(4, true) !== 2)
|
|
38
|
+
throw new Error("Only GLB container version 2 is supported.");
|
|
39
|
+
if (view.getUint32(8, true) !== bytes.byteLength)
|
|
40
|
+
throw new Error("GLB declared length does not match resident bytes.");
|
|
41
|
+
const jsonLength: number = view.getUint32(12, true);
|
|
42
|
+
if (
|
|
43
|
+
jsonLength === 0 ||
|
|
44
|
+
jsonLength % 4 !== 0 ||
|
|
45
|
+
view.getUint32(16, true) !== GLB_JSON_CHUNK ||
|
|
46
|
+
20 + jsonLength > bytes.byteLength
|
|
47
|
+
)
|
|
48
|
+
throw new Error("GLB first chunk is not one aligned JSON chunk.");
|
|
49
|
+
let cursor: number = 20 + jsonLength;
|
|
50
|
+
let bin: Uint8Array | null = null;
|
|
51
|
+
while (cursor < bytes.byteLength) {
|
|
52
|
+
if (cursor + 8 > bytes.byteLength)
|
|
53
|
+
throw new Error("GLB contains a truncated chunk header.");
|
|
54
|
+
const length: number = view.getUint32(cursor, true);
|
|
55
|
+
if (length % 4 !== 0 || cursor + 8 + length > bytes.byteLength)
|
|
56
|
+
throw new Error("GLB contains an unaligned or truncated chunk.");
|
|
57
|
+
const type: number = view.getUint32(cursor + 4, true);
|
|
58
|
+
if (type !== GLB_BIN_CHUNK || bin !== null)
|
|
59
|
+
throw new Error(
|
|
60
|
+
"GLB may contain only one optional BIN chunk after its JSON chunk.",
|
|
61
|
+
);
|
|
62
|
+
bin = bytes.subarray(cursor + 8, cursor + 8 + length);
|
|
63
|
+
cursor += 8 + length;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
json: decodeJson(bytes.subarray(20, 20 + jsonLength)),
|
|
67
|
+
format: vrmExtension ? "vrm" : "glb",
|
|
68
|
+
bin,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode strict UTF-8 JSON and refuse duplicate decoded member names.
|
|
3
|
+
*
|
|
4
|
+
* @evidence contracts/development/implementation.md#principled-implementation JSON.parse admits syntax before an iterative container/name scan rejects escaped-equivalent duplicates without recursion depth limits.
|
|
5
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure UTF-8, syntax and duplicate-member admission form one byte ingress shared by glTF and GLB.
|
|
6
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Last-wins duplicate keys cannot hide a competing loader interpretation, and invalid UTF-8 is not repaired.
|
|
7
|
+
* @evidence contracts/development/common.md#meaningful-documentation Prose names strict decoding, escape-equivalent duplication, iterative depth behavior and diagnostic wrapping.
|
|
8
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Text length drives O(N) parsing and duplicate scan; object name sets and scope stack scale with input members and depth.
|
|
9
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Syntax is parsed once and reused by the duplicate scan's valid-text premise; escaped names alone require local JSON string decoding.
|
|
10
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Text, scope stack and key sets are temporary; only the caller-owned parsed JSON tree survives return.
|
|
11
|
+
*/
|
|
12
|
+
export const decodeJson: (bytes: Uint8Array) => unknown = (
|
|
13
|
+
bytes: Uint8Array,
|
|
14
|
+
): unknown => {
|
|
15
|
+
try {
|
|
16
|
+
const text: string = new TextDecoder("utf-8", { fatal: true }).decode(
|
|
17
|
+
bytes,
|
|
18
|
+
);
|
|
19
|
+
const value: unknown = JSON.parse(text);
|
|
20
|
+
assertUniqueJsonObjectMembers(text);
|
|
21
|
+
return value;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`External model JSON is invalid: ${(error as Error).message}.`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Refuse decoded-equivalent member names before last-wins JSON can hide one.
|
|
31
|
+
*
|
|
32
|
+
* The scan runs only over text `JSON.parse` has already accepted, so it needs no syntax checks: one pass keeps a stack of open containers, with a name set for each object, and treats the string after `{` or after `,` inside an object as a member name. A name containing an escape is decoded through `JSON.parse`, so an escaped spelling collides with its plain spelling. The stack replaces recursion, so nesting depth never becomes call-stack depth. It lives here rather than reusing the production package's structured JSON ingress because production sits above ingest in the dependency graph; importing its ingress would reverse that package dependency.
|
|
33
|
+
*/
|
|
34
|
+
const assertUniqueJsonObjectMembers: (text: string) => void = (
|
|
35
|
+
text: string,
|
|
36
|
+
): void => {
|
|
37
|
+
const scopes: Array<Set<string> | null> = [];
|
|
38
|
+
let expectName: boolean = false;
|
|
39
|
+
let cursor: number = 0;
|
|
40
|
+
while (cursor < text.length) {
|
|
41
|
+
const code: number = text.charCodeAt(cursor);
|
|
42
|
+
if (code === 0x22) {
|
|
43
|
+
const start: number = cursor;
|
|
44
|
+
let escaped: boolean = false;
|
|
45
|
+
++cursor;
|
|
46
|
+
while (text.charCodeAt(cursor) !== 0x22) {
|
|
47
|
+
if (text.charCodeAt(cursor) === 0x5c) {
|
|
48
|
+
escaped = true;
|
|
49
|
+
++cursor;
|
|
50
|
+
}
|
|
51
|
+
++cursor;
|
|
52
|
+
}
|
|
53
|
+
++cursor;
|
|
54
|
+
if (expectName) {
|
|
55
|
+
const name: string = escaped
|
|
56
|
+
? (JSON.parse(text.slice(start, cursor)) as string)
|
|
57
|
+
: text.slice(start + 1, cursor - 1);
|
|
58
|
+
const names: Set<string> = scopes[scopes.length - 1]!;
|
|
59
|
+
if (names.has(name))
|
|
60
|
+
throw new Error(`duplicate member ${JSON.stringify(name)}`);
|
|
61
|
+
names.add(name);
|
|
62
|
+
expectName = false;
|
|
63
|
+
}
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (code === 0x7b) {
|
|
67
|
+
scopes.push(new Set<string>());
|
|
68
|
+
expectName = true;
|
|
69
|
+
} else if (code === 0x5b) scopes.push(null);
|
|
70
|
+
else if (code === 0x7d || code === 0x5d) {
|
|
71
|
+
scopes.pop();
|
|
72
|
+
expectName = false;
|
|
73
|
+
} else if (code === 0x2c) expectName = scopes[scopes.length - 1] !== null;
|
|
74
|
+
++cursor;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the case-insensitive suffix of the final project-relative path component.
|
|
3
|
+
*
|
|
4
|
+
* @evidence contracts/development/implementation.md#principled-implementation The last forward slash selects the contract's project-path basename and the last dot selects its extension.
|
|
5
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Suffix interpretation stays separate from container decoding and profile selection.
|
|
6
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No suffix is inferred from byte content and a basename without a dot stays extensionless.
|
|
7
|
+
* @evidence contracts/development/common.md#meaningful-documentation Documentation identifies project-relative slash convention, case folding and the empty-suffix result.
|
|
8
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Two last-index searches and one suffix lowercase copy cost O(path length) without filesystem access.
|
|
9
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Each inspection derives its suffix once before selecting the container parser.
|
|
10
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Only temporary substrings are allocated; paths, file handles and container bytes are not retained.
|
|
11
|
+
*/
|
|
12
|
+
export const fileExtension: (value: string) => string = (
|
|
13
|
+
value: string,
|
|
14
|
+
): string => {
|
|
15
|
+
const name: string = value.slice(value.lastIndexOf("/") + 1);
|
|
16
|
+
const index: number = name.lastIndexOf(".");
|
|
17
|
+
return index < 0 ? "" : name.slice(index).toLowerCase();
|
|
18
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a finite numeric tuple with a glTF default when omitted.
|
|
3
|
+
*
|
|
4
|
+
* Undefined copies the caller's fallback without validating it; motion-node callers supply finite three- or four-component glTF defaults. Present arrays must have the same length and finite numeric entries, or throw with the field/index path. Both branches return a fresh array.
|
|
5
|
+
*
|
|
6
|
+
* @evidence contracts/development/implementation.md#principled-implementation Undefined copies the fixed fallback; supplied arrays must match its length and contain only finite numbers.
|
|
7
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure The tuple gate owns numeric/arity admission while motion-node interpretation chooses translation, scale and quaternion defaults.
|
|
8
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Wrong lengths and nonfinite values throw; supplied tuples are not normalized or padded to hide defects.
|
|
9
|
+
* @evidence contracts/development/common.md#meaningful-documentation Comments identify omission, caller-owned copied output and indexed finite-value errors.
|
|
10
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Tuple length K drives O(K) time and result space; current callers use only three or four components.
|
|
11
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work The same tuple admission serves translation, rotation and scale without cross-call caching of mutable inputs.
|
|
12
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The returned K-number array belongs to its caller and retains no reference to the source or fallback array.
|
|
13
|
+
*/
|
|
14
|
+
export const finiteTuple: (
|
|
15
|
+
value: unknown,
|
|
16
|
+
path: string,
|
|
17
|
+
fallback: readonly number[],
|
|
18
|
+
) => number[] = (
|
|
19
|
+
value: unknown,
|
|
20
|
+
path: string,
|
|
21
|
+
fallback: readonly number[],
|
|
22
|
+
): number[] => {
|
|
23
|
+
if (value === undefined) return [...fallback];
|
|
24
|
+
if (Array.isArray(value) === false || value.length !== fallback.length)
|
|
25
|
+
throw new Error(
|
|
26
|
+
`${path} must contain exactly ${fallback.length} finite numbers.`,
|
|
27
|
+
);
|
|
28
|
+
return (value as unknown[]).map((entry: unknown, index: number): number => {
|
|
29
|
+
if (typeof entry !== "number" || Number.isFinite(entry) === false)
|
|
30
|
+
throw new Error(`${path}[${index}] must be finite.`);
|
|
31
|
+
return entry;
|
|
32
|
+
});
|
|
33
|
+
};
|