形态键预热
This commit is contained in:
@ -6,6 +6,7 @@ class BabylonMorphTargetAdapter {
|
||||
|
||||
buildCache(meshes) {
|
||||
this.morphTargetCache = {};
|
||||
this.meshes = meshes;
|
||||
let totalTargets = 0;
|
||||
|
||||
meshes.forEach(mesh => {
|
||||
@ -30,6 +31,44 @@ class BabylonMorphTargetAdapter {
|
||||
return totalTargets;
|
||||
}
|
||||
|
||||
warmupShaders(scene) {
|
||||
console.log('开始shader预热...');
|
||||
const startTime = performance.now();
|
||||
|
||||
// 预热:强制触发着色器编译
|
||||
// 使用多种值组合来触发所有可能的shader变体
|
||||
const testValues = [0, 0.2, 0.4, 0.6, 0.8, 1.0];
|
||||
|
||||
for (let pass = 0; pass < testValues.length; pass++) {
|
||||
const value = testValues[pass];
|
||||
for (const targets of Object.values(this.morphTargetCache)) {
|
||||
targets.forEach(mt => {
|
||||
mt.influence = value;
|
||||
});
|
||||
}
|
||||
|
||||
// 每次设置后都渲染,确保shader编译
|
||||
if (scene) {
|
||||
scene.render();
|
||||
}
|
||||
}
|
||||
|
||||
// 重置所有影响值
|
||||
for (const targets of Object.values(this.morphTargetCache)) {
|
||||
targets.forEach(mt => {
|
||||
mt.influence = 0;
|
||||
});
|
||||
}
|
||||
|
||||
// 最后渲染一次确保重置生效
|
||||
if (scene) {
|
||||
scene.render();
|
||||
}
|
||||
|
||||
const elapsed = performance.now() - startTime;
|
||||
console.log(`shader预热完成,耗时 ${elapsed.toFixed(2)}ms`);
|
||||
}
|
||||
|
||||
setInfluence(name, value) {
|
||||
const lowerName = name.toLowerCase();
|
||||
const targets = this.morphTargetCache[lowerName];
|
||||
|
||||
Reference in New Issue
Block a user