真实接口预热

This commit is contained in:
yinsx
2026-01-04 09:58:26 +08:00
parent b56492f80f
commit 2bd183463d
10 changed files with 386 additions and 207 deletions

View File

@ -31,10 +31,48 @@ class BabylonMorphTargetAdapter {
return totalTargets;
}
async warmupInvisible(scene) {
console.log('开始预热...');
const startTime = performance.now();
const allTargets = Object.values(this.morphTargetCache).flat();
const totalTargets = allTargets.length;
console.log(`预热 ${totalTargets} 个 morph targets`);
// 多轮预热,用不同值组合
const rounds = 10;
for (let r = 0; r < rounds; r++) {
const val = (r % 2 === 0) ? 1.0 : 0;
allTargets.forEach(mt => mt.influence = val);
scene.render();
await new Promise(r => requestAnimationFrame(r));
}
// 重置
allTargets.forEach(mt => mt.influence = 0);
scene.render();
// 等待几帧让 GPU 完全稳定
for (let i = 0; i < 5; i++) {
await new Promise(r => requestAnimationFrame(r));
}
console.log(`预热完成,耗时 ${(performance.now() - startTime).toFixed(2)}ms`);
}
warmupShaders(scene) {
console.log('开始shader预热...');
const startTime = performance.now();
// 强制同步更新所有 morph target managers
this.meshes?.forEach(mesh => {
const mtm = mesh.morphTargetManager;
if (mtm) {
mtm.enableNormalMorphing = true;
mtm.enableTangentMorphing = true;
}
});
// 预热:强制触发着色器编译
// 使用多种值组合来触发所有可能的shader变体
const testValues = [0, 0.2, 0.4, 0.6, 0.8, 1.0];