cocos creator 3.8.7 下面是缓存材质的 handle 使用 setUniform 做材质渐变。
当我打包 webgl 平台,使用调试模式的时候下面可以完美执行 ,但是关闭调试模式就不会有渐变效果了,打印log发现 onUpdate 里面的 _tempVec3a 数值是有变化的,而且也没有报错,请问是为什么呢?
private _cacheEmissiveHandles(): void {
this._MeshMaterials = [];
this._emissiveHandles = [];
this._emissivePasses = [];
const meshRenders = this.node.getComponentsInChildren(SkinnedMeshRenderer);
for (let i = 0; i < meshRenders.length; i++) {
const materials = meshRenders[i].materials;
for (let j = 0; j < materials.length; j++) {
this._MeshMaterials.push(materials[j]);
const pass = materials[j].passes[0];
if (pass) {
const h = pass.getHandle('emissiveScale',0,gfx.Type.FLOAT3);
if (h >= 0) {
this._emissivePasses.push(pass);
this._emissiveHandles.push(h);
}
}
}
}
}
if (!this.isRed) {
this.isRed = true;
// 使用 tween 做平滑的 lerp 过渡:先从 1→0 渐变回正常色
const flashObj = { val: 1 };
tween(flashObj)
.to(0.2, { val: 0 }, {
onUpdate: () => {
this._tempVec3a.set(flashObj.val, flashObj.val, flashObj.val);
for (let i = 0; i < this._emissiveHandles.length; i++) {
this._emissivePasses[i].setUniform(this._emissiveHandles[i], this._tempVec3a);
}
}
})
.call(() => {
this.isRed = false;
})
.start();
}