@automovie/ingest 0.0.0-stage → 0.1.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,48 @@
|
|
|
1
|
+
import type { AutoMovieHumanoidBone } from "@automovie/interface";
|
|
2
|
+
|
|
3
|
+
import { humanoidBoneOfName } from "../internal/humanoidBoneOfName";
|
|
4
|
+
import type { IHumanoidSlot } from "./IHumanoidSlot";
|
|
5
|
+
import { object } from "./object";
|
|
6
|
+
import { requiredArray } from "./requiredArray";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolve first-claim glTF skin joints to recognized humanoid naming slots.
|
|
10
|
+
*
|
|
11
|
+
* The caller has admitted skin joint indices. Nodes are visited in source order, eligible only when listed in a skin, with the first recognized name per slot retained; unrecognized names and later duplicate slots are ignored. Returned slots describe naming correspondence rather than anatomy or positive skin-weight coverage.
|
|
12
|
+
*
|
|
13
|
+
* @evidence contracts/development/implementation.md#principled-implementation Skin joint indices define eligible nodes and normalized aliases assign at most one source-order node per semantic slot.
|
|
14
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Skin membership and slot claiming stay here while the shared name helper owns this importer's supported naming vocabulary.
|
|
15
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Unrecognized names and repeated slots remain unmapped instead of overwriting first ownership or inferring missing anatomy.
|
|
16
|
+
* @evidence contracts/development/common.md#meaningful-documentation Comments state node-order first claim, skin-only eligibility and the distinction from actual weight coverage.
|
|
17
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Work follows skins, their joint entries, nodes and eligible node-name text, with expected constant-time membership and slot lookups.
|
|
18
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Each eligible node name is resolved once; the inspector separately shares mesh/skin weight checks.
|
|
19
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Temporary membership sets die with the call; returned slot records are bounded by the recognized humanoid vocabulary.
|
|
20
|
+
*/
|
|
21
|
+
export const gltfHumanoidBones: (
|
|
22
|
+
nodes: unknown[],
|
|
23
|
+
skins: unknown[],
|
|
24
|
+
) => IHumanoidSlot[] = (
|
|
25
|
+
nodes: unknown[],
|
|
26
|
+
skins: unknown[],
|
|
27
|
+
): IHumanoidSlot[] => {
|
|
28
|
+
const joints: Set<unknown> = new Set<unknown>(
|
|
29
|
+
skins.flatMap((value: unknown, index: number): unknown[] =>
|
|
30
|
+
requiredArray(
|
|
31
|
+
object(value, `skins[${index}]`).joints,
|
|
32
|
+
`skins[${index}].joints`,
|
|
33
|
+
),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
const used: Set<AutoMovieHumanoidBone> = new Set<AutoMovieHumanoidBone>();
|
|
37
|
+
const slots: IHumanoidSlot[] = [];
|
|
38
|
+
nodes.forEach((value: unknown, index: number): void => {
|
|
39
|
+
if (joints.has(index) === false) return;
|
|
40
|
+
const name: unknown = object(value, `nodes[${index}]`).name;
|
|
41
|
+
if (typeof name !== "string") return;
|
|
42
|
+
const bone: AutoMovieHumanoidBone | undefined = humanoidBoneOfName(name);
|
|
43
|
+
if (bone === undefined || used.has(bone)) return;
|
|
44
|
+
used.add(bone);
|
|
45
|
+
slots.push({ bone, node: index });
|
|
46
|
+
});
|
|
47
|
+
return slots;
|
|
48
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { AutoMovieHumanoidBone } from "@automovie/interface";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve an imported joint name to the humanoid slot its rig convention means.
|
|
5
|
+
*
|
|
6
|
+
* The name is lowercased, a leading `mixamorig` prefix (with or without its colon) is removed, and whitespace, `_`, `.`, `:`, `|` and `-` are dropped, so `mixamorig:LeftUpLeg`, `Left_UpLeg` and `leftUpLeg` all read as `leftupleg`. The table covers the supported Blender-style names (`Spine`, `LeftUpLeg`), Mixamo, VRM-style slot names (`leftUpperArm`), and Unreal mannequin spine chains (`spine_01` to `spine_03`). Fingers, eyes and jaw have no alias, so a hand rig maps only to its hand slot.
|
|
7
|
+
*
|
|
8
|
+
* @param name Joint node name exactly as the source declares it.
|
|
9
|
+
* @returns The slot, or `undefined` when no convention in the table names it.
|
|
10
|
+
*
|
|
11
|
+
* @evidence contracts/development/implementation.md#principled-implementation Lowercasing, removing a leading `mixamorig` prefix and dropping separator characters reduces each convention's spelling to one key, and an exact `Map` lookup resolves it, so inherited object keys can never match.
|
|
12
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure The table and the normalization live in one module that the skeleton importer and the byte inspector both call, replacing two copies that had to be kept in step.
|
|
13
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts The closed alias vocabulary is a naming convention supported by this mapper rather than an anatomical inference, and both callers keep their own first-claim rule instead of the helper guessing between duplicates.
|
|
14
|
+
* @evidence contracts/development/common.md#meaningful-documentation The documentation states the normalization steps with an example, the covered conventions, the unmapped finger, eye and jaw slots, and what `undefined` means.
|
|
15
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Cost is linear in the name length for two regular-expression passes and one lowercase copy, then one hash lookup.
|
|
16
|
+
* @evidenceExclude contracts/development/implementation.md#reuse-equivalent-work Each invocation normalizes its supplied name; a joint shared by several skins may be revisited, and this helper retains no cache over mutable source revisions.
|
|
17
|
+
* @evidenceExclude contracts/development/implementation.md#bound-retention-and-release-resources The module-level table is a fixed forty-entry constant; a call retains nothing.
|
|
18
|
+
*/
|
|
19
|
+
export const humanoidBoneOfName: (
|
|
20
|
+
name: string,
|
|
21
|
+
) => AutoMovieHumanoidBone | undefined = (
|
|
22
|
+
name: string,
|
|
23
|
+
): AutoMovieHumanoidBone | undefined =>
|
|
24
|
+
HUMANOID_ALIASES.get(
|
|
25
|
+
name
|
|
26
|
+
.toLowerCase()
|
|
27
|
+
.replace(/^mixamorig:?/u, "")
|
|
28
|
+
.replace(/[\s_.:|-]/gu, ""),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const HUMANOID_ALIASES: ReadonlyMap<string, AutoMovieHumanoidBone> = new Map<
|
|
32
|
+
string,
|
|
33
|
+
AutoMovieHumanoidBone
|
|
34
|
+
>([
|
|
35
|
+
["hips", "hips"],
|
|
36
|
+
["pelvis", "hips"],
|
|
37
|
+
["spine", "spine"],
|
|
38
|
+
["spine01", "spine"],
|
|
39
|
+
["spine1", "chest"],
|
|
40
|
+
["chest", "chest"],
|
|
41
|
+
["spine02", "chest"],
|
|
42
|
+
["spine2", "upperChest"],
|
|
43
|
+
["spine03", "upperChest"],
|
|
44
|
+
["upperchest", "upperChest"],
|
|
45
|
+
["neck", "neck"],
|
|
46
|
+
["head", "head"],
|
|
47
|
+
["leftshoulder", "leftShoulder"],
|
|
48
|
+
["leftclavicle", "leftShoulder"],
|
|
49
|
+
["leftarm", "leftUpperArm"],
|
|
50
|
+
["leftupperarm", "leftUpperArm"],
|
|
51
|
+
["leftforearm", "leftLowerArm"],
|
|
52
|
+
["leftlowerarm", "leftLowerArm"],
|
|
53
|
+
["lefthand", "leftHand"],
|
|
54
|
+
["rightshoulder", "rightShoulder"],
|
|
55
|
+
["rightclavicle", "rightShoulder"],
|
|
56
|
+
["rightarm", "rightUpperArm"],
|
|
57
|
+
["rightupperarm", "rightUpperArm"],
|
|
58
|
+
["rightforearm", "rightLowerArm"],
|
|
59
|
+
["rightlowerarm", "rightLowerArm"],
|
|
60
|
+
["righthand", "rightHand"],
|
|
61
|
+
["leftupleg", "leftUpperLeg"],
|
|
62
|
+
["leftupperleg", "leftUpperLeg"],
|
|
63
|
+
["leftleg", "leftLowerLeg"],
|
|
64
|
+
["leftlowerleg", "leftLowerLeg"],
|
|
65
|
+
["leftfoot", "leftFoot"],
|
|
66
|
+
["lefttoebase", "leftToes"],
|
|
67
|
+
["lefttoes", "leftToes"],
|
|
68
|
+
["rightupleg", "rightUpperLeg"],
|
|
69
|
+
["rightupperleg", "rightUpperLeg"],
|
|
70
|
+
["rightleg", "rightLowerLeg"],
|
|
71
|
+
["rightlowerleg", "rightLowerLeg"],
|
|
72
|
+
["rightfoot", "rightFoot"],
|
|
73
|
+
["righttoebase", "rightToes"],
|
|
74
|
+
["righttoes", "rightToes"],
|
|
75
|
+
]);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { object } from "./object";
|
|
2
|
+
import { optionalArray } from "./optionalArray";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Establish a unique-parent acyclic glTF node forest.
|
|
6
|
+
*
|
|
7
|
+
* @evidence contracts/development/implementation.md#principled-implementation Index-validated child edges fill one parent table; iterative three-state walks detect cycles and mark completed root paths.
|
|
8
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Hierarchy admission runs before profile dispatch so static, humanoid and motion consumers share one forest contract.
|
|
9
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Duplicate children, multiple parents and parent cycles throw without rewriting the graph or dropping links.
|
|
10
|
+
* @evidence contracts/development/common.md#meaningful-documentation Comments explain index-validation prerequisite, unique parent semantics and depth-safe iterative traversal.
|
|
11
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms N nodes and E child links cost O(N+E), since completed parent walks are marked and each node enters one unfinished path.
|
|
12
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work The returned parent table is reused by scene-root admission and motion-node interpretation in the same inspector call.
|
|
13
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources Parent/state/path arrays are bounded by node count; only the returned table remains with its synchronous caller.
|
|
14
|
+
*/
|
|
15
|
+
export const inspectExternalModelHierarchy: (
|
|
16
|
+
values: unknown[],
|
|
17
|
+
) => Array<number | undefined> = (
|
|
18
|
+
values: unknown[],
|
|
19
|
+
): Array<number | undefined> => {
|
|
20
|
+
const parentByIndex: Array<number | undefined> = new Array<
|
|
21
|
+
number | undefined
|
|
22
|
+
>(values.length);
|
|
23
|
+
values.forEach((value: unknown, parentIndex: number): void => {
|
|
24
|
+
const node: Record<string, unknown> = object(
|
|
25
|
+
value,
|
|
26
|
+
`nodes[${parentIndex}]`,
|
|
27
|
+
);
|
|
28
|
+
optionalArray(node.children, `nodes[${parentIndex}].children`).forEach(
|
|
29
|
+
(entry: unknown): void => {
|
|
30
|
+
const childIndex: number = entry as number;
|
|
31
|
+
const previous: number | undefined = parentByIndex[childIndex];
|
|
32
|
+
if (previous === parentIndex)
|
|
33
|
+
throw new Error(
|
|
34
|
+
`nodes[${parentIndex}].children repeats node ${childIndex}.`,
|
|
35
|
+
);
|
|
36
|
+
if (previous !== undefined)
|
|
37
|
+
throw new Error(
|
|
38
|
+
`nodes[${childIndex}] has multiple parents ${previous} and ${parentIndex}.`,
|
|
39
|
+
);
|
|
40
|
+
parentByIndex[childIndex] = parentIndex;
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// 0 = unvisited, 1 = on the current walk, 2 = proven to reach a root.
|
|
46
|
+
const state: Uint8Array = new Uint8Array(values.length);
|
|
47
|
+
for (let start: number = 0; start < values.length; ++start) {
|
|
48
|
+
if (state[start] !== 0) continue;
|
|
49
|
+
const path: number[] = [];
|
|
50
|
+
let index: number | undefined = start;
|
|
51
|
+
while (index !== undefined && state[index] === 0) {
|
|
52
|
+
state[index] = 1;
|
|
53
|
+
path.push(index);
|
|
54
|
+
index = parentByIndex[index];
|
|
55
|
+
}
|
|
56
|
+
if (index !== undefined && state[index] === 1)
|
|
57
|
+
throw new Error(`nodes[${index}] belongs to a parent cycle.`);
|
|
58
|
+
for (const entry of path) state[entry] = 2;
|
|
59
|
+
}
|
|
60
|
+
return parentByIndex;
|
|
61
|
+
};
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import type { IAutoMovieClip, IAutoMovieTrack } from "@automovie/interface";
|
|
2
|
+
|
|
3
|
+
import { AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE } from "../AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE";
|
|
4
|
+
import type { IAutoMovieExternalMotionInspection } from "../IAutoMovieExternalMotionInspection";
|
|
5
|
+
import type { IAutoMovieExternalMotionNodeInspection } from "../IAutoMovieExternalMotionNodeInspection";
|
|
6
|
+
import type { IAccessorSource } from "./IAccessorSource";
|
|
7
|
+
import { SHAPE_COMPONENTS } from "./SHAPE_COMPONENTS";
|
|
8
|
+
import { inspectExternalMotionNodes } from "./inspectExternalMotionNodes";
|
|
9
|
+
import { integerIndex } from "./integerIndex";
|
|
10
|
+
import { object } from "./object";
|
|
11
|
+
import { readMotionAccessor } from "./readMotionAccessor";
|
|
12
|
+
import { requiredArray } from "./requiredArray";
|
|
13
|
+
|
|
14
|
+
type AutoMovieMotionTargetPath =
|
|
15
|
+
| "translation"
|
|
16
|
+
| "rotation"
|
|
17
|
+
| "scale"
|
|
18
|
+
| "weights";
|
|
19
|
+
|
|
20
|
+
/** Accessor shape each target path's output must use. */
|
|
21
|
+
const MOTION_OUTPUT_TYPES: Readonly<
|
|
22
|
+
Record<AutoMovieMotionTargetPath, "SCALAR" | "VEC3" | "VEC4">
|
|
23
|
+
> = {
|
|
24
|
+
translation: "VEC3",
|
|
25
|
+
rotation: "VEC4",
|
|
26
|
+
scale: "VEC3",
|
|
27
|
+
weights: "SCALAR",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Normalize glTF animation samplers into deterministic node tracks.
|
|
32
|
+
*
|
|
33
|
+
* Empty animation inventories return undefined. Otherwise source-order clips and channel-order tracks own independent FLOAT keyframe copies, even when samplers share accessors. Times must be nonnegative and strictly increasing; output arity follows path and interpolation, with only quaternion value groups checked within 1e-4 of unit magnitude. Cubic tangents remain unchanged and weight arity is not checked against the target mesh's morph count. Missing interpolation means LINEAR; unknown interpolation, duplicate node/path channels and malformed data throw with the field path.
|
|
34
|
+
*
|
|
35
|
+
* @evidence contracts/development/implementation.md#principled-implementation Validated FLOAT accessors, strictly increasing nonnegative times, supported interpolation and target-specific arity determine copied clips.
|
|
36
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Motion normalization owns sampler/channel relationships while hierarchy, node TRS and byte readers remain separate owners.
|
|
37
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Duplicate targets and non-finite values throw; quaternion value groups outside the 1e-4 magnitude tolerance are refused, while accepted keyframes are copied without normalization. Weight counts are checked only for a nonempty whole keyframe group, not against a target mesh's morph count.
|
|
38
|
+
* @evidence contracts/development/common.md#meaningful-documentation Prose describes clip/channel ordering, exact keyframe ownership, interpolation, arity and quaternion checks.
|
|
39
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Cost follows node/channel counts and decoded/copied keyframe values; shared accessors are decoded once but each track owns a copy.
|
|
40
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Accessor index plus expected shape keys per-call decoding; immutable source/payload dependencies justify reuse and track arrays remain independent.
|
|
41
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The decode cache lives only for one inspection; returned clips retain arrays proportional to keyframe counts without raw payload bytes.
|
|
42
|
+
*/
|
|
43
|
+
export const inspectExternalMotion: (props: {
|
|
44
|
+
path: string;
|
|
45
|
+
byteLength: number;
|
|
46
|
+
animations: unknown[];
|
|
47
|
+
nodes: unknown[];
|
|
48
|
+
parentByIndex: readonly (number | undefined)[];
|
|
49
|
+
source: IAccessorSource;
|
|
50
|
+
}) => IAutoMovieExternalMotionInspection | undefined = (props: {
|
|
51
|
+
path: string;
|
|
52
|
+
byteLength: number;
|
|
53
|
+
animations: unknown[];
|
|
54
|
+
nodes: unknown[];
|
|
55
|
+
parentByIndex: readonly (number | undefined)[];
|
|
56
|
+
source: IAccessorSource;
|
|
57
|
+
}): IAutoMovieExternalMotionInspection | undefined => {
|
|
58
|
+
if (props.animations.length === 0) return undefined;
|
|
59
|
+
const nodes: IAutoMovieExternalMotionNodeInspection[] =
|
|
60
|
+
inspectExternalMotionNodes(props.nodes, props.parentByIndex);
|
|
61
|
+
const nodeIds: string[] = nodes.map(
|
|
62
|
+
(node: IAutoMovieExternalMotionNodeInspection): string => node.id,
|
|
63
|
+
);
|
|
64
|
+
// Shared accessors reuse finite FLOAT decoding; each track owns a copy and
|
|
65
|
+
// still checks its times, interpolation-specific arity and quaternion values.
|
|
66
|
+
const decoded: Map<string, number[]> = new Map<string, number[]>();
|
|
67
|
+
const readOnce: (
|
|
68
|
+
accessorIndex: number,
|
|
69
|
+
expectedType: "SCALAR" | "VEC3" | "VEC4",
|
|
70
|
+
path: string,
|
|
71
|
+
) => number[] = (
|
|
72
|
+
accessorIndex: number,
|
|
73
|
+
expectedType: "SCALAR" | "VEC3" | "VEC4",
|
|
74
|
+
path: string,
|
|
75
|
+
): number[] => {
|
|
76
|
+
const key: string = `${accessorIndex}:${expectedType}`;
|
|
77
|
+
let values: number[] | undefined = decoded.get(key);
|
|
78
|
+
if (values === undefined) {
|
|
79
|
+
values = readMotionAccessor(
|
|
80
|
+
props.source,
|
|
81
|
+
accessorIndex,
|
|
82
|
+
expectedType,
|
|
83
|
+
path,
|
|
84
|
+
);
|
|
85
|
+
decoded.set(key, values);
|
|
86
|
+
}
|
|
87
|
+
return values.slice();
|
|
88
|
+
};
|
|
89
|
+
const takes: IAutoMovieClip[] = props.animations.map(
|
|
90
|
+
(value: unknown, animationIndex: number): IAutoMovieClip => {
|
|
91
|
+
const animation: Record<string, unknown> = object(
|
|
92
|
+
value,
|
|
93
|
+
`animations[${animationIndex}]`,
|
|
94
|
+
);
|
|
95
|
+
const samplers: unknown[] = requiredArray(
|
|
96
|
+
animation.samplers,
|
|
97
|
+
`animations[${animationIndex}].samplers`,
|
|
98
|
+
);
|
|
99
|
+
const channels: unknown[] = requiredArray(
|
|
100
|
+
animation.channels,
|
|
101
|
+
`animations[${animationIndex}].channels`,
|
|
102
|
+
);
|
|
103
|
+
if (samplers.length === 0 || channels.length === 0)
|
|
104
|
+
throw new Error(
|
|
105
|
+
`animations[${animationIndex}] needs at least one sampler and channel.`,
|
|
106
|
+
);
|
|
107
|
+
const targets: Set<string> = new Set<string>();
|
|
108
|
+
const tracks: IAutoMovieTrack[] = channels.map(
|
|
109
|
+
(channelValue: unknown, channelIndex: number): IAutoMovieTrack => {
|
|
110
|
+
const channelPath: string = `animations[${animationIndex}].channels[${channelIndex}]`;
|
|
111
|
+
const channel: Record<string, unknown> = object(
|
|
112
|
+
channelValue,
|
|
113
|
+
channelPath,
|
|
114
|
+
);
|
|
115
|
+
integerIndex(
|
|
116
|
+
channel.sampler,
|
|
117
|
+
samplers.length,
|
|
118
|
+
`${channelPath}.sampler`,
|
|
119
|
+
true,
|
|
120
|
+
);
|
|
121
|
+
const target: Record<string, unknown> = object(
|
|
122
|
+
channel.target,
|
|
123
|
+
`${channelPath}.target`,
|
|
124
|
+
);
|
|
125
|
+
integerIndex(
|
|
126
|
+
target.node,
|
|
127
|
+
props.nodes.length,
|
|
128
|
+
`${channelPath}.target.node`,
|
|
129
|
+
true,
|
|
130
|
+
);
|
|
131
|
+
if (
|
|
132
|
+
typeof target.path !== "string" ||
|
|
133
|
+
Object.hasOwn(MOTION_OUTPUT_TYPES, target.path) === false
|
|
134
|
+
)
|
|
135
|
+
throw new Error(
|
|
136
|
+
`${channelPath}.target.path must be translation, rotation, scale, or weights.`,
|
|
137
|
+
);
|
|
138
|
+
const targetPath: AutoMovieMotionTargetPath =
|
|
139
|
+
target.path as AutoMovieMotionTargetPath;
|
|
140
|
+
const targetKey: string = `${String(target.node)}\u0000${targetPath}`;
|
|
141
|
+
if (targets.has(targetKey))
|
|
142
|
+
throw new Error(
|
|
143
|
+
`${channelPath} duplicates the ${targetPath} channel for node ${String(target.node)}.`,
|
|
144
|
+
);
|
|
145
|
+
targets.add(targetKey);
|
|
146
|
+
|
|
147
|
+
const samplerPath: string = `animations[${animationIndex}].samplers[${String(channel.sampler)}]`;
|
|
148
|
+
const sampler: Record<string, unknown> = object(
|
|
149
|
+
samplers[channel.sampler as number],
|
|
150
|
+
samplerPath,
|
|
151
|
+
);
|
|
152
|
+
integerIndex(
|
|
153
|
+
sampler.input,
|
|
154
|
+
props.source.accessors.length,
|
|
155
|
+
`${samplerPath}.input`,
|
|
156
|
+
true,
|
|
157
|
+
);
|
|
158
|
+
integerIndex(
|
|
159
|
+
sampler.output,
|
|
160
|
+
props.source.accessors.length,
|
|
161
|
+
`${samplerPath}.output`,
|
|
162
|
+
true,
|
|
163
|
+
);
|
|
164
|
+
const interpolation: IAutoMovieTrack["interpolation"] =
|
|
165
|
+
motionInterpolation(
|
|
166
|
+
sampler.interpolation,
|
|
167
|
+
`${samplerPath}.interpolation`,
|
|
168
|
+
);
|
|
169
|
+
const times: number[] = readOnce(
|
|
170
|
+
sampler.input as number,
|
|
171
|
+
"SCALAR",
|
|
172
|
+
`${samplerPath}.input`,
|
|
173
|
+
);
|
|
174
|
+
const values: number[] = readOnce(
|
|
175
|
+
sampler.output as number,
|
|
176
|
+
MOTION_OUTPUT_TYPES[targetPath],
|
|
177
|
+
`${samplerPath}.output`,
|
|
178
|
+
);
|
|
179
|
+
validateMotionTimes(times, `${samplerPath}.input`);
|
|
180
|
+
validateMotionOutput({
|
|
181
|
+
path: `${samplerPath}.output`,
|
|
182
|
+
targetPath,
|
|
183
|
+
interpolation,
|
|
184
|
+
keyframes: times.length,
|
|
185
|
+
values,
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
channel: {
|
|
189
|
+
kind: "node",
|
|
190
|
+
node: nodeIds[target.node as number]!,
|
|
191
|
+
path: targetPath,
|
|
192
|
+
},
|
|
193
|
+
times,
|
|
194
|
+
values,
|
|
195
|
+
interpolation,
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
);
|
|
199
|
+
const name: unknown = animation.name;
|
|
200
|
+
if (name !== undefined && typeof name !== "string")
|
|
201
|
+
throw new Error(`animations[${animationIndex}].name must be a string.`);
|
|
202
|
+
return {
|
|
203
|
+
id: `clip_${animationIndex}`,
|
|
204
|
+
name: name === undefined || name.length === 0 ? null : name,
|
|
205
|
+
duration: tracks.reduce(
|
|
206
|
+
(maximum: number, track: IAutoMovieTrack): number =>
|
|
207
|
+
Math.max(maximum, track.times[track.times.length - 1]!),
|
|
208
|
+
0,
|
|
209
|
+
),
|
|
210
|
+
loop: false,
|
|
211
|
+
tracks,
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
);
|
|
215
|
+
return {
|
|
216
|
+
path: props.path,
|
|
217
|
+
byteLength: props.byteLength,
|
|
218
|
+
interpretation: AUTOMOVIE_GLTF_MOTION_INTERPRETATION_PROFILE,
|
|
219
|
+
nodes,
|
|
220
|
+
nodeIds,
|
|
221
|
+
takes,
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const motionInterpolation: (
|
|
226
|
+
value: unknown,
|
|
227
|
+
path: string,
|
|
228
|
+
) => IAutoMovieTrack["interpolation"] = (
|
|
229
|
+
value: unknown,
|
|
230
|
+
path: string,
|
|
231
|
+
): IAutoMovieTrack["interpolation"] => {
|
|
232
|
+
if (value === undefined || value === "LINEAR") return "linear";
|
|
233
|
+
if (value === "STEP") return "step";
|
|
234
|
+
if (value === "CUBICSPLINE") return "cubicspline";
|
|
235
|
+
throw new Error(`${path} must be LINEAR, STEP, or CUBICSPLINE.`);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const validateMotionTimes: (times: number[], path: string) => void = (
|
|
239
|
+
times: number[],
|
|
240
|
+
path: string,
|
|
241
|
+
): void => {
|
|
242
|
+
for (let index: number = 0; index < times.length; ++index)
|
|
243
|
+
if (times[index]! < 0 || (index > 0 && times[index]! <= times[index - 1]!))
|
|
244
|
+
throw new Error(
|
|
245
|
+
`${path} keyframe times must be non-negative and strictly increasing.`,
|
|
246
|
+
);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const validateMotionOutput: (props: {
|
|
250
|
+
path: string;
|
|
251
|
+
targetPath: AutoMovieMotionTargetPath;
|
|
252
|
+
interpolation: IAutoMovieTrack["interpolation"];
|
|
253
|
+
keyframes: number;
|
|
254
|
+
values: number[];
|
|
255
|
+
}) => void = (props: {
|
|
256
|
+
path: string;
|
|
257
|
+
targetPath: AutoMovieMotionTargetPath;
|
|
258
|
+
interpolation: IAutoMovieTrack["interpolation"];
|
|
259
|
+
keyframes: number;
|
|
260
|
+
values: number[];
|
|
261
|
+
}): void => {
|
|
262
|
+
const factor: number = props.interpolation === "cubicspline" ? 3 : 1;
|
|
263
|
+
const width: number | null =
|
|
264
|
+
props.targetPath === "weights"
|
|
265
|
+
? null
|
|
266
|
+
: SHAPE_COMPONENTS[MOTION_OUTPUT_TYPES[props.targetPath]]!;
|
|
267
|
+
const group: number = props.keyframes * factor;
|
|
268
|
+
if (
|
|
269
|
+
group === 0 ||
|
|
270
|
+
(width === null
|
|
271
|
+
? props.values.length === 0 || props.values.length % group !== 0
|
|
272
|
+
: props.values.length !== group * width)
|
|
273
|
+
)
|
|
274
|
+
throw new Error(
|
|
275
|
+
`${props.path} does not match the ${props.targetPath} keyframe arity.`,
|
|
276
|
+
);
|
|
277
|
+
if (props.targetPath !== "rotation") return;
|
|
278
|
+
for (let frame: number = 0; frame < props.keyframes; ++frame) {
|
|
279
|
+
// A cubic-spline keyframe stores in-tangent, value, out-tangent; only the
|
|
280
|
+
// value must be a unit quaternion.
|
|
281
|
+
const at: number =
|
|
282
|
+
(props.interpolation === "cubicspline" ? frame * 3 + 1 : frame) * 4;
|
|
283
|
+
const magnitude: number = Math.hypot(
|
|
284
|
+
props.values[at]!,
|
|
285
|
+
props.values[at + 1]!,
|
|
286
|
+
props.values[at + 2]!,
|
|
287
|
+
props.values[at + 3]!,
|
|
288
|
+
);
|
|
289
|
+
if (Math.abs(magnitude - 1) > 1e-4)
|
|
290
|
+
throw new Error(`${props.path} contains a non-unit rotation keyframe.`);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { IAutoMovieExternalMotionNodeInspection } from "../IAutoMovieExternalMotionNodeInspection";
|
|
2
|
+
import { finiteTuple } from "./finiteTuple";
|
|
3
|
+
import { object } from "./object";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Read glTF motion nodes as finite canonical local TRS records.
|
|
7
|
+
*
|
|
8
|
+
* The caller supplies a validated acyclic parent table. Omitted translation, rotation and scale use glTF defaults; present tuples must be finite, scales positive and quaternion magnitude within 1e-4 of one before normalization. Matrix transforms throw instead of being decomposed. Records use source-index ids, null for absent/empty names or root parents, and fresh transform objects.
|
|
9
|
+
*
|
|
10
|
+
* @evidence contracts/development/implementation.md#principled-implementation Three/four-component tuples use glTF defaults; positive scale and unit-quaternion tolerance precede rotation normalization.
|
|
11
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Node interpretation owns stable index ids, parent ids and local transforms, separate from animation channel decoding.
|
|
12
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Matrix transforms are refused rather than decomposed; rig names do not invent skeletal semantics.
|
|
13
|
+
* @evidence contracts/development/common.md#meaningful-documentation Prose states defaults, matrix refusal, positive scale, quaternion normalization and absent name/parent meaning.
|
|
14
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms N nodes require O(N) time and output records, with fixed-size tuple work per node.
|
|
15
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work The admitted parent table is reused from structural hierarchy checks; each node transform is interpreted once per inspection.
|
|
16
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The returned node records own new fixed-size transforms; source JSON arrays and tuple temporaries are not retained.
|
|
17
|
+
*/
|
|
18
|
+
export const inspectExternalMotionNodes: (
|
|
19
|
+
values: unknown[],
|
|
20
|
+
parentByIndex: readonly (number | undefined)[],
|
|
21
|
+
) => IAutoMovieExternalMotionNodeInspection[] = (
|
|
22
|
+
values: unknown[],
|
|
23
|
+
parentByIndex: readonly (number | undefined)[],
|
|
24
|
+
): IAutoMovieExternalMotionNodeInspection[] =>
|
|
25
|
+
values.map(
|
|
26
|
+
(value: unknown, index: number): IAutoMovieExternalMotionNodeInspection => {
|
|
27
|
+
const node: Record<string, unknown> = object(value, `nodes[${index}]`);
|
|
28
|
+
if (node.matrix !== undefined)
|
|
29
|
+
throw new Error(
|
|
30
|
+
`nodes[${index}].matrix is unsupported by the glTF motion interpretation profile; declare translation, rotation, and scale explicitly.`,
|
|
31
|
+
);
|
|
32
|
+
if (node.name !== undefined && typeof node.name !== "string")
|
|
33
|
+
throw new Error(`nodes[${index}].name must be a string.`);
|
|
34
|
+
const translation: number[] = finiteTuple(
|
|
35
|
+
node.translation,
|
|
36
|
+
`nodes[${index}].translation`,
|
|
37
|
+
[0, 0, 0],
|
|
38
|
+
);
|
|
39
|
+
const rotation: number[] = finiteTuple(
|
|
40
|
+
node.rotation,
|
|
41
|
+
`nodes[${index}].rotation`,
|
|
42
|
+
[0, 0, 0, 1],
|
|
43
|
+
);
|
|
44
|
+
const scale: number[] = finiteTuple(
|
|
45
|
+
node.scale,
|
|
46
|
+
`nodes[${index}].scale`,
|
|
47
|
+
[1, 1, 1],
|
|
48
|
+
);
|
|
49
|
+
if (scale.some((component: number): boolean => component <= 0))
|
|
50
|
+
throw new Error(
|
|
51
|
+
`nodes[${index}].scale must contain only positive values.`,
|
|
52
|
+
);
|
|
53
|
+
const magnitude: number = Math.hypot(...rotation);
|
|
54
|
+
if (Math.abs(magnitude - 1) > 1e-4)
|
|
55
|
+
throw new Error(`nodes[${index}].rotation must be a unit quaternion.`);
|
|
56
|
+
const parent: number | undefined = parentByIndex[index];
|
|
57
|
+
return {
|
|
58
|
+
id: `node_${index}`,
|
|
59
|
+
index,
|
|
60
|
+
name:
|
|
61
|
+
typeof node.name === "string" && node.name.length !== 0
|
|
62
|
+
? node.name
|
|
63
|
+
: null,
|
|
64
|
+
parent: parent === undefined ? null : `node_${parent}`,
|
|
65
|
+
transform: {
|
|
66
|
+
translation: {
|
|
67
|
+
x: translation[0]!,
|
|
68
|
+
y: translation[1]!,
|
|
69
|
+
z: translation[2]!,
|
|
70
|
+
},
|
|
71
|
+
rotation: {
|
|
72
|
+
x: rotation[0]! / magnitude,
|
|
73
|
+
y: rotation[1]! / magnitude,
|
|
74
|
+
z: rotation[2]! / magnitude,
|
|
75
|
+
w: rotation[3]! / magnitude,
|
|
76
|
+
},
|
|
77
|
+
scale: { x: scale[0]!, y: scale[1]!, z: scale[2]! },
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { validNodeIndex } from "./validNodeIndex";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Admit an optional or required index into an already declared inventory.
|
|
5
|
+
*
|
|
6
|
+
* @evidence contracts/development/implementation.md#principled-implementation Safe integer identity and the half-open zero-to-length range establish resolvable references; omission is accepted only when optional.
|
|
7
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One gate owns reference existence semantics while callers supply the appropriate inventory and field path.
|
|
8
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Undefined required values, negatives, fractions and out-of-range indices throw instead of selecting a nearby element.
|
|
9
|
+
* @evidence contracts/development/common.md#meaningful-documentation Prose defines required omission, zero-based range, safe precision and path-named failure.
|
|
10
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms The helper performs constant-time predicates independent of the inventory population.
|
|
11
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work All reference-array validation delegates this same gate without a separate range implementation.
|
|
12
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources No inventory is copied or retained, and no resource is acquired by index admission.
|
|
13
|
+
*/
|
|
14
|
+
export const integerIndex: (
|
|
15
|
+
value: unknown,
|
|
16
|
+
length: number,
|
|
17
|
+
path: string,
|
|
18
|
+
required?: boolean,
|
|
19
|
+
) => void = (
|
|
20
|
+
value: unknown,
|
|
21
|
+
length: number,
|
|
22
|
+
path: string,
|
|
23
|
+
required: boolean = false,
|
|
24
|
+
): void => {
|
|
25
|
+
if (value === undefined && required === false) return;
|
|
26
|
+
if (validNodeIndex(value, length) === false)
|
|
27
|
+
throw new Error(`${path} does not resolve inside its declared inventory.`);
|
|
28
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { integerIndex } from "./integerIndex";
|
|
2
|
+
import { requiredArray } from "./requiredArray";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Validate every index in an optional glTF reference array.
|
|
6
|
+
*
|
|
7
|
+
* @evidence contracts/development/implementation.md#principled-implementation Undefined allows omitted references; a supplied array delegates each element's safe in-range admission with an indexed path.
|
|
8
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure Array shape belongs to requiredArray and each index predicate to integerIndex, leaving this owner only enumeration.
|
|
9
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Malformed references are neither skipped nor coerced, so the first failing index remains observable.
|
|
10
|
+
* @evidence contracts/development/common.md#meaningful-documentation Comments describe optional-array meaning, indexed failures and the predeclared inventory length.
|
|
11
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms An N-reference array costs O(N) with no new result array and constant work per index.
|
|
12
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Each reference is checked once using the shared single-index admission rule.
|
|
13
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The enumeration borrows its array for the call and retains no graph or payload resource.
|
|
14
|
+
*/
|
|
15
|
+
export const integerIndices: (
|
|
16
|
+
value: unknown,
|
|
17
|
+
length: number,
|
|
18
|
+
path: string,
|
|
19
|
+
) => void = (value: unknown, length: number, path: string): void => {
|
|
20
|
+
if (value === undefined) return;
|
|
21
|
+
requiredArray(value, path).forEach((entry: unknown, index: number): void =>
|
|
22
|
+
integerIndex(entry, length, `${path}[${index}]`, true),
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Require a safe nonnegative glTF byte offset.
|
|
3
|
+
*
|
|
4
|
+
* @evidence contracts/development/implementation.md#principled-implementation Number type, safe-integer identity and nonnegative sign protect subsequent declared-range arithmetic.
|
|
5
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One shared scalar rule serves buffer/accessor offsets without embedding range ownership.
|
|
6
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts Fractions, negative offsets and unsafe integers throw rather than being truncated or clamped.
|
|
7
|
+
* @evidence contracts/development/common.md#meaningful-documentation Prose states zero allowance, integer precision requirement, path diagnostic and unchanged input.
|
|
8
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Three scalar checks require constant time without payload allocation or byte traversal.
|
|
9
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work All offset owners reuse this gate; final offset-plus-length bounds remain with their range validators.
|
|
10
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources No input record or offset cache survives this pure admission call.
|
|
11
|
+
*/
|
|
12
|
+
export const nonNegativeInteger: (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 non-negative safe integer.`);
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Require a non-null non-array JSON record at its owning path.
|
|
3
|
+
*
|
|
4
|
+
* @evidence contracts/development/implementation.md#principled-implementation Runtime type and null/array exclusions establish an object shape before fields are read.
|
|
5
|
+
* @evidence contracts/development/implementation.md#clear-and-simple-structure One shared JSON record gate keeps identical error semantics across structural, payload and profile consumers.
|
|
6
|
+
* @evidence contracts/development/implementation.md#prohibited-implementation-shortcuts No value is cast into a usable record until the object predicate succeeds, and malformed inputs are not repaired.
|
|
7
|
+
* @evidence contracts/development/common.md#meaningful-documentation The comment identifies accepted shape, path-named failure and returned borrowed identity.
|
|
8
|
+
* @evidence contracts/development/implementation.md#efficient-algorithms Object shape admission uses constant-time predicates rather than copying or traversing properties.
|
|
9
|
+
* @evidence contracts/development/implementation.md#reuse-equivalent-work Every optional-object path delegates this same gate for present values.
|
|
10
|
+
* @evidence contracts/development/implementation.md#bound-retention-and-release-resources The helper returns the existing object and retains no metadata, payload or resource state.
|
|
11
|
+
*/
|
|
12
|
+
export const object: (
|
|
13
|
+
value: unknown,
|
|
14
|
+
path: string,
|
|
15
|
+
) => Record<string, unknown> = (
|
|
16
|
+
value: unknown,
|
|
17
|
+
path: string,
|
|
18
|
+
): Record<string, unknown> => {
|
|
19
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
20
|
+
throw new Error(`${path} must be an object.`);
|
|
21
|
+
return value as Record<string, unknown>;
|
|
22
|
+
};
|