[LayaAir 2.0]3D粒子特效第一次卡顿最终解决方案
困扰了很久,又不想花时间看laya底层源码,但项目必须要解决,硬着头皮看了一天。
基本原理:lh预加载完成后,对材质进行检索,预编译shader。
private loadEffectComplete():void{
var effect:Laya.Sprite3D = Laya.loader.getRes("res/effect/2/Conventional/bullet.lh");
this.compileShader(effect);
//===========放心使用吧=================
var myeffect:Laya.Sprite3D = effect.clone();
}
private compileShader(model: any): void {
//如果是粒子特效
if (model instanceof Laya.ShuriKenParticle3D) {
var shuriKenParticle3D: Laya.ShuriKenParticle3D = model as Laya.ShuriKenParticle3D;
var render:Laya.ShurikenParticleRenderer = shuriKenParticle3D.particleRenderer
var materials: Array<any> = render.materials;
var spriteDefine:number=render._defineDatas.value;var publicDefine:number=0;var materialDefine:number=0;
for (var i: number = 0; i < materials.length; i++) {
var mater: Laya.ShurikenParticleMaterial = materials[i] as Laya.ShurikenParticleMaterial;
var marData:any = mater._defineDatas;
publicDefine = (1 & (~mater._disablePublicDefineDatas.value));
materialDefine = mater._defineDatas.value;
if(mater._shader){
Laya.Shader3D.compileShader(mater._shader._name,0,0,publicDefine,spriteDefine,materialDefine);
}
console.log(publicDefine,spriteDefine,materialDefine);
}
}
//递归获取子对象
if (model._children) {
for (var i: number = 0; i < model._children.length; i++) {
this.compileShader(model._children[i]);
}
}
}
基本原理:lh预加载完成后,对材质进行检索,预编译shader。
private loadEffectComplete():void{
var effect:Laya.Sprite3D = Laya.loader.getRes("res/effect/2/Conventional/bullet.lh");
this.compileShader(effect);
//===========放心使用吧=================
var myeffect:Laya.Sprite3D = effect.clone();
}
private compileShader(model: any): void {
//如果是粒子特效
if (model instanceof Laya.ShuriKenParticle3D) {
var shuriKenParticle3D: Laya.ShuriKenParticle3D = model as Laya.ShuriKenParticle3D;
var render:Laya.ShurikenParticleRenderer = shuriKenParticle3D.particleRenderer
var materials: Array<any> = render.materials;
var spriteDefine:number=render._defineDatas.value;var publicDefine:number=0;var materialDefine:number=0;
for (var i: number = 0; i < materials.length; i++) {
var mater: Laya.ShurikenParticleMaterial = materials[i] as Laya.ShurikenParticleMaterial;
var marData:any = mater._defineDatas;
publicDefine = (1 & (~mater._disablePublicDefineDatas.value));
materialDefine = mater._defineDatas.value;
if(mater._shader){
Laya.Shader3D.compileShader(mater._shader._name,0,0,publicDefine,spriteDefine,materialDefine);
}
console.log(publicDefine,spriteDefine,materialDefine);
}
}
//递归获取子对象
if (model._children) {
for (var i: number = 0; i < model._children.length; i++) {
this.compileShader(model._children[i]);
}
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
3 个回复
feng888668
赞同来自:
叶秋
赞同来自:
不过大佬我有个问题。为什么我加入了雾化效果后。就没用了。加入雾化后。感觉之前的设置就没用了。。
Ace1024
赞同来自: