init
This commit is contained in:
@ -483,8 +483,8 @@ class BlendShapeAnimator {
|
|||||||
const expressions = window.ExpressionLibrary.expressions;
|
const expressions = window.ExpressionLibrary.expressions;
|
||||||
for (const exprKey in expressions) {
|
for (const exprKey in expressions) {
|
||||||
const expr = expressions[exprKey];
|
const expr = expressions[exprKey];
|
||||||
if (expr.shapes) {
|
if (expr.blendShapes) {
|
||||||
for (const shapeName in expr.shapes) {
|
for (const shapeName in expr.blendShapes) {
|
||||||
this.morphTargetAdapter.setInfluence(shapeName, 0);
|
this.morphTargetAdapter.setInfluence(shapeName, 0);
|
||||||
delete this.idleAnimations[shapeName];
|
delete this.idleAnimations[shapeName];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,8 +26,8 @@ const ExpressionLibrary = {
|
|||||||
smirk: {
|
smirk: {
|
||||||
name: '冷笑',
|
name: '冷笑',
|
||||||
blendShapes: {
|
blendShapes: {
|
||||||
eyeblinkleft: 0.41,
|
eyesquintleft: 0.35,
|
||||||
eyeblinkright: 0.41,
|
eyesquintright: 0.35,
|
||||||
mouthsmileleft: 0.3
|
mouthsmileleft: 0.3
|
||||||
},
|
},
|
||||||
duration: 2000
|
duration: 2000
|
||||||
@ -94,9 +94,7 @@ const ExpressionLibrary = {
|
|||||||
blendShapes: {
|
blendShapes: {
|
||||||
eyesquintleft: 0.3,
|
eyesquintleft: 0.3,
|
||||||
eyesquintright: 0.3,
|
eyesquintright: 0.3,
|
||||||
mouthpucker: 0.4,
|
mouthpucker: 0.4
|
||||||
eyelookupleft: 0.3,
|
|
||||||
eyelookupright: 0.3
|
|
||||||
},
|
},
|
||||||
duration: 3000
|
duration: 3000
|
||||||
},
|
},
|
||||||
@ -130,8 +128,10 @@ const ExpressionLibrary = {
|
|||||||
randomPlayer: {
|
randomPlayer: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
timeout: null,
|
timeout: null,
|
||||||
|
durationTimeout: null,
|
||||||
currentExpression: null,
|
currentExpression: null,
|
||||||
lastExpressionKey: null,
|
lastExpressionKey: null,
|
||||||
|
pausedEyeLook: false,
|
||||||
intervalMin: 3000,
|
intervalMin: 3000,
|
||||||
intervalMax: 8000,
|
intervalMax: 8000,
|
||||||
|
|
||||||
@ -146,12 +146,21 @@ const ExpressionLibrary = {
|
|||||||
clearTimeout(this.timeout);
|
clearTimeout(this.timeout);
|
||||||
this.timeout = null;
|
this.timeout = null;
|
||||||
}
|
}
|
||||||
|
if (this.durationTimeout) {
|
||||||
|
clearTimeout(this.durationTimeout);
|
||||||
|
this.durationTimeout = null;
|
||||||
|
}
|
||||||
this.reset();
|
this.reset();
|
||||||
},
|
},
|
||||||
|
|
||||||
scheduleNext: function() {
|
scheduleNext: function() {
|
||||||
if (!this.enabled) return;
|
if (!this.enabled) return;
|
||||||
|
|
||||||
|
// 清除之前的定时器(如果存在)
|
||||||
|
if (this.timeout) {
|
||||||
|
clearTimeout(this.timeout);
|
||||||
|
}
|
||||||
|
|
||||||
const delay = this.intervalMin + Math.random() * (this.intervalMax - this.intervalMin);
|
const delay = this.intervalMin + Math.random() * (this.intervalMax - this.intervalMin);
|
||||||
this.timeout = setTimeout(() => {
|
this.timeout = setTimeout(() => {
|
||||||
this.playRandom();
|
this.playRandom();
|
||||||
@ -186,6 +195,12 @@ const ExpressionLibrary = {
|
|||||||
key => ExpressionLibrary.expressions[key] === expression
|
key => ExpressionLibrary.expressions[key] === expression
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 暂停眼球移动(避免与表情冲突)
|
||||||
|
if (window.animator && window.animator.isEyeLookEnabled) {
|
||||||
|
window.animator._stopRandomEyeLook();
|
||||||
|
this.pausedEyeLook = true;
|
||||||
|
}
|
||||||
|
|
||||||
// 从主页面获取动画速度参数
|
// 从主页面获取动画速度参数
|
||||||
const speed = window.expressionParams?.speed || 400;
|
const speed = window.expressionParams?.speed || 400;
|
||||||
|
|
||||||
@ -200,7 +215,13 @@ const ExpressionLibrary = {
|
|||||||
const duration = (window.expressionDurations && window.expressionDurations[this.lastExpressionKey])
|
const duration = (window.expressionDurations && window.expressionDurations[this.lastExpressionKey])
|
||||||
|| expression.duration;
|
|| expression.duration;
|
||||||
|
|
||||||
setTimeout(() => {
|
// 清除之前的持续时间定时器(如果存在)
|
||||||
|
if (this.durationTimeout) {
|
||||||
|
clearTimeout(this.durationTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.durationTimeout = setTimeout(() => {
|
||||||
|
this.durationTimeout = null;
|
||||||
this.reset();
|
this.reset();
|
||||||
if (!this.enabled) return;
|
if (!this.enabled) return;
|
||||||
this.scheduleNext();
|
this.scheduleNext();
|
||||||
@ -221,6 +242,12 @@ const ExpressionLibrary = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.currentExpression = null;
|
this.currentExpression = null;
|
||||||
|
|
||||||
|
// 恢复眼球移动
|
||||||
|
if (this.pausedEyeLook && window.animator && window.animator.isEyeLookEnabled) {
|
||||||
|
window.animator._startRandomEyeLook();
|
||||||
|
this.pausedEyeLook = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,7 @@ function init() {
|
|||||||
animator.setMorphTargetAdapter(morphAdapter);
|
animator.setMorphTargetAdapter(morphAdapter);
|
||||||
|
|
||||||
// 导出全局变量供表情库使用
|
// 导出全局变量供表情库使用
|
||||||
|
window.animator = animator;
|
||||||
window.setIdleAnimation = (name, target, duration, easing) => {
|
window.setIdleAnimation = (name, target, duration, easing) => {
|
||||||
animator.setIdleAnimation(name, target, duration, easing);
|
animator.setIdleAnimation(name, target, duration, easing);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user