@lovelace_lol/loom3 1.0.2 → 1.0.3

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/index.js CHANGED
@@ -129,6 +129,18 @@ var BakedAnimationController = class {
129
129
  __publicField(this, "actionIdToClip", /* @__PURE__ */ new Map());
130
130
  this.host = host;
131
131
  }
132
+ getMeshNamesForAU(auId, config, explicitMeshNames) {
133
+ if (explicitMeshNames && explicitMeshNames.length > 0) {
134
+ return explicitMeshNames;
135
+ }
136
+ if (typeof this.host.getMeshNamesForAU === "function") {
137
+ return this.host.getMeshNamesForAU(auId) || [];
138
+ }
139
+ const facePart = config.auInfo?.[String(auId)]?.facePart;
140
+ if (facePart === "Tongue") return config.morphToMesh?.tongue || [];
141
+ if (facePart === "Eye") return config.morphToMesh?.eye || [];
142
+ return config.morphToMesh?.face || [];
143
+ }
132
144
  update(dtSeconds) {
133
145
  if (this.animationMixer) {
134
146
  this.animationMixer.update(dtSeconds);
@@ -429,6 +441,7 @@ var BakedAnimationController = class {
429
441
  this.addMorphTracks(tracks, visemeKey, keyframes, intensityScale, meshNames);
430
442
  }
431
443
  } else {
444
+ const auMeshNames = this.getMeshNamesForAU(auId, config, meshNames);
432
445
  const morphsBySide = config.auToMorphs[auId];
433
446
  const mixWeight = this.host.isMixedAU(auId) ? this.host.getAUMixWeight(auId) : 1;
434
447
  const leftKeys = morphsBySide?.left ?? [];
@@ -439,26 +452,26 @@ var BakedAnimationController = class {
439
452
  let effectiveScale = intensityScale * mixWeight;
440
453
  if (curveBalance > 0) effectiveScale *= 1 - curveBalance;
441
454
  if (typeof morphKey === "number") {
442
- this.addMorphIndexTracks(tracks, morphKey, keyframes, effectiveScale, meshNames);
455
+ this.addMorphIndexTracks(tracks, morphKey, keyframes, effectiveScale, auMeshNames);
443
456
  } else {
444
- this.addMorphTracks(tracks, morphKey, keyframes, effectiveScale, meshNames);
457
+ this.addMorphTracks(tracks, morphKey, keyframes, effectiveScale, auMeshNames);
445
458
  }
446
459
  }
447
460
  for (const morphKey of rightKeys) {
448
461
  let effectiveScale = intensityScale * mixWeight;
449
462
  if (curveBalance < 0) effectiveScale *= 1 + curveBalance;
450
463
  if (typeof morphKey === "number") {
451
- this.addMorphIndexTracks(tracks, morphKey, keyframes, effectiveScale, meshNames);
464
+ this.addMorphIndexTracks(tracks, morphKey, keyframes, effectiveScale, auMeshNames);
452
465
  } else {
453
- this.addMorphTracks(tracks, morphKey, keyframes, effectiveScale, meshNames);
466
+ this.addMorphTracks(tracks, morphKey, keyframes, effectiveScale, auMeshNames);
454
467
  }
455
468
  }
456
469
  for (const morphKey of centerKeys) {
457
470
  const effectiveScale = intensityScale * mixWeight;
458
471
  if (typeof morphKey === "number") {
459
- this.addMorphIndexTracks(tracks, morphKey, keyframes, effectiveScale, meshNames);
472
+ this.addMorphIndexTracks(tracks, morphKey, keyframes, effectiveScale, auMeshNames);
460
473
  } else {
461
- this.addMorphTracks(tracks, morphKey, keyframes, effectiveScale, meshNames);
474
+ this.addMorphTracks(tracks, morphKey, keyframes, effectiveScale, auMeshNames);
462
475
  }
463
476
  }
464
477
  }
@@ -846,11 +859,9 @@ var BakedAnimationController = class {
846
859
  }
847
860
  addMorphTracks(tracks, morphKey, keyframes, intensityScale, meshNames) {
848
861
  const config = this.host.getConfig();
849
- const meshes = this.host.getMeshes();
850
862
  const hasExplicitMeshes = !!(meshNames && meshNames.length > 0);
851
863
  const targetMeshNames = hasExplicitMeshes ? meshNames : config.morphToMesh?.face || [];
852
- const targetMeshes = targetMeshNames.length ? targetMeshNames.map((name) => this.host.getMeshByName(name)).filter(Boolean) : meshes;
853
- let added = false;
864
+ const targetMeshes = targetMeshNames.length ? targetMeshNames.map((name) => this.host.getMeshByName(name)).filter(Boolean) : [];
854
865
  const addTrackForMesh = (mesh) => {
855
866
  const dict = mesh.morphTargetDictionary;
856
867
  if (!dict || dict[morphKey] === void 0) return;
@@ -864,25 +875,17 @@ var BakedAnimationController = class {
864
875
  const trackName = `${mesh.uuid}.morphTargetInfluences[${morphIndex}]`;
865
876
  const track = new NumberKeyframeTrack(trackName, times, values);
866
877
  tracks.push(track);
867
- added = true;
868
878
  };
869
879
  for (const mesh of targetMeshes) {
870
880
  addTrackForMesh(mesh);
871
881
  }
872
- if (!added && !hasExplicitMeshes && targetMeshes !== meshes) {
873
- for (const mesh of meshes) {
874
- addTrackForMesh(mesh);
875
- }
876
- }
877
882
  }
878
883
  addMorphIndexTracks(tracks, morphIndex, keyframes, intensityScale, meshNames) {
879
884
  if (!Number.isInteger(morphIndex) || morphIndex < 0) return;
880
885
  const config = this.host.getConfig();
881
- const meshes = this.host.getMeshes();
882
886
  const hasExplicitMeshes = !!(meshNames && meshNames.length > 0);
883
887
  const targetMeshNames = hasExplicitMeshes ? meshNames : config.morphToMesh?.face || [];
884
- const targetMeshes = targetMeshNames.length ? targetMeshNames.map((name) => this.host.getMeshByName(name)).filter(Boolean) : meshes;
885
- let added = false;
888
+ const targetMeshes = targetMeshNames.length ? targetMeshNames.map((name) => this.host.getMeshByName(name)).filter(Boolean) : [];
886
889
  const addTrackForMesh = (mesh) => {
887
890
  const infl = mesh.morphTargetInfluences;
888
891
  if (!infl || morphIndex < 0 || morphIndex >= infl.length) return;
@@ -895,16 +898,10 @@ var BakedAnimationController = class {
895
898
  const trackName = `${mesh.uuid}.morphTargetInfluences[${morphIndex}]`;
896
899
  const track = new NumberKeyframeTrack(trackName, times, values);
897
900
  tracks.push(track);
898
- added = true;
899
901
  };
900
902
  for (const mesh of targetMeshes) {
901
903
  addTrackForMesh(mesh);
902
904
  }
903
- if (!added && !hasExplicitMeshes && targetMeshes !== meshes) {
904
- for (const mesh of meshes) {
905
- addTrackForMesh(mesh);
906
- }
907
- }
908
905
  }
909
906
  ensureMixer() {
910
907
  const model = this.host.getModel();
@@ -3508,6 +3505,7 @@ var _Loom3 = class _Loom3 {
3508
3505
  getModel: () => this.model,
3509
3506
  getMeshes: () => this.meshes,
3510
3507
  getMeshByName: (name) => this.meshByName.get(name),
3508
+ getMeshNamesForAU: (auId) => this.getMeshNamesForAU(auId),
3511
3509
  getBones: () => this.bones,
3512
3510
  getConfig: () => this.config,
3513
3511
  getCompositeRotations: () => this.compositeRotations,
@@ -3553,15 +3551,11 @@ var _Loom3 = class _Loom3 {
3553
3551
  this.resolvedFaceMeshes = this.resolveFaceMeshes(this.meshes);
3554
3552
  this.faceMesh = this.resolvedFaceMeshes.length > 0 ? this.meshByName.get(this.resolvedFaceMeshes[0]) || null : null;
3555
3553
  if (!this.config.morphToMesh?.face || this.config.morphToMesh.face.length === 0) {
3556
- const morphMeshNames = this.meshes.filter((m) => {
3557
- const infl = m.morphTargetInfluences;
3558
- const dict = m.morphTargetDictionary;
3559
- return Array.isArray(infl) && infl.length > 0 || dict && Object.keys(dict).length > 0;
3560
- }).map((m) => m.name).filter(Boolean);
3561
- if (morphMeshNames.length > 0) {
3554
+ const faceMeshNames = this.resolvedFaceMeshes.filter((name) => this.meshByName.has(name));
3555
+ if (faceMeshNames.length > 0) {
3562
3556
  this.config.morphToMesh = {
3563
3557
  ...this.config.morphToMesh,
3564
- face: Array.from(new Set(morphMeshNames))
3558
+ face: Array.from(new Set(faceMeshNames))
3565
3559
  };
3566
3560
  }
3567
3561
  }