1 |
- !function(e,t){"use strict";class r{constructor(){}static isZero(e){return Math.abs(e)<r.zeroTolerance}static nearEqual(e,t){return!!r.isZero(e-t)}static fastInvSqrt(e){return r.isZero(e)?e:1/Math.sqrt(e)}}r.zeroTolerance=1e-6,r.MaxValue=340282347e30,r.MinValue=-340282347e30,r.Deg2Rad=Math.PI/180;class i{constructor(e=0,t=0){this.x=e,this.y=t}setValue(e,t){this.x=e,this.y=t}static scale(e,t,r){r.x=e.x*t,r.y=e.y*t}fromArray(e,t=0){this.x=e[t+0],this.y=e[t+1]}cloneTo(e){var t=e;t.x=this.x,t.y=this.y}static dot(e,t){return e.x*t.x+e.y*t.y}static normalize(e,t){var r=e.x,i=e.y,a=r*r+i*i;a>0&&(a=1/Math.sqrt(a),t.x=r*a,t.y=i*a)}static scalarLength(e){var t=e.x,r=e.y;return Math.sqrt(t*t+r*r)}clone(){var e=new i;return this.cloneTo(e),e}forNativeElement(e=null){e?(this.elements=e,this.elements[0]=this.x,this.elements[1]=this.y):this.elements=new Float32Array([this.x,this.y]),i.rewriteNumProperty(this,"x",0),i.rewriteNumProperty(this,"y",1)}static rewriteNumProperty(e,t,r){Object.defineProperty(e,t,{get:function(){return this.elements[r]},set:function(e){this.elements[r]=e}})}}i.ZERO=new i(0,0),i.ONE=new i(1,1);class a{constructor(e=0,t=0,r=0,i=0){this.x=e,this.y=t,this.z=r,this.w=i}setValue(e,t,r,i){this.x=e,this.y=t,this.z=r,this.w=i}fromArray(e,t=0){this.x=e[t+0],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3]}cloneTo(e){var t=e;t.x=this.x,t.y=this.y,t.z=this.z,t.w=this.w}clone(){var e=new a;return this.cloneTo(e),e}static lerp(e,t,r,i){var a=e.x,n=e.y,s=e.z,o=e.w;i.x=a+r*(t.x-a),i.y=n+r*(t.y-n),i.z=s+r*(t.z-s),i.w=o+r*(t.w-o)}static transformByM4x4(e,t,r){var i=e.x,a=e.y,n=e.z,s=e.w,o=t.elements;r.x=i*o[0]+a*o[4]+n*o[8]+s*o[12],r.y=i*o[1]+a*o[5]+n*o[9]+s*o[13],r.z=i*o[2]+a*o[6]+n*o[10]+s*o[14],r.w=i*o[3]+a*o[7]+n*o[11]+s*o[15]}static equals(e,t){return r.nearEqual(Math.abs(e.x),Math.abs(t.x))&&r.nearEqual(Math.abs(e.y),Math.abs(t.y))&&r.nearEqual(Math.abs(e.z),Math.abs(t.z))&&r.nearEqual(Math.abs(e.w),Math.abs(t.w))}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}lengthSquared(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}static normalize(e,t){var r=e.length();if(r>0){var i=1/r;t.x=e.x*i,t.y=e.y*i,t.z=e.z*i,t.w=e.w*i}}static add(e,t,r){r.x=e.x+t.x,r.y=e.y+t.y,r.z=e.z+t.z,r.w=e.w+t.w}static subtract(e,t,r){r.x=e.x-t.x,r.y=e.y-t.y,r.z=e.z-t.z,r.w=e.w-t.w}static multiply(e,t,r){r.x=e.x*t.x,r.y=e.y*t.y,r.z=e.z*t.z,r.w=e.w*t.w}static scale(e,t,r){r.x=e.x*t,r.y=e.y*t,r.z=e.z*t,r.w=e.w*t}static Clamp(e,t,r,i){var a=e.x,n=e.y,s=e.z,o=e.w,l=t.x,_=t.y,h=t.z,c=t.w,d=r.x,u=r.y,m=r.z,f=r.w;a=(a=a>d?d:a)<l?l:a,n=(n=n>u?u:n)<_?_:n,s=(s=s>m?m:s)<h?h:s,o=(o=o>f?f:o)<c?c:o,i.x=a,i.y=n,i.z=s,i.w=o}static distanceSquared(e,t){var r=e.x-t.x,i=e.y-t.y,a=e.z-t.z,n=e.w-t.w;return r*r+i*i+a*a+n*n}static distance(e,t){var r=e.x-t.x,i=e.y-t.y,a=e.z-t.z,n=e.w-t.w;return Math.sqrt(r*r+i*i+a*a+n*n)}static dot(e,t){return e.x*t.x+e.y*t.y+e.z*t.z+e.w*t.w}static min(e,t,r){r.x=Math.min(e.x,t.x),r.y=Math.min(e.y,t.y),r.z=Math.min(e.z,t.z),r.w=Math.min(e.w,t.w)}static max(e,t,r){r.x=Math.max(e.x,t.x),r.y=Math.max(e.y,t.y),r.z=Math.max(e.z,t.z),r.w=Math.max(e.w,t.w)}forNativeElement(e=null){e?(this.elements=e,this.elements[0]=this.x,this.elements[1]=this.y,this.elements[2]=this.z,this.elements[3]=this.w):this.elements=new Float32Array([this.x,this.y,this.z,this.w]),i.rewriteNumProperty(this,"x",0),i.rewriteNumProperty(this,"y",1),i.rewriteNumProperty(this,"z",2),i.rewriteNumProperty(this,"w",3)}}a.ZERO=new a,a.ONE=new a(1,1,1,1),a.UnitX=new a(1,0,0,0),a.UnitY=new a(0,1,0,0),a.UnitZ=new a(0,0,1,0),a.UnitW=new a(0,0,0,1);class n{constructor(e=0,t=0,r=0,i=null){this.x=e,this.y=t,this.z=r}static distanceSquared(e,t){var r=e.x-t.x,i=e.y-t.y,a=e.z-t.z;return r*r+i*i+a*a}static distance(e,t){var r=e.x-t.x,i=e.y-t.y,a=e.z-t.z;return Math.sqrt(r*r+i*i+a*a)}static min(e,t,r){r.x=Math.min(e.x,t.x),r.y=Math.min(e.y,t.y),r.z=Math.min(e.z,t.z)}static max(e,t,r){r.x=Math.max(e.x,t.x),r.y=Math.max(e.y,t.y),r.z=Math.max(e.z,t.z)}static transformQuat(e,t,r){var i=e.x,a=e.y,n=e.z,s=t.x,o=t.y,l=t.z,_=t.w,h=_*i+o*n-l*a,c=_*a+l*i-s*n,d=_*n+s*a-o*i,u=-s*i-o*a-l*n;r.x=h*_+u*-s+c*-l-d*-o,r.y=c*_+u*-o+d*-s-h*-l,r.z=d*_+u*-l+h*-o-c*-s}static scalarLength(e){var t=e.x,r=e.y,i=e.z;return Math.sqrt(t*t+r*r+i*i)}static scalarLengthSquared(e){var t=e.x,r=e.y,i=e.z;return t*t+r*r+i*i}static normalize(e,t){var r=e.x,i=e.y,a=e.z,n=r*r+i*i+a*a;n>0&&(n=1/Math.sqrt(n),t.x=r*n,t.y=i*n,t.z=a*n)}static multiply(e,t,r){r.x=e.x*t.x,r.y=e.y*t.y,r.z=e.z*t.z}static scale(e,t,r){r.x=e.x*t,r.y=e.y*t,r.z=e.z*t}static lerp(e,t,r,i){var a=e.x,n=e.y,s=e.z;i.x=a+r*(t.x-a),i.y=n+r*(t.y-n),i.z=s+r*(t.z-s)}static transformV3ToV3(e,t,r){var i=n._tempVector4;n.transformV3ToV4(e,t,i),r.x=i.x,r.y=i.y,r.z=i.z}static transformV3ToV4(e,t,r){var i=e.x,a=e.y,n=e.z,s=t.elements;r.x=i*s[0]+a*s[4]+n*s[8]+s[12],r.y=i*s[1]+a*s[5]+n*s[9]+s[13],r.z=i*s[2]+a*s[6]+n*s[10]+s[14],r.w=i*s[3]+a*s[7]+n*s[11]+s[15]}static TransformNormal(e,t,r){var i=e.x,a=e.y,n=e.z,s=t.elements;r.x=i*s[0]+a*s[4]+n*s[8],r.y=i*s[1]+a*s[5]+n*s[9],r.z=i*s[2]+a*s[6]+n*s[10]}static transformCoordinate(e,t,r){var i=e.x,a=e.y,n=e.z,s=t.elements,o=i*s[3]+a*s[7]+n*s[11]+s[15];r.x=(i*s[0]+a*s[4]+n*s[8]+s[12])/o,r.y=(i*s[1]+a*s[5]+n*s[9]+s[13])/o,r.z=(i*s[2]+a*s[6]+n*s[10]+s[14])/o}static Clamp(e,t,r,i){var a=e.x,n=e.y,s=e.z,o=t.x,l=t.y,_=t.z,h=r.x,c=r.y,d=r.z;a=(a=a>h?h:a)<o?o:a,n=(n=n>c?c:n)<l?l:n,s=(s=s>d?d:s)<_?_:s,i.x=a,i.y=n,i.z=s}static add(e,t,r){r.x=e.x+t.x,r.y=e.y+t.y,r.z=e.z+t.z}static subtract(e,t,r){r.x=e.x-t.x,r.y=e.y-t.y,r.z=e.z-t.z}static cross(e,t,r){var i=e.x,a=e.y,n=e.z,s=t.x,o=t.y,l=t.z;r.x=a*l-n*o,r.y=n*s-i*l,r.z=i*o-a*s}static dot(e,t){return e.x*t.x+e.y*t.y+e.z*t.z}static equals(e,t){return r.nearEqual(e.x,t.x)&&r.nearEqual(e.y,t.y)&&r.nearEqual(e.z,t.z)}setValue(e,t,r){this.x=e,this.y=t,this.z=r}fromArray(e,t=0){this.x=e[t+0],this.y=e[t+1],this.z=e[t+2]}cloneTo(e){var t=e;t.x=this.x,t.y=this.y,t.z=this.z}clone(){var e=new n;return this.cloneTo(e),e}toDefault(){this.x=0,this.y=0,this.z=0}forNativeElement(e=null){e?(this.elements=e,this.elements[0]=this.x,this.elements[1]=this.y,this.elements[2]=this.z):this.elements=new Float32Array([this.x,this.y,this.z]),i.rewriteNumProperty(this,"x",0),i.rewriteNumProperty(this,"y",1),i.rewriteNumProperty(this,"z",2)}}var s,o,l,_,h,c,d,u,m,f,T,E;n._tempVector4=new a,n._ZERO=new n(0,0,0),n._ONE=new n(1,1,1),n._NegativeUnitX=new n(-1,0,0),n._UnitX=new n(1,0,0),n._UnitY=new n(0,1,0),n._UnitZ=new n(0,0,1),n._ForwardRH=new n(0,0,-1),n._ForwardLH=new n(0,0,1),n._Up=new n(0,1,0),(s=e.PBRRenderQuality||(e.PBRRenderQuality={}))[s.High=0]="High",s[s.Low=1]="Low";class p{constructor(){var e=this.elements=new Float32Array(9);e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1}static createRotationQuaternion(e,t){var r=e.x,i=e.y,a=e.z,n=e.w,s=r*r,o=i*i,l=a*a,_=r*i,h=a*n,c=a*r,d=i*n,u=i*a,m=r*n,f=t.elements;f[0]=1-2*(o+l),f[1]=2*(_+h),f[2]=2*(c-d),f[3]=2*(_-h),f[4]=1-2*(l+s),f[5]=2*(u+m),f[6]=2*(c+d),f[7]=2*(u-m),f[8]=1-2*(o+s)}static createFromTranslation(e,t){var r=t.elements;r[0]=1,r[1]=0,r[2]=0,r[3]=0,r[4]=1,r[5]=0,r[6]=e.x,r[7]=e.y,r[8]=1}static createFromRotation(e,t){var r=t.elements,i=Math.sin(e),a=Math.cos(e);r[0]=a,r[1]=i,r[2]=0,r[3]=-i,r[4]=a,r[5]=0,r[6]=0,r[7]=0,r[8]=1}static createFromScaling(e,t){var r=t.elements;r[0]=e.x,r[1]=0,r[2]=0,r[3]=0,r[4]=e.y,r[5]=0,r[6]=0,r[7]=0,r[8]=e.z}static createFromMatrix4x4(e,t){var r=e.elements,i=t.elements;i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[4],i[4]=r[5],i[5]=r[6],i[6]=r[8],i[7]=r[9],i[8]=r[10]}static multiply(e,t,r){var i=e.elements,a=t.elements,n=r.elements,s=i[0],o=i[1],l=i[2],_=i[3],h=i[4],c=i[5],d=i[6],u=i[7],m=i[8],f=a[0],T=a[1],E=a[2],p=a[3],g=a[4],S=a[5],R=a[6],v=a[7],x=a[8];n[0]=f*s+T*_+E*d,n[1]=f*o+T*h+E*v,n[2]=f*l+T*c+E*m,n[3]=p*s+g*_+S*d,n[4]=p*o+g*h+S*u,n[5]=p*l+g*c+S*m,n[6]=R*s+v*_+x*d,n[7]=R*o+v*h+x*u,n[8]=R*l+v*c+x*m}determinant(){var e=this.elements,t=e[0],r=e[1],i=e[2],a=e[3],n=e[4],s=e[5],o=e[6],l=e[7],_=e[8];return t*(_*n-s*l)+r*(-_*a+s*o)+i*(l*a-n*o)}translate(e,t){var r=t.elements,i=this.elements,a=i[0],n=i[1],s=i[2],o=i[3],l=i[4],_=i[5],h=i[6],c=i[7],d=i[8],u=e.x,m=e.y;r[0]=a,r[1]=n,r[2]=s,r[3]=o,r[4]=l,r[5]=_,r[6]=u*a+m*o+h,r[7]=u*n+m*l+c,r[8]=u*s+m*_+d}rotate(e,t){var r=t.elements,i=this.elements,a=i[0],n=i[1],s=i[2],o=i[3],l=i[4],_=i[5],h=i[6],c=i[7],d=i[8],u=Math.sin(e),m=Math.cos(e);r[0]=m*a+u*o,r[1]=m*n+u*l,r[2]=m*s+u*_,r[3]=m*o-u*a,r[4]=m*l-u*n,r[5]=m*_-u*s,r[6]=h,r[7]=c,r[8]=d}scale(e,t){var r=t.elements,i=this.elements,a=e.x,n=e.y;r[0]=a*i[0],r[1]=a*i[1],r[2]=a*i[2],r[3]=n*i[3],r[4]=n*i[4],r[5]=n*i[5],r[6]=i[6],r[7]=i[7],r[8]=i[8]}invert(e){var t=e.elements,r=this.elements,i=r[0],a=r[1],n=r[2],s=r[3],o=r[4],l=r[5],_=r[6],h=r[7],c=r[8],d=c*o-l*h,u=-c*s+l*_,m=h*s-o*_,f=i*d+a*u+n*m;f&&(f=1/f,t[0]=d*f,t[1]=(-c*a+n*h)*f,t[2]=(l*a-n*o)*f,t[3]=u*f,t[4]=(c*i-n*_)*f,t[5]=(-l*i+n*s)*f,t[6]=m*f,t[7]=(-h*i+a*_)*f,t[8]=(o*i-a*s)*f)}transpose(e){var t=e.elements,r=this.elements;if(e===this){var i=r[1],a=r[2],n=r[5];t[1]=r[3],t[2]=r[6],t[3]=i,t[5]=r[7],t[6]=a,t[7]=n}else t[0]=r[0],t[1]=r[3],t[2]=r[6],t[3]=r[1],t[4]=r[4],t[5]=r[7],t[6]=r[2],t[7]=r[5],t[8]=r[8]}identity(){var e=this.elements;e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1}cloneTo(e){var t,r,i;if((r=this.elements)!==(i=e.elements))for(t=0;t<9;++t)i[t]=r[t]}clone(){var e=new p;return this.cloneTo(e),e}static lookAt(e,t,r,i){n.subtract(e,t,p._tempV30),n.normalize(p._tempV30,p._tempV30),n.cross(r,p._tempV30,p._tempV31),n.normalize(p._tempV31,p._tempV31),n.cross(p._tempV30,p._tempV31,p._tempV32);var a=p._tempV30,s=p._tempV31,o=p._tempV32,l=i.elements;l[0]=s.x,l[3]=s.y,l[6]=s.z,l[1]=o.x,l[4]=o.y,l[7]=o.z,l[2]=a.x,l[5]=a.y,l[8]=a.z}}p.DEFAULT=new p,p._tempV30=new n,p._tempV31=new n,p._tempV32=new n;class g{}g.Shader3D=null,g.Scene3D=null,g.MeshRenderStaticBatchManager=null,g.MeshRenderDynamicBatchManager=null,g.SubMeshDynamicBatch=null,g.Laya3D=null,g.Matrix4x4=null,g.Physics3D=null,g.ShadowLightType=null;class S{constructor(e=0,t=0,r=0,i=1,a=null){this.x=e,this.y=t,this.z=r,this.w=i}static createFromYawPitchRoll(e,t,r,i){var a=.5*r,n=.5*t,s=.5*e,o=Math.sin(a),l=Math.cos(a),_=Math.sin(n),h=Math.cos(n),c=Math.sin(s),d=Math.cos(s);i.x=d*_*l+c*h*o,i.y=c*h*l-d*_*o,i.z=d*h*o-c*_*l,i.w=d*h*l+c*_*o}static multiply(e,t,r){var i=e.x,a=e.y,n=e.z,s=e.w,o=t.x,l=t.y,_=t.z,h=t.w,c=a*_-n*l,d=n*o-i*_,u=i*l-a*o,m=i*o+a*l+n*_;r.x=i*h+o*s+c,r.y=a*h+l*s+d,r.z=n*h+_*s+u,r.w=s*h-m}static arcTanAngle(e,t){return 0==e?1==t?Math.PI/2:-Math.PI/2:e>0?Math.atan(t/e):e<0?t>0?Math.atan(t/e)+Math.PI:Math.atan(t/e)-Math.PI:0}static angleTo(e,t,r){n.subtract(t,e,S.TEMPVector30),n.normalize(S.TEMPVector30,S.TEMPVector30),r.x=Math.asin(S.TEMPVector30.y),r.y=S.arcTanAngle(-S.TEMPVector30.z,-S.TEMPVector30.x)}static createFromAxisAngle(e,t,r){t*=.5;var i=Math.sin(t);r.x=i*e.x,r.y=i*e.y,r.z=i*e.z,r.w=Math.cos(t)}static createFromMatrix4x4(e,t){var r,i,a=e.elements,n=a[0]+a[5]+a[10];n>0?(r=Math.sqrt(n+1),t.w=.5*r,r=.5/r,t.x=(a[6]-a[9])*r,t.y=(a[8]-a[2])*r,t.z=(a[1]-a[4])*r):a[0]>=a[5]&&a[0]>=a[10]?(i=.5/(r=Math.sqrt(1+a[0]-a[5]-a[10])),t.x=.5*r,t.y=(a[1]+a[4])*i,t.z=(a[2]+a[8])*i,t.w=(a[6]-a[9])*i):a[5]>a[10]?(i=.5/(r=Math.sqrt(1+a[5]-a[0]-a[10])),t.x=(a[4]+a[1])*i,t.y=.5*r,t.z=(a[9]+a[6])*i,t.w=(a[8]-a[2])*i):(i=.5/(r=Math.sqrt(1+a[10]-a[0]-a[5])),t.x=(a[8]+a[2])*i,t.y=(a[9]+a[6])*i,t.z=.5*r,t.w=(a[1]-a[4])*i)}static slerp(e,t,r,i){var a,n,s,o,l,_=e.x,h=e.y,c=e.z,d=e.w,u=t.x,m=t.y,f=t.z,T=t.w;return(n=_*u+h*m+c*f+d*T)<0&&(n=-n,u=-u,m=-m,f=-f,T=-T),1-n>1e-6?(a=Math.acos(n),s=Math.sin(a),o=Math.sin((1-r)*a)/s,l=Math.sin(r*a)/s):(o=1-r,l=r),i.x=o*_+l*u,i.y=o*h+l*m,i.z=o*c+l*f,i.w=o*d+l*T,i}static lerp(e,t,r,i){var a=1-r;S.dot(e,t)>=0?(i.x=a*e.x+r*t.x,i.y=a*e.y+r*t.y,i.z=a*e.z+r*t.z,i.w=a*e.w+r*t.w):(i.x=a*e.x-r*t.x,i.y=a*e.y-r*t.y,i.z=a*e.z-r*t.z,i.w=a*e.w-r*t.w),i.normalize(i)}static add(e,t,r){r.x=e.x+t.x,r.y=e.y+t.y,r.z=e.z+t.z,r.w=e.w+t.w}static dot(e,t){return e.x*t.x+e.y*t.y+e.z*t.z+e.w*t.w}scaling(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,t.w=this.w*e}normalize(e){var t=this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w;t>0&&(t=1/Math.sqrt(t),e.x=this.x*t,e.y=this.y*t,e.z=this.z*t,e.w=this.w*t)}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}rotateX(e,t){e*=.5;var r=Math.sin(e),i=Math.cos(e);t.x=this.x*i+this.w*r,t.y=this.y*i+this.z*r,t.z=this.z*i-this.y*r,t.w=this.w*i-this.x*r}rotateY(e,t){e*=.5;var r=Math.sin(e),i=Math.cos(e);t.x=this.x*i-this.z*r,t.y=this.y*i+this.w*r,t.z=this.z*i+this.x*r,t.w=this.w*i-this.y*r}rotateZ(e,t){e*=.5;var r=Math.sin(e),i=Math.cos(e);t.x=this.x*i+this.y*r,t.y=this.y*i-this.x*r,t.z=this.z*i+this.w*r,t.w=this.w*i-this.z*r}getYawPitchRoll(e){n.transformQuat(n._ForwardRH,this,S.TEMPVector31),n.transformQuat(n._Up,this,S.TEMPVector32);var t=S.TEMPVector32;S.angleTo(n._ZERO,S.TEMPVector31,S.TEMPVector33);var r=S.TEMPVector33;r.x==Math.PI/2?(r.y=S.arcTanAngle(t.z,t.x),r.z=0):r.x==-Math.PI/2?(r.y=S.arcTanAngle(-t.z,-t.x),r.z=0):(g.Matrix4x4.createRotationY(-r.y,g.Matrix4x4.TEMPMatrix0),g.Matrix4x4.createRotationX(-r.x,g.Matrix4x4.TEMPMatrix1),n.transformCoordinate(S.TEMPVector32,g.Matrix4x4.TEMPMatrix0,S.TEMPVector32),n.transformCoordinate(S.TEMPVector32,g.Matrix4x4.TEMPMatrix1,S.TEMPVector32),r.z=S.arcTanAngle(t.y,-t.x)),r.y<=-Math.PI&&(r.y=Math.PI),r.z<=-Math.PI&&(r.z=Math.PI),r.y>=Math.PI&&r.z>=Math.PI&&(r.y=0,r.z=0,r.x=Math.PI-r.x);var i=e;i.x=r.y,i.y=r.x,i.z=r.z}invert(e){var t=this.x,r=this.y,i=this.z,a=this.w,n=t*t+r*r+i*i+a*a,s=n?1/n:0;e.x=-t*s,e.y=-r*s,e.z=-i*s,e.w=a*s}identity(){this.x=0,this.y=0,this.z=0,this.w=1}fromArray(e,t=0){this.x=e[t+0],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3]}cloneTo(e){this!==e&&(e.x=this.x,e.y=this.y,e.z=this.z,e.w=this.w)}clone(){var e=new S;return this.cloneTo(e),e}equals(e){return r.nearEqual(this.x,e.x)&&r.nearEqual(this.y,e.y)&&r.nearEqual(this.z,e.z)&&r.nearEqual(this.w,e.w)}static rotationLookAt(e,t,r){S.lookAt(n._ZERO,e,t,r)}static lookAt(e,t,r,i){p.lookAt(e,t,r,S._tempMatrix3x3),S.rotationMatrix(S._tempMatrix3x3,i)}lengthSquared(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}static invert(e,t){var i=e.lengthSquared();r.isZero(i)||(i=1/i,t.x=-e.x*i,t.y=-e.y*i,t.z=-e.z*i,t.w=e.w*i)}static rotationMatrix(e,t){var r,i,a=e.elements,n=a[0],s=a[1],o=a[2],l=a[3],_=a[4],h=a[5],c=a[6],d=a[7],u=a[8],m=n+_+u;m>0?(r=Math.sqrt(m+1),t.w=.5*r,r=.5/r,t.x=(h-d)*r,t.y=(c-o)*r,t.z=(s-l)*r):n>=_&&n>=u?(i=.5/(r=Math.sqrt(1+n-_-u)),t.x=.5*r,t.y=(s+l)*i,t.z=(o+c)*i,t.w=(h-d)*i):_>u?(i=.5/(r=Math.sqrt(1+_-n-u)),t.x=(l+s)*i,t.y=.5*r,t.z=(d+h)*i,t.w=(c-o)*i):(i=.5/(r=Math.sqrt(1+u-n-_)),t.x=(c+o)*i,t.y=(d+h)*i,t.z=.5*r,t.w=(s-l)*i)}forNativeElement(e=null){e?(this.elements=e,this.elements[0]=this.x,this.elements[1]=this.y,this.elements[2]=this.z,this.elements[3]=this.w):this.elements=new Float32Array([this.x,this.y,this.z,this.w]),i.rewriteNumProperty(this,"x",0),i.rewriteNumProperty(this,"y",1),i.rewriteNumProperty(this,"z",2),i.rewriteNumProperty(this,"w",3)}}S.TEMPVector30=new n,S.TEMPVector31=new n,S.TEMPVector32=new n,S.TEMPVector33=new n,S._tempMatrix3x3=new p,S.DEFAULT=new S,S.NAN=new S(NaN,NaN,NaN,NaN);class R{constructor(e=1,t=0,r=0,i=0,a=0,n=1,s=0,o=0,l=0,_=0,h=1,c=0,d=0,u=0,m=0,f=1,T=null){var E=this.elements=T||new Float32Array(16);E[0]=e,E[1]=t,E[2]=r,E[3]=i,E[4]=a,E[5]=n,E[6]=s,E[7]=o,E[8]=l,E[9]=_,E[10]=h,E[11]=c,E[12]=d,E[13]=u,E[14]=m,E[15]=f}static createRotationX(e,t){var r=t.elements,i=Math.sin(e),a=Math.cos(e);r[1]=r[2]=r[3]=r[4]=r[7]=r[8]=r[11]=r[12]=r[13]=r[14]=0,r[0]=r[15]=1,r[5]=r[10]=a,r[6]=i,r[9]=-i}static createRotationY(e,t){var r=t.elements,i=Math.sin(e),a=Math.cos(e);r[1]=r[3]=r[4]=r[6]=r[7]=r[9]=r[11]=r[12]=r[13]=r[14]=0,r[5]=r[15]=1,r[0]=r[10]=a,r[2]=-i,r[8]=i}static createRotationZ(e,t){var r=t.elements,i=Math.sin(e),a=Math.cos(e);r[2]=r[3]=r[6]=r[7]=r[8]=r[9]=r[11]=r[12]=r[13]=r[14]=0,r[10]=r[15]=1,r[0]=r[5]=a,r[1]=i,r[4]=-i}static createRotationYawPitchRoll(e,t,r,i){S.createFromYawPitchRoll(e,t,r,R._tempQuaternion),R.createRotationQuaternion(R._tempQuaternion,i)}static createRotationAxis(e,t,r){var i=e.x,a=e.y,n=e.z,s=Math.cos(t),o=Math.sin(t),l=i*i,_=a*a,h=n*n,c=i*a,d=i*n,u=a*n,m=r.elements;m[3]=m[7]=m[11]=m[12]=m[13]=m[14]=0,m[15]=1,m[0]=l+s*(1-l),m[1]=c-s*c+o*n,m[2]=d-s*d-o*a,m[4]=c-s*c-o*n,m[5]=_+s*(1-_),m[6]=u-s*u+o*i,m[8]=d-s*d+o*a,m[9]=u-s*u-o*i,m[10]=h+s*(1-h)}setRotation(e){var t=e.x,r=e.y,i=e.z,a=e.w,n=t*t,s=r*r,o=i*i,l=t*r,_=i*a,h=i*t,c=r*a,d=r*i,u=t*a,m=this.elements;m[0]=1-2*(s+o),m[1]=2*(l+_),m[2]=2*(h-c),m[4]=2*(l-_),m[5]=1-2*(o+n),m[6]=2*(d+u),m[8]=2*(h+c),m[9]=2*(d-u),m[10]=1-2*(s+n)}setPosition(e){var t=this.elements;t[12]=e.x,t[13]=e.y,t[14]=e.z}static createRotationQuaternion(e,t){var r=t.elements,i=e.x,a=e.y,n=e.z,s=e.w,o=i*i,l=a*a,_=n*n,h=i*a,c=n*s,d=n*i,u=a*s,m=a*n,f=i*s;r[3]=r[7]=r[11]=r[12]=r[13]=r[14]=0,r[15]=1,r[0]=1-2*(l+_),r[1]=2*(h+c),r[2]=2*(d-u),r[4]=2*(h-c),r[5]=1-2*(_+o),r[6]=2*(m+f),r[8]=2*(d+u),r[9]=2*(m-f),r[10]=1-2*(l+o)}static createTranslate(e,t){var r=t.elements;r[4]=r[8]=r[1]=r[9]=r[2]=r[6]=r[3]=r[7]=r[11]=0,r[0]=r[5]=r[10]=r[15]=1,r[12]=e.x,r[13]=e.y,r[14]=e.z}static createScaling(e,t){var r=t.elements;r[0]=e.x,r[5]=e.y,r[10]=e.z,r[1]=r[4]=r[8]=r[12]=r[9]=r[13]=r[2]=r[6]=r[14]=r[3]=r[7]=r[11]=0,r[15]=1}static multiply(e,t,r){var i=t.elements,a=e.elements,n=r.elements,s=i[0],o=i[1],l=i[2],_=i[3],h=i[4],c=i[5],d=i[6],u=i[7],m=i[8],f=i[9],T=i[10],E=i[11],p=i[12],g=i[13],S=i[14],R=i[15],v=a[0],x=a[1],A=a[2],I=a[3],M=a[4],D=a[5],C=a[6],y=a[7],L=a[8],O=a[9],N=a[10],P=a[11],b=a[12],w=a[13],V=a[14],B=a[15];n[0]=s*v+o*M+l*L+_*b,n[1]=s*x+o*D+l*O+_*w,n[2]=s*A+o*C+l*N+_*V,n[3]=s*I+o*y+l*P+_*B,n[4]=h*v+c*M+d*L+u*b,n[5]=h*x+c*D+d*O+u*w,n[6]=h*A+c*C+d*N+u*V,n[7]=h*I+c*y+d*P+u*B,n[8]=m*v+f*M+T*L+E*b,n[9]=m*x+f*D+T*O+E*w,n[10]=m*A+f*C+T*N+E*V,n[11]=m*I+f*y+T*P+E*B,n[12]=p*v+g*M+S*L+R*b,n[13]=p*x+g*D+S*O+R*w,n[14]=p*A+g*C+S*N+R*V,n[15]=p*I+g*y+S*P+R*B}static multiplyForNative(e,r,i){t.LayaGL.instance.matrix4x4Multiply(e.elements,r.elements,i.elements)}static createFromQuaternion(e,t){var r=t.elements,i=e.x,a=e.y,n=e.z,s=e.w,o=i+i,l=a+a,_=n+n,h=i*o,c=a*o,d=a*l,u=n*o,m=n*l,f=n*_,T=s*o,E=s*l,p=s*_;r[0]=1-d-f,r[1]=c+p,r[2]=u-E,r[3]=0,r[4]=c-p,r[5]=1-h-f,r[6]=m+T,r[7]=0,r[8]=u+E,r[9]=m-T,r[10]=1-h-d,r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1}static createAffineTransformation(e,t,r,i){var a=i.elements,n=t.x,s=t.y,o=t.z,l=t.w,_=n+n,h=s+s,c=o+o,d=n*_,u=n*h,m=n*c,f=s*h,T=s*c,E=o*c,p=l*_,g=l*h,S=l*c,R=r.x,v=r.y,x=r.z;a[0]=(1-(f+E))*R,a[1]=(u+S)*R,a[2]=(m-g)*R,a[3]=0,a[4]=(u-S)*v,a[5]=(1-(d+E))*v,a[6]=(T+p)*v,a[7]=0,a[8]=(m+g)*x,a[9]=(T-p)*x,a[10]=(1-(d+f))*x,a[11]=0,a[12]=e.x,a[13]=e.y,a[14]=e.z,a[15]=1}static createLookAt(e,t,r,i){var a=i.elements,s=R._tempVector0,o=R._tempVector1,l=R._tempVector2;n.subtract(e,t,l),n.normalize(l,l),n.cross(r,l,s),n.normalize(s,s),n.cross(l,s,o),a[3]=a[7]=a[11]=0,a[15]=1,a[0]=s.x,a[4]=s.y,a[8]=s.z,a[1]=o.x,a[5]=o.y,a[9]=o.z,a[2]=l.x,a[6]=l.y,a[10]=l.z,a[12]=-n.dot(s,e),a[13]=-n.dot(o,e),a[14]=-n.dot(l,e)}static createPerspective(e,t,r,i,a){var n=1/Math.tan(.5*e),s=r/(n/t),o=r/n;R.createPerspectiveOffCenter(-s,s,-o,o,r,i,a)}static createPerspectiveOffCenter(e,t,r,i,a,n,s){var o=s.elements,l=n/(n-a);o[1]=o[2]=o[3]=o[4]=o[6]=o[7]=o[12]=o[13]=o[15]=0,o[0]=2*a/(t-e),o[5]=2*a/(i-r),o[8]=(e+t)/(t-e),o[9]=(i+r)/(i-r),o[10]=-l,o[11]=-1,o[14]=-a*l}static createOrthoOffCenter(e,t,r,i,a,n,s){var o=s.elements,l=1/(n-a);o[1]=o[2]=o[3]=o[4]=o[6]=o[8]=o[7]=o[9]=o[11]=0,o[15]=1,o[0]=2/(t-e),o[5]=2/(i-r),o[10]=-l,o[12]=(e+t)/(e-t),o[13]=(i+r)/(r-i),o[14]=-a*l}getElementByRowColumn(e,t){if(e<0||e>3)throw new Error("row Rows and columns for matrices run from 0 to 3, inclusive.");if(t<0||t>3)throw new Error("column Rows and columns for matrices run from 0 to 3, inclusive.");return this.elements[4*e+t]}setElementByRowColumn(e,t,r){if(e<0||e>3)throw new Error("row Rows and columns for matrices run from 0 to 3, inclusive.");if(t<0||t>3)throw new Error("column Rows and columns for matrices run from 0 to 3, inclusive.");this.elements[4*e+t]=r}equalsOtherMatrix(e){var t=this.elements,i=e.elements;return r.nearEqual(t[0],i[0])&&r.nearEqual(t[1],i[1])&&r.nearEqual(t[2],i[2])&&r.nearEqual(t[3],i[3])&&r.nearEqual(t[4],i[4])&&r.nearEqual(t[5],i[5])&&r.nearEqual(t[6],i[6])&&r.nearEqual(t[7],i[7])&&r.nearEqual(t[8],i[8])&&r.nearEqual(t[9],i[9])&&r.nearEqual(t[10],i[10])&&r.nearEqual(t[11],i[11])&&r.nearEqual(t[12],i[12])&&r.nearEqual(t[13],i[13])&&r.nearEqual(t[14],i[14])&&r.nearEqual(t[15],i[15])}decomposeTransRotScale(e,t,r){var i=R._tempMatrix4x4;return this.decomposeTransRotMatScale(e,i,r)?(S.createFromMatrix4x4(i,t),!0):(t.identity(),!1)}decomposeTransRotMatScale(e,t,i){var a=this.elements,s=e,o=t.elements,l=i;s.x=a[12],s.y=a[13],s.z=a[14];var _=a[0],h=a[1],c=a[2],d=a[4],u=a[5],m=a[6],f=a[8],T=a[9],E=a[10],p=l.x=Math.sqrt(_*_+h*h+c*c),g=l.y=Math.sqrt(d*d+u*u+m*m),S=l.z=Math.sqrt(f*f+T*T+E*E);if(r.isZero(p)||r.isZero(g)||r.isZero(S))return o[1]=o[2]=o[3]=o[4]=o[6]=o[7]=o[8]=o[9]=o[11]=o[12]=o[13]=o[14]=0,o[0]=o[5]=o[10]=o[15]=1,!1;var v=R._tempVector0;v.x=f/S,v.y=T/S,v.z=E/S;var x=R._tempVector1;x.x=_/p,x.y=h/p,x.z=c/p;var A=R._tempVector2;n.cross(v,x,A);var I=R._tempVector1;return n.cross(A,v,I),o[3]=o[7]=o[11]=o[12]=o[13]=o[14]=0,o[15]=1,o[0]=I.x,o[1]=I.y,o[2]=I.z,o[4]=A.x,o[5]=A.y,o[6]=A.z,o[8]=v.x,o[9]=v.y,o[10]=v.z,o[0]*_+o[1]*h+o[2]*c<0&&(l.x=-p),o[4]*d+o[5]*u+o[6]*m<0&&(l.y=-g),o[8]*f+o[9]*T+o[10]*E<0&&(l.z=-S),!0}decomposeYawPitchRoll(e){var t=Math.asin(-this.elements[9]);e.y=t,Math.cos(t)>r.zeroTolerance?(e.z=Math.atan2(this.elements[1],this.elements[5]),e.x=Math.atan2(this.elements[8],this.elements[10])):(e.z=Math.atan2(-this.elements[4],this.elements[0]),e.x=0)}normalize(){var e=this.elements,t=e[0],r=e[1],i=e[2],a=Math.sqrt(t*t+r*r+i*i);if(!a)return e[0]=0,e[1]=0,void(e[2]=0);1!=a&&(a=1/a,e[0]=t*a,e[1]=r*a,e[2]=i*a)}transpose(){var e,t;return t=(e=this.elements)[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}invert(e){var t=this.elements,r=e.elements,i=t[0],a=t[1],n=t[2],s=t[3],o=t[4],l=t[5],_=t[6],h=t[7],c=t[8],d=t[9],u=t[10],m=t[11],f=t[12],T=t[13],E=t[14],p=t[15],g=i*l-a*o,S=i*_-n*o,R=i*h-s*o,v=a*_-n*l,x=a*h-s*l,A=n*h-s*_,I=c*T-d*f,M=c*E-u*f,D=c*p-m*f,C=d*E-u*T,y=d*p-m*T,L=u*p-m*E,O=g*L-S*y+R*C+v*D-x*M+A*I;0!==Math.abs(O)&&(O=1/O,r[0]=(l*L-_*y+h*C)*O,r[1]=(n*y-a*L-s*C)*O,r[2]=(T*A-E*x+p*v)*O,r[3]=(u*x-d*A-m*v)*O,r[4]=(_*D-o*L-h*M)*O,r[5]=(i*L-n*D+s*M)*O,r[6]=(E*R-f*A-p*S)*O,r[7]=(c*A-u*R+m*S)*O,r[8]=(o*y-l*D+h*I)*O,r[9]=(a*D-i*y-s*I)*O,r[10]=(f*x-T*R+p*g)*O,r[11]=(d*R-c*x-m*g)*O,r[12]=(l*M-o*C-_*I)*O,r[13]=(i*C-a*M+n*I)*O,r[14]=(T*S-f*v-E*g)*O,r[15]=(c*v-d*S+u*g)*O)}static billboard(e,t,i,a,s,o){n.subtract(e,t,R._tempVector0);var l=n.scalarLengthSquared(R._tempVector0);r.isZero(l)?(n.scale(s,-1,R._tempVector1),R._tempVector1.cloneTo(R._tempVector0)):n.scale(R._tempVector0,1/Math.sqrt(l),R._tempVector0),n.cross(a,R._tempVector0,R._tempVector2),n.normalize(R._tempVector2,R._tempVector2),n.cross(R._tempVector0,R._tempVector2,R._tempVector3);var _=R._tempVector2,h=R._tempVector3,c=R._tempVector0,d=e,u=o.elements;u[0]=_.x,u[1]=_.y,u[2]=_.z,u[3]=0,u[4]=h.x,u[5]=h.y,u[6]=h.z,u[7]=0,u[8]=c.x,u[9]=c.y,u[10]=c.z,u[11]=0,u[12]=d.x,u[13]=d.y,u[14]=d.z,u[15]=1}identity(){var e=this.elements;e[1]=e[2]=e[3]=e[4]=e[6]=e[7]=e[8]=e[9]=e[11]=e[12]=e[13]=e[14]=0,e[0]=e[5]=e[10]=e[15]=1}cloneTo(e){var t,r,i;if((r=this.elements)!==(i=e.elements))for(t=0;t<16;++t)i[t]=r[t]}clone(){var e=new R;return this.cloneTo(e),e}static translation(e,t){var r=t.elements;r[0]=r[5]=r[10]=r[15]=1,r[12]=e.x,r[13]=e.y,r[14]=e.z}getTranslationVector(e){var t=this.elements;e.x=t[12],e.y=t[13],e.z=t[14]}setTranslationVector(e){var t=this.elements,r=e;t[12]=r.x,t[13]=r.y,t[14]=r.z}getForward(e){var t=this.elements;e.x=-t[8],e.y=-t[9],e.z=-t[10]}setForward(e){var t=this.elements;t[8]=-e.x,t[9]=-e.y,t[10]=-e.z}getInvertFront(){this.decomposeTransRotScale(R._tempVector0,R._tempQuaternion,R._tempVector1);var e=R._tempVector1,t=e.x<0;return e.y<0&&(t=!t),e.z<0&&(t=!t),t}}R._tempMatrix4x4=new R,R.TEMPMatrix0=new R,R.TEMPMatrix1=new R,R._tempVector0=new n,R._tempVector1=new n,R._tempVector2=new n,R._tempVector3=new n,R._tempQuaternion=new S,R.DEFAULT=new R,R.ZERO=new R(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);class v{constructor(){this._scale=new n(1,1,1),this._centerMatrix=new R,this._attatched=!1,this._indexInCompound=-1,this._compoundParent=null,this._attatchedCollisionObject=null,this._referenceCount=0,this._localOffset=new n(0,0,0),this._localRotation=new S(0,0,0,1),this.needsCustomCollisionCallback=!1}static __init__(){var e=g.Physics3D._bullet;v._btScale=e.btVector3_create(1,1,1),v._btVector30=e.btVector3_create(0,0,0),v._btQuaternion0=e.btQuaternion_create(0,0,0,1),v._btTransform0=e.btTransform_create()}static _createAffineTransformation(e,t,r){var i=t.x,a=t.y,n=t.z,s=t.w,o=i+i,l=a+a,_=n+n,h=i*o,c=i*l,d=i*_,u=a*l,m=a*_,f=n*_,T=s*o,E=s*l,p=s*_;r[0]=1-(u+f),r[1]=c+p,r[2]=d-E,r[3]=0,r[4]=c-p,r[5]=1-(h+f),r[6]=m+T,r[7]=0,r[8]=d+E,r[9]=m-T,r[10]=1-(h+u),r[11]=0,r[12]=e.x,r[13]=e.y,r[14]=e.z,r[15]=1}get type(){return this._type}get localOffset(){return this._localOffset}set localOffset(e){this._localOffset=e,this._compoundParent&&this._compoundParent._updateChildTransform(this)}get localRotation(){return this._localRotation}set localRotation(e){this._localRotation=e,this._compoundParent&&this._compoundParent._updateChildTransform(this)}_setScale(e){if(this._compoundParent)this.updateLocalTransformations();else{var t=g.Physics3D._bullet;t.btVector3_setValue(v._btScale,e.x,e.y,e.z),t.btCollisionShape_setLocalScaling(this._btShape,v._btScale)}}_addReference(){this._referenceCount++}_removeReference(){this._referenceCount--}updateLocalTransformations(){if(this._compoundParent){var e=v._tempVector30;n.multiply(this.localOffset,this._scale,e),v._createAffineTransformation(e,this.localRotation,this._centerMatrix.elements)}else v._createAffineTransformation(this.localOffset,this.localRotation,this._centerMatrix.elements)}cloneTo(e){var t=e;this._localOffset.cloneTo(t.localOffset),this._localRotation.cloneTo(t.localRotation),t.localOffset=t.localOffset,t.localRotation=t.localRotation}clone(){return null}destroy(){this._btShape&&(g.Physics3D._bullet.btCollisionShape_destroy(this._btShape),this._btShape=null)}}v.SHAPEORIENTATION_UPX=0,v.SHAPEORIENTATION_UPY=1,v.SHAPEORIENTATION_UPZ=2,v.SHAPETYPES_BOX=0,v.SHAPETYPES_SPHERE=1,v.SHAPETYPES_CYLINDER=2,v.SHAPETYPES_CAPSULE=3,v.SHAPETYPES_CONVEXHULL=4,v.SHAPETYPES_COMPOUND=5,v.SHAPETYPES_STATICPLANE=6,v.SHAPETYPES_CONE=7,v._tempVector30=new n;class x extends v{constructor(e,t){super(),this._normal=e,this._offset=t,this._type=v.SHAPETYPES_STATICPLANE;var r=g.Physics3D._bullet;r.btVector3_setValue(x._btNormal,-e.x,e.y,e.z),this._btShape=r.btStaticPlaneShape_create(x._btNormal,t)}static __init__(){x._btNormal=g.Physics3D._bullet.btVector3_create(0,0,0)}clone(){var e=new x(this._normal,this._offset);return this.cloneTo(e),e}}class A extends v{constructor(){super(),this._childColliderShapes=[],this._type=v.SHAPETYPES_COMPOUND,this._btShape=g.Physics3D._bullet.btCompoundShape_create()}static __init__(){var e=g.Physics3D._bullet;A._btVector3One=e.btVector3_create(1,1,1),A._btTransform=e.btTransform_create(),A._btOffset=e.btVector3_create(0,0,0),A._btRotation=e.btQuaternion_create(0,0,0,1)}_clearChildShape(e){e._attatched=!1,e._compoundParent=null,e._indexInCompound=-1}_addReference(){}_removeReference(){}_updateChildTransform(e){var t=g.Physics3D._bullet,r=e.localOffset,i=e.localRotation,a=v._btVector30,n=v._btQuaternion0,s=v._btTransform0;t.btVector3_setValue(a,-r.x,r.y,r.z),t.btQuaternion_setValue(n,-i.x,i.y,i.z,-i.w),t.btTransform_setOrigin(s,a),t.btTransform_setRotation(s,n),t.btCompoundShape_updateChildTransform(this._btShape,e._indexInCompound,s,!0)}addChildShape(e){if(e._attatched)throw"CompoundColliderShape: this shape has attatched to other entity.";e._attatched=!0,e._compoundParent=this,e._indexInCompound=this._childColliderShapes.length,this._childColliderShapes.push(e);var t=e.localOffset,r=e.localRotation,i=g.Physics3D._bullet;i.btVector3_setValue(A._btOffset,-t.x,t.y,t.z),i.btQuaternion_setValue(A._btRotation,-r.x,r.y,r.z,-r.w),i.btTransform_setOrigin(A._btTransform,A._btOffset),i.btTransform_setRotation(A._btTransform,A._btRotation);var a=i.btCollisionShape_getLocalScaling(this._btShape);i.btCollisionShape_setLocalScaling(this._btShape,A._btVector3One),i.btCompoundShape_addChildShape(this._btShape,A._btTransform,e._btShape),i.btCollisionShape_setLocalScaling(this._btShape,a),this._attatchedCollisionObject&&(this._attatchedCollisionObject.colliderShape=this)}removeChildShape(e){if(e._compoundParent===this){var t=e._indexInCompound;this._clearChildShape(e);var r=this._childColliderShapes[this._childColliderShapes.length-1];r._indexInCompound=t,this._childColliderShapes[t]=r,this._childColliderShapes.pop(),g.Physics3D._bullet.btCompoundShape_removeChildShapeByIndex(this._btShape,t)}}clearChildShape(){for(var e=0,t=this._childColliderShapes.length;e<t;e++)this._clearChildShape(this._childColliderShapes[e]),g.Physics3D._bullet.btCompoundShape_removeChildShapeByIndex(this._btShape,0);this._childColliderShapes.length=0}getChildShapeCount(){return this._childColliderShapes.length}cloneTo(e){var t=e;t.clearChildShape();for(var r=0,i=this._childColliderShapes.length;r<i;r++)t.addChildShape(this._childColliderShapes[r].clone())}clone(){var e=new A;return this.cloneTo(e),e}destroy(){super.destroy();for(var e=0,t=this._childColliderShapes.length;e<t;e++){var r=this._childColliderShapes[e];0===r._referenceCount&&r.destroy()}}}class I extends t.EventDispatcher{constructor(e){super(),this._localPosition=new n(0,0,0),this._localRotation=new S(0,0,0,1),this._localScale=new n(1,1,1),this._localRotationEuler=new n(0,0,0),this._localMatrix=new R,this._position=new n(0,0,0),this._rotation=new S(0,0,0,1),this._scale=new n(1,1,1),this._rotationEuler=new n(0,0,0),this._worldMatrix=new R,this._children=null,this._parent=null,this._dummy=null,this._transformFlag=0,this._owner=e,this._children=[],this._setTransformFlag(I.TRANSFORM_LOCALQUATERNION|I.TRANSFORM_LOCALEULER|I.TRANSFORM_LOCALMATRIX,!1),this._setTransformFlag(I.TRANSFORM_WORLDPOSITION|I.TRANSFORM_WORLDQUATERNION|I.TRANSFORM_WORLDEULER|I.TRANSFORM_WORLDSCALE|I.TRANSFORM_WORLDMATRIX,!0)}get _isFrontFaceInvert(){var e=this.getWorldLossyScale(),t=e.x<0;return e.y<0&&(t=!t),e.z<0&&(t=!t),t}get owner(){return this._owner}get worldNeedUpdate(){return this._getTransformFlag(I.TRANSFORM_WORLDMATRIX)}get localPositionX(){return this._localPosition.x}set localPositionX(e){this._localPosition.x=e,this.localPosition=this._localPosition}get localPositionY(){return this._localPosition.y}set localPositionY(e){this._localPosition.y=e,this.localPosition=this._localPosition}get localPositionZ(){return this._localPosition.z}set localPositionZ(e){this._localPosition.z=e,this.localPosition=this._localPosition}get localPosition(){return this._localPosition}set localPosition(e){this._localPosition!==e&&e.cloneTo(this._localPosition),this._setTransformFlag(I.TRANSFORM_LOCALMATRIX,!0),this._onWorldPositionTransform()}get localRotationX(){return this.localRotation.x}set localRotationX(e){this._localRotation.x=e,this.localRotation=this._localRotation}get localRotationY(){return this.localRotation.y}set localRotationY(e){this._localRotation.y=e,this.localRotation=this._localRotation}get localRotationZ(){return this.localRotation.z}set localRotationZ(e){this._localRotation.z=e,this.localRotation=this._localRotation}get localRotationW(){return this.localRotation.w}set localRotationW(e){this._localRotation.w=e,this.localRotation=this._localRotation}get localRotation(){if(this._getTransformFlag(I.TRANSFORM_LOCALQUATERNION)){var e=this._localRotationEuler;S.createFromYawPitchRoll(e.y/I._angleToRandin,e.x/I._angleToRandin,e.z/I._angleToRandin,this._localRotation),this._setTransformFlag(I.TRANSFORM_LOCALQUATERNION,!1)}return this._localRotation}set localRotation(e){this._localRotation!==e&&e.cloneTo(this._localRotation),this._localRotation.normalize(this._localRotation),this._setTransformFlag(I.TRANSFORM_LOCALEULER|I.TRANSFORM_LOCALMATRIX,!0),this._setTransformFlag(I.TRANSFORM_LOCALQUATERNION,!1),this._onWorldRotationTransform()}get localScaleX(){return this._localScale.x}set localScaleX(e){this._localScale.x=e,this.localScale=this._localScale}get localScaleY(){return this._localScale.y}set localScaleY(e){this._localScale.y=e,this.localScale=this._localScale}get localScaleZ(){return this._localScale.z}set localScaleZ(e){this._localScale.z=e,this.localScale=this._localScale}get localScale(){return this._localScale}set localScale(e){this._localScale!==e&&e.cloneTo(this._localScale),this._setTransformFlag(I.TRANSFORM_LOCALMATRIX,!0),this._onWorldScaleTransform()}get localRotationEulerX(){return this.localRotationEuler.x}set localRotationEulerX(e){this._localRotationEuler.x=e,this.localRotationEuler=this._localRotationEuler}get localRotationEulerY(){return this.localRotationEuler.y}set localRotationEulerY(e){this._localRotationEuler.y=e,this.localRotationEuler=this._localRotationEuler}get localRotationEulerZ(){return this.localRotationEuler.z}set localRotationEulerZ(e){this._localRotationEuler.z=e,this.localRotationEuler=this._localRotationEuler}get localRotationEuler(){if(this._getTransformFlag(I.TRANSFORM_LOCALEULER)){this._localRotation.getYawPitchRoll(I._tempVector30);var e=I._tempVector30,t=this._localRotationEuler;t.x=e.y*I._angleToRandin,t.y=e.x*I._angleToRandin,t.z=e.z*I._angleToRandin,this._setTransformFlag(I.TRANSFORM_LOCALEULER,!1)}return this._localRotationEuler}set localRotationEuler(e){this._localRotationEuler!==e&&e.cloneTo(this._localRotationEuler),this._setTransformFlag(I.TRANSFORM_LOCALEULER,!1),this._setTransformFlag(I.TRANSFORM_LOCALQUATERNION|I.TRANSFORM_LOCALMATRIX,!0),this._onWorldRotationTransform()}get localMatrix(){return this._getTransformFlag(I.TRANSFORM_LOCALMATRIX)&&(R.createAffineTransformation(this._localPosition,this.localRotation,this._localScale,this._localMatrix),this._setTransformFlag(I.TRANSFORM_LOCALMATRIX,!1)),this._localMatrix}set localMatrix(e){this._localMatrix!==e&&e.cloneTo(this._localMatrix),this._localMatrix.decomposeTransRotScale(this._localPosition,this._localRotation,this._localScale),this._setTransformFlag(I.TRANSFORM_LOCALEULER,!0),this._setTransformFlag(I.TRANSFORM_LOCALMATRIX,!1),this._onWorldTransform()}get position(){if(this._getTransformFlag(I.TRANSFORM_WORLDPOSITION)){if(null!=this._parent){var e=this.worldMatrix.elements;this._position.x=e[12],this._position.y=e[13],this._position.z=e[14]}else this._localPosition.cloneTo(this._position);this._setTransformFlag(I.TRANSFORM_WORLDPOSITION,!1)}return this._position}set position(e){if(null!=this._parent){var t=I._tempMatrix0;this._parent.worldMatrix.invert(t),n.transformCoordinate(e,t,this._localPosition)}else e.cloneTo(this._localPosition);this.localPosition=this._localPosition,this._position!==e&&e.cloneTo(this._position),this._setTransformFlag(I.TRANSFORM_WORLDPOSITION,!1)}get rotation(){return this._getTransformFlag(I.TRANSFORM_WORLDQUATERNION)&&(null!=this._parent?S.multiply(this._parent.rotation,this.localRotation,this._rotation):this.localRotation.cloneTo(this._rotation),this._setTransformFlag(I.TRANSFORM_WORLDQUATERNION,!1)),this._rotation}set rotation(e){null!=this._parent?(this._parent.rotation.invert(I._tempQuaternion0),S.multiply(I._tempQuaternion0,e,this._localRotation)):e.cloneTo(this._localRotation),this.localRotation=this._localRotation,e!==this._rotation&&e.cloneTo(this._rotation),this._setTransformFlag(I.TRANSFORM_WORLDQUATERNION,!1)}get rotationEuler(){if(this._getTransformFlag(I.TRANSFORM_WORLDEULER)){this.rotation.getYawPitchRoll(I._tempVector30);var e=I._tempVector30,t=this._rotationEuler;t.x=e.y*I._angleToRandin,t.y=e.x*I._angleToRandin,t.z=e.z*I._angleToRandin,this._setTransformFlag(I.TRANSFORM_WORLDEULER,!1)}return this._rotationEuler}set rotationEuler(e){S.createFromYawPitchRoll(e.y/I._angleToRandin,e.x/I._angleToRandin,e.z/I._angleToRandin,this._rotation),this.rotation=this._rotation,this._rotationEuler!==e&&e.cloneTo(this._rotationEuler),this._setTransformFlag(I.TRANSFORM_WORLDEULER,!1)}get worldMatrix(){return this._getTransformFlag(I.TRANSFORM_WORLDMATRIX)&&(null!=this._parent?R.multiply(this._parent.worldMatrix,this.localMatrix,this._worldMatrix):this.localMatrix.cloneTo(this._worldMatrix),this._setTransformFlag(I.TRANSFORM_WORLDMATRIX,!1)),this._worldMatrix}set worldMatrix(e){null===this._parent?e.cloneTo(this._localMatrix):(this._parent.worldMatrix.invert(this._localMatrix),R.multiply(this._localMatrix,e,this._localMatrix)),this.localMatrix=this._localMatrix,this._worldMatrix!==e&&e.cloneTo(this._worldMatrix),this._setTransformFlag(I.TRANSFORM_WORLDMATRIX,!1)}_getScaleMatrix(){var e=I._tempQuaternion0,t=I._tempMatrix3x30,r=I._tempMatrix3x31,i=I._tempMatrix3x32;return p.createFromMatrix4x4(this.worldMatrix,r),this.rotation.invert(e),p.createRotationQuaternion(e,t),p.multiply(t,r,i),i}_setTransformFlag(e,t){t?this._transformFlag|=e:this._transformFlag&=~e}_getTransformFlag(e){return 0!=(this._transformFlag&e)}_setParent(e){if(this._parent!==e){if(this._parent){var t=this._parent._children,r=t.indexOf(this);t.splice(r,1)}e&&(e._children.push(this),e&&this._onWorldTransform()),this._parent=e}}_onWorldPositionRotationTransform(){if(!(this._getTransformFlag(I.TRANSFORM_WORLDMATRIX)&&this._getTransformFlag(I.TRANSFORM_WORLDPOSITION)&&this._getTransformFlag(I.TRANSFORM_WORLDQUATERNION)&&this._getTransformFlag(I.TRANSFORM_WORLDEULER))){this._setTransformFlag(I.TRANSFORM_WORLDMATRIX|I.TRANSFORM_WORLDPOSITION|I.TRANSFORM_WORLDQUATERNION|I.TRANSFORM_WORLDEULER,!0),this.event(t.Event.TRANSFORM_CHANGED,this._transformFlag);for(var e=0,r=this._children.length;e<r;e++)this._children[e]._onWorldPositionRotationTransform()}}_onWorldPositionScaleTransform(){if(!this._getTransformFlag(I.TRANSFORM_WORLDMATRIX)||!this._getTransformFlag(I.TRANSFORM_WORLDPOSITION)||!this._getTransformFlag(I.TRANSFORM_WORLDSCALE)){this._setTransformFlag(I.TRANSFORM_WORLDMATRIX|I.TRANSFORM_WORLDPOSITION|I.TRANSFORM_WORLDSCALE,!0),this.event(t.Event.TRANSFORM_CHANGED,this._transformFlag);for(var e=0,r=this._children.length;e<r;e++)this._children[e]._onWorldPositionScaleTransform()}}_onWorldPositionTransform(){if(!this._getTransformFlag(I.TRANSFORM_WORLDMATRIX)||!this._getTransformFlag(I.TRANSFORM_WORLDPOSITION)){this._setTransformFlag(I.TRANSFORM_WORLDMATRIX|I.TRANSFORM_WORLDPOSITION,!0),this.event(t.Event.TRANSFORM_CHANGED,this._transformFlag);for(var e=0,r=this._children.length;e<r;e++)this._children[e]._onWorldPositionTransform()}}_onWorldRotationTransform(){if(!this._getTransformFlag(I.TRANSFORM_WORLDMATRIX)||!this._getTransformFlag(I.TRANSFORM_WORLDQUATERNION)||!this._getTransformFlag(I.TRANSFORM_WORLDEULER)){this._setTransformFlag(I.TRANSFORM_WORLDMATRIX|I.TRANSFORM_WORLDQUATERNION|I.TRANSFORM_WORLDEULER,!0),this.event(t.Event.TRANSFORM_CHANGED,this._transformFlag);for(var e=0,r=this._children.length;e<r;e++)this._children[e]._onWorldPositionRotationTransform()}}_onWorldScaleTransform(){if(!this._getTransformFlag(I.TRANSFORM_WORLDMATRIX)||!this._getTransformFlag(I.TRANSFORM_WORLDSCALE)){this._setTransformFlag(I.TRANSFORM_WORLDMATRIX|I.TRANSFORM_WORLDSCALE,!0),this.event(t.Event.TRANSFORM_CHANGED,this._transformFlag);for(var e=0,r=this._children.length;e<r;e++)this._children[e]._onWorldPositionScaleTransform()}}_onWorldTransform(){if(!(this._getTransformFlag(I.TRANSFORM_WORLDMATRIX)&&this._getTransformFlag(I.TRANSFORM_WORLDPOSITION)&&this._getTransformFlag(I.TRANSFORM_WORLDQUATERNION)&&this._getTransformFlag(I.TRANSFORM_WORLDEULER)&&this._getTransformFlag(I.TRANSFORM_WORLDSCALE))){this._setTransformFlag(I.TRANSFORM_WORLDMATRIX|I.TRANSFORM_WORLDPOSITION|I.TRANSFORM_WORLDQUATERNION|I.TRANSFORM_WORLDEULER|I.TRANSFORM_WORLDSCALE,!0),this.event(t.Event.TRANSFORM_CHANGED,this._transformFlag);for(var e=0,r=this._children.length;e<r;e++)this._children[e]._onWorldTransform()}}translate(e,t=!0){t?(R.createFromQuaternion(this.localRotation,I._tempMatrix0),n.transformCoordinate(e,I._tempMatrix0,I._tempVector30),n.add(this.localPosition,I._tempVector30,this._localPosition),this.localPosition=this._localPosition):(n.add(this.position,e,this._position),this.position=this._position)}rotate(e,t=!0,r=!0){var i;r?i=e:(n.scale(e,Math.PI/180,I._tempVector30),i=I._tempVector30),S.createFromYawPitchRoll(i.y,i.x,i.z,I._tempQuaternion0),t?(S.multiply(this._localRotation,I._tempQuaternion0,this._localRotation),this.localRotation=this._localRotation):(S.multiply(I._tempQuaternion0,this.rotation,this._rotation),this.rotation=this._rotation)}getForward(e){var t=this.worldMatrix.elements;e.x=-t[8],e.y=-t[9],e.z=-t[10]}getUp(e){var t=this.worldMatrix.elements;e.x=t[4],e.y=t[5],e.z=t[6]}getRight(e){var t=this.worldMatrix.elements;e.x=t[0],e.y=t[1],e.z=t[2]}lookAt(e,t,i=!1){var a;if(i){if(a=this._localPosition,Math.abs(a.x-e.x)<r.zeroTolerance&&Math.abs(a.y-e.y)<r.zeroTolerance&&Math.abs(a.z-e.z)<r.zeroTolerance)return;S.lookAt(this._localPosition,e,t,this._localRotation),this._localRotation.invert(this._localRotation),this.localRotation=this._localRotation}else{var n=this.position;if(a=n,Math.abs(a.x-e.x)<r.zeroTolerance&&Math.abs(a.y-e.y)<r.zeroTolerance&&Math.abs(a.z-e.z)<r.zeroTolerance)return;S.lookAt(n,e,t,this._rotation),this._rotation.invert(this._rotation),this.rotation=this._rotation}}getWorldLossyScale(){if(this._getTransformFlag(I.TRANSFORM_WORLDSCALE)){if(null!==this._parent){var e=this._getScaleMatrix().elements;this._scale.x=e[0],this._scale.y=e[4],this._scale.z=e[8]}else this._localScale.cloneTo(this._scale);this._setTransformFlag(I.TRANSFORM_WORLDSCALE,!1)}return this._scale}setWorldLossyScale(e){if(null!==this._parent){var t=I._tempMatrix3x33,r=I._tempMatrix3x33,i=r.elements,a=this._parent._getScaleMatrix();a.invert(a),p.createFromScaling(e,t),p.multiply(a,t,r),this._localScale.x=i[0],this._localScale.y=i[4],this._localScale.z=i[8]}else e.cloneTo(this._localScale);this.localScale=this._localScale,this._scale!==e&&e.cloneTo(this._scale),this._setTransformFlag(I.TRANSFORM_WORLDSCALE,!1)}get scale(){return console.warn("Transfrm3D: discard function,please use getWorldLossyScale instead."),this.getWorldLossyScale()}set scale(e){console.warn("Transfrm3D: discard function,please use setWorldLossyScale instead."),this.setWorldLossyScale(e)}}I._tempVector30=new n,I._tempQuaternion0=new S,I._tempMatrix0=new R,I._tempMatrix3x30=new p,I._tempMatrix3x31=new p,I._tempMatrix3x32=new p,I._tempMatrix3x33=new p,I.TRANSFORM_LOCALQUATERNION=1,I.TRANSFORM_LOCALEULER=2,I.TRANSFORM_LOCALMATRIX=4,I.TRANSFORM_WORLDPOSITION=8,I.TRANSFORM_WORLDQUATERNION=16,I.TRANSFORM_WORLDSCALE=32,I.TRANSFORM_WORLDMATRIX=64,I.TRANSFORM_WORLDEULER=128,I._angleToRandin=180/Math.PI;class M{constructor(){}static setColliderCollision(e,t,r){}static getIColliderCollision(e,t){return!1}}M.COLLISIONFILTERGROUP_DEFAULTFILTER=1,M.COLLISIONFILTERGROUP_STATICFILTER=2,M.COLLISIONFILTERGROUP_KINEMATICFILTER=4,M.COLLISIONFILTERGROUP_DEBRISFILTER=8,M.COLLISIONFILTERGROUP_SENSORTRIGGER=16,M.COLLISIONFILTERGROUP_CHARACTERFILTER=32,M.COLLISIONFILTERGROUP_CUSTOMFILTER1=64,M.COLLISIONFILTERGROUP_CUSTOMFILTER2=128,M.COLLISIONFILTERGROUP_CUSTOMFILTER3=256,M.COLLISIONFILTERGROUP_CUSTOMFILTER4=512,M.COLLISIONFILTERGROUP_CUSTOMFILTER5=1024,M.COLLISIONFILTERGROUP_CUSTOMFILTER6=2048,M.COLLISIONFILTERGROUP_CUSTOMFILTER7=4096,M.COLLISIONFILTERGROUP_CUSTOMFILTER8=8192,M.COLLISIONFILTERGROUP_CUSTOMFILTER9=16384,M.COLLISIONFILTERGROUP_CUSTOMFILTER10=32768,M.COLLISIONFILTERGROUP_ALLFILTER=-1,M.gravity=new n(0,-9.81,0);class D extends v{constructor(e=1,t=1,r=1){super(),this._sizeX=e,this._sizeY=t,this._sizeZ=r,this._type=v.SHAPETYPES_BOX;var i=g.Physics3D._bullet;i.btVector3_setValue(D._btSize,e/2,t/2,r/2),this._btShape=i.btBoxShape_create(D._btSize)}static __init__(){D._btSize=g.Physics3D._bullet.btVector3_create(0,0,0)}get sizeX(){return this._sizeX}get sizeY(){return this._sizeY}get sizeZ(){return this._sizeZ}clone(){var e=new D(this._sizeX,this._sizeY,this._sizeZ);return this.cloneTo(e),e}}class C extends v{constructor(e=.5,t=1.25,r=v.SHAPEORIENTATION_UPY){super(),this._radius=e,this._length=t,this._orientation=r,this._type=v.SHAPETYPES_CAPSULE;var i=g.Physics3D._bullet;switch(r){case v.SHAPEORIENTATION_UPX:this._btShape=i.btCapsuleShapeX_create(e,t-2*e);break;case v.SHAPEORIENTATION_UPY:this._btShape=i.btCapsuleShape_create(e,t-2*e);break;case v.SHAPEORIENTATION_UPZ:this._btShape=i.btCapsuleShapeZ_create(e,t-2*e);break;default:throw"CapsuleColliderShape:unknown orientation."}}get radius(){return this._radius}get length(){return this._length}get orientation(){return this._orientation}_setScale(e){var t=C._tempVector30;switch(this.orientation){case v.SHAPEORIENTATION_UPX:t.x=e.x,t.y=t.z=Math.max(e.y,e.z);break;case v.SHAPEORIENTATION_UPY:t.y=e.y,t.x=t.z=Math.max(e.x,e.z);break;case v.SHAPEORIENTATION_UPZ:t.z=e.z,t.x=t.y=Math.max(e.x,e.y);break;default:throw"CapsuleColliderShape:unknown orientation."}super._setScale(t)}clone(){var e=new C(this._radius,this._length,this._orientation);return this.cloneTo(e),e}}C._tempVector30=new n;class y extends v{constructor(e=.5,t=1,r=v.SHAPEORIENTATION_UPY){super(),this._radius=1,this._height=.5,this._radius=e,this._height=t,this._orientation=r,this._type=v.SHAPETYPES_CYLINDER;var i=g.Physics3D._bullet;switch(r){case v.SHAPEORIENTATION_UPX:this._btShape=i.btConeShapeX_create(e,t);break;case v.SHAPEORIENTATION_UPY:this._btShape=i.btConeShape_create(e,t);break;case v.SHAPEORIENTATION_UPZ:this._btShape=i.btConeShapeZ_create(e,t);break;default:throw"ConeColliderShape:unknown orientation."}}get radius(){return this._radius}get height(){return this._height}get orientation(){return this._orientation}clone(){var e=new y(this._radius,this._height,this._orientation);return this.cloneTo(e),e}}class L extends v{constructor(e=.5,t=1,r=v.SHAPEORIENTATION_UPY){super(),this._radius=1,this._height=.5,this._radius=e,this._height=t,this._orientation=r,this._type=v.SHAPETYPES_CYLINDER;var i=g.Physics3D._bullet;switch(r){case v.SHAPEORIENTATION_UPX:i.btVector3_setValue(L._btSize,t/2,e,e),this._btShape=i.btCylinderShapeX_create(L._btSize);break;case v.SHAPEORIENTATION_UPY:i.btVector3_setValue(L._btSize,e,t/2,e),this._btShape=i.btCylinderShape_create(L._btSize);break;case v.SHAPEORIENTATION_UPZ:i.btVector3_setValue(L._btSize,e,e,t/2),this._btShape=i.btCylinderShapeZ_create(L._btSize);break;default:throw"CapsuleColliderShape:unknown orientation."}}static __init__(){L._btSize=g.Physics3D._bullet.btVector3_create(0,0,0)}get radius(){return this._radius}get height(){return this._height}get orientation(){return this._orientation}clone(){var e=new L(this._radius,this._height,this._orientation);return this.cloneTo(e),e}}class O extends v{constructor(){super(),this._mesh=null,this._convex=!1}get mesh(){return this._mesh}set mesh(e){if(this._mesh!==e){var t=g.Physics3D._bullet;this._mesh&&t.btCollisionShape_destroy(this._btShape),e&&(this._btShape=t.btGImpactMeshShape_create(e._getPhysicMesh()),t.btGImpactShapeInterface_updateBound(this._btShape)),this._mesh=e}}get convex(){return this._convex}set convex(e){this._convex=e}_setScale(e){if(this._compoundParent)this.updateLocalTransformations();else{var t=g.Physics3D._bullet;t.btVector3_setValue(v._btScale,e.x,e.y,e.z),t.btCollisionShape_setLocalScaling(this._btShape,v._btScale),t.btGImpactShapeInterface_updateBound(this._btShape)}}cloneTo(e){var t=e;t.convex=this._convex,t.mesh=this._mesh,super.cloneTo(e)}clone(){var e=new O;return this.cloneTo(e),e}destroy(){this._btShape&&(g.Physics3D._bullet.btCollisionShape_destroy(this._btShape),this._btShape=null)}}class N extends v{constructor(e=.5){super(),this._radius=e,this._type=v.SHAPETYPES_SPHERE,this._btShape=g.Physics3D._bullet.btSphereShape_create(e)}get radius(){return this._radius}clone(){var e=new N(this._radius);return this.cloneTo(e),e}}class P extends t.Component{constructor(e,t){super(),this._restitution=0,this._friction=.5,this._rollingFriction=0,this._ccdMotionThreshold=0,this._ccdSweptSphereRadius=0,this._collisionGroup=M.COLLISIONFILTERGROUP_DEFAULTFILTER,this._canCollideWith=M.COLLISIONFILTERGROUP_ALLFILTER,this._colliderShape=null,this._transformFlag=2147483647,this._controlBySimulation=!1,this._enableProcessCollisions=!0,this._inPhysicUpdateListIndex=-1,this.canScaleShape=!0,this._collisionGroup=e,this._canCollideWith=t,P._physicObjectsMap[this.id]=this}static __init__(){var e=g.Physics3D._bullet;P._btVector30=e.btVector3_create(0,0,0),P._btQuaternion0=e.btQuaternion_create(0,0,0,1)}static _createAffineTransformationArray(e,t,r,i,a,n,s,o,l){var _=i+i,h=a+a,c=n+n,d=i*_,u=i*h,m=i*c,f=a*h,T=a*c,E=n*c,p=s*_,g=s*h,S=s*c,R=o[0],v=o[1],x=o[2];l[0]=(1-(f+E))*R,l[1]=(u+S)*R,l[2]=(m-g)*R,l[3]=0,l[4]=(u-S)*v,l[5]=(1-(d+E))*v,l[6]=(T+p)*v,l[7]=0,l[8]=(m+g)*x,l[9]=(T-p)*x,l[10]=(1-(d+f))*x,l[11]=0,l[12]=e,l[13]=t,l[14]=r,l[15]=1}static _creatShape(e){var r;switch(e.type){case"BoxColliderShape":var i=e.size;r=i?new D(i[0],i[1],i[2]):new D;break;case"SphereColliderShape":r=new N(e.radius);break;case"CapsuleColliderShape":r=new C(e.radius,e.height,e.orientation);break;case"MeshColliderShape":var a=new O;e.mesh&&(a.mesh=t.Loader.getRes(e.mesh)),r=a;break;case"ConeColliderShape":r=new y(e.radius,e.height,e.orientation);break;case"CylinderColliderShape":r=new L(e.radius,e.height,e.orientation);break;default:throw"unknown shape type."}if(e.center){var n=r.localOffset;n.fromArray(e.center),r.localOffset=n}return r}static physicVector3TransformQuat(e,t,r,i,a,n){var s=e.x,o=e.y,l=e.z,_=a*s+r*l-i*o,h=a*o+i*s-t*l,c=a*l+t*o-r*s,d=-t*s-r*o-i*l;n.x=_*a+d*-t+h*-i-c*-r,n.y=h*a+d*-r+c*-t-_*-i,n.z=c*a+d*-i+_*-r-h*-t}static physicQuaternionMultiply(e,t,r,i,a,n){var s=a.x,o=a.y,l=a.z,_=a.w,h=t*l-r*o,c=r*s-e*l,d=e*o-t*s,u=e*s+t*o+r*l;n.x=e*_+s*i+h,n.y=t*_+o*i+c,n.z=r*_+l*i+d,n.w=i*_-u}get restitution(){return this._restitution}set restitution(e){this._restitution=e,this._btColliderObject&&g.Physics3D._bullet.btCollisionObject_setRestitution(this._btColliderObject,e)}get friction(){return this._friction}set friction(e){this._friction=e,this._btColliderObject&&g.Physics3D._bullet.btCollisionObject_setFriction(this._btColliderObject,e)}get rollingFriction(){return this._rollingFriction}set rollingFriction(e){this._rollingFriction=e,this._btColliderObject&&g.Physics3D._bullet.btCollisionObject_setRollingFriction(this._btColliderObject,e)}get ccdMotionThreshold(){return this._ccdMotionThreshold}set ccdMotionThreshold(e){this._ccdMotionThreshold=e,this._btColliderObject&&g.Physics3D._bullet.btCollisionObject_setCcdMotionThreshold(this._btColliderObject,e)}get ccdSweptSphereRadius(){return this._ccdSweptSphereRadius}set ccdSweptSphereRadius(e){this._ccdSweptSphereRadius=e,this._btColliderObject&&g.Physics3D._bullet.btCollisionObject_setCcdSweptSphereRadius(this._btColliderObject,e)}get isActive(){return!!this._btColliderObject&&g.Physics3D._bullet.btCollisionObject_isActive(this._btColliderObject)}get colliderShape(){return this._colliderShape}set colliderShape(e){var t=this._colliderShape;if(t&&(t._attatched=!1,t._attatchedCollisionObject=null),this._colliderShape=e,e){if(e._attatched)throw"PhysicsComponent: this shape has attatched to other entity.";if(e._attatched=!0,e._attatchedCollisionObject=this,this._btColliderObject){g.Physics3D._bullet.btCollisionObject_setCollisionShape(this._btColliderObject,e._btShape);var r=this._simulation&&this._enabled;r&&t&&this._removeFromSimulation(),this._onShapeChange(e),r&&(this._derivePhysicsTransformation(!0),this._addToSimulation())}}else this._simulation&&this._enabled&&t&&this._removeFromSimulation()}get simulation(){return this._simulation}get collisionGroup(){return this._collisionGroup}set collisionGroup(e){this._collisionGroup!==e&&(this._collisionGroup=e,this._simulation&&this._colliderShape&&this._enabled&&(this._removeFromSimulation(),this._addToSimulation()))}get canCollideWith(){return this._canCollideWith}set canCollideWith(e){this._canCollideWith!==e&&(this._canCollideWith=e,this._simulation&&this._colliderShape&&this._enabled&&(this._removeFromSimulation(),this._addToSimulation()))}_parseShape(e){var t=e.length;if(1===t){var r=P._creatShape(e[0]);this.colliderShape=r}else{for(var i=new A,a=0;a<t;a++)r=P._creatShape(e[a]),i.addChildShape(r);this.colliderShape=i}}_onScaleChange(e){this._colliderShape._setScale(e)}_onEnable(){this._simulation=this.owner._scene.physicsSimulation,g.Physics3D._bullet.btCollisionObject_setContactProcessingThreshold(this._btColliderObject,0),this._colliderShape&&(this._derivePhysicsTransformation(!0),this._addToSimulation())}_onDisable(){this._colliderShape&&(this._removeFromSimulation(),-1!==this._inPhysicUpdateListIndex&&this._simulation._physicsUpdateList.remove(this)),this._simulation=null}_onDestroy(){delete P._physicObjectsMap[this.id],g.Physics3D._bullet.btCollisionObject_destroy(this._btColliderObject),this._colliderShape.destroy(),super._onDestroy(),this._btColliderObject=null,this._colliderShape=null,this._simulation=null,this.owner.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onTransformChanged)}_isValid(){return this._simulation&&this._colliderShape&&this._enabled}_parse(e){null!=e.collisionGroup&&(this.collisionGroup=e.collisionGroup),null!=e.canCollideWith&&(this.canCollideWith=e.canCollideWith),null!=e.ccdMotionThreshold&&(this.ccdMotionThreshold=e.ccdMotionThreshold),null!=e.ccdSweptSphereRadius&&(this.ccdSweptSphereRadius=e.ccdSweptSphereRadius)}_setTransformFlag(e,t){t?this._transformFlag|=e:this._transformFlag&=~e}_getTransformFlag(e){return 0!=(this._transformFlag&e)}_addToSimulation(){}_removeFromSimulation(){}_derivePhysicsTransformation(e){var t=g.Physics3D._bullet,r=this._btColliderObject,i=t.btCollisionObject_getWorldTransform(r);this._innerDerivePhysicsTransformation(i,e),t.btCollisionObject_setWorldTransform(r,i)}_innerDerivePhysicsTransformation(e,t){var r=g.Physics3D._bullet,i=this.owner._transform;if(t||this._getTransformFlag(I.TRANSFORM_WORLDPOSITION)){var a=this._colliderShape.localOffset,s=i.position,o=P._btVector30;if(0!==a.x||0!==a.y||0!==a.z){var l=P._tempVector30,_=i.worldMatrix;n.transformCoordinate(a,_,l),r.btVector3_setValue(o,-l.x,l.y,l.z)}else r.btVector3_setValue(o,-s.x,s.y,s.z);r.btTransform_setOrigin(e,o),this._setTransformFlag(I.TRANSFORM_WORLDPOSITION,!1)}if(t||this._getTransformFlag(I.TRANSFORM_WORLDQUATERNION)){var h=this._colliderShape.localRotation,c=P._btQuaternion0,d=i.rotation;if(0!==h.x||0!==h.y||0!==h.z||1!==h.w){var u=P._tempQuaternion0;P.physicQuaternionMultiply(d.x,d.y,d.z,d.w,h,u),r.btQuaternion_setValue(c,-u.x,u.y,u.z,-u.w)}else r.btQuaternion_setValue(c,-d.x,d.y,d.z,-d.w);r.btTransform_setRotation(e,c),this._setTransformFlag(I.TRANSFORM_WORLDQUATERNION,!1)}(t||this._getTransformFlag(I.TRANSFORM_WORLDSCALE))&&(this._onScaleChange(i.getWorldLossyScale()),this._setTransformFlag(I.TRANSFORM_WORLDSCALE,!1))}_updateTransformComponent(e){var t=g.Physics3D._bullet,r=this._colliderShape,i=r.localOffset,a=r.localRotation,s=this.owner._transform,o=s.position,l=s.rotation,_=t.btTransform_getOrigin(e),h=t.btTransform_getRotation(e),c=-t.btQuaternion_x(h),d=t.btQuaternion_y(h),u=t.btQuaternion_z(h),m=-t.btQuaternion_w(h);if(0!==a.x||0!==a.y||0!==a.z||1!==a.w){var f=P._tempQuaternion0;a.invert(f),P.physicQuaternionMultiply(c,d,u,m,f,l)}else l.x=c,l.y=d,l.z=u,l.w=m;if(s.rotation=l,0!==i.x||0!==i.y||0!==i.z){var T=t.btCollisionShape_getLocalScaling(r._btShape),E=P._tempVector30;E.x=i.x*t.btVector3_x(T),E.y=i.y*t.btVector3_y(T),E.z=i.z*t.btVector3_z(T),n.transformQuat(E,l,E),o.x=-t.btVector3_x(_)-E.x,o.y=t.btVector3_y(_)-E.y,o.z=t.btVector3_z(_)-E.z}else o.x=-t.btVector3_x(_),o.y=t.btVector3_y(_),o.z=t.btVector3_z(_);s.position=o}_onShapeChange(e){var t=this._btColliderObject,r=g.Physics3D._bullet,i=r.btCollisionObject_getCollisionFlags(t);e.needsCustomCollisionCallback?0==(i&P.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK)&&r.btCollisionObject_setCollisionFlags(t,i|P.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK):(i&P.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK)>0&&r.btCollisionObject_setCollisionFlags(t,i^P.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK)}_onAdded(){this.enabled=this._enabled,this.restitution=this._restitution,this.friction=this._friction,this.rollingFriction=this._rollingFriction,this.ccdMotionThreshold=this._ccdMotionThreshold,this.ccdSweptSphereRadius=this._ccdSweptSphereRadius,this.owner.transform.on(t.Event.TRANSFORM_CHANGED,this,this._onTransformChanged)}_onTransformChanged(e){!P._addUpdateList&&this._controlBySimulation||(e&=I.TRANSFORM_WORLDPOSITION|I.TRANSFORM_WORLDQUATERNION|I.TRANSFORM_WORLDSCALE)&&(this._transformFlag|=e,this._isValid()&&-1===this._inPhysicUpdateListIndex&&this._simulation._physicsUpdateList.add(this))}_cloneTo(e){var t=e;t.restitution=this._restitution,t.friction=this._friction,t.rollingFriction=this._rollingFriction,t.ccdMotionThreshold=this._ccdMotionThreshold,t.ccdSweptSphereRadius=this._ccdSweptSphereRadius,t.collisionGroup=this._collisionGroup,t.canCollideWith=this._canCollideWith,t.canScaleShape=this.canScaleShape,this._colliderShape&&(t.colliderShape=this._colliderShape.clone())}}P.ACTIVATIONSTATE_ACTIVE_TAG=1,P.ACTIVATIONSTATE_ISLAND_SLEEPING=2,P.ACTIVATIONSTATE_WANTS_DEACTIVATION=3,P.ACTIVATIONSTATE_DISABLE_DEACTIVATION=4,P.ACTIVATIONSTATE_DISABLE_SIMULATION=5,P.COLLISIONFLAGS_STATIC_OBJECT=1,P.COLLISIONFLAGS_KINEMATIC_OBJECT=2,P.COLLISIONFLAGS_NO_CONTACT_RESPONSE=4,P.COLLISIONFLAGS_CUSTOM_MATERIAL_CALLBACK=8,P.COLLISIONFLAGS_CHARACTER_OBJECT=16,P.COLLISIONFLAGS_DISABLE_VISUALIZE_OBJECT=32,P.COLLISIONFLAGS_DISABLE_SPU_COLLISION_PROCESSING=64,P._tempVector30=new n,P._tempQuaternion0=new S,P._tempQuaternion1=new S,P._tempMatrix4x40=new R,P._physicObjectsMap={},P._addUpdateList=!0;class b{constructor(){this.elements=[],this.length=0}_add(e){this.length===this.elements.length?this.elements.push(e):this.elements[this.length]=e}add(e){this.length===this.elements.length?this.elements.push(e):this.elements[this.length]=e,this.length++}}class w extends b{constructor(){super()}add(e){if(-1!==e._inPhysicUpdateListIndex)throw"PhysicsUpdateList:element has in PhysicsUpdateList.";this._add(e),e._inPhysicUpdateListIndex=this.length++}remove(e){var t=e._inPhysicUpdateListIndex;if(this.length--,t!==this.length){var r=this.elements[this.length];this.elements[t]=r,r._inPhysicUpdateListIndex=t}e._inPhysicUpdateListIndex=-1}}class V{constructor(){this._idCounter=0,this.colliderA=null,this.colliderB=null,this.distance=0,this.normal=new n,this.positionOnA=new n,this.positionOnB=new n,this._id=++this._idCounter}}class B{constructor(){this.succeeded=!1,this.collider=null,this.point=new n,this.normal=new n,this.hitFraction=0}}class F{constructor(){this._lastUpdateFrame=-2147483648,this._updateFrame=-2147483648,this._isTrigger=!1,this.contacts=[]}_setUpdateFrame(e){this._lastUpdateFrame=this._updateFrame,this._updateFrame=e}}class U{constructor(){this._hitResultsPoolIndex=0,this._hitResultsPool=[],this._contactPonintsPoolIndex=0,this._contactPointsPool=[],this._collisionsPool=[],this._collisions={}}getHitResult(){var e=this._hitResultsPool[this._hitResultsPoolIndex++];return e||(e=new B,this._hitResultsPool.push(e)),e}recoverAllHitResultsPool(){this._hitResultsPoolIndex=0}getContactPoints(){var e=this._contactPointsPool[this._contactPonintsPoolIndex++];return e||(e=new V,this._contactPointsPool.push(e)),e}recoverAllContactPointsPool(){this._contactPonintsPoolIndex=0}getCollision(e,t){var r,i=e.id,a=t.id,n=this._collisions[i];return n&&(r=n[a]),r||(n||(n={},this._collisions[i]=n),(r=0===this._collisionsPool.length?new F:this._collisionsPool.pop())._colliderA=e,r._colliderB=t,n[a]=r),r}recoverCollision(e){var t=e._colliderA.id,r=e._colliderB.id;this._collisions[t][r]=null,this._collisionsPool.push(e)}garbageCollection(){for(var e in this._hitResultsPoolIndex=0,this._hitResultsPool.length=0,this._contactPonintsPoolIndex=0,this._contactPointsPool.length=0,this._collisionsPool.length=0,this._collisionsPool){var t=this._collisionsPool[e],r=!0;for(var i in t)t[i]?r=!1:delete t[i];r&&delete this._collisionsPool[e]}}}class G{constructor(e,t=0){this._gravity=new n(0,-10,0),this._btVector3Zero=g.Physics3D._bullet.btVector3_create(0,0,0),this._btDefaultQuaternion=g.Physics3D._bullet.btQuaternion_create(0,0,0,-1),this._collisionsUtils=new U,this._previousFrameCollisions=[],this._currentFrameCollisions=[],this._currentConstraint={},this._physicsUpdateList=new w,this._characters=[],this._updatedRigidbodies=0,this.maxSubSteps=1,this.fixedTimeStep=1/60,this.maxSubSteps=e.maxSubSteps,this.fixedTimeStep=e.fixedTimeStep;var r=g.Physics3D._bullet;this._btCollisionConfiguration=r.btDefaultCollisionConfiguration_create(),this._btDispatcher=r.btCollisionDispatcher_create(this._btCollisionConfiguration),this._btBroadphase=r.btDbvtBroadphase_create(),r.btOverlappingPairCache_setInternalGhostPairCallback(r.btDbvtBroadphase_getOverlappingPairCache(this._btBroadphase),r.btGhostPairCallback_create());var i=e.flags;if(i&G.PHYSICSENGINEFLAGS_COLLISIONSONLY)this._btCollisionWorld=new r.btCollisionWorld(this._btDispatcher,this._btBroadphase,this._btCollisionConfiguration);else{if(i&G.PHYSICSENGINEFLAGS_SOFTBODYSUPPORT)throw"PhysicsSimulation:SoftBody processing is not yet available";var a=r.btSequentialImpulseConstraintSolver_create();this._btDiscreteDynamicsWorld=r.btDiscreteDynamicsWorld_create(this._btDispatcher,this._btBroadphase,a,this._btCollisionConfiguration),this._btCollisionWorld=this._btDiscreteDynamicsWorld}this._btDiscreteDynamicsWorld&&(this._btSolverInfo=r.btDynamicsWorld_getSolverInfo(this._btDiscreteDynamicsWorld),this._btDispatchInfo=r.btCollisionWorld_getDispatchInfo(this._btDiscreteDynamicsWorld)),this._btClosestRayResultCallback=r.ClosestRayResultCallback_create(this._btVector3Zero,this._btVector3Zero),this._btAllHitsRayResultCallback=r.AllHitsRayResultCallback_create(this._btVector3Zero,this._btVector3Zero),this._btClosestConvexResultCallback=r.ClosestConvexResultCallback_create(this._btVector3Zero,this._btVector3Zero),this._btAllConvexResultCallback=r.AllConvexResultCallback_create(this._btVector3Zero,this._btVector3Zero),this.setHitsRayResultCallbackFlag(),r.btGImpactCollisionAlgorithm_RegisterAlgorithm(this._btDispatcher)}static __init__(){var e=g.Physics3D._bullet;G._btTempVector30=e.btVector3_create(0,0,0),G._btTempVector31=e.btVector3_create(0,0,0),G._btTempQuaternion0=e.btQuaternion_create(0,0,0,1),G._btTempQuaternion1=e.btQuaternion_create(0,0,0,1),G._btTempTransform0=e.btTransform_create(),G._btTempTransform1=e.btTransform_create()}static createConstraint(){}get continuousCollisionDetection(){return g.Physics3D._bullet.btCollisionWorld_get_m_useContinuous(this._btDispatchInfo)}set continuousCollisionDetection(e){g.Physics3D._bullet.btCollisionWorld_set_m_useContinuous(this._btDispatchInfo,e)}get gravity(){if(!this._btDiscreteDynamicsWorld)throw"Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";return this._gravity}set gravity(e){if(!this._btDiscreteDynamicsWorld)throw"Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";this._gravity=e;var t=g.Physics3D._bullet,r=G._btTempVector30;t.btVector3_setValue(r,-e.x,e.y,e.z),t.btDiscreteDynamicsWorld_setGravity(this._btDiscreteDynamicsWorld,r)}get speculativeContactRestitution(){if(!this._btDiscreteDynamicsWorld)throw"Simulation:Cannot Cannot perform this action when the physics engine is set to CollisionsOnly";return g.Physics3D._bullet.btDiscreteDynamicsWorld_getApplySpeculativeContactRestitution(this._btDiscreteDynamicsWorld)}set speculativeContactRestitution(e){if(!this._btDiscreteDynamicsWorld)throw"Simulation:Cannot Cannot perform this action when the physics engine is set to CollisionsOnly";g.Physics3D._bullet.btDiscreteDynamicsWorld_setApplySpeculativeContactRestitution(this._btDiscreteDynamicsWorld,e)}_simulate(e){this._updatedRigidbodies=0;var t=g.Physics3D._bullet;this._btDiscreteDynamicsWorld?t.btDiscreteDynamicsWorld_stepSimulation(this._btDiscreteDynamicsWorld,e,this.maxSubSteps,this.fixedTimeStep):t.PerformDiscreteCollisionDetection(this._btCollisionWorld)}_destroy(){var e=g.Physics3D._bullet;this._btDiscreteDynamicsWorld?(e.btCollisionWorld_destroy(this._btDiscreteDynamicsWorld),this._btDiscreteDynamicsWorld=null):(e.btCollisionWorld_destroy(this._btCollisionWorld),this._btCollisionWorld=null),e.btDbvtBroadphase_destroy(this._btBroadphase),this._btBroadphase=null,e.btCollisionDispatcher_destroy(this._btDispatcher),this._btDispatcher=null,e.btDefaultCollisionConfiguration_destroy(this._btCollisionConfiguration),this._btCollisionConfiguration=null}_addPhysicsCollider(e,t,r){g.Physics3D._bullet.btCollisionWorld_addCollisionObject(this._btCollisionWorld,e._btColliderObject,t,r)}_removePhysicsCollider(e){g.Physics3D._bullet.btCollisionWorld_removeCollisionObject(this._btCollisionWorld,e._btColliderObject)}_addRigidBody(e,t,r){if(!this._btDiscreteDynamicsWorld)throw"Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";g.Physics3D._bullet.btDiscreteDynamicsWorld_addRigidBody(this._btCollisionWorld,e._btColliderObject,t,r)}_removeRigidBody(e){if(!this._btDiscreteDynamicsWorld)throw"Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";g.Physics3D._bullet.btDiscreteDynamicsWorld_removeRigidBody(this._btCollisionWorld,e._btColliderObject)}_addCharacter(e,t,r){if(!this._btDiscreteDynamicsWorld)throw"Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";var i=g.Physics3D._bullet;i.btCollisionWorld_addCollisionObject(this._btCollisionWorld,e._btColliderObject,t,r),i.btDynamicsWorld_addAction(this._btCollisionWorld,e._btKinematicCharacter)}_removeCharacter(e){if(!this._btDiscreteDynamicsWorld)throw"Simulation:Cannot perform this action when the physics engine is set to CollisionsOnly";var t=g.Physics3D._bullet;t.btCollisionWorld_removeCollisionObject(this._btCollisionWorld,e._btColliderObject),t.btDynamicsWorld_removeAction(this._btCollisionWorld,e._btKinematicCharacter)}raycastFromTo(e,t,r=null,i=M.COLLISIONFILTERGROUP_ALLFILTER,a=M.COLLISIONFILTERGROUP_ALLFILTER){var n=g.Physics3D._bullet,s=this._btClosestRayResultCallback,o=G._btTempVector30,l=G._btTempVector31;if(n.btVector3_setValue(o,-e.x,e.y,e.z),n.btVector3_setValue(l,-t.x,t.y,t.z),n.ClosestRayResultCallback_set_m_rayFromWorld(s,o),n.ClosestRayResultCallback_set_m_rayToWorld(s,l),n.RayResultCallback_set_m_collisionFilterGroup(s,i),n.RayResultCallback_set_m_collisionFilterMask(s,a),n.RayResultCallback_set_m_collisionObject(s,null),n.RayResultCallback_set_m_closestHitFraction(s,1),n.btCollisionWorld_rayTest(this._btCollisionWorld,o,l,s),n.RayResultCallback_hasHit(s)){if(r){r.succeeded=!0,r.collider=P._physicObjectsMap[n.btCollisionObject_getUserIndex(n.RayResultCallback_get_m_collisionObject(s))],r.hitFraction=n.RayResultCallback_get_m_closestHitFraction(s);var _=n.ClosestRayResultCallback_get_m_hitPointWorld(s),h=r.point;h.x=-n.btVector3_x(_),h.y=n.btVector3_y(_),h.z=n.btVector3_z(_);var c=n.ClosestRayResultCallback_get_m_hitNormalWorld(s),d=r.normal;d.x=-n.btVector3_x(c),d.y=n.btVector3_y(c),d.z=n.btVector3_z(c)}return!0}return r&&(r.succeeded=!1),!1}raycastAllFromTo(e,t,r,i=M.COLLISIONFILTERGROUP_ALLFILTER,a=M.COLLISIONFILTERGROUP_ALLFILTER){var n=g.Physics3D._bullet,s=this._btAllHitsRayResultCallback,o=G._btTempVector30,l=G._btTempVector31;r.length=0,n.btVector3_setValue(o,-e.x,e.y,e.z),n.btVector3_setValue(l,-t.x,t.y,t.z),n.AllHitsRayResultCallback_set_m_rayFromWorld(s,o),n.AllHitsRayResultCallback_set_m_rayToWorld(s,l),n.RayResultCallback_set_m_collisionFilterGroup(s,i),n.RayResultCallback_set_m_collisionFilterMask(s,a);var _=n.AllHitsRayResultCallback_get_m_collisionObjects(s),h=n.AllHitsRayResultCallback_get_m_hitPointWorld(s),c=n.AllHitsRayResultCallback_get_m_hitNormalWorld(s),d=n.AllHitsRayResultCallback_get_m_hitFractions(s);n.tBtCollisionObjectArray_clear(_),n.tVector3Array_clear(h),n.tVector3Array_clear(c),n.tScalarArray_clear(d),n.btCollisionWorld_rayTest(this._btCollisionWorld,o,l,s);var u=n.tBtCollisionObjectArray_size(_);if(u>0){this._collisionsUtils.recoverAllHitResultsPool();for(var m=0;m<u;m++){var f=this._collisionsUtils.getHitResult();r.push(f),f.succeeded=!0,f.collider=P._physicObjectsMap[n.btCollisionObject_getUserIndex(n.tBtCollisionObjectArray_at(_,m))],f.hitFraction=n.tScalarArray_at(d,m);var T=n.tVector3Array_at(h,m),E=f.point;E.x=-n.btVector3_x(T),E.y=n.btVector3_y(T),E.z=n.btVector3_z(T);var p=n.tVector3Array_at(c,m),S=f.normal;S.x=-n.btVector3_x(p),S.y=n.btVector3_y(p),S.z=n.btVector3_z(p)}return!0}return!1}rayCast(e,t=null,r=2147483647,i=M.COLLISIONFILTERGROUP_ALLFILTER,a=M.COLLISIONFILTERGROUP_ALLFILTER){var s=e.origin,o=G._tempVector30;return n.normalize(e.direction,o),n.scale(o,r,o),n.add(s,o,o),this.raycastFromTo(s,o,t,i,a)}rayCastAll(e,t,r=2147483647,i=M.COLLISIONFILTERGROUP_ALLFILTER,a=M.COLLISIONFILTERGROUP_ALLFILTER){var s=e.origin,o=G._tempVector30;return n.normalize(e.direction,o),n.scale(o,r,o),n.add(s,o,o),this.raycastAllFromTo(s,o,t,i,a)}shapeCast(e,t,r,i=null,a=null,n=null,s=M.COLLISIONFILTERGROUP_ALLFILTER,o=M.COLLISIONFILTERGROUP_ALLFILTER,l=0){var _=g.Physics3D._bullet,h=this._btClosestConvexResultCallback,c=G._btTempVector30,d=G._btTempVector31,u=G._btTempQuaternion0,m=G._btTempQuaternion1,f=G._btTempTransform0,T=G._btTempTransform1,E=e._btShape;if(_.btVector3_setValue(c,-t.x,t.y,t.z),_.btVector3_setValue(d,-r.x,r.y,r.z),_.ConvexResultCallback_set_m_collisionFilterGroup(h,s),_.ConvexResultCallback_set_m_collisionFilterMask(h,o),_.btTransform_setOrigin(f,c),_.btTransform_setOrigin(T,d),a?(_.btQuaternion_setValue(u,-a.x,a.y,a.z,-a.w),_.btTransform_setRotation(f,u)):_.btTransform_setRotation(f,this._btDefaultQuaternion),n?(_.btQuaternion_setValue(m,-n.x,n.y,n.z,-n.w),_.btTransform_setRotation(T,m)):_.btTransform_setRotation(T,this._btDefaultQuaternion),_.ClosestConvexResultCallback_set_m_hitCollisionObject(h,null),_.ConvexResultCallback_set_m_closestHitFraction(h,1),_.btCollisionWorld_convexSweepTest(this._btCollisionWorld,E,f,T,h,l),_.ConvexResultCallback_hasHit(h)){if(i){i.succeeded=!0,i.collider=P._physicObjectsMap[_.btCollisionObject_getUserIndex(_.ClosestConvexResultCallback_get_m_hitCollisionObject(h))],i.hitFraction=_.ConvexResultCallback_get_m_closestHitFraction(h);var p=_.ClosestConvexResultCallback_get_m_hitPointWorld(h),S=_.ClosestConvexResultCallback_get_m_hitNormalWorld(h),R=i.point,v=i.normal;R.x=-_.btVector3_x(p),R.y=_.btVector3_y(p),R.z=_.btVector3_z(p),v.x=-_.btVector3_x(S),v.y=_.btVector3_y(S),v.z=_.btVector3_z(S)}return!0}return i&&(i.succeeded=!1),!1}shapeCastAll(e,t,r,i,a=null,n=null,s=M.COLLISIONFILTERGROUP_ALLFILTER,o=M.COLLISIONFILTERGROUP_ALLFILTER,l=0){var _=g.Physics3D._bullet,h=this._btAllConvexResultCallback,c=G._btTempVector30,d=G._btTempVector31,u=G._btTempQuaternion0,m=G._btTempQuaternion1,f=G._btTempTransform0,T=G._btTempTransform1,E=e._btShape;i.length=0,_.btVector3_setValue(c,-t.x,t.y,t.z),_.btVector3_setValue(d,-r.x,r.y,r.z),_.ConvexResultCallback_set_m_collisionFilterGroup(h,s),_.ConvexResultCallback_set_m_collisionFilterMask(h,o),_.btTransform_setOrigin(f,c),_.btTransform_setOrigin(T,d),a?(_.btQuaternion_setValue(u,-a.x,a.y,a.z,-a.w),_.btTransform_setRotation(f,u)):_.btTransform_setRotation(f,this._btDefaultQuaternion),n?(_.btQuaternion_setValue(m,-n.x,n.y,n.z,-n.w),_.btTransform_setRotation(T,m)):_.btTransform_setRotation(T,this._btDefaultQuaternion);var p=_.AllConvexResultCallback_get_m_collisionObjects(h),S=_.AllConvexResultCallback_get_m_hitPointWorld(h),R=_.AllConvexResultCallback_get_m_hitNormalWorld(h),v=_.AllConvexResultCallback_get_m_hitFractions(h);_.tVector3Array_clear(S),_.tVector3Array_clear(R),_.tScalarArray_clear(v),_.tBtCollisionObjectArray_clear(p),_.btCollisionWorld_convexSweepTest(this._btCollisionWorld,E,f,T,h,l);var x=_.tBtCollisionObjectArray_size(p);if(x>0){this._collisionsUtils.recoverAllHitResultsPool();for(var A=0;A<x;A++){var I=this._collisionsUtils.getHitResult();i.push(I),I.succeeded=!0,I.collider=P._physicObjectsMap[_.btCollisionObject_getUserIndex(_.tBtCollisionObjectArray_at(p,A))],I.hitFraction=_.tScalarArray_at(v,A);var D=_.tVector3Array_at(S,A),C=I.point;C.x=-_.btVector3_x(D),C.y=_.btVector3_y(D),C.z=_.btVector3_z(D);var y=_.tVector3Array_at(R,A),L=I.normal;L.x=-_.btVector3_x(y),L.y=_.btVector3_y(y),L.z=_.btVector3_z(y)}return!0}return!1}addConstraint(e,t=!1){if(!this._btDiscreteDynamicsWorld)throw"Cannot perform this action when the physics engine is set to CollisionsOnly";g.Physics3D._bullet.btCollisionWorld_addConstraint(this._btDiscreteDynamicsWorld,e._btConstraint,t),this._currentConstraint[e.id]=e}removeConstraint(e){if(!this._btDiscreteDynamicsWorld)throw"Cannot perform this action when the physics engine is set to CollisionsOnly";g.Physics3D._bullet.btCollisionWorld_removeConstraint(this._btDiscreteDynamicsWorld,e._btConstraint),delete this._currentConstraint[e.id]}setHitsRayResultCallbackFlag(e=1){var t=g.Physics3D._bullet;t.RayResultCallback_set_m_flags(this._btAllHitsRayResultCallback,e),t.RayResultCallback_set_m_flags(this._btClosestRayResultCallback,e)}_updatePhysicsTransformFromRender(){for(var e=this._physicsUpdateList.elements,t=0,r=this._physicsUpdateList.length;t<r;t++){var i=e[t];i._derivePhysicsTransformation(!1),i._inPhysicUpdateListIndex=-1}this._physicsUpdateList.length=0}_updateCharacters(){for(var e=0,t=this._characters.length;e<t;e++){var r=this._characters[e];r._updateTransformComponent(g.Physics3D._bullet.btCollisionObject_getWorldTransform(r._btColliderObject))}}_updateCollisions(){this._collisionsUtils.recoverAllContactPointsPool();var e=this._currentFrameCollisions;this._currentFrameCollisions=this._previousFrameCollisions,this._currentFrameCollisions.length=0,this._previousFrameCollisions=e;for(var r=t.Stat.loopCount,i=g.Physics3D._bullet,a=i.btDispatcher_getNumManifolds(this._btDispatcher),n=0;n<a;n++){var s,o=i.btDispatcher_getManifoldByIndexInternal(this._btDispatcher,n),l=P._physicObjectsMap[i.btCollisionObject_getUserIndex(i.btPersistentManifold_getBody0(o))],_=P._physicObjectsMap[i.btCollisionObject_getUserIndex(i.btPersistentManifold_getBody1(o))],h=null,c=null;if((l.isTrigger||_.isTrigger)&&(l.owner._needProcessTriggers||_.owner._needProcessTriggers))for(var d=i.btPersistentManifold_getNumContacts(o),u=0;u<d;u++){var m=i.btPersistentManifold_getContactPoint(o,u),f=i.btManifoldPoint_getDistance(m);if(f<=0){c=(h=this._collisionsUtils.getCollision(l,_)).contacts,(s=h._updateFrame!==r)&&(h._isTrigger=!0,c.length=0);break}}else if((l.owner._needProcessCollisions||_.owner._needProcessCollisions)&&(l._enableProcessCollisions||_._enableProcessCollisions))for(d=i.btPersistentManifold_getNumContacts(o),u=0;u<d;u++)if(m=i.btPersistentManifold_getContactPoint(o,u),(f=i.btManifoldPoint_getDistance(m))<=0){var T=this._collisionsUtils.getContactPoints();T.colliderA=l,T.colliderB=_,T.distance=f;var E=i.btManifoldPoint_get_m_normalWorldOnB(m),p=T.normal;p.x=-i.btVector3_x(E),p.y=i.btVector3_y(E),p.z=i.btVector3_z(E);var S=i.btManifoldPoint_get_m_positionWorldOnA(m),R=T.positionOnA;R.x=-i.btVector3_x(S),R.y=i.btVector3_y(S),R.z=i.btVector3_z(S);var v=i.btManifoldPoint_get_m_positionWorldOnB(m),x=T.positionOnB;x.x=-i.btVector3_x(v),x.y=i.btVector3_y(v),x.z=i.btVector3_z(v),h||(c=(h=this._collisionsUtils.getCollision(l,_)).contacts,(s=h._updateFrame!==r)&&(h._isTrigger=!1,c.length=0)),c.push(T)}h&&s&&(this._currentFrameCollisions.push(h),h._setUpdateFrame(r))}}_eventScripts(){for(var e=t.Stat.loopCount,r=0,i=this._currentFrameCollisions.length;r<i;r++){var a=this._currentFrameCollisions[r],n=a._colliderA,s=a._colliderB;if(!n.destroyed&&!s.destroyed)if(e-a._lastUpdateFrame==1){var o=n.owner,l=o._scripts;if(l)if(a._isTrigger){if(o._needProcessTriggers)for(var _=0,h=l.length;_<h;_++)l[_].onTriggerStay(s)}else if(o._needProcessCollisions)for(_=0,h=l.length;_<h;_++)a.other=s,l[_].onCollisionStay(a);var c=s.owner,d=c._scripts;if(d)if(a._isTrigger){if(c._needProcessTriggers)for(_=0,h=d.length;_<h;_++)d[_].onTriggerStay(n)}else if(c._needProcessCollisions)for(_=0,h=d.length;_<h;_++)a.other=n,d[_].onCollisionStay(a)}else{if(l=(o=n.owner)._scripts)if(a._isTrigger){if(o._needProcessTriggers)for(_=0,h=l.length;_<h;_++)l[_].onTriggerEnter(s)}else if(o._needProcessCollisions)for(_=0,h=l.length;_<h;_++)a.other=s,l[_].onCollisionEnter(a);if(d=(c=s.owner)._scripts)if(a._isTrigger){if(c._needProcessTriggers)for(_=0,h=d.length;_<h;_++)d[_].onTriggerEnter(n)}else if(c._needProcessCollisions)for(_=0,h=d.length;_<h;_++)a.other=n,d[_].onCollisionEnter(a)}}for(r=0,i=this._previousFrameCollisions.length;r<i;r++){var u=this._previousFrameCollisions[r],m=u._colliderA,f=u._colliderB;if(!m.destroyed&&!f.destroyed&&e-u._updateFrame==1){if(this._collisionsUtils.recoverCollision(u),l=(o=m.owner)._scripts)if(u._isTrigger){if(o._needProcessTriggers)for(_=0,h=l.length;_<h;_++)l[_].onTriggerExit(f)}else if(o._needProcessCollisions)for(_=0,h=l.length;_<h;_++)u.other=f,l[_].onCollisionExit(u);if(d=(c=f.owner)._scripts)if(u._isTrigger){if(c._needProcessTriggers)for(_=0,h=d.length;_<h;_++)d[_].onTriggerExit(m)}else if(c._needProcessCollisions)for(_=0,h=d.length;_<h;_++)u.other=m,d[_].onCollisionExit(u)}}for(var T in this._currentConstraint){var E=this._currentConstraint[T],p=E.owner._scripts;if(E.enabled&&E._isBreakConstrained()&&p&&0!=p.length)for(r=0,i=p.length;r<i;r++)p[r].onJointBreak()}}clearForces(){if(!this._btDiscreteDynamicsWorld)throw"Cannot perform this action when the physics engine is set to CollisionsOnly";g.Physics3D._bullet.btDiscreteDynamicsWorld_clearForces(this._btDiscreteDynamicsWorld)}}G.PHYSICSENGINEFLAGS_NONE=0,G.PHYSICSENGINEFLAGS_COLLISIONSONLY=1,G.PHYSICSENGINEFLAGS_SOFTBODYSUPPORT=2,G.PHYSICSENGINEFLAGS_MULTITHREADED=4,G.PHYSICSENGINEFLAGS_USEHARDWAREWHENPOSSIBLE=8,G.SOLVERMODE_RANDMIZE_ORDER=1,G.SOLVERMODE_FRICTION_SEPARATE=2,G.SOLVERMODE_USE_WARMSTARTING=4,G.SOLVERMODE_USE_2_FRICTION_DIRECTIONS=16,G.SOLVERMODE_ENABLE_FRICTION_DIRECTION_CACHING=32,G.SOLVERMODE_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION=64,G.SOLVERMODE_CACHE_FRIENDLY=128,G.SOLVERMODE_SIMD=256,G.SOLVERMODE_INTERLEAVE_CONTACT_AND_FRICTION_CONSTRAINTS=512,G.SOLVERMODE_ALLOW_ZERO_LENGTH_FRICTION_DIRECTIONS=1024,G.HITSRAYRESULTCALLBACK_FLAG_NONE=0,G.HITSRAYRESULTCALLBACK_FLAG_FILTERBACKFACESS=1,G.HITSRAYRESULTCALLBACK_FLAG_KEEPUNFILIPPEDNORMAL=2,G.HITSRAYRESULTCALLBACK_FLAG_USESUBSIMPLEXCONVEXCASTRAYTEST=4,G.HITSRAYRESULTCALLBACK_FLAG_USEGJKCONVEXCASTRAYTEST=8,G.HITSRAYRESULTCALLBACK_FLAG_TERMINATOR=4294967295,G._tempVector30=new n,G.disableSimulation=!1;class z{constructor(){}static lightAttenTexture(e,t,r,i,a,n){var s=e/r,o=1/(1+25*s);s>=.64&&(s>1?o=0:o*=1-(s-.64)/.36),n[a]=Math.floor(255*o+.5)}static haloTexture(e,t,r,i,a,n){var s=(e-(r>>=1))/r,o=(t-(i>>=1))/i,l=s*s+o*o;l>1&&(l=1),n[a]=Math.floor(255*(1-l)+.5)}static _generateTexture2D(e,r,i,a){var n=0,s=0;switch(e.format){case t.TextureFormat.R8G8B8:s=3;break;case t.TextureFormat.R8G8B8A8:s=4;break;case t.TextureFormat.Alpha8:s=1;break;default:throw"GeneratedTexture._generateTexture: unkonw texture format."}for(var o=new Uint8Array(r*i*s),l=0;l<i;l++)for(var _=0;_<r;_++)a(_,l,r,i,n,o),n+=s;e.setPixels(o)}}class H{static _createFloatTextureBuffer(e,r){var i=new t.Texture2D(e,r,t.TextureFormat.R32G32B32A32,!1,!1);return i.filterMode=t.FilterMode.Point,i.wrapModeU=t.WarpMode.Clamp,i.wrapModeV=t.WarpMode.Clamp,i.anisoLevel=0,i}static _convertToLayaVec3(e,t,r){var i=g.Physics3D._bullet;t.x=r?-i.btVector3_x(e):i.btVector3_x(e),t.y=i.btVector3_y(e),t.z=i.btVector3_z(e)}static _convertToBulletVec3(e,t,r){g.Physics3D._bullet.btVector3_setValue(t,r?-e.x:e.x,e.y,e.z)}static _rotationTransformScaleSkinAnimation(e,t,r,i,a,n,s,o,l,_,h,c){var d,u,m,f,T,E=H._tempArray16_0,p=H._tempArray16_1,g=H._tempArray16_2,S=i+i,R=a+a,v=n+n,x=i*S,A=a*S,I=a*R,M=n*S,D=n*R,C=n*v,y=s*S,L=s*R,O=s*v;for(E[15]=1,E[0]=1-I-C,E[1]=A+O,E[2]=M-L,E[4]=A-O,E[5]=1-x-C,E[6]=D+y,E[8]=M+L,E[9]=D-y,E[10]=1-x-I,p[15]=1,p[0]=o,p[5]=l,p[10]=_,d=0;d<4;d++)u=E[d],m=E[d+4],f=E[d+8],T=E[d+12],g[d]=u,g[d+4]=m,g[d+8]=f,g[d+12]=u*e+m*t+f*r+T;for(d=0;d<4;d++)u=g[d],m=g[d+4],f=g[d+8],T=g[d+12],h[d+c]=u*p[0]+m*p[1]+f*p[2]+T*p[3],h[d+c+4]=u*p[4]+m*p[5]+f*p[6]+T*p[7],h[d+c+8]=u*p[8]+m*p[9]+f*p[10]+T*p[11],h[d+c+12]=u*p[12]+m*p[13]+f*p[14]+T*p[15]}static _computeBoneAndAnimationDatasByBindPoseMatrxix(e,t,r,i,a,n){var s,o,l=0,_=0,h=e.length;for(s=0;s<h;l+=e[s].keyframeWidth,_+=16,s++)H._rotationTransformScaleSkinAnimation(t[l+0],t[l+1],t[l+2],t[l+3],t[l+4],t[l+5],t[l+6],t[l+7],t[l+8],t[l+9],i,_),0!=s&&(o=16*e[s].parentIndex,H.mulMatrixByArray(i,o,i,_,i,_));var c=r.length;for(s=0;s<c;s++)H.mulMatrixByArrayAndMatrixFast(i,16*n[s],r[s],a,16*s)}static _computeAnimationDatasByArrayAndMatrixFast(e,t,r,i){for(var a=0,n=e.length;a<n;a++)H.mulMatrixByArrayAndMatrixFast(t,16*i[a],e[a],r,16*a)}static _computeBoneAndAnimationDatasByBindPoseMatrxixOld(e,t,r,i,a){var n,s,o=0,l=0,_=e.length;for(n=0;n<_;o+=e[n].keyframeWidth,l+=16,n++)H._rotationTransformScaleSkinAnimation(t[o+7],t[o+8],t[o+9],t[o+3],t[o+4],t[o+5],t[o+6],t[o+0],t[o+1],t[o+2],i,l),0!=n&&(s=16*e[n].parentIndex,H.mulMatrixByArray(i,s,i,l,i,l));var h=r.length;for(n=0;n<h;n++){var c=16*n;H.mulMatrixByArrayAndMatrixFast(i,c,r[n],a,c)}}static _computeAnimationDatasByArrayAndMatrixFastOld(e,t,r){for(var i=e.length,a=0;a<i;a++){var n=16*a;H.mulMatrixByArrayAndMatrixFast(t,n,e[a],r,n)}}static _computeRootAnimationData(e,t,r){for(var i=0,a=0,n=0,s=e.length;i<s;a+=e[i].keyframeWidth,n+=16,i++)H.createAffineTransformationArray(t[a+0],t[a+1],t[a+2],t[a+3],t[a+4],t[a+5],t[a+6],t[a+7],t[a+8],t[a+9],r,n)}static transformVector3ArrayByQuat(e,t,r,i,a){var n=e[t],s=e[t+1],o=e[t+2],l=r.x,_=r.y,h=r.z,c=r.w,d=c*n+_*o-h*s,u=c*s+h*n-l*o,m=c*o+l*s-_*n,f=-l*n-_*s-h*o;i[a]=d*c+f*-l+u*-h-m*-_,i[a+1]=u*c+f*-_+m*-l-d*-h,i[a+2]=m*c+f*-h+d*-_-u*-l}static mulMatrixByArray(e,t,r,i,a,n){var s,o,l,_,h;if(a===r){for(r=H._tempArray16_3,s=0;s<16;++s)r[s]=a[n+s];i=0}for(s=0;s<4;s++)o=e[t+s],l=e[t+s+4],_=e[t+s+8],h=e[t+s+12],a[n+s]=o*r[i+0]+l*r[i+1]+_*r[i+2]+h*r[i+3],a[n+s+4]=o*r[i+4]+l*r[i+5]+_*r[i+6]+h*r[i+7],a[n+s+8]=o*r[i+8]+l*r[i+9]+_*r[i+10]+h*r[i+11],a[n+s+12]=o*r[i+12]+l*r[i+13]+_*r[i+14]+h*r[i+15]}static mulMatrixByArrayFast(e,t,r,i,a,n){var s,o,l,_,h;for(s=0;s<4;s++)o=e[t+s],l=e[t+s+4],_=e[t+s+8],h=e[t+s+12],a[n+s]=o*r[i+0]+l*r[i+1]+_*r[i+2]+h*r[i+3],a[n+s+4]=o*r[i+4]+l*r[i+5]+_*r[i+6]+h*r[i+7],a[n+s+8]=o*r[i+8]+l*r[i+9]+_*r[i+10]+h*r[i+11],a[n+s+12]=o*r[i+12]+l*r[i+13]+_*r[i+14]+h*r[i+15]}static mulMatrixByArrayAndMatrixFast(e,t,r,i,a){var n,s,o,l,_,h=r.elements,c=h[0],d=h[1],u=h[2],m=h[3],f=h[4],T=h[5],E=h[6],p=h[7],g=h[8],S=h[9],R=h[10],v=h[11],x=h[12],A=h[13],I=h[14],M=h[15],D=t,C=t+4,y=t+8,L=t+12,O=a,N=a+4,P=a+8,b=a+12;for(n=0;n<4;n++)s=e[D+n],o=e[C+n],l=e[y+n],_=e[L+n],i[O+n]=s*c+o*d+l*u+_*m,i[N+n]=s*f+o*T+l*E+_*p,i[P+n]=s*g+o*S+l*R+_*v,i[b+n]=s*x+o*A+l*I+_*M}static createAffineTransformationArray(e,t,r,i,a,n,s,o,l,_,h,c){var d=i+i,u=a+a,m=n+n,f=i*d,T=i*u,E=i*m,p=a*u,g=a*m,S=n*m,R=s*d,v=s*u,x=s*m;h[c+0]=(1-(p+S))*o,h[c+1]=(T+x)*o,h[c+2]=(E-v)*o,h[c+3]=0,h[c+4]=(T-x)*l,h[c+5]=(1-(f+S))*l,h[c+6]=(g+R)*l,h[c+7]=0,h[c+8]=(E+v)*_,h[c+9]=(g-R)*_,h[c+10]=(1-(f+p))*_,h[c+11]=0,h[c+12]=e,h[c+13]=t,h[c+14]=r,h[c+15]=1}static transformVector3ArrayToVector3ArrayCoordinate(e,t,r,i,a){var n=e[t+0],s=e[t+1],o=e[t+2],l=r.elements,_=n*l[3]+s*l[7]+o*l[11]+l[15];i[a]=n*l[0]+s*l[4]+o*l[8]+l[12]/_,i[a+1]=n*l[1]+s*l[5]+o*l[9]+l[13]/_,i[a+2]=n*l[2]+s*l[6]+o*l[10]+l[14]/_}static transformVector3ArrayToVector3ArrayNormal(e,t,r,i,a){var n=e[t+0],s=e[t+1],o=e[t+2],l=r.elements;i[a]=n*l[0]+s*l[4]+o*l[8],i[a+1]=n*l[1]+s*l[5]+o*l[9],i[a+2]=n*l[2]+s*l[6]+o*l[10]}static transformLightingMapTexcoordArray(e,t,r,i,a){i[a+0]=e[t+0]*r.x+r.z,i[a+1]=1-((1-e[t+1])*r.y+r.w)}static getURLVerion(e){var t=e.indexOf("?");return t>=0?e.substr(t):null}static _createAffineTransformationArray(e,t,r,i){var a=t.x,n=t.y,s=t.z,o=t.w,l=a+a,_=n+n,h=s+s,c=a*l,d=a*_,u=a*h,m=n*_,f=n*h,T=s*h,E=o*l,p=o*_,g=o*h,S=r.x,R=r.y,v=r.z;i[0]=(1-(m+T))*S,i[1]=(d+g)*S,i[2]=(u-p)*S,i[3]=0,i[4]=(d-g)*R,i[5]=(1-(c+T))*R,i[6]=(f+E)*R,i[7]=0,i[8]=(u+p)*v,i[9]=(f-E)*v,i[10]=(1-(c+m))*v,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1}static _mulMatrixArray(e,t,r,i,a){var n=t,s=e,o=i,l=n[r],_=n[r+1],h=n[r+2],c=n[r+3],d=n[r+4],u=n[r+5],m=n[r+6],f=n[r+7],T=n[r+8],E=n[r+9],p=n[r+10],g=n[r+11],S=n[r+12],R=n[r+13],v=n[r+14],x=n[r+15],A=s[0],I=s[1],M=s[2],D=s[3],C=s[4],y=s[5],L=s[6],O=s[7],N=s[8],P=s[9],b=s[10],w=s[11],V=s[12],B=s[13],F=s[14],U=s[15];o[a]=l*A+_*C+h*N+c*V,o[a+1]=l*I+_*y+h*P+c*B,o[a+2]=l*M+_*L+h*b+c*F,o[a+3]=l*D+_*O+h*w+c*U,o[a+4]=d*A+u*C+m*N+f*V,o[a+5]=d*I+u*y+m*P+f*B,o[a+6]=d*M+u*L+m*b+f*F,o[a+7]=d*D+u*O+m*w+f*U,o[a+8]=T*A+E*C+p*N+g*V,o[a+9]=T*I+E*y+p*P+g*B,o[a+10]=T*M+E*L+p*b+g*F,o[a+11]=T*D+E*O+p*w+g*U,o[a+12]=S*A+R*C+v*N+x*V,o[a+13]=S*I+R*y+v*P+x*B,o[a+14]=S*M+R*L+v*b+x*F,o[a+15]=S*D+R*O+v*w+x*U}static arcTanAngle(e,t){return 0==e?1==t?Math.PI/2:-Math.PI/2:e>0?Math.atan(t/e):e<0?t>0?Math.atan(t/e)+Math.PI:Math.atan(t/e)-Math.PI:0}static angleTo(e,t,r){n.subtract(t,e,S.TEMPVector30),n.normalize(S.TEMPVector30,S.TEMPVector30),r.x=Math.asin(S.TEMPVector30.y),r.y=H.arcTanAngle(-S.TEMPVector30.z,-S.TEMPVector30.x)}static transformQuat(e,t,r){var i=t,a=e.x,n=e.y,s=e.z,o=i[0],l=i[1],_=i[2],h=i[3],c=h*a+l*s-_*n,d=h*n+_*a-o*s,u=h*s+o*n-l*a,m=-o*a-l*n-_*s;r.x=c*h+m*-o+d*-_-u*-l,r.y=d*h+m*-l+u*-o-c*-_,r.z=u*h+m*-_+c*-l-d*-o}static quaternionWeight(e,t,r){r.x=e.x*t,r.y=e.y*t,r.z=e.z*t,r.w=e.w}static quaternionConjugate(e,t){t.x=-e.x,t.y=-e.y,t.z=-e.z,t.w=e.w}static scaleWeight(e,t,r){var i=e.x,a=e.y,n=e.z;r.x=i>0?Math.pow(Math.abs(i),t):-Math.pow(Math.abs(i),t),r.y=a>0?Math.pow(Math.abs(a),t):-Math.pow(Math.abs(a),t),r.z=n>0?Math.pow(Math.abs(n),t):-Math.pow(Math.abs(n),t)}static scaleBlend(e,t,r,i){var a=H._tempVector3_0,n=H._tempVector3_1;H.scaleWeight(e,1-r,a),H.scaleWeight(t,r,n);var s=r>.5?t:e;i.x=s.x>0?Math.abs(a.x*n.x):-Math.abs(a.x*n.x),i.y=s.y>0?Math.abs(a.y*n.y):-Math.abs(a.y*n.y),i.z=s.z>0?Math.abs(a.z*n.z):-Math.abs(a.z*n.z)}static matrix4x4MultiplyFFF(e,t,r){var i,a,n,s,o;if(r===t)for(t=new Float32Array(16),i=0;i<16;++i)t[i]=r[i];var l=t[0],_=t[1],h=t[2],c=t[3],d=t[4],u=t[5],m=t[6],f=t[7],T=t[8],E=t[9],p=t[10],g=t[11],S=t[12],R=t[13],v=t[14],x=t[15];for(i=0;i<4;i++)a=e[i],n=e[i+4],s=e[i+8],o=e[i+12],r[i]=a*l+n*_+s*h+o*c,r[i+4]=a*d+n*u+s*m+o*f,r[i+8]=a*T+n*E+s*p+o*g,r[i+12]=a*S+n*R+s*v+o*x}static matrix4x4MultiplyFFFForNative(e,r,i){t.LayaGL.instance.matrix4x4Multiply(e,r,i)}static matrix4x4MultiplyMFM(e,t,r){H.matrix4x4MultiplyFFF(e.elements,t,r.elements)}static _buildTexture2D(e,r,i,a,n=!1){var s=new t.Texture2D(e,r,i,n,!0);return s.anisoLevel=1,s.filterMode=t.FilterMode.Point,z._generateTexture2D(s,e,r,a),s}static _drawBound(e,t,r){e.lineCount+12>e.maxLineCount&&(e.maxLineCount+=12);var i=H._tempVector3_0,a=H._tempVector3_1,n=t.min,s=t.max;i.setValue(n.x,n.y,n.z),a.setValue(s.x,n.y,n.z),e.addLine(i,a,r,r),i.setValue(n.x,n.y,n.z),a.setValue(n.x,n.y,s.z),e.addLine(i,a,r,r),i.setValue(s.x,n.y,n.z),a.setValue(s.x,n.y,s.z),e.addLine(i,a,r,r),i.setValue(n.x,n.y,s.z),a.setValue(s.x,n.y,s.z),e.addLine(i,a,r,r),i.setValue(n.x,n.y,n.z),a.setValue(n.x,s.y,n.z),e.addLine(i,a,r,r),i.setValue(n.x,n.y,s.z),a.setValue(n.x,s.y,s.z),e.addLine(i,a,r,r),i.setValue(s.x,n.y,n.z),a.setValue(s.x,s.y,n.z),e.addLine(i,a,r,r),i.setValue(s.x,n.y,s.z),a.setValue(s.x,s.y,s.z),e.addLine(i,a,r,r),i.setValue(n.x,s.y,n.z),a.setValue(s.x,s.y,n.z),e.addLine(i,a,r,r),i.setValue(n.x,s.y,n.z),a.setValue(n.x,s.y,s.z),e.addLine(i,a,r,r),i.setValue(s.x,s.y,n.z),a.setValue(s.x,s.y,s.z),e.addLine(i,a,r,r),i.setValue(n.x,s.y,s.z),a.setValue(s.x,s.y,s.z),e.addLine(i,a,r,r)}static _getHierarchyPath(e,t,r){r.length=0;for(var i=t;i!==e;){var a=i._parent;if(!a)return null;r.push(a.getChildIndex(i)),i=a}return r}static _getNodeByHierarchyPath(e,t){for(var r=e,i=t.length-1;i>=0;i--)r=r.getChildAt(t[i]);return r}}H._tempVector3_0=new n,H._tempVector3_1=new n,H._tempArray16_0=new Float32Array(16),H._tempArray16_1=new Float32Array(16),H._tempArray16_2=new Float32Array(16),H._tempArray16_3=new Float32Array(16),H._compIdToNode=new Object;class k extends P{constructor(e=.1,t=null,r=M.COLLISIONFILTERGROUP_DEFAULTFILTER,i=M.COLLISIONFILTERGROUP_ALLFILTER){super(r,i),this._upAxis=new n(0,1,0),this._maxSlope=45,this._jumpSpeed=10,this._fallSpeed=55,this._gravity=new n(0,3*-9.8,0),this._btKinematicCharacter=null,this._stepHeight=e,t&&(this._upAxis=t),this._controlBySimulation=!0}static __init__(){k._btTempVector30=g.Physics3D._bullet.btVector3_create(0,0,0)}get fallSpeed(){return this._fallSpeed}set fallSpeed(e){this._fallSpeed=e,g.Physics3D._bullet.btKinematicCharacterController_setFallSpeed(this._btKinematicCharacter,e)}get jumpSpeed(){return this._jumpSpeed}set jumpSpeed(e){this._jumpSpeed=e,g.Physics3D._bullet.btKinematicCharacterController_setJumpSpeed(this._btKinematicCharacter,e)}get gravity(){return this._gravity}set gravity(e){this._gravity=e;var t=g.Physics3D._bullet,r=k._btTempVector30;t.btVector3_setValue(r,-e.x,e.y,e.z),t.btKinematicCharacterController_setGravity(this._btKinematicCharacter,r)}get maxSlope(){return this._maxSlope}set maxSlope(e){this._maxSlope=e,g.Physics3D._bullet.btKinematicCharacterController_setMaxSlope(this._btKinematicCharacter,e/180*Math.PI)}get isGrounded(){return g.Physics3D._bullet.btKinematicCharacterController_onGround(this._btKinematicCharacter)}get stepHeight(){return this._stepHeight}set stepHeight(e){this._stepHeight=e,g.Physics3D._bullet.btKinematicCharacterController_setStepHeight(this._btKinematicCharacter,e)}get upAxis(){return this._upAxis}set upAxis(e){this._upAxis=e;var t=k._btTempVector30;H._convertToBulletVec3(e,t,!1),g.Physics3D._bullet.btKinematicCharacterController_setUp(this._btKinematicCharacter,t)}_constructCharacter(){var e=g.Physics3D._bullet;this._btKinematicCharacter&&e.btKinematicCharacterController_destroy(this._btKinematicCharacter);var t=k._btTempVector30;e.btVector3_setValue(t,this._upAxis.x,this._upAxis.y,this._upAxis.z),this._btKinematicCharacter=e.btKinematicCharacterController_create(this._btColliderObject,this._colliderShape._btShape,this._stepHeight,t),this.fallSpeed=this._fallSpeed,this.maxSlope=this._maxSlope,this.jumpSpeed=this._jumpSpeed,this.gravity=this._gravity}_onShapeChange(e){super._onShapeChange(e),this._constructCharacter()}_onAdded(){var e=g.Physics3D._bullet,t=e.btPairCachingGhostObject_create();e.btCollisionObject_setUserIndex(t,this.id),e.btCollisionObject_setCollisionFlags(t,P.COLLISIONFLAGS_CHARACTER_OBJECT),this._btColliderObject=t,this._colliderShape&&this._constructCharacter(),super._onAdded()}_addToSimulation(){this._simulation._characters.push(this),this._simulation._addCharacter(this,this._collisionGroup,this._canCollideWith)}_removeFromSimulation(){this._simulation._removeCharacter(this);var e=this._simulation._characters;e.splice(e.indexOf(this),1)}_cloneTo(e){super._cloneTo(e);var t=e;t.stepHeight=this._stepHeight,t.upAxis=this._upAxis,t.maxSlope=this._maxSlope,t.jumpSpeed=this._jumpSpeed,t.fallSpeed=this._fallSpeed,t.gravity=this._gravity}_onDestroy(){g.Physics3D._bullet.btKinematicCharacterController_destroy(this._btKinematicCharacter),super._onDestroy(),this._btKinematicCharacter=null}move(e){var t=k._btVector30,r=g.Physics3D._bullet;r.btVector3_setValue(t,-e.x,e.y,e.z),r.btKinematicCharacterController_setWalkDirection(this._btKinematicCharacter,t)}jump(e=null){var t=g.Physics3D._bullet,r=k._btVector30;e?(H._convertToBulletVec3(e,r,!0),t.btKinematicCharacterController_jump(this._btKinematicCharacter,r)):(t.btVector3_setValue(r,0,0,0),t.btKinematicCharacterController_jump(this._btKinematicCharacter,r))}}k.UPAXIS_X=0,k.UPAXIS_Y=1,k.UPAXIS_Z=2;class W extends P{constructor(e,t){super(e,t),this._isTrigger=!1}get isTrigger(){return this._isTrigger}set isTrigger(e){this._isTrigger=e;var t=g.Physics3D._bullet;if(this._btColliderObject){var r=t.btCollisionObject_getCollisionFlags(this._btColliderObject);e?0==(r&P.COLLISIONFLAGS_NO_CONTACT_RESPONSE)&&t.btCollisionObject_setCollisionFlags(this._btColliderObject,r|P.COLLISIONFLAGS_NO_CONTACT_RESPONSE):0!=(r&P.COLLISIONFLAGS_NO_CONTACT_RESPONSE)&&t.btCollisionObject_setCollisionFlags(this._btColliderObject,r^P.COLLISIONFLAGS_NO_CONTACT_RESPONSE)}}_onAdded(){super._onAdded(),this.isTrigger=this._isTrigger}_cloneTo(e){super._cloneTo(e),e.isTrigger=this._isTrigger}}class X extends W{constructor(e=M.COLLISIONFILTERGROUP_DEFAULTFILTER,t=M.COLLISIONFILTERGROUP_ALLFILTER){super(e,t),this._isKinematic=!1,this._mass=1,this._gravity=new n(0,-10,0),this._angularDamping=0,this._linearDamping=0,this._overrideGravity=!1,this._totalTorque=new n(0,0,0),this._totalForce=new n(0,0,0),this._linearVelocity=new n,this._angularVelocity=new n,this._linearFactor=new n(1,1,1),this._angularFactor=new n(1,1,1),this._detectCollisions=!0,this._controlBySimulation=!0}static __init__(){var e=g.Physics3D._bullet;X._btTempVector30=e.btVector3_create(0,0,0),X._btTempVector31=e.btVector3_create(0,0,0),X._btVector3Zero=e.btVector3_create(0,0,0),X._btInertia=e.btVector3_create(0,0,0),X._btImpulse=e.btVector3_create(0,0,0),X._btImpulseOffset=e.btVector3_create(0,0,0),X._btGravity=e.btVector3_create(0,0,0),X._btTransform0=e.btTransform_create()}get mass(){return this._mass}set mass(e){e=Math.max(e,1e-7),this._mass=e,this._isKinematic||this._updateMass(e)}get isKinematic(){return this._isKinematic}set isKinematic(e){this._isKinematic=e,this._controlBySimulation=!e;var t=g.Physics3D._bullet,r=!!(this._simulation&&this._enabled&&this._colliderShape);r&&this._removeFromSimulation();var i=this._btColliderObject,a=t.btCollisionObject_getCollisionFlags(i);e?(a|=P.COLLISIONFLAGS_KINEMATIC_OBJECT,t.btCollisionObject_setCollisionFlags(i,a),t.btCollisionObject_forceActivationState(this._btColliderObject,P.ACTIVATIONSTATE_DISABLE_DEACTIVATION),this._enableProcessCollisions=!1,this._updateMass(0)):((a&P.COLLISIONFLAGS_KINEMATIC_OBJECT)>0&&(a^=P.COLLISIONFLAGS_KINEMATIC_OBJECT),t.btCollisionObject_setCollisionFlags(i,a),t.btCollisionObject_setActivationState(this._btColliderObject,P.ACTIVATIONSTATE_ACTIVE_TAG),this._enableProcessCollisions=!0,this._updateMass(this._mass));var n=X._btVector3Zero;t.btCollisionObject_setInterpolationLinearVelocity(i,n),t.btRigidBody_setLinearVelocity(i,n),t.btCollisionObject_setInterpolationAngularVelocity(i,n),t.btRigidBody_setAngularVelocity(i,n),r&&this._addToSimulation()}get linearDamping(){return this._linearDamping}set linearDamping(e){this._linearDamping=e,this._btColliderObject&&g.Physics3D._bullet.btRigidBody_setDamping(this._btColliderObject,e,this._angularDamping)}get angularDamping(){return this._angularDamping}set angularDamping(e){this._angularDamping=e,this._btColliderObject&&g.Physics3D._bullet.btRigidBody_setDamping(this._btColliderObject,this._linearDamping,e)}get overrideGravity(){return this._overrideGravity}set overrideGravity(e){this._overrideGravity=e;var t=g.Physics3D._bullet;if(this._btColliderObject){var r=t.btRigidBody_getFlags(this._btColliderObject);e?0==(r&X._BT_DISABLE_WORLD_GRAVITY)&&t.btRigidBody_setFlags(this._btColliderObject,r|X._BT_DISABLE_WORLD_GRAVITY):(r&X._BT_DISABLE_WORLD_GRAVITY)>0&&t.btRigidBody_setFlags(this._btColliderObject,r^X._BT_DISABLE_WORLD_GRAVITY)}}get gravity(){var e=g.Physics3D._bullet;return X._btGravity=e.btRigidBody_getGravity(this._btColliderObject),H._convertToLayaVec3(X._btGravity,this._gravity,!0),this._gravity}set gravity(e){this._gravity=e;var t=g.Physics3D._bullet;t.btVector3_setValue(X._btGravity,-e.x,e.y,e.z),t.btRigidBody_setGravity(this._btColliderObject,X._btGravity)}get totalForce(){if(this._btColliderObject){var e=g.Physics3D._bullet.btRigidBody_getTotalForce(this._btColliderObject);return H._convertToLayaVec3(e,this._totalForce,!0),this._totalForce}return null}get linearFactor(){return this._linearFactor}set linearFactor(e){this._linearFactor=e;var t=X._btTempVector30;H._convertToBulletVec3(e,t,!1),g.Physics3D._bullet.btRigidBody_setLinearFactor(this._btColliderObject,t)}get linearVelocity(){return this._btColliderObject&&H._convertToLayaVec3(g.Physics3D._bullet.btRigidBody_getLinearVelocity(this._btColliderObject),this._linearVelocity,!0),this._linearVelocity}set linearVelocity(e){if(this._linearVelocity=e,this._btColliderObject){var t=X._btTempVector30;H._convertToBulletVec3(e,t,!0),this.isSleeping&&this.wakeUp(),g.Physics3D._bullet.btRigidBody_setLinearVelocity(this._btColliderObject,t)}}get angularFactor(){return this._angularFactor}set angularFactor(e){this._angularFactor=e;var t=X._btTempVector30;H._convertToBulletVec3(e,t,!1),g.Physics3D._bullet.btRigidBody_setAngularFactor(this._btColliderObject,t)}get angularVelocity(){return this._btColliderObject&&H._convertToLayaVec3(g.Physics3D._bullet.btRigidBody_getAngularVelocity(this._btColliderObject),this._angularVelocity,!0),this._angularVelocity}set angularVelocity(e){if(this._angularVelocity=e,this._btColliderObject){var t=X._btTempVector30;H._convertToBulletVec3(e,t,!0),this.isSleeping&&this.wakeUp(),g.Physics3D._bullet.btRigidBody_setAngularVelocity(this._btColliderObject,t)}}get totalTorque(){if(this._btColliderObject){var e=g.Physics3D._bullet.btRigidBody_getTotalTorque(this._btColliderObject);return H._convertToLayaVec3(e,this._totalTorque,!0),this._totalTorque}return null}get detectCollisions(){return this._detectCollisions}set detectCollisions(e){this._detectCollisions!==e&&(this._detectCollisions=e,this._colliderShape&&this._enabled&&this._simulation&&(this._simulation._removeRigidBody(this),this._simulation._addRigidBody(this,this._collisionGroup,e?this._canCollideWith:0)))}get isSleeping(){return!!this._btColliderObject&&g.Physics3D._bullet.btCollisionObject_getActivationState(this._btColliderObject)===P.ACTIVATIONSTATE_ISLAND_SLEEPING}get sleepLinearVelocity(){return g.Physics3D._bullet.btRigidBody_getLinearSleepingThreshold(this._btColliderObject)}set sleepLinearVelocity(e){var t=g.Physics3D._bullet;t.btRigidBody_setSleepingThresholds(this._btColliderObject,e,t.btRigidBody_getAngularSleepingThreshold(this._btColliderObject))}get sleepAngularVelocity(){return g.Physics3D._bullet.btRigidBody_getAngularSleepingThreshold(this._btColliderObject)}set sleepAngularVelocity(e){var t=g.Physics3D._bullet;t.btRigidBody_setSleepingThresholds(this._btColliderObject,t.btRigidBody_getLinearSleepingThreshold(this._btColliderObject),e)}get btColliderObject(){return this._btColliderObject}set constaintRigidbodyA(e){this._constaintRigidbodyA=e}get constaintRigidbodyA(){return this._constaintRigidbodyA}set constaintRigidbodyB(e){this._constaintRigidbodyB=e}get constaintRigidbodyB(){return this._constaintRigidbodyB}_updateMass(e){if(this._btColliderObject&&this._colliderShape){var t=g.Physics3D._bullet;t.btCollisionShape_calculateLocalInertia(this._colliderShape._btShape,e,X._btInertia),t.btRigidBody_setMassProps(this._btColliderObject,e,X._btInertia),t.btRigidBody_updateInertiaTensor(this._btColliderObject)}}_onScaleChange(e){super._onScaleChange(e),this._updateMass(this._isKinematic?0:this._mass)}_derivePhysicsTransformation(e){var t=g.Physics3D._bullet,r=this._btColliderObject,i=t.btCollisionObject_getWorldTransform(r),a=X._btTransform0;t.btTransform_equal(a,i),this._innerDerivePhysicsTransformation(a,e),t.btRigidBody_setCenterOfMassTransform(r,a)}_onAdded(){var e=g.Physics3D._bullet,t=e.layaMotionState_create();e.layaMotionState_set_rigidBodyID(t,this._id),this._btLayaMotionState=t;var r=e.btRigidBodyConstructionInfo_create(0,t,null,X._btVector3Zero),i=e.btRigidBody_create(r);e.btCollisionObject_setUserIndex(i,this.id),this._btColliderObject=i,super._onAdded(),this.mass=this._mass,this.linearFactor=this._linearFactor,this.angularFactor=this._angularFactor,this.linearDamping=this._linearDamping,this.angularDamping=this._angularDamping,this.overrideGravity=this._overrideGravity,this.gravity=this._gravity,this.isKinematic=this._isKinematic,e.btRigidBodyConstructionInfo_destroy(r)}_onEnable(){super._onEnable(),this._constaintRigidbodyA&&this._constaintRigidbodyA.connectedBody._simulation&&(this._constaintRigidbodyA._createConstraint(),this._constaintRigidbodyA._onEnable()),this._constaintRigidbodyB&&this._constaintRigidbodyB.ownBody._simulation&&(this._constaintRigidbodyB._createConstraint(),this._constaintRigidbodyB._onEnable())}_onShapeChange(e){if(super._onShapeChange(e),this._isKinematic)this._updateMass(0);else{var t=g.Physics3D._bullet;t.btRigidBody_setCenterOfMassTransform(this._btColliderObject,t.btCollisionObject_getWorldTransform(this._btColliderObject)),this._updateMass(this._mass)}}_parse(e){if(null!=e.friction&&(this.friction=e.friction),null!=e.rollingFriction&&(this.rollingFriction=e.rollingFriction),null!=e.restitution&&(this.restitution=e.restitution),null!=e.isTrigger&&(this.isTrigger=e.isTrigger),null!=e.mass&&(this.mass=e.mass),null!=e.linearDamping&&(this.linearDamping=e.linearDamping),null!=e.angularDamping&&(this.angularDamping=e.angularDamping),null!=e.overrideGravity&&(this.overrideGravity=e.overrideGravity),null!=e.linearFactor){var t=this.linearFactor;t.fromArray(e.linearFactor),this.linearFactor=t}if(null!=e.angularFactor){var r=this.angularFactor;r.fromArray(e.angularFactor),this.angularFactor=r}e.gravity&&(this.gravity.fromArray(e.gravity),this.gravity=this.gravity),super._parse(e),this._parseShape(e.shapes),null!=e.isKinematic&&(this.isKinematic=e.isKinematic)}_onDestroy(){g.Physics3D._bullet.btMotionState_destroy(this._btLayaMotionState),super._onDestroy(),this._btLayaMotionState=null,this._gravity=null,this._totalTorque=null,this._linearVelocity=null,this._angularVelocity=null,this._linearFactor=null,this._angularFactor=null,this.constaintRigidbodyA&&this.constaintRigidbodyA._breakConstrained(),this.constaintRigidbodyB&&(this.constaintRigidbodyB.connectedBody=null,this.constaintRigidbodyB._onDisable())}_addToSimulation(){this._simulation._addRigidBody(this,this._collisionGroup,this._detectCollisions?this._canCollideWith:0)}_removeFromSimulation(){this._simulation._removeRigidBody(this)}_cloneTo(e){super._cloneTo(e);var t=e;t.isKinematic=this._isKinematic,t.mass=this._mass,t.gravity=this._gravity,t.angularDamping=this._angularDamping,t.linearDamping=this._linearDamping,t.overrideGravity=this._overrideGravity,t.linearVelocity=this._linearVelocity,t.angularVelocity=this._angularVelocity,t.linearFactor=this._linearFactor,t.angularFactor=this._angularFactor,t.detectCollisions=this._detectCollisions}applyForce(e,t=null){if(null==this._btColliderObject)throw"Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";var r=g.Physics3D._bullet,i=X._btTempVector30;if(r.btVector3_setValue(i,-e.x,e.y,e.z),t){var a=X._btTempVector31;r.btVector3_setValue(a,-t.x,t.y,t.z),r.btRigidBody_applyForce(this._btColliderObject,i,a)}else r.btRigidBody_applyCentralForce(this._btColliderObject,i)}applyTorque(e){if(null==this._btColliderObject)throw"Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";var t=g.Physics3D._bullet,r=X._btTempVector30;t.btVector3_setValue(r,-e.x,e.y,e.z),t.btRigidBody_applyTorque(this._btColliderObject,r)}applyImpulse(e,t=null){if(null==this._btColliderObject)throw"Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";var r=g.Physics3D._bullet;r.btVector3_setValue(X._btImpulse,-e.x,e.y,e.z),t?(r.btVector3_setValue(X._btImpulseOffset,-t.x,t.y,t.z),r.btRigidBody_applyImpulse(this._btColliderObject,X._btImpulse,X._btImpulseOffset)):r.btRigidBody_applyCentralImpulse(this._btColliderObject,X._btImpulse)}applyTorqueImpulse(e){if(null==this._btColliderObject)throw"Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";var t=g.Physics3D._bullet,r=X._btTempVector30;t.btVector3_setValue(r,-e.x,e.y,e.z),t.btRigidBody_applyTorqueImpulse(this._btColliderObject,r)}wakeUp(){this._btColliderObject&&g.Physics3D._bullet.btCollisionObject_activate(this._btColliderObject,!1)}clearForces(){var e=this._btColliderObject;if(null==e)throw"Attempted to call a Physics function that is avaliable only when the Entity has been already added to the Scene.";var t=g.Physics3D._bullet;t.btRigidBody_clearForces(e);var r=X._btVector3Zero;t.btCollisionObject_setInterpolationLinearVelocity(e,r),t.btRigidBody_setLinearVelocity(e,r),t.btCollisionObject_setInterpolationAngularVelocity(e,r),t.btRigidBody_setAngularVelocity(e,r)}}X.TYPE_STATIC=0,X.TYPE_DYNAMIC=1,X.TYPE_KINEMATIC=2,X._BT_DISABLE_WORLD_GRAVITY=1,X._BT_ENABLE_GYROPSCOPIC_FORCE=2;class Y{static __bulletinit__(){this._bullet=window.Physics3D,this._bullet&&(x.__init__(),v.__init__(),A.__init__(),P.__init__(),G.__init__(),D.__init__(),L.__init__(),k.__init__(),X.__init__())}static __cannoninit__(){this._cannon=window.CANNON,this._cannon&&(t.CannonColliderShape.__init__(),t.CannonPhysicsComponent.__init__(),t.CannonPhysicsSimulation.__init__(),t.CannonBoxColliderShape.__init__(),t.CannonRigidbody3D.__init__())}}Y._bullet=null,Y._cannon=null,Y._enablePhysics=!1;class j{constructor(){this._defaultPhysicsMemory=16,this._maxLightCount=32,this._lightClusterCount=new n(12,12,12),this._editerEnvironment=!1,this.isAntialias=!0,this.isAlpha=!1,this.premultipliedAlpha=!0,this.isStencil=!0,this.enableMultiLight=!0,this.octreeCulling=!1,this.octreeInitialSize=64,this.octreeInitialCenter=new n(0,0,0),this.octreeMinNodeSize=2,this.octreeLooseness=1.25,this.debugFrustumCulling=!1,this.pbrRenderQuality=e.PBRRenderQuality.High,this.isUseCannonPhysicsEngine=!1,this._maxAreaLightCountPerClusterAverage=Math.min(4*Math.floor(2048/this._lightClusterCount.z-1),this._maxLightCount)}static get useCannonPhysics(){return j._config.isUseCannonPhysicsEngine}static set useCannonPhysics(e){j._config.isUseCannonPhysicsEngine=e,e&&(Y.__cannoninit__(),g.Scene3D.cannonPhysicsSettings||(g.Scene3D.cannonPhysicsSettings=new t.CannonPhysicsSettings))}get defaultPhysicsMemory(){return this._defaultPhysicsMemory}set defaultPhysicsMemory(e){if(e<16)throw"defaultPhysicsMemory must large than 16M";this._defaultPhysicsMemory=e}get maxLightCount(){return this._maxLightCount}set maxLightCount(e){e>2048?(this._maxLightCount=2048,console.warn("Config3D: maxLightCount must less equal 2048.")):this._maxLightCount=e}get lightClusterCount(){return this._lightClusterCount}set lightClusterCount(e){e.x>128||e.y>128||e.z>128?(this._lightClusterCount.setValue(Math.min(e.x,128),Math.min(e.y,128),Math.min(e.z,128)),console.warn("Config3D: lightClusterCount X and Y、Z must less equal 128.")):e.cloneTo(this._lightClusterCount);var t=4*Math.floor(2048/this._lightClusterCount.z-1);t<this._maxLightCount&&console.warn("Config3D: if the area light(PointLight、SpotLight) count is large than "+t+",maybe the far away culster will ingonre some light."),this._maxAreaLightCountPerClusterAverage=Math.min(t,this._maxLightCount)}cloneTo(e){var t=e;t._defaultPhysicsMemory=this._defaultPhysicsMemory,t._editerEnvironment=this._editerEnvironment,t.isAntialias=this.isAntialias,t.isAlpha=this.isAlpha,t.premultipliedAlpha=this.premultipliedAlpha,t.isStencil=this.isStencil,t.octreeCulling=this.octreeCulling,this.octreeInitialCenter.cloneTo(t.octreeInitialCenter),t.octreeInitialSize=this.octreeInitialSize,t.octreeMinNodeSize=this.octreeMinNodeSize,t.octreeLooseness=this.octreeLooseness,t.debugFrustumCulling=this.debugFrustumCulling,t.maxLightCount=this.maxLightCount,t.enableMultiLight=this.enableMultiLight;var r=t.lightClusterCount;this.lightClusterCount.cloneTo(r),t.lightClusterCount=r,t.pbrRenderQuality=this.pbrRenderQuality}clone(){var e=new j;return this.cloneTo(e),e}}j._config=new j,window.Config3D=j;class Z{constructor(){this._ownerPath=[],this._propertys=[],this._keyFrames=[]}get ownerPathCount(){return this._ownerPath.length}get propertyCount(){return this._propertys.length}get keyFramesCount(){return this._keyFrames.length}_setOwnerPathCount(e){this._ownerPath.length=e}_setOwnerPathByIndex(e,t){this._ownerPath[e]=t}_joinOwnerPath(e){return this._ownerPath.join(e)}_setPropertyCount(e){this._propertys.length=e}_setPropertyByIndex(e,t){this._propertys[e]=t}_joinProperty(e){return this._propertys.join(e)}_setKeyframeCount(e){this._keyFrames.length=e}_setKeyframeByIndex(e,t){this._keyFrames[e]=t}getOwnerPathByIndex(e){return this._ownerPath[e]}getPropertyByIndex(e){return this._propertys[e]}getKeyframeByIndex(e){return this._keyFrames[e]}}class q{constructor(){}}class Q{constructor(){}cloneTo(e){e.time=this.time}clone(){var e=new Q;return this.cloneTo(e),e}}class K extends Q{constructor(){super()}cloneTo(e){super.cloneTo(e);var t=e;t.inTangent=this.inTangent,t.outTangent=this.outTangent,t.value=this.value}}class J extends Q{constructor(){super(),this.inTangent=new a,this.outTangent=new a,this.value=new S}cloneTo(e){super.cloneTo(e);var t=e;this.inTangent.cloneTo(t.inTangent),this.outTangent.cloneTo(t.outTangent),this.value.cloneTo(t.value)}}class $ extends Q{constructor(){super(),this.inTangent=new n,this.outTangent=new n,this.value=new n}cloneTo(e){super.cloneTo(e);var t=e;this.inTangent.cloneTo(t.inTangent),this.outTangent.cloneTo(t.outTangent),this.value.cloneTo(t.value)}}class ee{static READ_DATA(){ee._DATA.offset=ee._reader.getUint32(),ee._DATA.size=ee._reader.getUint32()}static READ_BLOCK(){for(var e=ee._BLOCK.count=ee._reader.getUint16(),t=ee._BLOCK.blockStarts=[],r=ee._BLOCK.blockLengths=[],i=0;i<e;i++)t.push(ee._reader.getUint32()),r.push(ee._reader.getUint32())}static READ_STRINGS(){var e=ee._reader.getUint32(),t=ee._reader.getUint16(),r=ee._reader.pos;ee._reader.pos=e+ee._DATA.offset;for(var i=0;i<t;i++)ee._strings[i]=ee._reader.readUTFString();ee._reader.pos=r}static parse(e,t){ee._animationClip=e,ee._reader=t,ee.READ_DATA(),ee.READ_BLOCK(),ee.READ_STRINGS();for(var r=0,i=ee._BLOCK.count;r<i;r++){var a=t.getUint16(),n=ee._strings[a],s=ee["READ_"+n];if(null==s)throw new Error("model file err,no this function:"+a+" "+n);s.call(null)}}static READ_ANIMATIONS(){var e,t,r,i=ee._reader,a=[],n=i.getUint16();for(a.length=n,e=0;e<n;e++)a[e]=i.getFloat32();var s=ee._animationClip;s.name=ee._strings[i.getUint16()];var o=s._duration=i.getFloat32();s.islooping=!!i.getByte(),s._frameRate=i.getInt16();var l=i.getInt16(),_=s._nodes;_.count=l;var h=s._nodesMap={},c=s._nodesDic={};for(e=0;e<l;e++){r=new Z,_.setNodeByIndex(e,r),r._indexInList=e;var d=r.type=i.getUint8(),u=i.getUint16();for(r._setOwnerPathCount(u),t=0;t<u;t++)r._setOwnerPathByIndex(t,ee._strings[i.getUint16()]);var m=r._joinOwnerPath("/"),f=h[m];f||(h[m]=f=[]),f.push(r),r.propertyOwner=ee._strings[i.getUint16()];var T=i.getUint16();for(r._setPropertyCount(T),t=0;t<T;t++)r._setPropertyByIndex(t,ee._strings[i.getUint16()]);var E=m+"."+r.propertyOwner+"."+r._joinProperty(".");c[E]=r,r.fullPath=E;var p=i.getUint16();for(r._setKeyframeCount(p),t=0;t<p;t++)switch(d){case 0:var g=new K;r._setKeyframeByIndex(t,g),g.time=a[i.getUint16()],g.inTangent=i.getFloat32(),g.outTangent=i.getFloat32(),g.value=i.getFloat32();break;case 1:case 3:case 4:var S=new $;r._setKeyframeByIndex(t,S),S.time=a[i.getUint16()];var R=S.inTangent,v=S.outTangent,x=S.value;R.x=i.getFloat32(),R.y=i.getFloat32(),R.z=i.getFloat32(),v.x=i.getFloat32(),v.y=i.getFloat32(),v.z=i.getFloat32(),x.x=i.getFloat32(),x.y=i.getFloat32(),x.z=i.getFloat32();break;case 2:var A=new J;r._setKeyframeByIndex(t,A),A.time=a[i.getUint16()];var I=A.inTangent,M=A.outTangent,D=A.value;I.x=i.getFloat32(),I.y=i.getFloat32(),I.z=i.getFloat32(),I.w=i.getFloat32(),M.x=i.getFloat32(),M.y=i.getFloat32(),M.z=i.getFloat32(),M.w=i.getFloat32(),D.x=i.getFloat32(),D.y=i.getFloat32(),D.z=i.getFloat32(),D.w=i.getFloat32();break;default:throw"AnimationClipParser03:unknown type."}}var C=i.getUint16();for(e=0;e<C;e++){var y=new q;y.time=Math.min(o,i.getFloat32()),y.eventName=ee._strings[i.getUint16()];var L=[],O=i.getUint16();for(O>0&&(y.params=L=[]),t=0;t<O;t++){switch(i.getByte()){case 0:L.push(!!i.getByte());break;case 1:L.push(i.getInt32());break;case 2:L.push(i.getFloat32());break;case 3:L.push(ee._strings[i.getUint16()]);break;default:throw new Error("unknown type.")}}s.addEvent(y)}}}ee._strings=[],ee._BLOCK={count:0},ee._DATA={offset:0,size:0};class te{static READ_DATA(){te._DATA.offset=te._reader.getUint32(),te._DATA.size=te._reader.getUint32()}static READ_BLOCK(){for(var e=te._BLOCK.count=te._reader.getUint16(),t=te._BLOCK.blockStarts=[],r=te._BLOCK.blockLengths=[],i=0;i<e;i++)t.push(te._reader.getUint32()),r.push(te._reader.getUint32())}static READ_STRINGS(){var e=te._reader.getUint32(),t=te._reader.getUint16(),r=te._reader.pos;te._reader.pos=e+te._DATA.offset;for(var i=0;i<t;i++)te._strings[i]=te._reader.readUTFString();te._reader.pos=r}static parse(e,t,r){te._animationClip=e,te._reader=t,te._version=r,te.READ_DATA(),te.READ_BLOCK(),te.READ_STRINGS();for(var i=0,a=te._BLOCK.count;i<a;i++){var n=t.getUint16(),s=te._strings[n],o=te["READ_"+s];if(null==o)throw new Error("model file err,no this function:"+n+" "+s);o.call(null)}te._version=null,te._reader=null,te._animationClip=null}static READ_ANIMATIONS(){var e,r,i,a=te._reader,n=[],s=a.getUint16();for(n.length=s,e=0;e<s;e++)n[e]=a.getFloat32();var o=te._animationClip;o.name=te._strings[a.getUint16()];var l=o._duration=a.getFloat32();o.islooping=!!a.getByte(),o._frameRate=a.getInt16();var _=a.getInt16(),h=o._nodes;h.count=_;var c=o._nodesMap={},d=o._nodesDic={};for(e=0;e<_;e++){i=new Z,h.setNodeByIndex(e,i),i._indexInList=e;var u=i.type=a.getUint8(),m=a.getUint16();for(i._setOwnerPathCount(m),r=0;r<m;r++)i._setOwnerPathByIndex(r,te._strings[a.getUint16()]);var f=i._joinOwnerPath("/"),T=c[f];T||(c[f]=T=[]),T.push(i),i.propertyOwner=te._strings[a.getUint16()];var E=a.getUint16();for(i._setPropertyCount(E),r=0;r<E;r++)i._setPropertyByIndex(r,te._strings[a.getUint16()]);var p=f+"."+i.propertyOwner+"."+i._joinProperty(".");d[p]=i,i.fullPath=p;var g=a.getUint16();switch(i._setKeyframeCount(g),te._version){case"LAYAANIMATION:04":for(r=0;r<g;r++)switch(u){case 0:var S=new K;i._setKeyframeByIndex(r,S),S.time=n[a.getUint16()],S.inTangent=a.getFloat32(),S.outTangent=a.getFloat32(),S.value=a.getFloat32();break;case 1:case 3:case 4:var R=new $;i._setKeyframeByIndex(r,R),R.time=n[a.getUint16()];var v=R.inTangent,x=R.outTangent,A=R.value;v.x=a.getFloat32(),v.y=a.getFloat32(),v.z=a.getFloat32(),x.x=a.getFloat32(),x.y=a.getFloat32(),x.z=a.getFloat32(),A.x=a.getFloat32(),A.y=a.getFloat32(),A.z=a.getFloat32();break;case 2:var I=new J;i._setKeyframeByIndex(r,I),I.time=n[a.getUint16()];var M=I.inTangent,D=I.outTangent,C=I.value;M.x=a.getFloat32(),M.y=a.getFloat32(),M.z=a.getFloat32(),M.w=a.getFloat32(),D.x=a.getFloat32(),D.y=a.getFloat32(),D.z=a.getFloat32(),D.w=a.getFloat32(),C.x=a.getFloat32(),C.y=a.getFloat32(),C.z=a.getFloat32(),C.w=a.getFloat32();break;default:throw"AnimationClipParser04:unknown type."}break;case"LAYAANIMATION:COMPRESSION_04":for(r=0;r<g;r++)switch(u){case 0:S=new K,i._setKeyframeByIndex(r,S),S.time=n[a.getUint16()],S.inTangent=t.HalfFloatUtils.convertToNumber(a.getUint16()),S.outTangent=t.HalfFloatUtils.convertToNumber(a.getUint16()),S.value=t.HalfFloatUtils.convertToNumber(a.getUint16());break;case 1:case 3:case 4:R=new $,i._setKeyframeByIndex(r,R),R.time=n[a.getUint16()],v=R.inTangent,x=R.outTangent,A=R.value,v.x=t.HalfFloatUtils.convertToNumber(a.getUint16()),v.y=t.HalfFloatUtils.convertToNumber(a.getUint16()),v.z=t.HalfFloatUtils.convertToNumber(a.getUint16()),x.x=t.HalfFloatUtils.convertToNumber(a.getUint16()),x.y=t.HalfFloatUtils.convertToNumber(a.getUint16()),x.z=t.HalfFloatUtils.convertToNumber(a.getUint16()),A.x=t.HalfFloatUtils.convertToNumber(a.getUint16()),A.y=t.HalfFloatUtils.convertToNumber(a.getUint16()),A.z=t.HalfFloatUtils.convertToNumber(a.getUint16());break;case 2:I=new J,i._setKeyframeByIndex(r,I),I.time=n[a.getUint16()],M=I.inTangent,D=I.outTangent,C=I.value,M.x=t.HalfFloatUtils.convertToNumber(a.getUint16()),M.y=t.HalfFloatUtils.convertToNumber(a.getUint16()),M.z=t.HalfFloatUtils.convertToNumber(a.getUint16()),M.w=t.HalfFloatUtils.convertToNumber(a.getUint16()),D.x=t.HalfFloatUtils.convertToNumber(a.getUint16()),D.y=t.HalfFloatUtils.convertToNumber(a.getUint16()),D.z=t.HalfFloatUtils.convertToNumber(a.getUint16()),D.w=t.HalfFloatUtils.convertToNumber(a.getUint16()),C.x=t.HalfFloatUtils.convertToNumber(a.getUint16()),C.y=t.HalfFloatUtils.convertToNumber(a.getUint16()),C.z=t.HalfFloatUtils.convertToNumber(a.getUint16()),C.w=t.HalfFloatUtils.convertToNumber(a.getUint16());break;default:throw"AnimationClipParser04:unknown type."}}}var y=a.getUint16();for(e=0;e<y;e++){var L=new q;L.time=Math.min(l,a.getFloat32()),L.eventName=te._strings[a.getUint16()];var O=[],N=a.getUint16();for(N>0&&(L.params=O=[]),r=0;r<N;r++){switch(a.getByte()){case 0:O.push(!!a.getByte());break;case 1:O.push(a.getInt32());break;case 2:O.push(a.getFloat32());break;case 3:O.push(te._strings[a.getUint16()]);break;default:throw new Error("unknown type.")}}o.addEvent(L)}}}te._strings=[],te._BLOCK={count:0},te._DATA={offset:0,size:0};class re{constructor(){this._nodes=[]}get count(){return this._nodes.length}set count(e){this._nodes.length=e}getNodeByIndex(e){return this._nodes[e]}setNodeByIndex(e,t){this._nodes[e]=t}}class ie extends t.Resource{constructor(){super(),this._duration=0,this._frameRate=0,this._nodes=new re,this.islooping=!1,this._animationEvents=[]}static _parse(e){var r=new ie,i=new t.Byte(e),a=i.readUTFString();switch(a){case"LAYAANIMATION:03":ee.parse(r,i);break;case"LAYAANIMATION:04":case"LAYAANIMATION:COMPRESSION_04":te.parse(r,i,a);break;default:throw"unknown animationClip version."}return r}static load(e,r){t.ILaya.loader.create(e,r,null,ie.ANIMATIONCLIP)}duration(){return this._duration}_hermiteInterpolate(e,t,r,i){var a=e.outTangent,n=t.inTangent;if(Number.isFinite(a)&&Number.isFinite(n)){var s=r*r,o=s*r,l=o-2*s+r,_=o-s,h=-2*o+3*s;return(2*o-3*s+1)*e.value+l*a*i+_*n*i+h*t.value}return e.value}_hermiteInterpolateVector3(e,t,r,i,a){var n=e.value,s=e.outTangent,o=t.value,l=t.inTangent,_=r*r,h=_*r,c=2*h-3*_+1,d=h-2*_+r,u=h-_,m=-2*h+3*_,f=s.x,T=l.x;Number.isFinite(f)&&Number.isFinite(T)?a.x=c*n.x+d*f*i+u*T*i+m*o.x:a.x=n.x,f=s.y,T=l.y,Number.isFinite(f)&&Number.isFinite(T)?a.y=c*n.y+d*f*i+u*T*i+m*o.y:a.y=n.y,f=s.z,T=l.z,Number.isFinite(f)&&Number.isFinite(T)?a.z=c*n.z+d*f*i+u*T*i+m*o.z:a.z=n.z}_hermiteInterpolateQuaternion(e,t,r,i,a){var n=e.value,s=e.outTangent,o=t.value,l=t.inTangent,_=r*r,h=_*r,c=2*h-3*_+1,d=h-2*_+r,u=h-_,m=-2*h+3*_,f=s.x,T=l.x;Number.isFinite(f)&&Number.isFinite(T)?a.x=c*n.x+d*f*i+u*T*i+m*o.x:a.x=n.x,f=s.y,T=l.y,Number.isFinite(f)&&Number.isFinite(T)?a.y=c*n.y+d*f*i+u*T*i+m*o.y:a.y=n.y,f=s.z,T=l.z,Number.isFinite(f)&&Number.isFinite(T)?a.z=c*n.z+d*f*i+u*T*i+m*o.z:a.z=n.z,f=s.w,T=l.w,Number.isFinite(f)&&Number.isFinite(T)?a.w=c*n.w+d*f*i+u*T*i+m*o.w:a.w=n.w}_evaluateClipDatasRealTime(e,t,r,i,a,n){for(var s=0,o=e.count;s<o;s++){var l,_=e.getNodeByIndex(s),h=_.type,c=_._keyFrames,d=c.length,u=r[s];if(a)for(-1!==u&&t<c[u].time&&(u=-1,r[s]=u),l=u+1;l<d&&!(c[l].time>t);)u++,l++,r[s]=u;else for((l=u+1)!==d&&t>c[l].time&&(u=d-1,r[s]=u),l=u+1;u>-1&&!(c[u].time<t);)u--,l--,r[s]=u;var m=l===d;switch(h){case 0:if(-1!==u){var f=c[u];if(m)n[s]=f.value;else{var T,E=c[l],p=E.time-f.time;T=0!==p?(t-f.time)/p:0,n[s]=this._hermiteInterpolate(f,E,T,p)}}else n[s]=c[0].value;i&&(n[s]=n[s]-c[0].value);break;case 1:case 4:var g=n[s];if(this._evaluateFrameNodeVector3DatasRealTime(c,u,m,t,g),i){var R=c[0].value;g.x-=R.x,g.y-=R.y,g.z-=R.z}break;case 2:var v=n[s];if(this._evaluateFrameNodeQuaternionDatasRealTime(c,u,m,t,v),i){var x=ie._tempQuaternion0,A=c[0].value;H.quaternionConjugate(A,x),S.multiply(x,v,v)}break;case 3:g=n[s],this._evaluateFrameNodeVector3DatasRealTime(c,u,m,t,g),i&&(R=c[0].value,g.x/=R.x,g.y/=R.y,g.z/=R.z);break;default:throw"AnimationClip:unknown node type."}}}_evaluateClipDatasRealTimeForNative(e,r,i,a){t.LayaGL.instance.evaluateClipDatasRealTime(e._nativeObj,r,i,a)}_evaluateFrameNodeVector3DatasRealTime(e,t,r,i,a){if(-1!==t){var n=e[t];if(r){var s=n.value;a.x=s.x,a.y=s.y,a.z=s.z}else{var o,l=e[t+1],_=n.time,h=l.time-_;o=0!==h?(i-_)/h:0,this._hermiteInterpolateVector3(n,l,o,h,a)}}else{var c=e[0].value;a.x=c.x,a.y=c.y,a.z=c.z}}_evaluateFrameNodeQuaternionDatasRealTime(e,t,r,i,a){if(-1!==t){var n=e[t];if(r){var s=n.value;a.x=s.x,a.y=s.y,a.z=s.z,a.w=s.w}else{var o,l=e[t+1],_=n.time,h=l.time-_;o=0!==h?(i-_)/h:0,this._hermiteInterpolateQuaternion(n,l,o,h,a)}}else{var c=e[0].value;a.x=c.x,a.y=c.y,a.z=c.z,a.w=c.w}}_binarySearchEventIndex(e){for(var t,r=0,i=this._animationEvents.length-1;r<=i;){t=Math.floor((r+i)/2);var a=this._animationEvents[t].time;if(a==e)return t;a>e?i=t-1:r=t+1}return r}addEvent(e){var t=this._binarySearchEventIndex(e.time);this._animationEvents.splice(t,0,e)}_disposeResource(){this._nodes=null,this._nodesMap=null}}ie.ANIMATIONCLIP="ANIMATIONCLIP",ie._tempQuaternion0=new S;class ae{constructor(){this._currentState=null}get normalizedTime(){return this._normalizedTime}get duration(){return this._duration}get animatorState(){return this._currentState}_resetPlayState(e,t){this._finish=!1,this._startPlayTime=e,this._elapsedTime=e,this._playEventIndex=0,this._lastIsFront=!0,this._normalizedTime=this._elapsedTime/t;var r=this._normalizedTime%1;this._normalizedPlayTime=r<0?r+1:r}_cloneTo(e){e._finish=this._finish,e._startPlayTime=this._startPlayTime,e._elapsedTime=this._elapsedTime,e._normalizedTime=this._normalizedTime,e._normalizedPlayTime=this._normalizedPlayTime,e._playEventIndex=this._playEventIndex,e._lastIsFront=this._lastIsFront}}class ne{constructor(e){this._defaultState=null,this._referenceCount=0,this._playType=-1,this._crossDuration=-1,this._crossMark=0,this._crossNodesOwnersCount=0,this._crossNodesOwners=[],this._crossNodesOwnersIndicesMap={},this._srcCrossClipNodeIndices=[],this._destCrossClipNodeIndices=[],this._statesMap={},this._states=[],this._playStateInfo=new ae,this._crossPlayStateInfo=new ae,this.blendingMode=ne.BLENDINGMODE_OVERRIDE,this.defaultWeight=1,this.playOnWake=!0,this.name=e}get defaultState(){return this._defaultState}set defaultState(e){this._defaultState=e,this._statesMap[e.name]=e}_removeClip(e,t,r,i){var a=i._clip,n=e[r];if(e.splice(r,1),delete t[i.name],this._animator){var s=a._nodes,o=n._nodeOwners;a._removeReference();for(var l=0,_=s.count;l<_;l++)this._animator._removeKeyframeNodeOwner(o,s.getNodeByIndex(l))}}_getReferenceCount(){return this._referenceCount}_addReference(e=1){for(var t=0,r=this._states.length;t<r;t++)this._states[t]._addReference(e);this._referenceCount+=e}_removeReference(e=1){for(var t=0,r=this._states.length;t<r;t++)this._states[t]._removeReference(e);this._referenceCount-=e}_clearReference(){this._removeReference(-this._referenceCount)}getCurrentPlayState(){return this._playStateInfo}getAnimatorState(e){var t=this._statesMap[e];return t||null}addState(e){var t=e.name;if(this._statesMap[t])throw"AnimatorControllerLayer:this stat's name has exist.";this._statesMap[t]=e,this._states.push(e),this._animator&&(e._clip._addReference(),this._animator._getOwnersByClip(e))}removeState(e){for(var t=this._states,r=-1,i=0,a=t.length;i<a;i++)if(t[i]===e){r=i;break}-1!==r&&this._removeClip(t,this._statesMap,r,e)}destroy(){this._clearReference(),this._statesMap=null,this._states=null,this._playStateInfo=null,this._crossPlayStateInfo=null,this._defaultState=null}cloneTo(e){var t=e;t.name=this.name,t.blendingMode=this.blendingMode,t.defaultWeight=this.defaultWeight,t.playOnWake=this.playOnWake}clone(){var e=new ne(this.name);return this.cloneTo(e),e}}ne.BLENDINGMODE_OVERRIDE=0,ne.BLENDINGMODE_ADDTIVE=1;class se{constructor(){this._referenceCount=0,this._clip=null,this._nodeOwners=[],this._currentFrameIndices=null,this._realtimeDatas=[],this._scripts=null,this.speed=1,this.clipStart=0,this.clipEnd=1}get clip(){return this._clip}set clip(e){if(this._clip!==e){if(this._clip&&this._referenceCount>0&&this._clip._removeReference(this._referenceCount),e){var t=this._realtimeDatas,r=e._nodes,i=r.count;this._currentFrameIndices=new Int16Array(i),this._resetFrameIndices(),this._referenceCount>0&&e._addReference(this._referenceCount),this._realtimeDatas.length=i;for(var a=0;a<i;a++)switch(r.getNodeByIndex(a).type){case 0:break;case 1:case 3:case 4:t[a]=new n;break;case 2:t[a]=new S;break;default:throw"AnimationClipParser04:unknown type."}}this._clip=e}}_getReferenceCount(){return this._referenceCount}_addReference(e=1){this._clip&&this._clip._addReference(e),this._referenceCount+=e}_removeReference(e=1){this._clip&&this._clip._removeReference(e),this._referenceCount-=e}_clearReference(){this._removeReference(-this._referenceCount)}_resetFrameIndices(){for(var e=0,t=this._currentFrameIndices.length;e<t;e++)this._currentFrameIndices[e]=-1}addScript(e){var t=new e;return this._scripts=this._scripts||[],this._scripts.push(t),t}getScript(e){if(this._scripts)for(var t=0,r=this._scripts.length;t<r;t++){var i=this._scripts[t];if(i instanceof e)return i}return null}getScripts(e){var t;if(this._scripts)for(var r=0,i=this._scripts.length;r<i;r++){var a=this._scripts[r];a instanceof e&&(t=t||[]).push(a)}return t}cloneTo(e){var t=e;t.name=this.name,t.speed=this.speed,t.clipStart=this.clipStart,t.clipEnd=this.clipEnd,t.clip=this._clip}clone(){var e=new se;return this.cloneTo(e),e}}class oe{constructor(){this.indexInList=-1,this.referenceCount=0,this.updateMark=-1,this.type=-1,this.fullPath=null,this.propertyOwner=null,this.property=null,this.defaultValue=null,this.value=null,this.crossFixedValue=null}saveCrossFixedValue(){if(this.propertyOwner)switch(this.type){case 0:this.crossFixedValue=this.value;break;case 1:case 3:case 4:case 2:this.value.cloneTo(this.crossFixedValue);break;default:throw"Animator:unknown type."}}}class le extends t.Component{constructor(){super(),this._keyframeNodeOwners=[],this._linkAvatarSpritesData={},this._linkAvatarSprites=[],this._renderableSprites=[],this.cullingMode=le.CULLINGMODE_CULLCOMPLETELY,this._controllerLayers=[],this._linkSprites={},this._speed=1,this._keyframeNodeOwnerMap={},this._updateMark=0}static _update(e){for(var t=e._animatorPool,r=t.elements,i=0,a=t.length;i<a;i++){var n=r[i];n&&n.enabled&&n._update()}}get speed(){return this._speed}set speed(e){this._speed=e}_linkToSprites(e){for(var t in e){for(var r=this.owner,i=e[t],a=0,n=i.length;a<n;a++){var s=i[a];if(""===s)break;if(!(r=r.getChildByName(s)))break}r&&this.linkSprite3DToAvatarNode(t,r)}}_addKeyframeNodeOwner(e,t,r){var i=t._indexInList,a=t.fullPath,n=this._keyframeNodeOwnerMap[a];if(n)n.referenceCount++,e[i]=n;else{for(var s=r,o=0,l=t.propertyCount;o<l&&(s=s[t.getPropertyByIndex(o)]);o++);(n=this._keyframeNodeOwnerMap[a]=new oe).fullPath=a,n.indexInList=this._keyframeNodeOwners.length,n.referenceCount=1,n.propertyOwner=r;var _=t.propertyCount,h=[];for(o=0;o<_;o++)h[o]=t.getPropertyByIndex(o);if(n.property=h,n.type=t.type,s)if(0===t.type)n.defaultValue=s;else{var c=new s.constructor;s.cloneTo(c),n.defaultValue=c,n.value=new s.constructor,n.crossFixedValue=new s.constructor}this._keyframeNodeOwners.push(n),e[i]=n}}_removeKeyframeNodeOwner(e,t){var r=t.fullPath,i=this._keyframeNodeOwnerMap[r];i&&(i.referenceCount--,0===i.referenceCount&&(delete this._keyframeNodeOwnerMap[r],this._keyframeNodeOwners.splice(this._keyframeNodeOwners.indexOf(i),1)),e[t._indexInList]=null)}_getOwnersByClip(e){var t=e._clip._nodes,r=t.count,i=e._nodeOwners;i.length=r;for(var a=0;a<r;a++){for(var n=t.getNodeByIndex(a),s=this._avatar?this._avatarNodeMap[this._avatar._rootNode.name]:this.owner,o=0,l=n.ownerPathCount;o<l;o++){var _=n.getOwnerPathByIndex(o);if(""===_)break;if(!(s=s.getChildByName(_)))break}if(s){var h=n.propertyOwner;h&&(s=s[h]),s&&this._addKeyframeNodeOwner(i,n,s)}}}_updatePlayer(e,t,r,i){var a=e._clip._duration*(e.clipEnd-e.clipStart),n=t._elapsedTime,s=n+r;t._lastElapsedTime=n,t._elapsedTime=s;var o=s/a;t._normalizedTime=o;var l=o%1;t._normalizedPlayTime=l<0?l+1:l,t._duration=a;var _=e._scripts;if(!i&&s>=a){if(t._finish=!0,t._elapsedTime=a,t._normalizedPlayTime=1,_)for(var h=0,c=_.length;h<c;h++)_[h].onStateExit()}else if(_)for(h=0,c=_.length;h<c;h++)_[h].onStateUpdate()}_eventScript(e,t,r,i,a){if(a)for(var n=t.length;r<n;r++){var s=t[r];if(!(s.time<=i))break;for(var o=0,l=e.length;o<l;o++){var _=e[o],h=_[s.eventName];h&&h.apply(_,s.params)}}else for(;r>=0&&(s=t[r]).time>=i;r--)for(o=0,l=e.length;o<l;o++)(h=(_=e[o])[s.eventName])&&h.apply(_,s.params);return r}_updateEventScript(e,t){var r=this.owner._scripts;if(r){var i=e._clip,a=i._animationEvents,n=i._duration,s=t._elapsedTime,o=s%n,l=Math.abs(Math.floor(s/n)-Math.floor(t._lastElapsedTime/n)),_=t._elapsedTime>=t._lastElapsedTime;t._lastIsFront!==_&&(_?t._playEventIndex++:t._playEventIndex--,t._lastIsFront=_);var h=t._playEventIndex;if(_){var c=this._eventScript(r,a,t._playEventIndex,l>0?n:o,!0);h===t._playEventIndex&&(t._playEventIndex=c);for(var d=0,u=l-1;d<u;d++)this._eventScript(r,a,0,n,!0);l>0&&o>0&&(t._playEventIndex=this._eventScript(r,a,0,o,!0))}else{c=this._eventScript(r,a,t._playEventIndex,l>0?0:o,!1);h===t._playEventIndex&&(t._playEventIndex=c);var m=a.length-1;for(d=0,u=l-1;d<u;d++)this._eventScript(r,a,m,0,!1);l>0&&o>0&&(t._playEventIndex=this._eventScript(r,a,m,o,!1))}}}_updateClipDatas(e,t,r,i){var a=e._clip,n=a._duration,s=e.clipStart*n+r._normalizedPlayTime*r._duration,o=e._currentFrameIndices,l=r._elapsedTime>r._lastElapsedTime;a._evaluateClipDatasRealTime(a._nodes,s,o,t,l,e._realtimeDatas)}_applyFloat(e,t,r,i,a,n,s){if(r.updateMark===this._updateMark)if(i)e[t]+=a*s;else{var o=e[t];e[t]=o+a*(s-o)}else if(n)e[t]=i?r.defaultValue+s:s;else if(i)e[t]=r.defaultValue+a*s;else{var l=r.defaultValue;e[t]=l+a*(s-l)}}_applyPositionAndRotationEuler(e,t,r,i,a,n){if(e.updateMark===this._updateMark)if(t)n.x+=r*a.x,n.y+=r*a.y,n.z+=r*a.z;else{var s=n.x,o=n.y,l=n.z;n.x=s+r*(a.x-s),n.y=o+r*(a.y-o),n.z=l+r*(a.z-l)}else if(i)if(t){var _=e.defaultValue;n.x=_.x+a.x,n.y=_.y+a.y,n.z=_.z+a.z}else n.x=a.x,n.y=a.y,n.z=a.z;else if(_=e.defaultValue,t)n.x=_.x+r*a.x,n.y=_.y+r*a.y,n.z=_.z+r*a.z;else{var h=_.x,c=_.y,d=_.z;n.x=h+r*(a.x-h),n.y=c+r*(a.y-c),n.z=d+r*(a.z-d)}}_applyRotation(e,t,r,i,a,n){if(e.updateMark===this._updateMark)if(t){var s=le._tempQuaternion1;H.quaternionWeight(a,r,s),s.normalize(s),S.multiply(n,s,n)}else S.lerp(n,a,r,n);else if(i)if(t){var o=e.defaultValue;S.multiply(o,a,n)}else n.x=a.x,n.y=a.y,n.z=a.z,n.w=a.w;else o=e.defaultValue,t?(s=le._tempQuaternion1,H.quaternionWeight(a,r,s),s.normalize(s),S.multiply(o,s,n)):S.lerp(o,a,r,n)}_applyScale(e,t,r,i,a,n){if(e.updateMark===this._updateMark)if(t){var s=le._tempVector31;H.scaleWeight(a,r,s),n.x=n.x*s.x,n.y=n.y*s.y,n.z=n.z*s.z}else H.scaleBlend(n,a,r,n);else if(i)if(t){var o=e.defaultValue;n.x=o.x*a.x,n.y=o.y*a.y,n.z=o.z*a.z}else n.x=a.x,n.y=a.y,n.z=a.z;else o=e.defaultValue,t?(s=le._tempVector31,H.scaleWeight(a,r,s),n.x=o.x*s.x,n.y=o.y*s.y,n.z=o.z*s.z):H.scaleBlend(o,a,r,n)}_applyCrossData(e,t,r,i,a,n,s){var o=e.propertyOwner;if(o){switch(e.type){case 0:for(var l=e.property,_=l.length-1,h=0;h<_&&(o=o[l[h]]);h++);var c=a+s*(n-a);e.value=c,o&&this._applyFloat(o,l[_],e,t,r,i,c);break;case 1:var d=o.localPosition,u=e.value,m=a.x,f=a.y,T=a.z;u.x=m+s*(n.x-m),u.y=f+s*(n.y-f),u.z=T+s*(n.z-T),this._applyPositionAndRotationEuler(e,t,r,i,u,d),o.localPosition=d;break;case 2:var E=o.localRotation,p=e.value;S.lerp(a,n,s,p),this._applyRotation(e,t,r,i,p,E),o.localRotation=E;break;case 3:var g=o.localScale,R=e.value;H.scaleBlend(a,n,s,R),this._applyScale(e,t,r,i,R,g),o.localScale=g;break;case 4:var v=o.localRotationEuler,x=e.value;m=a.x,f=a.y,T=a.z,x.x=m+s*(n.x-m),x.y=f+s*(n.y-f),x.z=T+s*(n.z-T),this._applyPositionAndRotationEuler(e,t,r,i,x,v),o.localRotationEuler=v}e.updateMark=this._updateMark}}_setClipDatasToNode(e,t,r,i){for(var a=e._realtimeDatas,n=e._clip._nodes,s=e._nodeOwners,o=0,l=n.count;o<l;o++){var _=s[o];if(_){var h=_.propertyOwner;if(h){switch(_.type){case 0:for(var c=_.property,d=c.length-1,u=0;u<d&&(h=h[c[u]]);u++);h&&this._applyFloat(h,c[d],_,t,r,i,a[o]);break;case 1:var m=h.localPosition;this._applyPositionAndRotationEuler(_,t,r,i,a[o],m),h.localPosition=m;break;case 2:var f=h.localRotation;this._applyRotation(_,t,r,i,a[o],f),h.localRotation=f;break;case 3:var T=h.localScale;this._applyScale(_,t,r,i,a[o],T),h.localScale=T;break;case 4:var E=h.localRotationEuler;this._applyPositionAndRotationEuler(_,t,r,i,a[o],E),h.localRotationEuler=E}_.updateMark=this._updateMark}}}}_setCrossClipDatasToNode(e,t,r,i,a){for(var n=e._crossNodesOwners,s=e._crossNodesOwnersCount,o=e.blendingMode!==ne.BLENDINGMODE_OVERRIDE,l=e.defaultWeight,_=r._realtimeDatas,h=e._destCrossClipNodeIndices,c=r._nodeOwners,d=t._realtimeDatas,u=e._srcCrossClipNodeIndices,m=t._nodeOwners,f=0;f<s;f++){var T=n[f];if(T){var E=u[f],p=h[f],g=-1!==E?d[E]:c[p].defaultValue,S=-1!==p?_[p]:m[E].defaultValue;this._applyCrossData(T,o,l,a,g,S,i)}}}_setFixedCrossClipDatasToNode(e,t,r,i){for(var a=e._crossNodesOwners,n=e._crossNodesOwnersCount,s=e.blendingMode!==ne.BLENDINGMODE_OVERRIDE,o=e.defaultWeight,l=t._realtimeDatas,_=e._destCrossClipNodeIndices,h=0;h<n;h++){var c=a[h];if(c){var d=_[h],u=c.crossFixedValue,m=-1!==d?l[d]:c.defaultValue;this._applyCrossData(c,s,o,i,u,m,r)}}}_revertDefaultKeyframeNodes(e){for(var t=e._nodeOwners,r=0,i=t.length;r<i;r++){var a=t[r];if(a){var n=a.propertyOwner;if(n)switch(a.type){case 0:for(var s=a.property,o=s.length-1,l=0;l<o&&(n=n[s[l]]);l++);n[s[o]]=a.defaultValue;break;case 1:var _=n.localPosition,h=a.defaultValue;_.x=h.x,_.y=h.y,_.z=h.z,n.localPosition=_;break;case 2:var c=n.localRotation,d=a.defaultValue;c.x=d.x,c.y=d.y,c.z=d.z,c.w=d.w,n.localRotation=c;break;case 3:var u=n.localScale;h=a.defaultValue,u.x=h.x,u.y=h.y,u.z=h.z,n.localScale=u;break;case 4:var m=n.localRotationEuler;h=a.defaultValue,m.x=h.x,m.y=h.y,m.z=h.z,n.localRotationEuler=m;break;default:throw"Animator:unknown type."}}}}_onAdded(){var e=this.owner._parent;this.owner._setHierarchyAnimator(this,e?e._hierarchyAnimator:null),this.owner._changeAnimatorToLinkSprite3DNoAvatar(this,!0,[])}_onDestroy(){for(var e=0,t=this._controllerLayers.length;e<t;e++)this._controllerLayers[e]._removeReference();var r=this.owner._parent;this.owner._clearHierarchyAnimator(this,r?r._hierarchyAnimator:null)}_onEnable(){this.owner._scene._animatorPool.add(this);for(var e=0,t=this._controllerLayers.length;e<t;e++){if(this._controllerLayers[e].playOnWake)this.getDefaultState(e)&&this.play(null,e,0)}}_onDisable(){this.owner._scene._animatorPool.remove(this)}_handleSpriteOwnersBySprite(e,t,r){for(var i=0,a=this._controllerLayers.length;i<a;i++)for(var n=this._controllerLayers[i]._states,s=0,o=n.length;s<o;s++){var l=n[s],_=l._clip,h=t.join("/"),c=_._nodesMap[h];if(c)for(var d=l._nodeOwners,u=0,m=c.length;u<m;u++)e?this._addKeyframeNodeOwner(d,c[u],r):this._removeKeyframeNodeOwner(d,c[u])}}_parse(e){var r=e.avatar;if(r){this.avatar=t.Loader.getRes(r.path);var i=r.linkSprites;this._linkSprites=i,this._linkToSprites(i)}e.clipPaths;for(var a=e.playOnWake,n=e.layers,s=0;s<n.length;s++){var o=n[s],l=new ne(o.name);l.defaultWeight=0===s?1:o.weight;var _=o.blendingMode;_&&(l.blendingMode=_),this.addControllerLayer(l);for(var h=o.states,c=0,d=h.length;c<d;c++){var u=h[c],m=u.clipPath;if(m){var f,T=u.name;if(f=t.Loader.getRes(m)){var E=new se;E.name=T,E.clip=f,l.addState(E),0===c&&(this.getControllerLayer(s).defaultState=E)}}}void 0!==a&&(l.playOnWake=a)}var p=e.cullingMode;void 0!==p&&(this.cullingMode=p)}_update(){var e=this.owner._scene.timer,t=e._delta/1e3;if(0!==this._speed&&0!==t){var r;if(this.cullingMode===le.CULLINGMODE_CULLCOMPLETELY){r=!1;for(var i=0,a=this._renderableSprites.length;i<a;i++)if(this._renderableSprites[i]._render.isRender){r=!0;break}}else r=!0;this._updateMark++;var n=e.scale;for(i=0,a=this._controllerLayers.length;i<a;i++){var s=this._controllerLayers[i],o=s._playStateInfo,l=s._crossPlayStateInfo;switch(u=s.blendingMode!==ne.BLENDINGMODE_OVERRIDE,s._playType){case 0:var _=o._currentState,h=_._clip,c=this._speed*_.speed,d=o._finish;if(d||this._updatePlayer(_,o,t*c,h.islooping),r){var u=s.blendingMode!==ne.BLENDINGMODE_OVERRIDE;this._updateClipDatas(_,u,o,n*c),this._setClipDatasToNode(_,u,s.defaultWeight,0===i),d||this._updateEventScript(_,o)}break;case 1:h=(_=o._currentState)._clip;var m=s._crossPlayState,f=m._clip,T=s._crossDuration,E=l._startPlayTime,p=f._duration-E,g=T>p?p/T:1,S=this._speed*m.speed;this._updatePlayer(m,l,t*g*S,f.islooping);var R=(l._elapsedTime-E)/g/T;R>=1?r&&(this._updateClipDatas(m,u,l,n*S),this._setClipDatasToNode(m,u,s.defaultWeight,0===i),s._playType=0,o._currentState=m,l._cloneTo(o)):(o._finish||(c=this._speed*_.speed,this._updatePlayer(_,o,t*c,h.islooping),r&&this._updateClipDatas(_,u,o,n*c)),r&&(this._updateClipDatas(m,u,l,n*g*S),this._setCrossClipDatasToNode(s,_,m,R,0===i))),r&&(this._updateEventScript(_,o),this._updateEventScript(m,l));break;case 2:f=(m=s._crossPlayState)._clip,T=s._crossDuration,E=l._startPlayTime,g=T>(p=f._duration-E)?p/T:1,S=this._speed*m.speed,this._updatePlayer(m,l,t*g*S,f.islooping),r&&((R=(l._elapsedTime-E)/g/T)>=1?(this._updateClipDatas(m,u,l,n*S),this._setClipDatasToNode(m,u,1,0===i),s._playType=0,o._currentState=m,l._cloneTo(o)):(this._updateClipDatas(m,u,l,n*g*S),this._setFixedCrossClipDatasToNode(s,m,R,0===i)),this._updateEventScript(m,l))}}r&&this._avatar&&this._updateAvatarNodesToSprite()}}_cloneTo(e){var t=e;t.avatar=this.avatar,t.cullingMode=this.cullingMode;for(var r=0,i=this._controllerLayers.length;r<i;r++){var a=this._controllerLayers[r];t.addControllerLayer(a.clone());for(var n=a._states,s=0,o=n.length;s<o;s++){var l=n[s].clone(),_=t.getControllerLayer(r);_.addState(l),0==s&&(_.defaultState=l)}}t._linkSprites=this._linkSprites,t._linkToSprites(this._linkSprites)}getDefaultState(e=0){return this._controllerLayers[e].defaultState}addState(e,t=0){this._controllerLayers[t].addState(e),console.warn("Animator:this function is discard,please use animatorControllerLayer.addState() instead.")}removeState(e,t=0){this._controllerLayers[t].removeState(e),console.warn("Animator:this function is discard,please use animatorControllerLayer.removeState() instead.")}addControllerLayer(e){this._controllerLayers.push(e),e._animator=this,e._addReference();for(var t=e._states,r=0,i=t.length;r<i;r++)this._getOwnersByClip(t[r])}getControllerLayer(e=0){return this._controllerLayers[e]}play(e=null,t=0,r=Number.NEGATIVE_INFINITY){var i=this._controllerLayers[t];if(i){var a=i.defaultState;if(!e&&!a)throw new Error("Animator:must have default clip value,please set clip property.");var n=i._playStateInfo,s=n._currentState,o=e?i._statesMap[e]:a,l=o._clip._duration,_=o._clip._duration*(o.clipEnd-o.clipStart);s!==o?(r!==Number.NEGATIVE_INFINITY?n._resetPlayState(l*r,_):n._resetPlayState(0,_),null!==s&&s!==o&&this._revertDefaultKeyframeNodes(s),i._playType=0,n._currentState=o):r!==Number.NEGATIVE_INFINITY&&(n._resetPlayState(l*r,_),i._playType=0);var h=o._scripts;if(h)for(var c=0,d=h.length;c<d;c++)h[c].onStateEnter()}else console.warn("Invalid layerIndex "+t+".")}crossFade(e,t,r=0,i=Number.NEGATIVE_INFINITY){var a=this._controllerLayers[r];if(a){var n=a._statesMap[e];if(n){var s=a._playType;if(-1===s)return void this.play(e,r,i);var o=a._crossPlayStateInfo,l=a._crossNodesOwners,_=a._crossNodesOwnersIndicesMap,h=a._playStateInfo._currentState,c=n._nodeOwners,d=a._destCrossClipNodeIndices,u=n._clip,m=u._nodes,f=u._nodesDic;switch(s){case 0:var T=h._nodeOwners,E=a._srcCrossClipNodeIndices,p=h._clip,g=p._nodes,S=p._nodesDic;a._playType=1;for(var R=++a._crossMark,v=a._crossNodesOwnersCount=0,x=0,A=g.count;x<A;x++){var I=g.getNodeByIndex(x),M=I._indexInList,D=T[M];if(D){var C=I.fullPath;E[v]=M;var y=f[C];d[v]=y?y._indexInList:-1,_[C]=R,l[v]=D,v++}}for(x=0,A=m.count;x<A;x++){var L=(y=m.getNodeByIndex(x))._indexInList,O=c[L];if(O){var N=y.fullPath;S[N]||(E[v]=-1,d[v]=L,_[N]=R,l[v]=O,v++)}}break;case 1:case 2:for(a._playType=2,x=0,A=l.length;x<A;x++){var P=l[x];P.saveCrossFixedValue(),y=f[P.fullPath],d[x]=y?y._indexInList:-1}for(v=a._crossNodesOwnersCount,R=a._crossMark,x=0,A=m.count;x<A;x++)(O=c[L=(y=m.getNodeByIndex(x))._indexInList])&&_[N=y.fullPath]!==R&&(d[v]=L,_[N]=R,P=c[L],l[v]=P,P.saveCrossFixedValue(),v++)}a._crossNodesOwnersCount=v,a._crossPlayState=n,a._crossDuration=h._clip._duration*t,i!==Number.NEGATIVE_INFINITY?o._resetPlayState(u._duration*i,a._crossDuration):o._resetPlayState(0,a._crossDuration);var b=n._scripts;if(b)for(x=0,A=b.length;x<A;x++)b[x].onStateEnter()}else console.warn("Invalid name "+r+".")}else console.warn("Invalid layerIndex "+r+".")}getCurrentAnimatorPlayState(e=0){return this._controllerLayers[e]._playStateInfo}get avatar(){return this._avatar}set avatar(e){if(this._avatar!==e)if(this._avatar=e,e)this._getAvatarOwnersAndInitDatasAsync(),this.owner._changeHierarchyAnimatorAvatar(this,e);else{var t=this.owner._parent;this.owner._changeHierarchyAnimatorAvatar(this,t?t._hierarchyAnimator._avatar:null)}}_isLinkSpriteToAnimationNodeData(e,t,r){var i=this._linkAvatarSpritesData[t];if(r)i||(this._linkAvatarSpritesData[t]=i=[]),i.push(e);else{var a=i.indexOf(e);i.splice(a,1)}}_getAvatarOwnersAndInitDatasAsync(){for(var e=0,t=this._controllerLayers.length;e<t;e++)for(var r=this._controllerLayers[e]._states,i=0,a=r.length;i<a;i++)this._getOwnersByClip(r[i]);for(var n in this._avatar._cloneDatasToAnimator(this),this._linkAvatarSpritesData){var s=this._linkAvatarSpritesData[n];if(s)for(var o=0,l=s.length;o<l;o++)this._isLinkSpriteToAnimationNode(s[o],n,!0)}}_isLinkSpriteToAnimationNode(e,t,r){if(this._avatar){var i=this._avatarNodeMap[t];if(i)if(r){e._transform._dummy=i.transform,this._linkAvatarSprites.push(e);var a=i.transform,n=e.transform;if(!n.owner.isStatic&&a){var s=n.worldMatrix,o=this.owner._transform._parent;if(o)H.matrix4x4MultiplyMFM(o.worldMatrix,a.getWorldMatrix(),s);else for(var l=s.elements,_=a.getWorldMatrix(),h=0;h<16;h++)l[h]=_[h];n.worldMatrix=s}}else e._transform._dummy=null,this._linkAvatarSprites.splice(this._linkAvatarSprites.indexOf(e),1)}}_updateAvatarNodesToSprite(){for(var e=0,t=this._linkAvatarSprites.length;e<t;e++){var r=this._linkAvatarSprites[e],i=r.transform._dummy,a=r.transform;if(!a.owner.isStatic&&i){var n=a.worldMatrix,s=this.owner._transform;H.matrix4x4MultiplyMFM(s.worldMatrix,i.getWorldMatrix(),n),a.worldMatrix=n}}}linkSprite3DToAvatarNode(e,t){return this._isLinkSpriteToAnimationNodeData(t,e,!0),this._isLinkSpriteToAnimationNode(t,e,!0),!0}unLinkSprite3DToAvatarNode(e){var t=e.transform._dummy;if(t){var r=t._owner.name;return this._isLinkSpriteToAnimationNodeData(e,r,!1),this._isLinkSpriteToAnimationNode(e,r,!1),!0}return!1}_updateAnimationNodeWorldMatix(e,r,i,a,n){t.LayaGL.instance.updateAnimationNodeWorldMatix(e,r,i,n,a)}}le._tempVector31=new n,le._tempQuaternion1=new S,le.CULLINGMODE_ALWAYSANIMATE=0,le.CULLINGMODE_CULLCOMPLETELY=2;class _e{constructor(){this.invertY=!1,this.configPipeLineMode="Forward"}}_e._instance=new _e;class he extends t.BaseTexture{constructor(e,r,i=t.RenderTextureFormat.R8G8B8,a=t.RenderTextureDepthFormat.DEPTH_16){super(i,!1),this._inPool=!1,this._isCameraTarget=!1,this._glTextureType=t.LayaGL.instance.TEXTURE_2D,this._width=e,this._height=r,this._depthStencilFormat=a,this._mipmapCount=1,this._create(e,r)}static get currentActive(){return he._currentActive}static createFromPool(e,r,i=t.RenderTextureFormat.R8G8B8,a=t.RenderTextureDepthFormat.DEPTH_16){for(var n,s=0,o=he._pool.length;s<o;s++)if((n=he._pool[s])._width==e&&n._height==r&&n._format==i&&n._depthStencilFormat==a){n._inPool=!1;var l=he._pool[o-1];return he._pool[s]=l,he._pool.length-=1,n}return(n=new he(e,r,i,a)).lock=!0,n}static recoverToPool(e){e._inPool||(he._pool.push(e),e._inPool=!0)}get depthStencilFormat(){return this._depthStencilFormat}get defaulteTexture(){return t.Texture2D.grayTexture}_create(e,r){var i=t.LayaGL.instance,a=i,n=this._glTextureType,s=t.LayaGL.layaGPUInstance,o=s._isWebGL2,l=this._format;if(this._frameBuffer=i.createFramebuffer(),i.bindFramebuffer(i.FRAMEBUFFER,this._frameBuffer),l!==t.RenderTextureFormat.Depth&&l!==t.RenderTextureFormat.ShadowMap){switch(t.WebGLContext.bindTexture(i,n,this._glTexture),l){case t.RenderTextureFormat.R8G8B8:o?a.texStorage2D(n,this._mipmapCount,a.RGB8,e,r):i.texImage2D(n,0,i.RGB,e,r,0,i.RGB,i.UNSIGNED_BYTE,null);break;case t.RenderTextureFormat.R8G8B8A8:o?a.texStorage2D(n,this._mipmapCount,a.RGBA8,e,r):i.texImage2D(n,0,i.RGBA,e,r,0,i.RGBA,i.UNSIGNED_BYTE,null);break;case t.RenderTextureFormat.Alpha8:o?a.texStorage2D(n,0,a.R8,e,r):i.texImage2D(n,0,i.ALPHA,e,r,0,i.ALPHA,i.UNSIGNED_BYTE,null);break;case t.RenderTextureFormat.R16G16B16A16:o?a.texStorage2D(n,this._mipmapCount,a.RGBA16F,e,r):i.texImage2D(n,0,i.RGBA,e,r,0,i.RGBA,s._oesTextureHalfFloat.HALF_FLOAT_OES,null)}i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,this._glTexture,0)}if(l==t.RenderTextureFormat.Depth||l==t.RenderTextureFormat.ShadowMap){switch(t.WebGLContext.bindTexture(i,n,this._glTexture),this._depthStencilFormat){case t.RenderTextureDepthFormat.DEPTH_16:o?a.texStorage2D(n,this._mipmapCount,a.DEPTH_COMPONENT16,e,r):i.texImage2D(n,0,i.DEPTH_COMPONENT,e,r,0,i.DEPTH_COMPONENT,i.UNSIGNED_SHORT,null),i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.TEXTURE_2D,this._glTexture,0);break;case t.RenderTextureDepthFormat.DEPTHSTENCIL_24_8:o?a.texStorage2D(n,this._mipmapCount,a.DEPTH24_STENCIL8,e,r):i.texImage2D(n,0,i.DEPTH_STENCIL,e,r,0,i.DEPTH_STENCIL,s._webgl_depth_texture.UNSIGNED_INT_24_8_WEBGL,null),i.framebufferTexture2D(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.TEXTURE_2D,this._glTexture,0);break;default:throw"RenderTexture: depth format RenderTexture must use depthFormat with DEPTH_16 and DEPTHSTENCIL_16_8."}o&&l==t.RenderTextureFormat.ShadowMap&&a.texParameteri(n,a.TEXTURE_COMPARE_MODE,a.COMPARE_REF_TO_TEXTURE)}else if(this._depthStencilFormat!==t.RenderTextureDepthFormat.DEPTHSTENCIL_NONE){switch(this._depthStencilBuffer=i.createRenderbuffer(),i.bindRenderbuffer(i.RENDERBUFFER,this._depthStencilBuffer),this._depthStencilFormat){case t.RenderTextureDepthFormat.DEPTH_16:i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_COMPONENT16,e,r),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_ATTACHMENT,i.RENDERBUFFER,this._depthStencilBuffer);break;case t.RenderTextureDepthFormat.STENCIL_8:i.renderbufferStorage(i.RENDERBUFFER,i.STENCIL_INDEX8,e,r),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.STENCIL_ATTACHMENT,i.RENDERBUFFER,this._depthStencilBuffer);break;case t.RenderTextureDepthFormat.DEPTHSTENCIL_24_8:i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_STENCIL,e,r),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.RENDERBUFFER,this._depthStencilBuffer);break;default:throw"RenderTexture: unkonw depth format."}i.bindRenderbuffer(i.RENDERBUFFER,null)}i.bindFramebuffer(i.FRAMEBUFFER,null),this._setWarpMode(i.TEXTURE_WRAP_S,this._wrapModeU),this._setWarpMode(i.TEXTURE_WRAP_T,this._wrapModeV),this._setFilterMode(this._filterMode),this._setAnisotropy(this._anisoLevel),this._readyed=!0,this._activeResource(),this._setGPUMemory(e*r*4)}_start(){var e=t.LayaGL.instance;e.bindFramebuffer(e.FRAMEBUFFER,this._frameBuffer),he._currentActive=this,this._isCameraTarget&&(_e._instance.invertY=!0),this._readyed=!1}_end(){var e=t.LayaGL.instance;e.bindFramebuffer(e.FRAMEBUFFER,null),he._currentActive=null,this._isCameraTarget&&(_e._instance.invertY=!1),this._readyed=!0}getData(e,r,i,a,n){if(t.Render.isConchApp&&2==window.conchConfig.threadMode)throw"native 2 thread mode use getDataAsync";var s=t.LayaGL.instance;return s.bindFramebuffer(s.FRAMEBUFFER,this._frameBuffer),s.checkFramebufferStatus(s.FRAMEBUFFER)===s.FRAMEBUFFER_COMPLETE?(s.readPixels(e,r,i,a,s.RGBA,s.UNSIGNED_BYTE,n),s.bindFramebuffer(s.FRAMEBUFFER,null),n):(s.bindFramebuffer(s.FRAMEBUFFER,null),null)}_disposeResource(){if(this._frameBuffer){var e=t.LayaGL.instance;e.deleteTexture(this._glTexture),e.deleteFramebuffer(this._frameBuffer),e.deleteRenderbuffer(this._depthStencilBuffer),this._glTexture=null,this._frameBuffer=null,this._depthStencilBuffer=null,this._setGPUMemory(0)}}getDataAsync(e,r,i,a,n){var s=t.LayaGL.instance;s.bindFramebuffer(s.FRAMEBUFFER,this._frameBuffer),s.readPixelsAsync(e,r,i,a,s.RGBA,s.UNSIGNED_BYTE,(function(e){n(new Uint8Array(e))})),s.bindFramebuffer(s.FRAMEBUFFER,null)}}he._pool=[];class ce{constructor(){this._mask=[],this._length=0}_intersectionDefineDatas(e){for(var t=e._mask,r=this._mask,i=this._length-1;i>=0;i--){var a=r[i]&t[i];0==a&&i==this._length-1?this._length--:r[i]=a}}add(e){var t=e._index,r=t+1,i=this._mask,a=this._length;if(a<r){for(i.length<r&&(i.length=r);a<t;a++)i[a]=0;i[t]=e._value,this._length=r}else i[t]|=e._value}remove(e){var t=e._index,r=this._mask,i=this._length-1;if(!(t>i)){var a=r[t]&~e._value;t==i&&0===a?this._length--:r[t]=a}}addDefineDatas(e){var t=e._mask,r=e._length,i=this._mask,a=this._length;if(a<r){i.length=r;for(var n=0;n<a;n++)i[n]|=t[n];for(;n<r;n++)i[n]=t[n];this._length=r}else for(n=0;n<r;n++)i[n]|=t[n]}removeDefineDatas(e){for(var t=e._mask,r=this._mask,i=this._length-1,a=Math.min(e._length,i);a>=0;a--){var n=r[a]&~t[a];a==i&&0===n?(i--,this._length--):r[a]=n}}has(e){var t=e._index;return!(t>=this._length)&&0!=(this._mask[t]&e._value)}clear(){this._length=0}cloneTo(e){var t=e,r=t._mask,i=this._mask,a=this._length;r.length=a;for(var n=0;n<a;n++)r[n]=i[n];t._length=a}clone(){var e=new ce;return this.cloneTo(e),e}}class de extends t.Buffer{constructor(e,r,i=!1){super(),this._vertexDeclaration=null,this._float32Reader=null;var a=t.LayaGL.instance;this._bufferUsage=r,this._bufferType=a.ARRAY_BUFFER,this._canRead=i,this._byteLength=e,this.bind(),a.bufferData(this._bufferType,this._byteLength,this._bufferUsage),i&&(this._buffer=new Uint8Array(e),this._float32Reader=new Float32Array(this._buffer.buffer))}get vertexDeclaration(){return this._vertexDeclaration}set vertexDeclaration(e){this._vertexDeclaration=e}get canRead(){return this._canRead}bind(){if(t.Buffer._bindedVertexBuffer!==this._glBuffer){var e=t.LayaGL.instance;return e.bindBuffer(e.ARRAY_BUFFER,this._glBuffer),t.Buffer._bindedVertexBuffer=this._glBuffer,!0}return!1}orphanStorage(){this.bind(),t.LayaGL.instance.bufferData(this._bufferType,this._byteLength,this._bufferUsage)}setData(e,r=0,i=0,a=Number.MAX_SAFE_INTEGER){if(this.bind(),0!==i||a!==Number.MAX_SAFE_INTEGER){var n=new Uint8Array(e,i,a);t.LayaGL.instance.bufferSubData(this._bufferType,r,n),this._canRead&&this._buffer.set(n,r)}else t.LayaGL.instance.bufferSubData(this._bufferType,r,e),this._canRead&&this._buffer.set(new Uint8Array(e),r)}getUint8Data(){if(this._canRead)return this._buffer;throw new Error("Can't read data from VertexBuffer with only write flag!")}getFloat32Data(){if(this._canRead)return this._float32Reader;throw new Error("Can't read data from VertexBuffer with only write flag!")}markAsUnreadbale(){this._canRead=!1,this._buffer=null,this._float32Reader=null}destroy(){super.destroy(),this._buffer=null,this._float32Reader=null,this._vertexDeclaration=null,this._byteLength=0}}de.DATATYPE_FLOAT32ARRAY=0,de.DATATYPE_UINT8ARRAY=1;class ue{static __init__(){var e=t.LayaGL.instance;ue._elementInfos={single:[1,e.FLOAT,0],vector2:[2,e.FLOAT,0],vector3:[3,e.FLOAT,0],vector4:[4,e.FLOAT,0],color:[4,e.FLOAT,0],byte4:[4,e.UNSIGNED_BYTE,0],short2:[2,e.FLOAT,0],short4:[4,e.FLOAT,0],normalizedshort2:[2,e.FLOAT,0],normalizedshort4:[4,e.FLOAT,0],halfvector2:[2,e.FLOAT,0],halfvector4:[4,e.FLOAT,0]}}static getElementInfos(e){var t=ue._elementInfos[e];if(t)return t;throw"VertexElementFormat: this vertexElementFormat is not implement."}}ue.Single="single",ue.Vector2="vector2",ue.Vector3="vector3",ue.Vector4="vector4",ue.Color="color",ue.Byte4="byte4",ue.Short2="short2",ue.Short4="short4",ue.NormalizedShort2="normalizedshort2",ue.NormalizedShort4="normalizedshort4",ue.HalfVector2="halfvector2",ue.HalfVector4="halfvector4";class me{constructor(e=null){this._ownerResource=null,this._data=null,this._defineDatas=new ce,this._runtimeCopyValues=[],this._ownerResource=e,this._initData()}_initData(){this._data=new Object}getData(){return this._data}addDefine(e){this._defineDatas.add(e)}removeDefine(e){this._defineDatas.remove(e)}hasDefine(e){return this._defineDatas.has(e)}clearDefine(){this._defineDatas.clear()}getBool(e){return this._data[e]}setBool(e,t){this._data[e]=t}getInt(e){return this._data[e]}setInt(e,t){this._data[e]=t}getNumber(e){return this._data[e]}setNumber(e,t){this._data[e]=t}getVector2(e){return this._data[e]}setVector2(e,t){this._data[e]=t}getVector3(e){return this._data[e]}setVector3(e,t){this._data[e]=t}getVector(e){return this._data[e]}setVector(e,t){this._data[e]=t}getQuaternion(e){return this._data[e]}setQuaternion(e,t){this._data[e]=t}getMatrix4x4(e){return this._data[e]}setMatrix4x4(e,t){this._data[e]=t}getBuffer(e){return this._data[e]}setBuffer(e,t){this._data[e]=t}setTexture(e,t){var r=this._data[e];this._data[e]=t,this._ownerResource&&this._ownerResource.referenceCount>0&&(r&&r._removeReference(),t&&t._addReference())}getTexture(e){return this._data[e]}setAttribute(e,t){this._data[e]=t}getAttribute(e){return this._data[e]}getLength(){return this._data.length}setLength(e){this._data.length=e}cloneTo(e){var r=e,s=r._data;for(var o in this._data){var l=this._data[o];if(null!=l)if("number"==typeof l)s[o]=l;else if("number"==typeof l)s[o]=l;else if("boolean"==typeof l)s[o]=l;else if(l instanceof i){var _=s[o]||(s[o]=new i);l.cloneTo(_),s[o]=_}else if(l instanceof n){var h=s[o]||(s[o]=new n);l.cloneTo(h),s[o]=h}else if(l instanceof a){var c=s[o]||(s[o]=new a);l.cloneTo(c),s[o]=c}else if(l instanceof R){var d=s[o]||(s[o]=new R);l.cloneTo(d),s[o]=d}else l instanceof t.BaseTexture&&(s[o]=l)}this._defineDatas.cloneTo(r._defineDatas)}clone(){var e=new me;return this.cloneTo(e),e}cloneToForNative(e){var r=e;this._int32Data.length-r._int32Data.length>0&&r.needRenewArrayBufferForNative(this._int32Data.length),r._int32Data.set(this._int32Data,0);var s=r._nativeArray,o=this._nativeArray.length;s.length=o;for(var l=0;l<o;l++){var _=this._nativeArray[l];if(_)if("number"==typeof _)s[l]=_,r.setNumber(l,_);else if("number"==typeof _)s[l]=_,r.setInt(l,_);else if("boolean"==typeof _)s[l]=_,r.setBool(l,_);else if(_ instanceof i){var h=s[l]||(s[l]=new i);_.cloneTo(h),s[l]=h,r.setVector2(l,h)}else if(_ instanceof n){var c=s[l]||(s[l]=new n);_.cloneTo(c),s[l]=c,r.setVector3(l,c)}else if(_ instanceof a){var d=s[l]||(s[l]=new a);_.cloneTo(d),s[l]=d,r.setVector(l,d)}else if(_ instanceof R){var u=s[l]||(s[l]=new R);_.cloneTo(u),s[l]=u,r.setMatrix4x4(l,u)}else _ instanceof t.BaseTexture&&(s[l]=_,r.setTexture(l,_))}this._defineDatas.cloneTo(r._defineDatas)}_initDataForNative(){this._frameCount=-1,this._runtimeCopyValues.length=0,this._nativeArray=[],this._data=new ArrayBuffer(32),this._int32Data=new Int32Array(this._data),this._float32Data=new Float32Array(this._data),t.LayaGL.instance.createArrayBufferRef(this._data,t.LayaGL.ARRAY_BUFFER_TYPE_DATA,!0)}needRenewArrayBufferForNative(e){if(e>=this._int32Data.length){var r=4*(e+1),i=this._int32Data,a=this._data.conchRef,n=this._data._ptrID;this._data=new ArrayBuffer(r),this._int32Data=new Int32Array(this._data),this._float32Data=new Float32Array(this._data),this._data.conchRef=a,this._data._ptrID=n,i&&this._int32Data.set(i,0);var s=t.LayaGL.instance;s.updateArrayBufferRef?s.updateArrayBufferRef(this._data._ptrID,a.isSyncToRender(),this._data):window.conch.updateArrayBufferRef(this._data._ptrID,a.isSyncToRender(),this._data)}}getDataForNative(){return this._nativeArray}getIntForNative(e){return this._int32Data[e]}setIntForNative(e,t){this.needRenewArrayBufferForNative(e),this._int32Data[e]=t,this._nativeArray[e]=t}getBoolForNative(e){return 1==this._int32Data[e]}setBoolForNative(e,t){this.needRenewArrayBufferForNative(e),this._int32Data[e]=t?1:0,this._nativeArray[e]=t}getNumberForNative(e){return this._float32Data[e]}setNumberForNative(e,t){this.needRenewArrayBufferForNative(e),this._float32Data[e]=t,this._nativeArray[e]=t}getMatrix4x4ForNative(e){return this._nativeArray[e]}setMatrix4x4ForNative(e,t){this.needRenewArrayBufferForNative(e),this._nativeArray[e]=t;var r=this.setReferenceForNative(t.elements);this._int32Data[e]=r}getVectorForNative(e){return this._nativeArray[e]}setVectorForNative(e,t){this.needRenewArrayBufferForNative(e),this._nativeArray[e]=t,t.elements||t.forNativeElement();var r=this.setReferenceForNative(t.elements);this._int32Data[e]=r}getVector2ForNative(e){return this._nativeArray[e]}setVector2ForNative(e,t){this.needRenewArrayBufferForNative(e),this._nativeArray[e]=t,t.elements||t.forNativeElement();var r=this.setReferenceForNative(t.elements);this._int32Data[e]=r}getVector3ForNative(e){return this._nativeArray[e]}setVector3ForNative(e,t){this.needRenewArrayBufferForNative(e),this._nativeArray[e]=t,t.elements||t.forNativeElement();var r=this.setReferenceForNative(t.elements);this._int32Data[e]=r}getQuaternionForNative(e){return this._nativeArray[e]}setQuaternionForNative(e,t){this.needRenewArrayBufferForNative(e),this._nativeArray[e]=t,t.elements||t.forNativeElement();var r=this.setReferenceForNative(t.elements);this._int32Data[e]=r}getBufferForNative(e){return this._nativeArray[e]}setBufferForNative(e,t){this.needRenewArrayBufferForNative(e),this._nativeArray[e]=t;var r=this.setReferenceForNative(t);this._int32Data[e]=r}getAttributeForNative(e){return this._nativeArray[e]}setAttributeForNative(e,r){this._nativeArray[e]=r,r._ptrID||t.LayaGL.instance.createArrayBufferRef(r,t.LayaGL.ARRAY_BUFFER_TYPE_DATA,!0),t.LayaGL.instance.syncBufferToRenderThread(r),this._int32Data[e]=r._ptrID}getTextureForNative(e){return this._nativeArray[e]}setTextureForNative(e,t){if(t){this.needRenewArrayBufferForNative(e);var r=this._nativeArray[e];this._nativeArray[e]=t;var i=t._getSource()||t.defaulteTexture._getSource();this._int32Data[e]=i.id,this._ownerResource&&this._ownerResource.referenceCount>0&&(r&&r._removeReference(),t&&t._addReference())}}setReferenceForNative(e){this.clearRuntimeCopyArray();var r=0,i=0;return me._SET_RUNTIME_VALUE_MODE_REFERENCE_?(t.LayaGL.instance.createArrayBufferRefs(e,t.LayaGL.ARRAY_BUFFER_TYPE_DATA,!0,t.LayaGL.ARRAY_BUFFER_REF_REFERENCE),r=0,i=e.getPtrID(r)):(t.LayaGL.instance.createArrayBufferRefs(e,t.LayaGL.ARRAY_BUFFER_TYPE_DATA,!0,t.LayaGL.ARRAY_BUFFER_REF_COPY),r=e.getRefNum()-1,i=e.getPtrID(r),this._runtimeCopyValues.push({obj:e,refID:r,ptrID:i})),t.LayaGL.instance.syncBufferToRenderThread(e,r),i}static setRuntimeValueMode(e){me._SET_RUNTIME_VALUE_MODE_REFERENCE_=e}clearRuntimeCopyArray(){var e=t.Stat.loopCount;if(this._frameCount!=e){this._frameCount=e;for(var r=0,i=this._runtimeCopyValues.length;r<i;r++){this._runtimeCopyValues[r].obj.clearRefNum()}this._runtimeCopyValues.length=0}}}me._SET_RUNTIME_VALUE_MODE_REFERENCE_=!0;class fe{constructor(e,t){this._id=++fe._uniqueIDCounter,this._vertexElementsDic={},this._vertexStride=e,this._vertexElements=t;var r=t.length;this._shaderValues=new me(null);for(var i=0;i<r;i++){var a=t[i],n=a._elementUsage;this._vertexElementsDic[n]=a;var s=new Int32Array(5),o=ue.getElementInfos(a._elementFormat);s[0]=o[0],s[1]=o[1],s[2]=o[2],s[3]=this._vertexStride,s[4]=a._offset,this._shaderValues.setAttribute(n,s)}}get id(){return this._id}get vertexStride(){return this._vertexStride}get vertexElementCount(){return this._vertexElements.length}getVertexElementByIndex(e){return this._vertexElements[e]}getVertexElementByUsage(e){return this._vertexElementsDic[e]}}fe._uniqueIDCounter=1;class Te{constructor(e,t,r){this._offset=e,this._elementFormat=t,this._elementUsage=r}get offset(){return this._offset}get elementFormat(){return this._elementFormat}get elementUsage(){return this._elementUsage}}class Ee extends t.BufferStateBase{constructor(){super()}applyVertexBuffer(e){if(t.BufferStateBase._curBindedBufferState!==this)throw"BufferState: must call bind() function first.";var r=t.LayaGL.instance,i=e.vertexDeclaration,a=i._shaderValues.getData();for(var n in this.vertexDeclaration=i,e.bind(),a){var s=parseInt(n),o=a[n];r.enableVertexAttribArray(s),r.vertexAttribPointer(s,o[0],o[1],!!o[2],o[3],o[4])}}applyVertexBuffers(e){if(t.BufferStateBase._curBindedBufferState!==this)throw"BufferState: must call bind() function first.";for(var r=t.LayaGL.instance,i=0,a=e.length;i<a;i++){var n=e[i],s=n.vertexDeclaration._shaderValues.getData();for(var o in n.bind(),s){var l=parseInt(o),_=s[o];r.enableVertexAttribArray(l),r.vertexAttribPointer(l,_[0],_[1],!!_[2],_[3],_[4])}}}applyInstanceVertexBuffer(e){if(t.LayaGL.layaGPUInstance.supportInstance()){if(t.BufferStateBase._curBindedBufferState!==this)throw"BufferState: must call bind() function first.";var r=t.LayaGL.instance,i=e.vertexDeclaration._shaderValues.getData();for(var a in e.bind(),i){var n=parseInt(a),s=i[a];r.enableVertexAttribArray(n),r.vertexAttribPointer(n,s[0],s[1],!!s[2],s[3],s[4]),t.LayaGL.layaGPUInstance.vertexAttribDivisor(n,1)}}}applyIndexBuffer(e){if(t.BufferStateBase._curBindedBufferState!==this)throw"BufferState: must call bind() function first.";this._bindedIndexBuffer!==e&&(e._bindForVAO(),this._bindedIndexBuffer=e)}}class pe extends t.Resource{constructor(){super(),this._bufferState=new Ee,this._bufferStateInvertUV=new Ee;var e=t.LayaGL.instance;this._vertexBuffer=new de(64,e.STATIC_DRAW,!1),this._vertexBuffer.vertexDeclaration=pe._vertexDeclaration,this._vertexBuffer.setData(pe._vertices.buffer),this._bufferState.bind(),this._bufferState.applyVertexBuffer(this._vertexBuffer),this._bufferState.unBind(),this._vertexBufferInvertUV=new de(64,e.STATIC_DRAW,!1),this._vertexBufferInvertUV.vertexDeclaration=pe._vertexDeclaration,this._vertexBufferInvertUV.setData(pe._verticesInvertUV.buffer),this._bufferStateInvertUV.bind(),this._bufferStateInvertUV.applyVertexBuffer(this._vertexBufferInvertUV),this._bufferStateInvertUV.unBind(),this._setGPUMemory(this._vertexBuffer._byteLength+this._vertexBufferInvertUV._byteLength)}static __init__(){pe._vertexDeclaration=new fe(16,[new Te(0,ue.Vector4,pe.SCREENQUAD_POSITION_UV)]),pe.instance=new pe,pe.instance.lock=!0}render(){var e=t.LayaGL.instance;this._bufferState.bind(),e.drawArrays(e.TRIANGLE_STRIP,0,4),t.Stat.renderBatches++}renderInvertUV(){var e=t.LayaGL.instance;this._bufferStateInvertUV.bind(),e.drawArrays(e.TRIANGLE_STRIP,0,4),t.Stat.renderBatches++}destroy(){super.destroy(),this._bufferState.destroy(),this._vertexBuffer.destroy(),this._bufferStateInvertUV.destroy(),this._vertexBufferInvertUV.destroy(),this._setGPUMemory(0)}}pe.SCREENQUAD_POSITION_UV=0,pe._vertices=new Float32Array([1,1,1,1,1,-1,1,0,-1,1,0,1,-1,-1,0,0]),pe._verticesInvertUV=new Float32Array([1,1,1,0,1,-1,1,1,-1,1,0,0,-1,-1,0,1]);class ge extends t.Resource{constructor(){super(),this._bufferState=new Ee,this._bufferStateInvertUV=new Ee;var e=t.LayaGL.instance;this._vertexBuffer=new de(48,e.STATIC_DRAW,!1),this._vertexBuffer.vertexDeclaration=ge._vertexDeclaration,this._vertexBuffer.setData(ge._vertices.buffer),this._bufferState.bind(),this._bufferState.applyVertexBuffer(this._vertexBuffer),this._bufferState.unBind(),this._vertexBufferInvertUV=new de(48,e.STATIC_DRAW,!1),this._vertexBufferInvertUV.vertexDeclaration=ge._vertexDeclaration,this._vertexBufferInvertUV.setData(ge._verticesInvertUV.buffer),this._bufferStateInvertUV.bind(),this._bufferStateInvertUV.applyVertexBuffer(this._vertexBufferInvertUV),this._bufferStateInvertUV.unBind(),this._setGPUMemory(this._vertexBuffer._byteLength+this._vertexBufferInvertUV._byteLength)}static __init__(){ge._vertexDeclaration=new fe(16,[new Te(0,ue.Vector4,ge.SCREENTRIANGLE_POSITION_UV)]),ge.instance=new ge,ge.instance.lock=!0}render(){var e=t.LayaGL.instance;this._bufferState.bind(),e.drawArrays(e.TRIANGLES,0,3),t.Stat.renderBatches++}renderInvertUV(){var e=t.LayaGL.instance;this._bufferStateInvertUV.bind(),e.drawArrays(e.TRIANGLES,0,3),t.Stat.renderBatches++}destroy(){super.destroy(),this._bufferState.destroy(),this._vertexBuffer.destroy(),this._bufferStateInvertUV.destroy(),this._vertexBufferInvertUV.destroy(),this._setGPUMemory(0)}}ge.SCREENTRIANGLE_POSITION_UV=0,ge._vertices=new Float32Array([-1,-1,0,0,-1,3,0,2,3,-1,2,0]),ge._verticesInvertUV=new Float32Array([-1,-1,0,1,-1,3,0,-1,3,-1,2,1]);class Se{constructor(e,t){this._index=e,this._value=t}}class Re{constructor(e,t,r,i){this._subShaderIndex=0,this._passIndex=0,this.setValue(e,t,r,i)}get shader(){return this._shader}get subShaderIndex(){return this._subShaderIndex}get passIndex(){return this._passIndex}get defineNames(){return this._defineNames}setValue(e,t,r,i){if(!e)throw"ShaderVariantInfo:Shader can't be null.";var a=e.getSubShaderAt(t);if(!a)throw`ShaderVariantInfo:Shader don't have subShaderIndex of ${t}.`;var n=a._passes[r];if(!n)throw`ShaderVariantInfo:Shader don't have passIndex of ${r}.`;for(var s=n._validDefine,o=0,l=i.length;o<l;o++){var _=i[o];if(!s.has(g.Shader3D.getDefineByName(_)))throw`ShaderVariantInfo:Invalid defineName ${_} in ${e._name} subShaderIndex of ${t} passIndex of ${r}.`}this._shader=e,this._subShaderIndex=t,this._passIndex=r,this._defineNames=i}equal(e){if(this._shader!==e._shader||this._subShaderIndex!==e._subShaderIndex||this._passIndex!==e._passIndex)return!1;var t=this._defineNames,r=e._defineNames;if(t.length!==r.length)return!1;for(var i=0,a=this._defineNames.length;i<a;i++)if(t[i]!==r[i])return!1;return!0}clone(){return new Re(this._shader,this._subShaderIndex,this._passIndex,this._defineNames.slice())}}class ve{constructor(){this._allCompiled=!1,this._variants=[]}get allCompiled(){return this._allCompiled}get variantCount(){return this._variants.length}add(e){for(var t=0,r=this._variants.length;t<r;t++)if(this._variants[t].equal(e))return!1;return this._variants.push(e.clone()),this._allCompiled=!1,!0}remove(e){for(var t=0,r=this._variants.length;t<r;t++)if(this._variants[t].equal(e))return this._variants.splice(t,1),!0;return!1}contatins(e){for(var t=0,r=this._variants.length;t<r;t++)if(this._variants[t].equal(e))return!0;return!1}getByIndex(e){return this._variants[e]}clear(){this._variants.length=0}compile(){if(!this._allCompiled){for(var e=this._variants,t=0,r=e.length;t<r;t++){var i=e[t];g.Shader3D.compileShaderByDefineNames(i._shader._name,i._subShaderIndex,i._passIndex,i._defineNames)}this._allCompiled=!0}}}class xe{constructor(e,t,r,i,a){this._attributeMap=null,this._uniformMap=null,this._enableInstancing=!1,this._supportReflectionProbe=!1,this._subShaders=[],this._name=e,this._attributeMap=t,this._uniformMap=r,this._enableInstancing=i,this._supportReflectionProbe=a}static _getNamesByDefineData(e,t){var r=xe._maskMap,i=e._mask;t.length=0;for(var a=0,n=e._length;a<n;a++)for(var s=r[a],o=i[a],l=0;l<32;l++){var _=1<<l;if(o>0&&_>o)break;o&_&&t.push(s[_])}}static getDefineByName(e){var t=xe._defineMap[e];if(!t){var r=xe._maskMap,i=xe._defineCounter,a=Math.floor(i/32),n=1<<i%32;t=new Se(a,n),xe._defineMap[e]=t,a==r.length&&(r.length++,r[a]={}),r[a][n]=e,xe._defineCounter++}return t}static propertyNameToID(e){if(null!=xe._propertyNameMap[e])return xe._propertyNameMap[e];var t=xe._propertyNameCounter++;return xe._propertyNameMap[e]=t,t}static getAttributeMapByDefine(e,t){var r={};for(var i in t)r[i]=t[i];for(var a=0,n=e.length;a<n;a++){switch(e[a]){case"SIMPLEBONE":t.a_Texcoord1&&(r.a_SimpleTextureParams=t.a_Texcoord1,delete r.a_Texcoord1),r.a_SimpleTextureParams=7}}return r}static addInclude(e,r){r=r.replace(t.ShaderCompile._clearCR,""),t.ShaderCompile.addInclude(e,r)}static compileShaderByDefineNames(e,t,r,i){var a=xe.find(e);if(a){var n=a.getSubShaderAt(t);if(n){var s=n._passes[r];if(s){var o=xe._compileDefineDatas;o.clear();for(var l=0,_=i.length;l<_;l++)o.add(xe.getDefineByName(i[l]));s.withCompile(o)}else console.warn("Shader3D: unknown passIndex.")}else console.warn("Shader3D: unknown subShaderIndex.")}else console.warn("Shader3D: unknown shader name.")}static add(e,t=null,r=null,i=!1,a=!1){return xe._preCompileShader[e]=new xe(e,t,r,i,a)}static find(e){return xe._preCompileShader[e]}get name(){return this._name}addSubShader(e){this._subShaders.push(e),e._owner=this}getSubShaderAt(e){return this._subShaders[e]}static compileShader(e,t,r,...i){var a=xe.find(e);if(a){var n=a.getSubShaderAt(t);if(n){var s=n._passes[r];if(s){var o=xe._compileDefineDatas,l=o._mask;l.length=0;for(var _=0,h=i.length;_<h;_++)l.push(i[_]);o._length=i.length,s.withCompile(o)}else console.warn("Shader3D: unknown passIndex.")}else console.warn("Shader3D: unknown subShaderIndex.")}else console.warn("Shader3D: unknown shader name.")}}xe._compileDefineDatas=new ce,xe.RENDER_STATE_CULL=0,xe.RENDER_STATE_BLEND=1,xe.RENDER_STATE_BLEND_SRC=2,xe.RENDER_STATE_BLEND_DST=3,xe.RENDER_STATE_BLEND_SRC_RGB=4,xe.RENDER_STATE_BLEND_DST_RGB=5,xe.RENDER_STATE_BLEND_SRC_ALPHA=6,xe.RENDER_STATE_BLEND_DST_ALPHA=7,xe.RENDER_STATE_BLEND_CONST_COLOR=8,xe.RENDER_STATE_BLEND_EQUATION=9,xe.RENDER_STATE_BLEND_EQUATION_RGB=10,xe.RENDER_STATE_BLEND_EQUATION_ALPHA=11,xe.RENDER_STATE_DEPTH_TEST=12,xe.RENDER_STATE_DEPTH_WRITE=13,xe.PERIOD_CUSTOM=0,xe.PERIOD_MATERIAL=1,xe.PERIOD_SPRITE=2,xe.PERIOD_CAMERA=3,xe.PERIOD_SCENE=4,xe._propertyNameCounter=0,xe._propertyNameMap={},xe._defineCounter=0,xe._defineMap={},xe._preCompileShader={},xe._maskMap=[],xe.debugMode=!1,xe.debugShaderVariantCollection=new ve;class Ae{constructor(){this._commandBuffer=null}static __init__(){Ae._screenShaderData=new me,Ae._screenShader=xe.find("BlitScreen")}run(){}recover(){this._commandBuffer=null}setContext(e){this._context=e}}Ae.SCREENTEXTURE_NAME="u_MainTex",Ae.SCREENTEXTUREOFFSETSCALE_NAME="u_OffsetScale",Ae.MAINTEXTURE_TEXELSIZE_NAME="u_MainTex_TexelSize",Ae.SCREENTEXTURE_ID=xe.propertyNameToID(Ae.SCREENTEXTURE_NAME),Ae.SCREENTEXTUREOFFSETSCALE_ID=xe.propertyNameToID(Ae.SCREENTEXTUREOFFSETSCALE_NAME),Ae.MAINTEXTURE_TEXELSIZE_ID=xe.propertyNameToID(Ae.MAINTEXTURE_TEXELSIZE_NAME);class Ie extends Ae{constructor(){super(...arguments),this._source=null,this._dest=null,this._offsetScale=null,this._shader=null,this._shaderData=null,this._subShader=0,this._sourceTexelSize=new a,this._screenType=0,this._drawDefineCavans=!1}static create(e,t,r=null,i=null,a=null,n=0,s=Ie._SCREENTYPE_QUAD,o=null,l=!1){var _;return(_=Ie._pool.length>0?Ie._pool.pop():new Ie)._source=e,_._dest=t,_._offsetScale=r,_._shader=i,_._shaderData=a,_._subShader=n,_._screenType=s,_._commandBuffer=o,_._drawDefineCavans=l,_}run(){var e;if(this._source)e=this._source;else{if(!this._commandBuffer._camera._internalRenderTexture)throw"camera internalRenderTexture is null,please set camera enableBuiltInRenderTexture";e=this._commandBuffer._camera._internalRenderTexture}var r=this._shader||Ae._screenShader,i=this._shaderData||Ae._screenShaderData,a=this._dest||this._drawDefineCavans?this._dest:this._commandBuffer._camera._internalRenderTexture;t.LayaGL.instance.viewport(0,0,a?a.width:_e.clientWidth,a?a.height:_e.clientHeight),i.setTexture(Ae.SCREENTEXTURE_ID,e),i.setVector(Ae.SCREENTEXTUREOFFSETSCALE_ID,this._offsetScale||Ie._defaultOffsetScale),this._sourceTexelSize.setValue(1/e.width,1/e.height,e.width,e.height),i.setVector(Ae.MAINTEXTURE_TEXELSIZE_ID,this._sourceTexelSize),he.currentActive&&he.currentActive._end(),a&&a._start();for(var n=r.getSubShaderAt(this._subShader)._passes,s=0,o=n.length;s<o;s++){var l=Ie._compileDefine;i._defineDatas.cloneTo(l);var _=n[s].withCompile(l);switch(_.bind(),_.uploadUniforms(_._materialUniformParamsMap,i,!0),_.uploadRenderStateBlendDepth(i),_.uploadRenderStateFrontFace(i,!1,null),this._screenType){case Ie._SCREENTYPE_QUAD:_e._instance.invertY?pe.instance.renderInvertUV():pe.instance.render();break;case Ie._SCREENTYPE_TRIANGLE:_e._instance.invertY?ge.instance.renderInvertUV():ge.instance.render();break;default:throw"BlitScreenQuadCMD:unknown screen Type."}}a&&a._end()}recover(){Ie._pool.push(this),this._source=null,this._dest=null,this._offsetScale=null,this._shader=null,this._shaderData=null,this._drawDefineCavans=!1,super.recover()}}Ie._SCREENTYPE_QUAD=0,Ie._SCREENTYPE_TRIANGLE=1,Ie._compileDefine=new ce,Ie._pool=[],Ie._defaultOffsetScale=new a(0,0,1,1);class Me extends Ae{constructor(){super(...arguments),this._renderTexture=null}static create(e){var t;return(t=Me._pool.length>0?Me._pool.pop():new Me)._renderTexture=e,t}run(){he.currentActive&&he.currentActive._end(),t.LayaGL.instance.viewport(0,0,this._renderTexture.width,this._renderTexture.height),this._renderTexture._start()}recover(){Me._pool.push(this),this._renderTexture=null}}Me._pool=[],(o=e.ShaderDataType||(e.ShaderDataType={}))[o.Int=0]="Int",o[o.Bool=1]="Bool",o[o.Number=2]="Number",o[o.Vector2=3]="Vector2",o[o.Vector3=4]="Vector3",o[o.Vector4=5]="Vector4",o[o.Quaternion=6]="Quaternion",o[o.Matrix4x4=7]="Matrix4x4",o[o.Buffer=8]="Buffer",o[o.Texture=9]="Texture";class De extends Ae{constructor(){super(...arguments),this._shaderData=null,this._nameID=0,this._value=null,this._dataType=-1}static create(e,t,r,i,a){var n;return(n=De._pool.length>0?De._pool.pop():new De)._shaderData=e,n._nameID=t,n._value=r,n._dataType=i,n._commandBuffer=a,n}run(){switch(this._dataType){case e.ShaderDataType.Int:this._shaderData.setInt(this._nameID,this._value);break;case e.ShaderDataType.Number:this._shaderData.setNumber(this._nameID,this._value);break;case e.ShaderDataType.Bool:this._shaderData.setBool(this._nameID,this._value);break;case e.ShaderDataType.Matrix4x4:this._shaderData.setMatrix4x4(this._nameID,this._value);break;case e.ShaderDataType.Quaternion:this._shaderData.setQuaternion(this._nameID,this._value);break;case e.ShaderDataType.Texture:this._shaderData.setTexture(this._nameID,this._value);break;case e.ShaderDataType.Vector4:this._shaderData.setVector(this._nameID,this._value);break;case e.ShaderDataType.Vector2:this._shaderData.setVector2(this._nameID,this._value);break;case e.ShaderDataType.Vector3:this._shaderData.setVector3(this._nameID,this._value);break;case e.ShaderDataType.Buffer:this._shaderData.setBuffer(this._nameID,this._value);break;default:throw"no type shaderValue on this CommendBuffer"}}recover(){De._pool.push(this),this._shaderData=null,this._nameID=0,this._value=null,this._dataType=-1}}De._pool=[];class Ce extends t.Node{constructor(e=null,t=!1){super(),this._needProcessCollisions=!1,this._needProcessTriggers=!1,this._id=++Ce._uniqueIDCounter,this._transform=new I(this),this._isStatic=t,this.layer=0,this.name=e||"New Sprite3D"}static __init__(){}static instantiate(e,t=null,r=!0,i=null,a=null){var n=e.clone();t&&t.addChild(n);var s=n.transform;if(r){var o=s.worldMatrix;e.transform.worldMatrix.cloneTo(o),s.worldMatrix=o}else i&&(s.position=i),a&&(s.rotation=a);return n}static load(e,r){t.Laya.loader.create(e,r,null,Ce.HIERARCHY)}get id(){return this._id}get layer(){return this._layer}set layer(e){if(this._layer!==e){if(!(e>=0&&e<=30))throw new Error("Layer value must be 0-30.");this._layer=e}}get url(){return this._url}get isStatic(){return this._isStatic}get transform(){return this._transform}_setCreateURL(e){this._url=t.URL.formatURL(e)}_changeAnimatorsToLinkSprite3D(e,t,r){var i=this.getComponent(le);if(i&&(i.avatar||e._changeAnimatorToLinkSprite3DNoAvatar(i,t,r)),this._parent&&this._parent instanceof Ce){r.unshift(this._parent.name);var a=this._parent;a._hierarchyAnimator&&a._changeAnimatorsToLinkSprite3D(e,t,r)}}_setHierarchyAnimator(e,t){this._changeHierarchyAnimator(e),this._changeAnimatorAvatar(e.avatar);for(var r=0,i=this._children.length;r<i;r++){var a=this._children[r];a._hierarchyAnimator==t&&a._setHierarchyAnimator(e,t)}}_clearHierarchyAnimator(e,t){this._changeHierarchyAnimator(t),this._changeAnimatorAvatar(t?t.avatar:null);for(var r=0,i=this._children.length;r<i;r++){var a=this._children[r];a._hierarchyAnimator==e&&a._clearHierarchyAnimator(e,t)}}_changeHierarchyAnimatorAvatar(e,t){this._changeAnimatorAvatar(t);for(var r=0,i=this._children.length;r<i;r++){var a=this._children[r];a._hierarchyAnimator==e&&a._changeHierarchyAnimatorAvatar(e,t)}}_changeAnimatorToLinkSprite3DNoAvatar(e,t,r){e._handleSpriteOwnersBySprite(t,r,this);for(var i=0,a=this._children.length;i<a;i++){var n=this._children[i],s=r.length;r.push(n.name),n._changeAnimatorToLinkSprite3DNoAvatar(e,t,r),r.splice(s,1)}}_changeHierarchyAnimator(e){this._hierarchyAnimator=e}_changeAnimatorAvatar(e){}_onAdded(){if(this._parent instanceof Ce){var e=this._parent;this.transform._setParent(e.transform),e._hierarchyAnimator&&(!this._hierarchyAnimator&&this._setHierarchyAnimator(e._hierarchyAnimator,null),e._changeAnimatorsToLinkSprite3D(this,!0,[this.name]))}super._onAdded()}_onRemoved(){if(super._onRemoved(),this._parent instanceof Ce){var e=this._parent;this.transform._setParent(null),e._hierarchyAnimator&&(this._hierarchyAnimator==e._hierarchyAnimator&&this._clearHierarchyAnimator(e._hierarchyAnimator,null),e._changeAnimatorsToLinkSprite3D(this,!1,[this.name]))}}_parse(e,t){if(void 0!==e.isStatic&&(this._isStatic=e.isStatic),void 0!==e.active&&(this.active=e.active),null!=e.name&&(this.name=e.name),void 0!==e.position){var r=this.transform.localPosition;r.fromArray(e.position),this.transform.localPosition=r}if(void 0!==e.rotationEuler){var i=this.transform.localRotationEuler;i.fromArray(e.rotationEuler),this.transform.localRotationEuler=i}if(void 0!==e.rotation){var a=this.transform.localRotation;a.fromArray(e.rotation),this.transform.localRotation=a}if(void 0!==e.scale){var n=this.transform.localScale;n.fromArray(e.scale),this.transform.localScale=n}null!=e.layer&&(this.layer=e.layer)}_cloneTo(e,t,r){if(this.destroyed)throw new Error("Sprite3D: Can't be cloned if the Sprite3D has destroyed.");var i=e,a=this._transform,n=i._transform;i.name=this.name,i.destroyed=this.destroyed,i.active=this.active,n.localPosition=a.localPosition,n.localRotation=a.localRotation,n.localScale=a.localScale,i._isStatic=this._isStatic,i.layer=this.layer,super._cloneTo(i,t,r)}static _createSprite3DInstance(e){for(var t=e._create(),r=e._children,i=0,a=r.length;i<a;i++){var n=Ce._createSprite3DInstance(r[i]);t.addChild(n)}return t}static _parseSprite3DInstance(e,t,r,i){for(var a=r._children,n=i._children,s=0,o=a.length;s<o;s++)Ce._parseSprite3DInstance(e,t,a[s],n[s]);r._cloneTo(i,e,t)}clone(){var e=Ce._createSprite3DInstance(this);return Ce._parseSprite3DInstance(this,e,this,e),e}destroy(e=!0){this.destroyed||(super.destroy(e),this._transform=null,this._scripts=null,this._url&&t.Loader.clearRes(this._url))}_create(){return new Ce}}Ce.HIERARCHY="HIERARCHY",Ce.WORLDMATRIX=xe.propertyNameToID("u_WorldMat"),Ce.MVPMATRIX=xe.propertyNameToID("u_MvpMatrix"),Ce._uniqueIDCounter=0;class ye extends Ae{constructor(){super(),this._projectionViewWorldMatrix=new R,this._renderShaderValue=new me,this._renderShaderValue=new me(null)}static create(e,t,r,i,a,n){var s;return(s=ye._pool.length>0?ye._pool.pop():new ye)._mesh=e,s._matrix=t,s._material=r,s._subMeshIndex=i,s._subShaderIndex=a,s._commandBuffer=n,s}run(){var e=this._material._shader.getSubShaderAt(this._subShaderIndex);this.setContext(this._commandBuffer._context);var t=this._context,r=t.invertY,i=t.scene,a=t.cameraShaderValue,n=t.projectionViewMatrix;R.multiply(n,this._matrix,this._projectionViewWorldMatrix),this._renderShaderValue.setMatrix4x4(Ce.WORLDMATRIX,this._matrix),this._renderShaderValue.setMatrix4x4(Ce.MVPMATRIX,this._projectionViewWorldMatrix);for(var s=t.pipelineMode,o=e._passes,l=0,_=o.length;l<_;l++){var h=o[l];if(h._pipelineMode===s){var c=ye._compileDefine;i._shaderValues._defineDatas.cloneTo(c),c.addDefineDatas(this._renderShaderValue._defineDatas),c.addDefineDatas(this._material._shaderValues._defineDatas);var d=t.shader=h.withCompile(c);d.bind(),d.uploadUniforms(d._sceneUniformParamsMap,i._shaderValues,!0),d.uploadUniforms(d._spriteUniformParamsMap,this._renderShaderValue,!0),d.uploadUniforms(d._cameraUniformParamsMap,a,!0);var u=this._material._shaderValues;d.uploadUniforms(d._materialUniformParamsMap,u,!0),d.uploadRenderStateBlendDepth(u),d.uploadRenderStateFrontFace(u,r,this._matrix.getInvertFront())}}var m,f=this._mesh._subMeshes;if(-1==this._subMeshIndex)for(var T=0,E=f.length;T<E;T++)(m=f[T])._prepareRender(t)&&m._render(t);else(m=(f=this._mesh._subMeshes)[this._subMeshIndex])._prepareRender(t)&&m._render(t)}recover(){ye._pool.push(this),this._renderShaderValue.clearDefine(),this._renderShaderValue._initData()}}ye._pool=[],ye._compileDefine=new ce;class Le extends Ae{constructor(){super(...arguments),this._clearColor=!1,this._clearDepth=!1,this._backgroundColor=new a,this._depth=1}static create(e,t,r,i=1,a){var n;return(n=Le._pool.length>0?Le._pool.pop():new Le)._clearColor=e,n._clearDepth=t,r.cloneTo(n._backgroundColor),n._depth=i,n._commandBuffer=a,n}run(){var e,r=t.LayaGL.instance,i=this._backgroundColor;this._clearColor&&(r.clearColor(i.x,i.y,i.z,i.w),e|=r.COLOR_BUFFER_BIT),this._clearDepth&&(r.clearDepth(this._depth),e|=r.DEPTH_BUFFER_BIT),(this._clearColor||this._clearDepth)&&r.clear(e)}recover(){}}Le._pool=[];class Oe{constructor(){this.updateMark=-1,this.pointLightCount=0,this.spotLightCount=0,this.indices=[]}}class Ne{constructor(e,t,r,a){this._updateMark=0,this._depthSliceParam=new i,this._xSlices=e,this._ySlices=t,this._zSlices=r;var n=e*t,s=r*(1+Math.ceil(a/4));this._clusterTexture=H._createFloatTextureBuffer(n,s),this._clusterTexture.lock=!0,this._clusterPixels=new Float32Array(n*s*4);for(var o=new Array(this._zSlices),l=0;l<this._zSlices;l++){o[l]=new Array(this._ySlices);for(var _=0;_<this._ySlices;_++){o[l][_]=new Array(this._xSlices);for(var h=0;h<this._xSlices;h++)o[l][_][h]=new Oe}}this._clusterDatas=o}_insertSpotLightSphere(e,t,r,i,a){var s=Ne._tempVector35;s.x=a.x-e.x,s.y=a.y-e.y,s.z=a.z-e.z;var o=n.dot(s,s),l=a.w;if(!(o>l*l))return!1;var _=n.dot(s,t);return!(Math.cos(i)*Math.sqrt(o-_*_)-_*Math.sin(i)>l||_>l+r||_<-l)}_placePointLightToClusters(e,t){for(var r=this._clusterDatas,i=this._updateMark,a=t.zMin,n=t.zMax;a<n;a++)for(var s=t.yMin,o=t.yMax;s<o;s++)for(var l=t.xMin,_=t.xMax;l<_;l++){var h=r[a][s][l];h.updateMark!=i&&(h.pointLightCount=0,h.spotLightCount=0,h.updateMark=i);var c=h.indices,d=h.pointLightCount++;d<c.length?c[d]=e:c.push(e)}}_placeSpotLightToClusters(e,t){for(var r=this._clusterDatas,i=this._updateMark,a=t.zMin,n=t.zMax;a<n;a++)for(var s=t.yMin,o=t.yMax;s<o;s++)for(var l=t.xMin,_=t.xMax;l<_;l++){var h=r[a][s][l];h.updateMark!=i&&(h.pointLightCount=0,h.spotLightCount=0,h.updateMark=i);var c=h.indices,d=h.pointLightCount+h.spotLightCount++;d<c.length?c[d]=e:c.push(e)}}_insertConePlane(e,t,r,i,a){var s=Ne._tempVector36,o=Ne._tempVector37;n.cross(a,t,s),n.cross(s,t,o),n.normalize(o,o);var l=r*Math.tan(i),_=e.x+r*t.x+l*o.x,h=e.y+r*t.y+l*o.y,c=e.z+r*t.z+l*o.z;return _*a.x+h*a.y+c*a.z<=0||e.x*a.x+e.y*a.y+e.z*a.z<=0}_shrinkSphereLightZPerspective(e,t,r,i,a){var n=r.z,s=n-i,o=n+i;if(s>t||o<=e)return!1;var l=this._depthSliceParam;return a.zMin=Math.floor(Math.log2(Math.max(s,e))*l.x-l.y),a.zMax=Math.min(Math.ceil(Math.log2(o)*l.x-l.y),this._zSlices),!0}_shrinkSpotLightZPerspective(e,t,r,i,a,n,s){var o=i.x,l=i.y,_=i.z,h=Math.tan(n)*a,c=r.x,d=r.y,u=r.z,m=o-c,f=l-d,T=_-u,E=m*m+f*f+T*T,p=Math.sqrt(1-T*T/E),g=Math.max(Math.min(u,_-p*h),r.z-a),S=Math.min(Math.max(u,_+p*h),r.z+a);if(g>t||S<=e)return!1;var R=this._depthSliceParam;return s.zMin=Math.floor(Math.log2(Math.max(g,e))*R.x-R.y),s.zMax=Math.min(Math.ceil(Math.log2(S)*R.x-R.y),this._zSlices),!0}_shrinkSphereLightByBoundOrth(e,t,r,i,a,n,s){var o=a.z,l=o-n,_=o+n;if(l>i||_<=r)return!1;var h=a.x,c=h-n,d=h+n;if(c>e||d<=-e)return!1;var u=a.y,m=u-n,f=u+n;if(m>t||f<=-t)return!1;var T=this._xSlices,E=this._ySlices,p=this._depthSliceParam,g=2*e/T,S=2*t/E;return s.xMin=Math.max(Math.floor((c+e)/g),0),s.xMax=Math.min(Math.ceil((d+e)/g),T),s.yMin=Math.max(Math.floor((t-f)/S),0),s.yMax=Math.min(Math.ceil((t-m)/S),E),s.zMin=Math.floor(Math.log2(Math.max(l,r))*p.x-p.y),s.zMax=Math.min(Math.ceil(Math.log2(_)*p.x-p.y),this._zSlices),!0}_shrinkSpotLightByBoundOrth(e,t,r,i,a,n,s,o,l){var _=n.x,h=n.y,c=n.z,d=Math.tan(o)*s,u=a.x,m=a.y,f=a.z,T=_-u,E=h-m,p=c-f,g=T*T+E*E+p*p,S=Math.sqrt(1-p*p/g),R=Math.max(Math.min(f,c-S*d),a.z-s),v=Math.min(Math.max(f,c+S*d),a.z+s);if(R>i||v<=r)return!1;var x=Math.sqrt(1-T*T/g),A=Math.max(Math.min(u,_-x*d),a.x-s),I=Math.min(Math.max(u,_+x*d),a.x+s);if(A>e||I<=-e)return!1;var M=Math.sqrt(1-E*E/g),D=Math.max(Math.min(m,h-M*d),a.y-s),C=Math.min(Math.max(m,h+M*d),a.y+s);if(D>t||C<=-t)return!1;var y=this._xSlices,L=this._ySlices,O=this._depthSliceParam,N=2*e/y,P=2*t/L;return l.xMin=Math.max(Math.floor((A+e)/N),0),l.xMax=Math.min(Math.ceil((I+e)/N),y),l.yMin=Math.max(Math.floor((t-C)/P),0),l.yMax=Math.min(Math.ceil((t-D)/P),L),l.zMin=Math.floor(Math.log2(Math.max(R,r))*O.x-O.y),l.zMax=Math.min(Math.ceil(Math.log2(v)*O.x-O.y),this._zSlices),!0}_shrinkXYByRadiusPerspective(e,t,r,i,a){var n,s,o,l,_,h=e.x,c=e.y,d=e.z,u=this._ySlices+1;for(_=0;_<u;_++){if(c*(m=a[_]).y+d*m.z<t){s=Math.max(0,_-1);break}}if(_==u)return!1;for(l=this._ySlices,_=s+1;_<u;_++){if(c*(m=a[_]).y+d*m.z<=-t){l=Math.max(0,_);break}}for(u=this._xSlices+1,_=0;_<u;_++){if(h*(m=i[_]).x+d*m.z<t){n=Math.max(0,_-1);break}}for(o=this._xSlices,_=n+1;_<u;_++){var m;if(h*(m=i[_]).x+d*m.z<=-t){o=Math.max(0,_);break}}return r.xMin=n,r.xMax=o,r.yMin=s,r.yMax=l,!0}_shrinkSpotXYByConePerspective(e,t,r,i,a,n,s){for(var o,l,_,h,c=Ne._tempVector32,d=a.yMax+1,u=a.yMin+1;u<d;u++)if(this._insertConePlane(e,t,r,i,s[u])){l=Math.max(0,u-1);break}h=a.yMax;for(u=l+1;u<d;u++){var m=s[u];if(c.setValue(0,-m.y,-m.z),!this._insertConePlane(e,t,r,i,c)){h=Math.max(0,u);break}}d=a.xMax+1;for(u=a.xMin+1;u<d;u++)if(this._insertConePlane(e,t,r,i,n[u])){o=Math.max(0,u-1);break}_=a.xMax;for(u=o+1;u<d;u++){m=n[u];if(c.setValue(-m.x,0,-m.z),!this._insertConePlane(e,t,r,i,c)){_=Math.max(0,u);break}}a.xMin=o,a.xMax=_,a.yMin=l,a.yMax=h}_updatePointLightPerspective(e,t,r,i,a,s,o){var l=Ne._tempLightBound,_=Ne._tempVector30;n.transformV3ToV3(i._transform.position,r,_),_.z*=-1,this._shrinkSphereLightZPerspective(e,t,_,i.range,l)&&this._shrinkXYByRadiusPerspective(_,i.range,l,s,o)&&this._placePointLightToClusters(a,l)}_updateSpotLightPerspective(e,t,r,i,a,s,o){var l=Ne._tempLightBound,_=Ne._tempVector30,h=Ne._tempVector31,c=Ne._tempVector34,d=i._transform.position,u=i.range;i._transform.worldMatrix.getForward(h),n.normalize(h,h),n.scale(h,u,c),n.add(d,c,c),n.transformV3ToV3(d,r,_),n.transformV3ToV3(c,r,c),_.z*=-1,c.z*=-1;var m=i.spotAngle/2*Math.PI/180;if(this._shrinkSpotLightZPerspective(e,t,_,c,u,m,l)&&this._shrinkXYByRadiusPerspective(_,u,l,s,o)){var f=Ne._tempVector33;f.x=c.x-_.x,f.y=c.y-_.y,f.z=c.z-_.z,n.normalize(f,f),this._shrinkSpotXYByConePerspective(_,f,u,m,l,s,o),this._placeSpotLightToClusters(a,l)}}_updatePointLightOrth(e,t,r,i,a,s,o){var l=Ne._tempLightBound,_=Ne._tempVector30;n.transformV3ToV3(s._transform.position,a,_),_.z*=-1,this._shrinkSphereLightByBoundOrth(e,t,r,i,_,s.range,l)&&this._placePointLightToClusters(o,l)}_updateSpotLightOrth(e,t,r,i,a,s,o){var l=Ne._tempLightBound,_=Ne._tempVector30,h=Ne._tempVector31,c=Ne._tempVector34,d=s._transform.position,u=s.range;s._transform.worldMatrix.getForward(h),n.normalize(h,h),n.scale(h,u,c),n.add(d,c,c),n.transformV3ToV3(d,a,_),n.transformV3ToV3(c,a,c),_.z*=-1,c.z*=-1;var m=s.spotAngle/2*Math.PI/180;this._shrinkSpotLightByBoundOrth(e,t,r,i,_,c,u,m,l)&&this._placeSpotLightToClusters(o,l)}update(e,t){this._updateMark++;var r=e.nearPlane;this._depthSliceParam.x=j._config.lightClusterCount.z/Math.log2(e.farPlane/r),this._depthSliceParam.y=Math.log2(r)*this._depthSliceParam.x;var i=e.nearPlane,a=e.farPlane,n=e.viewMatrix,s=t._directionLights._length,o=t._pointLights,l=o._length,_=o._elements,h=t._spotLights,c=h._length,d=h._elements;if(e.orthographic){for(var u=e.orthographicVerticalSize/2,m=u*e.aspectRatio,f=0;f<l;f++,s++)this._updatePointLightOrth(m,u,i,a,n,_[f],s);for(f=0;f<c;f++,s++)this._updateSpotLightOrth(m,u,i,a,n,d[f],s)}else{e._updateClusterPlaneXY();var T=e._clusterXPlanes,E=e._clusterYPlanes;for(f=0;f<l;f++,s++)this._updatePointLightPerspective(i,a,n,_[f],s,T,E);for(f=0;f<c;f++,s++)this._updateSpotLightPerspective(i,a,n,d[f],s,T,E)}if(l+c>0){for(var p=this._xSlices,g=this._ySlices,S=this._zSlices,R=p*g*4,v=R*S,x=this._clusterPixels,A=x.length,I=this._clusterDatas,M=this._updateMark,D=!0,C=0;C<S;C++)for(var y=0;y<g;y++)for(var L=0;L<p;L++){var O=I[C][y][L],N=4*(L+y*p+C*p*g);if(O.updateMark!==M)x[N]=0,x[N+1]=0;else if(D){var P=O.indices,b=O.pointLightCount,w=O.spotLightCount,V=b+w;if(v+V<A){x[N]=b,x[N+1]=w,x[N+2]=Math.floor(v/R),x[N+3]=v%R;for(f=0;f<V;f++)x[v++]=P[f]}else{V=A-(v+V),b=Math.min(b,V),x[N]=b,x[N+1]=Math.min(w,V-b),x[N+2]=Math.floor(v/R),x[N+3]=v%R;for(f=0;f<V;f++)x[v++]=P[f];D=!1}}}var B=this._clusterTexture.width;this._clusterTexture.setSubPixels(0,0,B,Math.ceil(v/(4*B)),x)}}}Ne._tempVector30=new n,Ne._tempVector31=new n,Ne._tempVector32=new n,Ne._tempVector33=new n,Ne._tempVector34=new n,Ne._tempVector35=new n,Ne._tempVector36=new n,Ne._tempVector37=new n,Ne._tempLightBound=new class{};class Pe{constructor(e,t=0){this.normal=e,this.distance=t}static createPlaneBy3P(e,t,r,i){var a=t.x-e.x,n=t.y-e.y,s=t.z-e.z,o=r.x-e.x,l=r.y-e.y,_=r.z-e.z,h=n*_-s*l,c=s*o-a*_,d=a*l-n*o,u=1/Math.sqrt(h*h+c*c+d*d),m=h*u,f=c*u,T=d*u,E=i.normal;E.x=m,E.y=f,E.z=T,i.distance=-(m*e.x+f*e.y+T*e.z)}normalize(){var e=this.normal.x,t=this.normal.y,r=this.normal.z,i=1/Math.sqrt(e*e+t*t+r*r);this.normal.x=e*i,this.normal.y=t*i,this.normal.z=r*i,this.distance*=i}cloneTo(e){var t=e;this.normal.cloneTo(t.normal),t.distance=this.distance}clone(){var e=new Pe(new n);return this.cloneTo(e),e}}Pe.PlaneIntersectionType_Back=0,Pe.PlaneIntersectionType_Front=1,Pe.PlaneIntersectionType_Intersecting=2;class be{constructor(e,t){this.origin=e,this.direction=t}}class we{}we.Disjoint=0,we.Contains=1,we.Intersects=2;class Ve{constructor(){}static distancePlaneToPoint(e,t){return n.dot(e.normal,t)-e.distance}static distanceBoxToPoint(e,t){var r=e.min,i=r.x,a=r.y,n=r.z,s=e.max,o=s.x,l=s.y,_=s.z,h=t.x,c=t.y,d=t.z,u=0;return h<i&&(u+=(i-h)*(i-h)),h>o&&(u+=(o-h)*(o-h)),c<a&&(u+=(a-c)*(a-c)),c>l&&(u+=(l-c)*(l-c)),d<n&&(u+=(n-d)*(n-d)),d>_&&(u+=(_-d)*(_-d)),Math.sqrt(u)}static distanceBoxToBox(e,t){var r,i=e.min,a=i.x,n=i.y,s=i.z,o=e.max,l=o.x,_=o.y,h=o.z,c=t.min,d=c.x,u=c.y,m=c.z,f=t.max,T=f.x,E=f.y,p=f.z,g=0;return a>T?g+=(r=a-T)*r:d>l&&(g+=(r=d-l)*r),n>E?g+=(r=n-E)*r:u>_&&(g+=(r=u-_)*r),s>p?g+=(r=s-p)*r:m>h&&(g+=(r=m-h)*r),Math.sqrt(g)}static distanceSphereToPoint(e,t){var r=Math.sqrt(n.distanceSquared(e.center,t));return r-=e.radius,Math.max(r,0)}static distanceSphereToSphere(e,t){var r=Math.sqrt(n.distanceSquared(e.center,t.center));return r-=e.radius+t.radius,Math.max(r,0)}static intersectsRayAndTriangleRD(e,t,i,a,n){var s=e.origin,o=s.x,l=s.y,_=s.z,h=e.direction,c=h.x,d=h.y,u=h.z,m=t.x,f=t.y,T=t.z,E=i.x,p=i.y,g=i.z,S=a.x,R=a.y,v=a.z,x=Ve._tempV30.x,A=Ve._tempV30.y,I=Ve._tempV30.z;x=E-m,A=p-f,I=g-T;var M=Ve._tempV31.x,D=Ve._tempV31.y,C=Ve._tempV31.z;M=S-m,D=R-f,C=v-T;var y=Ve._tempV32.x,L=Ve._tempV32.y,O=Ve._tempV32.z,N=x*(y=d*C-u*D)+A*(L=u*M-c*C)+I*(O=c*D-d*M);if(r.isZero(N))return!1;var P=1/N,b=Ve._tempV33.x,w=Ve._tempV33.y,V=Ve._tempV33.z,B=(b=o-m)*y+(w=l-f)*L+(V=_-T)*O;if((B*=P)<0||B>1)return!1;var F=Ve._tempV34.x,U=Ve._tempV34.y,G=Ve._tempV34.z,z=c*(F=w*I-V*A)+d*(U=V*x-b*I)+u*(G=b*A-w*x);if((z*=P)<0||B+z>1)return!1;var H=M*F+D*U+C*G;return!((H*=P)<0)}static intersectsRayAndTriangleRP(e,t,r,i,a){return Ve.intersectsRayAndTriangleRD(e,t,r,i,void 0)?(n.scale(e.direction,void 0,Ve._tempV30),n.add(e.origin,Ve._tempV30,a),!0):(a=n._ZERO,!1)}static intersectsRayAndPoint(e,t){n.subtract(e.origin,t,Ve._tempV30);var i=n.dot(Ve._tempV30,e.direction),a=n.dot(Ve._tempV30,Ve._tempV30)-r.zeroTolerance;return!(a>0&&i>0)&&!(i*i-a<0)}static intersectsRayAndRay(e,t,i){var a=e.origin,s=a.x,o=a.y,l=a.z,_=e.direction,h=_.x,c=_.y,d=_.z,u=t.origin,m=u.x,f=u.y,T=u.z,E=t.direction,p=E.x,g=E.y,S=E.z;n.cross(_,E,Ve._tempV30);var R=Ve._tempV30,v=n.scalarLength(Ve._tempV30);if(r.isZero(v)&&r.nearEqual(m,s)&&r.nearEqual(f,o)&&r.nearEqual(T,l))return!0;v*=v;var x=m-s,A=f-o,I=T-l,M=p,D=g,C=S,y=R.x,L=R.y,O=R.z,N=x*D*O+A*C*y+I*M*L-x*C*L-A*M*O-I*D*y;M=h,D=c,C=d;var P=N/v;n.scale(_,P,Ve._tempV30),n.scale(E,P,Ve._tempV31),n.add(a,Ve._tempV30,Ve._tempV32),n.add(u,Ve._tempV31,Ve._tempV33);var b=Ve._tempV32,w=Ve._tempV33;return!!(r.nearEqual(w.x,b.x)&&r.nearEqual(w.y,b.y)&&r.nearEqual(w.z,b.z))}static intersectsPlaneAndTriangle(e,t,r,i){var a=Ve.intersectsPlaneAndPoint(e,t),n=Ve.intersectsPlaneAndPoint(e,r),s=Ve.intersectsPlaneAndPoint(e,i);return a==Pe.PlaneIntersectionType_Front&&n==Pe.PlaneIntersectionType_Front&&s==Pe.PlaneIntersectionType_Front?Pe.PlaneIntersectionType_Front:a==Pe.PlaneIntersectionType_Back&&n==Pe.PlaneIntersectionType_Back&&s==Pe.PlaneIntersectionType_Back?Pe.PlaneIntersectionType_Back:Pe.PlaneIntersectionType_Intersecting}static intersectsRayAndPlaneRD(e,t){var i=t.normal,a=n.dot(i,e.direction);if(Math.abs(a)<r.zeroTolerance)return-1;var s=n.dot(i,e.origin),o=(-t.distance-s)/a;if(o<0){if(o<-r.zeroTolerance)return-1;o=0}return o}static intersectsRayAndPlaneRP(e,t,r){var i=Ve.intersectsRayAndPlaneRD(e,t);if(-1==i)return r.setValue(0,0,0),!1;var a=Ve._tempV30;return n.scale(e.direction,i,a),n.add(e.origin,a,r),!0}static intersectsRayAndBoxRD(e,t){var i=e.origin,a=i.x,n=i.y,s=i.z,o=e.direction,l=o.x,_=o.y,h=o.z,c=t.min,d=c.x,u=c.y,m=c.z,f=t.max,T=f.x,E=f.y,p=f.z,g=0,S=r.MaxValue;if(r.isZero(l)){if(a<d||a>T)return-1}else{var R=1/l,v=(d-a)*R,x=(T-a)*R;if(v>x){var A=v;v=x,x=A}if((g=Math.max(v,g))>(S=Math.min(x,S)))return-1}if(r.isZero(_)){if(n<u||n>E)return-1}else{var I=1/_,M=(u-n)*I,D=(E-n)*I;if(M>D){var C=M;M=D,D=C}if((g=Math.max(M,g))>(S=Math.min(D,S)))return-1}if(r.isZero(h)){if(s<m||s>p)return-1}else{var y=1/h,L=(m-s)*y,O=(p-s)*y;if(L>O){var N=L;L=O,O=N}if((g=Math.max(L,g))>(S=Math.min(O,S)))return-1}return g}static intersectsRayAndBoxRP(e,t,r){var i=Ve.intersectsRayAndBoxRD(e,t);return-1===i?(n._ZERO.cloneTo(r),i):(n.scale(e.direction,i,Ve._tempV30),n.add(e.origin,Ve._tempV30,Ve._tempV31),Ve._tempV31.cloneTo(r),i)}static intersectsRayAndSphereRD(e,t){var r=t.radius;n.subtract(e.origin,t.center,Ve._tempV30);var i=n.dot(Ve._tempV30,e.direction),a=n.dot(Ve._tempV30,Ve._tempV30)-r*r;if(a>0&&i>0)return-1;var s=i*i-a;if(s<0)return-1;var o=-i-Math.sqrt(s);return o<0&&(o=0),o}static intersectsRayAndSphereRP(e,t,r){var i=Ve.intersectsRayAndSphereRD(e,t);return-1===i?(n._ZERO.cloneTo(r),i):(n.scale(e.direction,i,Ve._tempV30),n.add(e.origin,Ve._tempV30,Ve._tempV31),Ve._tempV31.cloneTo(r),i)}static intersectsSphereAndTriangle(e,t,r,i){var a=e.center,s=e.radius;return Ve.closestPointPointTriangle(a,t,r,i,Ve._tempV30),n.subtract(Ve._tempV30,a,Ve._tempV31),n.dot(Ve._tempV31,Ve._tempV31)<=s*s}static intersectsPlaneAndPoint(e,t){var r=n.dot(e.normal,t)+e.distance;return r>0?Pe.PlaneIntersectionType_Front:r<0?Pe.PlaneIntersectionType_Back:Pe.PlaneIntersectionType_Intersecting}static intersectsPlaneAndPlane(e,t){n.cross(e.normal,t.normal,Ve._tempV30);var i=n.dot(Ve._tempV30,Ve._tempV30);return!r.isZero(i)}static intersectsPlaneAndPlaneRL(e,t,i){var a=e.normal,s=t.normal;n.cross(a,s,Ve._tempV34);var o=n.dot(Ve._tempV34,Ve._tempV34);return!r.isZero(o)&&(n.scale(s,e.distance,Ve._tempV30),n.scale(a,t.distance,Ve._tempV31),n.subtract(Ve._tempV30,Ve._tempV31,Ve._tempV32),n.cross(Ve._tempV32,Ve._tempV34,Ve._tempV33),n.normalize(Ve._tempV34,Ve._tempV34),!0)}static intersectsPlaneAndBox(e,t){var r=e.distance,i=e.normal,a=i.x,s=i.y,o=i.z,l=t.min,_=l.x,h=l.y,c=l.z,d=t.max,u=d.x,m=d.y,f=d.z;Ve._tempV30.x=a>0?_:u,Ve._tempV30.y=s>0?h:m,Ve._tempV30.z=o>0?c:f,Ve._tempV31.x=a>0?u:_,Ve._tempV31.y=s>0?m:h,Ve._tempV31.z=o>0?f:c;var T=n.dot(i,Ve._tempV30);return T+r>0?Pe.PlaneIntersectionType_Front:(T=n.dot(i,Ve._tempV31))+r<0?Pe.PlaneIntersectionType_Back:Pe.PlaneIntersectionType_Intersecting}static intersectsPlaneAndSphere(e,t){var r=t.radius,i=n.dot(e.normal,t.center)+e.distance;return i>r?Pe.PlaneIntersectionType_Front:i<-r?Pe.PlaneIntersectionType_Back:Pe.PlaneIntersectionType_Intersecting}static intersectsBoxAndBox(e,t){var r=e.min,i=e.max,a=t.min,n=t.max;return!(r.x>n.x||a.x>i.x)&&(!(r.y>n.y||a.y>i.y)&&!(r.z>n.z||a.z>i.z))}static intersectsBoxAndSphere(e,t){var r=t.center,i=t.radius,a=Ve._tempV30;return n.Clamp(r,e.min,e.max,a),n.distanceSquared(r,a)<=i*i}static intersectsSphereAndSphere(e,t){var r=e.radius+t.radius;return n.distanceSquared(e.center,t.center)<=r*r}static boxContainsPoint(e,t){var r=e.min,i=e.max;return r.x<=t.x&&i.x>=t.x&&r.y<=t.y&&i.y>=t.y&&r.z<=t.z&&i.z>=t.z?we.Contains:we.Disjoint}static boxContainsBox(e,t){var r=e.min,i=r.x,a=r.y,n=r.z,s=e.max,o=s.x,l=s.y,_=s.z,h=t.min,c=h.x,d=h.y,u=h.z,m=t.max,f=m.x,T=m.y,E=m.z;return o<c||i>f||l<d||a>T||_<u||n>E?we.Disjoint:i<=c&&f<=o&&a<=d&&T<=l&&n<=u&&E<=_?we.Contains:we.Intersects}static boxContainsSphere(e,t){var r=e.min,i=r.x,a=r.y,s=r.z,o=e.max,l=o.x,_=o.y,h=o.z,c=t.center,d=c.x,u=c.y,m=c.z,f=t.radius;return n.Clamp(c,r,o,Ve._tempV30),n.distanceSquared(c,Ve._tempV30)>f*f?we.Disjoint:i+f<=d&&d<=l-f&&l-i>f&&a+f<=u&&u<=_-f&&_-a>f&&s+f<=m&&m<=h-f&&h-s>f?we.Contains:we.Intersects}static sphereContainsPoint(e,t){return n.distanceSquared(t,e.center)<=e.radius*e.radius?we.Contains:we.Disjoint}static sphereContainsTriangle(e,t,r,i){var a=Ve.sphereContainsPoint(e,t),n=Ve.sphereContainsPoint(e,r),s=Ve.sphereContainsPoint(e,i);return a==we.Contains&&n==we.Contains&&s==we.Contains?we.Contains:Ve.intersectsSphereAndTriangle(e,t,r,i)?we.Intersects:we.Disjoint}static sphereContainsBox(e,t){var r=e.center,i=r.x,a=r.y,s=r.z,o=e.radius,l=t.min,_=l.x,h=l.y,c=l.z,d=t.max,u=d.x,m=d.y,f=d.z,T=Ve._tempV30;T.x,T.y,T.z;if(!Ve.intersectsBoxAndSphere(t,e))return we.Disjoint;var E=o*o;return i-_,a-m,s-f,n.scalarLengthSquared(Ve._tempV30)>E?we.Intersects:(i-u,a-m,s-f,n.scalarLengthSquared(Ve._tempV30)>E?we.Intersects:(i-u,a-h,s-f,n.scalarLengthSquared(Ve._tempV30)>E?we.Intersects:(i-_,a-h,s-f,n.scalarLengthSquared(Ve._tempV30)>E?we.Intersects:(i-_,a-m,s-c,n.scalarLengthSquared(Ve._tempV30)>E?we.Intersects:(i-u,a-m,s-c,n.scalarLengthSquared(Ve._tempV30)>E?we.Intersects:(i-u,a-h,s-c,n.scalarLengthSquared(Ve._tempV30)>E?we.Intersects:(i-_,a-h,s-c,n.scalarLengthSquared(Ve._tempV30)>E?we.Intersects:we.Contains)))))))}static sphereContainsSphere(e,t){var r=e.radius,i=t.radius,a=n.distance(e.center,t.center);return r+i<a?we.Disjoint:r-i<a?we.Intersects:we.Contains}static closestPointPointTriangle(e,t,r,i,a){n.subtract(r,t,Ve._tempV30),n.subtract(i,t,Ve._tempV31),n.subtract(e,t,Ve._tempV32),n.subtract(e,r,Ve._tempV33),n.subtract(e,i,Ve._tempV34);var s=n.dot(Ve._tempV30,Ve._tempV32),o=n.dot(Ve._tempV31,Ve._tempV32),l=n.dot(Ve._tempV30,Ve._tempV33),_=n.dot(Ve._tempV31,Ve._tempV33),h=n.dot(Ve._tempV30,Ve._tempV34),c=n.dot(Ve._tempV31,Ve._tempV34);if(s<=0&&o<=0)t.cloneTo(a);else if(l>=0&&_<=l)r.cloneTo(a);else{var d=s*_-l*o;if(d<=0&&s>=0&&l<=0){var u=s/(s-l);return n.scale(Ve._tempV30,u,a),void n.add(t,a,a)}if(c>=0&&h<=c)i.cloneTo(a);else{var m=h*o-s*c;if(m<=0&&o>=0&&c<=0){var f=o/(o-c);return n.scale(Ve._tempV31,f,a),void n.add(t,a,a)}var T=l*c-h*_;if(T<=0&&_-l>=0&&h-c>=0){var E=(_-l)/(_-l+(h-c));return n.subtract(i,r,a),n.scale(a,E,a),void n.add(r,a,a)}var p=1/(T+m+d),g=m*p,S=d*p;n.scale(Ve._tempV30,g,Ve._tempV35),n.scale(Ve._tempV31,S,Ve._tempV36),n.add(Ve._tempV35,Ve._tempV36,a),n.add(t,a,a)}}}static closestPointPlanePoint(e,t,r){var i=e.normal,a=n.dot(i,t)-e.distance;n.scale(i,a,Ve._tempV30),n.subtract(t,Ve._tempV30,r)}static closestPointBoxPoint(e,t,r){n.max(t,e.min,Ve._tempV30),n.min(Ve._tempV30,e.max,r)}static closestPointSpherePoint(e,t,r){var i=e.center;n.subtract(t,i,r),n.normalize(r,r),n.scale(r,e.radius,r),n.add(r,i,r)}static closestPointSphereSphere(e,t,r){var i=e.center;n.subtract(t.center,i,r),n.normalize(r,r),n.scale(r,e.radius,r),n.add(r,i,r)}}Ve._tempV30=new n,Ve._tempV31=new n,Ve._tempV32=new n,Ve._tempV33=new n,Ve._tempV34=new n,Ve._tempV35=new n,Ve._tempV36=new n,(l=e.FrustumCorner||(e.FrustumCorner={}))[l.FarBottomLeft=0]="FarBottomLeft",l[l.FarTopLeft=1]="FarTopLeft",l[l.FarTopRight=2]="FarTopRight",l[l.FarBottomRight=3]="FarBottomRight",l[l.nearBottomLeft=4]="nearBottomLeft",l[l.nearTopLeft=5]="nearTopLeft",l[l.nearTopRight=6]="nearTopRight",l[l.nearBottomRight=7]="nearBottomRight",l[l.unknown=8]="unknown";class Be{constructor(e){this._matrix=e,this._near=new Pe(new n),this._far=new Pe(new n),this._left=new Pe(new n),this._right=new Pe(new n),this._top=new Pe(new n),this._bottom=new Pe(new n),Be.getPlanesFromMatrix(this._matrix,this._near,this._far,this._left,this._right,this._top,this._bottom)}static getPlanesFromMatrix(e,t,r,i,a,n,s){var o=e.elements,l=o[0],_=o[1],h=o[2],c=o[3],d=o[4],u=o[5],m=o[6],f=o[7],T=o[8],E=o[9],p=o[10],g=o[11],S=o[12],R=o[13],v=o[14],x=o[15],A=t.normal;A.x=h,A.y=m,A.z=p,t.distance=v,t.normalize();var I=r.normal;I.x=c-h,I.y=f-m,I.z=g-p,r.distance=x-v,r.normalize();var M=i.normal;M.x=c+l,M.y=f+d,M.z=g+T,i.distance=x+S,i.normalize();var D=a.normal;D.x=c-l,D.y=f-d,D.z=g-T,a.distance=x-S,a.normalize();var C=n.normal;C.x=c-_,C.y=f-u,C.z=g-E,n.distance=x-R,n.normalize();var y=s.normal;y.x=c+_,y.y=f+u,y.z=g+E,s.distance=x+R,s.normalize()}get matrix(){return this._matrix}set matrix(e){e.cloneTo(this._matrix),Be.getPlanesFromMatrix(this._matrix,this._near,this._far,this._left,this._right,this._top,this._bottom)}get near(){return this._near}get far(){return this._far}get left(){return this._left}get right(){return this._right}get top(){return this._top}get bottom(){return this._bottom}equalsBoundFrustum(e){return this._matrix.equalsOtherMatrix(e.matrix)}equalsObj(e){if(e instanceof Be){var t=e;return this.equalsBoundFrustum(t)}return!1}getPlane(e){switch(e){case 0:return this._near;case 1:return this._far;case 2:return this._left;case 3:return this._right;case 4:return this._top;case 5:return this._bottom;default:return null}}static get3PlaneInterPoint(e,t,r,i){var a=e.normal,s=t.normal,o=r.normal;n.cross(s,o,Be._tempV30),n.cross(o,a,Be._tempV31),n.cross(a,s,Be._tempV32);var l=n.dot(a,Be._tempV30),_=n.dot(s,Be._tempV31),h=n.dot(o,Be._tempV32);n.scale(Be._tempV30,-e.distance/l,Be._tempV33),n.scale(Be._tempV31,-t.distance/_,Be._tempV34),n.scale(Be._tempV32,-r.distance/h,Be._tempV35),n.add(Be._tempV33,Be._tempV34,Be._tempV36),n.add(Be._tempV35,Be._tempV36,i)}getCorners(t){Be.get3PlaneInterPoint(this._near,this._bottom,this._right,t[e.FrustumCorner.nearBottomRight]),Be.get3PlaneInterPoint(this._near,this._top,this._right,t[e.FrustumCorner.nearTopRight]),Be.get3PlaneInterPoint(this._near,this._top,this._left,t[e.FrustumCorner.nearTopLeft]),Be.get3PlaneInterPoint(this._near,this._bottom,this._left,t[e.FrustumCorner.nearBottomLeft]),Be.get3PlaneInterPoint(this._far,this._bottom,this._right,t[e.FrustumCorner.FarBottomRight]),Be.get3PlaneInterPoint(this._far,this._top,this._right,t[e.FrustumCorner.FarTopRight]),Be.get3PlaneInterPoint(this._far,this._top,this._left,t[e.FrustumCorner.FarTopLeft]),Be.get3PlaneInterPoint(this._far,this._bottom,this._left,t[e.FrustumCorner.FarBottomLeft])}containsPoint(e){for(var t=Pe.PlaneIntersectionType_Front,r=Pe.PlaneIntersectionType_Front,i=0;i<6;i++){switch(i){case 0:r=Ve.intersectsPlaneAndPoint(this._near,e);break;case 1:r=Ve.intersectsPlaneAndPoint(this._far,e);break;case 2:r=Ve.intersectsPlaneAndPoint(this._left,e);break;case 3:r=Ve.intersectsPlaneAndPoint(this._right,e);break;case 4:r=Ve.intersectsPlaneAndPoint(this._top,e);break;case 5:r=Ve.intersectsPlaneAndPoint(this._bottom,e)}switch(r){case Pe.PlaneIntersectionType_Back:return we.Disjoint;case Pe.PlaneIntersectionType_Intersecting:t=Pe.PlaneIntersectionType_Intersecting}}switch(t){case Pe.PlaneIntersectionType_Intersecting:return we.Intersects;default:return we.Contains}}intersects(e){var t=e.min,r=e.max,i=t.x,a=t.y,n=t.z,s=r.x,o=r.y,l=r.z,_=this._near.normal;if(this._near.distance+_.x*(_.x<0?i:s)+_.y*(_.y<0?a:o)+_.z*(_.z<0?n:l)<0)return!1;var h=this._left.normal;if(this._left.distance+h.x*(h.x<0?i:s)+h.y*(h.y<0?a:o)+h.z*(h.z<0?n:l)<0)return!1;var c=this._right.normal;if(this._right.distance+c.x*(c.x<0?i:s)+c.y*(c.y<0?a:o)+c.z*(c.z<0?n:l)<0)return!1;var d=this._bottom.normal;if(this._bottom.distance+d.x*(d.x<0?i:s)+d.y*(d.y<0?a:o)+d.z*(d.z<0?n:l)<0)return!1;var u=this._top.normal;if(this._top.distance+u.x*(u.x<0?i:s)+u.y*(u.y<0?a:o)+u.z*(u.z<0?n:l)<0)return!1;var m=this._far.normal;return!(this._far.distance+m.x*(m.x<0?i:s)+m.y*(m.y<0?a:o)+m.z*(m.z<0?n:l)<0)}containsBoundBox(e){for(var t=Be._tempV30,r=Be._tempV31,i=e.min,a=e.max,n=we.Contains,s=0;s<6;s++){var o=this.getPlane(s),l=o.normal;if(l.x>=0?(t.x=a.x,r.x=i.x):(t.x=i.x,r.x=a.x),l.y>=0?(t.y=a.y,r.y=i.y):(t.y=i.y,r.y=a.y),l.z>=0?(t.z=a.z,r.z=i.z):(t.z=i.z,r.z=a.z),Ve.intersectsPlaneAndPoint(o,t)===Pe.PlaneIntersectionType_Back)return we.Disjoint;Ve.intersectsPlaneAndPoint(o,r)===Pe.PlaneIntersectionType_Back&&(n=we.Intersects)}return n}containsBoundSphere(e){for(var t=Pe.PlaneIntersectionType_Front,r=Pe.PlaneIntersectionType_Front,i=0;i<6;i++){switch(i){case 0:r=Ve.intersectsPlaneAndSphere(this._near,e);break;case 1:r=Ve.intersectsPlaneAndSphere(this._far,e);break;case 2:r=Ve.intersectsPlaneAndSphere(this._left,e);break;case 3:r=Ve.intersectsPlaneAndSphere(this._right,e);break;case 4:r=Ve.intersectsPlaneAndSphere(this._top,e);break;case 5:r=Ve.intersectsPlaneAndSphere(this._bottom,e)}switch(r){case Pe.PlaneIntersectionType_Back:return we.Disjoint;case Pe.PlaneIntersectionType_Intersecting:t=Pe.PlaneIntersectionType_Intersecting}}switch(t){case Pe.PlaneIntersectionType_Intersecting:return we.Intersects;default:return we.Contains}}}Be._tempV30=new n,Be._tempV31=new n,Be._tempV32=new n,Be._tempV33=new n,Be._tempV34=new n,Be._tempV35=new n,Be._tempV36=new n;class Fe{constructor(e,t,r,i){this.minDepth=0,this.maxDepth=1,this.x=e,this.y=t,this.width=r,this.height=i}project(e,t,r){n.transformV3ToV4(e,t,r);var i=r.x,a=r.y,s=r.z,o=r.w;1!==o&&(i/=o,a/=o,s/=o),r.x=.5*(i+1)*this.width+this.x,r.y=.5*(1-a)*this.height+this.y,r.z=s*(this.maxDepth-this.minDepth)+this.minDepth}unprojectFromMat(e,t,r){var i=t.elements;r.x=(e.x-this.x)/this.width*2-1,r.y=-((e.y-this.y)/this.height*2-1),r.z=(e.z-this.minDepth)/(this.maxDepth-this.minDepth);var a=r.x*i[3]+r.y*i[7]+r.z*i[11]+i[15];n.transformV3ToV3(r,t,r),1!==a&&(r.x=r.x/a,r.y=r.y/a,r.z=r.z/a)}unprojectFromWVP(e,t,r,i,a){R.multiply(t,r,Fe._tempMatrix4x4),i&&R.multiply(Fe._tempMatrix4x4,i,Fe._tempMatrix4x4),Fe._tempMatrix4x4.invert(Fe._tempMatrix4x4),this.unprojectFromMat(e,Fe._tempMatrix4x4,a)}cloneTo(e){e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e.minDepth=this.minDepth,e.maxDepth=this.maxDepth}}Fe._tempMatrix4x4=new R;class Ue{constructor(){}static calculateCursorRay(e,t,r,i,a,s){var o=e.x,l=e.y,_=Ue._tempVector30,h=_;h.x=o,h.y=l,h.z=t.minDepth;var c=Ue._tempVector31,d=c;d.x=o,d.y=l,d.z=t.maxDepth;var u=s.origin,m=Ue._tempVector32;t.unprojectFromWVP(_,r,i,a,u),t.unprojectFromWVP(c,r,i,a,m);var f=s.direction;f.x=m.x-u.x,f.y=m.y-u.y,f.z=m.z-u.z,n.normalize(s.direction,s.direction)}static rayIntersectsTriangle(e,t,r,i){var a=Ue._tempVector30,s=Ue._tempVector31;n.subtract(r,t,a),n.subtract(i,t,s);var o,l=Ue._tempVector32;if(n.cross(e.direction,s,l),(o=n.dot(a,l))>-Number.MIN_VALUE&&o<Number.MIN_VALUE)return Number.NaN;var _,h=1/o,c=Ue._tempVector33;if(n.subtract(e.origin,t,c),_=n.dot(c,l),(_*=h)<0||_>1)return Number.NaN;var d,u,m=Ue._tempVector34;return n.cross(c,a,m),d=n.dot(e.direction,m),(d*=h)<0||_+d>1?Number.NaN:(u=n.dot(s,m),(u*=h)<0?Number.NaN:u)}}Ue._tempVector30=new n,Ue._tempVector31=new n,Ue._tempVector32=new n,Ue._tempVector33=new n,Ue._tempVector34=new n,(_=e.IndexFormat||(e.IndexFormat={}))[_.UInt8=0]="UInt8",_[_.UInt16=1]="UInt16",_[_.UInt32=2]="UInt32";class Ge extends t.Buffer{constructor(r,i,a=35044,n=!1){switch(super(),this._indexType=r,this._indexCount=i,this._bufferUsage=a,this._bufferType=t.LayaGL.instance.ELEMENT_ARRAY_BUFFER,this._canRead=n,r){case e.IndexFormat.UInt32:this._indexTypeByteCount=4;break;case e.IndexFormat.UInt16:this._indexTypeByteCount=2;break;case e.IndexFormat.UInt8:this._indexTypeByteCount=1;break;default:throw new Error("unidentification index type.")}var s=this._indexTypeByteCount*i,o=t.BufferStateBase._curBindedBufferState;if(this._byteLength=s,o?o._bindedIndexBuffer===this?t.LayaGL.instance.bufferData(this._bufferType,s,this._bufferUsage):(o.unBind(),this.bind(),t.LayaGL.instance.bufferData(this._bufferType,s,this._bufferUsage),o.bind()):(this.bind(),t.LayaGL.instance.bufferData(this._bufferType,s,this._bufferUsage)),n)switch(r){case e.IndexFormat.UInt32:this._buffer=new Uint32Array(i);break;case e.IndexFormat.UInt16:this._buffer=new Uint16Array(i);break;case e.IndexFormat.UInt8:this._buffer=new Uint8Array(i)}}get indexType(){return this._indexType}get indexTypeByteCount(){return this._indexTypeByteCount}get indexCount(){return this._indexCount}get canRead(){return this._canRead}_bindForVAO(){if(!t.BufferStateBase._curBindedBufferState)throw"IndexBuffer3D: must bind current BufferState.";var e=t.LayaGL.instance;e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this._glBuffer)}bind(){if(t.BufferStateBase._curBindedBufferState)throw"IndexBuffer3D: must unbind current BufferState.";if(t.Buffer._bindedIndexBuffer!==this._glBuffer){var e=t.LayaGL.instance;return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this._glBuffer),t.Buffer._bindedIndexBuffer=this._glBuffer,!0}return!1}setData(r,i=0,a=0,n=4294967295){var s=this._indexTypeByteCount;if(0!==a||4294967295!==n)switch(this._indexType){case e.IndexFormat.UInt32:r=new Uint32Array(r.buffer,a*s,n);break;case e.IndexFormat.UInt16:r=new Uint16Array(r.buffer,a*s,n);break;case e.IndexFormat.UInt8:r=new Uint8Array(r.buffer,a*s,n)}var o=t.BufferStateBase._curBindedBufferState;if(o?o._bindedIndexBuffer===this?t.LayaGL.instance.bufferSubData(this._bufferType,i*s,r):(o.unBind(),this.bind(),t.LayaGL.instance.bufferSubData(this._bufferType,i*s,r),o.bind()):(this.bind(),t.LayaGL.instance.bufferSubData(this._bufferType,i*s,r)),this._canRead)if(0!==i||0!==a||4294967295!==n){var l=this._buffer.length-i;n>l&&(n=l);for(var _=0;_<n;_++)this._buffer[i+_]=r[_]}else this._buffer=r}getData(){if(this._canRead)return this._buffer;throw new Error("Can't read data from VertexBuffer with only write flag!")}destroy(){super.destroy(),this._buffer=null,this._byteLength=0,this._indexCount=0}}class ze{static __init__(){ze.instanceWorldMatrixDeclaration=new fe(64,[new Te(0,ue.Vector4,ze.MESH_WORLDMATRIX_ROW0),new Te(16,ue.Vector4,ze.MESH_WORLDMATRIX_ROW1),new Te(32,ue.Vector4,ze.MESH_WORLDMATRIX_ROW2),new Te(48,ue.Vector4,ze.MESH_WORLDMATRIX_ROW3)]),ze.instanceMVPMatrixDeclaration=new fe(64,[new Te(0,ue.Vector4,ze.MESH_MVPMATRIX_ROW0),new Te(16,ue.Vector4,ze.MESH_MVPMATRIX_ROW1),new Te(32,ue.Vector4,ze.MESH_MVPMATRIX_ROW2),new Te(48,ue.Vector4,ze.MESH_MVPMATRIX_ROW3)]),ze.instanceSimpleAnimatorDeclaration=new fe(16,[new Te(0,ue.Vector4,ze.MESH_SIMPLEANIMATOR)])}static getVertexDeclaration(e,t=!0){var r=ze._vertexDeclarationMap[e+(t?"_0":"_1")];if(!r){for(var i=e.split(","),a=0,n=[],s=0,o=i.length;s<o;s++){var l;switch(i[s]){case"POSITION":l=new Te(a,ue.Vector3,ze.MESH_POSITION0),a+=12;break;case"NORMAL":l=new Te(a,ue.Vector3,ze.MESH_NORMAL0),a+=12;break;case"COLOR":l=new Te(a,ue.Vector4,ze.MESH_COLOR0),a+=16;break;case"UV":l=new Te(a,ue.Vector2,ze.MESH_TEXTURECOORDINATE0),a+=8;break;case"UV1":l=new Te(a,ue.Vector2,ze.MESH_TEXTURECOORDINATE1),a+=8;break;case"BLENDWEIGHT":l=new Te(a,ue.Vector4,ze.MESH_BLENDWEIGHT0),a+=16;break;case"BLENDINDICES":t?(l=new Te(a,ue.Vector4,ze.MESH_BLENDINDICES0),a+=16):(l=new Te(a,ue.Byte4,ze.MESH_BLENDINDICES0),a+=4);break;case"TANGENT":l=new Te(a,ue.Vector4,ze.MESH_TANGENT0),a+=16;break;default:throw"VertexMesh: unknown vertex flag."}n.push(l)}r=new fe(a,n),ze._vertexDeclarationMap[e+(t?"_0":"_1")]=r}return r}}ze.MESH_POSITION0=0,ze.MESH_COLOR0=1,ze.MESH_TEXTURECOORDINATE0=2,ze.MESH_NORMAL0=3,ze.MESH_TANGENT0=4,ze.MESH_BLENDINDICES0=5,ze.MESH_BLENDWEIGHT0=6,ze.MESH_TEXTURECOORDINATE1=7,ze.MESH_WORLDMATRIX_ROW0=8,ze.MESH_WORLDMATRIX_ROW1=9,ze.MESH_WORLDMATRIX_ROW2=10,ze.MESH_WORLDMATRIX_ROW3=11,ze.MESH_MVPMATRIX_ROW0=12,ze.MESH_MVPMATRIX_ROW1=13,ze.MESH_MVPMATRIX_ROW2=14,ze.MESH_MVPMATRIX_ROW3=15,ze.MESH_SIMPLEANIMATOR=7,ze._vertexDeclarationMap={};class He{constructor(){}_render(e){}}class ke extends He{constructor(){super();var r=t.LayaGL.instance,i=new Float32Array([-1,1,-1,1,1,-1,1,1,1,-1,1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1]),a=new Uint8Array([0,1,2,2,3,0,4,7,6,6,5,4,0,3,7,7,4,0,1,5,6,6,2,1,3,2,6,6,7,3,0,4,5,5,1,0]),n=ze.getVertexDeclaration("POSITION");this._vertexBuffer=new de(8*n.vertexStride,r.STATIC_DRAW,!1),this._vertexBuffer.vertexDeclaration=n,this._indexBuffer=new Ge(e.IndexFormat.UInt8,36,r.STATIC_DRAW,!1),this._vertexBuffer.setData(i.buffer),this._indexBuffer.setData(a);var s=new Ee;s.bind(),s.applyVertexBuffer(this._vertexBuffer),s.applyIndexBuffer(this._indexBuffer),s.unBind(),this._bufferState=s}static __init__(){ke.instance=new ke}_render(e){var r=t.LayaGL.instance;r.drawElements(r.TRIANGLES,36,r.UNSIGNED_BYTE,0),t.Stat.trianglesFaces+=12,t.Stat.renderBatches++}}class We{constructor(){this._mesh=ke.instance}get material(){return this._material}set material(e){this._material!==e&&(this._material&&this._material._removeReference(),e&&e._addReference(),this._material=e)}get mesh(){return this._mesh}set mesh(e){this._mesh!==e&&(this._mesh=e)}_isAvailable(){return!(!this._material||!this._mesh)}_render(e){if(this._material&&this._mesh){var r=t.LayaGL.instance,i=e.scene,a=e.cameraShaderValue,s=e.camera,o=me._SET_RUNTIME_VALUE_MODE_REFERENCE_;t.ILaya.Render.supportWebGLPlusRendering&&me.setRuntimeValueMode(!1),t.WebGLContext.setCullFace(r,!1),t.WebGLContext.setDepthFunc(r,r.LEQUAL),t.WebGLContext.setDepthMask(r,!1);var l=We._compileDefine;this._material._shaderValues._defineDatas.cloneTo(l);var _=e.shader=this._material._shader.getSubShaderAt(0)._passes[0].withCompile(l),h=_.bind(),c=t.Stat.loopCount!==_._uploadMark,d=_._uploadScene!==i||c;(d||h)&&(_.uploadUniforms(_._sceneUniformParamsMap,i._shaderValues,d),_._uploadScene=i);s._getRenderTexture();var u=_._uploadCameraShaderValue!==a||c;if(u||h){var m=We._tempMatrix0,f=We._tempMatrix1;s.viewMatrix.cloneTo(m),s.projectionMatrix.cloneTo(f),m.setTranslationVector(n._ZERO),s.orthographic&&R.createPerspective(s.fieldOfView,s.aspectRatio,s.nearPlane,s.farPlane,f);var T=1/Math.tan(3.1416*s.fieldOfView/180*.5);f.elements[0]=T/s.aspectRatio,f.elements[5]=T,f.elements[10]=-.999999,f.elements[11]=-1,f.elements[14]=-0,s._applyViewProject(e,m,f),_.uploadUniforms(_._cameraUniformParamsMap,a,u),_._uploadCameraShaderValue=a}var E=_._uploadMaterial!==this._material||c;(E||h)&&(_.uploadUniforms(_._materialUniformParamsMap,this._material._shaderValues,E),_._uploadMaterial=this._material),this._mesh._bufferState.bind(),this._mesh._render(e),t.ILaya.Render.supportWebGLPlusRendering&&me.setRuntimeValueMode(o),t.WebGLContext.setDepthFunc(r,r.LESS),t.WebGLContext.setDepthMask(r,!0),s._applyViewProject(e,s.viewMatrix,s.projectionMatrix)}}destroy(){this._material&&(this._material._removeReference(),this._material=null)}}We._tempMatrix0=new R,We._tempMatrix1=new R,We._compileDefine=new ce;class Xe extends Ce{constructor(e=.3,t=1e3){super(),this._skyRenderer=new We,this._forward=new n,this._up=new n,this.clearColor=new a(100/255,149/255,237/255,1),this._shaderValues=new me(null),this._fieldOfView=60,this._useUserProjectionMatrix=!1,this._orthographic=!1,this._orthographicVerticalSize=10,this.renderingOrder=0,this._nearPlane=e,this._farPlane=t,this.cullingMask=2147483647,this.useOcclusionCulling=!0}get skyRenderer(){return this._skyRenderer}get fieldOfView(){return this._fieldOfView}set fieldOfView(e){this._fieldOfView=e,this._calculateProjectionMatrix()}get nearPlane(){return this._nearPlane}set nearPlane(e){this._nearPlane=e,this._calculateProjectionMatrix()}get farPlane(){return this._farPlane}set farPlane(e){this._farPlane=e,this._calculateProjectionMatrix()}get orthographic(){return this._orthographic}set orthographic(e){this._orthographic=e,this._calculateProjectionMatrix()}get orthographicVerticalSize(){return this._orthographicVerticalSize}set orthographicVerticalSize(e){this._orthographicVerticalSize=e,this._calculateProjectionMatrix()}get renderingOrder(){return this._renderingOrder}set renderingOrder(e){this._renderingOrder=e,this._sortCamerasByRenderingOrder()}_sortCamerasByRenderingOrder(){if(this.displayedInStage)for(var e=this.scene._cameraPool,t=e.length-1,r=0;r<t;r++)if(e[r].renderingOrder>e[t].renderingOrder){var i=e[r];e[r]=e[t],e[t]=i}}_calculateProjectionMatrix(){}_onScreenSizeChanged(){this._calculateProjectionMatrix()}_prepareCameraToRender(){var e=this._shaderValues;this.transform.getForward(this._forward),this.transform.getUp(this._up),e.setVector3(Xe.CAMERAPOS,this.transform.position),e.setVector3(Xe.CAMERADIRECTION,this._forward),e.setVector3(Xe.CAMERAUP,this._up)}render(e=null,t=null){}addLayer(e){this.cullingMask|=Math.pow(2,e)}removeLayer(e){this.cullingMask&=~Math.pow(2,e)}addAllLayers(){this.cullingMask=2147483647}removeAllLayers(){this.cullingMask=0}resetProjectionMatrix(){this._useUserProjectionMatrix=!1,this._calculateProjectionMatrix()}_onActive(){this._scene._addCamera(this),super._onActive()}_onInActive(){this._scene._removeCamera(this),super._onInActive()}_parse(e,r){super._parse(e,r),this.orthographic=e.orthographic,void 0!==e.orthographicVerticalSize&&(this.orthographicVerticalSize=e.orthographicVerticalSize),void 0!==e.fieldOfView&&(this.fieldOfView=e.fieldOfView),this.nearPlane=e.nearPlane,this.farPlane=e.farPlane;var i=e.clearColor;this.clearColor=new a(i[0],i[1],i[2],i[3]);var n=e.skyboxMaterial;n&&(this._skyRenderer.material=t.Loader.getRes(n.path))}destroy(e=!0){this._skyRenderer.destroy(),this._skyRenderer=null,t.Laya.stage.off(t.Event.RESIZE,this,this._onScreenSizeChanged),super.destroy(e)}_create(){return new Xe}}Xe._tempMatrix4x40=new R,Xe.CAMERAPOS=xe.propertyNameToID("u_CameraPos"),Xe.VIEWMATRIX=xe.propertyNameToID("u_View"),Xe.PROJECTMATRIX=xe.propertyNameToID("u_Projection"),Xe.VIEWPROJECTMATRIX=xe.propertyNameToID("u_ViewProjection"),Xe.CAMERADIRECTION=xe.propertyNameToID("u_CameraDirection"),Xe.CAMERAUP=xe.propertyNameToID("u_CameraUp"),Xe.VIEWPORT=xe.propertyNameToID("u_Viewport"),Xe.PROJECTION_PARAMS=xe.propertyNameToID("u_ProjectionParams"),Xe.DEPTHTEXTURE=xe.propertyNameToID("u_CameraDepthTexture"),Xe.DEPTHNORMALSTEXTURE=xe.propertyNameToID("u_CameraDepthNormalsTexture"),Xe.DEPTHZBUFFERPARAMS=xe.propertyNameToID("u_ZBufferParams"),Xe.SHADERDEFINE_DEPTH=xe.getDefineByName("DEPTHMAP"),Xe.SHADERDEFINE_DEPTHNORMALS=xe.getDefineByName("DEPTHNORMALSMAP"),Xe.RENDERINGTYPE_DEFERREDLIGHTING="DEFERREDLIGHTING",Xe.RENDERINGTYPE_FORWARDRENDERING="FORWARDRENDERING",Xe._invertYScaleMatrix=new R(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1),Xe._invertYProjectionMatrix=new R,Xe._invertYProjectionViewMatrix=new R,Xe.CLEARFLAG_SOLIDCOLOR=0,Xe.CLEARFLAG_SKY=1,Xe.CLEARFLAG_DEPTHONLY=2,Xe.CLEARFLAG_NONE=3,(h=e.ShadowMode||(e.ShadowMode={}))[h.None=0]="None",h[h.Hard=1]="Hard",h[h.SoftLow=2]="SoftLow",h[h.SoftHigh=3]="SoftHigh";class Ye{}(c=e.LightType||(e.LightType={}))[c.Directional=0]="Directional",c[c.Spot=1]="Spot",c[c.Point=2]="Point";class je extends Ce{constructor(){super(),this._shadowMode=e.ShadowMode.None,this._isAlternate=!1,this._shadowResolution=2048,this._shadowDistance=50,this._shadowDepthBias=1,this._shadowNormalBias=1,this._shadowNearPlane=.1,this._shadowStrength=1,this._lightWoldMatrix=new R,this._intensity=1,this._intensityColor=new n,this.color=new n(1,1,1),this._lightmapBakedType=je.LIGHTMAPBAKEDTYPE_REALTIME}get intensity(){return this._intensity}set intensity(e){this._intensity=e}get shadowMode(){return this._shadowMode}set shadowMode(e){this._shadowMode=e}get shadowDistance(){return this._shadowDistance}set shadowDistance(e){this._shadowDistance=e}get shadowResolution(){return this._shadowResolution}set shadowResolution(e){this._shadowResolution=e}get shadowDepthBias(){return this._shadowDepthBias}set shadowDepthBias(e){this._shadowDepthBias=e}get shadowNormalBias(){return this._shadowNormalBias}set shadowNormalBias(e){this._shadowNormalBias=e}get shadowStrength(){return this._shadowStrength}set shadowStrength(e){this._shadowStrength=e}get shadowNearPlane(){return this._shadowNearPlane}set shadowNearPlane(e){this._shadowNearPlane=e}get lightmapBakedType(){return this._lightmapBakedType}set lightmapBakedType(e){this._lightmapBakedType!==e&&(this._lightmapBakedType=e,this.activeInHierarchy&&(e!==je.LIGHTMAPBAKEDTYPE_BAKED?this._addToScene():this._removeFromScene()))}get lightWorldMatrix(){var e=this.transform.position,t=this.transform.rotation;return R.createAffineTransformation(e,t,n._ONE,this._lightWoldMatrix),this._lightWoldMatrix}_parse(e,t){super._parse(e,t);var r=e.color;this.color.fromArray(r),this.intensity=e.intensity,this.lightmapBakedType=e.lightmapBakedType}_cloneTo(e,t,r){super._cloneTo(e,t,r);var i=e;i.color=this.color.clone(),i.intensity=this.intensity,i.lightmapBakedType=this.lightmapBakedType}_addToScene(){var e=this._scene,t=j._config.maxLightCount;e._lightCount<t?(e._lightCount++,this._addToLightQueue(),this._isAlternate=!1):(e._alternateLights.add(this),this._isAlternate=!0,console.warn("LightSprite:light count has large than maxLightCount,the latest added light will be ignore."))}_removeFromScene(){var e=this._scene;if(this._isAlternate)e._alternateLights.remove(this);else if(e._lightCount--,this._removeFromLightQueue(),e._alternateLights._length>0){var t=e._alternateLights.shift();t._addToLightQueue(),t._isAlternate=!1,e._lightCount++}}_addToLightQueue(){}_removeFromLightQueue(){}_onActive(){super._onActive(),this.lightmapBakedType!==je.LIGHTMAPBAKEDTYPE_BAKED&&this._addToScene()}_onInActive(){super._onInActive(),this.lightmapBakedType!==je.LIGHTMAPBAKEDTYPE_BAKED&&this._removeFromScene()}_create(){return new je}get diffuseColor(){return console.log("LightSprite: discard property,please use color property instead."),this.color}set diffuseColor(e){console.log("LightSprite: discard property,please use color property instead."),this.color=e}}je.LIGHTMAPBAKEDTYPE_REALTIME=0,je.LIGHTMAPBAKEDTYPE_MIXED=1,je.LIGHTMAPBAKEDTYPE_BAKED=2,(d=e.ShadowCascadesMode||(e.ShadowCascadesMode={}))[d.NoCascades=0]="NoCascades",d[d.TwoCascades=1]="TwoCascades",d[d.FourCascades=2]="FourCascades",function(e){e[e.Near=0]="Near",e[e.Far=1]="Far",e[e.Left=2]="Left",e[e.Right=3]="Right",e[e.Bottom=4]="Bottom",e[e.Top=5]="Top"}(u||(u={}));class Ze{static supportShadow(){return t.LayaGL.layaGPUInstance._isWebGL2||t.SystemUtils.supportRenderTextureFormat(t.RenderTextureFormat.Depth)}static init(){t.LayaGL.layaGPUInstance._isWebGL2?Ze._shadowTextureFormat=t.RenderTextureFormat.ShadowMap:Ze._shadowTextureFormat=t.RenderTextureFormat.Depth}static getTemporaryShadowTexture(e,r,i){var a=he.createFromPool(e,r,Ze._shadowTextureFormat,i);return a.filterMode=t.FilterMode.Bilinear,a.wrapModeU=t.WarpMode.Clamp,a.wrapModeV=t.WarpMode.Clamp,a}static getShadowBias(t,i,a,n){var s;t._lightType==e.LightType.Directional?s=2/i.elements[0]:t._lightType==e.LightType.Spot?s=Math.tan(.5*t.spotAngle*r.Deg2Rad)*t.range:(console.warn("ShadowUtils:Only spot and directional shadow casters are supported now."),s=0);var o=s/a,l=-t._shadowDepthBias*o,_=-t._shadowNormalBias*o;if(t.shadowMode==e.ShadowMode.SoftHigh){const e=2.5;l*=e,_*=e}n.setValue(l,_,0,0)}static getCameraFrustumPlanes(e,t){Be.getPlanesFromMatrix(e,t[u.Near],t[u.Far],t[u.Left],t[u.Right],t[u.Top],t[u.Bottom])}static getFarWithRadius(e,t){return Math.sqrt(e*e/t)}static getCascadesSplitDistance(t,r,i,a,n,s,o,l){l[0]=i;var _=a-i,h=Math.tan(.5*n),c=1+h*h*(s*s+1);switch(o){case e.ShadowCascadesMode.NoCascades:l[1]=Ze.getFarWithRadius(a,c);break;case e.ShadowCascadesMode.TwoCascades:l[1]=Ze.getFarWithRadius(i+_*t,c),l[2]=Ze.getFarWithRadius(a,c);break;case e.ShadowCascadesMode.FourCascades:l[1]=Ze.getFarWithRadius(i+_*r.x,c),l[2]=Ze.getFarWithRadius(i+_*r.y,c),l[3]=Ze.getFarWithRadius(i+_*r.z,c),l[4]=Ze.getFarWithRadius(a,c)}}static applySliceTransform(e,t,r,i,a){var n=Ze._tempMatrix0.elements,s=1/t,o=1/r;n[0]=e.resolution*s,n[5]=e.resolution*o,n[12]=e.offsetX*s,n[13]=e.offsetY*o,n[1]=n[2]=n[2]=n[4]=n[6]=n[7]=n[8]=n[9]=n[11]=n[14]=0,n[10]=n[15]=1;var l=16*i;H._mulMatrixArray(n,a,l,a,l)}static getDirectionLightShadowCullPlanes(t,r,i,a,s,o){var l=Ze._frustumCorners,_=Ze._backPlaneFaces,h=Ze._frustumPlaneNeighbors,c=Ze._frustumTwoPlaneCorners,d=Ze._edgePlanePoint2,m=o.cullPlanes,f=t[u.Near],T=t[u.Far],E=t[u.Left],p=t[u.Right],g=t[u.Bottom],S=t[u.Top],R=i[r]-a,v=Ze._adjustNearPlane,x=Ze._adjustFarPlane;f.normal.cloneTo(v.normal),T.normal.cloneTo(x.normal),v.distance=f.distance-R,x.distance=Math.min(-f.distance+o.sphereCenterZ+o.splitBoundSphere.radius,T.distance),Be.get3PlaneInterPoint(v,g,p,l[e.FrustumCorner.nearBottomRight]),Be.get3PlaneInterPoint(v,S,p,l[e.FrustumCorner.nearTopRight]),Be.get3PlaneInterPoint(v,S,E,l[e.FrustumCorner.nearTopLeft]),Be.get3PlaneInterPoint(v,g,E,l[e.FrustumCorner.nearBottomLeft]),Be.get3PlaneInterPoint(x,g,p,l[e.FrustumCorner.FarBottomRight]),Be.get3PlaneInterPoint(x,S,p,l[e.FrustumCorner.FarTopRight]),Be.get3PlaneInterPoint(x,S,E,l[e.FrustumCorner.FarTopLeft]),Be.get3PlaneInterPoint(x,g,E,l[e.FrustumCorner.FarBottomLeft]);for(var A=0,I=0;I<6;I++){var M;switch(I){case u.Near:M=v;break;case u.Far:M=x;break;default:M=t[I]}n.dot(M.normal,s)<0&&(M.cloneTo(m[A]),_[A]=I,A++)}var D=A;for(I=0;I<A;I++)for(var C=_[I],y=h[C],L=0;L<4;L++){for(var O=y[L],N=!0,P=0;P<A;P++)if(O==_[P]){N=!1;break}if(N){var b=c[C][O],w=l[b[0]],V=l[b[1]];n.add(w,s,d),Pe.createPlaneBy3P(w,V,d,m[D++])}}o.cullPlaneCount=D}static getBoundSphereByFrustum(e,t,r,i,a,s,o){var l,_,h=Math.sqrt(1+i*i)*Math.tan(r/2),c=h*h,d=t-e,u=t+e;c>d/u?(l=t,_=t*h):(l=.5*u*(1+c),_=.5*Math.sqrt(d*d+2*(t*t+e*e)*c+u*u*c*c));var m=o.center;return o.radius=_,n.scale(s,l,m),n.add(a,m,m),l}static getMaxTileResolutionInAtlas(e,t,r){for(var i=Math.min(e,t),a=Math.floor(e/i)*Math.floor(t/i);a<r;)i=Math.floor(i>>1),a=Math.floor(e/i)*Math.floor(t/i);return i}static getDirectionalLightMatrices(e,t,r,i,a,s,o,l){var _=o.splitBoundSphere,h=_.center,c=_.radius,d=s/2,u=c*d/(d-Ze.atlasBorderSize),m=2*u,f=s/m,T=m/s,E=Math.ceil(n.dot(h,e)*f)*T,p=Math.ceil(n.dot(h,t)*f)*T,g=n.dot(h,r);h.x=e.x*E+t.x*p+r.x*g,h.y=e.y*E+t.y*p+r.y*g,h.z=e.z*E+t.z*p+r.z*g;var S=o.position,v=o.viewMatrix,x=o.projectionMatrix,A=o.viewProjectMatrix;o.resolution=s,o.offsetX=i%2*s,o.offsetY=Math.floor(i/2)*s,n.scale(r,c+a,S),n.subtract(h,S,S),R.createLookAt(S,h,e,v),R.createOrthoOffCenter(-u,u,-u,u,0,2*c+a,x),R.multiply(x,v,A),H._mulMatrixArray(Ze._shadowMapScaleOffsetMatrix.elements,A.elements,0,l,16*i)}static getSpotLightShadowData(e,t,r,i,a,n){var s=e.position=t.transform.position;e.resolution=r,n.setValue(1/r,1/r,r,r),e.offsetX=0,e.offsetY=0;var o=t.lightWorldMatrix,l=e.viewMatrix,_=e.projectionMatrix,h=e.viewProjectMatrix,c=e.cameraCullInfo.boundFrustum;o.invert(l),R.createPerspective(3.1416*t.spotAngle/180,1,.1,t.range,_),i.y=t.shadowStrength,R.multiply(_,l,h),c.matrix=h,h.cloneTo(a),e.cameraCullInfo.position=s}static prepareShadowReceiverShaderValues(e,t,r,i,a,n,s,o,l){if(n.setValue(1/t,1/r,t,r),s.setValue(e._shadowStrength,0,0,0),a>1){const e=16;for(var _=a*e,h=4*e;_<h;_++)o[_]=0;for(_=0;_<a;_++){var c=i[_].splitBoundSphere,d=c.center,u=c.radius,m=4*_;l[m]=d.x,l[m+1]=d.y,l[m+2]=d.z,l[m+3]=u*u}const t=4;for(_=a*t,h=4*t;_<h;_++)l[_]=0}}}Ze._tempMatrix0=new R,Ze._shadowMapScaleOffsetMatrix=new R(.5,0,0,0,0,.5,0,0,0,0,1,0,.5,.5,0,1),Ze._frustumCorners=[new n,new n,new n,new n,new n,new n,new n,new n],Ze._adjustNearPlane=new Pe(new n),Ze._adjustFarPlane=new Pe(new n),Ze._backPlaneFaces=new Array(5),Ze._edgePlanePoint2=new n,Ze._frustumPlaneNeighbors=[[u.Left,u.Right,u.Top,u.Bottom],[u.Left,u.Right,u.Top,u.Bottom],[u.Near,u.Far,u.Top,u.Bottom],[u.Near,u.Far,u.Top,u.Bottom],[u.Near,u.Far,u.Left,u.Right],[u.Near,u.Far,u.Left,u.Right]],Ze._frustumTwoPlaneCorners=[[[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.nearBottomLeft,e.FrustumCorner.nearTopLeft],[e.FrustumCorner.nearTopRight,e.FrustumCorner.nearBottomRight],[e.FrustumCorner.nearBottomRight,e.FrustumCorner.nearBottomLeft],[e.FrustumCorner.nearTopLeft,e.FrustumCorner.nearTopRight]],[[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.FarTopLeft,e.FrustumCorner.FarBottomLeft],[e.FrustumCorner.FarBottomRight,e.FrustumCorner.FarTopRight],[e.FrustumCorner.FarBottomLeft,e.FrustumCorner.FarBottomRight],[e.FrustumCorner.FarTopRight,e.FrustumCorner.FarTopLeft]],[[e.FrustumCorner.nearTopLeft,e.FrustumCorner.nearBottomLeft],[e.FrustumCorner.FarBottomLeft,e.FrustumCorner.FarTopLeft],[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.nearBottomLeft,e.FrustumCorner.FarBottomLeft],[e.FrustumCorner.FarTopLeft,e.FrustumCorner.nearTopLeft]],[[e.FrustumCorner.nearBottomRight,e.FrustumCorner.nearTopRight],[e.FrustumCorner.FarTopRight,e.FrustumCorner.FarBottomRight],[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.FarBottomRight,e.FrustumCorner.nearBottomRight],[e.FrustumCorner.nearTopRight,e.FrustumCorner.FarTopRight]],[[e.FrustumCorner.nearBottomLeft,e.FrustumCorner.nearBottomRight],[e.FrustumCorner.FarBottomRight,e.FrustumCorner.FarBottomLeft],[e.FrustumCorner.FarBottomLeft,e.FrustumCorner.nearBottomLeft],[e.FrustumCorner.nearBottomRight,e.FrustumCorner.FarBottomRight],[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.unknown,e.FrustumCorner.unknown]],[[e.FrustumCorner.nearTopRight,e.FrustumCorner.nearTopLeft],[e.FrustumCorner.FarTopLeft,e.FrustumCorner.FarTopRight],[e.FrustumCorner.nearTopLeft,e.FrustumCorner.FarTopLeft],[e.FrustumCorner.FarTopRight,e.FrustumCorner.nearTopRight],[e.FrustumCorner.unknown,e.FrustumCorner.unknown],[e.FrustumCorner.unknown,e.FrustumCorner.unknown]]],Ze.atlasBorderSize=4,(m=e.DepthTextureMode||(e.DepthTextureMode={}))[m.None=0]="None",m[m.Depth=1]="Depth",m[m.DepthNormals=2]="DepthNormals",m[m.MotionVectors=4]="MotionVectors";class qe{constructor(){this._zBufferParams=new a}update(r,i){switch(this._viewPort=r.viewport,this._camera=r,i){case e.DepthTextureMode.Depth:r.depthTexture=this._depthTexture=he.createFromPool(this._viewPort.width,this._viewPort.height,t.RenderTextureFormat.Depth,t.RenderTextureDepthFormat.DEPTH_16);break;case e.DepthTextureMode.DepthNormals:r.depthNormalTexture=this._depthNormalsTexture=he.createFromPool(this._viewPort.width,this._viewPort.height,t.RenderTextureFormat.R8G8B8A8,t.RenderTextureDepthFormat.DEPTH_16);break;case e.DepthTextureMode.MotionVectors:break;default:throw"there is UnDefined type of DepthTextureMode"}}render(r,i){var a=r.scene;switch(i){case e.DepthTextureMode.Depth:var n=a._shaderValues;r.pipelineMode="ShadowCaster",me.setRuntimeValueMode(!1),this._depthTexture._start(),n.setVector(qe.DEFINE_SHADOW_BIAS,qe.SHADOW_BIAS);var s=t.LayaGL.instance,o=this._viewPort.x,l=this._viewPort.y;s.enable(s.SCISSOR_TEST),s.viewport(o,l,this._viewPort.width,this._viewPort.height),s.scissor(o,l,this._viewPort.width,this._viewPort.height),s.clear(s.DEPTH_BUFFER_BIT),a._opaqueQueue._render(r),this._depthTexture._end(),me.setRuntimeValueMode(!0),this._setupDepthModeShaderValue(i,this._camera),r.pipelineMode=r.configPipeLineMode;break;case e.DepthTextureMode.DepthNormals:n=a._shaderValues;r.pipelineMode="DepthNormal",me.setRuntimeValueMode(!1),this._depthNormalsTexture._start();s=t.LayaGL.instance,o=this._viewPort.x,l=this._viewPort.y;s.enable(s.SCISSOR_TEST),s.viewport(o,l,this._viewPort.width,this._viewPort.height),s.scissor(o,l,this._viewPort.width,this._viewPort.height),s.clearColor(0,0,1,0),s.clear(s.DEPTH_BUFFER_BIT|s.COLOR_BUFFER_BIT),a._opaqueQueue._render(r),this._depthNormalsTexture._end(),me.setRuntimeValueMode(!0),this._setupDepthModeShaderValue(i,this._camera),r.pipelineMode=r.configPipeLineMode;break;case e.DepthTextureMode.MotionVectors:break;default:throw"there is UnDefined type of DepthTextureMode"}}_setupDepthModeShaderValue(t,r){switch(t){case e.DepthTextureMode.Depth:var i=r.farPlane,a=r.nearPlane;this._zBufferParams.setValue(1-i/a,i/a,(a-i)/(a*i),1/a),r._shaderValues.setVector(qe.DEFINE_SHADOW_BIAS,qe.SHADOW_BIAS),r._shaderValues.setTexture(qe.DEPTHTEXTURE,this._depthTexture),r._shaderValues.setVector(qe.DEPTHZBUFFERPARAMS,this._zBufferParams);break;case e.DepthTextureMode.DepthNormals:r._shaderValues.setTexture(qe.DEPTHNORMALSTEXTURE,this._depthNormalsTexture);break;case e.DepthTextureMode.MotionVectors:break;default:throw"there is UnDefined type of DepthTextureMode"}}cleanUp(){this._depthTexture&&he.recoverToPool(this._depthTexture),this._depthNormalsTexture&&he.recoverToPool(this._depthNormalsTexture),this._depthTexture=null,this._depthNormalsTexture=null}}qe.SHADOW_BIAS=new a,qe.DEFINE_SHADOW_BIAS=xe.propertyNameToID("u_ShadowBias"),qe.DEPTHTEXTURE=xe.propertyNameToID("u_CameraDepthTexture"),qe.DEPTHNORMALSTEXTURE=xe.propertyNameToID("u_CameraDepthNormalsTexture"),qe.DEPTHZBUFFERPARAMS=xe.propertyNameToID("u_ZBufferParams"),(f=e.CameraClearFlags||(e.CameraClearFlags={}))[f.SolidColor=0]="SolidColor",f[f.Sky=1]="Sky",f[f.DepthOnly=2]="DepthOnly",f[f.Nothing=3]="Nothing",(T=e.CameraEventFlags||(e.CameraEventFlags={}))[T.BeforeForwardOpaque=0]="BeforeForwardOpaque",T[T.BeforeSkyBox=2]="BeforeSkyBox",T[T.BeforeTransparent=4]="BeforeTransparent",T[T.BeforeImageEffect=6]="BeforeImageEffect",T[T.AfterEveryThing=8]="AfterEveryThing";class Qe extends Xe{constructor(r=0,n=.3,s=1e3){super(n,s),this._updateViewMatrix=!0,this._postProcess=null,this._enableHDR=!1,this._viewportParams=new a,this._projectionParams=new a,this._needBuiltInRenderTexture=!1,this._offScreenRenderTexture=null,this._internalRenderTexture=null,this._cameraEventCommandBuffer={},this._clusterPlaneCacheFlag=new i(-1,-1),this._screenOffsetScale=new a,this.enableRender=!0,this.clearFlag=e.CameraClearFlags.SolidColor,this._viewMatrix=new R,this._projectionMatrix=new R,this._projectionViewMatrix=new R,this._viewport=new Fe(0,0,0,0),this._normalizedViewport=new Fe(0,0,1,1),this._aspectRatio=r,this._boundFrustum=new Be(new R),this._calculateProjectionMatrix(),t.Laya.stage.on(t.Event.RESIZE,this,this._onScreenSizeChanged),this.transform.on(t.Event.TRANSFORM_CHANGED,this,this._onTransformChanged)}static drawRenderTextureByScene(e,r,i){e.renderTarget!=i&&(e.renderTarget&&he.recoverToPool(e.renderTarget),e.renderTarget=i);var a=e.viewport,n=e._needInternalRenderTexture(),s=_e._instance;r=s.scene=r;s.pipelineMode=s.configPipeLineMode,n?(e._internalRenderTexture=he.createFromPool(a.width,a.height,e._getRenderTextureFormat(),t.RenderTextureDepthFormat.DEPTH_16),e._internalRenderTexture.filterMode=t.FilterMode.Bilinear):e._internalRenderTexture=null;var o=e._renderShadowMap(r,s);return e._preRenderMainPass(s,r,n,a),e._renderMainPass(s,a,r,null,null,n),e._aftRenderMainPass(o),e.renderTarget}get aspectRatio(){if(0===this._aspectRatio){var e=this.viewport;return e.width/e.height}return this._aspectRatio}set aspectRatio(e){if(e<0)throw new Error("Camera: the aspect ratio has to be a positive real number.");this._aspectRatio=e,this._calculateProjectionMatrix()}get viewport(){return this._offScreenRenderTexture?this._calculationViewport(this._normalizedViewport,this._offScreenRenderTexture.width,this._offScreenRenderTexture.height):this._calculationViewport(this._normalizedViewport,_e.clientWidth,_e.clientHeight),this._viewport}set viewport(e){var t,r;this._offScreenRenderTexture?(t=this._offScreenRenderTexture.width,r=this._offScreenRenderTexture.height):(t=_e.clientWidth,r=_e.clientHeight),this._normalizedViewport.x=e.x/t,this._normalizedViewport.y=e.y/r,this._normalizedViewport.width=e.width/t,this._normalizedViewport.height=e.height/r,this._calculationViewport(this._normalizedViewport,t,r),this._calculateProjectionMatrix()}get normalizedViewport(){return this._normalizedViewport}set normalizedViewport(e){var t,r;this._offScreenRenderTexture?(t=this._offScreenRenderTexture.width,r=this._offScreenRenderTexture.height):(t=_e.clientWidth,r=_e.clientHeight),this._normalizedViewport!==e&&e.cloneTo(this._normalizedViewport),this._calculationViewport(e,t,r),this._calculateProjectionMatrix()}get viewMatrix(){if(this._updateViewMatrix){var e=this.transform.getWorldLossyScale(),t=e.x,r=e.y,i=e.z,a=this._viewMatrix.elements;this.transform.worldMatrix.cloneTo(this._viewMatrix),a[0]/=t,a[1]/=t,a[2]/=t,a[4]/=r,a[5]/=r,a[6]/=r,a[8]/=i,a[9]/=i,a[10]/=i,this._viewMatrix.invert(this._viewMatrix),this._updateViewMatrix=!1}return this._viewMatrix}get projectionMatrix(){return this._projectionMatrix}set projectionMatrix(e){this._projectionMatrix=e,this._useUserProjectionMatrix=!0}get projectionViewMatrix(){return R.multiply(this.projectionMatrix,this.viewMatrix,this._projectionViewMatrix),this._projectionViewMatrix}get boundFrustum(){return this._boundFrustum.matrix=this.projectionViewMatrix,this._boundFrustum}get renderTarget(){return this._offScreenRenderTexture}set renderTarget(e){var t=this._offScreenRenderTexture;t!==e&&(t&&(t._isCameraTarget=!1),e&&(e._isCameraTarget=!0),this._offScreenRenderTexture=e,this._calculateProjectionMatrix())}get postProcess(){return this._postProcess}set postProcess(e){this._postProcess=e,e&&e&&e._init(this)}get enableHDR(){return this._enableHDR}set enableHDR(e){!e||t.SystemUtils.supportRenderTextureFormat(t.RenderTextureFormat.R16G16B16A16)?this._enableHDR=e:console.warn("Camera:can't enable HDR in this device.")}get enableBuiltInRenderTexture(){return this._needBuiltInRenderTexture}set enableBuiltInRenderTexture(e){this._needBuiltInRenderTexture=e}get depthTextureMode(){return this._depthTextureMode}set depthTextureMode(e){this._depthTextureMode=e}_calculationViewport(e,t,r){var i=e.x*t,a=e.y*r,n=i+Math.max(e.width*t,0),s=a+Math.max(e.height*r,0),o=Math.ceil(i),l=Math.ceil(a),_=Math.floor(n),h=Math.floor(s),c=o-i>=.5?Math.floor(i):o,d=l-a>=.5?Math.floor(a):l,u=n-_>=.5?Math.ceil(n):_,m=s-h>=.5?Math.ceil(s):h;this._viewport.x=c,this._viewport.y=d,this._viewport.width=u-c,this._viewport.height=m-d}_calculateProjectionMatrix(){if(!this._useUserProjectionMatrix)if(this._orthographic){var e=.5*this.orthographicVerticalSize,t=e*this.aspectRatio;R.createOrthoOffCenter(-t,t,-e,e,this.nearPlane,this.farPlane,this._projectionMatrix)}else R.createPerspective(3.1416*this.fieldOfView/180,this.aspectRatio,this.nearPlane,this.farPlane,this._projectionMatrix)}_isLayerVisible(e){return 0!=(Math.pow(2,e)&this.cullingMask)}_onTransformChanged(e){(e&=I.TRANSFORM_WORLDMATRIX)&&(this._updateViewMatrix=!0)}_parse(e,t){super._parse(e,t);var r=e.clearFlag;void 0!==r&&(this.clearFlag=r);var i=e.viewport;this.normalizedViewport=new Fe(i[0],i[1],i[2],i[3]);var a=e.enableHDR;void 0!==a&&(this.enableHDR=a)}_getCanvasWidth(){return this._offScreenRenderTexture?this._offScreenRenderTexture.width:_e.clientWidth}_getCanvasHeight(){return this._offScreenRenderTexture?this._offScreenRenderTexture.height:_e.clientHeight}_getRenderTexture(){return this._internalRenderTexture||this._offScreenRenderTexture}_needInternalRenderTexture(){return!!(this._postProcess&&this._postProcess.enable||this._enableHDR||this._needBuiltInRenderTexture)}_getRenderTextureFormat(){return this._enableHDR?t.RenderTextureFormat.R16G16B16A16:t.RenderTextureFormat.R8G8B8}_prepareCameraToRender(){super._prepareCameraToRender();var e=this.viewport;this._viewportParams.setValue(e.x,e.y,e.width,e.height),this._projectionParams.setValue(this._nearPlane,this._farPlane,_e._instance.invertY?-1:1,1/this.farPlane),this._shaderValues.setVector(Xe.VIEWPORT,this._viewportParams),this._shaderValues.setVector(Xe.PROJECTION_PARAMS,this._projectionParams)}_applyViewProject(e,t,r){var i,a=this._shaderValues;e.invertY?(R.multiply(Xe._invertYScaleMatrix,r,Xe._invertYProjectionMatrix),R.multiply(Xe._invertYProjectionMatrix,t,Xe._invertYProjectionViewMatrix),r=Xe._invertYProjectionMatrix,i=Xe._invertYProjectionViewMatrix):(R.multiply(r,t,this._projectionViewMatrix),i=this._projectionViewMatrix),e.viewMatrix=t,e.projectionMatrix=r,e.projectionViewMatrix=i,a.setMatrix4x4(Xe.VIEWMATRIX,t),a.setMatrix4x4(Xe.PROJECTMATRIX,r),a.setMatrix4x4(Xe.VIEWPROJECTMATRIX,i)}_updateClusterPlaneXY(){var e=this.fieldOfView,t=this.aspectRatio;if(this._clusterPlaneCacheFlag.x!==e||this._clusterPlaneCacheFlag.y!==t){var r=j._config.lightClusterCount,i=r.x,a=r.y,s=i+1,o=a+1,l=this._clusterXPlanes,_=this._clusterYPlanes;if(!l){l=this._clusterXPlanes=new Array(s),_=this._clusterYPlanes=new Array(o);for(var h=0;h<s;h++)l[h]=new n;for(h=0;h<o;h++)_[h]=new n}var c=Math.tan(this.fieldOfView/2*Math.PI/180),d=this.aspectRatio*c,u=2*c/i,m=2*d/a;for(h=0;h<s;h++){var f=m*h-d,T=1/Math.sqrt(1+f*f);l[h].setValue(T,0,-f*T)}for(h=0;h<o;h++){f=c-u*h;var E=-1/Math.sqrt(1+f*f);_[h].setValue(0,E,-f*E)}this._clusterPlaneCacheFlag.x=e,this._clusterPlaneCacheFlag.y=t}}_applyCommandBuffer(e,r){var i=t.LayaGL.instance,a=this._cameraEventCommandBuffer[e];a&&0!=a.length&&(a.forEach((function(e){e._context=r,e._apply()})),he.currentActive&&he.currentActive._end(),this._internalRenderTexture?this._internalRenderTexture._start():i.bindFramebuffer(i.FRAMEBUFFER,null),i.viewport(0,0,r.viewport.width,r.viewport.height))}_renderShadowMap(t,r){var i,a=t._mainDirectionLight,n=a&&a.shadowMode!==e.ShadowMode.None&&Ze.supportShadow();n?(t._shaderValues.removeDefine(Ye.SHADERDEFINE_SHADOW_SPOT),t._shaderValues.addDefine(Ye.SHADERDEFINE_SHADOW),(i=g.Scene3D._shadowCasterPass).update(this,a,g.ShadowLightType.DirectionLight),i.render(r,t,g.ShadowLightType.DirectionLight)):t._shaderValues.removeDefine(Ye.SHADERDEFINE_SHADOW);var s=t._mainSpotLight,o=s&&s.shadowMode!==e.ShadowMode.None&&Ze.supportShadow();return o?(t._shaderValues.removeDefine(Ye.SHADERDEFINE_SHADOW),t._shaderValues.addDefine(Ye.SHADERDEFINE_SHADOW_SPOT),(i=g.Scene3D._shadowCasterPass).update(this,s,g.ShadowLightType.SpotLight),i.render(r,t,g.ShadowLightType.SpotLight)):t._shaderValues.removeDefine(Ye.SHADERDEFINE_SHADOW_SPOT),n&&t._shaderValues.addDefine(Ye.SHADERDEFINE_SHADOW),o&&t._shaderValues.addDefine(Ye.SHADERDEFINE_SHADOW_SPOT),n||o}_preRenderMainPass(r,i,a,n){r.camera=this,r.cameraShaderValue=this._shaderValues,Qe._updateMark++,i._preRenderScript();var s=t.LayaGL.instance;if(a&&!this._offScreenRenderTexture&&(this.clearFlag==e.CameraClearFlags.DepthOnly||this.clearFlag==e.CameraClearFlags.Nothing))if(this._enableHDR){var o=he.createFromPool(n.width,n.height,t.RenderTextureFormat.R8G8B8,t.RenderTextureDepthFormat.DEPTH_16);o.filterMode=t.FilterMode.Bilinear,t.WebGLContext.bindTexture(s,s.TEXTURE_2D,o._getSource()),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,n.x,_e.clientHeight-(n.y+n.height),n.width,n.height);var l=Ie.create(o,this._internalRenderTexture);l.run(),l.recover(),he.recoverToPool(o)}else t.WebGLContext.bindTexture(s,s.TEXTURE_2D,this._internalRenderTexture._getSource()),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,n.x,_e.clientHeight-(n.y+n.height),n.width,n.height)}_renderMainPass(r,i,a,n,s,o){var l=t.LayaGL.instance,_=this._getRenderTexture();if(r.viewport=i,this._prepareCameraToRender(),j._config._multiLighting&&Ne.instance.update(this,a),a._preCulling(r,this,n,s),0!=this.depthTextureMode&&(this._applyViewProject(r,this.viewMatrix,this._projectionMatrix),this._renderDepthMode(r)),_&&_._start(),this._applyViewProject(r,this.viewMatrix,this._projectionMatrix),a._clear(l,r),this._applyCommandBuffer(e.CameraEventFlags.BeforeForwardOpaque,r),a._renderScene(r,g.Scene3D.SCENERENDERFLAG_RENDERQPAQUE),this._applyCommandBuffer(e.CameraEventFlags.BeforeSkyBox,r),a._renderScene(r,g.Scene3D.SCENERENDERFLAG_SKYBOX),this._applyCommandBuffer(e.CameraEventFlags.BeforeTransparent,r),a._renderScene(r,g.Scene3D.SCENERENDERFLAG_RENDERTRANSPARENT),a._postRenderScript(),this._applyCommandBuffer(e.CameraEventFlags.BeforeImageEffect,r),_&&_._end(),o){if(this._postProcess&&this._postProcess.enable)this._postProcess._render(),this._postProcess._applyPostProcessCommandBuffers();else if(this._enableHDR||this._needBuiltInRenderTexture){var h=this._getCanvasWidth(),c=this._getCanvasHeight();this._screenOffsetScale.setValue(i.x/h,i.y/c,i.width/h,i.height/c);var d=Ie.create(this._internalRenderTexture,this._offScreenRenderTexture?this._offScreenRenderTexture:null,this._screenOffsetScale,null,null,0,Ie._SCREENTYPE_QUAD,null,!0);d.run(),d.recover()}he.recoverToPool(this._internalRenderTexture)}this._applyCommandBuffer(e.CameraEventFlags.AfterEveryThing,r)}_renderDepthMode(t){var r=this._depthTextureMode;0!=(r&e.DepthTextureMode.Depth)&&(Qe.depthPass.update(this,e.DepthTextureMode.Depth),Qe.depthPass.render(t,e.DepthTextureMode.Depth)),0!=(r&e.DepthTextureMode.DepthNormals)&&(Qe.depthPass.update(this,e.DepthTextureMode.DepthNormals),Qe.depthPass.render(t,e.DepthTextureMode.DepthNormals))}get depthTexture(){return this._depthTexture}set depthTexture(e){this._depthTexture=e}get depthNormalTexture(){return this._depthNormalsTexture}set depthNormalTexture(e){this._depthNormalsTexture=e}_aftRenderMainPass(e){e&&g.Scene3D._shadowCasterPass.cleanUp(),Qe.depthPass.cleanUp()}render(e=null,r=null){if(this.activeInHierarchy){var i=this.viewport,a=this._needInternalRenderTexture(),n=_e._instance,s=n.scene=this._scene;n.pipelineMode=n.configPipeLineMode,a?(this._internalRenderTexture=he.createFromPool(i.width,i.height,this._getRenderTextureFormat(),t.RenderTextureDepthFormat.DEPTH_16),this._internalRenderTexture.filterMode=t.FilterMode.Bilinear):this._internalRenderTexture=null;var o=this._renderShadowMap(s,n);this._preRenderMainPass(n,s,a,i),this._renderMainPass(n,i,s,e,r,a),this._aftRenderMainPass(o)}}viewportPointToRay(e,t){Ue.calculateCursorRay(e,this.viewport,this._projectionMatrix,this.viewMatrix,null,t)}normalizedViewportPointToRay(e,t){var r=Qe._tempVector20,i=this.viewport;r.x=e.x*i.width,r.y=e.y*i.height,Ue.calculateCursorRay(r,this.viewport,this._projectionMatrix,this.viewMatrix,null,t)}worldToViewportPoint(e,r){R.multiply(this._projectionMatrix,this._viewMatrix,this._projectionViewMatrix),this.viewport.project(e,this._projectionViewMatrix,r),r.x=r.x/t.Laya.stage.clientScaleX,r.y=r.y/t.Laya.stage.clientScaleY}worldToNormalizedViewportPoint(e,r){R.multiply(this._projectionMatrix,this._viewMatrix,this._projectionViewMatrix),this.normalizedViewport.project(e,this._projectionViewMatrix,r),r.x=r.x/t.Laya.stage.clientScaleX,r.y=r.y/t.Laya.stage.clientScaleY}convertScreenCoordToOrthographicCoord(e,r){if(this._orthographic){var i=_e.clientWidth,a=_e.clientHeight,s=this.orthographicVerticalSize*this.aspectRatio/i,o=this.orthographicVerticalSize/a;return r.x=(-i/2+e.x*t.Laya.stage.clientScaleX)*s,r.y=(a/2-e.y*t.Laya.stage.clientScaleY)*o,r.z=(this.nearPlane-this.farPlane)*(e.z+1)/2-this.nearPlane,n.transformCoordinate(r,this.transform.worldMatrix,r),!0}return!1}destroy(e=!0){this._offScreenRenderTexture=null,this.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onTransformChanged),super.destroy(e)}addCommandBuffer(e,t){var r=this._cameraEventCommandBuffer[e];r||(r=this._cameraEventCommandBuffer[e]=[]),r.indexOf(t)<0&&r.push(t),t._camera=this}removeCommandBuffer(e,t){var r=this._cameraEventCommandBuffer[e];if(!r)throw"Camera:unknown event.";var i=r.indexOf(t);-1!=i&&r.splice(i,1)}removeCommandBuffers(e){this._cameraEventCommandBuffer[e]&&(this._cameraEventCommandBuffer[e].length=0)}_create(){return new Qe}}Qe._tempVector20=new i,Qe._updateMark=0,Qe.depthPass=new qe;class Ke{constructor(){this.renderSubShader=null,this.renderType=Ke.RENDERTYPE_NORMAL}getInvertFront(){return this._transform._isFrontFaceInvert}setTransform(e){this._transform=e}setGeometry(e){this._geometry=e}addToOpaqueRenderQueue(e,t){t.elements.add(this)}addToTransparentRenderQueue(e,t){t.elements.add(this),t.lastTransparentBatched=!1,t.lastTransparentRenderElement=this}_update(e,t,r,i,a=0){if(this.material){var n=this.material._shader.getSubShaderAt(0);if(this.renderSubShader=null,r)if(i){var s=n.getFlag(i);if(!s)return;for(var o=r._subShaders,l=0,_=o.length;l<_;l++){var h=o[l];if(s===h.getFlag(i)){this.renderSubShader=h;break}}if(!this.renderSubShader)return}else this.renderSubShader=r.getSubShaderAt(a);else this.renderSubShader=n;var c=e._getRenderQueue(this.material.renderQueue);c.isTransparent?this.addToTransparentRenderQueue(t,c):this.addToOpaqueRenderQueue(t,c)}}_render(e){var t,r,i,a=e.invertY,n=Qe._updateMark,s=e.scene,o=e.cameraShaderValue,l=this._transform,_=this._geometry;e.renderElement=this,n!==this.render._updateMark||this.renderType!==this.render._updateRenderType?(this.render._renderUpdate(e,l),this.render._renderUpdateWithCamera(e,l),this.render._updateMark=n,this.render._updateRenderType=this.renderType):this.renderType==Ke.RENDERTYPE_INSTANCEBATCH&&(this.render._renderUpdate(e,l),this.render._renderUpdateWithCamera(e,l));var h=e.pipelineMode;if(_._prepareRender(e))for(var c=this.renderSubShader._passes,d=0,u=c.length;d<u;d++){var m=c[d];if(m._pipelineMode===h){var f=Ke._compileDefine;s._shaderValues._defineDatas.cloneTo(f),f.addDefineDatas(this.render._shaderValues._defineDatas),f.addDefineDatas(this.material._shaderValues._defineDatas);var T=e.shader=m.withCompile(f),E=T.bind(),p=n!==T._uploadMark,g=T._uploadScene!==s||p;(g||E)&&(T.uploadUniforms(T._sceneUniformParamsMap,s._shaderValues,g),T._uploadScene=s);var S=T._uploadRender!==this.render||T._uploadRenderType!==this.renderType||p;(S||E)&&(T.uploadUniforms(T._spriteUniformParamsMap,this.render._shaderValues,S),T._uploadRender=this.render,T._uploadRenderType=this.renderType);var R=T._uploadCameraShaderValue!==o||p;(R||E)&&(T.uploadUniforms(T._cameraUniformParamsMap,o,R),T._uploadCameraShaderValue=o);var v=T._uploadMaterial!==this.material||p;(v||E)&&(T.uploadUniforms(T._materialUniformParamsMap,this.material._shaderValues,v),T._uploadMaterial=this.material);var x=this.material._shaderValues;t!==this.material||r!==T?(T.uploadRenderStateBlendDepth(x),T.uploadRenderStateFrontFace(x,a,this.getInvertFront()),t=this.material,r=T,i=this.render):i!==this.render&&(T.uploadRenderStateFrontFace(x,a,this.getInvertFront()),i=this.render),_._render(e),T._uploadMark=n}}this.renderType!==Ke.RENDERTYPE_NORMAL&&this.render._revertBatchRenderUpdate(e)}destroy(){this._transform=null,this._geometry=null,this.material=null,this.render=null}}Ke.RENDERTYPE_NORMAL=0,Ke.RENDERTYPE_STATICBATCH=1,Ke.RENDERTYPE_INSTANCEBATCH=2,Ke.RENDERTYPE_VERTEXBATCH=3,Ke._compileDefine=new ce;class Je extends Ae{static create(e,t,r,i){var a;return(a=Je._pool.length>0?Je._pool.pop():new Je)._render=e,a._material=t,a._subShaderIndex=r,a._commandBuffer=i,a}_elementRender(e,t){var r,i,a,n=t.invertY,s=Qe._updateMark,o=t.scene;this._render._scene=t.scene;var l=t.cameraShaderValue,_=e._transform,h=e._geometry;t.renderElement=e,s!==e.render._updateMark||e.renderType!==e.render._updateRenderType?(e.render._renderUpdate(t,_),e.render._renderUpdateWithCamera(t,_),e.render._updateMark=s,e.render._updateRenderType=e.renderType):e.renderType==Ke.RENDERTYPE_INSTANCEBATCH&&(e.render._renderUpdate(t,_),e.render._renderUpdateWithCamera(t,_));var c=t.pipelineMode;if(h._prepareRender(t))for(var d=e.renderSubShader._passes,u=0,m=d.length;u<m;u++){var f=d[u];if(f._pipelineMode===c){var T=Je._compileDefine;o._shaderValues._defineDatas.cloneTo(T),T.addDefineDatas(e.render._shaderValues._defineDatas),T.addDefineDatas(this._material._shaderValues._defineDatas);var E=t.shader=f.withCompile(T),p=E.bind(),g=s!==E._uploadMark,S=E._uploadScene!==o||g;(S||p)&&(E.uploadUniforms(E._sceneUniformParamsMap,o._shaderValues,S),E._uploadScene=o);var R=E._uploadRender!==e.render||E._uploadRenderType!==e.renderType||g;(R||p)&&(E.uploadUniforms(E._spriteUniformParamsMap,e.render._shaderValues,R),E._uploadRender=e.render,E._uploadRenderType=e.renderType);var v=E._uploadCameraShaderValue!==l||g;(v||p)&&(E.uploadUniforms(E._cameraUniformParamsMap,l,v),E._uploadCameraShaderValue=l);var x=E._uploadMaterial!==this._material||g;(x||p)&&(E.uploadUniforms(E._materialUniformParamsMap,this._material._shaderValues,x),E._uploadMaterial=this._material);var A=this._material._shaderValues;r!==this._material||i!==E?(E.uploadRenderStateBlendDepth(A),E.uploadRenderStateFrontFace(A,n,e.getInvertFront()),r=this._material,i=E,a=e.render):a!==e.render&&(E.uploadRenderStateFrontFace(A,n,e.getInvertFront()),a=e.render),h._render(t),E._uploadMark=s}}e.renderType!==Ke.RENDERTYPE_NORMAL&&e.render._revertBatchRenderUpdate(t)}run(){if(!this._material)throw"This render command material cannot be empty";this.setContext(this._commandBuffer._context);for(var e=this._context,t=(e.scene,this._render._renderElements),r=0,i=t.length;r<i;r++){var a=t[r];this._renderElementUpdate(a),this._elementRender(a,e)}}_renderElementUpdate(e){this._material&&(e.renderSubShader=this._material._shader.getSubShaderAt(this._subShaderIndex))}recover(){Je._pool.push(this)}}Je._pool=[],Je._compileDefine=new ce;class $e extends Ae{constructor(){super(...arguments),this._nameID=0,this._value=null,this._dataType=-1}static create(e,t,r,i){var a;return(a=$e._pool.length>0?$e._pool.pop():new $e)._nameID=e,a._value=t,a._dataType=r,a._commandBuffer=i,a}run(){var t=this._commandBuffer._camera.scene._shaderValues;switch(this._dataType){case e.ShaderDataType.Int:t.setInt(this._nameID,this._value);break;case e.ShaderDataType.Number:t.setNumber(this._nameID,this._value);break;case e.ShaderDataType.Bool:t.setBool(this._nameID,this._value);break;case e.ShaderDataType.Matrix4x4:t.setMatrix4x4(this._nameID,this._value);break;case e.ShaderDataType.Quaternion:t.setQuaternion(this._nameID,this._value);break;case e.ShaderDataType.Texture:t.setTexture(this._nameID,this._value);break;case e.ShaderDataType.Vector4:t.setVector(this._nameID,this._value);break;case e.ShaderDataType.Vector2:t.setVector2(this._nameID,this._value);break;case e.ShaderDataType.Vector3:t.setVector3(this._nameID,this._value);break;case e.ShaderDataType.Buffer:t.setBuffer(this._nameID,this._value);break;default:throw"no type shaderValue on this CommendBuffer"}}recover(){$e._pool.push(this),this._nameID=0,this._value=null,this._dataType=-1}}$e._pool=[];class et{constructor(){this._camera=null,this._commands=[]}_apply(){for(var e=0,t=this._commands.length;e<t;e++)this._commands[e].run()}setShaderDataTexture(t,r,i){this._commands.push(De.create(t,r,i,e.ShaderDataType.Texture,this))}setGlobalTexture(t,r){this._commands.push($e.create(t,r,e.ShaderDataType.Texture,this))}setShaderDataVector(t,r,i){this._commands.push(De.create(t,r,i,e.ShaderDataType.Vector4,this))}setGlobalVector(t,r){this._commands.push($e.create(t,r,e.ShaderDataType.Vector4,this))}setShaderDataVector3(t,r,i){this._commands.push(De.create(t,r,i,e.ShaderDataType.Vector3,this))}setGlobalVector3(t,r){this._commands.push($e.create(t,r,e.ShaderDataType.Vector3,this))}setShaderDataVector2(t,r,i){this._commands.push(De.create(t,r,i,e.ShaderDataType.Vector2,this))}setGlobalVector2(t,r){this._commands.push($e.create(t,r,e.ShaderDataType.Vector2,this))}setShaderDataNumber(t,r,i){this._commands.push(De.create(t,r,i,e.ShaderDataType.Number,this))}setGlobalNumber(t,r){this._commands.push($e.create(t,r,e.ShaderDataType.Number,this))}setShaderDataInt(t,r,i){this._commands.push(De.create(t,r,i,e.ShaderDataType.Int,this))}setGlobalInt(t,r){this._commands.push($e.create(t,r,e.ShaderDataType.Int,this))}setShaderDataMatrix(t,r,i){this._commands.push(De.create(t,r,i,e.ShaderDataType.Matrix4x4,this))}setGlobalMatrix(t,r){this._commands.push($e.create(t,r,e.ShaderDataType.Matrix4x4,this))}blitScreenQuad(e,t,r=null,i=null,a=null,n=0){this._commands.push(Ie.create(e,t,r,i,a,n,Ie._SCREENTYPE_QUAD,this))}blitScreenQuadByMaterial(e,t,r=null,i=null,a=0){var n,s;i&&(n=i._shader,s=i.shaderData),this._commands.push(Ie.create(e,t,r,n,s,a,Ie._SCREENTYPE_QUAD,this))}blitScreenTriangle(e,t,r=null,i=null,a=null,n=0,s=!1){this._commands.push(Ie.create(e,t,r,i,a,n,Ie._SCREENTYPE_TRIANGLE,this,s))}setRenderTarget(e){this._commands.push(Me.create(e))}clearRenderTarget(e,t,r,i=1){this._commands.push(Le.create(e,t,r,i,this))}drawMesh(e,t,r,i,a){this._commands.push(ye.create(e,t,r,i,a,this))}drawRender(e,t,r){this._commands.push(Je.create(e,t,r,this))}clear(){for(var e=0,t=this._commands.length;e<t;e++)this._commands[e].recover();this._commands.length=0}}class tt{constructor(){this.source=null,this.destination=null,this.camera=null,this.compositeShaderData=null,this.command=null,this.deferredReleaseTextures=[]}}class rt{constructor(){this._compositeShader=xe.find("PostProcessComposite"),this._compositeShaderData=new me,this._effects=[],this._enable=!0,this._context=null,this._context=new tt,this._context.compositeShaderData=this._compositeShaderData,this._context.command=new et}static __init__(){rt.SHADERDEFINE_BLOOM_LOW=xe.getDefineByName("BLOOM_LOW"),rt.SHADERDEFINE_BLOOM=xe.getDefineByName("BLOOM"),rt.SHADERDEFINE_FINALPASS=xe.getDefineByName("FINALPASS")}get enable(){return this._enable}set enable(e){this._enable=e}_init(e){this._context.camera=e,this._context.command._camera=e}_render(){var e=me._SET_RUNTIME_VALUE_MODE_REFERENCE_;t.ILaya.Render.supportWebGLPlusRendering&&me.setRuntimeValueMode(!1);var r=this._context.camera,i=r.viewport,a=r._internalRenderTexture,n=a;this._context.command.clear(),this._context.source=n,this._context.destination=a,this._context.compositeShaderData.clearDefine(),this._context.compositeShaderData.setTexture(rt.SHADERVALUE_AUTOEXPOSURETEX,t.Texture2D.whiteTexture);for(var s=0,o=this._effects.length;s<o;s++)this._effects[s].render(this._context);this._compositeShaderData.addDefine(rt.SHADERDEFINE_FINALPASS);var l=r._offScreenRenderTexture,_=l||null;this._context.destination=_;var h=r._getCanvasWidth(),c=r._getCanvasHeight();r._screenOffsetScale.setValue(i.x/h,i.y/c,i.width/h,i.height/c),this._context.command.blitScreenTriangle(this._context.source,_,r._screenOffsetScale,this._compositeShader,this._compositeShaderData,0,!0),he.recoverToPool(n);var d=this._context.deferredReleaseTextures;for(s=0,o=d.length;s<o;s++)he.recoverToPool(d[s]);d.length=0,t.ILaya.Render.supportWebGLPlusRendering&&me.setRuntimeValueMode(e)}addEffect(e){this._effects.push(e)}removeEffect(e){var t=this._effects.indexOf(e);-1!==t&&this._effects.splice(t,1)}_applyPostProcessCommandBuffers(){this._context.command._apply()}}rt.SHADERVALUE_MAINTEX=xe.propertyNameToID("u_MainTex"),rt.SHADERVALUE_BLOOMTEX=xe.propertyNameToID("u_BloomTex"),rt.SHADERVALUE_AUTOEXPOSURETEX=xe.propertyNameToID("u_AutoExposureTex"),rt.SHADERVALUE_BLOOM_DIRTTEX=xe.propertyNameToID("u_Bloom_DirtTex"),rt.SHADERVALUE_BLOOMTEX_TEXELSIZE=xe.propertyNameToID("u_BloomTex_TexelSize"),rt.SHADERVALUE_BLOOM_DIRTTILEOFFSET=xe.propertyNameToID("u_Bloom_DirtTileOffset"),rt.SHADERVALUE_BLOOM_SETTINGS=xe.propertyNameToID("u_Bloom_Settings"),rt.SHADERVALUE_BLOOM_COLOR=xe.propertyNameToID("u_Bloom_Color");class it extends t.EventDispatcher{constructor(e){super(),this._owner=e,this._children=[],this._localMatrix=new Float32Array(16),this._localPosition=new n,this._localRotation=new S,this._localScale=new n,this._worldMatrix=new Float32Array(16),this._localQuaternionUpdate=!1,this._locaEulerlUpdate=!1,this._localUpdate=!1,this._worldUpdate=!0}_getlocalMatrix(){return this._localUpdate&&(H._createAffineTransformationArray(this._localPosition,this._localRotation,this._localScale,this._localMatrix),this._localUpdate=!1),this._localMatrix}_onWorldTransform(){if(!this._worldUpdate){this._worldUpdate=!0,this.event(t.Event.TRANSFORM_CHANGED);for(var e=0,r=this._children.length;e<r;e++)this._children[e]._onWorldTransform()}}get localPosition(){return this._localPosition}set localPosition(e){this._localPosition=e,this._localUpdate=!0,this._onWorldTransform()}get localRotation(){if(this._localQuaternionUpdate){var e=this._localRotationEuler;S.createFromYawPitchRoll(e.y/it._angleToRandin,e.x/it._angleToRandin,e.z/it._angleToRandin,this._localRotation),this._localQuaternionUpdate=!1}return this._localRotation}set localRotation(e){this._localRotation=e,this._locaEulerlUpdate=!0,this._localQuaternionUpdate=!1,this._localUpdate=!0,this._onWorldTransform()}get localScale(){return this._localScale}set localScale(e){this._localScale=e,this._localUpdate=!0,this._onWorldTransform()}get localRotationEuler(){if(this._locaEulerlUpdate){this._localRotation.getYawPitchRoll(it._tempVector3);var e=it._tempVector3,t=this._localRotationEuler;t.x=e.y*it._angleToRandin,t.y=e.x*it._angleToRandin,t.z=e.z*it._angleToRandin,this._locaEulerlUpdate=!1}return this._localRotationEuler}set localRotationEuler(e){this._localRotationEuler=e,this._locaEulerlUpdate=!1,this._localQuaternionUpdate=!0,this._localUpdate=!0,this._onWorldTransform()}getWorldMatrix(){if(this._worldUpdate){if(null!=this._parent)H.matrix4x4MultiplyFFF(this._parent.getWorldMatrix(),this._getlocalMatrix(),this._worldMatrix);else{var e=this._worldMatrix;e[1]=e[2]=e[3]=e[4]=e[6]=e[7]=e[8]=e[9]=e[11]=e[12]=e[13]=e[14]=0,e[0]=e[5]=e[10]=e[15]=1}this._worldUpdate=!1}return this._worldMatrix}setParent(e){if(this._parent!==e){if(this._parent){var t=this._parent._children,r=t.indexOf(this);t.splice(r,1)}e&&(e._children.push(this),e&&this._onWorldTransform()),this._parent=e}}}it._tempVector3=new n,it._angleToRandin=180/Math.PI;class at{constructor(){this._parent=null,this.name=null,this._worldMatrixIndex=0,this._children=[],this.transform=new it(this)}addChild(e){e._parent=this,e.transform.setParent(this.transform),this._children.push(e)}removeChild(e){var t=this._children.indexOf(e);-1!==t&&this._children.splice(t,1)}getChildByName(e){for(var t=0,r=this._children.length;t<r;t++){var i=this._children[t];if(i.name===e)return i}return null}getChildByIndex(e){return this._children[e]}getChildCount(){return this._children.length}cloneTo(e){var t=e;t.name=this.name;for(var r=0,i=this._children.length;r<i;r++){var a=this._children[r],n=a.clone();t.addChild(n);var s=a.transform,o=n.transform,l=o.localPosition,_=o.localRotation,h=o.localScale;s.localPosition.cloneTo(l),s.localRotation.cloneTo(_),s.localScale.cloneTo(h),o.localPosition=l,o.localRotation=_,o.localScale=h}}clone(){var e=new at;return this.cloneTo(e),e}_cloneNative(e,t,r,i,a,n,s){var o=s._nativeCurCloneCount;a[o]=n;var l=new at;return l._worldMatrixIndex=o,this._cloneToNative(l,e,t,r,i,a,o,s),l}_cloneToNative(e,t,r,i,a,n,s,o){var l=e;l.name=this.name;for(var _=0,h=this._children.length;_<h;_++){var c=this._children[_];o._nativeCurCloneCount++;var d=c._cloneNative(t,r,i,a,n,s,o);l.addChild(d);var u=c.transform,m=d.transform,f=m.localPosition,T=m.localRotation,E=m.localScale;u.localPosition.cloneTo(f),u.localRotation.cloneTo(T),u.localScale.cloneTo(E),m.localPosition=f,m.localRotation=T,m.localScale=E}}}class nt extends t.Resource{constructor(){super(),this._nativeNodeCount=0,this._nativeCurCloneCount=0}static _parse(e,t=null,r=null){var i=new nt;if(i._rootNode=new at,e.version){var a=e.rootNode;a&&i._parseNode(a,i._rootNode)}return i}static load(e,r){t.ILaya.loader.create(e,r,null,nt.AVATAR)}_initCloneToAnimator(e,t){t._avatarNodeMap[e.name]=e;for(var r=0,i=e.getChildCount();r<i;r++)this._initCloneToAnimator(e.getChildByIndex(r),t)}_parseNode(e,t){var r=e.props.name;t.name=r;var i=e.props,a=t.transform,n=a.localPosition,s=a.localRotation,o=a.localScale;n.fromArray(i.translate),s.fromArray(i.rotation),o.fromArray(i.scale),a.localPosition=n,a.localRotation=s,a.localScale=o;for(var l=e.child,_=0,h=l.length;_<h;_++){var c=l[_],d=new at;t.addChild(d),this._parseNode(c,d)}}_cloneDatasToAnimator(e){var t;t=this._rootNode.clone();var r=this._rootNode.transform,i=t.transform,a=i.localPosition,n=i.localRotation,s=i.localScale;r.localPosition.cloneTo(a),r.localRotation.cloneTo(n),r.localScale.cloneTo(s),i.localPosition=a,i.localRotation=n,i.localScale=s,e._avatarNodeMap={},this._initCloneToAnimator(t,e)}cloneTo(e){var t=e,r=this._rootNode.clone();t._rootNode=r}clone(){var e=new nt;return this.cloneTo(e),e}_cloneDatasToAnimatorNative(e){var t=new Float32Array(3*this._nativeNodeCount),r=new Float32Array(4*this._nativeNodeCount),i=new Float32Array(3*this._nativeNodeCount),a=new Float32Array(16*this._nativeNodeCount),n=new Int16Array(this._nativeNodeCount);e._animationNodeLocalPositions=t,e._animationNodeLocalRotations=r,e._animationNodeLocalScales=i,e._animationNodeWorldMatrixs=a,e._animationNodeParentIndices=n,this._nativeCurCloneCount=0;var s=this._rootNode._cloneNative(t,r,i,a,n,-1,this),o=this._rootNode.transform,l=s.transform,_=l.localPosition,h=l.localRotation,c=l.localScale;o.localPosition.cloneTo(_),o.localRotation.cloneTo(h),o.localScale.cloneTo(c),l.localPosition=_,l.localRotation=h,l.localScale=c,e._avatarNodeMap={},this._initCloneToAnimator(s,e)}}nt.AVATAR="AVATAR";class st extends t.Resource{constructor(){super(),this._shaderValues=null,this._shaderValues=new me(this),this.renderQueue=st.RENDERQUEUE_OPAQUE,this._alphaTest=!1}static load(e,r){t.Laya.loader.create(e,r,null,st.MATERIAL)}static __initDefine__(){st.SHADERDEFINE_ALPHATEST=xe.getDefineByName("ALPHATEST")}static _parse(e,r=null,s=null){var o,l=e,_=l.props,h=_.type,c=t.ClassUtils.getRegClass(h);if(!c)throw"_getSprite3DHierarchyInnerUrls 错误: "+e.type+" 不是类";switch(o=new c,l.version){case"LAYAMATERIAL:01":case"LAYAMATERIAL:02":var d,u;for(var m in _)switch(m){case"type":break;case"vectors":var f=_[m];for(d=0,u=f.length;d<u;d++){var T=f[d],E=T.value;switch(E.length){case 2:o[T.name]=new i(E[0],E[1]);break;case 3:o[T.name]=new n(E[0],E[1],E[2]);break;case 4:o[T.name]=new a(E[0],E[1],E[2],E[3]);break;default:throw new Error("BaseMaterial:unkonwn color length.")}}break;case"textures":var p=_[m];for(d=0,u=p.length;d<u;d++){var g=p[d],S=g.path;S&&(o[g.name]=t.Loader.getRes(S))}break;case"defines":var R=_[m];for(d=0,u=R.length;d<u;d++){var v=xe.getDefineByName(R[d]);o._shaderValues.addDefine(v)}break;case"renderStates":var x=_[m][0],A=o;A.blend=x.blend,A.cull=x.cull,A.depthTest=x.depthTest,A.depthWrite=x.depthWrite,A.blendSrc=x.srcBlend,A.blendDst=x.dstBlend;break;case"cull":o.cull=_[m];break;case"blend":o.blend=_[m];break;case"depthWrite":o.depthWrite=_[m];break;case"srcBlend":o.blendSrc=_[m];break;case"dstBlend":o.blendDst=_[m];break;default:o[m]=_[m]}break;default:throw new Error("BaseMaterial:unkonwn version.")}return o}get shaderData(){return this._shaderValues}get alphaTestValue(){return this._shaderValues.getNumber(st.ALPHATESTVALUE)}set alphaTestValue(e){this._shaderValues.setNumber(st.ALPHATESTVALUE,e)}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest=e,e?this._shaderValues.addDefine(st.SHADERDEFINE_ALPHATEST):this._shaderValues.removeDefine(st.SHADERDEFINE_ALPHATEST)}get depthWrite(){return this._shaderValues.getBool(st.DEPTH_WRITE)}set depthWrite(e){this._shaderValues.setBool(st.DEPTH_WRITE,e)}get cull(){return this._shaderValues.getInt(st.CULL)}set cull(e){this._shaderValues.setInt(st.CULL,e)}get blend(){return this._shaderValues.getInt(st.BLEND)}set blend(e){this._shaderValues.setInt(st.BLEND,e)}get blendSrc(){return this._shaderValues.getInt(st.BLEND_SRC)}set blendSrc(e){this._shaderValues.setInt(st.BLEND_SRC,e)}get blendDst(){return this._shaderValues.getInt(st.BLEND_DST)}set blendDst(e){this._shaderValues.setInt(st.BLEND_DST,e)}get depthTest(){return this._shaderValues.getInt(st.DEPTH_TEST)}set depthTest(e){this._shaderValues.setInt(st.DEPTH_TEST,e)}_removeTetxureReference(){var e=this._shaderValues.getData();for(var r in e){var i=e[r];i&&i instanceof t.BaseTexture&&i._removeReference()}}_disposeResource(){this._referenceCount>0&&this._removeTetxureReference(),this._shaderValues=null}_addReference(e=1){super._addReference(e);var r=this._shaderValues.getData();for(var i in r){var a=r[i];a&&a instanceof t.BaseTexture&&a._addReference()}}_removeReference(e=1){super._removeReference(e),this._removeTetxureReference()}setShaderName(e){if(this._shader=xe.find(e),!this._shader)throw new Error("BaseMaterial: unknown shader name.")}cloneTo(e){var t=e;t.name=this.name,t.renderQueue=this.renderQueue,this._shaderValues.cloneTo(t._shaderValues)}clone(){var e=new st;return this.cloneTo(e),e}get _defineDatas(){return this._shaderValues._defineDatas}}st.MATERIAL="MATERIAL",st.RENDERQUEUE_OPAQUE=2e3,st.RENDERQUEUE_ALPHATEST=2450,st.RENDERQUEUE_TRANSPARENT=3e3,st.ALPHATESTVALUE=xe.propertyNameToID("u_AlphaTestValue"),st.CULL=xe.propertyNameToID("s_Cull"),st.BLEND=xe.propertyNameToID("s_Blend"),st.BLEND_SRC=xe.propertyNameToID("s_BlendSrc"),st.BLEND_DST=xe.propertyNameToID("s_BlendDst"),st.DEPTH_TEST=xe.propertyNameToID("s_DepthTest"),st.DEPTH_WRITE=xe.propertyNameToID("s_DepthWrite"),st.SHADERDEFINE_ALPHATEST=null;class ot{static load(e,r){t.Laya.loader.create(e,r,null,st.MATERIAL)}static __initDefine__(){ot.SHADERDEFINE_ALPHATEST=st.SHADERDEFINE_ALPHATEST}}ot.MATERIAL="MATERIAL",ot.RENDERQUEUE_OPAQUE=2e3,ot.RENDERQUEUE_ALPHATEST=2450,ot.RENDERQUEUE_TRANSPARENT=3e3,ot.ALPHATESTVALUE=xe.propertyNameToID("u_AlphaTestValue"),ot.SHADERDEFINE_ALPHATEST=null;class lt{constructor(){this.cull=lt.CULL_BACK,this.blend=lt.BLEND_DISABLE,this.srcBlend=lt.BLENDPARAM_ONE,this.dstBlend=lt.BLENDPARAM_ZERO,this.srcBlendRGB=lt.BLENDPARAM_ONE,this.dstBlendRGB=lt.BLENDPARAM_ZERO,this.srcBlendAlpha=lt.BLENDPARAM_ONE,this.dstBlendAlpha=lt.BLENDPARAM_ZERO,this.blendConstColor=new a(1,1,1,1),this.blendEquation=lt.BLENDEQUATION_ADD,this.blendEquationRGB=lt.BLENDEQUATION_ADD,this.blendEquationAlpha=lt.BLENDEQUATION_ADD,this.depthTest=lt.DEPTHTEST_LEQUAL,this.depthWrite=!0}cloneTo(e){var t=e;t.cull=this.cull,t.blend=this.blend,t.srcBlend=this.srcBlend,t.dstBlend=this.dstBlend,t.srcBlendRGB=this.srcBlendRGB,t.dstBlendRGB=this.dstBlendRGB,t.srcBlendAlpha=this.srcBlendAlpha,t.dstBlendAlpha=this.dstBlendAlpha,this.blendConstColor.cloneTo(t.blendConstColor),t.blendEquation=this.blendEquation,t.blendEquationRGB=this.blendEquationRGB,t.blendEquationAlpha=this.blendEquationAlpha,t.depthTest=this.depthTest,t.depthWrite=this.depthWrite}clone(){var e=new lt;return this.cloneTo(e),e}}lt.CULL_NONE=0,lt.CULL_FRONT=1,lt.CULL_BACK=2,lt.BLEND_DISABLE=0,lt.BLEND_ENABLE_ALL=1,lt.BLEND_ENABLE_SEPERATE=2,lt.BLENDPARAM_ZERO=0,lt.BLENDPARAM_ONE=1,lt.BLENDPARAM_SRC_COLOR=768,lt.BLENDPARAM_ONE_MINUS_SRC_COLOR=769,lt.BLENDPARAM_DST_COLOR=774,lt.BLENDPARAM_ONE_MINUS_DST_COLOR=775,lt.BLENDPARAM_SRC_ALPHA=770,lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA=771,lt.BLENDPARAM_DST_ALPHA=772,lt.BLENDPARAM_ONE_MINUS_DST_ALPHA=773,lt.BLENDPARAM_SRC_ALPHA_SATURATE=776,lt.BLENDEQUATION_ADD=32774,lt.BLENDEQUATION_SUBTRACT=32778,lt.BLENDEQUATION_REVERSE_SUBTRACT=32779,lt.DEPTHTEST_OFF=0,lt.DEPTHTEST_NEVER=512,lt.DEPTHTEST_LESS=513,lt.DEPTHTEST_EQUAL=514,lt.DEPTHTEST_LEQUAL=515,lt.DEPTHTEST_GREATER=516,lt.DEPTHTEST_NOTEQUAL=517,lt.DEPTHTEST_GEQUAL=518,lt.DEPTHTEST_ALWAYS=519;class _t extends st{constructor(){super(),this._enableVertexColor=!1,this.setShaderName("BLINNPHONG"),this._albedoIntensity=1,this._albedoColor=new a(1,1,1,1);var e=this._shaderValues;e.setVector(_t.ALBEDOCOLOR,new a(1,1,1,1)),e.setVector(_t.MATERIALSPECULAR,new a(1,1,1,1)),e.setNumber(_t.SHININESS,.078125),e.setNumber(st.ALPHATESTVALUE,.5),e.setVector(_t.TILINGOFFSET,new a(1,1,0,0)),this._enableLighting=!0,this.renderMode=_t.RENDERMODE_OPAQUE}static __initDefine__(){_t.SHADERDEFINE_DIFFUSEMAP=xe.getDefineByName("DIFFUSEMAP"),_t.SHADERDEFINE_NORMALMAP=xe.getDefineByName("NORMALMAP"),_t.SHADERDEFINE_SPECULARMAP=xe.getDefineByName("SPECULARMAP"),_t.SHADERDEFINE_TILINGOFFSET=xe.getDefineByName("TILINGOFFSET"),_t.SHADERDEFINE_ENABLEVERTEXCOLOR=xe.getDefineByName("ENABLEVERTEXCOLOR")}get _ColorR(){return this._albedoColor.x}set _ColorR(e){this._albedoColor.x=e,this.albedoColor=this._albedoColor}get _ColorG(){return this._albedoColor.y}set _ColorG(e){this._albedoColor.y=e,this.albedoColor=this._albedoColor}get _ColorB(){return this._albedoColor.z}set _ColorB(e){this._albedoColor.z=e,this.albedoColor=this._albedoColor}get _ColorA(){return this._albedoColor.w}set _ColorA(e){this._albedoColor.w=e,this.albedoColor=this._albedoColor}get _Color(){return this._shaderValues.getVector(_t.ALBEDOCOLOR)}set _Color(e){this.albedoColor=e}get _SpecColorR(){return this._shaderValues.getVector(_t.MATERIALSPECULAR).x}set _SpecColorR(e){this._shaderValues.getVector(_t.MATERIALSPECULAR).x=e}get _SpecColorG(){return this._shaderValues.getVector(_t.MATERIALSPECULAR).y}set _SpecColorG(e){this._shaderValues.getVector(_t.MATERIALSPECULAR).y=e}get _SpecColorB(){return this._shaderValues.getVector(_t.MATERIALSPECULAR).z}set _SpecColorB(e){this._shaderValues.getVector(_t.MATERIALSPECULAR).z=e}get _SpecColorA(){return this._shaderValues.getVector(_t.MATERIALSPECULAR).w}set _SpecColorA(e){this._shaderValues.getVector(_t.MATERIALSPECULAR).w=e}get _SpecColor(){return this._shaderValues.getVector(_t.MATERIALSPECULAR)}set _SpecColor(e){this.specularColor=e}get _AlbedoIntensity(){return this._albedoIntensity}set _AlbedoIntensity(e){if(this._albedoIntensity!==e){var t=this._shaderValues.getVector(_t.ALBEDOCOLOR);a.scale(this._albedoColor,e,t),this._albedoIntensity=e,this._shaderValues.setVector(_t.ALBEDOCOLOR,t)}}get _Shininess(){return this._shaderValues.getNumber(_t.SHININESS)}set _Shininess(e){e=Math.max(0,Math.min(1,e)),this._shaderValues.setNumber(_t.SHININESS,e)}get _MainTex_STX(){return this._shaderValues.getVector(_t.TILINGOFFSET).x}set _MainTex_STX(e){var t=this._shaderValues.getVector(_t.TILINGOFFSET);t.x=e,this.tilingOffset=t}get _MainTex_STY(){return this._shaderValues.getVector(_t.TILINGOFFSET).y}set _MainTex_STY(e){var t=this._shaderValues.getVector(_t.TILINGOFFSET);t.y=e,this.tilingOffset=t}get _MainTex_STZ(){return this._shaderValues.getVector(_t.TILINGOFFSET).z}set _MainTex_STZ(e){var t=this._shaderValues.getVector(_t.TILINGOFFSET);t.z=e,this.tilingOffset=t}get _MainTex_STW(){return this._shaderValues.getVector(_t.TILINGOFFSET).w}set _MainTex_STW(e){var t=this._shaderValues.getVector(_t.TILINGOFFSET);t.w=e,this.tilingOffset=t}get _MainTex_ST(){return this._shaderValues.getVector(_t.TILINGOFFSET)}set _MainTex_ST(e){this.tilingOffset=e}get _Cutoff(){return this.alphaTestValue}set _Cutoff(e){this.alphaTestValue=e}set renderMode(e){switch(e){case _t.RENDERMODE_OPAQUE:this.alphaTest=!1,this.renderQueue=st.RENDERQUEUE_OPAQUE,this.depthWrite=!0,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_DISABLE,this.depthTest=lt.DEPTHTEST_LESS;break;case _t.RENDERMODE_CUTOUT:this.renderQueue=st.RENDERQUEUE_ALPHATEST,this.alphaTest=!0,this.depthWrite=!0,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_DISABLE,this.depthTest=lt.DEPTHTEST_LESS;break;case _t.RENDERMODE_TRANSPARENT:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.alphaTest=!1,this.depthWrite=!1,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA,this.depthTest=lt.DEPTHTEST_LESS;break;default:throw new Error("Material:renderMode value error.")}}get enableVertexColor(){return this._enableVertexColor}set enableVertexColor(e){this._enableVertexColor=e,e?this._shaderValues.addDefine(_t.SHADERDEFINE_ENABLEVERTEXCOLOR):this._shaderValues.removeDefine(_t.SHADERDEFINE_ENABLEVERTEXCOLOR)}get tilingOffsetX(){return this._MainTex_STX}set tilingOffsetX(e){this._MainTex_STX=e}get tilingOffsetY(){return this._MainTex_STY}set tilingOffsetY(e){this._MainTex_STY=e}get tilingOffsetZ(){return this._MainTex_STZ}set tilingOffsetZ(e){this._MainTex_STZ=e}get tilingOffsetW(){return this._MainTex_STW}set tilingOffsetW(e){this._MainTex_STW=e}get tilingOffset(){return this._shaderValues.getVector(_t.TILINGOFFSET)}set tilingOffset(e){e&&(1!=e.x||1!=e.y||0!=e.z||0!=e.w)?this._shaderValues.addDefine(_t.SHADERDEFINE_TILINGOFFSET):this._shaderValues.removeDefine(_t.SHADERDEFINE_TILINGOFFSET),this._shaderValues.setVector(_t.TILINGOFFSET,e)}get albedoColorR(){return this._ColorR}set albedoColorR(e){this._ColorR=e}get albedoColorG(){return this._ColorG}set albedoColorG(e){this._ColorG=e}get albedoColorB(){return this._ColorB}set albedoColorB(e){this._ColorB=e}get albedoColorA(){return this._ColorA}set albedoColorA(e){this._ColorA=e}get albedoColor(){return this._albedoColor}set albedoColor(e){var t=this._shaderValues.getVector(_t.ALBEDOCOLOR);a.scale(e,this._albedoIntensity,t),this._albedoColor=e,this._shaderValues.setVector(_t.ALBEDOCOLOR,t)}get albedoIntensity(){return this._albedoIntensity}set albedoIntensity(e){this._AlbedoIntensity=e}get specularColorR(){return this._SpecColorR}set specularColorR(e){this._SpecColorR=e}get specularColorG(){return this._SpecColorG}set specularColorG(e){this._SpecColorG=e}get specularColorB(){return this._SpecColorB}set specularColorB(e){this._SpecColorB=e}get specularColorA(){return this._SpecColorA}set specularColorA(e){this._SpecColorA=e}get specularColor(){return this._shaderValues.getVector(_t.MATERIALSPECULAR)}set specularColor(e){this._shaderValues.setVector(_t.MATERIALSPECULAR,e)}get shininess(){return this._Shininess}set shininess(e){this._Shininess=e}get albedoTexture(){return this._shaderValues.getTexture(_t.ALBEDOTEXTURE)}set albedoTexture(e){e?this._shaderValues.addDefine(_t.SHADERDEFINE_DIFFUSEMAP):this._shaderValues.removeDefine(_t.SHADERDEFINE_DIFFUSEMAP),this._shaderValues.setTexture(_t.ALBEDOTEXTURE,e)}get normalTexture(){return this._shaderValues.getTexture(_t.NORMALTEXTURE)}set normalTexture(e){e?this._shaderValues.addDefine(_t.SHADERDEFINE_NORMALMAP):this._shaderValues.removeDefine(_t.SHADERDEFINE_NORMALMAP),this._shaderValues.setTexture(_t.NORMALTEXTURE,e)}get specularTexture(){return this._shaderValues.getTexture(_t.SPECULARTEXTURE)}set specularTexture(e){e?this._shaderValues.addDefine(_t.SHADERDEFINE_SPECULARMAP):this._shaderValues.removeDefine(_t.SHADERDEFINE_SPECULARMAP),this._shaderValues.setTexture(_t.SPECULARTEXTURE,e)}clone(){var e=new _t;return this.cloneTo(e),e}cloneTo(e){super.cloneTo(e);var t=e;t._enableLighting=this._enableLighting,t._albedoIntensity=this._albedoIntensity,t._enableVertexColor=this._enableVertexColor,this._albedoColor.cloneTo(t._albedoColor)}}_t.RENDERMODE_OPAQUE=0,_t.RENDERMODE_CUTOUT=1,_t.RENDERMODE_TRANSPARENT=2,_t.ALBEDOTEXTURE=xe.propertyNameToID("u_DiffuseTexture"),_t.NORMALTEXTURE=xe.propertyNameToID("u_NormalTexture"),_t.SPECULARTEXTURE=xe.propertyNameToID("u_SpecularTexture"),_t.ALBEDOCOLOR=xe.propertyNameToID("u_DiffuseColor"),_t.MATERIALSPECULAR=xe.propertyNameToID("u_MaterialSpecular"),_t.SHININESS=xe.propertyNameToID("u_Shininess"),_t.TILINGOFFSET=xe.propertyNameToID("u_TilingOffset");class ht extends st{constructor(){super(),this.setShaderName("Effect"),this._color=new a(1,1,1,1),this._shaderValues.setVector(ht.TINTCOLOR,new a(1,1,1,1)),this.renderMode=ht.RENDERMODE_ADDTIVE}static __initDefine__(){ht.SHADERDEFINE_MAINTEXTURE=xe.getDefineByName("MAINTEXTURE"),ht.SHADERDEFINE_TILINGOFFSET=xe.getDefineByName("TILINGOFFSET"),ht.SHADERDEFINE_ADDTIVEFOG=xe.getDefineByName("ADDTIVEFOG")}get _TintColorR(){return this._color.x}set _TintColorR(e){this._color.x=e,this.color=this._color}get _TintColorG(){return this._color.y}set _TintColorG(e){this._color.y=e,this.color=this._color}get _TintColorB(){return this._color.z}set _TintColorB(e){this._color.z=e,this.color=this._color}get _TintColorA(){return this._color.w}set _TintColorA(e){this._color.w=e,this.color=this._color}get _TintColor(){return this._shaderValues.getVector(ht.TINTCOLOR)}set _TintColor(e){this.color=e}get _MainTex_STX(){return this._shaderValues.getVector(ht.TILINGOFFSET).x}set _MainTex_STX(e){var t=this._shaderValues.getVector(ht.TILINGOFFSET);t.x=e,this.tilingOffset=t}get _MainTex_STY(){return this._shaderValues.getVector(ht.TILINGOFFSET).y}set _MainTex_STY(e){var t=this._shaderValues.getVector(ht.TILINGOFFSET);t.y=e,this.tilingOffset=t}get _MainTex_STZ(){return this._shaderValues.getVector(ht.TILINGOFFSET).z}set _MainTex_STZ(e){var t=this._shaderValues.getVector(ht.TILINGOFFSET);t.z=e,this.tilingOffset=t}get _MainTex_STW(){return this._shaderValues.getVector(ht.TILINGOFFSET).w}set _MainTex_STW(e){var t=this._shaderValues.getVector(ht.TILINGOFFSET);t.w=e,this.tilingOffset=t}get _MainTex_ST(){return this._shaderValues.getVector(ht.TILINGOFFSET)}set _MainTex_ST(e){this.tilingOffset=e}set renderMode(e){switch(e){case ht.RENDERMODE_ADDTIVE:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.alphaTest=!1,this.depthWrite=!1,this.cull=lt.CULL_NONE,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE,this.depthTest=lt.DEPTHTEST_LESS,this._shaderValues.addDefine(ht.SHADERDEFINE_ADDTIVEFOG);break;case ht.RENDERMODE_ALPHABLENDED:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.alphaTest=!1,this.depthWrite=!1,this.cull=lt.CULL_NONE,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA,this.depthTest=lt.DEPTHTEST_LESS,this._shaderValues.removeDefine(ht.SHADERDEFINE_ADDTIVEFOG);break;default:throw new Error("MeshEffectMaterial : renderMode value error.")}}get colorR(){return this._TintColorR}set colorR(e){this._TintColorR=e}get colorG(){return this._TintColorG}set colorG(e){this._TintColorG=e}get colorB(){return this._TintColorB}set colorB(e){this._TintColorB=e}get colorA(){return this._TintColorA}set colorA(e){this._TintColorA=e}get color(){return this._shaderValues.getVector(ht.TINTCOLOR)}set color(e){this._shaderValues.setVector(ht.TINTCOLOR,e)}get texture(){return this._shaderValues.getTexture(ht.MAINTEXTURE)}set texture(e){e?this._shaderValues.addDefine(ht.SHADERDEFINE_MAINTEXTURE):this._shaderValues.removeDefine(ht.SHADERDEFINE_MAINTEXTURE),this._shaderValues.setTexture(ht.MAINTEXTURE,e)}get tilingOffsetX(){return this._MainTex_STX}set tilingOffsetX(e){this._MainTex_STX=e}get tilingOffsetY(){return this._MainTex_STY}set tilingOffsetY(e){this._MainTex_STY=e}get tilingOffsetZ(){return this._MainTex_STZ}set tilingOffsetZ(e){this._MainTex_STZ=e}get tilingOffsetW(){return this._MainTex_STW}set tilingOffsetW(e){this._MainTex_STW=e}get tilingOffset(){return this._shaderValues.getVector(ht.TILINGOFFSET)}set tilingOffset(e){e&&(1!=e.x||1!=e.y||0!=e.z||0!=e.w)?this._shaderValues.addDefine(ht.SHADERDEFINE_TILINGOFFSET):this._shaderValues.removeDefine(ht.SHADERDEFINE_TILINGOFFSET),this._shaderValues.setVector(ht.TILINGOFFSET,e)}clone(){var e=new ht;return this.cloneTo(e),e}}ht.RENDERMODE_ADDTIVE=0,ht.RENDERMODE_ALPHABLENDED=1,ht.MAINTEXTURE=xe.propertyNameToID("u_AlbedoTexture"),ht.TINTCOLOR=xe.propertyNameToID("u_AlbedoColor"),ht.TILINGOFFSET=xe.propertyNameToID("u_TilingOffset");class ct extends st{constructor(){super(),this._enableLighting=!0,this.setShaderName("ExtendTerrain"),this.renderMode=ct.RENDERMODE_OPAQUE}static __initDefine__(){ct.SHADERDEFINE_DETAIL_NUM1=xe.getDefineByName("ExtendTerrain_DETAIL_NUM1"),ct.SHADERDEFINE_DETAIL_NUM2=xe.getDefineByName("ExtendTerrain_DETAIL_NUM2"),ct.SHADERDEFINE_DETAIL_NUM3=xe.getDefineByName("ExtendTerrain_DETAIL_NUM3"),ct.SHADERDEFINE_DETAIL_NUM4=xe.getDefineByName("ExtendTerrain_DETAIL_NUM4"),ct.SHADERDEFINE_DETAIL_NUM5=xe.getDefineByName("ExtendTerrain_DETAIL_NUM5")}get splatAlphaTexture(){return this._shaderValues.getTexture(ct.SPLATALPHATEXTURE)}set splatAlphaTexture(e){this._shaderValues.setTexture(ct.SPLATALPHATEXTURE,e)}get diffuseTexture1(){return this._shaderValues.getTexture(ct.DIFFUSETEXTURE1)}set diffuseTexture1(e){this._shaderValues.setTexture(ct.DIFFUSETEXTURE1,e),this._setDetailNum(1)}get diffuseTexture2(){return this._shaderValues.getTexture(ct.DIFFUSETEXTURE2)}set diffuseTexture2(e){this._shaderValues.setTexture(ct.DIFFUSETEXTURE2,e),this._setDetailNum(2)}get diffuseTexture3(){return this._shaderValues.getTexture(ct.DIFFUSETEXTURE3)}set diffuseTexture3(e){this._shaderValues.setTexture(ct.DIFFUSETEXTURE3,e),this._setDetailNum(3)}get diffuseTexture4(){return this._shaderValues.getTexture(ct.DIFFUSETEXTURE4)}set diffuseTexture4(e){this._shaderValues.setTexture(ct.DIFFUSETEXTURE4,e),this._setDetailNum(4)}get diffuseTexture5(){return this._shaderValues.getTexture(ct.DIFFUSETEXTURE5)}set diffuseTexture5(e){this._shaderValues.setTexture(ct.DIFFUSETEXTURE5,e),this._setDetailNum(5)}set diffuseScaleOffset1(e){this._shaderValues.setVector(ct.DIFFUSESCALEOFFSET1,e)}set diffuseScaleOffset2(e){this._shaderValues.setVector(ct.DIFFUSESCALEOFFSET2,e)}set diffuseScaleOffset3(e){this._shaderValues.setVector(ct.DIFFUSESCALEOFFSET3,e)}set diffuseScaleOffset4(e){this._shaderValues.setVector(ct.DIFFUSESCALEOFFSET4,e)}set diffuseScaleOffset5(e){this._shaderValues.setVector(ct.DIFFUSESCALEOFFSET5,e)}set renderMode(e){switch(e){case ct.RENDERMODE_OPAQUE:this.renderQueue=st.RENDERQUEUE_OPAQUE,this.depthWrite=!0,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_DISABLE,this.depthTest=lt.DEPTHTEST_LESS;break;case ct.RENDERMODE_TRANSPARENT:this.renderQueue=st.RENDERQUEUE_OPAQUE,this.depthWrite=!1,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA,this.depthTest=lt.DEPTHTEST_LEQUAL;break;default:throw new Error("ExtendTerrainMaterial:renderMode value error.")}}_setDetailNum(e){switch(e){case 1:this._shaderValues.addDefine(ct.SHADERDEFINE_DETAIL_NUM1),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM2),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM3),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM4),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM5);break;case 2:this._shaderValues.addDefine(ct.SHADERDEFINE_DETAIL_NUM2),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM1),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM3),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM4),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM5);break;case 3:this._shaderValues.addDefine(ct.SHADERDEFINE_DETAIL_NUM3),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM1),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM2),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM4),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM5);break;case 4:this._shaderValues.addDefine(ct.SHADERDEFINE_DETAIL_NUM4),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM1),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM2),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM3),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM5);break;case 5:this._shaderValues.addDefine(ct.SHADERDEFINE_DETAIL_NUM5),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM1),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM2),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM3),this._shaderValues.removeDefine(ct.SHADERDEFINE_DETAIL_NUM4)}}clone(){var e=new ct;return this.cloneTo(e),e}}ct.RENDERMODE_OPAQUE=1,ct.RENDERMODE_TRANSPARENT=2,ct.SPLATALPHATEXTURE=xe.propertyNameToID("u_SplatAlphaTexture"),ct.DIFFUSETEXTURE1=xe.propertyNameToID("u_DiffuseTexture1"),ct.DIFFUSETEXTURE2=xe.propertyNameToID("u_DiffuseTexture2"),ct.DIFFUSETEXTURE3=xe.propertyNameToID("u_DiffuseTexture3"),ct.DIFFUSETEXTURE4=xe.propertyNameToID("u_DiffuseTexture4"),ct.DIFFUSETEXTURE5=xe.propertyNameToID("u_DiffuseTexture5"),ct.DIFFUSESCALEOFFSET1=xe.propertyNameToID("u_DiffuseScaleOffset1"),ct.DIFFUSESCALEOFFSET2=xe.propertyNameToID("u_DiffuseScaleOffset2"),ct.DIFFUSESCALEOFFSET3=xe.propertyNameToID("u_DiffuseScaleOffset3"),ct.DIFFUSESCALEOFFSET4=xe.propertyNameToID("u_DiffuseScaleOffset4"),ct.DIFFUSESCALEOFFSET5=xe.propertyNameToID("u_DiffuseScaleOffset5"),(E=e.PBRRenderMode||(e.PBRRenderMode={}))[E.Opaque=0]="Opaque",E[E.Cutout=1]="Cutout",E[E.Fade=2]="Fade",E[E.Transparent=3]="Transparent";class dt extends st{constructor(){super(),this._enableEmission=!1,this._shaderValues.setVector(dt.ALBEDOCOLOR,new a(1,1,1,1)),this._shaderValues.setVector(dt.EMISSIONCOLOR,new a(1,1,1,1)),this._shaderValues.setNumber(dt.SMOOTHNESS,.5),this._shaderValues.setNumber(dt.SMOOTHNESSSCALE,1),this._shaderValues.setNumber(dt.OCCLUSIONSTRENGTH,1),this._shaderValues.setNumber(dt.NORMALSCALE,1),this._shaderValues.setNumber(dt.PARALLAXSCALE,.001),this._shaderValues.setNumber(st.ALPHATESTVALUE,.5),this.renderMode=e.PBRRenderMode.Opaque}static __init__(){dt.SHADERDEFINE_ALBEDOTEXTURE=xe.getDefineByName("ALBEDOTEXTURE"),dt.SHADERDEFINE_NORMALTEXTURE=xe.getDefineByName("NORMALTEXTURE"),dt.SHADERDEFINE_PARALLAXTEXTURE=xe.getDefineByName("PARALLAXTEXTURE"),dt.SHADERDEFINE_OCCLUSIONTEXTURE=xe.getDefineByName("OCCLUSIONTEXTURE"),dt.SHADERDEFINE_EMISSION=xe.getDefineByName("EMISSION"),dt.SHADERDEFINE_EMISSIONTEXTURE=xe.getDefineByName("EMISSIONTEXTURE"),dt.SHADERDEFINE_TILINGOFFSET=xe.getDefineByName("TILINGOFFSET"),dt.SHADERDEFINE_TRANSPARENTBLEND=xe.getDefineByName("TRANSPARENTBLEND"),dt.SHADERDEFINE_LAYA_PBR_BRDF_HIGH=xe.getDefineByName("LAYA_PBR_BRDF_HIGH"),dt.SHADERDEFINE_LAYA_PBR_BRDF_LOW=xe.getDefineByName("LAYA_PBR_BRDF_LOW")}get albedoColor(){return this._shaderValues.getVector(dt.ALBEDOCOLOR)}set albedoColor(e){this._shaderValues.setVector(dt.ALBEDOCOLOR,e)}get albedoTexture(){return this._shaderValues.getTexture(dt.ALBEDOTEXTURE)}set albedoTexture(e){e?this._shaderValues.addDefine(dt.SHADERDEFINE_ALBEDOTEXTURE):this._shaderValues.removeDefine(dt.SHADERDEFINE_ALBEDOTEXTURE),this._shaderValues.setTexture(dt.ALBEDOTEXTURE,e)}get normalTexture(){return this._shaderValues.getTexture(dt.NORMALTEXTURE)}set normalTexture(e){e?this._shaderValues.addDefine(dt.SHADERDEFINE_NORMALTEXTURE):this._shaderValues.removeDefine(dt.SHADERDEFINE_NORMALTEXTURE),this._shaderValues.setTexture(dt.NORMALTEXTURE,e)}get normalTextureScale(){return this._shaderValues.getNumber(dt.NORMALSCALE)}set normalTextureScale(e){this._shaderValues.setNumber(dt.NORMALSCALE,e)}get parallaxTexture(){return this._shaderValues.getTexture(dt.PARALLAXTEXTURE)}set parallaxTexture(e){e?this._shaderValues.addDefine(dt.SHADERDEFINE_PARALLAXTEXTURE):this._shaderValues.removeDefine(dt.SHADERDEFINE_PARALLAXTEXTURE),this._shaderValues.setTexture(dt.PARALLAXTEXTURE,e)}get parallaxTextureScale(){return this._shaderValues.getNumber(dt.PARALLAXSCALE)}set parallaxTextureScale(e){this._shaderValues.setNumber(dt.PARALLAXSCALE,Math.max(.005,Math.min(.08,e)))}get occlusionTexture(){return this._shaderValues.getTexture(dt.OCCLUSIONTEXTURE)}set occlusionTexture(e){e?this._shaderValues.addDefine(dt.SHADERDEFINE_OCCLUSIONTEXTURE):this._shaderValues.removeDefine(dt.SHADERDEFINE_OCCLUSIONTEXTURE),this._shaderValues.setTexture(dt.OCCLUSIONTEXTURE,e)}get occlusionTextureStrength(){return this._shaderValues.getNumber(dt.OCCLUSIONSTRENGTH)}set occlusionTextureStrength(e){this._shaderValues.setNumber(dt.OCCLUSIONSTRENGTH,Math.max(0,Math.min(1,e)))}get smoothness(){return this._shaderValues.getNumber(dt.SMOOTHNESS)}set smoothness(e){this._shaderValues.setNumber(dt.SMOOTHNESS,Math.max(0,Math.min(1,e)))}get smoothnessTextureScale(){return this._shaderValues.getNumber(dt.SMOOTHNESSSCALE)}set smoothnessTextureScale(e){this._shaderValues.setNumber(dt.SMOOTHNESSSCALE,Math.max(0,Math.min(1,e)))}get enableEmission(){return this._enableEmission}set enableEmission(e){e?this._shaderValues.addDefine(dt.SHADERDEFINE_EMISSION):this._shaderValues.removeDefine(dt.SHADERDEFINE_EMISSION),this._enableEmission=e}get emissionColor(){return this._shaderValues.getVector(dt.EMISSIONCOLOR)}set emissionColor(e){this._shaderValues.setVector(dt.EMISSIONCOLOR,e)}get emissionTexture(){return this._shaderValues.getTexture(dt.EMISSIONTEXTURE)}set emissionTexture(e){e?this._shaderValues.addDefine(dt.SHADERDEFINE_EMISSIONTEXTURE):this._shaderValues.removeDefine(dt.SHADERDEFINE_EMISSIONTEXTURE),this._shaderValues.setTexture(dt.EMISSIONTEXTURE,e)}get tilingOffset(){return this._shaderValues.getVector(dt.TILINGOFFSET)}set tilingOffset(e){e&&(1!=e.x||1!=e.y||0!=e.z||0!=e.w)?this._shaderValues.addDefine(dt.SHADERDEFINE_TILINGOFFSET):this._shaderValues.removeDefine(dt.SHADERDEFINE_TILINGOFFSET),this._shaderValues.setVector(dt.TILINGOFFSET,e)}set renderMode(t){switch(t){case e.PBRRenderMode.Opaque:this.alphaTest=!1,this.renderQueue=st.RENDERQUEUE_OPAQUE,this.depthWrite=!0,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_DISABLE,this.depthTest=lt.DEPTHTEST_LESS,this._shaderValues.removeDefine(dt.SHADERDEFINE_TRANSPARENTBLEND);break;case e.PBRRenderMode.Cutout:this.renderQueue=st.RENDERQUEUE_ALPHATEST,this.alphaTest=!0,this.depthWrite=!0,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_DISABLE,this.depthTest=lt.DEPTHTEST_LESS,this._shaderValues.removeDefine(dt.SHADERDEFINE_TRANSPARENTBLEND);break;case e.PBRRenderMode.Fade:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.alphaTest=!1,this.depthWrite=!1,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA,this.depthTest=lt.DEPTHTEST_LESS,this._shaderValues.removeDefine(dt.SHADERDEFINE_TRANSPARENTBLEND);break;case e.PBRRenderMode.Transparent:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.alphaTest=!1,this.depthWrite=!1,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_ONE,this.blendDst=lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA,this.depthTest=lt.DEPTHTEST_LESS,this._shaderValues.addDefine(dt.SHADERDEFINE_TRANSPARENTBLEND);break;default:throw new Error("PBRMaterial:unknown renderMode value.")}}get enableReflection(){return!0}set enableReflection(e){}}dt.ALBEDOTEXTURE=xe.propertyNameToID("u_AlbedoTexture"),dt.ALBEDOCOLOR=xe.propertyNameToID("u_AlbedoColor"),dt.TILINGOFFSET=xe.propertyNameToID("u_TilingOffset"),dt.NORMALTEXTURE=xe.propertyNameToID("u_NormalTexture"),dt.NORMALSCALE=xe.propertyNameToID("u_NormalScale"),dt.SMOOTHNESS=xe.propertyNameToID("u_Smoothness"),dt.SMOOTHNESSSCALE=xe.propertyNameToID("u_SmoothnessScale"),dt.OCCLUSIONTEXTURE=xe.propertyNameToID("u_OcclusionTexture"),dt.OCCLUSIONSTRENGTH=xe.propertyNameToID("u_occlusionStrength"),dt.PARALLAXTEXTURE=xe.propertyNameToID("u_ParallaxTexture"),dt.PARALLAXSCALE=xe.propertyNameToID("u_ParallaxScale"),dt.EMISSIONTEXTURE=xe.propertyNameToID("u_EmissionTexture"),dt.EMISSIONCOLOR=xe.propertyNameToID("u_EmissionColor"),dt.renderQuality=e.PBRRenderQuality.High;var ut,mt,ft,Tt,Et,pt='#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n\r\n#include "Lighting.glsl";\r\n\r\nattribute vec4 a_Position;\r\nattribute vec3 a_Normal;\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_WorldMat;\r\n#else\r\n\tuniform mat4 u_WorldMat;\r\n#endif\r\n\r\nuniform mat4 u_ViewProjection;\r\nuniform vec4 u_ProjectionParams;\r\n\r\n//传入法线\r\nvarying vec4 depthNormals;\r\n\r\n\r\nvec4 depthNormalsVertex()\r\n{\r\n\tmat4 worldMat;\r\n\t#ifdef GPU_INSTANCE\r\n\t\tworldMat = a_WorldMat;\r\n\t#else\r\n\t\tworldMat = u_WorldMat;\r\n\t#endif\r\n\t\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform;\r\n\t \t#ifdef SIMPLEBONE\r\n\t\t\tfloat currentPixelPos;\r\n\t\t\t#ifdef GPU_INSTANCE\r\n\t\t\t\tcurrentPixelPos = a_SimpleTextureParams.x+a_SimpleTextureParams.y;\r\n\t\t\t#else\r\n\t\t\t\tcurrentPixelPos = u_SimpleAnimatorParams.x+u_SimpleAnimatorParams.y;\r\n\t\t\t#endif\r\n\t\t\tfloat offset = 1.0/u_SimpleAnimatorTextureSize;\r\n\t\t\tskinTransform = loadMatFromTexture(currentPixelPos,int(a_BoneIndices.x),offset) * a_BoneWeights.x;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.y),offset) * a_BoneWeights.y;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.z),offset) * a_BoneWeights.z;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.w),offset) * a_BoneWeights.w;\r\n\t\t#else\r\n\t\t\tskinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\t#endif\r\n\t\tworldMat = worldMat * skinTransform;\r\n\t#endif\r\n\r\n\tvec4 positionWS = worldMat * a_Position;\r\n\r\n\tmat3 worldInvMat;\r\n\t#ifdef BONE\r\n\t\tworldInvMat=INVERSE_MAT(mat3(worldMat*skinTransform));\r\n\t#else\r\n\t\tworldInvMat=INVERSE_MAT(mat3(worldMat));\r\n\t#endif \r\n\r\n\tvec3 normalWS = normalize(a_Normal*worldInvMat);//if no normalize will cause precision problem\r\n\r\n\tdepthNormals.xyz = normalWS;\r\n\tvec4 positionCS = u_ViewProjection * positionWS;\r\n\tdepthNormals.w = (positionCS.z * 2.0 - positionCS.w)*u_ProjectionParams.w;\r\n\t\r\n return positionCS;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tvec4 positionCS = depthNormalsVertex();\r\n\tgl_Position=remapGLPositionZ(positionCS);\r\n}',gt='#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n#include "DepthNormalUtil.glsl";\r\n\r\nvarying vec4 depthNormals;\r\n\r\nvoid main()\r\n{\r\n\tgl_FragColor=depthNormalsFragment(depthNormals);\r\n}';class St{constructor(){this.textureID=-1}}class Rt extends t.Resource{constructor(e,t,r,i,a){super(),this._stateParamsMap=[],this._uploadMark=-1,this._uploadRenderType=-1,this._vs=e,this._ps=t,this._attributeMap=r,this._uniformMap=i,this._shaderPass=a,this._globaluniformMap=[],this._create(),this.lock=!0}_create(){var e=t.LayaGL.instance;for(var r in this._program=e.createProgram(),this._vshader=this._createShader(e,this._vs,e.VERTEX_SHADER),this._pshader=this._createShader(e,this._ps,e.FRAGMENT_SHADER),e.attachShader(this._program,this._vshader),e.attachShader(this._program,this._pshader),this._attributeMap)e.bindAttribLocation(this._program,this._attributeMap[r],r);if(e.linkProgram(this._program),!t.Render.isConchApp&&xe.debugMode&&!e.getProgramParameter(this._program,e.LINK_STATUS))throw e.getProgramInfoLog(this._program);var i=[],a=[],n=[],s=[],o=[];this._customUniformParamsMap=[];var l,_,h,c=e.getProgramParameter(this._program,e.ACTIVE_UNIFORMS);for(t.WebGLContext.useProgram(e,this._program),this._curActTexIndex=0,_=0;_<c;_++){var d=e.getActiveUniform(this._program,_),u=d.name;(l=new St).location=e.getUniformLocation(this._program,u),u.indexOf("[0]")>0?(l.name=u=u.substr(0,u.length-3),l.isArray=!0):(l.name=u,l.isArray=!1),l.type=d.type,this._addShaderUnifiormFun(l);var m=this._uniformMap[u];if(null!=m)switch(l.dataOffset=xe.propertyNameToID(u),m){case xe.PERIOD_CUSTOM:o.push(l);break;case xe.PERIOD_MATERIAL:s.push(l);break;case xe.PERIOD_SPRITE:n.push(l);break;case xe.PERIOD_CAMERA:a.push(l);break;case xe.PERIOD_SCENE:i.push(l);break;default:throw new Error("Shader3D: period is unkonw.")}else l.dataOffset=xe.propertyNameToID(u),this._globaluniformMap[u]=xe.PERIOD_SCENE,i.push(l)}for(this._sceneUniformParamsMap=t.LayaGL.instance.createCommandEncoder(4*i.length*5+4,64,!0),_=0,h=i.length;_<h;_++)this._sceneUniformParamsMap.addShaderUniform(i[_]);for(this._cameraUniformParamsMap=t.LayaGL.instance.createCommandEncoder(4*a.length*5+4,64,!0),_=0,h=a.length;_<h;_++)this._cameraUniformParamsMap.addShaderUniform(a[_]);for(this._spriteUniformParamsMap=t.LayaGL.instance.createCommandEncoder(4*n.length*5+4,64,!0),_=0,h=n.length;_<h;_++)this._spriteUniformParamsMap.addShaderUniform(n[_]);for(this._materialUniformParamsMap=t.LayaGL.instance.createCommandEncoder(4*s.length*5+4,64,!0),_=0,h=s.length;_<h;_++)this._materialUniformParamsMap.addShaderUniform(s[_]);for(this._customUniformParamsMap.length=o.length,_=0,h=o.length;_<h;_++){var f=o[_];this._customUniformParamsMap[f.dataOffset]=f}var T=this._shaderPass._stateMap;for(var E in T)this._stateParamsMap[T[E]]=xe.propertyNameToID(E)}_getRenderState(e,t){var r=this._stateParamsMap[t];return null==r?null:e[r]}_disposeResource(){t.LayaGL.instance.deleteShader(this._vshader),t.LayaGL.instance.deleteShader(this._pshader),t.LayaGL.instance.deleteProgram(this._program),this._vshader=this._pshader=this._program=null,this._setGPUMemory(0),this._curActTexIndex=0}_addShaderUnifiormFun(e){var r=t.LayaGL.instance;e.caller=this;var i=e.isArray;switch(e.type){case r.BOOL:e.fun=this._uniform1i,e.uploadedValue=new Array(1);break;case r.INT:e.fun=i?this._uniform1iv:this._uniform1i,e.uploadedValue=new Array(1);break;case r.FLOAT:e.fun=i?this._uniform1fv:this._uniform1f,e.uploadedValue=new Array(1);break;case r.FLOAT_VEC2:e.fun=i?this._uniform_vec2v:this._uniform_vec2,e.uploadedValue=new Array(2);break;case r.FLOAT_VEC3:e.fun=i?this._uniform_vec3v:this._uniform_vec3,e.uploadedValue=new Array(3);break;case r.FLOAT_VEC4:e.fun=i?this._uniform_vec4v:this._uniform_vec4,e.uploadedValue=new Array(4);break;case r.FLOAT_MAT2:e.fun=this._uniformMatrix2fv;break;case r.FLOAT_MAT3:e.fun=this._uniformMatrix3fv;break;case r.FLOAT_MAT4:e.fun=i?this._uniformMatrix4fv:this._uniformMatrix4f;break;case r.SAMPLER_2D:case r.SAMPLER_2D_SHADOW:r.uniform1i(e.location,this._curActTexIndex),e.textureID=t.WebGLContext._glTextureIDs[this._curActTexIndex++],e.fun=this._uniform_sampler2D;break;case 35679:r.uniform1i(e.location,this._curActTexIndex),e.textureID=t.WebGLContext._glTextureIDs[this._curActTexIndex++],e.fun=this._uniform_sampler3D;break;case r.SAMPLER_CUBE:r.uniform1i(e.location,this._curActTexIndex),e.textureID=t.WebGLContext._glTextureIDs[this._curActTexIndex++],e.fun=this._uniform_samplerCube;break;default:throw new Error("compile shader err!")}}_createShader(e,t,r){var i=e.createShader(r);if(e.shaderSource(i,t),e.compileShader(i),xe.debugMode&&!e.getShaderParameter(i,e.COMPILE_STATUS))throw e.getShaderInfoLog(i);return i}_uniform1f(e,r){var i=e.uploadedValue;return i[0]!==r?(t.LayaGL.instance.uniform1f(e.location,i[0]=r),1):0}_uniform1fv(e,r){if(r.length<4){var i=e.uploadedValue;return i[0]!==r[0]||i[1]!==r[1]||i[2]!==r[2]||i[3]!==r[3]?(t.LayaGL.instance.uniform1fv(e.location,r),i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],1):0}return t.LayaGL.instance.uniform1fv(e.location,r),1}_uniform_vec2(e,r){var i=e.uploadedValue;return i[0]!==r.x||i[1]!==r.y?(t.LayaGL.instance.uniform2f(e.location,i[0]=r.x,i[1]=r.y),1):0}_uniform_vec2v(e,r){if(r.length<2){var i=e.uploadedValue;return i[0]!==r[0]||i[1]!==r[1]||i[2]!==r[2]||i[3]!==r[3]?(t.LayaGL.instance.uniform2fv(e.location,r),i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3],1):0}return t.LayaGL.instance.uniform2fv(e.location,r),1}_uniform_vec3(e,r){var i=e.uploadedValue;return i[0]!==r.x||i[1]!==r.y||i[2]!==r.z?(t.LayaGL.instance.uniform3f(e.location,i[0]=r.x,i[1]=r.y,i[2]=r.z),1):0}_uniform_vec3v(e,r){return t.LayaGL.instance.uniform3fv(e.location,r),1}_uniform_vec4(e,r){var i=e.uploadedValue;return i[0]!==r.x||i[1]!==r.y||i[2]!==r.z||i[3]!==r.w?(t.LayaGL.instance.uniform4f(e.location,i[0]=r.x,i[1]=r.y,i[2]=r.z,i[3]=r.w),1):0}_uniform_vec4v(e,r){return t.LayaGL.instance.uniform4fv(e.location,r),1}_uniformMatrix2fv(e,r){return t.LayaGL.instance.uniformMatrix2fv(e.location,!1,r),1}_uniformMatrix3fv(e,r){return t.LayaGL.instance.uniformMatrix3fv(e.location,!1,r),1}_uniformMatrix4f(e,r){var i=r.elements;return t.LayaGL.instance.uniformMatrix4fv(e.location,!1,i),1}_uniformMatrix4fv(e,r){return t.LayaGL.instance.uniformMatrix4fv(e.location,!1,r),1}_uniform1i(e,r){var i=e.uploadedValue;return i[0]!==r?(t.LayaGL.instance.uniform1i(e.location,i[0]=r),1):0}_uniform1iv(e,r){return t.LayaGL.instance.uniform1iv(e.location,r),1}_uniform_ivec2(e,r){var i=e.uploadedValue;return i[0]!==r[0]||i[1]!==r[1]?(t.LayaGL.instance.uniform2i(e.location,i[0]=r[0],i[1]=r[1]),1):0}_uniform_ivec2v(e,r){return t.LayaGL.instance.uniform2iv(e.location,r),1}_uniform_vec3i(e,r){var i=e.uploadedValue;return i[0]!==r[0]||i[1]!==r[1]||i[2]!==r[2]?(t.LayaGL.instance.uniform3i(e.location,i[0]=r[0],i[1]=r[1],i[2]=r[2]),1):0}_uniform_vec3vi(e,r){return t.LayaGL.instance.uniform3iv(e.location,r),1}_uniform_vec4i(e,r){var i=e.uploadedValue;return i[0]!==r[0]||i[1]!==r[1]||i[2]!==r[2]||i[3]!==r[3]?(t.LayaGL.instance.uniform4i(e.location,i[0]=r[0],i[1]=r[1],i[2]=r[2],i[3]=r[3]),1):0}_uniform_vec4vi(e,r){return t.LayaGL.instance.uniform4iv(e.location,r),1}_uniform_sampler2D(e,r){var i=r._getSource()||r.defaulteTexture._getSource(),a=t.LayaGL.instance;return t.WebGLContext.activeTexture(a,e.textureID),t.WebGLContext.bindTexture(a,a.TEXTURE_2D,i),0}_uniform_sampler3D(e,r){var i=r._getSource()||r.defaulteTexture._getSource(),a=t.LayaGL.instance;return t.WebGLContext.activeTexture(a,e.textureID),t.WebGLContext.bindTexture(a,WebGL2RenderingContext.TEXTURE_3D,i),0}_uniform_samplerCube(e,r){var i=r._getSource()||r.defaulteTexture._getSource(),a=t.LayaGL.instance;return t.WebGLContext.activeTexture(a,e.textureID),t.WebGLContext.bindTexture(a,a.TEXTURE_CUBE_MAP,i),0}bind(){return t.WebGLContext.useProgram(t.LayaGL.instance,this._program)}uploadUniforms(e,r,i){t.Stat.shaderCall+=t.LayaGLRunner.uploadShaderUniforms(t.LayaGL.instance,e,r,i)}uploadRenderStateBlendDepth(e){var r=t.LayaGL.instance,i=this._shaderPass.renderState,a=e.getData(),n=this._getRenderState(a,xe.RENDER_STATE_DEPTH_WRITE),s=this._getRenderState(a,xe.RENDER_STATE_DEPTH_TEST),o=this._getRenderState(a,xe.RENDER_STATE_BLEND);switch(null==n&&(n=i.depthWrite),null==s&&(s=i.depthTest),null==o&&(o=i.blend),t.WebGLContext.setDepthMask(r,n),s===lt.DEPTHTEST_OFF?t.WebGLContext.setDepthTest(r,!1):(t.WebGLContext.setDepthTest(r,!0),t.WebGLContext.setDepthFunc(r,s)),o){case lt.BLEND_DISABLE:t.WebGLContext.setBlend(r,!1);break;case lt.BLEND_ENABLE_ALL:var l=this._getRenderState(a,xe.RENDER_STATE_BLEND_EQUATION),_=this._getRenderState(a,xe.RENDER_STATE_BLEND_SRC),h=this._getRenderState(a,xe.RENDER_STATE_BLEND_DST);null==l&&(l=i.blendEquation),null==_&&(_=i.srcBlend),null==h&&(h=i.dstBlend),t.WebGLContext.setBlend(r,!0),t.WebGLContext.setBlendEquation(r,l),t.WebGLContext.setBlendFunc(r,_,h);break;case lt.BLEND_ENABLE_SEPERATE:var c=this._getRenderState(a,xe.RENDER_STATE_BLEND_EQUATION_RGB),d=this._getRenderState(a,xe.RENDER_STATE_BLEND_EQUATION_ALPHA),u=this._getRenderState(a,xe.RENDER_STATE_BLEND_SRC_RGB),m=this._getRenderState(a,xe.RENDER_STATE_BLEND_DST_RGB),f=this._getRenderState(a,xe.RENDER_STATE_BLEND_SRC_ALPHA),T=this._getRenderState(a,xe.RENDER_STATE_BLEND_DST_ALPHA);null==c&&(c=i.blendEquationRGB),null==d&&(d=i.blendEquationAlpha),null==u&&(u=i.srcBlendRGB),null==m&&(m=i.dstBlendRGB),null==f&&(f=i.srcBlendAlpha),null==T&&(T=i.dstBlendAlpha),t.WebGLContext.setBlend(r,!0),t.WebGLContext.setBlendEquationSeparate(r,c,d),t.WebGLContext.setBlendFuncSeperate(r,u,m,f,T)}}uploadRenderStateFrontFace(e,r,i){var a,n=t.LayaGL.instance,s=this._shaderPass.renderState,o=e.getData(),l=this._getRenderState(o,xe.RENDER_STATE_CULL);switch(null==l&&(l=s.cull),l){case lt.CULL_NONE:t.WebGLContext.setCullFace(n,!1);break;case lt.CULL_FRONT:t.WebGLContext.setCullFace(n,!0),a=r?i?n.CCW:n.CW:i?n.CW:n.CCW,t.WebGLContext.setFrontFace(n,a);break;case lt.CULL_BACK:t.WebGLContext.setCullFace(n,!0),a=r?i?n.CW:n.CCW:i?n.CCW:n.CW,t.WebGLContext.setFrontFace(n,a)}}uploadCustomUniform(e,r){t.Stat.shaderCall+=t.LayaGLRunner.uploadCustomUniform(t.LayaGL.instance,this._customUniformParamsMap,e,r)}_uniformMatrix2fvForNative(e,r){return t.LayaGL.instance.uniformMatrix2fvEx(e.location,!1,r),1}_uniformMatrix3fvForNative(e,r){return t.LayaGL.instance.uniformMatrix3fvEx(e.location,!1,r),1}_uniformMatrix4fvForNative(e,r){return t.LayaGL.instance.uniformMatrix4fvEx(e.location,!1,r),1}}class vt extends b{constructor(){super()}add(e){if(-1!==e._getIndexInList())throw"SimpleSingletonList:"+e+" has in SingletonList.";this._add(e),e._setIndexInList(this.length++)}remove(e){var t=e._getIndexInList();if(this.length--,t!==this.length){var r=this.elements[this.length];this.elements[t]=r,r._setIndexInList(t)}e._setIndexInList(-1)}clear(){for(var e=this.elements,t=0,r=this.length;t<r;t++)e[t]._setIndexInList(-1);this.length=0}}class xt{constructor(e=1,t=1,r=1,i=1){this.r=e,this.g=t,this.b=r,this.a=i}static gammaToLinearSpace(e){return e<=.04045?e/12.92:e<1?Math.pow((e+.055)/1.055,2.4):Math.pow(e,2.4)}static linearToGammaSpace(e){return e<=0?0:e<=.0031308?12.92*e:e<=1?1.055*Math.pow(e,.41666)-.055:Math.pow(e,.41666)}toLinear(e){e.r=xt.gammaToLinearSpace(this.r),e.g=xt.gammaToLinearSpace(this.g),e.b=xt.gammaToLinearSpace(this.b)}toGamma(e){e.r=xt.linearToGammaSpace(this.r),e.g=xt.linearToGammaSpace(this.g),e.b=xt.linearToGammaSpace(this.b)}cloneTo(e){var t=e;t.r=this.r,t.g=this.g,t.b=this.b,t.a=this.a}clone(){var e=new xt;return this.cloneTo(e),e}forNativeElement(){}}xt.RED=new xt(1,0,0,1),xt.GREEN=new xt(0,1,0,1),xt.BLUE=new xt(0,0,1,1),xt.CYAN=new xt(0,1,1,1),xt.YELLOW=new xt(1,.92,.016,1),xt.MAGENTA=new xt(1,0,1,1),xt.GRAY=new xt(.5,.5,.5,1),xt.WHITE=new xt(1,1,1,1),xt.BLACK=new xt(0,0,0,1);class At{}class It{}class Mt{static __init__(){}static _drawTraversalCullingBound(e,t){for(var r=e.elements,i=0,a=e.length;i<a;i++){var n=Mt._tempColor0;n.r=0,n.g=1,n.b=0,n.a=1,H._drawBound(t,r[i].bounds._getBoundBox(),n)}}static _traversalCulling(e,r,i,a,s,o,l){for(var _=a.elements,h=e.boundFrustum,c=e.position,d=e.cullingMask,u=t.Stat.loopCount,m=0,f=a.length;m<f;m++){var T=_[m];if((l?T._castShadow&&T._enable:0!=(Math.pow(2,T._owner._layer)&d)&&T._enable)&&(t.Stat.frustumCulling++,!e.useOcclusionCulling||T._needRender(h,i))){T._renderMark=u,T._distanceForSort=n.distance(T.bounds.getCenter(),c);for(var E=T._renderElements,p=0,g=E.length;p<g;p++)E[p]._update(r,i,s,o)}}}static renderObjectCulling(e,t,r,i,a,n){var s=t._opaqueQueue,o=t._transparentQueue,l=t._renders;t._clearRenderQueue();var _=t._octree;if(_&&(_.updateMotionObjects(),_.shrinkRootIfPossible(),_.getCollidingWithFrustum(e,r,i,a,n)),Mt._traversalCulling(e,t,r,l,i,a,n),Mt.debugFrustumCulling){var h=t._debugTool;h.clear(),_&&(_.drawAllBounds(h),_.drawAllObjects(h)),Mt._drawTraversalCullingBound(l,h)}var c=s.elements.length;c>0&&s._quickSort(0,c-1),(c=o.elements.length)>0&&o._quickSort(0,c-1)}static cullingShadow(e,r,i){var a=r._renders;r._clearRenderQueue();for(var s=r._opaqueQueue,o=e.position,l=e.cullPlaneCount,_=e.cullPlanes,h=(e.cullSphere,e.direction,a.elements),c=t.Stat.loopCount,d=0,u=a.length;d<u;d++){var m=h[d];if(m._castShadow&&m._enable){t.Stat.frustumCulling++;for(var f=m.bounds,T=f.getMin(),E=f.getMax(),p=T.x,g=T.y,S=T.z,R=E.x,v=E.y,x=E.z,A=!0,I=0;I<l;I++){var M=_[I],D=M.normal;if(M.distance+D.x*(D.x<0?p:R)+D.y*(D.y<0?g:v)+D.z*(D.z<0?S:x)<0){A=!1;break}}if(A){m._renderMark=c,m._distanceForSort=n.distance(f.getCenter(),o);for(var C=m._renderElements,y=(I=0,C.length);I<y;I++)C[I]._update(r,i,null,null)}}}return s.elements.length>0}static cullingSpotShadow(e,r,i){var a=r._renders;r._clearRenderQueue();for(var s=r._opaqueQueue,o=a.elements,l=t.Stat.loopCount,_=0,h=a.length;_<h;_++){var c=o[_];if(c._castShadow&&c._enable&&c._needRender(e.boundFrustum,i)){var d=c.bounds;c._renderMark=l,c._distanceForSort=n.distance(d.getCenter(),e.position);for(var u=c._renderElements,m=0,f=u.length;m<f;m++)u[m]._update(r,i,null,null)}}return s.elements.length>0}static renderObjectCullingNative(e,r,i,a,s,o){var l,_,h,c=r._opaqueQueue,d=r._transparentQueue;r._clearRenderQueue();var u=a.length,m=a.elements;for(l=0;l<u;l++)m[l].bounds,m[l]._updateForNative&&m[l]._updateForNative(i);e.boundFrustum;Mt.cullingNative(e._boundFrustumBuffer,Mt._cullingBuffer,r._cullingBufferIndices,u,r._cullingBufferResult);var f=t.Stat.loopCount,T=i.camera._transform.position;for(l=0;l<u;l++){var E=m[l];if(!e.useOcclusionCulling||e._isLayerVisible(E._owner._layer)&&E._enable&&r._cullingBufferResult[l]){E._renderMark=f,E._distanceForSort=n.distance(E.bounds.getCenter(),T);var p=E._renderElements;for(_=0,h=p.length;_<h;_++){p[_]._update(r,i,s,o)}}}var g=c.elements.length;g>0&&c._quickSort(0,g-1),(g=d.elements.length)>0&&d._quickSort(0,g-1)}static cullingNative(e,r,i,a,n){return t.LayaGL.instance.culling(e,r,i,a,n)}}Mt._tempColor0=new xt,Mt._tempVector0=new n,Mt._cameraCullInfo=new At,Mt._shadowCullInfo=new It,Mt.debugFrustumCulling=!1;class Dt{constructor(){this._coefficients=new Float32Array(27)}getCoefficient(e,t){return this._coefficients[9*e+t]}setCoefficient(e,t,r){this._coefficients[9*e+t]=r}setCoefficients(e,t,r,i,a,n,s,o,l,_){var h=9*e;this._coefficients[h]=t,this._coefficients[++h]=r,this._coefficients[++h]=i,this._coefficients[++h]=a,this._coefficients[++h]=n,this._coefficients[++h]=s,this._coefficients[++h]=o,this._coefficients[++h]=l,this._coefficients[++h]=_}cloneTo(e){if(this!==e)for(var t=this._coefficients,r=e._coefficients,i=0;i<27;i++)r[i]=t[i]}}Dt._default=new Dt;class Ct{constructor(){this._pressedSprite=null,this._pressedLoopCount=-1,this.sprite=null,this.mousePositionX=0,this.mousePositionY=0}}class yt{constructor(){this._indexInList=-1,this._identifier=-1,this._position=new i}get identifier(){return this._identifier}get position(){return this._position}_getIndexInList(){return this._indexInList}_setIndexInList(e){this._indexInList=e}}class Lt{constructor(){this._eventList=[],this._mouseTouch=new Ct,this._touchPool=[],this._touches=new vt,this._multiTouchEnabled=!0,this._pushEventList=(e=>{e.cancelable&&e.preventDefault(),this._eventList.push(e)}).bind(this)}__init__(e,t){this._scene=t,e.oncontextmenu=function(e){return!1}}_onCanvasEvent(e){e.addEventListener("mousedown",this._pushEventList),e.addEventListener("mouseup",this._pushEventList,!0),e.addEventListener("mousemove",this._pushEventList,!0),e.addEventListener("touchstart",this._pushEventList),e.addEventListener("touchend",this._pushEventList,!0),e.addEventListener("touchmove",this._pushEventList,!0),e.addEventListener("touchcancel",this._pushEventList,!0)}_offCanvasEvent(e){e.removeEventListener("mousedown",this._pushEventList),e.removeEventListener("mouseup",this._pushEventList,!0),e.removeEventListener("mousemove",this._pushEventList,!0),e.removeEventListener("touchstart",this._pushEventList),e.removeEventListener("touchend",this._pushEventList,!0),e.removeEventListener("touchmove",this._pushEventList,!0),e.removeEventListener("touchcancel",this._pushEventList,!0),this._eventList.length=0,this._touches.clear()}touchCount(){return this._touches.length}get multiTouchEnabled(){return this._multiTouchEnabled}set multiTouchEnabled(e){this._multiTouchEnabled=e}_getTouch(e,t){var r=this._touchPool[e];return 0==t&&r&&-1!=r._getIndexInList()||1==t&&r&&-1==r._getIndexInList()?null:(r||(r=new yt,this._touchPool[e]=r,r._identifier=e),r)}_mouseTouchDown(){var e=this._mouseTouch,r=e.sprite;if(e._pressedSprite=r,e._pressedLoopCount=t.Stat.loopCount,r){var i=r._scripts;if(i)for(var a=0,n=i.length;a<n;a++)i[a].onMouseDown()}}_mouseTouchUp(){var e,t,r=this._mouseTouch,i=r._pressedSprite;r._pressedSprite=null,r._pressedLoopCount=-1;var a=r.sprite;if(a&&a===i){var n=a._scripts;if(n)for(e=0,t=n.length;e<t;e++)n[e].onMouseClick()}if(i){var s=i._scripts;if(s)for(e=0,t=s.length;e<t;e++)s[e].onMouseUp()}}_mouseTouchRayCast(t){var r=Lt._tempHitResult0,i=Lt._tempVector20,a=Lt._tempRay0;r.succeeded=!1;var n=this._mouseTouch.mousePositionX,s=this._mouseTouch.mousePositionY;i.x=n,i.y=s;for(var o=t.length-1;o>=0;o--){var l=t[o],_=l.viewport;if(i.x>=_.x&&i.y>=_.y&&i.x<=_.width&&i.y<=_.height)if(l.viewportPointToRay(i,a),this._scene._physicsSimulation.rayCast(a,r)||l.clearFlag===e.CameraClearFlags.SolidColor||l.clearFlag===e.CameraClearFlags.Sky)break}var h=this._mouseTouch,c=h.sprite;if(r.succeeded){var d=r.collider.owner;h.sprite=d;var u=d._scripts;if(c!==d&&u)for(var m=0,f=u.length;m<f;m++)u[m].onMouseEnter()}else h.sprite=null;if(c&&c!==d){var T=c._scripts;if(T)for(m=0,f=T.length;m<f;m++)T[m].onMouseOut()}}_changeTouches(e,r){for(var i=0,a=0,n=this._touches.length,s=0,o=e.length;s<o;s++){var l=e[s],_=l.identifier;if(this._multiTouchEnabled||0===this._touches.length||0!=r){var h=this._getTouch(_,r);if(1!=r||h){var c=this._touchPool[_]._position,d=Lt._tempPoint;d.setTo(l.pageX,l.pageY),t.ILaya.stage._canvasTransform.invertTransformPoint(d);var u=d.x,m=d.y;switch(r){case 0:h&&this._touches.add(h),i+=u,a+=m;break;case 1:h&&this._touches.remove(h),i-=u,a-=m;break;case 2:i=u-c.x,a=m-c.y}c.x=u,c.y=m}}}var f=this._touches.length;0===f?(this._mouseTouch.mousePositionX=0,this._mouseTouch.mousePositionY=0):(this._mouseTouch.mousePositionX=(this._mouseTouch.mousePositionX*n+i)/f,this._mouseTouch.mousePositionY=(this._mouseTouch.mousePositionY*n+a)/f)}_update(){var e,r,i,a,n=Y._enablePhysics&&!G.disableSimulation;r=this._eventList.length;var s=this._scene._cameraPool;if(r>0){var o=!1;for(e=0;e<r;e++){var l=this._eventList[e];switch(l.type){case"mousedown":n&&this._mouseTouchDown();break;case"mouseup":n&&this._mouseTouchUp();break;case"mousemove":var _=Lt._tempPoint;_.setTo(l.pageX,l.pageY),t.ILaya.stage._canvasTransform.invertTransformPoint(_),this._mouseTouch.mousePositionX=_.x,this._mouseTouch.mousePositionY=_.y,n&&(o=!0);break;case"touchstart":var h=this._touches.length;this._changeTouches(l.changedTouches,0),n&&(!j._config.isUseCannonPhysicsEngine&&this._mouseTouchRayCast(s),0===h&&this._mouseTouchDown());break;case"touchend":case"touchcancel":this._changeTouches(l.changedTouches,1),n&&0===this._touches.length&&this._mouseTouchUp();break;case"touchmove":this._changeTouches(l.changedTouches,2),n&&(o=!0);break;default:throw"Input3D:unkonwn event type."}}o&&!j._config.isUseCannonPhysicsEngine&&this._mouseTouchRayCast(s),this._eventList.length=0}if(n){var c=this._mouseTouch,d=c._pressedSprite;if(d&&t.Stat.loopCount>c._pressedLoopCount){var u=d._scripts;if(u)for(i=0,a=u.length;i<a;i++)u[i].onMouseDrag()}var m=c.sprite;if(m){var f=m._scripts;if(f)for(i=0,a=f.length;i<a;i++)f[i].onMouseOver()}}}getTouch(e){return e<this._touches.length?this._touches.elements[e]:null}}Lt._tempPoint=new t.Point,Lt._tempVector20=new i,Lt._tempRay0=new be(new n,new n),Lt._tempHitResult0=new B;class Ot{constructor(){this.flags=0,this.maxSubSteps=1,this.fixedTimeStep=1/60}}class Nt{constructor(e,t){this._position=e,this._textureCoordinate0=t}static get vertexDeclaration(){return Nt._vertexDeclaration}static __init__(){Nt._vertexDeclaration=new fe(20,[new Te(0,ue.Vector3,ze.MESH_POSITION0),new Te(12,ue.Vector2,ze.MESH_TEXTURECOORDINATE0)])}get position(){return this._position}get textureCoordinate0(){return this._textureCoordinate0}get vertexDeclaration(){return Nt._vertexDeclaration}}class Pt extends He{constructor(r=48,i=48){super();var a=t.LayaGL.instance;this._stacks=r,this._slices=i;for(var n=Nt.vertexDeclaration,s=n.vertexStride/4,o=(this._stacks+1)*(this._slices+1),l=3*this._stacks*(this._slices+1)*2,_=new Float32Array(o*s),h=new Uint16Array(l),c=Math.PI/this._stacks,d=2*Math.PI/this._slices,u=0,m=0,f=0,T=0;T<this._stacks+1;T++)for(var E=Math.sin(T*c),p=Math.cos(T*c),g=0;g<this._slices+1;g++){var S=E*Math.sin(g*d),R=E*Math.cos(g*d);_[m+0]=S*Pt._radius,_[m+1]=p*Pt._radius,_[m+2]=R*Pt._radius,_[m+3]=-g/this._slices+.75,_[m+4]=T/this._stacks,m+=s,T!=this._stacks-1&&(h[f++]=u+1,h[f++]=u,h[f++]=u+(this._slices+1),h[f++]=u+(this._slices+1),h[f++]=u,h[f++]=u+this._slices,u++)}this._vertexBuffer=new de(4*_.length,a.STATIC_DRAW,!1),this._vertexBuffer.vertexDeclaration=n,this._indexBuffer=new Ge(e.IndexFormat.UInt16,h.length,a.STATIC_DRAW,!1),this._vertexBuffer.setData(_.buffer),this._indexBuffer.setData(h);var v=new Ee;v.bind(),v.applyVertexBuffer(this._vertexBuffer),v.applyIndexBuffer(this._indexBuffer),v.unBind(),this._bufferState=v}static __init__(){Pt.instance=new Pt}get stacks(){return this._stacks}get slices(){return this._slices}_render(e){var r=t.LayaGL.instance,i=this._indexBuffer.indexCount;r.drawElements(r.TRIANGLES,i,r.UNSIGNED_SHORT,0),t.Stat.trianglesFaces+=i/3,t.Stat.renderBatches++}}Pt._radius=1,(ut=e.TextureCubeFace||(e.TextureCubeFace={}))[ut.PositiveX=0]="PositiveX",ut[ut.NegativeX=1]="NegativeX",ut[ut.PositiveY=2]="PositiveY",ut[ut.NegativeY=3]="NegativeY",ut[ut.PositiveZ=4]="PositiveZ",ut[ut.NegativeZ=5]="NegativeZ";class bt extends t.BaseTexture{constructor(e,r=t.TextureFormat.R8G8B8,i=!1){super(r,i),this._glTextureType=t.LayaGL.instance.TEXTURE_CUBE_MAP,this._width=e,this._height=e;var a=t.LayaGL.instance;if(this._setWarpMode(a.TEXTURE_WRAP_S,this._wrapModeU),this._setWarpMode(a.TEXTURE_WRAP_T,this._wrapModeV),this._setFilterMode(this._filterMode),this._setAnisotropy(this._anisoLevel),this._mipmap){this._mipmapCount=Math.ceil(Math.log2(e))+1;for(var n=0;n<this._mipmapCount;n++)this._setPixels([],n,Math.max(e>>n,1),Math.max(e>>n,1));this._setGPUMemory(e*e*4*(1+1/3)*6)}else this._mipmapCount=1,this._setGPUMemory(e*e*4*6)}static get blackTexture(){return bt._blackTexture}static get grayTexture(){return bt._grayTexture}static __init__(){var e=new bt(1,t.TextureFormat.R8G8B8,!1),r=new bt(1,t.TextureFormat.R8G8B8,!1),i=new Uint8Array(3);i[0]=0,i[1]=0,i[2]=0,e.setSixSidePixels([i,i,i,i,i,i]),e.lock=!0,i[0]=128,i[1]=128,i[2]=128,r.setSixSidePixels([i,i,i,i,i,i]),r.lock=!0,bt._grayTexture=r,bt._blackTexture=e}static _parse(e,t=null,r=null){var i=r?new bt(0,r[0],r[1]):new bt(0);return i.setSixSideImageSources(e),i}static _parseBin(e,t=null,r=null){var i=r?new bt(0,r[0],r[1]):new bt(0);return i.setSixSideImageSources(e),i}static load(e,r){var i=t.LoaderManager.createMap[t.Utils.getFilecompatibleExtension(e)]?t.Utils.getFilecompatibleExtension(e):t.Utils.getFileExtension(e),a=t.LoaderManager.createMap[i]?t.LoaderManager.createMap[i][0]:null;t.ILaya.loader.create(e,r,null,a)}get defaulteTexture(){return bt.grayTexture}_setPixels(e,r,i,a){var n=t.LayaGL.instance,s=this._getGLFormat();t.WebGLContext.bindTexture(n,this._glTextureType,this._glTexture),this.format===t.TextureFormat.R8G8B8?(n.pixelStorei(n.UNPACK_ALIGNMENT,1),n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_Z,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[0]),n.texImage2D(n.TEXTURE_CUBE_MAP_NEGATIVE_Z,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[1]),n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[2]),n.texImage2D(n.TEXTURE_CUBE_MAP_NEGATIVE_X,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[3]),n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_Y,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[4]),n.texImage2D(n.TEXTURE_CUBE_MAP_NEGATIVE_Y,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[5]),n.pixelStorei(n.UNPACK_ALIGNMENT,4)):(n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_Z,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[0]),n.texImage2D(n.TEXTURE_CUBE_MAP_NEGATIVE_Z,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[1]),n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[2]),n.texImage2D(n.TEXTURE_CUBE_MAP_NEGATIVE_X,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[3]),n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_Y,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[4]),n.texImage2D(n.TEXTURE_CUBE_MAP_NEGATIVE_Y,r,s,i,a,0,s,n.UNSIGNED_BYTE,e[5]))}setSixSideImageSources(e,r=!1){for(var i,a,n=0;n<6;n++){var s=e[n];if(!s)return void console.log("TextureCube: image Source can't be null.");var o=s.width,l=s.height;if(n>0&&i!==o)return void console.log("TextureCube: each side image's width and height must same.");if((i=o)!==(a=l))return void console.log("TextureCube: each side image's width and height must same.")}this._width=i,this._height=a;var _=t.LayaGL.instance;t.WebGLContext.bindTexture(_,this._glTextureType,this._glTexture);var h=this._getGLFormat();if(t.Render.isConchApp){if(1==r)for(var c=0;c<6;c++)e[c].setPremultiplyAlpha(r);_.texImage2D(_.TEXTURE_CUBE_MAP_POSITIVE_Z,0,_.RGBA,_.RGBA,_.UNSIGNED_BYTE,e[0]),_.texImage2D(_.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,_.RGBA,_.RGBA,_.UNSIGNED_BYTE,e[1]),_.texImage2D(_.TEXTURE_CUBE_MAP_POSITIVE_X,0,_.RGBA,_.RGBA,_.UNSIGNED_BYTE,e[2]),_.texImage2D(_.TEXTURE_CUBE_MAP_NEGATIVE_X,0,_.RGBA,_.RGBA,_.UNSIGNED_BYTE,e[3]),_.texImage2D(_.TEXTURE_CUBE_MAP_POSITIVE_Y,0,_.RGBA,_.RGBA,_.UNSIGNED_BYTE,e[4]),_.texImage2D(_.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,_.RGBA,_.RGBA,_.UNSIGNED_BYTE,e[5])}else r&&_.pixelStorei(_.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),_.texImage2D(_.TEXTURE_CUBE_MAP_POSITIVE_Z,0,h,h,_.UNSIGNED_BYTE,e[0]),_.texImage2D(_.TEXTURE_CUBE_MAP_NEGATIVE_Z,0,h,h,_.UNSIGNED_BYTE,e[1]),_.texImage2D(_.TEXTURE_CUBE_MAP_POSITIVE_X,0,h,h,_.UNSIGNED_BYTE,e[2]),_.texImage2D(_.TEXTURE_CUBE_MAP_NEGATIVE_X,0,h,h,_.UNSIGNED_BYTE,e[3]),_.texImage2D(_.TEXTURE_CUBE_MAP_POSITIVE_Y,0,h,h,_.UNSIGNED_BYTE,e[4]),_.texImage2D(_.TEXTURE_CUBE_MAP_NEGATIVE_Y,0,h,h,_.UNSIGNED_BYTE,e[5]),r&&_.pixelStorei(_.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);this._mipmap&&this._isPot(i)&&this._isPot(a)?(_.generateMipmap(this._glTextureType),this._setGPUMemory(i*a*4*(1+1/3)*6)):this._setGPUMemory(i*a*4*6),this._setWarpMode(_.TEXTURE_WRAP_S,this._wrapModeU),this._setWarpMode(_.TEXTURE_WRAP_T,this._wrapModeV),this._setFilterMode(this._filterMode),this._readyed=!0,this._activeResource()}setSixSidePixels(e,r=0){if(!e)throw new Error("TextureCube:pixels can't be null.");var i=Math.max(this._width>>r,1),a=Math.max(this._height>>r,1),n=i*a*this._getFormatByteCount();if(e[0].length<n)throw"TextureCube:pixels length should at least "+n+".";if(this._setPixels(e,r,i,a),0===r){var s=t.LayaGL.instance;this._setWarpMode(s.TEXTURE_WRAP_S,this._wrapModeU),this._setWarpMode(s.TEXTURE_WRAP_T,this._wrapModeV)}this._readyed=!0,this._activeResource()}setImageSource(r,i,a=0){var n=this._width,s=this._height;if(!i||n===i.width&&s===i.height){var o=t.LayaGL.instance;t.WebGLContext.bindTexture(o,this._glTextureType,this._glTexture);var l=this._getGLFormat();switch(r){case e.TextureCubeFace.NegativeX:o.texImage2D(o.TEXTURE_CUBE_MAP_NEGATIVE_X,a,l,l,o.UNSIGNED_BYTE,i);break;case e.TextureCubeFace.PositiveX:o.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_X,a,l,l,o.UNSIGNED_BYTE,i);break;case e.TextureCubeFace.NegativeY:o.texImage2D(o.TEXTURE_CUBE_MAP_NEGATIVE_Y,a,l,l,o.UNSIGNED_BYTE,i);break;case e.TextureCubeFace.PositiveY:o.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_Y,a,l,l,o.UNSIGNED_BYTE,i);break;case e.TextureCubeFace.NegativeZ:o.texImage2D(o.TEXTURE_CUBE_MAP_NEGATIVE_Z,a,l,l,o.UNSIGNED_BYTE,i);break;case e.TextureCubeFace.PositiveZ:o.texImage2D(o.TEXTURE_CUBE_MAP_POSITIVE_Z,a,l,l,o.UNSIGNED_BYTE,i)}this._mipmap&&this._isPot(n)&&this._isPot(s)?(o.generateMipmap(this._glTextureType),this._setGPUMemory(n*s*4*(1+1/3)*6)):this._setGPUMemory(n*s*4*6),this._setWarpMode(o.TEXTURE_WRAP_S,this._wrapModeU),this._setWarpMode(o.TEXTURE_WRAP_T,this._wrapModeV),this._setFilterMode(this._filterMode),this._readyed=!0}else console.log("TextureCube: imageSource's width and height must same.")}}bt.TEXTURECUBE="TEXTURECUBE",bt.TEXTURECUBEBIN="TEXTURECUBEBIN";class wt{constructor(){this._length=0,this._elements=[]}add(e){this._length===this._elements.length?this._elements.push(e):this._elements[this._length]=e,this._length++}remove(e){var t=this._elements.indexOf(e);if(this._length--,t!==this._length){var r=this._elements[this._length];this._elements[t]=r}}shift(){return this._length--,this._elements.shift()}getBrightestLight(){for(var e,t=-1,r=this._elements,i=0;i<this._length;i++){var a=r[i]._intensity;t<a&&(t=a,e=i)}return e}normalLightOrdering(e){this._elements;var t=this._elements[0];this._elements[0]=this._elements[e],this._elements[e]=t}}class Vt extends wt{remove(e){var t=this._elements.indexOf(e);this._elements.splice(t,1),this._length--}}class Bt extends st{constructor(){super(),this.setShaderName("LineShader"),this._shaderValues.setVector(Bt.COLOR,new a(1,1,1,1))}static __initDefine__(){}get color(){return this._shaderValues.getVector(Bt.COLOR)}set color(e){this._shaderValues.setVector(Bt.COLOR,e)}clone(){var e=new Bt;return this.cloneTo(e),e}}Bt.COLOR=xe.propertyNameToID("u_Color");class Ft{constructor(e,t){this.min=e,this.max=t}_rotateExtents(e,t,r){var i=e.x,a=e.y,n=e.z,s=t.elements;r.x=Math.abs(s[0]*i)+Math.abs(s[4]*a)+Math.abs(s[8]*n),r.y=Math.abs(s[1]*i)+Math.abs(s[5]*a)+Math.abs(s[9]*n),r.z=Math.abs(s[2]*i)+Math.abs(s[6]*a)+Math.abs(s[10]*n)}getCorners(e){e.length=8;var t=this.min.x,r=this.min.y,i=this.min.z,a=this.max.x,s=this.max.y,o=this.max.z;e[0]=new n(t,s,o),e[1]=new n(a,s,o),e[2]=new n(a,r,o),e[3]=new n(t,r,o),e[4]=new n(t,s,i),e[5]=new n(a,s,i),e[6]=new n(a,r,i),e[7]=new n(t,r,i)}getCenter(e){n.add(this.min,this.max,e),n.scale(e,.5,e)}getExtent(e){n.subtract(this.max,this.min,e),n.scale(e,.5,e)}setCenterAndExtent(e,t){n.subtract(e,t,this.min),n.add(e,t,this.max)}tranform(e,t){var r=Ft._tempVector30,i=Ft._tempVector31;this.getCenter(r),this.getExtent(i),n.transformCoordinate(r,e,r),this._rotateExtents(i,e,i),t.setCenterAndExtent(r,i)}toDefault(){this.min.toDefault(),this.max.toDefault()}static createfromPoints(e,t){if(null==e)throw new Error("points");var r=t.min,i=t.max;r.x=Number.MAX_VALUE,r.y=Number.MAX_VALUE,r.z=Number.MAX_VALUE,i.x=-Number.MAX_VALUE,i.y=-Number.MAX_VALUE,i.z=-Number.MAX_VALUE;for(var a=0,s=e.length;a<s;++a)n.min(r,e[a],r),n.max(i,e[a],i)}static merge(e,t,r){n.min(e.min,t.min,r.min),n.max(e.max,t.max,r.max)}cloneTo(e){var t=e;this.min.cloneTo(t.min),this.max.cloneTo(t.max)}clone(){var e=new Ft(new n,new n);return this.cloneTo(e),e}}Ft._tempVector30=new n,Ft._tempVector31=new n;class Ut{constructor(e,t){this._updateFlag=0,this._center=new n,this._extent=new n,this._boundBox=new Ft(new n,new n),e.cloneTo(this._boundBox.min),t.cloneTo(this._boundBox.max),this._setUpdateFlag(Ut._UPDATE_CENTER|Ut._UPDATE_EXTENT,!0)}setMin(e){var t=this._boundBox.min;e!==t&&e.cloneTo(t),this._setUpdateFlag(Ut._UPDATE_CENTER|Ut._UPDATE_EXTENT,!0),this._setUpdateFlag(Ut._UPDATE_MIN,!1)}getMin(){var e=this._boundBox.min;return this._getUpdateFlag(Ut._UPDATE_MIN)&&(this._getMin(this.getCenter(),this.getExtent(),e),this._setUpdateFlag(Ut._UPDATE_MIN,!1)),e}setMax(e){var t=this._boundBox.max;e!==t&&e.cloneTo(t),this._setUpdateFlag(Ut._UPDATE_CENTER|Ut._UPDATE_EXTENT,!0),this._setUpdateFlag(Ut._UPDATE_MAX,!1)}getMax(){var e=this._boundBox.max;return this._getUpdateFlag(Ut._UPDATE_MAX)&&(this._getMax(this.getCenter(),this.getExtent(),e),this._setUpdateFlag(Ut._UPDATE_MAX,!1)),e}setCenter(e){e!==this._center&&e.cloneTo(this._center),this._setUpdateFlag(Ut._UPDATE_MIN|Ut._UPDATE_MAX,!0),this._setUpdateFlag(Ut._UPDATE_CENTER,!1)}getCenter(){return this._getUpdateFlag(Ut._UPDATE_CENTER)&&(this._getCenter(this.getMin(),this.getMax(),this._center),this._setUpdateFlag(Ut._UPDATE_CENTER,!1)),this._center}setExtent(e){e!==this._extent&&e.cloneTo(this._extent),this._setUpdateFlag(Ut._UPDATE_MIN|Ut._UPDATE_MAX,!0),this._setUpdateFlag(Ut._UPDATE_EXTENT,!1)}getExtent(){return this._getUpdateFlag(Ut._UPDATE_EXTENT)&&(this._getExtent(this.getMin(),this.getMax(),this._extent),this._setUpdateFlag(Ut._UPDATE_EXTENT,!1)),this._extent}_getUpdateFlag(e){return 0!=(this._updateFlag&e)}_setUpdateFlag(e,t){t?this._updateFlag|=e:this._updateFlag&=~e}_getCenter(e,t,r){n.add(e,t,r),n.scale(r,.5,r)}_getExtent(e,t,r){n.subtract(t,e,r),n.scale(r,.5,r)}_getMin(e,t,r){n.subtract(e,t,r)}_getMax(e,t,r){n.add(e,t,r)}_rotateExtents(e,t,r){var i=e.x,a=e.y,n=e.z,s=t.elements;r.x=Math.abs(s[0]*i)+Math.abs(s[4]*a)+Math.abs(s[8]*n),r.y=Math.abs(s[1]*i)+Math.abs(s[5]*a)+Math.abs(s[9]*n),r.z=Math.abs(s[2]*i)+Math.abs(s[6]*a)+Math.abs(s[10]*n)}_tranform(e,t){var r=t._center,i=t._extent;n.transformCoordinate(this.getCenter(),e,r),this._rotateExtents(this.getExtent(),e,i),t._boundBox.setCenterAndExtent(r,i),t._updateFlag=0}_getBoundBox(){if(this._updateFlag&Ut._UPDATE_MIN){var e=this._boundBox.min;this._getMin(this.getCenter(),this.getExtent(),e),this._setUpdateFlag(Ut._UPDATE_MIN,!1)}if(this._updateFlag&Ut._UPDATE_MAX){var t=this._boundBox.max;this._getMax(this.getCenter(),this.getExtent(),t),this._setUpdateFlag(Ut._UPDATE_MAX,!1)}return this._boundBox}calculateBoundsintersection(e){var t=this.getMax(),r=this.getMin(),i=e.getMax(),a=e.getMin(),n=Ut.TEMP_VECTOR3_MAX0,s=Ut.TEMP_VECTOR3_MAX1,o=this.getExtent(),l=e.getExtent();return n.setValue(Math.max(t.x,i.x)-Math.min(r.x,a.x),Math.max(t.y,i.y)-Math.min(r.y,a.y),Math.max(t.z,i.z)-Math.min(r.z,a.z)),s.setValue(2*(o.x+l.x),2*(o.y+l.y),2*(o.z+l.z)),n.x>s.x||n.y>s.y||n.z>s.z?-1:(s.x-n.x)*(s.y-n.y)*(s.z-n.z)}cloneTo(e){var t=e;this.getMin().cloneTo(t._boundBox.min),this.getMax().cloneTo(t._boundBox.max),this.getCenter().cloneTo(t._center),this.getExtent().cloneTo(t._extent),t._updateFlag=0}clone(){var e=new Ut(new n,new n);return this.cloneTo(e),e}}Ut._UPDATE_MIN=1,Ut._UPDATE_MAX=2,Ut._UPDATE_CENTER=4,Ut._UPDATE_EXTENT=8,Ut.TEMP_VECTOR3_MAX0=new n,Ut.TEMP_VECTOR3_MAX1=new n;class Gt{constructor(){this._destroyed=!1}get destroyed(){return this._destroyed}_getType(){throw"GeometryElement:must override it."}_prepareRender(e){return!0}_render(e){throw"GeometryElement:must override it."}destroy(){this._destroyed||(this._destroyed=!0)}}Gt._typeCounter=0;class zt{constructor(){}static get vertexDeclaration(){return zt._vertexDeclaration}static __init__(){zt._vertexDeclaration=new fe(28,[new Te(0,ue.Vector3,ze.MESH_POSITION0),new Te(12,ue.Vector4,ze.MESH_COLOR0)])}get vertexDeclaration(){return zt._vertexDeclaration}}class Ht extends Gt{constructor(e,r){super(),this._floatCountPerVertices=7,this._minUpdate=Number.MAX_VALUE,this._maxUpdate=Number.MIN_VALUE,this._bufferState=new Ee,this._floatBound=new Float32Array(6),this._calculateBound=!1,this._maxLineCount=0,this._lineCount=0;var i=2*r;this._owner=e,this._maxLineCount=r,this._vertices=new Float32Array(i*this._floatCountPerVertices),this._vertexBuffer=new de(zt.vertexDeclaration.vertexStride*i,t.LayaGL.instance.STATIC_DRAW,!1),this._vertexBuffer.vertexDeclaration=zt.vertexDeclaration,this._bufferState.bind(),this._bufferState.applyVertexBuffer(this._vertexBuffer),this._bufferState.unBind();var a=Ht._tempVector0,n=Ht._tempVector1;a.setValue(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),n.setValue(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),this._bounds=new Ut(a,n)}_getType(){return Ht._type}_resizeLineData(e){var r=2*e,i=this._vertices;this._vertexBuffer.destroy(),this._maxLineCount=e;var a=r*this._floatCountPerVertices;this._vertices=new Float32Array(a),this._vertexBuffer=new de(zt.vertexDeclaration.vertexStride*r,t.LayaGL.instance.STATIC_DRAW,!1),this._vertexBuffer.vertexDeclaration=zt.vertexDeclaration,a<i.length?(this._vertices.set(new Float32Array(i.buffer,0,a)),this._vertexBuffer.setData(this._vertices.buffer,0,0,4*a)):(this._vertices.set(i),this._vertexBuffer.setData(this._vertices.buffer,0,0,4*i.length)),this._bufferState.bind(),this._bufferState.applyVertexBuffer(this._vertexBuffer),this._bufferState.unBind()}_updateLineVertices(e,t,r,i,a){t&&(this._vertices[e+0]=t.x,this._vertices[e+1]=t.y,this._vertices[e+2]=t.z),i&&(this._vertices[e+3]=i.r,this._vertices[e+4]=i.g,this._vertices[e+5]=i.b,this._vertices[e+6]=i.a),r&&(this._vertices[e+7]=r.x,this._vertices[e+8]=r.y,this._vertices[e+9]=r.z),a&&(this._vertices[e+10]=a.r,this._vertices[e+11]=a.g,this._vertices[e+12]=a.b,this._vertices[e+13]=a.a),this._minUpdate=Math.min(this._minUpdate,e),this._maxUpdate=Math.max(this._maxUpdate,e+2*this._floatCountPerVertices);var s=this._bounds,o=this._floatBound,l=s.getMin(),_=s.getMax();n.min(l,t,l),n.min(l,r,l),n.max(_,t,_),n.max(_,r,_),s.setMin(l),s.setMax(_),o[0]=l.x,o[1]=l.y,o[2]=l.z,o[3]=_.x,o[4]=_.y,o[5]=_.z}_reCalculateBound(){if(this._calculateBound){var e=this._vertices,t=Ht._tempVector0,r=Ht._tempVector1;t.setValue(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),r.setValue(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var i=0;i<2*this._lineCount;++i){var a=this._floatCountPerVertices*i,n=e[a+0],s=e[a+1],o=e[a+2];t.x=Math.min(n,t.x),t.y=Math.min(s,t.y),t.z=Math.min(o,t.z),r.x=Math.max(n,r.x),r.y=Math.max(s,r.y),r.z=Math.max(o,r.z)}this._bounds.setMin(t),this._bounds.setMax(r);var l=this._floatBound;l[0]=t.x,l[1]=t.y,l[2]=t.z,l[3]=r.x,l[4]=r.y,l[5]=r.z,this._calculateBound=!1}}_removeLineData(e){var t=2*this._floatCountPerVertices,r=e+1,i=e*t,a=this._vertices,n=new Float32Array(a.buffer,r*t*4,(this._lineCount-r)*t);a.set(n,i),this._minUpdate=Math.min(this._minUpdate,i),this._maxUpdate=Math.max(this._maxUpdate,i+n.length),this._lineCount--;var s=this._floatBound,o=a[i],l=a[i+1],_=a[i+2],h=a[i+7],c=a[i+8],d=a[i+9],u=s[0],m=s[1],f=s[2],T=s[3],E=s[4],p=s[5];o!==u&&o!==T&&l!==m&&l!==E&&_!==f&&_!==p&&h!==u&&h!==T&&c!==m&&c!==E&&d!==f&&d!==p||(this._calculateBound=!0)}_updateLineData(e,t,r,i,a){var n=2*this._floatCountPerVertices;this._updateLineVertices(e*n,t,r,i,a)}_updateLineDatas(e,t){for(var r=2*this._floatCountPerVertices,i=t.length,a=0;a<i;a++){var n=t[a];this._updateLineVertices((e+a)*r,n.startPosition,n.endPosition,n.startColor,n.endColor)}}_getLineData(e,t){var r=t.startPosition,i=t.startColor,a=t.endPosition,n=t.endColor,s=this._vertices,o=e*this._floatCountPerVertices*2;r.x=s[o+0],r.y=s[o+1],r.z=s[o+2],i.r=s[o+3],i.g=s[o+4],i.b=s[o+5],i.a=s[o+6],a.x=s[o+7],a.y=s[o+8],a.z=s[o+9],n.r=s[o+10],n.g=s[o+11],n.b=s[o+12],n.a=s[o+13]}_prepareRender(e){return!0}_render(e){if(this._minUpdate!==Number.MAX_VALUE&&this._maxUpdate!==Number.MIN_VALUE&&(this._vertexBuffer.setData(this._vertices.buffer,4*this._minUpdate,4*this._minUpdate,4*(this._maxUpdate-this._minUpdate)),this._minUpdate=Number.MAX_VALUE,this._maxUpdate=Number.MIN_VALUE),this._lineCount>0){this._bufferState.bind();var r=t.LayaGL.instance;r.drawArrays(r.LINES,0,2*this._lineCount),t.Stat.renderBatches++}}destroy(){this._destroyed||(super.destroy(),this._bufferState.destroy(),this._vertexBuffer.destroy(),this._bufferState=null,this._vertexBuffer=null,this._vertices=null)}}Ht._tempVector0=new n,Ht._tempVector1=new n,Ht._type=Gt._typeCounter++;class kt extends Ce{constructor(e){super(e)}static __init__(){kt.SHADERDEFINE_RECEIVE_SHADOW=xe.getDefineByName("RECEIVESHADOW"),kt.SAHDERDEFINE_LIGHTMAP=xe.getDefineByName("LIGHTMAP"),kt.SHADERDEFINE_LIGHTMAP_DIRECTIONAL=xe.getDefineByName("LIGHTMAP_DIRECTIONAL")}_onInActive(){super._onInActive(),this._scene._removeRenderObject(this._render)}_onActive(){super._onActive(),this._scene._addRenderObject(this._render)}_onActiveInScene(){if(super._onActiveInScene(),g.Laya3D._editerEnvironment){var e=this._scene,t=new a;e._allotPickColorByID(this.id,t),e._pickIdToSprite[this.id]=this,this._render._shaderValues.setVector(kt.PICKCOLOR,t)}}_addToInitStaticBatchManager(){}_setBelongScene(e){super._setBelongScene(e),this._render._setBelongScene(e)}_setUnBelongScene(){this._render._shaderValues.removeDefine(kt.SAHDERDEFINE_LIGHTMAP),super._setUnBelongScene()}_changeHierarchyAnimator(e){if(this._hierarchyAnimator){var t=this._hierarchyAnimator._renderableSprites;t.splice(t.indexOf(this),1)}e&&e._renderableSprites.push(this),super._changeHierarchyAnimator(e)}destroy(e=!0){super.destroy(e),this._render._destroy(),this._render=null}_create(){return new kt(this.name)}}kt.LIGHTMAPSCALEOFFSET=xe.propertyNameToID("u_LightmapScaleOffset"),kt.LIGHTMAP=xe.propertyNameToID("u_LightMap"),kt.LIGHTMAP_DIRECTION=xe.propertyNameToID("u_LightMapDirection"),kt.PICKCOLOR=xe.propertyNameToID("u_PickColor"),kt.REFLECTIONTEXTURE=xe.propertyNameToID("u_ReflectTexture"),kt.REFLECTIONCUBE_HDR_PARAMS=xe.propertyNameToID("u_ReflectCubeHDRParams"),kt.REFLECTIONCUBE_PROBEPOSITION=xe.propertyNameToID("u_SpecCubeProbePosition"),kt.REFLECTIONCUBE_PROBEBOXMAX=xe.propertyNameToID("u_SpecCubeBoxMax"),kt.REFLECTIONCUBE_PROBEBOXMIN=xe.propertyNameToID("u_SpecCubeBoxMin");class Wt{constructor(){this.updateMark=-1,this.indexInList=-1,this.batched=!1}}class Xt extends Gt{constructor(){super(),this.maxInstanceCount=1024,this.instanceWorldMatrixData=new Float32Array(16*this.maxInstanceCount),this.instanceMVPMatrixData=new Float32Array(16*this.maxInstanceCount),this.instanceSimpleAnimatorData=new Float32Array(4*this.maxInstanceCount);var e=t.LayaGL.instance;this.instanceWorldMatrixBuffer=new de(4*this.instanceWorldMatrixData.length,e.DYNAMIC_DRAW),this.instanceMVPMatrixBuffer=new de(4*this.instanceMVPMatrixData.length,e.DYNAMIC_DRAW),this.instanceWorldMatrixBuffer.vertexDeclaration=ze.instanceWorldMatrixDeclaration,this.instanceMVPMatrixBuffer.vertexDeclaration=ze.instanceMVPMatrixDeclaration,this.instanceSimpleAnimatorBuffer=new de(4*this.instanceSimpleAnimatorData.length,e.DYNAMIC_DRAW),this.instanceSimpleAnimatorBuffer.vertexDeclaration=ze.instanceSimpleAnimatorDeclaration}static __init__(){Xt.instance=new Xt}_render(e){var r=t.LayaGL.instance,i=e.renderElement,a=i.instanceSubMesh,n=i.instanceBatchElementList.length,s=a._indexCount;a._mesh._instanceBufferState.bind(),t.LayaGL.layaGPUInstance.drawElementsInstanced(r.TRIANGLES,s,r.UNSIGNED_SHORT,2*a._indexStart,n),t.Stat.renderBatches++,t.Stat.savedRenderBatches+=n-1,t.Stat.trianglesFaces+=s*n/3}}class Yt extends Ke{constructor(){super(),this._dynamicWorldPositionNormalNeedUpdate=!0}_onWorldMatrixChanged(){this._dynamicWorldPositionNormalNeedUpdate=!0}_computeWorldPositionsAndNormals(e,t,r,i){if(this._dynamicWorldPositionNormalNeedUpdate){for(var a=this._geometry,n=a._vertexBuffer,s=n.vertexDeclaration.vertexStride/4,o=n.getFloat32Data(),l=this._transform.worldMatrix,_=this._transform.rotation,h=a._indices,c=0;c<i;c++){var d=(r?h[c]:c)*s,u=3*c;H.transformVector3ArrayToVector3ArrayCoordinate(o,d+e,l,this._dynamicWorldPositions,u),-1!==t&&H.transformVector3ArrayByQuat(o,d+t,_,this._dynamicWorldNormals,u)}this._dynamicWorldPositionNormalNeedUpdate=!1}}setTransform(e){this._transform!==e&&(this._transform&&this._transform.off(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatrixChanged),e&&e.on(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatrixChanged),this._dynamicWorldPositionNormalNeedUpdate=!0,this._transform=e)}setGeometry(e){if(this._geometry!==e){var t=e,r=t._mesh;if(r){var i=r._subMeshes.length>1,a=i?t._indexCount:r._vertexCount;if(a<=g.SubMeshDynamicBatch.maxAllowVertexCount){var n=3*a;this._dynamicVertexBatch=!0,this._dynamicWorldPositions=new Float32Array(n),this._dynamicWorldNormals=new Float32Array(n),this._dynamicVertexCount=a,this._dynamicMultiSubMesh=i}else this._dynamicVertexBatch=!1}this._geometry=e}}addToOpaqueRenderQueue(e,r){var i=this.staticBatch,a=r.elements,n=a.elements;if(!i||this.render._probReflection&&!this.render._probReflection._isScene)if(this.renderSubShader._owner._enableInstancing&&t.LayaGL.layaGPUInstance.supportInstance()&&this.render.lightmapIndex<0&&(!this.render._probReflection||this.render._probReflection._isScene)){var s=this._geometry,o=g.MeshRenderDynamicBatchManager.instance,l=o.getInstanceBatchOpaquaMark(this.render.receiveShadow,this.material.id,s._id,this._transform._isFrontFaceInvert);if(o._updateCountMark===l.updateMark){var _=l.indexInList;if(l.batched){var h=n[_].instanceBatchElementList;h.length===Xt.instance.maxInstanceCount?(l.updateMark=o._updateCountMark,l.indexInList=a.length,l.batched=!1,a.add(this)):h.add(this)}else{var c=n[_],d=c.render,u=o._getBatchRenderElementFromPool();u.renderType=Ke.RENDERTYPE_INSTANCEBATCH,u.setGeometry(Xt.instance),u.material=c.material,u.setTransform(null),u.render=d,u.instanceSubMesh=s,u.renderSubShader=c.renderSubShader;var m=u.instanceBatchElementList;m.length=0,m.add(c),m.add(this),n[_]=u,l.batched=!0}}else l.updateMark=o._updateCountMark,l.indexInList=a.length,l.batched=!1,a.add(this)}else if(this._dynamicVertexBatch){var f=this._geometry._vertexBuffer.vertexDeclaration,T=g.MeshRenderDynamicBatchManager.instance,E=T.getVertexBatchOpaquaMark(this.render.lightmapIndex+1,this.render.receiveShadow,this.material.id,f.id);if(T._updateCountMark===E.updateMark){var p=E.indexInList;if(E.batched)n[p].vertexBatchElementList.add(this);else{var S=n[p],R=S.render,v=T._getBatchRenderElementFromPool();v.renderType=Ke.RENDERTYPE_VERTEXBATCH,v.setGeometry(g.SubMeshDynamicBatch.instance),v.material=S.material,v.setTransform(null),v.render=R,v.vertexBatchVertexDeclaration=f,v.renderSubShader=S.renderSubShader;var x=v.vertexBatchElementList;x.length=0,x.add(S),x.add(this),n[p]=v,E.batched=!0}}else E.updateMark=T._updateCountMark,E.indexInList=a.length,E.batched=!1,a.add(this)}else a.add(this);else{var A=g.MeshRenderStaticBatchManager.instance,I=A.getBatchOpaquaMark(this.render.lightmapIndex+1,this.render.receiveShadow,this.material.id,i._batchID);if(A._updateCountMark===I.updateMark){var M=I.indexInList;if(I.batched)n[M].staticBatchElementList.add(this);else{var D=n[M],C=D.render,y=A._getBatchRenderElementFromPool();y.renderType=Ke.RENDERTYPE_STATICBATCH,y.setGeometry(i),y.material=D.material;var L=i.batchOwner,O=L?L._transform:null;y.setTransform(O),y.render=C,y.renderSubShader=D.renderSubShader;var N=y.staticBatchElementList;N.length=0,N.add(D),N.add(this),n[M]=y,I.batched=!0}}else I.updateMark=A._updateCountMark,I.indexInList=a.length,I.batched=!1,a.add(this)}}addToTransparentRenderQueue(e,r){var i=this.staticBatch,a=r.elements,n=a.elements;if(i){var s=g.MeshRenderStaticBatchManager.instance,o=r.lastTransparentRenderElement;if(o){var l=o.render;if(o._geometry._getType()!==this._geometry._getType()||o.staticBatch!==i||o.material!==this.material||l.receiveShadow!==this.render.receiveShadow||l.lightmapIndex!==this.render.lightmapIndex)a.add(this),r.lastTransparentBatched=!1;else{if(r.lastTransparentBatched)n[a.length-1].staticBatchElementList.add(this);else{var _=s._getBatchRenderElementFromPool();_.renderType=Ke.RENDERTYPE_STATICBATCH,_.setGeometry(i),_.material=o.material;var h=i.batchOwner,c=h?h._transform:null;_.setTransform(c),_.render=this.render,_.renderSubShader=o.renderSubShader;var d=_.staticBatchElementList;d.length=0,d.add(o),d.add(this),n[a.length-1]=_}r.lastTransparentBatched=!0}}else a.add(this),r.lastTransparentBatched=!1}else if(this.renderSubShader._owner._enableInstancing&&t.LayaGL.layaGPUInstance.supportInstance()&&this.render.lightmapIndex<0&&(!this.render._probReflection||this.render._probReflection._isScene)){var u=this._geometry,m=g.MeshRenderDynamicBatchManager.instance,f=r.lastTransparentRenderElement;if(f){var T=f.render;if(f._geometry._getType()!==this._geometry._getType()||f._geometry!==u||f.material!==this.material||T.receiveShadow!==this.render.receiveShadow)a.add(this),r.lastTransparentBatched=!1;else if(r.lastTransparentBatched){var E=n[a.length-1].instanceBatchElementList;E.length===Xt.instance.maxInstanceCount?(a.add(this),r.lastTransparentBatched=!1):(E.add(this),r.lastTransparentBatched=!0)}else{var p=m._getBatchRenderElementFromPool();p.renderType=Ke.RENDERTYPE_INSTANCEBATCH,p.setGeometry(Xt.instance),p.material=f.material,p.setTransform(null),p.render=this.render,p.instanceSubMesh=u,p.renderSubShader=f.renderSubShader;var S=p.instanceBatchElementList;S.length=0,S.add(f),S.add(this),n[a.length-1]=p,r.lastTransparentBatched=!0}}else a.add(this),r.lastTransparentBatched=!1}else if(this._dynamicVertexBatch){var R=this._geometry._vertexBuffer.vertexDeclaration,v=g.MeshRenderDynamicBatchManager.instance,x=r.lastTransparentRenderElement;if(x){var A=x.render;if(x._dynamicVertexBatch&&x._geometry._getType()===this._geometry._getType()&&x._geometry._vertexBuffer._vertexDeclaration===R&&x.material===this.material&&A.receiveShadow===this.render.receiveShadow&&A.lightmapIndex===this.render.lightmapIndex){if(r.lastTransparentBatched)n[a.length-1].vertexBatchElementList.add(this);else{var I=v._getBatchRenderElementFromPool();I.renderType=Ke.RENDERTYPE_VERTEXBATCH,I.setGeometry(g.SubMeshDynamicBatch.instance),I.material=x.material,I.setTransform(null),I.render=this.render,I.vertexBatchVertexDeclaration=R,I.renderSubShader=x.renderSubShader;var M=I.vertexBatchElementList;M.length=0,M.add(x),M.add(this),n[a.length-1]=I}r.lastTransparentBatched=!0}else a.add(this),r.lastTransparentBatched=!1}else a.add(this),r.lastTransparentBatched=!1}else a.add(this);r.lastTransparentRenderElement=this}getInvertFront(){switch(this.renderType){case Ke.RENDERTYPE_NORMAL:return this._transform._isFrontFaceInvert;case Ke.RENDERTYPE_STATICBATCH:case Ke.RENDERTYPE_VERTEXBATCH:return!1;case Ke.RENDERTYPE_INSTANCEBATCH:return this.instanceBatchElementList.elements[0]._transform._isFrontFaceInvert;default:throw"SubMeshRenderElement: unknown renderType"}}destroy(){super.destroy(),this._dynamicWorldPositions=null,this._dynamicWorldNormals=null,this.staticBatch=null,this.staticBatchElementList=null,this.vertexBatchElementList=null,this.vertexBatchVertexDeclaration=null}}class jt{constructor(){this._initBatchSprites=[],this._staticBatches={},this._batchRenderElementPoolIndex=0,this._batchRenderElementPool=[]}static _addToStaticBatchQueue(e,t){e instanceof kt&&t.push(e);for(var r=0,i=e.numChildren;r<i;r++)jt._addToStaticBatchQueue(e._children[r],t)}static _registerManager(e){jt._managers.push(e)}static combine(e,t=null){t||(t=[],e&&jt._addToStaticBatchQueue(e,t));var r=t.length;if(r>0){for(var i=0;i<r;i++){var a=t[i];a.destroyed||(a._render._isPartOfStaticBatch?console.warn("StaticBatchManager: Sprite "+a.name+" has a part of Static Batch,it will be ignore."):a._addToInitStaticBatchManager())}for(var n=0,s=jt._managers.length;n<s;n++){jt._managers[n]._initStaticBatchs(e)}}}_partition(e,t,r){for(var i=e[Math.floor((r+t)/2)];t<=r;){for(;this._compare(e[t],i)<0;)t++;for(;this._compare(e[r],i)>0;)r--;if(t<r){var a=e[t];e[t]=e[r],e[r]=a,t++,r--}else if(t===r){t++;break}}return t}_quickSort(e,t,r){if(e.length>1){var i=this._partition(e,t,r),a=i-1;t<a&&this._quickSort(e,t,a),i<r&&this._quickSort(e,i,r)}}_compare(e,t){throw"StaticBatch:must override this function."}_initStaticBatchs(e){throw"StaticBatch:must override this function."}_getBatchRenderElementFromPool(){throw"StaticBatch:must override this function."}_addBatchSprite(e){this._initBatchSprites.push(e)}_clear(){this._batchRenderElementPoolIndex=0}_garbageCollection(){throw"StaticBatchManager: must override it."}dispose(){this._staticBatches=null}}jt._managers=[];class Zt extends Gt{constructor(e,t){super(),this._bufferState=new Ee,this._batchID=Zt._batchIDCounter++,this._batchElements=[],this._currentBatchVertexCount=0,this._currentBatchIndexCount=0,this._vertexDeclaration=t,this.batchOwner=e}_getStaticBatchBakedVertexs(e,t,r,i,a,n){var s,o=n._vertexBuffer,l=o.vertexDeclaration,_=l.getVertexElementByUsage(ze.MESH_POSITION0)._offset/4,h=l.getVertexElementByUsage(ze.MESH_NORMAL0),c=h?h._offset/4:-1,d=l.getVertexElementByUsage(ze.MESH_COLOR0),u=d?d._offset/4:-1,m=l.getVertexElementByUsage(ze.MESH_TEXTURECOORDINATE0),f=m?m._offset/4:-1,T=l.getVertexElementByUsage(ze.MESH_TEXTURECOORDINATE1),E=T?T._offset/4:-1,p=l.getVertexElementByUsage(ze.MESH_TANGENT0),g=p?p._offset/4:-1,S=l.vertexStride/4,v=o.getFloat32Data();r?(r.worldMatrix.invert(Zt._tempMatrix4x40),s=Zt._tempMatrix4x41,R.multiply(Zt._tempMatrix4x40,i.worldMatrix,s)):s=i.worldMatrix;var x=Zt._tempMatrix4x42;s.invert(x),x.transpose();var A=Zt._tempQuaternion0;s.decomposeTransRotScale(Zt._tempVector30,A,Zt._tempVector31);for(var I=a.lightmapScaleOffset,M=n.vertexCount,D=0;D<M;D++){var C,y,L=D*S,O=18*(D+t);H.transformVector3ArrayToVector3ArrayCoordinate(v,L+_,s,e,O+0),-1!==c&&H.transformVector3ArrayToVector3ArrayNormal(v,L+c,x,e,O+3);var N=O+6;if(-1!==u){var P=L+u;for(C=0,y=4;C<y;C++)e[N+C]=v[P+C]}else for(C=0,y=4;C<y;C++)e[N+C]=1;if(-1!==f){var b=L+f;e[O+10]=v[b],e[O+11]=v[b+1]}if(I&&(-1!==E?H.transformLightingMapTexcoordArray(v,L+E,I,e,O+12):H.transformLightingMapTexcoordArray(v,L+f,I,e,O+12)),-1!==g){var w=L+g;H.transformVector3ArrayToVector3ArrayNormal(v,w,x,e,O+14),e[O+17]=v[w+3]}}return M}addTest(e){var t=e.meshFilter.sharedMesh.vertexCount;return!(this._currentBatchVertexCount+t>Zt.maxBatchVertexCount)}add(e){var t=e.meshFilter.sharedMesh,r=t.vertexCount;this._batchElements.push(e);var i=e._render;i._isPartOfStaticBatch=!0,i._staticBatch=this;for(var a=i._renderElements,n=0,s=a.length;n<s;n++)a[n].staticBatch=this;this._currentBatchIndexCount+=t._indexBuffer.indexCount,this._currentBatchVertexCount+=r}remove(e){var t=e.meshFilter.sharedMesh,r=this._batchElements.indexOf(e);if(-1!==r){this._batchElements.splice(r,1);for(var i=e._render._renderElements,a=0,n=i.length;a<n;a++)i[a].staticBatch=null;this._currentBatchIndexCount=this._currentBatchIndexCount-t._indexBuffer.indexCount,this._currentBatchVertexCount=this._currentBatchVertexCount-t.vertexCount,e._render._isPartOfStaticBatch=!1}}finishInit(){this._vertexBuffer&&(this._vertexBuffer.destroy(),this._indexBuffer.destroy(),t.Resource._addGPUMemory(-(this._vertexBuffer._byteLength+this._indexBuffer._byteLength)));var r=t.LayaGL.instance,i=0,a=0,n=this.batchOwner,s=this._vertexDeclaration.vertexStride/4,o=new Float32Array(s*this._currentBatchVertexCount),l=new Uint16Array(this._currentBatchIndexCount);this._vertexBuffer=new de(this._vertexDeclaration.vertexStride*this._currentBatchVertexCount,r.STATIC_DRAW),this._vertexBuffer.vertexDeclaration=this._vertexDeclaration,this._indexBuffer=new Ge(e.IndexFormat.UInt16,this._currentBatchIndexCount,r.STATIC_DRAW);for(var _=0,h=this._batchElements.length;_<h;_++){for(var c,d=this._batchElements[_],u=d.meshFilter.sharedMesh,m=this._getStaticBatchBakedVertexs(o,i,n?n._transform:null,d._transform,d._render,u),f=u._indexBuffer.getData(),T=i,E=a+f.length,p=d._render._renderElements,g=0,S=u.subMeshCount;g<S;g++){var R=u._subMeshes[g],v=a+R._indexStart,x=p[g];x.staticBatchIndexStart=v,x.staticBatchIndexEnd=v+R._indexCount}if(l.set(f,a),n?d._transform._isFrontFaceInvert!==n.transform._isFrontFaceInvert:d._transform._isFrontFaceInvert)for(c=a;c<E;c+=3){l[c]=T+l[c];var A=l[c+1],I=l[c+2];l[c+1]=T+I,l[c+2]=T+A}else for(c=a;c<E;c+=3)l[c]=T+l[c],l[c+1]=T+l[c+1],l[c+2]=T+l[c+2];a+=f.length,i+=m}this._vertexBuffer.setData(o.buffer),this._indexBuffer.setData(l);var M=this._vertexBuffer._byteLength+this._indexBuffer._byteLength;t.Resource._addGPUMemory(M),this._bufferState.bind(),this._bufferState.applyVertexBuffer(this._vertexBuffer),this._bufferState.applyIndexBuffer(this._indexBuffer),this._bufferState.unBind()}_render(e){this._bufferState.bind();for(var r=t.LayaGL.instance,i=e.renderElement.staticBatchElementList,a=i.elements,n=0,s=0,o=i.length,l=1;l<o;l++){if(a[l-1].staticBatchIndexEnd!==a[l].staticBatchIndexStart){var _=a[n].staticBatchIndexStart,h=a[s].staticBatchIndexEnd-_;r.drawElements(r.TRIANGLES,h,r.UNSIGNED_SHORT,2*_),n=++s,t.Stat.trianglesFaces+=h/3}else s++}_=a[n].staticBatchIndexStart,h=a[s].staticBatchIndexEnd-_,r.drawElements(r.TRIANGLES,h,r.UNSIGNED_SHORT,2*_),t.Stat.renderBatches++,t.Stat.savedRenderBatches+=o-1,t.Stat.trianglesFaces+=h/3}dispose(){var e=this._vertexBuffer._byteLength+this._indexBuffer._byteLength;t.Resource._addGPUMemory(-e),this._batchElements=null,this.batchOwner=null,this._vertexDeclaration=null,this._bufferState.destroy(),this._vertexBuffer.destroy(),this._indexBuffer.destroy(),this._vertexBuffer=null,this._indexBuffer=null,this._bufferState=null}}Zt._tempVector30=new n,Zt._tempVector31=new n,Zt._tempQuaternion0=new S,Zt._tempMatrix4x40=new R,Zt._tempMatrix4x41=new R,Zt._tempMatrix4x42=new R,Zt.maxBatchVertexCount=65535,Zt._batchIDCounter=0;class qt extends jt{constructor(){super(),this._opaqueBatchMarks=[],this._updateCountMark=0}static __init__(){qt._verDec=ze.getVertexDeclaration("POSITION,NORMAL,COLOR,UV,UV1,TANGENT")}_compare(e,t){var r=e._render,i=t._render,a=e.meshFilter.sharedMesh,n=t.meshFilter.sharedMesh,s=r.lightmapIndex-i.lightmapIndex;if(0===s){var o=(r.receiveShadow?1:0)-(i.receiveShadow?1:0);if(0===o){var l=r.sharedMaterial&&i.sharedMaterial?r.sharedMaterial.id-i.sharedMaterial.id:0;if(0===l){var _=a._vertexBuffer.vertexDeclaration.id-n._vertexBuffer.vertexDeclaration.id;return 0===_?n._indexBuffer.indexCount-a._indexBuffer.indexCount:_}return l}return o}return s}_getBatchRenderElementFromPool(){var e=this._batchRenderElementPool[this._batchRenderElementPoolIndex++];return e||(e=new Yt,this._batchRenderElementPool[this._batchRenderElementPoolIndex-1]=e,e.staticBatchElementList=new b),e}_getStaticBatch(e,t,r){var i=e[r];return i||(i=e[r]=new Zt(t,qt._verDec),this._staticBatches[i._batchID]=i),i}_initStaticBatchs(e){var t=this._initBatchSprites;this._quickSort(t,0,t.length-1);for(var r,i=[],a=!1,n=0,s=0,o=t.length;s<o;s++){var l=t[s];if(a)r.addTest(l)?r.add(l):(a=!1,n++);else s!==o-1&&((r=this._getStaticBatch(i,e,n)).add(l),a=!0)}for(s=0,o=i.length;s<o;s++){var _=i[s];_&&_.finishInit()}this._initBatchSprites.length=0}_removeRenderSprite(e){var t=e._render,r=t._staticBatch,i=r._batchElements,a=i.indexOf(e);if(-1!==a){i.splice(a,1),t._staticBatch=null;for(var n=t._renderElements,s=0,o=n.length;s<o;s++)n[s].staticBatch=null}0===i.length&&(delete this._staticBatches[r._batchID],r.dispose())}_clear(){super._clear(),this._updateCountMark++}_garbageCollection(){for(var e in this._staticBatches){var t=this._staticBatches[e];0===t._batchElements.length&&(t.dispose(),delete this._staticBatches[e])}}getBatchOpaquaMark(e,t,r,i){var a=t?1:0,n=this._opaqueBatchMarks[e]||(this._opaqueBatchMarks[e]=[]),s=n[a]||(n[a]=[]),o=s[r]||(s[r]=[]);return o[i]||(o[i]=new Wt)}}qt.instance=new qt,(mt=e.ReflectionProbeMode||(e.ReflectionProbeMode={}))[mt.off=0]="off",mt[mt.simple=1]="simple";class Qt extends Ce{constructor(){super(),this._boxProjection=!1,this._size=new n,this._offset=new n,this._reflectionHDRParams=new a,this._reflectionDecodeFormat=t.TextureDecodeFormat.Normal,this._isScene=!1}get boxProjection(){return this._boxProjection}set boxProjection(e){this._boxProjection=e}get importance(){return this._importance}set importance(e){this._importance=e}get intensity(){return this._intensity}set intensity(e){e=Math.max(Math.min(e,1),0),this._reflectionHDRParams.x=e,this._reflectionDecodeFormat==t.TextureDecodeFormat.RGBM&&(this._reflectionHDRParams.x*=5),this._intensity=e}get reflectionTexture(){return this._reflectionTexture}set reflectionTexture(e){this._reflectionTexture=e,this._reflectionTexture._addReference()}get bounds(){return this._bounds}set bounds(e){this._bounds=e}get boundsMax(){return this._bounds.getMax()}get boundsMin(){return this._bounds.getMin()}get probePosition(){return this.transform.position}get reflectionHDRParams(){return this._reflectionHDRParams}set reflectionHDRParams(e){this._reflectionHDRParams=e}_parse(e,r){super._parse(e,r),this._boxProjection=e.boxProjection,this._importance=e.importance,this._reflectionTexture=t.Loader.getRes(e.reflection);var i=this.transform.position;this._size.fromArray(e.boxSize),n.scale(this._size,.5,Qt.TEMPVECTOR3),this._offset.fromArray(e.boxOffset);var a=new n,s=new n;n.add(i,Qt.TEMPVECTOR3,s),n.add(s,this._offset,s),n.subtract(i,Qt.TEMPVECTOR3,a),n.add(a,this._offset,a),this._reflectionDecodeFormat=e.reflectionDecodingFormat,this.intensity=e.intensity,this._bounds?(this._bounds.setMin(a),this._bounds.setMax(s)):this.bounds=new Ut(a,s)}_setIndexInReflectionList(e){this._indexInReflectProbList=e}_getIndexInReflectionList(){return this._indexInReflectProbList}_onActive(){super._onActive(),this._reflectionTexture&&this.scene._reflectionProbeManager.add(this)}_onInActive(){super._onInActive(),this.reflectionTexture&&this.scene._reflectionProbeManager.remove(this)}destroy(e=!0){this.destroyed||(super.destroy(e),this._reflectionTexture&&this._reflectionTexture._removeReference(),this._reflectionTexture=null,this._bounds=null)}_cloneTo(e,t,r){var i=e;i.bounds=this.bounds,i.boxProjection=this.boxProjection,i.importance=this.importance,i._size=this._size,i._offset=this._offset,i.intensity=this.intensity,i.reflectionHDRParams=this.reflectionHDRParams,super._cloneTo(e,t,r)}}Qt.TEMPVECTOR3=new n,Qt.defaultTextureHDRDecodeValues=new a(1,1,0,0);class Kt extends t.EventDispatcher{constructor(r){super(),this._lightmapScaleOffset=new a(1,1,0,0),this._indexInList=-1,this._indexInCastShadowList=-1,this._boundsChange=!0,this._castShadow=!1,this._supportOctree=!0,this._sharedMaterials=[],this._renderMark=-1,this._indexInOctreeMotionList=-1,this._reflectionMode=e.ReflectionProbeMode.simple,this._updateMark=-1,this._updateRenderType=-1,this._isPartOfStaticBatch=!1,this._staticBatch=null,this._id=++Kt._uniqueIDCounter,this._indexInCastShadowList=-1,this._bounds=new Ut(n._ZERO,n._ZERO),this._renderElements=[],this._owner=r,this._enable=!0,this._materialsInstance=[],this._shaderValues=new me(null),this.lightmapIndex=-1,this.receiveShadow=!1,this.sortingFudge=0,r&&this._owner.transform.on(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange)}get id(){return this._id}get lightmapIndex(){return this._lightmapIndex}set lightmapIndex(e){this._lightmapIndex=e}get lightmapScaleOffset(){return this._lightmapScaleOffset}set lightmapScaleOffset(e){if(!e)throw"BaseRender: lightmapScaleOffset can't be null.";this._lightmapScaleOffset=e,this._shaderValues.setVector(kt.LIGHTMAPSCALEOFFSET,e)}get enable(){return this._enable}set enable(e){this._enable=!!e}get material(){var e=this._sharedMaterials[0];if(e&&!this._materialsInstance[0]){var t=this._getInstanceMaterial(e,0),r=this._renderElements[0];r&&(r.material=t)}return this._sharedMaterials[0]}set material(e){this.sharedMaterial=e,this._isSupportReflection()}get materials(){for(var e=0,t=this._sharedMaterials.length;e<t;e++)if(!this._materialsInstance[e]){var r=this._getInstanceMaterial(this._sharedMaterials[e],e),i=this._renderElements[e];i&&(i.material=r)}return this._sharedMaterials.slice()}set materials(e){this.sharedMaterials=e,this._isSupportReflection()}get sharedMaterial(){return this._sharedMaterials[0]}set sharedMaterial(e){var t=this._sharedMaterials[0];if(t!==e){this._sharedMaterials[0]=e,this._materialsInstance[0]=!1,this._changeMaterialReference(t,e);var r=this._renderElements[0];r&&(r.material=e)}this._isSupportReflection()}get sharedMaterials(){return this._sharedMaterials.slice()}set sharedMaterials(e){for(var t=this._materialsInstance,r=this._sharedMaterials,i=0,a=r.length;i<a;i++){var n=r[i];n&&n._removeReference()}if(!e)throw new Error("BaseRender: shadredMaterials value can't be null.");var s=e.length;for(t.length=s,r.length=s,i=0;i<s;i++){n=r[i];var o=e[i];if(n!==o){t[i]=!1;var l=this._renderElements[i];l&&(l.material=o)}o&&o._addReference(),r[i]=o}this._isSupportReflection()}get bounds(){return this._boundsChange&&(this._calculateBoundingBox(),this._boundsChange=!1),this._bounds}set receiveShadow(e){this._receiveShadow!==e&&(this._receiveShadow=e,e?this._shaderValues.addDefine(kt.SHADERDEFINE_RECEIVE_SHADOW):this._shaderValues.removeDefine(kt.SHADERDEFINE_RECEIVE_SHADOW))}get receiveShadow(){return this._receiveShadow}get castShadow(){return this._castShadow}set castShadow(e){this._castShadow=e}get isPartOfStaticBatch(){return this._isPartOfStaticBatch}get isRender(){return-1==this._renderMark||this._renderMark==t.Stat.loopCount-1}set reflectionMode(e){this._reflectionMode=e}get reflectionMode(){return this._reflectionMode}_getOctreeNode(){return this._octreeNode}_setOctreeNode(e){e||-1!==this._indexInOctreeMotionList&&this._octreeNode._octree.removeMotionObject(this),this._octreeNode=e}_getIndexInMotionList(){return this._indexInOctreeMotionList}_setIndexInMotionList(e){this._indexInOctreeMotionList=e}_changeMaterialReference(e,t){e&&e._removeReference(),t._addReference()}_getInstanceMaterial(e,t){var r=e.clone();return r.name=r.name+"(Instance)",this._materialsInstance[t]=!0,this._changeMaterialReference(this._sharedMaterials[t],r),this._sharedMaterials[t]=r,r}_isSupportReflection(){this._surportReflectionProbe=!1;for(var e=this._sharedMaterials,t=0,r=e.length;t<r;t++){var i=e[t];this._surportReflectionProbe=this._surportReflectionProbe||i&&i._shader._supportReflectionProbe}}_addReflectionProbeUpdate(){this._surportReflectionProbe&&1==this._reflectionMode&&this._scene._reflectionProbeManager.addMotionObject(this)}_applyLightMapParams(){var e=this._scene.lightmaps,t=this._shaderValues,r=this._lightmapIndex;if(r>=0&&r<e.length){var i=e[r];t.setTexture(kt.LIGHTMAP,i.lightmapColor),t.addDefine(kt.SAHDERDEFINE_LIGHTMAP),i.lightmapDirection?(t.setTexture(kt.LIGHTMAP_DIRECTION,i.lightmapDirection),t.addDefine(kt.SHADERDEFINE_LIGHTMAP_DIRECTIONAL)):t.removeDefine(kt.SHADERDEFINE_LIGHTMAP_DIRECTIONAL)}else t.removeDefine(kt.SAHDERDEFINE_LIGHTMAP),t.removeDefine(kt.SHADERDEFINE_LIGHTMAP_DIRECTIONAL)}_onWorldMatNeedChange(e){this._boundsChange=!0,this._octreeNode&&(e&=I.TRANSFORM_WORLDPOSITION|I.TRANSFORM_WORLDQUATERNION|I.TRANSFORM_WORLDSCALE)&&-1===this._indexInOctreeMotionList&&this._octreeNode._octree.addMotionObject(this),this._addReflectionProbeUpdate()}_calculateBoundingBox(){throw"BaseRender: must override it."}_getIndexInList(){return this._indexInList}_setIndexInList(e){this._indexInList=e}_setBelongScene(e){this._scene=e}_needRender(e,t){return!0}_renderUpdate(e,t){}_renderUpdateWithCamera(e,t){}_revertBatchRenderUpdate(e){}_destroy(){-1!==this._indexInOctreeMotionList&&this._octreeNode._octree.removeMotionObject(this),this.offAll();var e=0,t=0;for(e=0,t=this._renderElements.length;e<t;e++)this._renderElements[e].destroy();for(e=0,t=this._sharedMaterials.length;e<t;e++)this._sharedMaterials[e].destroyed||this._sharedMaterials[e]._removeReference();this._renderElements=null,this._owner=null,this._sharedMaterials=null,this._bounds=null,this._lightmapScaleOffset=null}markAsUnStatic(){this._isPartOfStaticBatch&&(qt.instance._removeRenderSprite(this._owner),this._isPartOfStaticBatch=!1)}}Kt._tempBoundBoxCorners=[new n,new n,new n,new n,new n,new n,new n,new n],Kt._uniqueIDCounter=0,Kt._defaultLightmapScaleOffset=new a(1,1,0,0);class Jt extends Kt{constructor(e){super(e),this._projectionViewWorldMatrix=new R}_calculateBoundingBox(){var e=this._owner.transform.worldMatrix,t=this._owner._geometryFilter;t._reCalculateBound(),t._bounds._tranform(e,this._bounds)}_renderUpdateWithCamera(e,t){var r=e.projectionViewMatrix,i=this._shaderValues;if(t){var a=t.worldMatrix;i.setMatrix4x4(Ce.WORLDMATRIX,a),R.multiply(r,a,this._projectionViewWorldMatrix),i.setMatrix4x4(Ce.MVPMATRIX,this._projectionViewWorldMatrix)}else i.setMatrix4x4(Ce.WORLDMATRIX,R.DEFAULT),i.setMatrix4x4(Ce.MVPMATRIX,r)}}class $t extends kt{constructor(e=2,t=null){super(t),this._isRenderActive=!1,this._isInRenders=!1,this._geometryFilter=new Ht(this,e),this._render=new Jt(this),this._changeRenderObjects(this._render,0,Bt.defaultMaterial)}get maxLineCount(){return this._geometryFilter._maxLineCount}set maxLineCount(e){this._geometryFilter._resizeLineData(e),this._geometryFilter._lineCount=Math.min(this._geometryFilter._lineCount,e)}get lineCount(){return this._geometryFilter._lineCount}set lineCount(e){if(e>this.maxLineCount)throw"PixelLineSprite3D: lineCount can't large than maxLineCount";this._geometryFilter._lineCount=e}get pixelLineRenderer(){return this._render}_onInActive(){t.Stat.spriteCount--,0!=this._geometryFilter._lineCount&&this._isRenderActive&&(this._scene._removeRenderObject(this._render),this._isInRenders=!1),this._isRenderActive=!1}_onActive(){t.Stat.spriteCount++,this._isRenderActive=!0,0!=this._geometryFilter._lineCount&&(this._scene._addRenderObject(this._render),this._isInRenders=!0)}_changeRenderObjects(e,t,r){var i=this._render._renderElements;r||(r=Bt.defaultMaterial);var a=i[t];a||(a=i[t]=new Ke),a.setTransform(this._transform),a.setGeometry(this._geometryFilter),a.render=this._render,a.material=r}addLine(e,t,r,i){if(this._geometryFilter._lineCount===this._geometryFilter._maxLineCount)throw"PixelLineSprite3D: lineCount has equal with maxLineCount.";this._geometryFilter._updateLineData(this._geometryFilter._lineCount++,e,t,r,i),this._isRenderActive&&!this._isInRenders&&this._geometryFilter._lineCount>0&&(this._scene._addRenderObject(this._render),this._isInRenders=!0)}addLines(e){var t=this._geometryFilter._lineCount,r=e.length;if(t+r>this._geometryFilter._maxLineCount)throw"PixelLineSprite3D: lineCount plus lines count must less than maxLineCount.";this._geometryFilter._updateLineDatas(t,e),this._geometryFilter._lineCount+=r,this._isRenderActive&&!this._isInRenders&&this._geometryFilter._lineCount>0&&(this._scene._addRenderObject(this._render),this._isInRenders=!0)}removeLine(e){if(!(e<this._geometryFilter._lineCount))throw"PixelLineSprite3D: index must less than lineCount.";this._geometryFilter._removeLineData(e),this._isRenderActive&&this._isInRenders&&0==this._geometryFilter._lineCount&&(this._scene._removeRenderObject(this._render),this._isInRenders=!1)}setLine(e,t,r,i,a){if(!(e<this._geometryFilter._lineCount))throw"PixelLineSprite3D: index must less than lineCount.";this._geometryFilter._updateLineData(e,t,r,i,a)}getLine(e,t){if(!(e<this.lineCount))throw"PixelLineSprite3D: index must less than lineCount.";this._geometryFilter._getLineData(e,t)}clear(){this._geometryFilter._lineCount=0,this._isRenderActive&&this._isInRenders&&(this._scene._removeRenderObject(this._render),this._isInRenders=!1)}_create(){return new $t}}class er{constructor(e=!1){this.isTransparent=!1,this.elements=new b,this.lastTransparentRenderElement=null,this.lastTransparentBatched=!1,this.isTransparent=e}_compare(e,t){var r=e.material.renderQueue-t.material.renderQueue;return 0===r?(this.isTransparent?t.render._distanceForSort-e.render._distanceForSort:e.render._distanceForSort-t.render._distanceForSort)+t.render.sortingFudge-e.render.sortingFudge:r}_partitionRenderObject(e,t){for(var r=this.elements.elements,i=r[Math.floor((t+e)/2)];e<=t;){for(;this._compare(r[e],i)<0;)e++;for(;this._compare(r[t],i)>0;)t--;if(e<t){var a=r[e];r[e]=r[t],r[t]=a,e++,t--}else if(e===t){e++;break}}return e}_quickSort(e,t){if(this.elements.length>1){var r=this._partitionRenderObject(e,t),i=r-1;e<i&&this._quickSort(e,i),r<t&&this._quickSort(r,t)}}_render(e){for(var t=this.elements.elements,r=0,i=this.elements.length;r<i;r++)t[r]._render(e)}clear(){this.elements.length=0,this.lastTransparentRenderElement=null,this.lastTransparentBatched=!1}}class tr{constructor(e,t,r,i){this._bounds=new Ft(new n,new n),this._objects=[],this._isContaion=!1,this.center=new n,this.baseLength=0,this._setValues(e,t,r,i)}static _encapsulates(e,t){return Ve.boxContainsBox(e,t)==we.Contains}_setValues(e,t,r,i){this._octree=e,this._parent=t,this.baseLength=r,i.cloneTo(this.center);var a=this._bounds.min,n=this._bounds.max,s=e._looseness*r/2;a.setValue(i.x-s,i.y-s,i.z-s),n.setValue(i.x+s,i.y+s,i.z+s)}_getChildBound(e){if(null!=this._children&&this._children[e])return this._children[e]._bounds;var t=this.baseLength/4,r=this.baseLength/2*this._octree._looseness/2,i=tr._tempBoundBox,a=i.min,n=i.max;switch(e){case 0:a.x=this.center.x-t-r,a.y=this.center.y+t-r,a.z=this.center.z-t-r,n.x=this.center.x-t+r,n.y=this.center.y+t+r,n.z=this.center.z-t+r;break;case 1:a.x=this.center.x+t-r,a.y=this.center.y+t-r,a.z=this.center.z-t-r,n.x=this.center.x+t+r,n.y=this.center.y+t+r,n.z=this.center.z-t+r;break;case 2:a.x=this.center.x-t-r,a.y=this.center.y+t-r,a.z=this.center.z+t-r,n.x=this.center.x-t+r,n.y=this.center.y+t+r,n.z=this.center.z+t+r;break;case 3:a.x=this.center.x+t-r,a.y=this.center.y+t-r,a.z=this.center.z+t-r,n.x=this.center.x+t+r,n.y=this.center.y+t+r,n.z=this.center.z+t+r;break;case 4:a.x=this.center.x-t-r,a.y=this.center.y-t-r,a.z=this.center.z-t-r,n.x=this.center.x-t+r,n.y=this.center.y-t+r,n.z=this.center.z-t+r;break;case 5:a.x=this.center.x+t-r,a.y=this.center.y-t-r,a.z=this.center.z-t-r,n.x=this.center.x+t+r,n.y=this.center.y-t+r,n.z=this.center.z-t+r;break;case 6:a.x=this.center.x-t-r,a.y=this.center.y-t-r,a.z=this.center.z+t-r,n.x=this.center.x-t+r,n.y=this.center.y-t+r,n.z=this.center.z+t+r;break;case 7:a.x=this.center.x+t-r,a.y=this.center.y-t-r,a.z=this.center.z+t-r,n.x=this.center.x+t+r,n.y=this.center.y-t+r,n.z=this.center.z+t+r}return i}_getChildCenter(e){if(null!=this._children)return this._children[e].center;var t=this.baseLength/4,r=tr._tempVector30;switch(e){case 0:r.x=this.center.x-t,r.y=this.center.y+t,r.z=this.center.z-t;break;case 1:r.x=this.center.x+t,r.y=this.center.y+t,r.z=this.center.z-t;break;case 2:r.x=this.center.x-t,r.y=this.center.y+t,r.z=this.center.z+t;break;case 3:r.x=this.center.x+t,r.y=this.center.y+t,r.z=this.center.z+t;break;case 4:r.x=this.center.x-t,r.y=this.center.y-t,r.z=this.center.z-t;break;case 5:r.x=this.center.x+t,r.y=this.center.y-t,r.z=this.center.z-t;break;case 6:r.x=this.center.x-t,r.y=this.center.y-t,r.z=this.center.z+t;break;case 7:r.x=this.center.x+t,r.y=this.center.y-t,r.z=this.center.z+t}return r}_getChild(e){var t=this.baseLength/4;switch(this._children||(this._children=[]),e){case 0:return this._children[0]||(this._children[0]=new tr(this._octree,this,this.baseLength/2,new n(this.center.x+-t,this.center.y+t,this.center.z-t)));case 1:return this._children[1]||(this._children[1]=new tr(this._octree,this,this.baseLength/2,new n(this.center.x+t,this.center.y+t,this.center.z-t)));case 2:return this._children[2]||(this._children[2]=new tr(this._octree,this,this.baseLength/2,new n(this.center.x-t,this.center.y+t,this.center.z+t)));case 3:return this._children[3]||(this._children[3]=new tr(this._octree,this,this.baseLength/2,new n(this.center.x+t,this.center.y+t,this.center.z+t)));case 4:return this._children[4]||(this._children[4]=new tr(this._octree,this,this.baseLength/2,new n(this.center.x-t,this.center.y-t,this.center.z-t)));case 5:return this._children[5]||(this._children[5]=new tr(this._octree,this,this.baseLength/2,new n(this.center.x+t,this.center.y-t,this.center.z-t)));case 6:return this._children[6]||(this._children[6]=new tr(this._octree,this,this.baseLength/2,new n(this.center.x-t,this.center.y-t,this.center.z+t)));case 7:return this._children[7]||(this._children[7]=new tr(this._octree,this,this.baseLength/2,new n(this.center.x+t,this.center.y-t,this.center.z+t)));default:throw"BoundsOctreeNode: unknown index."}}_shouldMerge(){for(var e=this._objects.length,t=0;t<8;t++){var r=this._children[t];if(r){if(null!=r._children)return!1;e+=r._objects.length}}return e<=tr._NUM_OBJECTS_ALLOWED}_mergeChildren(){for(var e=0;e<8;e++){var t=this._children[e];if(t){t._parent=null;for(var r=t._objects,i=r.length-1;i>=0;i--){var a=r[i];this._objects.push(a),a._setOctreeNode(this)}}}this._children=null}_merge(){if(null===this._children){var e=this._parent;e&&e._shouldMerge()&&(e._mergeChildren(),e._merge())}}_checkAddNode(e){if(null==this._children){if(this._objects.length<tr._NUM_OBJECTS_ALLOWED||this.baseLength/2<this._octree._minSize)return this;for(var t=this._objects.length-1;t>=0;t--){var r=this._objects[t],i=this._bestFitChild(r.bounds.getCenter());tr._encapsulates(this._getChildBound(i),r.bounds._getBoundBox())&&(this._objects.splice(this._objects.indexOf(r),1),this._getChild(i)._add(r))}}var a=this._bestFitChild(e.bounds.getCenter());return tr._encapsulates(this._getChildBound(a),e.bounds._getBoundBox())?this._getChild(a)._checkAddNode(e):this}_add(e){var t=this._checkAddNode(e);t._objects.push(e),e._setOctreeNode(t)}_remove(e){var t=this._objects.indexOf(e);this._objects.splice(t,1),e._setOctreeNode(null),this._merge()}_addUp(e){return Ve.boxContainsBox(this._bounds,e.bounds._getBoundBox())===we.Contains?(this._add(e),!0):!!this._parent&&this._parent._addUp(e)}_getCollidingWithFrustum(e,r,i,a,s,o){var l=e.boundFrustum,_=e.position,h=e.cullingMask;if(i){var c=l.containsBoundBox(this._bounds);if(t.Stat.octreeNodeCulling++,c===we.Disjoint)return;i=c===we.Intersects}this._isContaion=!i;for(var d=r.scene,u=t.Stat.loopCount,m=0,f=this._objects.length;m<f;m++){var T=this._objects[m];if(o?T._castShadow&&T._enable:0!=(Math.pow(2,T._owner._layer)&h)&&T._enable){if(i&&(t.Stat.frustumCulling++,!T._needRender(l,r)))continue;T._renderMark=u,T._distanceForSort=n.distance(T.bounds.getCenter(),_);for(var E=T._renderElements,p=0,g=E.length;p<g;p++){E[p]._update(d,r,a,s)}}}if(null!=this._children)for(m=0;m<8;m++){var S=this._children[m];S&&S._getCollidingWithFrustum(e,r,i,a,s,o)}}_getCollidingWithBoundBox(e,t,r){if(t){var i=Ve.boxContainsBox(this._bounds,e);if(i===we.Disjoint)return;t=i===we.Intersects}if(t)for(var a=0,n=this._objects.length;a<n;a++){var s=this._objects[a];Ve.intersectsBoxAndBox(s.bounds._getBoundBox(),e)&&r.push(s)}if(null!=this._children)for(a=0;a<8;a++){this._children[a]._getCollidingWithBoundBox(e,t,r)}}_bestFitChild(e){return(e.x<=this.center.x?0:1)+(e.y>=this.center.y?0:4)+(e.z<=this.center.z?0:2)}_update(e){if(Ve.boxContainsBox(this._bounds,e.bounds._getBoundBox())===we.Contains){var t=this._checkAddNode(e);if(t!==e._getOctreeNode()){t._objects.push(e),e._setOctreeNode(t);var r=this._objects.indexOf(e);this._objects.splice(r,1),this._merge()}return!0}if(this._parent){var i=this._parent._addUp(e);return i&&(r=this._objects.indexOf(e),this._objects.splice(r,1),this._merge()),i}return!1}add(e){return!!tr._encapsulates(this._bounds,e.bounds._getBoundBox())&&(this._add(e),!0)}remove(e){return e._getOctreeNode()===this&&(this._remove(e),!0)}update(e){return e._getOctreeNode()===this&&this._update(e)}shrinkIfPossible(e){if(this.baseLength<2*e)return this;for(var t=-1,r=0,i=this._objects.length;r<i;r++){var a=this._objects[r],n=this._bestFitChild(a.bounds.getCenter());if(0!=r&&n!=t)return this;var s=this._getChildBound(n);if(!tr._encapsulates(s,a.bounds._getBoundBox()))return this;0==r&&(t=n)}if(null==this._children){if(-1!=t){var o=this._getChildCenter(t);this._setValues(this._octree,null,this.baseLength/2,o)}return this}var l=!1;for(r=0,i=this._children.length;r<i;r++){var _=this._children[r];if(_&&_.hasAnyObjects()){if(l)return this;if(t>=0&&t!=r)return this;l=!0,t=r}}if(-1!=t){var h=this._children[t];return h._parent=null,h}return this}hasAnyObjects(){if(this._objects.length>0)return!0;if(null!=this._children)for(var e=0;e<8;e++){var t=this._children[e];if(t&&t.hasAnyObjects())return!0}return!1}getCollidingWithBoundBox(e,t){this._getCollidingWithBoundBox(e,!0,t)}getCollidingWithRay(e,t,r=Number.MAX_VALUE){var i=Ve.intersectsRayAndBoxRD(e,this._bounds);if(!(-1==i||i>r)){for(var a=0,n=this._objects.length;a<n;a++){var s=this._objects[a];-1!==(i=Ve.intersectsRayAndBoxRD(e,s.bounds._getBoundBox()))&&i<=r&&t.push(s)}if(null!=this._children)for(a=0;a<8;a++){this._children[a].getCollidingWithRay(e,t,r)}}}getCollidingWithFrustum(e,t,r,i,a){this._getCollidingWithFrustum(e,t,!0,r,i,a)}isCollidingWithBoundBox(e){if(!Ve.intersectsBoxAndBox(this._bounds,e))return!1;for(var t=0,r=this._objects.length;t<r;t++){var i=this._objects[t];if(Ve.intersectsBoxAndBox(i.bounds._getBoundBox(),e))return!0}if(null!=this._children)for(t=0;t<8;t++){if(this._children[t].isCollidingWithBoundBox(e))return!0}return!1}isCollidingWithRay(e,t=Number.MAX_VALUE){var r=Ve.intersectsRayAndBoxRD(e,this._bounds);if(-1==r||r>t)return!1;for(var i=0,a=this._objects.length;i<a;i++){var n=this._objects[i];if(-1!==(r=Ve.intersectsRayAndBoxRD(e,n.bounds._getBoundBox()))&&r<=t)return!0}if(null!=this._children)for(i=0;i<8;i++){if(this._children[i].isCollidingWithRay(e,t))return!0}return!1}getBound(){return this._bounds}drawAllBounds(e,t,r){if(null!==this._children||0!=this._objects.length){t++;var i=tr._tempColor0;if(this._isContaion)i.r=0,i.g=0,i.b=1;else{var a=r?t/r:0;i.r=1-a,i.g=a,i.b=0}if(i.a=.3,H._drawBound(e,this._bounds,i),null!=this._children)for(var n=0;n<8;n++){var s=this._children[n];s&&s.drawAllBounds(e,t,r)}}}drawAllObjects(e,t,r){t++;var i=tr._tempColor0;if(this._isContaion)i.r=0,i.g=0,i.b=1;else{var a=r?t/r:0;i.r=1-a,i.g=a,i.b=0}i.a=1;for(var n=0,s=this._objects.length;n<s;n++)H._drawBound(e,this._objects[n].bounds._getBoundBox(),i);if(null!=this._children)for(n=0;n<8;n++){var o=this._children[n];o&&o.drawAllObjects(e,t,r)}}}tr._tempVector3=new n,tr._tempVector30=new n,tr._tempVector31=new n,tr._tempColor0=new xt,tr._tempBoundBox=new Ft(new n,new n),tr._NUM_OBJECTS_ALLOWED=8;class rr extends b{constructor(){super()}add(e){if(-1!==e._getIndexInMotionList())throw"OctreeMotionList:element has in PhysicsUpdateList.";this._add(e),e._setIndexInMotionList(this.length++)}remove(e){var t=e._getIndexInMotionList();if(this.length--,t!==this.length){var r=this.elements[this.length];this.elements[t]=r,r._setIndexInMotionList(t)}e._setIndexInMotionList(-1)}}class ir{constructor(e,t,r,i){this._motionObjects=new rr,this.count=0,r>e&&(console.warn("Minimum node size must be at least as big as the initial world size. Was: "+r+" Adjusted to: "+e),r=e),this._initialSize=e,this._minSize=r,this._looseness=Math.min(Math.max(i,1),2),this._rootNode=new tr(this,null,e,t)}_getMaxDepth(e,t){t++;var r=e._children;if(null!=r)for(var i=t,a=0,n=r.length;a<n;a++){var s=r[a];s&&(t=Math.max(this._getMaxDepth(s,i),t))}return t}_grow(e){var t=e.x>=0?1:-1,r=e.y>=0?1:-1,i=e.z>=0?1:-1,a=this._rootNode,s=this._rootNode.baseLength/2,o=2*this._rootNode.baseLength,l=this._rootNode.center,_=new n(l.x+t*s,l.y+r*s,l.z+i*s);if(this._rootNode=new tr(this,null,o,_),a.hasAnyObjects()){for(var h=this._rootNode._bestFitChild(a.center),c=[],d=0;d<8;d++)d==h&&(a._parent=this._rootNode,c[d]=a);this._rootNode._children=c}}add(e){for(var t=0;!this._rootNode.add(e);){var r=ir._tempVector30;if(n.subtract(e.bounds.getCenter(),this._rootNode.center,r),this._grow(r),++t>20)throw"Aborted Add operation as it seemed to be going on forever ("+(t-1)+") attempts at growing the octree."}this.count++}remove(e){var t=e._getOctreeNode().remove(e);return t&&this.count--,t}update(e){var t=0,r=e._getOctreeNode();if(r){for(;!r._update(e);){var i=ir._tempVector30;if(n.subtract(e.bounds.getCenter(),this._rootNode.center,i),this._grow(i),++t>20)throw"Aborted Add operation as it seemed to be going on forever ("+(t-1)+") attempts at growing the octree."}return!0}return!1}shrinkRootIfPossible(){this._rootNode=this._rootNode.shrinkIfPossible(this._initialSize)}addMotionObject(e){this._motionObjects.add(e)}removeMotionObject(e){this._motionObjects.remove(e)}updateMotionObjects(){for(var e=this._motionObjects.elements,t=0,r=this._motionObjects.length;t<r;t++){var i=e[t];this.update(i),i._setIndexInMotionList(-1)}this._motionObjects.length=0}isCollidingWithBoundBox(e){return this._rootNode.isCollidingWithBoundBox(e)}isCollidingWithRay(e,t=Number.MAX_VALUE){return this._rootNode.isCollidingWithRay(e,t)}getCollidingWithBoundBox(e,t){this._rootNode.getCollidingWithBoundBox(e,t)}getCollidingWithRay(e,t,r=Number.MAX_VALUE){this._rootNode.getCollidingWithRay(e,t,r)}getCollidingWithFrustum(e,t,r,i,a){this._rootNode.getCollidingWithFrustum(e,t,r,i,a)}getMaxBounds(){return this._rootNode.getBound()}drawAllBounds(e){var t=this._getMaxDepth(this._rootNode,-1);this._rootNode.drawAllBounds(e,-1,t)}drawAllObjects(e){var t=this._getMaxDepth(this._rootNode,-1);this._rootNode.drawAllObjects(e,-1,t)}}ir._tempVector30=new n;class ar{}class nr{constructor(e,t){this.center=e,this.radius=t}toDefault(){this.center.toDefault(),this.radius=0}static createFromSubPoints(e,t,r,i){if(null==e)throw new Error("points");if(t<0||t>=e.length)throw new Error("start"+t+"Must be in the range [0, "+(e.length-1)+"]");if(r<0||t+r>e.length)throw new Error("count"+r+"Must be in the range <= "+e.length+"}");var a=t+r,s=nr._tempVector3;s.x=0,s.y=0,s.z=0;for(var o=t;o<a;++o)n.add(e[o],s,s);var l=i.center;n.scale(s,1/r,l);var _=0;for(o=t;o<a;++o){var h=n.distanceSquared(l,e[o]);h>_&&(_=h)}i.radius=Math.sqrt(_)}static createfromPoints(e,t){if(null==e)throw new Error("points");nr.createFromSubPoints(e,0,e.length,t)}intersectsRayDistance(e){return Ve.intersectsRayAndSphereRD(e,this)}intersectsRayPoint(e,t){return Ve.intersectsRayAndSphereRP(e,this,t)}cloneTo(e){var t=e;this.center.cloneTo(t.center),t.radius=this.radius}clone(){var e=new nr(new n,0);return this.cloneTo(e),e}}nr._tempVector3=new n;class sr{constructor(){this.cameraShaderValue=new me,this.position=new n,this.viewMatrix=new R,this.projectionMatrix=new R,this.viewProjectMatrix=new R,this.cullPlanes=[new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n)],this.splitBoundSphere=new nr(new n,0)}}class or{constructor(){this.cameraShaderValue=new me,this.position=new n,this.viewMatrix=new R,this.projectionMatrix=new R,this.viewProjectMatrix=new R,this.cameraCullInfo=new At}}(ft=e.ShadowLightType||(e.ShadowLightType={}))[ft.DirectionLight=0]="DirectionLight",ft[ft.SpotLight=1]="SpotLight",ft[ft.PointLight=2]="PointLight";class lr{constructor(){this._shadowBias=new a,this._shadowParams=new a,this._shadowMapSize=new a,this._shadowSpotMapSize=new a,this._shadowMatrices=new Float32Array(16*lr._maxCascades),this._shadowSpotMatrices=new R,this._splitBoundSpheres=new Float32Array(4*lr._maxCascades),this._cascadeCount=0,this._shadowMapWidth=0,this._shadowMapHeight=0,this._shadowSliceDatas=[new sr,new sr,new sr,new sr],this._shadowSpotData=new or,this._lightUp=new n,this._lightSide=new n,this._lightForward=new n,this._shadowSpotData.cameraCullInfo.boundFrustum=new Be(new R)}_setupShadowCasterShaderValues(t,r,i,a,n,s,o){switch(r.setVector(lr.SHADOW_BIAS,s),o){case e.LightType.Directional:r.setVector3(lr.SHADOW_LIGHT_DIRECTION,a);break;case e.LightType.Spot:r.setVector(lr.SHADOW_PARAMS,n);break;case e.LightType.Point:}var l=i.cameraShaderValue;l.setMatrix4x4(Xe.VIEWMATRIX,i.viewMatrix),l.setMatrix4x4(Xe.PROJECTMATRIX,i.projectionMatrix),l.setMatrix4x4(Xe.VIEWPROJECTMATRIX,i.viewProjectMatrix),t.viewMatrix=i.viewMatrix,t.projectionMatrix=i.projectionMatrix,t.projectionViewMatrix=i.viewProjectMatrix}_setupShadowReceiverShaderValues(t){var r=this._light;switch(r.shadowCascadesMode!==e.ShadowCascadesMode.NoCascades?t.addDefine(Ye.SHADERDEFINE_SHADOW_CASCADE):t.removeDefine(Ye.SHADERDEFINE_SHADOW_CASCADE),r.shadowMode){case e.ShadowMode.Hard:t.removeDefine(Ye.SHADERDEFINE_SHADOW_SOFT_SHADOW_LOW),t.removeDefine(Ye.SHADERDEFINE_SHADOW_SOFT_SHADOW_HIGH);break;case e.ShadowMode.SoftLow:t.addDefine(Ye.SHADERDEFINE_SHADOW_SOFT_SHADOW_LOW),t.removeDefine(Ye.SHADERDEFINE_SHADOW_SOFT_SHADOW_HIGH);break;case e.ShadowMode.SoftHigh:t.addDefine(Ye.SHADERDEFINE_SHADOW_SOFT_SHADOW_HIGH),t.removeDefine(Ye.SHADERDEFINE_SHADOW_SOFT_SHADOW_LOW)}t.setTexture(lr.SHADOW_MAP,this._shadowDirectLightMap),t.setBuffer(lr.SHADOW_MATRICES,this._shadowMatrices),t.setVector(lr.SHADOW_MAP_SIZE,this._shadowMapSize),t.setVector(lr.SHADOW_PARAMS,this._shadowParams),t.setBuffer(lr.SHADOW_SPLIT_SPHERES,this._splitBoundSpheres)}_setupSpotShadowReceiverShaderValues(t){switch(this._light.shadowMode){case e.ShadowMode.Hard:t.removeDefine(Ye.SHADERDEFINE_SHADOW_SPOT_SOFT_SHADOW_HIGH),t.removeDefine(Ye.SHADERDEFINE_SHADOW_SPOT_SOFT_SHADOW_LOW);break;case e.ShadowMode.SoftLow:t.addDefine(Ye.SHADERDEFINE_SHADOW_SPOT_SOFT_SHADOW_LOW),t.removeDefine(Ye.SHADERDEFINE_SHADOW_SPOT_SOFT_SHADOW_HIGH);break;case e.ShadowMode.SoftHigh:t.addDefine(Ye.SHADERDEFINE_SHADOW_SPOT_SOFT_SHADOW_HIGH),t.removeDefine(Ye.SHADERDEFINE_SHADOW_SPOT_SOFT_SHADOW_LOW)}t.setTexture(lr.SHADOW_SPOTMAP,this._shadowSpotLightMap),t.setMatrix4x4(lr.SHADOW_SPOTMATRICES,this._shadowSpotMatrices),t.setVector(lr.SHADOW_SPOTMAP_SIZE,this._shadowSpotMapSize),t.setVector(lr.SHADOW_PARAMS,this._shadowParams)}update(t,i,a){switch(a){case e.ShadowLightType.DirectionLight:this._light=i;var s=(M=lr._tempMatrix0).elements,o=this._lightUp,l=this._lightSide,_=this._lightForward;R.createFromQuaternion(i._transform.rotation,M),l.setValue(s[0],s[1],s[2]),o.setValue(s[4],s[5],s[6]),_.setValue(-s[8],-s[9],-s[10]);var h,c,d,u,m=i._shadowResolution,f=i._shadowCascadesMode;f==e.ShadowCascadesMode.NoCascades?(h=1,c=m,d=m,u=m):(h=f==e.ShadowCascadesMode.TwoCascades?2:4,d=2*(c=Ze.getMaxTileResolutionInAtlas(m,m,h)),u=f==e.ShadowCascadesMode.TwoCascades?c:2*c),this._cascadeCount=h,this._shadowMapWidth=d,this._shadowMapHeight=u;var T=lr._cascadesSplitDistance,E=lr._frustumPlanes,p=t.nearPlane,g=Math.min(t.farPlane,i._shadowDistance),S=this._shadowMatrices,v=this._splitBoundSpheres;Ze.getCascadesSplitDistance(i._shadowTwoCascadeSplits,i._shadowFourCascadeSplits,p,g,t.fieldOfView*r.Deg2Rad,t.aspectRatio,f,T),Ze.getCameraFrustumPlanes(t.projectionViewMatrix,E);var x=lr._tempVector30;t._transform.getForward(x),n.normalize(x,x);for(var A=0;A<h;A++){var I=this._shadowSliceDatas[A];I.sphereCenterZ=Ze.getBoundSphereByFrustum(T[A],T[A+1],t.fieldOfView*r.Deg2Rad,t.aspectRatio,t._transform.position,x,I.splitBoundSphere),Ze.getDirectionLightShadowCullPlanes(E,A,T,p,_,I),Ze.getDirectionalLightMatrices(o,l,_,A,i._shadowNearPlane,c,I,S),h>1&&Ze.applySliceTransform(I,d,u,A,S)}Ze.prepareShadowReceiverShaderValues(i,d,u,this._shadowSliceDatas,h,this._shadowMapSize,this._shadowParams,S,v);break;case e.ShadowLightType.SpotLight:this._light=i;var M=lr._tempMatrix0,D=(_=this._lightForward,this._light._shadowResolution);this._shadowMapWidth=D,this._shadowMapHeight=D;var C=this._shadowSpotData;Ze.getSpotLightShadowData(C,this._light,D,this._shadowParams,this._shadowSpotMatrices,this._shadowSpotMapSize);break;case e.ShadowLightType.PointLight:break;default:throw"There is no shadow of this type"}}render(r,i,a){switch(a){case e.ShadowLightType.DirectionLight:var n=i._shaderValues;r.pipelineMode="ShadowCaster",me.setRuntimeValueMode(!1),(T=this._shadowDirectLightMap=Ze.getTemporaryShadowTexture(this._shadowMapWidth,this._shadowMapHeight,t.RenderTextureDepthFormat.DEPTH_16))._start();for(var s=this._light,o=0,l=this._cascadeCount;o<l;o++){var _=this._shadowSliceDatas[o];Ze.getShadowBias(s,_.projectionMatrix,_.resolution,this._shadowBias),this._setupShadowCasterShaderValues(r,n,_,this._lightForward,this._shadowParams,this._shadowBias,e.LightType.Directional);var h=Mt._shadowCullInfo;h.position=_.position,h.cullPlanes=_.cullPlanes,h.cullPlaneCount=_.cullPlaneCount,h.cullSphere=_.splitBoundSphere,h.direction=this._lightForward;var c=Mt.cullingShadow(h,i,r);r.cameraShaderValue=_.cameraShaderValue,Qe._updateMark++;var d=t.LayaGL.instance,u=_.resolution,m=_.offsetX,f=_.offsetY;d.enable(d.SCISSOR_TEST),d.viewport(m,f,u,u),d.scissor(m,f,u,u),d.clear(d.DEPTH_BUFFER_BIT),c&&(d.scissor(m+1,f+1,u-2,u-2),i._opaqueQueue._render(r))}T._end(),this._setupShadowReceiverShaderValues(n),me.setRuntimeValueMode(!0),r.pipelineMode=r.configPipeLineMode;break;case e.ShadowLightType.SpotLight:n=i._shaderValues;r.pipelineMode="ShadowCaster",me.setRuntimeValueMode(!1);var T,E=this._light;(T=this._shadowSpotLightMap=Ze.getTemporaryShadowTexture(this._shadowMapWidth,this._shadowMapHeight,t.RenderTextureDepthFormat.DEPTH_16))._start();var p=this._shadowSpotData;Ze.getShadowBias(E,p.projectionMatrix,p.resolution,this._shadowBias),this._setupShadowCasterShaderValues(r,n,p,this._light.transform.position,this._shadowParams,this._shadowBias,e.LightType.Spot);c=Mt.cullingSpotShadow(p.cameraCullInfo,i,r);r.cameraShaderValue=p.cameraShaderValue,Qe._updateMark++,(d=t.LayaGL.instance).enable(d.SCISSOR_TEST),d.viewport(p.offsetX,p.offsetY,p.resolution,p.resolution),d.scissor(p.offsetX,p.offsetY,p.resolution,p.resolution),d.clear(d.DEPTH_BUFFER_BIT),c&&(d.scissor(p.offsetX,p.offsetY,p.resolution,p.resolution),i._opaqueQueue._render(r)),T._end(),this._setupSpotShadowReceiverShaderValues(n),me.setRuntimeValueMode(!0),r.pipelineMode=r.configPipeLineMode;break;case e.ShadowLightType.PointLight:break;default:throw"There is no shadow of this type"}}cleanUp(){this._shadowDirectLightMap&&he.recoverToPool(this._shadowDirectLightMap),this._shadowSpotLightMap&&he.recoverToPool(this._shadowSpotLightMap),this._shadowDirectLightMap=null,this._shadowSpotLightMap=null,this._light=null}}lr._tempVector30=new n,lr._tempMatrix0=new R,lr.SHADOW_BIAS=xe.propertyNameToID("u_ShadowBias"),lr.SHADOW_LIGHT_DIRECTION=xe.propertyNameToID("u_ShadowLightDirection"),lr.SHADOW_SPLIT_SPHERES=xe.propertyNameToID("u_ShadowSplitSpheres"),lr.SHADOW_MATRICES=xe.propertyNameToID("u_ShadowMatrices"),lr.SHADOW_MAP_SIZE=xe.propertyNameToID("u_ShadowMapSize"),lr.SHADOW_MAP=xe.propertyNameToID("u_ShadowMap"),lr.SHADOW_PARAMS=xe.propertyNameToID("u_ShadowParams"),lr.SHADOW_SPOTMAP_SIZE=xe.propertyNameToID("u_SpotShadowMapSize"),lr.SHADOW_SPOTMAP=xe.propertyNameToID("u_SpotShadowMap"),lr.SHADOW_SPOTMATRICES=xe.propertyNameToID("u_SpotViewProjectMatrix"),lr._maxCascades=4,lr._cascadesSplitDistance=new Array(lr._maxCascades+1),lr._frustumPlanes=new Array(new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n),new Pe(new n));class _r{constructor(){this._batchRenderElementPool=[]}static _registerManager(e){_r._managers.push(e)}_clear(){this._batchRenderElementPoolIndex=0}_getBatchRenderElementFromPool(){throw"StaticBatch:must override this function."}dispose(){}}_r._managers=[];class hr extends b{constructor(){super()}add(e){this._add(e),e._setIndexInReflectionList(this.length++)}remove(e){var t=e._getIndexInReflectionList();if(this.length--,t!==this.length){var r=this.elements[this.length];this.elements[t]=r,r._setIndexInReflectionList(t)}e._setIndexInReflectionList(-1)}}class cr{constructor(){this._reflectionProbes=new hr,this._motionObjects=new b,this._needUpdateAllRender=!1,this._sceneReflectionProbe=new Qt,this._sceneReflectionProbe.bounds=new Ut(new n(0,0,0),new n(0,0,0)),this._sceneReflectionProbe.boxProjection=!1,this._sceneReflectionProbe._isScene=!0}set sceneReflectionProbe(e){this._sceneReflectionProbe.reflectionTexture=e}set sceneReflectionCubeHDRParam(e){this._sceneReflectionProbe.reflectionHDRParams=e}_updateMotionObjects(e){if(0!=this._reflectionProbes.length){for(var t,r,i=this._reflectionProbes.elements,a=0,n=e.bounds,s=0,o=this._reflectionProbes.length;s<o;s++){var l=i[s];if(t){if(t.importance>l.importance)continue;if((r=n.calculateBoundsintersection(l.bounds))<a&&t.importance==l.importance)continue}else if((r=n.calculateBoundsintersection(l.bounds))<a)continue;t=l,a=r}!t&&this._sceneReflectionProbe&&(t=this._sceneReflectionProbe),e._probReflection=t}else e._probReflection=this._sceneReflectionProbe}add(e){this._reflectionProbes.add(e),this._needUpdateAllRender=!0}remove(e){this._reflectionProbes.remove(e),this._needUpdateAllRender=!0}addMotionObject(e){this._motionObjects.add(e)}update(){for(var e=this._motionObjects.elements,t=0,r=this._motionObjects.length;t<r;t++)this._updateMotionObjects(e[t]);this.clearMotionObjects()}updateAllRenderObjects(e){for(var t=e.elements,r=0,i=e.length;r<i;r++)this._updateMotionObjects(t[r]);this._needUpdateAllRender=!1}clearMotionObjects(){this._motionObjects.length=0}destroy(){}}(Tt=e.AmbientMode||(e.AmbientMode={}))[Tt.SolidColor=0]="SolidColor",Tt[Tt.SphericalHarmonics=1]="SphericalHarmonics";class dr extends t.Sprite{constructor(){super(),this._lightCount=0,this._pointLights=new wt,this._spotLights=new wt,this._directionLights=new wt,this._alternateLights=new Vt,this._lightmaps=[],this._skyRenderer=new We,this._input=new Lt,this._timer=t.ILaya.timer,this._time=0,this._shCoefficients=new Array(7),this._ambientMode=e.AmbientMode.SolidColor,this._ambientSphericalHarmonics=new Dt,this._ambientSphericalHarmonicsIntensity=1,this._reflectionDecodeFormat=t.TextureDecodeFormat.Normal,this._reflectionIntensity=1,this._collsionTestList=[],this._renders=new vt,this._opaqueQueue=new er(!1),this._transparentQueue=new er(!0),this._cameraPool=[],this._animatorPool=new vt,this._scriptPool=new Array,this._tempScriptPool=new Array,this._needClearScriptPool=!1,this._reflectionCubeHDRParams=new a,this._reflectionProbeManager=new cr,this.currentCreationLayer=Math.pow(2,0),this.enableLight=!0,this._key=new t.SubmitKey,this._pickIdToSprite=new Object,this._reflectionMode=0,!j._config.isUseCannonPhysicsEngine&&Y._bullet?this._physicsSimulation=new G(dr.physicsSettings):Y._cannon&&(this._cannonPhysicsSimulation=new t.CannonPhysicsSimulation(dr.cannonPhysicsSettings)),this._shaderValues=new me(null),this.enableFog=!1,this.fogStart=300,this.fogRange=1e3,this.fogColor=new n(.7,.7,.7),this.ambientColor=new n(.212,.227,.259),this.reflectionIntensity=1,this.reflection=bt.blackTexture;for(var r=0;r<7;r++)this._shCoefficients[r]=new a;if(this._reflectionProbeManager.sceneReflectionCubeHDRParam=this._reflectionCubeHDRParams,this._scene=this,this._input.__init__(t.Render.canvas,this),dr.octreeCulling&&(this._octree=new ir(dr.octreeInitialSize,dr.octreeInitialCenter,dr.octreeMinNodeSize,dr.octreeLooseness)),Mt.debugFrustumCulling){this._debugTool=new $t;var i=new Bt;i.renderQueue=st.RENDERQUEUE_TRANSPARENT,i.alphaTest=!1,i.depthWrite=!1,i.cull=lt.CULL_BACK,i.blend=lt.BLEND_ENABLE_ALL,i.blendSrc=lt.BLENDPARAM_SRC_ALPHA,i.blendDst=lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA,i.depthTest=lt.DEPTHTEST_LESS,this._debugTool.pixelLineRenderer.sharedMaterial=i}}static __init__(){var r=j._config;if(r._multiLighting){const e=4;var i=r.maxLightCount,a=r.lightClusterCount;Ne.instance=new Ne(a.x,a.y,a.z,Math.min(r.maxLightCount,r._maxAreaLightCountPerClusterAverage)),dr._lightTexture=H._createFloatTextureBuffer(e,i),dr._lightTexture.lock=!0,dr._lightPixles=new Float32Array(i*e*4)}Ye.SHADERDEFINE_FOG=xe.getDefineByName("FOG"),Ye.SHADERDEFINE_DIRECTIONLIGHT=xe.getDefineByName("DIRECTIONLIGHT"),Ye.SHADERDEFINE_POINTLIGHT=xe.getDefineByName("POINTLIGHT"),Ye.SHADERDEFINE_SPOTLIGHT=xe.getDefineByName("SPOTLIGHT"),Ye.SHADERDEFINE_SHADOW=xe.getDefineByName("SHADOW"),Ye.SHADERDEFINE_SHADOW_CASCADE=xe.getDefineByName("SHADOW_CASCADE"),Ye.SHADERDEFINE_SHADOW_SOFT_SHADOW_LOW=xe.getDefineByName("SHADOW_SOFT_SHADOW_LOW"),Ye.SHADERDEFINE_SHADOW_SOFT_SHADOW_HIGH=xe.getDefineByName("SHADOW_SOFT_SHADOW_HIGH"),Ye.SHADERDEFINE_GI_AMBIENT_SH=xe.getDefineByName("GI_AMBIENT_SH"),Ye.SHADERDEFINE_SHADOW_SPOT=xe.getDefineByName("SHADOW_SPOT"),Ye.SHADERDEFINE_SHADOW_SPOT_SOFT_SHADOW_LOW=xe.getDefineByName("SHADOW_SPOT_SOFT_SHADOW_LOW"),Ye.SHADERDEFINE_SHADOW_SPOT_SOFT_SHADOW_HIGH=xe.getDefineByName("SHADOW_SPOT_SOFT_SHADOW_HIGH");var n=j._config,s=dr._configDefineValues;switch(n._multiLighting||s.add(xe.SHADERDEFINE_LEGACYSINGALLIGHTING),t.LayaGL.layaGPUInstance._isWebGL2?s.add(xe.SHADERDEFINE_GRAPHICS_API_GLES3):s.add(xe.SHADERDEFINE_GRAPHICS_API_GLES2),n.pbrRenderQuality){case e.PBRRenderQuality.High:s.add(dt.SHADERDEFINE_LAYA_PBR_BRDF_HIGH);break;case e.PBRRenderQuality.Low:s.add(dt.SHADERDEFINE_LAYA_PBR_BRDF_LOW);break;default:throw"Scene3D:unknown shader quality."}n.isUseCannonPhysicsEngine?dr.cannonPhysicsSettings=new t.CannonPhysicsSettings:dr.physicsSettings=new Ot}static load(e,r){t.ILaya.loader.create(e,r,null,dr.HIERARCHY)}get url(){return this._url}get enableFog(){return this._enableFog}set enableFog(e){this._enableFog!==e&&(this._enableFog=e,e?this._shaderValues.addDefine(Ye.SHADERDEFINE_FOG):this._shaderValues.removeDefine(Ye.SHADERDEFINE_FOG))}get fogColor(){return this._shaderValues.getVector3(dr.FOGCOLOR)}set fogColor(e){this._shaderValues.setVector3(dr.FOGCOLOR,e)}get fogStart(){return this._shaderValues.getNumber(dr.FOGSTART)}set fogStart(e){this._shaderValues.setNumber(dr.FOGSTART,e)}get fogRange(){return this._shaderValues.getNumber(dr.FOGRANGE)}set fogRange(e){this._shaderValues.setNumber(dr.FOGRANGE,e)}get ambientMode(){return this._ambientMode}set ambientMode(t){if(this._ambientMode!==t){switch(t){case e.AmbientMode.SolidColor:this._shaderValues.removeDefine(Ye.SHADERDEFINE_GI_AMBIENT_SH);break;case e.AmbientMode.SphericalHarmonics:this._shaderValues.addDefine(Ye.SHADERDEFINE_GI_AMBIENT_SH);break;default:throw"Scene3D: unknown ambientMode."}this._ambientMode=t}}get ambientColor(){return this._shaderValues.getVector3(dr.AMBIENTCOLOR)}set ambientColor(e){this._shaderValues.setVector3(dr.AMBIENTCOLOR,e)}get ambientSphericalHarmonics(){return this._ambientSphericalHarmonics}set ambientSphericalHarmonics(e){var t=e||Dt._default;this._applySHCoefficients(t,Math.pow(this._ambientSphericalHarmonicsIntensity,2.2)),this._ambientSphericalHarmonics!=e&&e.cloneTo(this._ambientSphericalHarmonics)}get ambientSphericalHarmonicsIntensity(){return this._ambientSphericalHarmonicsIntensity}set ambientSphericalHarmonicsIntensity(e){if(e=Math.max(Math.min(e,8),0),this._ambientSphericalHarmonicsIntensity!==e){var t=this._ambientSphericalHarmonics||Dt._default;this._applySHCoefficients(t,Math.pow(e,2.2)),this._ambientSphericalHarmonicsIntensity=e}}get reflection(){return this._reflection}set reflection(e){e=e||bt.blackTexture,this._reflection!=e&&(e._addReference(),this._reflectionProbeManager.sceneReflectionProbe=e,this._reflection=e,this._reflectionProbeManager._needUpdateAllRender=!0)}get reflectionDecodingFormat(){return this._reflectionDecodeFormat}set reflectionDecodingFormat(e){this._reflectionDecodeFormat!=e&&(this._reflectionCubeHDRParams.x=this._reflectionIntensity,this._reflectionDecodeFormat==t.TextureDecodeFormat.RGBM&&(this._reflectionCubeHDRParams.x*=5),this._reflectionDecodeFormat=e,this._reflectionProbeManager.sceneReflectionCubeHDRParam=this._reflectionCubeHDRParams)}get reflectionIntensity(){return this._reflectionIntensity}set reflectionIntensity(e){e=Math.max(Math.min(e,1),0),this._reflectionCubeHDRParams.x=e,this._reflectionDecodeFormat==t.TextureDecodeFormat.RGBM&&(this._reflectionCubeHDRParams.x*=5),this._reflectionIntensity=e,this._reflectionProbeManager.sceneReflectionCubeHDRParam=this._reflectionCubeHDRParams}get skyRenderer(){return this._skyRenderer}get physicsSimulation(){return this._physicsSimulation}get cannonPhysicsSimulation(){return this._cannonPhysicsSimulation}get timer(){return this._timer}set timer(e){this._timer=e}get input(){return this._input}get lightmaps(){return this._lightmaps.slice()}set lightmaps(e){var t=this._lightmaps;if(t)for(var r=0,i=t.length;r<i;r++){(n=t[r]).lightmapColor._removeReference(),n.lightmapDirection._removeReference()}if(e){var a=e.length;for(t.length=a,r=0;r<a;r++){var n;(n=e[r]).lightmapColor&&n.lightmapColor._addReference(),n.lightmapDirection&&n.lightmapDirection._addReference(),t[r]=n}}else t.length=0}_applySHCoefficients(e,t){for(var r=this._shCoefficients,i=0;i<3;i++){var a=r[i],n=r[i+3];a.setValue(e.getCoefficient(i,3)*t,e.getCoefficient(i,1)*t,e.getCoefficient(i,2)*t,(e.getCoefficient(i,0)-e.getCoefficient(i,6))*t),n.setValue(e.getCoefficient(i,4)*t,e.getCoefficient(i,5)*t,3*e.getCoefficient(i,6)*t,e.getCoefficient(i,7)*t)}r[6].setValue(e.getCoefficient(0,8)*t,e.getCoefficient(1,8)*t,e.getCoefficient(2,8)*t,1);var s=this._shaderValues;s.setVector(dr.AMBIENTSHAR,r[0]),s.setVector(dr.AMBIENTSHAG,r[1]),s.setVector(dr.AMBIENTSHAB,r[2]),s.setVector(dr.AMBIENTSHBR,r[3]),s.setVector(dr.AMBIENTSHBG,r[4]),s.setVector(dr.AMBIENTSHBB,r[5]),s.setVector(dr.AMBIENTSHC,r[6])}_update(){var e=this.timer._delta/1e3;this._time+=e,this._shaderValues.setNumber(dr.TIME,this._time);var r=this._physicsSimulation;if(!Y._enablePhysics||G.disableSimulation||j._config.isUseCannonPhysicsEngine||(r._updatePhysicsTransformFromRender(),P._addUpdateList=!1,r._simulate(e),r._updateCharacters(),P._addUpdateList=!0,r._updateCollisions(),r._eventScripts()),Y._cannon&&j._config.isUseCannonPhysicsEngine){var i=this._cannonPhysicsSimulation;i._updatePhysicsTransformFromRender(),t.CannonPhysicsComponent._addUpdateList=!1,i._simulate(e),t.CannonPhysicsComponent._addUpdateList=!0,i._updateCollisions(),i._eventScripts()}this._input._update(),this._clearScript(),this._updateScript(),le._update(this),t.VideoTexture._update(),this._reflectionProbeManager._needUpdateAllRender?this._reflectionProbeManager.updateAllRenderObjects(this._renders):this._reflectionProbeManager.update(),this._lateUpdateScript()}_binarySearchIndexInCameraPool(e){for(var t,r=0,i=this._cameraPool.length-1;r<=i;){t=Math.floor((r+i)/2);var a=this._cameraPool[t]._renderingOrder;if(a==e._renderingOrder)return t;a>e._renderingOrder?i=t-1:r=t+1}return r}_allotPickColorByID(e,t){var r=Math.floor(e/65025);e-=255*r*255;var i=Math.floor(e/255),a=e-=255*i;t.x=r/255,t.y=i/255,t.z=a/255,t.w=1}_searchIDByPickColor(e){return 255*e.x*255+255*e.y+e.z}onEnable(){this._input._onCanvasEvent(t.Render.canvas)}onDisable(){this._input._offCanvasEvent(t.Render.canvas)}_setCreateURL(e){this._url=t.URL.formatURL(e)}_getGroup(){return this._group}_setGroup(e){this._group=e}_clearScript(){if(this._needClearScriptPool){for(var e=this._scriptPool,t=0,r=e.length;t<r;t++){var i=e[t];i&&(i._indexInPool=this._tempScriptPool.length,this._tempScriptPool.push(i))}this._scriptPool=this._tempScriptPool,e.length=0,this._tempScriptPool=e,this._needClearScriptPool=!1}}_updateScript(){for(var e=this._scriptPool,t=0,r=e.length;t<r;t++){var i=e[t];i&&i.enabled&&i.onUpdate()}}_lateUpdateScript(){for(var e=this._scriptPool,t=0,r=e.length;t<r;t++){var i=e[t];i&&i.enabled&&i.onLateUpdate()}}_onActive(){super._onActive(),t.ILaya.stage._scene3Ds.push(this)}_onInActive(){super._onInActive();var e=t.ILaya.stage._scene3Ds;e.splice(e.indexOf(this),1)}_prepareSceneToRender(){var e=this._shaderValues;if(j._config._multiLighting){var t=dr._lightTexture,r=dr._lightPixles;const v=t.width,x=4*v;var i=0,a=this._directionLights._length,s=this._directionLights._elements;if(a>0){var o=this._directionLights.getBrightestLight();this._mainDirectionLight=s[o],this._directionLights.normalLightOrdering(o);for(var l=0;l<a;l++,i++){var _=(S=s[l])._direction,h=S._intensityColor,c=x*i;n.scale(S.color,S._intensity,h),S.transform.worldMatrix.getForward(_),n.normalize(_,_),r[c]=h.x,r[c+1]=h.y,r[c+2]=h.z,r[c+4]=_.x,r[c+5]=_.y,r[c+6]=_.z,0==l&&(e.setVector3(dr.SUNLIGHTDIRCOLOR,h),e.setVector3(dr.SUNLIGHTDIRECTION,_))}e.addDefine(Ye.SHADERDEFINE_DIRECTIONLIGHT)}else e.removeDefine(Ye.SHADERDEFINE_DIRECTIONLIGHT);var d=this._pointLights._length;if(d>0){var u=this._pointLights._elements,m=this._pointLights.getBrightestLight();this._mainPointLight=u[m],this._pointLights.normalLightOrdering(m);for(l=0;l<d;l++,i++){var f=(R=u[l]).transform.position;h=R._intensityColor,c=x*i;n.scale(R.color,R._intensity,h),r[c]=h.x,r[c+1]=h.y,r[c+2]=h.z,r[c+3]=R.range,r[c+4]=f.x,r[c+5]=f.y,r[c+6]=f.z}e.addDefine(Ye.SHADERDEFINE_POINTLIGHT)}else e.removeDefine(Ye.SHADERDEFINE_POINTLIGHT);var T=this._spotLights._length;if(T>0){var E=this._spotLights._elements,p=this._spotLights.getBrightestLight();this._mainSpotLight=E[p],this._spotLights.normalLightOrdering(p);for(l=0;l<T;l++,i++){var g=E[l];_=g._direction,f=g.transform.position,h=g._intensityColor,c=x*i;n.scale(g.color,g._intensity,h),g.transform.worldMatrix.getForward(_),n.normalize(_,_),r[c]=h.x,r[c+1]=h.y,r[c+2]=h.z,r[c+3]=g.range,r[c+4]=f.x,r[c+5]=f.y,r[c+6]=f.z,r[c+7]=g.spotAngle*Math.PI/180,r[c+8]=_.x,r[c+9]=_.y,r[c+10]=_.z}e.addDefine(Ye.SHADERDEFINE_SPOTLIGHT)}else e.removeDefine(Ye.SHADERDEFINE_SPOTLIGHT);i>0&&t.setSubPixels(0,0,v,i,r,0),e.setTexture(dr.LIGHTBUFFER,t),e.setInt(dr.DIRECTIONLIGHTCOUNT,this._directionLights._length),e.setTexture(dr.CLUSTERBUFFER,Ne.instance._clusterTexture)}else{if(this._directionLights._length>0){var S=this._directionLights._elements[0];this._mainDirectionLight=S,n.scale(S.color,S._intensity,S._intensityColor),S.transform.worldMatrix.getForward(S._direction),n.normalize(S._direction,S._direction),e.setVector3(dr.LIGHTDIRCOLOR,S._intensityColor),e.setVector3(dr.LIGHTDIRECTION,S._direction),e.setVector3(dr.SUNLIGHTDIRCOLOR,S._intensityColor),e.setVector3(dr.SUNLIGHTDIRECTION,S._direction),e.addDefine(Ye.SHADERDEFINE_DIRECTIONLIGHT)}else e.removeDefine(Ye.SHADERDEFINE_DIRECTIONLIGHT);if(this._pointLights._length>0){var R=this._pointLights._elements[0];this._mainPointLight=R,n.scale(R.color,R._intensity,R._intensityColor),e.setVector3(dr.POINTLIGHTCOLOR,R._intensityColor),e.setVector3(dr.POINTLIGHTPOS,R.transform.position),e.setNumber(dr.POINTLIGHTRANGE,R.range),e.addDefine(Ye.SHADERDEFINE_POINTLIGHT)}else e.removeDefine(Ye.SHADERDEFINE_POINTLIGHT);if(this._spotLights._length>0){var v=this._spotLights._elements[0];this._mainSpotLight=v,n.scale(v.color,v._intensity,v._intensityColor),e.setVector3(dr.SPOTLIGHTCOLOR,v._intensityColor),e.setVector3(dr.SPOTLIGHTPOS,v.transform.position),v.transform.worldMatrix.getForward(v._direction),n.normalize(v._direction,v._direction),e.setVector3(dr.SPOTLIGHTDIRECTION,v._direction),e.setNumber(dr.SPOTLIGHTRANGE,v.range),e.setNumber(dr.SPOTLIGHTSPOTANGLE,v.spotAngle*Math.PI/180),e.addDefine(Ye.SHADERDEFINE_SPOTLIGHT)}else e.removeDefine(Ye.SHADERDEFINE_SPOTLIGHT)}}_addScript(e){var t=this._scriptPool;e._indexInPool=t.length,t.push(e)}_removeScript(e){this._scriptPool[e._indexInPool]=null,e._indexInPool=-1,this._needClearScriptPool=!0}_preRenderScript(){for(var e=this._scriptPool,t=0,r=e.length;t<r;t++){var i=e[t];i&&i.enabled&&i.onPreRender()}}_postRenderScript(){for(var e=this._scriptPool,t=0,r=e.length;t<r;t++){var i=e[t];i&&i.enabled&&i.onPostRender()}}_addCamera(e){for(var t=this._binarySearchIndexInCameraPool(e),r=e._renderingOrder,i=this._cameraPool.length;t<i&&this._cameraPool[t]._renderingOrder<=r;)t++;this._cameraPool.splice(t,0,e)}_removeCamera(e){this._cameraPool.splice(this._cameraPool.indexOf(e),1)}_preCulling(e,t,r,i){var a=Mt._cameraCullInfo;a.position=t._transform.position,a.cullingMask=t.cullingMask,a.boundFrustum=t.boundFrustum,a.useOcclusionCulling=t.useOcclusionCulling,Mt.renderObjectCulling(a,this,e,r,i,!1)}_clear(r,i){var a,n,s,o=i.viewport,l=i.camera,_=l._getRenderTexture(),h=o.width,c=o.height;l._needInternalRenderTexture()?(a=0,n=0):(a=o.x,n=l._getCanvasHeight()-o.y-c),r.viewport(a,n,h,c);var d=l.clearFlag;switch(d!==e.CameraClearFlags.Sky||l.skyRenderer._isAvailable()||this._skyRenderer._isAvailable()||(d=e.CameraClearFlags.SolidColor),d){case e.CameraClearFlags.SolidColor:var u=l.clearColor;if(r.enable(r.SCISSOR_TEST),r.scissor(a,n,h,c),u?r.clearColor(u.x,u.y,u.z,u.w):r.clearColor(0,0,0,0),_)switch(s=r.COLOR_BUFFER_BIT,_.depthStencilFormat){case t.RenderTextureDepthFormat.DEPTH_16:s|=r.DEPTH_BUFFER_BIT;break;case t.RenderTextureDepthFormat.STENCIL_8:s|=r.STENCIL_BUFFER_BIT;break;case t.RenderTextureDepthFormat.DEPTHSTENCIL_24_8:s|=r.DEPTH_BUFFER_BIT,s|=r.STENCIL_BUFFER_BIT}else s=r.COLOR_BUFFER_BIT|r.DEPTH_BUFFER_BIT;t.WebGLContext.setDepthMask(r,!0),r.clear(s),r.disable(r.SCISSOR_TEST);break;case e.CameraClearFlags.Sky:case e.CameraClearFlags.DepthOnly:if(r.enable(r.SCISSOR_TEST),r.scissor(a,n,h,c),_)switch(_.depthStencilFormat){case t.RenderTextureDepthFormat.DEPTH_16:s=r.DEPTH_BUFFER_BIT;break;case t.RenderTextureDepthFormat.STENCIL_8:s=r.STENCIL_BUFFER_BIT;break;case t.RenderTextureDepthFormat.DEPTHSTENCIL_24_8:s=r.DEPTH_BUFFER_BIT|r.STENCIL_BUFFER_BIT}else s=r.DEPTH_BUFFER_BIT;t.WebGLContext.setDepthMask(r,!0),r.clear(s),r.disable(r.SCISSOR_TEST);break;case e.CameraClearFlags.Nothing:break;default:throw new Error("Scene3D:camera clearFlag invalid.")}}_renderScene(t,r){var i=t.camera;switch(r){case dr.SCENERENDERFLAG_RENDERQPAQUE:this._opaqueQueue._render(t);break;case dr.SCENERENDERFLAG_SKYBOX:i.clearFlag===e.CameraClearFlags.Sky&&(i.skyRenderer._isAvailable()?i.skyRenderer._render(t):this._skyRenderer._isAvailable()&&this._skyRenderer._render(t));break;case dr.SCENERENDERFLAG_RENDERTRANSPARENT:if(this._transparentQueue._render(t),Mt.debugFrustumCulling)for(var a=this._debugTool._render._renderElements,n=0,s=a.length;n<s;n++)a[n]._update(this,t,null,null),a[n]._render(t)}}_parse(e,r){var i=e.lightmaps;if(i){for(var a=i.length,n=new Array(a),s=0;s<a;s++){var o=new ar,l=i[s];l.path?o.lightmapColor=t.Loader.getRes(l.path):(o.lightmapColor=t.Loader.getRes(l.color.path),l.direction&&(o.lightmapDirection=t.Loader.getRes(l.direction.path))),n[s]=o}this.lightmaps=n}var _=e.ambientColor;if(_){var h=this.ambientColor;h.fromArray(_),this.ambientColor=h}var c=e.sky;if(c)switch(this._skyRenderer.material=t.Loader.getRes(c.material.path),c.mesh){case"SkyBox":this._skyRenderer.mesh=ke.instance;break;case"SkyDome":this._skyRenderer.mesh=Pt.instance;break;default:this.skyRenderer.mesh=ke.instance}this.enableFog=e.enableFog,this.fogStart=e.fogStart,this.fogRange=e.fogRange;var d=e.fogColor;if(d){var u=this.fogColor;u.fromArray(d),this.fogColor=u}var m=e.ambientSphericalHarmonics;if(m){var f=this.ambientSphericalHarmonics;for(s=0;s<3;s++){var T=9*s;f.setCoefficients(s,m[T],m[T+1],m[T+2],m[T+3],m[T+4],m[T+5],m[T+6],m[T+7],m[T+8])}this.ambientSphericalHarmonics=f}var E=e.reflection;null!=E&&(this.reflection=t.Loader.getRes(E));var p=e.reflectionDecodingFormat;null!=p&&(this.reflectionDecodingFormat=p);var g=e.ambientMode;null!=g&&(this.ambientMode=g);var S=e.ambientSphericalHarmonicsIntensity;null!=S&&(this.ambientSphericalHarmonicsIntensity=S);var R=e.reflectionIntensity;null!=R&&(this.reflectionIntensity=R)}_addRenderObject(e){this._octree&&e._supportOctree?this._octree.add(e):this._renders.add(e),e._addReflectionProbeUpdate()}_removeRenderObject(e){this._octree&&e._supportOctree?this._octree.remove(e):this._renders.remove(e)}_getRenderQueue(e){return e<=2500?this._opaqueQueue:this._transparentQueue}_clearRenderQueue(){this._opaqueQueue.clear(),this._transparentQueue.clear();for(var e=jt._managers,t=0,r=e.length;t<r;t++)e[t]._clear();var i=_r._managers;for(t=0,r=i.length;t<r;t++)i[t]._clear()}destroy(e=!0){if(!this.destroyed){super.destroy(e),this._skyRenderer.destroy(),this._skyRenderer=null,this._directionLights=null,this._pointLights=null,this._spotLights=null,this._alternateLights=null,this._shaderValues=null,this._renders=null,this._cameraPool=null,this._octree=null,this._physicsSimulation&&this._physicsSimulation._destroy(),this._reflection._removeReference(),this._reflection=null;var r=this._lightmaps;if(r)for(var i=0,a=r.length;i<a;i++){var n=r[i];n.lightmapColor&&n.lightmapColor._removeReference(),n.lightmapDirection&&n.lightmapDirection._removeReference()}this._lightmaps=null,this._reflectionProbeManager.destroy(),t.Loader.clearRes(this.url)}}render(e,r,i){e._curSubmit=t.SubmitBase.RENDERBASE,this._children.length>0&&e.addRenderObject(this)}renderSubmit(){var e,r,i;t.LayaGL.instance;for(this._prepareSceneToRender(),e=0,i=(r=this._cameraPool.length)-1;e<r;e++){t.Render.supportWebGLPlusRendering&&me.setRuntimeValueMode(e==i);var a=this._cameraPool[e];a.enableRender&&a.render()}return t.Context.set2DRenderConfig(),1}getRenderType(){return 0}releaseRender(){}reUse(e,t){return 0}setGlobalShaderValue(t,r,i){var a=xe.propertyNameToID(t);switch(r){case e.ShaderDataType.Int:this._shaderValues.setInt(a,i);break;case e.ShaderDataType.Number:this._shaderValues.setNumber(a,i);break;case e.ShaderDataType.Bool:this._shaderValues.setBool(a,i);break;case e.ShaderDataType.Matrix4x4:this._shaderValues.setMatrix4x4(a,i);break;case e.ShaderDataType.Quaternion:this._shaderValues.setQuaternion(a,i);break;case e.ShaderDataType.Texture:this._shaderValues.setTexture(a,i);break;case e.ShaderDataType.Vector4:this._shaderValues.setVector(a,i);break;case e.ShaderDataType.Vector2:this._shaderValues.setVector2(a,i);break;case e.ShaderDataType.Vector3:this._shaderValues.setVector3(a,i);break;case e.ShaderDataType.Buffer:this._shaderValues.setBuffer(a,i)}}get customReflection(){return this._reflection}set customReflection(e){this._reflection!=e&&(e._addReference(),this._reflectionProbeManager.sceneReflectionProbe=e,this._reflection=e)}get reflectionMode(){return this._reflectionMode}set reflectionMode(e){this._reflectionMode=e}setlightmaps(e){for(var t=this._lightmaps,r=0,i=t.length;r<i;r++)t[r].lightmapColor._removeReference();if(!e)throw new Error("Scene3D: value value can't be null.");var a=e.length;for(t.length=a,r=0;r<a;r++){var n=e[r];n._addReference(),t[r]||(t[r]=new ar),t[r].lightmapColor=n}}getlightmaps(){for(var e=new Array(this._lightmaps.length),t=0;t<this._lightmaps.length;t++)e[t]=this._lightmaps[t].lightmapColor;return e}}dr._shadowCasterPass=new lr,dr.HIERARCHY="HIERARCHY",dr.octreeCulling=!1,dr.octreeInitialSize=64,dr.octreeInitialCenter=new n(0,0,0),dr.octreeMinNodeSize=2,dr.octreeLooseness=1.25,dr.REFLECTIONMODE_SKYBOX=0,dr.REFLECTIONMODE_CUSTOM=1,dr.SCENERENDERFLAG_RENDERQPAQUE=0,dr.SCENERENDERFLAG_SKYBOX=1,dr.SCENERENDERFLAG_RENDERTRANSPARENT=2,dr.FOGCOLOR=xe.propertyNameToID("u_FogColor"),dr.FOGSTART=xe.propertyNameToID("u_FogStart"),dr.FOGRANGE=xe.propertyNameToID("u_FogRange"),dr.DIRECTIONLIGHTCOUNT=xe.propertyNameToID("u_DirationLightCount"),dr.LIGHTBUFFER=xe.propertyNameToID("u_LightBuffer"),dr.CLUSTERBUFFER=xe.propertyNameToID("u_LightClusterBuffer"),dr.SUNLIGHTDIRECTION=xe.propertyNameToID("u_SunLight.direction"),dr.SUNLIGHTDIRCOLOR=xe.propertyNameToID("u_SunLight.color"),dr.AMBIENTSHAR=xe.propertyNameToID("u_AmbientSHAr"),dr.AMBIENTSHAG=xe.propertyNameToID("u_AmbientSHAg"),dr.AMBIENTSHAB=xe.propertyNameToID("u_AmbientSHAb"),dr.AMBIENTSHBR=xe.propertyNameToID("u_AmbientSHBr"),dr.AMBIENTSHBG=xe.propertyNameToID("u_AmbientSHBg"),dr.AMBIENTSHBB=xe.propertyNameToID("u_AmbientSHBb"),dr.AMBIENTSHC=xe.propertyNameToID("u_AmbientSHC"),dr.LIGHTDIRECTION=xe.propertyNameToID("u_DirectionLight.direction"),dr.LIGHTDIRCOLOR=xe.propertyNameToID("u_DirectionLight.color"),dr.POINTLIGHTPOS=xe.propertyNameToID("u_PointLight.position"),dr.POINTLIGHTRANGE=xe.propertyNameToID("u_PointLight.range"),dr.POINTLIGHTATTENUATION=xe.propertyNameToID("u_PointLight.attenuation"),dr.POINTLIGHTCOLOR=xe.propertyNameToID("u_PointLight.color"),dr.SPOTLIGHTPOS=xe.propertyNameToID("u_SpotLight.position"),dr.SPOTLIGHTDIRECTION=xe.propertyNameToID("u_SpotLight.direction"),dr.SPOTLIGHTSPOTANGLE=xe.propertyNameToID("u_SpotLight.spot"),dr.SPOTLIGHTRANGE=xe.propertyNameToID("u_SpotLight.range"),dr.SPOTLIGHTCOLOR=xe.propertyNameToID("u_SpotLight.color"),dr.AMBIENTCOLOR=xe.propertyNameToID("u_AmbientColor"),dr.TIME=xe.propertyNameToID("u_Time"),dr._configDefineValues=new ce;class ur extends t.ShaderCompile{constructor(e,t,r,i){for(var a in super(t,r,null),this._cacheSharders={},this._cacheShaderHierarchy=1,this._renderState=new lt,this._validDefine=new ce,this._tags={},this._owner=e,this._stateMap=i,this.defs)this._validDefine.add(xe.getDefineByName(a))}get renderState(){return this._renderState}_compileToTree(e,r,i,a,n){var s,o,l,_,h,c,d,u,m,f,T;for(m=i;m<r.length;m++)if(!((l=r[m]).length<1)&&0!==(c=l.indexOf("//"))){if(c>=0&&(l=l.substr(0,c)),s=u||new t.ShaderNode(a),u=null,s.text=l,s.noCompile=!0,(c=l.indexOf("#"))>=0){for(_="#",T=c+1,f=l.length;T<f;T++){var E=l.charAt(T);if(" "===E||"\t"===E||"?"===E)break;_+=E}switch(s.name=_,_){case"#ifdef":case"#ifndef":if(s.src=l,s.noCompile=null!=l.match(/[!&|()=<>]/),s.noCompile?console.log("function():Boolean{return "+l.substr(c+s.name.length)+"}"):(d=l.replace(/^\s*/,"").split(/\s+/),s.setCondition(d[1],"#ifdef"===_?t.ShaderCompile.IFDEF_YES:t.ShaderCompile.IFDEF_ELSE),s.text="//"+s.text),s.setParent(e),e=s,n)for(d=l.substr(T).split(t.ShaderCompile._splitToWordExps3),T=0;T<d.length;T++)(l=d[T]).length&&(n[l]=!0);continue;case"#if":case"#elif":if(s.src=l,s.noCompile=!0,"#elif"==_&&((o=(e=e.parent).childs[e.childs.length-1]).text=o.src,o.noCompile=!0,o.condition=null),s.setParent(e),e=s,n)for(d=l.substr(T).split(t.ShaderCompile._splitToWordExps3),T=0;T<d.length;T++)(l=d[T]).length&&"defined"!=l&&(n[l]=!0);continue;case"#else":s.src=l,o=(e=e.parent).childs[e.childs.length-1],s.noCompile=o.noCompile,s.noCompile||(s.condition=o.condition,s.conditionType=o.conditionType==t.ShaderCompile.IFDEF_YES?t.ShaderCompile.IFDEF_ELSE:t.ShaderCompile.IFDEF_YES,s.text="//"+s.text+" "+o.text+" "+s.conditionType),s.setParent(e),e=s;continue;case"#endif":o=(e=e.parent).childs[e.childs.length-1],s.noCompile=o.noCompile,s.noCompile||(s.text="//"+s.text),s.setParent(e);continue;case"#include":d=t.ShaderCompile.splitToWords(l,null);var p=t.ShaderCompile.includes[d[1]];if(!p)throw"ShaderCompile error no this include file:"+d[1];if((c=d[0].indexOf("?"))<0){s.setParent(e),l=p.getWith("with"==d[2]?d[3]:null),this._compileToTree(s,l.split("\n"),0,a,n),s.text="";continue}s.setCondition(d[0].substr(c+1),t.ShaderCompile.IFDEF_YES),s.text=p.getWith("with"==d[2]?d[3]:null);break;case"#import":h=(d=t.ShaderCompile.splitToWords(l,null))[1],a.push({node:s,file:t.ShaderCompile.includes[h],ofs:s.text.length});continue}}else{if((o=e.childs[e.childs.length-1])&&!o.name){a.length>0&&t.ShaderCompile.splitToWords(l,o),u=s,o.text+="\n"+l;continue}a.length>0&&t.ShaderCompile.splitToWords(l,s)}s.setParent(e)}}_resizeCacheShaderMap(e,t,r){var i=this._cacheShaderHierarchy-1;if(t==i){for(var a in e)for(var n=e[a],s=0,o=r-i;s<o;s++)s==o-1?e[0]=n:e=e[0==s?a:0]={};this._cacheShaderHierarchy=r}else for(var a in e)this._resizeCacheShaderMap(e[a],++t,r)}_addDebugShaderVariantCollection(e,t,r){var i=xe._debugShaderVariantInfo,a=this._owner,n=a._owner,s=e._mask;xe._getNamesByDefineData(e,t),r.length=s.length;for(var o=0,l=s.length;o<l;o++)r[o]=s[o];i?i.setValue(n,n._subShaders.indexOf(a),a._passes.indexOf(this),t):xe._debugShaderVariantInfo=i=new Re(n,n._subShaders.indexOf(a),a._passes.indexOf(this),t),xe.debugShaderVariantCollection.add(i)}withCompile(e){var r,i=ur._debugDefineString,a=ur._debugDefineMask;e._intersectionDefineDatas(this._validDefine),xe.debugMode&&(r=e._length,this._addDebugShaderVariantCollection(e,i,a)),e.addDefineDatas(dr._configDefineValues);var n=this._cacheSharders,s=e._length;s>this._cacheShaderHierarchy&&(this._resizeCacheShaderMap(n,0,s),this._cacheShaderHierarchy=s);for(var o=e._mask,l=e._length-1,_=this._cacheShaderHierarchy-1,h=0;h<_;h++){var c=l<h?0:o[h],d=n[c];d||(n[c]=d={}),n=d}var u=l<_?0:o[_],m=n[u];if(m)return m;var f=ur._defineString;xe._getNamesByDefineData(e,f);var T,E,p=j._config,g=p.lightClusterCount,S={},R="";t.WebGL._isWebGL2?(T="#version 300 es\n\n\t\t\t\t#define attribute in\n\t\t\t\t#define varying out\n\t\t\t\t#define texture2D texture\n",E="#version 300 es\n\n\t\t\t\t#define varying in\n\t\t\t\tout highp vec4 pc_fragColor;\n\t\t\t\t#define gl_FragColor pc_fragColor\n\t\t\t\t#define gl_FragDepthEXT gl_FragDepth\n\t\t\t\t#define texture2D texture\n\t\t\t\t#define textureCube texture\n\t\t\t\t#define texture2DProj textureProj\n\t\t\t\t#define texture2DLodEXT textureLod\n\t\t\t\t#define texture2DProjLodEXT textureProjLod\n\t\t\t\t#define textureCubeLodEXT textureLod\n\t\t\t\t#define texture2DGradEXT textureGrad\n\t\t\t\t#define texture2DProjGradEXT textureProjGrad\n\t\t\t\t#define textureCubeGradEXT textureGrad\n"):(T="",E="#ifdef GL_EXT_shader_texture_lod\n\t\t\t\t\t#extension GL_EXT_shader_texture_lod : enable\n\t\t\t\t#endif\n\t\t\t\t#if !defined(GL_EXT_shader_texture_lod)\n\t\t\t\t\t#define texture1DLodEXT texture1D\n\t\t\t\t\t#define texture2DLodEXT texture2D\n\t\t\t\t\t#define texture2DProjLodEXT texture2DProj\n\t\t\t\t\t#define texture3DLodEXT texture3D\n\t\t\t\t\t#define textureCubeLodEXT textureCube\n\t\t\t\t#endif\n"),R+="#define MAX_LIGHT_COUNT "+p.maxLightCount+"\n",R+="#define MAX_LIGHT_COUNT_PER_CLUSTER "+p._maxAreaLightCountPerClusterAverage+"\n",R+="#define CLUSTER_X_COUNT "+g.x+"\n",R+="#define CLUSTER_Y_COUNT "+g.y+"\n",R+="#define CLUSTER_Z_COUNT "+g.z+"\n",R+="#define SHADER_CAPAILITY_LEVEL "+t.SystemUtils._shaderCapailityLevel+"\n";h=0;for(var v=f.length;h<v;h++){var x=f[h];R+="#define "+x+"\n",S[x]=!0}var A=this._VS.toscript(S,[]),I="";0==A[0].indexOf("#version")&&(I=A[0]+"\n",A.shift());var M=this._PS.toscript(S,[]),D="";0==M[0].indexOf("#version")&&(D=M[0]+"\n",M.shift());var C=xe.getAttributeMapByDefine(f,this._owner._attributeMap);if(m=new Rt(I+T+R+A.join("\n"),D+E+R+M.join("\n"),C,this._owner._uniformMap||this._owner._owner._uniformMap,this),n[u]=m,xe.debugMode){var y="",L="";for(h=0,v=r;h<v;h++)L+=h==v-1?a[h]:a[h]+",";for(h=0,v=i.length;h<v;h++)y+=h==v-1?i[h]:i[h]+",";console.log("%cLayaAir: Shader Compile Information---ShaderName:"+this._owner._owner._name+" SubShaderIndex:"+this._owner._owner._subShaders.indexOf(this._owner)+" PassIndex:"+this._owner._passes.indexOf(this)+" DefineMask:["+L+"] DefineNames:["+y+"]","color:green")}return m}setTag(e,t){t?this._tags[e]=t:delete this._tags[e]}getTag(e){return this._tags[e]}}ur._defineString=[],ur._debugDefineString=[],ur._debugDefineMask=[];class mr{constructor(e,t){this._flags={},this._passes=[],this._attributeMap=e,this._uniformMap=t}setFlag(e,t){t?this._flags[e]=t:delete this._flags[e]}getFlag(e){return this._flags[e]}addShaderPass(e,t,r=null,i="Forward"){var a=new ur(this,e,t,r);return a._pipelineMode=i,this._passes.push(a),a}}(Et=e.PBRSpecularSmoothnessSource||(e.PBRSpecularSmoothnessSource={}))[Et.SpecularTextureAlpha=0]="SpecularTextureAlpha",Et[Et.AlbedoTextureAlpha=1]="AlbedoTextureAlpha";class fr extends dt{constructor(){super(),this.setShaderName("PBRSpecular"),this._shaderValues.setVector(fr.SPECULARCOLOR,new a(.2,.2,.2,1))}static __init__(){fr.SHADERDEFINE_SPECULARGLOSSTEXTURE=xe.getDefineByName("SPECULARGLOSSTEXTURE"),fr.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA=xe.getDefineByName("SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA");var e={a_Position:ze.MESH_POSITION0,a_Normal:ze.MESH_NORMAL0,a_Tangent0:ze.MESH_TANGENT0,a_Texcoord0:ze.MESH_TEXTURECOORDINATE0,a_Texcoord1:ze.MESH_TEXTURECOORDINATE1,a_BoneWeights:ze.MESH_BLENDWEIGHT0,a_BoneIndices:ze.MESH_BLENDINDICES0,a_MvpMatrix:ze.MESH_MVPMATRIX_ROW0,a_WorldMat:ze.MESH_WORLDMATRIX_ROW0},t={u_Bones:xe.PERIOD_CUSTOM,u_MvpMatrix:xe.PERIOD_SPRITE,u_WorldMat:xe.PERIOD_SPRITE,u_LightmapScaleOffset:xe.PERIOD_SPRITE,u_LightMap:xe.PERIOD_SPRITE,u_LightMapDirection:xe.PERIOD_SPRITE,u_SimpleAnimatorTexture:xe.PERIOD_SPRITE,u_SimpleAnimatorParams:xe.PERIOD_SPRITE,u_SimpleAnimatorTextureSize:xe.PERIOD_SPRITE,u_ReflectCubeHDRParams:xe.PERIOD_SPRITE,u_ReflectTexture:xe.PERIOD_SPRITE,u_SpecCubeProbePosition:xe.PERIOD_SPRITE,u_SpecCubeBoxMax:xe.PERIOD_SPRITE,u_SpecCubeBoxMin:xe.PERIOD_SPRITE,u_CameraPos:xe.PERIOD_CAMERA,u_View:xe.PERIOD_CAMERA,u_ProjectionParams:xe.PERIOD_CAMERA,u_Viewport:xe.PERIOD_CAMERA,u_ViewProjection:xe.PERIOD_CAMERA,u_AlphaTestValue:xe.PERIOD_MATERIAL,u_AlbedoColor:xe.PERIOD_MATERIAL,u_EmissionColor:xe.PERIOD_MATERIAL,u_AlbedoTexture:xe.PERIOD_MATERIAL,u_NormalTexture:xe.PERIOD_MATERIAL,u_ParallaxTexture:xe.PERIOD_MATERIAL,u_OcclusionTexture:xe.PERIOD_MATERIAL,u_EmissionTexture:xe.PERIOD_MATERIAL,u_Smoothness:xe.PERIOD_MATERIAL,u_SmoothnessScale:xe.PERIOD_MATERIAL,u_occlusionStrength:xe.PERIOD_MATERIAL,u_NormalScale:xe.PERIOD_MATERIAL,u_ParallaxScale:xe.PERIOD_MATERIAL,u_TilingOffset:xe.PERIOD_MATERIAL,u_SpecGlossTexture:xe.PERIOD_MATERIAL,u_SpecularColor:xe.PERIOD_MATERIAL,u_AmbientColor:xe.PERIOD_SCENE,u_FogStart:xe.PERIOD_SCENE,u_FogRange:xe.PERIOD_SCENE,u_FogColor:xe.PERIOD_SCENE,u_DirationLightCount:xe.PERIOD_SCENE,u_LightBuffer:xe.PERIOD_SCENE,u_LightClusterBuffer:xe.PERIOD_SCENE,u_ShadowBias:xe.PERIOD_SCENE,u_ShadowLightDirection:xe.PERIOD_SCENE,u_ShadowMap:xe.PERIOD_SCENE,u_ShadowParams:xe.PERIOD_SCENE,u_ShadowSplitSpheres:xe.PERIOD_SCENE,u_ShadowMatrices:xe.PERIOD_SCENE,u_ShadowMapSize:xe.PERIOD_SCENE,u_SpotShadowMap:xe.PERIOD_SCENE,u_SpotViewProjectMatrix:xe.PERIOD_SCENE,u_ShadowLightPosition:xe.PERIOD_SCENE,u_AmbientSHAr:xe.PERIOD_SCENE,u_AmbientSHAg:xe.PERIOD_SCENE,u_AmbientSHAb:xe.PERIOD_SCENE,u_AmbientSHBr:xe.PERIOD_SCENE,u_AmbientSHBg:xe.PERIOD_SCENE,u_AmbientSHBb:xe.PERIOD_SCENE,u_AmbientSHC:xe.PERIOD_SCENE,"u_DirectionLight.direction":xe.PERIOD_SCENE,"u_DirectionLight.color":xe.PERIOD_SCENE,"u_PointLight.position":xe.PERIOD_SCENE,"u_PointLight.range":xe.PERIOD_SCENE,"u_PointLight.color":xe.PERIOD_SCENE,"u_SpotLight.position":xe.PERIOD_SCENE,"u_SpotLight.direction":xe.PERIOD_SCENE,"u_SpotLight.range":xe.PERIOD_SCENE,"u_SpotLight.spot":xe.PERIOD_SCENE,"u_SpotLight.color":xe.PERIOD_SCENE},r={s_Cull:xe.RENDER_STATE_CULL,s_Blend:xe.RENDER_STATE_BLEND,s_BlendSrc:xe.RENDER_STATE_BLEND_SRC,s_BlendDst:xe.RENDER_STATE_BLEND_DST,s_DepthTest:xe.RENDER_STATE_DEPTH_TEST,s_DepthWrite:xe.RENDER_STATE_DEPTH_WRITE},i=xe.add("PBRSpecular",e,t,!0,!0),a=new mr(e,t);i.addSubShader(a),a.addShaderPass('#include "PBRVSInput.glsl";\r\n#include "Lighting.glsl";\r\n#include "PBRVertex.glsl";\r\n\r\nvoid main()\r\n{\r\n\tvertexForward();\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n\r\n#define SETUP_BRDF_INPUT specularSetup\r\n\r\n#include "Lighting.glsl";\r\n#include "PBRFSInput.glsl";\r\n#include "LayaPBRBRDF.glsl";\r\n#include "GlobalIllumination.glsl";\r\n#include "Shadow.glsl"\r\n#include "PBRCore.glsl";\r\n\r\nvoid main()\r\n{\r\n\tfragmentForward();\r\n}',r,"Forward"),a.addShaderPass('#include "ShadowCasterVS.glsl"\r\n\r\nvoid main()\r\n{\r\n\tvec4 positionCS = shadowCasterVertex();\r\n\tgl_Position=remapGLPositionZ(positionCS);\r\n}','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n\r\n#include "ShadowCasterFS.glsl"\r\n\r\nvoid main()\r\n{\r\n\tgl_FragColor=shadowCasterFragment();\r\n}',r,"ShadowCaster"),a.addShaderPass(pt,gt,r,"DepthNormal")}get specularTexture(){return this._shaderValues.getTexture(fr.SPECULARTEXTURE)}set specularTexture(e){e?this._shaderValues.addDefine(fr.SHADERDEFINE_SPECULARGLOSSTEXTURE):this._shaderValues.removeDefine(fr.SHADERDEFINE_SPECULARGLOSSTEXTURE),this._shaderValues.setTexture(fr.SPECULARTEXTURE,e)}get specularColor(){return this._shaderValues.getVector(fr.SPECULARCOLOR)}set specularColor(e){this._shaderValues.setVector(fr.SPECULARCOLOR,e)}clone(){var e=new fr;return this.cloneTo(e),e}}fr.SPECULARTEXTURE=xe.propertyNameToID("u_SpecGlossTexture"),fr.SPECULARCOLOR=xe.propertyNameToID("u_SpecularColor");var Tr,Er,pr;(Tr=e.PBRMetallicSmoothnessSource||(e.PBRMetallicSmoothnessSource={}))[Tr.MetallicGlossTextureAlpha=0]="MetallicGlossTextureAlpha",Tr[Tr.AlbedoTextureAlpha=1]="AlbedoTextureAlpha";class gr extends dt{constructor(){super(),this._smoothnessSource=0,this.setShaderName("PBR"),this._shaderValues.setNumber(gr.METALLIC,0)}static __init__(){gr.SHADERDEFINE_METALLICGLOSSTEXTURE=xe.getDefineByName("METALLICGLOSSTEXTURE"),gr.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA=xe.getDefineByName("SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA");var e={a_Position:ze.MESH_POSITION0,a_Normal:ze.MESH_NORMAL0,a_Tangent0:ze.MESH_TANGENT0,a_Texcoord0:ze.MESH_TEXTURECOORDINATE0,a_Texcoord1:ze.MESH_TEXTURECOORDINATE1,a_BoneWeights:ze.MESH_BLENDWEIGHT0,a_BoneIndices:ze.MESH_BLENDINDICES0,a_MvpMatrix:ze.MESH_MVPMATRIX_ROW0,a_WorldMat:ze.MESH_WORLDMATRIX_ROW0},t={u_Bones:xe.PERIOD_CUSTOM,u_MvpMatrix:xe.PERIOD_SPRITE,u_WorldMat:xe.PERIOD_SPRITE,u_LightmapScaleOffset:xe.PERIOD_SPRITE,u_LightMap:xe.PERIOD_SPRITE,u_LightMapDirection:xe.PERIOD_SPRITE,u_SimpleAnimatorTexture:xe.PERIOD_SPRITE,u_SimpleAnimatorParams:xe.PERIOD_SPRITE,u_SimpleAnimatorTextureSize:xe.PERIOD_SPRITE,u_ReflectCubeHDRParams:xe.PERIOD_SPRITE,u_ReflectTexture:xe.PERIOD_SPRITE,u_SpecCubeProbePosition:xe.PERIOD_SPRITE,u_SpecCubeBoxMax:xe.PERIOD_SPRITE,u_SpecCubeBoxMin:xe.PERIOD_SPRITE,u_CameraPos:xe.PERIOD_CAMERA,u_View:xe.PERIOD_CAMERA,u_ProjectionParams:xe.PERIOD_CAMERA,u_Viewport:xe.PERIOD_CAMERA,u_ViewProjection:xe.PERIOD_CAMERA,u_AlphaTestValue:xe.PERIOD_MATERIAL,u_AlbedoColor:xe.PERIOD_MATERIAL,u_EmissionColor:xe.PERIOD_MATERIAL,u_AlbedoTexture:xe.PERIOD_MATERIAL,u_NormalTexture:xe.PERIOD_MATERIAL,u_ParallaxTexture:xe.PERIOD_MATERIAL,u_OcclusionTexture:xe.PERIOD_MATERIAL,u_EmissionTexture:xe.PERIOD_MATERIAL,u_Smoothness:xe.PERIOD_MATERIAL,u_SmoothnessScale:xe.PERIOD_MATERIAL,u_occlusionStrength:xe.PERIOD_MATERIAL,u_NormalScale:xe.PERIOD_MATERIAL,u_ParallaxScale:xe.PERIOD_MATERIAL,u_TilingOffset:xe.PERIOD_MATERIAL,u_MetallicGlossTexture:xe.PERIOD_MATERIAL,u_Metallic:xe.PERIOD_MATERIAL,u_AmbientColor:xe.PERIOD_SCENE,u_FogStart:xe.PERIOD_SCENE,u_FogRange:xe.PERIOD_SCENE,u_FogColor:xe.PERIOD_SCENE,u_DirationLightCount:xe.PERIOD_SCENE,u_LightBuffer:xe.PERIOD_SCENE,u_LightClusterBuffer:xe.PERIOD_SCENE,u_ShadowBias:xe.PERIOD_SCENE,u_ShadowLightDirection:xe.PERIOD_SCENE,u_ShadowMap:xe.PERIOD_SCENE,u_ShadowParams:xe.PERIOD_SCENE,u_ShadowSplitSpheres:xe.PERIOD_SCENE,u_ShadowMatrices:xe.PERIOD_SCENE,u_ShadowMapSize:xe.PERIOD_SCENE,u_SpotShadowMap:xe.PERIOD_SCENE,u_SpotViewProjectMatrix:xe.PERIOD_SCENE,u_ShadowLightPosition:xe.PERIOD_SCENE,u_AmbientSHAr:xe.PERIOD_SCENE,u_AmbientSHAg:xe.PERIOD_SCENE,u_AmbientSHAb:xe.PERIOD_SCENE,u_AmbientSHBr:xe.PERIOD_SCENE,u_AmbientSHBg:xe.PERIOD_SCENE,u_AmbientSHBb:xe.PERIOD_SCENE,u_AmbientSHC:xe.PERIOD_SCENE,"u_DirectionLight.direction":xe.PERIOD_SCENE,"u_DirectionLight.color":xe.PERIOD_SCENE,"u_PointLight.position":xe.PERIOD_SCENE,"u_PointLight.range":xe.PERIOD_SCENE,"u_PointLight.color":xe.PERIOD_SCENE,"u_SpotLight.position":xe.PERIOD_SCENE,"u_SpotLight.direction":xe.PERIOD_SCENE,"u_SpotLight.range":xe.PERIOD_SCENE,"u_SpotLight.spot":xe.PERIOD_SCENE,"u_SpotLight.color":xe.PERIOD_SCENE},r={s_Cull:xe.RENDER_STATE_CULL,s_Blend:xe.RENDER_STATE_BLEND,s_BlendSrc:xe.RENDER_STATE_BLEND_SRC,s_BlendDst:xe.RENDER_STATE_BLEND_DST,s_DepthTest:xe.RENDER_STATE_DEPTH_TEST,s_DepthWrite:xe.RENDER_STATE_DEPTH_WRITE},i=xe.add("PBR",e,t,!0,!0),a=new mr(e,t);i.addSubShader(a),a.addShaderPass('#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n#include "Lighting.glsl";\r\n#include "LayaUtile.glsl"\r\n#include "Shadow.glsl"\r\n#include "PBRVSInput.glsl";\r\n#include "PBRVertex.glsl";\r\n\r\nvoid main()\r\n{\r\n\tvertexForward();\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n\r\n#include "Lighting.glsl";\r\n#include "Shadow.glsl"\r\n#include "PBRFSInput.glsl";\r\n#include "LayaPBRBRDF.glsl";\r\n#include "GlobalIllumination.glsl";\r\n#include "PBRCore.glsl";\r\n\r\nvoid main()\r\n{\r\n\tfragmentForward();\r\n}',r,"Forward"),a.addShaderPass('#include "ShadowCasterVS.glsl"\r\n\r\nvoid main()\r\n{\r\n\tvec4 positionCS = shadowCasterVertex();\r\n\tgl_Position=remapGLPositionZ(positionCS);\r\n}','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n\r\n#include "ShadowCasterFS.glsl"\r\n\r\nvoid main()\r\n{\r\n\tgl_FragColor=shadowCasterFragment();\r\n}',r,"ShadowCaster"),a.addShaderPass(pt,gt,r,"DepthNormal")}get metallicGlossTexture(){return this._shaderValues.getTexture(gr.METALLICGLOSSTEXTURE)}set metallicGlossTexture(e){e?this._shaderValues.addDefine(gr.SHADERDEFINE_METALLICGLOSSTEXTURE):this._shaderValues.removeDefine(gr.SHADERDEFINE_METALLICGLOSSTEXTURE),this._shaderValues.setTexture(gr.METALLICGLOSSTEXTURE,e)}get metallic(){return this._shaderValues.getNumber(gr.METALLIC)}set metallic(e){this._shaderValues.setNumber(gr.METALLIC,Math.max(0,Math.min(1,e)))}get smoothnessSource(){return this._smoothnessSource}set smoothnessSource(e){e?this._shaderValues.addDefine(gr.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA):this._shaderValues.removeDefine(gr.SHADERDEFINE_SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA),this._smoothnessSource=e}clone(){var e=new gr;return this.cloneTo(e),e}}gr.METALLICGLOSSTEXTURE=xe.propertyNameToID("u_MetallicGlossTexture"),gr.METALLIC=xe.propertyNameToID("u_Metallic");class Sr extends st{constructor(){super(),this.setShaderName("SkyBox"),this.tintColor=new a(.5,.5,.5,.5),this.exposure=1,this.rotation=0}static __initDefine__(){}get tintColor(){return this._shaderValues.getVector(Sr.TINTCOLOR)}set tintColor(e){this._shaderValues.setVector(Sr.TINTCOLOR,e)}get exposure(){return this._shaderValues.getNumber(Sr.EXPOSURE)}set exposure(e){this._shaderValues.setNumber(Sr.EXPOSURE,e)}get rotation(){return this._shaderValues.getNumber(Sr.ROTATION)}set rotation(e){this._shaderValues.setNumber(Sr.ROTATION,e)}get textureCube(){return this._shaderValues.getTexture(Sr.TEXTURECUBE)}set textureCube(e){this._shaderValues.setTexture(Sr.TEXTURECUBE,e)}clone(){var e=new Sr;return this.cloneTo(e),e}}Sr.TINTCOLOR=xe.propertyNameToID("u_TintColor"),Sr.EXPOSURE=xe.propertyNameToID("u_Exposure"),Sr.ROTATION=xe.propertyNameToID("u_Rotation"),Sr.TEXTURECUBE=xe.propertyNameToID("u_CubeTexture");class Rr extends st{constructor(){super(),this.setShaderName("SkyBoxProcedural"),this.sunDisk=Rr.SUN_HIGH_QUALITY,this.sunSize=.04,this.sunSizeConvergence=5,this.atmosphereThickness=1,this.skyTint=new a(.5,.5,.5,1),this.groundTint=new a(.369,.349,.341,1),this.exposure=1.3}static __initDefine__(){Rr.SHADERDEFINE_SUN_HIGH_QUALITY=xe.getDefineByName("SUN_HIGH_QUALITY"),Rr.SHADERDEFINE_SUN_SIMPLE=xe.getDefineByName("SUN_SIMPLE")}get sunDisk(){return this._sunDisk}set sunDisk(e){switch(e){case Rr.SUN_HIGH_QUALITY:this._shaderValues.removeDefine(Rr.SHADERDEFINE_SUN_SIMPLE),this._shaderValues.addDefine(Rr.SHADERDEFINE_SUN_HIGH_QUALITY);break;case Rr.SUN_SIMPLE:this._shaderValues.removeDefine(Rr.SHADERDEFINE_SUN_HIGH_QUALITY),this._shaderValues.addDefine(Rr.SHADERDEFINE_SUN_SIMPLE);break;case Rr.SUN_NODE:this._shaderValues.removeDefine(Rr.SHADERDEFINE_SUN_HIGH_QUALITY),this._shaderValues.removeDefine(Rr.SHADERDEFINE_SUN_SIMPLE);break;default:throw"SkyBoxProceduralMaterial: unknown sun value."}this._sunDisk=e}get sunSize(){return this._shaderValues.getNumber(Rr.SUNSIZE)}set sunSize(e){e=Math.min(Math.max(0,e),1),this._shaderValues.setNumber(Rr.SUNSIZE,e)}get sunSizeConvergence(){return this._shaderValues.getNumber(Rr.SUNSIZECONVERGENCE)}set sunSizeConvergence(e){e=Math.min(Math.max(0,e),20),this._shaderValues.setNumber(Rr.SUNSIZECONVERGENCE,e)}get atmosphereThickness(){return this._shaderValues.getNumber(Rr.ATMOSPHERETHICKNESS)}set atmosphereThickness(e){e=Math.min(Math.max(0,e),5),this._shaderValues.setNumber(Rr.ATMOSPHERETHICKNESS,e)}get skyTint(){return this._shaderValues.getVector(Rr.SKYTINT)}set skyTint(e){this._shaderValues.setVector(Rr.SKYTINT,e)}get groundTint(){return this._shaderValues.getVector(Rr.GROUNDTINT)}set groundTint(e){this._shaderValues.setVector(Rr.GROUNDTINT,e)}get exposure(){return this._shaderValues.getNumber(Rr.EXPOSURE)}set exposure(e){e=Math.min(Math.max(0,e),8),this._shaderValues.setNumber(Rr.EXPOSURE,e)}clone(){var e=new Rr;return this.cloneTo(e),e}}Rr.SUN_NODE=0,Rr.SUN_SIMPLE=1,Rr.SUN_HIGH_QUALITY=2,Rr.SUNSIZE=xe.propertyNameToID("u_SunSize"),Rr.SUNSIZECONVERGENCE=xe.propertyNameToID("u_SunSizeConvergence"),Rr.ATMOSPHERETHICKNESS=xe.propertyNameToID("u_AtmosphereThickness"),Rr.SKYTINT=xe.propertyNameToID("u_SkyTint"),Rr.GROUNDTINT=xe.propertyNameToID("u_GroundTint"),Rr.EXPOSURE=xe.propertyNameToID("u_Exposure");class vr extends st{constructor(){super(),this._albedoColor=new a(1,1,1,1),this._albedoIntensity=1,this._enableVertexColor=!1,this.setShaderName("Unlit"),this._shaderValues.setVector(vr.ALBEDOCOLOR,new a(1,1,1,1)),this.renderMode=vr.RENDERMODE_OPAQUE}static __initDefine__(){vr.SHADERDEFINE_ALBEDOTEXTURE=xe.getDefineByName("ALBEDOTEXTURE"),vr.SHADERDEFINE_TILINGOFFSET=xe.getDefineByName("TILINGOFFSET"),vr.SHADERDEFINE_ENABLEVERTEXCOLOR=xe.getDefineByName("ENABLEVERTEXCOLOR")}get _ColorR(){return this._albedoColor.x}set _ColorR(e){this._albedoColor.x=e,this.albedoColor=this._albedoColor}get _ColorG(){return this._albedoColor.y}set _ColorG(e){this._albedoColor.y=e,this.albedoColor=this._albedoColor}get _ColorB(){return this._albedoColor.z}set _ColorB(e){this._albedoColor.z=e,this.albedoColor=this._albedoColor}get _ColorA(){return this._albedoColor.w}set _ColorA(e){this._albedoColor.w=e,this.albedoColor=this._albedoColor}get _Color(){return this._shaderValues.getVector(vr.ALBEDOCOLOR)}set _Color(e){this.albedoColor=e}get _AlbedoIntensity(){return this._albedoIntensity}set _AlbedoIntensity(e){if(this._albedoIntensity!==e){var t=this._shaderValues.getVector(vr.ALBEDOCOLOR);a.scale(this._albedoColor,e,t),this._albedoIntensity=e,this._shaderValues.setVector(vr.ALBEDOCOLOR,t)}}get _MainTex_STX(){return this._shaderValues.getVector(vr.TILINGOFFSET).x}set _MainTex_STX(e){var t=this._shaderValues.getVector(vr.TILINGOFFSET);t.x=e,this.tilingOffset=t}get _MainTex_STY(){return this._shaderValues.getVector(vr.TILINGOFFSET).y}set _MainTex_STY(e){var t=this._shaderValues.getVector(vr.TILINGOFFSET);t.y=e,this.tilingOffset=t}get _MainTex_STZ(){return this._shaderValues.getVector(vr.TILINGOFFSET).z}set _MainTex_STZ(e){var t=this._shaderValues.getVector(vr.TILINGOFFSET);t.z=e,this.tilingOffset=t}get _MainTex_STW(){return this._shaderValues.getVector(vr.TILINGOFFSET).w}set _MainTex_STW(e){var t=this._shaderValues.getVector(vr.TILINGOFFSET);t.w=e,this.tilingOffset=t}get _MainTex_ST(){return this._shaderValues.getVector(vr.TILINGOFFSET)}set _MainTex_ST(e){this.tilingOffset=e}get _Cutoff(){return this.alphaTestValue}set _Cutoff(e){this.alphaTestValue=e}get albedoColorR(){return this._ColorR}set albedoColorR(e){this._ColorR=e}get albedoColorG(){return this._ColorG}set albedoColorG(e){this._ColorG=e}get albedoColorB(){return this._ColorB}set albedoColorB(e){this._ColorB=e}get albedoColorA(){return this._ColorA}set albedoColorA(e){this._ColorA=e}get albedoColor(){return this._albedoColor}set albedoColor(e){var t=this._shaderValues.getVector(vr.ALBEDOCOLOR);a.scale(e,this._albedoIntensity,t),this._albedoColor=e,this._shaderValues.setVector(vr.ALBEDOCOLOR,t)}get albedoIntensity(){return this._albedoIntensity}set albedoIntensity(e){this._AlbedoIntensity=e}get albedoTexture(){return this._shaderValues.getTexture(vr.ALBEDOTEXTURE)}set albedoTexture(e){e?this._shaderValues.addDefine(vr.SHADERDEFINE_ALBEDOTEXTURE):this._shaderValues.removeDefine(vr.SHADERDEFINE_ALBEDOTEXTURE),this._shaderValues.setTexture(vr.ALBEDOTEXTURE,e)}get tilingOffsetX(){return this._MainTex_STX}set tilingOffsetX(e){this._MainTex_STX=e}get tilingOffsetY(){return this._MainTex_STY}set tilingOffsetY(e){this._MainTex_STY=e}get tilingOffsetZ(){return this._MainTex_STZ}set tilingOffsetZ(e){this._MainTex_STZ=e}get tilingOffsetW(){return this._MainTex_STW}set tilingOffsetW(e){this._MainTex_STW=e}get tilingOffset(){return this._shaderValues.getVector(vr.TILINGOFFSET)}set tilingOffset(e){e&&(1!=e.x||1!=e.y||0!=e.z||0!=e.w)?this._shaderValues.addDefine(vr.SHADERDEFINE_TILINGOFFSET):this._shaderValues.removeDefine(vr.SHADERDEFINE_TILINGOFFSET),this._shaderValues.setVector(vr.TILINGOFFSET,e)}get enableVertexColor(){return this._enableVertexColor}set enableVertexColor(e){this._enableVertexColor=e,e?this._shaderValues.addDefine(vr.SHADERDEFINE_ENABLEVERTEXCOLOR):this._shaderValues.removeDefine(vr.SHADERDEFINE_ENABLEVERTEXCOLOR)}set renderMode(e){switch(e){case vr.RENDERMODE_OPAQUE:this.alphaTest=!1,this.renderQueue=st.RENDERQUEUE_OPAQUE,this.depthWrite=!0,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_DISABLE,this.depthTest=lt.DEPTHTEST_LESS;break;case vr.RENDERMODE_CUTOUT:this.renderQueue=st.RENDERQUEUE_ALPHATEST,this.alphaTest=!0,this.depthWrite=!0,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_DISABLE,this.depthTest=lt.DEPTHTEST_LESS;break;case vr.RENDERMODE_TRANSPARENT:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.alphaTest=!1,this.depthWrite=!1,this.cull=lt.CULL_BACK,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA,this.depthTest=lt.DEPTHTEST_LESS;break;default:throw new Error("UnlitMaterial : renderMode value error.")}}clone(){var e=new vr;return this.cloneTo(e),e}}vr.RENDERMODE_OPAQUE=0,vr.RENDERMODE_CUTOUT=1,vr.RENDERMODE_TRANSPARENT=2,vr.RENDERMODE_ADDTIVE=3,vr.ALBEDOTEXTURE=xe.propertyNameToID("u_AlbedoTexture"),vr.ALBEDOCOLOR=xe.propertyNameToID("u_AlbedoColor"),vr.TILINGOFFSET=xe.propertyNameToID("u_TilingOffset");class xr extends st{constructor(){super(),this.setShaderName("WaterPrimary"),this._shaderValues.setVector(xr.HORIZONCOLOR,new a(.172,.463,.435,0)),this._shaderValues.setNumber(xr.WAVESCALE,.15),this._shaderValues.setVector(xr.WAVESPEED,new a(19,9,-16,-7))}static __initDefine__(){xr.SHADERDEFINE_MAINTEXTURE=xe.getDefineByName("MAINTEXTURE"),xr.SHADERDEFINE_NORMALTEXTURE=xe.getDefineByName("NORMALTEXTURE")}get horizonColor(){return this._shaderValues.getVector(xr.HORIZONCOLOR)}set horizonColor(e){this._shaderValues.setVector(xr.HORIZONCOLOR,e)}get mainTexture(){return this._shaderValues.getTexture(xr.MAINTEXTURE)}set mainTexture(e){e?this._shaderValues.addDefine(xr.SHADERDEFINE_MAINTEXTURE):this._shaderValues.removeDefine(xr.SHADERDEFINE_MAINTEXTURE),this._shaderValues.setTexture(xr.MAINTEXTURE,e)}get normalTexture(){return this._shaderValues.getTexture(xr.NORMALTEXTURE)}set normalTexture(e){e?this._shaderValues.addDefine(xr.SHADERDEFINE_NORMALTEXTURE):this._shaderValues.removeDefine(xr.SHADERDEFINE_NORMALTEXTURE),this._shaderValues.setTexture(xr.NORMALTEXTURE,e)}get waveScale(){return this._shaderValues.getNumber(xr.WAVESCALE)}set waveScale(e){this._shaderValues.setNumber(xr.WAVESCALE,e)}get waveSpeed(){return this._shaderValues.getVector(xr.WAVESPEED)}set waveSpeed(e){this._shaderValues.setVector(xr.WAVESPEED,e)}clone(){var e=new xr;return this.cloneTo(e),e}}xr.HORIZONCOLOR=xe.propertyNameToID("u_HorizonColor"),xr.MAINTEXTURE=xe.propertyNameToID("u_MainTexture"),xr.NORMALTEXTURE=xe.propertyNameToID("u_NormalTexture"),xr.WAVESCALE=xe.propertyNameToID("u_WaveScale"),xr.WAVESPEED=xe.propertyNameToID("u_WaveSpeed");class Ar{}class Ir extends Kt{constructor(e){super(e),this._revertStaticBatchDefineUV1=!1,this._projectionViewWorldMatrix=new R}_createRenderElement(){return new Yt}_onMeshChange(e){if(e){var t=e.subMeshCount;this._renderElements.length=t;for(var r=0;r<t;r++){var i=this._renderElements[r];if(!i){var a=this.sharedMaterials[r];(i=this._renderElements[r]=this._createRenderElement()).setTransform(this._owner._transform),i.render=this,i.material=a||_t.defaultMaterial}i.setGeometry(e.getSubMesh(r))}}else this._renderElements.length=0;this._boundsChange=!0}_calculateBoundingBox(){var e=this._owner.meshFilter.sharedMesh;if(e){var t=this._owner.transform.worldMatrix;e.bounds._tranform(t,this._bounds)}}_needRender(e,t){return!e||e.intersects(this.bounds._getBoundBox())}_renderUpdate(t,r){this._applyLightMapParams();var i=t.renderElement;switch(i.renderType){case Ke.RENDERTYPE_NORMAL:this._shaderValues.setMatrix4x4(Ce.WORLDMATRIX,r.worldMatrix);break;case Ke.RENDERTYPE_STATICBATCH:r?this._shaderValues.setMatrix4x4(Ce.WORLDMATRIX,r.worldMatrix):this._shaderValues.setMatrix4x4(Ce.WORLDMATRIX,R.DEFAULT),this._shaderValues.hasDefine(Ar.SHADERDEFINE_UV1)?this._revertStaticBatchDefineUV1=!1:(this._shaderValues.addDefine(Ar.SHADERDEFINE_UV1),this._revertStaticBatchDefineUV1=!0),this._shaderValues.setVector(kt.LIGHTMAPSCALEOFFSET,Kt._defaultLightmapScaleOffset);break;case Ke.RENDERTYPE_VERTEXBATCH:this._shaderValues.setMatrix4x4(Ce.WORLDMATRIX,R.DEFAULT);break;case Ke.RENDERTYPE_INSTANCEBATCH:for(var a=Xt.instance.instanceWorldMatrixData,n=i.instanceBatchElementList,s=n.elements,o=n.length,l=0;l<o;l++)a.set(s[l]._transform.worldMatrix.elements,16*l);var _=Xt.instance.instanceWorldMatrixBuffer;_.orphanStorage(),_.setData(a.buffer,0,0,16*o*4),this._shaderValues.addDefine(Ar.SHADERDEFINE_GPU_INSTANCE)}this._probReflection&&(this._reflectionMode==e.ReflectionProbeMode.off?(this._shaderValues.removeDefine(Ar.SHADERDEFINE_SPECCUBE_BOX_PROJECTION),this._shaderValues.setVector(kt.REFLECTIONCUBE_HDR_PARAMS,Qt.defaultTextureHDRDecodeValues),this._shaderValues.setTexture(kt.REFLECTIONTEXTURE,bt.blackTexture)):(this._probReflection.boxProjection?(this._shaderValues.addDefine(Ar.SHADERDEFINE_SPECCUBE_BOX_PROJECTION),this._shaderValues.setVector3(kt.REFLECTIONCUBE_PROBEPOSITION,this._probReflection.probePosition),this._shaderValues.setVector3(kt.REFLECTIONCUBE_PROBEBOXMAX,this._probReflection.boundsMax),this._shaderValues.setVector3(kt.REFLECTIONCUBE_PROBEBOXMIN,this._probReflection.boundsMin)):this._shaderValues.removeDefine(Ar.SHADERDEFINE_SPECCUBE_BOX_PROJECTION),this._shaderValues.setTexture(kt.REFLECTIONTEXTURE,this._probReflection.reflectionTexture),this._shaderValues.setVector(kt.REFLECTIONCUBE_HDR_PARAMS,this._probReflection.reflectionHDRParams)))}_renderUpdateWithCamera(e,t){var r=e.projectionViewMatrix;if(r){var i=e.renderElement;switch(i.renderType){case Ke.RENDERTYPE_NORMAL:case Ke.RENDERTYPE_STATICBATCH:case Ke.RENDERTYPE_VERTEXBATCH:t?(R.multiply(r,t.worldMatrix,this._projectionViewWorldMatrix),this._shaderValues.setMatrix4x4(Ce.MVPMATRIX,this._projectionViewWorldMatrix)):this._shaderValues.setMatrix4x4(Ce.MVPMATRIX,r);break;case Ke.RENDERTYPE_INSTANCEBATCH:for(var a=Xt.instance.instanceMVPMatrixData,n=i.instanceBatchElementList,s=n.elements,o=n.length,l=0;l<o;l++){var _=s[l]._transform.worldMatrix;H.mulMatrixByArray(r.elements,0,_.elements,0,a,16*l)}var h=Xt.instance.instanceMVPMatrixBuffer;h.orphanStorage(),h.setData(a.buffer,0,0,16*o*4)}}}_revertBatchRenderUpdate(e){switch(e.renderElement.renderType){case Ke.RENDERTYPE_STATICBATCH:this._revertStaticBatchDefineUV1&&this._shaderValues.removeDefine(Ar.SHADERDEFINE_UV1),this._shaderValues.setVector(kt.LIGHTMAPSCALEOFFSET,this.lightmapScaleOffset);break;case Ke.RENDERTYPE_INSTANCEBATCH:this._shaderValues.removeDefine(Ar.SHADERDEFINE_GPU_INSTANCE)}}_destroy(){this._isPartOfStaticBatch&&qt.instance._removeRenderSprite(this._owner),super._destroy()}}class Mr{constructor(e){this._owner=e}get sharedMesh(){return this._sharedMesh}set sharedMesh(e){if(this._sharedMesh!==e){var t=this._owner._render._shaderValues,r=this._sharedMesh;if(r){r._removeReference(),this._getMeshDefine(r,Mr._meshVerticeDefine);for(var i=0,a=Mr._meshVerticeDefine.length;i<a;i++)t.removeDefine(Mr._meshVerticeDefine[i])}if(e){e._addReference(),this._getMeshDefine(e,Mr._meshVerticeDefine);for(i=0,a=Mr._meshVerticeDefine.length;i<a;i++)t.addDefine(Mr._meshVerticeDefine[i])}this._owner._render._onMeshChange(e),this._sharedMesh=e}}_getMeshDefine(e,t){t.length=0;for(var r=0,i=e._subMeshes.length;r<i;r++)for(var a=e.getSubMesh(r)._vertexBuffer._vertexDeclaration._vertexElements,n=0,s=a.length;n<s;n++){switch(a[n]._elementUsage){case ze.MESH_COLOR0:t.push(Ar.SHADERDEFINE_COLOR);break;case ze.MESH_TEXTURECOORDINATE0:t.push(Ar.SHADERDEFINE_UV0);break;case ze.MESH_TEXTURECOORDINATE1:t.push(Ar.SHADERDEFINE_UV1)}}}destroy(){this._owner=null,this._sharedMesh&&(this._sharedMesh._removeReference(),this._sharedMesh=null)}}Mr._meshVerticeDefine=[];class Dr extends Gt{constructor(){super(),this._bufferState=new Ee;var r=t.LayaGL.instance,i=ze.getVertexDeclaration("POSITION,NORMAL,COLOR,UV,UV1,TANGENT").vertexStride*Dr.maxIndicesCount;this._vertices=new Float32Array(i/4),this._vertexBuffer=new de(i,r.DYNAMIC_DRAW),this._indices=new Int16Array(Dr.maxIndicesCount),this._indexBuffer=new Ge(e.IndexFormat.UInt16,this._indices.length,r.DYNAMIC_DRAW);var a=this._vertexBuffer._byteLength+this._indexBuffer._byteLength;t.Resource._addMemory(a,a)}static __init__(){Dr.instance=new Dr}_getBatchVertices(e,t,r,i,a,n){var s=e.vertexStride/4,o=n._vertexBuffer.getFloat32Data(),l=(a.render.lightmapScaleOffset,a._dynamicMultiSubMesh),_=a._dynamicVertexCount;a._computeWorldPositionsAndNormals(this._positionOffset,this._normalOffset,l,_);for(var h=a._dynamicWorldPositions,c=a._dynamicWorldNormals,d=n._indices,u=0;u<_;u++){var m=(l?d[u]:u)*s,f=(u+r)*s,T=3*u,E=f+this._positionOffset;t[E]=h[T],t[E+1]=h[T+1],t[E+2]=h[T+2],-1!==this._normalOffset&&(t[E=f+this._normalOffset]=c[T],t[E+1]=c[T+1],t[E+2]=c[T+2]),-1!==this._colorOffset&&(E=f+this._colorOffset,T=m+this._colorOffset,t[E]=o[T],t[E+1]=o[T+1],t[E+2]=o[T+2],t[E+3]=o[T+3]),-1!==this._uv0Offset&&(E=f+this._uv0Offset,T=m+this._uv0Offset,t[E]=o[T],t[E+1]=o[T+1]),-1!==this._sTangentOffset&&(E=f+this._sTangentOffset,T=m+this._sTangentOffset,t[E]=o[T],t[E+1]=o[T+1],t[E+2]=o[T+2],t[E+3]=o[T+3],E=f+this._sTangentOffset,T=m+this._sTangentOffset,t[E]=o[T],t[E+1]=o[T+1],t[E+2]=o[T+2],t[E+3]=o[T+3])}}_getBatchIndices(e,t,r,i,a,n){var s,o,l,_=a._indices,h=i._isFrontFaceInvert;if(n)if(h)for(s=0,o=_.length;s<o;s+=3){var c=r+s;e[l=t+s]=c,e[l+1]=c+2,e[l+2]=c+1}else for(s=0,o=_.length;s<o;s+=3)c=r+s,e[l=t+s]=c,e[l+1]=c+1,e[l+2]=c+2;else if(h)for(s=0,o=_.length;s<o;s+=3)e[l=t+s]=r+_[s],e[l+1]=r+_[s+2],e[l+2]=r+_[s+1];else for(s=0,o=_.length;s<o;s+=3)e[l=t+s]=r+_[s],e[l+1]=r+_[s+1],e[l+2]=r+_[s+2]}_flush(e,r){var i=t.LayaGL.instance;this._vertexBuffer.setData(this._vertices.buffer,0,0,e*this._bufferState.vertexDeclaration.vertexStride),this._indexBuffer.setData(this._indices,0,0,r),i.drawElements(i.TRIANGLES,r,i.UNSIGNED_SHORT,0)}_prepareRender(e){var t=e.renderElement.vertexBatchVertexDeclaration;this._bufferState=g.MeshRenderDynamicBatchManager.instance._getBufferState(t),this._positionOffset=t.getVertexElementByUsage(ze.MESH_POSITION0)._offset/4;var r=t.getVertexElementByUsage(ze.MESH_NORMAL0);this._normalOffset=r?r._offset/4:-1;var i=t.getVertexElementByUsage(ze.MESH_COLOR0);this._colorOffset=i?i._offset/4:-1;var a=t.getVertexElementByUsage(ze.MESH_TEXTURECOORDINATE0);this._uv0Offset=a?a._offset/4:-1;var n=t.getVertexElementByUsage(ze.MESH_TEXTURECOORDINATE1);this._uv1Offset=n?n._offset/4:-1;var s=t.getVertexElementByUsage(ze.MESH_TANGENT0);return this._sTangentOffset=s?s._offset/4:-1,!0}_render(e){this._bufferState.bind();for(var r=e.renderElement,i=r.vertexBatchVertexDeclaration,a=r.vertexBatchElementList,n=0,s=0,o=(i.vertexStride,0),l=a.length,_=a.elements,h=0;h<l;h++){var c=_[h],d=c._geometry,u=d._indexCount;s+u>Dr.maxIndicesCount&&(this._flush(n,s),o++,t.Stat.trianglesFaces+=s/3,n=s=0);var m=c._transform;this._getBatchVertices(i,this._vertices,n,m,c,d),this._getBatchIndices(this._indices,s,n,m,d,c._dynamicMultiSubMesh),n+=c._dynamicVertexCount,s+=u}this._flush(n,s),o++,t.Stat.renderBatches+=o,t.Stat.savedRenderBatches+=l-o,t.Stat.trianglesFaces+=s/3}}Dr.maxAllowVertexCount=10,Dr.maxAllowAttribueCount=900,Dr.maxIndicesCount=32e3;class Cr extends _r{constructor(){super(),this._instanceBatchOpaqueMarks=[],this._vertexBatchOpaqueMarks=[],this._cacheBufferStates=[],this._updateCountMark=0}getInstanceBatchOpaquaMark(e,t,r,i){var a=this._instanceBatchOpaqueMarks[e?0:1]||(this._instanceBatchOpaqueMarks[e?0:1]=[]),n=a[t]||(a[t]=[]),s=n[r]||(n[r]=[]);return s[i?1:0]||(s[i?1:0]=new Wt)}getVertexBatchOpaquaMark(e,t,r,i){var a=this._vertexBatchOpaqueMarks[e]||(this._vertexBatchOpaqueMarks[e]=[]),n=a[t?0:1]||(a[t?0:1]=[]),s=n[r]||(n[r]=[]);return s[i]||(s[i]=new Wt)}_getBufferState(e){var t=this._cacheBufferStates[e.id];if(!t){var r=Dr.instance;(t=new Ee).bind();var i=r._vertexBuffer;i.vertexDeclaration=e,t.applyVertexBuffer(i),t.applyIndexBuffer(r._indexBuffer),t.unBind(),this._cacheBufferStates[e.id]=t}return t}_getBatchRenderElementFromPool(){var e=this._batchRenderElementPool[this._batchRenderElementPoolIndex++];return e||(e=new Yt,this._batchRenderElementPool[this._batchRenderElementPoolIndex-1]=e,e.vertexBatchElementList=new b,e.instanceBatchElementList=new b),e}_clear(){super._clear(),this._updateCountMark++}}Cr.instance=new Cr;class yr extends kt{constructor(e=null,t=null){super(t),this._meshFilter=new Mr(this),this._render=new Ir(this),e&&(this._meshFilter.sharedMesh=e)}static __init__(){Ar.SHADERDEFINE_UV0=xe.getDefineByName("UV"),Ar.SHADERDEFINE_COLOR=xe.getDefineByName("COLOR"),Ar.SHADERDEFINE_UV1=xe.getDefineByName("UV1"),Ar.SHADERDEFINE_GPU_INSTANCE=xe.getDefineByName("GPU_INSTANCE"),Ar.SHADERDEFINE_SPECCUBE_BOX_PROJECTION=xe.getDefineByName("SPECCUBE_BOX_PROJECTION"),jt._registerManager(qt.instance),_r._registerManager(Cr.instance)}get meshFilter(){return this._meshFilter}get meshRenderer(){return this._render}_parse(e,r){super._parse(e,r);var i=this.meshRenderer,n=e.lightmapIndex;null!=n&&(i.lightmapIndex=n);var s=e.lightmapScaleOffset;s&&(i.lightmapScaleOffset=new a(s[0],s[1],s[2],s[3])),null!=e.meshPath&&(this.meshFilter.sharedMesh=t.Loader.getRes(e.meshPath)),null!=e.enableRender&&(i.enable=e.enableRender),null!=e.receiveShadows&&(i.receiveShadow=e.receiveShadows),null!=e.castShadow&&(i.castShadow=e.castShadow);var o=e.materials;if(o){var l=i.sharedMaterials,_=o.length;l.length=_;for(var h=0;h<_;h++)l[h]=t.Loader.getRes(o[h].path);i.sharedMaterials=l}}_addToInitStaticBatchManager(){this.meshFilter.sharedMesh&&qt.instance._addBatchSprite(this)}_cloneTo(e,t,r){var i=e;i._meshFilter.sharedMesh=this._meshFilter.sharedMesh;var a=this._render,n=i._render;n.enable=a.enable,n.sharedMaterials=a.sharedMaterials,n.castShadow=a.castShadow;var s=a.lightmapScaleOffset;s&&(n.lightmapScaleOffset=s.clone()),n.lightmapIndex=a.lightmapIndex,n.receiveShadow=a.receiveShadow,n.sortingFudge=a.sortingFudge,super._cloneTo(e,t,r)}destroy(e=!0){this.destroyed||(super.destroy(e),this._meshFilter.destroy())}_create(){return new yr}}class Lr{}Lr.Blend=0,Lr.Fixed=1;class Or{constructor(e,t){this._mode=0,this._maxColorRGBKeysCount=0,this._maxColorAlphaKeysCount=0,this._colorRGBKeysCount=0,this._colorAlphaKeysCount=0,this._alphaElements=null,this._rgbElements=null,this._maxColorRGBKeysCount=e,this._maxColorAlphaKeysCount=t,this._rgbElements=new Float32Array(4*e),this._alphaElements=new Float32Array(2*t)}get mode(){return this._mode}set mode(e){this._mode=e}get colorRGBKeysCount(){return this._colorRGBKeysCount}get colorAlphaKeysCount(){return this._colorAlphaKeysCount}get maxColorRGBKeysCount(){return this._maxColorRGBKeysCount}get maxColorAlphaKeysCount(){return this._maxColorAlphaKeysCount}addColorRGB(e,t){if(this._colorRGBKeysCount<this._maxColorRGBKeysCount){var r=4*this._colorRGBKeysCount;this._rgbElements[r]=e,this._rgbElements[r+1]=t.r,this._rgbElements[r+2]=t.g,this._rgbElements[r+3]=t.b,this._colorRGBKeysCount++}else console.warn("Gradient:warning:data count must lessEqual than "+this._maxColorRGBKeysCount)}addColorAlpha(e,t){if(this._colorAlphaKeysCount<this._maxColorAlphaKeysCount){var r=2*this._colorAlphaKeysCount;this._alphaElements[r]=e,this._alphaElements[r+1]=t,this._colorAlphaKeysCount++}else console.warn("Gradient:warning:data count must lessEqual than "+this._maxColorAlphaKeysCount)}updateColorRGB(e,t,r){if(e<this._colorRGBKeysCount){var i=4*e;this._rgbElements[i]=t,this._rgbElements[i+1]=r.r,this._rgbElements[i+2]=r.g,this._rgbElements[i+3]=r.b}else console.warn("Gradient:warning:index must lessEqual than colorRGBKeysCount:"+this._colorRGBKeysCount)}updateColorAlpha(e,t,r){if(e<this._colorAlphaKeysCount){var i=2*e;this._alphaElements[i]=t,this._alphaElements[i+1]=r}else console.warn("Gradient:warning:index must lessEqual than colorAlphaKeysCount:"+this._colorAlphaKeysCount)}evaluateColorRGB(e,t,r=0,i=!1){e=Math.min(Math.max(e,0),1);var a=this._rgbElements,n=r;if(i)for(var s=n;s>=0;s--){var o=4*s;if(e===(u=a[o]))return t.r=a[o+1],t.g=a[o+2],t.b=a[o+3],n;switch(this._mode){case Lr.Blend:if(e>u){if(e>(d=a[o+4]))throw"Gradient:wrong startSearchIndex.";var l=d-u,_=d-e,h=e-u;return t.r=(_*a[o+1]+h*a[o+5])/l,t.g=(_*a[o+2]+h*a[o+6])/l,t.b=(_*a[o+3]+h*a[o+7])/l,n}n--;continue;case Lr.Fixed:if(e>u){if(e>a[o+4])throw"Gradient:wrong startSearchIndex.";return t.r=a[o+5],t.g=a[o+6],t.b=a[o+7],n}n--;continue;default:throw"Gradient:unknown mode."}}else{s=0;for(var c=this._rgbElements.length;s<c;s++){var d;if(e===(d=a[o=4*s]))return t.r=a[o+1],t.g=a[o+2],t.b=a[o+3],n;switch(this._mode){case Lr.Blend:if(e<d){var u;if(e<(u=a[o-4]))throw"Gradient:wrong startSearchIndex.";l=d-u,_=d-e,h=e-u;return t.r=(_*a[o-3]+h*a[o+1])/l,t.g=(_*a[o-2]+h*a[o+2])/l,t.b=(_*a[o-1]+h*a[o+3])/l,n}n++;continue;case Lr.Fixed:if(e<d){if(e<a[o-4])throw"Gradient:wrong startSearchIndex.";return t.r=a[o+1],t.g=a[o+2],t.b=a[o+3],n}n++;continue;default:throw"Gradient:unknown mode."}}}return n}evaluateColorAlpha(e,t,r=0,i=!1){e=Math.min(Math.max(e,0),1);var a=this._alphaElements,n=r;if(i)for(var s=n;s>=0;s--){if(e===(u=a[c=2*s]))return t.a=a[c+1],n;switch(this._mode){case Lr.Blend:if(e>u){if(e>(d=a[c+2]))throw"Gradient:wrong startSearchIndex.";var o=d-u,l=d-e,_=e-u;return t.a=(l*a[c+1]+_*a[c+3])/o,n}n--;continue;case Lr.Fixed:if(e>u){if(e>a[c+2])throw"Gradient:wrong startSearchIndex.";return t.a=a[c+3],n}n--;continue;default:throw"Gradient:unknown mode."}}else{s=n;for(var h=this._alphaElements.length;s<h;s++){var c,d;if(e===(d=a[c=2*s]))return t.a=a[c+1],n;switch(this._mode){case Lr.Blend:if(e<d){var u;if(e<(u=a[c-2]))throw"Gradient:wrong startSearchIndex.";o=d-u,l=d-e,_=e-u;return t.a=(l*a[c-1]+_*a[c+1])/o,n}n++;continue;case Lr.Fixed:if(e<d){if(e<a[c-2])throw"Gradient:wrong startSearchIndex.";return t.a=a[c+1],n}n++;continue;default:throw"Gradient:unknown mode."}}}return n}cloneTo(e){var t,r,i=e;i._colorAlphaKeysCount=this._colorAlphaKeysCount;var a=i._alphaElements;for(t=0,r=this._alphaElements.length;t<r;t++)a[t]=this._alphaElements[t];i._colorRGBKeysCount=this._colorRGBKeysCount;var n=i._rgbElements;for(t=0,r=this._rgbElements.length;t<r;t++)n[t]=this._rgbElements[t]}clone(){var e=new Or(this._maxColorRGBKeysCount,this._maxColorAlphaKeysCount);return this.cloneTo(e),e}}class Nr{constructor(e,t,r){this._time=e,this._minCount=t,this._maxCount=r}get time(){return this._time}get minCount(){return this._minCount}get maxCount(){return this._maxCount}cloneTo(e){var t=e;t._time=this._time,t._minCount=this._minCount,t._maxCount=this._maxCount}clone(){var e=new Nr(this._time,this._minCount,this._maxCount);return this.cloneTo(e),e}}class Pr{constructor(){this._type=0,this._constant=null,this._constantMin=null,this._constantMax=null,this._gradient=null,this._gradientMin=null,this._gradientMax=null}static createByConstant(e){var t=new Pr;return t._type=0,t._constant=e,t}static createByGradient(e){var t=new Pr;return t._type=1,t._gradient=e,t}static createByRandomTwoConstant(e,t){var r=new Pr;return r._type=2,r._constantMin=e,r._constantMax=t,r}static createByRandomTwoGradient(e,t){var r=new Pr;return r._type=3,r._gradientMin=e,r._gradientMax=t,r}get type(){return this._type}get constant(){return this._constant}get constantMin(){return this._constantMin}get constantMax(){return this._constantMax}get gradient(){return this._gradient}get gradientMin(){return this._gradientMin}get gradientMax(){return this._gradientMax}cloneTo(e){var t=e;t._type=this._type,this._constant.cloneTo(t._constant),this._constantMin.cloneTo(t._constantMin),this._constantMax.cloneTo(t._constantMax),this._gradient.cloneTo(t._gradient),this._gradientMin.cloneTo(t._gradientMin),this._gradientMax.cloneTo(t._gradientMax)}clone(){var e=new Pr;return this.cloneTo(e),e}}class br{constructor(e){this._color=e}get color(){return this._color}cloneTo(e){var t=e;this._color.cloneTo(t._color),t.enable=this.enable}clone(){var e;switch(this._color.type){case 0:e=Pr.createByConstant(this._color.constant.clone());break;case 1:e=Pr.createByGradient(this._color.gradient.clone());break;case 2:e=Pr.createByRandomTwoConstant(this._color.constantMin.clone(),this._color.constantMax.clone());break;case 3:e=Pr.createByRandomTwoGradient(this._color.gradientMin.clone(),this._color.gradientMax.clone())}var t=new br(e);return t.enable=this.enable,t}}class wr{constructor(){this._type=0,this._constant=0,this._overTime=null,this._constantMin=0,this._constantMax=0,this._overTimeMin=null,this._overTimeMax=null}static createByConstant(e=0){var t=new wr;return t._type=0,t._constant=e,t}static createByOverTime(e){var t=new wr;return t._type=1,t._overTime=e,t}static createByRandomTwoConstant(e=0,t=0){var r=new wr;return r._type=2,r._constantMin=e,r._constantMax=t,r}static createByRandomTwoOverTime(e,t){var r=new wr;return r._type=3,r._overTimeMin=e,r._overTimeMax=t,r}get type(){return this._type}get constant(){return this._constant}get frameOverTimeData(){return this._overTime}get constantMin(){return this._constantMin}get constantMax(){return this._constantMax}get frameOverTimeDataMin(){return this._overTimeMin}get frameOverTimeDataMax(){return this._overTimeMax}cloneTo(e){var t=e;t._type=this._type,t._constant=this._constant,this._overTime&&this._overTime.cloneTo(t._overTime),t._constantMin=this._constantMin,t._constantMax=this._constantMax,this._overTimeMin&&this._overTimeMin.cloneTo(t._overTimeMin),this._overTimeMax&&this._overTimeMax.cloneTo(t._overTimeMax)}clone(){var e=new wr;return this.cloneTo(e),e}}class Vr{constructor(){this._type=0,this._separateAxes=!1,this._constant=0,this._constantSeparate=null,this._gradient=null,this._gradientX=null,this._gradientY=null,this._gradientZ=null,this._gradientW=null,this._constantMin=0,this._constantMax=0,this._constantMinSeparate=null,this._constantMaxSeparate=null,this._gradientMin=null,this._gradientMax=null,this._gradientXMin=null,this._gradientXMax=null,this._gradientYMin=null,this._gradientYMax=null,this._gradientZMin=null,this._gradientZMax=null,this._gradientWMin=null,this._gradientWMax=null}static createByConstant(e){var t=new Vr;return t._type=0,t._separateAxes=!1,t._constant=e,t}static createByConstantSeparate(e){var t=new Vr;return t._type=0,t._separateAxes=!0,t._constantSeparate=e,t}static createByGradient(e){var t=new Vr;return t._type=1,t._separateAxes=!1,t._gradient=e,t}static createByGradientSeparate(e,t,r){var i=new Vr;return i._type=1,i._separateAxes=!0,i._gradientX=e,i._gradientY=t,i._gradientZ=r,i}static createByRandomTwoConstant(e,t){var r=new Vr;return r._type=2,r._separateAxes=!1,r._constantMin=e,r._constantMax=t,r}static createByRandomTwoConstantSeparate(e,t){var r=new Vr;return r._type=2,r._separateAxes=!0,r._constantMinSeparate=e,r._constantMaxSeparate=t,r}static createByRandomTwoGradient(e,t){var r=new Vr;return r._type=3,r._separateAxes=!1,r._gradientMin=e,r._gradientMax=t,r}static createByRandomTwoGradientSeparate(e,t,r,i,a,n,s,o){var l=new Vr;return l._type=3,l._separateAxes=!0,l._gradientXMin=e,l._gradientXMax=t,l._gradientYMin=r,l._gradientYMax=i,l._gradientZMin=a,l._gradientZMax=n,l._gradientWMin=s,l._gradientWMax=o,l}get type(){return this._type}get separateAxes(){return this._separateAxes}get constant(){return this._constant}get constantSeparate(){return this._constantSeparate}get gradient(){return this._gradient}get gradientX(){return this._gradientX}get gradientY(){return this._gradientY}get gradientZ(){return this._gradientZ}get gradientW(){return this._gradientW}get constantMin(){return this._constantMin}get constantMax(){return this._constantMax}get constantMinSeparate(){return this._constantMinSeparate}get constantMaxSeparate(){return this._constantMaxSeparate}get gradientMin(){return this._gradientMin}get gradientMax(){return this._gradientMax}get gradientXMin(){return this._gradientXMin}get gradientXMax(){return this._gradientXMax}get gradientYMin(){return this._gradientYMin}get gradientYMax(){return this._gradientYMax}get gradientZMin(){return this._gradientZMin}get gradientZMax(){return this._gradientZMax}get gradientWMin(){return this._gradientWMin}get gradientWMax(){return this._gradientWMax}cloneTo(e){var t=e;t._type=this._type,t._separateAxes=this._separateAxes,t._constant=this._constant,this._constantSeparate.cloneTo(t._constantSeparate),this._gradient.cloneTo(t._gradient),this._gradientX.cloneTo(t._gradientX),this._gradientY.cloneTo(t._gradientY),this._gradientZ.cloneTo(t._gradientZ),t._constantMin=this._constantMin,t._constantMax=this._constantMax,this._constantMinSeparate.cloneTo(t._constantMinSeparate),this._constantMaxSeparate.cloneTo(t._constantMaxSeparate),this._gradientMin.cloneTo(t._gradientMin),this._gradientMax.cloneTo(t._gradientMax),this._gradientXMin.cloneTo(t._gradientXMin),this._gradientXMax.cloneTo(t._gradientXMax),this._gradientYMin.cloneTo(t._gradientYMin),this._gradientYMax.cloneTo(t._gradientYMax),this._gradientZMin.cloneTo(t._gradientZMin),this._gradientZMax.cloneTo(t._gradientZMax)}clone(){var e=new Vr;return this.cloneTo(e),e}}class Br{constructor(){this._currentLength=0,this._elements=new Float32Array(8)}get gradientCount(){return this._currentLength/2}add(e,t){this._currentLength<8?(6===this._currentLength&&1!==e&&(e=1,console.log("Warning:the forth key is be force set to 1.")),this._elements[this._currentLength++]=e,this._elements[this._currentLength++]=t):console.log("Warning:data count must lessEqual than 4")}cloneTo(e){var t=e;t._currentLength=this._currentLength;for(var r=t._elements,i=0,a=this._elements.length;i<a;i++)r[i]=this._elements[i]}clone(){var e=new Br;return this.cloneTo(e),e}}class Fr{constructor(){this._currentLength=0,this._elements=new Float32Array(8)}get gradientCount(){return this._currentLength/2}add(e,t){this._currentLength<8?(6===this._currentLength&&1!==e&&(e=1,console.log("GradientDataNumber warning:the forth key is be force set to 1.")),this._elements[this._currentLength++]=e,this._elements[this._currentLength++]=t):console.log("GradientDataNumber warning:data count must lessEqual than 4")}getKeyByIndex(e){return this._elements[2*e]}getValueByIndex(e){return this._elements[2*e+1]}getAverageValue(){for(var e=0,t=0,r=0,i=this._currentLength-2;r<i;r+=2){var a=this._elements[r+1];a+=this._elements[r+3],e+=a*=this._elements[r+2]-this._elements[r],t++}return e/t}cloneTo(e){var t=e;t._currentLength=this._currentLength;for(var r=t._elements,i=0,a=this._elements.length;i<a;i++)r[i]=this._elements[i]}clone(){var e=new Fr;return this.cloneTo(e),e}}class Ur{constructor(){this._type=0,this._separateAxes=!1,this._gradient=null,this._gradientX=null,this._gradientY=null,this._gradientZ=null,this._constantMin=0,this._constantMax=0,this._constantMinSeparate=null,this._constantMaxSeparate=null,this._gradientMin=null,this._gradientMax=null,this._gradientXMin=null,this._gradientXMax=null,this._gradientYMin=null,this._gradientYMax=null,this._gradientZMin=null,this._gradientZMax=null}static createByGradient(e){var t=new Ur;return t._type=0,t._separateAxes=!1,t._gradient=e,t}static createByGradientSeparate(e,t,r){var i=new Ur;return i._type=0,i._separateAxes=!0,i._gradientX=e,i._gradientY=t,i._gradientZ=r,i}static createByRandomTwoConstant(e,t){var r=new Ur;return r._type=1,r._separateAxes=!1,r._constantMin=e,r._constantMax=t,r}static createByRandomTwoConstantSeparate(e,t){var r=new Ur;return r._type=1,r._separateAxes=!0,r._constantMinSeparate=e,r._constantMaxSeparate=t,r}static createByRandomTwoGradient(e,t){var r=new Ur;return r._type=2,r._separateAxes=!1,r._gradientMin=e,r._gradientMax=t,r}static createByRandomTwoGradientSeparate(e,t,r,i,a,n){var s=new Ur;return s._type=2,s._separateAxes=!0,s._gradientXMin=e,s._gradientXMax=t,s._gradientYMin=r,s._gradientYMax=i,s._gradientZMin=a,s._gradientZMax=n,s}get type(){return this._type}get separateAxes(){return this._separateAxes}get gradient(){return this._gradient}get gradientX(){return this._gradientX}get gradientY(){return this._gradientY}get gradientZ(){return this._gradientZ}get constantMin(){return this._constantMin}get constantMax(){return this._constantMax}get constantMinSeparate(){return this._constantMinSeparate}get constantMaxSeparate(){return this._constantMaxSeparate}get gradientMin(){return this._gradientMin}get gradientMax(){return this._gradientMax}get gradientXMin(){return this._gradientXMin}get gradientXMax(){return this._gradientXMax}get gradientYMin(){return this._gradientYMin}get gradientYMax(){return this._gradientYMax}get gradientZMin(){return this._gradientZMin}get gradientZMax(){return this._gradientZMax}getMaxSizeInGradient(e=!1){var t,r,i=-Number.MAX_VALUE;switch(this._type){case 0:if(this._separateAxes){for(t=0,r=this._gradientX.gradientCount;t<r;t++)i=Math.max(i,this._gradientX.getValueByIndex(t));for(t=0,r=this._gradientY.gradientCount;t<r;t++)i=Math.max(i,this._gradientY.getValueByIndex(t));if(e)for(t=0,r=this._gradientZ.gradientCount;t<r;t++)i=Math.max(i,this._gradientZ.getValueByIndex(t))}else for(t=0,r=this._gradient.gradientCount;t<r;t++)i=Math.max(i,this._gradient.getValueByIndex(t));break;case 1:this._separateAxes?(i=Math.max(this._constantMinSeparate.x,this._constantMaxSeparate.x),i=Math.max(i,this._constantMinSeparate.y),e&&(i=i=Math.max(i,this._constantMaxSeparate.z))):i=Math.max(this._constantMin,this._constantMax);break;case 2:if(this._separateAxes){for(t=0,r=this._gradientXMin.gradientCount;t<r;t++)i=Math.max(i,this._gradientXMin.getValueByIndex(t));for(t=0,r=this._gradientXMax.gradientCount;t<r;t++)i=Math.max(i,this._gradientXMax.getValueByIndex(t));for(t=0,r=this._gradientYMin.gradientCount;t<r;t++)i=Math.max(i,this._gradientYMin.getValueByIndex(t));for(t=0,r=this._gradientZMax.gradientCount;t<r;t++)i=Math.max(i,this._gradientZMax.getValueByIndex(t));if(e){for(t=0,r=this._gradientZMin.gradientCount;t<r;t++)i=Math.max(i,this._gradientZMin.getValueByIndex(t));for(t=0,r=this._gradientZMax.gradientCount;t<r;t++)i=Math.max(i,this._gradientZMax.getValueByIndex(t))}}else{for(t=0,r=this._gradientMin.gradientCount;t<r;t++)i=Math.max(i,this._gradientMin.getValueByIndex(t));for(t=0,r=this._gradientMax.gradientCount;t<r;t++)i=Math.max(i,this._gradientMax.getValueByIndex(t))}}return i}cloneTo(e){var t=e;t._type=this._type,t._separateAxes=this._separateAxes,this._gradient.cloneTo(t._gradient),this._gradientX.cloneTo(t._gradientX),this._gradientY.cloneTo(t._gradientY),this._gradientZ.cloneTo(t._gradientZ),t._constantMin=this._constantMin,t._constantMax=this._constantMax,this._constantMinSeparate.cloneTo(t._constantMinSeparate),this._constantMaxSeparate.cloneTo(t._constantMaxSeparate),this._gradientMin.cloneTo(t._gradientMin),this._gradientMax.cloneTo(t._gradientMax),this._gradientXMin.cloneTo(t._gradientXMin),this._gradientXMax.cloneTo(t._gradientXMax),this._gradientYMin.cloneTo(t._gradientYMin),this._gradientYMax.cloneTo(t._gradientYMax),this._gradientZMin.cloneTo(t._gradientZMin),this._gradientZMax.cloneTo(t._gradientZMax)}clone(){var e=new Ur;return this.cloneTo(e),e}}class Gr{constructor(){this._type=0,this._constant=null,this._gradientX=null,this._gradientY=null,this._gradientZ=null,this._constantMin=null,this._constantMax=null,this._gradientXMin=null,this._gradientXMax=null,this._gradientYMin=null,this._gradientYMax=null,this._gradientZMin=null,this._gradientZMax=null}static createByConstant(e){var t=new Gr;return t._type=0,t._constant=e,t}static createByGradient(e,t,r){var i=new Gr;return i._type=1,i._gradientX=e,i._gradientY=t,i._gradientZ=r,i}static createByRandomTwoConstant(e,t){var r=new Gr;return r._type=2,r._constantMin=e,r._constantMax=t,r}static createByRandomTwoGradient(e,t,r,i,a,n){var s=new Gr;return s._type=3,s._gradientXMin=e,s._gradientXMax=t,s._gradientYMin=r,s._gradientYMax=i,s._gradientZMin=a,s._gradientZMax=n,s}get type(){return this._type}get constant(){return this._constant}get gradientX(){return this._gradientX}get gradientY(){return this._gradientY}get gradientZ(){return this._gradientZ}get constantMin(){return this._constantMin}get constantMax(){return this._constantMax}get gradientXMin(){return this._gradientXMin}get gradientXMax(){return this._gradientXMax}get gradientYMin(){return this._gradientYMin}get gradientYMax(){return this._gradientYMax}get gradientZMin(){return this._gradientZMin}get gradientZMax(){return this._gradientZMax}cloneTo(e){var t=e;t._type=this._type,this._constant.cloneTo(t._constant),this._gradientX.cloneTo(t._gradientX),this._gradientY.cloneTo(t._gradientY),this._gradientZ.cloneTo(t._gradientZ),this._constantMin.cloneTo(t._constantMin),this._constantMax.cloneTo(t._constantMax),this._gradientXMin.cloneTo(t._gradientXMin),this._gradientXMax.cloneTo(t._gradientXMax),this._gradientYMin.cloneTo(t._gradientYMin),this._gradientYMax.cloneTo(t._gradientYMax),this._gradientZMin.cloneTo(t._gradientZMin),this._gradientZMax.cloneTo(t._gradientZMax)}clone(){var e=new Gr;return this.cloneTo(e),e}}class zr{constructor(e){this._angularVelocity=e}get angularVelocity(){return this._angularVelocity}cloneTo(e){var t=e;this._angularVelocity.cloneTo(t._angularVelocity),t.enable=this.enable}clone(){var e;switch(this._angularVelocity.type){case 0:e=this._angularVelocity.separateAxes?Vr.createByConstantSeparate(this._angularVelocity.constantSeparate.clone()):Vr.createByConstant(this._angularVelocity.constant);break;case 1:e=this._angularVelocity.separateAxes?Vr.createByGradientSeparate(this._angularVelocity.gradientX.clone(),this._angularVelocity.gradientY.clone(),this._angularVelocity.gradientZ.clone()):Vr.createByGradient(this._angularVelocity.gradient.clone());break;case 2:e=this._angularVelocity.separateAxes?Vr.createByRandomTwoConstantSeparate(this._angularVelocity.constantMinSeparate.clone(),this._angularVelocity.constantMaxSeparate.clone()):Vr.createByRandomTwoConstant(this._angularVelocity.constantMin,this._angularVelocity.constantMax);break;case 3:e=this._angularVelocity.separateAxes?Vr.createByRandomTwoGradientSeparate(this._angularVelocity.gradientXMin.clone(),this._angularVelocity.gradientYMin.clone(),this._angularVelocity.gradientZMin.clone(),this._angularVelocity.gradientWMin.clone(),this._angularVelocity.gradientXMax.clone(),this._angularVelocity.gradientYMax.clone(),this._angularVelocity.gradientZMax.clone(),this._angularVelocity.gradientWMax.clone()):Vr.createByRandomTwoGradient(this._angularVelocity.gradientMin.clone(),this._angularVelocity.gradientMax.clone())}var t=new zr(e);return t.enable=this.enable,t}}(Er=e.ParticleSystemShapeType||(e.ParticleSystemShapeType={}))[Er.Box=0]="Box",Er[Er.Circle=1]="Circle",Er[Er.Cone=2]="Cone",Er[Er.Hemisphere=3]="Hemisphere",Er[Er.Sphere=4]="Sphere";class Hr{constructor(){this.enable=!0,this.randomDirection=0}_getShapeBoundBox(e){throw new Error("BaseShape: must override it.")}_getSpeedBoundBox(e){throw new Error("BaseShape: must override it.")}generatePositionAndDirection(e,t,r=null,i=null){throw new Error("BaseShape: must override it.")}_calculateProceduralBounds(e,t,r){this._getShapeBoundBox(e);var i=e.min,a=e.max;n.multiply(i,t,i),n.multiply(a,t,a);var s=new Ft(new n,new n);this.randomDirection?(s.min=new n(-1,-1,-1),s.max=new n(1,1,1)):this._getSpeedBoundBox(s);var o=new Ft(new n,new n),l=o.min,_=o.max;n.scale(s.min,r.y,l),n.scale(s.max,r.y,_),n.add(e.min,l,l),n.add(e.max,_,_),n.min(e.min,l,e.min),n.max(e.max,l,e.max);var h=new Ft(new n,new n),c=h.min,d=h.max;n.scale(s.min,r.x,c),n.scale(s.max,r.x,d),n.min(h.min,d,l),n.max(h.min,d,_),n.min(e.min,l,e.min),n.max(e.max,l,e.max)}cloneTo(e){e.enable=this.enable}clone(){var e=new Hr;return this.cloneTo(e),e}}class kr{static _randomPointUnitArcCircle(e,t,r=null){var i;i=r?r.getFloat()*e:Math.random()*e,t.x=Math.cos(i),t.y=Math.sin(i)}static _randomPointInsideUnitArcCircle(e,t,r=null){var i;kr._randomPointUnitArcCircle(e,t,r),i=r?Math.pow(r.getFloat(),.5):Math.pow(Math.random(),.5),t.x=t.x*i,t.y=t.y*i}static _randomPointUnitCircle(e,t=null){var r;r=t?t.getFloat()*Math.PI*2:Math.random()*Math.PI*2,e.x=Math.cos(r),e.y=Math.sin(r)}static _randomPointInsideUnitCircle(e,t=null){var r;kr._randomPointUnitCircle(e),r=t?Math.pow(t.getFloat(),.5):Math.pow(Math.random(),.5),e.x=e.x*r,e.y=e.y*r}static _randomPointUnitSphere(e,t=null){var r,i;t?(r=e.z=2*t.getFloat()-1,i=t.getFloat()*Math.PI*2):(r=e.z=2*Math.random()-1,i=Math.random()*Math.PI*2);var a=Math.sqrt(1-r*r);e.x=a*Math.cos(i),e.y=a*Math.sin(i)}static _randomPointInsideUnitSphere(e,t=null){var r;kr._randomPointUnitSphere(e),r=t?Math.pow(t.getFloat(),1/3):Math.pow(Math.random(),1/3),e.x=e.x*r,e.y=e.y*r,e.z=e.z*r}static _randomPointInsideHalfUnitBox(e,t=null){t?(e.x=t.getFloat()-.5,e.y=t.getFloat()-.5,e.z=t.getFloat()-.5):(e.x=Math.random()-.5,e.y=Math.random()-.5,e.z=Math.random()-.5)}constructor(){}}class Wr extends Hr{constructor(){super(),this.shapeType=e.ParticleSystemShapeType.Box,this.x=1,this.y=1,this.z=1}_getShapeBoundBox(e){var t=e.min;t.x=.5*-this.x,t.y=.5*-this.y,t.z=.5*-this.z;var r=e.max;r.x=.5*this.x,r.y=.5*this.y,r.z=.5*this.z}_getSpeedBoundBox(e){var t=e.min;t.x=0,t.y=0,t.z=0;var r=e.max;r.x=0,r.y=1,r.z=0}generatePositionAndDirection(e,t,r=null,i=null){r?(r.seed=i[16],kr._randomPointInsideHalfUnitBox(e,r),i[16]=r.seed):kr._randomPointInsideHalfUnitBox(e),e.x=this.x*e.x,e.y=this.y*e.y,e.z=this.z*e.z,this.randomDirection?r?(r.seed=i[17],kr._randomPointUnitSphere(t,r),i[17]=r.seed):kr._randomPointUnitSphere(t):(t.x=0,t.y=0,t.z=1)}cloneTo(e){super.cloneTo(e);var t=e;t.x=this.x,t.y=this.y,t.z=this.z,t.randomDirection=this.randomDirection}clone(){var e=new Wr;return this.cloneTo(e),e}}class Xr extends Hr{constructor(){super(),this.shapeType=e.ParticleSystemShapeType.Circle,this.radius=1,this.arc=2*Math.PI,this.emitFromEdge=!1}_getShapeBoundBox(e){var t=e.min;t.x=t.z=-this.radius,t.y=0;var r=e.max;r.x=r.z=this.radius,r.y=0}_getSpeedBoundBox(e){var t=e.min;t.x=t.y=-1,t.z=0;var r=e.max;r.x=r.y=1,r.z=0}generatePositionAndDirection(e,t,r=null,i=null){var a=Xr._tempPositionPoint;r?(r.seed=i[16],this.emitFromEdge?kr._randomPointUnitArcCircle(this.arc,Xr._tempPositionPoint,r):kr._randomPointInsideUnitArcCircle(this.arc,Xr._tempPositionPoint,r),i[16]=r.seed):this.emitFromEdge?kr._randomPointUnitArcCircle(this.arc,Xr._tempPositionPoint):kr._randomPointInsideUnitArcCircle(this.arc,Xr._tempPositionPoint),e.x=-a.x,e.y=a.y,e.z=0,n.scale(e,this.radius,e),this.randomDirection?r?(r.seed=i[17],kr._randomPointUnitSphere(t,r),i[17]=r.seed):kr._randomPointUnitSphere(t):e.cloneTo(t)}cloneTo(e){super.cloneTo(e);var t=e;t.radius=this.radius,t.arc=this.arc,t.emitFromEdge=this.emitFromEdge,t.randomDirection=this.randomDirection}clone(){var e=new Xr;return this.cloneTo(e),e}}Xr._tempPositionPoint=new i;class Yr extends Hr{constructor(){super(),this.shapeType=e.ParticleSystemShapeType.Cone,this.angle=25/180*Math.PI,this.radius=1,this.length=5,this.emitType=0}_getShapeBoundBox(e){const t=this.radius+this.length*Math.sin(this.angle),r=this.length*Math.cos(this.angle);var i=e.min;i.x=i.y=-t,i.z=0;var a=e.max;a.x=a.y=t,a.z=r}_getSpeedBoundBox(e){const t=Math.sin(this.angle);var r=e.min;r.x=r.y=-t,r.z=0;var i=e.max;i.x=i.y=t,i.z=1}generatePositionAndDirection(e,t,r=null,i=null){var a,s,o,l=Yr._tempPositionPoint,_=Math.cos(this.angle),h=Math.sin(this.angle);switch(this.emitType){case 0:r?(r.seed=i[16],kr._randomPointInsideUnitCircle(Yr._tempPositionPoint,r),i[16]=r.seed):kr._randomPointInsideUnitCircle(Yr._tempPositionPoint),a=l.x,s=l.y,e.x=a*this.radius,e.y=s*this.radius,e.z=0,this.randomDirection?(r?(r.seed=i[17],kr._randomPointInsideUnitCircle(Yr._tempDirectionPoint,r),i[17]=r.seed):kr._randomPointInsideUnitCircle(Yr._tempDirectionPoint),o=Yr._tempDirectionPoint,t.x=o.x*h,t.y=o.y*h):(t.x=a*h,t.y=s*h),t.z=_;break;case 1:r?(r.seed=i[16],kr._randomPointUnitCircle(Yr._tempPositionPoint,r),i[16]=r.seed):kr._randomPointUnitCircle(Yr._tempPositionPoint),a=l.x,s=l.y,e.x=a*this.radius,e.y=s*this.radius,e.z=0,this.randomDirection?(r?(r.seed=i[17],kr._randomPointInsideUnitCircle(Yr._tempDirectionPoint,r),i[17]=r.seed):kr._randomPointInsideUnitCircle(Yr._tempDirectionPoint),o=Yr._tempDirectionPoint,t.x=o.x*h,t.y=o.y*h):(t.x=a*h,t.y=s*h),t.z=_;break;case 2:r?(r.seed=i[16],kr._randomPointInsideUnitCircle(Yr._tempPositionPoint,r)):kr._randomPointInsideUnitCircle(Yr._tempPositionPoint),a=l.x,s=l.y,e.x=a*this.radius,e.y=s*this.radius,e.z=0,t.x=a*h,t.y=s*h,t.z=_,n.normalize(t,t),r?(n.scale(t,this.length*r.getFloat(),t),i[16]=r.seed):n.scale(t,this.length*Math.random(),t),n.add(e,t,e),this.randomDirection&&(r?(r.seed=i[17],kr._randomPointUnitSphere(t,r),i[17]=r.seed):kr._randomPointUnitSphere(t));break;case 3:r?(r.seed=i[16],kr._randomPointUnitCircle(Yr._tempPositionPoint,r)):kr._randomPointUnitCircle(Yr._tempPositionPoint),a=l.x,s=l.y,e.x=a*this.radius,e.y=s*this.radius,e.z=0,t.x=a*h,t.y=s*h,t.z=_,n.normalize(t,t),r?(n.scale(t,this.length*r.getFloat(),t),i[16]=r.seed):n.scale(t,this.length*Math.random(),t),n.add(e,t,e),this.randomDirection&&(r?(r.seed=i[17],kr._randomPointUnitSphere(t,r),i[17]=r.seed):kr._randomPointUnitSphere(t));break;default:throw new Error("ConeShape:emitType is invalid.")}}cloneTo(e){super.cloneTo(e);var t=e;t.angle=this.angle,t.radius=this.radius,t.length=this.length,t.emitType=this.emitType,t.randomDirection=this.randomDirection}clone(){var e=new Yr;return this.cloneTo(e),e}}Yr._tempPositionPoint=new i,Yr._tempDirectionPoint=new i;class jr extends Hr{constructor(){super(),this.shapeType=e.ParticleSystemShapeType.Hemisphere,this.radius=1,this.emitFromShell=!1}_getShapeBoundBox(e){var t=e.min;t.x=t.y=t.z=-this.radius;var r=e.max;r.x=r.y=this.radius,r.z=0}_getSpeedBoundBox(e){var t=e.min;t.x=t.y=-1,t.z=0;var r=e.max;r.x=r.y=r.z=1}generatePositionAndDirection(e,t,r=null,i=null){r?(r.seed=i[16],this.emitFromShell?kr._randomPointUnitSphere(e,r):kr._randomPointInsideUnitSphere(e,r),i[16]=r.seed):this.emitFromShell?kr._randomPointUnitSphere(e):kr._randomPointInsideUnitSphere(e),n.scale(e,this.radius,e);var a=e.z;a<0&&(e.z=-1*a),this.randomDirection?r?(r.seed=i[17],kr._randomPointUnitSphere(t,r),i[17]=r.seed):kr._randomPointUnitSphere(t):e.cloneTo(t)}cloneTo(e){super.cloneTo(e);var t=e;t.radius=this.radius,t.emitFromShell=this.emitFromShell,t.randomDirection=this.randomDirection}clone(){var e=new jr;return this.cloneTo(e),e}}class Zr extends Hr{constructor(){super(),this.shapeType=e.ParticleSystemShapeType.Sphere,this.radius=1,this.emitFromShell=!1}_getShapeBoundBox(e){var t=e.min;t.x=t.y=t.z=-this.radius;var r=e.max;r.x=r.y=r.z=this.radius}_getSpeedBoundBox(e){var t=e.min;t.x=t.y=t.z=-1;var r=e.max;r.x=r.y=r.z=1}generatePositionAndDirection(e,t,r=null,i=null){r?(r.seed=i[16],this.emitFromShell?kr._randomPointUnitSphere(e,r):kr._randomPointInsideUnitSphere(e,r),i[16]=r.seed):this.emitFromShell?kr._randomPointUnitSphere(e):kr._randomPointInsideUnitSphere(e),n.scale(e,this.radius,e),this.randomDirection?r?(r.seed=i[17],kr._randomPointUnitSphere(t,r),i[17]=r.seed):kr._randomPointUnitSphere(t):e.cloneTo(t)}cloneTo(e){super.cloneTo(e);var t=e;t.radius=this.radius,t.emitFromShell=this.emitFromShell,t.randomDirection=this.randomDirection}clone(){var e=new Zr;return this.cloneTo(e),e}}class qr{constructor(e){this._size=e}get size(){return this._size}cloneTo(e){var t=e;this._size.cloneTo(t._size),t.enable=this.enable}clone(){var e;switch(this._size.type){case 0:e=this._size.separateAxes?Ur.createByGradientSeparate(this._size.gradientX.clone(),this._size.gradientY.clone(),this._size.gradientZ.clone()):Ur.createByGradient(this._size.gradient.clone());break;case 1:e=this._size.separateAxes?Ur.createByRandomTwoConstantSeparate(this._size.constantMinSeparate.clone(),this._size.constantMaxSeparate.clone()):Ur.createByRandomTwoConstant(this._size.constantMin,this._size.constantMax);break;case 2:e=this._size.separateAxes?Ur.createByRandomTwoGradientSeparate(this._size.gradientXMin.clone(),this._size.gradientYMin.clone(),this._size.gradientZMin.clone(),this._size.gradientXMax.clone(),this._size.gradientYMax.clone(),this._size.gradientZMax.clone()):Ur.createByRandomTwoGradient(this._size.gradientMin.clone(),this._size.gradientMax.clone())}var t=new qr(e);return t.enable=this.enable,t}}class Qr{constructor(){this._type=0,this._constant=0,this._constantMin=0,this._constantMax=0}static createByConstant(e=0){var t=new Qr;return t._type=0,t._constant=e,t}static createByRandomTwoConstant(e=0,t=0){var r=new Qr;return r._type=1,r._constantMin=e,r._constantMax=t,r}get type(){return this._type}get constant(){return this._constant}get constantMin(){return this._constantMin}get constantMax(){return this._constantMax}cloneTo(e){var t=e;t._type=this._type,t._constant=this._constant,t._constantMin=this._constantMin,t._constantMax=this._constantMax}clone(){var e=new Qr;return this.cloneTo(e),e}}class Kr{constructor(e,t){this.type=0,this.randomRow=!1,this.rowIndex=0,this.cycles=0,this.enableUVChannels=0,this.enable=!1,this.tiles=new i(1,1),this.type=0,this.randomRow=!0,this.rowIndex=0,this.cycles=1,this.enableUVChannels=1,this._frame=e,this._startFrame=t}get frame(){return this._frame}get startFrame(){return this._startFrame}cloneTo(e){var t=e;this.tiles.cloneTo(t.tiles),t.type=this.type,t.randomRow=this.randomRow,t.rowIndex=this.rowIndex,t.cycles=this.cycles,t.enableUVChannels=this.enableUVChannels,t.enable=this.enable,this._frame.cloneTo(t._frame),this._startFrame.cloneTo(t._startFrame)}clone(){var e,t;switch(this._frame.type){case 0:e=wr.createByConstant(this._frame.constant);break;case 1:e=wr.createByOverTime(this._frame.frameOverTimeData.clone());break;case 2:e=wr.createByRandomTwoConstant(this._frame.constantMin,this._frame.constantMax);break;case 3:e=wr.createByRandomTwoOverTime(this._frame.frameOverTimeDataMin.clone(),this._frame.frameOverTimeDataMax.clone())}switch(this._startFrame.type){case 0:t=Qr.createByConstant(this._startFrame.constant);break;case 1:t=Qr.createByRandomTwoConstant(this._startFrame.constantMin,this._startFrame.constantMax)}var r=new Kr(e,t);return this.cloneTo(r),r}}class Jr{constructor(e){this.enable=!1,this.space=0,this._velocity=e}get velocity(){return this._velocity}cloneTo(e){var t=e;this._velocity.cloneTo(t._velocity),t.enable=this.enable,t.space=this.space}clone(){var e;switch(this._velocity.type){case 0:e=Gr.createByConstant(this._velocity.constant.clone());break;case 1:e=Gr.createByGradient(this._velocity.gradientX.clone(),this._velocity.gradientY.clone(),this._velocity.gradientZ.clone());break;case 2:e=Gr.createByRandomTwoConstant(this._velocity.constantMin.clone(),this._velocity.constantMax.clone());break;case 3:e=Gr.createByRandomTwoGradient(this._velocity.gradientXMin.clone(),this._velocity.gradientXMax.clone(),this._velocity.gradientYMin.clone(),this._velocity.gradientYMax.clone(),this._velocity.gradientZMin.clone(),this._velocity.gradientZMax.clone())}var t=new Jr(e);return t.enable=this.enable,t.space=this.space,t}}class $r{}$r.WORLDPOSITION=xe.propertyNameToID("u_WorldPosition"),$r.WORLDROTATION=xe.propertyNameToID("u_WorldRotation"),$r.POSITIONSCALE=xe.propertyNameToID("u_PositionScale"),$r.SIZESCALE=xe.propertyNameToID("u_SizeScale"),$r.SCALINGMODE=xe.propertyNameToID("u_ScalingMode"),$r.GRAVITY=xe.propertyNameToID("u_Gravity"),$r.THREEDSTARTROTATION=xe.propertyNameToID("u_ThreeDStartRotation"),$r.STRETCHEDBILLBOARDLENGTHSCALE=xe.propertyNameToID("u_StretchedBillboardLengthScale"),$r.STRETCHEDBILLBOARDSPEEDSCALE=xe.propertyNameToID("u_StretchedBillboardSpeedScale"),$r.SIMULATIONSPACE=xe.propertyNameToID("u_SimulationSpace"),$r.CURRENTTIME=xe.propertyNameToID("u_CurrentTime"),$r.VOLVELOCITYCONST=xe.propertyNameToID("u_VOLVelocityConst"),$r.VOLVELOCITYGRADIENTX=xe.propertyNameToID("u_VOLVelocityGradientX"),$r.VOLVELOCITYGRADIENTY=xe.propertyNameToID("u_VOLVelocityGradientY"),$r.VOLVELOCITYGRADIENTZ=xe.propertyNameToID("u_VOLVelocityGradientZ"),$r.VOLVELOCITYCONSTMAX=xe.propertyNameToID("u_VOLVelocityConstMax"),$r.VOLVELOCITYGRADIENTXMAX=xe.propertyNameToID("u_VOLVelocityGradientMaxX"),$r.VOLVELOCITYGRADIENTYMAX=xe.propertyNameToID("u_VOLVelocityGradientMaxY"),$r.VOLVELOCITYGRADIENTZMAX=xe.propertyNameToID("u_VOLVelocityGradientMaxZ"),$r.VOLSPACETYPE=xe.propertyNameToID("u_VOLSpaceType"),$r.COLOROVERLIFEGRADIENTALPHAS=xe.propertyNameToID("u_ColorOverLifeGradientAlphas"),$r.COLOROVERLIFEGRADIENTCOLORS=xe.propertyNameToID("u_ColorOverLifeGradientColors"),$r.MAXCOLOROVERLIFEGRADIENTALPHAS=xe.propertyNameToID("u_MaxColorOverLifeGradientAlphas"),$r.MAXCOLOROVERLIFEGRADIENTCOLORS=xe.propertyNameToID("u_MaxColorOverLifeGradientColors"),$r.SOLSIZEGRADIENT=xe.propertyNameToID("u_SOLSizeGradient"),$r.SOLSIZEGRADIENTX=xe.propertyNameToID("u_SOLSizeGradientX"),$r.SOLSIZEGRADIENTY=xe.propertyNameToID("u_SOLSizeGradientY"),$r.SOLSizeGradientZ=xe.propertyNameToID("u_SOLSizeGradientZ"),$r.SOLSizeGradientMax=xe.propertyNameToID("u_SOLSizeGradientMax"),$r.SOLSIZEGRADIENTXMAX=xe.propertyNameToID("u_SOLSizeGradientMaxX"),$r.SOLSIZEGRADIENTYMAX=xe.propertyNameToID("u_SOLSizeGradientMaxY"),$r.SOLSizeGradientZMAX=xe.propertyNameToID("u_SOLSizeGradientMaxZ"),$r.ROLANGULARVELOCITYCONST=xe.propertyNameToID("u_ROLAngularVelocityConst"),$r.ROLANGULARVELOCITYCONSTSEPRARATE=xe.propertyNameToID("u_ROLAngularVelocityConstSeprarate"),$r.ROLANGULARVELOCITYGRADIENT=xe.propertyNameToID("u_ROLAngularVelocityGradient"),$r.ROLANGULARVELOCITYGRADIENTX=xe.propertyNameToID("u_ROLAngularVelocityGradientX"),$r.ROLANGULARVELOCITYGRADIENTY=xe.propertyNameToID("u_ROLAngularVelocityGradientY"),$r.ROLANGULARVELOCITYGRADIENTZ=xe.propertyNameToID("u_ROLAngularVelocityGradientZ"),$r.ROLANGULARVELOCITYCONSTMAX=xe.propertyNameToID("u_ROLAngularVelocityConstMax"),$r.ROLANGULARVELOCITYCONSTMAXSEPRARATE=xe.propertyNameToID("u_ROLAngularVelocityConstMaxSeprarate"),$r.ROLANGULARVELOCITYGRADIENTMAX=xe.propertyNameToID("u_ROLAngularVelocityGradientMax"),$r.ROLANGULARVELOCITYGRADIENTXMAX=xe.propertyNameToID("u_ROLAngularVelocityGradientMaxX"),$r.ROLANGULARVELOCITYGRADIENTYMAX=xe.propertyNameToID("u_ROLAngularVelocityGradientMaxY"),$r.ROLANGULARVELOCITYGRADIENTZMAX=xe.propertyNameToID("u_ROLAngularVelocityGradientMaxZ"),$r.ROLANGULARVELOCITYGRADIENTWMAX=xe.propertyNameToID("u_ROLAngularVelocityGradientMaxW"),$r.TEXTURESHEETANIMATIONCYCLES=xe.propertyNameToID("u_TSACycles"),$r.TEXTURESHEETANIMATIONSUBUVLENGTH=xe.propertyNameToID("u_TSASubUVLength"),$r.TEXTURESHEETANIMATIONGRADIENTUVS=xe.propertyNameToID("u_TSAGradientUVs"),$r.TEXTURESHEETANIMATIONGRADIENTMAXUVS=xe.propertyNameToID("u_TSAMaxGradientUVs");class ei extends st{constructor(){super(),this.setShaderName("PARTICLESHURIKEN"),this._color=new a(1,1,1,1),this.renderMode=ei.RENDERMODE_ALPHABLENDED}static __initDefine__(){ei.SHADERDEFINE_DIFFUSEMAP=xe.getDefineByName("DIFFUSEMAP"),ei.SHADERDEFINE_TINTCOLOR=xe.getDefineByName("TINTCOLOR"),ei.SHADERDEFINE_ADDTIVEFOG=xe.getDefineByName("ADDTIVEFOG"),ei.SHADERDEFINE_TILINGOFFSET=xe.getDefineByName("TILINGOFFSET")}get _TintColor(){return this.color}set _TintColor(e){this.color=e}get _TintColorR(){return this._color.x}set _TintColorR(e){this._color.x=e,this.color=this._color}get _TintColorG(){return this._color.y}set _TintColorG(e){this._color.y=e,this.color=this._color}get _TintColorB(){return this._color.z}set _TintColorB(e){this._color.z=e,this.color=this._color}get _TintColorA(){return this._color.w}set _TintColorA(e){this._color.w=e,this.color=this._color}get _MainTex_ST(){return this._shaderValues.getVector(ei.TILINGOFFSET)}set _MainTex_ST(e){var t=this._shaderValues.getVector(ei.TILINGOFFSET);t.setValue(e.x,e.y,e.z,e.w),this.tilingOffset=t}get _MainTex_STX(){return this._shaderValues.getVector(ei.TILINGOFFSET).x}set _MainTex_STX(e){var t=this._shaderValues.getVector(ei.TILINGOFFSET);t.x=e,this.tilingOffset=t}get _MainTex_STY(){return this._shaderValues.getVector(ei.TILINGOFFSET).y}set _MainTex_STY(e){var t=this._shaderValues.getVector(ei.TILINGOFFSET);t.y=e,this.tilingOffset=t}get _MainTex_STZ(){return this._shaderValues.getVector(ei.TILINGOFFSET).z}set _MainTex_STZ(e){var t=this._shaderValues.getVector(ei.TILINGOFFSET);t.z=e,this.tilingOffset=t}get _MainTex_STW(){return this._shaderValues.getVector(ei.TILINGOFFSET).w}set _MainTex_STW(e){var t=this._shaderValues.getVector(ei.TILINGOFFSET);t.w=e,this.tilingOffset=t}set renderMode(e){switch(e){case ei.RENDERMODE_ADDTIVE:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.depthWrite=!1,this.cull=lt.CULL_NONE,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE,this.alphaTest=!1,this._shaderValues.addDefine(ei.SHADERDEFINE_ADDTIVEFOG);break;case ei.RENDERMODE_ALPHABLENDED:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.depthWrite=!1,this.cull=lt.CULL_NONE,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA,this.alphaTest=!1,this._shaderValues.removeDefine(ei.SHADERDEFINE_ADDTIVEFOG);break;default:throw new Error("ShurikenParticleMaterial : renderMode value error.")}}get colorR(){return this._TintColorR}set colorR(e){this._TintColorR=e}get colorG(){return this._TintColorG}set colorG(e){this._TintColorG=e}get colorB(){return this._TintColorB}set colorB(e){this._TintColorB=e}get colorA(){return this._TintColorA}set colorA(e){this._TintColorA=e}get color(){return this._shaderValues.getVector(ei.TINTCOLOR)}set color(e){e?this._shaderValues.addDefine(ei.SHADERDEFINE_TINTCOLOR):this._shaderValues.removeDefine(ei.SHADERDEFINE_TINTCOLOR),this._shaderValues.setVector(ei.TINTCOLOR,e)}get tilingOffsetX(){return this._MainTex_STX}set tilingOffsetX(e){this._MainTex_STX=e}get tilingOffsetY(){return this._MainTex_STY}set tilingOffsetY(e){this._MainTex_STY=e}get tilingOffsetZ(){return this._MainTex_STZ}set tilingOffsetZ(e){this._MainTex_STZ=e}get tilingOffsetW(){return this._MainTex_STW}set tilingOffsetW(e){this._MainTex_STW=e}get tilingOffset(){return this._shaderValues.getVector(ei.TILINGOFFSET)}set tilingOffset(e){e&&(1!=e.x||1!=e.y||0!=e.z||0!=e.w)?this._shaderValues.addDefine(ei.SHADERDEFINE_TILINGOFFSET):this._shaderValues.removeDefine(ei.SHADERDEFINE_TILINGOFFSET),this._shaderValues.setVector(ei.TILINGOFFSET,e)}get texture(){return this._shaderValues.getTexture(ei.DIFFUSETEXTURE)}set texture(e){e?this._shaderValues.addDefine(ei.SHADERDEFINE_DIFFUSEMAP):this._shaderValues.removeDefine(ei.SHADERDEFINE_DIFFUSEMAP),this._shaderValues.setTexture(ei.DIFFUSETEXTURE,e)}clone(){var e=new ei;return this.cloneTo(e),e}}ei.RENDERMODE_ALPHABLENDED=0,ei.RENDERMODE_ADDTIVE=1,ei.DIFFUSETEXTURE=xe.propertyNameToID("u_texture"),ei.TINTCOLOR=xe.propertyNameToID("u_Tintcolor"),ei.TILINGOFFSET=xe.propertyNameToID("u_TilingOffset");class ti extends Kt{constructor(e){super(e),this._finalGravity=new n,this._tempRotationMatrix=new R,this._mesh=null,this.stretchedBillboardCameraSpeedScale=0,this.stretchedBillboardSpeedScale=0,this.stretchedBillboardLengthScale=2,this._defaultBoundBox=new Ft(new n,new n),this.renderMode=0,this._supportOctree=!1}get renderMode(){return this._renderMode}set renderMode(e){if(this._renderMode!==e){var t=this._shaderValues;switch(this._renderMode){case 0:t.removeDefine($r.SHADERDEFINE_RENDERMODE_BILLBOARD);break;case 1:t.removeDefine($r.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD);break;case 2:t.removeDefine($r.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD);break;case 3:t.removeDefine($r.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD);break;case 4:t.removeDefine($r.SHADERDEFINE_RENDERMODE_MESH)}switch(this._renderMode=e,e){case 0:t.addDefine($r.SHADERDEFINE_RENDERMODE_BILLBOARD);break;case 1:t.addDefine($r.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD);break;case 2:t.addDefine($r.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD);break;case 3:t.addDefine($r.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD);break;case 4:t.addDefine($r.SHADERDEFINE_RENDERMODE_MESH);break;default:throw new Error("ShurikenParticleRender: unknown renderMode Value.")}var r=this._owner.particleSystem;r&&r._initBufferDatas()}}get mesh(){return this._mesh}set mesh(e){this._mesh!==e&&(this._mesh&&this._mesh._removeReference(),this._mesh=e,e&&e._addReference(),this._owner.particleSystem._initBufferDatas())}_calculateBoundingBox(){var e=this._owner.particleSystem;if(e._useCustomBounds)e.customBounds._tranform(this._owner.transform.worldMatrix,this._bounds);else if(e._simulationSupported()){if(e._generateBounds(),e._bounds._tranform(this._owner.transform.worldMatrix,this._bounds),0!=e.gravityModifier){var t=this._bounds.getMax(),r=this._bounds.getMin(),i=e._gravityOffset;t.y-=i.x,r.y-=i.y,this._bounds.setMax(t),this._bounds.setMin(r)}}else{(r=this._bounds.getMin()).setValue(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),this._bounds.setMin(r),(t=this._bounds.getMax()).setValue(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._bounds.setMax(t)}}_needRender(e,t){return!e||!!e.intersects(this.bounds._getBoundBox())&&!!this._owner.particleSystem.isAlive}_renderUpdate(e,t){var r=this._owner.particleSystem,i=this._shaderValues,a=this._owner.transform;switch(r.simulationSpace){case 0:break;case 1:i.setVector3($r.WORLDPOSITION,a.position),i.setQuaternion($r.WORLDROTATION,a.rotation);break;default:throw new Error("ShurikenParticleMaterial: SimulationSpace value is invalid.")}switch(r.scaleMode){case 0:var s=a.getWorldLossyScale();i.setVector3($r.POSITIONSCALE,s),i.setVector3($r.SIZESCALE,s);break;case 1:var o=a.localScale;i.setVector3($r.POSITIONSCALE,o),i.setVector3($r.SIZESCALE,o);break;case 2:i.setVector3($r.POSITIONSCALE,a.getWorldLossyScale()),i.setVector3($r.SIZESCALE,n._ONE)}n.scale(M.gravity,r.gravityModifier,this._finalGravity),i.setVector3($r.GRAVITY,this._finalGravity),i.setInt($r.SIMULATIONSPACE,r.simulationSpace),i.setBool($r.THREEDSTARTROTATION,r.threeDStartRotation),i.setInt($r.SCALINGMODE,r.scaleMode),i.setNumber($r.STRETCHEDBILLBOARDLENGTHSCALE,this.stretchedBillboardLengthScale),i.setNumber($r.STRETCHEDBILLBOARDSPEEDSCALE,this.stretchedBillboardSpeedScale),i.setNumber($r.CURRENTTIME,r._currentTime)}get bounds(){return this._boundsChange&&(this._calculateBoundingBox(),this._boundsChange=!1),this._bounds}_destroy(){super._destroy(),this._mesh&&(this._mesh._removeReference(),this._mesh=null)}}class ri{constructor(){}}ri.PARTICLE_CORNERTEXTURECOORDINATE0=5,ri.PARTICLE_POSITION0=1,ri.PARTICLE_COLOR0=2,ri.PARTICLE_TEXTURECOORDINATE0=3,ri.PARTICLE_SHAPEPOSITIONSTARTLIFETIME=4,ri.PARTICLE_DIRECTIONTIME=0,ri.PARTICLE_STARTCOLOR0=6,ri.PARTICLE_ENDCOLOR0=7,ri.PARTICLE_STARTSIZE=8,ri.PARTICLE_STARTROTATION=9,ri.PARTICLE_STARTSPEED=10,ri.PARTICLE_RANDOM0=11,ri.PARTICLE_RANDOM1=12,ri.PARTICLE_SIMULATIONWORLDPOSTION=13,ri.PARTICLE_SIMULATIONWORLDROTATION=14;class ii extends ri{constructor(e,t,r,i,a,n,s,o,l,_,h,c,d,u){super(),this._cornerTextureCoordinate=e,this._positionStartLifeTime=t,this._velocity=r,this._startColor=i,this._startSize=a,this._startRotation0=n,this._startRotation1=s,this._startRotation2=o,this._startLifeTime=l,this._time=_,this._startSpeed=h,this._randoms0=this.random0,this._randoms1=this.random1,this._simulationWorldPostion=u}static get vertexDeclaration(){return ii._vertexDeclaration}static __init__(){ii._vertexDeclaration=new fe(152,[new Te(0,ue.Vector4,ri.PARTICLE_CORNERTEXTURECOORDINATE0),new Te(16,ue.Vector4,ri.PARTICLE_SHAPEPOSITIONSTARTLIFETIME),new Te(32,ue.Vector4,ri.PARTICLE_DIRECTIONTIME),new Te(48,ue.Vector4,ri.PARTICLE_STARTCOLOR0),new Te(64,ue.Vector3,ri.PARTICLE_STARTSIZE),new Te(76,ue.Vector3,ri.PARTICLE_STARTROTATION),new Te(88,ue.Single,ri.PARTICLE_STARTSPEED),new Te(92,ue.Vector4,ri.PARTICLE_RANDOM0),new Te(108,ue.Vector4,ri.PARTICLE_RANDOM1),new Te(124,ue.Vector3,ri.PARTICLE_SIMULATIONWORLDPOSTION),new Te(136,ue.Vector4,ri.PARTICLE_SIMULATIONWORLDROTATION)])}get cornerTextureCoordinate(){return this._cornerTextureCoordinate}get positionStartLifeTime(){return this._positionStartLifeTime}get velocity(){return this._velocity}get startColor(){return this._startColor}get startSize(){return this._startSize}get startRotation0(){return this._startRotation0}get startRotation1(){return this._startRotation1}get startRotation2(){return this._startRotation2}get startLifeTime(){return this._startLifeTime}get time(){return this._time}get startSpeed(){return this._startSpeed}get random0(){return this._randoms0}get random1(){return this._randoms1}get simulationWorldPostion(){return this._simulationWorldPostion}}class ai extends ri{constructor(e,t,r,i,a,n,s,o,l,_,h,c,d,u){super(),this._cornerTextureCoordinate=e,this._positionStartLifeTime=t,this._velocity=r,this._startColor=i,this._startSize=a,this._startRotation0=n,this._startRotation1=s,this._startRotation2=o,this._startLifeTime=l,this._time=_,this._startSpeed=h,this._randoms0=this.random0,this._randoms1=this.random1,this._simulationWorldPostion=u}static __init__(){ai._vertexDeclaration=new fe(172,[new Te(0,ue.Vector3,ri.PARTICLE_POSITION0),new Te(12,ue.Vector4,ri.PARTICLE_COLOR0),new Te(28,ue.Vector2,ri.PARTICLE_TEXTURECOORDINATE0),new Te(36,ue.Vector4,ri.PARTICLE_SHAPEPOSITIONSTARTLIFETIME),new Te(52,ue.Vector4,ri.PARTICLE_DIRECTIONTIME),new Te(68,ue.Vector4,ri.PARTICLE_STARTCOLOR0),new Te(84,ue.Vector3,ri.PARTICLE_STARTSIZE),new Te(96,ue.Vector3,ri.PARTICLE_STARTROTATION),new Te(108,ue.Single,ri.PARTICLE_STARTSPEED),new Te(112,ue.Vector4,ri.PARTICLE_RANDOM0),new Te(128,ue.Vector4,ri.PARTICLE_RANDOM1),new Te(144,ue.Vector3,ri.PARTICLE_SIMULATIONWORLDPOSTION),new Te(156,ue.Vector4,ri.PARTICLE_SIMULATIONWORLDROTATION)])}static get vertexDeclaration(){return ai._vertexDeclaration}get cornerTextureCoordinate(){return this._cornerTextureCoordinate}get position(){return this._positionStartLifeTime}get velocity(){return this._velocity}get startColor(){return this._startColor}get startSize(){return this._startSize}get startRotation0(){return this._startRotation0}get startRotation1(){return this._startRotation1}get startRotation2(){return this._startRotation2}get startLifeTime(){return this._startLifeTime}get time(){return this._time}get startSpeed(){return this._startSpeed}get random0(){return this._randoms0}get random1(){return this._randoms1}get simulationWorldPostion(){return this._simulationWorldPostion}}class ni{constructor(e){this._temp=new Uint32Array(1),this.seeds=new Uint32Array(4),this.seeds[0]=e,this.seeds[1]=1812433253*this.seeds[0]+1,this.seeds[2]=1812433253*this.seeds[1]+1,this.seeds[3]=1812433253*this.seeds[2]+1}static getFloatFromInt(e){return 1/8388607*(8388607&e)}static getByteFromInt(e){return(8388607&e)>>>15}get seed(){return this.seeds[0]}set seed(e){this.seeds[0]=e,this.seeds[1]=1812433253*this.seeds[0]+1,this.seeds[2]=1812433253*this.seeds[1]+1,this.seeds[3]=1812433253*this.seeds[2]+1}getUint(){return this._temp[0]=this.seeds[0]^this.seeds[0]<<11,this.seeds[0]=this.seeds[1],this.seeds[1]=this.seeds[2],this.seeds[2]=this.seeds[3],this.seeds[3]=this.seeds[3]^this.seeds[3]>>>19^this._temp[0]^this._temp[0]>>>8,this.seeds[3]}getFloat(){return this.getUint(),(8388607&this.seeds[3])*(1/8388607)}getSignedFloat(){return 2*this.getFloat()-1}}class si{constructor(){this._emissionRate=10,this._destroyed=!1,this._bursts=[]}set emissionRate(e){if(e<0)throw new Error("ParticleBaseShape:emissionRate value must large or equal than 0.");this._emissionRate=e}get emissionRate(){return this._emissionRate}get destroyed(){return this._destroyed}destroy(){this._bursts=null,this._destroyed=!0}getBurstsCount(){return this._bursts.length}getBurstByIndex(e){return this._bursts[e]}addBurst(e){var t=this._bursts.length;if(t>0)for(var r=0;r<t;r++)this._bursts[r].time>e.time&&this._bursts.splice(r,0,e);this._bursts.push(e)}removeBurst(e){var t=this._bursts.indexOf(e);-1!==t&&this._bursts.splice(t,1)}removeBurstByIndex(e){this._bursts.splice(e,1)}clearBurst(){this._bursts.length=0}cloneTo(e){var t=e,r=t._bursts;r.length=this._bursts.length;for(var i=0,a=this._bursts.length;i<a;i++){var n=r[i];n?this._bursts[i].cloneTo(n):r[i]=this._bursts[i].clone()}t._emissionRate=this._emissionRate,t.enable=this.enable}clone(){var e=new si;return this.cloneTo(e),e}}class oi{constructor(){}static _getStartLifetimeFromGradient(e,r){for(var i=1,a=e.gradientCount;i<a;i++){var n=e.getKeyByIndex(i);if(n>=r){var s=e.getKeyByIndex(i-1),o=(r-s)/(n-s);return t.MathUtil.lerp(e.getValueByIndex(i-1),e.getValueByIndex(i),o)}}throw new Error("ShurikenParticleData: can't get value foam startLifeTimeGradient.")}static _randomInvertRoationArray(e,t,r,i,a){var n;i?(i.seed=a[6],n=i.getFloat(),a[6]=i.seed):n=Math.random(),n<r?(t.x=-e.x,t.y=-e.y,t.z=-e.z):(t.x=e.x,t.y=e.y,t.z=e.z)}static _randomInvertRoation(e,t,r,i){var a;return r?(r.seed=i[6],a=r.getFloat(),i[6]=r.seed):a=Math.random(),a<t&&(e=-e),e}static create(e,r,i){var n=e.autoRandomSeed,s=e._rand,o=e._randomSeeds;switch(e.startColorType){case 0:var l=e.startColorConstant;oi.startColor.x=l.x,oi.startColor.y=l.y,oi.startColor.z=l.z,oi.startColor.w=l.w;break;case 2:n?a.lerp(e.startColorConstantMin,e.startColorConstantMax,Math.random(),oi.startColor):(s.seed=o[3],a.lerp(e.startColorConstantMin,e.startColorConstantMax,s.getFloat(),oi.startColor),o[3]=s.seed)}var _=e.colorOverLifetime;if(_&&_.enable){var h=_.color;switch(h.type){case 0:oi.startColor.x=oi.startColor.x*h.constant.x,oi.startColor.y=oi.startColor.y*h.constant.y,oi.startColor.z=oi.startColor.z*h.constant.z,oi.startColor.w=oi.startColor.w*h.constant.w;break;case 2:var c;n?c=Math.random():(s.seed=o[10],c=s.getFloat(),o[10]=s.seed);var d=h.constantMin,u=h.constantMax;oi.startColor.x=oi.startColor.x*t.MathUtil.lerp(d.x,u.x,c),oi.startColor.y=oi.startColor.y*t.MathUtil.lerp(d.y,u.y,c),oi.startColor.z=oi.startColor.z*t.MathUtil.lerp(d.z,u.z,c),oi.startColor.w=oi.startColor.w*t.MathUtil.lerp(d.w,u.w,c)}}var m=oi.startSize;switch(e.startSizeType){case 0:if(e.threeDStartSize){var f=e.startSizeConstantSeparate;m[0]=f.x,m[1]=f.y,m[2]=f.z}else m[0]=m[1]=m[2]=e.startSizeConstant;break;case 2:if(e.threeDStartSize){var T=e.startSizeConstantMinSeparate,E=e.startSizeConstantMaxSeparate;n?(m[0]=t.MathUtil.lerp(T.x,E.x,Math.random()),m[1]=t.MathUtil.lerp(T.y,E.y,Math.random()),m[2]=t.MathUtil.lerp(T.z,E.z,Math.random())):(s.seed=o[4],m[0]=t.MathUtil.lerp(T.x,E.x,s.getFloat()),m[1]=t.MathUtil.lerp(T.y,E.y,s.getFloat()),m[2]=t.MathUtil.lerp(T.z,E.z,s.getFloat()),o[4]=s.seed)}else n?m[0]=m[1]=m[2]=t.MathUtil.lerp(e.startSizeConstantMin,e.startSizeConstantMax,Math.random()):(s.seed=o[4],m[0]=m[1]=m[2]=t.MathUtil.lerp(e.startSizeConstantMin,e.startSizeConstantMax,s.getFloat()),o[4]=s.seed)}var p=e.sizeOverLifetime;if(p&&p.enable&&1===p.size.type){var g,S=p.size;if(S.separateAxes)n?(m[0]=m[0]*t.MathUtil.lerp(S.constantMinSeparate.x,S.constantMaxSeparate.x,Math.random()),m[1]=m[1]*t.MathUtil.lerp(S.constantMinSeparate.y,S.constantMaxSeparate.y,Math.random()),m[2]=m[2]*t.MathUtil.lerp(S.constantMinSeparate.z,S.constantMaxSeparate.z,Math.random())):(s.seed=o[11],m[0]=m[0]*t.MathUtil.lerp(S.constantMinSeparate.x,S.constantMaxSeparate.x,s.getFloat()),m[1]=m[1]*t.MathUtil.lerp(S.constantMinSeparate.y,S.constantMaxSeparate.y,s.getFloat()),m[2]=m[2]*t.MathUtil.lerp(S.constantMinSeparate.z,S.constantMaxSeparate.z,s.getFloat()),o[11]=s.seed);else n?g=t.MathUtil.lerp(S.constantMin,S.constantMax,Math.random()):(s.seed=o[11],g=t.MathUtil.lerp(S.constantMin,S.constantMax,s.getFloat()),o[11]=s.seed),m[0]=m[0]*g,m[1]=m[1]*g,m[2]=m[2]*g}var R=r.renderMode;if(1!==R)switch(e.startRotationType){case 0:if(e.threeDStartRotation){var v=e.startRotationConstantSeparate,x=oi._tempVector30;oi._randomInvertRoationArray(v,x,e.randomizeRotationDirection,n?null:s,o),oi.startRotation[0]=x.x,oi.startRotation[1]=x.y,oi.startRotation[2]=4!==R?-x.z:x.z}else oi.startRotation[0]=oi._randomInvertRoation(e.startRotationConstant,e.randomizeRotationDirection,n?null:s,o),oi.startRotation[1]=0,oi.startRotation[2]=0;break;case 2:if(e.threeDStartRotation){var A=e.startRotationConstantMinSeparate,I=e.startRotationConstantMaxSeparate,M=oi._tempVector30;n?(M.x=t.MathUtil.lerp(A.x,I.x,Math.random()),M.y=t.MathUtil.lerp(A.y,I.y,Math.random()),M.z=t.MathUtil.lerp(A.z,I.z,Math.random())):(s.seed=o[5],M.x=t.MathUtil.lerp(A.x,I.x,s.getFloat()),M.y=t.MathUtil.lerp(A.y,I.y,s.getFloat()),M.z=t.MathUtil.lerp(A.z,I.z,s.getFloat()),o[5]=s.seed),oi._randomInvertRoationArray(M,M,e.randomizeRotationDirection,n?null:s,o),oi.startRotation[0]=M.x,oi.startRotation[1]=M.y,oi.startRotation[2]=4!==R?-M.z:M.z}else n?oi.startRotation[0]=oi._randomInvertRoation(t.MathUtil.lerp(e.startRotationConstantMin,e.startRotationConstantMax,Math.random()),e.randomizeRotationDirection,n?null:s,o):(s.seed=o[5],oi.startRotation[0]=oi._randomInvertRoation(t.MathUtil.lerp(e.startRotationConstantMin,e.startRotationConstantMax,s.getFloat()),e.randomizeRotationDirection,n?null:s,o),o[5]=s.seed)}switch(e.startLifetimeType){case 0:oi.startLifeTime=e.startLifetimeConstant;break;case 1:oi.startLifeTime=oi._getStartLifetimeFromGradient(e.startLifeTimeGradient,e.emissionTime);break;case 2:n?oi.startLifeTime=t.MathUtil.lerp(e.startLifetimeConstantMin,e.startLifetimeConstantMax,Math.random()):(s.seed=o[7],oi.startLifeTime=t.MathUtil.lerp(e.startLifetimeConstantMin,e.startLifetimeConstantMax,s.getFloat()),o[7]=s.seed);break;case 3:var D=e.emissionTime;n?oi.startLifeTime=t.MathUtil.lerp(oi._getStartLifetimeFromGradient(e.startLifeTimeGradientMin,D),oi._getStartLifetimeFromGradient(e.startLifeTimeGradientMax,D),Math.random()):(s.seed=o[7],oi.startLifeTime=t.MathUtil.lerp(oi._getStartLifetimeFromGradient(e.startLifeTimeGradientMin,D),oi._getStartLifetimeFromGradient(e.startLifeTimeGradientMax,D),s.getFloat()),o[7]=s.seed)}var C=e.textureSheetAnimation;if(C&&C.enable){var y,L=C.tiles,O=L.x,N=L.y,P=1/O,b=1/N,w=C.startFrame;switch(w.type){case 0:y=w.constant;break;case 1:n?y=t.MathUtil.lerp(w.constantMin,w.constantMax,Math.random()):(s.seed=o[14],y=t.MathUtil.lerp(w.constantMin,w.constantMax,s.getFloat()),o[14]=s.seed)}var V=C.frame,B=C.cycles;switch(V.type){case 0:y+=V.constant*B;break;case 2:n?y+=t.MathUtil.lerp(V.constantMin,V.constantMax,Math.random())*B:(s.seed=o[15],y+=t.MathUtil.lerp(V.constantMin,V.constantMax,s.getFloat())*B,o[15]=s.seed)}var F=0;switch(C.type){case 0:F=Math.floor(y/O);break;case 1:C.randomRow?n?F=Math.floor(Math.random()*N):(s.seed=o[13],F=Math.floor(s.getFloat()*N),o[13]=s.seed):F=C.rowIndex}var U=Math.floor(y%O);oi.startUVInfo=oi.startUVInfo,oi.startUVInfo[0]=P,oi.startUVInfo[1]=b,oi.startUVInfo[2]=U*P,oi.startUVInfo[3]=F*b}else oi.startUVInfo=oi.startUVInfo,oi.startUVInfo[0]=1,oi.startUVInfo[1]=1,oi.startUVInfo[2]=0,oi.startUVInfo[3]=0}}oi._tempVector30=new n,oi.startColor=new a,oi.startSize=new Float32Array(3),oi.startRotation=new Float32Array(3),oi.startUVInfo=new Float32Array(4);class li extends Gt{constructor(e){super(),this._boundingSphere=null,this._boundingBox=null,this._boundingBoxCorners=null,this._bounds=null,this._gravityOffset=new i,this._customBounds=null,this._useCustomBounds=!1,this._owner=null,this._ownerRender=null,this._vertices=null,this._floatCountPerVertex=0,this._startLifeTimeIndex=0,this._timeIndex=0,this._simulateUpdate=!1,this._firstActiveElement=0,this._firstNewElement=0,this._firstFreeElement=0,this._firstRetiredElement=0,this._drawCounter=0,this._bufferMaxParticles=0,this._emission=null,this._shape=null,this._isEmitting=!1,this._isPlaying=!1,this._isPaused=!1,this._playStartDelay=0,this._frameRateTime=0,this._emissionTime=0,this._totalDelayTime=0,this._burstsIndex=0,this._velocityOverLifetime=null,this._colorOverLifetime=null,this._sizeOverLifetime=null,this._rotationOverLifetime=null,this._textureSheetAnimation=null,this._startLifetimeType=0,this._startLifetimeConstant=0,this._startLifeTimeGradient=null,this._startLifetimeConstantMin=0,this._startLifetimeConstantMax=0,this._startLifeTimeGradientMin=null,this._startLifeTimeGradientMax=null,this._maxStartLifetime=0,this._uvLength=new i,this._vertexStride=0,this._indexStride=0,this._vertexBuffer=null,this._indexBuffer=null,this._bufferState=new Ee,this._updateMask=0,this._currentTime=0,this._startUpdateLoopCount=0,this._rand=null,this._randomSeeds=null,this.duration=0,this.looping=!1,this.prewarm=!1,this.startDelayType=0,this.startDelay=0,this.startDelayMin=0,this.startDelayMax=0,this.startSpeedType=0,this.startSpeedConstant=0,this.startSpeedConstantMin=0,this.startSpeedConstantMax=0,this.threeDStartSize=!1,this.startSizeType=0,this.startSizeConstant=0,this.startSizeConstantSeparate=null,this.startSizeConstantMin=0,this.startSizeConstantMax=0,this.startSizeConstantMinSeparate=null,this.startSizeConstantMaxSeparate=null,this.threeDStartRotation=!1,this.startRotationType=0,this.startRotationConstant=0,this.startRotationConstantSeparate=null,this.startRotationConstantMin=0,this.startRotationConstantMax=0,this.startRotationConstantMinSeparate=null,this.startRotationConstantMaxSeparate=null,this.randomizeRotationDirection=0,this.startColorType=0,this.startColorConstant=new a(1,1,1,1),this.startColorConstantMin=new a(0,0,0,0),this.startColorConstantMax=new a(1,1,1,1),this.gravityModifier=0,this.simulationSpace=0,this.simulationSpeed=1,this.scaleMode=1,this.playOnAwake=!1,this.randomSeed=null,this.autoRandomSeed=!1,this.isPerformanceMode=!1,this._firstActiveElement=0,this._firstNewElement=0,this._firstFreeElement=0,this._firstRetiredElement=0,this._owner=e,this._ownerRender=e.particleRenderer,this._boundingBoxCorners=[],this._boundingSphere=new nr(new n,Number.MAX_VALUE),this._boundingBox=new Ft(new n(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),new n(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)),this._bounds=new Ut(this._boundingBox.min,this._boundingBox.max),this._useCustomBounds=!1,this._currentTime=0,this._isEmitting=!1,this._isPlaying=!1,this._isPaused=!1,this._burstsIndex=0,this._frameRateTime=0,this._emissionTime=0,this._totalDelayTime=0,this._simulateUpdate=!1,this._bufferMaxParticles=1,this.duration=5,this.looping=!0,this.prewarm=!1,this.startDelayType=0,this.startDelay=0,this.startDelayMin=0,this.startDelayMax=0,this._startLifetimeType=0,this._startLifetimeConstant=5,this._startLifeTimeGradient=new Fr,this._startLifetimeConstantMin=0,this._startLifetimeConstantMax=5,this._startLifeTimeGradientMin=new Fr,this._startLifeTimeGradientMax=new Fr,this._maxStartLifetime=5,this.startSpeedType=0,this.startSpeedConstant=5,this.startSpeedConstantMin=0,this.startSpeedConstantMax=5,this.threeDStartSize=!1,this.startSizeType=0,this.startSizeConstant=1,this.startSizeConstantSeparate=new n(1,1,1),this.startSizeConstantMin=0,this.startSizeConstantMax=1,this.startSizeConstantMinSeparate=new n(0,0,0),this.startSizeConstantMaxSeparate=new n(1,1,1),this.threeDStartRotation=!1,this.startRotationType=0,this.startRotationConstant=0,this.startRotationConstantSeparate=new n(0,0,0),this.startRotationConstantMin=0,this.startRotationConstantMax=0,this.startRotationConstantMinSeparate=new n(0,0,0),this.startRotationConstantMaxSeparate=new n(0,0,0),this.gravityModifier=0,this.simulationSpace=1,this.scaleMode=1,this.playOnAwake=!0,this._rand=new ni(0),this.autoRandomSeed=!0,this.randomSeed=new Uint32Array(1),this._randomSeeds=new Uint32Array(li._RANDOMOFFSET.length),this.isPerformanceMode=!0,this._emission=new si,this._emission.enable=!0}get maxParticles(){return this._bufferMaxParticles-1}set maxParticles(e){var t=e+1;t!==this._bufferMaxParticles&&(this._bufferMaxParticles=t,this._initBufferDatas())}get emission(){return this._emission}get aliveParticleCount(){return this._firstNewElement>=this._firstRetiredElement?this._firstNewElement-this._firstRetiredElement:this._bufferMaxParticles-this._firstRetiredElement+this._firstNewElement}get emissionTime(){return this._emissionTime>this.duration?this.duration:this._emissionTime}get shape(){return this._shape}set shape(e){this._shape!==e&&(e&&e.enable?this._owner._render._shaderValues.addDefine($r.SHADERDEFINE_SHAPE):this._owner._render._shaderValues.removeDefine($r.SHADERDEFINE_SHAPE),this._shape=e)}get isAlive(){return!!(this._isPlaying||this.aliveParticleCount>0)}get isEmitting(){return this._isEmitting}get isPlaying(){return this._isPlaying}get isPaused(){return this._isPaused}get startLifetimeType(){return this._startLifetimeType}set startLifetimeType(e){var t,r;switch(this.startLifetimeType){case 0:this._maxStartLifetime=this.startLifetimeConstant;break;case 1:this._maxStartLifetime=-Number.MAX_VALUE;var i=i;for(t=0,r=i.gradientCount;t<r;t++)this._maxStartLifetime=Math.max(this._maxStartLifetime,i.getValueByIndex(t));break;case 2:this._maxStartLifetime=Math.max(this.startLifetimeConstantMin,this.startLifetimeConstantMax);break;case 3:this._maxStartLifetime=-Number.MAX_VALUE;var a=a;for(t=0,r=a.gradientCount;t<r;t++)this._maxStartLifetime=Math.max(this._maxStartLifetime,a.getValueByIndex(t));var n=n;for(t=0,r=n.gradientCount;t<r;t++)this._maxStartLifetime=Math.max(this._maxStartLifetime,n.getValueByIndex(t))}this._startLifetimeType=e}get startLifetimeConstant(){return this._startLifetimeConstant}set startLifetimeConstant(e){0===this._startLifetimeType&&(this._maxStartLifetime=e),this._startLifetimeConstant=e}get startLifeTimeGradient(){return this._startLifeTimeGradient}set startLifeTimeGradient(e){if(1===this._startLifetimeType){this._maxStartLifetime=-Number.MAX_VALUE;for(var t=0,r=e.gradientCount;t<r;t++)this._maxStartLifetime=Math.max(this._maxStartLifetime,e.getValueByIndex(t))}this._startLifeTimeGradient=e}get startLifetimeConstantMin(){return this._startLifetimeConstantMin}set startLifetimeConstantMin(e){2===this._startLifetimeType&&(this._maxStartLifetime=Math.max(e,this._startLifetimeConstantMax)),this._startLifetimeConstantMin=e}get startLifetimeConstantMax(){return this._startLifetimeConstantMax}set startLifetimeConstantMax(e){2===this._startLifetimeType&&(this._maxStartLifetime=Math.max(this._startLifetimeConstantMin,e)),this._startLifetimeConstantMax=e}get startLifeTimeGradientMin(){return this._startLifeTimeGradientMin}set startLifeTimeGradientMin(e){if(3===this._startLifetimeType){var t,r;for(this._maxStartLifetime=-Number.MAX_VALUE,t=0,r=e.gradientCount;t<r;t++)this._maxStartLifetime=Math.max(this._maxStartLifetime,e.getValueByIndex(t));for(t=0,r=this._startLifeTimeGradientMax.gradientCount;t<r;t++)this._maxStartLifetime=Math.max(this._maxStartLifetime,this._startLifeTimeGradientMax.getValueByIndex(t))}this._startLifeTimeGradientMin=e}get startLifeTimeGradientMax(){return this._startLifeTimeGradientMax}set startLifeTimeGradientMax(e){if(3===this._startLifetimeType){var t,r;for(this._maxStartLifetime=-Number.MAX_VALUE,t=0,r=this._startLifeTimeGradientMin.gradientCount;t<r;t++)this._maxStartLifetime=Math.max(this._maxStartLifetime,this._startLifeTimeGradientMin.getValueByIndex(t));for(t=0,r=e.gradientCount;t<r;t++)this._maxStartLifetime=Math.max(this._maxStartLifetime,e.getValueByIndex(t))}this._startLifeTimeGradientMax=e}get velocityOverLifetime(){return this._velocityOverLifetime}set velocityOverLifetime(e){var t=this._owner._render._shaderValues;if(e){var r=e.velocity,i=r.type;if(e.enable)switch(i){case 0:t.addDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT);break;case 1:t.addDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE);break;case 2:t.addDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT);break;case 3:t.addDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE)}else t.removeDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT),t.removeDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE),t.removeDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT),t.removeDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE);switch(i){case 0:t.setVector3($r.VOLVELOCITYCONST,r.constant);break;case 1:t.setBuffer($r.VOLVELOCITYGRADIENTX,r.gradientX._elements),t.setBuffer($r.VOLVELOCITYGRADIENTY,r.gradientY._elements),t.setBuffer($r.VOLVELOCITYGRADIENTZ,r.gradientZ._elements);break;case 2:t.setVector3($r.VOLVELOCITYCONST,r.constantMin),t.setVector3($r.VOLVELOCITYCONSTMAX,r.constantMax);break;case 3:t.setBuffer($r.VOLVELOCITYGRADIENTX,r.gradientXMin._elements),t.setBuffer($r.VOLVELOCITYGRADIENTXMAX,r.gradientXMax._elements),t.setBuffer($r.VOLVELOCITYGRADIENTY,r.gradientYMin._elements),t.setBuffer($r.VOLVELOCITYGRADIENTYMAX,r.gradientYMax._elements),t.setBuffer($r.VOLVELOCITYGRADIENTZ,r.gradientZMin._elements),t.setBuffer($r.VOLVELOCITYGRADIENTZMAX,r.gradientZMax._elements)}t.setInt($r.VOLSPACETYPE,e.space)}else t.removeDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT),t.removeDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE),t.removeDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT),t.removeDefine($r.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE);this._velocityOverLifetime=e}get colorOverLifetime(){return this._colorOverLifetime}set colorOverLifetime(e){var t=this._owner._render._shaderValues;if(e){var r=e.color;if(e.enable)switch(r.type){case 1:t.addDefine($r.SHADERDEFINE_COLOROVERLIFETIME);break;case 3:t.addDefine($r.SHADERDEFINE_RANDOMCOLOROVERLIFETIME)}else t.removeDefine($r.SHADERDEFINE_COLOROVERLIFETIME),t.removeDefine($r.SHADERDEFINE_RANDOMCOLOROVERLIFETIME);switch(r.type){case 1:var i=r.gradient;t.setBuffer($r.COLOROVERLIFEGRADIENTALPHAS,i._alphaElements),t.setBuffer($r.COLOROVERLIFEGRADIENTCOLORS,i._rgbElements);break;case 3:var a=r.gradientMin,n=r.gradientMax;t.setBuffer($r.COLOROVERLIFEGRADIENTALPHAS,a._alphaElements),t.setBuffer($r.COLOROVERLIFEGRADIENTCOLORS,a._rgbElements),t.setBuffer($r.MAXCOLOROVERLIFEGRADIENTALPHAS,n._alphaElements),t.setBuffer($r.MAXCOLOROVERLIFEGRADIENTCOLORS,n._rgbElements)}}else t.removeDefine($r.SHADERDEFINE_COLOROVERLIFETIME),t.removeDefine($r.SHADERDEFINE_RANDOMCOLOROVERLIFETIME),t.setBuffer($r.COLOROVERLIFEGRADIENTALPHAS,i._alphaElements),t.setBuffer($r.COLOROVERLIFEGRADIENTCOLORS,i._rgbElements),t.setBuffer($r.COLOROVERLIFEGRADIENTALPHAS,a._alphaElements),t.setBuffer($r.COLOROVERLIFEGRADIENTCOLORS,a._rgbElements),t.setBuffer($r.MAXCOLOROVERLIFEGRADIENTALPHAS,n._alphaElements),t.setBuffer($r.MAXCOLOROVERLIFEGRADIENTCOLORS,n._rgbElements);this._colorOverLifetime=e}get sizeOverLifetime(){return this._sizeOverLifetime}set sizeOverLifetime(e){var t=this._owner._render._shaderValues;if(e){var r=e.size,i=r.separateAxes,a=r.type;if(e.enable)switch(a){case 0:i?t.addDefine($r.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE):t.addDefine($r.SHADERDEFINE_SIZEOVERLIFETIMECURVE);break;case 2:i?t.addDefine($r.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE):t.addDefine($r.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES)}else t.removeDefine($r.SHADERDEFINE_SIZEOVERLIFETIMECURVE),t.removeDefine($r.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE),t.removeDefine($r.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES),t.removeDefine($r.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE);switch(a){case 0:i?(t.setBuffer($r.SOLSIZEGRADIENTX,r.gradientX._elements),t.setBuffer($r.SOLSIZEGRADIENTY,r.gradientY._elements),t.setBuffer($r.SOLSizeGradientZ,r.gradientZ._elements)):t.setBuffer($r.SOLSIZEGRADIENT,r.gradient._elements);break;case 2:i?(t.setBuffer($r.SOLSIZEGRADIENTX,r.gradientXMin._elements),t.setBuffer($r.SOLSIZEGRADIENTXMAX,r.gradientXMax._elements),t.setBuffer($r.SOLSIZEGRADIENTY,r.gradientYMin._elements),t.setBuffer($r.SOLSIZEGRADIENTYMAX,r.gradientYMax._elements),t.setBuffer($r.SOLSizeGradientZ,r.gradientZMin._elements),t.setBuffer($r.SOLSizeGradientZMAX,r.gradientZMax._elements)):(t.setBuffer($r.SOLSIZEGRADIENT,r.gradientMin._elements),t.setBuffer($r.SOLSizeGradientMax,r.gradientMax._elements))}}else t.removeDefine($r.SHADERDEFINE_SIZEOVERLIFETIMECURVE),t.removeDefine($r.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE),t.removeDefine($r.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES),t.removeDefine($r.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE);this._sizeOverLifetime=e}get rotationOverLifetime(){return this._rotationOverLifetime}set rotationOverLifetime(e){var t=this._owner._render._shaderValues;if(e){var r=e.angularVelocity;if(!r)return;var i=r.separateAxes,a=r.type;if(e.enable)switch(i?t.addDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE):t.addDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIME),a){case 0:t.addDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT);break;case 1:t.addDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE);break;case 2:t.addDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS);break;case 3:t.addDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES)}else t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIME),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES);switch(a){case 0:i?t.setVector3($r.ROLANGULARVELOCITYCONSTSEPRARATE,r.constantSeparate):t.setNumber($r.ROLANGULARVELOCITYCONST,r.constant);break;case 1:i?(t.setBuffer($r.ROLANGULARVELOCITYGRADIENTX,r.gradientX._elements),t.setBuffer($r.ROLANGULARVELOCITYGRADIENTY,r.gradientY._elements),t.setBuffer($r.ROLANGULARVELOCITYGRADIENTZ,r.gradientZ._elements)):t.setBuffer($r.ROLANGULARVELOCITYGRADIENT,r.gradient._elements);break;case 2:i?(t.setVector3($r.ROLANGULARVELOCITYCONSTSEPRARATE,r.constantMinSeparate),t.setVector3($r.ROLANGULARVELOCITYCONSTMAXSEPRARATE,r.constantMaxSeparate)):(t.setNumber($r.ROLANGULARVELOCITYCONST,r.constantMin),t.setNumber($r.ROLANGULARVELOCITYCONSTMAX,r.constantMax));break;case 3:i?(t.setBuffer($r.ROLANGULARVELOCITYGRADIENTX,r.gradientXMin._elements),t.setBuffer($r.ROLANGULARVELOCITYGRADIENTXMAX,r.gradientXMax._elements),t.setBuffer($r.ROLANGULARVELOCITYGRADIENTY,r.gradientYMin._elements),t.setBuffer($r.ROLANGULARVELOCITYGRADIENTYMAX,r.gradientYMax._elements),t.setBuffer($r.ROLANGULARVELOCITYGRADIENTZ,r.gradientZMin._elements),t.setBuffer($r.ROLANGULARVELOCITYGRADIENTZMAX,r.gradientZMax._elements)):(t.setBuffer($r.ROLANGULARVELOCITYGRADIENT,r.gradientMin._elements),t.setBuffer($r.ROLANGULARVELOCITYGRADIENTMAX,r.gradientMax._elements))}}else t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIME),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS),t.removeDefine($r.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES);this._rotationOverLifetime=e}get textureSheetAnimation(){return this._textureSheetAnimation}set textureSheetAnimation(e){var t=this._owner._render._shaderValues;if(e){var r=e.frame,i=r.type;if(e.enable)switch(i){case 1:t.addDefine($r.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE);break;case 3:t.addDefine($r.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE)}else t.removeDefine($r.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE),t.removeDefine($r.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE);if(1===i||3===i){t.setNumber($r.TEXTURESHEETANIMATIONCYCLES,e.cycles);var a=e.tiles,n=this._uvLength;n.x=1/a.x,n.y=1/a.y,t.setVector2($r.TEXTURESHEETANIMATIONSUBUVLENGTH,this._uvLength)}switch(i){case 1:t.setBuffer($r.TEXTURESHEETANIMATIONGRADIENTUVS,r.frameOverTimeData._elements);break;case 3:t.setBuffer($r.TEXTURESHEETANIMATIONGRADIENTUVS,r.frameOverTimeDataMin._elements),t.setBuffer($r.TEXTURESHEETANIMATIONGRADIENTMAXUVS,r.frameOverTimeDataMax._elements)}}else t.removeDefine($r.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE),t.removeDefine($r.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE);this._textureSheetAnimation=e}_getVertexBuffer(e=0){return 0===e?this._vertexBuffer:null}_getIndexBuffer(){return this._indexBuffer}_generateBoundingSphere(){var e=this._boundingSphere.center;e.x=0,e.y=0,e.z=0,this._boundingSphere.radius=Number.MAX_VALUE}_generateBoundingBox(){var e,t,r,i,a,s,o,l,_,h=this._owner.particleRenderer,c=this._boundingBox.min,d=this._boundingBox.max;switch(this.startLifetimeType){case 0:r=this.startLifetimeConstant;break;case 1:r=-Number.MAX_VALUE;var u=u;for(e=0,t=u.gradientCount;e<t;e++)r=Math.max(r,u.getValueByIndex(e));break;case 2:r=Math.max(this.startLifetimeConstantMin,this.startLifetimeConstantMax);break;case 3:r=-Number.MAX_VALUE;var m=m;for(e=0,t=m.gradientCount;e<t;e++)r=Math.max(r,m.getValueByIndex(e));var f=f;for(e=0,t=f.gradientCount;e<t;e++)r=Math.max(r,f.getValueByIndex(e))}switch(this.startSpeedType){case 0:i=a=this.startSpeedConstant;break;case 1:break;case 2:i=this.startLifetimeConstantMin,a=this.startLifetimeConstantMax}this._shape&&this._shape.enable||(s=o=n._ZERO,l=n._ZERO,_=n._UnitZ);var T,E,p=new n(l.x*i,l.y*i,l.z*i),g=new n(_.x*a,_.y*a,_.z*a);if(this._velocityOverLifetime&&this._velocityOverLifetime.enable){var S=this._velocityOverLifetime.velocity;switch(S.type){case 0:S.constant;break;case 1:new n(S.gradientX.getAverageValue(),S.gradientY.getAverageValue(),S.gradientZ.getAverageValue());break;case 2:S.constantMin,S.constantMax;break;case 3:new n(S.gradientXMin.getAverageValue(),S.gradientYMin.getAverageValue(),S.gradientZMin.getAverageValue()),new n(S.gradientXMax.getAverageValue(),S.gradientYMax.getAverageValue(),S.gradientZMax.getAverageValue())}}var R,v,x,A,I=this._owner.transform,M=I.position,D=li._tempVector39,C=h.renderMode;switch(this.scaleMode){case 0:var y=I.getWorldLossyScale();T=y,D.x=y.x,D.y=y.z,D.z=y.y,1===C&&(E=y);break;case 1:var L=I.localScale;T=L,D.x=L.x,D.y=L.z,D.z=L.y,1===C&&(E=L);break;case 2:T=I.getWorldLossyScale(),D.x=D.y=D.z=1,1===C&&(E=n._ONE)}switch(this._velocityOverLifetime&&this._velocityOverLifetime.enable||(R=new n(p.x*r,p.y*r,p.z*r),v=new n(g.x*r,g.y*r,g.z*r),2!=this.scaleMode?(n.add(s,R,c),n.multiply(T,c,c),n.add(o,v,d),n.multiply(T,d,d)):(n.multiply(T,s,c),n.add(c,R,c),n.multiply(T,o,d),n.add(d,v,d))),this.simulationSpace){case 0:break;case 1:n.add(c,M,c),n.add(d,M,d)}switch(this.startSizeType){case 0:if(this.threeDStartSize){var O=O;x=Math.max(O.x,O.y),1===C&&(A=O.y)}else x=this.startSizeConstant,1===C&&(A=this.startSizeConstant);break;case 1:break;case 2:if(this.threeDStartSize){var N=N;x=Math.max(N.x,N.y),1===C&&(A=N.y)}else x=this.startSizeConstantMax,1===C&&(A=this.startSizeConstantMax)}if(this._sizeOverLifetime&&this._sizeOverLifetime.enable){this._sizeOverLifetime.size;x*=this._sizeOverLifetime.size.getMaxSizeInGradient()}var P,b,w=li._tempVector30;switch(C){case 0:P=x*li.halfKSqrtOf2,n.scale(D,x,w),n.subtract(c,w,c),n.add(d,w,d);break;case 1:var V=li._tempVector31,B=li._tempVector32,F=li._tempVector33,U=li._tempVector34;this._velocityOverLifetime&&this._velocityOverLifetime.enable||(n.multiply(E,g,B),n.multiply(E,p,F));var G=A*h.stretchedBillboardLengthScale,z=n.scalarLength(B)*h.stretchedBillboardSpeedScale+G,H=n.scalarLength(F)*h.stretchedBillboardSpeedScale+G,k=li._tempVector35,W=li._tempVector36;n.normalize(B,k),n.scale(k,z,U),n.subtract(v,U,U),n.normalize(F,W),n.scale(W,H,V),n.add(R,V,V),P=x*li.halfKSqrtOf2,n.scale(D,P,w);var X=li._tempVector37,Y=li._tempVector38;n.scale(k,.5,X),n.scale(W,.5,Y),n.multiply(X,D,X),n.multiply(Y,D,Y),n.add(c,Y,c),n.min(c,U,c),n.subtract(c,w,c),n.subtract(d,X,d),n.max(d,V,d),n.add(d,w,d);break;case 2:b=.5*(x*=Math.cos(.7853981633974483)),w.x=D.x*b,w.y=D.z*b,n.subtract(c,w,c),n.add(d,w,d);break;case 3:b=.5*(x*=Math.cos(.7853981633974483)),n.scale(D,b,w),n.subtract(c,w,c),n.add(d,w,d)}this._boundingBox.getCorners(this._boundingBoxCorners)}_generateBounds(){var t=this._owner.particleRenderer,r=this._bounds.getMin(),i=this._bounds.getMax(),a=0;switch(this.startLifetimeType){case 0:a=this._startLifetimeConstant;break;case 2:a=this._startLifetimeConstantMax}var s=0;switch(this.startSpeedType){case 0:s=this.startSpeedConstant;break;case 2:s=this.startSpeedConstantMax}var o=0;if(this.threeDStartSize)switch(this.startSizeType){case 0:o=Math.max(this.startSizeConstantSeparate.x,this.startSizeConstantSeparate.y,this.startSizeConstantSeparate.z);break;case 2:o=Math.max(this.startSizeConstantMaxSeparate.x,this.startSizeConstantMaxSeparate.y,this.startSizeConstantMaxSeparate.z)}else switch(this.startSizeType){case 0:o=this.startSizeConstant;break;case 2:o=this.startSizeConstantMax}var l=li._tempVector30,_=li._tempVector31,h=li._tempVector32,c=li._tempVector33;if(l.setValue(0,0,1),_.setValue(0,0,0),h.setValue(0,0,0),c.setValue(0,0,0),this.shape&&this.shape.enable)switch(this.shape.shapeType){case e.ParticleSystemShapeType.Sphere:var d=this.shape;l.setValue(1,1,1),_.setValue(1,1,1),h.setValue(d.radius,d.radius,d.radius),c.setValue(d.radius,d.radius,d.radius);break;case e.ParticleSystemShapeType.Hemisphere:var u=this.shape;l.setValue(1,1,1),_.setValue(1,1,1),h.setValue(u.radius,u.radius,u.radius),c.setValue(u.radius,u.radius,0);break;case e.ParticleSystemShapeType.Cone:var m=this.shape;if(0==m.emitType||1==m.emitType){var f=m.angle,T=Math.sin(f);l.setValue(T,T,1),_.setValue(T,T,0),h.setValue(m.radius,m.radius,0),c.setValue(m.radius,m.radius,0);break}if(2==m.emitType||3==m.emitType){f=m.angle,T=Math.sin(f);var E=m.length;l.setValue(T,T,1),_.setValue(T,T,0);var p=Math.tan(f),g=m.radius+E*p;h.setValue(g,g,E),c.setValue(g,g,0)}break;case e.ParticleSystemShapeType.Box:var S=this.shape;0!=this.shape.randomDirection&&(l.setValue(1,1,1),_.setValue(1,1,1)),h.setValue(S.x/2,S.y/2,S.z/2),c.setValue(S.x/2,S.y/2,S.z/2);break;case e.ParticleSystemShapeType.Circle:var R=this.shape;l.setValue(1,1,1),_.setValue(1,1,1),h.setValue(R.radius,R.radius,0),c.setValue(R.radius,R.radius,0)}var v=0,x=4==t.renderMode;switch(t.renderMode){case 0:case 1:case 2:case 3:v=li.halfKSqrtOf2;break;case 4:var A=t.mesh.bounds;v=Math.sqrt(Math.pow(A.getExtent().x,2)+Math.pow(A.getExtent().y,2)+Math.pow(A.getExtent().z,2))}var I=li._tempVector36;if(I.setValue(1,1,1),this.sizeOverLifetime&&this.sizeOverLifetime.enable){var M=this.sizeOverLifetime.size.getMaxSizeInGradient(x);I.setValue(M,M,M)}var D=v*o;n.scale(I,D,I);var C=li._tempVector34,y=li._tempVector35;if(s>0?(n.scale(l,s,C),n.scale(_,s,y)):(n.scale(l,-s,y),n.scale(_,-s,C)),this.velocityOverLifetime&&this.velocityOverLifetime.enable){var L=this.velocityOverLifetime.velocity,O=li._tempVector37;switch(O.setValue(0,0,0),L.type){case 0:L.constant.cloneTo(O);break;case 2:L.constantMax.cloneTo(O);break;case 1:var N=L.gradientX.getAverageValue(),P=L.gradientY.getAverageValue(),b=L.gradientZ.getAverageValue();O.setValue(N,P,b);break;case 3:var w=L.gradientXMax.getAverageValue(),V=L.gradientYMax.getAverageValue(),B=L.gradientZMax.getAverageValue();O.setValue(w,V,B)}1==this.velocityOverLifetime.space&&n.transformV3ToV3(O,this._owner.transform.worldMatrix,O),n.add(C,O,C),n.subtract(y,O,y),n.max(C,n._ZERO,C),n.max(y,n._ZERO,y)}n.scale(C,a,C),n.scale(y,a,y);var F=this.gravityModifier;if(0!=F){var U=.5*li.g*F*a*a,G=C.y-U,z=y.y+U;G=G>0?G:0,z=z>0?z:0,this._gravityOffset.setValue(C.y-G,z-y.y)}n.add(C,I,i),n.add(i,h,i),n.add(y,I,r),n.add(r,c,r),n.scale(r,-1,r),this._bounds.setMin(r),this._bounds.setMax(i)}get customBounds(){return this._customBounds}set customBounds(e){this._useCustomBounds=!!e,this._customBounds=e}_simulationSupported(){return 0!=this.simulationSpace}_updateEmission(){if(this.isAlive)if(this._simulateUpdate)this._simulateUpdate=!1;else{var e=this._startUpdateLoopCount===t.Stat.loopCount||this._isPaused?0:this._owner._scene.timer._delta/1e3;e=Math.min(li._maxElapsedTime,e*this.simulationSpeed),this._updateParticles(e)}}_updateParticles(e){(4!==this._ownerRender.renderMode||this._ownerRender.mesh)&&(this._currentTime+=e,this._retireActiveParticles(),this._freeRetiredParticles(),this._totalDelayTime+=e,this._totalDelayTime<this._playStartDelay||this._emission.enable&&this._isEmitting&&!this._isPaused&&this._advanceTime(e,this._currentTime))}_updateParticlesSimulationRestart(e){this._firstActiveElement=0,this._firstNewElement=0,this._firstFreeElement=0,this._firstRetiredElement=0,this._burstsIndex=0,this._frameRateTime=e,this._emissionTime=0,this._totalDelayTime=0,this._currentTime=e;var t=e;t<this._playStartDelay?this._totalDelayTime=t:this._emission.enable&&this._advanceTime(e,e)}_retireActiveParticles(){for(;this._firstActiveElement!=this._firstNewElement;){var e=this._firstActiveElement*this._floatCountPerVertex*this._vertexStride,t=e+this._timeIndex;if(this._currentTime-this._vertices[t]+1e-4<this._vertices[e+this._startLifeTimeIndex])break;this._vertices[t]=this._drawCounter,this._firstActiveElement++,this._firstActiveElement>=this._bufferMaxParticles&&(this._firstActiveElement=0)}}_freeRetiredParticles(){for(;this._firstRetiredElement!=this._firstActiveElement;){this._drawCounter,this._vertices[this._firstRetiredElement*this._floatCountPerVertex*this._vertexStride+this._timeIndex];this._firstRetiredElement++,this._firstRetiredElement>=this._bufferMaxParticles&&(this._firstRetiredElement=0)}}_burst(e,r){for(var i=0,a=this._emission._bursts,n=a.length;this._burstsIndex<n;this._burstsIndex++){var s,o=a[this._burstsIndex],l=o.time;if(!(e<=l&&l<r))break;this.autoRandomSeed?s=t.MathUtil.lerp(o.minCount,o.maxCount,Math.random()):(this._rand.seed=this._randomSeeds[0],s=t.MathUtil.lerp(o.minCount,o.maxCount,this._rand.getFloat()),this._randomSeeds[0]=this._rand.seed),i+=s}return i}_advanceTime(e,t){var r,i=this._emissionTime;this._emissionTime+=e;var a=0;if(this._emissionTime>this.duration){if(!this.looping){for(a=Math.min(this.maxParticles-this.aliveParticleCount,a),r=0;r<a;r++)this.emit(t);return this._isPlaying=!1,void this.stop()}a+=this._burst(i,this._emissionTime),this._emissionTime-=this.duration,this._burstsIndex=0,a+=this._burst(0,this._emissionTime)}else a+=this._burst(i,this._emissionTime);for(a=Math.min(this.maxParticles-this.aliveParticleCount,a),r=0;r<a;r++)this.emit(t);var n=this.emission.emissionRate;if(n>0){var s=1/n;for(this._frameRateTime+=s,this._frameRateTime=this._currentTime-(this._currentTime-this._frameRateTime)%this._maxStartLifetime;this._frameRateTime<=t&&this.emit(this._frameRateTime);)this._frameRateTime+=s;this._frameRateTime=Math.floor(t/s)*s}}_initBufferDatas(){if(this._vertexBuffer){var r=this._vertexBuffer._byteLength+2*this._indexBuffer.indexCount;this._vertexBuffer.destroy(),this._indexBuffer.destroy(),t.Resource._addMemory(-r,-r)}var i=t.LayaGL.instance,a=this._ownerRender,n=a.renderMode;if(-1!==n&&this.maxParticles>0){var s,o,l,_,h,c,d,u=0,m=(r=0,a.mesh);if(4===n){if(m){d=ai.vertexDeclaration,this._floatCountPerVertex=d.vertexStride/4,this._startLifeTimeIndex=12,this._timeIndex=16,this._vertexStride=m._vertexCount;var f=this._bufferMaxParticles*this._vertexStride,T=f%65535;if(Math.floor(f/65535)+1>1)throw new Error("ShurikenParticleSystem:the maxParticleCount multiply mesh vertexCount is large than 65535.");u=d.vertexStride*T,this._vertexBuffer=new de(u,i.DYNAMIC_DRAW),this._vertexBuffer.vertexDeclaration=d,this._vertices=new Float32Array(this._floatCountPerVertex*T),this._indexStride=m._indexBuffer.indexCount;var E=m._indexBuffer.getData(),p=this._bufferMaxParticles*this._indexStride;for(this._indexBuffer=new Ge(e.IndexFormat.UInt16,p,i.STATIC_DRAW),s=new Uint16Array(p),r=u+2*p,h=0,o=0;o<this._bufferMaxParticles;o++){var g=o*this._vertexStride;for(l=0,_=E.length;l<_;l++)s[h++]=g+E[l]}this._indexBuffer.setData(s),this._bufferState.bind(),this._bufferState.applyVertexBuffer(this._vertexBuffer),this._bufferState.applyIndexBuffer(this._indexBuffer),this._bufferState.unBind()}}else{for(d=ii.vertexDeclaration,this._floatCountPerVertex=d.vertexStride/4,this._startLifeTimeIndex=7,this._timeIndex=11,this._vertexStride=4,u=d.vertexStride*this._bufferMaxParticles*this._vertexStride,this._vertexBuffer=new de(u,i.DYNAMIC_DRAW),this._vertexBuffer.vertexDeclaration=d,this._vertices=new Float32Array(this._floatCountPerVertex*this._bufferMaxParticles*this._vertexStride),o=0;o<this._bufferMaxParticles;o++)c=o*this._floatCountPerVertex*this._vertexStride,this._vertices[c]=-.5,this._vertices[c+1]=-.5,this._vertices[c+2]=0,this._vertices[c+3]=1,c+=this._floatCountPerVertex,this._vertices[c]=.5,this._vertices[c+1]=-.5,this._vertices[c+2]=1,this._vertices[c+3]=1,c+=this._floatCountPerVertex,this._vertices[c]=.5,this._vertices[c+1]=.5,this._vertices[c+2]=1,this._vertices[c+3]=0,c+=this._floatCountPerVertex,this._vertices[c]=-.5,this._vertices[c+1]=.5,this._vertices[c+2]=0,this._vertices[c+3]=0;for(this._indexStride=6,this._indexBuffer=new Ge(e.IndexFormat.UInt16,6*this._bufferMaxParticles,i.STATIC_DRAW),s=new Uint16Array(6*this._bufferMaxParticles),o=0;o<this._bufferMaxParticles;o++){h=6*o;var S=o*this._vertexStride,R=S+2;s[h++]=S,s[h++]=R,s[h++]=S+1,s[h++]=S,s[h++]=S+3,s[h++]=R}this._indexBuffer.setData(s),r=u+6*this._bufferMaxParticles*2,this._bufferState.bind(),this._bufferState.applyVertexBuffer(this._vertexBuffer),this._bufferState.applyIndexBuffer(this._indexBuffer),this._bufferState.unBind()}t.Resource._addMemory(r,r)}}destroy(){super.destroy();var e=this._vertexBuffer._byteLength+2*this._indexBuffer.indexCount;t.Resource._addMemory(-e,-e),this._bufferState.destroy(),this._vertexBuffer.destroy(),this._indexBuffer.destroy(),this._emission.destroy(),this._boundingBox=null,this._boundingSphere=null,this._boundingBoxCorners=null,this._bounds=null,this._customBounds=null,this._bufferState=null,this._vertexBuffer=null,this._indexBuffer=null,this._owner=null,this._vertices=null,this._indexBuffer=null,this._emission=null,this._shape=null,this.startLifeTimeGradient=null,this.startLifeTimeGradientMin=null,this.startLifeTimeGradientMax=null,this.startSizeConstantSeparate=null,this.startSizeConstantMinSeparate=null,this.startSizeConstantMaxSeparate=null,this.startRotationConstantSeparate=null,this.startRotationConstantMinSeparate=null,this.startRotationConstantMaxSeparate=null,this.startColorConstant=null,this.startColorConstantMin=null,this.startColorConstantMax=null,this._velocityOverLifetime=null,this._colorOverLifetime=null,this._sizeOverLifetime=null,this._rotationOverLifetime=null,this._textureSheetAnimation=null}emit(e){var t=li._tempPosition,r=li._tempDirection;return this._shape&&this._shape.enable?this.autoRandomSeed?this._shape.generatePositionAndDirection(t,r):this._shape.generatePositionAndDirection(t,r,this._rand,this._randomSeeds):(t.x=t.y=t.z=0,r.x=r.y=0,r.z=1),this.addParticle(t,r,e)}addParticle(e,r,i){n.normalize(r,r);var a=this._firstFreeElement+1;if(a>=this._bufferMaxParticles&&(a=0),a===this._firstRetiredElement)return!1;var s,o,l,_,h,c,d,u,m,f,T=this._owner.transform;if(oi.create(this,this._ownerRender,T),this._currentTime-i>=oi.startLifeTime)return!0;switch(0==this.simulationSpace&&(s=T.position,o=T.rotation),this.startSpeedType){case 0:l=this.startSpeedConstant;break;case 2:this.autoRandomSeed?l=t.MathUtil.lerp(this.startSpeedConstantMin,this.startSpeedConstantMax,Math.random()):(this._rand.seed=this._randomSeeds[8],l=t.MathUtil.lerp(this.startSpeedConstantMin,this.startSpeedConstantMax,this._rand.getFloat()),this._randomSeeds[8]=this._rand.seed)}var E=this._velocityOverLifetime&&this._velocityOverLifetime.enable;if(E){var p=this._velocityOverLifetime.velocity.type;2===p||3===p?this.autoRandomSeed?(_=Math.random(),h=Math.random(),c=Math.random()):(this._rand.seed=this._randomSeeds[9],_=this._rand.getFloat(),h=this._rand.getFloat(),c=this._rand.getFloat(),this._randomSeeds[9]=this._rand.seed):E=!1}else E=!1;var g=this._colorOverLifetime&&this._colorOverLifetime.enable;g?3===this._colorOverLifetime.color.type?this.autoRandomSeed?d=Math.random():(this._rand.seed=this._randomSeeds[10],d=this._rand.getFloat(),this._randomSeeds[10]=this._rand.seed):g=!1:g=!1;var S=this._sizeOverLifetime&&this._sizeOverLifetime.enable;S?3===this._sizeOverLifetime.size.type?this.autoRandomSeed?u=Math.random():(this._rand.seed=this._randomSeeds[11],u=this._rand.getFloat(),this._randomSeeds[11]=this._rand.seed):S=!1:S=!1;var R=this._rotationOverLifetime&&this._rotationOverLifetime.enable;if(R){var v=this._rotationOverLifetime.angularVelocity.type;2===v||3===v?this.autoRandomSeed?m=Math.random():(this._rand.seed=this._randomSeeds[12],m=this._rand.getFloat(),this._randomSeeds[12]=this._rand.seed):R=!1}else R=!1;var x=this._textureSheetAnimation&&this._textureSheetAnimation.enable;x?3===this._textureSheetAnimation.frame.type?this.autoRandomSeed?f=Math.random():(this._rand.seed=this._randomSeeds[15],f=this._rand.getFloat(),this._randomSeeds[15]=this._rand.seed):x=!1:x=!1;var A,I,M,D,C,y,L=this._firstFreeElement*this._floatCountPerVertex*this._vertexStride,O=oi.startUVInfo[0],N=oi.startUVInfo[1],P=oi.startUVInfo[2],b=oi.startUVInfo[3],w=this._ownerRender;if(4===w.renderMode){var V=w.mesh._vertexBuffer;A=V.getFloat32Data();var B=V.vertexDeclaration;M=B.getVertexElementByUsage(ze.MESH_POSITION0)._offset/4;var F=B.getVertexElementByUsage(ze.MESH_COLOR0);D=F?F._offset/4:-1;var U=B.getVertexElementByUsage(ze.MESH_TEXTURECOORDINATE0);C=U?U._offset/4:-1,I=B.vertexStride/4,y=0}else{this._vertices[L+2]=P,this._vertices[L+3]=b+N;var G=L+this._floatCountPerVertex;this._vertices[G+2]=P+O,this._vertices[G+3]=b+N;var z=G+this._floatCountPerVertex;this._vertices[z+2]=P+O,this._vertices[z+3]=b;var H=z+this._floatCountPerVertex;this._vertices[H+2]=P,this._vertices[H+3]=b}for(var k=L,W=L+this._floatCountPerVertex*this._vertexStride;k<W;k+=this._floatCountPerVertex){var X;if(4===w.renderMode){X=k;var Y=I*y++,j=Y+M;this._vertices[X++]=A[j++],this._vertices[X++]=A[j++],this._vertices[X++]=A[j],-1===D?(this._vertices[X++]=1,this._vertices[X++]=1,this._vertices[X++]=1,this._vertices[X++]=1):(j=Y+D,this._vertices[X++]=A[j++],this._vertices[X++]=A[j++],this._vertices[X++]=A[j++],this._vertices[X++]=A[j]),-1===C?(this._vertices[X++]=0,this._vertices[X++]=0):(j=Y+C,this._vertices[X++]=P+A[j++]*O,this._vertices[X++]=b+A[j]*N)}else X=k+4;switch(this._vertices[X++]=e.x,this._vertices[X++]=e.y,this._vertices[X++]=e.z,this._vertices[X++]=oi.startLifeTime,this._vertices[X++]=r.x,this._vertices[X++]=r.y,this._vertices[X++]=r.z,this._vertices[X++]=i,this._vertices[X++]=oi.startColor.x,this._vertices[X++]=oi.startColor.y,this._vertices[X++]=oi.startColor.z,this._vertices[X++]=oi.startColor.w,this._vertices[X++]=oi.startSize[0],this._vertices[X++]=oi.startSize[1],this._vertices[X++]=oi.startSize[2],this._vertices[X++]=oi.startRotation[0],this._vertices[X++]=oi.startRotation[1],this._vertices[X++]=oi.startRotation[2],this._vertices[X++]=l,g&&(this._vertices[X+1]=d),S&&(this._vertices[X+2]=u),R&&(this._vertices[X+3]=m),x&&(this._vertices[X+4]=f),E&&(this._vertices[X+5]=_,this._vertices[X+6]=h,this._vertices[X+7]=c),this.simulationSpace){case 0:X+=8,this._vertices[X++]=s.x,this._vertices[X++]=s.y,this._vertices[X++]=s.z,this._vertices[X++]=o.x,this._vertices[X++]=o.y,this._vertices[X++]=o.z,this._vertices[X++]=o.w;break;case 1:break;default:throw new Error("ShurikenParticleMaterial: SimulationSpace value is invalid.")}}return this._firstFreeElement=a,!0}addNewParticlesToVertexBuffer(){var e,t=this._vertexStride*this._floatCountPerVertex*4;this._firstNewElement<this._firstFreeElement?(e=this._firstNewElement*t,this._vertexBuffer.setData(this._vertices.buffer,e,e,(this._firstFreeElement-this._firstNewElement)*t)):(e=this._firstNewElement*t,this._vertexBuffer.setData(this._vertices.buffer,e,e,(this._bufferMaxParticles-this._firstNewElement)*t),this._firstFreeElement>0&&this._vertexBuffer.setData(this._vertices.buffer,0,0,this._firstFreeElement*t)),this._firstNewElement=this._firstFreeElement}_getType(){return li._type}_prepareRender(e){return this._updateMask!=t.Stat.loopCount&&(this._updateMask=t.Stat.loopCount,this._updateEmission(),this._firstNewElement!=this._firstFreeElement&&this.addNewParticlesToVertexBuffer(),this._drawCounter++),this._firstActiveElement!=this._firstFreeElement}_render(e){var r;this._bufferState.bind();var i=t.LayaGL.instance;this._firstActiveElement<this._firstFreeElement?(r=(this._firstFreeElement-this._firstActiveElement)*this._indexStride,i.drawElements(i.TRIANGLES,r,i.UNSIGNED_SHORT,2*this._firstActiveElement*this._indexStride),t.Stat.trianglesFaces+=r/3,t.Stat.renderBatches++):(r=(this._bufferMaxParticles-this._firstActiveElement)*this._indexStride,i.drawElements(i.TRIANGLES,r,i.UNSIGNED_SHORT,2*this._firstActiveElement*this._indexStride),t.Stat.trianglesFaces+=r/3,t.Stat.renderBatches++,this._firstFreeElement>0&&(r=this._firstFreeElement*this._indexStride,i.drawElements(i.TRIANGLES,r,i.UNSIGNED_SHORT,0),t.Stat.trianglesFaces+=r/3,t.Stat.renderBatches++))}play(){if(this._burstsIndex=0,this._isEmitting=!0,this._isPlaying=!0,this._isPaused=!1,this._emissionTime=0,this._totalDelayTime=0,!this.autoRandomSeed)for(var e=0,r=this._randomSeeds.length;e<r;e++)this._randomSeeds[e]=this.randomSeed[0]+li._RANDOMOFFSET[e];switch(this.startDelayType){case 0:this._playStartDelay=this.startDelay;break;case 1:this.autoRandomSeed?this._playStartDelay=t.MathUtil.lerp(this.startDelayMin,this.startDelayMax,Math.random()):(this._rand.seed=this._randomSeeds[2],this._playStartDelay=t.MathUtil.lerp(this.startDelayMin,this.startDelayMax,this._rand.getFloat()),this._randomSeeds[2]=this._rand.seed);break;default:throw new Error("Utils3D: startDelayType is invalid.")}this._frameRateTime=this._currentTime+this._playStartDelay,this._startUpdateLoopCount=t.Stat.loopCount}pause(){this._isPaused=!0}simulate(e,t=!0){this._simulateUpdate=!0,t?this._updateParticlesSimulationRestart(e):(this._isPaused=!1,this._updateParticles(e)),this.pause()}stop(){this._burstsIndex=0,this._isEmitting=!1,this._emissionTime=0}cloneTo(e){var t=e;t._useCustomBounds=this._useCustomBounds,this._customBounds&&this._customBounds.cloneTo(t._customBounds),t.duration=this.duration,t.looping=this.looping,t.prewarm=this.prewarm,t.startDelayType=this.startDelayType,t.startDelay=this.startDelay,t.startDelayMin=this.startDelayMin,t.startDelayMax=this.startDelayMax,t._maxStartLifetime=this._maxStartLifetime,t.startLifetimeType=this.startLifetimeType,t.startLifetimeConstant=this.startLifetimeConstant,this.startLifeTimeGradient.cloneTo(t.startLifeTimeGradient),t.startLifetimeConstantMin=this.startLifetimeConstantMin,t.startLifetimeConstantMax=this.startLifetimeConstantMax,this.startLifeTimeGradientMin.cloneTo(t.startLifeTimeGradientMin),this.startLifeTimeGradientMax.cloneTo(t.startLifeTimeGradientMax),t.startSpeedType=this.startSpeedType,t.startSpeedConstant=this.startSpeedConstant,t.startSpeedConstantMin=this.startSpeedConstantMin,t.startSpeedConstantMax=this.startSpeedConstantMax,t.threeDStartSize=this.threeDStartSize,t.startSizeType=this.startSizeType,t.startSizeConstant=this.startSizeConstant,this.startSizeConstantSeparate.cloneTo(t.startSizeConstantSeparate),t.startSizeConstantMin=this.startSizeConstantMin,t.startSizeConstantMax=this.startSizeConstantMax,this.startSizeConstantMinSeparate.cloneTo(t.startSizeConstantMinSeparate),this.startSizeConstantMaxSeparate.cloneTo(t.startSizeConstantMaxSeparate),t.threeDStartRotation=this.threeDStartRotation,t.startRotationType=this.startRotationType,t.startRotationConstant=this.startRotationConstant,this.startRotationConstantSeparate.cloneTo(t.startRotationConstantSeparate),t.startRotationConstantMin=this.startRotationConstantMin,t.startRotationConstantMax=this.startRotationConstantMax,this.startRotationConstantMinSeparate.cloneTo(t.startRotationConstantMinSeparate),this.startRotationConstantMaxSeparate.cloneTo(t.startRotationConstantMaxSeparate),t.randomizeRotationDirection=this.randomizeRotationDirection,t.startColorType=this.startColorType,this.startColorConstant.cloneTo(t.startColorConstant),this.startColorConstantMin.cloneTo(t.startColorConstantMin),this.startColorConstantMax.cloneTo(t.startColorConstantMax),t.gravityModifier=this.gravityModifier,t.simulationSpace=this.simulationSpace,t.scaleMode=this.scaleMode,t.playOnAwake=this.playOnAwake,t.autoRandomSeed=this.autoRandomSeed,t.randomSeed[0]=this.randomSeed[0],t.maxParticles=this.maxParticles,this._emission&&(t._emission=this._emission.clone()),this.shape&&(t.shape=this.shape.clone()),this.velocityOverLifetime&&(t.velocityOverLifetime=this.velocityOverLifetime.clone()),this.colorOverLifetime&&(t.colorOverLifetime=this.colorOverLifetime.clone()),this.sizeOverLifetime&&(t.sizeOverLifetime=this.sizeOverLifetime.clone()),this.rotationOverLifetime&&(t.rotationOverLifetime=this.rotationOverLifetime.clone()),this.textureSheetAnimation&&(t.textureSheetAnimation=this.textureSheetAnimation.clone()),t.isPerformanceMode=this.isPerformanceMode,t._isEmitting=this._isEmitting,t._isPlaying=this._isPlaying,t._isPaused=this._isPaused,t._playStartDelay=this._playStartDelay,t._frameRateTime=this._frameRateTime,t._emissionTime=this._emissionTime,t._totalDelayTime=this._totalDelayTime,t._burstsIndex=this._burstsIndex}clone(){var e=new li(null);return this.cloneTo(e),e}}li._RANDOMOFFSET=new Uint32Array([592910910,3276756734,322376503,306581307,1793934638,3737431713,2527743459,2368504881,4085612399,3774601268,326370691,1494990940,1089181156,3159510623,2941263940,2786374529,271901988,4233252447]),li.halfKSqrtOf2=.71,li.g=9.8,li._maxElapsedTime=1/3,li._tempVector30=new n,li._tempVector31=new n,li._tempVector32=new n,li._tempVector33=new n,li._tempVector34=new n,li._tempVector35=new n,li._tempVector36=new n,li._tempVector37=new n,li._tempVector38=new n,li._tempVector39=new n,li._tempPosition=new n,li._tempDirection=new n,li._type=Gt._typeCounter++;class _i extends kt{constructor(){super(null),this._render=new ti(this),this._particleSystem=new li(this);var e=this._render._renderElements[0]=new Ke;e.setTransform(this._transform),e.render=this._render,e.setGeometry(this._particleSystem),e.material=ei.defaultMaterial}static __init__(){$r.SHADERDEFINE_RENDERMODE_BILLBOARD=xe.getDefineByName("SPHERHBILLBOARD"),$r.SHADERDEFINE_RENDERMODE_STRETCHEDBILLBOARD=xe.getDefineByName("STRETCHEDBILLBOARD"),$r.SHADERDEFINE_RENDERMODE_HORIZONTALBILLBOARD=xe.getDefineByName("HORIZONTALBILLBOARD"),$r.SHADERDEFINE_RENDERMODE_VERTICALBILLBOARD=xe.getDefineByName("VERTICALBILLBOARD"),$r.SHADERDEFINE_COLOROVERLIFETIME=xe.getDefineByName("COLOROVERLIFETIME"),$r.SHADERDEFINE_RANDOMCOLOROVERLIFETIME=xe.getDefineByName("RANDOMCOLOROVERLIFETIME"),$r.SHADERDEFINE_VELOCITYOVERLIFETIMECONSTANT=xe.getDefineByName("VELOCITYOVERLIFETIMECONSTANT"),$r.SHADERDEFINE_VELOCITYOVERLIFETIMECURVE=xe.getDefineByName("VELOCITYOVERLIFETIMECURVE"),$r.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCONSTANT=xe.getDefineByName("VELOCITYOVERLIFETIMERANDOMCONSTANT"),$r.SHADERDEFINE_VELOCITYOVERLIFETIMERANDOMCURVE=xe.getDefineByName("VELOCITYOVERLIFETIMERANDOMCURVE"),$r.SHADERDEFINE_TEXTURESHEETANIMATIONCURVE=xe.getDefineByName("TEXTURESHEETANIMATIONCURVE"),$r.SHADERDEFINE_TEXTURESHEETANIMATIONRANDOMCURVE=xe.getDefineByName("TEXTURESHEETANIMATIONRANDOMCURVE"),$r.SHADERDEFINE_ROTATIONOVERLIFETIME=xe.getDefineByName("ROTATIONOVERLIFETIME"),$r.SHADERDEFINE_ROTATIONOVERLIFETIMESEPERATE=xe.getDefineByName("ROTATIONOVERLIFETIMESEPERATE"),$r.SHADERDEFINE_ROTATIONOVERLIFETIMECONSTANT=xe.getDefineByName("ROTATIONOVERLIFETIMECONSTANT"),$r.SHADERDEFINE_ROTATIONOVERLIFETIMECURVE=xe.getDefineByName("ROTATIONOVERLIFETIMECURVE"),$r.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCONSTANTS=xe.getDefineByName("ROTATIONOVERLIFETIMERANDOMCONSTANTS"),$r.SHADERDEFINE_ROTATIONOVERLIFETIMERANDOMCURVES=xe.getDefineByName("ROTATIONOVERLIFETIMERANDOMCURVES"),$r.SHADERDEFINE_SIZEOVERLIFETIMECURVE=xe.getDefineByName("SIZEOVERLIFETIMECURVE"),$r.SHADERDEFINE_SIZEOVERLIFETIMECURVESEPERATE=xe.getDefineByName("SIZEOVERLIFETIMECURVESEPERATE"),$r.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVES=xe.getDefineByName("SIZEOVERLIFETIMERANDOMCURVES"),$r.SHADERDEFINE_SIZEOVERLIFETIMERANDOMCURVESSEPERATE=xe.getDefineByName("SIZEOVERLIFETIMERANDOMCURVESSEPERATE"),$r.SHADERDEFINE_RENDERMODE_MESH=xe.getDefineByName("RENDERMODE_MESH"),$r.SHADERDEFINE_SHAPE=xe.getDefineByName("SHAPE")}get particleSystem(){return this._particleSystem}get particleRenderer(){return this._render}_parseModule(e,r){for(var i in r)switch(i){case"bases":var a=r.bases;for(var n in a)e[n]=a[n];break;case"vector2s":var s=r.vector2s;for(var n in s){var o=e[n],l=s[n];o.setValue(l[0],l[1]),e[n]=o}break;case"vector3s":var _=r.vector3s;for(var n in _){var h=e[n],c=_[n];h.setValue(c[0],c[1],c[2]),e[n]=h}break;case"vector4s":var d=r.vector4s;for(var n in d){var u=e[n],m=d[n];u.setValue(m[0],m[1],m[2],m[3]),e[n]=u}break;case"gradientDataNumbers":var f=r.gradientDataNumbers;for(var n in f){for(var T=e[n],E=r[n],p=0,g=E.length;p<g;p++){var S=E[p];T.add(S.key,S.value)}e[n]=T}break;case"resources":var R=r.resources;for(var n in R)e[n]=t.Loader.getRes(R[n]);break;case"bursts":var v=r.bursts;for(p=0,g=v.length;p<g;p++){var x=v[p];e.addBurst(new Nr(x.time,x.min,x.max))}break;case"randomSeed":e.randomSeed[0]=r.randomSeed;break;case"shapeType":case"type":case"color":case"size":case"frame":case"startFrame":case"angularVelocity":case"velocity":break;default:throw"ShurikenParticle3D:unknown type."}}_parse(e,t){if(super._parse(e,t),e.main){var r=this.particleSystem,i=this.particleRenderer;this._parseModule(i,e.renderer),this._parseModule(r,e.main),this._parseModule(r.emission,e.emission);var s=e.shape;if(s){var o;switch(s.shapeType){case 0:o=new Zr;break;case 1:o=new jr;break;case 2:o=new Yr;break;case 3:o=new Wr;break;case 7:o=new Xr;break;default:throw"ShuriKenParticle3D:unknown shape type."}this._parseModule(o,s),r.shape=o}var l=e.velocityOverLifetime;if(l){var _,h=l.velocity;switch(h.type){case 0:var c=h.constant;_=Gr.createByConstant(c?new n(c[0],c[1],c[2]):new n(0,0,0));break;case 1:_=Gr.createByGradient(this._initParticleVelocity(h.gradientX),this._initParticleVelocity(h.gradientY),this._initParticleVelocity(h.gradientZ));break;case 2:var d=h.constantMin,u=h.constantMax;_=Gr.createByRandomTwoConstant(d?new n(d[0],d[1],d[2]):new n(0,0,0),u?new n(u[0],u[1],u[2]):new n(0,0,0));break;case 3:_=Gr.createByRandomTwoGradient(this._initParticleVelocity(h.gradientXMin),this._initParticleVelocity(h.gradientXMax),this._initParticleVelocity(h.gradientYMin),this._initParticleVelocity(h.gradientYMax),this._initParticleVelocity(h.gradientZMin),this._initParticleVelocity(h.gradientZMax))}var m=new Jr(_);this._parseModule(m,l),r.velocityOverLifetime=m}var f=e.colorOverLifetime;if(f){var T,E=f.color;switch(E.type){case 0:var p=E.constant;T=Pr.createByConstant(p?new a(p[0],p[1],p[2],p[3]):new a(0,0,0,0));break;case 1:T=Pr.createByGradient(this._initParticleColor(E.gradient));break;case 2:var g=E.constantMin,S=E.constantMax;T=Pr.createByRandomTwoConstant(g?new a(g[0],g[1],g[2],g[3]):new a(0,0,0,0),g?new a(S[0],S[1],S[2],S[3]):new a(0,0,0,0));break;case 3:T=Pr.createByRandomTwoGradient(this._initParticleColor(E.gradientMin),this._initParticleColor(E.gradientMax))}var R=new br(T);this._parseModule(R,f),r.colorOverLifetime=R}var v=e.sizeOverLifetime;if(v){var x,A=v.size;switch(A.type){case 0:x=A.separateAxes?Ur.createByGradientSeparate(this._initParticleSize(A.gradientX),this._initParticleSize(A.gradientY),this._initParticleSize(A.gradientZ)):Ur.createByGradient(this._initParticleSize(A.gradient));break;case 1:if(A.separateAxes){var I=A.constantMinSeparate,M=A.constantMaxSeparate;x=Ur.createByRandomTwoConstantSeparate(I?new n(I[0],I[1],I[2]):new n(0,0,0),M?new n(M[0],M[1],M[2]):new n(0,0,0))}else x=Ur.createByRandomTwoConstant(A.constantMin||0,A.constantMax||0);break;case 2:x=A.separateAxes?Ur.createByRandomTwoGradientSeparate(this._initParticleSize(A.gradientXMin),this._initParticleSize(A.gradientYMin),this._initParticleSize(A.gradientZMin),this._initParticleSize(A.gradientXMax),this._initParticleSize(A.gradientYMax),this._initParticleSize(A.gradientZMax)):Ur.createByRandomTwoGradient(this._initParticleSize(A.gradientMin),this._initParticleSize(A.gradientMax))}var D=new qr(x);this._parseModule(D,v),r.sizeOverLifetime=D}var C=e.rotationOverLifetime;if(C){var y,L=C.angularVelocity;switch(L.type){case 0:if(L.separateAxes){var O=L.constantSeparate;y=Vr.createByConstantSeparate(O?new n(O[0],O[1],O[2]):new n(0,0,Math.PI/4))}else y=Vr.createByConstant(L.constant||Math.PI/4);break;case 1:y=L.separateAxes?Vr.createByGradientSeparate(this._initParticleRotation(L.gradientX),this._initParticleRotation(L.gradientY),this._initParticleRotation(L.gradientZ)):Vr.createByGradient(this._initParticleRotation(L.gradient));break;case 2:if(L.separateAxes){var N=L.constantMinSeparate,P=L.constantMaxSeparate;y=Vr.createByRandomTwoConstantSeparate(N?new n(N[0],N[1],N[2]):new n(0,0,0),P?new n(P[0],P[1],P[2]):new n(0,0,Math.PI/4))}else y=Vr.createByRandomTwoConstant(L.constantMin||0,L.constantMax||Math.PI/4);break;case 3:L.separateAxes||(y=Vr.createByRandomTwoGradient(this._initParticleRotation(L.gradientMin),this._initParticleRotation(L.gradientMax)))}var b=new zr(y);this._parseModule(b,C),r.rotationOverLifetime=b}var w=e.textureSheetAnimation;if(w){var V,B=w.frame;switch(B.type){case 0:V=wr.createByConstant(B.constant);break;case 1:V=wr.createByOverTime(this._initParticleFrame(B.overTime));break;case 2:V=wr.createByRandomTwoConstant(B.constantMin,B.constantMax);break;case 3:V=wr.createByRandomTwoOverTime(this._initParticleFrame(B.overTimeMin),this._initParticleFrame(B.overTimeMax))}var F,U=w.startFrame;switch(U.type){case 0:F=Qr.createByConstant(U.constant);break;case 1:F=Qr.createByRandomTwoConstant(U.constantMin,U.constantMax)}var G=new Kr(V,F);this._parseModule(G,w),r.textureSheetAnimation=G}}else this._parseOld(e)}_activeHierarchy(e){super._activeHierarchy(e),this.particleSystem.playOnAwake&&this.particleSystem.play()}_inActiveHierarchy(e){super._inActiveHierarchy(e),this.particleSystem.isAlive&&this.particleSystem.simulate(0,!0)}_cloneTo(e,t,r){var i=e,a=i._particleSystem;this._particleSystem.cloneTo(a);var n=i._render,s=this._render;n.sharedMaterials=s.sharedMaterials,n.enable=s.enable,n.renderMode=s.renderMode,n.mesh=s.mesh,n.stretchedBillboardCameraSpeedScale=s.stretchedBillboardCameraSpeedScale,n.stretchedBillboardSpeedScale=s.stretchedBillboardSpeedScale,n.stretchedBillboardLengthScale=s.stretchedBillboardLengthScale,n.sortingFudge=s.sortingFudge,super._cloneTo(e,t,r)}destroy(e=!0){this.destroyed||(super.destroy(e),this._particleSystem.destroy(),this._particleSystem=null)}_create(){return new _i}_parseOld(e){const r=Math.PI/180;var s,o,l,_=this.particleRenderer,h=e.material;h&&(l=t.Loader.getRes(h.path)),_.sharedMaterial=l;var c=e.meshPath;c&&(_.mesh=t.Loader.getRes(c)),_.renderMode=e.renderMode,_.stretchedBillboardCameraSpeedScale=e.stretchedBillboardCameraSpeedScale,_.stretchedBillboardSpeedScale=e.stretchedBillboardSpeedScale,_.stretchedBillboardLengthScale=e.stretchedBillboardLengthScale,_.sortingFudge=e.sortingFudge?e.sortingFudge:0;var d=this.particleSystem;d.isPerformanceMode=e.isPerformanceMode,d.duration=e.duration,d.looping=e.looping,d.prewarm=e.prewarm,d.startDelayType=e.startDelayType,d.startDelay=e.startDelay,d.startDelayMin=e.startDelayMin,d.startDelayMax=e.startDelayMax,d.startLifetimeType=e.startLifetimeType,d.startLifetimeConstant=e.startLifetimeConstant,d.startLifeTimeGradient=_i._initStartLife(e.startLifetimeGradient),d.startLifetimeConstantMin=e.startLifetimeConstantMin,d.startLifetimeConstantMax=e.startLifetimeConstantMax,d.startLifeTimeGradientMin=_i._initStartLife(e.startLifetimeGradientMin),d.startLifeTimeGradientMax=_i._initStartLife(e.startLifetimeGradientMax),d.startSpeedType=e.startSpeedType,d.startSpeedConstant=e.startSpeedConstant,d.startSpeedConstantMin=e.startSpeedConstantMin,d.startSpeedConstantMax=e.startSpeedConstantMax,d.threeDStartSize=e.threeDStartSize,d.startSizeType=e.startSizeType,d.startSizeConstant=e.startSizeConstant;var u=e.startSizeConstantSeparate,m=d.startSizeConstantSeparate;m.x=u[0],m.y=u[1],m.z=u[2],d.startSizeConstantMin=e.startSizeConstantMin,d.startSizeConstantMax=e.startSizeConstantMax;var f=e.startSizeConstantMinSeparate,T=d.startSizeConstantMinSeparate;T.x=f[0],T.y=f[1],T.z=f[2];var E=e.startSizeConstantMaxSeparate,p=d.startSizeConstantMaxSeparate;p.x=E[0],p.y=E[1],p.z=E[2],d.threeDStartRotation=e.threeDStartRotation,d.startRotationType=e.startRotationType,d.startRotationConstant=e.startRotationConstant*r;var g=e.startRotationConstantSeparate,S=d.startRotationConstantSeparate;S.x=g[0]*r,S.y=g[1]*r,S.z=g[2]*r,d.startRotationConstantMin=e.startRotationConstantMin*r,d.startRotationConstantMax=e.startRotationConstantMax*r;var R=e.startRotationConstantMinSeparate,v=d.startRotationConstantMinSeparate;v.x=R[0]*r,v.y=R[1]*r,v.z=R[2]*r;var x=e.startRotationConstantMaxSeparate,A=d.startRotationConstantMaxSeparate;A.x=x[0]*r,A.y=x[1]*r,A.z=x[2]*r,d.randomizeRotationDirection=e.randomizeRotationDirection,d.startColorType=e.startColorType;var I=e.startColorConstant,M=d.startColorConstant;M.x=I[0],M.y=I[1],M.z=I[2],M.w=I[3];var D=e.startColorConstantMin,C=d.startColorConstantMin;C.x=D[0],C.y=D[1],C.z=D[2],C.w=D[3];var y=e.startColorConstantMax,L=d.startColorConstantMax;L.x=y[0],L.y=y[1],L.z=y[2],L.w=y[3],d.gravityModifier=e.gravityModifier,d.simulationSpace=e.simulationSpace,void 0!==e.simulationSpeed&&(d.simulationSpeed=e.simulationSpeed),d.scaleMode=e.scaleMode,d.playOnAwake=e.playOnAwake,d.maxParticles=e.maxParticles;var O=e.autoRandomSeed;null!=O&&(d.autoRandomSeed=O);var N=e.randomSeed;null!=N&&(d.randomSeed[0]=N);var P=e.emission,b=d.emission;if(P){b.emissionRate=P.emissionRate;var w=P.bursts;if(w)for(s=0,o=w.length;s<o;s++){var V=w[s];b.addBurst(new Nr(V.time,V.min,V.max))}b.enable=P.enable}else b.enable=!1;var B=e.shape;if(B){var F;switch(B.shapeType){case 0:var U;F=U=new Zr,U.radius=B.sphereRadius,U.emitFromShell=B.sphereEmitFromShell,U.randomDirection=B.sphereRandomDirection;break;case 1:var G;F=G=new jr,G.radius=B.hemiSphereRadius,G.emitFromShell=B.hemiSphereEmitFromShell,G.randomDirection=B.hemiSphereRandomDirection;break;case 2:var z;F=z=new Yr,z.angle=B.coneAngle*r,z.radius=B.coneRadius,z.length=B.coneLength,z.emitType=B.coneEmitType,z.randomDirection=B.coneRandomDirection;break;case 3:var H;F=H=new Wr,H.x=B.boxX,H.y=B.boxY,H.z=B.boxZ,H.randomDirection=B.boxRandomDirection;break;case 7:var k;F=k=new Xr,k.radius=B.circleRadius,k.arc=B.circleArc*r,k.emitFromEdge=B.circleEmitFromEdge,k.randomDirection=B.circleRandomDirection;break;default:var W;F=W=new Xr,W.radius=B.circleRadius,W.arc=B.circleArc*r,W.emitFromEdge=B.circleEmitFromEdge,W.randomDirection=B.circleRandomDirection}F.enable=B.enable,d.shape=F}var X=e.velocityOverLifetime;if(X){var Y,j=X.velocity;switch(j.type){case 0:var Z=j.constant;Y=Gr.createByConstant(new n(Z[0],Z[1],Z[2]));break;case 1:Y=Gr.createByGradient(this._initParticleVelocity(j.gradientX),this._initParticleVelocity(j.gradientY),this._initParticleVelocity(j.gradientZ));break;case 2:var q=j.constantMin,Q=j.constantMax;Y=Gr.createByRandomTwoConstant(new n(q[0],q[1],q[2]),new n(Q[0],Q[1],Q[2]));break;case 3:Y=Gr.createByRandomTwoGradient(this._initParticleVelocity(j.gradientXMin),this._initParticleVelocity(j.gradientXMax),this._initParticleVelocity(j.gradientYMin),this._initParticleVelocity(j.gradientYMax),this._initParticleVelocity(j.gradientZMin),this._initParticleVelocity(j.gradientZMax))}var K=new Jr(Y);K.space=X.space,K.enable=X.enable,d.velocityOverLifetime=K}var J=e.colorOverLifetime;if(J){var $,ee=J.color;switch(ee.type){case 0:var te=ee.constant;$=Pr.createByConstant(new a(te[0],te[1],te[2],te[3]));break;case 1:$=Pr.createByGradient(this._initParticleColor(ee.gradient));break;case 2:var re=ee.constantMin,ie=ee.constantMax;$=Pr.createByRandomTwoConstant(new a(re[0],re[1],re[2],re[3]),new a(ie[0],ie[1],ie[2],ie[3]));break;case 3:$=Pr.createByRandomTwoGradient(this._initParticleColor(ee.gradientMin),this._initParticleColor(ee.gradientMax))}var ae=new br($);ae.enable=J.enable,d.colorOverLifetime=ae}var ne=e.sizeOverLifetime;if(ne){var se,oe=ne.size;switch(oe.type){case 0:se=oe.separateAxes?Ur.createByGradientSeparate(this._initParticleSize(oe.gradientX),this._initParticleSize(oe.gradientY),this._initParticleSize(oe.gradientZ)):Ur.createByGradient(this._initParticleSize(oe.gradient));break;case 1:if(oe.separateAxes){var le=oe.constantMinSeparate,_e=oe.constantMaxSeparate;se=Ur.createByRandomTwoConstantSeparate(new n(le[0],le[1],le[2]),new n(_e[0],_e[1],_e[2]))}else se=Ur.createByRandomTwoConstant(oe.constantMin,oe.constantMax);break;case 2:se=oe.separateAxes?Ur.createByRandomTwoGradientSeparate(this._initParticleSize(oe.gradientXMin),this._initParticleSize(oe.gradientYMin),this._initParticleSize(oe.gradientZMin),this._initParticleSize(oe.gradientXMax),this._initParticleSize(oe.gradientYMax),this._initParticleSize(oe.gradientZMax)):Ur.createByRandomTwoGradient(this._initParticleSize(oe.gradientMin),this._initParticleSize(oe.gradientMax))}var he=new qr(se);he.enable=ne.enable,d.sizeOverLifetime=he}var ce=e.rotationOverLifetime;if(ce){var de,ue=ce.angularVelocity;switch(ue.type){case 0:if(ue.separateAxes){var me=ue.constantSeparate;de=Vr.createByConstantSeparate(new n(me[0]*r,me[1]*r,me[2]*r))}else de=Vr.createByConstant(ue.constant*r);break;case 1:de=ue.separateAxes?Vr.createByGradientSeparate(this._initParticleRotation(ue.gradientX),this._initParticleRotation(ue.gradientY),this._initParticleRotation(ue.gradientZ)):Vr.createByGradient(this._initParticleRotation(ue.gradient));break;case 2:if(ue.separateAxes){var fe=ue.constantMinSeparate,Te=ue.constantMaxSeparate;de=Vr.createByRandomTwoConstantSeparate(new n(fe[0]*r,fe[1]*r,fe[2]*r),new n(Te[0]*r,Te[1]*r,Te[2]*r))}else de=Vr.createByRandomTwoConstant(ue.constantMin*r,ue.constantMax*r);break;case 3:ue.separateAxes||(de=Vr.createByRandomTwoGradient(this._initParticleRotation(ue.gradientMin),this._initParticleRotation(ue.gradientMax)))}var Ee=new zr(de);Ee.enable=ce.enable,d.rotationOverLifetime=Ee}var pe=e.textureSheetAnimation;if(pe){var ge,Se=pe.frame;switch(Se.type){case 0:ge=wr.createByConstant(Se.constant);break;case 1:ge=wr.createByOverTime(this._initParticleFrame(Se.overTime));break;case 2:ge=wr.createByRandomTwoConstant(Se.constantMin,Se.constantMax);break;case 3:ge=wr.createByRandomTwoOverTime(this._initParticleFrame(Se.overTimeMin),this._initParticleFrame(Se.overTimeMax))}var Re,ve=pe.startFrame;switch(ve.type){case 0:Re=Qr.createByConstant(ve.constant);break;case 1:Re=Qr.createByRandomTwoConstant(ve.constantMin,ve.constantMax)}var xe=new Kr(ge,Re);xe.enable=pe.enable;var Ae=pe.tiles;xe.tiles=new i(Ae[0],Ae[1]),xe.type=pe.type,xe.randomRow=pe.randomRow;var Ie=pe.rowIndex;void 0!==Ie&&(xe.rowIndex=Ie),xe.cycles=pe.cycles,d.textureSheetAnimation=xe}}_initParticleColor(e){var t=new Or(4,4);if(e){var r,i,a=e.alphas;if(a)for(r=0,i=a.length;r<i;r++){3==r&&i>4&&(r=i-1,console.warn("GradientDataColor warning:alpha data length is large than 4, will ignore the middle data."));var n=a[r];t.addColorAlpha(n.key,n.value)}else t.addColorAlpha(0,1),t.addColorAlpha(1,1);var s=e.rgbs;if(s)for(r=0,i=s.length;r<i;r++){3==r&&i>4&&(r=i-1,console.warn("GradientDataColor warning:rgb data length is large than 4, will ignore the middle data."));var o=s[r],l=o.value;t.addColorRGB(o.key,new xt(l[0],l[1],l[2],1))}else t.addColorRGB(0,new xt(1,1,1,1)),t.addColorRGB(1,new xt(1,1,1,1))}else t.addColorAlpha(0,1),t.addColorAlpha(1,1),t.addColorRGB(0,new xt(1,1,1,1)),t.addColorRGB(1,new xt(1,1,1,1));return t}_initParticleFrame(e){var t=new Br;if(e)for(var r=e.frames,i=0,a=r.length;i<a;i++){var n=r[i];t.add(n.key,n.value)}else t.add(0,0),t.add(1,1);return t}static _initStartLife(e){for(var t=new Fr,r=e.startLifetimes,i=0,a=r.length;i<a;i++){var n=r[i];t.add(n.key,n.value)}return t}_initParticleVelocity(e){for(var t=new Fr,r=e.velocitys,i=0,a=r.length;i<a;i++){var n=r[i];t.add(n.key,n.value)}return t}_initParticleSize(e){var t=new Fr;if(e)for(var r=e.sizes,i=0,a=r.length;i<a;i++){var n=r[i];t.add(n.key,n.value)}else t.add(0,0),t.add(1,1);return t}_initParticleRotation(e){for(var t=new Fr,r=e.angularVelocitys,i=0,a=r.length;i<a;i++){var n=r[i];t.add(n.key,n.value/180*Math.PI)}return t}}class hi{}class ci extends Ir{constructor(e){super(e),this._bones=[],this._skinnedDataLoopMarks=[],this._localBounds=new Ut(n._ZERO,n._ZERO),this._cacheAnimationNode=[]}get localBounds(){return this._localBounds}set localBounds(e){this._localBounds=e}get rootBone(){return this._cacheRootBone}set rootBone(e){this._cacheRootBone!=e&&(this._cacheRootBone?this._cacheRootBone.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange):this._owner.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange),e?e.transform.on(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange):this._owner.transform.on(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange),this._cacheRootBone=e,this._onWorldMatNeedChange(I.TRANSFORM_WORLDPOSITION|I.TRANSFORM_WORLDQUATERNION|I.TRANSFORM_WORLDSCALE))}get bones(){return this._bones}_computeSkinnedData(){if(this._cacheMesh&&this._cacheAvatar||this._cacheMesh&&!this._cacheAvatar)for(var e=this._cacheMesh._inverseBindPoses,t=this._cacheMesh._skinnedMatrixCaches,r=0,i=this._cacheMesh.subMeshCount;r<i;r++)for(var a=this._cacheMesh.getSubMesh(r)._boneIndicesList,n=this._skinnedData[r],s=0,o=a.length;s<o;s++){var l=a[s];this._computeSubSkinnedData(e,l,n[s],t)}}_computeSubSkinnedData(e,r,i,a){for(var n=0,s=r.length;n<s;n++){var o=r[n];if(this._skinnedDataLoopMarks[o]===t.Stat.loopCount)for(var l=a[o],_=this._skinnedData[l.subMeshIndex][l.batchIndex],h=16*l.batchBoneIndex,c=16*n,d=0;d<16;d++)i[c+d]=_[h+d];else this._cacheAvatar?H._mulMatrixArray(this._cacheAnimationNode[o].transform.getWorldMatrix(),e[o].elements,0,i,16*n):H._mulMatrixArray(this._bones[o].transform.worldMatrix.elements,e[o].elements,0,i,16*n),this._skinnedDataLoopMarks[o]=t.Stat.loopCount}}_onWorldMatNeedChange(e){this._boundsChange=!0,this._octreeNode&&(this._cacheAvatar?-1===this._indexInOctreeMotionList&&this._octreeNode._octree.addMotionObject(this):(e&=I.TRANSFORM_WORLDPOSITION|I.TRANSFORM_WORLDQUATERNION|I.TRANSFORM_WORLDSCALE)&&-1===this._indexInOctreeMotionList&&this._octreeNode._octree.addMotionObject(this))}_createRenderElement(){return new Ke}_onMeshChange(e){super._onMeshChange(e),this._cacheMesh=e;var t=e.subMeshCount;this._skinnedData=[],this._skinnedDataLoopMarks.length=e._inverseBindPoses.length;for(var r=0;r<t;r++)for(var i=e.getSubMesh(r)._boneIndicesList,a=i.length,n=this._skinnedData[r]=[],s=0;s<a;s++)n[s]=new Float32Array(16*i[s].length);this._cacheAvatar&&e&&this._getCacheAnimationNodes()}_setCacheAnimator(e){this._cacheAnimator=e,this._shaderValues.addDefine(hi.SHADERDEFINE_BONE),this._setRootNode()}_calculateBoundingBox(){if(this._cacheAvatar)if(this._cacheAnimator&&this._rootBone){var e=ci._tempMatrix4x4;H.matrix4x4MultiplyMFM(this._cacheAnimator.owner.transform.worldMatrix,this._cacheRootAnimationNode.transform.getWorldMatrix(),e),this._localBounds._tranform(e,this._bounds)}else super._calculateBoundingBox();else this._cacheRootBone?this._localBounds._tranform(this._cacheRootBone.transform.worldMatrix,this._bounds):this._localBounds._tranform(this._owner.transform.worldMatrix,this._bounds)}_renderUpdate(t,r){if(this._cacheAnimator)if(this._computeSkinnedData(),this._cacheAvatar){var i=this._cacheAnimator.owner._transform;this._shaderValues.setMatrix4x4(Ce.WORLDMATRIX,i.worldMatrix)}else this._shaderValues.setMatrix4x4(Ce.WORLDMATRIX,R.DEFAULT);else this._shaderValues.setMatrix4x4(Ce.WORLDMATRIX,r.worldMatrix);this._probReflection&&(this._reflectionMode==e.ReflectionProbeMode.off?(this._shaderValues.removeDefine(Ar.SHADERDEFINE_SPECCUBE_BOX_PROJECTION),this._shaderValues.setVector(kt.REFLECTIONCUBE_HDR_PARAMS,Qt.defaultTextureHDRDecodeValues),this._shaderValues.setTexture(kt.REFLECTIONTEXTURE,bt.blackTexture)):(this._probReflection.boxProjection?(this._shaderValues.addDefine(Ar.SHADERDEFINE_SPECCUBE_BOX_PROJECTION),this._shaderValues.setVector3(kt.REFLECTIONCUBE_PROBEPOSITION,this._probReflection.probePosition),this._shaderValues.setVector3(kt.REFLECTIONCUBE_PROBEBOXMAX,this._probReflection.boundsMax),this._shaderValues.setVector3(kt.REFLECTIONCUBE_PROBEBOXMIN,this._probReflection.boundsMin)):this._shaderValues.removeDefine(Ar.SHADERDEFINE_SPECCUBE_BOX_PROJECTION),this._shaderValues.setTexture(kt.REFLECTIONTEXTURE,this._probReflection.reflectionTexture),this._shaderValues.setVector(kt.REFLECTIONCUBE_HDR_PARAMS,this._probReflection.reflectionHDRParams)))}_renderUpdateWithCamera(e,t){var r=e.projectionViewMatrix;if(this._cacheAnimator)if(this._cacheAvatar){var i=this._cacheAnimator.owner._transform;R.multiply(r,i.worldMatrix,this._projectionViewWorldMatrix),this._shaderValues.setMatrix4x4(Ce.MVPMATRIX,this._projectionViewWorldMatrix)}else this._shaderValues.setMatrix4x4(Ce.MVPMATRIX,r);else R.multiply(r,t.worldMatrix,this._projectionViewWorldMatrix),this._shaderValues.setMatrix4x4(Ce.MVPMATRIX,this._projectionViewWorldMatrix)}_destroy(){super._destroy(),this._cacheAvatar?this._cacheRootAnimationNode&&this._cacheRootAnimationNode.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange):this._cacheRootBone?!this._cacheRootBone.destroyed&&this._cacheRootBone.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange):this._owner&&!this._owner.destroyed&&this._owner.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange)}get bounds(){return(this._boundsChange||this._cacheAvatar)&&(this._calculateBoundingBox(),this._boundsChange=!1),this._bounds}_setRootBone(e){this._rootBone=e,this._setRootNode()}_setRootNode(){var e;e=this._cacheAnimator&&this._rootBone&&this._cacheAvatar?this._cacheAnimator._avatarNodeMap[this._rootBone]:null,this._cacheRootAnimationNode!=e&&(this._onWorldMatNeedChange(I.TRANSFORM_WORLDPOSITION|I.TRANSFORM_WORLDQUATERNION|I.TRANSFORM_WORLDSCALE),this._owner.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange),this._cacheRootAnimationNode&&this._cacheRootAnimationNode.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange),e&&e.transform.on(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange),this._cacheRootAnimationNode=e)}_getCacheAnimationNodes(){var e=this._cacheMesh._boneNames,t=this._cacheMesh._inverseBindPoses.length;this._cacheAnimationNode.length=t;for(var r=this._cacheAnimator._avatarNodeMap,i=0;i<t;i++){var a=r[e[i]];this._cacheAnimationNode[i]=a}}_setCacheAvatar(e){this._cacheAvatar!==e&&(this._cacheMesh?(this._cacheAvatar=e,e&&(this._shaderValues.addDefine(hi.SHADERDEFINE_BONE),this._getCacheAnimationNodes())):this._cacheAvatar=e,this._setRootNode())}_computeSubSkinnedDataNative(e,r,i,a,n){t.LayaGL.instance.computeSubSkinnedData(e,r,i,a,n)}_computeSkinnedDataForNative(){if(this._cacheMesh&&this._cacheAvatar||this._cacheMesh&&!this._cacheAvatar)for(var e=this._cacheMesh._inverseBindPoses,t=this._cacheMesh._skinnedMatrixCaches,r=0,i=this._cacheMesh.subMeshCount;r<i;r++)for(var a=this._cacheMesh.getSubMesh(r)._boneIndicesList,n=this._skinnedData[r],s=0,o=a.length;s<o;s++){var l=a[s];this._computeSubSkinnedData(e,l,n[s],t)}}}ci._tempMatrix4x4=new R;class di extends kt{constructor(e=null,t=null){super(t),this._meshFilter=new Mr(this),this._render=new ci(this),e&&(this._meshFilter.sharedMesh=e)}static __init__(){hi.SHADERDEFINE_BONE=xe.getDefineByName("BONE"),hi.SHADERDEFINE_SIMPLEBONE=xe.getDefineByName("SIMPLEBONE")}get meshFilter(){return this._meshFilter}get skinnedMeshRenderer(){return this._render}_parse(e,r){super._parse(e,r);var i=this.skinnedMeshRenderer,s=e.lightmapIndex;null!=s&&(i.lightmapIndex=s);var o,l=e.lightmapScaleOffset;if(l&&(i.lightmapScaleOffset=new a(l[0],l[1],l[2],l[3])),null!=e.enableRender&&(i.enable=e.enableRender),null!=e.receiveShadows&&(i.receiveShadow=e.receiveShadows),null!=e.castShadow&&(i.castShadow=e.castShadow),o=e.meshPath){var _=t.Loader.getRes(o);_&&(this.meshFilter.sharedMesh=_)}var h=e.materials;if(h){var c=i.sharedMaterials,d=h.length;c.length=d;for(var u=0;u<d;u++)c[u]=t.Loader.getRes(h[u].path);i.sharedMaterials=c}var m=e.boundBox,f=m.min,T=m.max;if(i.localBounds.setMin(new n(f[0],f[1],f[2])),i.localBounds.setMax(new n(T[0],T[1],T[2])),r){var E=e.rootBone;i.rootBone=r[E];var p,g=e.bones;for(u=0,p=g.length;u<p;u++)i.bones.push(r[g[u]])}else e.rootBone&&i._setRootBone(e.rootBone)}_changeHierarchyAnimator(e){super._changeHierarchyAnimator(e),this.skinnedMeshRenderer._setCacheAnimator(e)}_changeAnimatorAvatar(e){this.skinnedMeshRenderer._setCacheAvatar(e)}_cloneTo(e,t,r){var i=e;i.meshFilter.sharedMesh=this.meshFilter.sharedMesh;var a=this._render,n=i._render;n.enable=a.enable,n.sharedMaterials=a.sharedMaterials,n.castShadow=a.castShadow;var s=a.lightmapScaleOffset;s&&(n.lightmapScaleOffset=s.clone()),n.receiveShadow=a.receiveShadow,n.sortingFudge=a.sortingFudge,n._rootBone=a._rootBone;var o=a.bones,l=n.bones,_=o.length;l.length=_;var h=a.rootBone;if(h){var c=H._getHierarchyPath(t,h,di._tempArray0);n.rootBone=c?H._getNodeByHierarchyPath(r,c):h}for(var d=0;d<o.length;d++)c=H._getHierarchyPath(t,o[d],di._tempArray0),l[d]=c?H._getNodeByHierarchyPath(r,c):o[d];var u=a.localBounds;u&&u.cloneTo(n.localBounds),super._cloneTo(e,t,r)}destroy(e=!0){this.destroyed||(super.destroy(e),this._meshFilter.destroy())}_create(){return new di}}di._tempArray0=[],di.BONES=xe.propertyNameToID("u_Bones"),di.SIMPLE_SIMPLEANIMATORTEXTURE=xe.propertyNameToID("u_SimpleAnimatorTexture"),di.SIMPLE_SIMPLEANIMATORPARAMS=xe.propertyNameToID("u_SimpleAnimatorParams"),di.SIMPLE_SIMPLEANIMATORTEXTURESIZE=xe.propertyNameToID("u_SimpleAnimatorTextureSize");class ui extends st{constructor(){super(),this.setShaderName("Trail"),this._color=new a(1,1,1,1),this._shaderValues.setVector(ui.TINTCOLOR,new a(1,1,1,1)),this.renderMode=ui.RENDERMODE_ALPHABLENDED}static __initDefine__(){ui.SHADERDEFINE_MAINTEXTURE=xe.getDefineByName("MAINTEXTURE"),ui.SHADERDEFINE_TILINGOFFSET=xe.getDefineByName("TILINGOFFSET"),ui.SHADERDEFINE_ADDTIVEFOG=xe.getDefineByName("ADDTIVEFOG")}get _TintColorR(){return this._color.x}set _TintColorR(e){this._color.x=e,this.color=this._color}get _TintColorG(){return this._color.y}set _TintColorG(e){this._color.y=e,this.color=this._color}get _TintColorB(){return this._color.z}set _TintColorB(e){this._color.z=e,this.color=this._color}get _TintColorA(){return this._color.w}set _TintColorA(e){this._color.w=e,this.color=this._color}get _MainTex_STX(){return this._shaderValues.getVector(ui.TILINGOFFSET).x}set _MainTex_STX(e){var t=this._shaderValues.getVector(ui.TILINGOFFSET);t.x=e,this.tilingOffset=t}get _MainTex_STY(){return this._shaderValues.getVector(ui.TILINGOFFSET).y}set _MainTex_STY(e){var t=this._shaderValues.getVector(ui.TILINGOFFSET);t.y=e,this.tilingOffset=t}get _MainTex_STZ(){return this._shaderValues.getVector(ui.TILINGOFFSET).z}set _MainTex_STZ(e){var t=this._shaderValues.getVector(ui.TILINGOFFSET);t.z=e,this.tilingOffset=t}get _MainTex_STW(){return this._shaderValues.getVector(ui.TILINGOFFSET).w}set _MainTex_STW(e){var t=this._shaderValues.getVector(ui.TILINGOFFSET);t.w=e,this.tilingOffset=t}set renderMode(e){switch(e){case ui.RENDERMODE_ADDTIVE:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.alphaTest=!1,this.depthWrite=!1,this.cull=lt.CULL_NONE,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE,this.depthTest=lt.DEPTHTEST_LESS,this._shaderValues.addDefine(ui.SHADERDEFINE_ADDTIVEFOG);break;case ui.RENDERMODE_ALPHABLENDED:this.renderQueue=st.RENDERQUEUE_TRANSPARENT,this.alphaTest=!1,this.depthWrite=!1,this.cull=lt.CULL_NONE,this.blend=lt.BLEND_ENABLE_ALL,this.blendSrc=lt.BLENDPARAM_SRC_ALPHA,this.blendDst=lt.BLENDPARAM_ONE_MINUS_SRC_ALPHA,this.depthTest=lt.DEPTHTEST_LESS,this._shaderValues.removeDefine(ui.SHADERDEFINE_ADDTIVEFOG);break;default:throw new Error("TrailMaterial : renderMode value error.")}}get colorR(){return this._TintColorR}set colorR(e){this._TintColorR=e}get colorG(){return this._TintColorG}set colorG(e){this._TintColorG=e}get colorB(){return this._TintColorB}set colorB(e){this._TintColorB=e}get colorA(){return this._TintColorA}set colorA(e){this._TintColorA=e}get color(){return this._shaderValues.getVector(ui.TINTCOLOR)}set color(e){this._shaderValues.setVector(ui.TINTCOLOR,e)}get texture(){return this._shaderValues.getTexture(ui.MAINTEXTURE)}set texture(e){e?this._shaderValues.addDefine(ui.SHADERDEFINE_MAINTEXTURE):this._shaderValues.removeDefine(ui.SHADERDEFINE_MAINTEXTURE),this._shaderValues.setTexture(ui.MAINTEXTURE,e)}get tilingOffsetX(){return this._MainTex_STX}set tilingOffsetX(e){this._MainTex_STX=e}get tilingOffsetY(){return this._MainTex_STY}set tilingOffsetY(e){this._MainTex_STY=e}get tilingOffsetZ(){return this._MainTex_STZ}set tilingOffsetZ(e){this._MainTex_STZ=e}get tilingOffsetW(){return this._MainTex_STW}set tilingOffsetW(e){this._MainTex_STW=e}get tilingOffset(){return this._shaderValues.getVector(ui.TILINGOFFSET)}set tilingOffset(e){e&&(1!=e.x||1!=e.y||0!=e.z||0!=e.w)?this._shaderValues.addDefine(ui.SHADERDEFINE_TILINGOFFSET):this._shaderValues.removeDefine(ui.SHADERDEFINE_TILINGOFFSET),this._shaderValues.setVector(ui.TILINGOFFSET,e)}clone(){var e=new ui;return this.cloneTo(e),e}}ui.RENDERMODE_ALPHABLENDED=0,ui.RENDERMODE_ADDTIVE=1,ui.MAINTEXTURE=xe.propertyNameToID("u_MainTexture"),ui.TINTCOLOR=xe.propertyNameToID("u_MainColor"),ui.TILINGOFFSET=xe.propertyNameToID("u_TilingOffset");class mi{}mi.Stretch=0,mi.Tile=1,(pr=e.TrailAlignment||(e.TrailAlignment={}))[pr.View=0]="View",pr[pr.TransformZ=1]="TransformZ";class fi{static get vertexDeclaration1(){return fi._vertexDeclaration1}static get vertexDeclaration2(){return fi._vertexDeclaration2}get vertexDeclaration(){return fi._vertexDeclaration1}static __init__(){fi._vertexDeclaration1=new fe(32,[new Te(0,ue.Vector3,fi.TRAIL_POSITION0),new Te(12,ue.Vector3,fi.TRAIL_OFFSETVECTOR),new Te(24,ue.Single,fi.TRAIL_TIME0),new Te(28,ue.Single,fi.TRAIL_TEXTURECOORDINATE0Y)]),fi._vertexDeclaration2=new fe(20,[new Te(0,ue.Single,fi.TRAIL_TEXTURECOORDINATE0X),new Te(4,ue.Color,fi.TRAIL_COLOR)])}}fi.TRAIL_POSITION0=0,fi.TRAIL_OFFSETVECTOR=1,fi.TRAIL_TIME0=2,fi.TRAIL_TEXTURECOORDINATE0Y=3,fi.TRAIL_TEXTURECOORDINATE0X=4,fi.TRAIL_COLOR=5;class Ti extends Gt{constructor(e){super(),this._floatCountPerVertices1=8,this._floatCountPerVertices2=5,this._increaseSegementCount=16,this._activeIndex=0,this._endIndex=0,this._needAddFirstVertex=!1,this._isTempEndVertex=!1,this._vertices1=null,this._vertices2=null,this._lastFixedVertexPosition=new n,this._bufferState=new Ee,this.tmpColor=new xt,this._disappearBoundsMode=!1,this._owner=e,this._segementCount=this._increaseSegementCount,this._resizeData(this._segementCount,this._bufferState);var t=this._owner._owner.trailRenderer.bounds,r=this._owner._owner.transform.position;t.setMin(r),t.setMax(r)}_resizeData(e,r){this._subBirthTime=new Float32Array(e),this._subDistance=new Float64Array(e);var i=t.LayaGL.instance,a=2*e,n=fi.vertexDeclaration1,s=fi.vertexDeclaration2,o=[],l=a*n.vertexStride,_=a*s.vertexStride,h=l+_;this._vertices1=new Float32Array(a*this._floatCountPerVertices1),this._vertices2=new Float32Array(a*this._floatCountPerVertices2),this._vertexBuffer1=new de(l,i.STATIC_DRAW,!1),this._vertexBuffer1.vertexDeclaration=n,this._vertexBuffer2=new de(_,i.DYNAMIC_DRAW,!1),this._vertexBuffer2.vertexDeclaration=s,o.push(this._vertexBuffer1),o.push(this._vertexBuffer2),r.bind(),r.applyVertexBuffers(o),r.unBind(),t.Resource._addMemory(h,h)}_resetData(){var e=this._endIndex-this._activeIndex,r=new Float32Array(this._vertices1.buffer,2*this._floatCountPerVertices1*this._activeIndex*4,2*this._floatCountPerVertices1*e),i=new Float32Array(this._vertices2.buffer,2*this._floatCountPerVertices2*this._activeIndex*4,2*this._floatCountPerVertices2*e),a=new Float64Array(this._subDistance.buffer,8*this._activeIndex,e),n=new Float32Array(this._subBirthTime.buffer,4*this._activeIndex,e);if(e===this._segementCount){var s=this._vertexBuffer1._byteLength+this._vertexBuffer2._byteLength;t.Resource._addMemory(-s,-s),this._vertexBuffer1.destroy(),this._vertexBuffer2.destroy(),this._segementCount+=this._increaseSegementCount,this._resizeData(this._segementCount,this._bufferState)}this._vertices1.set(r,0),this._vertices2.set(i,0),this._subDistance.set(a,0),this._subBirthTime.set(n,0),this._endIndex=e,this._activeIndex=0,this._vertexBuffer1.setData(this._vertices1.buffer,0,2*this._floatCountPerVertices1*this._activeIndex*4,2*this._floatCountPerVertices1*e*4),this._vertexBuffer2.setData(this._vertices2.buffer,0,2*this._floatCountPerVertices2*this._activeIndex*4,2*this._floatCountPerVertices2*e*4)}_updateTrail(e,t,r){n.equals(t,r)||(this._endIndex-this._activeIndex==0?this._addTrailByFirstPosition(e,r):this._addTrailByNextPosition(e,r))}_addTrailByFirstPosition(e,t){this._endIndex===this._segementCount&&this._resetData(),this._subDistance[this._endIndex]=0,this._subBirthTime[this._endIndex]=this._owner._curtime,this._endIndex++,t.cloneTo(this._lastFixedVertexPosition),this._needAddFirstVertex=!0}_addTrailByNextPosition(t,i){var a=Ti._tempVector30,s=Ti._tempVector31;switch(this._owner.alignment){case e.TrailAlignment.View:var o=t.viewMatrix;n.transformCoordinate(i,o,Ti._tempVector33),n.transformCoordinate(this._lastFixedVertexPosition,o,Ti._tempVector34),n.subtract(Ti._tempVector33,Ti._tempVector34,a),n.cross(Ti._tempVector33,a,s);break;case e.TrailAlignment.TransformZ:n.subtract(i,this._lastFixedVertexPosition,a);var l=Ti._tempVector32;this._owner._owner.transform.getForward(l),n.cross(a,l,s)}n.normalize(s,s),n.scale(s,this._owner.widthMultiplier/2,s);var _,h,c=n.scalarLength(a);this._needAddFirstVertex&&(this._updateVerticesByPositionData(i,s,this._endIndex-1),this._needAddFirstVertex=!1),c-this._owner.minVertexDistance>=r.zeroTolerance?(this._isTempEndVertex?(_=this._endIndex-1,h=c-this._subDistance[_],this._updateVerticesByPosition(i,s,c,_),this._owner._totalLength+=h):(this._endIndex===this._segementCount&&this._resetData(),this._updateVerticesByPosition(i,s,c,this._endIndex),this._owner._totalLength+=c,this._endIndex++),i.cloneTo(this._lastFixedVertexPosition),this._isTempEndVertex=!1):(this._isTempEndVertex?(_=this._endIndex-1,h=c-this._subDistance[_],this._updateVerticesByPosition(i,s,c,_),this._owner._totalLength+=h):(this._endIndex===this._segementCount&&this._resetData(),this._updateVerticesByPosition(i,s,c,this._endIndex),this._owner._totalLength+=c,this._endIndex++),this._isTempEndVertex=!0)}_updateVerticesByPositionData(e,t,r){var i=2*this._floatCountPerVertices1*r,a=this._owner._curtime;this._vertices1[i]=e.x,this._vertices1[i+1]=e.y,this._vertices1[i+2]=e.z,this._vertices1[i+3]=-t.x,this._vertices1[i+4]=-t.y,this._vertices1[i+5]=-t.z,this._vertices1[i+6]=a,this._vertices1[i+7]=1,this._vertices1[i+8]=e.x,this._vertices1[i+9]=e.y,this._vertices1[i+10]=e.z,this._vertices1[i+11]=t.x,this._vertices1[i+12]=t.y,this._vertices1[i+13]=t.z,this._vertices1[i+14]=a,this._vertices1[i+15]=0;var s=this._owner._owner.trailRenderer.bounds,o=s.getMin(),l=s.getMax(),_=Ti._tempVector35,h=Ti._tempVector36,c=Ti._tempVector32;n.add(e,t,_),n.subtract(e,t,h),n.min(h,_,c),n.min(o,c,o),s.setMin(o),n.max(_,h,c),n.max(l,c,l),s.setMax(l);var d=2*this._floatCountPerVertices1;this._vertexBuffer1.setData(this._vertices1.buffer,4*i,4*i,4*d)}_updateVerticesByPosition(e,t,r,i){this._updateVerticesByPositionData(e,t,i),this._subDistance[i]=r,this._subBirthTime[i]=this._owner._curtime}_updateVertexBufferUV(){var e,t,r;if(this._disappearBoundsMode){e=this._owner._owner.trailRenderer.bounds;var i=this._owner._owner.transform.position;e.setMin(i),e.setMax(i),t=e.getMin(),r=e.getMax()}for(var a=this._endIndex,s=0,o=this._owner.colorGradient,l=o.colorAlphaKeysCount-1,_=o.colorRGBKeysCount-1,h=this._owner._totalLength,c=2*this._floatCountPerVertices2,d=this._activeIndex;d<a;d++){var u,m;d!==this._activeIndex&&(s+=this._subDistance[d]),this._owner.textureMode==mi.Stretch?m=u=1-s/h:(m=1-s/h,u=1-(h-s)),_=o.evaluateColorRGB(m,this.tmpColor,_,!0),l=o.evaluateColorAlpha(m,this.tmpColor,l,!0);var f=d*c;if(this._vertices2[f+0]=u,this._vertices2[f+1]=this.tmpColor.r,this._vertices2[f+2]=this.tmpColor.g,this._vertices2[f+3]=this.tmpColor.b,this._vertices2[f+4]=this.tmpColor.a,this._vertices2[f+5]=u,this._vertices2[f+6]=this.tmpColor.r,this._vertices2[f+7]=this.tmpColor.g,this._vertices2[f+8]=this.tmpColor.b,this._vertices2[f+9]=this.tmpColor.a,this._disappearBoundsMode){var T=2*this._floatCountPerVertices1*d,E=Ti._tempVector32,p=Ti._tempVector33,g=Ti._tempVector34;E.setValue(this._vertices1[T+0],this._vertices1[T+1],this._vertices1[T+2]),p.setValue(this._vertices1[T+3],this._vertices1[T+4],this._vertices1[T+5]),n.add(E,p,g),n.min(g,t,t),n.max(g,r,r),n.subtract(E,p,g),n.min(g,t,t),n.max(g,r,r)}}this._disappearBoundsMode&&(e.setMin(t),e.setMax(r),this._disappearBoundsMode=!1);var S=this._activeIndex*c;this._vertexBuffer2.setData(this._vertices2.buffer,4*S,4*S,4*(a*c-S))}_updateDisappear(){for(var e=this._endIndex,t=this._activeIndex;t<e&&this._owner._curtime-this._subBirthTime[t]>=this._owner.time+r.zeroTolerance;t++){var i=t+1;if(i!==e&&(this._owner._totalLength-=this._subDistance[i]),this._isTempEndVertex&&i===e-1){this._floatCountPerVertices1;var a=this._lastFixedVertexPosition;a.x=this._vertices1[0],a.y=this._vertices1[1],a.z=this._vertices1[2],this._isTempEndVertex=!1}this._activeIndex++,this._disappearBoundsMode=!0}}_getType(){return Ti._type}_prepareRender(e){return this._endIndex-this._activeIndex>1}_render(e){this._bufferState.bind();var r=t.LayaGL.instance,i=2*this._activeIndex,a=2*this._endIndex-i;r.drawArrays(r.TRIANGLE_STRIP,i,a),t.Stat.renderBatches++,t.Stat.trianglesFaces+=a-2}destroy(){super.destroy();var e=this._vertexBuffer1._byteLength+this._vertexBuffer2._byteLength;t.Resource._addMemory(-e,-e),this._bufferState.destroy(),this._vertexBuffer1.destroy(),this._vertexBuffer2.destroy(),this._bufferState=null,this._vertices1=null,this._vertexBuffer1=null,this._vertices2=null,this._vertexBuffer2=null,this._subBirthTime=null,this._subDistance=null,this._lastFixedVertexPosition=null,this._disappearBoundsMode=!1}clear(){this._activeIndex=0,this._endIndex=0,this._disappearBoundsMode=!1,this._subBirthTime.fill(0),this._subDistance.fill(0),this._segementCount=0,this._isTempEndVertex=!1,this._needAddFirstVertex=!1,this._lastFixedVertexPosition.setValue(0,0,0)}}Ti.ALIGNMENT_VIEW=0,Ti.ALIGNMENT_TRANSFORM_Z=1,Ti._tempVector30=new n,Ti._tempVector31=new n,Ti._tempVector32=new n,Ti._tempVector33=new n,Ti._tempVector34=new n,Ti._tempVector35=new n,Ti._tempVector36=new n,Ti._type=Gt._typeCounter++;class Ei{constructor(e){this._totalLength=0,this._lastPosition=new n,this._curtime=0,this.alignment=Ei.ALIGNMENT_VIEW,this._owner=e,this._initDefaultData(),this.addRenderElement()}get time(){return this._time}set time(e){this._time=e,this._owner._render._shaderValues.setNumber(Ei.LIFETIME,e)}get minVertexDistance(){return this._minVertexDistance}set minVertexDistance(e){this._minVertexDistance=e}get widthMultiplier(){return this._widthMultiplier}set widthMultiplier(e){this._widthMultiplier=e}get widthCurve(){return this._widthCurve}set widthCurve(e){this._widthCurve=e;var t,r,i=new Float32Array(4*e.length),a=0;for(t=0,r=e.length;t<r;t++)i[a++]=e[t].time,i[a++]=e[t].inTangent,i[a++]=e[t].outTangent,i[a++]=e[t].value;this._owner._render._shaderValues.setBuffer(Ei.WIDTHCURVE,i),this._owner._render._shaderValues.setInt(Ei.WIDTHCURVEKEYLENGTH,e.length)}get colorGradient(){return this._colorGradient}set colorGradient(e){this._colorGradient=e}get textureMode(){return this._textureMode}set textureMode(e){this._textureMode=e}addRenderElement(){var e=this._owner._render,t=e._renderElements,r=e.sharedMaterials[0];r||(r=ui.defaultMaterial);var i=new Ke;i.setTransform(this._owner._transform),i.render=e,i.material=r,this._trialGeometry=new Ti(this),i.setGeometry(this._trialGeometry),t.push(i)}_update(e){var t=this._owner._render;this._curtime+=e.scene.timer._delta/1e3,t._shaderValues.setNumber(Ei.CURTIME,this._curtime);var r=this._owner.transform.position,i=t._renderElements[0]._geometry;i._updateDisappear(),i._updateTrail(e.camera,this._lastPosition,r),i._updateVertexBufferUV(),r.cloneTo(this._lastPosition)}_initDefaultData(){this.time=5,this.minVertexDistance=.1,this.widthMultiplier=1,this.textureMode=mi.Stretch;var e=[],t=new K;t.time=0,t.inTangent=0,t.outTangent=0,t.value=1,e.push(t);var r=new K;r.time=1,r.inTangent=0,r.outTangent=0,r.value=1,e.push(r),this.widthCurve=e;var i=new Or(2,2);i.mode=Lr.Blend,i.addColorRGB(0,xt.WHITE),i.addColorRGB(1,xt.WHITE),i.addColorAlpha(0,1),i.addColorAlpha(1,1),this.colorGradient=i}destroy(){this._trialGeometry.destroy(),this._trialGeometry=null,this._widthCurve=null,this._colorGradient=null}clear(){this._trialGeometry.clear(),this._lastPosition.setValue(0,0,0),this._curtime=0,this._totalLength=0}}Ei.CURTIME=xe.propertyNameToID("u_CurTime"),Ei.LIFETIME=xe.propertyNameToID("u_LifeTime"),Ei.WIDTHCURVE=xe.propertyNameToID("u_WidthCurve"),Ei.WIDTHCURVEKEYLENGTH=xe.propertyNameToID("u_WidthCurveKeyLength"),Ei.ALIGNMENT_VIEW=0,Ei.ALIGNMENT_TRANSFORM_Z=1;class pi extends Kt{constructor(e){super(e),this._projectionViewWorldMatrix=new R}_calculateBoundingBox(){}_needRender(e,t){return this._owner.trailFilter._update(t),!e||e.intersects(this.bounds._getBoundBox())}_updateForNative(e){this._owner.trailFilter._update(e)}_renderUpdate(e,t){super._renderUpdate(e,t)}_renderUpdateWithCamera(e,t){var r=e.projectionViewMatrix;t?(R.multiply(r,t.worldMatrix,this._projectionViewWorldMatrix),this._shaderValues.setMatrix4x4(Ce.MVPMATRIX,this._projectionViewWorldMatrix)):this._shaderValues.setMatrix4x4(Ce.MVPMATRIX,r)}}class gi extends kt{constructor(e=null){super(e),this._render=new pi(this),this._geometryFilter=new Ei(this)}static __init__(){}get trailFilter(){return this._geometryFilter}get trailRenderer(){return this._render}_parse(e,r){super._parse(e,r);var i,a,n=this._render,s=this._geometryFilter,o=e.materials;if(o){var l=n.sharedMaterials,_=o.length;for(l.length=_,i=0;i<_;i++)l[i]=t.Loader.getRes(o[i].path);n.sharedMaterials=l}s.time=e.time,s.minVertexDistance=e.minVertexDistance,s.widthMultiplier=e.widthMultiplier,s.textureMode=e.textureMode,null!=e.alignment&&(s.alignment=e.alignment);var h=[],c=e.widthCurve;for(i=0,a=c.length;i<a;i++){var d=new K;d.time=c[i].time,d.inTangent=c[i].inTangent,d.outTangent=c[i].outTangent,d.value=c[i].value,h.push(d)}s.widthCurve=h;var u=e.colorGradient,m=u.colorKeys,f=u.alphaKeys,T=new Or(m.length,f.length);for(T.mode=u.mode,i=0,a=m.length;i<a;i++){var E=m[i];T.addColorRGB(E.time,new xt(E.value[0],E.value[1],E.value[2],1))}for(i=0,a=f.length;i<a;i++){var p=f[i];T.addColorAlpha(p.time,p.value)}s.colorGradient=T}_onActive(){super._onActive(),this._transform.position.cloneTo(this._geometryFilter._lastPosition)}_cloneTo(e,t,r){var i,a;super._cloneTo(e,t,r);var n=e,s=n.trailFilter;s.time=this.trailFilter.time,s.minVertexDistance=this.trailFilter.minVertexDistance,s.widthMultiplier=this.trailFilter.widthMultiplier,s.textureMode=this.trailFilter.textureMode,s.alignment=this.trailFilter.alignment;var o=this.trailFilter.widthCurve,l=[];for(i=0,a=o.length;i<a;i++){var _=new K;o[i].cloneTo(_),l.push(_)}s.widthCurve=l;var h=new Or(this.trailFilter.colorGradient.maxColorRGBKeysCount,this.trailFilter.colorGradient.maxColorAlphaKeysCount);this.trailFilter.colorGradient.cloneTo(h),s.colorGradient=h,n.trailRenderer.sharedMaterial=this.trailRenderer.sharedMaterial}destroy(e=!0){this.destroyed||(super.destroy(e),this._geometryFilter.destroy(),this._geometryFilter=null)}clear(){this._geometryFilter.clear()}_create(){return new gi}}class Si{constructor(e,t,r,i){this._position=e,this._normal=t,this._textureCoord0=r,this._textureCoord1=i}static __init__(){Si._vertexDeclaration=new fe(40,[new Te(0,ue.Vector3,Si.TERRAIN_POSITION0),new Te(12,ue.Vector3,Si.TERRAIN_NORMAL0),new Te(24,ue.Vector2,Si.TERRAIN_TEXTURECOORDINATE0),new Te(32,ue.Vector2,Si.TERRAIN_TEXTURECOORDINATE1)])}static get vertexDeclaration(){return Si._vertexDeclaration}get position(){return this._position}get normal(){return this._normal}get textureCoord0(){return this._textureCoord0}get textureCoord1(){return this._textureCoord1}get vertexDeclaration(){return Si._vertexDeclaration}}Si.TERRAIN_POSITION0=0,Si.TERRAIN_NORMAL0=1,Si.TERRAIN_TEXTURECOORDINATE0=2,Si.TERRAIN_TEXTURECOORDINATE1=3;class Ri{}Ri._interactive={getWorldTransform:(e,t)=>{},setWorldTransform:(e,t)=>{var r=P._physicObjectsMap[e];r._simulation._updatedRigidbodies++,r._updateTransformComponent(t)}};class vi extends W{constructor(e=M.COLLISIONFILTERGROUP_DEFAULTFILTER,t=M.COLLISIONFILTERGROUP_ALLFILTER){super(e,t),this._enableProcessCollisions=!1}_addToSimulation(){this._simulation._addPhysicsCollider(this,this._collisionGroup,this._canCollideWith)}_removeFromSimulation(){this._simulation._removePhysicsCollider(this)}_parse(e){null!=e.friction&&(this.friction=e.friction),null!=e.rollingFriction&&(this.rollingFriction=e.rollingFriction),null!=e.restitution&&(this.restitution=e.restitution),null!=e.isTrigger&&(this.isTrigger=e.isTrigger),super._parse(e),this._parseShape(e.shapes)}_onAdded(){var e=Y._bullet,t=e.btCollisionObject_create();e.btCollisionObject_setUserIndex(t,this.id),e.btCollisionObject_forceActivationState(t,P.ACTIVATIONSTATE_DISABLE_SIMULATION);var r=e.btCollisionObject_getCollisionFlags(t);this.owner.isStatic?((r&P.COLLISIONFLAGS_KINEMATIC_OBJECT)>0&&(r^=P.COLLISIONFLAGS_KINEMATIC_OBJECT),r|=P.COLLISIONFLAGS_STATIC_OBJECT):((r&P.COLLISIONFLAGS_STATIC_OBJECT)>0&&(r^=P.COLLISIONFLAGS_STATIC_OBJECT),r|=P.COLLISIONFLAGS_KINEMATIC_OBJECT),e.btCollisionObject_setCollisionFlags(t,r),this._btColliderObject=t,super._onAdded()}}class xi extends Gt{constructor(e){super(),this._id=++xi._uniqueIDCounter,this._mesh=e,this._boneIndicesList=[],this._subIndexBufferStart=[],this._subIndexBufferCount=[]}get indexCount(){return this._indexCount}_setIndexRange(t,r,i=e.IndexFormat.UInt16){this._indexStart=t,this._indexCount=r,i==e.IndexFormat.UInt16?this._indices=new Uint16Array(this._indexBuffer.getData().buffer,2*t,r):this._indices=new Uint32Array(this._indexBuffer.getData().buffer,4*t,r)}_getType(){return xi._type}_prepareRender(e){return this._mesh._uploadVerticesData(),!0}_render(r){var i=this._mesh;if(i.indexFormat!==e.IndexFormat.UInt32||t.LayaGL.layaGPUInstance.supportElementIndexUint32()){var a,n,s=t.LayaGL.instance,o=r.renderElement.render._skinnedData;switch(i.indexFormat){case e.IndexFormat.UInt32:a=s.UNSIGNED_INT,n=4;break;case e.IndexFormat.UInt16:a=s.UNSIGNED_SHORT,n=2;break;case e.IndexFormat.UInt8:a=s.UNSIGNED_BYTE,n=1}if(i._bufferState.bind(),o)for(var l=o[this._indexInMesh],_=0,h=this._boneIndicesList.length;_<h;_++)r.shader.uploadCustomUniform(di.BONES,l[_]),s.drawElements(s.TRIANGLES,this._subIndexBufferCount[_],a,this._subIndexBufferStart[_]*n);else s.drawElements(s.TRIANGLES,this._indexCount,a,this._indexStart*n);t.Stat.trianglesFaces+=this._indexCount/3,t.Stat.renderBatches++}else console.warn("SubMesh:this device do not support IndexFormat.UInt32.")}getIndices(){if(this._mesh._isReadable)return this._indices.slice();throw"SubMesh:can't get indices on subMesh,mesh's isReadable must be true."}setIndices(e){this._indexBuffer.setData(e,this._indexStart,0,this._indexCount)}destroy(){this._destroyed||(super.destroy(),this._indexBuffer.destroy(),this._indexBuffer=null,this._mesh=null,this._boneIndicesList=null,this._subIndexBufferStart=null,this._subIndexBufferCount=null,this._skinAnimationDatas=null)}}xi._uniqueIDCounter=0,xi._type=Gt._typeCounter++;class Ai{constructor(e,t,r){this.subMeshIndex=e,this.batchIndex=t,this.batchBoneIndex=r}}class Ii extends t.Resource{constructor(t=!0){super(),this._tempVector30=new n,this._tempVector31=new n,this._tempVector32=new n,this._minVerticesUpdate=-1,this._maxVerticesUpdate=-1,this._needUpdateBounds=!0,this._bounds=new Ut(new n,new n),this._bufferState=new Ee,this._instanceBufferState=new Ee,this._instanceBufferStateType=0,this._vertexBuffer=null,this._indexBuffer=null,this._skinnedMatrixCaches=[],this._vertexCount=0,this._indexFormat=e.IndexFormat.UInt16,this._isReadable=t,this._subMeshes=[]}static __init__(){var e=Y._bullet;e&&(Ii._nativeTempVector30=e.btVector3_create(0,0,0),Ii._nativeTempVector31=e.btVector3_create(0,0,0),Ii._nativeTempVector32=e.btVector3_create(0,0,0))}static load(e,r){t.ILaya.loader.create(e,r,null,Ii.MESH)}get inverseAbsoluteBindPoses(){return this._inverseBindPoses}get vertexCount(){return this._vertexCount}get indexCount(){return this._indexBuffer.indexCount}get subMeshCount(){return this._subMeshes.length}get bounds(){return this._bounds}set bounds(e){this._bounds!==e&&e.cloneTo(this._bounds)}get indexFormat(){return this._indexFormat}_getPositionElement(e){for(var t=e.vertexDeclaration._vertexElements,r=0,i=t.length;r<i;r++){var a=t[r];if(a._elementFormat===ue.Vector3&&a._elementUsage===ze.MESH_POSITION0)return a}return null}_getVerticeElementData(e,t){e.length=this._vertexCount;var r=this._vertexBuffer.vertexDeclaration,s=r.getVertexElementByUsage(t);if(s){var o=this._vertexBuffer.getUint8Data(),l=this._vertexBuffer.getFloat32Data(),_=r.vertexStride,h=_/4,c=s._offset,d=c/4;switch(t){case ze.MESH_TEXTURECOORDINATE0:case ze.MESH_TEXTURECOORDINATE1:for(var u=0;u<this._vertexCount;u++){var m=h*u+d;e[u]=new i(l[m],l[m+1])}break;case ze.MESH_POSITION0:case ze.MESH_NORMAL0:for(u=0;u<this._vertexCount;u++){m=h*u+d;e[u]=new n(l[m],l[m+1],l[m+2])}break;case ze.MESH_TANGENT0:case ze.MESH_BLENDWEIGHT0:for(u=0;u<this._vertexCount;u++){m=h*u+d;e[u]=new a(l[m],l[m+1],l[m+2],l[m+3])}break;case ze.MESH_COLOR0:for(u=0;u<this._vertexCount;u++){m=h*u+d;e[u]=new xt(l[m],l[m+1],l[m+2],l[m+3])}break;case ze.MESH_BLENDINDICES0:for(u=0;u<this._vertexCount;u++){m=_*u+c;e[u]=new a(o[m],o[m+1],o[m+2],o[m+3])}break;default:throw"Mesh:Unknown elementUsage."}}}_setVerticeElementData(e,t){var r=this._vertexBuffer.vertexDeclaration,i=r.getVertexElementByUsage(t);if(i){var a=this._vertexBuffer.getUint8Data(),n=this._vertexBuffer.getFloat32Data(),s=r.vertexStride,o=s/4,l=i._offset,_=l/4;switch(t){case ze.MESH_TEXTURECOORDINATE0:case ze.MESH_TEXTURECOORDINATE1:for(var h=0,c=e.length;h<c;h++){var d=o*h+_,u=e[h];n[d]=u.x,n[d+1]=u.y}break;case ze.MESH_POSITION0:case ze.MESH_NORMAL0:for(h=0,c=e.length;h<c;h++){d=o*h+_;var m=e[h];n[d]=m.x,n[d+1]=m.y,n[d+2]=m.z}break;case ze.MESH_TANGENT0:case ze.MESH_BLENDWEIGHT0:for(h=0,c=e.length;h<c;h++){d=o*h+_;var f=e[h];n[d]=f.x,n[d+1]=f.y,n[d+2]=f.z,n[d+3]=f.w}break;case ze.MESH_COLOR0:for(h=0,c=e.length;h<c;h++){d=o*h+_;var T=e[h];n[d]=T.r,n[d+1]=T.g,n[d+2]=T.b,n[d+3]=T.a}break;case ze.MESH_BLENDINDICES0:for(h=0,c=e.length;h<c;h++){d=s*h+l,f=e[h];a[d]=f.x,a[d+1]=f.y,a[d+2]=f.z,a[d+3]=f.w}break;default:throw"Mesh:Unknown elementUsage."}this._minVerticesUpdate=0,this._maxVerticesUpdate=Number.MAX_SAFE_INTEGER}else console.warn("Mesh: the mesh don't have this VertexElement.")}_disposeResource(){for(var e=0,t=this._subMeshes.length;e<t;e++)this._subMeshes[e].destroy();this._btTriangleMesh&&Y._bullet.btStridingMeshInterface_destroy(this._btTriangleMesh),this._vertexBuffer.destroy(),this._indexBuffer.destroy(),this._bufferState.destroy(),this._instanceBufferState.destroy(),this._setCPUMemory(0),this._setGPUMemory(0),this._bufferState=null,this._instanceBufferState=null,this._vertexBuffer=null,this._indexBuffer=null,this._subMeshes=null,this._btTriangleMesh=null,this._indexBuffer=null,this._boneNames=null,this._inverseBindPoses=null}_setSubMeshes(e){this._subMeshes=e;for(var t=0,r=e.length;t<r;t++)e[t]._indexInMesh=t}_setBuffer(e,t){var r=this._bufferState;r.bind(),r.applyVertexBuffer(e),r.applyIndexBuffer(t),r.unBind()}_setInstanceBuffer(e){var t=this._instanceBufferState;switch(t.bind(),t.applyVertexBuffer(this._vertexBuffer),t.applyInstanceVertexBuffer(Xt.instance.instanceWorldMatrixBuffer),t.applyInstanceVertexBuffer(Xt.instance.instanceMVPMatrixBuffer),e){case Ii.MESH_INSTANCEBUFFER_TYPE_SIMPLEANIMATOR:t.applyInstanceVertexBuffer(Xt.instance.instanceSimpleAnimatorBuffer)}t.applyIndexBuffer(this._indexBuffer),t.unBind()}_getPhysicMesh(){if(!this._btTriangleMesh){for(var e=Y._bullet,t=e.btTriangleMesh_create(),r=Ii._nativeTempVector30,i=Ii._nativeTempVector31,a=Ii._nativeTempVector32,n=this._tempVector30,s=this._tempVector31,o=this._tempVector32,l=this._vertexBuffer,_=this._getPositionElement(l),h=l.getFloat32Data(),c=l.vertexDeclaration.vertexStride/4,d=_._offset/4,u=this._indexBuffer.getData(),m=0,f=u.length;m<f;m+=3){var T=u[m]*c+d,E=u[m+1]*c+d,p=u[m+2]*c+d;n.setValue(h[T],h[T+1],h[T+2]),s.setValue(h[E],h[E+1],h[E+2]),o.setValue(h[p],h[p+1],h[p+2]),H._convertToBulletVec3(n,r,!0),H._convertToBulletVec3(s,i,!0),H._convertToBulletVec3(o,a,!0),e.btTriangleMesh_addTriangle(t,r,i,a,!0)}this._btTriangleMesh=t}return this._btTriangleMesh}_uploadVerticesData(){var e=this._minVerticesUpdate,t=this._maxVerticesUpdate;if(-1!==e&&-1!==t){var r=e;this._vertexBuffer.setData(this._vertexBuffer.getUint8Data().buffer,r,r,t-e),this._minVerticesUpdate=-1,this._maxVerticesUpdate=-1}}getSubMesh(e){return this._subMeshes[e]}getPositions(e){if(!this._isReadable)throw"Mesh:can't get positions on mesh,isReadable must be true.";this._getVerticeElementData(e,ze.MESH_POSITION0)}setPositions(e){if(!this._isReadable)throw"Mesh:setPosition() need isReadable must be true or use setVertices().";this._setVerticeElementData(e,ze.MESH_POSITION0),this._needUpdateBounds=!0}getColors(e){if(!this._isReadable)throw"Mesh:can't get colors on mesh,isReadable must be true.";this._getVerticeElementData(e,ze.MESH_COLOR0)}setColors(e){if(!this._isReadable)throw"Mesh:setColors() need isReadable must be true or use setVertices().";this._setVerticeElementData(e,ze.MESH_COLOR0)}getUVs(e,t=0){if(!this._isReadable)throw"Mesh:can't get uvs on mesh,isReadable must be true.";switch(t){case 0:this._getVerticeElementData(e,ze.MESH_TEXTURECOORDINATE0);break;case 1:this._getVerticeElementData(e,ze.MESH_TEXTURECOORDINATE1);break;default:throw"Mesh:Invalid channel."}}setUVs(e,t=0){if(!this._isReadable)throw"Mesh:setUVs() need isReadable must be true or use setVertices().";switch(t){case 0:this._setVerticeElementData(e,ze.MESH_TEXTURECOORDINATE0);break;case 1:this._setVerticeElementData(e,ze.MESH_TEXTURECOORDINATE1);break;default:throw"Mesh:Invalid channel."}}getNormals(e){if(!this._isReadable)throw"Mesh:can't get colors on mesh,isReadable must be true.";this._getVerticeElementData(e,ze.MESH_NORMAL0)}setNormals(e){if(!this._isReadable)throw"Mesh:setNormals() need must be true or use setVertices().";this._setVerticeElementData(e,ze.MESH_NORMAL0)}getTangents(e){if(!this._isReadable)throw"Mesh:can't get colors on mesh,isReadable must be true.";this._getVerticeElementData(e,ze.MESH_TANGENT0)}setTangents(e){if(!this._isReadable)throw"Mesh:setTangents() need isReadable must be true or use setVertices().";this._setVerticeElementData(e,ze.MESH_TANGENT0)}getBoneWeights(e){if(!this._isReadable)throw"Mesh:can't get boneWeights on mesh,isReadable must be true.";this._getVerticeElementData(e,ze.MESH_BLENDWEIGHT0)}setBoneWeights(e){if(!this._isReadable)throw"Mesh:setBoneWeights() need isReadable must be true or use setVertices().";this._setVerticeElementData(e,ze.MESH_BLENDWEIGHT0)}getBoneIndices(e){if(!this._isReadable)throw"Mesh:can't get boneIndices on mesh,isReadable must be true.";this._getVerticeElementData(e,ze.MESH_BLENDINDICES0)}setBoneIndices(e){if(!this._isReadable)throw"Mesh:setBoneIndices() need isReadable must be true or use setVertices().";this._setVerticeElementData(e,ze.MESH_BLENDINDICES0)}markAsUnreadbale(){this._uploadVerticesData(),this._vertexBuffer.markAsUnreadbale(),this._isReadable=!1}getVertexDeclaration(){return this._vertexBuffer._vertexDeclaration}getVertices(){if(this._isReadable)return this._vertexBuffer.getUint8Data().buffer.slice(0);throw"Mesh:can't get vertices on mesh,isReadable must be true."}setVertices(e){this._vertexBuffer.setData(e),this._needUpdateBounds=!0}getIndices(){if(this._isReadable)return this._indexBuffer.getData().slice();throw"Mesh:can't get indices on subMesh,mesh's isReadable must be true."}setIndices(r){var i;r instanceof Uint32Array?i=e.IndexFormat.UInt32:r instanceof Uint16Array?i=e.IndexFormat.UInt16:r instanceof Uint8Array&&(i=e.IndexFormat.UInt8);var a=this._indexBuffer;this._indexFormat===i&&a.indexCount===r.length||(a.destroy(),this._indexBuffer=a=new Ge(i,r.length,t.LayaGL.instance.STATIC_DRAW,this._isReadable)),a.setData(r),this._indexFormat=i}calculateBounds(){if(!this._isReadable)throw"Mesh:can't calculate bounds on subMesh,mesh's isReadable must be true.";if(this._needUpdateBounds){var e=this._tempVector30,t=this._tempVector31;e.x=e.y=e.z=Number.MAX_VALUE,t.x=t.y=t.z=-Number.MAX_VALUE;for(var r=this._vertexBuffer,i=this._getPositionElement(r),a=r.getFloat32Data(),n=r.vertexDeclaration.vertexStride/4,s=i._offset/4,o=0,l=a.length;o<l;o+=n){var _=o+s,h=a[_],c=a[_+1],d=a[_+2];e.x=Math.min(e.x,h),e.y=Math.min(e.y,c),e.z=Math.min(e.z,d),t.x=Math.max(t.x,h),t.y=Math.max(t.y,c),t.z=Math.max(t.z,d)}this._bounds.setMin(e),this._bounds.setMax(t),this._needUpdateBounds=!1}}cloneTo(t){var r=t,i=this._vertexBuffer,a=new de(i._byteLength,i.bufferUsage,i.canRead);a.vertexDeclaration=i.vertexDeclaration,a.setData(i.getUint8Data().slice().buffer),r._vertexBuffer=a,r._vertexCount=this._vertexCount;var n,s=this._indexBuffer,o=new Ge(e.IndexFormat.UInt16,s.indexCount,s.bufferUsage,s.canRead);o.setData(s.getData().slice()),r._indexBuffer=o,r._setBuffer(r._vertexBuffer,o),r._setInstanceBuffer(this._instanceBufferStateType),r._setCPUMemory(this.cpuMemory),r._setGPUMemory(this.gpuMemory);var l=this._boneNames;if(l){var _=r._boneNames=[];for(n=0;n<l.length;n++)_[n]=l[n]}var h=this._inverseBindPoses;if(h){var c=r._inverseBindPoses=[];for(n=0;n<h.length;n++)c[n]=h[n]}var d=this._skinnedMatrixCaches.length;for(r._skinnedMatrixCaches.length=d,n=0;n<d;n++){var u=this._skinnedMatrixCaches[n];r._skinnedMatrixCaches[n]=new Ai(u.subMeshIndex,u.batchIndex,u.batchBoneIndex)}for(n=0;n<this.subMeshCount;n++){var m=this._subMeshes[n],f=m._subIndexBufferStart,T=m._subIndexBufferCount,E=m._boneIndicesList,p=new xi(r);p._subIndexBufferStart.length=f.length,p._subIndexBufferCount.length=T.length,p._boneIndicesList.length=E.length;for(var g=0;g<f.length;g++)p._subIndexBufferStart[g]=f[g];for(g=0;g<T.length;g++)p._subIndexBufferCount[g]=T[g];for(g=0;g<E.length;g++)p._boneIndicesList[g]=new Uint16Array(E[g]);p._indexBuffer=o,p._indexStart=m._indexStart,p._indexCount=m._indexCount,p._indices=new Uint16Array(o.getData().buffer,2*m._indexStart,m._indexCount);var S=r._vertexBuffer;p._vertexBuffer=S,r._subMeshes.push(p)}r._setSubMeshes(r._subMeshes)}clone(){var e=new Ii;return this.cloneTo(e),e}}Ii.MESH="MESH",Ii.MESH_INSTANCEBUFFER_TYPE_NORMAL=0,Ii.MESH_INSTANCEBUFFER_TYPE_SIMPLEANIMATOR=1;class Mi{static __init__(){}static _createMesh(r,i,a){var n=t.LayaGL.instance,s=new Ii,o=new xi(s),l=new de(4*i.length,n.STATIC_DRAW,!0);l.vertexDeclaration=r,l.setData(i.buffer),s._vertexBuffer=l,s._vertexCount=l._byteLength/r.vertexStride;var _=new Ge(e.IndexFormat.UInt16,a.length,n.STATIC_DRAW,!0);_.setData(a),s._indexBuffer=_,s._setBuffer(l,_),s._setInstanceBuffer(s._instanceBufferStateType),o._vertexBuffer=l,o._indexBuffer=_,o._setIndexRange(0,_.indexCount);var h=o._subIndexBufferStart,c=o._subIndexBufferCount,d=o._boneIndicesList;h.length=1,c.length=1,d.length=1,h[0]=0,c[0]=_.indexCount;var u=[];u.push(o),s._setSubMeshes(u),s.calculateBounds();var m=l._byteLength+_._byteLength;return s._setCPUMemory(m),s._setGPUMemory(m),s}static createBox(e=1,t=1,r=1){var i=ze.getVertexDeclaration("POSITION,NORMAL,UV"),a=e/2,n=t/2,s=r/2,o=new Float32Array([-a,n,-s,0,1,0,0,0,a,n,-s,0,1,0,1,0,a,n,s,0,1,0,1,1,-a,n,s,0,1,0,0,1,-a,-n,-s,0,-1,0,0,1,a,-n,-s,0,-1,0,1,1,a,-n,s,0,-1,0,1,0,-a,-n,s,0,-1,0,0,0,-a,n,-s,-1,0,0,0,0,-a,n,s,-1,0,0,1,0,-a,-n,s,-1,0,0,1,1,-a,-n,-s,-1,0,0,0,1,a,n,-s,1,0,0,1,0,a,n,s,1,0,0,0,0,a,-n,s,1,0,0,0,1,a,-n,-s,1,0,0,1,1,-a,n,s,0,0,1,0,0,a,n,s,0,0,1,1,0,a,-n,s,0,0,1,1,1,-a,-n,s,0,0,1,0,1,-a,n,-s,0,0,-1,1,0,a,n,-s,0,0,-1,0,0,a,-n,-s,0,0,-1,0,1,-a,-n,-s,0,0,-1,1,1]),l=new Uint16Array([0,1,2,2,3,0,4,7,6,6,5,4,8,9,10,10,11,8,12,15,14,14,13,12,16,17,18,18,19,16,20,23,22,22,21,20]);return Mi._createMesh(i,o,l)}static createCapsule(e=.5,t=2,r=16,i=32){var a,n,s=(r+1)*(i+1)*2+2*(i+1),o=3*r*(i+1)*2*2+2*i*3,l=ze.getVertexDeclaration("POSITION,NORMAL,UV"),_=l.vertexStride/4,h=new Float32Array(s*_),c=new Uint16Array(o),d=Math.PI/2/r,u=2*Math.PI/i,m=t/2-e,f=0,T=0,E=0,p=0,g=0,S=0;for(a=0;a<=r;a++)for(n=0;n<=i;n++)f=e*Math.cos(a*d)*Math.cos(n*u+Math.PI),T=e*Math.sin(a*d),E=e*Math.cos(a*d)*Math.sin(n*u+Math.PI),h[p++]=f,h[p++]=T+m,h[p++]=E,h[p++]=f,h[p++]=T,h[p++]=E,h[p++]=1-n/i,h[p++]=(1-a/r)*(Math.PI*e/2/(t+Math.PI*e)),a<r&&(c[g++]=a*(i+1)+n+(i+1),c[g++]=a*(i+1)+n,c[g++]=a*(i+1)+n+1,c[g++]=a*(i+1)+n+i,c[g++]=a*(i+1)+n,c[g++]=a*(i+1)+n+(i+1));for(S+=(r+1)*(i+1),a=0;a<=r;a++)for(n=0;n<=i;n++)f=e*Math.cos(a*d)*Math.cos(n*u+Math.PI),T=e*Math.sin(-a*d),E=e*Math.cos(a*d)*Math.sin(n*u+Math.PI),h[p++]=f,h[p++]=T-m,h[p++]=E,h[p++]=f,h[p++]=T,h[p++]=E,h[p++]=1-n/i,h[p++]=(a/r*(Math.PI*e/2)+(t+Math.PI*e/2))/(t+Math.PI*e),a<r&&(c[g++]=S+a*(i+1)+n,c[g++]=S+a*(i+1)+n+(i+1),c[g++]=S+a*(i+1)+n+1,c[g++]=S+a*(i+1)+n,c[g++]=S+a*(i+1)+n+i,c[g++]=S+a*(i+1)+n+(i+1));for(S+=(r+1)*(i+1),n=0;n<=i;n++)f=e*Math.cos(n*u+Math.PI),T=m,E=e*Math.sin(n*u+Math.PI),h[p++]=f,h[p+8*(i+1)-1]=f,h[p++]=T,h[p+8*(i+1)-1]=-T,h[p++]=E,h[p+8*(i+1)-1]=E,h[p++]=f,h[p+8*(i+1)-1]=f,h[p++]=0,h[p+8*(i+1)-1]=0,h[p++]=E,h[p+8*(i+1)-1]=E,h[p++]=1-1*n/i,h[p+8*(i+1)-1]=1-1*n/i,h[p++]=Math.PI*e/2/(t+Math.PI*e),h[p+8*(i+1)-1]=(Math.PI*e/2+t)/(t+Math.PI*e);for(n=0;n<i;n++)c[g++]=n+S+(i+1),c[g++]=n+S+1,c[g++]=n+S,c[g++]=n+S+(i+1),c[g++]=n+S+(i+1)+1,c[g++]=n+S+1;return S+=2*(i+1),Mi._createMesh(l,h,c)}static createCone(e=.5,t=1,r=32){for(var i,a=r+1+1+2*(r+1),s=6*r+3*r,o=ze.getVertexDeclaration("POSITION,NORMAL,UV"),l=o.vertexStride/4,_=new Float32Array(a*l),h=new Uint16Array(s),c=2*Math.PI/r,d=t/2,u=0,m=0,f=0,T=0,E=0,p=new n,g=new n(0,-1,0),R=new n(0,d,0),v=new n,x=new n,A=new S,I=new n,M=0,D=0,C=0;C<=r;C++)u=C*c,f=Math.cos(u+Math.PI)*e,T=d,E=Math.sin(u+Math.PI)*e,_[M++]=0,_[M+8*(r+1)-1]=f,_[M++]=T,_[M+8*(r+1)-1]=-T,_[M++]=0,_[M+8*(r+1)-1]=E,p.x=f,p.y=0,p.z=E,v.x=f,v.y=-T,v.z=E,n.subtract(v,R,x),n.normalize(x,x),i=Math.acos(n.dot(g,x)),n.cross(g,x,I),n.normalize(I,I),S.createFromAxisAngle(I,i,A),n.normalize(p,p),n.transformQuat(p,A,p),n.normalize(p,p),_[M++]=p.x,_[M+8*(r+1)-1]=p.x,_[M++]=p.y,_[M+8*(r+1)-1]=p.y,_[M++]=p.z,_[M+8*(r+1)-1]=p.z,_[M++]=1-1*C/r,_[M+8*(r+1)-1]=1-1*C/r,_[M++]=0,_[M+8*(r+1)-1]=1;M+=8*(r+1);for(var y=0;y<r;y++)h[D++]=y+m+(r+1),h[D++]=y+m+1,h[D++]=y+m,h[D++]=y+m+(r+1),h[D++]=y+m+(r+1)+1,h[D++]=y+m+1;m+=2*(r+1);for(var L=0;L<=r;L++)0===L&&(_[M++]=0,_[M++]=-d,_[M++]=0,_[M++]=0,_[M++]=-1,_[M++]=0,_[M++]=.5,_[M++]=.5),u=L*c,f=Math.cos(u+Math.PI)*e,T=-d,E=Math.sin(u+Math.PI)*e,_[M++]=f,_[M++]=T,_[M++]=E,_[M++]=0,_[M++]=-1,_[M++]=0,_[M++]=.5+.5*Math.cos(u),_[M++]=.5+.5*Math.sin(u);for(var O=0;O<r;O++)h[D++]=0+m,h[D++]=O+2+m,h[D++]=O+1+m;return m+=r+1+1,Mi._createMesh(o,_,h)}static createCylinder(e=.5,t=2,r=32){for(var i=r+1+1+2*(r+1)+(r+1+1),a=3*r+6*r+3*r,n=ze.getVertexDeclaration("POSITION,NORMAL,UV"),s=n.vertexStride/4,o=new Float32Array(i*s),l=new Uint16Array(a),_=2*Math.PI/r,h=t/2,c=0,d=0,u=0,m=0,f=0,T=0,E=0,p=0;p<=r;p++)0===p&&(o[T++]=0,o[T++]=h,o[T++]=0,o[T++]=0,o[T++]=1,o[T++]=0,o[T++]=.5,o[T++]=.5),c=p*_,u=Math.cos(c)*e,m=h,f=Math.sin(c)*e,o[T++]=u,o[T++]=m,o[T++]=f,o[T++]=0,o[T++]=1,o[T++]=0,o[T++]=.5+.5*Math.cos(c),o[T++]=.5+.5*Math.sin(c);for(var g=0;g<r;g++)l[E++]=0,l[E++]=g+1,l[E++]=g+2;d+=r+1+1;for(var S=0;S<=r;S++)c=S*_,u=Math.cos(c+Math.PI)*e,m=h,f=Math.sin(c+Math.PI)*e,o[T++]=u,o[T+8*(r+1)-1]=u,o[T++]=m,o[T+8*(r+1)-1]=-m,o[T++]=f,o[T+8*(r+1)-1]=f,o[T++]=u,o[T+8*(r+1)-1]=u,o[T++]=0,o[T+8*(r+1)-1]=0,o[T++]=f,o[T+8*(r+1)-1]=f,o[T++]=1-1*S/r,o[T+8*(r+1)-1]=1-1*S/r,o[T++]=0,o[T+8*(r+1)-1]=1;T+=8*(r+1);for(var R=0;R<r;R++)l[E++]=R+d+(r+1),l[E++]=R+d+1,l[E++]=R+d,l[E++]=R+d+(r+1),l[E++]=R+d+(r+1)+1,l[E++]=R+d+1;d+=2*(r+1);for(var v=0;v<=r;v++)0===v&&(o[T++]=0,o[T++]=-h,o[T++]=0,o[T++]=0,o[T++]=-1,o[T++]=0,o[T++]=.5,o[T++]=.5),c=v*_,u=Math.cos(c+Math.PI)*e,m=-h,f=Math.sin(c+Math.PI)*e,o[T++]=u,o[T++]=m,o[T++]=f,o[T++]=0,o[T++]=-1,o[T++]=0,o[T++]=.5+.5*Math.cos(c),o[T++]=.5+.5*Math.sin(c);for(var x=0;x<r;x++)l[E++]=0+d,l[E++]=x+2+d,l[E++]=x+1+d;return d+=r+1+1,Mi._createMesh(n,o,l)}static createPlane(e=10,t=10,r=10,i=10){for(var a=(r+1)*(i+1),n=new Uint16Array(r*i*2*3),s=ze.getVertexDeclaration("POSITION,NORMAL,UV"),o=s.vertexStride/4,l=new Float32Array(a*o),_=e/2,h=t/2,c=e/r,d=t/i,u=0,m=0;m<=i;m++)for(var f=0;f<=r;f++)l[u++]=f*c-_,l[u++]=0,l[u++]=m*d-h,l[u++]=0,l[u++]=1,l[u++]=0,l[u++]=1*f/r,l[u++]=1*m/i;var T=0;for(m=0;m<i;m++)for(f=0;f<r;f++)n[T++]=(m+1)*(r+1)+f,n[T++]=m*(r+1)+f,n[T++]=(m+1)*(r+1)+f+1,n[T++]=m*(r+1)+f,n[T++]=m*(r+1)+f+1,n[T++]=(m+1)*(r+1)+f+1;return Mi._createMesh(s,l,n)}static createQuad(e=1,t=1){var r=ze.getVertexDeclaration("POSITION,NORMAL,UV"),i=e/2,a=t/2,n=new Float32Array([-i,a,0,0,0,1,0,0,i,a,0,0,0,1,1,0,-i,-a,0,0,0,1,0,1,i,-a,0,0,0,1,1,1]),s=new Uint16Array([0,1,2,3,2,1]);return Mi._createMesh(r,n,s)}static createSphere(e=.5,t=32,r=32){var i=(t+1)*(r+1),a=3*t*(r+1)*2,n=new Uint16Array(a),s=ze.getVertexDeclaration("POSITION,NORMAL,UV"),o=s.vertexStride/4,l=new Float32Array(i*o),_=Math.PI/t,h=2*Math.PI/r,c=0;i=0,a=0;for(var d=0;d<t+1;d++)for(var u=Math.sin(d*_),m=Math.cos(d*_),f=0;f<r+1;f++){var T=u*Math.sin(f*h+1*Math.PI/2),E=u*Math.cos(f*h+1*Math.PI/2);l[i+0]=T*e,l[i+1]=m*e,l[i+2]=E*e,l[i+3]=T,l[i+4]=m,l[i+5]=E,l[i+6]=f/r,l[i+7]=d/t,i+=o,d!=t-1&&(n[a++]=c+(r+1),n[a++]=c,n[a++]=c+1,n[a++]=c+r,n[a++]=c,n[a++]=c+(r+1),c++)}return Mi._createMesh(s,l,n)}}var Di='#include "Lighting.glsl";\r\n#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\nattribute vec4 a_PositionTexcoord;\r\nvarying vec2 v_Texcoord0;\r\n\r\nvoid main() {\r\n\tgl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\r\n\tv_Texcoord0 = a_PositionTexcoord.zw;\r\n\tgl_Position = remapGLPositionZ(gl_Position);\r\n}';class Ci{constructor(){}static __init__(){xe.SHADERDEFINE_LEGACYSINGALLIGHTING=xe.getDefineByName("LEGACYSINGLELIGHTING"),xe.SHADERDEFINE_GRAPHICS_API_GLES2=xe.getDefineByName("GRAPHICS_API_GLES2"),xe.SHADERDEFINE_GRAPHICS_API_GLES3=xe.getDefineByName("GRAPHICS_API_GLES3"),xe.addInclude("Lighting.glsl","#ifdef GRAPHICS_API_GLES3\r\n\t#define INVERSE_MAT(mat) inverse(mat)\r\n#else\r\n\t#define INVERSE_MAT(mat) inverseMat(mat)\r\n#endif\r\n\r\nstruct DirectionLight {\r\n\tvec3 color;\r\n\tvec3 direction;\r\n};\r\n\r\nstruct PointLight {\r\n\tvec3 color;\r\n\tvec3 position;\r\n\tfloat range;\r\n};\r\n\r\nstruct SpotLight {\r\n\tvec3 color;\r\n\tvec3 position;\r\n\tfloat range;\r\n\tvec3 direction;\r\n\tfloat spot;\r\n};\r\n\r\nstruct LayaGI{\r\n\tvec3 diffuse;\r\n\tvec3 specular;\r\n};\r\n\r\nstruct LayaLight{\r\n\tvec3 color;\r\n\tvec3 dir;\r\n};\r\n\r\nconst int c_ClusterBufferWidth = CLUSTER_X_COUNT*CLUSTER_Y_COUNT;\r\nconst int c_ClusterBufferHeight = CLUSTER_Z_COUNT*(1+int(ceil(float(MAX_LIGHT_COUNT_PER_CLUSTER)/4.0)));\r\nconst int c_ClusterBufferFloatWidth = c_ClusterBufferWidth*4;\r\n\r\n#ifndef GRAPHICS_API_GLES3\r\n\tmat3 inverseMat(mat3 m) {\r\n\t\tfloat a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];\r\n\t\tfloat a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];\r\n\t\tfloat a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];\r\n\r\n\t\tfloat b01 = a22 * a11 - a12 * a21;\r\n\t\tfloat b11 = -a22 * a10 + a12 * a20;\r\n\t\tfloat b21 = a21 * a10 - a11 * a20;\r\n\r\n\t\tfloat det = a00 * b01 + a01 * b11 + a02 * b21;\r\n\r\n\t\treturn mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),\r\n\t\t\t\t\tb11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),\r\n\t\t\t\t\tb21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;\r\n\t}\r\n#endif\r\n\r\nivec4 getClusterInfo(sampler2D clusterBuffer,mat4 viewMatrix,vec4 viewport,vec3 position,vec4 fragCoord,vec4 projectParams)\r\n{\r\n\tvec3 viewPos = vec3(viewMatrix*vec4(position, 1.0)); //position in viewspace\r\n\r\n\tint clusterXIndex = int(floor(fragCoord.x/ (float(viewport.z)/float(CLUSTER_X_COUNT))));\r\n int clusterYIndex = int(floor((viewport.w * (projectParams.z <0.0? 0.0 : 1.0) - fragCoord.y * projectParams.z)/ (float(viewport.w)/float(CLUSTER_Y_COUNT))));//Maybe Flipped ProjectMatrix\r\n\tfloat zSliceParam =float(CLUSTER_Z_COUNT)/log2(projectParams.y / projectParams.x);\r\n \tint clusterZIndex = int(floor(log2(-viewPos.z) * zSliceParam- log2(projectParams.x) * zSliceParam));//projectParams x:cameraNear y:cameraFar\r\n\r\n\tvec2 uv= vec2((float(clusterXIndex + clusterYIndex * CLUSTER_X_COUNT)+0.5)/float(c_ClusterBufferWidth),\r\n\t\t\t\t(float(clusterZIndex)+0.5)/float(c_ClusterBufferHeight));\r\n\tvec4 clusterPixel=texture2D(clusterBuffer, uv);\r\n\treturn ivec4(clusterPixel);//X:Point Count Y:Spot Count Z、W:Light Offset\r\n}\r\n\r\n\r\nint getLightIndex(sampler2D clusterBuffer,int offset,int index) \r\n{\r\n\tint totalOffset=offset+index;\r\n\tint row=totalOffset/c_ClusterBufferFloatWidth;\r\n\tint lastRowFloat=totalOffset-row*c_ClusterBufferFloatWidth;\r\n\tint col=lastRowFloat/4;\r\n\tvec2 uv=vec2((float(col)+0.5)/float(c_ClusterBufferWidth),\r\n\t\t\t\t(float(row)+0.5)/float(c_ClusterBufferHeight));\r\n\tvec4 texel = texture2D(clusterBuffer, uv);\r\n int pixelComponent = lastRowFloat-col*4;\r\n if (pixelComponent == 0) \r\n return int(texel.x);\r\n else if (pixelComponent == 1) \r\n return int(texel.y);\r\n else if (pixelComponent == 2) \r\n return int(texel.z);\r\n else //pixelComponent==3\r\n return int(texel.w);\r\n}\r\n\r\nDirectionLight getDirectionLight(sampler2D lightBuffer,int index) \r\n{\r\n DirectionLight light;\r\n float v = (float(index)+0.5)/ float(MAX_LIGHT_COUNT);\r\n vec4 p1 = texture2D(lightBuffer, vec2(0.125,v));\r\n vec4 p2 = texture2D(lightBuffer, vec2(0.375,v));\r\n\tlight.color=p1.rgb;\r\n light.direction = p2.rgb;\r\n return light;\r\n}\r\n\r\nPointLight getPointLight(sampler2D lightBuffer,sampler2D clusterBuffer,ivec4 clusterInfo,int index) \r\n{\r\n PointLight light;\r\n\tint pointIndex=getLightIndex(clusterBuffer,clusterInfo.z*c_ClusterBufferFloatWidth+clusterInfo.w,index);\r\n float v = (float(pointIndex)+0.5)/ float(MAX_LIGHT_COUNT);\r\n vec4 p1 = texture2D(lightBuffer, vec2(0.125,v));\r\n vec4 p2 = texture2D(lightBuffer, vec2(0.375,v));\r\n\tlight.color=p1.rgb;\r\n\tlight.range = p1.a;\r\n light.position = p2.rgb;\r\n return light;\r\n}\r\n\r\nSpotLight getSpotLight(sampler2D lightBuffer,sampler2D clusterBuffer,ivec4 clusterInfo,int index) \r\n{\r\n SpotLight light;\r\n\tint spoIndex=getLightIndex(clusterBuffer,clusterInfo.z*c_ClusterBufferFloatWidth+clusterInfo.w,clusterInfo.x+index);\r\n float v = (float(spoIndex)+0.5)/ float(MAX_LIGHT_COUNT);\r\n vec4 p1 = texture2D(lightBuffer, vec2(0.125,v));\r\n vec4 p2 = texture2D(lightBuffer, vec2(0.375,v));\r\n\tvec4 p3 = texture2D(lightBuffer, vec2(0.625,v));\r\n light.color = p1.rgb;\r\n\tlight.range=p1.a;\r\n light.position = p2.rgb;\r\n\tlight.spot = p2.a;\r\n\tlight.direction = p3.rgb;\r\n return light;\r\n}\r\n\r\n// Laya中使用衰减纹理\r\nfloat LayaAttenuation(in vec3 L,in float invLightRadius) {\r\n\tfloat fRatio = clamp(length(L) * invLightRadius,0.0,1.0);\r\n\tfRatio *= fRatio;\r\n\treturn 1.0 / (1.0 + 25.0 * fRatio)* clamp(4.0*(1.0 - fRatio),0.0,1.0); //fade to black as if 4 pixel texture\r\n}\r\n\r\n// Same as Just Cause 2 and Crysis 2 (you can read GPU Pro 1 book for more information)\r\nfloat BasicAttenuation(in vec3 L,in float invLightRadius) {\r\n\tvec3 distance = L * invLightRadius;\r\n\tfloat attenuation = clamp(1.0 - dot(distance, distance),0.0,1.0); // Equals float attenuation = saturate(1.0f - dot(L, L) / (lightRadius * lightRadius));\r\n\treturn attenuation * attenuation;\r\n}\r\n\r\n// Inspired on http://fools.slindev.com/viewtopic.php?f=11&t=21&view=unread#unread\r\nfloat NaturalAttenuation(in vec3 L,in float invLightRadius) {\r\n\tfloat attenuationFactor = 30.0;\r\n\tvec3 distance = L * invLightRadius;\r\n\tfloat attenuation = dot(distance, distance); // Equals float attenuation = dot(L, L) / (lightRadius * lightRadius);\r\n\tattenuation = 1.0 / (attenuation * attenuationFactor + 1.0);\r\n\t// Second we move down the function therewith it reaches zero at abscissa 1:\r\n\tattenuationFactor = 1.0 / (attenuationFactor + 1.0); //attenuationFactor contains now the value we have to subtract\r\n\tattenuation = max(attenuation - attenuationFactor, 0.0); // The max fixes a bug.\r\n\t// Finally we expand the equation along the y-axis so that it starts with a function value of 1 again.\r\n\tattenuation /= 1.0 - attenuationFactor;\r\n\treturn attenuation;\r\n}\r\n\r\nvoid LayaAirBlinnPhongLight (in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir,in vec3 lightColor, in vec3 lightVec,out vec3 diffuseColor,out vec3 specularColor) {\r\n\tmediump vec3 h = normalize(viewDir-lightVec);\r\n\tlowp float ln = max (0.0, dot (-lightVec,normal));\r\n\tfloat nh = max (0.0, dot (h,normal));\r\n\tdiffuseColor=lightColor * ln;\r\n\tspecularColor=lightColor *specColor*pow (nh, specColorIntensity*128.0) * gloss;\r\n}\r\n\r\nvoid LayaAirBlinnPhongDiectionLight (in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir, in DirectionLight light,out vec3 diffuseColor,out vec3 specularColor) {\r\n\tvec3 lightVec=normalize(light.direction);\r\n\tLayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.color,lightVec,diffuseColor,specularColor);\r\n}\r\n\r\nvoid LayaAirBlinnPhongPointLight (in vec3 pos,in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir, in PointLight light,out vec3 diffuseColor,out vec3 specularColor) {\r\n\tvec3 lightVec = pos-light.position;\r\n\tLayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.color,lightVec/length(lightVec),diffuseColor,specularColor);\r\n\tfloat attenuate = LayaAttenuation(lightVec, 1.0/light.range);\r\n\tdiffuseColor *= attenuate;\r\n\tspecularColor*= attenuate;\r\n}\r\n\r\nvoid LayaAirBlinnPhongSpotLight (in vec3 pos,in vec3 specColor,in float specColorIntensity,in vec3 normal,in vec3 gloss, in vec3 viewDir, in SpotLight light,out vec3 diffuseColor,out vec3 specularColor) {\r\n\tvec3 lightVec = pos-light.position;\r\n\tvec3 normalLightVec=lightVec/length(lightVec);\r\n\tLayaAirBlinnPhongLight(specColor,specColorIntensity,normal,gloss,viewDir,light.color,normalLightVec,diffuseColor,specularColor);\r\n\tvec2 cosAngles=cos(vec2(light.spot,light.spot*0.5)*0.5);//ConeAttenuation\r\n\tfloat dl=dot(normalize(light.direction),normalLightVec);\r\n\tdl*=smoothstep(cosAngles[0],cosAngles[1],dl);\r\n\tfloat attenuate = LayaAttenuation(lightVec, 1.0/light.range)*dl;\r\n\tdiffuseColor *=attenuate;\r\n\tspecularColor *=attenuate;\r\n}\r\n\r\nvec3 NormalSampleToWorldSpace(vec3 normalMapSample, vec3 unitNormal, vec3 tangent,vec3 binormal) {\r\n\tvec3 normalT =vec3(2.0*normalMapSample.x - 1.0,1.0-2.0*normalMapSample.y,2.0*normalMapSample.z - 1.0);\r\n\tmediump vec3 N = unitNormal;\r\n\tmediump vec3 T = tangent;\r\n\tmediump vec3 B = binormal;\r\n\tmat3 TBN = mat3(T, B, N);\r\n\r\n\t// Transform from tangent space to world space.\r\n\tvec3 bumpedNormal =normalize(TBN*normalT);\r\n\treturn bumpedNormal;\r\n}\r\n\r\nvec3 NormalSampleToWorldSpace1(vec4 normalMapSample, vec3 tangent, vec3 binormal, vec3 unitNormal) {\r\n\tvec3 normalT;\r\n\tnormalT.x = 2.0 * normalMapSample.x - 1.0;\r\n\tnormalT.y = 1.0 - 2.0 * normalMapSample.y;\r\n\tnormalT.z = sqrt(1.0 - clamp(dot(normalT.xy, normalT.xy), 0.0, 1.0));\r\n\r\n\tvec3 T = normalize(tangent);\r\n\tvec3 B = normalize(binormal);\r\n\tvec3 N = normalize(unitNormal);\r\n\tmat3 TBN = mat3(T, B, N);\r\n\r\n\t// Transform from tangent space to world space.\r\n\tvec3 bumpedNormal = TBN * normalize(normalT);\r\n\r\n\treturn bumpedNormal;\r\n}\r\n\r\nvec3 DecodeLightmap(vec4 color) {\r\n\treturn color.rgb*color.a*5.0;\r\n}\r\n\r\nvec3 decodeHDR(vec4 color,float range) {\r\n\treturn color.rgb*color.a*range;\r\n}\r\n\r\nvec2 TransformUV(vec2 texcoord,vec4 tilingOffset) {\r\n\tvec2 transTexcoord=vec2(texcoord.x,texcoord.y-1.0)*tilingOffset.xy+vec2(tilingOffset.z,-tilingOffset.w);\r\n\ttransTexcoord.y+=1.0;\r\n\treturn transTexcoord;\r\n}\r\n\r\nvec4 remapGLPositionZ(vec4 position) {\r\n\tposition.z=position.z * 2.0 - position.w;\r\n\treturn position;\r\n}\r\n\r\nmediump vec3 layaLinearToGammaSpace (mediump vec3 linRGB)\r\n{\r\n linRGB = max(linRGB, vec3(0.0));\r\n // An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1\r\n return max(1.055 * pow(linRGB,vec3(0.416666667)) - 0.055, 0.0); \r\n}\r\n\r\nLayaLight layaDirectionLightToLight(in DirectionLight light,in float attenuate)\r\n{\r\n\tLayaLight relight;\r\n\trelight.color = light.color*attenuate;\r\n\trelight.dir = light.direction;\r\n\treturn relight;\r\n}\r\n\r\nLayaLight layaPointLightToLight(in vec3 pos,in vec3 normal, in PointLight light,in float attenuate)\r\n{\r\n\tLayaLight relight;\r\n\tvec3 lightVec = pos-light.position;\r\n\tattenuate *= LayaAttenuation(lightVec, 1.0/light.range);\r\n\trelight.color = light.color*attenuate;\r\n\trelight.dir = normalize(lightVec);\r\n\treturn relight;\r\n}\r\n\r\nLayaLight layaSpotLightToLight(in vec3 pos,in vec3 normal, in SpotLight light,in float attenuate)\r\n{\r\n\tLayaLight relight;\r\n\tvec3 lightVec = pos-light.position;\r\n\tvec3 normalLightVec=lightVec/length(lightVec);\r\n\tvec2 cosAngles=cos(vec2(light.spot,light.spot*0.5)*0.5);//ConeAttenuation\r\n\tfloat dl=dot(normalize(light.direction),normalLightVec);\r\n\tdl*=smoothstep(cosAngles[0],cosAngles[1],dl);\r\n\tattenuate *= LayaAttenuation(lightVec, 1.0/light.range)*dl;\r\n\trelight.dir = normalLightVec;\r\n\trelight.color = light.color*attenuate;\r\n\treturn relight;\r\n}\r\n\r\n\r\n\r\n\r\n"),xe.addInclude("ShadowSampleTent.glsl",'// ------------------------------------------------------------------\r\n// PCF Filtering Tent Functions\r\n// ------------------------------------------------------------------\r\n\r\n// Assuming a isoceles right angled triangle of height "triangleHeight" (as drawn below).\r\n// This function return the area of the triangle above the first texel(in Y the first texel).\r\n//\r\n// |\\ <-- 45 degree slop isosceles right angled triangle\r\n// | \\\r\n// ---- <-- length of this side is "triangleHeight"\r\n// _ _ _ _ <-- texels\r\nfloat sampleShadowGetIRTriangleTexelArea(float triangleHeight)\r\n{\r\n return triangleHeight - 0.5;\r\n}\r\n\r\n// Assuming a isoceles triangle of 1.5 texels height and 3 texels wide lying on 4 texels.\r\n// This function return the area of the triangle above each of those texels.\r\n// | <-- offset from -0.5 to 0.5, 0 meaning triangle is exactly in the center\r\n// / \\ <-- 45 degree slop isosceles triangle (ie tent projected in 2D)\r\n// / \\\r\n// _ _ _ _ <-- texels\r\n// X Y Z W <-- result indices (in computedArea.xyzw and computedAreaUncut.xyzw)\r\n// Top point at (right,top) in a texel,left bottom point at (middle,middle) in a texel,right bottom point at (middle,middle) in a texel.\r\nvoid sampleShadowGetTexelAreasTent3x3(float offset, out vec4 computedArea, out vec4 computedAreaUncut)\r\n{\r\n // Compute the exterior areas,a and h is same.\r\n float a = offset + 0.5;\r\n float offsetSquaredHalved = a * a * 0.5;\r\n computedAreaUncut.x = computedArea.x = offsetSquaredHalved - offset;\r\n computedAreaUncut.w = computedArea.w = offsetSquaredHalved;\r\n\r\n // Compute the middle areas\r\n // For Y : We find the area in Y of as if the left section of the isoceles triangle would\r\n // intersect the axis between Y and Z (ie where offset = 0).\r\n computedAreaUncut.y = sampleShadowGetIRTriangleTexelArea(1.5 - offset);\r\n // This area is superior to the one we are looking for if (offset < 0) thus we need to\r\n // subtract the area of the triangle defined by (0,1.5-offset), (0,1.5+offset), (-offset,1.5).\r\n float clampedOffsetLeft = min(offset,0.0);\r\n float areaOfSmallLeftTriangle = clampedOffsetLeft * clampedOffsetLeft;\r\n computedArea.y = computedAreaUncut.y - areaOfSmallLeftTriangle;\r\n\r\n // We do the same for the Z but with the right part of the isoceles triangle\r\n computedAreaUncut.z = sampleShadowGetIRTriangleTexelArea(1.5 + offset);\r\n float clampedOffsetRight = max(offset,0.0);\r\n float areaOfSmallRightTriangle = clampedOffsetRight * clampedOffsetRight;\r\n computedArea.z = computedAreaUncut.z - areaOfSmallRightTriangle;\r\n}\r\n\r\n// Assuming a isoceles triangle of 2.5 texel height and 5 texels wide lying on 6 texels.\r\n// This function return the weight of each texels area relative to the full triangle area.\r\n// / \\\r\n// _ _ _ _ _ _ <-- texels\r\n// 0 1 2 3 4 5 <-- computed area indices (in texelsWeights[])\r\n// Top point at (right,top) in a texel,left bottom point at (middle,middle) in a texel,right bottom point at (middle,middle) in a texel.\r\nvoid sampleShadowGetTexelWeightsTent5x5(float offset, out vec3 texelsWeightsA, out vec3 texelsWeightsB)\r\n{\r\n vec4 areaFrom3texelTriangle;\r\n vec4 areaUncutFrom3texelTriangle;\r\n sampleShadowGetTexelAreasTent3x3(offset, areaFrom3texelTriangle, areaUncutFrom3texelTriangle);\r\n\r\n // Triangle slope is 45 degree thus we can almost reuse the result of the 3 texel wide computation.\r\n // the 5 texel wide triangle can be seen as the 3 texel wide one but shifted up by one unit/texel.\r\n // 0.16 is 1/(the triangle area)\r\n texelsWeightsA.x = 0.16 * (areaFrom3texelTriangle.x);\r\n texelsWeightsA.y = 0.16 * (areaUncutFrom3texelTriangle.y);\r\n texelsWeightsA.z = 0.16 * (areaFrom3texelTriangle.y + 1.0);\r\n texelsWeightsB.x = 0.16 * (areaFrom3texelTriangle.z + 1.0);\r\n texelsWeightsB.y = 0.16 * (areaUncutFrom3texelTriangle.z);\r\n texelsWeightsB.z = 0.16 * (areaFrom3texelTriangle.w);\r\n}\r\n\r\n// 5x5 Tent filter (45 degree sloped triangles in U and V)\r\nvoid sampleShadowComputeSamplesTent5x5(vec4 shadowMapTextureTexelSize, vec2 coord, out float fetchesWeights[9], out vec2 fetchesUV[9])\r\n{\r\n // tent base is 5x5 base thus covering from 25 to 36 texels, thus we need 9 bilinear PCF fetches\r\n vec2 tentCenterInTexelSpace = coord.xy * shadowMapTextureTexelSize.zw;\r\n vec2 centerOfFetchesInTexelSpace = floor(tentCenterInTexelSpace + 0.5);\r\n vec2 offsetFromTentCenterToCenterOfFetches = tentCenterInTexelSpace - centerOfFetchesInTexelSpace;\r\n\r\n // find the weight of each texel based on the area of a 45 degree slop tent above each of them.\r\n vec3 texelsWeightsUA, texelsWeightsUB;\r\n vec3 texelsWeightsVA, texelsWeightsVB;\r\n sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.x, texelsWeightsUA, texelsWeightsUB);\r\n sampleShadowGetTexelWeightsTent5x5(offsetFromTentCenterToCenterOfFetches.y, texelsWeightsVA, texelsWeightsVB);\r\n\r\n // each fetch will cover a group of 2x2 texels, the weight of each group is the sum of the weights of the texels\r\n vec3 fetchesWeightsU = vec3(texelsWeightsUA.xz, texelsWeightsUB.y) + vec3(texelsWeightsUA.y, texelsWeightsUB.xz);\r\n vec3 fetchesWeightsV = vec3(texelsWeightsVA.xz, texelsWeightsVB.y) + vec3(texelsWeightsVA.y, texelsWeightsVB.xz);\r\n\r\n // move the PCF bilinear fetches to respect texels weights\r\n vec3 fetchesOffsetsU = vec3(texelsWeightsUA.y, texelsWeightsUB.xz) / fetchesWeightsU.xyz + vec3(-2.5,-0.5,1.5);\r\n vec3 fetchesOffsetsV = vec3(texelsWeightsVA.y, texelsWeightsVB.xz) / fetchesWeightsV.xyz + vec3(-2.5,-0.5,1.5);\r\n fetchesOffsetsU *= shadowMapTextureTexelSize.xxx;\r\n fetchesOffsetsV *= shadowMapTextureTexelSize.yyy;\r\n\r\n vec2 bilinearFetchOrigin = centerOfFetchesInTexelSpace * shadowMapTextureTexelSize.xy;\r\n fetchesUV[0] = bilinearFetchOrigin + vec2(fetchesOffsetsU.x, fetchesOffsetsV.x);\r\n fetchesUV[1] = bilinearFetchOrigin + vec2(fetchesOffsetsU.y, fetchesOffsetsV.x);\r\n fetchesUV[2] = bilinearFetchOrigin + vec2(fetchesOffsetsU.z, fetchesOffsetsV.x);\r\n fetchesUV[3] = bilinearFetchOrigin + vec2(fetchesOffsetsU.x, fetchesOffsetsV.y);\r\n fetchesUV[4] = bilinearFetchOrigin + vec2(fetchesOffsetsU.y, fetchesOffsetsV.y);\r\n fetchesUV[5] = bilinearFetchOrigin + vec2(fetchesOffsetsU.z, fetchesOffsetsV.y);\r\n fetchesUV[6] = bilinearFetchOrigin + vec2(fetchesOffsetsU.x, fetchesOffsetsV.z);\r\n fetchesUV[7] = bilinearFetchOrigin + vec2(fetchesOffsetsU.y, fetchesOffsetsV.z);\r\n fetchesUV[8] = bilinearFetchOrigin + vec2(fetchesOffsetsU.z, fetchesOffsetsV.z);\r\n\r\n fetchesWeights[0] = fetchesWeightsU.x * fetchesWeightsV.x;\r\n fetchesWeights[1] = fetchesWeightsU.y * fetchesWeightsV.x;\r\n fetchesWeights[2] = fetchesWeightsU.z * fetchesWeightsV.x;\r\n fetchesWeights[3] = fetchesWeightsU.x * fetchesWeightsV.y;\r\n fetchesWeights[4] = fetchesWeightsU.y * fetchesWeightsV.y;\r\n fetchesWeights[5] = fetchesWeightsU.z * fetchesWeightsV.y;\r\n fetchesWeights[6] = fetchesWeightsU.x * fetchesWeightsV.z;\r\n fetchesWeights[7] = fetchesWeightsU.y * fetchesWeightsV.z;\r\n fetchesWeights[8] = fetchesWeightsU.z * fetchesWeightsV.z;\r\n}'),xe.addInclude("GlobalIllumination.glsl",'struct LayaGIInput\r\n{\r\n\tvec2 lightmapUV;\r\n\tvec3 worldPos;\r\n};\r\n\r\n#define LAYA_SPECCUBE_LOD_STEPS 6.0\r\n\r\nuniform vec3 u_AmbientColor;\r\n\r\n#if defined(GI_AMBIENT_SH)\r\n\tuniform vec4 u_AmbientSHAr;\r\n\tuniform vec4 u_AmbientSHAg;\r\n\tuniform vec4 u_AmbientSHAb;\r\n\tuniform vec4 u_AmbientSHBr;\r\n\tuniform vec4 u_AmbientSHBg;\r\n\tuniform vec4 u_AmbientSHBb;\r\n\tuniform vec4 u_AmbientSHC;\r\n#endif\r\n\r\nuniform samplerCube u_ReflectTexture;\r\nuniform vec4 u_ReflectCubeHDRParams;\r\n\r\n#ifdef SPECCUBE_BOX_PROJECTION\r\n\tuniform vec3 u_SpecCubeProbePosition;\r\n\tuniform vec3 u_SpecCubeBoxMax;\r\n\tuniform vec3 u_SpecCubeBoxMin;\r\n#endif\r\n\r\n\r\n#ifdef GI_AMBIENT_SH\r\n\tmediump vec3 shEvalLinearL0L1(mediump vec4 normal)\r\n\t{\r\n\t\tmediump vec3 x;\r\n\t\t// Linear (L1) + constant (L0) polynomial terms\r\n\t\tx.r = dot(u_AmbientSHAr, normal);\r\n\t\tx.g = dot(u_AmbientSHAg, normal);\r\n\t\tx.b = dot(u_AmbientSHAb, normal);\r\n\t\treturn x;\r\n\t}\r\n\r\n\tmediump vec3 shEvalLinearL2(mediump vec4 normal)\r\n\t{\r\n\t\tmediump vec3 x1,x2;\r\n\t\t// 4 of the quadratic (L2) polynomials\r\n\t\tmediump vec4 vB = normal.xyzz * normal.yzzx;\r\n\t\tx1.r = dot(u_AmbientSHBr, vB);\r\n\t\tx1.g = dot(u_AmbientSHBg, vB);\r\n\t\tx1.b = dot(u_AmbientSHBb, vB);\r\n\r\n\t\t// Final (5th) quadratic (L2) polynomial\r\n\t\tmediump float vC = normal.x*normal.x - normal.y*normal.y;\r\n\t\tx2 = u_AmbientSHC.rgb * vC;\r\n\r\n\t\treturn x1 + x2;\r\n\t}\r\n\t\r\n\tmediump vec3 shadeSHPerPixel(mediump vec3 normal)\r\n\t{\r\n\t\tmediump vec3 ambientContrib;\r\n\t\tmediump vec4 normalV4=vec4(-normal.x,normal.yz, 1.0);//Note:SH Data is left-hand,so x need inverse\r\n\t\tambientContrib = shEvalLinearL0L1(normalV4);\r\n\t\tambientContrib += shEvalLinearL2(normalV4);\r\n\t\tmediump vec3 ambient = max(vec3(0.0), ambientContrib);\r\n\t\tambient = layaLinearToGammaSpace(ambient);\r\n\t\treturn ambient;\r\n\t}\r\n#endif\r\n\r\n\r\n\r\n mediump vec3 BoxProjectedCubemapDirection(mediump vec3 worldRefl,mediump vec3 worldPos,mediump vec3 cubemapCenter,mediump vec3 boxMin,mediump vec3 boxMax){\r\n\t mediump vec3 nrdir = normalize(worldRefl);\r\n\t mediump vec3 rbmax = (boxMax - worldPos);\r\n\t mediump vec3 rbmin = (boxMin - worldPos);\r\n\t mediump vec3 select = step(vec3(0.0), worldRefl);\r\n\t mediump vec3 rbminmax = mix(rbmin, rbmax, select);\r\n\trbminmax = rbminmax / nrdir;\r\n\tmediump float scalar = min(min(rbminmax.x, rbminmax.y), rbminmax.z);\r\n\t mediump vec3 worldChangeRefl = nrdir * scalar + (worldPos - cubemapCenter);\r\n\treturn worldChangeRefl;\r\n}\r\n\r\n\r\nmediump vec3 layaDecodeDirectionalLightmap (mediump vec3 color, lowp vec4 dirTex, mediump vec3 normalWorld)\r\n{\r\n // In directional (non-specular) mode Enlighten bakes dominant light direction\r\n // in a way, that using it for half Lambert and then dividing by a "rebalancing coefficient"\r\n // gives a result close to plain diffuse response lightmaps, but normalmapped.\r\n\r\n // Note that dir is not unit length on purpose. Its length is "directionality", like\r\n // for the directional specular lightmaps.\r\n\tlowp vec3 directional=dirTex.xyz - 0.5;\r\n\tdirectional.x=-directional.x;//NOTE:because coord System\r\n mediump float halfLambert = dot(normalWorld,directional) + 0.5;\r\n\r\n return color * halfLambert / max(1e-4, dirTex.w);\r\n}\r\n\r\nvec3 layaGIBase(LayaGIInput giInput,mediump float occlusion, mediump vec3 normalWorld)\r\n{\r\n\tvec3 indirectDiffuse;\r\n\t#ifdef LIGHTMAP\t\r\n\t\tmediump vec3 bakedColor =decodeHDR(texture2D(u_LightMap, giInput.lightmapUV),5.0);\r\n\t\t#ifdef LIGHTMAP_DIRECTIONAL\r\n\t\t\tlowp vec4 bakedDirTex = texture2D (u_LightMapDirection, giInput.lightmapUV);\r\n indirectDiffuse = layaDecodeDirectionalLightmap (bakedColor, bakedDirTex, normalWorld);\r\n\t\t#else //unDirectional lightmap\r\n\t\t\tindirectDiffuse = bakedColor;\r\n\t\t#endif\r\n\t#else\r\n\t\t#ifdef GI_AMBIENT_SH\r\n\t\t\tindirectDiffuse = shadeSHPerPixel(normalWorld);\r\n\t\t#else\r\n\t\t\tindirectDiffuse = u_AmbientColor; //already in gamma space\r\n\t\t#endif\r\n\t#endif\r\n\r\n\tindirectDiffuse*=occlusion;\r\n\treturn indirectDiffuse;\r\n}\r\n\r\nmediump vec3 layaGlossyEnvironment(mediump vec4 glossIn)\r\n{\r\n\tmediump float perceptualRoughness = glossIn.a;\r\n\r\n\t// use approximation to solve,below is more reasonable,but maybe slow. \r\n\t// float m = perceptualRoughnessToRoughness(perceptualRoughness); // m is the real roughness parameter\r\n // const float fEps = 1.192092896e-07F; // smallest such that 1.0+FLT_EPSILON != 1.0 (+1e-4h is NOT good here. is visibly very wrong)\r\n // float n = (2.0/max(fEps, m*m))-2.0; // remap to spec power. See eq. 21 in --\x3e https://dl.dropboxusercontent.com/u/55891920/papers/mm_brdf.pdf\r\n // n /= 4; // remap from n_dot_h formulatino to n_dot_r. See section "Pre-convolved Cube Maps vs Path Tracers" --\x3e https://s3.amazonaws.com/docs.knaldtech.com/knald/1.0.0/lys_power_drops.html\r\n // perceptualRoughness = pow( 2/(n+2), 0.25); // remap back to square root of real roughness (0.25 include both the sqrt root of the conversion and sqrt for going from roughness to perceptualRoughness)\r\n\tperceptualRoughness = perceptualRoughness * (1.7 - 0.7*perceptualRoughness);//just a approximation,but fast.\r\n \r\n\tmediump float mip = perceptualRoughness * LAYA_SPECCUBE_LOD_STEPS;\r\n\tmediump vec3 uvw = glossIn.rgb;\r\n\tuvw.x=-uvw.x;//Note:reflectCube is left-hand,so x need inverse\r\n\tmediump vec4 rgbm=textureCubeLodEXT(u_ReflectTexture,uvw,mip);\r\n\treturn decodeHDR(rgbm,u_ReflectCubeHDRParams.x);\r\n}\r\n\r\nmediump vec3 layaGIIndirectSpecular(LayaGIInput giInput,mediump float occlusion, vec4 glossIn)\r\n{\r\n\t#ifdef SPECCUBE_BOX_PROJECTION\r\n\t\tvec3 originalReflUVW = glossIn.xyz;\r\n\t\tglossIn.xyz =BoxProjectedCubemapDirection(originalReflUVW,giInput.worldPos,u_SpecCubeProbePosition,u_SpecCubeBoxMin,u_SpecCubeBoxMax);\r\n\t#endif\r\n\tmediump vec3 specular = layaGlossyEnvironment(glossIn);\r\n\treturn specular * occlusion;\r\n}\r\n\r\n\r\nLayaGI layaGlobalIllumination(LayaGIInput giInput,mediump float occlusion, mediump vec3 normalWorld,mediump vec4 uvwRoughness)\r\n{\r\n\tLayaGI gi;\r\n\tgi.diffuse = layaGIBase(giInput,occlusion, normalWorld);\r\n\tgi.specular = layaGIIndirectSpecular(giInput,occlusion, uvwRoughness);\r\n\treturn gi;\r\n}\r\n\r\n\r\n'),xe.addInclude("Shadow.glsl",'#ifndef GRAPHICS_API_GLES3\r\n\t#define NO_NATIVE_SHADOWMAP\r\n#endif\r\n\r\n#if defined(NO_NATIVE_SHADOWMAP)\r\n\t#define TEXTURE2D_SHADOW(textureName) uniform mediump sampler2D textureName\r\n\t#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) (texture2D(textureName,coord3.xy).r<coord3.z?0.0:1.0)\r\n\t#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2D shadowMap\r\n#else\r\n\t#define TEXTURE2D_SHADOW(textureName) uniform mediump sampler2DShadow textureName\r\n\t#define SAMPLE_TEXTURE2D_SHADOW(textureName, coord3) textureLod(textureName,coord3,0.0)\r\n\t#define TEXTURE2D_SHADOW_PARAM(shadowMap) mediump sampler2DShadow shadowMap\r\n#endif\r\n\r\n#if defined(RECEIVESHADOW)&&defined(SHADOW)\r\n #define CALCULATE_SHADOWS\r\n#endif\r\n\r\n#if defined(RECEIVESHADOW)&&defined(SHADOW_SPOT)\r\n\t#define CALCULATE_SPOTSHADOWS\r\n#endif\r\n\r\nuniform vec4 u_ShadowBias; // x: depth bias, y: normal bias\r\n\r\n#if defined(CALCULATE_SHADOWS)||defined(CALCULATE_SPOTSHADOWS)\r\n\t#include "ShadowSampleTent.glsl"\r\n\tuniform vec4 u_ShadowMapSize;\r\n\tuniform vec4 u_SpotShadowMapSize;\r\n\tuniform vec4 u_ShadowParams; // x: shadowStrength y: ShadowSpotLightStrength\r\n\r\n\t\r\n\tfloat sampleShdowMapFiltered4(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowMapSize)\r\n\t{\r\n\t\tfloat attenuation;\r\n\t\tvec4 attenuation4;\r\n\t\tvec2 offset=shadowMapSize.xy/2.0;\r\n\t\tvec3 shadowCoord0=shadowCoord + vec3(-offset,0.0);\r\n\t\tvec3 shadowCoord1=shadowCoord + vec3(offset.x,-offset.y,0.0);\r\n\t\tvec3 shadowCoord2=shadowCoord + vec3(-offset.x,offset.y,0.0);\r\n\t\tvec3 shadowCoord3=shadowCoord + vec3(offset,0.0);\r\n\t\tattenuation4.x = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord0);\r\n\t\tattenuation4.y = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord1);\r\n\t\tattenuation4.z = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord2);\r\n\t\tattenuation4.w = SAMPLE_TEXTURE2D_SHADOW(shadowMap, shadowCoord3);\r\n\t\tattenuation = dot(attenuation4, vec4(0.25));\r\n\t\treturn attenuation;\r\n\t}\r\n\r\n\tfloat sampleShdowMapFiltered9(TEXTURE2D_SHADOW_PARAM(shadowMap),vec3 shadowCoord,vec4 shadowmapSize)\r\n\t{\r\n\t\tfloat attenuation;\r\n\t\tfloat fetchesWeights[9];\r\n\t\tvec2 fetchesUV[9];\r\n\t\tsampleShadowComputeSamplesTent5x5(shadowmapSize, shadowCoord.xy, fetchesWeights, fetchesUV);\r\n\t\tattenuation = fetchesWeights[0] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[0].xy, shadowCoord.z));\r\n\t\tattenuation += fetchesWeights[1] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[1].xy, shadowCoord.z));\r\n\t\tattenuation += fetchesWeights[2] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[2].xy, shadowCoord.z));\r\n\t\tattenuation += fetchesWeights[3] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[3].xy, shadowCoord.z));\r\n\t\tattenuation += fetchesWeights[4] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[4].xy, shadowCoord.z));\r\n\t\tattenuation += fetchesWeights[5] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[5].xy, shadowCoord.z));\r\n\t\tattenuation += fetchesWeights[6] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[6].xy, shadowCoord.z));\r\n\t\tattenuation += fetchesWeights[7] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[7].xy, shadowCoord.z));\r\n\t\tattenuation += fetchesWeights[8] * SAMPLE_TEXTURE2D_SHADOW(shadowMap, vec3(fetchesUV[8].xy, shadowCoord.z));\r\n\t\treturn attenuation;\r\n\t}\r\n\r\n#endif\r\n\r\n\r\n\r\n\r\n#if defined(CALCULATE_SHADOWS)\r\n\r\n\tTEXTURE2D_SHADOW(u_ShadowMap);\r\n\r\n\tuniform mat4 u_ShadowMatrices[4];\r\n\tuniform vec4 u_ShadowSplitSpheres[4];// max cascade is 4\r\n\r\n\tmediump int computeCascadeIndex(vec3 positionWS)\r\n\t{\r\n\t\tvec3 fromCenter0 = positionWS - u_ShadowSplitSpheres[0].xyz;\r\n\t\tvec3 fromCenter1 = positionWS - u_ShadowSplitSpheres[1].xyz;\r\n\t\tvec3 fromCenter2 = positionWS - u_ShadowSplitSpheres[2].xyz;\r\n\t\tvec3 fromCenter3 = positionWS - u_ShadowSplitSpheres[3].xyz;\r\n\r\n\t\tmediump vec4 comparison = vec4(\r\n\t\t\tdot(fromCenter0, fromCenter0)<u_ShadowSplitSpheres[0].w,\r\n\t\t\tdot(fromCenter1, fromCenter1)<u_ShadowSplitSpheres[1].w,\r\n\t\t\tdot(fromCenter2, fromCenter2)<u_ShadowSplitSpheres[2].w,\r\n\t\t\tdot(fromCenter3, fromCenter3)<u_ShadowSplitSpheres[3].w);\r\n\t\tcomparison.yzw = clamp(comparison.yzw - comparison.xyz,0.0,1.0);//keep the nearest\r\n\t\tmediump vec4 indexCoefficient = vec4(4.0,3.0,2.0,1.0);\r\n\t\tmediump int index = 4 - int(dot(comparison, indexCoefficient));\r\n\t\treturn index;\r\n\t}\r\n\r\n\tvec4 getShadowCoord(vec4 positionWS)\r\n\t{\r\n\t\t#ifdef SHADOW_CASCADE\r\n\t\t\tmediump int cascadeIndex = computeCascadeIndex(positionWS.xyz);\r\n\t\t\tif(cascadeIndex > 3)// out of shadow range cascadeIndex is 4.\r\n\t\t\t\treturn vec4(0.0);\r\n\t\t\t\r\n\t\t\t#ifdef GRAPHICS_API_GLES3\r\n\t\t\t\treturn u_ShadowMatrices[cascadeIndex] * positionWS;\r\n\t\t\t#else\r\n\t\t\t\tmat4 shadowMat;\r\n\t\t\t\tif(cascadeIndex == 0)\r\n\t\t\t\t\tshadowMat = u_ShadowMatrices[0];\r\n\t\t\t\telse if(cascadeIndex == 1)\r\n\t\t\t\t\tshadowMat = u_ShadowMatrices[1];\r\n\t\t\t\telse if(cascadeIndex == 2)\r\n\t\t\t\t\tshadowMat = u_ShadowMatrices[2];\r\n\t\t\t\telse\r\n\t\t\t\t\tshadowMat = u_ShadowMatrices[3];\r\n\t\t\t\treturn shadowMat * positionWS;\r\n\t\t\t#endif\r\n\t\t#else\r\n\t\t\treturn u_ShadowMatrices[0] * positionWS;\r\n\t\t#endif\r\n\t}\r\n\r\n\tfloat sampleShadowmap(vec4 shadowCoord)\r\n\t{\r\n\t\tshadowCoord.xyz /= shadowCoord.w;\r\n\t\tfloat attenuation = 1.0;\r\n\t\tif(shadowCoord.z > 0.0 && shadowCoord.z < 1.0)\r\n\t\t{\r\n\t\t\t#if defined(SHADOW_SOFT_SHADOW_HIGH)\r\n\t\t\t\tattenuation = sampleShdowMapFiltered9(u_ShadowMap,shadowCoord.xyz,u_ShadowMapSize);\r\n\t\t\t#elif defined(SHADOW_SOFT_SHADOW_LOW)\r\n\t\t\t\tattenuation = sampleShdowMapFiltered4(u_ShadowMap,shadowCoord.xyz,u_ShadowMapSize);\r\n\t\t\t#else\r\n\t\t\t\tattenuation = SAMPLE_TEXTURE2D_SHADOW(u_ShadowMap,shadowCoord.xyz);\r\n\t\t\t#endif\r\n\t\t\tattenuation = mix(1.0,attenuation,u_ShadowParams.x);//shadowParams.x:shadow strength\r\n\t\t}\r\n\t\treturn attenuation;\r\n\t}\r\n#endif\r\n\r\n#if defined(CALCULATE_SPOTSHADOWS)//shader���Զ���ĺ겻����ifdef ����ij�if defined\r\n\tTEXTURE2D_SHADOW(u_SpotShadowMap);\r\n\tuniform mat4 u_SpotViewProjectMatrix;\r\n\tfloat sampleSpotShadowmap(vec4 shadowCoord)\r\n\t{\r\n\t\tshadowCoord.xyz /= shadowCoord.w;\r\n\t\tfloat attenuation = 1.0;\r\n\t\tshadowCoord.xy +=1.0;\r\n\t\tshadowCoord.xy/=2.0; \r\n\t\tif(shadowCoord.z > 0.0 && shadowCoord.z < 1.0)\r\n\t\t{\r\n\t\t\t#if defined(SHADOW_SPOT_SOFT_SHADOW_HIGH)\r\n\t\t\t\tattenuation = sampleShdowMapFiltered9(u_SpotShadowMap,shadowCoord.xyz,u_SpotShadowMapSize);\r\n\t\t\t#elif defined(SHADOW_SPOT_SOFT_SHADOW_LOW)\r\n\t\t\t\tattenuation = sampleShdowMapFiltered4(u_SpotShadowMap,shadowCoord.xyz,u_SpotShadowMapSize);\r\n\t\t\t#else\r\n\t\t\t\tattenuation = SAMPLE_TEXTURE2D_SHADOW(u_SpotShadowMap,shadowCoord.xyz);\r\n\t\t\t#endif\r\n\t\t\tattenuation = mix(1.0,attenuation,u_ShadowParams.y);//shadowParams.y:shadow strength\r\n\t\t}\r\n\t\treturn attenuation;\r\n\t}\r\n#endif\r\n\r\nvec3 applyShadowBias(vec3 positionWS, vec3 normalWS, vec3 lightDirection)\r\n{\r\n float invNdotL = 1.0 - clamp(dot(-lightDirection, normalWS),0.0,1.0);\r\n float scale = invNdotL * u_ShadowBias.y;\r\n\r\n // normal bias is negative since we want to apply an inset normal offset\r\n positionWS += -lightDirection * u_ShadowBias.xxx;\r\n positionWS += normalWS * vec3(scale);\r\n return positionWS;\r\n}\r\n'),xe.addInclude("ShadowCasterVS.glsl",'#include "Lighting.glsl";\r\n#include "Shadow.glsl"\r\n\r\nattribute vec4 a_Position;\r\nattribute vec3 a_Normal;\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_WorldMat;\r\n#else\r\n\tuniform mat4 u_WorldMat;\r\n#endif\r\n\r\nuniform mat4 u_ViewProjection;\r\n\r\n#ifdef SHADOW\r\n\tuniform vec3 u_ShadowLightDirection;\r\n#endif\r\n\r\n\r\nvec4 shadowCasterVertex()\r\n{\r\n\tmat4 worldMat;\r\n\t#ifdef GPU_INSTANCE\r\n\t\tworldMat = a_WorldMat;\r\n\t#else\r\n\t\tworldMat = u_WorldMat;\r\n\t#endif\r\n\t\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform;\r\n\t \t#ifdef SIMPLEBONE\r\n\t\t\tfloat currentPixelPos;\r\n\t\t\t#ifdef GPU_INSTANCE\r\n\t\t\t\tcurrentPixelPos = a_SimpleTextureParams.x+a_SimpleTextureParams.y;\r\n\t\t\t#else\r\n\t\t\t\tcurrentPixelPos = u_SimpleAnimatorParams.x+u_SimpleAnimatorParams.y;\r\n\t\t\t#endif\r\n\t\t\tfloat offset = 1.0/u_SimpleAnimatorTextureSize;\r\n\t\t\tskinTransform = loadMatFromTexture(currentPixelPos,int(a_BoneIndices.x),offset) * a_BoneWeights.x;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.y),offset) * a_BoneWeights.y;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.z),offset) * a_BoneWeights.z;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.w),offset) * a_BoneWeights.w;\r\n\t\t#else\r\n\t\t\tskinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\t#endif\r\n\t\tworldMat = worldMat * skinTransform;\r\n\t#endif\r\n\r\n\tvec4 positionWS = worldMat * a_Position;\r\n\tmat3 worldInvMat;\r\n\t#ifdef BONE\r\n\t\tworldInvMat=INVERSE_MAT(mat3(worldMat*skinTransform));\r\n\t#else\r\n\t\tworldInvMat=INVERSE_MAT(mat3(worldMat));\r\n\t#endif \r\n\r\n\tvec3 normalWS = normalize(a_Normal*worldInvMat);//if no normalize will cause precision problem\r\n\t#ifdef SHADOW\r\n\t\tpositionWS.xyz = applyShadowBias(positionWS.xyz,normalWS,u_ShadowLightDirection);\r\n\t#endif\r\n\r\n\tvec4 positionCS = u_ViewProjection * positionWS;\r\n\t#ifdef SHADOW_SPOT\r\n\t\tpositionCS.z = positionCS.z-u_ShadowBias.x/positionCS.w;\r\n\t#endif\r\n\tpositionCS.z = max(positionCS.z, 0.0);//min ndc z is 0.0\r\n\t\r\n\t// //TODO没考虑UV动画呢\r\n\t// #if defined(DIFFUSEMAP)&&defined(ALPHATEST)\r\n\t// \tv_Texcoord0=a_Texcoord0;\r\n\t// #endif\r\n return positionCS;\r\n}\r\n'),xe.addInclude("ShadowCasterFS.glsl","vec4 shadowCasterFragment()\r\n{\r\n return vec4(0.0);\r\n}\r\n"),xe.addInclude("Colors.glsl",'#include "StdLib.glsl";\r\n\r\n#define EPSILON 1.0e-4\r\n\r\n// Quadratic color thresholding\r\n// curve = (threshold - knee, knee * 2, 0.25 / knee)\r\nmediump vec4 quadraticThreshold(mediump vec4 color, mediump float threshold, mediump vec3 curve) {\r\n\t// Pixel brightness\r\n\tmediump float br = max3(color.r, color.g, color.b);\r\n\r\n\t// Under-threshold part: quadratic curve\r\n\tmediump float rq = clamp(br - curve.x, 0.0, curve.y);\r\n\trq = curve.z * rq * rq;\r\n\r\n\t// Combine and apply the brightness response curve.\r\n\tcolor *= max(rq, br - threshold) / max(br, EPSILON);\r\n\r\n\treturn color;\r\n}\r\n\r\n\r\n\r\n//\r\n// sRGB transfer functions\r\n// Fast path ref: http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1\r\n//\r\nmediump vec3 sRGBToLinear(mediump vec3 c) {\r\n\t#ifdef USE_VERY_FAST_SRGB\r\n\t\treturn c * c;\r\n\t#elif defined(USE_FAST_SRGB)\r\n\t\treturn c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);\r\n\t#else\r\n\t\tmediump vec3 linearRGBLo = c / 12.92;\r\n\t\tmediump vec3 power=vec3(2.4, 2.4, 2.4);\r\n\t\tmediump vec3 linearRGBHi = positivePow((c + 0.055) / 1.055, power);\r\n\t\tmediump vec3 linearRGB =vec3((c.r<=0.04045) ? linearRGBLo.r : linearRGBHi.r,(c.g<=0.04045) ? linearRGBLo.g : linearRGBHi.g,(c.b<=0.04045) ? linearRGBLo.b : linearRGBHi.b);\r\n\t\treturn linearRGB;\r\n\t#endif\r\n}\r\n\r\nmediump vec4 sRGBToLinear(mediump vec4 c){\r\n return vec4(sRGBToLinear(c.rgb), c.a);\r\n}\r\n\r\n\r\n\r\nmediump vec3 linearToSRGB(mediump vec3 c) {\r\n\t#ifdef USE_VERY_FAST_SRGB\r\n\t\treturn sqrt(c);\r\n\t#elif defined(USE_FAST_SRGB)\r\n\t\treturn max(1.055 * PositivePow(c, 0.416666667) - 0.055, 0.0);\r\n\t#else\r\n\t\tmediump vec3 sRGBLo = c * 12.92;\r\n\t\tmediump vec3 power=vec3(1.0 / 2.4, 1.0 / 2.4, 1.0 / 2.4);\r\n\t\tmediump vec3 sRGBHi = (positivePow(c, power) * 1.055) - 0.055;\r\n\t\tmediump vec3 sRGB =vec3((c.r<=0.0031308) ? sRGBLo.r : sRGBHi.r,(c.g<=0.0031308) ? sRGBLo.g : sRGBHi.g,(c.b<=0.0031308) ? sRGBLo.b : sRGBHi.b);\r\n\t\treturn sRGB;\r\n\t#endif\r\n}\r\n\r\nmediump vec4 linearToSRGB(mediump vec4 c){\r\n return vec4(linearToSRGB(c.rgb), c.a);\r\n}'),xe.addInclude("Sampling.glsl","// Better, temporally stable box filtering\r\n// [Jimenez14] http://goo.gl/eomGso\r\n// . . . . . . .\r\n// . A . B . C .\r\n// . . D . E . .\r\n// . F . G . H .\r\n// . . I . J . .\r\n// . K . L . M .\r\n// . . . . . . .\r\nmediump vec4 downsampleBox13Tap(sampler2D tex, vec2 uv, vec2 texelSize)\r\n{\r\n mediump vec4 A = texture2D(tex, uv + texelSize * vec2(-1.0, -1.0));\r\n mediump vec4 B = texture2D(tex, uv + texelSize * vec2( 0.0, -1.0));\r\n mediump vec4 C = texture2D(tex, uv + texelSize * vec2( 1.0, -1.0));\r\n mediump vec4 D = texture2D(tex, uv + texelSize * vec2(-0.5, -0.5));\r\n mediump vec4 E = texture2D(tex, uv + texelSize * vec2( 0.5, -0.5));\r\n mediump vec4 F = texture2D(tex, uv + texelSize * vec2(-1.0, 0.0));\r\n mediump vec4 G = texture2D(tex, uv);\r\n mediump vec4 H = texture2D(tex, uv + texelSize * vec2( 1.0, 0.0));\r\n mediump vec4 I = texture2D(tex, uv + texelSize * vec2(-0.5, 0.5));\r\n mediump vec4 J = texture2D(tex, uv + texelSize * vec2( 0.5, 0.5));\r\n mediump vec4 K = texture2D(tex, uv + texelSize * vec2(-1.0, 1.0));\r\n mediump vec4 L = texture2D(tex, uv + texelSize * vec2( 0.0, 1.0));\r\n mediump vec4 M = texture2D(tex, uv + texelSize * vec2( 1.0, 1.0));\r\n\r\n\tmediump vec2 scale= vec2(0.5, 0.125);\r\n mediump vec2 div = (1.0 / 4.0) * scale;\r\n\r\n mediump vec4 o = (D + E + I + J) * div.x;\r\n o += (A + B + G + F) * div.y;\r\n o += (B + C + H + G) * div.y;\r\n o += (F + G + L + K) * div.y;\r\n o += (G + H + M + L) * div.y;\r\n\r\n return o;\r\n}\r\n\r\n// Standard box filtering\r\nmediump vec4 downsampleBox4Tap(sampler2D tex, vec2 uv, vec2 texelSize)\r\n{\r\n vec4 d = texelSize.xyxy * vec4(-1.0, -1.0, 1.0, 1.0);\r\n\r\n mediump vec4 s = texture2D(tex, uv + d.xy);\r\n s += texture2D(tex, uv + d.zy);\r\n s += texture2D(tex, uv + d.xw);\r\n s += texture2D(tex, uv + d.zw);\r\n\r\n return s * (1.0 / 4.0);\r\n}\r\n\r\n// 9-tap bilinear upsampler (tent filter)\r\n// . . . . . . .\r\n// . 1 . 2 . 1 .\r\n// . . . . . . .\r\n// . 2 . 4 . 2 .\r\n// . . . . . . .\r\n// . 1 . 2 . 1 .\r\n// . . . . . . .\r\nmediump vec4 upsampleTent(sampler2D tex, vec2 uv, vec2 texelSize, vec4 sampleScale)\r\n{\r\n vec4 d = texelSize.xyxy * vec4(1.0, 1.0, -1.0, 0.0) * sampleScale;\r\n\r\n mediump vec4 s = texture2D(tex, uv - d.xy);\r\n s += texture2D(tex, uv - d.wy) * 2.0;\r\n s += texture2D(tex, uv - d.zy);\r\n\r\n s += texture2D(tex, uv + d.zw) * 2.0;\r\n s += texture2D(tex, uv) * 4.0;\r\n s += texture2D(tex,\tuv + d.xw) * 2.0;\r\n\r\n s += texture2D(tex, uv + d.zy);\r\n s += texture2D(tex, uv + d.wy) * 2.0;\r\n s += texture2D(tex, uv + d.xy);\r\n\r\n return s * (1.0 / 16.0);\r\n}\r\n\r\n// Standard box filtering\r\nmediump vec4 upsampleBox(sampler2D tex, vec2 uv, vec2 texelSize, vec4 sampleScale)\r\n{\r\n vec4 d = texelSize.xyxy * vec4(-1.0, -1.0, 1.0, 1.0) * 0.5 * sampleScale;\r\n\r\n mediump vec4 s = texture2D(tex, uv + d.xy);\r\n s += texture2D(tex, uv + d.zy);\r\n s += texture2D(tex, uv + d.xw);\r\n s += texture2D(tex, uv + d.zw);\r\n\r\n return s * (1.0 / 4.0);\r\n}"),xe.addInclude("StdLib.glsl","#define HALF_MAX 65504.0 // (2 - 2^-10) * 2^15\r\n\r\n#define FLT_EPSILON 1.192092896e-07 // Smallest positive number, such that 1.0 + FLT_EPSILON != 1.0\r\n\r\nmediump vec4 safeHDR(mediump vec4 c)\r\n{\r\n return min(c, HALF_MAX);\r\n}\r\n\r\nfloat max3(float a, float b, float c)\r\n{\r\n return max(max(a, b), c);\r\n}\r\n\r\nvec3 positivePow(vec3 base, vec3 power)\r\n{\r\n return pow(max(abs(base), vec3(FLT_EPSILON, FLT_EPSILON, FLT_EPSILON)), power);\r\n}"),xe.addInclude("PBRVSInput.glsl","attribute vec4 a_Position;\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_MvpMatrix;\r\n\tattribute mat4 a_WorldMat;\r\n#else\r\n\tuniform mat4 u_MvpMatrix;\r\n\tuniform mat4 u_WorldMat;\r\n#endif\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\nattribute vec3 a_Normal;\r\nvarying vec3 v_Normal; \r\n\r\n#if defined(NORMALTEXTURE)||defined(PARALLAXTEXTURE)\r\n\tattribute vec4 a_Tangent0;\r\n\tvarying vec3 v_Tangent;\r\n\tvarying vec3 v_Binormal;\r\n #ifdef PARALLAXTEXTURE\r\n\t varying vec3 v_ViewDirForParallax;\r\n #endif\r\n#endif\r\n\r\n#if defined(ALBEDOTEXTURE)||defined(METALLICGLOSSTEXTURE)||defined(NORMALTEXTURE)||defined(EMISSIONTEXTURE)||defined(OCCLUSIONTEXTURE)||defined(PARALLAXTEXTURE)||(defined(LIGHTMAP)&&defined(UV))\r\n\tattribute vec2 a_Texcoord0;\r\n\tvarying vec2 v_Texcoord0;\r\n#endif\r\n\r\n#if defined(LIGHTMAP)&&defined(UV1)\r\n\tattribute vec2 a_Texcoord1;\r\n#endif\r\n\r\n#ifdef LIGHTMAP\r\n\tuniform vec4 u_LightmapScaleOffset;\r\n\tvarying vec2 v_LightMapUV;\r\n#endif\r\n\r\nuniform vec3 u_CameraPos;\r\nvarying vec3 v_EyeVec;\r\nvarying vec3 v_PositionWorld;\r\nvarying float v_posViewZ;\r\n\r\n#if defined(CALCULATE_SHADOWS)&&!defined(SHADOW_CASCADE)\r\n\tvarying vec4 v_ShadowCoord;\r\n#endif\r\n\r\n#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\tvarying vec4 v_SpotShadowCoord;\r\n#endif\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif"),xe.addInclude("PBRFSInput.glsl","#ifdef ALPHATEST\r\n\tuniform float u_AlphaTestValue;\r\n#endif\r\n\r\nuniform vec4 u_AlbedoColor;\r\n\r\n#ifdef NORMALTEXTURE\r\n\tuniform sampler2D u_NormalTexture;\r\n\tuniform float u_NormalScale;\r\n#endif\r\n\r\n#ifdef ALBEDOTEXTURE\r\n\tuniform sampler2D u_AlbedoTexture;\r\n#endif\r\n\r\n#ifdef METALLICGLOSSTEXTURE\r\n\tuniform sampler2D u_MetallicGlossTexture;\r\n#endif\r\nuniform float u_Metallic;\r\n\r\n#ifdef SPECULARGLOSSTEXTURE\r\n\tuniform sampler2D u_SpecGlossTexture;\r\n#endif\r\nuniform vec3 u_SpecularColor;\r\n\r\nuniform float u_Smoothness;\r\nuniform float u_SmoothnessScale;\r\n\r\n#ifdef PARALLAXTEXTURE\r\n\tuniform sampler2D u_ParallaxTexture;\r\n\tuniform float u_ParallaxScale;\r\n\tvarying vec3 v_ViewDirForParallax;\r\n#endif\r\n\r\n#ifdef OCCLUSIONTEXTURE\r\n\tuniform sampler2D u_OcclusionTexture;\r\n\tuniform float u_occlusionStrength;\r\n#endif\r\n\r\n#ifdef EMISSION \r\n\t#ifdef EMISSIONTEXTURE\r\n\t\tuniform sampler2D u_EmissionTexture;\r\n\t#endif\r\n\tuniform vec4 u_EmissionColor;\r\n#endif\r\n\r\n#if defined(ALBEDOTEXTURE)||defined(METALLICGLOSSTEXTURE)||defined(NORMALTEXTURE)||defined(EMISSIONTEXTURE)||defined(OCCLUSIONTEXTURE)||defined(PARALLAXTEXTURE)\r\n\tvarying vec2 v_Texcoord0;\r\n#endif\r\n\r\n#ifdef LIGHTMAP\r\n\tvarying vec2 v_LightMapUV;\r\n\tuniform sampler2D u_LightMap;\r\n\t#ifdef LIGHTMAP_DIRECTIONAL\r\n\t\tuniform sampler2D u_LightMapDirection;\r\n\t#endif\r\n#endif\r\n\r\nvarying vec3 v_Normal; \r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t#ifdef LEGACYSINGLELIGHTING\r\n\t\t#ifdef DIRECTIONLIGHT\r\n\t\t\tuniform DirectionLight u_DirectionLight;\r\n\t\t#endif\r\n\t\t#ifdef POINTLIGHT\r\n\t\t\tuniform PointLight u_PointLight;\r\n\t\t#endif\r\n\t\t#ifdef SPOTLIGHT\r\n\t\t\tuniform SpotLight u_SpotLight;\r\n\t\t#endif\r\n\t#else\r\n\t\tuniform mat4 u_View;\r\n\t\tuniform vec4 u_ProjectionParams;\r\n\t\tuniform vec4 u_Viewport;\r\n\t\tuniform int u_DirationLightCount;\r\n\t\tuniform sampler2D u_LightBuffer;\r\n\t\tuniform sampler2D u_LightClusterBuffer;\r\n\t#endif\r\n#endif\r\n\r\nvarying vec3 v_EyeVec;\r\n\r\n#ifdef NORMALTEXTURE\r\n\tvarying vec3 v_Tangent;\r\n\tvarying vec3 v_Binormal;\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\tuniform vec3 u_FogColor;\r\n#endif\r\n\r\n\r\n//后面考虑宏TODO\r\nvarying vec3 v_PositionWorld;\r\n\r\n#if defined(CALCULATE_SHADOWS)&&!defined(SHADOW_CASCADE)\r\n\tvarying vec4 v_ShadowCoord;\r\n#endif\r\n\r\n#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\tvarying vec4 v_SpotShadowCoord;\r\n#endif\r\n\r\nmediump float lerpOneTo(mediump float b, mediump float t)\r\n{\r\n mediump float oneMinusT = 1.0 - t;\r\n return oneMinusT + b * t;\r\n}\r\n\r\n#ifdef EMISSION \r\n\tvec3 emission(vec2 uv)\r\n\t{\r\n\t\t#ifdef EMISSIONTEXTURE\r\n\t\t\treturn texture2D(u_EmissionTexture, uv).rgb * u_EmissionColor.rgb;\r\n\t\t#else\r\n\t\t\treturn u_EmissionColor.rgb;\r\n\t\t#endif\r\n\t}\r\n#endif\r\n\r\nmediump float getAlpha(vec2 uv)\r\n{\r\n\t#ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\r\n\t\treturn u_AlbedoColor.a;\r\n\t#else\r\n\t\t#ifdef ALBEDOTEXTURE\r\n\t\t\treturn texture2D(u_AlbedoTexture, uv).a * u_AlbedoColor.a;\r\n\t\t#else\r\n\t\t\treturn u_AlbedoColor.a;\r\n\t\t#endif\r\n\t#endif\r\n}\r\n\r\nmediump float getOcclusion(vec2 uv)\r\n{\r\n\t#ifdef OCCLUSIONTEXTURE\r\n\t\tmediump float occ = texture2D(u_OcclusionTexture, uv).g;\r\n\t\treturn lerpOneTo(occ, u_occlusionStrength);\r\n\t#else\r\n\t\treturn 1.0;\r\n\t#endif\r\n}\r\n\r\nmediump vec3 albedo(vec2 uv)\r\n{\r\n\t#ifdef ALBEDOTEXTURE\r\n\t\treturn u_AlbedoColor.rgb * texture2D(u_AlbedoTexture, uv).rgb;\r\n\t#else\r\n\t\treturn u_AlbedoColor.rgb;\r\n\t#endif\r\n\t//TODO:Detail Texture\r\n}\r\n\r\nmediump vec2 getMetallicGloss(vec2 uv)\r\n{\r\n\tmediump vec2 ms;//x is metallic,y is smoothness\r\n\t#ifdef METALLICGLOSSTEXTURE\r\n\t\t#ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\r\n\t\t\tms.x = texture2D(u_MetallicGlossTexture, uv).r;\r\n\t\t\t#ifdef ALBEDOTEXTURE\r\n\t\t\t\tms.y = texture2D(u_AlbedoTexture, uv).a*u_SmoothnessScale;\r\n\t\t\t#else\r\n\t\t\t\tms.y = u_SmoothnessScale;\r\n\t\t\t#endif\r\n\t\t#else\r\n\t\t\tms = texture2D(u_MetallicGlossTexture, uv).ra;\r\n\t\t\tms.y *= u_SmoothnessScale;\r\n\t\t#endif\r\n\t#else\r\n\t\tms.x = u_Metallic;\r\n\t\t#ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\r\n\t\t\t#ifdef ALBEDOTEXTURE\r\n\t\t\t\tms.y = texture2D(u_AlbedoTexture, uv).a * u_SmoothnessScale;\r\n\t\t\t#else\r\n\t\t\t\tms.y = u_SmoothnessScale;\r\n\t\t\t#endif\r\n\t\t#else\r\n\t\t\tms.y = u_Smoothness;\r\n\t\t#endif\r\n\t#endif\r\n\treturn ms;\r\n}\r\n\r\nmediump vec4 specularGloss(vec2 uv)\r\n{\r\n\tmediump vec4 sg;\r\n\t#ifdef SPECULARGLOSSTEXTURE\r\n\t\t#ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\r\n\t\t\tsg.rgb = texture2D(u_SpecGlossTexture, uv).rgb;\r\n\t\t\t#ifdef ALBEDOTEXTURE\r\n\t\t\t\tsg.a = texture2D(u_AlbedoTexture, uv).a*u_SmoothnessScale;\r\n\t\t\t#else\r\n\t\t\t\tsg.a = u_SmoothnessScale;\r\n\t\t\t#endif\r\n\t\t#else\r\n\t\t\tsg = texture2D(u_SpecGlossTexture, uv);\r\n\t\t\tsg.a *= u_SmoothnessScale;\r\n\t\t#endif\r\n\t#else\r\n\t\tsg.rgb = u_SpecularColor.rgb;\r\n\t\t#ifdef SMOOTHNESSSOURCE_ALBEDOTEXTURE_ALPHA\r\n\t\t\t#ifdef ALBEDOTEXTURE\r\n\t\t\t\tsg.a = texture2D(u_AlbedoTexture, uv).a * u_SmoothnessScale;\r\n\t\t\t#else\r\n\t\t\t\tsg.a = u_SmoothnessScale;\r\n\t\t\t#endif\r\n\t\t#else\r\n\t\t\tsg.a = u_Smoothness;\r\n\t\t#endif\r\n\t#endif\r\n\t\treturn sg;\r\n}\r\n\r\n\r\n#ifdef NORMALTEXTURE\r\n\tmediump vec3 unpackScaleNormal(mediump vec3 packednormal, mediump float bumpScale)\r\n\t{\r\n\t\tmediump vec3 normal = packednormal.xyz * 2.0 - 1.0;\r\n\t\tnormal.y=-normal.y;//NOTE:because unity to LayaAir coordSystem.\r\n\t\tnormal.xy *= bumpScale;\r\n\t\treturn normal;\r\n\t}\r\n\t\r\n\tmediump vec3 normalInTangentSpace(vec2 texcoords)\r\n\t{\r\n\t\tmediump vec3 normalTangent = unpackScaleNormal(texture2D(u_NormalTexture, texcoords).rgb,u_NormalScale);\r\n\t\treturn normalTangent;\r\n\t}\r\n#endif\r\n\r\n#ifdef PARALLAXTEXTURE\r\n\tmediump vec2 parallaxOffset1Step(mediump float h, mediump float height, mediump vec3 viewDir)\r\n\t{\r\n\t\th = h * height - height / 2.0;\r\n\t\tviewDir.z += 0.42;\r\n\t\treturn h * (viewDir.xy / viewDir.z);\r\n\t}\r\n\r\n\tvec2 parallax(vec2 texcoords, mediump vec3 viewDir)\r\n\t{\r\n\t\tmediump float h = texture2D(u_ParallaxTexture, texcoords.xy).g;\r\n\t\tvec2 offset = parallaxOffset1Step(h, u_ParallaxScale, viewDir);\r\n\t\treturn texcoords+offset;\r\n\t}\r\n#endif\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"),xe.addInclude("LayaPBRBRDF.glsl",'// allow to explicitly override LAYA_BRDF_GI and LAYA_BRDF_LIGHT in custom shader,default is layaBRDFHighGI and layaBRDFHighLight\r\n#if !defined (LAYA_BRDF_GI) \r\n\t#if defined(LAYA_PBR_BRDF_LOW)\r\n\t\t#define LAYA_BRDF_GI layaBRDFLowGI\r\n\t#elif defined(LAYA_PBR_BRDF_HIGH)\r\n\t\t#define LAYA_BRDF_GI layaBRDFHighGI\r\n\t#endif\r\n#endif\r\n#if !defined (LAYA_BRDF_LIGHT)\r\n\t#if defined(LAYA_PBR_BRDF_LOW)\r\n\t\t#define LAYA_BRDF_LIGHT layaBRDFLowLight\r\n\t#elif defined(LAYA_PBR_BRDF_HIGH)\r\n\t\t#define LAYA_BRDF_LIGHT layaBRDFHighLight\r\n\t#endif\r\n#endif\r\n\r\n#define PI 3.14159265359\r\n#define INV_PI 0.31830988618\r\n\r\nmediump float pow4(mediump float x)\r\n{\r\n\treturn x * x * x * x;\r\n}\r\n\r\nmediump float pow5(mediump float x)\r\n{\r\n\treturn x * x * x * x * x;\r\n}\r\n\r\nmediump vec3 fresnelLerp(mediump vec3 F0,mediump vec3 F90,mediump float cosA)\r\n{\r\n\tfloat t = pow5(1.0 - cosA); // ala Schlick interpoliation\r\n\treturn mix(F0, F90, t);\r\n}\r\n\r\nmediump vec3 fresnelTerm(mediump vec3 F0,mediump float cosA)\r\n{\r\n\tfloat t = pow5(1.0 - cosA); // ala Schlick interpoliation\r\n\treturn F0 + (vec3(1.0) - F0) * t;\r\n}\r\n\r\n// approximage Schlick with ^4 instead of ^5\r\nmediump vec3 fresnelLerpFast (mediump vec3 F0, mediump vec3 F90,mediump float cosA)\r\n{\r\n mediump float t = pow4 (1.0 - cosA);\r\n return mix (F0, F90, t);\r\n}\r\n\r\nfloat smoothnessToPerceptualRoughness(float smoothness)\r\n{\r\n return 1.0 - smoothness;\r\n}\r\n\r\nfloat perceptualRoughnessToRoughness(float perceptualRoughness)\r\n{\r\n return perceptualRoughness * perceptualRoughness;\r\n}\r\n\r\nvec3 safeNormalize(vec3 inVec)\r\n{\r\n\tfloat dp3 = max(0.001,dot(inVec,inVec));\r\n\treturn inVec * inversesqrt(dp3);\r\n}\r\n\r\n// Note: Disney diffuse must be multiply by diffuseAlbedo / PI. This is done outside of this function.\r\nmediump float disneyDiffuse(mediump float NdotV,mediump float NdotL,mediump float LdotH,mediump float perceptualRoughness)\r\n{\r\n\t//https://www.cnblogs.com/herenzhiming/articles/5790389.html\r\n\tmediump float fd90 = 0.5 + 2.0 * LdotH * LdotH * perceptualRoughness;\r\n\t// Two schlick fresnel term\r\n\tmediump float lightScatter = (1.0 + (fd90 - 1.0) * pow5(1.0 - NdotL));\r\n\tmediump float viewScatter = (1.0 + (fd90 - 1.0) * pow5(1.0 - NdotV));\r\n\r\n\treturn lightScatter * viewScatter;\r\n}\r\n\r\n// Ref: http://jcgt.org/published/0003/02/03/paper.pdf\r\nfloat smithJointGGXVisibilityTerm(float NdotL, float NdotV, float roughness)\r\n{\r\n\t// Original formulation:\r\n // lambda_v = (-1 + sqrt(a2 * (1 - NdotL2) / NdotL2 + 1)) * 0.5f;\r\n // lambda_l = (-1 + sqrt(a2 * (1 - NdotV2) / NdotV2 + 1)) * 0.5f;\r\n // G = 1 / (1 + lambda_v + lambda_l);\r\n\r\n\t// scientific code implement:\r\n\t// Reorder code to be more optimal\r\n // half a = roughness;\r\n // half a2 = a * a;\r\n\r\n // half lambdaV = NdotL * sqrt((-NdotV * a2 + NdotV) * NdotV + a2);\r\n // half lambdaL = NdotV * sqrt((-NdotL * a2 + NdotL) * NdotL + a2);\r\n\r\n // Simplify visibility term: (2.0f * NdotL * NdotV) / ((4.0f * NdotL * NdotV) * (lambda_v + lambda_l + 1e-5f));\r\n // return 0.5f / (lambdaV + lambdaL + 1e-5f); \r\n\t// This function is not intended to be running on Mobile,therefore epsilon is smaller than can be represented by half\r\n\r\n\t// Approximation of the above formulation (simplify the sqrt, not mathematically correct but close enough)\r\n\tfloat a = roughness;\r\n\tfloat lambdaV = NdotL * (NdotV * (1.0 - a) + a);\r\n\tfloat lambdaL = NdotV * (NdotL * (1.0 - a) + a);\r\n\treturn 0.5 / (lambdaV + lambdaL + 1e-5);\r\n}\r\n\r\nfloat ggxTerm(float NdotH, float roughness)\r\n{\r\n\tfloat a2 = roughness * roughness;\r\n\tfloat d = (NdotH * a2 - NdotH) * NdotH + 1.0; // 2 mad\r\n\treturn INV_PI * a2 / (d * d + 1e-7); // This function is not intended to be running on Mobile,therefore epsilon is smaller than what can be represented by half//返回值小用half来返回\r\n}\r\n\r\n// BRDF1-------------------------------------------------------------------------------------\r\n\r\n// Note: BRDF entry points use smoothness and oneMinusReflectivity for optimization purposes,\r\n// mostly for DX9 SM2.0 level. Most of the math is being done on these (1-x) values, and that saves a few precious ALU slots.\r\n\r\n// Main Physically Based BRDF\r\n// Derived from Disney work and based on Torrance-Sparrow micro-facet model\r\n//\r\n// BRDF = kD / pi + kS * (D * V * F) / 4\r\n// I = BRDF * NdotL\r\n//\r\n// *NDF GGX:\r\n// *Smith for Visiblity term\r\n// *Schlick approximation for Fresnel\r\nmediump vec4 layaBRDFHighLight(mediump vec3 diffColor, mediump vec3 specColor, mediump float oneMinusReflectivity, float perceptualRoughness,float roughness,mediump float nv,vec3 normal, vec3 viewDir,LayaLight light)\r\n{\r\n\tvec3 halfDir = safeNormalize(viewDir-light.dir);\r\n\r\n\tfloat nl = clamp(dot(normal, -light.dir),0.0,1.0);\r\n\tfloat nh = clamp(dot(normal, halfDir),0.0,1.0);\r\n\tmediump float lv = clamp(dot(light.dir, viewDir),0.0,1.0);\r\n\tmediump float lh = clamp(dot(light.dir, -halfDir),0.0,1.0);\r\n\r\n\t// Diffuse term\r\n\tmediump float diffuseTerm = disneyDiffuse(nv, nl, lh, perceptualRoughness) * nl;\r\n\r\n\t// Specular term\r\n // HACK: theoretically we should divide diffuseTerm by Pi and not multiply specularTerm!\r\n // BUT that will make shader look significantly darker than Legacy ones\r\n\r\n\t// GGX with roughtness to 0 would mean no specular at all, using max(roughness, 0.002) here to match HDrenderloop roughtness remapping.\r\n\troughness = max(roughness, 0.002);\r\n\tfloat V = smithJointGGXVisibilityTerm(nl, nv, roughness);\r\n\tfloat D = ggxTerm(nh, roughness);\r\n\r\n\tfloat specularTerm = V * D * PI; // Torrance-Sparrow model, Fresnel is applied later\r\n\r\n\t//#ifdef LAYA_COLORSPACE_GAMMA\r\n\tspecularTerm = sqrt(max(1e-4, specularTerm));\r\n\t//#endif\r\n\tspecularTerm = max(0.0, specularTerm * nl);\r\n\t\t\r\n\tmediump vec3 color = diffColor * light.color * diffuseTerm + specularTerm * light.color * fresnelTerm(specColor, lh);\r\n\treturn vec4(color, 1.0);\r\n}\r\n\r\nvec4 layaBRDFHighGI(mediump vec3 diffColor,mediump vec3 specColor,mediump float oneMinusReflectivity,float smoothness ,float perceptualRoughness,float roughness,mediump float nv,vec3 normal, vec3 viewDir,LayaGI gi)\r\n{\r\n\t// surfaceReduction = Int D(NdotH) * NdotH * Id(NdotL>0) dH = 1/(roughness^2+1)\r\n\tfloat surfaceReduction;\r\n\tsurfaceReduction = 1.0 - 0.28*roughness*perceptualRoughness;// 1-0.28*x^3 as approximation for (1/(x^4+1))^(1/2.2) on the domain [0;1]\r\n\tfloat grazingTerm = clamp(smoothness + (1.0 - oneMinusReflectivity),0.0,1.0);\r\n\tmediump vec3 color =diffColor * gi.diffuse + surfaceReduction * gi.specular * fresnelLerp(specColor,vec3(grazingTerm), nv);\r\n\treturn vec4(color,1.0);\r\n}\r\n// BRDF1-------------------------------------------------------------------------------------\r\n\r\n\r\n// BRDF2-------------------------------------------------------------------------------------\r\n// Based on Minimalist CookTorrance BRDF\r\n// Implementation is slightly different from original derivation: http://www.thetenthplanet.de/archives/255\r\n//\r\n// *NDF [Modified] GGX:\r\n// *Modified Kelemen and Szirmay-Kalos for Visibility term\r\n// *Fresnel approximated with 1/LdotH\r\nmediump vec4 layaBRDFLowLight (mediump vec3 diffColor, mediump vec3 specColor,mediump float oneMinusReflectivity,float perceptualRoughness,float roughness,mediump float nv,vec3 normal,vec3 viewDir,LayaLight light)\r\n{\r\n vec3 halfDir = safeNormalize (viewDir-light.dir);\r\n mediump float nl = clamp(dot(normal, -light.dir),0.0,1.0);\r\n float nh = clamp(dot(normal, halfDir),0.0,1.0);\r\n float lh = clamp(dot(-light.dir, halfDir),0.0,1.0);\r\n\r\n // GGX Distribution multiplied by combined approximation of Visibility and Fresnel\r\n // See "Optimizing PBR for Mobile" from Siggraph 2015 moving mobile graphics course\r\n // https://community.arm.com/events/1155\r\n mediump float a = roughness;\r\n float a2 = a*a;\r\n\r\n float d = nh * nh * (a2 - 1.0) + 1.00001;\r\n\t// #ifdef LAYA_COLORSPACE_GAMMA\r\n\t\t// Tighter approximation for Gamma only rendering mode!\r\n\t\t// DVF = sqrt(DVF);\r\n\t\t// DVF = (a * sqrt(.25)) / (max(sqrt(0.1), lh)*sqrt(roughness + .5) * d);\r\n\t\tfloat specularTerm = a / (max(0.32, lh) * (1.5 + roughness) * d);\r\n\t// #else\r\n\t// \tfloat specularTerm = a2 / (max(0.1f, lh*lh) * (roughness + 0.5f) * (d * d) * 4);\r\n\t// #endif\r\n\r\n // on mobiles (where half actually means something) denominator have risk of overflow\r\n // clamp below was added specifically to "fix" that, but dx compiler (we convert bytecode to metal/gles)\r\n // sees that specularTerm have only non-negative terms, so it skips max(0,..) in clamp (leaving only min(100,...))\r\n\r\n\t//#if defined (SHADER_API_MOBILE)\r\n specularTerm = specularTerm - 1e-4;\r\n\t//#endif\r\n\r\n\t// #else\r\n\t\t// // Legacy\r\n\t\t// half specularPower = PerceptualRoughnessToSpecPower(perceptualRoughness);\r\n\t\t// // Modified with approximate Visibility function that takes roughness into account\r\n\t\t// // Original ((n+1)*N.H^n) / (8*Pi * L.H^3) didn\'t take into account roughness\r\n\t\t// // and produced extremely bright specular at grazing angles\r\n\r\n\t\t// half invV = lh * lh * smoothness + perceptualRoughness * perceptualRoughness; // approx ModifiedKelemenVisibilityTerm(lh, perceptualRoughness);\r\n\t\t// half invF = lh;\r\n\r\n\t\t// half specularTerm = ((specularPower + 1) * pow (nh, specularPower)) / (8 * invV * invF + 1e-4h);\r\n\r\n\t\t// #ifdef LAYA_COLORSPACE_GAMMA\r\n\t\t// \tspecularTerm = sqrt(max(1e-4f, specularTerm));\r\n\t\t// #endif\r\n\t// #endif\r\n\r\n\t// #if defined (SHADER_API_MOBILE)\r\n\t\tspecularTerm = clamp(specularTerm, 0.0, 100.0); // Prevent FP16 overflow on mobiles\r\n\t// #endif\r\n \r\n mediump vec3 color = (diffColor + specularTerm * specColor) * light.color * nl;\r\n\r\n return vec4(color, 1.0);\r\n}\r\n\r\nmediump vec4 layaBRDFLowGI (mediump vec3 diffColor, mediump vec3 specColor,mediump float oneMinusReflectivity,mediump float smoothness,float perceptualRoughness,float roughness,mediump float nv,vec3 normal,vec3 viewDir,LayaGI gi)\r\n{\r\n\t// surfaceReduction = Int D(NdotH) * NdotH * Id(NdotL>0) dH = 1/(realRoughness^2+1)\r\n\r\n // 1-0.28*x^3 as approximation for (1/(x^4+1))^(1/2.2) on the domain [0;1]\r\n // 1-x^3*(0.6-0.08*x) approximation for 1/(x^4+1)\r\n\t// #ifdef LAYA_COLORSPACE_GAMMA\r\n\t\tmediump float surfaceReduction = 0.28;\r\n\t// #else\r\n\t\t// mediump float surfaceReduction = (0.6-0.08*perceptualRoughness);\r\n\t// #endif\r\n\r\n surfaceReduction = 1.0 - roughness*perceptualRoughness*surfaceReduction;\r\n\r\n\tmediump float grazingTerm = clamp(smoothness + (1.0-oneMinusReflectivity),0.0,1.0);\r\n\tmediump vec3 color =gi.diffuse * diffColor+ surfaceReduction * gi.specular * fresnelLerpFast (specColor, vec3(grazingTerm), nv);\r\n\r\n return vec4(color, 1.0);\r\n}\r\n// BRDF2-------------------------------------------------------------------------------------'),xe.addInclude("PBRCore.glsl","struct FragmentCommonData{\r\n\tvec3 diffColor;\r\n\tvec3 specColor;\r\n\tfloat oneMinusReflectivity;\r\n\tfloat smoothness;\r\n\t//vec3 eyeVec;TODO:maybe can remove\r\n\t//float alpha;\r\n\t//vec3 reflUVW;\r\n};\r\n\r\n#if !defined(SETUP_BRDF_INPUT)//shader内部的宏需要将改成#ifdef改成#if类型 不然会被Laya的shader分析器优化掉\r\n #define SETUP_BRDF_INPUT metallicSetup//default is metallicSetup,also can be other. \r\n#endif\r\n\r\nconst mediump vec4 dielectricSpecularColor = vec4(0.220916301, 0.220916301, 0.220916301, 1.0 - 0.220916301);\r\n\r\nmediump vec3 diffuseAndSpecularFromMetallic(mediump vec3 albedo,mediump float metallic, out mediump vec3 specColor, out mediump float oneMinusReflectivity)\r\n{\r\n\tspecColor = mix(dielectricSpecularColor.rgb, albedo, metallic);\r\n\toneMinusReflectivity= dielectricSpecularColor.a*(1.0-metallic);//diffuse proportion\r\n\treturn albedo * oneMinusReflectivity;\r\n}\r\n\r\nmediump float specularStrength(mediump vec3 specular)\r\n{\r\n return max (max (specular.r, specular.g), specular.b);\r\n}\r\n\r\n// Diffuse/Spec Energy conservation\r\nmediump vec3 energyConservationBetweenDiffuseAndSpecular (mediump vec3 albedo, mediump vec3 specColor, out mediump float oneMinusReflectivity)\r\n{\r\n\toneMinusReflectivity = 1.0 - specularStrength(specColor);\r\n return albedo * (vec3(1.0) - specColor);\r\n}\r\n\r\n#ifdef TRANSPARENTBLEND\r\n\tmediump vec3 preMultiplyAlpha (mediump vec3 diffColor, mediump float alpha, mediump float oneMinusReflectivity,out mediump float modifiedAlpha)\r\n\t{\r\n\t\t// Transparency 'removes' from Diffuse component\r\n\t\tdiffColor *= alpha;\r\n\t\t// Reflectivity 'removes' from the rest of components, including Transparency\r\n\t\t// modifiedAlpha = 1.0-(1.0-alpha)*(1.0-reflectivity) = 1.0-(oneMinusReflectivity - alpha*oneMinusReflectivity) = 1.0-oneMinusReflectivity + alpha*oneMinusReflectivity\r\n\t\tmodifiedAlpha = 1.0 - oneMinusReflectivity + alpha*oneMinusReflectivity;\r\n\t\treturn diffColor;\r\n\t}\r\n#endif\r\n\r\nFragmentCommonData metallicSetup(vec2 uv)\r\n{\r\n\tmediump vec2 metallicGloss = getMetallicGloss(uv);\r\n\tmediump float metallic = metallicGloss.x;\r\n\tmediump float smoothness = metallicGloss.y; // this is 1 minus the square root of real roughness m.\r\n\tmediump float oneMinusReflectivity;\r\n\tmediump vec3 specColor;\r\n\tmediump vec3 diffColor = diffuseAndSpecularFromMetallic(albedo(uv), metallic,/*out*/specColor,/*out*/oneMinusReflectivity);\r\n\r\n\tFragmentCommonData o;\r\n\to.diffColor = diffColor;\r\n\to.specColor = specColor;\r\n\to.oneMinusReflectivity = oneMinusReflectivity;\r\n\to.smoothness = smoothness;\r\n\treturn o;\r\n}\r\n\r\nFragmentCommonData specularSetup(vec2 uv)\r\n{\r\n mediump vec4 specGloss = specularGloss(uv);\r\n mediump vec3 specColor = specGloss.rgb;\r\n mediump float smoothness = specGloss.a;\r\n\r\n mediump float oneMinusReflectivity;\r\n mediump vec3 diffColor = energyConservationBetweenDiffuseAndSpecular (albedo(uv), specColor, /*out*/ oneMinusReflectivity);\r\n\r\n FragmentCommonData o;\r\n o.diffColor = diffColor;\r\n o.specColor = specColor;\r\n o.oneMinusReflectivity = oneMinusReflectivity;\r\n o.smoothness = smoothness;\r\n return o;\r\n}\r\n\r\nLayaGI fragmentGI(float smoothness,vec3 eyeVec,mediump float occlusion,mediump vec2 lightmapUV,vec3 worldnormal,vec3 worldPos)\r\n{\r\n\tLayaGIInput giInput;\r\n\t#ifdef LIGHTMAP\r\n\t\tgiInput.lightmapUV=lightmapUV;\r\n\t#endif\r\n\tgiInput.worldPos = worldPos;\r\n\r\n\tvec3 worldViewDir = -eyeVec;\r\n\tmediump vec4 uvwRoughness;\r\n\tuvwRoughness.rgb = reflect(worldViewDir, worldnormal);//reflectUVW\r\n\tuvwRoughness.a= smoothnessToPerceptualRoughness(smoothness);//perceptualRoughness\r\n\r\n\treturn layaGlobalIllumination(giInput,occlusion, worldnormal, uvwRoughness);\r\n}\r\n\r\n\r\nvec3 perPixelWorldNormal(vec2 uv,vec3 normal,vec3 binormal,vec3 tangent)\r\n{\r\n\t#ifdef NORMALTEXTURE\r\n\t\tmediump vec3 normalTangent=normalInTangentSpace(uv);\r\n\t\tvec3 normalWorld = normalize(tangent * normalTangent.x + binormal * normalTangent.y + normal * normalTangent.z);\r\n\t#else\r\n\t\tvec3 normalWorld = normalize(normal);\r\n\t#endif\r\n\t\treturn normalWorld;\r\n}\r\n\r\nvoid fragmentForward()\r\n{\r\n\tvec2 uv;\r\n\t#if defined(ALBEDOTEXTURE)||defined(METALLICGLOSSTEXTURE)||defined(NORMALTEXTURE)||defined(EMISSIONTEXTURE)||defined(OCCLUSIONTEXTURE)||defined(PARALLAXTEXTURE)\r\n\t\t#ifdef PARALLAXTEXTURE\r\n\t\t\tuv = parallax(v_Texcoord0,normalize(v_ViewDirForParallax));\r\n\t\t#else\r\n\t\t\tuv = v_Texcoord0;\r\n\t\t#endif\r\n\t#endif\r\n\r\n\tmediump float alpha = getAlpha(uv);\r\n\t#ifdef ALPHATEST\r\n\t\tif(alpha<u_AlphaTestValue)\r\n\t\t\tdiscard;\r\n\t#endif\r\n\r\n\tFragmentCommonData o = SETUP_BRDF_INPUT(uv);\r\n\t\r\n\tvec3 binormal;\r\n\tvec3 tangent;\r\n\t#ifdef NORMALTEXTURE\r\n\t\ttangent = v_Tangent;\r\n\t\tbinormal = v_Binormal;\r\n\t#endif\r\n\r\n\tvec3 normal = v_Normal;\r\n\tvec3 normalWorld = perPixelWorldNormal(uv,normal,binormal,tangent);//In FS if the normal use mediump before normalize will cause precision prolem in mobile device.\r\n\tvec3 eyeVec = normalize(v_EyeVec);\r\n\tvec3 posworld = v_PositionWorld;\r\n\r\n\t#ifdef TRANSPARENTBLEND\r\n\t\to.diffColor=preMultiplyAlpha(o.diffColor,alpha,o.oneMinusReflectivity,/*out*/alpha);// shader relies on pre-multiply alpha-blend (srcBlend = One, dstBlend = OneMinusSrcAlpha)\r\n\t#endif\r\n\r\n\tmediump float occlusion = getOcclusion(uv);\r\n\tmediump vec2 lightMapUV;\r\n\t#ifdef LIGHTMAP\r\n\t\tlightMapUV=v_LightMapUV;\r\n\t#endif\r\n\tfloat perceptualRoughness = smoothnessToPerceptualRoughness(o.smoothness);\r\n\tfloat roughness = perceptualRoughnessToRoughness(perceptualRoughness);\r\n\tfloat nv = abs(dot(normalWorld, eyeVec));\r\n\tLayaGI gi =fragmentGI(o.smoothness,eyeVec,occlusion,lightMapUV,normalWorld,posworld);\r\n\tvec4 color = LAYA_BRDF_GI(o.diffColor,o.specColor,o.oneMinusReflectivity,o.smoothness,perceptualRoughness,roughness,nv,normalWorld,eyeVec,gi);\r\n\t\r\n\tfloat shadowAttenuation = 1.0;\r\n\t#ifdef LEGACYSINGLELIGHTING\r\n\t\t#ifdef DIRECTIONLIGHT\r\n\t\t\t#if defined(CALCULATE_SHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\t\t\t#ifdef SHADOW_CASCADE\r\n\t\t\t\t\tvec4 shadowCoord = getShadowCoord(vec4(v_PositionWorld,1.0));\r\n\t\t\t\t#else\r\n\t\t\t\t\tvec4 shadowCoord = v_ShadowCoord;\r\n\t\t\t\t#endif\r\n\t\t\t\tshadowAttenuation=sampleShadowmap(shadowCoord);\r\n\t\t\t#endif\r\n\t\t\tLayaLight dirLight = layaDirectionLightToLight(u_DirectionLight,shadowAttenuation);\r\n\t\t\tcolor+= LAYA_BRDF_LIGHT(o.diffColor,o.specColor,o.oneMinusReflectivity,perceptualRoughness,roughness,nv,normalWorld,eyeVec,dirLight);\r\n\t\t#endif\r\n\t\r\n\t\t#ifdef POINTLIGHT\r\n\t\t\tshadowAttenuation = 1.0;\r\n\t\t\tLayaLight poiLight = layaPointLightToLight(posworld,normalWorld,u_PointLight,shadowAttenuation);\r\n\t\t\tcolor+= LAYA_BRDF_LIGHT(o.diffColor,o.specColor,o.oneMinusReflectivity,perceptualRoughness,roughness,nv,normalWorld,eyeVec,poiLight);\r\n\t\t#endif\r\n\t\t\r\n\t\t#ifdef SPOTLIGHT\r\n\t\t\tshadowAttenuation = 1.0;\r\n\t\t\t#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\t\t\tvec4 spotShadowcoord = v_SpotShadowCoord;\r\n\t\t\t\tshadowAttenuation = sampleSpotShadowmap(spotShadowcoord);\r\n\t\t\t#endif\r\n\t\t LayaLight spoLight = layaSpotLightToLight(posworld,normalWorld,u_SpotLight,shadowAttenuation);\r\n\t\t\tcolor+= LAYA_BRDF_LIGHT(o.diffColor,o.specColor,o.oneMinusReflectivity,perceptualRoughness,roughness,nv,normalWorld,eyeVec,spoLight);\r\n\t\t#endif\r\n\t#else\r\n\t \t#ifdef DIRECTIONLIGHT\r\n\t\t\tfor (int i = 0; i < MAX_LIGHT_COUNT; i++) \r\n\t\t\t{\r\n\t\t\t\tshadowAttenuation = 1.0;\r\n\t\t\t\tif(i >= u_DirationLightCount)\r\n\t\t\t\t\tbreak;\r\n\t\t\t\t#if defined(CALCULATE_SHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\t\t\t\tif(i == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t#ifdef SHADOW_CASCADE\r\n\t\t\t\t\t\t\tvec4 shadowCoord = getShadowCoord(vec4(v_PositionWorld,1.0));\r\n\t\t\t\t\t\t#else\r\n\t\t\t\t\t\t\tvec4 shadowCoord = v_ShadowCoord;\r\n\t\t\t\t\t\t#endif\r\n\t\t\t\t\t\tshadowAttenuation *= sampleShadowmap(shadowCoord);\r\n\t\t\t\t\t}\r\n\t\t\t\t#endif\r\n\t\t\t\tDirectionLight directionLight = getDirectionLight(u_LightBuffer,i);\r\n\t\t\t\tLayaLight dirLight = layaDirectionLightToLight(directionLight,shadowAttenuation);\r\n\t\t\t \tcolor+=LAYA_BRDF_LIGHT(o.diffColor,o.specColor,o.oneMinusReflectivity,perceptualRoughness,roughness,nv,normalWorld,eyeVec,dirLight);\r\n\t\t\t}\r\n\t \t#endif\r\n\t\t#if defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\t\tivec4 clusterInfo =getClusterInfo(u_LightClusterBuffer,u_View,u_Viewport, v_PositionWorld,gl_FragCoord,u_ProjectionParams);\r\n\t\t\t#ifdef POINTLIGHT\r\n\t\t\t\tfor (int i = 0; i < MAX_LIGHT_COUNT; i++) \r\n\t\t\t\t{\r\n\t\t\t\t\tshadowAttenuation = 1.0;\r\n\t\t\t\t\tif(i >= clusterInfo.x)//PointLightCount\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tPointLight pointLight = getPointLight(u_LightBuffer,u_LightClusterBuffer,clusterInfo,i);\r\n\t\t\t\t\tLayaLight poiLight = layaPointLightToLight(posworld,normalWorld,pointLight,shadowAttenuation);\r\n\t\t\t\t\tcolor+= LAYA_BRDF_LIGHT(o.diffColor,o.specColor,o.oneMinusReflectivity,perceptualRoughness,roughness,nv,normalWorld,eyeVec,poiLight);\r\n\t\t\t\t}\r\n\t\t\t#endif\r\n\t\t\t#ifdef SPOTLIGHT\r\n\t\t\t\tfor (int i = 0; i < MAX_LIGHT_COUNT; i++) \r\n\t\t\t\t{\r\n\t\t\t\t\tshadowAttenuation = 1.0;\r\n\t\t\t\t\tif(i >= clusterInfo.y)//SpotLightCount\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\t\t\t\t\tif(i == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tvec4 spotShadowcoord = v_SpotShadowCoord;\r\n\t\t\t\t\t\t\tshadowAttenuation= sampleSpotShadowmap(spotShadowcoord);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t#endif\r\n\t\t\t\t\tSpotLight spotLight = getSpotLight(u_LightBuffer,u_LightClusterBuffer,clusterInfo,i);\r\n\t\t\t\t\tLayaLight spoLight = layaSpotLightToLight(posworld,normalWorld,spotLight,shadowAttenuation);\r\n\t\t\t\t\tcolor+= LAYA_BRDF_LIGHT(o.diffColor,o.specColor,o.oneMinusReflectivity,perceptualRoughness,roughness,nv,normalWorld,eyeVec,spoLight);\r\n\t\t\t\t}\r\n\t\t\t#endif\r\n\t\t#endif\r\n\t #endif\r\n\r\n\t#ifdef EMISSION\r\n\t\tcolor.rgb += emission(uv);\r\n\t#endif\r\n\r\n\t#ifdef FOG\r\n\t\tfloat lerpFact=clamp((1.0/gl_FragCoord.w-u_FogStart)/u_FogRange,0.0,1.0);\r\n\t\tcolor.rgb=mix(color.rgb,u_FogColor,lerpFact);\r\n\t#endif\r\n\t\r\n\tgl_FragColor=vec4(color.rgb,alpha);\r\n}\r\n\r\n\r\n\r\n"),xe.addInclude("PBRVertex.glsl","vec2 transformLightMapUV(in vec2 texcoord,in vec4 lightmapScaleOffset)\r\n{\r\n\tvec2 lightMapUV=vec2(texcoord.x,1.0-texcoord.y)*lightmapScaleOffset.xy+lightmapScaleOffset.zw;\r\n\tlightMapUV.y=1.0-lightMapUV.y;\r\n\treturn lightMapUV; \r\n}\r\n\r\nvoid vertexForward()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform;\r\n\t \t#ifdef SIMPLEBONE\r\n\t\t\tfloat currentPixelPos;\r\n\t\t\t#ifdef GPU_INSTANCE\r\n\t\t\t\tcurrentPixelPos = a_SimpleTextureParams.x+a_SimpleTextureParams.y;\r\n\t\t\t#else\r\n\t\t\t\tcurrentPixelPos = u_SimpleAnimatorParams.x+u_SimpleAnimatorParams.y;\r\n\t\t\t#endif\r\n\t\t\tfloat offset = 1.0/u_SimpleAnimatorTextureSize;\r\n\t\t\tskinTransform = loadMatFromTexture(currentPixelPos,int(a_BoneIndices.x),offset) * a_BoneWeights.x;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.y),offset) * a_BoneWeights.y;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.z),offset) * a_BoneWeights.z;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.w),offset) * a_BoneWeights.w;\r\n\t\t#else\r\n\t\t\tskinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\t#endif\r\n\t\tposition=skinTransform*a_Position;\r\n\t #else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\r\n\tmat4 worldMat;\r\n\t#ifdef GPU_INSTANCE\r\n\t\tworldMat = a_WorldMat;\r\n\t#else\r\n\t\tworldMat = u_WorldMat;\r\n\t#endif\r\n\r\n\tv_PositionWorld=(worldMat*position).xyz;\r\n\r\n\t#if defined(ALBEDOTEXTURE)||defined(METALLICGLOSSTEXTURE)||defined(NORMALTEXTURE)||defined(EMISSIONTEXTURE)||defined(OCCLUSIONTEXTURE)||defined(PARALLAXTEXTURE)\r\n\t\t#ifdef TILINGOFFSET\r\n\t\t\tv_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\r\n\t\t#else\r\n\t\t\tv_Texcoord0=a_Texcoord0;\r\n\t\t#endif\r\n\t#endif\r\n\r\n\tv_EyeVec =u_CameraPos-v_PositionWorld;//will normalize per-pixel\r\n\r\n\t#ifdef LIGHTMAP\r\n\t\tvec2 texcoord;\r\n\t\t#ifdef UV1\r\n\t\t\ttexcoord=a_Texcoord1;\r\n\t\t#else\r\n\t\t\ttexcoord=a_Texcoord0;\r\n\t\t#endif\r\n\t\tv_LightMapUV=transformLightMapUV(texcoord,u_LightmapScaleOffset);\r\n\t#endif\r\n\r\n\tmat3 worldInvMat;\r\n\t#ifdef BONE\r\n\t\tworldInvMat=INVERSE_MAT(mat3(worldMat*skinTransform));\r\n\t#else\r\n\t\tworldInvMat=INVERSE_MAT(mat3(worldMat));\r\n\t#endif\r\n\r\n\tv_Normal=normalize(a_Normal*worldInvMat);//if no normalize will cause precision problem.\r\n\r\n\t#ifdef NORMALTEXTURE\r\n\t\tv_Tangent=normalize(a_Tangent0.xyz*worldInvMat);\r\n\t\tv_Binormal=cross(v_Normal,v_Tangent)*a_Tangent0.w;\r\n\t#endif\r\n\r\n\t#ifdef PARALLAXTEXTURE\r\n\t\tvec3 binormal = cross(a_Normal, a_Tangent0.xyz)*a_Tangent0.w;\r\n\t\tmat3 objectTBN = mat3(a_Tangent0.xyz, binormal, a_Normal);\r\n\t\tv_ViewDirForParallax =(u_CameraPos*worldInvMat-position.xyz)*objectTBN;\r\n\t#endif\r\n\r\n\t#if defined(CALCULATE_SHADOWS)&&!defined(SHADOW_CASCADE)\r\n\t\tv_ShadowCoord = getShadowCoord(vec4(v_PositionWorld,1.0));\r\n\t#endif\r\n\r\n\t#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\tv_SpotShadowCoord = u_SpotViewProjectMatrix*vec4(v_PositionWorld,1.0);\r\n\t#endif\r\n}"),xe.addInclude("LayaUtile.glsl","\r\n\r\n//SimpleSkinnedMesh\r\n#ifdef SIMPLEBONE\r\n\t#ifdef GPU_INSTANCE\r\n\t\tattribute vec4 a_SimpleTextureParams;\r\n\t#else\r\n\t\tuniform vec4 u_SimpleAnimatorParams;\r\n\t#endif\r\n\tuniform sampler2D u_SimpleAnimatorTexture;\r\n\r\n\tuniform float u_SimpleAnimatorTextureSize; \r\n#endif\r\n\r\n\r\n#ifdef SIMPLEBONE\r\n\tmat4 loadMatFromTexture(float FramePos,int boneIndices,float offset)\r\n\t{\r\n\t\tvec2 uv;\r\n\t\tfloat PixelPos = FramePos+float(boneIndices)*4.0;\r\n\t\tfloat halfOffset = offset * 0.5;\r\n\t\tfloat uvoffset = PixelPos/u_SimpleAnimatorTextureSize;\r\n\t\tuv.y = floor(uvoffset)*offset+halfOffset;\r\n\t\tuv.x = mod(float(PixelPos),u_SimpleAnimatorTextureSize)*offset+halfOffset;\r\n\t\tvec4 mat0row = texture2D(u_SimpleAnimatorTexture,uv);\r\n\t\tuv.x+=offset;\r\n\t\tvec4 mat1row = texture2D(u_SimpleAnimatorTexture,uv);\r\n\t\tuv.x+=offset;\r\n\t\tvec4 mat2row = texture2D(u_SimpleAnimatorTexture,uv);\r\n\t\tuv.x+=offset;\r\n\t\tvec4 mat3row = texture2D(u_SimpleAnimatorTexture,uv);\r\n\t\tmat4 m =mat4(mat0row.x,mat0row.y,mat0row.z,mat0row.w,\r\n\t\t\t\tmat1row.x,mat1row.y,mat1row.z,mat1row.w,\r\n\t\t\t\tmat2row.x,mat2row.y,mat2row.z,mat2row.w,\r\n\t\t\t\tmat3row.x,mat3row.y,mat3row.z,mat3row.w);\r\n\t\treturn m;\r\n\t}\r\n#endif\r\n\r\n"),xe.addInclude("DepthNormalUtil.glsl","#define SAMPLE_DEPTH_TEXTURE(textureName,coord2) (texture2D(textureName,coord2).r)\r\n//此方法库用来压缩解析深度贴图,法线深度贴图\r\n\r\n/*camera 传入的Texture以及*/\r\nuniform sampler2D u_CameraDepthTexture;\r\nuniform vec4 u_ZBufferParams;\r\nuniform sampler2D u_CameraDepthNormalsTexture;\r\n\r\n// Encoding/decoding view space normals into 2D 0..1 vector\r\nvec2 EncodeViewNormalStereo( vec3 n )\r\n{\r\n n.z = abs(n.z);\r\n float kScale = 1.7777;\r\n vec2 enc;\r\n enc = n.xy / (n.z+1.0);\r\n enc /= kScale;\r\n enc = enc*0.5+0.5;\r\n return enc;\r\n}\r\n\r\nvec3 DecodeViewNormalStereo( vec4 enc4 )\r\n{\r\n float kScale = 1.7777;\r\n vec3 nn = enc4.xyz*vec3(2.0*kScale,2.0*kScale,0.0) + vec3(-kScale,-kScale,1.0);\r\n float g = 2.0 / dot(nn.xyz,nn.xyz);\r\n vec3 n;\r\n n.xy = g*nn.xy;\r\n n.z = g-1.0;\r\n return n;\r\n}\r\n\r\n\r\n// Encoding/decoding [0..1) floats into 8 bit/channel RG. Note that 1.0 will not be encoded properly.\r\nvec2 EncodeFloatRG( float v )\r\n{\r\n vec2 kEncodeMul = vec2(1.0, 255.0);\r\n float kEncodeBit = 1.0/255.0;\r\n vec2 enc = kEncodeMul * v;\r\n enc = fract(enc);\r\n enc.x -= enc.y * kEncodeBit;\r\n return enc;\r\n}\r\n\r\n\r\n\r\nfloat DecodeFloatRG( vec2 enc )\r\n{\r\n vec2 kDecodeDot = vec2(1.0, 1.0/255.0);\r\n return dot( enc, kDecodeDot );\r\n}\r\n\r\nvec4 EncodeDepthNormal(float depth,vec3 normals){\r\n\tvec4 encode;\r\n\tencode.xy = EncodeViewNormalStereo(normals);\r\n\tencode.zw = EncodeFloatRG(depth);\r\n return encode;\r\n}\r\n\r\nvoid DecodeDepthNormal( vec4 enc, out float depth, out vec3 normal )\r\n{\r\n depth = DecodeFloatRG (enc.zw);\r\n normal = DecodeViewNormalStereo (enc);\r\n}\r\n\r\n\r\n\r\nvec4 depthNormalsFragment(vec4 depthNormal)\r\n{\r\n return EncodeDepthNormal(depthNormal.w,depthNormal.xyz);\r\n}\r\n\r\n\r\n// Z buffer to linear 0..1 depth\r\nfloat Linear01Depth(float z,vec4 zbufferParams)\r\n{\r\n return 1.0 / (zbufferParams.x * z + zbufferParams.y);\r\n}\r\n// Z buffer to linear depth\r\nfloat LinearEyeDepth(float z,vec4 zbufferParams)\r\n{\r\n return 1.0 / (zbufferParams.z * z + zbufferParams.w);\r\n}\r\n");var e={a_Position:ze.MESH_POSITION0,a_Color:ze.MESH_COLOR0,a_Normal:ze.MESH_NORMAL0,a_Texcoord0:ze.MESH_TEXTURECOORDINATE0,a_Texcoord1:ze.MESH_TEXTURECOORDINATE1,a_BoneWeights:ze.MESH_BLENDWEIGHT0,a_BoneIndices:ze.MESH_BLENDINDICES0,a_Tangent0:ze.MESH_TANGENT0,a_MvpMatrix:ze.MESH_MVPMATRIX_ROW0,a_WorldMat:ze.MESH_WORLDMATRIX_ROW0},t={u_Bones:xe.PERIOD_CUSTOM,u_DiffuseTexture:xe.PERIOD_MATERIAL,u_SpecularTexture:xe.PERIOD_MATERIAL,u_NormalTexture:xe.PERIOD_MATERIAL,u_AlphaTestValue:xe.PERIOD_MATERIAL,u_DiffuseColor:xe.PERIOD_MATERIAL,u_MaterialSpecular:xe.PERIOD_MATERIAL,u_Shininess:xe.PERIOD_MATERIAL,u_TilingOffset:xe.PERIOD_MATERIAL,u_WorldMat:xe.PERIOD_SPRITE,u_MvpMatrix:xe.PERIOD_SPRITE,u_LightmapScaleOffset:xe.PERIOD_SPRITE,u_LightMap:xe.PERIOD_SPRITE,u_LightMapDirection:xe.PERIOD_SPRITE,u_SimpleAnimatorTexture:xe.PERIOD_SPRITE,u_SimpleAnimatorParams:xe.PERIOD_SPRITE,u_SimpleAnimatorTextureSize:xe.PERIOD_SPRITE,u_CameraPos:xe.PERIOD_CAMERA,u_Viewport:xe.PERIOD_CAMERA,u_ProjectionParams:xe.PERIOD_CAMERA,u_View:xe.PERIOD_CAMERA,u_ViewProjection:xe.PERIOD_CAMERA,u_ReflectTexture:xe.PERIOD_SCENE,u_FogStart:xe.PERIOD_SCENE,u_FogRange:xe.PERIOD_SCENE,u_FogColor:xe.PERIOD_SCENE,u_DirationLightCount:xe.PERIOD_SCENE,u_LightBuffer:xe.PERIOD_SCENE,u_LightClusterBuffer:xe.PERIOD_SCENE,u_AmbientColor:xe.PERIOD_SCENE,u_ShadowBias:xe.PERIOD_SCENE,u_ShadowLightDirection:xe.PERIOD_SCENE,u_ShadowMap:xe.PERIOD_SCENE,u_ShadowParams:xe.PERIOD_SCENE,u_ShadowSplitSpheres:xe.PERIOD_SCENE,u_ShadowMatrices:xe.PERIOD_SCENE,u_ShadowMapSize:xe.PERIOD_SCENE,u_SpotShadowMap:xe.PERIOD_SCENE,u_SpotViewProjectMatrix:xe.PERIOD_SCENE,u_ShadowLightPosition:xe.PERIOD_SCENE,u_AmbientSHAr:xe.PERIOD_SCENE,u_AmbientSHAg:xe.PERIOD_SCENE,u_AmbientSHAb:xe.PERIOD_SCENE,u_AmbientSHBr:xe.PERIOD_SCENE,u_AmbientSHBg:xe.PERIOD_SCENE,u_AmbientSHBb:xe.PERIOD_SCENE,u_AmbientSHC:xe.PERIOD_SCENE,"u_DirectionLight.color":xe.PERIOD_SCENE,"u_DirectionLight.direction":xe.PERIOD_SCENE,"u_PointLight.position":xe.PERIOD_SCENE,"u_PointLight.range":xe.PERIOD_SCENE,"u_PointLight.color":xe.PERIOD_SCENE,"u_SpotLight.position":xe.PERIOD_SCENE,"u_SpotLight.direction":xe.PERIOD_SCENE,"u_SpotLight.range":xe.PERIOD_SCENE,"u_SpotLight.spot":xe.PERIOD_SCENE,"u_SpotLight.color":xe.PERIOD_SCENE},r={s_Cull:xe.RENDER_STATE_CULL,s_Blend:xe.RENDER_STATE_BLEND,s_BlendSrc:xe.RENDER_STATE_BLEND_SRC,s_BlendDst:xe.RENDER_STATE_BLEND_DST,s_DepthTest:xe.RENDER_STATE_DEPTH_TEST,s_DepthWrite:xe.RENDER_STATE_DEPTH_WRITE},i=xe.add("BLINNPHONG",null,null,!0),a=new mr(e,t);i.addSubShader(a),a.addShaderPass('#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n#include "Lighting.glsl";\r\n#include "LayaUtile.glsl"\r\n#include "Shadow.glsl";\r\n\r\n\r\nattribute vec4 a_Position;\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_MvpMatrix;\r\n#else\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\n\r\n#if defined(DIFFUSEMAP)||((defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&(defined(SPECULARMAP)||defined(NORMALMAP)))||(defined(LIGHTMAP)&&defined(UV))\r\n\tattribute vec2 a_Texcoord0;\r\n\tvarying vec2 v_Texcoord0;\r\n#endif\r\n\r\n#if defined(LIGHTMAP)&&defined(UV1)\r\n\tattribute vec2 a_Texcoord1;\r\n#endif\r\n\r\n#ifdef LIGHTMAP\r\n\tuniform vec4 u_LightmapScaleOffset;\r\n\tvarying vec2 v_LightMapUV;\r\n#endif\r\n\r\n#ifdef COLOR\r\n\tattribute vec4 a_Color;\r\n\tvarying vec4 v_Color;\r\n#endif\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\nattribute vec3 a_Normal;\r\nvarying vec3 v_Normal; \r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\tuniform vec3 u_CameraPos;\r\n\tvarying vec3 v_ViewDir; \r\n#endif\r\n\r\n#if defined(NORMALMAP)\r\n\tattribute vec4 a_Tangent0;\r\n\tvarying vec3 v_Tangent;\r\n\tvarying vec3 v_Binormal;\r\n#endif\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_WorldMat;\r\n#else\r\n\tuniform mat4 u_WorldMat;\r\n#endif\r\n\r\n#if defined(POINTLIGHT)||defined(SPOTLIGHT)||(defined(CALCULATE_SHADOWS)&&defined(SHADOW_CASCADE))||defined(CALCULATE_SPOTSHADOWS)\r\n\tvarying vec3 v_PositionWorld;\r\n#endif\r\n\r\n#if defined(CALCULATE_SHADOWS)&&!defined(SHADOW_CASCADE)\r\n\tvarying vec4 v_ShadowCoord;\r\n#endif\r\n\r\n#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\tvarying vec4 v_SpotShadowCoord;\r\n#endif\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\n\r\n\r\nvoid main()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform;\r\n\t \t#ifdef SIMPLEBONE\r\n\t\t\tfloat currentPixelPos;\r\n\t\t\t#ifdef GPU_INSTANCE\r\n\t\t\t\tcurrentPixelPos = a_SimpleTextureParams.x+a_SimpleTextureParams.y;\r\n\t\t\t#else\r\n\t\t\t\tcurrentPixelPos = u_SimpleAnimatorParams.x+u_SimpleAnimatorParams.y;\r\n\t\t\t#endif\r\n\t\t\tfloat offset = 1.0/u_SimpleAnimatorTextureSize;\r\n\t\t\tskinTransform = loadMatFromTexture(currentPixelPos,int(a_BoneIndices.x),offset) * a_BoneWeights.x;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.y),offset) * a_BoneWeights.y;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.z),offset) * a_BoneWeights.z;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.w),offset) * a_BoneWeights.w;\r\n\t\t#else\r\n\t\t\tskinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\t#endif\r\n\t\tposition=skinTransform*a_Position;\r\n\t #else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\t\r\n\tmat4 worldMat;\r\n\t#ifdef GPU_INSTANCE\r\n\t\tworldMat = a_WorldMat;\r\n\t#else\r\n\t\tworldMat = u_WorldMat;\r\n\t#endif\r\n\r\n\tmat3 worldInvMat;\r\n\t#ifdef BONE\r\n\t\tworldInvMat=INVERSE_MAT(mat3(worldMat*skinTransform));\r\n\t#else\r\n\t\tworldInvMat=INVERSE_MAT(mat3(worldMat));\r\n\t#endif \r\n\tv_Normal=normalize(a_Normal*worldInvMat);\r\n\t#if defined(NORMALMAP)\r\n\t\tv_Tangent=normalize(a_Tangent0.xyz*worldInvMat);\r\n\t\tv_Binormal=cross(v_Normal,v_Tangent)*a_Tangent0.w;\r\n\t#endif\r\n\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||(defined(CALCULATE_SHADOWS)&&defined(SHADOW_CASCADE))||defined(CALCULATE_SPOTSHADOWS)\r\n\t\tvec3 positionWS=(worldMat*position).xyz;\r\n\t\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\t\tv_ViewDir = u_CameraPos-positionWS;\r\n\t\t#endif\r\n\t\t#if defined(POINTLIGHT)||defined(SPOTLIGHT)||(defined(CALCULATE_SHADOWS)&&defined(SHADOW_CASCADE))||defined(CALCULATE_SPOTSHADOWS)\r\n\t\t\tv_PositionWorld = positionWS;\r\n\t\t#endif\r\n\t#endif\r\n\r\n\t#if defined(DIFFUSEMAP)||((defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&(defined(SPECULARMAP)||defined(NORMALMAP)))\r\n\t\t#ifdef TILINGOFFSET\r\n\t\t\tv_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\r\n\t\t#else\r\n\t\t\tv_Texcoord0=a_Texcoord0;\r\n\t\t#endif\r\n\t#endif\r\n\r\n\t#ifdef LIGHTMAP\r\n\t\t#ifdef UV1\r\n\t\t\tv_LightMapUV=vec2(a_Texcoord1.x,1.0-a_Texcoord1.y)*u_LightmapScaleOffset.xy+u_LightmapScaleOffset.zw;\r\n\t\t#else\r\n\t\t\tv_LightMapUV=vec2(a_Texcoord0.x,1.0-a_Texcoord0.y)*u_LightmapScaleOffset.xy+u_LightmapScaleOffset.zw;\r\n\t\t#endif \r\n\t\tv_LightMapUV.y=1.0-v_LightMapUV.y;\r\n\t#endif\r\n\r\n\t#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\t\tv_Color=a_Color;\r\n\t#endif\r\n\r\n\t#if defined(CALCULATE_SHADOWS)&&!defined(SHADOW_CASCADE)\r\n\t\tv_ShadowCoord =getShadowCoord(vec4(positionWS,1.0));\r\n\t#endif\r\n\r\n\t#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\tv_SpotShadowCoord = u_SpotViewProjectMatrix*vec4(positionWS,1.0);\r\n\t#endif\r\n\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n\r\n#include "Lighting.glsl";\r\n#include "Shadow.glsl"\r\n\r\nuniform vec4 u_DiffuseColor;\r\n\r\n#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\tvarying vec4 v_Color;\r\n#endif\r\n\r\n#ifdef ALPHATEST\r\n\tuniform float u_AlphaTestValue;\r\n#endif\r\n\r\n#ifdef DIFFUSEMAP\r\n\tuniform sampler2D u_DiffuseTexture;\r\n#endif\r\n\r\n\r\n#if defined(DIFFUSEMAP)||((defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT))&&(defined(SPECULARMAP)||defined(NORMALMAP)))\r\n\tvarying vec2 v_Texcoord0;\r\n#endif\r\n\r\n#ifdef LIGHTMAP\r\n\tvarying vec2 v_LightMapUV;\r\n\tuniform sampler2D u_LightMap;\r\n\t#ifdef LIGHTMAP_DIRECTIONAL\r\n\t\tuniform sampler2D u_LightMapDirection;\r\n\t#endif\r\n#endif\r\n\r\nvarying vec3 v_Normal;\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\tvarying vec3 v_ViewDir; \r\n\r\n\tuniform vec3 u_MaterialSpecular;\r\n\tuniform float u_Shininess;\r\n\r\n\t#ifdef LEGACYSINGLELIGHTING\r\n\t\t#ifdef DIRECTIONLIGHT\r\n\t\t\tuniform DirectionLight u_DirectionLight;\r\n\t\t#endif\r\n\t\t#ifdef POINTLIGHT\r\n\t\t\tuniform PointLight u_PointLight;\r\n\t\t#endif\r\n\t\t#ifdef SPOTLIGHT\r\n\t\t\tuniform SpotLight u_SpotLight;\r\n\t\t#endif\r\n\t#else\r\n\t\tuniform mat4 u_View;\r\n\t\tuniform vec4 u_ProjectionParams;\r\n\t\tuniform vec4 u_Viewport;\r\n\t\tuniform int u_DirationLightCount;\r\n\t\tuniform sampler2D u_LightBuffer;\r\n\t\tuniform sampler2D u_LightClusterBuffer;\r\n\t#endif\r\n\r\n\t#ifdef SPECULARMAP \r\n\t\tuniform sampler2D u_SpecularTexture;\r\n\t#endif\r\n#endif\r\n\r\n#ifdef NORMALMAP \r\n\tuniform sampler2D u_NormalTexture;\r\n\tvarying vec3 v_Tangent;\r\n\tvarying vec3 v_Binormal;\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\tuniform vec3 u_FogColor;\r\n#endif\r\n\r\n#if defined(POINTLIGHT)||defined(SPOTLIGHT)||(defined(CALCULATE_SHADOWS)&&defined(SHADOW_CASCADE))||defined(CALCULATE_SPOTSHADOWS)\r\n\tvarying vec3 v_PositionWorld;\r\n#endif\r\n\r\n\r\n#include "GlobalIllumination.glsl";//"GlobalIllumination.glsl use uniform should at front of this\r\n\r\n#if defined(CALCULATE_SHADOWS)&&!defined(SHADOW_CASCADE)\r\n\tvarying vec4 v_ShadowCoord;\r\n#endif\r\n\r\n#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\tvarying vec4 v_SpotShadowCoord;\r\n#endif\r\n\r\n\r\nvoid main()\r\n{\r\n\tvec3 normal;//light and SH maybe use normal\r\n\t#if defined(NORMALMAP)\r\n\t\tvec3 normalMapSample = texture2D(u_NormalTexture, v_Texcoord0).rgb;\r\n\t\tnormal = normalize(NormalSampleToWorldSpace(normalMapSample, v_Normal, v_Tangent,v_Binormal));\r\n\t#else\r\n\t\tnormal = normalize(v_Normal);\r\n\t#endif\r\n\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tvec3 viewDir= normalize(v_ViewDir);\r\n\t#endif\r\n\r\n\tLayaGIInput giInput;\r\n\t#ifdef LIGHTMAP\t\r\n\t\tgiInput.lightmapUV=v_LightMapUV;\r\n\t#endif\r\n\tvec3 globalDiffuse=layaGIBase(giInput,1.0,normal);\r\n\t\r\n\tvec4 mainColor=u_DiffuseColor;\r\n\t#ifdef DIFFUSEMAP\r\n\t\tvec4 difTexColor=texture2D(u_DiffuseTexture, v_Texcoord0);\r\n\t\tmainColor=mainColor*difTexColor;\r\n\t#endif \r\n\t#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\t\tmainColor=mainColor*v_Color;\r\n\t#endif \r\n \r\n\t#ifdef ALPHATEST\r\n\t\tif(mainColor.a<u_AlphaTestValue)\r\n\t\t\tdiscard;\r\n\t#endif\r\n \r\n\t\r\n\tvec3 diffuse = vec3(0.0);\r\n\tvec3 specular= vec3(0.0);\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tvec3 dif,spe;\r\n\t\t#ifdef SPECULARMAP\r\n\t\t\tvec3 gloss=texture2D(u_SpecularTexture, v_Texcoord0).rgb;\r\n\t\t#else\r\n\t\t\t#ifdef DIFFUSEMAP\r\n\t\t\t\tvec3 gloss=vec3(difTexColor.a);\r\n\t\t\t#else\r\n\t\t\t\tvec3 gloss=vec3(1.0);\r\n\t\t\t#endif\r\n\t\t#endif\r\n\t#endif\r\n\r\n\t\r\n\t\r\n\t#ifdef LEGACYSINGLELIGHTING\r\n\t\t#ifdef DIRECTIONLIGHT\r\n\t\t\tLayaAirBlinnPhongDiectionLight(u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,u_DirectionLight,dif,spe);\r\n\t\t\t#if defined(CALCULATE_SHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\t\t\t#ifdef SHADOW_CASCADE\r\n\t\t\t\t\tvec4 shadowCoord = getShadowCoord(vec4(v_PositionWorld,1.0));\r\n\t\t\t\t#else\r\n\t\t\t\t\tvec4 shadowCoord = v_ShadowCoord;\r\n\t\t\t\t#endif\r\n\t\t\t\tfloat shadowAttenuation=sampleShadowmap(shadowCoord);\r\n\t\t\t\tdif *= shadowAttenuation;\r\n\t\t\t\tspe *= shadowAttenuation;\r\n\t\t\t#endif\r\n\t\t\tdiffuse+=dif;\r\n\t\t\tspecular+=spe;\r\n\t\t#endif\r\n\t\r\n\t\t#ifdef POINTLIGHT\r\n\t\t\tLayaAirBlinnPhongPointLight(v_PositionWorld,u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,u_PointLight,dif,spe);\r\n\t\t\tdiffuse+=dif;\r\n\t\t\tspecular+=spe;\r\n\t\t#endif\r\n\r\n\t\t#ifdef SPOTLIGHT\r\n\t\t\tLayaAirBlinnPhongSpotLight(v_PositionWorld,u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,u_SpotLight,dif,spe);\r\n\t\t\t#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\t\t\tvec4 spotShadowcoord = v_SpotShadowCoord;\r\n\t\t\t\tfloat spotShadowAttenuation = sampleSpotShadowmap(spotShadowcoord);\r\n\t\t\t\tdif *= spotShadowAttenuation;\r\n\t\t\t\tspe *= spotShadowAttenuation;\r\n\t\t\t#endif\r\n\t\t\tdiffuse+=dif;\r\n\t\t\tspecular+=spe;\r\n\t\t#endif\r\n\t#else\r\n\t\t#ifdef DIRECTIONLIGHT\r\n\t\t\tfor (int i = 0; i < MAX_LIGHT_COUNT; i++) \r\n\t\t\t{\r\n\t\t\t\tif(i >= u_DirationLightCount)\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tDirectionLight directionLight = getDirectionLight(u_LightBuffer,i);\r\n\t\t\t\t#if defined(CALCULATE_SHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\t\t\t\tif(i == 0)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t#ifdef SHADOW_CASCADE\r\n\t\t\t\t\t\t\tvec4 shadowCoord = getShadowCoord(vec4(v_PositionWorld,1.0));\r\n\t\t\t\t\t\t#else\r\n\t\t\t\t\t\t\tvec4 shadowCoord = v_ShadowCoord;\r\n\t\t\t\t\t\t#endif\r\n\t\t\t\t\t\tdirectionLight.color *= sampleShadowmap(shadowCoord);\r\n\t\t\t\t\t}\r\n\t\t\t\t#endif\r\n\t\t\t\tLayaAirBlinnPhongDiectionLight(u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,directionLight,dif,spe);\r\n\t\t\t\tdiffuse+=dif;\r\n\t\t\t\tspecular+=spe;\r\n\t\t\t}\r\n\t\t#endif\r\n\t\t#if defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\t\tivec4 clusterInfo =getClusterInfo(u_LightClusterBuffer,u_View,u_Viewport, v_PositionWorld,gl_FragCoord,u_ProjectionParams);\r\n\t\t\t#ifdef POINTLIGHT\r\n\t\t\t\tfor (int i = 0; i < MAX_LIGHT_COUNT; i++) \r\n\t\t\t\t{\r\n\t\t\t\t\tif(i >= clusterInfo.x)//PointLightCount\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tPointLight pointLight = getPointLight(u_LightBuffer,u_LightClusterBuffer,clusterInfo,i);\r\n\t\t\t\t\tLayaAirBlinnPhongPointLight(v_PositionWorld,u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,pointLight,dif,spe);\r\n\t\t\t\t\tdiffuse+=dif;\r\n\t\t\t\t\tspecular+=spe;\r\n\t\t\t\t}\r\n\t\t\t#endif\r\n\t\t\t#ifdef SPOTLIGHT\r\n\t\t\t\tfor (int i = 0; i < MAX_LIGHT_COUNT; i++) \r\n\t\t\t\t{\r\n\t\t\t\t\tif(i >= clusterInfo.y)//SpotLightCount\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tSpotLight spotLight = getSpotLight(u_LightBuffer,u_LightClusterBuffer,clusterInfo,i);\r\n\t\t\t\t\t#if defined(CALCULATE_SPOTSHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\t\t\t\t\tif(i == 0)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tvec4 spotShadowcoord = v_SpotShadowCoord;\r\n\t\t\t\t\t\t\tspotLight.color *= sampleSpotShadowmap(spotShadowcoord);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t#endif\r\n\t\t\t\t\tLayaAirBlinnPhongSpotLight(v_PositionWorld,u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,spotLight,dif,spe);\r\n\t\t\t\t\tdiffuse+=dif;\r\n\t\t\t\t\tspecular+=spe;\r\n\t\t\t\t}\r\n\t\t\t#endif\r\n\t\t#endif\r\n\t#endif\r\n\r\n\tgl_FragColor =vec4(mainColor.rgb*(globalDiffuse + diffuse),mainColor.a);\r\n\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tgl_FragColor.rgb+=specular;\r\n\t#endif\r\n\t \r\n\t#ifdef FOG\r\n\t\tfloat lerpFact=clamp((1.0/gl_FragCoord.w-u_FogStart)/u_FogRange,0.0,1.0);\r\n\t\tgl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\r\n\t#endif\r\n}\r\n\r\n',r,"Forward");a.addShaderPass('#include "ShadowCasterVS.glsl"\r\n\r\nvoid main()\r\n{\r\n\tvec4 positionCS = shadowCasterVertex();\r\n\tgl_Position=remapGLPositionZ(positionCS);\r\n}','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n\tprecision highp int;\r\n#else\r\n\tprecision mediump float;\r\n\tprecision mediump int;\r\n#endif\r\n\r\n#include "ShadowCasterFS.glsl"\r\n\r\nvoid main()\r\n{\r\n\tgl_FragColor=shadowCasterFragment();\r\n}',r,"ShadowCaster");a.addShaderPass(pt,gt,r,"DepthNormal"),e={a_Position:ze.MESH_POSITION0,a_Color:ze.MESH_COLOR0},t={u_MvpMatrix:xe.PERIOD_SPRITE,u_Color:xe.PERIOD_MATERIAL},r={s_Cull:xe.RENDER_STATE_CULL,s_Blend:xe.RENDER_STATE_BLEND,s_BlendSrc:xe.RENDER_STATE_BLEND_SRC,s_BlendDst:xe.RENDER_STATE_BLEND_DST,s_DepthTest:xe.RENDER_STATE_DEPTH_TEST,s_DepthWrite:xe.RENDER_STATE_DEPTH_WRITE},i=xe.add("LineShader"),a=new mr(e,t),i.addSubShader(a),a.addShaderPass('#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\nprecision highp float;\r\n#else\r\nprecision mediump float;\r\n#endif\r\n\r\n#include "Lighting.glsl";\r\n\r\nattribute vec4 a_Position;\r\nuniform mat4 u_MvpMatrix;\r\nuniform vec4 u_Color;\r\nattribute vec4 a_Color;\r\nvarying vec4 v_Color;\r\n\r\n\r\nvoid main()\r\n{\r\n\tgl_Position = u_MvpMatrix * a_Position;\r\n\tv_Color=a_Color*u_Color;\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}',"#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\nprecision highp float;\r\n#else\r\nprecision mediump float;\r\n#endif\r\n\r\nvarying vec4 v_Color;\r\nuniform vec4 u_Color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = v_Color * u_Color; \r\n}\r\n\r\n",r),e={a_Position:ze.MESH_POSITION0,a_Color:ze.MESH_COLOR0,a_Texcoord0:ze.MESH_TEXTURECOORDINATE0,a_BoneWeights:ze.MESH_BLENDWEIGHT0,a_BoneIndices:ze.MESH_BLENDINDICES0,a_MvpMatrix:ze.MESH_MVPMATRIX_ROW0},t={u_Bones:xe.PERIOD_CUSTOM,u_AlbedoTexture:xe.PERIOD_MATERIAL,u_AlbedoColor:xe.PERIOD_MATERIAL,u_TilingOffset:xe.PERIOD_MATERIAL,u_AlphaTestValue:xe.PERIOD_MATERIAL,u_MvpMatrix:xe.PERIOD_SPRITE,u_SimpleAnimatorTexture:xe.PERIOD_SPRITE,u_SimpleAnimatorParams:xe.PERIOD_SPRITE,u_SimpleAnimatorTextureSize:xe.PERIOD_SPRITE,u_FogStart:xe.PERIOD_SCENE,u_FogRange:xe.PERIOD_SCENE,u_FogColor:xe.PERIOD_SCENE},r={s_Cull:xe.RENDER_STATE_CULL,s_Blend:xe.RENDER_STATE_BLEND,s_BlendSrc:xe.RENDER_STATE_BLEND_SRC,s_BlendDst:xe.RENDER_STATE_BLEND_DST,s_DepthTest:xe.RENDER_STATE_DEPTH_TEST,s_DepthWrite:xe.RENDER_STATE_DEPTH_WRITE},i=xe.add("Unlit",null,null,!0),a=new mr(e,t),i.addSubShader(a),a.addShaderPass('#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n#include "Lighting.glsl";\r\n#include "LayaUtile.glsl";\r\n\r\nattribute vec4 a_Position;\r\n\r\nattribute vec2 a_Texcoord0;\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_MvpMatrix;\r\n#else\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\n\r\nattribute vec4 a_Color;\r\nvarying vec4 v_Color;\r\nvarying vec2 v_Texcoord0;\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\nvoid main() {\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform;\r\n\t \t#ifdef SIMPLEBONE\r\n\t\t\tfloat currentPixelPos;\r\n\t\t\t#ifdef GPU_INSTANCE\r\n\t\t\t\tcurrentPixelPos = a_SimpleTextureParams.x+a_SimpleTextureParams.y;\r\n\t\t\t#else\r\n\t\t\t\tcurrentPixelPos = u_SimpleAnimatorParams.x+u_SimpleAnimatorParams.y;\r\n\t\t\t#endif\r\n\t\t\tfloat offset = 1.0/u_SimpleAnimatorTextureSize;\r\n\t\t\tskinTransform = loadMatFromTexture(currentPixelPos,int(a_BoneIndices.x),offset) * a_BoneWeights.x;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.y),offset) * a_BoneWeights.y;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.z),offset) * a_BoneWeights.z;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.w),offset) * a_BoneWeights.w;\r\n\t\t#else\r\n\t\t\tskinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\t#endif\r\n\t\tposition=skinTransform*a_Position;\r\n\t #else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\r\n\t#ifdef TILINGOFFSET\r\n\t\tv_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\r\n\t#else\r\n\t\tv_Texcoord0=a_Texcoord0;\r\n\t#endif\r\n\r\n\t#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\t\tv_Color = a_Color;\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}',"#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\tvarying vec4 v_Color;\r\n#endif\r\n\r\n#ifdef ALBEDOTEXTURE\r\n\tuniform sampler2D u_AlbedoTexture;\r\n\tvarying vec2 v_Texcoord0;\r\n#endif\r\n\r\nuniform vec4 u_AlbedoColor;\r\n\r\n#ifdef ALPHATEST\r\n\tuniform float u_AlphaTestValue;\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\t#ifdef ADDTIVEFOG\r\n\t#else\r\n\t\tuniform vec3 u_FogColor;\r\n\t#endif\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = u_AlbedoColor;\r\n\t#ifdef ALBEDOTEXTURE\r\n\t\tcolor *= texture2D(u_AlbedoTexture, v_Texcoord0);\r\n\t#endif\r\n\t#if defined(COLOR)&&defined(ENABLEVERTEXCOLOR)\r\n\t\tcolor *= v_Color;\r\n\t#endif\r\n\t\r\n\t#ifdef ALPHATEST\r\n\t\tif(color.a < u_AlphaTestValue)\r\n\t\t\tdiscard;\r\n\t#endif\r\n\t\r\n\tgl_FragColor = color;\r\n\t\r\n\t#ifdef FOG\r\n\t\tfloat lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\r\n\t\t#ifdef ADDTIVEFOG\r\n\t\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.0), lerpFact);\r\n\t\t#else\r\n\t\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n}\r\n\r\n",r),e={a_Position:ze.MESH_POSITION0,a_Texcoord0:ze.MESH_TEXTURECOORDINATE0,a_BoneWeights:ze.MESH_BLENDWEIGHT0,a_BoneIndices:ze.MESH_BLENDINDICES0,a_MvpMatrix:ze.MESH_MVPMATRIX_ROW0},t={u_Bones:xe.PERIOD_CUSTOM,u_AlbedoTexture:xe.PERIOD_MATERIAL,u_AlbedoColor:xe.PERIOD_MATERIAL,u_TilingOffset:xe.PERIOD_MATERIAL,u_AlphaTestValue:xe.PERIOD_MATERIAL,u_MvpMatrix:xe.PERIOD_SPRITE,u_SimpleAnimatorTexture:xe.PERIOD_SPRITE,u_SimpleAnimatorParams:xe.PERIOD_SPRITE,u_SimpleAnimatorTextureSize:xe.PERIOD_SPRITE,u_FogStart:xe.PERIOD_SCENE,u_FogRange:xe.PERIOD_SCENE,u_FogColor:xe.PERIOD_SCENE},r={s_Cull:xe.RENDER_STATE_CULL,s_Blend:xe.RENDER_STATE_BLEND,s_BlendSrc:xe.RENDER_STATE_BLEND_SRC,s_BlendDst:xe.RENDER_STATE_BLEND_DST,s_DepthTest:xe.RENDER_STATE_DEPTH_TEST,s_DepthWrite:xe.RENDER_STATE_DEPTH_WRITE},i=xe.add("Effect",null,null,!0),a=new mr(e,t),i.addSubShader(a),a.addShaderPass('#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n#include "Lighting.glsl";\r\n#include "LayaUtile.glsl";\r\n\r\nattribute vec4 a_Position;\r\nattribute vec4 a_Color;\r\nattribute vec2 a_Texcoord0;\r\n\r\n#ifdef GPU_INSTANCE\r\n\tattribute mat4 a_MvpMatrix;\r\n#else\r\n\tuniform mat4 u_MvpMatrix;\r\n#endif\r\n\r\n#ifdef COLOR\r\n\tvarying vec4 v_Color;\r\n#endif\r\nvarying vec2 v_Texcoord0;\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\n#ifdef BONE\r\n\tconst int c_MaxBoneCount = 24;\r\n\tattribute vec4 a_BoneIndices;\r\n\tattribute vec4 a_BoneWeights;\r\n\tuniform mat4 u_Bones[c_MaxBoneCount];\r\n#endif\r\n\r\n\r\nvoid main()\r\n{\r\n\tvec4 position;\r\n\t#ifdef BONE\r\n\t\tmat4 skinTransform;\r\n\t \t#ifdef SIMPLEBONE\r\n\t\t\tfloat currentPixelPos;\r\n\t\t\t#ifdef GPU_INSTANCE\r\n\t\t\t\tcurrentPixelPos = a_SimpleTextureParams.x+a_SimpleTextureParams.y;\r\n\t\t\t#else\r\n\t\t\t\tcurrentPixelPos = u_SimpleAnimatorParams.x+u_SimpleAnimatorParams.y;\r\n\t\t\t#endif\r\n\t\t\tfloat offset = 1.0/u_SimpleAnimatorTextureSize;\r\n\t\t\tskinTransform = loadMatFromTexture(currentPixelPos,int(a_BoneIndices.x),offset) * a_BoneWeights.x;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.y),offset) * a_BoneWeights.y;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.z),offset) * a_BoneWeights.z;\r\n\t\t\tskinTransform += loadMatFromTexture(currentPixelPos,int(a_BoneIndices.w),offset) * a_BoneWeights.w;\r\n\t\t#else\r\n\t\t\tskinTransform = u_Bones[int(a_BoneIndices.x)] * a_BoneWeights.x;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.y)] * a_BoneWeights.y;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.z)] * a_BoneWeights.z;\r\n\t\t\tskinTransform += u_Bones[int(a_BoneIndices.w)] * a_BoneWeights.w;\r\n\t\t#endif\r\n\t\tposition=skinTransform*a_Position;\r\n\t #else\r\n\t\tposition=a_Position;\r\n\t#endif\r\n\t#ifdef GPU_INSTANCE\r\n\t\tgl_Position = a_MvpMatrix * position;\r\n\t#else\r\n\t\tgl_Position = u_MvpMatrix * position;\r\n\t#endif\r\n\t\r\n\t#ifdef TILINGOFFSET\r\n\t\tv_Texcoord0=TransformUV(a_Texcoord0,u_TilingOffset);\r\n\t#else\r\n\t\tv_Texcoord0=a_Texcoord0;\r\n\t#endif\r\n\t\t\r\n\t#ifdef COLOR\r\n\t\tv_Color = a_Color;\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}',"#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#ifdef COLOR\r\n\tvarying vec4 v_Color;\r\n#endif\r\nvarying vec2 v_Texcoord0;\r\n\r\n#ifdef MAINTEXTURE\r\n\tuniform sampler2D u_AlbedoTexture;\r\n#endif\r\n\r\nuniform vec4 u_AlbedoColor;\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\t#ifdef ADDTIVEFOG\r\n\t#else\r\n\t\tuniform vec3 u_FogColor;\r\n\t#endif\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = 2.0 * u_AlbedoColor;\r\n\t#ifdef COLOR\r\n\t\tcolor *= v_Color;\r\n\t#endif\r\n\t#ifdef MAINTEXTURE\r\n\t\tcolor *= texture2D(u_AlbedoTexture, v_Texcoord0);\r\n\t#endif\r\n\t\r\n\tgl_FragColor = color;\r\n\t\r\n\t#ifdef FOG\r\n\t\tfloat lerpFact = clamp((1.0 / gl_FragCoord.w - u_FogStart) / u_FogRange, 0.0, 1.0);\r\n\t\t#ifdef ADDTIVEFOG\r\n\t\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.0), lerpFact);\r\n\t\t#else\r\n\t\t\tgl_FragColor.rgb = mix(gl_FragColor.rgb, u_FogColor, lerpFact);\r\n\t\t#endif\r\n\t#endif\r\n}\r\n\r\n",r),e={a_CornerTextureCoordinate:ri.PARTICLE_CORNERTEXTURECOORDINATE0,a_MeshPosition:ri.PARTICLE_POSITION0,a_MeshColor:ri.PARTICLE_COLOR0,a_MeshTextureCoordinate:ri.PARTICLE_TEXTURECOORDINATE0,a_ShapePositionStartLifeTime:ri.PARTICLE_SHAPEPOSITIONSTARTLIFETIME,a_DirectionTime:ri.PARTICLE_DIRECTIONTIME,a_StartColor:ri.PARTICLE_STARTCOLOR0,a_EndColor:ri.PARTICLE_ENDCOLOR0,a_StartSize:ri.PARTICLE_STARTSIZE,a_StartRotation0:ri.PARTICLE_STARTROTATION,a_StartSpeed:ri.PARTICLE_STARTSPEED,a_Random0:ri.PARTICLE_RANDOM0,a_Random1:ri.PARTICLE_RANDOM1,a_SimulationWorldPostion:ri.PARTICLE_SIMULATIONWORLDPOSTION,a_SimulationWorldRotation:ri.PARTICLE_SIMULATIONWORLDROTATION},t={u_Tintcolor:xe.PERIOD_MATERIAL,u_TilingOffset:xe.PERIOD_MATERIAL,u_texture:xe.PERIOD_MATERIAL,u_WorldPosition:xe.PERIOD_SPRITE,u_WorldRotation:xe.PERIOD_SPRITE,u_PositionScale:xe.PERIOD_SPRITE,u_SizeScale:xe.PERIOD_SPRITE,u_ScalingMode:xe.PERIOD_SPRITE,u_Gravity:xe.PERIOD_SPRITE,u_ThreeDStartRotation:xe.PERIOD_SPRITE,u_StretchedBillboardLengthScale:xe.PERIOD_SPRITE,u_StretchedBillboardSpeedScale:xe.PERIOD_SPRITE,u_SimulationSpace:xe.PERIOD_SPRITE,u_CurrentTime:xe.PERIOD_SPRITE,u_ColorOverLifeGradientAlphas:xe.PERIOD_SPRITE,u_ColorOverLifeGradientColors:xe.PERIOD_SPRITE,u_MaxColorOverLifeGradientAlphas:xe.PERIOD_SPRITE,u_MaxColorOverLifeGradientColors:xe.PERIOD_SPRITE,u_VOLVelocityConst:xe.PERIOD_SPRITE,u_VOLVelocityGradientX:xe.PERIOD_SPRITE,u_VOLVelocityGradientY:xe.PERIOD_SPRITE,u_VOLVelocityGradientZ:xe.PERIOD_SPRITE,u_VOLVelocityConstMax:xe.PERIOD_SPRITE,u_VOLVelocityGradientMaxX:xe.PERIOD_SPRITE,u_VOLVelocityGradientMaxY:xe.PERIOD_SPRITE,u_VOLVelocityGradientMaxZ:xe.PERIOD_SPRITE,u_VOLSpaceType:xe.PERIOD_SPRITE,u_SOLSizeGradient:xe.PERIOD_SPRITE,u_SOLSizeGradientX:xe.PERIOD_SPRITE,u_SOLSizeGradientY:xe.PERIOD_SPRITE,u_SOLSizeGradientZ:xe.PERIOD_SPRITE,u_SOLSizeGradientMax:xe.PERIOD_SPRITE,u_SOLSizeGradientMaxX:xe.PERIOD_SPRITE,u_SOLSizeGradientMaxY:xe.PERIOD_SPRITE,u_SOLSizeGradientMaxZ:xe.PERIOD_SPRITE,u_ROLAngularVelocityConst:xe.PERIOD_SPRITE,u_ROLAngularVelocityConstSeprarate:xe.PERIOD_SPRITE,u_ROLAngularVelocityGradient:xe.PERIOD_SPRITE,u_ROLAngularVelocityGradientX:xe.PERIOD_SPRITE,u_ROLAngularVelocityGradientY:xe.PERIOD_SPRITE,u_ROLAngularVelocityGradientZ:xe.PERIOD_SPRITE,u_ROLAngularVelocityConstMax:xe.PERIOD_SPRITE,u_ROLAngularVelocityConstMaxSeprarate:xe.PERIOD_SPRITE,u_ROLAngularVelocityGradientMax:xe.PERIOD_SPRITE,u_ROLAngularVelocityGradientMaxX:xe.PERIOD_SPRITE,u_ROLAngularVelocityGradientMaxY:xe.PERIOD_SPRITE,u_ROLAngularVelocityGradientMaxZ:xe.PERIOD_SPRITE,u_ROLAngularVelocityGradientMaxW:xe.PERIOD_SPRITE,u_TSACycles:xe.PERIOD_SPRITE,u_TSASubUVLength:xe.PERIOD_SPRITE,u_TSAGradientUVs:xe.PERIOD_SPRITE,u_TSAMaxGradientUVs:xe.PERIOD_SPRITE,u_CameraPos:xe.PERIOD_CAMERA,u_CameraDirection:xe.PERIOD_CAMERA,u_CameraUp:xe.PERIOD_CAMERA,u_View:xe.PERIOD_CAMERA,u_Projection:xe.PERIOD_CAMERA,u_FogStart:xe.PERIOD_SCENE,u_FogRange:xe.PERIOD_SCENE,u_FogColor:xe.PERIOD_SCENE},r={s_Cull:xe.RENDER_STATE_CULL,s_Blend:xe.RENDER_STATE_BLEND,s_BlendSrc:xe.RENDER_STATE_BLEND_SRC,s_BlendDst:xe.RENDER_STATE_BLEND_DST,s_DepthTest:xe.RENDER_STATE_DEPTH_TEST,s_DepthWrite:xe.RENDER_STATE_DEPTH_WRITE},i=xe.add("PARTICLESHURIKEN"),a=new mr(e,t),i.addSubShader(a),a.addShaderPass('// #include "Lighting.glsl";\r\n\r\n//修改这里剔除没有用到的光照函数,增加粒子的编译速度\r\nvec2 TransformUV(vec2 texcoord,vec4 tilingOffset) {\r\n\tvec2 transTexcoord=vec2(texcoord.x,texcoord.y-1.0)*tilingOffset.xy+vec2(tilingOffset.z,-tilingOffset.w);\r\n\ttransTexcoord.y+=1.0;\r\n\treturn transTexcoord;\r\n}\r\n\r\nvec4 remapGLPositionZ(vec4 position) {\r\n\tposition.z=position.z * 2.0 - position.w;\r\n\treturn position;\r\n}\r\n\r\n#if defined(GL_FRAGMENT_PRECISION_HIGH)\r\n precision highp float;\r\n#else\r\n precision mediump float;\r\n#endif\r\n\r\n#if defined(SPHERHBILLBOARD)||defined(STRETCHEDBILLBOARD)||defined(HORIZONTALBILLBOARD)||defined(VERTICALBILLBOARD)\r\n\tattribute vec4 a_CornerTextureCoordinate;\r\n#endif\r\n#ifdef RENDERMODE_MESH\r\n\tattribute vec3 a_MeshPosition;\r\n\tattribute vec4 a_MeshColor;\r\n\tattribute vec2 a_MeshTextureCoordinate;\r\n\tvarying vec4 v_MeshColor;\r\n#endif\r\n\r\nattribute vec4 a_ShapePositionStartLifeTime;\r\nattribute vec4 a_DirectionTime;\r\nattribute vec4 a_StartColor;\r\nattribute vec3 a_StartSize;\r\nattribute vec3 a_StartRotation0;\r\nattribute float a_StartSpeed;\r\n#if defined(COLOROVERLIFETIME)||defined(RANDOMCOLOROVERLIFETIME)||defined(SIZEOVERLIFETIMERANDOMCURVES)||defined(SIZEOVERLIFETIMERANDOMCURVESSEPERATE)||defined(ROTATIONOVERLIFETIMERANDOMCONSTANTS)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\r\n attribute vec4 a_Random0;\r\n#endif\r\n#if defined(TEXTURESHEETANIMATIONRANDOMCURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n attribute vec4 a_Random1;\r\n#endif\r\nattribute vec3 a_SimulationWorldPostion;\r\nattribute vec4 a_SimulationWorldRotation;\r\n\r\nvarying vec4 v_Color;\r\n#ifdef DIFFUSEMAP\r\n\tvarying vec2 v_TextureCoordinate;\r\n#endif\r\n\r\nuniform float u_CurrentTime;\r\nuniform vec3 u_Gravity;\r\n\r\nuniform vec3 u_WorldPosition;\r\nuniform vec4 u_WorldRotation;\r\nuniform bool u_ThreeDStartRotation;\r\nuniform int u_ScalingMode;\r\nuniform vec3 u_PositionScale;\r\nuniform vec3 u_SizeScale;\r\nuniform mat4 u_View;\r\nuniform mat4 u_Projection;\r\n\r\n#ifdef STRETCHEDBILLBOARD\r\n\tuniform vec3 u_CameraPos;\r\n#endif\r\nuniform vec3 u_CameraDirection;//TODO:只有几种广告牌模式需要用\r\nuniform vec3 u_CameraUp;\r\n\r\nuniform float u_StretchedBillboardLengthScale;\r\nuniform float u_StretchedBillboardSpeedScale;\r\nuniform int u_SimulationSpace;\r\n\r\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n uniform int u_VOLSpaceType;\r\n#endif\r\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)\r\n uniform vec3 u_VOLVelocityConst;\r\n#endif\r\n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n uniform vec2 u_VOLVelocityGradientX[4];//x为key,y为速度\r\n uniform vec2 u_VOLVelocityGradientY[4];//x为key,y为速度\r\n uniform vec2 u_VOLVelocityGradientZ[4];//x为key,y为速度\r\n#endif\r\n#ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\r\n uniform vec3 u_VOLVelocityConstMax;\r\n#endif\r\n#ifdef VELOCITYOVERLIFETIMERANDOMCURVE\r\n uniform vec2 u_VOLVelocityGradientMaxX[4];//x为key,y为速度\r\n uniform vec2 u_VOLVelocityGradientMaxY[4];//x为key,y为速度\r\n uniform vec2 u_VOLVelocityGradientMaxZ[4];//x为key,y为速度\r\n#endif\r\n\r\n#ifdef COLOROVERLIFETIME\r\n uniform vec4 u_ColorOverLifeGradientColors[4];//x为key,yzw为Color\r\n uniform vec2 u_ColorOverLifeGradientAlphas[4];//x为key,y为Alpha\r\n#endif\r\n#ifdef RANDOMCOLOROVERLIFETIME\r\n uniform vec4 u_ColorOverLifeGradientColors[4];//x为key,yzw为Color\r\n uniform vec2 u_ColorOverLifeGradientAlphas[4];//x为key,y为Alpha\r\n uniform vec4 u_MaxColorOverLifeGradientColors[4];//x为key,yzw为Color\r\n uniform vec2 u_MaxColorOverLifeGradientAlphas[4];//x为key,y为Alpha\r\n#endif\r\n\r\n\r\n#if defined(SIZEOVERLIFETIMECURVE)||defined(SIZEOVERLIFETIMERANDOMCURVES)\r\n uniform vec2 u_SOLSizeGradient[4];//x为key,y为尺寸\r\n#endif\r\n#ifdef SIZEOVERLIFETIMERANDOMCURVES\r\n uniform vec2 u_SOLSizeGradientMax[4];//x为key,y为尺寸\r\n#endif\r\n#if defined(SIZEOVERLIFETIMECURVESEPERATE)||defined(SIZEOVERLIFETIMERANDOMCURVESSEPERATE)\r\n uniform vec2 u_SOLSizeGradientX[4];//x为key,y为尺寸\r\n uniform vec2 u_SOLSizeGradientY[4];//x为key,y为尺寸\r\n uniform vec2 u_SOLSizeGradientZ[4];//x为key,y为尺寸\r\n#endif\r\n#ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\r\n uniform vec2 u_SOLSizeGradientMaxX[4];//x为key,y为尺寸\r\n uniform vec2 u_SOLSizeGradientMaxY[4];//x为key,y为尺寸\r\n uniform vec2 u_SOLSizeGradientMaxZ[4];//x为key,y为尺寸\r\n#endif\r\n\r\n\r\n#ifdef ROTATIONOVERLIFETIME\r\n #if defined(ROTATIONOVERLIFETIMECONSTANT)||defined(ROTATIONOVERLIFETIMERANDOMCONSTANTS)\r\n uniform float u_ROLAngularVelocityConst;\r\n #endif\r\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n uniform float u_ROLAngularVelocityConstMax;\r\n #endif\r\n #if defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\r\n uniform vec2 u_ROLAngularVelocityGradient[4];//x为key,y为旋转\r\n #endif\r\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n uniform vec2 u_ROLAngularVelocityGradientMax[4];//x为key,y为旋转\r\n #endif\r\n#endif\r\n#ifdef ROTATIONOVERLIFETIMESEPERATE\r\n #if defined(ROTATIONOVERLIFETIMECONSTANT)||defined(ROTATIONOVERLIFETIMERANDOMCONSTANTS)\r\n uniform vec3 u_ROLAngularVelocityConstSeprarate;\r\n #endif\r\n #ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n uniform vec3 u_ROLAngularVelocityConstMaxSeprarate;\r\n #endif\r\n #if defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\r\n uniform vec2 u_ROLAngularVelocityGradientX[4];\r\n uniform vec2 u_ROLAngularVelocityGradientY[4];\r\n uniform vec2 u_ROLAngularVelocityGradientZ[4];\r\n #endif\r\n #ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n uniform vec2 u_ROLAngularVelocityGradientMaxX[4];\r\n uniform vec2 u_ROLAngularVelocityGradientMaxY[4];\r\n uniform vec2 u_ROLAngularVelocityGradientMaxZ[4];\r\n\tuniform vec2 u_ROLAngularVelocityGradientMaxW[4];\r\n #endif\r\n#endif\r\n\r\n#if defined(TEXTURESHEETANIMATIONCURVE)||defined(TEXTURESHEETANIMATIONRANDOMCURVE)\r\n uniform float u_TSACycles;\r\n uniform vec2 u_TSASubUVLength;\r\n uniform vec2 u_TSAGradientUVs[4];//x为key,y为frame\r\n#endif\r\n#ifdef TEXTURESHEETANIMATIONRANDOMCURVE\r\n uniform vec2 u_TSAMaxGradientUVs[4];//x为key,y为frame\r\n#endif\r\n\r\n#ifdef TILINGOFFSET\r\n\tuniform vec4 u_TilingOffset;\r\n#endif\r\n\r\nvec3 rotationByEuler(in vec3 vector,in vec3 rot)\r\n{\r\n\tfloat halfRoll = rot.z * 0.5;\r\n float halfPitch = rot.x * 0.5;\r\n\tfloat halfYaw = rot.y * 0.5;\r\n\r\n\tfloat sinRoll = sin(halfRoll);\r\n\tfloat cosRoll = cos(halfRoll);\r\n\tfloat sinPitch = sin(halfPitch);\r\n\tfloat cosPitch = cos(halfPitch);\r\n\tfloat sinYaw = sin(halfYaw);\r\n\tfloat cosYaw = cos(halfYaw);\r\n\r\n\tfloat quaX = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);\r\n\tfloat quaY = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);\r\n\tfloat quaZ = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);\r\n\tfloat quaW = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll);\r\n\t\r\n\t//vec4 q=vec4(quaX,quaY,quaZ,quaW);\r\n\t//vec3 temp = cross(q.xyz, vector) + q.w * vector;\r\n\t//return (cross(temp, -q.xyz) + dot(q.xyz,vector) * q.xyz + q.w * temp);\r\n\t\r\n\tfloat x = quaX + quaX;\r\n float y = quaY + quaY;\r\n float z = quaZ + quaZ;\r\n float wx = quaW * x;\r\n float wy = quaW * y;\r\n float wz = quaW * z;\r\n\tfloat xx = quaX * x;\r\n float xy = quaX * y;\r\n\tfloat xz = quaX * z;\r\n float yy = quaY * y;\r\n float yz = quaY * z;\r\n float zz = quaZ * z;\r\n\r\n return vec3(((vector.x * ((1.0 - yy) - zz)) + (vector.y * (xy - wz))) + (vector.z * (xz + wy)),\r\n ((vector.x * (xy + wz)) + (vector.y * ((1.0 - xx) - zz))) + (vector.z * (yz - wx)),\r\n ((vector.x * (xz - wy)) + (vector.y * (yz + wx))) + (vector.z * ((1.0 - xx) - yy)));\r\n\t\r\n}\r\n\r\n//假定axis已经归一化\r\nvec3 rotationByAxis(in vec3 vector,in vec3 axis, in float angle)\r\n{\r\n\tfloat halfAngle = angle * 0.5;\r\n\tfloat sin = sin(halfAngle);\r\n\t\r\n\tfloat quaX = axis.x * sin;\r\n\tfloat quaY = axis.y * sin;\r\n\tfloat quaZ = axis.z * sin;\r\n\tfloat quaW = cos(halfAngle);\r\n\t\r\n\t//vec4 q=vec4(quaX,quaY,quaZ,quaW);\r\n\t//vec3 temp = cross(q.xyz, vector) + q.w * vector;\r\n\t//return (cross(temp, -q.xyz) + dot(q.xyz,vector) * q.xyz + q.w * temp);\r\n\t\r\n\tfloat x = quaX + quaX;\r\n float y = quaY + quaY;\r\n float z = quaZ + quaZ;\r\n float wx = quaW * x;\r\n float wy = quaW * y;\r\n float wz = quaW * z;\r\n\tfloat xx = quaX * x;\r\n float xy = quaX * y;\r\n\tfloat xz = quaX * z;\r\n float yy = quaY * y;\r\n float yz = quaY * z;\r\n float zz = quaZ * z;\r\n\r\n return vec3(((vector.x * ((1.0 - yy) - zz)) + (vector.y * (xy - wz))) + (vector.z * (xz + wy)),\r\n ((vector.x * (xy + wz)) + (vector.y * ((1.0 - xx) - zz))) + (vector.z * (yz - wx)),\r\n ((vector.x * (xz - wy)) + (vector.y * (yz + wx))) + (vector.z * ((1.0 - xx) - yy)));\r\n\t\r\n}\r\n\r\nvec3 rotationByQuaternions(in vec3 v,in vec4 q) \r\n{\r\n\treturn v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);\r\n}\r\n\r\n \r\n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)||defined(SIZEOVERLIFETIMECURVE)||defined(SIZEOVERLIFETIMECURVESEPERATE)||defined(SIZEOVERLIFETIMERANDOMCURVES)||defined(SIZEOVERLIFETIMERANDOMCURVESSEPERATE)\r\nfloat getCurValueFromGradientFloat(in vec2 gradientNumbers[4],in float normalizedAge)\r\n{\r\n\tfloat curValue;\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec2 gradientNumber=gradientNumbers[i];\r\n\t\tfloat key=gradientNumber.x;\r\n\t\tif(key>=normalizedAge)\r\n\t\t{\r\n\t\t\tvec2 lastGradientNumber=gradientNumbers[i-1];\r\n\t\t\tfloat lastKey=lastGradientNumber.x;\r\n\t\t\tfloat age=(normalizedAge-lastKey)/(key-lastKey);\r\n\t\t\tcurValue=mix(lastGradientNumber.y,gradientNumber.y,age);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn curValue;\r\n}\r\n#endif\r\n\r\n#if defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)||defined(ROTATIONOVERLIFETIMECURVE)||defined(ROTATIONOVERLIFETIMERANDOMCURVES)\r\nfloat getTotalValueFromGradientFloat(in vec2 gradientNumbers[4],in float normalizedAge)\r\n{\r\n\tfloat totalValue=0.0;\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec2 gradientNumber=gradientNumbers[i];\r\n\t\tfloat key=gradientNumber.x;\r\n\t\tvec2 lastGradientNumber=gradientNumbers[i-1];\r\n\t\tfloat lastValue=lastGradientNumber.y;\r\n\t\t\r\n\t\tif(key>=normalizedAge){\r\n\t\t\tfloat lastKey=lastGradientNumber.x;\r\n\t\t\tfloat age=(normalizedAge-lastKey)/(key-lastKey);\r\n\t\t\ttotalValue+=(lastValue+mix(lastValue,gradientNumber.y,age))/2.0*a_ShapePositionStartLifeTime.w*(normalizedAge-lastKey);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t\telse{\r\n\t\t\ttotalValue+=(lastValue+gradientNumber.y)/2.0*a_ShapePositionStartLifeTime.w*(key-lastGradientNumber.x);\r\n\t\t}\r\n\t}\r\n\treturn totalValue;\r\n}\r\n#endif\r\n\r\n#if defined(COLOROVERLIFETIME)||defined(RANDOMCOLOROVERLIFETIME)\r\nvec4 getColorFromGradient(in vec2 gradientAlphas[4],in vec4 gradientColors[4],in float normalizedAge)\r\n{\r\n\tvec4 overTimeColor;\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec2 gradientAlpha=gradientAlphas[i];\r\n\t\tfloat alphaKey=gradientAlpha.x;\r\n\t\tif(alphaKey>=normalizedAge)\r\n\t\t{\r\n\t\t\tvec2 lastGradientAlpha=gradientAlphas[i-1];\r\n\t\t\tfloat lastAlphaKey=lastGradientAlpha.x;\r\n\t\t\tfloat age=(normalizedAge-lastAlphaKey)/(alphaKey-lastAlphaKey);\r\n\t\t\toverTimeColor.a=mix(lastGradientAlpha.y,gradientAlpha.y,age);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\t\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec4 gradientColor=gradientColors[i];\r\n\t\tfloat colorKey=gradientColor.x;\r\n\t\tif(colorKey>=normalizedAge)\r\n\t\t{\r\n\t\t\tvec4 lastGradientColor=gradientColors[i-1];\r\n\t\t\tfloat lastColorKey=lastGradientColor.x;\r\n\t\t\tfloat age=(normalizedAge-lastColorKey)/(colorKey-lastColorKey);\r\n\t\t\toverTimeColor.rgb=mix(gradientColors[i-1].yzw,gradientColor.yzw,age);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn overTimeColor;\r\n}\r\n#endif\r\n\r\n\r\n#if defined(TEXTURESHEETANIMATIONCURVE)||defined(TEXTURESHEETANIMATIONRANDOMCURVE)\r\nfloat getFrameFromGradient(in vec2 gradientFrames[4],in float normalizedAge)\r\n{\r\n\tfloat overTimeFrame;\r\n\tfor(int i=1;i<4;i++)\r\n\t{\r\n\t\tvec2 gradientFrame=gradientFrames[i];\r\n\t\tfloat key=gradientFrame.x;\r\n\t\tif(key>=normalizedAge)\r\n\t\t{\r\n\t\t\tvec2 lastGradientFrame=gradientFrames[i-1];\r\n\t\t\tfloat lastKey=lastGradientFrame.x;\r\n\t\t\tfloat age=(normalizedAge-lastKey)/(key-lastKey);\r\n\t\t\toverTimeFrame=mix(lastGradientFrame.y,gradientFrame.y,age);\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn floor(overTimeFrame);\r\n}\r\n#endif\r\n\r\n#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\nvec3 computeParticleLifeVelocity(in float normalizedAge)\r\n{\r\n vec3 outLifeVelocity;\r\n #ifdef VELOCITYOVERLIFETIMECONSTANT\r\n\t outLifeVelocity=u_VOLVelocityConst; \r\n #endif\r\n #ifdef VELOCITYOVERLIFETIMECURVE\r\n outLifeVelocity= vec3(getCurValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge));\r\n #endif\r\n #ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\r\n\t outLifeVelocity=mix(u_VOLVelocityConst,u_VOLVelocityConstMax,vec3(a_Random1.y,a_Random1.z,a_Random1.w)); \r\n #endif\r\n #ifdef VELOCITYOVERLIFETIMERANDOMCURVE\r\n outLifeVelocity=vec3(mix(getCurValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxX,normalizedAge),a_Random1.y),\r\n\t mix(getCurValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxY,normalizedAge),a_Random1.z),\r\n\t\t\t\t\t mix(getCurValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge),getCurValueFromGradientFloat(u_VOLVelocityGradientMaxZ,normalizedAge),a_Random1.w));\r\n #endif\r\n\t\t\t\t\t\r\n return outLifeVelocity;\r\n} \r\n#endif\r\n\r\nvec3 computeParticlePosition(in vec3 startVelocity, in vec3 lifeVelocity,in float age,in float normalizedAge,vec3 gravityVelocity,vec4 worldRotation)\r\n{\r\n vec3 startPosition;\r\n vec3 lifePosition;\r\n #if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n\t#ifdef VELOCITYOVERLIFETIMECONSTANT\r\n\t\t startPosition=startVelocity*age;\r\n\t\t lifePosition=lifeVelocity*age;\r\n\t#endif\r\n\t#ifdef VELOCITYOVERLIFETIMECURVE\r\n\t\t startPosition=startVelocity*age;\r\n\t\t lifePosition=vec3(getTotalValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge));\r\n\t#endif\r\n\t#ifdef VELOCITYOVERLIFETIMERANDOMCONSTANT\r\n\t\t startPosition=startVelocity*age;\r\n\t\t lifePosition=lifeVelocity*age;\r\n\t#endif\r\n\t#ifdef VELOCITYOVERLIFETIMERANDOMCURVE\r\n\t\t startPosition=startVelocity*age;\r\n\t\t lifePosition=vec3(mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxX,normalizedAge),a_Random1.y)\r\n\t ,mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxY,normalizedAge),a_Random1.z)\r\n\t ,mix(getTotalValueFromGradientFloat(u_VOLVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_VOLVelocityGradientMaxZ,normalizedAge),a_Random1.w));\r\n\t#endif\r\n\t\r\n\tvec3 finalPosition;\r\n\tif(u_VOLSpaceType==0){\r\n\t if(u_ScalingMode!=2)\r\n\t finalPosition =rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition+lifePosition),worldRotation);\r\n\t else\r\n\t finalPosition =rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition+lifePosition,worldRotation);\r\n\t}\r\n\telse{\r\n\t if(u_ScalingMode!=2)\r\n\t finalPosition = rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition),worldRotation)+lifePosition;\r\n\t else\r\n\t finalPosition = rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation)+lifePosition;\r\n\t}\r\n #else\r\n\t startPosition=startVelocity*age;\r\n\t vec3 finalPosition;\r\n\t if(u_ScalingMode!=2)\r\n\t\t\tfinalPosition = rotationByQuaternions(u_PositionScale*(a_ShapePositionStartLifeTime.xyz+startPosition),worldRotation);\r\n\t else\r\n\t \tfinalPosition = rotationByQuaternions(u_PositionScale*a_ShapePositionStartLifeTime.xyz+startPosition,worldRotation);\r\n #endif\r\n \r\n if(u_SimulationSpace==0)\r\n finalPosition=finalPosition+a_SimulationWorldPostion;\r\n else if(u_SimulationSpace==1) \r\n finalPosition=finalPosition+u_WorldPosition;\r\n \r\n finalPosition+=0.5*gravityVelocity*age;\r\n \r\n return finalPosition;\r\n}\r\n\r\n\r\nvec4 computeParticleColor(in vec4 color,in float normalizedAge)\r\n{\r\n\t#ifdef COLOROVERLIFETIME\r\n\t color*=getColorFromGradient(u_ColorOverLifeGradientAlphas,u_ColorOverLifeGradientColors,normalizedAge);\r\n\t#endif\r\n\t\r\n\t#ifdef RANDOMCOLOROVERLIFETIME\r\n\t color*=mix(getColorFromGradient(u_ColorOverLifeGradientAlphas,u_ColorOverLifeGradientColors,normalizedAge),getColorFromGradient(u_MaxColorOverLifeGradientAlphas,u_MaxColorOverLifeGradientColors,normalizedAge),a_Random0.y);\r\n\t#endif\r\n\r\n return color;\r\n}\r\n\r\nvec2 computeParticleSizeBillbard(in vec2 size,in float normalizedAge)\r\n{\r\n\t#ifdef SIZEOVERLIFETIMECURVE\r\n\t\tsize*=getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge);\r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVES\r\n\t size*=mix(getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMax,normalizedAge),a_Random0.z); \r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMECURVESEPERATE\r\n\t\tsize*=vec2(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge));\r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\r\n\t size*=vec2(mix(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxX,normalizedAge),a_Random0.z)\r\n\t ,mix(getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxY,normalizedAge),a_Random0.z));\r\n\t#endif\r\n\treturn size;\r\n}\r\n\r\n#ifdef RENDERMODE_MESH\r\nvec3 computeParticleSizeMesh(in vec3 size,in float normalizedAge)\r\n{\r\n\t#ifdef SIZEOVERLIFETIMECURVE\r\n\t\tsize*=getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge);\r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVES\r\n\t size*=mix(getCurValueFromGradientFloat(u_SOLSizeGradient,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMax,normalizedAge),a_Random0.z); \r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMECURVESEPERATE\r\n\t\tsize*=vec3(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientZ,normalizedAge));\r\n\t#endif\r\n\t#ifdef SIZEOVERLIFETIMERANDOMCURVESSEPERATE\r\n\t size*=vec3(mix(getCurValueFromGradientFloat(u_SOLSizeGradientX,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxX,normalizedAge),a_Random0.z)\r\n\t ,mix(getCurValueFromGradientFloat(u_SOLSizeGradientY,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxY,normalizedAge),a_Random0.z)\r\n\t\t,mix(getCurValueFromGradientFloat(u_SOLSizeGradientZ,normalizedAge),getCurValueFromGradientFloat(u_SOLSizeGradientMaxZ,normalizedAge),a_Random0.z));\r\n\t#endif\r\n\treturn size;\r\n}\r\n#endif\r\n\r\nfloat computeParticleRotationFloat(in float rotation,in float age,in float normalizedAge)\r\n{ \r\n\t#ifdef ROTATIONOVERLIFETIME\r\n\t\t#ifdef ROTATIONOVERLIFETIMECONSTANT\r\n\t\t\tfloat ageRot=u_ROLAngularVelocityConst*age;\r\n\t rotation+=ageRot;\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\r\n\t\t\trotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge);\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n\t\t\tfloat ageRot=mix(u_ROLAngularVelocityConst,u_ROLAngularVelocityConstMax,a_Random0.w)*age;\r\n\t rotation+=ageRot;\r\n\t #endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n\t\t\trotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,normalizedAge),a_Random0.w);\r\n\t\t#endif\r\n\t#endif\r\n\t#ifdef ROTATIONOVERLIFETIMESEPERATE\r\n\t\t#ifdef ROTATIONOVERLIFETIMECONSTANT\r\n\t\t\tfloat ageRot=u_ROLAngularVelocityConstSeprarate.z*age;\r\n\t rotation+=ageRot;\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\r\n\t\t\trotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge);\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n\t\t\tfloat ageRot=mix(u_ROLAngularVelocityConstSeprarate.z,u_ROLAngularVelocityConstMaxSeprarate.z,a_Random0.w)*age;\r\n\t rotation+=ageRot;\r\n\t #endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n\t\t\trotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxZ,normalizedAge),a_Random0.w));\r\n\t\t#endif\r\n\t#endif\r\n\treturn rotation;\r\n}\r\n\r\n#if defined(RENDERMODE_MESH)&&(defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE))\r\nvec3 computeParticleRotationVec3(in vec3 rotation,in float age,in float normalizedAge)\r\n{ \r\n\t#ifdef ROTATIONOVERLIFETIME\r\n\t#ifdef ROTATIONOVERLIFETIMECONSTANT\r\n\t\t\tfloat ageRot=u_ROLAngularVelocityConst*age;\r\n\t rotation+=ageRot;\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\r\n\t\t\trotation+=getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge);\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n\t\t\tfloat ageRot=mix(u_ROLAngularVelocityConst,u_ROLAngularVelocityConstMax,a_Random0.w)*age;\r\n\t rotation+=ageRot;\r\n\t #endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n\t\t\trotation+=mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradient,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMax,normalizedAge),a_Random0.w);\r\n\t\t#endif\r\n\t#endif\r\n\t#ifdef ROTATIONOVERLIFETIMESEPERATE\r\n\t\t#ifdef ROTATIONOVERLIFETIMECONSTANT\r\n\t\t\tvec3 ageRot=u_ROLAngularVelocityConstSeprarate*age;\r\n\t rotation+=ageRot;\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMECURVE\r\n\t\t\trotation+=vec3(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge));\r\n\t\t#endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCONSTANTS\r\n\t\t\tvec3 ageRot=mix(u_ROLAngularVelocityConstSeprarate,u_ROLAngularVelocityConstMaxSeprarate,a_Random0.w)*age;\r\n\t rotation+=ageRot;\r\n\t #endif\r\n\t\t#ifdef ROTATIONOVERLIFETIMERANDOMCURVES\r\n\t\t\trotation+=vec3(mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientX,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxX,normalizedAge),a_Random0.w)\r\n\t ,mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientY,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxY,normalizedAge),a_Random0.w)\r\n\t ,mix(getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientZ,normalizedAge),getTotalValueFromGradientFloat(u_ROLAngularVelocityGradientMaxZ,normalizedAge),a_Random0.w));\r\n\t\t#endif\r\n\t#endif\r\n\treturn rotation;\r\n}\r\n#endif\r\n\r\nvec2 computeParticleUV(in vec2 uv,in float normalizedAge)\r\n{ \r\n\t#ifdef TEXTURESHEETANIMATIONCURVE\r\n\t\tfloat cycleNormalizedAge=normalizedAge*u_TSACycles;\r\n\t\tfloat frame=getFrameFromGradient(u_TSAGradientUVs,cycleNormalizedAge-floor(cycleNormalizedAge));\r\n\t\tfloat totalULength=frame*u_TSASubUVLength.x;\r\n\t\tfloat floorTotalULength=floor(totalULength);\r\n\t uv.x+=totalULength-floorTotalULength;\r\n\t\tuv.y+=floorTotalULength*u_TSASubUVLength.y;\r\n #endif\r\n\t#ifdef TEXTURESHEETANIMATIONRANDOMCURVE\r\n\t\tfloat cycleNormalizedAge=normalizedAge*u_TSACycles;\r\n\t\tfloat uvNormalizedAge=cycleNormalizedAge-floor(cycleNormalizedAge);\r\n\t float frame=floor(mix(getFrameFromGradient(u_TSAGradientUVs,uvNormalizedAge),getFrameFromGradient(u_TSAMaxGradientUVs,uvNormalizedAge),a_Random1.x));\r\n\t\tfloat totalULength=frame*u_TSASubUVLength.x;\r\n\t\tfloat floorTotalULength=floor(totalULength);\r\n\t uv.x+=totalULength-floorTotalULength;\r\n\t\tuv.y+=floorTotalULength*u_TSASubUVLength.y;\r\n #endif\r\n\treturn uv;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tfloat age = u_CurrentTime - a_DirectionTime.w;\r\n\tfloat normalizedAge = age/a_ShapePositionStartLifeTime.w;\r\n\tvec3 lifeVelocity;\r\n\tif(normalizedAge<1.0)\r\n\t{ \r\n\t\tvec3 startVelocity=a_DirectionTime.xyz*a_StartSpeed;\r\n\t\t#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n\t\t\tlifeVelocity= computeParticleLifeVelocity(normalizedAge);//计算粒子生命周期速度\r\n\t\t#endif \r\n\t\tvec3 gravityVelocity=u_Gravity*age;\r\n\t\t\r\n\t\tvec4 worldRotation;\r\n\t\tif(u_SimulationSpace==0)\r\n\t\t\tworldRotation=a_SimulationWorldRotation;\r\n\t\telse\r\n\t\t\tworldRotation=u_WorldRotation;\r\n\t\t\r\n\t\tvec3 center=computeParticlePosition(startVelocity, lifeVelocity, age, normalizedAge,gravityVelocity,worldRotation);//计算粒子位置\r\n\t\r\n\t\r\n\t\t#ifdef SPHERHBILLBOARD\r\n\t\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\r\n\t\t\tvec3 cameraUpVector =normalize(u_CameraUp);//TODO:是否外面归一化\r\n\t\t\tvec3 sideVector = normalize(cross(u_CameraDirection,cameraUpVector));\r\n\t\t\tvec3 upVector = normalize(cross(sideVector,u_CameraDirection));\r\n\t\t\tcorner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\r\n\t\t\t#if defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE)\r\n\t\t\t\tif(u_ThreeDStartRotation){\r\n\t\t\t\t\tvec3 rotation=vec3(a_StartRotation0.xy,computeParticleRotationFloat(a_StartRotation0.z,age,normalizedAge));\r\n\t\t\t\t\tcenter += u_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,rotation);\r\n\t\t\t\t}\r\n\t\t\t\telse{\r\n\t\t\t\t\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\r\n\t\t\t\t\tfloat c = cos(rot);\r\n\t\t\t\t\tfloat s = sin(rot);\r\n\t\t\t\t\tmat2 rotation= mat2(c, -s, s, c);\r\n\t\t\t\t\tcorner=rotation*corner;\r\n\t\t\t\t\tcenter += u_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);\r\n\t\t\t\t}\r\n\t\t\t#else\r\n\t\t\t\tif(u_ThreeDStartRotation){\r\n\t\t\t\t\tcenter += u_SizeScale.xzy*rotationByEuler(corner.x*sideVector+corner.y*upVector,a_StartRotation0);\r\n\t\t\t\t}\r\n\t\t\t\telse{\r\n\t\t\t\t\tfloat c = cos(a_StartRotation0.x);\r\n\t\t\t\t\tfloat s = sin(a_StartRotation0.x);\r\n\t\t\t\t\tmat2 rotation= mat2(c, -s, s, c);\r\n\t\t\t\t\tcorner=rotation*corner;\r\n\t\t\t\t\tcenter += u_SizeScale.xzy*(corner.x*sideVector+corner.y*upVector);\r\n\t\t\t\t}\r\n\t\t\t#endif\r\n\t\t#endif\r\n\t\r\n\t\t#ifdef STRETCHEDBILLBOARD\r\n\t\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\r\n\t\t\tvec3 velocity;\r\n\t\t\t#if defined(VELOCITYOVERLIFETIMECONSTANT)||defined(VELOCITYOVERLIFETIMECURVE)||defined(VELOCITYOVERLIFETIMERANDOMCONSTANT)||defined(VELOCITYOVERLIFETIMERANDOMCURVE)\r\n\t\t\t\tif(u_VOLSpaceType==0)\r\n\t\t\t\tvelocity=rotationByQuaternions(u_SizeScale*(startVelocity+lifeVelocity),worldRotation)+gravityVelocity;\r\n\t\t\t\telse\r\n\t\t\t\tvelocity=rotationByQuaternions(u_SizeScale*startVelocity,worldRotation)+lifeVelocity+gravityVelocity;\r\n\t\t\t#else\r\n\t\t\t\tvelocity= rotationByQuaternions(u_SizeScale*startVelocity,worldRotation)+gravityVelocity;\r\n\t\t\t#endif\t\r\n\t\t\tvec3 cameraUpVector = normalize(velocity);\r\n\t\t\tvec3 direction = normalize(center-u_CameraPos);\r\n\t\t\tvec3 sideVector = normalize(cross(direction,normalize(velocity)));\r\n\t\t\t\r\n\t\t\tsideVector=u_SizeScale.xzy*sideVector;\r\n\t\t\tcameraUpVector=length(vec3(u_SizeScale.x,0.0,0.0))*cameraUpVector;\r\n\t\t\t\r\n\t\t\tvec2 size=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\r\n\t\t\t\r\n\t\t\tconst mat2 rotaionZHalfPI=mat2(0.0, -1.0, 1.0, 0.0);\r\n\t\t\tcorner=rotaionZHalfPI*corner;\r\n\t\t\tcorner.y=corner.y-abs(corner.y);\r\n\t\t\t\r\n\t\t\tfloat speed=length(velocity);//TODO:\r\n\t\t\tcenter +=sign(u_SizeScale.x)*(sign(u_StretchedBillboardLengthScale)*size.x*corner.x*sideVector+(speed*u_StretchedBillboardSpeedScale+size.y*u_StretchedBillboardLengthScale)*corner.y*cameraUpVector);\r\n\t\t#endif\r\n\t\r\n\t\t#ifdef HORIZONTALBILLBOARD\r\n\t\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\r\n\t\t\tconst vec3 cameraUpVector=vec3(0.0,0.0,1.0);\r\n\t\t\tconst vec3 sideVector = vec3(-1.0,0.0,0.0);\r\n\t\t\t\r\n\t\t\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\r\n\t\t\tfloat c = cos(rot);\r\n\t\t\tfloat s = sin(rot);\r\n\t\t\tmat2 rotation= mat2(c, -s, s, c);\r\n\t\t\tcorner=rotation*corner*cos(0.78539816339744830961566084581988);//TODO:临时缩小cos45,不确定U3D原因\r\n\t\t\tcorner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\r\n\t\t\tcenter +=u_SizeScale.xzy*(corner.x*sideVector+ corner.y*cameraUpVector);\r\n\t\t#endif\r\n\t\r\n\t\t#ifdef VERTICALBILLBOARD\r\n\t\t\tvec2 corner=a_CornerTextureCoordinate.xy;//Billboard模式z轴无效\r\n\t\t\tconst vec3 cameraUpVector =vec3(0.0,1.0,0.0);\r\n\t\t\tvec3 sideVector = normalize(cross(u_CameraDirection,cameraUpVector));\r\n\t\t\t\r\n\t\t\tfloat rot = computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\r\n\t\t\tfloat c = cos(rot);\r\n\t\t\tfloat s = sin(rot);\r\n\t\t\tmat2 rotation= mat2(c, -s, s, c);\r\n\t\t\tcorner=rotation*corner*cos(0.78539816339744830961566084581988);//TODO:临时缩小cos45,不确定U3D原因\r\n\t\t\tcorner*=computeParticleSizeBillbard(a_StartSize.xy,normalizedAge);\r\n\t\t\tcenter +=u_SizeScale.xzy*(corner.x*sideVector+ corner.y*cameraUpVector);\r\n\t\t#endif\r\n\t\r\n\t\t#ifdef RENDERMODE_MESH\r\n\t\t\tvec3 size=computeParticleSizeMesh(a_StartSize,normalizedAge);\r\n\t\t\t#if defined(ROTATIONOVERLIFETIME)||defined(ROTATIONOVERLIFETIMESEPERATE)\r\n\t\t\t\tif(u_ThreeDStartRotation){\r\n\t\t\t\t\tvec3 rotation=vec3(a_StartRotation0.xy,computeParticleRotationFloat(a_StartRotation0.z, age,normalizedAge));\r\n\t\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByEuler(a_MeshPosition*size,rotation),worldRotation);\r\n\t\t\t\t}\r\n\t\t\t\telse{\r\n\t\t\t\t\t#ifdef ROTATIONOVERLIFETIME\r\n\t\t\t\t\t\tfloat angle=computeParticleRotationFloat(a_StartRotation0.x, age,normalizedAge);\r\n\t\t\t\t\t\tif(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){\r\n\t\t\t\t\t\t\tcenter+= (rotationByQuaternions(rotationByAxis(u_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),angle),worldRotation));//已验证\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse{\r\n\t\t\t\t\t\t\t#ifdef SHAPE\r\n\t\t\t\t\t\t\t\tcenter+= u_SizeScale.xzy*(rotationByQuaternions(rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),angle),worldRotation));\r\n\t\t\t\t\t\t\t#else\r\n\t\t\t\t\t\t\t\tif(u_SimulationSpace==0)\r\n\t\t\t\t\t\t\t\t\tcenter+=rotationByAxis(u_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle);//已验证\r\n\t\t\t\t\t\t\t\telse if(u_SimulationSpace==1)\r\n\t\t\t\t\t\t\t\t\tcenter+=rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),angle),worldRotation);//已验证\r\n\t\t\t\t\t\t\t#endif\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t#endif\r\n\t\t\t\t\t#ifdef ROTATIONOVERLIFETIMESEPERATE\r\n\t\t\t\t\t\t//TODO:是否应合并if(u_ThreeDStartRotation)分支代码,待测试\r\n\t\t\t\t\t\tvec3 angle=computeParticleRotationVec3(vec3(0.0,0.0,-a_StartRotation0.x), age,normalizedAge);\r\n\t\t\t\t\t\tcenter+= (rotationByQuaternions(rotationByEuler(u_SizeScale*a_MeshPosition*size,vec3(angle.x,angle.y,angle.z)),worldRotation));//已验证\r\n\t\t\t\t\t#endif\t\t\r\n\t\t\t\t}\r\n\t\t\t#else\r\n\t\t\t\tif(u_ThreeDStartRotation){\r\n\t\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByEuler(a_MeshPosition*size,a_StartRotation0),worldRotation);//已验证\r\n\t\t\t\t}\r\n\t\t\t\telse{\r\n\t\t\t\t\tif(a_ShapePositionStartLifeTime.x!=0.0||a_ShapePositionStartLifeTime.y!=0.0){\r\n\t\t\t\t\t\tif(u_SimulationSpace==0)\r\n\t\t\t\t\t\t\tcenter+= rotationByAxis(u_SizeScale*a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),a_StartRotation0.x);\r\n\t\t\t\t\t\telse if(u_SimulationSpace==1)\r\n\t\t\t\t\t\t\tcenter+= (rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,normalize(cross(vec3(0.0,0.0,1.0),vec3(a_ShapePositionStartLifeTime.xy,0.0))),a_StartRotation0.x),worldRotation));//已验证\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse{\r\n\t\t\t\t\t\t#ifdef SHAPE\r\n\t\t\t\t\t\t\tif(u_SimulationSpace==0)\r\n\t\t\t\t\t\t\t\tcenter+= u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x);\r\n\t\t\t\t\t\t\telse if(u_SimulationSpace==1)\r\n\t\t\t\t\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,-1.0,0.0),a_StartRotation0.x),worldRotation);\t\r\n\t\t\t\t\t\t#else\r\n\t\t\t\t\t\t\tif(u_SimulationSpace==0)\r\n\t\t\t\t\t\t\t\tcenter+= rotationByAxis(u_SizeScale*a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x);\r\n\t\t\t\t\t\t\telse if(u_SimulationSpace==1)\r\n\t\t\t\t\t\t\t\tcenter+= rotationByQuaternions(u_SizeScale*rotationByAxis(a_MeshPosition*size,vec3(0.0,0.0,-1.0),a_StartRotation0.x),worldRotation);//已验证\r\n\t\t\t\t\t\t#endif\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t#endif\r\n\t\t\tv_MeshColor=a_MeshColor;\r\n\t\t#endif\r\n\t\r\n\t\tgl_Position=u_Projection*u_View*vec4(center,1.0);\r\n\t\tv_Color = computeParticleColor(a_StartColor, normalizedAge);\r\n\t\t#ifdef DIFFUSEMAP\r\n\t\t\t#if defined(SPHERHBILLBOARD)||defined(STRETCHEDBILLBOARD)||defined(HORIZONTALBILLBOARD)||defined(VERTICALBILLBOARD)\r\n\t\t\t\tv_TextureCoordinate =computeParticleUV(a_CornerTextureCoordinate.zw, normalizedAge);\r\n\t\t\t#endif\r\n\t\t\t#ifdef RENDERMODE_MESH\r\n\t\t\t\tv_TextureCoordinate =computeParticleUV(a_MeshTextureCoordinate, normalizedAge);\r\n\t\t\t#endif\r\n\t\t\t\r\n\t\t\t#ifdef TILINGOFFSET\r\n\t\t\t\tv_TextureCoordinate=TransformUV(v_TextureCoordinate,u_TilingOffset);\r\n\t\t\t#endif\r\n\t\t#endif\r\n \t}\r\n \telse\r\n\t{\r\n\t\tgl_Position=vec4(2.0,2.0,2.0,1.0);//Discard use out of X(-1,1),Y(-1,1),Z(0,1)\r\n\t}\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n\r\n',"#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n precision highp float;\r\n#else\r\n precision mediump float;\r\n#endif\r\n\r\nvarying vec4 v_Color;\r\nvarying vec2 v_TextureCoordinate;\r\nuniform sampler2D u_texture;\r\nuniform vec4 u_Tintcolor;\r\n\r\n#ifdef RENDERMODE_MESH\r\n\tvarying vec4 v_MeshColor;\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\t#ifdef ADDTIVEFOG\r\n\t#else\r\n\t\tuniform vec3 u_FogColor;\r\n\t#endif\r\n#endif\r\n\r\n\r\nvoid main()\r\n{\t\r\n\t#ifdef RENDERMODE_MESH\r\n\t\tgl_FragColor=v_MeshColor;\r\n\t#else\r\n\t\tgl_FragColor=vec4(1.0);\t\r\n\t#endif\r\n\t\t\r\n\t#ifdef DIFFUSEMAP\r\n\t\t#ifdef TINTCOLOR\r\n\t\t\tgl_FragColor*=texture2D(u_texture,v_TextureCoordinate)*u_Tintcolor*2.0*v_Color;\r\n\t\t#else\r\n\t\t\tgl_FragColor*=texture2D(u_texture,v_TextureCoordinate)*v_Color;\r\n\t\t#endif\r\n\t#else\r\n\t\t#ifdef TINTCOLOR\r\n\t\t\tgl_FragColor*=u_Tintcolor*2.0*v_Color;\r\n\t\t#else\r\n\t\t\tgl_FragColor*=v_Color;\r\n\t\t#endif\r\n\t#endif\r\n\t\r\n\t#ifdef FOG\r\n\t\tfloat lerpFact=clamp((1.0/gl_FragCoord.w-u_FogStart)/u_FogRange,0.0,1.0);\r\n\t\t#ifdef ADDTIVEFOG\r\n\t\t\tgl_FragColor.rgb=mix(gl_FragColor.rgb,vec3(0.0,0.0,0.0),lerpFact);\r\n\t\t#else\r\n\t\t\tgl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\r\n\t\t#endif\r\n\t#endif\r\n}",r),e={a_Position:ze.MESH_POSITION0},t={u_TintColor:xe.PERIOD_MATERIAL,u_Exposure:xe.PERIOD_MATERIAL,u_Rotation:xe.PERIOD_MATERIAL,u_CubeTexture:xe.PERIOD_MATERIAL,u_ViewProjection:xe.PERIOD_CAMERA},i=xe.add("SkyBox"),a=new mr(e,t),i.addSubShader(a),a.addShaderPass('#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\nprecision highp float;\r\n#else\r\nprecision mediump float;\r\n#endif\r\n#include "Lighting.glsl";\r\n\r\nattribute vec4 a_Position;\r\nuniform mat4 u_ViewProjection;\r\nuniform float u_Rotation;\r\nvarying vec3 v_Texcoord;\r\n\r\n\r\nvec4 rotateAroundYInDegrees (vec4 vertex, float degrees)\r\n{\r\n\tfloat angle = degrees * 3.141593 / 180.0;\r\n\tfloat sina=sin(angle);\r\n\tfloat cosa=cos(angle);\r\n\tmat2 m = mat2(cosa, -sina, sina, cosa);\r\n\treturn vec4(m*vertex.xz, vertex.yw).xzyw;\r\n}\r\n\t\t\r\nvoid main()\r\n{\r\n\tvec4 position=rotateAroundYInDegrees(a_Position,u_Rotation);\r\n\tgl_Position = u_ViewProjection*position;\r\n\tv_Texcoord=vec3(-a_Position.x,a_Position.yz);//转换坐标系\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n',"#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\nprecision highp float;\r\n#else\r\nprecision mediump float;\r\n#endif\r\n\r\nvarying vec3 v_Texcoord;\r\n\r\nuniform samplerCube u_CubeTexture;\r\nuniform float u_Exposure;\r\nuniform vec4 u_TintColor;\r\n\r\n\r\nvoid main()\r\n{\t\r\n\tvec3 color=textureCube(u_CubeTexture, v_Texcoord).rgb*u_TintColor.rgb*u_Exposure*2.0;\r\n\tgl_FragColor=vec4(color,1.0);\r\n}\r\n\r\n"),e={a_Position:ze.MESH_POSITION0},t={u_SunSize:xe.PERIOD_MATERIAL,u_SunSizeConvergence:xe.PERIOD_MATERIAL,u_AtmosphereThickness:xe.PERIOD_MATERIAL,u_SkyTint:xe.PERIOD_MATERIAL,u_GroundTint:xe.PERIOD_MATERIAL,u_Exposure:xe.PERIOD_MATERIAL,u_ViewProjection:xe.PERIOD_CAMERA,"u_SunLight.direction":xe.PERIOD_SCENE,"u_SunLight.color":xe.PERIOD_SCENE},i=xe.add("SkyBoxProcedural"),a=new mr(e,t),i.addSubShader(a),a.addShaderPass("#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include \"Lighting.glsl\";\r\n\r\n#define OUTER_RADIUS 1.025\r\n#define RAYLEIGH (mix(0.0, 0.0025, pow(u_AtmosphereThickness,2.5)))// Rayleigh constant Rayleigh为夜空光和极光亮度单位\r\n#define MIE 0.0010 // Mie constant 米氏散射\r\n#define SUN_BRIGHTNESS 20.0 // Sun brightness\r\n#define MAX_SCATTER 50.0 // Maximum scattering value, to prevent math overflows on Adrenos\r\n\r\nconst float SKY_GROUND_THRESHOLD = 0.02;\r\nconst float outerRadius = OUTER_RADIUS;\r\nconst float outerRadius2 = OUTER_RADIUS*OUTER_RADIUS;\r\nconst float innerRadius = 1.0;\r\nconst float innerRadius2 = 1.0;\r\nconst float cameraHeight = 0.0001;\r\n\r\nconst float HDSundiskIntensityFactor = 15.0;\r\nconst float simpleSundiskIntensityFactor = 27.0;\r\n\r\nconst float sunScale = 400.0 * SUN_BRIGHTNESS;\r\nconst float kmESun = MIE * SUN_BRIGHTNESS;\r\nconst float km4PI = MIE * 4.0 * 3.14159265;\r\nconst float scale = 1.0 / (OUTER_RADIUS - 1.0);\r\nconst float scaleDepth = 0.25;\r\nconst float scaleOverScaleDepth = (1.0 / (OUTER_RADIUS - 1.0)) / 0.25;\r\nconst float samples = 2.0; // THIS IS UNROLLED MANUALLY, DON'T TOUCH\r\n\r\n// RGB wavelengths .35 (.62=158), .43 (.68=174), .525 (.75=190)\r\nconst vec3 c_DefaultScatteringWavelength = vec3(0.65, 0.57, 0.475);//默认散射波长\r\nconst vec3 c_VariableRangeForScatteringWavelength = vec3(0.15, 0.15, 0.15);//散射播放的可变范围\r\n\r\nattribute vec4 a_Position;\r\n\r\nuniform mat4 u_ViewProjection;\r\nuniform vec3 u_SkyTint;\r\nuniform vec3 u_GroundTint;\r\nuniform float u_Exposure;\r\nuniform float u_AtmosphereThickness;\r\nuniform DirectionLight u_SunLight;\r\n\r\nvarying vec3 v_GroundColor;\r\nvarying vec3 v_SkyColor;\r\n\r\n#ifdef SUN_HIGH_QUALITY\r\n\tvarying vec3 v_Vertex;\r\n#elif defined(SUN_SIMPLE)\r\n\tvarying vec3 v_RayDir;\r\n#else\r\n\tvarying float v_SkyGroundFactor;\r\n#endif\r\n\r\n#if defined(SUN_HIGH_QUALITY)||defined(SUN_SIMPLE)\r\n\tvarying vec3 v_SunColor;\r\n#endif\r\n\r\n// Calculates the Rayleigh phase function\r\nfloat getRayleighPhase(vec3 light, vec3 ray) \r\n{\r\n\tfloat eyeCos = dot(light, ray);\r\n\treturn 0.75 + 0.75*eyeCos*eyeCos;\r\n}\r\n\r\nfloat scaleAngle(float inCos)\r\n{\r\n\tfloat x = 1.0 - inCos;\r\n\treturn 0.25 * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));\r\n}\r\n\r\n\r\nvoid main () {\r\n\tgl_Position = u_ViewProjection*a_Position;\r\n\r\n\tvec3 skyTintInGammaSpace = u_SkyTint;//支持非GAMMA空间后要调整\r\n\tvec3 scatteringWavelength = mix(c_DefaultScatteringWavelength-c_VariableRangeForScatteringWavelength,c_DefaultScatteringWavelength+c_VariableRangeForScatteringWavelength,vec3(1.0) - skyTintInGammaSpace); // using Tint in sRGB+ gamma allows for more visually linear interpolation and to keep (0.5) at (128, gray in sRGB) point\r\n\tvec3 invWavelength = 1.0 / pow(scatteringWavelength, vec3(4.0));\r\n\r\n\tfloat krESun = RAYLEIGH * SUN_BRIGHTNESS;\r\n\tfloat kr4PI = RAYLEIGH * 4.0 * 3.14159265;\r\n\r\n\tvec3 cameraPos = vec3(0.0,innerRadius + cameraHeight,0.0); // The camera's current position\r\n\r\n\t// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)\r\n\tvec3 eyeRay = normalize(a_Position.xyz);\r\n\r\n\tfloat far = 0.0;\r\n\tvec3 cIn, cOut;\r\n\tif (eyeRay.y >= 0.0) {// Sky\r\n\t\t// Calculate the length of the \"atmosphere\"\r\n\t\tfar = sqrt(outerRadius2 + innerRadius2 * eyeRay.y * eyeRay.y - innerRadius2) - innerRadius * eyeRay.y;\r\n\r\n\t\t// Calculate the ray's starting position, then calculate its scattering offset\r\n\t\tfloat height = innerRadius + cameraHeight;\r\n\t\tfloat depth = exp(scaleOverScaleDepth * -cameraHeight);\r\n\t\tfloat startAngle = dot(eyeRay, cameraPos) / height;\r\n\t\tfloat startOffset = depth*scaleAngle(startAngle);\r\n\r\n\t\t// Initialize the scattering loop variables\r\n\t\tfloat sampleLength = far / samples;\r\n\t\tfloat scaledLength = sampleLength * scale;\r\n\t\tvec3 sampleRay = eyeRay * sampleLength;\r\n\t\tvec3 samplePoint = cameraPos + sampleRay * 0.5;\r\n\r\n\t\tvec3 frontColor = vec3(0.0);\r\n\t\t//unrolling this manually to avoid some platform for loop slow\r\n\t\t{\r\n\t\t\tfloat height = length(samplePoint);\r\n\t\t\tfloat depth = exp(scaleOverScaleDepth * (innerRadius - height));\r\n\t\t\tfloat lightAngle = dot(-u_SunLight.direction, samplePoint) / height;\r\n\t\t\tfloat cameraAngle = dot(eyeRay, samplePoint) / height;\r\n\t\t\tfloat scatter = (startOffset + depth*(scaleAngle(lightAngle) - scaleAngle(cameraAngle)));\r\n\t\t\tvec3 attenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\r\n\r\n\t\t\tfrontColor += attenuate * (depth * scaledLength);\r\n\t\t\tsamplePoint += sampleRay;\r\n\t\t}\r\n\t\t{\r\n\t\t\tfloat height = length(samplePoint);\r\n\t\t\tfloat depth = exp(scaleOverScaleDepth * (innerRadius - height));\r\n\t\t\tfloat lightAngle = dot(-u_SunLight.direction, samplePoint) / height;\r\n\t\t\tfloat cameraAngle = dot(eyeRay, samplePoint) / height;\r\n\t\t\tfloat scatter = (startOffset + depth*(scaleAngle(lightAngle) - scaleAngle(cameraAngle)));\r\n\t\t\tvec3 attenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\r\n\r\n\t\t\tfrontColor += attenuate * (depth * scaledLength);\r\n\t\t\tsamplePoint += sampleRay;\r\n\t\t}\r\n\r\n\t\t// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader\r\n\t\tcIn = frontColor * (invWavelength * krESun);\r\n\t\tcOut = frontColor * kmESun;\r\n\t} else {// Ground\r\n\t\tfar = (-cameraHeight) / (min(-0.001, eyeRay.y));\r\n\t\tvec3 pos = cameraPos + far * eyeRay;\r\n\r\n\t\t// Calculate the ray's starting position, then calculate its scattering offset\r\n\t\tfloat depth = exp((-cameraHeight) * (1.0/scaleDepth));\r\n\t\tfloat cameraAngle = dot(-eyeRay, pos);\r\n\t\tfloat lightAngle = dot(-u_SunLight.direction, pos);\r\n\t\tfloat cameraScale = scaleAngle(cameraAngle);\r\n\t\tfloat lightScale = scaleAngle(lightAngle);\r\n\t\tfloat cameraOffset = depth*cameraScale;\r\n\t\tfloat temp = lightScale + cameraScale;\r\n\r\n\t\t// Initialize the scattering loop variables\r\n\t\tfloat sampleLength = far / samples;\r\n\t\tfloat scaledLength = sampleLength * scale;\r\n\t\tvec3 sampleRay = eyeRay * sampleLength;\r\n\t\tvec3 samplePoint = cameraPos + sampleRay * 0.5;\r\n\r\n\t\t// Now loop through the sample rays\r\n\t\tvec3 frontColor = vec3(0.0, 0.0, 0.0);\r\n\t\tvec3 attenuate;\r\n\r\n\t\t// Loop removed because we kept hitting SM2.0 temp variable limits. Doesn't affect the image too much.\r\n\t\t{\r\n\t\t\tfloat height = length(samplePoint);\r\n\t\t\tfloat depth = exp(scaleOverScaleDepth * (innerRadius - height));\r\n\t\t\tfloat scatter = depth*temp - cameraOffset;\r\n\t\t\tattenuate = exp(-clamp(scatter, 0.0, MAX_SCATTER) * (invWavelength * kr4PI + km4PI));\r\n\t\t\tfrontColor += attenuate * (depth * scaledLength);\r\n\t\t\tsamplePoint += sampleRay;\r\n\t\t}\r\n\r\n\t\tcIn = frontColor * (invWavelength * krESun + kmESun);\r\n\t\tcOut = clamp(attenuate, 0.0, 1.0);\r\n\t}\r\n\r\n\t#ifdef SUN_HIGH_QUALITY\r\n\t\tv_Vertex = -a_Position.xyz;\r\n\t#elif defined(SUN_SIMPLE) \r\n\t\tv_RayDir = -eyeRay;\r\n\t#else\r\n\t\tv_SkyGroundFactor = -eyeRay.y / SKY_GROUND_THRESHOLD;\r\n\t#endif\r\n\r\n\t// if we want to calculate color in vprog:\r\n\t// in case of linear: multiply by _Exposure in here (even in case of lerp it will be common multiplier, so we can skip mul in fshader)\r\n\tv_GroundColor = u_Exposure * (cIn + u_GroundTint*u_GroundTint * cOut);//u_GroundColor*u_GroundColor is gamma space convert to linear space\r\n\tv_SkyColor = u_Exposure * (cIn * getRayleighPhase(-u_SunLight.direction, -eyeRay));\r\n\r\n\t\r\n\t// The sun should have a stable intensity in its course in the sky. Moreover it should match the highlight of a purely specular material.\r\n\t// This matching was done using the Unity3D standard shader BRDF1 on the 5/31/2017\r\n\t// Finally we want the sun to be always bright even in LDR thus the normalization of the lightColor for low intensity.\r\n\tfloat lightColorIntensity = clamp(length(u_SunLight.color), 0.25, 1.0);\r\n\r\n\t#ifdef SUN_HIGH_QUALITY \r\n\t\tv_SunColor = HDSundiskIntensityFactor * clamp(cOut,0.0,1.0) * u_SunLight.color / lightColorIntensity;\r\n\t#elif defined(SUN_SIMPLE) \r\n\t\tv_SunColor = simpleSundiskIntensityFactor * clamp(cOut * sunScale,0.0,1.0) * u_SunLight.color / lightColorIntensity;\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n",'#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include "Lighting.glsl";\r\n\r\nconst float MIE_G = -0.990;\r\nconst float MIE_G2 = 0.9801;\r\nconst float SKY_GROUND_THRESHOLD = 0.02;\r\n\r\nuniform float u_SunSize;\r\nuniform float u_SunSizeConvergence;\r\nuniform DirectionLight u_SunLight;\r\n\r\n\r\nvarying vec3 v_GroundColor;\r\nvarying vec3 v_SkyColor;\r\n\r\n\r\n#ifdef SUN_HIGH_QUALITY\r\n\tvarying vec3 v_Vertex;\r\n#elif defined(SUN_SIMPLE)\r\n\tvarying vec3 v_RayDir;\r\n#else\r\n\tvarying float v_SkyGroundFactor;\r\n#endif\r\n\r\n#if defined(SUN_HIGH_QUALITY)||defined(SUN_SIMPLE)\r\n\tvarying vec3 v_SunColor;\r\n#endif\r\n\r\n// Calculates the Mie phase function\r\nfloat getMiePhase(float eyeCos, float eyeCos2) {\r\n\tfloat temp = 1.0 + MIE_G2 - 2.0 * MIE_G * eyeCos;\r\n\ttemp = pow(temp, pow(u_SunSize,0.65) * 10.0);\r\n\ttemp = max(temp,1.0e-4); // prevent division by zero, esp. in half precision\r\n\ttemp = 1.5 * ((1.0 - MIE_G2) / (2.0 + MIE_G2)) * (1.0 + eyeCos2) / temp;\r\n\treturn temp;\r\n}\r\n\r\n// Calculates the sun shape\r\nfloat calcSunAttenuation(vec3 lightPos, vec3 ray) {\r\n\t#ifdef SUN_HIGH_QUALITY\r\n\t\tfloat focusedEyeCos = pow(clamp(dot(lightPos, ray),0.0,1.0), u_SunSizeConvergence);\r\n\t\treturn getMiePhase(-focusedEyeCos, focusedEyeCos * focusedEyeCos);\r\n\t#else //SUN_SIMPLE\r\n\t\tvec3 delta = lightPos - ray;\r\n\t\tfloat dist = length(delta);\r\n\t\tfloat spot = 1.0 - smoothstep(0.0, u_SunSize, dist);\r\n\t\treturn spot * spot;\r\n\t#endif\r\n}\r\n\r\nvoid main() {\r\n\t// if y > 1 [eyeRay.y < -SKY_GROUND_THRESHOLD] - ground\r\n\t// if y >= 0 and < 1 [eyeRay.y <= 0 and > -SKY_GROUND_THRESHOLD] - horizon\r\n\t// if y < 0 [eyeRay.y > 0] - sky\r\n\tvec3 col = vec3(0.0, 0.0, 0.0);\r\n\r\n\t#ifdef SUN_HIGH_QUALITY\r\n\t\tvec3 ray = normalize(v_Vertex);\r\n\t\tfloat y = ray.y / SKY_GROUND_THRESHOLD;\r\n\t#elif defined(SUN_SIMPLE) \r\n\t\tvec3 ray = v_RayDir;\r\n\t\tfloat y = ray.y / SKY_GROUND_THRESHOLD;\t\r\n\t#else\r\n\t\tfloat y = v_SkyGroundFactor;\r\n\t#endif\r\n\r\n\t// if we did precalculate color in vprog: just do lerp between them\r\n\tcol = mix(v_SkyColor, v_GroundColor, clamp(y,0.0,1.0));\r\n\r\n\t#if defined(SUN_HIGH_QUALITY)||defined(SUN_SIMPLE)\r\n\t\tif (y < 0.0)\r\n\t\t\tcol += v_SunColor * calcSunAttenuation(-u_SunLight.direction, -ray);\r\n\t#endif\r\n\r\n\tcol = sqrt(col);//linear space convert to gamma space\r\n\tgl_FragColor=vec4(col,1.0);\r\n}\r\n\r\n'),e={a_Position:ze.MESH_POSITION0,a_Normal:ze.MESH_NORMAL0,a_Texcoord0:ze.MESH_TEXTURECOORDINATE0},t={u_MvpMatrix:xe.PERIOD_SPRITE,u_WorldMat:xe.PERIOD_SPRITE,u_CameraPos:xe.PERIOD_CAMERA,u_Viewport:xe.PERIOD_CAMERA,u_ProjectionParams:xe.PERIOD_CAMERA,u_View:xe.PERIOD_CAMERA,u_LightmapScaleOffset:xe.PERIOD_SPRITE,u_LightMap:xe.PERIOD_SPRITE,u_SplatAlphaTexture:xe.PERIOD_MATERIAL,u_DiffuseTexture1:xe.PERIOD_MATERIAL,u_DiffuseTexture2:xe.PERIOD_MATERIAL,u_DiffuseTexture3:xe.PERIOD_MATERIAL,u_DiffuseTexture4:xe.PERIOD_MATERIAL,u_DiffuseTexture5:xe.PERIOD_MATERIAL,u_DiffuseScaleOffset1:xe.PERIOD_MATERIAL,u_DiffuseScaleOffset2:xe.PERIOD_MATERIAL,u_DiffuseScaleOffset3:xe.PERIOD_MATERIAL,u_DiffuseScaleOffset4:xe.PERIOD_MATERIAL,u_DiffuseScaleOffset5:xe.PERIOD_MATERIAL,u_FogStart:xe.PERIOD_SCENE,u_FogRange:xe.PERIOD_SCENE,u_FogColor:xe.PERIOD_SCENE,u_DirationLightCount:xe.PERIOD_SCENE,u_LightBuffer:xe.PERIOD_SCENE,u_LightClusterBuffer:xe.PERIOD_SCENE,u_AmbientColor:xe.PERIOD_SCENE,u_ShadowMap:xe.PERIOD_SCENE,u_shadowMap2:xe.PERIOD_SCENE,u_shadowMap3:xe.PERIOD_SCENE,u_ShadowSplitSpheres:xe.PERIOD_SCENE,u_ShadowMatrices:xe.PERIOD_SCENE,u_ShadowMapSize:xe.PERIOD_SCENE,"u_DirectionLight.color":xe.PERIOD_SCENE,"u_DirectionLight.direction":xe.PERIOD_SCENE,"u_PointLight.position":xe.PERIOD_SCENE,"u_PointLight.range":xe.PERIOD_SCENE,"u_PointLight.color":xe.PERIOD_SCENE,"u_SpotLight.position":xe.PERIOD_SCENE,"u_SpotLight.direction":xe.PERIOD_SCENE,"u_SpotLight.range":xe.PERIOD_SCENE,"u_SpotLight.spot":xe.PERIOD_SCENE,"u_SpotLight.color":xe.PERIOD_SCENE},r={s_Cull:xe.RENDER_STATE_CULL,s_Blend:xe.RENDER_STATE_BLEND,s_BlendSrc:xe.RENDER_STATE_BLEND_SRC,s_BlendDst:xe.RENDER_STATE_BLEND_DST,s_DepthTest:xe.RENDER_STATE_DEPTH_TEST,s_DepthWrite:xe.RENDER_STATE_DEPTH_WRITE},i=xe.add("ExtendTerrain"),a=new mr(e,t),i.addSubShader(a),a.addShaderPass('#include "Lighting.glsl";\r\n\r\nattribute vec4 a_Position;\r\nattribute vec2 a_Texcoord0;\r\n\r\nuniform mat4 u_MvpMatrix;\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(LIGHTMAP)\r\n\tattribute vec3 a_Normal;\r\n\tvarying vec3 v_Normal;\r\n#endif\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)||(defined(CALCULATE_SHADOWS)&&defined(SHADOWMAP_PSSM1))\r\n\tuniform mat4 u_WorldMat;\r\n\tvarying vec3 v_PositionWorld;\r\n#endif\r\n\r\n#ifdef LIGHTMAP\r\n\tvarying vec2 v_LightMapUV;\r\n\tuniform vec4 u_LightmapScaleOffset;\r\n#endif\r\n\r\n#if defined(CALCULATE_SHADOWS)//shader���Զ���ĺ겻����ifdef ����ij�if defined\r\n\tvarying vec4 v_ShadowCoord;\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tgl_Position = u_MvpMatrix * a_Position;\r\n \r\n\tv_Texcoord0 = a_Texcoord0;\r\n \r\n\t#ifdef LIGHTMAP\r\n\t\tv_LightMapUV = vec2(a_Texcoord0.x, 1.0 - a_Texcoord0.y) * u_LightmapScaleOffset.xy + u_LightmapScaleOffset.zw;\r\n\t\tv_LightMapUV.y = 1.0 - v_LightMapUV.y;\r\n\t#endif\r\n \r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tv_Normal = a_Normal;\r\n\t#endif\r\n\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)||(defined(CALCULATE_SHADOWS)&&defined(SHADOWMAP_PSSM1))\r\n\t\tv_PositionWorld=(u_WorldMat*a_Position).xyz;\r\n\t#endif\r\n\r\n\t#if defined(CALCULATE_SHADOWS)//shader���Զ���ĺ겻����ifdef ����ij�if defined\r\n\t\tv_ShadowCoord = getShadowCoord(vec4(v_PositionWorld));\r\n\t#endif\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include "Lighting.glsl";\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)\r\n\tuniform vec3 u_CameraPos;\r\n\tvarying vec3 v_Normal;\r\n\tvarying vec3 v_PositionWorld;\r\n#endif\r\n\r\n#ifdef FOG\r\n\tuniform float u_FogStart;\r\n\tuniform float u_FogRange;\r\n\tuniform vec3 u_FogColor;\r\n#endif\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t#ifdef LEGACYSINGLELIGHTING\r\n\t\t#ifdef DIRECTIONLIGHT\r\n\t\t\tuniform DirectionLight u_DirectionLight;\r\n\t\t#endif\r\n\t\t#ifdef POINTLIGHT\r\n\t\t\tuniform PointLight u_PointLight;\r\n\t\t#endif\r\n\t\t#ifdef SPOTLIGHT\r\n\t\t\tuniform SpotLight u_SpotLight;\r\n\t\t#endif\r\n\t#else\r\n\t\tuniform mat4 u_View;\r\n\t\tuniform vec4 u_ProjectionParams;\r\n\t\tuniform vec4 u_Viewport;\r\n\t\tuniform int u_DirationLightCount;\r\n\t\tuniform sampler2D u_LightBuffer;\r\n\t\tuniform sampler2D u_LightClusterBuffer;\r\n\t#endif\r\n#endif\r\n\r\n#include "Shadow.glsl"\r\n#if defined(CALCULATE_SHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\tvarying vec4 v_ShadowCoord;\r\n#endif\r\nvarying float v_posViewZ;\r\n\r\nuniform vec3 u_AmbientColor;\r\n\r\nuniform sampler2D u_SplatAlphaTexture;\r\n\r\nuniform sampler2D u_DiffuseTexture1;\r\nuniform sampler2D u_DiffuseTexture2;\r\nuniform sampler2D u_DiffuseTexture3;\r\nuniform sampler2D u_DiffuseTexture4;\r\nuniform sampler2D u_DiffuseTexture5;\r\n\r\nuniform vec4 u_DiffuseScaleOffset1;\r\nuniform vec4 u_DiffuseScaleOffset2;\r\nuniform vec4 u_DiffuseScaleOffset3;\r\nuniform vec4 u_DiffuseScaleOffset4;\r\nuniform vec4 u_DiffuseScaleOffset5;\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\n#ifdef LIGHTMAP\r\n\tuniform sampler2D u_LightMap;\r\n\tvarying vec2 v_LightMapUV;\r\n#endif\r\n\r\nvoid main()\r\n{\r\n\tvec4 splatAlpha = vec4(1.0);\r\n\t#ifdef ExtendTerrain_DETAIL_NUM1\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r;\r\n\t#endif\r\n\t#ifdef ExtendTerrain_DETAIL_NUM2\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * (1.0 - splatAlpha.r);\r\n\t#endif\r\n\t#ifdef ExtendTerrain_DETAIL_NUM3\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\r\n\t\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * (1.0 - splatAlpha.r - splatAlpha.g);\r\n\t#endif\r\n\t#ifdef ExtendTerrain_DETAIL_NUM4\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\r\n\t\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\r\n\t\tvec4 color4 = texture2D(u_DiffuseTexture4, v_Texcoord0 * u_DiffuseScaleOffset4.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * splatAlpha.b + color4.xyz * (1.0 - splatAlpha.r - splatAlpha.g - splatAlpha.b);\r\n\t#endif\r\n\t#ifdef ExtendTerrain_DETAIL_NUM5\r\n\t\tsplatAlpha = texture2D(u_SplatAlphaTexture, v_Texcoord0);\r\n\t\tvec4 color1 = texture2D(u_DiffuseTexture1, v_Texcoord0 * u_DiffuseScaleOffset1.xy);\r\n\t\tvec4 color2 = texture2D(u_DiffuseTexture2, v_Texcoord0 * u_DiffuseScaleOffset2.xy);\r\n\t\tvec4 color3 = texture2D(u_DiffuseTexture3, v_Texcoord0 * u_DiffuseScaleOffset3.xy);\r\n\t\tvec4 color4 = texture2D(u_DiffuseTexture4, v_Texcoord0 * u_DiffuseScaleOffset4.xy);\r\n\t\tvec4 color5 = texture2D(u_DiffuseTexture5, v_Texcoord0 * u_DiffuseScaleOffset5.xy);\r\n\t\tgl_FragColor.xyz = color1.xyz * splatAlpha.r + color2.xyz * splatAlpha.g + color3.xyz * splatAlpha.b + color4.xyz * splatAlpha.a + color5.xyz * (1.0 - splatAlpha.r - splatAlpha.g - splatAlpha.b - splatAlpha.a);\r\n\t#endif\r\n\t\tgl_FragColor.w = splatAlpha.a;\r\n\t\t\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\tvec3 normal = v_Normal;\r\n\t\tvec3 dif, spe;\r\n\t#endif\r\n\r\n\tvec3 diffuse = vec3(0.0);\r\n\tvec3 specular= vec3(0.0);\r\n\t#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)||defined(FOG)\r\n\t\tvec3 toEye;\r\n\t\t#ifdef FOG\r\n\t\t\ttoEye=u_CameraPos-v_PositionWorld;\r\n\t\t\tfloat toEyeLength=length(toEye);\r\n\t\t\ttoEye/=toEyeLength;\r\n\t\t#else\r\n\t\t\ttoEye=normalize(u_CameraPos-v_PositionWorld);\r\n\t\t#endif\r\n\t#endif\r\n\r\n\t#ifdef LEGACYSINGLELIGHTING\r\n\t\t#ifdef DIRECTIONLIGHT\r\n\t\t\tLayaAirBlinnPhongDiectionLight(vec3(0.0),1.0,normal,vec3(1.0),toEye,u_DirectionLight,dif,spe);\r\n\t\t\tdiffuse+=dif;\r\n\t\t\tspecular+=spe;\r\n\t\t#endif\r\n\t\r\n\t\t#ifdef POINTLIGHT\r\n\t\t\tLayaAirBlinnPhongPointLight(v_PositionWorld,vec3(0.0),1.0,normal,vec3(1.0),toEye,u_PointLight,dif,spe);\r\n\t\t\tdiffuse+=dif;\r\n\t\t\tspecular+=spe;\r\n\t\t#endif\r\n\r\n\t\t#ifdef SPOTLIGHT\r\n\t\t\tLayaAirBlinnPhongSpotLight(v_PositionWorld,vec3(0.0),1.0,normal,vec3(1.0),toEye,u_SpotLight,dif,spe);\r\n\t\t\tdiffuse+=dif;\r\n\t\t\tspecular+=spe;\r\n\t\t#endif\r\n\t#else\r\n\t\t#ifdef DIRECTIONLIGHT\r\n\t\t\tfor (int i = 0; i < MAX_LIGHT_COUNT; i++) \r\n\t\t\t{\r\n\t\t\t\tif(i >= u_DirationLightCount)\r\n\t\t\t\t\tbreak;\r\n\t\t\t\tDirectionLight directionLight = getDirectionLight(u_LightBuffer,i);\r\n\t\t\t\tLayaAirBlinnPhongDiectionLight(vec3(0.0),1.0,normal,vec3(1.0),toEye,directionLight,dif,spe);\r\n\t\t\t\tdiffuse+=dif;\r\n\t\t\t\tspecular+=spe;\r\n\t\t\t}\r\n\t\t#endif\r\n\t\t#if defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t\t\tivec4 clusterInfo =getClusterInfo(u_LightClusterBuffer,u_View,u_Viewport, v_PositionWorld,gl_FragCoord,u_ProjectionParams);\r\n\t\t\t#ifdef POINTLIGHT\r\n\t\t\t\tfor (int i = 0; i < MAX_LIGHT_COUNT; i++) \r\n\t\t\t\t{\r\n\t\t\t\t\tif(i >= clusterInfo.x)//PointLightCount\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tPointLight pointLight = getPointLight(u_LightBuffer,u_LightClusterBuffer,clusterInfo,i);\r\n\t\t\t\t\tLayaAirBlinnPhongPointLight(v_PositionWorld,vec3(0.0),1.0,normal,vec3(1.0),toEye,pointLight,dif,spe);\r\n\t\t\t\t\tdiffuse+=dif;\r\n\t\t\t\t\tspecular+=spe;\r\n\t\t\t\t}\r\n\t\t\t#endif\r\n\t\t\t#ifdef SPOTLIGHT\r\n\t\t\t\tfor (int i = 0; i < MAX_LIGHT_COUNT; i++) \r\n\t\t\t\t{\r\n\t\t\t\t\tif(i >= clusterInfo.y)//SpotLightCount\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\tSpotLight spotLight = getSpotLight(u_LightBuffer,u_LightClusterBuffer,clusterInfo,i);\r\n\t\t\t\t\tLayaAirBlinnPhongSpotLight(v_PositionWorld,vec3(0.0),1.0,normal,vec3(1.0),toEye\t,spotLight,dif,spe);\r\n\t\t\t\t\tdiffuse+=dif;\r\n\t\t\t\t\tspecular+=spe;\r\n\t\t\t\t}\r\n\t\t\t#endif\r\n\t\t#endif\r\n\t#endif\r\n\r\nvec3 globalDiffuse = u_AmbientColor;\r\n#ifdef LIGHTMAP\r\n\tglobalDiffuse += decodeHDR(texture2D(u_LightMap, v_LightMapUV),5.0);\r\n#endif\r\n\r\n#if defined(CALCULATE_SHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\tfloat shadowValue = shadowValue = sampleShadowmap(v_ShadowCoord);\r\n\tgl_FragColor = vec4(gl_FragColor.rgb * (globalDiffuse + diffuse) * shadowValue, gl_FragColor.a);\r\n#else\r\n\tgl_FragColor = vec4(gl_FragColor.rgb * (globalDiffuse + diffuse), gl_FragColor.a);\r\n#endif\r\n\r\n#if defined(DIRECTIONLIGHT)||defined(POINTLIGHT)||defined(SPOTLIGHT)\r\n\t#if defined(CALCULATE_SHADOWS)//shader中自定义的宏不可用ifdef 必须改成if defined\r\n\t\tgl_FragColor.rgb += specular * shadowValue;\r\n\t#else\r\n\t\tgl_FragColor.rgb += specular;\r\n\t#endif\r\n#endif\r\n\r\n#ifdef FOG\r\n\tfloat lerpFact=clamp((toEyeLength-u_FogStart)/u_FogRange,0.0,1.0);\r\n\tgl_FragColor.rgb=mix(gl_FragColor.rgb,u_FogColor,lerpFact);\r\n#endif\r\n}\r\n\r\n\r\n\r\n\r\n\r\n',r),e={a_Position:fi.TRAIL_POSITION0,a_OffsetVector:fi.TRAIL_OFFSETVECTOR,a_Texcoord0X:fi.TRAIL_TEXTURECOORDINATE0X,a_Texcoord0Y:fi.TRAIL_TEXTURECOORDINATE0Y,a_BirthTime:fi.TRAIL_TIME0,a_Color:fi.TRAIL_COLOR},t={u_MvpMatrix:xe.PERIOD_SPRITE,u_View:xe.PERIOD_CAMERA,u_Projection:xe.PERIOD_CAMERA,u_TilingOffset:xe.PERIOD_MATERIAL,u_MainTexture:xe.PERIOD_MATERIAL,u_MainColor:xe.PERIOD_MATERIAL,u_CurTime:xe.PERIOD_SPRITE,u_LifeTime:xe.PERIOD_SPRITE,u_WidthCurve:xe.PERIOD_SPRITE,u_WidthCurveKeyLength:xe.PERIOD_SPRITE,u_GradientColorkey:xe.PERIOD_SPRITE,u_GradientAlphakey:xe.PERIOD_SPRITE},r={s_Cull:xe.RENDER_STATE_CULL,s_Blend:xe.RENDER_STATE_BLEND,s_BlendSrc:xe.RENDER_STATE_BLEND_SRC,s_BlendDst:xe.RENDER_STATE_BLEND_DST,s_DepthTest:xe.RENDER_STATE_DEPTH_TEST,s_DepthWrite:xe.RENDER_STATE_DEPTH_WRITE},i=xe.add("Trail"),a=new mr(e,t),i.addSubShader(a),a.addShaderPass('#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n#include "Lighting.glsl";\r\n\r\nattribute vec3 a_Position;\r\nattribute vec3 a_OffsetVector;\r\nattribute vec4 a_Color;\r\nattribute float a_Texcoord0X;\r\nattribute float a_Texcoord0Y;\r\nattribute float a_BirthTime;\r\n\r\nuniform mat4 u_View;\r\nuniform mat4 u_Projection;\r\n\r\nuniform vec4 u_TilingOffset;\r\n\r\nuniform float u_CurTime;\r\nuniform float u_LifeTime;\r\nuniform vec4 u_WidthCurve[10];\r\nuniform int u_WidthCurveKeyLength;\r\n\r\nvarying vec2 v_Texcoord0;\r\nvarying vec4 v_Color;\r\n\r\nfloat hermiteInterpolate(float t, float outTangent, float inTangent, float duration, float value1, float value2)\r\n{\r\n\tfloat t2 = t * t;\r\n\tfloat t3 = t2 * t;\r\n\tfloat a = 2.0 * t3 - 3.0 * t2 + 1.0;\r\n\tfloat b = t3 - 2.0 * t2 + t;\r\n\tfloat c = t3 - t2;\r\n\tfloat d = -2.0 * t3 + 3.0 * t2;\r\n\treturn a * value1 + b * outTangent * duration + c * inTangent * duration + d * value2;\r\n}\r\n\r\nfloat getCurWidth(in float normalizeTime)\r\n{\r\n\tfloat width;\r\n\tif(normalizeTime == 0.0){\r\n\t\twidth=u_WidthCurve[0].w;\r\n\t}\r\n\telse if(normalizeTime >= 1.0){\r\n\t\twidth=u_WidthCurve[u_WidthCurveKeyLength - 1].w;\r\n\t}\r\n\telse{\r\n\t\tfor(int i = 0; i < 10; i ++ )\r\n\t\t{\r\n\t\t\tif(normalizeTime == u_WidthCurve[i].x){\r\n\t\t\t\twidth=u_WidthCurve[i].w;\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tvec4 lastFrame = u_WidthCurve[i];\r\n\t\t\tvec4 nextFrame = u_WidthCurve[i + 1];\r\n\t\t\tif(normalizeTime > lastFrame.x && normalizeTime < nextFrame.x)\r\n\t\t\t{\r\n\t\t\t\tfloat duration = nextFrame.x - lastFrame.x;\r\n\t\t\t\tfloat t = (normalizeTime - lastFrame.x) / duration;\r\n\t\t\t\tfloat outTangent = lastFrame.z;\r\n\t\t\t\tfloat inTangent = nextFrame.y;\r\n\t\t\t\tfloat value1 = lastFrame.w;\r\n\t\t\t\tfloat value2 = nextFrame.w;\r\n\t\t\t\twidth=hermiteInterpolate(t, outTangent, inTangent, duration, value1, value2);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn width;\r\n}\t\r\n\r\nvoid main()\r\n{\r\n\tfloat normalizeTime = (u_CurTime - a_BirthTime) / u_LifeTime;\r\n\t\r\n\t#ifdef TILINGOFFSET\r\n\t\tv_Texcoord0 = vec2(a_Texcoord0X, 1.0 - a_Texcoord0Y) * u_TilingOffset.xy + u_TilingOffset.zw;\r\n\t#else\r\n\t\tv_Texcoord0 = vec2(a_Texcoord0X, a_Texcoord0Y);\r\n\t#endif\r\n\t\r\n\tv_Color = a_Color;\r\n\t\r\n\tvec3 cameraPos = (u_View*vec4(a_Position,1.0)).rgb;\r\n\tgl_Position = u_Projection * vec4(cameraPos+a_OffsetVector * getCurWidth(normalizeTime),1.0);\r\n\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}\r\n',"#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\nuniform sampler2D u_MainTexture;\r\nuniform vec4 u_MainColor;\r\n\r\nvarying vec2 v_Texcoord0;\r\nvarying vec4 v_Color;\r\n\r\nvoid main()\r\n{\r\n\tvec4 color = 2.0 * u_MainColor * v_Color;\r\n\t#ifdef MAINTEXTURE\r\n\t\tvec4 mainTextureColor = texture2D(u_MainTexture, v_Texcoord0);\r\n\t\tcolor *= mainTextureColor;\r\n\t#endif\r\n\tgl_FragColor = color;\r\n}\r\n\r\n ",r),e={a_Position:ze.MESH_POSITION0,a_Normal:ze.MESH_NORMAL0,a_Tangent0:ze.MESH_TANGENT0},t={u_MvpMatrix:xe.PERIOD_SPRITE,u_WorldMat:xe.PERIOD_SPRITE,u_CameraPos:xe.PERIOD_CAMERA,u_Time:xe.PERIOD_SCENE,u_MainTexture:xe.PERIOD_MATERIAL,u_NormalTexture:xe.PERIOD_MATERIAL,u_HorizonColor:xe.PERIOD_MATERIAL,u_WaveScale:xe.PERIOD_MATERIAL,u_WaveSpeed:xe.PERIOD_MATERIAL},i=xe.add("WaterPrimary"),a=new mr(e,t),i.addSubShader(a),a.addShaderPass('#include "Lighting.glsl";\r\n\r\nattribute vec4 a_Position;\r\nattribute vec3 a_Normal;\r\nattribute vec4 a_Tangent0;\r\n\r\nuniform mat4 u_MvpMatrix;\r\nuniform mat4 u_WorldMat;\r\nuniform vec3 u_CameraPos;\r\nuniform float u_WaveScale;\r\nuniform vec4 u_WaveSpeed;\r\nuniform float u_Time;\r\n\r\nvarying vec3 v_Normal;\r\nvarying vec3 v_Tangent;\r\nvarying vec3 v_Binormal;\r\nvarying vec3 v_ViewDir;\r\nvarying vec2 v_Texcoord0;\r\nvarying vec2 v_Texcoord1;\r\n\r\nvoid main()\r\n{\r\n\tvec4 positionWorld = u_WorldMat * a_Position;\r\n\tvec4 position = u_MvpMatrix * a_Position;\r\n\t\r\n\tvec4 temp = vec4(positionWorld.x, positionWorld.z, positionWorld.x, positionWorld.z) * u_WaveScale + u_WaveSpeed * u_WaveScale * u_Time;\r\n\t\r\n\tv_Texcoord0 = temp.xy * vec2(0.4, 0.45);\r\n\tv_Texcoord1 = temp.wz;\r\n\t\r\n\tmat3 worldMat = mat3(u_WorldMat);\r\n\tv_Normal = worldMat * a_Normal;\r\n\tv_Tangent = worldMat * a_Tangent0.xyz;\r\n\tv_Binormal = cross(v_Normal, v_Tangent) * a_Tangent0.w;\r\n\t\r\n\tv_ViewDir = u_CameraPos - positionWorld.xyz;\r\n\tgl_Position = position;\r\n\tgl_Position=remapGLPositionZ(gl_Position);\r\n}','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#ifdef MAINTEXTURE\r\n\tuniform sampler2D u_MainTexture;\r\n#endif\r\n\r\n#ifdef NORMALTEXTURE\r\n\tuniform sampler2D u_NormalTexture;\r\n#endif\r\n\r\nuniform vec4 u_HorizonColor;\r\n\r\nvarying vec3 v_Normal;\r\nvarying vec3 v_Tangent;\r\nvarying vec3 v_Binormal;\r\nvarying vec3 v_ViewDir;\r\nvarying vec2 v_Texcoord0;\r\nvarying vec2 v_Texcoord1;\r\n\r\n\r\n#include "Lighting.glsl"\r\n\r\n\r\n\r\nvec3 NormalSampleToWorldSpace(vec4 normalMapSample) {\r\n\tvec3 normalT;\r\n\tnormalT.x = 2.0 * normalMapSample.x - 1.0;\r\n\tnormalT.y = 1.0 - 2.0 * normalMapSample.y;\r\n\tnormalT.z = sqrt(1.0 - clamp(dot(normalT.xy, normalT.xy), 0.0, 1.0));\r\n\r\n\tvec3 bumpedNormal = normalize(normalT);\r\n\r\n\treturn bumpedNormal;\r\n}\r\n\r\n\r\nvoid main()\r\n{\r\n\tvec4 bumpColor1 = texture2D(u_NormalTexture, v_Texcoord0);\r\n\tvec4 bumpColor2 = texture2D(u_NormalTexture, v_Texcoord1);\r\n\r\n\tvec3 normal1 = NormalSampleToWorldSpace(bumpColor1);\r\n\tvec3 normal2 = NormalSampleToWorldSpace(bumpColor2);\r\n\t\r\n\tvec3 normal = normalize((normal1 + normal2) * 0.5);\r\n\tvec3 viewDir = normalize(v_ViewDir);\r\n\tfloat fresnel = dot(viewDir, normal);\r\n\t\r\n\tvec4 waterColor = texture2D(u_MainTexture, vec2(fresnel, fresnel));\r\n\t\r\n\tvec4 color;\r\n\tcolor.rgb = mix(waterColor.rgb, u_HorizonColor.rgb, vec3(waterColor.a));\r\n\tcolor.a = u_HorizonColor.a;\r\n\t\r\n\tgl_FragColor = color;\r\n}\r\n\r\n\r\n'),e={a_PositionTexcoord:ze.MESH_POSITION0},t={u_MainTex:xe.PERIOD_MATERIAL,u_OffsetScale:xe.PERIOD_MATERIAL},i=xe.add("BlitScreen"),a=new mr(e,t),i.addSubShader(a);var n=a.addShaderPass('#include "Lighting.glsl";\r\n#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\nattribute vec4 a_PositionTexcoord;\r\nuniform vec4 u_OffsetScale;\r\nvarying vec2 v_Texcoord0;\r\n\r\nvoid main() {\t\r\n\tgl_Position = vec4(u_OffsetScale.x*2.0-1.0+(a_PositionTexcoord.x+1.0)*u_OffsetScale.z,(1.0-((u_OffsetScale.y*2.0-1.0+(-a_PositionTexcoord.y+1.0)*u_OffsetScale.w)+1.0)/2.0)*2.0-1.0, 0.0, 1.0);\t\r\n\tv_Texcoord0 = a_PositionTexcoord.zw;\r\n\tgl_Position = remapGLPositionZ(gl_Position);\r\n}',"#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\nuniform sampler2D u_MainTex;\r\nvarying vec2 v_Texcoord0;\r\n\r\nvoid main() {\r\n\tgl_FragColor = texture2D(u_MainTex, v_Texcoord0);\r\n}\r\n\r\n").renderState;n.depthTest=lt.DEPTHTEST_ALWAYS,n.depthWrite=!1,n.cull=lt.CULL_NONE,n.blend=lt.BLEND_DISABLE,e={a_PositionTexcoord:ze.MESH_POSITION0},t={u_MainTex:xe.PERIOD_MATERIAL,u_BloomTex:xe.PERIOD_MATERIAL,u_AutoExposureTex:xe.PERIOD_MATERIAL,u_MainTex_TexelSize:xe.PERIOD_MATERIAL,u_SampleScale:xe.PERIOD_MATERIAL,u_Threshold:xe.PERIOD_MATERIAL,u_Params:xe.PERIOD_MATERIAL},i=xe.add("PostProcessBloom"),a=new mr(e,t),i.addSubShader(a),(n=a.addShaderPass(Di,'#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include "Colors.glsl";\r\n#include "Sampling.glsl";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_AutoExposureTex;\r\nuniform vec4 u_MainTex_TexelSize;\r\nuniform vec4 u_Threshold; // x: threshold value (linear), y: threshold - knee, z: knee * 2, w: 0.25 / knee\r\nuniform vec4 u_Params; // x: clamp, yzw: unused\r\n\r\nmediump vec4 prefilter(mediump vec4 color, vec2 uv) {\r\n\tmediump float autoExposure = texture2D(u_AutoExposureTex, uv).r;\r\n\tcolor *= autoExposure;\r\n\tcolor = min(vec4(u_Params.x), color); // clamp to max\r\n\tcolor = quadraticThreshold(color, u_Threshold.x, u_Threshold.yzw);\r\n\treturn color;\r\n}\r\n\r\nvoid fragPrefilter13() {\r\n\tmediump vec4 color = downsampleBox13Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\r\n\tgl_FragColor = prefilter(safeHDR(color), v_Texcoord0);\r\n}\r\n\r\nvoid main() {\r\n\tfragPrefilter13();\r\n}').renderState).depthTest=lt.DEPTHTEST_ALWAYS,n.depthWrite=!1,n.cull=lt.CULL_NONE,n.blend=lt.BLEND_DISABLE,a=new mr(e,t),i.addSubShader(a),(n=a.addShaderPass(Di,'#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include "Colors.glsl";\r\n#include "Sampling.glsl";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_AutoExposureTex;\r\nuniform vec4 u_MainTex_TexelSize;\r\nuniform vec4 u_Threshold; // x: threshold value (linear), y: threshold - knee, z: knee * 2, w: 0.25 / knee\r\nuniform vec4 u_Params; // x: clamp, yzw: unused\r\n\r\nmediump vec4 prefilter(mediump vec4 color, vec2 uv) {\r\n\tmediump float autoExposure = texture2D(u_AutoExposureTex, uv).r;\r\n\tcolor *= autoExposure;\r\n\tcolor = min(vec4(u_Params.x), color); // clamp to max\r\n\tcolor = quadraticThreshold(color, u_Threshold.x, u_Threshold.yzw);\r\n\treturn color;\r\n}\r\n\r\nvoid fragPrefilter4() {\r\n\tmediump vec4 color = downsampleBox4Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\r\n\tgl_FragColor = prefilter(safeHDR(color), v_Texcoord0);\r\n}\r\n\r\nvoid main() {\r\n\tfragPrefilter4();\r\n}').renderState).depthTest=lt.DEPTHTEST_ALWAYS,n.depthWrite=!1,n.cull=lt.CULL_NONE,n.blend=lt.BLEND_DISABLE,a=new mr(e,t),i.addSubShader(a),(n=a.addShaderPass(Di,'#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include "Colors.glsl";\r\n#include "Sampling.glsl";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform vec4 u_MainTex_TexelSize;\r\n\r\nvoid fragDownsample13() {\r\n\tmediump vec4 color = downsampleBox13Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\r\n\tgl_FragColor = color;\r\n}\r\n\r\nvoid main() {\r\n\tfragDownsample13();\r\n}').renderState).depthTest=lt.DEPTHTEST_ALWAYS,n.depthWrite=!1,n.cull=lt.CULL_NONE,n.blend=lt.BLEND_DISABLE,a=new mr(e,t),i.addSubShader(a),(n=a.addShaderPass(Di,'#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include "Colors.glsl";\r\n#include "Sampling.glsl";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform vec4 u_MainTex_TexelSize;\r\n\r\nvoid fragDownsample4() {\r\n\tmediump vec4 color = downsampleBox4Tap(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy);\r\n\tgl_FragColor = color;\r\n}\r\n\r\nvoid main() {\r\n\tfragDownsample4();\r\n}').renderState).depthTest=lt.DEPTHTEST_ALWAYS,n.depthWrite=!1,n.cull=lt.CULL_NONE,n.blend=lt.BLEND_DISABLE,a=new mr(e,t),i.addSubShader(a),(n=a.addShaderPass(Di,'#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include "Colors.glsl";\r\n#include "Sampling.glsl";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_BloomTex;\r\n\r\nuniform vec4 u_MainTex_TexelSize;\r\nuniform float u_SampleScale;\r\n\r\nmediump vec4 combine(mediump vec4 bloom, vec2 uv) {\r\n\tmediump vec4 color = texture2D(u_BloomTex, uv);\r\n\treturn bloom + color;\r\n}\r\n\r\nvoid fragUpsampleTent() {\r\n\tmediump vec4 bloom = upsampleTent(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy, vec4(u_SampleScale));\r\n\tgl_FragColor = combine(bloom, v_Texcoord0);\r\n}\r\n\r\nvoid main() {\r\n\tfragUpsampleTent();\r\n}').renderState).depthTest=lt.DEPTHTEST_ALWAYS,n.depthWrite=!1,n.cull=lt.CULL_NONE,n.blend=lt.BLEND_DISABLE,a=new mr(e,t),i.addSubShader(a),(n=a.addShaderPass(Di,'#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include "Colors.glsl";\r\n#include "Sampling.glsl";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_BloomTex;\r\n\r\nuniform vec4 u_MainTex_TexelSize;\r\nuniform float u_SampleScale;\r\n\r\nmediump vec4 combine(mediump vec4 bloom, vec2 uv) {\r\n\tmediump vec4 color = texture2D(u_BloomTex, uv);\r\n\treturn bloom + color;\r\n}\r\n\r\nvoid fragUpsampleBox() {\r\n\tmediump vec4 bloom = upsampleBox(u_MainTex, v_Texcoord0, u_MainTex_TexelSize.xy, vec4(u_SampleScale));\r\n\tgl_FragColor = combine(bloom, v_Texcoord0);\r\n}\r\n\r\nvoid main() {\r\n\tfragUpsampleBox();\r\n}').renderState).depthTest=lt.DEPTHTEST_ALWAYS,n.depthWrite=!1,n.cull=lt.CULL_NONE,n.blend=lt.BLEND_DISABLE,e={a_PositionTexcoord:ze.MESH_POSITION0},t={u_MainTex:xe.PERIOD_MATERIAL,u_BloomTex:xe.PERIOD_MATERIAL,u_AutoExposureTex:xe.PERIOD_MATERIAL,u_Bloom_DirtTileOffset:xe.PERIOD_MATERIAL,u_Bloom_DirtTex:xe.PERIOD_MATERIAL,u_BloomTex_TexelSize:xe.PERIOD_MATERIAL,u_Bloom_Settings:xe.PERIOD_MATERIAL,u_Bloom_Color:xe.PERIOD_MATERIAL},i=xe.add("PostProcessComposite"),a=new mr(e,t),i.addSubShader(a),(n=a.addShaderPass('#include "Lighting.glsl";\r\n\r\nattribute vec4 a_PositionTexcoord;\r\nvarying vec2 v_Texcoord0;\r\n\r\nvoid main() {\r\n\tgl_Position = vec4(a_PositionTexcoord.xy, 0.0, 1.0);\r\n\tv_Texcoord0 = a_PositionTexcoord.zw;\r\n\tgl_Position = remapGLPositionZ(gl_Position);\r\n}','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#include "Colors.glsl";\r\n#include "Sampling.glsl";\r\n\r\nvarying vec2 v_Texcoord0;\r\n\r\nuniform sampler2D u_MainTex;\r\nuniform sampler2D u_BloomTex;\r\n\r\nuniform sampler2D u_AutoExposureTex;\r\nuniform sampler2D u_Bloom_DirtTex;\r\nuniform vec4 u_BloomTex_TexelSize;\r\nuniform vec4 u_Bloom_DirtTileOffset; // xy: tiling, zw: offset\r\nuniform mediump vec3 u_Bloom_Settings;// x: sampleScale, y: intensity, z: dirt intensity\r\nuniform mediump vec3 u_Bloom_Color;\r\n\r\nvoid main() {\r\n\tmediump float autoExposure = texture2D(u_AutoExposureTex, v_Texcoord0).r;\r\n\tmediump vec4 color=vec4(0.0);\r\n\tcolor = texture2D(u_MainTex, v_Texcoord0);\r\n\t\r\n\tcolor = sRGBToLinear(color);\r\n\tcolor.rgb *= autoExposure;\r\n\t\r\n\t#if defined(BLOOM)||defined(BLOOM_LOW)\r\n\t\t#ifdef BLOOM\r\n\t\t\tmediump vec4 bloom = upsampleTent(u_BloomTex, v_Texcoord0, u_BloomTex_TexelSize.xy, vec4(u_Bloom_Settings.x));\r\n\t\t#else\r\n\t\t\tmediump vec4 bloom = upsampleBox(u_BloomTex, v_Texcoord0, u_BloomTex_TexelSize.xy, vec4(u_Bloom_Settings.x));\r\n\t\t#endif\r\n\r\n\t\t// UVs should be Distort(uv * u_Bloom_DirtTileOffset.xy + u_Bloom_DirtTileOffset.zw)\r\n\t\t// but considering we use a cover-style scale on the dirt texture the difference\r\n\t\t// isn\'t massive so we chose to save a few ALUs here instead in case lens distortion\r\n\t\t// is active\r\n\t\tmediump vec4 dirt =vec4(texture2D(u_Bloom_DirtTex, v_Texcoord0 * u_Bloom_DirtTileOffset.xy + u_Bloom_DirtTileOffset.zw).rgb, 0.0);\r\n\r\n\t\t// Additive bloom (artist friendly)\r\n\t\tbloom *= u_Bloom_Settings.y;\r\n\t\tdirt *= u_Bloom_Settings.z;\r\n\t\tmediump vec4 bloomColor=vec4(u_Bloom_Color, 1.0);\r\n\t\tcolor += bloom * bloomColor;\r\n\t\tcolor += dirt * bloom;\r\n\t#endif\r\n\t\r\n\tmediump vec4 finalColor = color;\r\n\tfinalColor = linearToSRGB(finalColor);\r\n\t//finalColor.rgb = Dither(finalColor.rgb, v_Texcoord0);//TODO:抖动\r\n\tgl_FragColor = finalColor;\r\n}').renderState).depthTest=lt.DEPTHTEST_ALWAYS,n.depthWrite=!1,n.cull=lt.CULL_NONE,n.blend=lt.BLEND_DISABLE}}class yi extends je{constructor(){super(),this._direction=new n,this._shadowCascadesMode=e.ShadowCascadesMode.NoCascades,this._shadowTwoCascadeSplits=1/3,this._shadowFourCascadeSplits=new n(1/15,.2,7/15),this._lightType=e.LightType.Directional}get shadowCascadesMode(){return this._shadowCascadesMode}set shadowCascadesMode(e){this._shadowCascadesMode=e}get shadowTwoCascadeSplits(){return this._shadowTwoCascadeSplits}set shadowTwoCascadeSplits(e){this._shadowTwoCascadeSplits=e}get shadowFourCascadeSplits(){return this._shadowFourCascadeSplits}set shadowFourCascadeSplits(e){if(e.x>e.y||e.y>e.z||e.z>1)throw"DiretionLight:Invalid value.";e.cloneTo(this._shadowFourCascadeSplits)}_addToLightQueue(){this._scene._directionLights.add(this)}_removeFromLightQueue(){this._scene._directionLights.remove(this)}_create(){return new yi}}class Li extends je{constructor(){super(),this._range=6,this._lightType=e.LightType.Point}get range(){return this._range}set range(e){this._range=e}_addToLightQueue(){this._scene._pointLights.add(this)}_removeFromLightQueue(){this._scene._pointLights.remove(this)}_parse(e,t){super._parse(e,t),this.range=e.range}_cloneTo(t,r,i){super._cloneTo(t,r,i);var a=t;a.range=this.range,a._lightType=e.LightType.Point}_create(){return new Li}}class Oi extends je{constructor(){super(),this._spotAngle=30,this._range=10,this._direction=new n,this._lightType=e.LightType.Spot}get spotAngle(){return this._spotAngle}set spotAngle(e){this._spotAngle=Math.max(Math.min(e,179),0)}get range(){return this._range}set range(e){this._range=e}_addToLightQueue(){this._scene._spotLights.add(this)}_removeFromLightQueue(){this._scene._spotLights.remove(this)}_parse(e,t){super._parse(e,t),this.range=e.range,this.spotAngle=e.spotAngle}_cloneTo(e,t,r){super._cloneTo(e,t,r);var i=e;i.range=this.range,i.spotAngle=this.spotAngle}_create(){return new Oi}}class Ni extends ci{constructor(e){super(e),this._simpleAnimatorParams=new a,this._simpleAnimatorOffset=new i,this._shaderValues.addDefine(hi.SHADERDEFINE_SIMPLEBONE),this._shaderValues.addDefine(hi.SHADERDEFINE_BONE)}get simpleAnimatorTexture(){return this._simpleAnimatorTexture}set simpleAnimatorTexture(e){this._simpleAnimatorTexture=e,this._simpleAnimatorTextureSize=e.width,this._shaderValues.setTexture(Ni.SIMPLE_SIMPLEANIMATORTEXTURE,e),e._addReference(),this._shaderValues.setNumber(Ni.SIMPLE_SIMPLEANIMATORTEXTURESIZE,this._simpleAnimatorTextureSize)}get simpleAnimatorOffset(){return this._simpleAnimatorOffset}set simpleAnimatorOffset(e){e.cloneTo(this._simpleAnimatorOffset)}_computeAnimatorParamsData(){this._cacheMesh&&(this._simpleAnimatorParams.x=this._simpleAnimatorOffset.x,this._simpleAnimatorParams.y=Math.round(this._simpleAnimatorOffset.y)*this._bonesNums*4)}_createRenderElement(){return new Yt}_setCacheAnimator(e){this._cacheAnimator=e,this._shaderValues.addDefine(hi.SHADERDEFINE_SIMPLEBONE)}_onMeshChange(e){super._onMeshChange(e),this._cacheMesh=e}_renderUpdate(e,t){var r=e.renderElement;switch(r.renderType){case Ke.RENDERTYPE_NORMAL:if(this._cacheAnimator){var i=this._cacheAnimator.owner.transform.worldMatrix;this._shaderValues.setMatrix4x4(Ce.WORLDMATRIX,i)}else this._shaderValues.setMatrix4x4(Ce.WORLDMATRIX,t.worldMatrix);this._computeAnimatorParamsData(),this._shaderValues.setVector(Ni.SIMPLE_SIMPLEANIMATORPARAMS,this._simpleAnimatorParams);break;case Ke.RENDERTYPE_INSTANCEBATCH:var a=Xt.instance.instanceWorldMatrixData,n=r.instanceBatchElementList,s=n.elements,o=n.length;if(this._cacheAnimator)for(var l=0;l<o;l++){var _=s[l].render._cacheAnimator.owner._transform.worldMatrix;a.set(_.elements,16*l)}else for(l=0;l<o;l++)a.set(s[l]._transform.worldMatrix.elements,16*l);var h=Xt.instance.instanceWorldMatrixBuffer;h.orphanStorage(),h.setData(a.buffer,0,0,16*o*4),this._shaderValues.addDefine(Ar.SHADERDEFINE_GPU_INSTANCE);var c=Xt.instance.instanceSimpleAnimatorData;if(this._cacheAnimator)for(l=0;l<o;l++){var d=s[l].render;d._computeAnimatorParamsData();var u=d._simpleAnimatorParams,m=4*l;c[m]=u.x,c[m+1]=u.y}else for(l=0;l<o;l++)c[m]=0,c[m+1]=0;var f=Xt.instance.instanceSimpleAnimatorBuffer;f.orphanStorage(),f.setData(c.buffer,0,0,4*o*4)}}_renderUpdateWithCamera(e,t){var r=e.projectionViewMatrix;if(r){var i=e.renderElement;switch(i.renderType){case Ke.RENDERTYPE_NORMAL:if(this._cacheAnimator){var a=this._cacheAnimator.owner._transform.worldMatrix;R.multiply(r,a,this._projectionViewWorldMatrix),this._shaderValues.setMatrix4x4(Ce.MVPMATRIX,this._projectionViewWorldMatrix)}else R.multiply(r,t.worldMatrix,this._projectionViewWorldMatrix),this._shaderValues.setMatrix4x4(Ce.MVPMATRIX,this._projectionViewWorldMatrix);break;case Ke.RENDERTYPE_INSTANCEBATCH:var n=Xt.instance.instanceMVPMatrixData,s=i.instanceBatchElementList,o=s.elements,l=s.length;if(this._cacheAnimator)for(var _=0;_<l;_++){var h=o[_].render._cacheAnimator.owner._transform.worldMatrix;H.mulMatrixByArray(r.elements,0,h.elements,0,n,16*_)}else for(_=0;_<l;_++){h=o[_]._transform.worldMatrix;H.mulMatrixByArray(r.elements,0,h.elements,0,n,16*_)}var c=Xt.instance.instanceMVPMatrixBuffer;c.orphanStorage(),c.setData(n.buffer,0,0,16*l*4)}}}_destroy(){this._cacheRootBone&&!this._cacheRootBone.destroyed&&this._cacheRootBone.transform.off(t.Event.TRANSFORM_CHANGED,this,this._onWorldMatNeedChange),this._simpleAnimatorTexture&&this._simpleAnimatorTexture._removeReference(),this._simpleAnimatorTexture=null}}class Pi extends kt{constructor(e=null,t=null){super(t),this._meshFilter=new Mr(this),this._render=new Ni(this),e&&(this._meshFilter.sharedMesh=e)}static __init__(){Ni.SIMPLE_SIMPLEANIMATORPARAMS=Pi.SIMPLE_SIMPLEANIMATORPARAMS,Ni.SIMPLE_SIMPLEANIMATORTEXTURE=Pi.SIMPLE_SIMPLEANIMATORTEXTURE,Ni.SIMPLE_SIMPLEANIMATORTEXTURESIZE=Pi.SIMPLE_SIMPLEANIMATORTEXTURESIZE}get meshFilter(){return this._meshFilter}get simpleSkinnedMeshRenderer(){return this._render}_parse(e,r){super._parse(e,r);var i=this.simpleSkinnedMeshRenderer,s=e.lightmapIndex;null!=s&&(i.lightmapIndex=s);var o,l=e.lightmapScaleOffset;if(l&&(i.lightmapScaleOffset=new a(l[0],l[1],l[2],l[3])),null!=e.enableRender&&(i.enable=e.enableRender),null!=e.receiveShadows&&(i.receiveShadow=e.receiveShadows),null!=e.castShadow&&(i.castShadow=e.castShadow),o=e.meshPath){var _=t.Loader.getRes(o);_&&(this.meshFilter.sharedMesh=_)}var h=e.materials;if(h){var c=i.sharedMaterials,d=h.length;c.length=d;for(var u=0;u<d;u++)c[u]=t.Loader.getRes(h[u].path);i.sharedMaterials=c}var m=e.boundBox,f=m.min,T=m.max;if(i.localBounds.setMin(new n(f[0],f[1],f[2])),i.localBounds.setMax(new n(T[0],T[1],T[2])),r){var E=e.rootBone;i.rootBone=r[E];var p,g=e.bones;for(u=0,p=g.length;u<p;u++)i.bones.push(r[g[u]]);i._bonesNums=e.bonesNums?e.bonesNums:i.bones.length}else e.rootBone&&i._setRootBone(e.rootBone);var S=e.animatorTexture;if(S){var R=t.Loader.getRes(S);i.simpleAnimatorTexture=R}}_changeHierarchyAnimator(e){super._changeHierarchyAnimator(e),this.simpleSkinnedMeshRenderer._setCacheAnimator(e)}_cloneTo(e,t,r){var i=e;i.meshFilter.sharedMesh=this.meshFilter.sharedMesh;var a=this._render,n=i._render;n.enable=a.enable,n.sharedMaterials=a.sharedMaterials,n.castShadow=a.castShadow;var s=a.lightmapScaleOffset;s&&(n.lightmapScaleOffset=s.clone()),n.receiveShadow=a.receiveShadow,n.sortingFudge=a.sortingFudge,n._rootBone=a._rootBone;var o=a.bones,l=n.bones,_=o.length;l.length=_;var h=a.rootBone;if(h){var c=H._getHierarchyPath(t,h,Pi._tempArray0);n.rootBone=c?H._getNodeByHierarchyPath(r,c):h}for(var d=0;d<o.length;d++)c=H._getHierarchyPath(t,o[d],Pi._tempArray0),l[d]=c?H._getNodeByHierarchyPath(r,c):o[d];var u=a.localBounds;u&&u.cloneTo(n.localBounds),n.simpleAnimatorOffset=a.simpleAnimatorOffset,n.simpleAnimatorTexture=a.simpleAnimatorTexture,n._bonesNums=a._bonesNums,super._cloneTo(e,t,r)}destroy(e=!0){this.destroyed||(super.destroy(e),this._meshFilter.destroy())}_create(){return new Pi}}Pi._tempArray0=[],Pi.SIMPLE_SIMPLEANIMATORTEXTURE=xe.propertyNameToID("u_SimpleAnimatorTexture"),Pi.SIMPLE_SIMPLEANIMATORPARAMS=xe.propertyNameToID("u_SimpleAnimatorParams"),Pi.SIMPLE_SIMPLEANIMATORTEXTURESIZE=xe.propertyNameToID("u_SimpleAnimatorTextureSize");class bi{static _createSprite3DInstance(e,t,r){var i;switch(e.type){case"Scene3D":i=new dr;break;case"Sprite3D":i=new Ce;break;case"MeshSprite3D":i=new yr,r&&e.props.isStatic&&r.push(i);break;case"SkinnedMeshSprite3D":i=new di;break;case"SimpleSkinnedMeshSprite3D":i=new Pi;break;case"ShuriKenParticle3D":i=new _i;break;case"Camera":i=new Qe;break;case"DirectionLight":i=new yi;break;case"PointLight":i=new Li;break;case"SpotLight":i=new Oi;break;case"TrailSprite3D":i=new gi;break;case"ReflectionProbe":i=new Qt;break;default:throw new Error("Utils3D:unidentified class type in (.lh) file.")}var a=e.child;if(a)for(var n=0,s=a.length;n<s;n++){var o=bi._createSprite3DInstance(a[n],t,r);i.addChild(o)}return t[e.instanceID]=i,i}static _createComponentInstance(e,r,i){var a=r[e.instanceID];a._parse(e.props,r);var n=e.child;if(n)for(var s=0,o=n.length;s<o;s++)bi._createComponentInstance(n[s],r,i);var l=e.components;if(l)for(var _=0,h=l.length;_<h;_++){var c=l[_],d=t.ClassUtils.getRegClass(c.type);if(d)a.addComponent(d)._parse(c,i);else console.warn("Unkown component type.")}}static _createNodeByJson02(e,t){var r={},i={component:[],data:[]},a=bi._createSprite3DInstance(e,r,t);return bi._createComponentInstance(e,r,i),bi._createInteractInstance(i,r),a}static _createInteractInstance(e,t){for(var r=e.component,i=e.data,a=0,n=r.length;a<n;a++)r[a]._parseInteractive(i[a],t)}static _parse(e,t=null,r=null){var i,a=e.data,n=[];switch(e.version){case"LAYAHIERARCHY:02":i=bi._createNodeByJson02(a,n);break;default:i=bi._createNodeByJson(a,n)}return jt.combine(i,n),i}static _parseScene(e,t=null,r=null){var i,a=e.data,n=[];switch(e.version){case"LAYASCENE3D:02":i=bi._createNodeByJson02(a,n);break;default:i=bi._createNodeByJson(a,n)}return jt.combine(null,n),i}static _createNodeByJson(e,r){var i;switch(e.type){case"Scene3D":i=new dr;break;case"Sprite3D":i=new Ce;break;case"MeshSprite3D":i=new yr,r&&e.props.isStatic&&r.push(i);break;case"SkinnedMeshSprite3D":i=new di;break;case"ShuriKenParticle3D":i=new _i;break;case"Camera":i=new Qe;break;case"DirectionLight":i=new yi;break;case"PointLight":i=new Li;break;case"SpotLight":i=new Oi;break;case"TrailSprite3D":i=new gi;break;default:throw new Error("Utils3D:unidentified class type in (.lh) file.")}var a=e.child;if(a)for(var n=0,s=a.length;n<s;n++){var o=bi._createNodeByJson(a[n],r);i.addChild(o)}var l=e.components;if(l)for(var _=0,h=l.length;_<h;_++){var c=l[_],d=t.ClassUtils.getRegClass(c.type);if(d)i.addComponent(d)._parse(c);else console.warn("Unkown component type.")}return i._parse(e.props,null),i}}class wi{static parse(e,t,r,i){wi._mesh=r,wi._subMeshes=i,wi._version=t,wi._readData=e,wi.READ_DATA(),wi.READ_BLOCK(),wi.READ_STRINGS();for(var a=0,n=wi._BLOCK.count;a<n;a++){wi._readData.pos=wi._BLOCK.blockStarts[a];var s=wi._readData.getUint16(),o=wi._strings[s],l=wi["READ_"+o];if(null==l)throw new Error("model file err,no this function:"+s+" "+o);l.call(null)}wi._strings.length=0,wi._readData=null,wi._version=null,wi._mesh=null,wi._subMeshes=null}static _readString(){return wi._strings[wi._readData.getUint16()]}static READ_DATA(){wi._DATA.offset=wi._readData.getUint32(),wi._DATA.size=wi._readData.getUint32()}static READ_BLOCK(){for(var e=wi._BLOCK.count=wi._readData.getUint16(),t=wi._BLOCK.blockStarts=[],r=wi._BLOCK.blockLengths=[],i=0;i<e;i++)t.push(wi._readData.getUint32()),r.push(wi._readData.getUint32())}static READ_STRINGS(){var e=wi._readData.getUint32(),t=wi._readData.getUint16(),r=wi._readData.pos;wi._readData.pos=e+wi._DATA.offset;for(var i=0;i<t;i++)wi._strings[i]=wi._readData.readUTFString();wi._readData.pos=r}static READ_MESH(){var r,i=t.LayaGL.instance,a=(wi._readString(),wi._readData.__getBuffer()),n=0,s=wi._readData.getInt16(),o=wi._DATA.offset;for(r=0;r<s;r++){var l,_=o+wi._readData.getUint32(),h=wi._readData.getUint32(),c=a.slice(_,_+h),d=new Float32Array(c),u=wi._readString();switch(wi._version){case"LAYAMODEL:0301":case"LAYAMODEL:0400":l=ze.getVertexDeclaration(u);break;case"LAYAMODEL:0401":l=ze.getVertexDeclaration(u,!1);break;default:throw new Error("LoadModelV03: unknown version.")}if(!l)throw new Error("LoadModelV03: unknown vertexDeclaration.");var m=new de(4*d.length,i.STATIC_DRAW,!0);m.vertexDeclaration=l,m.setData(d.buffer),wi._mesh._vertexBuffer=m,wi._mesh._vertexCount+=m._byteLength/l.vertexStride,n+=4*d.length}var f=o+wi._readData.getUint32(),T=wi._readData.getUint32(),E=new Uint16Array(a.slice(f,f+T)),p=new Ge(e.IndexFormat.UInt16,T/2,i.STATIC_DRAW,!0);p.setData(E),wi._mesh._indexBuffer=p,n+=2*p.indexCount,wi._mesh._setBuffer(wi._mesh._vertexBuffer,p),wi._mesh._setCPUMemory(n),wi._mesh._setGPUMemory(n);var g=wi._mesh._boneNames=[],S=wi._readData.getUint16();for(g.length=S,r=0;r<S;r++)g[r]=wi._strings[wi._readData.getUint16()];wi._readData.pos+=8;var v=wi._readData.getUint32(),x=wi._readData.getUint32(),A=new Float32Array(a.slice(o+v,o+v+x)),I=A.length,M=wi._mesh._inverseBindPosesBuffer=new ArrayBuffer(4*I);for(wi._mesh._inverseBindPoses=[],wi._mesh._instanceBufferStateType=0!=I?Ii.MESH_INSTANCEBUFFER_TYPE_SIMPLEANIMATOR:Ii.MESH_INSTANCEBUFFER_TYPE_NORMAL,wi._mesh._setInstanceBuffer(wi._mesh._instanceBufferStateType),r=0;r<I;r+=16){var D=new R(A[r+0],A[r+1],A[r+2],A[r+3],A[r+4],A[r+5],A[r+6],A[r+7],A[r+8],A[r+9],A[r+10],A[r+11],A[r+12],A[r+13],A[r+14],A[r+15],new Float32Array(M,4*r,16));wi._mesh._inverseBindPoses[r/16]=D}return!0}static READ_SUBMESH(){var e=wi._readData.__getBuffer(),t=new xi(wi._mesh);wi._readData.getInt16(),wi._readData.getUint32(),wi._readData.getUint32();var r=wi._readData.getUint32(),i=wi._readData.getUint32(),a=wi._mesh._indexBuffer;t._indexBuffer=a,t._setIndexRange(r,i);var n=wi._mesh._vertexBuffer;t._vertexBuffer=n;var s=wi._DATA.offset,o=t._subIndexBufferStart,l=t._subIndexBufferCount,_=t._boneIndicesList,h=wi._readData.getUint16();o.length=h,l.length=h,_.length=h;var c=wi._mesh._skinnedMatrixCaches,d=wi._subMeshes.length;c.length=wi._mesh._inverseBindPoses.length;for(var u=0;u<h;u++){o[u]=wi._readData.getUint32(),l[u]=wi._readData.getUint32();for(var m=wi._readData.getUint32(),f=wi._readData.getUint32(),T=_[u]=new Uint16Array(e.slice(s+m,s+m+f)),E=T.length,p=0;p<E;p++){var g=T[p];c[g]||(c[g]=new Ai(d,u,p))}}return wi._subMeshes.push(t),!0}}wi._BLOCK={count:0},wi._DATA={offset:0,size:0},wi._strings=[];class Vi{static parse(e,t,r,i){Vi._mesh=r,Vi._subMeshes=i,Vi._version=t,Vi._readData=e,Vi.READ_DATA(),Vi.READ_BLOCK(),Vi.READ_STRINGS();for(var a=0,n=Vi._BLOCK.count;a<n;a++){Vi._readData.pos=Vi._BLOCK.blockStarts[a];var s=Vi._readData.getUint16(),o=Vi._strings[s],l=Vi["READ_"+o];if(null==l)throw new Error("model file err,no this function:"+s+" "+o);l.call(null)}Vi._strings.length=0,Vi._readData=null,Vi._version=null,Vi._mesh=null,Vi._subMeshes=null}static _readString(){return Vi._strings[Vi._readData.getUint16()]}static READ_DATA(){Vi._DATA.offset=Vi._readData.getUint32(),Vi._DATA.size=Vi._readData.getUint32()}static READ_BLOCK(){for(var e=Vi._BLOCK.count=Vi._readData.getUint16(),t=Vi._BLOCK.blockStarts=[],r=Vi._BLOCK.blockLengths=[],i=0;i<e;i++)t.push(Vi._readData.getUint32()),r.push(Vi._readData.getUint32())}static READ_STRINGS(){var e=Vi._readData.getUint32(),t=Vi._readData.getUint16(),r=Vi._readData.pos;Vi._readData.pos=e+Vi._DATA.offset;for(var i=0;i<t;i++)Vi._strings[i]=Vi._readData.readUTFString();Vi._readData.pos=r}static READ_MESH(){var r,i=t.LayaGL.instance,a=0,n=(Vi._readString(),Vi._readData),s=n.__getBuffer(),o=n.getInt16(),l=Vi._DATA.offset;for(r=0;r<o;r++){var _,h,c,d=l+n.getUint32(),u=n.getUint32(),m=Vi._readString(),f=ze.getVertexDeclaration(m,!1),T=f.vertexStride,E=m.split(","),p=E.length,g=Vi._mesh;switch(Vi._version){case"LAYAMODEL:05":case"LAYAMODEL:0501":_=s.slice(d,d+u*T),h=new Float32Array(_),c=new Uint8Array(_);break;case"LAYAMODEL:COMPRESSION_05":case"LAYAMODEL:COMPRESSION_0501":_=new ArrayBuffer(T*u),h=new Float32Array(_),c=new Uint8Array(_);var S=n.pos;n.pos=d;for(var v=0;v<u;v++)for(var x,A=v*T,I=0;I<p;I++)switch(E[I]){case"POSITION":h[x=A/4]=t.HalfFloatUtils.convertToNumber(n.getUint16()),h[x+1]=t.HalfFloatUtils.convertToNumber(n.getUint16()),h[x+2]=t.HalfFloatUtils.convertToNumber(n.getUint16()),A+=12;break;case"NORMAL":h[x=A/4]=n.getUint8()/127.5-1,h[x+1]=n.getUint8()/127.5-1,h[x+2]=n.getUint8()/127.5-1,A+=12;break;case"COLOR":h[x=A/4]=n.getUint8()/255,h[x+1]=n.getUint8()/255,h[x+2]=n.getUint8()/255,h[x+3]=n.getUint8()/255,A+=16;break;case"UV":case"UV1":h[x=A/4]=t.HalfFloatUtils.convertToNumber(n.getUint16()),h[x+1]=t.HalfFloatUtils.convertToNumber(n.getUint16()),A+=8;break;case"BLENDWEIGHT":h[x=A/4]=n.getUint8()/255,h[x+1]=n.getUint8()/255,h[x+2]=n.getUint8()/255,h[x+3]=n.getUint8()/255,A+=16;break;case"BLENDINDICES":c[A]=n.getUint8(),c[A+1]=n.getUint8(),c[A+2]=n.getUint8(),c[A+3]=n.getUint8(),A+=4;break;case"TANGENT":h[x=A/4]=n.getUint8()/127.5-1,h[x+1]=n.getUint8()/127.5-1,h[x+2]=n.getUint8()/127.5-1,h[x+3]=n.getUint8()/127.5-1,A+=16}n.pos=S}var M=new de(_.byteLength,i.STATIC_DRAW,!0);M.vertexDeclaration=f,M.setData(_);u=M._byteLength/f.vertexStride;g._indexFormat=u>65535?e.IndexFormat.UInt32:e.IndexFormat.UInt16,g._vertexBuffer=M,g._vertexCount+=u,a+=4*h.length}var D,C=l+n.getUint32(),y=n.getUint32();D=g.indexFormat==e.IndexFormat.UInt32?new Uint32Array(s.slice(C,C+y)):new Uint16Array(s.slice(C,C+y));var L=new Ge(g.indexFormat,D.length,i.STATIC_DRAW,!0);if(L.setData(D),g._indexBuffer=L,g._setBuffer(g._vertexBuffer,L),a+=2*L.indexCount,g._setCPUMemory(a),g._setGPUMemory(a),"LAYAMODEL:0501"==Vi._version||"LAYAMODEL:COMPRESSION_0501"==Vi._version){var O=g.bounds,N=O.getMin(),P=O.getMax();N.setValue(n.getFloat32(),n.getFloat32(),n.getFloat32()),P.setValue(n.getFloat32(),n.getFloat32(),n.getFloat32()),O.setMin(N),O.setMax(P),g.bounds=O}var b=g._boneNames=[],w=n.getUint16();for(b.length=w,r=0;r<w;r++)b[r]=Vi._strings[n.getUint16()];var V=n.getUint32(),B=n.getUint32(),F=new Float32Array(s.slice(l+V,l+V+B)),U=F.length,G=g._inverseBindPosesBuffer=new ArrayBuffer(4*U);for(g._inverseBindPoses=[],g._instanceBufferStateType=0!=U?Ii.MESH_INSTANCEBUFFER_TYPE_SIMPLEANIMATOR:Ii.MESH_INSTANCEBUFFER_TYPE_NORMAL,g._setInstanceBuffer(g._instanceBufferStateType),r=0;r<U;r+=16){var z=new R(F[r+0],F[r+1],F[r+2],F[r+3],F[r+4],F[r+5],F[r+6],F[r+7],F[r+8],F[r+9],F[r+10],F[r+11],F[r+12],F[r+13],F[r+14],F[r+15],new Float32Array(G,4*r,16));g._inverseBindPoses[r/16]=z}return!0}static READ_SUBMESH(){var e=Vi._readData,t=e.__getBuffer(),r=new xi(Vi._mesh);e.getInt16();var i=e.getUint32(),a=e.getUint32(),n=Vi._mesh._indexBuffer;r._indexBuffer=n,r._setIndexRange(i,a);var s=Vi._mesh._vertexBuffer;r._vertexBuffer=s;var o=Vi._DATA.offset,l=r._subIndexBufferStart,_=r._subIndexBufferCount,h=r._boneIndicesList,c=e.getUint16();l.length=c,_.length=c,h.length=c;var d=Vi._mesh._skinnedMatrixCaches,u=Vi._subMeshes.length;d.length=Vi._mesh._inverseBindPoses.length;for(var m=0;m<c;m++){l[m]=e.getUint32(),_[m]=e.getUint32();for(var f=e.getUint32(),T=e.getUint32(),E=h[m]=new Uint16Array(t.slice(o+f,o+f+T)),p=0,g=E.length;p<g;p++){var S=E[p];d[S]||(d[S]=new Ai(u,m,p))}}return Vi._subMeshes.push(r),!0}}Vi._BLOCK={count:0},Vi._DATA={offset:0,size:0},Vi._strings=[];class Bi{static _parse(e,t=null,r=null){var i=new Ii;return Bi.read(e,i,i._subMeshes),i}static read(e,r,i){var a=new t.Byte(e);a.pos=0;var n=a.readUTFString();switch(n){case"LAYAMODEL:0301":case"LAYAMODEL:0400":case"LAYAMODEL:0401":wi.parse(a,n,r,i);break;case"LAYAMODEL:05":case"LAYAMODEL:COMPRESSION_05":case"LAYAMODEL:0501":case"LAYAMODEL:COMPRESSION_0501":Vi.parse(a,n,r,i);break;default:throw new Error("MeshReader: unknown mesh version.")}r._setSubMeshes(i),"LAYAMODEL:0501"!=n&&"LAYAMODEL:COMPRESSION_0501"!=n&&r.calculateBounds()}}class Fi extends st{constructor(){super(),this._exposure=1,this._textureDecodeFormat=t.TextureDecodeFormat.Normal,this._textureHDRParams=new a(1,0,0,1),this.setShaderName("SkyPanoramic");var e=this._shaderValues;e.setVector(Fi.TINTCOLOR,new a(.5,.5,.5,.5)),e.setNumber(Fi.ROTATION,0),e.setVector(Fi.TEXTURE_HDR_PARAMS,this._textureHDRParams)}static __init__(){var e={a_Position:ze.MESH_POSITION0},t={u_TintColor:xe.PERIOD_MATERIAL,u_TextureHDRParams:xe.PERIOD_MATERIAL,u_Rotation:xe.PERIOD_MATERIAL,u_Texture:xe.PERIOD_MATERIAL,u_ViewProjection:xe.PERIOD_CAMERA},r=xe.add("SkyPanoramic"),i=new mr(e,t);r.addSubShader(i),i.addShaderPass('#include "Lighting.glsl";\r\n\r\n#define PI 3.14159265359\r\n\r\nattribute vec4 a_Position;\r\n\r\nuniform mat4 u_ViewProjection;\r\nuniform float u_Rotation;\r\n\r\nvarying vec3 v_Texcoord;\r\nvarying vec2 v_Image180ScaleAndCutoff;\r\nvarying vec4 v_Layout3DScaleAndOffset;\r\n\r\nvec4 rotateAroundYInDegrees (vec4 vertex, float degrees)\r\n{\r\n\tfloat angle = degrees * PI / 180.0;\r\n\tfloat sina=sin(angle);\r\n\tfloat cosa=cos(angle);\r\n\tmat2 m = mat2(cosa, -sina, sina, cosa);\r\n\treturn vec4(m*vertex.xz, vertex.yw).xzyw;\r\n}\r\n\r\n\t\t\r\nvoid main()\r\n{\r\n\tvec4 position = rotateAroundYInDegrees(a_Position, u_Rotation);\r\n\tgl_Position = u_ViewProjection*position;\r\n\r\n\tv_Texcoord=vec3(-a_Position.x,-a_Position.y,a_Position.z);// NOTE: -a_Position.x convert coords system\r\n\r\n\t// Calculate constant horizontal scale and cutoff for 180 (vs 360) image type\r\n\tv_Image180ScaleAndCutoff = vec2(1.0, 1.0);// 360 degree mode\r\n\r\n\t// Calculate constant scale and offset for 3D layouts\r\n\tv_Layout3DScaleAndOffset = vec4(0,0,1,1);\r\n}\r\n','#if defined(GL_FRAGMENT_PRECISION_HIGH)// 原来的写法会被我们自己的解析流程处理,而我们的解析是不认内置宏的,导致被删掉,所以改成 if defined 了\r\n\tprecision highp float;\r\n#else\r\n\tprecision mediump float;\r\n#endif\r\n\r\n#define PI 3.14159265359\r\n#include "Lighting.glsl";\r\n\r\nuniform sampler2D u_Texture;\r\nuniform vec4 u_TextureHDRParams;\r\nuniform vec4 u_TintColor;\r\n\r\nvarying vec3 v_Texcoord;\r\nvarying vec2 v_Image180ScaleAndCutoff;\r\nvarying vec4 v_Layout3DScaleAndOffset;\r\n\r\nvec2 ToRadialCoords(vec3 coords)\r\n{\r\n\tvec3 normalizedCoords = normalize(coords);\r\n\tfloat latitude = acos(normalizedCoords.y);\r\n\tfloat longitude = atan(normalizedCoords.z,normalizedCoords.x);\r\n\tvec2 sphereCoords = vec2(longitude, latitude) * vec2(0.5/PI, 1.0/PI);\r\n\treturn vec2(0.5,1.0) - sphereCoords;\r\n}\r\n\r\n\r\nvoid main()\r\n{\t\r\n\tvec2 tc = ToRadialCoords(v_Texcoord);\r\n\tif (tc.x > v_Image180ScaleAndCutoff.y)\r\n\t\tgl_FragColor=vec4(0,0,0,1);\r\n\ttc.x = mod(tc.x*v_Image180ScaleAndCutoff.x, 1.0);\r\n\ttc = (tc + v_Layout3DScaleAndOffset.xy) * v_Layout3DScaleAndOffset.zw;\r\n\r\n\tmediump vec4 tex = texture2D (u_Texture, tc);\r\n\tmediump vec3 c = decodeHDR (tex, u_TextureHDRParams.x);\r\n\tc = c * u_TintColor.rgb * 2.0;//Gamma Space is 2.0,linear space is 4.59479380\r\n\tgl_FragColor=vec4(c, 1.0);\r\n}\r\n\r\n')}get tintColor(){return this._shaderValues.getVector(Fi.TINTCOLOR)}set tintColor(e){this._shaderValues.setVector(Fi.TINTCOLOR,e)}get exposure(){return this._exposure}set exposure(e){this._exposure!==e&&(this._exposure=e,this._textureDecodeFormat==t.TextureDecodeFormat.RGBM?this._textureHDRParams.x=e*t.BaseTexture._rgbmRange:this._textureHDRParams.x=e)}get rotation(){return this._shaderValues.getNumber(Fi.ROTATION)}set rotation(e){this._shaderValues.setNumber(Fi.ROTATION,e)}get panoramicTexture(){return this._shaderValues.getTexture(Fi.TEXTURE)}set panoramicTexture(e){this._shaderValues.setTexture(Fi.TEXTURE,e)}get panoramicTextureDecodeFormat(){return this._textureDecodeFormat}set panoramicTextureDecodeFormat(e){this._textureDecodeFormat!==e&&(this._textureDecodeFormat=e,e==t.TextureDecodeFormat.RGBM?this._textureHDRParams.x=this._exposure*t.BaseTexture._rgbmRange:this._textureHDRParams.x=this._exposure)}}Fi.TINTCOLOR=xe.propertyNameToID("u_TintColor"),Fi.EXPOSURE=xe.propertyNameToID("u_Exposure"),Fi.ROTATION=xe.propertyNameToID("u_Rotation"),Fi.TEXTURE=xe.propertyNameToID("u_Texture"),Fi.TEXTURE_HDR_PARAMS=xe.propertyNameToID("u_TextureHDRParams");class Ui extends t.Component{constructor(e){super(),this._anchor=new n,this._connectAnchor=new n,this._feedbackEnabled=!1,this._getJointFeedBack=!1,this._currentForce=new n,this._currentTorque=new n,this._constraintType=e;var t=Y._bullet;this._btframATrans=t.btTransform_create(),this._btframBTrans=t.btTransform_create(),t.btTransform_setIdentity(this._btframATrans),t.btTransform_setIdentity(this._btframBTrans),this._btframAPos=t.btVector3_create(0,0,0),this._btframBPos=t.btVector3_create(0,0,0),t.btTransform_setOrigin(this._btframATrans,this._btframAPos),t.btTransform_setOrigin(this._btframBTrans,this._btframBPos),this._breakForce=-1,this._breakTorque=-1}get enabled(){return super.enabled}set enabled(e){super.enabled=e}get appliedImpulse(){return this._feedbackEnabled||(this._btConstraint.EnableFeedback(!0),this._feedbackEnabled=!0),this._btConstraint.AppliedImpulse}set connectedBody(e){this._connectedBody=e,e&&(e.constaintRigidbodyB=this)}get connectedBody(){return this._connectedBody}get ownBody(){return this._ownBody}set ownBody(e){this._ownBody=e,e.constaintRigidbodyA=this}get currentForce(){return this._getJointFeedBack||this._getFeedBackInfo(),this._currentForce}get currentTorque(){return this._getJointFeedBack||this._getFeedBackInfo(),this._currentTorque}get breakForce(){return this._breakForce}set breakForce(e){this._breakForce=e}get breakTorque(){return this._breakTorque}set breakTorque(e){this._breakTorque=e}set anchor(e){e.cloneTo(this._anchor),this.setFrames()}get anchor(){return this._anchor}set connectAnchor(e){e.cloneTo(this._connectAnchor),this.setFrames()}get connectAnchor(){return this._connectAnchor}setOverrideNumSolverIterations(e){Y._bullet.btTypedConstraint_setOverrideNumSolverIterations(this._btConstraint,e)}setConstraintEnabled(e){Y._bullet.btTypedConstraint_setEnabled(this._btConstraint,e)}_onEnable(){super._onEnable(),this.enabled=!0}_onDisable(){super._onDisable(),this.enabled=!1}setFrames(){var e=Y._bullet;e.btVector3_setValue(this._btframAPos,-this._anchor.x,this.anchor.y,this.anchor.z),e.btVector3_setValue(this._btframBPos,-this._connectAnchor.x,this._connectAnchor.y,this._connectAnchor.z),e.btTransform_setOrigin(this._btframATrans,this._btframAPos),e.btTransform_setOrigin(this._btframBTrans,this._btframBPos)}_addToSimulation(){}_removeFromSimulation(){}_createConstraint(){}setConnectRigidBody(e,t){var r=e&&!!(e._simulation&&e._enabled&&e.colliderShape),i=t&&!!(t._simulation&&t._enabled&&t.colliderShape);if(!r||!i)throw"ownerRigid or connectRigidBody is not in Simulation";e==this._ownBody&&t==this._connectedBody||(!(!this.enabled||!this._simulation)&&this._removeFromSimulation(),this._ownBody=e,this._connectedBody=t,this._ownBody.constaintRigidbodyA=this,this._connectedBody.constaintRigidbodyB=this,this._createConstraint())}getcurrentForce(e){if(!this._btJointFeedBackObj)throw"this Constraint is not simulation";var t=Y._bullet,r=t.btJointFeedback_getAppliedForceBodyA(this._btJointFeedBackObj);e.setValue(t.btVector3_x(r),t.btVector3_y(r),t.btVector3_z(r))}getcurrentTorque(e){if(!this._btJointFeedBackObj)throw"this Constraint is not simulation";var t=Y._bullet,r=t.btJointFeedback_getAppliedTorqueBodyA(this._btJointFeedBackObj);e.setValue(t.btVector3_x(r),t.btVector3_y(r),t.btVector3_z(r))}_onDestroy(){var e=Y._bullet;this._simulation&&this._removeFromSimulation(),this._btConstraint&&this._btJointFeedBackObj&&this._simulation&&(e.btTypedConstraint_destroy(this._btConstraint),e.btJointFeedback_destroy(this._btJointFeedBackObj),this._btJointFeedBackObj=null,this._btConstraint=null),super._onDisable()}_isBreakConstrained(){if(this._getJointFeedBack=!1,-1==this.breakForce&&-1==this.breakTorque)return!1;this._getFeedBackInfo();var e=-1!=this._breakForce&&n.scalarLength(this._currentForce)>this._breakForce,t=-1!=this._breakTorque&&n.scalarLength(this._currentTorque)>this._breakTorque;return!(!e&&!t)&&(this._breakConstrained(),!0)}_parse(e){this._anchor.fromArray(e.anchor),this._connectAnchor.fromArray(e.connectAnchor),this.setFrames()}_getFeedBackInfo(){var e=Y._bullet,t=e.btJointFeedback_getAppliedForceBodyA(this._btJointFeedBackObj),r=e.btJointFeedback_getAppliedTorqueBodyA(this._btJointFeedBackObj);this._currentTorque.setValue(e.btVector3_x(r),e.btVector3_y(r),e.btVector3_z(r)),this._currentForce.setValue(e.btVector3_x(t),e.btVector3_y(t),e.btVector3_z(t)),this._getJointFeedBack=!0}_breakConstrained(){this.ownBody.constaintRigidbodyA=null,this.connectedBody&&(this.connectedBody.constaintRigidbodyB=null),this.destroy()}}Ui.CONSTRAINT_POINT2POINT_CONSTRAINT_TYPE=3,Ui.CONSTRAINT_HINGE_CONSTRAINT_TYPE=4,Ui.CONSTRAINT_CONETWIST_CONSTRAINT_TYPE=5,Ui.CONSTRAINT_D6_CONSTRAINT_TYPE=6,Ui.CONSTRAINT_SLIDER_CONSTRAINT_TYPE=7,Ui.CONSTRAINT_CONTACT_CONSTRAINT_TYPE=8,Ui.CONSTRAINT_D6_SPRING_CONSTRAINT_TYPE=9,Ui.CONSTRAINT_GEAR_CONSTRAINT_TYPE=10,Ui.CONSTRAINT_FIXED_CONSTRAINT_TYPE=11,Ui.CONSTRAINT_MAX_CONSTRAINT_TYPE=12,Ui.CONSTRAINT_CONSTRAINT_ERP=1,Ui.CONSTRAINT_CONSTRAINT_STOP_ERP=2,Ui.CONSTRAINT_CONSTRAINT_CFM=3,Ui.CONSTRAINT_CONSTRAINT_STOP_CFM=4,Ui.tempForceV3=new n;class Gi extends Ui{constructor(){super(Ui.CONSTRAINT_FIXED_CONSTRAINT_TYPE),this.breakForce=-1,this.breakTorque=-1}_addToSimulation(){this._simulation&&this._simulation.addConstraint(this,this.enabled)}_removeFromSimulation(){this._simulation.removeConstraint(this),this._simulation=null}_createConstraint(){if(this.ownBody&&this.ownBody._simulation&&this.connectedBody&&this.connectedBody._simulation){var e=Y._bullet;this._btConstraint=e.btFixedConstraint_create(this.ownBody.btColliderObject,this._btframATrans,this.connectedBody.btColliderObject,this._btframBTrans),this._btJointFeedBackObj=e.btJointFeedback_create(this._btConstraint),e.btTypedConstraint_setJointFeedback(this._btConstraint,this._btJointFeedBackObj),this._simulation=this.owner._scene.physicsSimulation,this._addToSimulation(),Y._bullet.btTypedConstraint_setEnabled(this._btConstraint,!0)}}_onAdded(){super._onAdded()}_onEnable(){this._btConstraint&&(super._onEnable(),this._btConstraint&&Y._bullet.btTypedConstraint_setEnabled(this._btConstraint,!0))}_onDisable(){super._onDisable(),this.connectedBody||this._removeFromSimulation(),this._btConstraint&&Y._bullet.btTypedConstraint_setEnabled(this._btConstraint,!1)}_onDestroy(){super._onDestroy()}_parse(e,t=null){super._parse(e),-1!=e.rigidbodyID&&-1!=e.connectRigidbodyID&&(t.component.push(this),t.data.push(e)),null!=e.breakForce&&(this.breakForce=e.breakForce),null!=e.breakTorque&&(this.breakTorque=e.breakTorque)}_parseInteractive(e=null,t=null){var r=t[e.rigidbodyID].getComponent(X),i=t[e.connectRigidbodyID].getComponent(X);this.ownBody=r,this.connectedBody=i}_cloneTo(e){}}class zi extends Ui{constructor(){super(Ui.CONSTRAINT_D6_SPRING_CONSTRAINT_TYPE),this._axis=new n,this._secondaryAxis=new n,this._minLinearLimit=new n,this._maxLinearLimit=new n,this._minAngularLimit=new n,this._maxAngularLimit=new n,this._linearLimitSpring=new n,this._angularLimitSpring=new n,this._linearBounce=new n,this._angularBounce=new n,this._linearDamp=new n,this._angularDamp=new n,this._xMotion=0,this._yMotion=0,this._zMotion=0,this._angularXMotion=0,this._angularYMotion=0,this._angularZMotion=0;var e=Y._bullet;this._btAxis=e.btVector3_create(-1,0,0),this._btSecondaryAxis=e.btVector3_create(0,1,0)}get axis(){return this._axis}get secondaryAxis(){return this._secondaryAxis}set maxAngularLimit(e){e.cloneTo(this._maxAngularLimit)}set minAngularLimit(e){e.cloneTo(this._minAngularLimit)}get maxAngularLimit(){return this._maxAngularLimit}get minAngularLimit(){return this._minAngularLimit}set maxLinearLimit(e){e.cloneTo(this._maxLinearLimit)}set minLinearLimit(e){e.cloneTo(this._minLinearLimit)}get maxLinearLimit(){return this._maxLinearLimit}get minLinearLimit(){return this._minLinearLimit}set XMotion(e){this._xMotion!=e&&(this._xMotion=e,this.setLimit(zi.MOTION_LINEAR_INDEX_X,e,-this._maxLinearLimit.x,-this._minLinearLimit.x))}get XMotion(){return this._xMotion}set YMotion(e){this._yMotion!=e&&(this._yMotion=e,this.setLimit(zi.MOTION_LINEAR_INDEX_Y,e,this._minLinearLimit.y,this._maxLinearLimit.y))}get YMotion(){return this._yMotion}set ZMotion(e){this._zMotion!=e&&(this._zMotion=e,this.setLimit(zi.MOTION_LINEAR_INDEX_Z,e,this._minLinearLimit.z,this._maxLinearLimit.z))}get ZMotion(){return this._zMotion}set angularXMotion(e){this._angularXMotion!=e&&(this._angularXMotion=e,this.setLimit(zi.MOTION_ANGULAR_INDEX_X,e,-this._maxAngularLimit.x,-this._minAngularLimit.x))}get angularXMotion(){return this._angularXMotion}set angularYMotion(e){this._angularYMotion!=e&&(this._angularYMotion=e,this.setLimit(zi.MOTION_ANGULAR_INDEX_Y,e,this._minAngularLimit.y,this._maxAngularLimit.y))}get angularYMotion(){return this._angularYMotion}set angularZMotion(e){this._angularZMotion!=e&&(this._angularZMotion=e,this.setLimit(zi.MOTION_ANGULAR_INDEX_Z,e,this._minAngularLimit.z,this._maxAngularLimit.z))}get angularZMotion(){return this._angularZMotion}set linearLimitSpring(e){n.equals(this._linearLimitSpring,e)||(e.cloneTo(this._linearLimitSpring),this.setSpring(zi.MOTION_LINEAR_INDEX_X,e.x),this.setSpring(zi.MOTION_LINEAR_INDEX_Y,e.y),this.setSpring(zi.MOTION_LINEAR_INDEX_Z,e.z))}get linearLimitSpring(){return this._linearLimitSpring}set angularLimitSpring(e){n.equals(this._angularLimitSpring,e)||(e.cloneTo(this._angularLimitSpring),this.setSpring(zi.MOTION_ANGULAR_INDEX_X,e.x),this.setSpring(zi.MOTION_ANGULAR_INDEX_Y,e.y),this.setSpring(zi.MOTION_ANGULAR_INDEX_Z,e.z))}get angularLimitSpring(){return this._angularLimitSpring}set linearBounce(e){n.equals(this._linearBounce,e)||(e.cloneTo(this._linearBounce),this.setBounce(zi.MOTION_LINEAR_INDEX_X,e.x),this.setBounce(zi.MOTION_LINEAR_INDEX_Y,e.y),this.setBounce(zi.MOTION_LINEAR_INDEX_Z,e.z))}get linearBounce(){return this._linearBounce}set angularBounce(e){n.equals(this._angularBounce,e)||(e.cloneTo(this._angularBounce),this.setBounce(zi.MOTION_ANGULAR_INDEX_X,e.x),this.setBounce(zi.MOTION_ANGULAR_INDEX_Y,e.y),this.setBounce(zi.MOTION_ANGULAR_INDEX_Z,e.z))}get angularBounce(){return this._angularBounce}set linearDamp(e){n.equals(this._linearDamp,e)||(e.cloneTo(this._linearDamp),this.setDamping(zi.MOTION_LINEAR_INDEX_X,e.x),this.setDamping(zi.MOTION_LINEAR_INDEX_Y,e.y),this.setDamping(zi.MOTION_LINEAR_INDEX_Z,e.z))}get linearDamp(){return this._linearDamp}set angularDamp(e){n.equals(this._angularDamp,e)||(e.cloneTo(this._angularDamp),this.setDamping(zi.MOTION_ANGULAR_INDEX_X,e.x),this.setDamping(zi.MOTION_ANGULAR_INDEX_Y,e.y),this.setDamping(zi.MOTION_ANGULAR_INDEX_Z,e.z))}get angularDamp(){return this._angularDamp}set anchor(e){e.cloneTo(this._anchor),this.setFrames()}get anchor(){return this._anchor}set connectAnchor(e){e.cloneTo(this._connectAnchor),this.setFrames()}get connectAnchor(){return this._connectAnchor}setAxis(e,t){if(this._btConstraint){var r=Y._bullet;this._axis.setValue(e.x,e.y,e.y),this._secondaryAxis.setValue(t.x,t.y,t.z),this._btAxis=r.btVector3_setValue(-e.x,e.y,e.z),this._btSecondaryAxis=r.btVector3_setValue(-t.x,t.y,t.z),r.btGeneric6DofSpring2Constraint_setAxis(this._btConstraint,this._btAxis,this._btSecondaryAxis)}}setLimit(e,t,r,i){if(this._btConstraint){var a=Y._bullet;switch(t){case zi.CONFIG_MOTION_TYPE_LOCKED:a.btGeneric6DofSpring2Constraint_setLimit(this._btConstraint,e,0,0);break;case zi.CONFIG_MOTION_TYPE_LIMITED:r<i&&a.btGeneric6DofSpring2Constraint_setLimit(this._btConstraint,e,r,i);break;case zi.CONFIG_MOTION_TYPE_FREE:a.btGeneric6DofSpring2Constraint_setLimit(this._btConstraint,e,1,0);break;default:throw"No Type of Axis Motion"}}}setSpring(e,t,r=!0){if(this._btConstraint){var i=Y._bullet,a=t>0;i.btGeneric6DofSpring2Constraint_enableSpring(this._btConstraint,e,a),a&&i.btGeneric6DofSpring2Constraint_setStiffness(this._btConstraint,e,t,r)}}setBounce(e,t){this._btConstraint&&(t=t<=0?0:t,Y._bullet.btGeneric6DofSpring2Constraint_setBounce(this._btConstraint,e,t))}setDamping(e,t,r=!0){this._btConstraint&&(t=t<=0?0:t,Y._bullet.btGeneric6DofSpring2Constraint_setDamping(this._btConstraint,e,t,r))}setEquilibriumPoint(e,t){Y._bullet.btGeneric6DofSpring2Constraint_setEquilibriumPoint(this._btConstraint,e,t)}enableMotor(e,t){Y._bullet.btGeneric6DofSpring2Constraint_enableMotor(this._btConstraint,e,t)}setServo(e,t){Y._bullet.btGeneric6DofSpring2Constraint_setServo(this._btConstraint,e,t)}setTargetVelocity(e,t){Y._bullet.btGeneric6DofSpring2Constraint_setTargetVelocity(this._btConstraint,e,t)}setTargetPosition(e,t){Y._bullet.btGeneric6DofSpring2Constraint_setServoTarget(this._btConstraint,e,t)}setMaxMotorForce(e,t){Y._bullet.btGeneric6DofSpring2Constraint_setMaxMotorForce(this._btConstraint,e,t)}setParam(e,t,r){Y._bullet.btTypedConstraint_setParam(this._btConstraint,e,t,r)}setFrames(){super.setFrames();var e=Y._bullet;this._btConstraint&&e.btGeneric6DofSpring2Constraint_setFrames(this._btConstraint,this._btframATrans,this._btframBTrans)}_addToSimulation(){this._simulation&&this._simulation.addConstraint(this,this.enabled)}_removeFromSimulation(){this._simulation.removeConstraint(this),this._simulation=null}_createConstraint(){var e=Y._bullet;this._btConstraint=e.btGeneric6DofSpring2Constraint_create(this.ownBody.btColliderObject,this._btframAPos,this.connectedBody.btColliderObject,this._btframBPos,zi.RO_XYZ),this._btJointFeedBackObj=e.btJointFeedback_create(this._btConstraint),e.btTypedConstraint_setJointFeedback(this._btConstraint,this._btJointFeedBackObj),this._simulation=this.owner._scene.physicsSimulation,this._initAllConstraintInfo(),this._addToSimulation(),Y._bullet.btTypedConstraint_setEnabled(this._btConstraint,!0)}_initAllConstraintInfo(){this.setLimit(zi.MOTION_LINEAR_INDEX_X,this._xMotion,-this._maxLinearLimit.x,-this._minLinearLimit.x),this.setLimit(zi.MOTION_LINEAR_INDEX_Y,this._yMotion,this._minLinearLimit.y,this._maxLinearLimit.y),this.setLimit(zi.MOTION_LINEAR_INDEX_Z,this._zMotion,this._minLinearLimit.z,this._maxLinearLimit.z),this.setLimit(zi.MOTION_ANGULAR_INDEX_X,this._angularXMotion,-this._maxAngularLimit.x,-this._minAngularLimit.x),this.setLimit(zi.MOTION_ANGULAR_INDEX_Y,this._angularYMotion,this._minAngularLimit.y,this._maxAngularLimit.y),this.setLimit(zi.MOTION_ANGULAR_INDEX_Z,this._angularZMotion,this._minAngularLimit.z,this._maxAngularLimit.z),this.setSpring(zi.MOTION_LINEAR_INDEX_X,this._linearLimitSpring.x),this.setSpring(zi.MOTION_LINEAR_INDEX_Y,this._linearLimitSpring.y),this.setSpring(zi.MOTION_LINEAR_INDEX_Z,this._linearLimitSpring.z),this.setSpring(zi.MOTION_ANGULAR_INDEX_X,this._angularLimitSpring.x),this.setSpring(zi.MOTION_ANGULAR_INDEX_Y,this._angularLimitSpring.y),this.setSpring(zi.MOTION_ANGULAR_INDEX_Z,this._angularLimitSpring.z),this.setBounce(zi.MOTION_LINEAR_INDEX_X,this._linearBounce.x),this.setBounce(zi.MOTION_LINEAR_INDEX_Y,this._linearBounce.y),this.setBounce(zi.MOTION_LINEAR_INDEX_Z,this._linearBounce.z),this.setBounce(zi.MOTION_ANGULAR_INDEX_X,this._angularBounce.x),this.setBounce(zi.MOTION_ANGULAR_INDEX_Y,this._angularBounce.y),this.setBounce(zi.MOTION_ANGULAR_INDEX_Z,this._angularBounce.z),this.setDamping(zi.MOTION_LINEAR_INDEX_X,this._linearDamp.x),this.setDamping(zi.MOTION_LINEAR_INDEX_Y,this._linearDamp.y),this.setDamping(zi.MOTION_LINEAR_INDEX_Z,this._linearDamp.z),this.setDamping(zi.MOTION_ANGULAR_INDEX_X,this._angularDamp.x),this.setDamping(zi.MOTION_ANGULAR_INDEX_Y,this._angularDamp.y),this.setDamping(zi.MOTION_ANGULAR_INDEX_Z,this._angularDamp.z),this.setFrames(),this.setEquilibriumPoint(0,0)}_onAdded(){super._onAdded()}_onEnable(){this._btConstraint&&(super._onEnable(),this._btConstraint&&Y._bullet.btTypedConstraint_setEnabled(this._btConstraint,!0))}_onDisable(){super._onDisable(),!this.connectedBody&&this._simulation&&this._removeFromSimulation(),this._btConstraint&&Y._bullet.btTypedConstraint_setEnabled(this._btConstraint,!1)}_parse(e,t=null){super._parse(e),this._axis.fromArray(e.axis),this._secondaryAxis.fromArray(e.secondaryAxis);var r=e.linearLimit;this._minLinearLimit.setValue(-r,-r,-r),this._maxLinearLimit.setValue(r,r,r);var i=e.linearLimitSpring;this._linearLimitSpring.setValue(i,i,i);var a=e.linearLimitDamper;this._linearDamp.setValue(a,a,a);var n=e.linearLimitBounciness;this._linearBounce.setValue(n,n,n);var s=e.lowAngularXLimit,o=e.highAngularXLimit,l=e.angularYLimit,_=e.angularZLimit;this._minAngularLimit.setValue(s,-l,-_),this._maxAngularLimit.setValue(o,l,_);var h=e.highAngularXLimitBounciness,c=e.angularYLimitBounciness,d=e.angularZLimitBounciness;this._angularBounce.setValue(h,c,d);var u=e.angularXLimitSpring,m=e.angularYZLimitSpring;this._angularLimitSpring.setValue(u,m,m);var f=e.angularXLimitDamper,T=e.angularYZLimitDamper;this._angularDamp.setValue(f,T,T),this.XMotion=e.xMotion,this.YMotion=e.yMotion,this.ZMotion=e.zMotion,this.angularXMotion=e.angularXMotion,this.angularYMotion=e.angularYMotion,this.angularZMotion=e.angularZMotion,-1!=e.rigidbodyID&&-1!=e.connectRigidbodyID&&(t.component.push(this),t.data.push(e)),null!=e.breakForce&&(this.breakForce=e.breakForce),null!=e.breakTorque&&(this.breakTorque=e.breakTorque)}_parseInteractive(e=null,t=null){var r=t[e.rigidbodyID].getComponent(X),i=t[e.connectRigidbodyID].getComponent(X);this.ownBody=r,this.connectedBody=i}_onDestroy(){super._onDestroy()}_cloneTo(e){}}zi.CONFIG_MOTION_TYPE_LOCKED=0,zi.CONFIG_MOTION_TYPE_LIMITED=1,zi.CONFIG_MOTION_TYPE_FREE=2,zi.MOTION_LINEAR_INDEX_X=0,zi.MOTION_LINEAR_INDEX_Y=1,zi.MOTION_LINEAR_INDEX_Z=2,zi.MOTION_ANGULAR_INDEX_X=3,zi.MOTION_ANGULAR_INDEX_Y=4,zi.MOTION_ANGULAR_INDEX_Z=5,zi.RO_XYZ=0,zi.RO_XZY=1,zi.RO_YXZ=2,zi.RO_YZX=3,zi.RO_ZXY=4,zi.RO_ZYX=5;class Hi{constructor(){}static get enablePhysics(){return Y._enablePhysics}static _cancelLoadByUrl(e){t.Laya.loader.cancelLoadByUrl(e),Hi._innerFirstLevelLoaderManager.cancelLoadByUrl(e),Hi._innerSecondLevelLoaderManager.cancelLoadByUrl(e),Hi._innerThirdLevelLoaderManager.cancelLoadByUrl(e),Hi._innerFourthLevelLoaderManager.cancelLoadByUrl(e)}static _changeWebGLSize(e,r){t.WebGL.onStageResize(e,r),_e.clientWidth=e,_e.clientHeight=r}static __init__(r,i,a){if(t.Config.isAntialias=a.isAntialias,t.Config.isAlpha=a.isAlpha,t.Config.premultipliedAlpha=a.premultipliedAlpha,t.Config.isStencil=a.isStencil,t.WebGL.enable()){t.RunDriver.changeWebGLSize=Hi._changeWebGLSize,t.Render.is3DMode=!0,t.Laya.init(r,i),t.Render.supportWebGLPlusRendering||(t.LayaGL.instance=t.WebGLContext.mainContext,t.LayaGL.instance.createCommandEncoder=function(e=128,r=64,i=!1){return new t.CommandEncoder(this,e,r,i)}),a._multiLighting=a.enableMultiLight&&t.SystemUtils.supportTextureFormat(t.TextureFormat.R32G32B32A32),g.Shader3D=xe,g.Scene3D=dr,g.MeshRenderStaticBatchManager=qt,g.MeshRenderDynamicBatchManager=Cr,g.SubMeshDynamicBatch=Dr,g.Laya3D=Hi,g.Matrix4x4=R,g.Physics3D=Y,g.ShadowLightType=e.ShadowLightType,Hi.enableNative3D(),a.isUseCannonPhysicsEngine&&Y.__cannoninit__(),Y.__bulletinit__(),ue.__init__(),ze.__init__(),ii.__init__(),ai.__init__(),Nt.__init__(),fi.__init__(),Si.__init__(),zt.__init__(),Xt.__init__(),Dr.__init__(),Ci.__init__(),Ze.init(),dt.__init__(),gr.__init__(),fr.__init__(),Fi.__init__(),Ii.__init__(),Mi.__init__(),Ce.__init__(),kt.__init__(),yr.__init__(),di.__init__(),Pi.__init__(),_i.__init__(),gi.__init__(),rt.__init__(),dr.__init__(),qt.__init__(),st.__initDefine__(),ot.__initDefine__(),_t.__initDefine__(),Rr.__initDefine__(),vr.__initDefine__(),ui.__initDefine__(),ht.__initDefine__(),xr.__initDefine__(),ei.__initDefine__(),ct.__initDefine__(),Bt.__initDefine__(),Sr.__initDefine__(),Ae.__init__(),t.ClassUtils.regClass("Laya.SkyPanoramicMaterial",Fi),t.ClassUtils.regClass("Laya.EffectMaterial",ht),t.ClassUtils.regClass("Laya.UnlitMaterial",vr),t.ClassUtils.regClass("Laya.BlinnPhongMaterial",_t),t.ClassUtils.regClass("Laya.SkyProceduralMaterial",Rr),t.ClassUtils.regClass("Laya.PBRStandardMaterial",gr),t.ClassUtils.regClass("Laya.PBRSpecularMaterial",fr),t.ClassUtils.regClass("Laya.SkyBoxMaterial",Sr),t.ClassUtils.regClass("Laya.WaterPrimaryMaterial",xr),t.ClassUtils.regClass("Laya.ExtendTerrainMaterial",ct),t.ClassUtils.regClass("Laya.ShurikenParticleMaterial",ei),t.ClassUtils.regClass("Laya.TrailMaterial",ui),t.ClassUtils.regClass("Laya.PhysicsCollider",vi),t.ClassUtils.regClass("Laya.Rigidbody3D",X),t.ClassUtils.regClass("Laya.CharacterController",k),t.ClassUtils.regClass("Laya.Animator",le),t.ClassUtils.regClass("PhysicsCollider",vi),t.ClassUtils.regClass("CharacterController",k),t.ClassUtils.regClass("Animator",le),t.ClassUtils.regClass("Rigidbody3D",X),t.ClassUtils.regClass("FixedConstraint",Gi),t.ClassUtils.regClass("ConfigurableConstraint",zi),Bt.defaultMaterial=new Bt,_t.defaultMaterial=new _t,ht.defaultMaterial=new ht,vr.defaultMaterial=new vr,ei.defaultMaterial=new ei,ui.defaultMaterial=new ui,Rr.defaultMaterial=new Rr,Sr.defaultMaterial=new Sr,xr.defaultMaterial=new xr,Bt.defaultMaterial.lock=!0,_t.defaultMaterial.lock=!0,ht.defaultMaterial.lock=!0,vr.defaultMaterial.lock=!0,ei.defaultMaterial.lock=!0,ui.defaultMaterial.lock=!0,Rr.defaultMaterial.lock=!0,Sr.defaultMaterial.lock=!0,xr.defaultMaterial.lock=!0,t.Texture2D.__init__(),bt.__init__(),ke.__init__(),Pt.__init__(),pe.__init__(),ge.__init__(),Mt.__init__(),t.HalfFloatUtils.__init__();var n=t.LoaderManager.createMap;n.lh=[Hi.HIERARCHY,bi._parse],n.ls=[Hi.HIERARCHY,bi._parseScene],n.lm=[Hi.MESH,Bi._parse],n.lmat=[Hi.MATERIAL,st._parse],n.jpg=[Hi.TEXTURE2D,t.Texture2D._parse],n.jpeg=[Hi.TEXTURE2D,t.Texture2D._parse],n.bmp=[Hi.TEXTURE2D,t.Texture2D._parse],n.gif=[Hi.TEXTURE2D,t.Texture2D._parse],n.png=[Hi.TEXTURE2D,t.Texture2D._parse],n.dds=[Hi.TEXTURE2D,t.Texture2D._parse],n.ktx=[Hi.TEXTURE2D,t.Texture2D._parse],n.pvr=[Hi.TEXTURE2D,t.Texture2D._parse],n.lani=[Hi.ANIMATIONCLIP,ie._parse],n.lav=[Hi.AVATAR,nt._parse],n.ltc=[Hi.TEXTURECUBE,bt._parse],n.ltcb=[Hi.TEXTURECUBEBIN,bt._parseBin],n["ltcb.ls"]=[Hi.TEXTURECUBEBIN,bt._parseBin],n["lanit.ls"]=[Hi.TEXTURE2D,t.Texture2D._SimpleAnimatorTextureParse];var s=t.Loader.parserMap;s[Hi.HIERARCHY]=Hi._loadHierarchy,s[Hi.MESH]=Hi._loadMesh,s[Hi.MATERIAL]=Hi._loadMaterial,s[Hi.TEXTURECUBE]=Hi._loadTextureCube,s[Hi.TEXTURECUBEBIN]=Hi._loadTextureCubeBin,s[Hi.TEXTURE2D]=Hi._loadTexture2D,s[Hi.ANIMATIONCLIP]=Hi._loadAnimationClip,s[Hi.AVATAR]=Hi._loadAvatar,s[Hi.SIMPLEANIMATORBIN]=Hi._loadSimpleAnimator,Hi._innerFirstLevelLoaderManager.on(t.Event.ERROR,null,Hi._eventLoadManagerError),Hi._innerSecondLevelLoaderManager.on(t.Event.ERROR,null,Hi._eventLoadManagerError),Hi._innerThirdLevelLoaderManager.on(t.Event.ERROR,null,Hi._eventLoadManagerError),Hi._innerFourthLevelLoaderManager.on(t.Event.ERROR,null,Hi._eventLoadManagerError)}else alert("Laya3D init error,must support webGL!")}static enableNative3D(){var e=me,r=Rt;t.Render.supportWebGLPlusRendering&&(e.prototype._initData=e.prototype._initDataForNative,e.prototype.setBool=e.prototype.setBoolForNative,e.prototype.getBool=e.prototype.getBoolForNative,e.prototype.setInt=e.prototype.setIntForNative,e.prototype.getInt=e.prototype.getIntForNative,e.prototype.setNumber=e.prototype.setNumberForNative,e.prototype.getNumber=e.prototype.getNumberForNative,e.prototype.setVector=e.prototype.setVectorForNative,e.prototype.getVector=e.prototype.getVectorForNative,e.prototype.setVector2=e.prototype.setVector2ForNative,e.prototype.getVector2=e.prototype.getVector2ForNative,e.prototype.setVector3=e.prototype.setVector3ForNative,e.prototype.getVector3=e.prototype.getVector3ForNative,e.prototype.setQuaternion=e.prototype.setQuaternionForNative,e.prototype.getQuaternion=e.prototype.getQuaternionForNative,e.prototype.setMatrix4x4=e.prototype.setMatrix4x4ForNative,e.prototype.getMatrix4x4=e.prototype.getMatrix4x4ForNative,e.prototype.setBuffer=e.prototype.setBufferForNative,e.prototype.getBuffer=e.prototype.getBufferForNative,e.prototype.setTexture=e.prototype.setTextureForNative,e.prototype.getTexture=e.prototype.getTextureForNative,e.prototype.setAttribute=e.prototype.setAttributeForNative,e.prototype.getAttribute=e.prototype.getAttributeForNative,e.prototype.cloneTo=e.prototype.cloneToForNative,e.prototype.getData=e.prototype.getDataForNative,r.prototype._uniformMatrix2fv=r.prototype._uniformMatrix2fvForNative,r.prototype._uniformMatrix3fv=r.prototype._uniformMatrix3fvForNative,r.prototype._uniformMatrix4fv=r.prototype._uniformMatrix4fvForNative,t.LayaGLRunner.uploadShaderUniforms=t.LayaGLRunner.uploadShaderUniformsForNative)}static formatRelativePath(e,t){var r;if(r=e+t,"."===t.charAt(0)){for(var i=r.split("/"),a=0,n=i.length;a<n;a++)if(".."==i[a]){var s=a-1;s>0&&".."!==i[s]&&(i.splice(s,2),a-=2)}r=i.join("/")}return r}static _endLoad(e,r=null,i=null){if(i)for(var a=0,n=i.length;a<n;a++){var s=t.Loader.getRes(i[a]);s&&s._removeReference()}e.endLoad(r)}static _eventLoadManagerError(e){t.Laya.loader.event(t.Event.ERROR,e)}static _addHierarchyInnerUrls(e,t,r,i,a,n,s=null,o=null){var l=Hi.formatRelativePath(i,a);return r&&(l+=r),e.push({url:l,type:n,constructParams:s,propertyParams:o}),t.push(l),l}static _getSprite3DHierarchyInnerUrls(e,t,r,i,a,n,s,o){var l,_,h=e.props;switch(e.type){case"Scene3D":var c=h.lightmaps;for(l=0,_=c.length;l<_;l++){var d=c[l];if(d.path)d.path=Hi._addHierarchyInnerUrls(a,n,s,o,d.path,Hi.TEXTURE2D,d.constructParams,d.propertyParams);else{var u=d.color;u.path=Hi._addHierarchyInnerUrls(a,n,s,o,u.path,Hi.TEXTURE2D,u.constructParams,u.propertyParams);var m=d.direction;m&&(m.path=Hi._addHierarchyInnerUrls(a,n,s,o,m.path,Hi.TEXTURE2D,m.constructParams,m.propertyParams))}}var f=h.reflectionTexture;f&&(h.reflection=Hi._addHierarchyInnerUrls(i,n,s,o,f,Hi.TEXTURECUBE));var T=h.reflection;if(T&&(h.reflection=Hi._addHierarchyInnerUrls(a,n,s,o,T,Hi.TEXTURECUBEBIN)),h.sky){var E=h.sky.material;E&&(E.path=Hi._addHierarchyInnerUrls(r,n,s,o,E.path,Hi.MATERIAL))}break;case"Camera":var p=h.skyboxMaterial;p&&(p.path=Hi._addHierarchyInnerUrls(r,n,s,o,p.path,Hi.MATERIAL));break;case"TrailSprite3D":case"MeshSprite3D":case"SkinnedMeshSprite3D":case"SimpleSkinnedMeshSprite3D":var g=h.meshPath;g&&(h.meshPath=Hi._addHierarchyInnerUrls(t,n,s,o,g,Hi.MESH));var S=h.materials;if(S)for(l=0,_=S.length;l<_;l++)S[l].path=Hi._addHierarchyInnerUrls(r,n,s,o,S[l].path,Hi.MATERIAL);"SimpleSkinnedMeshSprite3D"==e.type&&h.animatorTexture&&(h.animatorTexture=Hi._addHierarchyInnerUrls(a,n,s,o,h.animatorTexture,Hi.SIMPLEANIMATORBIN));break;case"ShuriKenParticle3D":if(h.main){var R=h.renderer.resources,v=R.mesh,x=R.material;v&&(R.mesh=Hi._addHierarchyInnerUrls(t,n,s,o,v,Hi.MESH)),x&&(R.material=Hi._addHierarchyInnerUrls(r,n,s,o,x,Hi.MATERIAL))}else{var A=h.meshPath;A&&(h.meshPath=Hi._addHierarchyInnerUrls(t,n,s,o,A,Hi.MESH)),h.material.path=Hi._addHierarchyInnerUrls(r,n,s,o,h.material.path,Hi.MATERIAL)}break;case"Terrain":Hi._addHierarchyInnerUrls(a,n,s,o,h.dataPath,Hi.TERRAINRES);break;case"ReflectionProbe":var I=h.reflection;I&&(h.reflection=Hi._addHierarchyInnerUrls(t,n,s,o,I,Hi.TEXTURECUBEBIN))}var M=e.components;if(M)for(var D=0,C=M.length;D<C;D++){var y=M[D];switch(y.type){case"Animator":y.avatarPath;var L=y.avatar;L&&(L.path=Hi._addHierarchyInnerUrls(a,n,s,o,L.path,Hi.AVATAR));var O=y.clipPaths;if(O)for(l=0,_=O.length;l<_;l++)O[l]=Hi._addHierarchyInnerUrls(a,n,s,o,O[l],Hi.ANIMATIONCLIP);else{var N=y.layers;for(l=0;l<N.length;l++)for(var P=N[l].states,b=0,w=P.length;b<w;b++){var V=P[b].clipPath;V&&(P[b].clipPath=Hi._addHierarchyInnerUrls(a,n,s,o,V,Hi.ANIMATIONCLIP))}}break;case"PhysicsCollider":case"Rigidbody3D":case"CharacterController":var B=y.shapes;for(l=0;l<B.length;l++){var F=B[l];if("MeshColliderShape"===F.type)(v=F.mesh)&&(F.mesh=Hi._addHierarchyInnerUrls(t,n,s,o,v,Hi.MESH))}}}var U=e.child;for(l=0,_=U.length;l<_;l++)Hi._getSprite3DHierarchyInnerUrls(U[l],t,r,i,a,n,s,o)}static _loadHierarchy(e){e._originType=e.type,e.on(t.Event.LOADED,null,Hi._onHierarchylhLoaded,[e]),e.load(e.url,t.Loader.JSON,!1,null,!0)}static _onHierarchylhLoaded(e,r){var i=e.url,a=H.getURLVerion(i),n=t.URL.getPath(i),s=[],o=[],l=[],_=[],h=[];Hi._getSprite3DHierarchyInnerUrls(r.data,s,o,l,_,h,a,n);var c=s.length+o.length+_.length,d=c+1,u=1/d;if(Hi._onProcessChange(e,0,u,1),_.length>0){var m=c/d,f=t.Handler.create(null,Hi._onProcessChange,[e,u,m],!1);Hi._innerFourthLevelLoaderManager._create(_,!1,t.Handler.create(null,Hi._onHierarchyInnerForthLevResouLoaded,[e,f,r,h,s,o,l,u+m*_.length,m]),f,null,null,null,1,!0)}else Hi._onHierarchyInnerForthLevResouLoaded(e,null,r,h,s,o,l,u,m)}static _onHierarchyInnerForthLevResouLoaded(e,r,i,a,n,s,o,l,_){if(r&&r.recover(),o.length>0){var h=t.Handler.create(null,Hi._onProcessChange,[e,l,_],!1);Hi._innerThirdLevelLoaderManager._create(o,!1,t.Handler.create(null,Hi._onHierarchyInnerThirdLevResouLoaded,[e,h,i,a,n,s,l+_*s.length,_]),r,null,null,null,1,!0)}else Hi._onHierarchyInnerThirdLevResouLoaded(e,null,i,a,n,s,l,_)}static _onHierarchyInnerThirdLevResouLoaded(e,r,i,a,n,s,o,l){if(r&&r.recover(),s.length>0){var _=t.Handler.create(null,Hi._onProcessChange,[e,o,l],!1);Hi._innerSecondLevelLoaderManager._create(s,!1,t.Handler.create(null,Hi._onHierarchyInnerSecondLevResouLoaded,[e,_,i,a,n,o+l*s.length,l]),r,null,null,null,1,!0)}else Hi._onHierarchyInnerSecondLevResouLoaded(e,null,i,a,n,o,l)}static _onHierarchyInnerSecondLevResouLoaded(e,r,i,a,n,s,o){if(r&&r.recover(),n.length>0){var l=t.Handler.create(null,Hi._onProcessChange,[e,s,o],!1);Hi._innerFirstLevelLoaderManager._create(n,!1,t.Handler.create(null,Hi._onHierarchyInnerFirstLevResouLoaded,[e,l,i,a]),r,null,null,null,1,!0)}else Hi._onHierarchyInnerFirstLevResouLoaded(e,null,i,a)}static _onHierarchyInnerFirstLevResouLoaded(e,t,r,i){t&&t.recover(),e._cache=e._createCache;var a="Scene3D"===r.data.type?bi._parseScene(r,e._propertyParams,e._constructParams):bi._parse(r,e._propertyParams,e._constructParams);Hi._endLoad(e,a,i)}static _loadMesh(e){e.on(t.Event.LOADED,null,Hi._onMeshLmLoaded,[e]),e.load(e.url,t.Loader.BUFFER,!1,null,!0)}static _onMeshLmLoaded(e,t){e._cache=e._createCache;var r=Bi._parse(t,e._propertyParams,e._constructParams);Hi._endLoad(e,r)}static _loadMaterial(e){e.on(t.Event.LOADED,null,Hi._onMaterilLmatLoaded,[e]),e.load(e.url,t.Loader.JSON,!1,null,!0)}static _onMaterilLmatLoaded(e,r){var i,a=e.url,n=H.getURLVerion(a),s=t.URL.getPath(a),o=[],l=[];r.customProps;switch(r.version){case"LAYAMATERIAL:01":case"LAYAMATERIAL:02":var _,h,c=r.props.textures;if(c)for(_=0,h=c.length;_<h;_++){var d=c[_],u=d.path;u&&(i=Hi.formatRelativePath(s,u),n&&(i+=n),o.push({url:i,constructParams:d.constructParams,propertyParams:d.propertyParams}),l.push(i),d.path=i)}break;default:throw new Error("Laya3D:unkonwn version.")}var m=o.length,f=m+1,T=1/f;if(Hi._onProcessChange(e,0,T,1),m>0){var E=t.Handler.create(null,Hi._onProcessChange,[e,T,m/f],!1);Hi._innerFourthLevelLoaderManager._create(o,!1,t.Handler.create(null,Hi._onMateialTexturesLoaded,[e,E,r,l]),E,null,null,null,1,!0)}else Hi._onMateialTexturesLoaded(e,null,r,null)}static _onMateialTexturesLoaded(e,t,r,i){e._cache=e._createCache;var a=st._parse(r,e._propertyParams,e._constructParams);Hi._endLoad(e,a,i),t&&t.recover()}static _loadAvatar(e){e.on(t.Event.LOADED,null,(function(t){e._cache=e._createCache;var r=nt._parse(t,e._propertyParams,e._constructParams);Hi._endLoad(e,r)})),e.load(e.url,t.Loader.JSON,!1,null,!0)}static _loadSimpleAnimator(e){e.on(t.Event.LOADED,null,(function(r){e._cache=e._createCache;var i=t.Texture2D._SimpleAnimatorTextureParse(r,e._propertyParams,e._constructParams);Hi._endLoad(e,i)})),e.load(e.url,t.Loader.BUFFER,!1,null,!0)}static _loadAnimationClip(e){e.on(t.Event.LOADED,null,(function(t){e._cache=e._createCache;var r=ie._parse(t);Hi._endLoad(e,r)})),e.load(e.url,t.Loader.BUFFER,!1,null,!0)}static _loadTexture2D(e){var r,i=e.url,a=i.lastIndexOf(".")+1,n=i.indexOf("?"),s=-1==n?i.length:n;switch(i.substr(a,s-a)){case"jpg":case"jpeg":case"bmp":case"gif":case"png":r="nativeimage";break;case"dds":case"ktx":case"pvr":r=t.Loader.BUFFER}e.on(t.Event.LOADED,null,(function(r){e._cache=e._createCache;var i=t.Texture2D._parse(r,e._propertyParams,e._constructParams);Hi._endLoad(e,i)})),e.load(e.url,r,!1,null,!0)}static _loadTextureCube(e){e.on(t.Event.LOADED,null,Hi._onTextureCubeLtcLoaded,[e]),e.load(e.url,t.Loader.JSON,!1,null,!0)}static _loadTextureCubeBin(e){e.on(t.Event.LOADED,null,r=>{e._cache=e._createCache;var i=new t.Byte(r);if("LAYATEXTURECUBE:0000"!==i.readUTFString())throw"Laya3D:unknow version.";var a=i.readUint8(),n=i.getUint8(),s=i.readUint16(),o=i.getUint8(),l=i.getUint8(),_=i.getUint8(),h=i.getUint8(),c=new bt(s,a,n>1);c.filterMode=o,c.wrapModeU=l,c.wrapModeV=_,c.anisoLevel=h;for(var d=i.pos,u=s,m=0;m<n;m++){for(var f=new Array(6),T=u*u*c._getFormatByteCount(),E=0;E<6;E++)f[E]=new Uint8Array(r,d,T),d+=T;c.setSixSidePixels(f,m),u/=2}Hi._endLoad(e,c)}),e.load(e.url,t.Loader.BUFFER,!1,null,!0)}static _onTextureCubeLtcLoaded(e,r){var i=t.URL.getPath(e.url),a=[Hi.formatRelativePath(i,r.front),Hi.formatRelativePath(i,r.back),Hi.formatRelativePath(i,r.left),Hi.formatRelativePath(i,r.right),Hi.formatRelativePath(i,r.up),Hi.formatRelativePath(i,r.down)];Hi._onProcessChange(e,0,1/7,1);var n=t.Handler.create(null,Hi._onProcessChange,[e,1/7,6/7],!1);Hi._innerFourthLevelLoaderManager.load(a,t.Handler.create(null,Hi._onTextureCubeImagesLoaded,[e,a,n]),n,"nativeimage")}static _onTextureCubeImagesLoaded(e,r,i){for(var a=new Array(6),n=0;n<6;n++)a[n]=t.Loader.getRes(r[n]);e._cache=e._createCache;var s=bt._parse(a,e._propertyParams,e._constructParams);for(i.recover(),n=0;n<6;n++)t.Loader.clearRes(r[n]);Hi._endLoad(e,s)}static _onProcessChange(e,r,i,a){(a=r+a*i)<1&&e.event(t.Event.PROGRESS,2*a/3+1/3)}static init(e,t,r=null,i=null){if(Hi._isInit)i&&i.run();else{Hi._isInit=!0,r&&r.cloneTo(j._config),r=j._config,Mt.debugFrustumCulling=r.debugFrustumCulling,Hi._editerEnvironment=r._editerEnvironment,dr.octreeCulling=r.octreeCulling,dr.octreeInitialSize=r.octreeInitialSize,dr.octreeInitialCenter=r.octreeInitialCenter,dr.octreeMinNodeSize=r.octreeMinNodeSize,dr.octreeLooseness=r.octreeLooseness;var a=window.Physics3D;null==a||r.isUseCannonPhysicsEngine?(Y._enablePhysics=!1,Hi.__init__(e,t,r),i&&i.run()):(Y._enablePhysics=!0,a(16*r.defaultPhysicsMemory,Ri._interactive).then((function(){Hi.__init__(e,t,r),i&&i.run()})))}}}Hi.HIERARCHY="HIERARCHY",Hi.MESH="MESH",Hi.MATERIAL="MATERIAL",Hi.TEXTURE2D="TEXTURE2D",Hi.TEXTURECUBE="TEXTURECUBE",Hi.TEXTURECUBEBIN="TEXTURECUBEBIN",Hi.ANIMATIONCLIP="ANIMATIONCLIP",Hi.AVATAR="AVATAR",Hi.TERRAINHEIGHTDATA="TERRAINHEIGHTDATA",Hi.TERRAINRES="TERRAIN",Hi.SIMPLEANIMATORBIN="SIMPLEANIMATOR",Hi._innerFirstLevelLoaderManager=new t.LoaderManager,Hi._innerSecondLevelLoaderManager=new t.LoaderManager,Hi._innerThirdLevelLoaderManager=new t.LoaderManager,Hi._innerFourthLevelLoaderManager=new t.LoaderManager,Hi._isInit=!1,Hi._editerEnvironment=!1,Hi.physicsSettings=new Ot,window.Laya3D=Hi;class ki extends t.Component{constructor(){super(...arguments),this._indexInPool=-1}get isSingleton(){return!1}_checkProcessTriggers(){var e=ki.prototype;return this.onTriggerEnter!==e.onTriggerEnter||(this.onTriggerStay!==e.onTriggerStay||this.onTriggerExit!==e.onTriggerExit)}_checkProcessCollisions(){var e=ki.prototype;return this.onCollisionEnter!==e.onCollisionEnter||(this.onCollisionStay!==e.onCollisionStay||this.onCollisionExit!==e.onCollisionExit)}_onAwake(){this.onAwake(),this.onStart!==ki.prototype.onStart&&t.Laya.startTimer.callLater(this,this.onStart)}_onEnable(){this.owner._scene._addScript(this),this.onEnable()}_onDisable(){this.owner._scene._removeScript(this),this.owner.offAllCaller(this),this.onDisable()}_onDestroy(){var e=this.owner._scripts;e.splice(e.indexOf(this),1);var t=this.owner;t._needProcessTriggers=!1;for(var r=0,i=e.length;r<i;r++)if(e[r]._checkProcessTriggers()){t._needProcessTriggers=!0;break}for(t._needProcessCollisions=!1,r=0,i=e.length;r<i;r++)if(e[r]._checkProcessCollisions()){t._needProcessCollisions=!0;break}this.onDestroy()}_isScript(){return!0}_onAdded(){var e=this.owner,t=e._scripts;t||(e._scripts=t=[]),t.push(this),e._needProcessCollisions||(e._needProcessCollisions=this._checkProcessCollisions()),e._needProcessTriggers||(e._needProcessTriggers=this._checkProcessTriggers())}onAwake(){}onEnable(){}onStart(){}onTriggerEnter(e){}onTriggerStay(e){}onTriggerExit(e){}onCollisionEnter(e){}onCollisionStay(e){}onCollisionExit(e){}onJointBreak(){}onMouseDown(){}onMouseDrag(){}onMouseClick(){}onMouseUp(){}onMouseEnter(){}onMouseOver(){}onMouseOut(){}onUpdate(){}onLateUpdate(){}onPreRender(){}onPostRender(){}onDisable(){}onDestroy(){}}class Wi{constructor(e,t,r,i){this._datas=[],this._w=e,this._h=t,this._minHeight=r,this._maxHeight=i}static creatFromMesh(e,t,r,i){for(var a=[],s=[],o=e.subMeshCount,l=0;l<o;l++){for(var _=e.getSubMesh(l),h=_._vertexBuffer,c=h.getFloat32Data(),d=[],u=0;u<c.length;u+=h.vertexDeclaration.vertexStride/4){var m=new n(c[u+0],c[u+1],c[u+2]);d.push(m)}a.push(d);var f=_._indexBuffer;s.push(f.getData())}var T=e.bounds,E=T.getMin().x,p=T.getMin().z,g=T.getMax().x,S=T.getMax().z,R=T.getMin().y,v=T.getMax().y,x=g-E,A=S-p,I=i.x=x/(t-1),M=i.y=A/(r-1),D=new Wi(t,r,R,v),C=Wi._tempRay,y=C.direction;y.x=0,y.y=-1,y.z=0;var L=v+.1;C.origin.y=L;for(var O=0;O<r;O++){var N=p+O*M;D._datas[O]=[];for(var P=0;P<t;P++){var b=E+P*I,w=C.origin;w.x=b,w.z=N;var V=Wi._getPosition(C,a,s);D._datas[O][P]=V===Number.MAX_VALUE?NaN:L-V}}return D}static createFromImage(e,t,r){for(var i=e.width,a=e.height,n=new Wi(i,a,t,r),s=(r-t)/254,o=e.getPixels(),l=0,_=0;_<a;_++)for(var h=n._datas[_]=[],c=0;c<i;c++){var d=o[l++],u=o[l++],m=o[l++],f=o[l++];h[c]=255==d&&255==u&&255==m&&255==f?NaN:(d+u+m)/3*s+t}return n}static _getPosition(e,t,r){for(var i=Number.MAX_VALUE,a=0;a<t.length;a++)for(var n=t[a],s=r[a],o=0;o<s.length;o+=3){var l=n[s[o+0]],_=n[s[o+1]],h=n[s[o+2]],c=Ue.rayIntersectsTriangle(e,l,_,h);!isNaN(c)&&c<i&&(i=c)}return i}get width(){return this._w}get height(){return this._h}get maxHeight(){return this._maxHeight}get minHeight(){return this._minHeight}_inBounds(e,t){return e>=0&&e<this._h&&t>=0&&t<this._w}getHeight(e,t){return this._inBounds(e,t)?this._datas[e][t]:NaN}}Wi._tempRay=new be(new n,new n);class Xi extends yr{constructor(e,t,r=null){super(e,r),this._heightMap=t,this._cellSize=new i}static createFromMesh(e,t,r,i=null){var a=new Xi(e,null,i);return a._initCreateFromMesh(t,r),a}static createFromMeshAndHeightMap(e,t,r,i,a=null){var n=new Xi(e,null,a);return n._initCreateFromMeshHeightMap(t,r,i),n}get minX(){var e=this.transform.worldMatrix.elements;return this._minX*this._getScaleX()+e[12]}get minZ(){var e=this.transform.worldMatrix.elements;return this._minZ*this._getScaleZ()+e[14]}get width(){return(this._heightMap.width-1)*this._cellSize.x*this._getScaleX()}get depth(){return(this._heightMap.height-1)*this._cellSize.y*this._getScaleZ()}_disableRotation(){var e=this.transform.rotation;e.x=0,e.y=0,e.z=0,e.w=1,this.transform.rotation=e}_getScaleX(){var e=this.transform.worldMatrix.elements,t=e[0],r=e[1],i=e[2];return Math.sqrt(t*t+r*r+i*i)}_getScaleZ(){var e=this.transform.worldMatrix.elements,t=e[8],r=e[9],i=e[10];return Math.sqrt(t*t+r*r+i*i)}_initCreateFromMesh(e,t){this._heightMap=Wi.creatFromMesh(this.meshFilter.sharedMesh,e,t,this._cellSize);var r=this.meshFilter.sharedMesh.bounds,i=r.getMin();r.getMax();this._minX=i.x,this._minZ=i.z}_initCreateFromMeshHeightMap(e,t,r){var i=this.meshFilter.sharedMesh.bounds;this._heightMap=Wi.createFromImage(e,t,r),this._computeCellSize(i);var a=i.getMin();i.getMax();this._minX=a.x,this._minZ=a.z}_computeCellSize(e){var t=e.getMin(),r=e.getMax(),i=t.x,a=t.z,n=r.x-i,s=r.z-a;this._cellSize.x=n/(this._heightMap.width-1),this._cellSize.y=s/(this._heightMap.height-1)}_update(e){this._disableRotation()}getHeight(e,t){Xi._tempVector3.x=e,Xi._tempVector3.y=0,Xi._tempVector3.z=t,this._disableRotation();var r=this.transform.worldMatrix;r.invert(Xi._tempMatrix4x4),n.transformCoordinate(Xi._tempVector3,Xi._tempMatrix4x4,Xi._tempVector3),e=Xi._tempVector3.x,t=Xi._tempVector3.z;var i=(e-this._minX)/this._cellSize.x,a=(t-this._minZ)/this._cellSize.y,s=Math.floor(a),o=Math.floor(i),l=i-o,_=a-s,h=r.elements,c=h[4],d=h[5],u=h[6],m=Math.sqrt(c*c+d*d+u*u),f=h[13],T=this._heightMap.getHeight(s,o+1),E=this._heightMap.getHeight(s+1,o);if(isNaN(T)||isNaN(E))return NaN;if(l+_<=1){var p=this._heightMap.getHeight(s,o);return isNaN(p)?NaN:(p+l*(T-p)+_*(E-p))*m+f}var g=this._heightMap.getHeight(s+1,o+1);return isNaN(g)?NaN:(g+(1-l)*(E-g)+(1-_)*(T-g))*m+f}}Xi._tempVector3=new n,Xi._tempMatrix4x4=new R;class Yi{constructor(){this._currentLength=0,this._elements=new Float32Array(12)}get gradientCount(){return this._currentLength/3}add(e,t){this._currentLength<8?(6===this._currentLength&&1!==e&&(e=1,console.log("GradientDataVector2 warning:the forth key is be force set to 1.")),this._elements[this._currentLength++]=e,this._elements[this._currentLength++]=t.x,this._elements[this._currentLength++]=t.y):console.log("GradientDataVector2 warning:data count must lessEqual than 4")}cloneTo(e){var t=e;t._currentLength=this._currentLength;for(var r=t._elements,i=0,a=this._elements.length;i<a;i++)r[i]=this._elements[i]}clone(){var e=new Yi;return this.cloneTo(e),e}}class ji{constructor(){}render(e){}}class Zi extends ji{constructor(){super(),this._shader=null,this._shaderData=new me,this._linearColor=new xt,this._bloomTextureTexelSize=new a,this._shaderThreshold=new a,this._shaderParams=new a,this._pyramid=null,this._intensity=0,this._threshold=1,this._softKnee=.5,this._diffusion=7,this._anamorphicRatio=0,this._dirtIntensity=0,this._shaderSetting=new a,this._dirtTileOffset=new a,this.clamp=65472,this.color=new xt(1,1,1,1),this.fastMode=!1,this.dirtTexture=null,this._shader=xe.find("PostProcessBloom"),this._pyramid=new Array(2*Zi.MAXPYRAMIDSIZE)}get intensity(){return this._intensity}set intensity(e){this._intensity=Math.max(e,0)}get threshold(){return this._threshold}set threshold(e){this._threshold=Math.max(e,0)}get softKnee(){return this._softKnee}set softKnee(e){this._softKnee=Math.min(Math.max(e,0),1)}get diffusion(){return this._diffusion}set diffusion(e){this._diffusion=Math.min(Math.max(e,1),10)}get anamorphicRatio(){return this._anamorphicRatio}set anamorphicRatio(e){this._anamorphicRatio=Math.min(Math.max(e,-1),1)}get dirtIntensity(){return this._dirtIntensity}set dirtIntensity(e){this._dirtIntensity=Math.max(e,0)}render(e){var r=e.command,i=e.camera.viewport;this._shaderData.setTexture(Zi.SHADERVALUE_AUTOEXPOSURETEX,t.Texture2D.whiteTexture);var n,s=this._anamorphicRatio,o=s<0?-s:0,l=s>0?s:0,_=Math.floor(i.width/(2-o)),h=Math.floor(i.height/(2-l)),c=Math.max(_,h);n=Math.log2(c)+this._diffusion-10;var d=Math.floor(n),u=Math.min(Math.max(d,1),Zi.MAXPYRAMIDSIZE),m=.5+n-d;this._shaderData.setNumber(Zi.SHADERVALUE_SAMPLESCALE,m);var f=xt.gammaToLinearSpace(this.threshold),T=f*this._softKnee+1e-5;this._shaderThreshold.setValue(f,f-T,2*T,.25/T),this._shaderData.setVector(Zi.SHADERVALUE_THRESHOLD,this._shaderThreshold);var E=xt.gammaToLinearSpace(this.clamp);this._shaderParams.setValue(E,0,0,0),this._shaderData.setVector(Zi.SHADERVALUE_PARAMS,this._shaderParams);for(var p=this.fastMode?1:0,g=e.source,S=0;S<u;S++){var R=2*S,v=R+1,x=0==S?Zi.SUBSHADER_PREFILTER13+p:Zi.SUBSHADER_DOWNSAMPLE13+p,A=he.createFromPool(_,h,t.RenderTextureFormat.R8G8B8,t.RenderTextureDepthFormat.DEPTHSTENCIL_NONE);if(A.filterMode=t.FilterMode.Bilinear,this._pyramid[R]=A,S!==u-1){var I=he.createFromPool(_,h,t.RenderTextureFormat.R8G8B8,t.RenderTextureDepthFormat.DEPTHSTENCIL_NONE);I.filterMode=t.FilterMode.Bilinear,this._pyramid[v]=I}r.blitScreenTriangle(g,A,null,this._shader,this._shaderData,x),g=A,_=Math.max(Math.floor(_/2),1),h=Math.max(Math.floor(h/2),1)}var M=this._pyramid[2*(u-1)];for(S=u-2;S>=0;S--)v=(R=2*S)+1,A=this._pyramid[R],I=this._pyramid[v],r.setShaderDataTexture(this._shaderData,Zi.SHADERVALUE_BLOOMTEX,A),r.blitScreenTriangle(M,I,null,this._shader,this._shaderData,Zi.SUBSHADER_UPSAMPLETENT+p),M=I;var D=this._linearColor;this.color.toLinear(D);var C=Math.pow(2,this._intensity/10)-1,y=this._shaderSetting;this._shaderSetting.setValue(m,C,this._dirtIntensity,u);var L=this.dirtTexture?this.dirtTexture:t.Texture2D.blackTexture,O=L.width/L.height,N=i.width/i.height,P=this._dirtTileOffset;O>N?P.setValue(N/O,1,.5*(1-P.x),0):O<N&&P.setValue(1,O/N,0,.5*(1-P.y));var b=e.compositeShaderData;for(this.fastMode?b.addDefine(rt.SHADERDEFINE_BLOOM_LOW):b.addDefine(rt.SHADERDEFINE_BLOOM),this._bloomTextureTexelSize.setValue(1/M.width,1/M.height,M.width,M.height),b.setVector(rt.SHADERVALUE_BLOOM_DIRTTILEOFFSET,P),b.setVector(rt.SHADERVALUE_BLOOM_SETTINGS,y),b.setVector(rt.SHADERVALUE_BLOOM_COLOR,new a(D.r,D.g,D.b,D.a)),b.setTexture(rt.SHADERVALUE_BLOOM_DIRTTEX,L),b.setTexture(rt.SHADERVALUE_BLOOMTEX,M),b.setVector(rt.SHADERVALUE_BLOOMTEX_TEXELSIZE,this._bloomTextureTexelSize),S=0;S<u;S++)v=(R=2*S)+1,he.recoverToPool(this._pyramid[R]),0!==S&&S!==u-1&&he.recoverToPool(this._pyramid[v]);e.deferredReleaseTextures.push(M)}}Zi.SHADERVALUE_MAINTEX=xe.propertyNameToID("u_MainTex"),Zi.SHADERVALUE_AUTOEXPOSURETEX=xe.propertyNameToID("u_AutoExposureTex"),Zi.SHADERVALUE_SAMPLESCALE=xe.propertyNameToID("u_SampleScale"),Zi.SHADERVALUE_THRESHOLD=xe.propertyNameToID("u_Threshold"),Zi.SHADERVALUE_PARAMS=xe.propertyNameToID("u_Params"),Zi.SHADERVALUE_BLOOMTEX=xe.propertyNameToID("u_BloomTex"),Zi.SUBSHADER_PREFILTER13=0,Zi.SUBSHADER_PREFILTER4=1,Zi.SUBSHADER_DOWNSAMPLE13=2,Zi.SUBSHADER_DOWNSAMPLE4=3,Zi.SUBSHADER_UPSAMPLETENT=4,Zi.SUBSHADER_UPSAMPLEBOX=5,Zi.MAXPYRAMIDSIZE=16;class qi{constructor(e=0,t=0,r=0,i=0){var a=this.elements=new Float32Array(4);a[0]=e,a[1]=t,a[2]=r,a[3]=i}get x(){return this.elements[0]}set x(e){this.elements[0]=e}get y(){return this.elements[1]}set y(e){this.elements[1]=e}get z(){return this.elements[2]}set z(e){this.elements[2]=e}get w(){return this.elements[3]}set w(e){this.elements[3]=e}fromArray(e,t=0){this.elements[0]=e[t+0],this.elements[1]=e[t+1],this.elements[2]=e[t+2],this.elements[3]=e[t+3]}cloneTo(e){var t=e.elements,r=this.elements;t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3]}clone(){var e=new qi;return this.cloneTo(e),e}static lerp(e,t,r,i){var a=i.elements,n=e.elements,s=t.elements,o=n[0],l=n[1],_=n[2],h=n[3];a[0]=o+r*(s[0]-o),a[1]=l+r*(s[1]-l),a[2]=_+r*(s[2]-_),a[3]=h+r*(s[3]-h)}static transformByM4x4(e,t,r){var i=e.elements,a=i[0],n=i[1],s=i[2],o=i[3],l=t.elements,_=r.elements;_[0]=a*l[0]+n*l[4]+s*l[8]+o*l[12],_[1]=a*l[1]+n*l[5]+s*l[9]+o*l[13],_[2]=a*l[2]+n*l[6]+s*l[10]+o*l[14],_[3]=a*l[3]+n*l[7]+s*l[11]+o*l[15]}static equals(e,t){var i=e.elements,a=t.elements;return r.nearEqual(Math.abs(i[0]),Math.abs(a[0]))&&r.nearEqual(Math.abs(i[1]),Math.abs(a[1]))&&r.nearEqual(Math.abs(i[2]),Math.abs(a[2]))&&r.nearEqual(Math.abs(i[3]),Math.abs(a[3]))}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}lengthSquared(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}static normalize(e,t){var r=e.elements,i=t.elements,a=e.length();a>0&&(i[0]=r[0]*a,i[1]=r[1]*a,i[2]=r[2]*a,i[3]=r[3]*a)}static add(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=a[0]+n[0],i[1]=a[1]+n[1],i[2]=a[2]+n[2],i[3]=a[3]+n[3]}static subtract(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=a[0]-n[0],i[1]=a[1]-n[1],i[2]=a[2]-n[2],i[3]=a[3]-n[3]}static multiply(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=a[0]*n[0],i[1]=a[1]*n[1],i[2]=a[2]*n[2],i[3]=a[3]*n[3]}static scale(e,t,r){var i=r.elements,a=e.elements;i[0]=a[0]*t,i[1]=a[1]*t,i[2]=a[2]*t,i[3]=a[3]*t}static Clamp(e,t,r,i){var a=e.elements,n=a[0],s=a[1],o=a[2],l=a[3],_=t.elements,h=_[0],c=_[1],d=_[2],u=_[3],m=r.elements,f=m[0],T=m[1],E=m[2],p=m[3],g=i.elements;n=(n=n>f?f:n)<h?h:n,s=(s=s>T?T:s)<c?c:s,o=(o=o>E?E:o)<d?d:o,l=(l=l>p?p:l)<u?u:l,g[0]=n,g[1]=s,g[2]=o,g[3]=l}static distanceSquared(e,t){var r=e.elements,i=t.elements,a=r[0]-i[0],n=r[1]-i[1],s=r[2]-i[2],o=r[3]-i[3];return a*a+n*n+s*s+o*o}static distance(e,t){var r=e.elements,i=t.elements,a=r[0]-i[0],n=r[1]-i[1],s=r[2]-i[2],o=r[3]-i[3];return Math.sqrt(a*a+n*n+s*s+o*o)}static dot(e,t){var r=e.elements,i=t.elements;return r[0]*i[0]+r[1]*i[1]+r[2]*i[2]+r[3]*i[3]}static min(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=Math.min(a[0],n[0]),i[1]=Math.min(a[1],n[1]),i[2]=Math.min(a[2],n[2]),i[3]=Math.min(a[3],n[3])}static max(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=Math.max(a[0],n[0]),i[1]=Math.max(a[1],n[1]),i[2]=Math.max(a[2],n[2]),i[3]=Math.max(a[3],n[3])}}qi.ZERO=new qi,qi.ONE=new qi(1,1,1,1),qi.UnitX=new qi(1,0,0,0),qi.UnitY=new qi(0,1,0,0),qi.UnitZ=new qi(0,0,1,0),qi.UnitW=new qi(0,0,0,1);class Qi{constructor(e=0,t=0,r=0,i=null){var a;a=i||new Float32Array(3),this.elements=a,a[0]=e,a[1]=t,a[2]=r}static distanceSquared(e,t){var r=e.elements,i=t.elements,a=r[0]-i[0],n=r[1]-i[1],s=r[2]-i[2];return a*a+n*n+s*s}static distance(e,t){var r=e.elements,i=t.elements,a=r[0]-i[0],n=r[1]-i[1],s=r[2]-i[2];return Math.sqrt(a*a+n*n+s*s)}static min(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=Math.min(a[0],n[0]),i[1]=Math.min(a[1],n[1]),i[2]=Math.min(a[2],n[2])}static max(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=Math.max(a[0],n[0]),i[1]=Math.max(a[1],n[1]),i[2]=Math.max(a[2],n[2])}static transformQuat(e,t,r){var i=r.elements,a=e.elements,n=t.elements,s=a[0],o=a[1],l=a[2],_=n[0],h=n[1],c=n[2],d=n[3],u=d*s+h*l-c*o,m=d*o+c*s-_*l,f=d*l+_*o-h*s,T=-_*s-h*o-c*l;i[0]=u*d+T*-_+m*-c-f*-h,i[1]=m*d+T*-h+f*-_-u*-c,i[2]=f*d+T*-c+u*-h-m*-_}static scalarLength(e){var t=e.elements,r=t[0],i=t[1],a=t[2];return Math.sqrt(r*r+i*i+a*a)}static scalarLengthSquared(e){var t=e.elements,r=t[0],i=t[1],a=t[2];return r*r+i*i+a*a}static normalize(e,t){var r=e.elements,i=t.elements,a=r[0],n=r[1],s=r[2],o=a*a+n*n+s*s;o>0&&(o=1/Math.sqrt(o),i[0]=r[0]*o,i[1]=r[1]*o,i[2]=r[2]*o)}static multiply(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=a[0]*n[0],i[1]=a[1]*n[1],i[2]=a[2]*n[2]}static scale(e,t,r){var i=r.elements,a=e.elements;i[0]=a[0]*t,i[1]=a[1]*t,i[2]=a[2]*t}static lerp(e,t,r,i){var a=i.elements,n=e.elements,s=t.elements,o=n[0],l=n[1],_=n[2];a[0]=o+r*(s[0]-o),a[1]=l+r*(s[1]-l),a[2]=_+r*(s[2]-_)}static transformV3ToV3(e,t,r){var i=Qi._tempVector4;Qi.transformV3ToV4(e,t,i);var a=i.elements,n=r.elements;n[0]=a[0],n[1]=a[1],n[2]=a[2]}static transformV3ToV4(e,t,r){var i=e.elements,a=i[0],n=i[1],s=i[2],o=t.elements,l=r.elements;l[0]=a*o[0]+n*o[4]+s*o[8]+o[12],l[1]=a*o[1]+n*o[5]+s*o[9]+o[13],l[2]=a*o[2]+n*o[6]+s*o[10]+o[14],l[3]=a*o[3]+n*o[7]+s*o[11]+o[15]}static TransformNormal(e,t,r){var i=e.elements,a=i[0],n=i[1],s=i[2],o=t.elements,l=r.elements;l[0]=a*o[0]+n*o[4]+s*o[8],l[1]=a*o[1]+n*o[5]+s*o[9],l[2]=a*o[2]+n*o[6]+s*o[10]}static transformCoordinate(e,t,r){var i=e.elements,a=i[0],n=i[1],s=i[2],o=t.elements,l=a*o[3]+n*o[7]+s*o[11]+o[15],_=r.elements;_[0]=a*o[0]+n*o[4]+s*o[8]+o[12]/l,_[1]=a*o[1]+n*o[5]+s*o[9]+o[13]/l,_[2]=a*o[2]+n*o[6]+s*o[10]+o[14]/l}static Clamp(e,t,r,i){var a=e.elements,n=a[0],s=a[1],o=a[2],l=t.elements,_=l[0],h=l[1],c=l[2],d=r.elements,u=d[0],m=d[1],f=d[2],T=i.elements;n=(n=n>u?u:n)<_?_:n,s=(s=s>m?m:s)<h?h:s,o=(o=o>f?f:o)<c?c:o,T[0]=n,T[1]=s,T[2]=o}static add(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=a[0]+n[0],i[1]=a[1]+n[1],i[2]=a[2]+n[2]}static subtract(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=a[0]-n[0],i[1]=a[1]-n[1],i[2]=a[2]-n[2]}static cross(e,t,r){var i=e.elements,a=t.elements,n=r.elements,s=i[0],o=i[1],l=i[2],_=a[0],h=a[1],c=a[2];n[0]=o*c-l*h,n[1]=l*_-s*c,n[2]=s*h-o*_}static dot(e,t){var r=e.elements,i=t.elements;return r[0]*i[0]+r[1]*i[1]+r[2]*i[2]}static equals(e,t){var i=e.elements,a=t.elements;return r.nearEqual(i[0],a[0])&&r.nearEqual(i[1],a[1])&&r.nearEqual(i[2],a[2])}get x(){return this.elements[0]}set x(e){this.elements[0]=e}get y(){return this.elements[1]}set y(e){this.elements[1]=e}get z(){return this.elements[2]}set z(e){this.elements[2]=e}setValue(e,t,r){this.elements[0]=e,this.elements[1]=t,this.elements[2]=r}fromArray(e,t=0){this.elements[0]=e[t+0],this.elements[1]=e[t+1],this.elements[2]=e[t+2]}cloneTo(e){var t=e.elements,r=this.elements;t[0]=r[0],t[1]=r[1],t[2]=r[2]}clone(){var e=new Qi;return this.cloneTo(e),e}toDefault(){this.elements[0]=0,this.elements[1]=0,this.elements[2]=0}}Qi._tempVector4=new qi,Qi.ZERO=new Qi(0,0,0),Qi.ONE=new Qi(1,1,1),Qi.NegativeUnitX=new Qi(-1,0,0),Qi.UnitX=new Qi(1,0,0),Qi.UnitY=new Qi(0,1,0),Qi.UnitZ=new Qi(0,0,1),Qi.ForwardRH=new Qi(0,0,-1),Qi.ForwardLH=new Qi(0,0,1),Qi.Up=new Qi(0,1,0),Qi.NAN=new Qi(NaN,NaN,NaN);class Ki{constructor(e=0,t=0,r=0,i=1,a=null){var n;(n=a||new Float32Array(4))[0]=e,n[1]=t,n[2]=r,n[3]=i,this.elements=n}static _dotArray(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}static _normalizeArray(e,t){var r=e[0],i=e[1],a=e[2],n=e[3],s=r*r+i*i+a*a+n*n;s>0&&(s=1/Math.sqrt(s),t[0]=r*s,t[1]=i*s,t[2]=a*s,t[3]=n*s)}static _lerpArray(e,t,r,i){var a=1-r;Ki._dotArray(e,t)>=0?(i[0]=a*e[0]+r*t[0],i[1]=a*e[1]+r*t[1],i[2]=a*e[2]+r*t[2],i[3]=a*e[3]+r*t[3]):(i[0]=a*e[0]-r*t[0],i[1]=a*e[1]-r*t[1],i[2]=a*e[2]-r*t[2],i[3]=a*e[3]-r*t[3]),Ki._normalizeArray(i,i)}static createFromYawPitchRoll(e,t,r,i){var a=.5*r,n=.5*t,s=.5*e,o=Math.sin(a),l=Math.cos(a),_=Math.sin(n),h=Math.cos(n),c=Math.sin(s),d=Math.cos(s),u=i.elements;u[0]=d*_*l+c*h*o,u[1]=c*h*l-d*_*o,u[2]=d*h*o-c*_*l,u[3]=d*h*l+c*_*o}static multiply(e,t,r){var i=e.elements,a=t.elements,n=r.elements,s=i[0],o=i[1],l=i[2],_=i[3],h=a[0],c=a[1],d=a[2],u=a[3],m=o*d-l*c,f=l*h-s*d,T=s*c-o*h,E=s*h+o*c+l*d;n[0]=s*u+h*_+m,n[1]=o*u+c*_+f,n[2]=l*u+d*_+T,n[3]=_*u-E}static arcTanAngle(e,t){return 0==e?1==t?Math.PI/2:-Math.PI/2:e>0?Math.atan(t/e):e<0?t>0?Math.atan(t/e)+Math.PI:Math.atan(t/e)-Math.PI:0}static angleTo(e,t,r){Qi.subtract(t,e,Ki.TEMPVector30),Qi.normalize(Ki.TEMPVector30,Ki.TEMPVector30),r.elements[0]=Math.asin(Ki.TEMPVector30.y),r.elements[1]=Ki.arcTanAngle(-Ki.TEMPVector30.z,-Ki.TEMPVector30.x)}static createFromAxisAngle(e,t,r){var i=r.elements,a=e.elements;t*=.5;var n=Math.sin(t);i[0]=n*a[0],i[1]=n*a[1],i[2]=n*a[2],i[3]=Math.cos(t)}static createFromMatrix3x3(e,t){var r,i=t.elements,a=e.elements,n=a[0]+a[4]+a[8];if(n>0)r=Math.sqrt(n+1),i[3]=.5*r,r=.5/r,i[0]=(a[5]-a[7])*r,i[1]=(a[6]-a[2])*r,i[2]=(a[1]-a[3])*r;else{var s=0;a[4]>a[0]&&(s=1),a[8]>a[3*s+s]&&(s=2);var o=(s+1)%3,l=(s+2)%3;r=Math.sqrt(a[3*s+s]-a[3*o+o]-a[3*l+l]+1),i[s]=.5*r,r=.5/r,i[3]=(a[3*o+l]-a[3*l+o])*r,i[o]=(a[3*o+s]+a[3*s+o])*r,i[l]=(a[3*l+s]+a[3*s+l])*r}}static createFromMatrix4x4(e,t){var r,i,a=e.elements,n=t.elements,s=a[0]+a[5]+a[10];s>0?(r=Math.sqrt(s+1),n[3]=.5*r,r=.5/r,n[0]=(a[6]-a[9])*r,n[1]=(a[8]-a[2])*r,n[2]=(a[1]-a[4])*r):a[0]>=a[5]&&a[0]>=a[10]?(i=.5/(r=Math.sqrt(1+a[0]-a[5]-a[10])),n[0]=.5*r,n[1]=(a[1]+a[4])*i,n[2]=(a[2]+a[8])*i,n[3]=(a[6]-a[9])*i):a[5]>a[10]?(i=.5/(r=Math.sqrt(1+a[5]-a[0]-a[10])),n[0]=(a[4]+a[1])*i,n[1]=.5*r,n[2]=(a[9]+a[6])*i,n[3]=(a[8]-a[2])*i):(i=.5/(r=Math.sqrt(1+a[10]-a[0]-a[5])),n[0]=(a[8]+a[2])*i,n[1]=(a[9]+a[6])*i,n[2]=.5*r,n[3]=(a[1]-a[4])*i)}static slerp(e,t,r,i){var a,n,s,o,l,_=e.elements,h=t.elements,c=i.elements,d=_[0],u=_[1],m=_[2],f=_[3],T=h[0],E=h[1],p=h[2],g=h[3];return(n=d*T+u*E+m*p+f*g)<0&&(n=-n,T=-T,E=-E,p=-p,g=-g),1-n>1e-6?(a=Math.acos(n),s=Math.sin(a),o=Math.sin((1-r)*a)/s,l=Math.sin(r*a)/s):(o=1-r,l=r),c[0]=o*d+l*T,c[1]=o*u+l*E,c[2]=o*m+l*p,c[3]=o*f+l*g,c}static lerp(e,t,r,i){Ki._lerpArray(e.elements,t.elements,r,i.elements)}static add(e,t,r){var i=r.elements,a=e.elements,n=t.elements;i[0]=a[0]+n[0],i[1]=a[1]+n[1],i[2]=a[2]+n[2],i[3]=a[3]+n[3]}static dot(e,t){return Ki._dotArray(e.elements,t.elements)}get x(){return this.elements[0]}set x(e){this.elements[0]=e}get y(){return this.elements[1]}set y(e){this.elements[1]=e}get z(){return this.elements[2]}set z(e){this.elements[2]=e}get w(){return this.elements[3]}set w(e){this.elements[3]=e}scaling(e,t){var r=t.elements,i=this.elements;r[0]=i[0]*e,r[1]=i[1]*e,r[2]=i[2]*e,r[3]=i[3]*e}normalize(e){Ki._normalizeArray(this.elements,e.elements)}length(){var e=this.elements,t=e[0],r=e[1],i=e[2],a=e[3];return Math.sqrt(t*t+r*r+i*i+a*a)}rotateX(e,t){var r=t.elements,i=this.elements;e*=.5;var a=i[0],n=i[1],s=i[2],o=i[3],l=Math.sin(e),_=Math.cos(e);r[0]=a*_+o*l,r[1]=n*_+s*l,r[2]=s*_-n*l,r[3]=o*_-a*l}rotateY(e,t){var r=t.elements,i=this.elements;e*=.5;var a=i[0],n=i[1],s=i[2],o=i[3],l=Math.sin(e),_=Math.cos(e);r[0]=a*_-s*l,r[1]=n*_+o*l,r[2]=s*_+a*l,r[3]=o*_-n*l}rotateZ(e,t){var r=t.elements,i=this.elements;e*=.5;var a=i[0],n=i[1],s=i[2],o=i[3],l=Math.sin(e),_=Math.cos(e);r[0]=a*_+n*l,r[1]=n*_-a*l,r[2]=s*_+o*l,r[3]=o*_-s*l}getYawPitchRoll(e){Qi.transformQuat(Qi.ForwardRH,this,Ki.TEMPVector31),Qi.transformQuat(Qi.Up,this,Ki.TEMPVector32);var t=Ki.TEMPVector32.elements;Ki.angleTo(Qi.ZERO,Ki.TEMPVector31,Ki.TEMPVector33);var r=Ki.TEMPVector33.elements;r[0]==Math.PI/2?(r[1]=Ki.arcTanAngle(t[2],t[0]),r[2]=0):r[0]==-Math.PI/2?(r[1]=Ki.arcTanAngle(-t[2],-t[0]),r[2]=0):(R.createRotationY(-r[1],Ki.TEMPMatrix0),R.createRotationX(-r[0],Ki.TEMPMatrix1),Qi.transformCoordinate(Ki.TEMPVector32,Ki.TEMPMatrix0,Ki.TEMPVector32),Qi.transformCoordinate(Ki.TEMPVector32,Ki.TEMPMatrix1,Ki.TEMPVector32),r[2]=Ki.arcTanAngle(t[1],-t[0])),r[1]<=-Math.PI&&(r[1]=Math.PI),r[2]<=-Math.PI&&(r[2]=Math.PI),r[1]>=Math.PI&&r[2]>=Math.PI&&(r[1]=0,r[2]=0,r[0]=Math.PI-r[0]);var i=e.elements;i[0]=r[1],i[1]=r[0],i[2]=r[2]}invert(e){var t=e.elements,r=this.elements,i=r[0],a=r[1],n=r[2],s=r[3],o=i*i+a*a+n*n+s*s,l=o?1/o:0;t[0]=-i*l,t[1]=-a*l,t[2]=-n*l,t[3]=s*l}identity(){var e=this.elements;e[0]=0,e[1]=0,e[2]=0,e[3]=1}fromArray(e,t=0){this.elements[0]=e[t+0],this.elements[1]=e[t+1],this.elements[2]=e[t+2],this.elements[3]=e[t+3]}cloneTo(e){var t,r,i;if((r=this.elements)!==(i=e.elements))for(t=0;t<4;++t)i[t]=r[t]}clone(){var e=new Ki;return this.cloneTo(e),e}equals(e){var t=this.elements,i=e.elements;return r.nearEqual(t[0],i[0])&&r.nearEqual(t[1],i[1])&&r.nearEqual(t[2],i[2])&&r.nearEqual(t[3],i[3])}static rotationLookAt(e,t,r){Ki.lookAt(Qi.ZERO,e,t,r)}static lookAt(e,t,r,i){p.lookAt(e,t,r,Ki._tempMatrix3x3),Ki.rotationMatrix(Ki._tempMatrix3x3,i)}lengthSquared(){var e=this.elements[0],t=this.elements[1],r=this.elements[2],i=this.elements[3];return e*e+t*t+r*r+i*i}static invert(e,t){var i=e.elements,a=t.elements,n=e.lengthSquared();r.isZero(n)||(n=1/n,a[0]=-i[0]*n,a[1]=-i[1]*n,a[2]=-i[2]*n,a[3]=i[3]*n)}static rotationMatrix(e,t){var r,i,a=e.elements,n=a[0],s=a[1],o=a[2],l=a[3],_=a[4],h=a[5],c=a[6],d=a[7],u=a[8],m=t.elements,f=n+_+u;f>0?(r=Math.sqrt(f+1),m[3]=.5*r,r=.5/r,m[0]=(h-d)*r,m[1]=(c-o)*r,m[2]=(s-l)*r):n>=_&&n>=u?(i=.5/(r=Math.sqrt(1+n-_-u)),m[0]=.5*r,m[1]=(s+l)*i,m[2]=(o+c)*i,m[3]=(h-d)*i):_>u?(i=.5/(r=Math.sqrt(1+_-n-u)),m[0]=(l+s)*i,m[1]=.5*r,m[2]=(d+h)*i,m[3]=(c-o)*i):(i=.5/(r=Math.sqrt(1+u-n-_)),m[0]=(c+o)*i,m[1]=(d+h)*i,m[2]=.5*r,m[3]=(s-l)*i)}}Ki.TEMPVector30=new Qi,Ki.TEMPVector31=new Qi,Ki.TEMPVector32=new Qi,Ki.TEMPVector33=new Qi,Ki.TEMPMatrix0=new R,Ki.TEMPMatrix1=new R,Ki._tempMatrix3x3=new p,Ki.DEFAULT=new Ki,Ki.NAN=new Ki(NaN,NaN,NaN,NaN);class Ji{constructor(e){if(!(e instanceof Array)||4!==e.length)throw new Error("Rand:Seed must be an array with 4 numbers");this._state0U=0|e[0],this._state0L=0|e[1],this._state1U=0|e[2],this._state1L=0|e[3]}randomint(){var e=this._state0U,t=this._state0L,r=this._state1U,i=this._state1L,a=(i>>>0)+(t>>>0),n=r+e+(a/2>>>31)>>>0,s=a>>>0;this._state0U=r,this._state0L=i;var o=0,l=0;o=(e^=o=e<<23|(-512&t)>>>9)^r,l=(t^=l=t<<23)^i;o^=e>>>18,l^=t>>>18|(262143&e)<<14;return o^=r>>>5,l^=i>>>5|(31&r)<<27,this._state1U=o,this._state1L=l,[n,s]}random(){var e=this.randomint(),t=e[0],r=1023<<20|t>>>12,i=0|(e[1]>>>12|(4095&t)<<20);return Ji._CONVERTION_BUFFER.setUint32(0,r,!1),Ji._CONVERTION_BUFFER.setUint32(4,i,!1),Ji._CONVERTION_BUFFER.getFloat64(0,!1)-1}}Ji._CONVERTION_BUFFER=new DataView(new ArrayBuffer(8)),Ji.defaultRand=new Ji([0,Date.now()/65536,0,Date.now()%65536]);class $i{constructor(e,t){this._width=0,this._height=0,this._width=e,this._height=t}static get fullScreen(){return new $i(-1,-1)}get width(){return-1===this._width?_e.clientWidth:this._width}get height(){return-1===this._height?_e.clientHeight:this._height}}e.AlternateLightQueue=Vt,e.AnimationClip=ie,e.AnimationClipParser03=ee,e.AnimationClipParser04=te,e.AnimationEvent=q,e.AnimationNode=at,e.AnimationTransform3D=it,e.Animator=le,e.AnimatorControllerLayer=ne,e.AnimatorPlayState=ae,e.AnimatorState=se,e.AnimatorStateScript=class{constructor(){}onStateEnter(){}onStateUpdate(){}onStateExit(){}},e.Avatar=nt,e.BaseCamera=Xe,e.BaseMaterial=ot,e.BaseRender=Kt,e.BaseShape=Hr,e.BatchMark=Wt,e.BlinnPhongMaterial=_t,e.BlitScreenQuadCMD=Ie,e.BloomEffect=Zi,e.BoundBox=Ft,e.BoundFrustum=Be,e.BoundSphere=nr,e.Bounds=Ut,e.BoundsOctree=ir,e.BoundsOctreeNode=tr,e.BoxColliderShape=D,e.BoxShape=Wr,e.BufferState=Ee,e.BulletInteractive=Ri,e.Burst=Nr,e.Camera=Qe,e.CameraCullInfo=At,e.CapsuleColliderShape=C,e.CastShadowList=class extends b{constructor(){super()}add(e){if(-1!==e._indexInCastShadowList)throw"CastShadowList:element has in CastShadowList.";this._add(e),e._indexInCastShadowList=this.length++}remove(e){var t=e._indexInCastShadowList;if(this.length--,t!==this.length){var r=this.elements[this.length];this.elements[t]=r,r._indexInCastShadowList=t}e._indexInCastShadowList=-1}},e.CharacterController=k,e.CircleShape=Xr,e.ClearRenderTextureCMD=Le,e.Cluster=Ne,e.ColliderShape=v,e.Collision=F,e.CollisionTool=U,e.CollisionUtils=Ve,e.Color=xt,e.ColorOverLifetime=br,e.Command=Ae,e.CommandBuffer=et,e.CompoundColliderShape=A,e.ConchQuaternion=Ki,e.ConchVector3=Qi,e.ConchVector4=qi,e.ConeColliderShape=y,e.ConeShape=Yr,e.Config3D=j,e.ConfigurableConstraint=zi,e.Constraint3D=class{constructor(){}},e.ConstraintComponent=Ui,e.ContactPoint=V,e.ContainmentType=we,e.CylinderColliderShape=L,e.DefineDatas=ce,e.DepthPass=qe,e.DirectionLight=yi,e.DrawMeshCMD=ye,e.DrawRenderCMD=Je,e.DynamicBatchManager=_r,e.EffectMaterial=ht,e.Emission=si,e.ExtendTerrainMaterial=ct,e.FixedConstraint=Gi,e.FloatKeyframe=K,e.FrameOverTime=wr,e.FrustumCulling=Mt,e.GeometryElement=Gt,e.Gradient=Or,e.GradientAngularVelocity=Vr,e.GradientColor=Pr,e.GradientDataInt=Br,e.GradientDataNumber=Fr,e.GradientDataVector2=Yi,e.GradientMode=Lr,e.GradientSize=Ur,e.GradientVelocity=Gr,e.HeightMap=Wi,e.HemisphereShape=jr,e.HitResult=B,e.ILaya3D=g,e.IndexBuffer3D=Ge,e.Input3D=Lt,e.Keyframe=Q,e.KeyframeNode=Z,e.KeyframeNodeList=re,e.KeyframeNodeOwner=oe,e.Laya3D=Hi,e.LightQueue=wt,e.LightSprite=je,e.Lightmap=ar,e.LoadModelV04=wi,e.LoadModelV05=Vi,e.Material=st,e.MathUtils3D=r,e.Matrix3x3=p,e.Matrix4x4=R,e.Mesh=Ii,e.MeshColliderShape=O,e.MeshFilter=Mr,e.MeshReader=Bi,e.MeshRenderDynamicBatchManager=Cr,e.MeshRenderStaticBatchManager=qt,e.MeshRenderer=Ir,e.MeshSprite3D=yr,e.MeshSprite3DShaderDeclaration=Ar,e.MeshTerrainSprite3D=Xi,e.MouseTouch=Ct,e.OctreeMotionList=rr,e.PBRMaterial=dt,e.PBRSpecularMaterial=fr,e.PBRStandardMaterial=gr,e.Physics3D=Y,e.Physics3DUtils=M,e.PhysicsCollider=vi,e.PhysicsComponent=P,e.PhysicsSettings=Ot,e.PhysicsSimulation=G,e.PhysicsTriggerComponent=W,e.PhysicsUpdateList=w,e.Picker=Ue,e.PixelLineData=class{constructor(){this.startPosition=new n,this.endPosition=new n,this.startColor=new xt,this.endColor=new xt}cloneTo(e){this.startPosition.cloneTo(e.startPosition),this.endPosition.cloneTo(e.endPosition),this.startColor.cloneTo(e.startColor),this.endColor.cloneTo(e.endColor)}},e.PixelLineFilter=Ht,e.PixelLineMaterial=Bt,e.PixelLineRenderer=Jt,e.PixelLineSprite3D=$t,e.PixelLineVertex=zt,e.Plane=Pe,e.PointLight=Li,e.PostProcess=rt,e.PostProcessEffect=ji,e.PostProcessRenderContext=tt,e.PrimitiveMesh=Mi,e.Quaternion=S,e.QuaternionKeyframe=J,e.Rand=ni,e.RandX=Ji,e.Ray=be,e.ReflectionProbe=Qt,e.ReflectionProbeList=hr,e.ReflectionProbeManager=cr,e.RenderContext3D=_e,e.RenderElement=Ke,e.RenderQueue=er,e.RenderState=lt,e.RenderTexture=he,e.RenderableSprite3D=kt,e.Rigidbody3D=X,e.RotationOverLifetime=zr,e.Scene3D=dr,e.Scene3DShaderDeclaration=Ye,e.Scene3DUtils=bi,e.ScreenQuad=pe,e.ScreenTriangle=ge,e.Script3D=ki,e.SetGlobalShaderDataCMD=$e,e.SetRenderTargetCMD=Me,e.SetShaderDataCMD=De,e.Shader3D=xe,e.ShaderData=me,e.ShaderDefine=Se,e.ShaderInit3D=Ci,e.ShaderInstance=Rt,e.ShaderPass=ur,e.ShaderVariable=St,e.ShaderVariant=Re,e.ShaderVariantCollection=ve,e.ShadowCasterPass=lr,e.ShadowCullInfo=It,e.ShadowSliceData=sr,e.ShadowSpotData=or,e.ShadowUtils=Ze,e.ShapeUtils=kr,e.ShuriKenParticle3D=_i,e.ShuriKenParticle3DShaderDeclaration=$r,e.ShurikenParticleData=oi,e.ShurikenParticleMaterial=ei,e.ShurikenParticleRenderer=ti,e.ShurikenParticleSystem=li,e.SimpleSingletonList=vt,e.SimpleSkinnedMeshRenderer=Ni,e.SimpleSkinnedMeshSprite3D=Pi,e.SingletonList=b,e.Size=$i,e.SizeOverLifetime=qr,e.SkinnedMeshRenderer=ci,e.SkinnedMeshSprite3D=di,e.SkinnedMeshSprite3DShaderDeclaration=hi,e.SkyBox=ke,e.SkyBoxMaterial=Sr,e.SkyDome=Pt,e.SkyMesh=He,e.SkyPanoramicMaterial=Fi,e.SkyProceduralMaterial=Rr,e.SkyRenderer=We,e.SphereColliderShape=N,e.SphereShape=Zr,e.SphericalHarmonicsL2=Dt,e.SpotLight=Oi,e.Sprite3D=Ce,e.StartFrame=Qr,e.StaticBatchManager=jt,e.StaticPlaneColliderShape=x,e.SubMesh=xi,e.SubMeshDynamicBatch=Dr,e.SubMeshInstanceBatch=Xt,e.SubMeshRenderElement=Yt,e.SubMeshStaticBatch=Zt,e.SubShader=mr,e.TextMesh=class{constructor(){}get text(){return this._text}set text(e){this._text=e}get fontSize(){return this._fontSize}set fontSize(e){this._fontSize=e}get color(){return this._color}set color(e){this._color=e}_createVertexBuffer(e){}_resizeVertexBuffer(e){}_addChar(){}},e.TextureCube=bt,e.TextureGenerator=z,e.TextureMode=mi,e.TextureSheetAnimation=Kr,e.Touch=yt,e.TrailFilter=Ei,e.TrailGeometry=Ti,e.TrailMaterial=ui,e.TrailRenderer=pi,e.TrailSprite3D=gi,e.Transform3D=I,e.UnlitMaterial=vr,e.Utils3D=H,e.Vector2=i,e.Vector3=n,e.Vector3Keyframe=$,e.Vector4=a,e.VelocityOverLifetime=Jr,e.VertexBuffer3D=de,e.VertexDeclaration=fe,e.VertexElement=Te,e.VertexElementFormat=ue,e.VertexMesh=ze,e.VertexPositionTerrain=Si,e.VertexPositionTexture0=Nt,e.VertexShuriKenParticle=ri,e.VertexShurikenParticleBillboard=ii,e.VertexShurikenParticleMesh=ai,e.VertexTrail=fi,e.Viewport=Fe,e.WaterPrimaryMaterial=xr,e.skinnedMatrixCache=Ai}(window.Laya=window.Laya||{},Laya);
|