@lovelace_lol/embody 0.0.3 → 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.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");
@@ -719,12 +709,11 @@ var WasmRuntimeCore = class {
719
709
  if (!RuntimeCtor) {
720
710
  throw new Error("Embody Wasm module does not export RuntimeCore");
721
711
  }
722
- this.core = new RuntimeCtor(getProfileVisemeSlots(options.profile).length);
712
+ this.core = new RuntimeCtor(0);
723
713
  this.reloadBindings();
724
714
  }
725
715
  setProfile(profile) {
726
716
  this.profile = profile;
727
- this.core.set_viseme_slot_count(getProfileVisemeSlots(profile).length);
728
717
  this.reloadBindings();
729
718
  }
730
719
  setModelDescriptor(model) {
@@ -769,191 +758,9 @@ var WasmRuntimeCore = class {
769
758
  };
770
759
  }
771
760
  reloadBindings() {
772
- const { auBindings, mixedAus, visemeBindings } = compileMorphBindings(this.profile, this.model);
773
- this.core.load_au_morph_bindings(auBindings);
774
- this.core.load_viseme_morph_bindings(visemeBindings);
775
- this.core.set_mixed_aus(mixedAus);
776
- const boneBindings = compileBoneBindings(this.profile, this.model);
777
- this.core.load_bone_rest_transforms(boneBindings.restTransforms);
778
- this.core.load_composite_axes(boneBindings.compositeAxes);
779
- this.core.load_bone_translations(boneBindings.translations);
780
- this.core.load_jaw_binding(boneBindings.jawBinding);
781
- this.core.load_viseme_jaw_amounts(boneBindings.visemeJawAmounts);
761
+ this.core.configure_with_profile(JSON.stringify(this.profile), JSON.stringify(this.model));
782
762
  }
783
763
  };
784
- function compileMorphBindings(profile, model) {
785
- const auRows = [];
786
- const mixed = [];
787
- for (const [auIdText, entry] of Object.entries(profile.auToMorphs || {})) {
788
- const auId = Number(auIdText);
789
- if (Number.isNaN(auId) || !entry) continue;
790
- const meshNames = getMeshNamesForAUProfile(profile, auId);
791
- const hasMorphs = !!(entry.left?.length || entry.right?.length || entry.center?.length);
792
- if (hasMorphs && profile.auToBones?.[auId]?.length) {
793
- mixed.push(auId);
794
- }
795
- pushAuSide(auRows, auId, 0, entry.left || [], meshNames, model, profile);
796
- pushAuSide(auRows, auId, 1, entry.right || [], meshNames, model, profile);
797
- pushAuSide(auRows, auId, 2, entry.center || [], meshNames, model, profile);
798
- }
799
- const visemeRows = [];
800
- const visemeMeshNames = getMeshNamesForVisemeProfile(profile);
801
- const slotCount = getProfileVisemeSlots(profile).length;
802
- for (let index = 0; index < slotCount; index += 1) {
803
- for (const bindingTarget of getVisemeBindingTargets(profile, index)) {
804
- for (const resolved of resolveMorphTargets(model, profile, bindingTarget.morph, visemeMeshNames)) {
805
- visemeRows.push(
806
- index,
807
- Number(resolved.mesh.id),
808
- Number(resolved.morphTarget.id),
809
- bindingTarget.weight
810
- );
811
- }
812
- }
813
- }
814
- return {
815
- auBindings: Float32Array.from(auRows),
816
- visemeBindings: Float32Array.from(visemeRows),
817
- mixedAus: Uint32Array.from(mixed)
818
- };
819
- }
820
- function compileBoneBindings(profile, model) {
821
- const referencedBones = /* @__PURE__ */ new Map();
822
- const findBone = (nodeKey) => {
823
- const bone = findBoneDescriptor(profile, model, nodeKey);
824
- if (bone) referencedBones.set(bone.id, bone);
825
- return bone;
826
- };
827
- const boneSideForAU = (auId, nodeKey) => {
828
- const side = profile.auToBones?.[auId]?.find((candidate) => candidate.node === nodeKey)?.side;
829
- if (side === "left") return BONE_SIDE_LEFT;
830
- if (side === "right") return BONE_SIDE_RIGHT;
831
- return BONE_SIDE_NONE;
832
- };
833
- const compositeRows = [];
834
- for (const composite of profile.compositeRotations || []) {
835
- const bone = findBone(composite.node);
836
- if (!bone) continue;
837
- const axes = [
838
- { axis: 1, config: composite.yaw },
839
- { axis: 0, config: composite.pitch },
840
- { axis: 2, config: composite.roll }
841
- ];
842
- for (const { axis, config } of axes) {
843
- if (!config) continue;
844
- const negativeAUs = toAUList(config.negative);
845
- const positiveAUs = toAUList(config.positive);
846
- const hasDirectional = negativeAUs.length > 0 && positiveAUs.length > 0;
847
- const valueRows = [];
848
- if (hasDirectional) {
849
- for (const auId of negativeAUs) {
850
- valueRows.push([auId, AXIS_GROUP_NEGATIVE, boneSideForAU(auId, composite.node)]);
851
- }
852
- for (const auId of positiveAUs) {
853
- valueRows.push([auId, AXIS_GROUP_POSITIVE, boneSideForAU(auId, composite.node)]);
854
- }
855
- } else {
856
- for (const auId of config.aus) {
857
- valueRows.push([auId, AXIS_GROUP_PLAIN, boneSideForAU(auId, composite.node)]);
858
- }
859
- }
860
- const bindingRows = [];
861
- const pushBindingRows = (auIds, group) => {
862
- for (const auId of auIds) {
863
- const binding = profile.auToBones?.[auId]?.find(
864
- (candidate) => candidate.node === composite.node
865
- );
866
- if (!binding?.maxDegrees) continue;
867
- const channel = ROTATION_CHANNELS[binding.channel];
868
- if (channel === void 0) continue;
869
- bindingRows.push([
870
- auId,
871
- group,
872
- boneSideForAU(auId, composite.node),
873
- channel,
874
- binding.scale,
875
- binding.maxDegrees
876
- ]);
877
- }
878
- };
879
- pushBindingRows(negativeAUs, AXIS_GROUP_NEGATIVE);
880
- pushBindingRows(positiveAUs, AXIS_GROUP_POSITIVE);
881
- pushBindingRows(config.aus, AXIS_GROUP_PLAIN);
882
- compositeRows.push(
883
- Number(bone.id),
884
- axis,
885
- hasDirectional ? 1 : 0,
886
- valueRows.length,
887
- bindingRows.length,
888
- 0,
889
- 0,
890
- 0
891
- );
892
- for (const row of valueRows) compositeRows.push(...row);
893
- for (const row of bindingRows) compositeRows.push(...row);
894
- }
895
- }
896
- const translationRows = [];
897
- for (const [auIdText, bindings] of Object.entries(profile.auToBones || {})) {
898
- const auId = Number(auIdText);
899
- if (Number.isNaN(auId)) continue;
900
- for (const binding of bindings || []) {
901
- const channel = TRANSLATION_CHANNELS[binding.channel];
902
- if (channel === void 0 || binding.maxUnits === void 0) continue;
903
- const bone = findBone(binding.node);
904
- if (!bone) continue;
905
- translationRows.push(auId, Number(bone.id), channel, binding.scale, binding.maxUnits);
906
- }
907
- }
908
- const jawRow = [];
909
- const jawBinding = findAutoVisemeJawBinding(profile, model);
910
- if (jawBinding?.maxDegrees) {
911
- const bone = findBone(jawBinding.node);
912
- const channel = ROTATION_CHANNELS[jawBinding.channel];
913
- if (bone && channel !== void 0) {
914
- jawRow.push(Number(bone.id), channel, jawBinding.scale, jawBinding.maxDegrees);
915
- }
916
- }
917
- const restRows = [];
918
- for (const bone of referencedBones.values()) {
919
- const position = bone.restTransform?.position;
920
- const rotation = bone.restTransform?.rotation;
921
- restRows.push(
922
- Number(bone.id),
923
- position?.x ?? 0,
924
- position?.y ?? 0,
925
- position?.z ?? 0,
926
- rotation?.x ?? 0,
927
- rotation?.y ?? 0,
928
- rotation?.z ?? 0,
929
- rotation?.w ?? 1
930
- );
931
- }
932
- return {
933
- restTransforms: Float32Array.from(restRows),
934
- compositeAxes: Float32Array.from(compositeRows),
935
- translations: Float32Array.from(translationRows),
936
- jawBinding: Float32Array.from(jawRow),
937
- visemeJawAmounts: Float32Array.from(getVisemeJawAmounts(profile) ?? [])
938
- };
939
- }
940
- function findBoneDescriptor(profile, model, nodeKey) {
941
- const configuredName = profile.boneNodes?.[nodeKey] || nodeKey;
942
- const prefix = profile.bonePrefix ?? "";
943
- const suffix = profile.boneSuffix ?? "";
944
- const prefixedName = prefix && !configuredName.startsWith(prefix) ? `${prefix}${configuredName}` : configuredName;
945
- const fullName = suffix && !prefixedName.endsWith(suffix) ? `${prefixedName}${suffix}` : prefixedName;
946
- const candidates = /* @__PURE__ */ new Set([nodeKey, configuredName, fullName]);
947
- return model.bones.find((bone) => candidates.has(bone.name));
948
- }
949
- function findAutoVisemeJawBinding(profile, model) {
950
- const isRotation = (binding) => binding?.channel === "rx" || binding?.channel === "ry" || binding?.channel === "rz";
951
- const candidates = [
952
- profile.auToBones?.[103]?.find(isRotation),
953
- profile.auToBones?.[26]?.find(isRotation)
954
- ].filter((binding) => !!binding);
955
- return candidates.find((binding) => !!findBoneDescriptor(profile, model, binding.node)) ?? candidates[0] ?? null;
956
- }
957
764
  function unpackBoneFrameDelta(values) {
958
765
  const stride = PACKED_BONE_FRAME_DELTA_STRIDE;
959
766
  const writes = [];
@@ -994,47 +801,7 @@ function unpackMorphFrameDelta(values) {
994
801
  }
995
802
  return writes;
996
803
  }
997
- function pushAuSide(rows, auId, side, morphs, meshNames, model, profile) {
998
- for (const morph of morphs) {
999
- for (const resolved of resolveMorphTargets(model, profile, morph, meshNames)) {
1000
- rows.push(
1001
- auId,
1002
- side,
1003
- Number(resolved.mesh.id),
1004
- Number(resolved.morphTarget.id),
1005
- 1
1006
- );
1007
- }
1008
- }
1009
- }
1010
- function resolveMorphTargets(model, profile, morph, meshNames) {
1011
- const result = [];
1012
- for (const meshName of meshNames) {
1013
- const mesh = model.meshes.find((candidate) => candidate.name === meshName);
1014
- if (!mesh) continue;
1015
- const morphTargets = mesh.morphTargetIds.map((id) => model.morphTargets.find((candidate) => candidate.id === id)).filter((target2) => !!target2);
1016
- const target = typeof morph === "number" ? morphTargets.find((candidate) => candidate.hostIndex === morph) : resolveMorphTargetByName2(morphTargets, morph, profile);
1017
- if (target) {
1018
- result.push({ mesh, morphTarget: target });
1019
- }
1020
- }
1021
- return result;
1022
- }
1023
- function resolveMorphTargetByName2(targets, key, profile) {
1024
- const prefix = profile.morphPrefix || "";
1025
- const suffix = profile.morphSuffix || "";
1026
- const fullName = prefix + key + suffix;
1027
- const exact = targets.find((target) => target.name === fullName);
1028
- if (exact) return exact;
1029
- const suffixRegex = profile.suffixPattern ? new RegExp(profile.suffixPattern) : null;
1030
- if (!suffixRegex) return void 0;
1031
- return targets.find((target) => {
1032
- if (!target.name.startsWith(fullName)) return false;
1033
- const candidateSuffix = target.name.slice(fullName.length);
1034
- return candidateSuffix === "" || suffixRegex.test(candidateSuffix);
1035
- });
1036
- }
1037
804
 
1038
- export { AU_MORPH_BINDING_STRIDE, 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, VISEME_MORPH_BINDING_STRIDE, WasmRuntimeCore, compileBoneBindings, compileMorphBindings, composeTemplateSkeletonFitTransform, isTemplateSkeletonFitStatus, numericArrayToNumbers, unpackBoneFrameDelta, unpackMorphFrameDelta, validateTemplateSkeletonFitMetadata };
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 };
1039
806
  //# sourceMappingURL=core.js.map
1040
807
  //# sourceMappingURL=core.js.map