优化,增加表情幅度
This commit is contained in:
@ -36,7 +36,8 @@ class BlendShapeAnimator {
|
||||
this.expressionParams = config.expressionParams || {
|
||||
intervalMin: 3000,
|
||||
intervalMax: 8000,
|
||||
speed: 400
|
||||
speed: 400,
|
||||
strength: 1.0
|
||||
};
|
||||
|
||||
this.enabledExpressions = new Set();
|
||||
@ -269,12 +270,20 @@ class BlendShapeAnimator {
|
||||
|
||||
// 设置空闲动画
|
||||
setIdleAnimation(name, target, duration = 200, easing = 'easeOutQuad') {
|
||||
const currentValue = this.morphTargetAdapter
|
||||
? this.morphTargetAdapter.getInfluence(name) || 0
|
||||
: (this.idleAnimations[name]?.target || 0);
|
||||
|
||||
const anim = this.idleAnimations[name] || {};
|
||||
const unchanged = Math.abs(currentValue - target) < 1e-4 && Math.abs((anim.target ?? 0) - target) < 1e-4;
|
||||
|
||||
this.idleAnimations[name] = {
|
||||
target: target,
|
||||
duration: duration,
|
||||
easing: easing,
|
||||
startTime: null,
|
||||
startValue: this.idleAnimations[name]?.target || 0
|
||||
// 如果目标基本不变,保持当前起点,避免反复重新插值导致抖动
|
||||
startTime: unchanged ? performance.now() : null,
|
||||
startValue: currentValue
|
||||
};
|
||||
}
|
||||
|
||||
@ -305,7 +314,9 @@ class BlendShapeAnimator {
|
||||
if (anim.target === 0) {
|
||||
delete this.idleAnimations[name];
|
||||
} else {
|
||||
anim.startTime = null;
|
||||
// 目标保持不变,锁定在当前值,避免反复重新插值造成抖动
|
||||
anim.startValue = anim.target;
|
||||
anim.startTime = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,11 +203,11 @@ const ExpressionLibrary = {
|
||||
|
||||
// 从主页面获取动画速度参数
|
||||
const speed = window.expressionParams?.speed || 400;
|
||||
|
||||
const strength = window.expressionParams?.strength ?? 1;
|
||||
// 应用表情
|
||||
for (const [name, value] of Object.entries(expression.blendShapes)) {
|
||||
if (window.setIdleAnimation) {
|
||||
window.setIdleAnimation(name, value, speed, 'easeInOutCubic');
|
||||
window.setIdleAnimation(name, value * strength, speed, 'easeInOutCubic');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -142,11 +142,16 @@
|
||||
</div>
|
||||
<div class="param-item">
|
||||
<label>频率间隔 (秒): <span class="param-value" id="expressionIntervalValue">1-1</span></label>
|
||||
<input type="range" id="expressionIntervalMin" min="1" max="8" step="0.5" value="1"
|
||||
<input type="range" id="expressionIntervalMin" min="0" max="8" step="0.5" value="1"
|
||||
oninput="updateExpressionInterval()">
|
||||
<input type="range" id="expressionIntervalMax" min="1" max="15" step="0.5" value="1"
|
||||
<input type="range" id="expressionIntervalMax" min="0.5" max="15" step="0.5" value="1"
|
||||
oninput="updateExpressionInterval()">
|
||||
</div>
|
||||
<div class="param-item">
|
||||
<label>表情幅度: <span class="param-value" id="expressionStrengthValue">1.3</span></label>
|
||||
<input type="range" id="expressionStrength" min="0" max="2" step="0.1" value="1.0"
|
||||
oninput="updateExpressionStrength(this.value)">
|
||||
</div>
|
||||
<div class="param-item">
|
||||
<label>动画速度 (ms): <span class="param-value" id="expressionSpeedValue">400</span></label>
|
||||
<input type="range" id="expressionSpeed" min="200" max="800" step="50" value="400"
|
||||
|
||||
@ -395,6 +395,11 @@ function updateExpressionSpeed(value) {
|
||||
document.getElementById('expressionSpeedValue').textContent = value;
|
||||
}
|
||||
|
||||
function updateExpressionStrength(value) {
|
||||
animator.expressionParams.strength = parseFloat(value);
|
||||
document.getElementById('expressionStrengthValue').textContent = value;
|
||||
}
|
||||
|
||||
// 折叠/展开功能
|
||||
function toggleCollapse(event, paramGroupId) {
|
||||
event.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user