mirror of
https://github.com/VickScarlet/lifeRestart.git
synced 2026-03-25 08:34:16 +08:00
1 line
28 KiB
JavaScript
1 line
28 KiB
JavaScript
!function(r,n){n.un,n.uns;var t=n.static,s=n.class,a=n.getset,o=(n.__newvec,laya.webgl.canvas.BlendMode),c=(laya.events.Event,laya.resource.HTMLCanvas),l=laya.utils.Handler,h=laya.webgl.utils.IndexBuffer2D,u=(laya.net.Loader,laya.maths.MathUtil),d=laya.maths.Matrix,m=laya.renders.Render,e=(laya.renders.RenderContext,laya.renders.RenderSprite,laya.webgl.shader.Shader),i=laya.display.Sprite,_=laya.utils.Stat,p=laya.resource.Texture,f=laya.utils.Utils,v=laya.webgl.shader.d2.value.Value2D,x=laya.webgl.utils.VertexBuffer2D,y=laya.webgl.WebGL,C=(laya.webgl.WebGLContext,function(){function t(){this._frameTime=0,this._emissionRate=60,this._emissionTime=0,this.minEmissionTime=1/60,this._particleTemplate=null}s(t,"laya.particle.emitter.EmitterBase");var e=t.prototype;return e.start=function(t){void 0===t&&(t=2147483647),0!=this._emissionRate&&(this._emissionTime=t)},e.stop=function(){this._emissionTime=0},e.clear=function(){this._emissionTime=0},e.emit=function(){},e.advanceTime=function(t){if(this._emissionTime-=t=void 0===t?1:t,!(this._emissionTime<0||(this._frameTime+=t,this._frameTime<this.minEmissionTime)))for(;this._frameTime>this.minEmissionTime;)this._frameTime-=this.minEmissionTime,this.emit()},a(0,e,"particleTemplate",null,function(t){this._particleTemplate=t}),a(0,e,"emissionRate",function(){return this._emissionRate},function(t){t<=0||0<(this._emissionRate=t)&&(this.minEmissionTime=1/t)}),t}()),P=(s(g,"laya.particle.ParticleData"),g.Create=function(t,e,i,a){var r=new g;r.position=e,u.scaleVector3(i,t.emitterVelocitySensitivity,g._tempVelocity);e=u.lerp(t.minHorizontalVelocity,t.maxHorizontalVelocity,Math.random()),i=Math.random()*Math.PI*2;g._tempVelocity[0]+=e*Math.cos(i),g._tempVelocity[2]+=e*Math.sin(i),g._tempVelocity[1]+=u.lerp(t.minVerticalVelocity,t.maxVerticalVelocity,Math.random()),r.velocity=g._tempVelocity,r.startColor=g._tempStartColor,r.endColor=g._tempEndColor;var n=0;if(t.disableColor)for(n=0;n<4;n++)r.startColor[n]=1,r.endColor[n]=1;else if(t.colorComponentInter)for(n=0;n<4;n++)r.startColor[n]=u.lerp(t.minStartColor[n],t.maxStartColor[n],Math.random()),r.endColor[n]=u.lerp(t.minEndColor[n],t.maxEndColor[n],Math.random());else u.lerpVector4(t.minStartColor,t.maxStartColor,Math.random(),r.startColor),u.lerpVector4(t.minEndColor,t.maxEndColor,Math.random(),r.endColor);r.sizeRotation=g._tempSizeRotation;i=Math.random();r.sizeRotation[0]=u.lerp(t.minStartSize,t.maxStartSize,i),r.sizeRotation[1]=u.lerp(t.minEndSize,t.maxEndSize,i),r.sizeRotation[2]=u.lerp(t.minRotateSpeed,t.maxRotateSpeed,Math.random()),r.radius=g._tempRadius;i=Math.random();r.radius[0]=u.lerp(t.minStartRadius,t.maxStartRadius,i),r.radius[1]=u.lerp(t.minEndRadius,t.maxEndRadius,i),r.radian=g._tempRadian,r.radian[0]=u.lerp(t.minHorizontalStartRadian,t.maxHorizontalStartRadian,Math.random()),r.radian[1]=u.lerp(t.minVerticalStartRadian,t.maxVerticalStartRadian,Math.random());i=t.useEndRadian;return r.radian[2]=i?u.lerp(t.minHorizontalEndRadian,t.maxHorizontalEndRadian,Math.random()):r.radian[0],r.radian[3]=i?u.lerp(t.minVerticalEndRadian,t.maxVerticalEndRadian,Math.random()):r.radian[1],r.durationAddScale=t.ageAddScale*Math.random(),r.time=a,r},t(g,["_tempVelocity",function(){return this._tempVelocity=new Float32Array(3)},"_tempStartColor",function(){return this._tempStartColor=new Float32Array(4)},"_tempEndColor",function(){return this._tempEndColor=new Float32Array(4)},"_tempSizeRotation",function(){return this._tempSizeRotation=new Float32Array(3)},"_tempRadius",function(){return this._tempRadius=new Float32Array(2)},"_tempRadian",function(){return this._tempRadian=new Float32Array(4)}]),g);function g(){this.position=null,this.velocity=null,this.startColor=null,this.endColor=null,this.sizeRotation=null,this.radius=null,this.radian=null,this.durationAddScale=NaN,this.time=NaN}s(R,"laya.particle.ParticleEmitter"),R.prototype.update=function(t,e){if(0<(t/=1e3)){u.subtractVector3(e,this._previousPosition,this._tempVelocity),u.scaleVector3(this._tempVelocity,1/t,this._tempVelocity);for(var i=this._timeLeftOver+t,a=-this._timeLeftOver;i>this._timeBetweenParticles;)a+=this._timeBetweenParticles,i-=this._timeBetweenParticles,u.lerpVector3(this._previousPosition,e,a/t,this._tempPosition),this._templet.addParticleArray(this._tempPosition,this._tempVelocity);this._timeLeftOver=i}this._previousPosition[0]=e[0],this._previousPosition[1]=e[1],this._previousPosition[2]=e[2]};function R(t,e,i){this._templet=null,this._timeBetweenParticles=NaN,this._previousPosition=null,this._timeLeftOver=0,this._tempVelocity=new Float32Array([0,0,0]),this._tempPosition=new Float32Array([0,0,0]),this._templet=t,this._timeBetweenParticles=1/e,this._previousPosition=i}var S=(s(V,"laya.particle.ParticleSetting"),V.checkSetting=function(t){for(var e in V._defaultSetting)t.hasOwnProperty(e)||(t[e]=V._defaultSetting[e]);t.endVelocity=+t.endVelocity,t.gravity[0]=+t.gravity[0],t.gravity[1]=+t.gravity[1],t.gravity[2]=+t.gravity[2]},t(V,["_defaultSetting",function(){return this._defaultSetting=new V}]),V);function V(){this.textureName=null,this.textureCount=1,this.maxPartices=100,this.duration=1,this.ageAddScale=0,this.emitterVelocitySensitivity=1,this.minStartSize=100,this.maxStartSize=100,this.minEndSize=100,this.maxEndSize=100,this.minHorizontalVelocity=0,this.maxHorizontalVelocity=0,this.minVerticalVelocity=0,this.maxVerticalVelocity=0,this.endVelocity=1,this.minRotateSpeed=0,this.maxRotateSpeed=0,this.minStartRadius=0,this.maxStartRadius=0,this.minEndRadius=0,this.maxEndRadius=0,this.minHorizontalStartRadian=0,this.maxHorizontalStartRadian=0,this.minVerticalStartRadian=0,this.maxVerticalStartRadian=0,this.useEndRadian=!0,this.minHorizontalEndRadian=0,this.maxHorizontalEndRadian=0,this.minVerticalEndRadian=0,this.maxVerticalEndRadian=0,this.colorComponentInter=!1,this.disableColor=!1,this.blendState=0,this.emitterType="null",this.emissionRate=0,this.sphereEmitterRadius=1,this.sphereEmitterVelocity=0,this.sphereEmitterVelocityAddVariance=0,this.ringEmitterRadius=30,this.ringEmitterVelocity=0,this.ringEmitterVelocityAddVariance=0,this.ringEmitterUp=2,this.gravity=new Float32Array([0,0,0]),this.minStartColor=new Float32Array([1,1,1,1]),this.maxStartColor=new Float32Array([1,1,1,1]),this.minEndColor=new Float32Array([1,1,1,1]),this.maxEndColor=new Float32Array([1,1,1,1]),this.pointEmitterPosition=new Float32Array([0,0,0]),this.pointEmitterPositionVariance=new Float32Array([0,0,0]),this.pointEmitterVelocity=new Float32Array([0,0,0]),this.pointEmitterVelocityAddVariance=new Float32Array([0,0,0]),this.boxEmitterCenterPosition=new Float32Array([0,0,0]),this.boxEmitterSize=new Float32Array([0,0,0]),this.boxEmitterVelocity=new Float32Array([0,0,0]),this.boxEmitterVelocityAddVariance=new Float32Array([0,0,0]),this.sphereEmitterCenterPosition=new Float32Array([0,0,0]),this.ringEmitterCenterPosition=new Float32Array([0,0,0]),this.positionVariance=new Float32Array([0,0,0])}var E=(s(A,"laya.particle.ParticleTemplateBase"),A.prototype.addParticleArray=function(t,e){},A);function A(){this.settings=null,this.texture=null}var T=function(){function t(){this.u_Duration=NaN,this.u_EndVelocity=NaN,this.u_Gravity=null,this.a_Position=null,this.a_Velocity=null,this.a_StartColor=null,this.a_EndColor=null,this.a_SizeRotation=null,this.a_Radius=null,this.a_Radian=null,this.a_AgeAddScale=NaN,this.gl_Position=null,this.v_Color=null,this.oSize=NaN,this._color=new Float32Array(4),this._position=new Float32Array(3)}s(t,"laya.particle.particleUtils.CanvasShader");var e=t.prototype;return e.getLen=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2])},e.ComputeParticlePosition=function(t,e,i,a){this._position[0]=t[0],this._position[1]=t[1],this._position[2]=t[2];for(var r=this.getLen(e),n=r*a+(r*this.u_EndVelocity-r)*a*a/2,s=this.getLen(e),o=0,o=0;o<3;o++)this._position[o]=this._position[o]+e[o]/s*n*this.u_Duration,this._position[o]+=this.u_Gravity[o]*i*a;var l=u.lerp(this.a_Radius[0],this.a_Radius[1],a),h=u.lerp(this.a_Radian[0],this.a_Radian[2],a),t=u.lerp(this.a_Radian[1],this.a_Radian[3],a),r=Math.cos(t)*l;return this._position[1]+=Math.sin(t)*l,this._position[0]+=Math.cos(h)*r,this._position[2]+=Math.sin(h)*r,new Float32Array([this._position[0],this._position[1],0,1])},e.ComputeParticleSize=function(t,e,i){return u.lerp(t,e,i)},e.ComputeParticleRotation=function(t,e){return t*e},e.ComputeParticleColor=function(t,e,i){var a=this._color;return u.lerpVector4(t,e,i,a),a[3]=a[3]*i*(1-i)*(1-i)*6.7,a},e.clamp=function(t,e,i){return t<e?e:i<t?i:t},e.getData=function(t){t*=1+this.a_AgeAddScale;var e=this.clamp(t/this.u_Duration,0,1);this.gl_Position=this.ComputeParticlePosition(this.a_Position,this.a_Velocity,t,e);var i=this.ComputeParticleSize(this.a_SizeRotation[0],this.a_SizeRotation[1],e),a=this.ComputeParticleRotation(this.a_SizeRotation[2],t);this.v_Color=this.ComputeParticleColor(this.a_StartColor,this.a_EndColor,e);t=new d,e=i/this.oSize*2;t.scale(e,e),t.rotate(a),t.setTranslate(this.gl_Position[0],-this.gl_Position[1]);a=this.v_Color[3];return[this.v_Color,a,t,this.v_Color[0]*a,this.v_Color[1]*a,this.v_Color[2]*a]},t}(),w=(s(z,"laya.particle.particleUtils.CMDParticle"),z.prototype.setCmds=function(t){this.cmds=t,this.maxIndex=t.length-1},z);function z(){this.maxIndex=0,this.cmds=null,this.id=0}var b=(s(F,"laya.particle.particleUtils.PicTool"),F.getCanvasPic=function(t,e){t=t.bitmap;var i=new c("2D"),a=i.getContext("2d");i.size(t.width,t.height);var r=e>>16&255,n=e>>8&255,s=255&e;if(m.isConchApp&&a.setFilter(r/255,n/255,s/255,0),a.drawImage(t.source,0,0),!m.isConchApp){for(var t=a.getImageData(0,0,i.width,i.height),o=t.data,l=0,h=o.length;l<h;l+=4)0!=o[l+3]&&(o[l]*=r/255,o[l+1]*=n/255,o[l+2]*=s/255);a.putImageData(t,0,0)}return i},F.getRGBPic=function(t){return[new p(F.getCanvasPic(t,16711680)),new p(F.getCanvasPic(t,65280)),new p(F.getCanvasPic(t,255))]},F);function F(){}var D=function(t){function e(t){this.setting=null,this._posRange=null,this._canvasTemplate=null,this._emitFun=null,e.__super.call(this),this.template=t}s(e,"laya.particle.emitter.Emitter2D",t);var i=e.prototype;return i.emit=function(){t.prototype.emit.call(this),null!=this._emitFun&&this._emitFun()},i.getRandom=function(t){return(2*Math.random()-1)*t},i.webGLEmit=function(){var t=new Float32Array(3);t[0]=this.getRandom(this._posRange[0]),t[1]=this.getRandom(this._posRange[1]),t[2]=this.getRandom(this._posRange[2]);var e=new Float32Array(3);e[0]=0,e[1]=0,e[2]=0,this._particleTemplate.addParticleArray(t,e)},i.canvasEmit=function(){var t=new Float32Array(3);t[0]=this.getRandom(this._posRange[0]),t[1]=this.getRandom(this._posRange[1]),t[2]=this.getRandom(this._posRange[2]);var e=new Float32Array(3);e[0]=0,e[1]=0,e[2]=0,this._particleTemplate.addParticleArray(t,e)},a(0,i,"template",function(){return this._particleTemplate},function(t){(this._particleTemplate=t)||(this._emitFun=null,this.setting=null,this._posRange=null),this.setting=t.settings,this._posRange=this.setting.positionVariance,this._particleTemplate instanceof laya.particle.ParticleTemplate2D?this._emitFun=this.webGLEmit:this._particleTemplate instanceof laya.particle.ParticleTemplateCanvas&&(this._canvasTemplate=t,this._emitFun=this.canvasEmit)}),e}(C),C=function(){function e(t){this._vertices=null,this._vertexBuffer=null,this._indexBuffer=null,this._floatCountPerVertex=29,this._firstActiveElement=0,this._firstNewElement=0,this._firstFreeElement=0,this._firstRetiredElement=0,this._currentTime=0,this._drawCounter=0,e.__super.call(this),this.settings=t}s(e,"laya.particle.ParticleTemplateWebGL",E);var t=e.prototype;return t.initialize=function(){this._vertices=new Float32Array(this.settings.maxPartices*this._floatCountPerVertex*4);for(var t,e=0;e<this.settings.maxPartices;e++){for(var i=Math.random(),a=this.settings.textureCount?1/this.settings.textureCount:1,r=NaN,r=0;r<this.settings.textureCount&&!(i<r+a);r+=a);t=e*this._floatCountPerVertex*4,this._vertices[t+0*this._floatCountPerVertex]=-1,this._vertices[t+0*this._floatCountPerVertex+1]=-1,this._vertices[t+0*this._floatCountPerVertex+2]=0,this._vertices[t+0*this._floatCountPerVertex+3]=r,this._vertices[t+ +this._floatCountPerVertex]=1,this._vertices[t+ +this._floatCountPerVertex+1]=-1,this._vertices[t+ +this._floatCountPerVertex+2]=1,this._vertices[t+ +this._floatCountPerVertex+3]=r,this._vertices[t+2*this._floatCountPerVertex]=1,this._vertices[t+2*this._floatCountPerVertex+1]=1,this._vertices[t+2*this._floatCountPerVertex+2]=1,this._vertices[t+2*this._floatCountPerVertex+3]=r+a,this._vertices[t+3*this._floatCountPerVertex]=-1,this._vertices[t+3*this._floatCountPerVertex+1]=1,this._vertices[t+3*this._floatCountPerVertex+2]=0,this._vertices[t+3*this._floatCountPerVertex+3]=r+a}},t.loadContent=function(){},t.update=function(t){this._currentTime+=t/1e3,this.retireActiveParticles(),this.freeRetiredParticles(),this._firstActiveElement==this._firstFreeElement&&(this._currentTime=0),this._firstRetiredElement==this._firstActiveElement&&(this._drawCounter=0)},t.retireActiveParticles=function(){for(var t=this.settings.duration;this._firstActiveElement!=this._firstNewElement;){var e=this._firstActiveElement*this._floatCountPerVertex*4,i=28+e,a=this._currentTime-this._vertices[i];if(1e-4+(a*=1+this._vertices[27+e])<t)break;this._vertices[i]=this._drawCounter,this._firstActiveElement++,this._firstActiveElement>=this.settings.maxPartices&&(this._firstActiveElement=0)}},t.freeRetiredParticles=function(){for(;this._firstRetiredElement!=this._firstActiveElement;){if(this._drawCounter-this._vertices[this._firstRetiredElement*this._floatCountPerVertex*4+28]<3)break;this._firstRetiredElement++,this._firstRetiredElement>=this.settings.maxPartices&&(this._firstRetiredElement=0)}},t.addNewParticlesToVertexBuffer=function(){},t.addParticleArray=function(t,e){var i=this._firstFreeElement+1;if((i=i>=this.settings.maxPartices?0:i)!==this._firstRetiredElement){for(var a=P.Create(this.settings,t,e,this._currentTime),r=this._firstFreeElement*this._floatCountPerVertex*4,n=0;n<4;n++){for(var s=0,o=0,s=0,o=4;s<3;s++)this._vertices[r+n*this._floatCountPerVertex+o+s]=a.position[s];for(s=0,o=7;s<3;s++)this._vertices[r+n*this._floatCountPerVertex+o+s]=a.velocity[s];for(s=0,o=10;s<4;s++)this._vertices[r+n*this._floatCountPerVertex+o+s]=a.startColor[s];for(s=0,o=14;s<4;s++)this._vertices[r+n*this._floatCountPerVertex+o+s]=a.endColor[s];for(s=0,o=18;s<3;s++)this._vertices[r+n*this._floatCountPerVertex+o+s]=a.sizeRotation[s];for(s=0,o=21;s<2;s++)this._vertices[r+n*this._floatCountPerVertex+o+s]=a.radius[s];for(s=0,o=23;s<4;s++)this._vertices[r+n*this._floatCountPerVertex+o+s]=a.radian[s];this._vertices[r+n*this._floatCountPerVertex+27]=a.durationAddScale,this._vertices[r+n*this._floatCountPerVertex+28]=a.time}this._firstFreeElement=i}},e}(),N=function(){function e(t){this._ready=!1,this.textureList=[],this.particleList=[],this.pX=0,this.pY=0,this.activeParticles=[],this.deadParticles=[],this.iList=[],this._maxNumParticles=0,this.textureWidth=NaN,this.dTextureWidth=NaN,this.colorChange=!0,this.step=1/60,this.canvasShader=new T,e.__super.call(this),this.settings=t,this._maxNumParticles=t.maxPartices,this.texture=new p,this.texture.on("loaded",this,this._textureLoaded),this.texture.load(t.textureName)}s(e,"laya.particle.ParticleTemplateCanvas",E);var t=e.prototype;return t._textureLoaded=function(t){this.setTexture(this.texture),this._ready=!0},t.clear=function(t){void 0===t&&(t=!0),this.deadParticles.length=0,this.activeParticles.length=0,this.textureList.length=0},t.setTexture=function(t){this.texture=t,this.textureWidth=t.width,this.dTextureWidth=1/this.textureWidth,this.pX=.5*-t.width,this.pY=.5*-t.height,this.textureList=e.changeTexture(t,this.textureList),this.particleList.length=0,this.deadParticles.length=0,this.activeParticles.length=0},t._createAParticleData=function(t,e){this.canvasShader.u_EndVelocity=this.settings.endVelocity,this.canvasShader.u_Gravity=this.settings.gravity,this.canvasShader.u_Duration=this.settings.duration,t=P.Create(this.settings,t,e,0),this.canvasShader.a_Position=t.position,this.canvasShader.a_Velocity=t.velocity,this.canvasShader.a_StartColor=t.startColor,this.canvasShader.a_EndColor=t.endColor,this.canvasShader.a_SizeRotation=t.sizeRotation,this.canvasShader.a_Radius=t.radius,this.canvasShader.a_Radian=t.radian,this.canvasShader.a_AgeAddScale=t.durationAddScale,this.canvasShader.oSize=this.textureWidth;for(var e=new w,i=0,a=this.settings.duration/(1+t.durationAddScale),r=[],i=0;i<a;i+=this.step)r.push(this.canvasShader.getData(i));return e.id=this.particleList.length,this.particleList.push(e),e.setCmds(r),e},t.addParticleArray=function(t,e){var i;this._ready&&(this.particleList.length<this._maxNumParticles?(i=this._createAParticleData(t,e),this.iList[i.id]=0,this.activeParticles.push(i)):0<this.deadParticles.length&&(i=this.deadParticles.pop(),this.iList[i.id]=0,this.activeParticles.push(i)))},t.advanceTime=function(t){if(void 0===t&&(t=1),this._ready)for(var e,i=this.activeParticles,a=this.deadParticles,r=0,t=i.length,n=0,s=this.iList,r=t-1;-1<r;r--)(n=s[(e=i[r]).id])>=e.maxIndex?(n=0,i.splice(r,1),a.push(e)):n+=1,s[e.id]=n},t.render=function(t,e,i){this._ready&&(this.activeParticles.length<1||this.textureList.length<2||(this.settings.disableColor?this.noColorRender(t,e,i):this.canvasRender(t,e,i)))},t.noColorRender=function(t,e,i){var a,r,n,s,o=this.activeParticles,l=0,h=o.length,c=this.pX,u=this.pY,d=2*-c,m=2*-u,_=(this.textureList,this.iList);for(t.translate(e,i),s=t.ctx.globalAlpha,l=0;l<h;l++)n=_[(a=o[l]).id],(a=a.cmds[n])&&((r=a[1])<=.01||(t.setAlpha(s*r),t.drawTextureWithTransform(this.texture,c,u,d,m,a[2],1)));t.setAlpha(s),t.translate(-e,-i)},t.canvasRender=function(t,e,i){var a,r,n,s,o=this.activeParticles,l=0,h=o.length,c=this.pX,u=this.pY,d=2*-c,m=2*-u,_=this.textureList,p=this.iList;for(t.translate(e,i),n=t.ctx.globalAlpha,s=t.ctx.globalCompositeOperation,t.blendMode("lighter"),l=0;l<h;l++)r=p[(a=o[l]).id],(a=a.cmds[r])&&(a[1]<=.01||(t.save(),t.transformByMatrix(a[2]),.01<a[3]&&(t.setAlpha(n*a[3]),t.drawTexture(_[0],c,u,d,m)),.01<a[4]&&(t.setAlpha(n*a[4]),t.drawTexture(_[1],c,u,d,m)),.01<a[5]&&(t.setAlpha(n*a[5]),t.drawTexture(_[2],c,u,d,m)),t.restore()));t.setAlpha(n),t.translate(-e,-i),t.blendMode(s)},e.changeTexture=function(t,e,i){return(e=e||[]).length=0,i&&i.disableColor?e.push(t,t,t):f.copyArray(e,b.getRGBPic(t)),e},e}(),L=function(i){function a(t){this._vertexBuffer2D=null,this._indexBuffer2D=null,this.x=0,this.y=0,this._blendFn=null,this._startTime=0,this.sv=new M,a.__super.call(this,t);var e=this;n.loader.load(this.settings.textureName,l.create(null,function(t){t.bitmap.enableMerageInAtlas=!1,e.texture=t})),this.sv.u_Duration=this.settings.duration,this.sv.u_Gravity=this.settings.gravity,this.sv.u_EndVelocity=this.settings.endVelocity,this._blendFn=o.fns[t.blendState],this.initialize(),this._vertexBuffer=this._vertexBuffer2D=x.create(-1,35048),this._indexBuffer=this._indexBuffer2D=h.create(35044),this.loadContent()}s(a,"laya.particle.ParticleTemplate2D",i);var t=a.prototype;return n.imps(t,{"laya.webgl.submit.ISubmit":!0}),t.getRenderType=function(){return-111},t.releaseRender=function(){},t.addParticleArray=function(t,e){t[0]+=this.x,t[1]+=this.y,i.prototype.addParticleArray.call(this,t,e)},t.loadContent=function(){for(var t=new Uint16Array(6*this.settings.maxPartices),e=0;e<this.settings.maxPartices;e++)t[6*e+0]=4*e+0,t[6*e+1]=4*e+1,t[6*e+2]=4*e+2,t[6*e+3]=4*e+0,t[6*e+4]=4*e+2,t[6*e+5]=4*e+3;this._indexBuffer2D.clear(),this._indexBuffer2D.append(t),this._indexBuffer2D.upload()},t.addNewParticlesToVertexBuffer=function(){this._vertexBuffer2D.clear(),this._vertexBuffer2D.append(this._vertices);var t=0;this._firstNewElement<this._firstFreeElement?(t=4*this._firstNewElement*this._floatCountPerVertex*4,this._vertexBuffer2D.subUpload(t,t,t+4*(this._firstFreeElement-this._firstNewElement)*this._floatCountPerVertex*4)):(t=4*this._firstNewElement*this._floatCountPerVertex*4,this._vertexBuffer2D.subUpload(t,t,t+4*(this.settings.maxPartices-this._firstNewElement)*this._floatCountPerVertex*4),0<this._firstFreeElement&&(this._vertexBuffer2D.setNeedUpload(),this._vertexBuffer2D.subUpload(0,0,4*this._firstFreeElement*this._floatCountPerVertex*4))),this._firstNewElement=this._firstFreeElement},t.renderSubmit=function(){return this.texture&&this.texture.loaded&&(this.update(n.timer.delta),this.sv.u_CurrentTime=this._currentTime,this._firstNewElement!=this._firstFreeElement&&this.addNewParticlesToVertexBuffer(),this.blend(),this._firstActiveElement!=this._firstFreeElement&&(y.mainContext,this._vertexBuffer2D.bind(this._indexBuffer2D),this.sv.u_texture=this.texture.source,this.sv.upload(),this._firstActiveElement<this._firstFreeElement?y.mainContext.drawElements(4,6*(this._firstFreeElement-this._firstActiveElement),5123,6*this._firstActiveElement*2):(y.mainContext.drawElements(4,6*(this.settings.maxPartices-this._firstActiveElement),5123,6*this._firstActiveElement*2),0<this._firstFreeElement&&y.mainContext.drawElements(4,6*this._firstFreeElement,5123,0)),_.drawCall++),this._drawCounter++),1},t.blend=function(){var t;o.activeBlendFunction!==this._blendFn&&((t=y.mainContext).enable(3042),this._blendFn(t),o.activeBlendFunction=this._blendFn)},t.dispose=function(){this._vertexBuffer2D.dispose(),this._indexBuffer2D.dispose()},a.activeBlendType=-1,a}(C),M=(s(B,"laya.particle.shader.value.ParticleShaderValue",v),B.prototype.upload=function(){this.refresh(),B.pShader.upload(this)},t(B,["pShader",function(){return this.pShader=new I}]),B);function B(){this.a_CornerTextureCoordinate=[4,5126,!1,116,0],this.a_Position=[3,5126,!1,116,16],this.a_Velocity=[3,5126,!1,116,28],this.a_StartColor=[4,5126,!1,116,40],this.a_EndColor=[4,5126,!1,116,56],this.a_SizeRotation=[3,5126,!1,116,72],this.a_Radius=[2,5126,!1,116,84],this.a_Radian=[4,5126,!1,116,92],this.a_AgeAddScale=[1,5126,!1,116,108],this.a_Time=[1,5126,!1,116,112],this.u_CurrentTime=NaN,this.u_Duration=NaN,this.u_Gravity=null,this.u_EndVelocity=NaN,this.u_texture=null,B.__super.call(this,0,0)}!function(e){function i(t){this._matrix4=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],this._particleTemplate=null,this._canvasTemplate=null,this._emitter=null,this.autoPlay=!0,i.__super.call(this),t&&this.setParticleSetting(t)}s(i,"laya.particle.Particle2D",e);var t=i.prototype;t.load=function(t){n.loader.load(t,l.create(this,this.setParticleSetting),null,"json")},t.setParticleSetting=function(e){var i=this;if(!e)return this.stop();if(S.checkSetting(e),r.ConchParticleTemplate2D&&!m.isWebGL||(this.customRenderEnable=!0),m.isWebGL)this._particleTemplate=new L(e),this.graphics._saveToCmd(m.context._drawParticle,[this._particleTemplate]);else{if(m.isConchApp&&r.ConchParticleTemplate2D){this._particleTemplate=new ConchParticleTemplate2D;var a=this;return n.loader.load(e.textureName,l.create(null,function(t){a._particleTemplate.texture=t,a._particleTemplate.settings=e,m.isConchNode?a.graphics.drawParticle(a._particleTemplate):a.graphics._saveToCmd(m.context._drawParticle,[i._particleTemplate])})),this._emitter={start:function(){}},this.play=this._particleTemplate.play.bind(this._particleTemplate),this.stop=this._particleTemplate.stop.bind(this._particleTemplate),void(this.autoPlay&&this.play())}this._particleTemplate=this._canvasTemplate=new N(e)}this._emitter?this._emitter.template=this._particleTemplate:this._emitter=new D(this._particleTemplate),this.autoPlay&&(this.emitter.start(),this.play())},t.play=function(){this.timer.frameLoop(1,this,this._loop)},t.stop=function(){this.timer.clear(this,this._loop)},t._loop=function(){this.advanceTime(1/60)},t.advanceTime=function(t){void 0===t&&(t=1),this._canvasTemplate&&this._canvasTemplate.advanceTime(t),this._emitter&&this._emitter.advanceTime(t)},t.customRender=function(t,e,i){m.isWebGL&&(this._matrix4[0]=t.ctx._curMat.a,this._matrix4[1]=t.ctx._curMat.b,this._matrix4[4]=t.ctx._curMat.c,this._matrix4[5]=t.ctx._curMat.d,this._matrix4[12]=t.ctx._curMat.tx,this._matrix4[13]=t.ctx._curMat.ty,this._particleTemplate.sv.u_mmat=this._matrix4),this._canvasTemplate&&this._canvasTemplate.render(t,e,i)},t.destroy=function(t){void 0===t&&(t=!0),this._particleTemplate instanceof laya.particle.ParticleTemplate2D&&this._particleTemplate.dispose(),e.prototype.destroy.call(this,t)},a(0,t,"url",null,function(t){this.load(t)}),a(0,t,"emitter",function(){return this._emitter})}(i);var I=(s(H,"laya.particle.shader.ParticleShader",e),t(H,["vs",function(){return this.vs="attribute vec4 a_CornerTextureCoordinate;\nattribute vec3 a_Position;\nattribute vec3 a_Velocity;\nattribute vec4 a_StartColor;\nattribute vec4 a_EndColor;\nattribute vec3 a_SizeRotation;\nattribute vec2 a_Radius;\nattribute vec4 a_Radian;\nattribute float a_AgeAddScale;\nattribute float a_Time;\n\nvarying vec4 v_Color;\nvarying vec2 v_TextureCoordinate;\n\nuniform float u_CurrentTime;\nuniform float u_Duration;\nuniform float u_EndVelocity;\nuniform vec3 u_Gravity;\n\n#ifdef PARTICLE3D\n uniform mat4 u_WorldMat;\n uniform mat4 u_View;\n uniform mat4 u_Projection;\n uniform vec2 u_ViewportScale;\n#else\n uniform vec2 size;\n uniform mat4 mmat;\n uniform mat4 u_mmat;\n#endif\n\nvec4 ComputeParticlePosition(in vec3 position, in vec3 velocity,in float age,in float normalizedAge)\n{\n\n float startVelocity = length(velocity);//起始标量速度\n float endVelocity = startVelocity * u_EndVelocity;//结束标量速度\n\n float velocityIntegral = startVelocity * normalizedAge +(endVelocity - startVelocity) * normalizedAge *normalizedAge/2.0;//计算当前速度的标量(单位空间),vt=v0*t+(1/2)*a*(t^2)\n \n vec3 addPosition = normalize(velocity) * velocityIntegral * u_Duration;//计算受自身速度影响的位置,转换标量到矢量 \n addPosition += u_Gravity * age * normalizedAge;//计算受重力影响的位置\n \n float radius=mix(a_Radius.x, a_Radius.y, normalizedAge); //计算粒子受半径和角度影响(无需计算角度和半径时,可用宏定义优化屏蔽此计算)\n float radianHorizontal =mix(a_Radian.x,a_Radian.z,normalizedAge);\n float radianVertical =mix(a_Radian.y,a_Radian.w,normalizedAge);\n \n float r =cos(radianVertical)* radius;\n addPosition.y += sin(radianVertical) * radius;\n\t\n addPosition.x += cos(radianHorizontal) *r;\n addPosition.z += sin(radianHorizontal) *r;\n \n #ifdef PARTICLE3D\n position+=addPosition;\n return u_Projection*u_View*u_WorldMat*(vec4(position, 1.0));\n #else\n addPosition.y=-addPosition.y;//2D粒子位置更新需要取负,2D粒子坐标系Y轴正向朝上\n position+=addPosition;\n return vec4(position,1.0);\n #endif\n}\n\nfloat ComputeParticleSize(in float startSize,in float endSize, in float normalizedAge)\n{ \n float size = mix(startSize, endSize, normalizedAge);\n \n\t#ifdef PARTICLE3D\n //Project the size into screen coordinates.\n return size * u_Projection[1][1];\n\t#else\n\t return size;\n\t#endif\n}\n\nmat2 ComputeParticleRotation(in float rot,in float age)\n{ \n float rotation =rot * age;\n //计算2x2旋转矩阵.\n float c = cos(rotation);\n float s = sin(rotation);\n return mat2(c, -s, s, c);\n}\n\nvec4 ComputeParticleColor(in vec4 startColor,in vec4 endColor,in float normalizedAge)\n{\n\tvec4 color=mix(startColor,endColor,normalizedAge);\n //硬编码设置,使粒子淡入很快,淡出很慢,6.7的缩放因子把置归一在0到1之间,可以谷歌x*(1-x)*(1-x)*6.7的制图表\n color.a *= normalizedAge * (1.0-normalizedAge) * (1.0-normalizedAge) * 6.7;\n \n return color;\n}\n\nvoid main()\n{\n float age = u_CurrentTime - a_Time;\n age *= 1.0 + a_AgeAddScale;\n float normalizedAge = clamp(age / u_Duration,0.0,1.0);\n gl_Position = ComputeParticlePosition(a_Position, a_Velocity, age, normalizedAge);//计算粒子位置\n float pSize = ComputeParticleSize(a_SizeRotation.x,a_SizeRotation.y, normalizedAge);\n mat2 rotation = ComputeParticleRotation(a_SizeRotation.z, age);\n\t\n #ifdef PARTICLE3D\n\tgl_Position.xy += (rotation*a_CornerTextureCoordinate.xy) * pSize * u_ViewportScale;\n #else\n mat4 mat=u_mmat*mmat;\n gl_Position=vec4((mat*gl_Position).xy,0.0,1.0);\n\tgl_Position.xy += (rotation*a_CornerTextureCoordinate.xy) * pSize*vec2(mat[0][0],mat[1][1]);\n gl_Position=vec4((gl_Position.x/size.x-0.5)*2.0,(0.5-gl_Position.y/size.y)*2.0,0.0,1.0);\n #endif\n \n v_Color = ComputeParticleColor(a_StartColor,a_EndColor, normalizedAge);\n v_TextureCoordinate =a_CornerTextureCoordinate.zw;\n}\n\n"},"ps",function(){return this.ps="#ifdef FSHIGHPRECISION\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n\nvarying vec4 v_Color;\nvarying vec2 v_TextureCoordinate;\nuniform sampler2D u_texture;\n\nvoid main()\n{\t\n\tgl_FragColor=texture2D(u_texture,v_TextureCoordinate)*v_Color;\n\tgl_FragColor.xyz *= v_Color.w;\n}"}]),H);function H(){H.__super.call(this,H.vs,H.ps,"ParticleShader")}}(window,(document,Laya)),"function"==typeof define&&define.amd&&define("laya.core",["require","exports"],function(t,e){"use strict";for(var i in Object.defineProperty(e,"__esModule",{value:!0}),Laya){var a=Laya[i];a&&a.__isclass&&(e[i]=a)}}); |