@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
package/dist/core.js
CHANGED
|
@@ -696,16 +696,6 @@ function morphWriteKey(meshId, morphTargetId) {
|
|
|
696
696
|
}
|
|
697
697
|
|
|
698
698
|
// src/core/WasmRuntimeCore.ts
|
|
699
|
-
var AU_MORPH_BINDING_STRIDE = 5;
|
|
700
|
-
var VISEME_MORPH_BINDING_STRIDE = 4;
|
|
701
|
-
var AXIS_GROUP_NEGATIVE = 0;
|
|
702
|
-
var AXIS_GROUP_POSITIVE = 1;
|
|
703
|
-
var AXIS_GROUP_PLAIN = 2;
|
|
704
|
-
var BONE_SIDE_NONE = 0;
|
|
705
|
-
var BONE_SIDE_LEFT = 1;
|
|
706
|
-
var BONE_SIDE_RIGHT = 2;
|
|
707
|
-
var ROTATION_CHANNELS = { rx: 0, ry: 1, rz: 2 };
|
|
708
|
-
var TRANSLATION_CHANNELS = { tx: 0, ty: 1, tz: 2 };
|
|
709
699
|
var WasmRuntimeCore = class {
|
|
710
700
|
constructor(options) {
|
|
711
701
|
__publicField(this, "wasm");
|
|
@@ -771,179 +761,6 @@ var WasmRuntimeCore = class {
|
|
|
771
761
|
this.core.configure_with_profile(JSON.stringify(this.profile), JSON.stringify(this.model));
|
|
772
762
|
}
|
|
773
763
|
};
|
|
774
|
-
function compileMorphBindings(profile, model) {
|
|
775
|
-
const auRows = [];
|
|
776
|
-
const mixed = [];
|
|
777
|
-
for (const [auIdText, entry] of Object.entries(profile.auToMorphs || {})) {
|
|
778
|
-
const auId = Number(auIdText);
|
|
779
|
-
if (Number.isNaN(auId) || !entry) continue;
|
|
780
|
-
const meshNames = getMeshNamesForAUProfile(profile, auId);
|
|
781
|
-
const hasMorphs = !!(entry.left?.length || entry.right?.length || entry.center?.length);
|
|
782
|
-
if (hasMorphs && profile.auToBones?.[auId]?.length) {
|
|
783
|
-
mixed.push(auId);
|
|
784
|
-
}
|
|
785
|
-
pushAuSide(auRows, auId, 0, entry.left || [], meshNames, model, profile);
|
|
786
|
-
pushAuSide(auRows, auId, 1, entry.right || [], meshNames, model, profile);
|
|
787
|
-
pushAuSide(auRows, auId, 2, entry.center || [], meshNames, model, profile);
|
|
788
|
-
}
|
|
789
|
-
const visemeRows = [];
|
|
790
|
-
const visemeMeshNames = getMeshNamesForVisemeProfile(profile);
|
|
791
|
-
const slotCount = getProfileVisemeSlots(profile).length;
|
|
792
|
-
for (let index = 0; index < slotCount; index += 1) {
|
|
793
|
-
for (const bindingTarget of getVisemeBindingTargets(profile, index)) {
|
|
794
|
-
for (const resolved of resolveMorphTargets(model, profile, bindingTarget.morph, visemeMeshNames)) {
|
|
795
|
-
visemeRows.push(
|
|
796
|
-
index,
|
|
797
|
-
Number(resolved.mesh.id),
|
|
798
|
-
Number(resolved.morphTarget.id),
|
|
799
|
-
bindingTarget.weight
|
|
800
|
-
);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
return {
|
|
805
|
-
auBindings: Float32Array.from(auRows),
|
|
806
|
-
visemeBindings: Float32Array.from(visemeRows),
|
|
807
|
-
mixedAus: Uint32Array.from(mixed)
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
function compileBoneBindings(profile, model) {
|
|
811
|
-
const referencedBones = /* @__PURE__ */ new Map();
|
|
812
|
-
const findBone = (nodeKey) => {
|
|
813
|
-
const bone = findBoneDescriptor(profile, model, nodeKey);
|
|
814
|
-
if (bone) referencedBones.set(bone.id, bone);
|
|
815
|
-
return bone;
|
|
816
|
-
};
|
|
817
|
-
const boneSideForAU = (auId, nodeKey) => {
|
|
818
|
-
const side = profile.auToBones?.[auId]?.find((candidate) => candidate.node === nodeKey)?.side;
|
|
819
|
-
if (side === "left") return BONE_SIDE_LEFT;
|
|
820
|
-
if (side === "right") return BONE_SIDE_RIGHT;
|
|
821
|
-
return BONE_SIDE_NONE;
|
|
822
|
-
};
|
|
823
|
-
const compositeRows = [];
|
|
824
|
-
for (const composite of profile.compositeRotations || []) {
|
|
825
|
-
const bone = findBone(composite.node);
|
|
826
|
-
if (!bone) continue;
|
|
827
|
-
const axes = [
|
|
828
|
-
{ axis: 1, config: composite.yaw },
|
|
829
|
-
{ axis: 0, config: composite.pitch },
|
|
830
|
-
{ axis: 2, config: composite.roll }
|
|
831
|
-
];
|
|
832
|
-
for (const { axis, config } of axes) {
|
|
833
|
-
if (!config) continue;
|
|
834
|
-
const negativeAUs = toAUList(config.negative);
|
|
835
|
-
const positiveAUs = toAUList(config.positive);
|
|
836
|
-
const hasDirectional = negativeAUs.length > 0 && positiveAUs.length > 0;
|
|
837
|
-
const valueRows = [];
|
|
838
|
-
if (hasDirectional) {
|
|
839
|
-
for (const auId of negativeAUs) {
|
|
840
|
-
valueRows.push([auId, AXIS_GROUP_NEGATIVE, boneSideForAU(auId, composite.node)]);
|
|
841
|
-
}
|
|
842
|
-
for (const auId of positiveAUs) {
|
|
843
|
-
valueRows.push([auId, AXIS_GROUP_POSITIVE, boneSideForAU(auId, composite.node)]);
|
|
844
|
-
}
|
|
845
|
-
} else {
|
|
846
|
-
for (const auId of config.aus) {
|
|
847
|
-
valueRows.push([auId, AXIS_GROUP_PLAIN, boneSideForAU(auId, composite.node)]);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
const bindingRows = [];
|
|
851
|
-
const pushBindingRows = (auIds, group) => {
|
|
852
|
-
for (const auId of auIds) {
|
|
853
|
-
const binding = profile.auToBones?.[auId]?.find(
|
|
854
|
-
(candidate) => candidate.node === composite.node
|
|
855
|
-
);
|
|
856
|
-
if (!binding?.maxDegrees) continue;
|
|
857
|
-
const channel = ROTATION_CHANNELS[binding.channel];
|
|
858
|
-
if (channel === void 0) continue;
|
|
859
|
-
bindingRows.push([
|
|
860
|
-
auId,
|
|
861
|
-
group,
|
|
862
|
-
boneSideForAU(auId, composite.node),
|
|
863
|
-
channel,
|
|
864
|
-
binding.scale,
|
|
865
|
-
binding.maxDegrees
|
|
866
|
-
]);
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
|
-
pushBindingRows(negativeAUs, AXIS_GROUP_NEGATIVE);
|
|
870
|
-
pushBindingRows(positiveAUs, AXIS_GROUP_POSITIVE);
|
|
871
|
-
pushBindingRows(config.aus, AXIS_GROUP_PLAIN);
|
|
872
|
-
compositeRows.push(
|
|
873
|
-
Number(bone.id),
|
|
874
|
-
axis,
|
|
875
|
-
hasDirectional ? 1 : 0,
|
|
876
|
-
valueRows.length,
|
|
877
|
-
bindingRows.length,
|
|
878
|
-
0,
|
|
879
|
-
0,
|
|
880
|
-
0
|
|
881
|
-
);
|
|
882
|
-
for (const row of valueRows) compositeRows.push(...row);
|
|
883
|
-
for (const row of bindingRows) compositeRows.push(...row);
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
const translationRows = [];
|
|
887
|
-
for (const [auIdText, bindings] of Object.entries(profile.auToBones || {})) {
|
|
888
|
-
const auId = Number(auIdText);
|
|
889
|
-
if (Number.isNaN(auId)) continue;
|
|
890
|
-
for (const binding of bindings || []) {
|
|
891
|
-
const channel = TRANSLATION_CHANNELS[binding.channel];
|
|
892
|
-
if (channel === void 0 || binding.maxUnits === void 0) continue;
|
|
893
|
-
const bone = findBone(binding.node);
|
|
894
|
-
if (!bone) continue;
|
|
895
|
-
translationRows.push(auId, Number(bone.id), channel, binding.scale, binding.maxUnits);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
const jawRow = [];
|
|
899
|
-
const jawBinding = findAutoVisemeJawBinding(profile, model);
|
|
900
|
-
if (jawBinding?.maxDegrees) {
|
|
901
|
-
const bone = findBone(jawBinding.node);
|
|
902
|
-
const channel = ROTATION_CHANNELS[jawBinding.channel];
|
|
903
|
-
if (bone && channel !== void 0) {
|
|
904
|
-
jawRow.push(Number(bone.id), channel, jawBinding.scale, jawBinding.maxDegrees);
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
const restRows = [];
|
|
908
|
-
for (const bone of referencedBones.values()) {
|
|
909
|
-
const position = bone.restTransform?.position;
|
|
910
|
-
const rotation = bone.restTransform?.rotation;
|
|
911
|
-
restRows.push(
|
|
912
|
-
Number(bone.id),
|
|
913
|
-
position?.x ?? 0,
|
|
914
|
-
position?.y ?? 0,
|
|
915
|
-
position?.z ?? 0,
|
|
916
|
-
rotation?.x ?? 0,
|
|
917
|
-
rotation?.y ?? 0,
|
|
918
|
-
rotation?.z ?? 0,
|
|
919
|
-
rotation?.w ?? 1
|
|
920
|
-
);
|
|
921
|
-
}
|
|
922
|
-
return {
|
|
923
|
-
restTransforms: Float32Array.from(restRows),
|
|
924
|
-
compositeAxes: Float32Array.from(compositeRows),
|
|
925
|
-
translations: Float32Array.from(translationRows),
|
|
926
|
-
jawBinding: Float32Array.from(jawRow),
|
|
927
|
-
visemeJawAmounts: Float32Array.from(getVisemeJawAmounts(profile) ?? [])
|
|
928
|
-
};
|
|
929
|
-
}
|
|
930
|
-
function findBoneDescriptor(profile, model, nodeKey) {
|
|
931
|
-
const configuredName = profile.boneNodes?.[nodeKey] || nodeKey;
|
|
932
|
-
const prefix = profile.bonePrefix ?? "";
|
|
933
|
-
const suffix = profile.boneSuffix ?? "";
|
|
934
|
-
const prefixedName = prefix && !configuredName.startsWith(prefix) ? `${prefix}${configuredName}` : configuredName;
|
|
935
|
-
const fullName = suffix && !prefixedName.endsWith(suffix) ? `${prefixedName}${suffix}` : prefixedName;
|
|
936
|
-
const candidates = /* @__PURE__ */ new Set([nodeKey, configuredName, fullName]);
|
|
937
|
-
return model.bones.find((bone) => candidates.has(bone.name));
|
|
938
|
-
}
|
|
939
|
-
function findAutoVisemeJawBinding(profile, model) {
|
|
940
|
-
const isRotation = (binding) => binding?.channel === "rx" || binding?.channel === "ry" || binding?.channel === "rz";
|
|
941
|
-
const candidates = [
|
|
942
|
-
profile.auToBones?.[103]?.find(isRotation),
|
|
943
|
-
profile.auToBones?.[26]?.find(isRotation)
|
|
944
|
-
].filter((binding) => !!binding);
|
|
945
|
-
return candidates.find((binding) => !!findBoneDescriptor(profile, model, binding.node)) ?? candidates[0] ?? null;
|
|
946
|
-
}
|
|
947
764
|
function unpackBoneFrameDelta(values) {
|
|
948
765
|
const stride = PACKED_BONE_FRAME_DELTA_STRIDE;
|
|
949
766
|
const writes = [];
|
|
@@ -984,47 +801,7 @@ function unpackMorphFrameDelta(values) {
|
|
|
984
801
|
}
|
|
985
802
|
return writes;
|
|
986
803
|
}
|
|
987
|
-
function pushAuSide(rows, auId, side, morphs, meshNames, model, profile) {
|
|
988
|
-
for (const morph of morphs) {
|
|
989
|
-
for (const resolved of resolveMorphTargets(model, profile, morph, meshNames)) {
|
|
990
|
-
rows.push(
|
|
991
|
-
auId,
|
|
992
|
-
side,
|
|
993
|
-
Number(resolved.mesh.id),
|
|
994
|
-
Number(resolved.morphTarget.id),
|
|
995
|
-
1
|
|
996
|
-
);
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
function resolveMorphTargets(model, profile, morph, meshNames) {
|
|
1001
|
-
const result = [];
|
|
1002
|
-
for (const meshName of meshNames) {
|
|
1003
|
-
const mesh = model.meshes.find((candidate) => candidate.name === meshName);
|
|
1004
|
-
if (!mesh) continue;
|
|
1005
|
-
const morphTargets = mesh.morphTargetIds.map((id) => model.morphTargets.find((candidate) => candidate.id === id)).filter((target2) => !!target2);
|
|
1006
|
-
const target = typeof morph === "number" ? morphTargets.find((candidate) => candidate.hostIndex === morph) : resolveMorphTargetByName2(morphTargets, morph, profile);
|
|
1007
|
-
if (target) {
|
|
1008
|
-
result.push({ mesh, morphTarget: target });
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
return result;
|
|
1012
|
-
}
|
|
1013
|
-
function resolveMorphTargetByName2(targets, key, profile) {
|
|
1014
|
-
const prefix = profile.morphPrefix || "";
|
|
1015
|
-
const suffix = profile.morphSuffix || "";
|
|
1016
|
-
const fullName = prefix + key + suffix;
|
|
1017
|
-
const exact = targets.find((target) => target.name === fullName);
|
|
1018
|
-
if (exact) return exact;
|
|
1019
|
-
const suffixRegex = profile.suffixPattern ? new RegExp(profile.suffixPattern) : null;
|
|
1020
|
-
if (!suffixRegex) return void 0;
|
|
1021
|
-
return targets.find((target) => {
|
|
1022
|
-
if (!target.name.startsWith(fullName)) return false;
|
|
1023
|
-
const candidateSuffix = target.name.slice(fullName.length);
|
|
1024
|
-
return candidateSuffix === "" || suffixRegex.test(candidateSuffix);
|
|
1025
|
-
});
|
|
1026
|
-
}
|
|
1027
804
|
|
|
1028
|
-
export {
|
|
805
|
+
export { MESH_PROPORTIONS_FIELDS, MESH_PROPORTIONS_STRIDE, TEMPLATE_SKELETON_FIT_METADATA_KIND, TEMPLATE_SKELETON_FIT_METADATA_VERSION, TEMPLATE_SKELETON_FIT_SOLUTION_FIELDS, TEMPLATE_SKELETON_FIT_SOLUTION_STRIDE, TEMPLATE_SKELETON_FIT_STATUSES, TEMPLATE_SKELETON_FIT_TRANSFORM_FIELDS, TEMPLATE_SKELETON_FIT_TRANSFORM_STRIDE, TEMPLATE_SKELETON_FIT_VERTICAL_ANCHORS, TEMPLATE_SKELETON_FIT_VERTICAL_AXES, TsClipCompiler, TsRuntimeCore, WasmRuntimeCore, composeTemplateSkeletonFitTransform, isTemplateSkeletonFitStatus, numericArrayToNumbers, unpackBoneFrameDelta, unpackMorphFrameDelta, validateTemplateSkeletonFitMetadata };
|
|
1029
806
|
//# sourceMappingURL=core.js.map
|
|
1030
807
|
//# sourceMappingURL=core.js.map
|