@lovelace_lol/embody 0.0.4 → 0.0.5
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/dist/core/WasmRuntimeCore.d.ts +2 -24
- package/dist/core/index.d.ts +2 -2
- package/dist/core.cjs +0 -227
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +1 -224
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +0 -227
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -224
- package/dist/index.js.map +1 -1
- package/dist/three.cjs.map +1 -1
- package/dist/three.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import type { BoneFrameDelta, FrameDelta, ModelDescriptor, MorphTargetFrameDelta } from './contracts';
|
|
2
2
|
import type { Profile } from '../mappings/types';
|
|
3
3
|
import type { EmbodyCoreWasmModule } from '../wasmTypes';
|
|
4
|
-
export declare const AU_MORPH_BINDING_STRIDE = 5;
|
|
5
|
-
export declare const VISEME_MORPH_BINDING_STRIDE = 4;
|
|
6
|
-
export type MorphBindingSide = 0 | 1 | 2;
|
|
7
4
|
export interface WasmRuntimeCoreOptions {
|
|
8
5
|
readonly profile: Profile;
|
|
9
6
|
readonly model: ModelDescriptor;
|
|
10
7
|
readonly wasm: EmbodyCoreWasmModule;
|
|
11
8
|
}
|
|
12
9
|
/**
|
|
13
|
-
* TypeScript facade over the Rust Wasm RuntimeCore
|
|
14
|
-
*
|
|
10
|
+
* TypeScript facade over the host-neutral Rust Wasm RuntimeCore.
|
|
11
|
+
* JavaScript only owns JSON handoff and packed FrameDelta unpacking here.
|
|
15
12
|
*/
|
|
16
13
|
export declare class WasmRuntimeCore {
|
|
17
14
|
private readonly wasm;
|
|
@@ -32,24 +29,5 @@ export declare class WasmRuntimeCore {
|
|
|
32
29
|
evaluateFrameDelta(deltaSeconds?: number): FrameDelta;
|
|
33
30
|
private reloadBindings;
|
|
34
31
|
}
|
|
35
|
-
export declare function compileMorphBindings(profile: Profile, model: ModelDescriptor): {
|
|
36
|
-
auBindings: Float32Array;
|
|
37
|
-
visemeBindings: Float32Array;
|
|
38
|
-
mixedAus: Uint32Array;
|
|
39
|
-
};
|
|
40
|
-
export interface CompiledBoneBindings {
|
|
41
|
-
restTransforms: Float32Array;
|
|
42
|
-
compositeAxes: Float32Array;
|
|
43
|
-
translations: Float32Array;
|
|
44
|
-
jawBinding: Float32Array;
|
|
45
|
-
visemeJawAmounts: Float32Array;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Compile profile bone mappings into the packed tables the Rust RuntimeCore
|
|
49
|
-
* consumes: rest transforms, composite rotation axes (in yaw/pitch/roll
|
|
50
|
-
* application order), AU translations, and the auto viseme jaw binding.
|
|
51
|
-
* Mirrors the mapping resolution in TsRuntimeCore.collectBoneWrites.
|
|
52
|
-
*/
|
|
53
|
-
export declare function compileBoneBindings(profile: Profile, model: ModelDescriptor): CompiledBoneBindings;
|
|
54
32
|
export declare function unpackBoneFrameDelta(values: ArrayLike<number>): BoneFrameDelta[];
|
|
55
33
|
export declare function unpackMorphFrameDelta(values: ArrayLike<number>): MorphTargetFrameDelta[];
|
package/dist/core/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type { BoneDescriptor, BoneFrameDelta, BoneId, BoneTransformTrackTarget,
|
|
|
2
2
|
export { TEMPLATE_SKELETON_FIT_METADATA_KIND, TEMPLATE_SKELETON_FIT_METADATA_VERSION, MESH_PROPORTIONS_FIELDS, MESH_PROPORTIONS_STRIDE, TEMPLATE_SKELETON_FIT_STATUSES, TEMPLATE_SKELETON_FIT_SOLUTION_FIELDS, TEMPLATE_SKELETON_FIT_SOLUTION_STRIDE, TEMPLATE_SKELETON_FIT_TRANSFORM_FIELDS, TEMPLATE_SKELETON_FIT_TRANSFORM_STRIDE, TEMPLATE_SKELETON_FIT_VERTICAL_ANCHORS, TEMPLATE_SKELETON_FIT_VERTICAL_AXES, composeTemplateSkeletonFitTransform, isTemplateSkeletonFitStatus, validateTemplateSkeletonFitMetadata, } from './contracts';
|
|
3
3
|
export { TsClipCompiler, numericArrayToNumbers, } from './TsClipCompiler';
|
|
4
4
|
export { TsRuntimeCore } from './TsRuntimeCore';
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
5
|
+
export { WasmRuntimeCore, unpackMorphFrameDelta, unpackBoneFrameDelta, } from './WasmRuntimeCore';
|
|
6
|
+
export type { WasmRuntimeCoreOptions, } from './WasmRuntimeCore';
|
|
7
7
|
export type { TsClipCompilerInput, TsClipCompilerKeyframe, TsClipCompilerTrackInput, TsClipCurveTarget, TsClipCurvesInput, } from './TsClipCompiler';
|
|
8
8
|
export type { TsRuntimeCoreOptions } from './TsRuntimeCore';
|
package/dist/core.cjs
CHANGED
|
@@ -698,16 +698,6 @@ function morphWriteKey(meshId, morphTargetId) {
|
|
|
698
698
|
}
|
|
699
699
|
|
|
700
700
|
// src/core/WasmRuntimeCore.ts
|
|
701
|
-
var AU_MORPH_BINDING_STRIDE = 5;
|
|
702
|
-
var VISEME_MORPH_BINDING_STRIDE = 4;
|
|
703
|
-
var AXIS_GROUP_NEGATIVE = 0;
|
|
704
|
-
var AXIS_GROUP_POSITIVE = 1;
|
|
705
|
-
var AXIS_GROUP_PLAIN = 2;
|
|
706
|
-
var BONE_SIDE_NONE = 0;
|
|
707
|
-
var BONE_SIDE_LEFT = 1;
|
|
708
|
-
var BONE_SIDE_RIGHT = 2;
|
|
709
|
-
var ROTATION_CHANNELS = { rx: 0, ry: 1, rz: 2 };
|
|
710
|
-
var TRANSLATION_CHANNELS = { tx: 0, ty: 1, tz: 2 };
|
|
711
701
|
var WasmRuntimeCore = class {
|
|
712
702
|
constructor(options) {
|
|
713
703
|
__publicField(this, "wasm");
|
|
@@ -773,179 +763,6 @@ var WasmRuntimeCore = class {
|
|
|
773
763
|
this.core.configure_with_profile(JSON.stringify(this.profile), JSON.stringify(this.model));
|
|
774
764
|
}
|
|
775
765
|
};
|
|
776
|
-
function compileMorphBindings(profile, model) {
|
|
777
|
-
const auRows = [];
|
|
778
|
-
const mixed = [];
|
|
779
|
-
for (const [auIdText, entry] of Object.entries(profile.auToMorphs || {})) {
|
|
780
|
-
const auId = Number(auIdText);
|
|
781
|
-
if (Number.isNaN(auId) || !entry) continue;
|
|
782
|
-
const meshNames = getMeshNamesForAUProfile(profile, auId);
|
|
783
|
-
const hasMorphs = !!(entry.left?.length || entry.right?.length || entry.center?.length);
|
|
784
|
-
if (hasMorphs && profile.auToBones?.[auId]?.length) {
|
|
785
|
-
mixed.push(auId);
|
|
786
|
-
}
|
|
787
|
-
pushAuSide(auRows, auId, 0, entry.left || [], meshNames, model, profile);
|
|
788
|
-
pushAuSide(auRows, auId, 1, entry.right || [], meshNames, model, profile);
|
|
789
|
-
pushAuSide(auRows, auId, 2, entry.center || [], meshNames, model, profile);
|
|
790
|
-
}
|
|
791
|
-
const visemeRows = [];
|
|
792
|
-
const visemeMeshNames = getMeshNamesForVisemeProfile(profile);
|
|
793
|
-
const slotCount = getProfileVisemeSlots(profile).length;
|
|
794
|
-
for (let index = 0; index < slotCount; index += 1) {
|
|
795
|
-
for (const bindingTarget of getVisemeBindingTargets(profile, index)) {
|
|
796
|
-
for (const resolved of resolveMorphTargets(model, profile, bindingTarget.morph, visemeMeshNames)) {
|
|
797
|
-
visemeRows.push(
|
|
798
|
-
index,
|
|
799
|
-
Number(resolved.mesh.id),
|
|
800
|
-
Number(resolved.morphTarget.id),
|
|
801
|
-
bindingTarget.weight
|
|
802
|
-
);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
return {
|
|
807
|
-
auBindings: Float32Array.from(auRows),
|
|
808
|
-
visemeBindings: Float32Array.from(visemeRows),
|
|
809
|
-
mixedAus: Uint32Array.from(mixed)
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
function compileBoneBindings(profile, model) {
|
|
813
|
-
const referencedBones = /* @__PURE__ */ new Map();
|
|
814
|
-
const findBone = (nodeKey) => {
|
|
815
|
-
const bone = findBoneDescriptor(profile, model, nodeKey);
|
|
816
|
-
if (bone) referencedBones.set(bone.id, bone);
|
|
817
|
-
return bone;
|
|
818
|
-
};
|
|
819
|
-
const boneSideForAU = (auId, nodeKey) => {
|
|
820
|
-
const side = profile.auToBones?.[auId]?.find((candidate) => candidate.node === nodeKey)?.side;
|
|
821
|
-
if (side === "left") return BONE_SIDE_LEFT;
|
|
822
|
-
if (side === "right") return BONE_SIDE_RIGHT;
|
|
823
|
-
return BONE_SIDE_NONE;
|
|
824
|
-
};
|
|
825
|
-
const compositeRows = [];
|
|
826
|
-
for (const composite of profile.compositeRotations || []) {
|
|
827
|
-
const bone = findBone(composite.node);
|
|
828
|
-
if (!bone) continue;
|
|
829
|
-
const axes = [
|
|
830
|
-
{ axis: 1, config: composite.yaw },
|
|
831
|
-
{ axis: 0, config: composite.pitch },
|
|
832
|
-
{ axis: 2, config: composite.roll }
|
|
833
|
-
];
|
|
834
|
-
for (const { axis, config } of axes) {
|
|
835
|
-
if (!config) continue;
|
|
836
|
-
const negativeAUs = toAUList(config.negative);
|
|
837
|
-
const positiveAUs = toAUList(config.positive);
|
|
838
|
-
const hasDirectional = negativeAUs.length > 0 && positiveAUs.length > 0;
|
|
839
|
-
const valueRows = [];
|
|
840
|
-
if (hasDirectional) {
|
|
841
|
-
for (const auId of negativeAUs) {
|
|
842
|
-
valueRows.push([auId, AXIS_GROUP_NEGATIVE, boneSideForAU(auId, composite.node)]);
|
|
843
|
-
}
|
|
844
|
-
for (const auId of positiveAUs) {
|
|
845
|
-
valueRows.push([auId, AXIS_GROUP_POSITIVE, boneSideForAU(auId, composite.node)]);
|
|
846
|
-
}
|
|
847
|
-
} else {
|
|
848
|
-
for (const auId of config.aus) {
|
|
849
|
-
valueRows.push([auId, AXIS_GROUP_PLAIN, boneSideForAU(auId, composite.node)]);
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
const bindingRows = [];
|
|
853
|
-
const pushBindingRows = (auIds, group) => {
|
|
854
|
-
for (const auId of auIds) {
|
|
855
|
-
const binding = profile.auToBones?.[auId]?.find(
|
|
856
|
-
(candidate) => candidate.node === composite.node
|
|
857
|
-
);
|
|
858
|
-
if (!binding?.maxDegrees) continue;
|
|
859
|
-
const channel = ROTATION_CHANNELS[binding.channel];
|
|
860
|
-
if (channel === void 0) continue;
|
|
861
|
-
bindingRows.push([
|
|
862
|
-
auId,
|
|
863
|
-
group,
|
|
864
|
-
boneSideForAU(auId, composite.node),
|
|
865
|
-
channel,
|
|
866
|
-
binding.scale,
|
|
867
|
-
binding.maxDegrees
|
|
868
|
-
]);
|
|
869
|
-
}
|
|
870
|
-
};
|
|
871
|
-
pushBindingRows(negativeAUs, AXIS_GROUP_NEGATIVE);
|
|
872
|
-
pushBindingRows(positiveAUs, AXIS_GROUP_POSITIVE);
|
|
873
|
-
pushBindingRows(config.aus, AXIS_GROUP_PLAIN);
|
|
874
|
-
compositeRows.push(
|
|
875
|
-
Number(bone.id),
|
|
876
|
-
axis,
|
|
877
|
-
hasDirectional ? 1 : 0,
|
|
878
|
-
valueRows.length,
|
|
879
|
-
bindingRows.length,
|
|
880
|
-
0,
|
|
881
|
-
0,
|
|
882
|
-
0
|
|
883
|
-
);
|
|
884
|
-
for (const row of valueRows) compositeRows.push(...row);
|
|
885
|
-
for (const row of bindingRows) compositeRows.push(...row);
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
const translationRows = [];
|
|
889
|
-
for (const [auIdText, bindings] of Object.entries(profile.auToBones || {})) {
|
|
890
|
-
const auId = Number(auIdText);
|
|
891
|
-
if (Number.isNaN(auId)) continue;
|
|
892
|
-
for (const binding of bindings || []) {
|
|
893
|
-
const channel = TRANSLATION_CHANNELS[binding.channel];
|
|
894
|
-
if (channel === void 0 || binding.maxUnits === void 0) continue;
|
|
895
|
-
const bone = findBone(binding.node);
|
|
896
|
-
if (!bone) continue;
|
|
897
|
-
translationRows.push(auId, Number(bone.id), channel, binding.scale, binding.maxUnits);
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
const jawRow = [];
|
|
901
|
-
const jawBinding = findAutoVisemeJawBinding(profile, model);
|
|
902
|
-
if (jawBinding?.maxDegrees) {
|
|
903
|
-
const bone = findBone(jawBinding.node);
|
|
904
|
-
const channel = ROTATION_CHANNELS[jawBinding.channel];
|
|
905
|
-
if (bone && channel !== void 0) {
|
|
906
|
-
jawRow.push(Number(bone.id), channel, jawBinding.scale, jawBinding.maxDegrees);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
const restRows = [];
|
|
910
|
-
for (const bone of referencedBones.values()) {
|
|
911
|
-
const position = bone.restTransform?.position;
|
|
912
|
-
const rotation = bone.restTransform?.rotation;
|
|
913
|
-
restRows.push(
|
|
914
|
-
Number(bone.id),
|
|
915
|
-
position?.x ?? 0,
|
|
916
|
-
position?.y ?? 0,
|
|
917
|
-
position?.z ?? 0,
|
|
918
|
-
rotation?.x ?? 0,
|
|
919
|
-
rotation?.y ?? 0,
|
|
920
|
-
rotation?.z ?? 0,
|
|
921
|
-
rotation?.w ?? 1
|
|
922
|
-
);
|
|
923
|
-
}
|
|
924
|
-
return {
|
|
925
|
-
restTransforms: Float32Array.from(restRows),
|
|
926
|
-
compositeAxes: Float32Array.from(compositeRows),
|
|
927
|
-
translations: Float32Array.from(translationRows),
|
|
928
|
-
jawBinding: Float32Array.from(jawRow),
|
|
929
|
-
visemeJawAmounts: Float32Array.from(getVisemeJawAmounts(profile) ?? [])
|
|
930
|
-
};
|
|
931
|
-
}
|
|
932
|
-
function findBoneDescriptor(profile, model, nodeKey) {
|
|
933
|
-
const configuredName = profile.boneNodes?.[nodeKey] || nodeKey;
|
|
934
|
-
const prefix = profile.bonePrefix ?? "";
|
|
935
|
-
const suffix = profile.boneSuffix ?? "";
|
|
936
|
-
const prefixedName = prefix && !configuredName.startsWith(prefix) ? `${prefix}${configuredName}` : configuredName;
|
|
937
|
-
const fullName = suffix && !prefixedName.endsWith(suffix) ? `${prefixedName}${suffix}` : prefixedName;
|
|
938
|
-
const candidates = /* @__PURE__ */ new Set([nodeKey, configuredName, fullName]);
|
|
939
|
-
return model.bones.find((bone) => candidates.has(bone.name));
|
|
940
|
-
}
|
|
941
|
-
function findAutoVisemeJawBinding(profile, model) {
|
|
942
|
-
const isRotation = (binding) => binding?.channel === "rx" || binding?.channel === "ry" || binding?.channel === "rz";
|
|
943
|
-
const candidates = [
|
|
944
|
-
profile.auToBones?.[103]?.find(isRotation),
|
|
945
|
-
profile.auToBones?.[26]?.find(isRotation)
|
|
946
|
-
].filter((binding) => !!binding);
|
|
947
|
-
return candidates.find((binding) => !!findBoneDescriptor(profile, model, binding.node)) ?? candidates[0] ?? null;
|
|
948
|
-
}
|
|
949
766
|
function unpackBoneFrameDelta(values) {
|
|
950
767
|
const stride = PACKED_BONE_FRAME_DELTA_STRIDE;
|
|
951
768
|
const writes = [];
|
|
@@ -986,48 +803,7 @@ function unpackMorphFrameDelta(values) {
|
|
|
986
803
|
}
|
|
987
804
|
return writes;
|
|
988
805
|
}
|
|
989
|
-
function pushAuSide(rows, auId, side, morphs, meshNames, model, profile) {
|
|
990
|
-
for (const morph of morphs) {
|
|
991
|
-
for (const resolved of resolveMorphTargets(model, profile, morph, meshNames)) {
|
|
992
|
-
rows.push(
|
|
993
|
-
auId,
|
|
994
|
-
side,
|
|
995
|
-
Number(resolved.mesh.id),
|
|
996
|
-
Number(resolved.morphTarget.id),
|
|
997
|
-
1
|
|
998
|
-
);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
function resolveMorphTargets(model, profile, morph, meshNames) {
|
|
1003
|
-
const result = [];
|
|
1004
|
-
for (const meshName of meshNames) {
|
|
1005
|
-
const mesh = model.meshes.find((candidate) => candidate.name === meshName);
|
|
1006
|
-
if (!mesh) continue;
|
|
1007
|
-
const morphTargets = mesh.morphTargetIds.map((id) => model.morphTargets.find((candidate) => candidate.id === id)).filter((target2) => !!target2);
|
|
1008
|
-
const target = typeof morph === "number" ? morphTargets.find((candidate) => candidate.hostIndex === morph) : resolveMorphTargetByName2(morphTargets, morph, profile);
|
|
1009
|
-
if (target) {
|
|
1010
|
-
result.push({ mesh, morphTarget: target });
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
return result;
|
|
1014
|
-
}
|
|
1015
|
-
function resolveMorphTargetByName2(targets, key, profile) {
|
|
1016
|
-
const prefix = profile.morphPrefix || "";
|
|
1017
|
-
const suffix = profile.morphSuffix || "";
|
|
1018
|
-
const fullName = prefix + key + suffix;
|
|
1019
|
-
const exact = targets.find((target) => target.name === fullName);
|
|
1020
|
-
if (exact) return exact;
|
|
1021
|
-
const suffixRegex = profile.suffixPattern ? new RegExp(profile.suffixPattern) : null;
|
|
1022
|
-
if (!suffixRegex) return void 0;
|
|
1023
|
-
return targets.find((target) => {
|
|
1024
|
-
if (!target.name.startsWith(fullName)) return false;
|
|
1025
|
-
const candidateSuffix = target.name.slice(fullName.length);
|
|
1026
|
-
return candidateSuffix === "" || suffixRegex.test(candidateSuffix);
|
|
1027
|
-
});
|
|
1028
|
-
}
|
|
1029
806
|
|
|
1030
|
-
exports.AU_MORPH_BINDING_STRIDE = AU_MORPH_BINDING_STRIDE;
|
|
1031
807
|
exports.MESH_PROPORTIONS_FIELDS = MESH_PROPORTIONS_FIELDS;
|
|
1032
808
|
exports.MESH_PROPORTIONS_STRIDE = MESH_PROPORTIONS_STRIDE;
|
|
1033
809
|
exports.TEMPLATE_SKELETON_FIT_METADATA_KIND = TEMPLATE_SKELETON_FIT_METADATA_KIND;
|
|
@@ -1041,10 +817,7 @@ exports.TEMPLATE_SKELETON_FIT_VERTICAL_ANCHORS = TEMPLATE_SKELETON_FIT_VERTICAL_
|
|
|
1041
817
|
exports.TEMPLATE_SKELETON_FIT_VERTICAL_AXES = TEMPLATE_SKELETON_FIT_VERTICAL_AXES;
|
|
1042
818
|
exports.TsClipCompiler = TsClipCompiler;
|
|
1043
819
|
exports.TsRuntimeCore = TsRuntimeCore;
|
|
1044
|
-
exports.VISEME_MORPH_BINDING_STRIDE = VISEME_MORPH_BINDING_STRIDE;
|
|
1045
820
|
exports.WasmRuntimeCore = WasmRuntimeCore;
|
|
1046
|
-
exports.compileBoneBindings = compileBoneBindings;
|
|
1047
|
-
exports.compileMorphBindings = compileMorphBindings;
|
|
1048
821
|
exports.composeTemplateSkeletonFitTransform = composeTemplateSkeletonFitTransform;
|
|
1049
822
|
exports.isTemplateSkeletonFitStatus = isTemplateSkeletonFitStatus;
|
|
1050
823
|
exports.numericArrayToNumbers = numericArrayToNumbers;
|