@sage-rsc/talking-head-react 1.4.1 → 1.4.2
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.cjs +1 -1
- package/dist/index.js +6 -6
- package/package.json +1 -1
- package/src/lib/talkinghead.mjs +15 -6
package/dist/index.js
CHANGED
|
@@ -4016,7 +4016,7 @@ class Ne {
|
|
|
4016
4016
|
default:
|
|
4017
4017
|
r += 12, u = u * r;
|
|
4018
4018
|
}
|
|
4019
|
-
a = a * r, this.controlsEnd = new g.Vector3(a, u, 0), this.cameraEnd = new g.Vector3(a, u, r).applyEuler(new g.Euler(o, l, 0)), this.cameraClock === null && (this.controls.target.copy(this.controlsEnd), this.camera.position.copy(this.cameraEnd)), this.controlsStart = this.controls.target.clone(), this.cameraStart = this.camera.position.clone(), this.cameraClock = 0;
|
|
4019
|
+
a = a * r, this.controlsEnd = new g.Vector3(a, u, 0), this.cameraEnd = new g.Vector3(a, u, r).applyEuler(new g.Euler(o, l, 0)), this.controls && (this.cameraClock === null && (this.controls.target.copy(this.controlsEnd), this.camera.position.copy(this.cameraEnd)), this.controlsStart = this.controls.target.clone(), this.cameraStart = this.camera.position.clone(), this.cameraClock = 0);
|
|
4020
4020
|
}
|
|
4021
4021
|
/**
|
|
4022
4022
|
* Change light colors and intensities.
|
|
@@ -4035,7 +4035,7 @@ class Ne {
|
|
|
4035
4035
|
* Resize avatar.
|
|
4036
4036
|
*/
|
|
4037
4037
|
onResize() {
|
|
4038
|
-
this.isAvatarOnly || (this.camera.aspect = this.nodeAvatar.clientWidth / this.nodeAvatar.clientHeight, this.camera.updateProjectionMatrix(), this.renderer.setSize(this.nodeAvatar.clientWidth, this.nodeAvatar.clientHeight), this.controls.update(), this.render());
|
|
4038
|
+
this.isAvatarOnly || (this.camera.aspect = this.nodeAvatar.clientWidth / this.nodeAvatar.clientHeight, this.camera.updateProjectionMatrix(), this.renderer.setSize(this.nodeAvatar.clientWidth, this.nodeAvatar.clientHeight), this.controls && this.controls.update(), this.render());
|
|
4039
4039
|
}
|
|
4040
4040
|
/**
|
|
4041
4041
|
* Update avatar pose.
|
|
@@ -4589,12 +4589,12 @@ class Ne {
|
|
|
4589
4589
|
})))), e > 2 * this.animFrameDur && (e = 2 * this.animFrameDur), (this.viewName !== "full" || this.isAvatarOnly) && (t = this.mtRandomized[Math.floor(Math.random() * this.mtRandomized.length)], i = this.mtAvatar[t], i.needsUpdate || Object.assign(i, { base: (this.mood.baseline[t] || 0) + (1 + l / 255) * Math.random() / 5, needsUpdate: !0 })), this.updatePoseBase(this.animClock), this.mixer && this.mixer.update(e / 1e3 * this.mixer.timeScale), this.updatePoseDelta(), (this.isSpeaking || this.isListening) && h ? l > this.volumeMax ? (this.volumeHeadBase = 0.05, Math.random() > 0.6 && (this.volumeHeadTarget = -0.05 - Math.random() / 15), this.volumeMax = l) : (this.volumeMax *= 0.92, this.volumeHeadTarget = this.volumeHeadBase - 0.9 * (this.volumeHeadBase - this.volumeHeadTarget)) : (this.volumeHeadTarget = 0, this.volumeMax = 0), t = this.volumeHeadTarget - this.volumeHeadCurrent, i = Math.abs(t), i > 1e-4 && (o = i * (this.volumeHeadEasing(Math.min(1, this.volumeHeadVelocity * e / 1e3 / i) / 2 + 0.5) - 0.5), this.volumeHeadCurrent += Math.sign(t) * Math.min(i, o)), Math.abs(this.volumeHeadCurrent) > 1e-4 && (K.setFromAxisAngle(dt, this.volumeHeadCurrent), this.objectNeck.quaternion.multiply(K)), We.setFromObject(this.armature), this.objectLeftToeBase.getWorldPosition(Re), Re.sub(this.armature.position), this.objectRightToeBase.getWorldPosition(Ie), Ie.sub(this.armature.position), this.objectHips.position.y -= We.min.y / 2, this.objectHips.position.x -= (Re.x + Ie.x) / 4, this.objectHips.position.z -= (Re.z + Ie.z) / 2, this.dynamicbones.update(e), this.fbxAnimationLoader && this.fbxAnimationLoader.update(), this.applyShoulderAdjustmentToBones(), this.opt.update && this.opt.update(e), this.updateMorphTargets(e), this.isAvatarOnly)
|
|
4590
4590
|
this.stats && this.stats.end();
|
|
4591
4591
|
else {
|
|
4592
|
-
if (this.cameraClock !== null && this.cameraClock < 1e3) {
|
|
4592
|
+
if (this.controls && this.cameraClock !== null && this.cameraClock < 1e3) {
|
|
4593
4593
|
this.cameraClock += e, this.cameraClock > 1e3 && (this.cameraClock = 1e3);
|
|
4594
4594
|
let r = new g.Spherical().setFromVector3(this.cameraStart), d = new g.Spherical().setFromVector3(this.cameraEnd);
|
|
4595
4595
|
r.phi += this.easing(this.cameraClock / 1e3) * (d.phi - r.phi), r.theta += this.easing(this.cameraClock / 1e3) * (d.theta - r.theta), r.radius += this.easing(this.cameraClock / 1e3) * (d.radius - r.radius), r.makeSafe(), this.camera.position.setFromSpherical(r), this.controlsStart.x !== this.controlsEnd.x ? this.controls.target.copy(this.controlsStart.lerp(this.controlsEnd, this.easing(this.cameraClock / 1e3))) : (r.setFromVector3(this.controlsStart), d.setFromVector3(this.controlsEnd), r.phi += this.easing(this.cameraClock / 1e3) * (d.phi - r.phi), r.theta += this.easing(this.cameraClock / 1e3) * (d.theta - r.theta), r.radius += this.easing(this.cameraClock / 1e3) * (d.radius - r.radius), r.makeSafe(), this.controls.target.setFromSpherical(r)), this.controls.update();
|
|
4596
4596
|
}
|
|
4597
|
-
this.controls.autoRotate && this.controls.update(), this.stats && this.stats.end(), this.render();
|
|
4597
|
+
this.controls && this.controls.autoRotate && this.controls.update(), this.stats && this.stats.end(), this.render();
|
|
4598
4598
|
}
|
|
4599
4599
|
}
|
|
4600
4600
|
/**
|
|
@@ -5431,14 +5431,14 @@ class Ne {
|
|
|
5431
5431
|
* @return {numeric} Autorotate speed.
|
|
5432
5432
|
*/
|
|
5433
5433
|
getAutoRotateSpeed(n) {
|
|
5434
|
-
return this.controls.autoRotateSpeed;
|
|
5434
|
+
return this.controls ? this.controls.autoRotateSpeed : 0;
|
|
5435
5435
|
}
|
|
5436
5436
|
/**
|
|
5437
5437
|
* Set autorotate.
|
|
5438
5438
|
* @param {numeric} speed Autorotate speed, e.g. value 2 = 30 secs per orbit at 60fps.
|
|
5439
5439
|
*/
|
|
5440
5440
|
setAutoRotateSpeed(n) {
|
|
5441
|
-
this.controls.autoRotateSpeed = n, this.controls.autoRotate = n > 0;
|
|
5441
|
+
this.controls && (this.controls.autoRotateSpeed = n, this.controls.autoRotate = n > 0);
|
|
5442
5442
|
}
|
|
5443
5443
|
/**
|
|
5444
5444
|
* Start animation cycle.
|
package/package.json
CHANGED
package/src/lib/talkinghead.mjs
CHANGED
|
@@ -1512,6 +1512,11 @@ class TalkingHead {
|
|
|
1512
1512
|
this.controlsEnd = new THREE.Vector3(x, y, 0);
|
|
1513
1513
|
this.cameraEnd = new THREE.Vector3(x, y, z).applyEuler( new THREE.Euler( cameraRotateX, cameraRotateY, 0 ) );
|
|
1514
1514
|
|
|
1515
|
+
// Guard against null controls (e.g., in avatarOnly mode or before initialization)
|
|
1516
|
+
if ( !this.controls ) {
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1515
1520
|
if ( this.cameraClock === null ) {
|
|
1516
1521
|
this.controls.target.copy( this.controlsEnd );
|
|
1517
1522
|
this.camera.position.copy( this.cameraEnd );
|
|
@@ -1585,7 +1590,9 @@ class TalkingHead {
|
|
|
1585
1590
|
this.camera.aspect = this.nodeAvatar.clientWidth / this.nodeAvatar.clientHeight;
|
|
1586
1591
|
this.camera.updateProjectionMatrix();
|
|
1587
1592
|
this.renderer.setSize( this.nodeAvatar.clientWidth, this.nodeAvatar.clientHeight );
|
|
1593
|
+
if ( this.controls ) {
|
|
1588
1594
|
this.controls.update();
|
|
1595
|
+
}
|
|
1589
1596
|
this.render();
|
|
1590
1597
|
}
|
|
1591
1598
|
}
|
|
@@ -2829,7 +2836,7 @@ class TalkingHead {
|
|
|
2829
2836
|
} else {
|
|
2830
2837
|
|
|
2831
2838
|
// Camera
|
|
2832
|
-
if ( this.cameraClock !== null && this.cameraClock < 1000 ) {
|
|
2839
|
+
if ( this.controls && this.cameraClock !== null && this.cameraClock < 1000 ) {
|
|
2833
2840
|
this.cameraClock += dt;
|
|
2834
2841
|
if ( this.cameraClock > 1000 ) this.cameraClock = 1000;
|
|
2835
2842
|
let s = new THREE.Spherical().setFromVector3(this.cameraStart);
|
|
@@ -2854,7 +2861,7 @@ class TalkingHead {
|
|
|
2854
2861
|
}
|
|
2855
2862
|
|
|
2856
2863
|
// Autorotate
|
|
2857
|
-
if ( this.controls.autoRotate ) this.controls.update();
|
|
2864
|
+
if ( this.controls && this.controls.autoRotate ) this.controls.update();
|
|
2858
2865
|
|
|
2859
2866
|
// Statistics end
|
|
2860
2867
|
if ( this.stats ) {
|
|
@@ -2890,7 +2897,7 @@ class TalkingHead {
|
|
|
2890
2897
|
const langLower = lang.toLowerCase();
|
|
2891
2898
|
// Use statically imported modules from LIPSYNC_MODULES
|
|
2892
2899
|
if (LIPSYNC_MODULES[langLower]) {
|
|
2893
|
-
|
|
2900
|
+
const className = 'Lipsync' + lang.charAt(0).toUpperCase() + lang.slice(1);
|
|
2894
2901
|
if (LIPSYNC_MODULES[langLower][className]) {
|
|
2895
2902
|
this.lipsync[lang] = new LIPSYNC_MODULES[langLower][className];
|
|
2896
2903
|
} else {
|
|
@@ -4358,7 +4365,7 @@ class TalkingHead {
|
|
|
4358
4365
|
* @return {numeric} Autorotate speed.
|
|
4359
4366
|
*/
|
|
4360
4367
|
getAutoRotateSpeed(k) {
|
|
4361
|
-
return this.controls.autoRotateSpeed;
|
|
4368
|
+
return this.controls ? this.controls.autoRotateSpeed : 0;
|
|
4362
4369
|
}
|
|
4363
4370
|
|
|
4364
4371
|
/**
|
|
@@ -4366,8 +4373,10 @@ class TalkingHead {
|
|
|
4366
4373
|
* @param {numeric} speed Autorotate speed, e.g. value 2 = 30 secs per orbit at 60fps.
|
|
4367
4374
|
*/
|
|
4368
4375
|
setAutoRotateSpeed(speed) {
|
|
4369
|
-
this.controls
|
|
4370
|
-
|
|
4376
|
+
if ( this.controls ) {
|
|
4377
|
+
this.controls.autoRotateSpeed = speed;
|
|
4378
|
+
this.controls.autoRotate = (speed > 0);
|
|
4379
|
+
}
|
|
4371
4380
|
}
|
|
4372
4381
|
|
|
4373
4382
|
/**
|