@sage-rsc/talking-head-react 1.0.11 → 1.0.14

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.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("three"),l=require("./index-DteE3mfs.cjs");function m(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const r=m(c);class h{constructor(e){this.avatar=e,this.THREE=r,this.loader=new l.FBXLoader,this.animations=new Map,this.currentAnimation=null,this.mixer=null,this.clock=new r.Clock,e&&e.armature&&(this.mixer=new r.AnimationMixer(e.armature))}async loadGestureAnimations(e){const t=l.getAnimation(e);if(!t||!t.enabled)return console.warn(`No FBX animations configured for gesture: ${e}`),[];const n=[];for(const o of t.files)try{console.log(`Loading FBX animation: ${o}`);const i=await this.loadFBXAnimation(o);i&&n.push({clip:i,config:t,filePath:o})}catch(i){console.error(`Failed to load FBX animation ${o}:`,i)}return this.animations.set(e,n),n}async loadFBXAnimation(e){const t=e.split(".").pop().toLowerCase();if(t!=="fbx"){const n=`Invalid file type for FBX animation: ${e}. Expected .fbx file, got .${t}`;return console.error(n),Promise.reject(new Error(n))}return new Promise((n,o)=>{this.loader.load(e,i=>{try{const a=i.animations;a&&a.length>0?(console.log(`Loaded ${a.length} animation clips from ${e}`),n(a[0])):(console.warn(`No animation clips found in ${e}`),n(null))}catch(a){console.error(`Error processing FBX file ${e}:`,a),o(a)}},i=>{i.total>0&&console.log(`Loading progress for ${e}: ${(i.loaded/i.total*100).toFixed(1)}%`)},i=>{console.error(`Failed to load FBX file ${e}:`,i),i.message&&i.message.includes("version number")&&(console.error("FBX Loader Error: Cannot find version number"),console.error("This usually means:"),console.error("1. The file is not a valid FBX file"),console.error("2. The file might be corrupted"),console.error("3. The file path might be incorrect"),console.error("4. The file might be a GLB file instead of FBX"),console.error("5. The file might not exist at the specified path")),o(i)})})}async playGestureAnimation(e,t=1){if(!this.mixer){console.warn("Animation mixer not initialized");return}this.stopCurrentAnimation();let n=this.animations.get(e);if(n||(n=await this.loadGestureAnimations(e)),n.length===0){console.warn(`No animations available for gesture: ${e}`);return}const o=n[Math.floor(Math.random()*n.length)],i=o.config,a=this.mixer.clipAction(o.clip);a.setEffectiveWeight(i.weight*t),a.setLoop(i.loop?r.LoopRepeat:r.LoopOnce,1/0),a.clampWhenFinished=!0,a.reset(),a.fadeIn(i.blendTime),a.play(),this.currentAnimation={action:a,gestureType:e,config:i},console.log(`Playing FBX animation: ${e} with intensity: ${t}`)}async testFBXCompatibility(e){return new Promise(t=>{this.loader.load(e,n=>{try{const o={success:!0,hasAnimations:n.animations&&n.animations.length>0,animationCount:n.animations?n.animations.length:0,hasSkeleton:n.children.some(i=>i.type==="SkinnedMesh"||i.skeleton),hasGeometry:n.children.some(i=>i.geometry&&i.geometry.attributes),duration:n.animations&&n.animations.length>0?n.animations[0].duration:0,tracks:n.animations&&n.animations.length>0?n.animations[0].tracks.length:0,boneNames:this.extractBoneNames(n),error:null};t(o)}catch(o){t({success:!1,error:o.message,hasAnimations:!1,animationCount:0,hasSkeleton:!1,hasGeometry:!1,boneNames:[]})}},n=>{console.log(`Loading ${e}: ${(n.loaded/n.total*100).toFixed(1)}%`)},n=>{t({success:!1,error:n.message||"Failed to load file",hasAnimations:!1,animationCount:0,hasSkeleton:!1,hasGeometry:!1,boneNames:[]})})})}extractBoneNames(e){const t=[];return e.traverse(n=>{(n.isBone||n.type==="Bone")&&t.push(n.name),n.skeleton&&n.skeleton.bones.forEach(o=>{t.includes(o.name)||t.push(o.name)})}),t}stopCurrentAnimation(){this.currentAnimation&&this.currentAnimation.action&&(this.currentAnimation.action.fadeOut(.2),setTimeout(()=>{this.currentAnimation.action.stop(),this.currentAnimation=null},200))}update(){this.mixer&&this.mixer.update(this.clock.getDelta())}setIntensity(e){if(this.currentAnimation&&this.currentAnimation.action){const t=this.currentAnimation.config;this.currentAnimation.action.setEffectiveWeight(t.weight*e)}}hasAnimations(e){return this.animations.has(e)&&this.animations.get(e).length>0}getLoadedGestures(){return Array.from(this.animations.keys())}async preloadAnimations(e){console.log("Preloading FBX animations...");const t=e.map(n=>this.loadGestureAnimations(n));try{await Promise.all(t),console.log("All FBX animations preloaded successfully")}catch(n){console.error("Error preloading animations:",n)}}dispose(){this.stopCurrentAnimation(),this.animations.clear(),this.mixer=null}}exports.FBXAnimationLoader=h;
@@ -1,5 +1,5 @@
1
1
  import * as s from "three";
2
- import { F as r, g as l } from "./index-B9rJ-4Pb.js";
2
+ import { F as r, g as l } from "./index-n11SsKXF.js";
3
3
  class h {
4
4
  constructor(i) {
5
5
  this.avatar = i, this.THREE = s, this.loader = new r(), this.animations = /* @__PURE__ */ new Map(), this.currentAnimation = null, this.mixer = null, this.clock = new s.Clock(), i && i.armature && (this.mixer = new s.AnimationMixer(i.armature));
@@ -14,17 +14,17 @@ class h {
14
14
  if (!t || !t.enabled)
15
15
  return console.warn(`No FBX animations configured for gesture: ${i}`), [];
16
16
  const n = [];
17
- for (const a of t.files)
17
+ for (const e of t.files)
18
18
  try {
19
- console.log(`Loading FBX animation: ${a}`);
20
- const o = await this.loadFBXAnimation(a);
19
+ console.log(`Loading FBX animation: ${e}`);
20
+ const o = await this.loadFBXAnimation(e);
21
21
  o && n.push({
22
22
  clip: o,
23
23
  config: t,
24
- filePath: a
24
+ filePath: e
25
25
  });
26
26
  } catch (o) {
27
- console.error(`Failed to load FBX animation ${a}:`, o);
27
+ console.error(`Failed to load FBX animation ${e}:`, o);
28
28
  }
29
29
  return this.animations.set(i, n), n;
30
30
  }
@@ -34,22 +34,27 @@ class h {
34
34
  * @returns {Promise<THREE.AnimationClip|null>} Animation clip or null
35
35
  */
36
36
  async loadFBXAnimation(i) {
37
- return new Promise((t, n) => {
37
+ const t = i.split(".").pop().toLowerCase();
38
+ if (t !== "fbx") {
39
+ const n = `Invalid file type for FBX animation: ${i}. Expected .fbx file, got .${t}`;
40
+ return console.error(n), Promise.reject(new Error(n));
41
+ }
42
+ return new Promise((n, e) => {
38
43
  this.loader.load(
39
44
  i,
40
- (a) => {
45
+ (o) => {
41
46
  try {
42
- const o = a.animations;
43
- o && o.length > 0 ? (console.log(`Loaded ${o.length} animation clips from ${i}`), t(o[0])) : (console.warn(`No animation clips found in ${i}`), t(null));
44
- } catch (o) {
45
- console.error(`Error processing FBX file ${i}:`, o), n(o);
47
+ const a = o.animations;
48
+ a && a.length > 0 ? (console.log(`Loaded ${a.length} animation clips from ${i}`), n(a[0])) : (console.warn(`No animation clips found in ${i}`), n(null));
49
+ } catch (a) {
50
+ console.error(`Error processing FBX file ${i}:`, a), e(a);
46
51
  }
47
52
  },
48
- (a) => {
49
- console.log(`Loading progress for ${i}: ${a.loaded / a.total * 100}%`);
53
+ (o) => {
54
+ o.total > 0 && console.log(`Loading progress for ${i}: ${(o.loaded / o.total * 100).toFixed(1)}%`);
50
55
  },
51
- (a) => {
52
- console.error(`Failed to load FBX file ${i}:`, a), n(a);
56
+ (o) => {
57
+ console.error(`Failed to load FBX file ${i}:`, o), o.message && o.message.includes("version number") && (console.error("FBX Loader Error: Cannot find version number"), console.error("This usually means:"), console.error("1. The file is not a valid FBX file"), console.error("2. The file might be corrupted"), console.error("3. The file path might be incorrect"), console.error("4. The file might be a GLB file instead of FBX"), console.error("5. The file might not exist at the specified path")), e(o);
53
58
  }
54
59
  );
55
60
  });
@@ -70,9 +75,9 @@ class h {
70
75
  console.warn(`No animations available for gesture: ${i}`);
71
76
  return;
72
77
  }
73
- const a = n[Math.floor(Math.random() * n.length)], o = a.config, e = this.mixer.clipAction(a.clip);
74
- e.setEffectiveWeight(o.weight * t), e.setLoop(o.loop ? s.LoopRepeat : s.LoopOnce, 1 / 0), e.clampWhenFinished = !0, e.reset(), e.fadeIn(o.blendTime), e.play(), this.currentAnimation = {
75
- action: e,
78
+ const e = n[Math.floor(Math.random() * n.length)], o = e.config, a = this.mixer.clipAction(e.clip);
79
+ a.setEffectiveWeight(o.weight * t), a.setLoop(o.loop ? s.LoopRepeat : s.LoopOnce, 1 / 0), a.clampWhenFinished = !0, a.reset(), a.fadeIn(o.blendTime), a.play(), this.currentAnimation = {
80
+ action: a,
76
81
  gestureType: i,
77
82
  config: o
78
83
  }, console.log(`Playing FBX animation: ${i} with intensity: ${t}`);
@@ -88,7 +93,7 @@ class h {
88
93
  i,
89
94
  (n) => {
90
95
  try {
91
- const a = {
96
+ const e = {
92
97
  success: !0,
93
98
  hasAnimations: n.animations && n.animations.length > 0,
94
99
  animationCount: n.animations ? n.animations.length : 0,
@@ -103,11 +108,11 @@ class h {
103
108
  boneNames: this.extractBoneNames(n),
104
109
  error: null
105
110
  };
106
- t(a);
107
- } catch (a) {
111
+ t(e);
112
+ } catch (e) {
108
113
  t({
109
114
  success: !1,
110
- error: a.message,
115
+ error: e.message,
111
116
  hasAnimations: !1,
112
117
  animationCount: 0,
113
118
  hasSkeleton: !1,
@@ -141,8 +146,8 @@ class h {
141
146
  extractBoneNames(i) {
142
147
  const t = [];
143
148
  return i.traverse((n) => {
144
- (n.isBone || n.type === "Bone") && t.push(n.name), n.skeleton && n.skeleton.bones.forEach((a) => {
145
- t.includes(a.name) || t.push(a.name);
149
+ (n.isBone || n.type === "Bone") && t.push(n.name), n.skeleton && n.skeleton.bones.forEach((e) => {
150
+ t.includes(e.name) || t.push(e.name);
146
151
  });
147
152
  }), t;
148
153
  }