2023-02-15 15:05:11 +01:00
! function ( t , e ) { "object" == typeof exports && "object" == typeof module ? module . exports = e ( ) : "function" == typeof define && define . amd ? define ( [ ] , e ) : "object" == typeof exports ? exports . OptimalSelect = e ( ) : t . OptimalSelect = e ( ) } ( this , function ( ) { return i = [ function ( t , e , i ) { "use strict" ; Object . defineProperty ( e , "__esModule" , { value : ! 0 } ) , e . convertNodeList = function ( t ) { for ( var e = t . length , i = new Array ( e ) , r = 0 ; r < e ; r ++ ) i [ r ] = t [ r ] ; return i } , e . escapeValue = function ( t ) { return t && t . replace ( /['"`\\/:\?&!#$%^()[\]{|}*+;,.<=>@~]/g , "\\$&" ) . replace ( /\n/g , "A" ) } } , function ( t , e , i ) { "use strict" ; Object . defineProperty ( e , "__esModule" , { value : ! 0 } ) , e . getCommonAncestor = function ( t ) { for ( var e = ( 1 < arguments . length && void 0 !== arguments [ 1 ] ? arguments [ 1 ] : { } ) . root , r = void 0 === e ? document : e , n = [ ] , i = ( t . forEach ( function ( t , e ) { for ( var i = [ ] ; t !== r ; ) t = t . parentNode , i . unshift ( t ) ; n [ e ] = i } ) , n . sort ( function ( t , e ) { return t . length - e . length } ) , n . shift ( ) ) , s = null , o = 0 , a = i . length ; o < a ; o ++ ) if ( "break" === function ( ) { var e = i [ o ] ; if ( n . some ( function ( t ) { return ! t . some ( function ( t ) { return t === e } ) } ) ) return "break" ; s = e } ( ) ) break ; return s } , e . getCommonProperties = function ( t ) { var l = { classes : [ ] , attributes : { } , tag : null } ; return t . forEach ( function ( t ) { var i , r , n , e , s = l . classes , o = l . attributes , a = l . tag ; void 0 !== s && ( ( i = t . getAttribute ( "class" ) ) ? ( i = i . trim ( ) . split ( " " ) , s . length ? ( s = s . filter ( function ( e ) { return i . some ( function ( t ) { return t === e } ) } ) ) . length ? l . classes = s : delete l . classes : l . classes = i ) : delete l . classes ) , void 0 !== o && ( r = t . attributes , n = Object . keys ( r ) . reduce ( function ( t , e ) { var e = r [ e ] , i = e . name ; return e && "class" !== i && ( t [ i ] = e . value ) , t } , { } ) , s = Object . keys ( n ) , e = Object . keys ( o ) , s . length ? e . length ? ( o = e . reduce ( function ( t , e ) { var i = o [ e ] ; return i === n [ e ] && ( t [ e ] = i ) , t } , { } ) , Object . keys ( o ) . length ? l . attributes = o : delete l . attributes ) : l . attributes = n : delete l . attributes ) , void 0 !== a && ( s = t . tagName . toLowerCase ( ) , a ? s !== a && delete l . tag : l . tag = s ) } ) , l } } , function ( t , e , i ) { "use strict" ; Object . defineProperty ( e , "__esModule" , { value : ! 0 } ) , e . default = function ( t , e ) { var i = 2 < arguments . length && void 0 !== arguments [ 2 ] ? arguments [ 2 ] : { } ; Array . isArray ( e ) || ( e = e . length ? ( 0 , u . convertNodeList ) ( e ) : [ e ] ) ; if ( ! e . length || e . some ( function ( t ) { return 1 !== t . nodeType } ) ) throw new Error ( 'Invalid input - to compare HTMLElements its necessary to provide a reference of the selected node(s)! (missing "elements")' ) ; ( 0 , h . default ) ( e [ 0 ] , i ) ; var r = t . replace ( /> /g , ">" ) . split ( /\s+(?=(?:(?:[^"]*"){2})*[^"]*$)/ ) ; if ( r . length < 2 ) return c ( "" , t , "" , e ) ; var n = [ r . pop ( ) ] ; for ( ; 1 < r . length ; ) { var s = r . pop ( ) , o = r . join ( " " ) , a = n . join ( " " ) , l = o + " " + a ; document . querySelectorAll ( l ) . length !== e . length && n . unshift ( c ( o , s , a , e ) ) } n . unshift ( r [ 0 ] ) , ( r = n ) [ 0 ] = c ( "" , r [ 0 ] , r . slice ( 1 ) . join ( " " ) , e ) , r [ r . length - 1 ] = c ( r . slice ( 0 , - 1 ) . join ( " " ) , r [ r . length - 1 ] , "" , e ) ; return r . join ( " " ) . replace ( />/g , "> " ) . trim ( ) } ; var r = i ( 3 ) , h = ( r = r ) && r . _ _esModule ? r : { default : r } , u = i ( 0 ) ; function c ( i , r , n , s ) { if ( i . length && ( i += " " ) , n . length && ( n = " " + n ) , /\[*\]/ . test ( r ) ) { var t = r . replace ( /=.*$/ , "]" ) , o = "" + i + t + n ; if ( p ( document . querySelectorAll ( o ) , s ) ) r = t ; else for ( var a = document . querySelectorAll ( "" + i + t ) , l = 0 , e = a . length ; l < e ; l ++ ) if ( "break" === function ( ) { var t , e = a [ l ] ; if ( s . some ( function ( t ) { return e . contains ( t ) } ) ) return t = e . tagName . toLowerCase ( ) , o = "" + i + t + n , p ( document . querySelectorAll ( o ) , s ) && ( r = t ) , "break" } ( ) ) break } if ( />/ . test ( r ) && ( t = r . replace ( />/ , "" ) , o = "" + i + t + n , p ( document . querySelectorAll ( o ) , s ) && ( r = t ) ) , /:nth-child/ . test ( r ) && ( t = r . replace ( /nth-child/g , "nth-of-type" ) , o = "" + i + t + n , p ( document . querySelectorAll ( o ) , s ) && ( r = t ) ) , /\.\S+\.\S+/ . test ( r ) ) { for ( var h = r . trim ( ) . split ( "." ) . slice ( 1 ) . map ( function ( t ) { return "." + t } ) . sort ( function ( t , e ) { return t . length - e . length } ) ; h . length ; ) { var u = r . replace ( h . shift ( ) , "" ) . trim ( ) ; if ( ! ( o = ( "" + i + u + n ) . trim ( ) ) . length || ">" === o . charAt ( 0 ) || ">" === o . charAt ( o . length - 1 ) ) break ; p ( document . querySelectorAll ( o ) , s ) && ( r = u ) } if ( ( h = r && r . match ( /\./g ) ) && 2 < h . length ) for ( var c = document . querySelectorAll ( "" + i + r ) , l = 0 , e = c . length ; l < e ; l ++ ) if ( "break" === function ( ) { var t , e = c [ l ] ; if ( s . some ( function ( t ) { return e . contains ( t ) } ) ) return t = e . tagName . toLowerCase ( ) , o = "" + i + t + n , p ( document . querySelectorAll ( o ) , s ) && ( r = t ) , "break" } ( ) ) break } return r } function p ( i , t ) { var r = i . length ; return r === t . length && t . every ( function ( t ) { for ( var e = 0 ; e < r ; e ++ ) if ( i [ e ] === t ) return ! 0 ;
2022-10-04 10:51:35 +02:00
attribute vec3 aVertexPosition ;
attribute vec2 aTextureCoord ;
attribute vec4 aColor ;
attribute float aTextureId ;
uniform mat3 projectionMatrix ;
varying vec2 vTextureCoord ;
varying vec4 vColor ;
varying float vTextureId ;
void main ( void ) {
gl _Position . xyw = projectionMatrix * aVertexPosition ;
gl _Position . z = 0.0 ;
vTextureCoord = aTextureCoord ;
vTextureId = aTextureId ;
vColor = aColor ;
}
` ,fragment: `
varying vec2 vTextureCoord ;
varying vec4 vColor ;
varying float vTextureId ;
uniform sampler2D uSamplers [ % count % ] ;
void main ( void ) {
vec4 color ;
% forloop %
gl _FragColor = color * vColor ;
2023-02-15 15:05:11 +01:00
} ` ,geometryClass:U,vertexSize:7},t);return class extends _.AbstractBatchRenderer{constructor(t){super(t),this.shaderGenerator=new _.BatchShaderGenerator(e,i),this.geometryClass=n,this.vertexSize=r}packInterleavedGeometry(t,e,i,r,n){var{uint32View:s,float32View:o}=e,a=r/this.vertexSize,l=t.uvs,h=t.indices,u=t.vertexData,c=t.vertexData2d,p=t._texture.baseTexture._batchLocation,e=Math.min(t.worldAlpha,1),d=e<1&&t._texture.baseTexture.alphaMode?g.premultiplyTint(t._tintRGB,e):t._tintRGB+(255*e<<24);if(c){let e=0;for(let t=0;t<c.length;t+=3,e+=2)o[r++]=c[t],o[r++]=c[t+1],o[r++]=c[t+2],o[r++]=l[e],o[r++]=l[e+1],s[r++]=d,o[r++]=p}else for(let t=0;t<u.length;t+=2)o[r++]=u[t],o[r++]=u[t+1],o[r++]=1,o[r++]=l[t],o[r++]=l[t+1],s[r++]=d,o[r++]=p;for(let t=0;t<h.length;t++)i[n++]=a+h[t]}}}}class G{constructor(t,e=!0){G.prototype.__init.call(this),this.legacy=t,e&&(this.enabled=!0),this.legacy.proj=this}__init(){this._enabled=!1}get enabled(){return this._enabled}set enabled(t){this._enabled=t}clear(){}}a.TRANSFORM_STEP=void 0;var X,i=a.TRANSFORM_STEP||(a.TRANSFORM_STEP={}),i=(i[i.NONE=0]="NONE",i[i.BEFORE_PROJ=4]="BEFORE_PROJ",i[i.PROJ=5]="PROJ",i[i.ALL=9]="ALL",a.AFFINE=void 0,a.AFFINE||(a.AFFINE={}));function H(t){var e=this.proj,i=this,r=t._worldID,n=i.localTransform,s=e.scaleAfterAffine&&2<=e.affine,o=(i._localID!==i._currentLocalID&&(s?(n.a=i._cx,n.b=i._sx,n.c=i._cy,n.d=i._sy,n.tx=i.position._x,n.ty=i.position._y):(n.a=i._cx*i.scale._x,n.b=i._sx*i.scale._x,n.c=i._cy*i.scale._y,n.d=i._sy*i.scale._y,n.tx=i.position._x-(i.pivot._x*n.a+i.pivot._y*n.c),n.ty=i.position._y-(i.pivot._x*n.b+i.pivot._y*n.d)),i._currentLocalID=i._localID,e._currentProjID=-1),e._projID);e._currentProjID!==o&&(e._currentProjID=o,e.updateLocalTransform(n),i._parentID=-1),i._parentID!==r&&((o=t.proj)&&!o._affine?e.world.setToMult(o.world,e.local):e.world.setToMultLegacy(t.worldTransform,e.local),n=i.worldTransform,e.world.copyTo(n,e._affine,e.affinePreserveOrientation),s&&(n.a*=i.scale._x,n.b*=i.scale._x,n.c*=i.scale._y,n.d*=i.scale._y,n.tx-=i.pivot._x*n.a+i.pivot._y*n.c,n.ty-=i.pivot._x*n.b+i.pivot._y*n.d),i._parentID=r,i._worldID++)}i[i.NONE=0]="NONE",i[i.FREE=1]="FREE",i[i.AXIS_X=2]="AXIS_X",i[i.AXIS_Y=3]="AXIS_Y",i[i.POINT=4]="POINT",i[i.AXIS_XR=5]="AXIS_XR";class r extends G{constructor(...t){super(...t),r.prototype.__init.call(this),r.prototype.__init2.call(this),r.prototype.__init3.call(this),r.prototype.__init4.call(this),r.prototype.__init5.call(this)}updateLocalTransform(t){}__init(){this._projID=0}__init2(){this._currentProjID=-1}__init3(){this._affine=a.AFFINE.NONE}__init4(){this.affinePreserveOrientation=!1}__init5(){this.scaleAfterAffine=!0}set affine(t){this._affine!==t&&(this._affine=t,this._currentProjID=-1,this.legacy._currentLocalID=-1)}get affine(){return this._affine}set enabled(t){t!==this._enabled&&(this._enabled=t,this.legacy.updateTransform=t?H:d.Transform.prototype.updateTransform,this.legacy._parentID=-1)}clear(){this._currentProjID=-1,this._projID=0}}class Y extends _.AbstractBatchRenderer{constructor(...t){super(...t),Y.prototype.__init.call(this),Y.prototype.__init2.call(this)}__init(){this.forceMaxTextures=0}getUniforms(t){return this.defUniforms}syncUniforms(t){if(t){var e=this._shader;for(const i in t)e.uniforms[i]=t[i]}}__init2(){this.defUniforms={}}buildDrawCalls(e,i,r){var{_bufferedElements:n,_attributeBuffer:s,_indexBuffer:o,vertexSize:a}=this,l=_.AbstractBatchRenderer._drawCallPool;let h=this._dcIndex,u=this._aIndex,c=this._iIndex,p=l[h];p.start=this._iIndex,p.texArray=e;for(let t=i;t<r;++t){var d=n[t],f=d._texture.baseTexture,f=g.premultiplyBlendMode[f.alphaMode?1:0][d.blendMode],m=this.getUniforms(d);n[t]=null,i<t&&(p.blend!==f||p.uniforms!==m)&&(p.size=c-p.start,i=t,(p=l[++h]).texArray=e,p.start=c),this.packInterleavedGeometry(d,s,o,u,c),u+=d.vertexData.length/2*a,c+=d.indices.length,p.blend=f,p.uniforms=m}i<r&&(p.size=c-p.start,++h),this._dcIndex=h,this._aIndex=u,this._iIndex=c}drawBatches(){var e=this._dcIndex,{gl:i,state:r,shader:n}=this.renderer,s=_.AbstractBatchRenderer._drawCallPool;let o=null,a=null;for(let t=0;t
2022-10-04 10:51:35 +02:00
attribute vec2 aTextureCoord ;
uniform mat3 projectionMatrix ;
uniform mat3 translationMatrix ;
uniform mat3 uTransform ;
varying vec3 vTextureCoord ;
void main ( void )
{
gl _Position . xyw = projectionMatrix * translationMatrix * vec3 ( aVertexPosition , 1.0 ) ;
vTextureCoord = uTransform * vec3 ( aTextureCoord , 1.0 ) ;
}
2023-02-15 15:05:11 +01:00
` ,c=new n;class K extends _.ObjectRenderer{constructor(t){super(t),K.prototype.__init.call(this);t={globals:this.renderer.globalUniforms};this.shader=_.Shader.from(q, `
2022-10-04 10:51:35 +02:00
varying vec3 vTextureCoord ;
uniform sampler2D uSampler ;
uniform vec4 uColor ;
uniform mat3 uMapCoord ;
uniform vec4 uClampFrame ;
uniform vec2 uClampOffset ;
void main ( void )
{
vec2 coord = mod ( vTextureCoord . xy / vTextureCoord . z - uClampOffset , vec2 ( 1.0 , 1.0 ) ) + uClampOffset ;
coord = ( uMapCoord * vec3 ( coord , 1.0 ) ) . xy ;
coord = clamp ( coord , uClampFrame . xy , uClampFrame . zw ) ;
vec4 sample = texture2D ( uSampler , coord ) ;
gl _FragColor = sample * uColor ;
}
2023-02-15 15:05:11 +01:00
` ,t),this.simpleShader=_.Shader.from(q, `
2022-10-04 10:51:35 +02:00
varying vec3 vTextureCoord ;
uniform sampler2D uSampler ;
uniform vec4 uColor ;
void main ( void )
{
vec4 sample = texture2D ( uSampler , vTextureCoord . xy / vTextureCoord . z ) ;
gl _FragColor = sample * uColor ;
}
2023-02-15 15:05:11 +01:00
` ,t)}__init(){this.quad=new _.QuadUv}render(t){var e=this.renderer,i=this.quad;let r=i.vertices;r[0]=r[6]=t._width*-t.anchor.x,r[1]=r[3]=t._height*-t.anchor.y,r[2]=r[4]=t._width*(1-t.anchor.x),r[5]=r[7]=t._height*(1-t.anchor.y),t.uvRespectAnchor&&((r=i.uvs)[0]=r[6]=-t.anchor.x,r[1]=r[3]=-t.anchor.y,r[2]=r[4]=1-t.anchor.x,r[5]=r[7]=1-t.anchor.y),i.invalidate();var n=t._texture,s=n.baseTexture,o=t.tileProj.world,a=t.uvMatrix;let l=s.isPowerOfTwo&&n.frame.width===s.width&&n.frame.height===s.height;l&&(s._glTextures[e.CONTEXT_UID]?l=s.wrapMode!==u.WRAP_MODES.CLAMP:s.wrapMode===u.WRAP_MODES.CLAMP&&(s.wrapMode=u.WRAP_MODES.REPEAT));var h=l?this.simpleShader:this.shader;c.identity(),c.scale(n.width,n.height),c.prepend(o),c.scale(1/t._width,1/t._height),c.invert(),l?c.prepend(a.mapCoord):(h.uniforms.uMapCoord=a.mapCoord.toArray(!0),h.uniforms.uClampFrame=a.uClampFrame,h.uniforms.uClampOffset=a.uClampOffset),h.uniforms.uTransform=c.toArray(!0),h.uniforms.uColor=g.premultiplyTintToRgba(t.tint,t.worldAlpha,h.uniforms.uColor,s.premultiplyAlpha),h.uniforms.translationMatrix=t.worldTransform.toArray(!0),h.uniforms.uSampler=n,e.shader.bind(h,!1),e.geometry.bind(i,void 0),e.state.setBlendMode(g.correctBlendMode(t.blendMode,s.premultiplyAlpha)),e.geometry.draw(u.DRAW_MODES.TRIANGLES,6,0)}}const h=new d.Point,p=[new d.Point,new d.Point,new d.Point,new d.Point],o=new d.Rectangle,Z=new n;class l extends r{constructor(t,e){super(t,e),l.prototype.__init.call(this),l.prototype.__init2.call(this),l.prototype.__init3.call(this),this.local=new n,this.world=new n}__init(){this.matrix=new n}__init2(){this.pivot=new d.ObservablePoint(this.onChange,this,0,0)}__init3(){this.reverseLocalOrder=!1}onChange(){var t=this.pivot,e=this.matrix.mat3;e[6]=-(t._x*e[0]+t._y*e[3]),e[7]=-(t._x*e[1]+t._y*e[4]),this._projID++}setAxisX(t,e=1){var i=t.x,t=t.y,r=Math.sqrt(i*i+t*t),n=this.matrix.mat3;n[0]=i/r,n[1]=t/r,n[2]=e/r,this.onChange()}setAxisY(t,e=1){var i=t.x,t=t.y,r=Math.sqrt(i*i+t*t),n=this.matrix.mat3;n[3]=i/r,n[4]=t/r,n[5]=e/r,this.onChange()}mapSprite(t,e){var i=t.texture;o.x=-t.anchor.x*i.orig.width,o.y=-t.anchor.y*i.orig.height,o.width=i.orig.width,o.height=i.orig.height,this.mapQuad(o,e)}mapQuad(e,i){p[0].set(e.x,e.y),p[1].set(e.x+e.width,e.y),p[2].set(e.x+e.width,e.y+e.height),p[3].set(e.x,e.y+e.height);let r=1,n=2,s=3;e=W(i[0],i[2],i[1],i[3],h);if(0!==e){r=1,n=3,s=2;var e=Math.sqrt((i[0].x-h.x)*(i[0].x-h.x)+(i[0].y-h.y)*(i[0].y-h.y)),o=Math.sqrt((i[r].x-h.x)*(i[r].x-h.x)+(i[r].y-h.y)*(i[r].y-h.y)),a=Math.sqrt((i[n].x-h.x)*(i[n].x-h.x)+(i[n].y-h.y)*(i[n].y-h.y)),l=Math.sqrt((i[s].x-h.x)*(i[s].x-h.x)+(i[s].y-h.y)*(i[s].y-h.y)),e=(e+l)/l,l=(o+a)/a,a=(o+a)/o;let t=this.matrix.mat3;t[0]=p[0].x*e,t[1]=p[0].y*e,t[2]=e,t[3]=p[r].x*l,t[4]=p[r].y*l,t[5]=l,t[6]=p[n].x*a,t[7]=p[n].y*a,t[8]=a,this.matrix.invert(),(t=Z.mat3)[0]=i[0].x,t[1]=i[0].y,t[2]=1,t[3]=i[r].x,t[4]=i[r].y,t[5]=1,t[6]=i[n].x,t[7]=i[n].y,t[8]=1,this.matrix.setToMult(Z,this.matrix),this._projID++}}updateLocalTransform(t){0!==this._projID?this.reverseLocalOrder?this.local.setToMultLegacy2(this.matrix,t):this.local.setToMultLegacy(t,this.matrix):this.local.copyFrom(t)}clear(){super.clear(),this.matrix.identity(),this.pivot.set(0,0)}}function Q(){return this.proj.affine?this.transform.worldTransform:this.proj.world}class $ extends t.Container{constructor(){super(),this.proj=new l(this.transform)}toLocal(t,e,i,r,n=a.TRANSFORM_STEP.ALL){return e&&(t=e.toGlobal(t,i,r)),r||this._recursivePostUpdateTransform(),n>=a.TRANSFORM_STEP.PROJ?(r||this.displayObjectUpdateTransform(),(this.proj.affine?this.transform.worldTransform:this.proj.world).applyInverse(t,i)):(this.parent?i=this.parent.worldTransform.applyInverse(t,i):(i.x=t.x,i.y=t.y),n===a.TRANSFORM_STEP.NONE?i:this.transform.localTransform.applyInverse(i,i))}get worldTransform(){return this.proj.affine?this.transform.worldTransform:this.proj.world}}const J= $ .prototype.toLocal;class f extends s.Mesh{static __initStatic(){this.defaultVertexShader= ` precision highp float ;
2022-10-04 10:51:35 +02:00
attribute vec2 aVertexPosition ;
attribute vec2 aTextureCoord ;
uniform mat3 projectionMatrix ;
uniform mat3 translationMatrix ;
uniform mat3 uTextureMatrix ;
varying vec2 vTextureCoord ;
void main ( void )
{
gl _Position . xyw = projectionMatrix * translationMatrix * vec3 ( aVertexPosition , 1.0 ) ;
gl _Position . z = 0.0 ;
vTextureCoord = ( uTextureMatrix * vec3 ( aTextureCoord , 1.0 ) ) . xy ;
}
` }static __initStatic2(){this.defaultFragmentShader= `
varying vec2 vTextureCoord ;
uniform vec4 uColor ;
uniform sampler2D uSampler ;
void main ( void )
{
gl _FragColor = texture2D ( uSampler , vTextureCoord ) * uColor ;
2023-02-15 15:05:11 +01:00
} ` }constructor(t,e,i,r){super(t,e,i,r),f.prototype.__init.call(this),this.proj=new l(this.transform)}__init(){this.vertexData2d=null}calculateVertices(){if(this.proj._affine)this.vertexData2d=null,super.calculateVertices();else{var t=this.geometry,e=t.buffers[0].data;if(t.vertexDirtyId!==this.vertexDirty||this._transformID!==this.transform._worldID){this._transformID=this.transform._worldID,this.vertexData.length!==e.length&&(this.vertexData=new Float32Array(e.length)),this.vertexData2d&&this.vertexData2d.length===3*e.length/2||(this.vertexData2d=new Float32Array(3*e.length));var i=this.proj.world.mat3,r=this.vertexData2d,n=this.vertexData;for(let t=0;t<n.length/2;t++){var s=e[2*t],o=e[2*t+1],a=i[0]*s+i[3]*o+i[6],l=i[1]*s+i[4]*o+i[7],s=i[2]*s+i[5]*o+i[8];r[3*t]=a,r[3*t+1]=l,r[3*t+2]=s,n[2*t]=a/s,n[2*t+1]=l/s}this.vertexDirty=t.vertexDirtyId}}}_renderDefault(t){var e=this.shader;e.alpha=this.worldAlpha,e.update&&e.update(),t.batch.flush(),function(t){let e=void 0,i=t[0],r=1;for(;r<t.length;){var n=t[r],s=t[r+1];if(r+=2,("optionalAccess"===n||"optionalCall"===n)&&null==i)return;"access"===n||"optionalAccess"===n?i=s(e=i):"call"!==n&&"optionalCall"!==n||(i=s((...t)=>i.call(e,...t)),e=void 0)}return i}([e,"access",t=>t.program,"access",t=>t.uniformData,"optionalAccess",t=>t.translationMatrix])&&(e.uniforms.translationMatrix=this.worldTransform.toArray(!0)),t.shader.bind(e,!1),t.state.set(this.state),t.geometry.bind(this.geometry,e),t.geometry.draw(this.drawMode,this.size,this.start,this.geometry.instanceCount)}toLocal(t,e,i,r,n=a.TRANSFORM_STEP.ALL){return J.call(this,t,e,i,r,n)}get worldTransform(){return this.proj.affine?this.transform.worldTransform:this.proj.world}}f.__initStatic(),f.__initStatic2();class tt extends f{constructor(t,e,i,r,n){super(new s.MeshGeometry(e,i,r),new s.MeshMaterial(t,{program:_.Program.from(f.defaultVertexShader,f.defaultFragmentShader),pluginName:"batch2d"}),null,n),tt.prototype.__init2.call(this),this.geometry.getBuffer("aVertexPosition").static=!1}__init2(){this.autoUpdate=!0}get vertices(){return this.geometry.getBuffer("aVertexPosition").data}set vertices(t){this.geometry.getBuffer("aVertexPosition").data=t}_render(t){this.autoUpdate&&this.geometry.getBuffer("aVertexPosition").update(),super._render(t)}}class m extends e.Sprite{constructor(t){super(t),m.prototype.__init.call(this),this.proj=new l(this.transform),this.pluginName="batch2d"}__init(){this.vertexData2d=null}_calculateBounds(){this.calculateTrimmedVertices(),this._bounds.addQuad(this.vertexTrimmedData)}calculateVertices(){var n=this._texture;if(this.proj._affine)this.vertexData2d=null,super.calculateVertices();else{this.vertexData2d||(this.vertexData2d=new Float32Array(12));var s=this.transform._worldID,o=n._updateID;if(this._transformID!==s||this._textureID!==o){this._textureID!==o&&(this.uvs=n._uvs.uvsFloat32),this._transformID=s,this._textureID=o;var s=this.proj.world.mat3,o=this.vertexData2d,a=this.vertexData,l=n.trim,n=n.orig,h=this._anchor;let t,e,i,r;i=l?(e=l.x-h._x*n.width,t=e+l.width,(r=l.y-h._y*n.height)+l.height):(e=-h._x*n.width,t=e+n.width,(r=-h._y*n.height)+n.height),o[0]=s[0]*e+s[3]*r+s[6],o[1]=s[1]*e+s[4]*r+s[7],o[2]=s[2]*e+s[5]*r+s[8],o[3]=s[0]*t+s[3]*r+s[6],o[4]=s[1]*t+s[4]*r+s[7],o[5]=s[2]*t+s[5]*r+s[8],o[6]=s[0]*t+s[3]*i+s[6],o[7]=s[1]*t+s[4]*i+s[7],o[8]=s[2]*t+s[5]*i+s[8],o[9]=s[0]*e+s[3]*i+s[6],o[10]=s[1]*e+s[4]*i+s[7],o[11]=s[2]*e+s[5]*i+s[8],a[0]=o[0]/o[2],a[1]=o[1]/o[2],a[2]=o[3]/o[5],a[3]=o[4]/o[5],a[4]=o[6]/o[8],a[5]=o[7]/o[8],a[6]=o[9]/o[11],a[7]=o[10]/o[11]}}}calculateTrimmedVertices(){if(this.proj._affine)super.calculateTrimmedVertices();else{var t=this.transform._worldID,e=this._texture._updateID;if(this.vertexTrimmedData){if(this._transformTrimmedID===t&&this._textureTrimmedID===e)return}else this.vertexTrimmedData=new Float32Array(8);this._transformTrimmedID=t,this._textureTrimmedID=e;var t=this._texture,e=this.vertexTrimmedData,t=t.orig,i=this.tileProj?this._width:t.width,t=this.tileProj?this._height:t.height,r=this._anchor,n=this.proj.world.mat3,s=-r._x*i,i=s+i,r=-r._y*t,t=r+t,o=1/(n[2]*s+n[5]*
2022-10-04 10:51:35 +02:00
attribute vec2 aVertexPosition ;
attribute vec2 aTextureCoord ;
uniform mat3 projectionMatrix ;
uniform mat3 otherMatrix ;
varying vec3 vMaskCoord ;
varying vec2 vTextureCoord ;
void main ( void )
{
gl _Position = vec4 ( ( projectionMatrix * vec3 ( aVertexPosition , 1.0 ) ) . xy , 0.0 , 1.0 ) ;
vTextureCoord = aTextureCoord ;
vMaskCoord = otherMatrix * vec3 ( aTextureCoord , 1.0 ) ;
}
` , `
varying vec3 vMaskCoord ;
varying vec2 vTextureCoord ;
uniform sampler2D uSampler ;
uniform sampler2D mask ;
uniform float alpha ;
uniform vec4 maskClamp ;
void main ( void )
{
vec2 uv = vMaskCoord . xy / vMaskCoord . z ;
float clip = step ( 3.5 ,
step ( maskClamp . x , uv . x ) +
step ( maskClamp . y , uv . y ) +
step ( uv . x , maskClamp . z ) +
step ( uv . y , maskClamp . w ) ) ;
vec4 original = texture2D ( uSampler , vTextureCoord ) ;
vec4 masky = texture2D ( mask , uv ) ;
original *= ( masky . r * masky . a * alpha * clip ) ;
gl _FragColor = original ;
}
2023-02-15 15:05:11 +01:00
` ),st.prototype.__init.call(this),t.renderable=!1,this.maskSprite=t}__init(){this.maskMatrix=new n}apply(t,e,i,r){var n=this.maskSprite,s=this.maskSprite.texture;s.valid&&(s.uvMatrix||(s.uvMatrix=new _.TextureMatrix(s,0)),s.uvMatrix.update(),this.uniforms.npmAlpha=s.baseTexture.alphaMode?0:1,this.uniforms.mask=n.texture,this.uniforms.otherMatrix=st.calculateSpriteMatrix(e,this.maskMatrix,n).prepend(s.uvMatrix.mapCoord),this.uniforms.alpha=n.worldAlpha,this.uniforms.maskClamp=s.uvMatrix.uClampFrame,t.applyFilter(this,e,i,r))}static calculateSpriteMatrix(t,e,i){var r=i.proj,n=t.filterFrame,r=r&&!r._affine?r.world.copyTo2dOr3d(nt):nt.copyFrom(i.transform.worldTransform),s=i.texture.orig;return e.set(t.width,0,0,t.height,n.x,n.y),r.invert(),e.setToMult(r,e),e.scaleAndTranslate(1/s.width,1/s.height,i.anchor.x,i.anchor.y),e}}_.MaskSystem.prototype.pushSpriteMask=function(t){var e=t["maskObject"],t=t._target;let i=this.alphaMaskPool[this.alphaMaskIndex];(i=i||(this.alphaMaskPool[this.alphaMaskIndex]=[new st(e)]))[0].resolution=this.renderer.resolution,i[0].maskSprite=e;var r=t.filterArea;t.filterArea=e.getBounds(!0),this.renderer.filter.push(t,i),t.filterArea=r,this.alphaMaskIndex++},_.Renderer.registerPlugin("tilingSprite2d",K);class ot extends d.Point{constructor(t,e,i){super(t,e),this.z=i}set(t,e,i){return this.x=t||0,this.y=void 0===e?this.x:e||0,this.z=void 0===e?this.x:i||0,this}copyFrom(t){return this.set(t.x,t.y,t.z||0),this}copyTo(t){return t.set(this.x,this.y,this.z),t}}class y extends d.ObservablePoint{constructor(...t){super(...t),y.prototype.__init.call(this)}__init(){this._z=0}get z(){return this._z}set z(t){this._z!==t&&(this._z=t,this.cb.call(this.scope))}set(t,e,i){var t=t||0,r=void 0===e?t:e||0,e=void 0===e?t:i||0;return this._x===t&&this._y===r&&this._z===e||(this._x=t,this._y=r,this._z=e,this.cb.call(this.scope)),this}copyFrom(t){return this.set(t.x,t.y,t.z||0),this}copyTo(t){return t.set(this._x,this._y,this._z),t}}class b{constructor(t,e,i){b.prototype.__init.call(this),b.prototype.__init2.call(this),b.prototype.__init3.call(this),this._x=t||0,this._y=e||0,this._z=i||0,this.quaternion=new Float64Array(4),this.quaternion[3]=1,this.update()}__init(){this._quatUpdateId=-1}__init2(){this._quatDirtyId=0}__init3(){this._sign=1}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this._quatDirtyId++)}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this._quatDirtyId++)}get z(){return this._z}set z(t){this._z!==t&&(this._z=t,this._quatDirtyId++)}get pitch(){return this._x}set pitch(t){this._x!==t&&(this._x=t,this._quatDirtyId++)}get yaw(){return this._y}set yaw(t){this._y!==t&&(this._y=t,this._quatDirtyId++)}get roll(){return this._z}set roll(t){this._z!==t&&(this._z=t,this._quatDirtyId++)}set(t,e,i){t=t||0,e=e||0,i=i||0;this._x===t&&this._y===e&&this._z===i||(this._x=t,this._y=e,this._z=i,this._quatDirtyId++)}copyFrom(t){var e=t.x,i=t.y,t=t.z;return this._x===e&&this._y===i&&this._z===t||(this._x=e,this._y=i,this._z=t,this._quatDirtyId++),this}copyTo(t){return t.set(this._x,this._y,this._z),t}equals(t){return this._x===t.x&&this._y===t.y&&this._z===t.z}clone(){return new b(this._x,this._y,this._z)}update(){if(this._quatUpdateId===this._quatDirtyId)return!1;this._quatUpdateId=this._quatDirtyId;var t=Math.cos(this._x/2),e=Math.cos(this._y/2),i=Math.cos(this._z/2),r=this._sign,n=r*Math.sin(this._x/2),s=r*Math.sin(this._y/2),r=r*Math.sin(this._z/2),o=this.quaternion;return o[0]=n*e*i+t*s*r,o[1]=t*s*i-n*e*r,o[2]=t*e*r+n*s*i,o[3]=t*e*i-n*s*r,!0}}class x{constructor(t,e,i,r,n){this.cb=t,this.scope=e,x.prototype.__init.call(this),x.prototype.__init2.call(this),x.prototype.__init3.call(this),this._x=i||0,this._y=r||0,this._z=n||0,this.quaternion=new Float64Array(4),this.quaternion[3]=1,this.update()}__init(){this._quatUpdateId=-1}__init2(){this._quatDirtyId=0}__init3(){this._sign=1}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this._quatDirtyId++,this.cb.call(this.scope))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this._quatDirtyId++,this.cb.call(this.scope))}get z(){return this._z}set z(
2022-10-04 10:51:35 +02:00
attribute vec2 aVertexPosition ;
attribute vec3 aTrans1 ;
attribute vec3 aTrans2 ;
attribute vec2 aSamplerSize ;
attribute vec4 aFrame ;
attribute vec4 aColor ;
attribute float aTextureId ;
uniform mat3 projectionMatrix ;
uniform mat3 translationMatrix ;
varying vec2 vertexPosition ;
varying vec3 vTrans1 ;
varying vec3 vTrans2 ;
varying vec2 vSamplerSize ;
varying vec4 vFrame ;
varying vec4 vColor ;
varying float vTextureId ;
void main ( void ) {
gl _Position . xyw = projectionMatrix * translationMatrix * vec3 ( aVertexPosition , 1.0 ) ;
gl _Position . z = 0.0 ;
vertexPosition = aVertexPosition ;
vTrans1 = aTrans1 ;
vTrans2 = aTrans2 ;
vTextureId = aTextureId ;
vColor = aColor ;
vSamplerSize = aSamplerSize ;
vFrame = aFrame ;
}
` ,fragment: ` precision highp float ;
varying vec2 vertexPosition ;
varying vec3 vTrans1 ;
varying vec3 vTrans2 ;
varying vec2 vSamplerSize ;
varying vec4 vFrame ;
varying vec4 vColor ;
varying float vTextureId ;
uniform sampler2D uSamplers [ % count % ] ;
uniform vec4 distortion ;
void main ( void ) {
vec2 surface ;
vec2 surface2 ;
float vx = vertexPosition . x ;
float vy = vertexPosition . y ;
float dx = distortion . x ;
float dy = distortion . y ;
float revx = distortion . z ;
float revy = distortion . w ;
if ( distortion . x == 0.0 ) {
surface . x = vx ;
surface . y = vy / ( 1.0 + dy * vx ) ;
surface2 = surface ;
} else
if ( distortion . y == 0.0 ) {
surface . y = vy ;
surface . x = vx / ( 1.0 + dx * vy ) ;
surface2 = surface ;
} else {
float c = vy * dx - vx * dy ;
float b = ( c + 1.0 ) * 0.5 ;
float b2 = ( - c + 1.0 ) * 0.5 ;
float d = b * b + vx * dy ;
if ( d < - 0.00001 ) {
discard ;
}
d = sqrt ( max ( d , 0.0 ) ) ;
surface . x = ( - b + d ) * revy ;
surface2 . x = ( - b - d ) * revy ;
surface . y = ( - b2 + d ) * revx ;
surface2 . y = ( - b2 - d ) * revx ;
}
vec2 uv ;
uv . x = vTrans1 . x * surface . x + vTrans1 . y * surface . y + vTrans1 . z ;
uv . y = vTrans2 . x * surface . x + vTrans2 . y * surface . y + vTrans2 . z ;
vec2 pixels = uv * vSamplerSize ;
if ( pixels . x < vFrame . x || pixels . x > vFrame . z ||
pixels . y < vFrame . y || pixels . y > vFrame . w ) {
uv . x = vTrans1 . x * surface2 . x + vTrans1 . y * surface2 . y + vTrans1 . z ;
uv . y = vTrans2 . x * surface2 . x + vTrans2 . y * surface2 . y + vTrans2 . z ;
pixels = uv * vSamplerSize ;
if ( pixels . x < vFrame . x || pixels . x > vFrame . z ||
pixels . y < vFrame . y || pixels . y > vFrame . w ) {
discard ;
}
}
vec4 edge ;
edge . xy = clamp ( pixels - vFrame . xy + 0.5 , vec2 ( 0.0 , 0.0 ) , vec2 ( 1.0 , 1.0 ) ) ;
edge . zw = clamp ( vFrame . zw - pixels + 0.5 , vec2 ( 0.0 , 0.0 ) , vec2 ( 1.0 , 1.0 ) ) ;
float alpha = 1.0 ; //edge.x * edge.y * edge.z * edge.w;
vec4 rColor = vColor * alpha ;
float textureId = floor ( vTextureId + 0.5 ) ;
vec2 vTextureCoord = uv ;
vec4 color ;
% forloop %
gl _FragColor = color * rColor ;
2023-02-15 15:05:11 +01:00
} ` ,geometryClass:_t,vertexSize:16},t);return X=class extends Y{constructor(t){super(t),X.prototype.__init.call(this),X.prototype.__init2.call(this),X.prototype.__init3.call(this),this.shaderGenerator=new _.BatchShaderGenerator(e,i),this.geometryClass=n,this.vertexSize=r}__init(){this.defUniforms={translationMatrix:new d.Matrix,distortion:new Float32Array([0,0,1/0,1/0])}}__init2(){this.size=1e3}__init3(){this.forceMaxTextures=1}getUniforms(t){t=t.proj;return null!==t.surface?t.uniforms:null!==t._activeProjection?t._activeProjection.uniforms:this.defUniforms}packInterleavedGeometry(t,e,i,r,n){var{uint32View:s,float32View:o}=e,a=r/this.vertexSize,l=t.indices,h=t.vertexData,u=t._texture._frame,c=t.aTrans,{_batchLocation:p,realWidth:d,realHeight:f,resolution:m}=t._texture.baseTexture,e=Math.min(t.worldAlpha,1),_=e<1&&t._texture.baseTexture.alphaMode?g.premultiplyTint(t._tintRGB,e):t._tintRGB+(255*e<<24);for(let t=0;t<h.length;t+=2)o[r]=h[t],o[r+1]=h[t+1],o[r+2]=c.a,o[r+3]=c.c,o[r+4]=c.tx,o[r+5]=c.b,o[r+6]=c.d,o[r+7]=c.ty,o[r+8]=d,o[r+9]=f,o[r+10]=u.x*m,o[r+11]=u.y*m,o[r+12]=(u.x+u.width)*m,o[r+13]=(u.y+u.height)*m,s[r+14]=_,o[r+15]=p,r+=16;for(let t=0;t<l.length;t++)i[n++]=a+l[t]}}}}const R=[new d.Point,new d.Point,new d.Point,new d.Point],C=[0,0,0,0];class M{constructor(){M.prototype.__init.call(this),M.prototype.__init2.call(this),M.prototype.__init3.call(this),M.prototype.__init4.call(this)}__init(){this.surfaceID="default"}__init2(){this._updateID=0}__init3(){this.vertexSrc=""}__init4(){this.fragmentSrc=""}fillUniforms(t){}clear(){}boundsQuad(t,e,i){let r=e[0],n=e[1],s=e[0],o=e[1];for(let t=2;t<8;t+=2)r>e[t]&&(r=e[t]),s<e[t]&&(s=e[t]),n>e[t+1]&&(n=e[t+1]),o<e[t+1]&&(o=e[t+1]);if(R[0].set(r,n),this.apply(R[0],R[0]),R[1].set(s,n),this.apply(R[1],R[1]),R[2].set(s,o),this.apply(R[2],R[2]),R[3].set(r,o),this.apply(R[3],R[3]),i)i.apply(R[0],R[0]),i.apply(R[1],R[1]),i.apply(R[2],R[2]),i.apply(R[3],R[3]),e[0]=R[0].x,e[1]=R[0].y,e[2]=R[1].x,e[3]=R[1].y,e[4]=R[2].x,e[5]=R[2].y,e[6]=R[3].x,e[7]=R[3].y;else{for(let t=1;t<=3;t++){var a;(R[t].y<R[0].y||R[t].y===R[0].y&&R[t].x<R[0].x)&&(a=R[0],R[0]=R[t],R[t]=a)}for(let t=1;t<=3;t++)C[t]=Math.atan2(R[t].y-R[0].y,R[t].x-R[0].x);for(let e=1;e<=3;e++)for(let t=e+1;t<=3;t++){var l;C[e]>C[t]&&(l=R[e],R[e]=R[t],R[t]=l,l=C[e],C[e]=C[t],C[t]=l)}e[0]=R[0].x,e[1]=R[0].y,e[2]=R[1].x,e[3]=R[1].y,e[4]=R[2].x,e[5]=R[2].y,e[6]=R[3].x,e[7]=R[3].y,(R[3].x-R[2].x)*(R[1].y-R[2].y)-(R[1].x-R[2].x)*(R[3].y-R[2].y)<0&&(e[4]=R[3].x,e[5]=R[3].y)}}}const vt=new d.Matrix,k=new d.Rectangle,I=new d.Point;class yt extends M{constructor(...t){super(...t),yt.prototype.__init.call(this)}__init(){this.distortion=new d.Point}clear(){this.distortion.set(0,0)}apply(t,e){e=e||new d.Point;var i=this.distortion,r=t.x*t.y;return e.x=t.x+i.x*r,e.y=t.y+i.y*r,e}applyInverse(t,e){e=e||new d.Point;var i=t.x,t=t.y,r=this.distortion.x,n=this.distortion.y;if(0===r)e.x=i,e.y=t/(1+n*i);else if(0===n)e.y=t,e.x=i/(1+r*t);else{var t=.5*(t*r-i*n+1)/n,s=t*t+i/n;if(s<=1e-5)return e.set(NaN,NaN),e;e.x=0<n?-t+Math.sqrt(s):-t-Math.sqrt(s),e.y=(i/e.x-1)/r}return e}mapSprite(t,e,i){var r=t.texture;return k.x=-t.anchor.x*r.orig.width,k.y=-t.anchor.y*r.orig.height,k.width=r.orig.width,k.height=r.orig.height,this.mapQuad(k,e,i||t.transform)}mapQuad(t,e,i){var r=-t.x/t.width,n=-t.y/t.height,s=(1-t.x)/t.width,t=(1-t.y)/t.height,o=e[0].x*(1-r)+e[1].x*r,a=e[0].y*(1-r)+e[1].y*r,l=e[0].x*(1-s)+e[1].x*s,h=e[0].y*(1-s)+e[1].y*s,u=e[3].x*(1-r)+e[2].x*r,r=e[3].y*(1-r)+e[2].y*r,c=e[3].x*(1-s)+e[2].x*s,e=e[3].y*(1-s)+e[2].y*s,s=o*(1-n)+u*n,p=a*(1-n)+r*n,d=l*(1-n)+c*n,n=h*(1-n)+e*n,o=o*(1-t)+u*t,u=a*(1-t)+r*t,a=l*(1-t)+c*t,r=h*(1-t)+e*t,l=vt;return l.tx=s,l.ty=p,l.a=d-s,l.b=n-p,l.c=o-s,l.d=u-p,I.set(a,r),l.applyInverse(I,I),this.distortion.set(I.x-1,I.y-1),i.setFromMatrix(l),this}fillUniforms(t){t.distortion=t.distortion||new Float32Array([0,0,0,0]);var e=Math.abs(this.distortion.x),i=Math.abs(this.distortion.y);t.distortion[0]=1e4*e<=i?0:this.distortion.x,t.distortion[1]=1e4*i<=e?0:this.distortion.y,t.distortion[2]=1/t.distortion[0],t.distortion[3]=1/t.distorti