From ea4bc6502dae4c4154e300b802c30cfa5cc2ef55 Mon Sep 17 00:00:00 2001 From: yinsx Date: Fri, 26 Dec 2025 15:51:59 +0800 Subject: [PATCH] init --- examples/3d/blendshapeAnimator.js | 4 ++-- examples/3d/expressionLibrary.js | 39 ++++++++++++++++++++++++++----- examples/3d/main.js | 1 + 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/examples/3d/blendshapeAnimator.js b/examples/3d/blendshapeAnimator.js index 3da5d85..3bbb1c2 100644 --- a/examples/3d/blendshapeAnimator.js +++ b/examples/3d/blendshapeAnimator.js @@ -483,8 +483,8 @@ class BlendShapeAnimator { const expressions = window.ExpressionLibrary.expressions; for (const exprKey in expressions) { const expr = expressions[exprKey]; - if (expr.shapes) { - for (const shapeName in expr.shapes) { + if (expr.blendShapes) { + for (const shapeName in expr.blendShapes) { this.morphTargetAdapter.setInfluence(shapeName, 0); delete this.idleAnimations[shapeName]; } diff --git a/examples/3d/expressionLibrary.js b/examples/3d/expressionLibrary.js index c3791cb..ae9d9de 100644 --- a/examples/3d/expressionLibrary.js +++ b/examples/3d/expressionLibrary.js @@ -26,8 +26,8 @@ const ExpressionLibrary = { smirk: { name: '冷笑', blendShapes: { - eyeblinkleft: 0.41, - eyeblinkright: 0.41, + eyesquintleft: 0.35, + eyesquintright: 0.35, mouthsmileleft: 0.3 }, duration: 2000 @@ -94,9 +94,7 @@ const ExpressionLibrary = { blendShapes: { eyesquintleft: 0.3, eyesquintright: 0.3, - mouthpucker: 0.4, - eyelookupleft: 0.3, - eyelookupright: 0.3 + mouthpucker: 0.4 }, duration: 3000 }, @@ -130,8 +128,10 @@ const ExpressionLibrary = { randomPlayer: { enabled: false, timeout: null, + durationTimeout: null, currentExpression: null, lastExpressionKey: null, + pausedEyeLook: false, intervalMin: 3000, intervalMax: 8000, @@ -146,12 +146,21 @@ const ExpressionLibrary = { clearTimeout(this.timeout); this.timeout = null; } + if (this.durationTimeout) { + clearTimeout(this.durationTimeout); + this.durationTimeout = null; + } this.reset(); }, scheduleNext: function() { if (!this.enabled) return; + // 清除之前的定时器(如果存在) + if (this.timeout) { + clearTimeout(this.timeout); + } + const delay = this.intervalMin + Math.random() * (this.intervalMax - this.intervalMin); this.timeout = setTimeout(() => { this.playRandom(); @@ -186,6 +195,12 @@ const ExpressionLibrary = { key => ExpressionLibrary.expressions[key] === expression ); + // 暂停眼球移动(避免与表情冲突) + if (window.animator && window.animator.isEyeLookEnabled) { + window.animator._stopRandomEyeLook(); + this.pausedEyeLook = true; + } + // 从主页面获取动画速度参数 const speed = window.expressionParams?.speed || 400; @@ -200,7 +215,13 @@ const ExpressionLibrary = { const duration = (window.expressionDurations && window.expressionDurations[this.lastExpressionKey]) || expression.duration; - setTimeout(() => { + // 清除之前的持续时间定时器(如果存在) + if (this.durationTimeout) { + clearTimeout(this.durationTimeout); + } + + this.durationTimeout = setTimeout(() => { + this.durationTimeout = null; this.reset(); if (!this.enabled) return; this.scheduleNext(); @@ -221,6 +242,12 @@ const ExpressionLibrary = { } this.currentExpression = null; + + // 恢复眼球移动 + if (this.pausedEyeLook && window.animator && window.animator.isEyeLookEnabled) { + window.animator._startRandomEyeLook(); + this.pausedEyeLook = false; + } } }, diff --git a/examples/3d/main.js b/examples/3d/main.js index de76b45..453947f 100644 --- a/examples/3d/main.js +++ b/examples/3d/main.js @@ -29,6 +29,7 @@ function init() { animator.setMorphTargetAdapter(morphAdapter); // 导出全局变量供表情库使用 + window.animator = animator; window.setIdleAnimation = (name, target, duration, easing) => { animator.setIdleAnimation(name, target, duration, easing); };