2023-05-02 15:09:38 +02:00
! function ( e , t ) { "object" == typeof exports && "object" == typeof module ? module . exports = t ( ) : "function" == typeof define && define . amd ? define ( [ ] , t ) : "object" == typeof exports ? exports . OptimalSelect = t ( ) : e . OptimalSelect = t ( ) } ( this , function ( ) { return i = [ function ( e , t , i ) { "use strict" ; Object . defineProperty ( t , "__esModule" , { value : ! 0 } ) , t . convertNodeList = function ( e ) { for ( var t = e . length , i = new Array ( t ) , r = 0 ; r < t ; r ++ ) i [ r ] = e [ r ] ; return i } , t . escapeValue = function ( e ) { return e && e . replace ( /['"`\\/:\?&!#$%^()[\]{|}*+;,.<=>@~]/g , "\\$&" ) . replace ( /\n/g , "A" ) } } , function ( e , t , i ) { "use strict" ; Object . defineProperty ( t , "__esModule" , { value : ! 0 } ) , t . getCommonAncestor = function ( e ) { for ( var t = ( 1 < arguments . length && void 0 !== arguments [ 1 ] ? arguments [ 1 ] : { } ) . root , r = void 0 === t ? document : t , n = [ ] , i = ( e . forEach ( function ( e , t ) { for ( var i = [ ] ; e !== r ; ) e = e . parentNode , i . unshift ( e ) ; n [ t ] = i } ) , n . sort ( function ( e , t ) { return e . length - t . length } ) , n . shift ( ) ) , s = null , o = 0 , a = i . length ; o < a ; o ++ ) if ( "break" === function ( ) { var t = i [ o ] ; if ( n . some ( function ( e ) { return ! e . some ( function ( e ) { return e === t } ) } ) ) return "break" ; s = t } ( ) ) break ; return s } , t . getCommonProperties = function ( e ) { var l = { classes : [ ] , attributes : { } , tag : null } ; return e . forEach ( function ( e ) { var i , r , n , t , s = l . classes , o = l . attributes , a = l . tag ; void 0 !== s && ( ( i = e . getAttribute ( "class" ) ) ? ( i = i . trim ( ) . split ( " " ) , s . length ? ( s = s . filter ( function ( t ) { return i . some ( function ( e ) { return e === t } ) } ) ) . length ? l . classes = s : delete l . classes : l . classes = i ) : delete l . classes ) , void 0 !== o && ( r = e . attributes , n = Object . keys ( r ) . reduce ( function ( e , t ) { var t = r [ t ] , i = t . name ; return t && "class" !== i && ( e [ i ] = t . value ) , e } , { } ) , s = Object . keys ( n ) , t = Object . keys ( o ) , s . length ? t . length ? ( o = t . reduce ( function ( e , t ) { var i = o [ t ] ; return i === n [ t ] && ( e [ t ] = i ) , e } , { } ) , Object . keys ( o ) . length ? l . attributes = o : delete l . attributes ) : l . attributes = n : delete l . attributes ) , void 0 !== a && ( s = e . tagName . toLowerCase ( ) , a ? s !== a && delete l . tag : l . tag = s ) } ) , l } } , function ( e , t , i ) { "use strict" ; Object . defineProperty ( t , "__esModule" , { value : ! 0 } ) , t . default = function ( e , t ) { var i = 2 < arguments . length && void 0 !== arguments [ 2 ] ? arguments [ 2 ] : { } ; Array . isArray ( t ) || ( t = t . length ? ( 0 , h . convertNodeList ) ( t ) : [ t ] ) ; if ( ! t . length || t . some ( function ( e ) { return 1 !== e . nodeType } ) ) throw new Error ( 'Invalid input - to compare HTMLElements its necessary to provide a reference of the selected node(s)! (missing "elements")' ) ; ( 0 , u . default ) ( t [ 0 ] , i ) ; var r = e . replace ( /> /g , ">" ) . split ( /\s+(?=(?:(?:[^"]*"){2})*[^"]*$)/ ) ; if ( r . length < 2 ) return c ( "" , e , "" , t ) ; 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 !== t . length && n . unshift ( c ( o , s , a , t ) ) } n . unshift ( r [ 0 ] ) , ( r = n ) [ 0 ] = c ( "" , r [ 0 ] , r . slice ( 1 ) . join ( " " ) , t ) , r [ r . length - 1 ] = c ( r . slice ( 0 , - 1 ) . join ( " " ) , r [ r . length - 1 ] , "" , t ) ; return r . join ( " " ) . replace ( />/g , "> " ) . trim ( ) } ; var r = i ( 3 ) , u = ( r = r ) && r . _ _esModule ? r : { default : r } , h = i ( 0 ) ; function c ( i , r , n , s ) { if ( i . length && ( i += " " ) , n . length && ( n = " " + n ) , /\[*\]/ . test ( r ) ) { var e = r . replace ( /=.*$/ , "]" ) , o = "" + i + e + n ; if ( p ( document . querySelectorAll ( o ) , s ) ) r = e ; else for ( var a = document . querySelectorAll ( "" + i + e ) , l = 0 , t = a . length ; l < t ; l ++ ) if ( "break" === function ( ) { var e , t = a [ l ] ; if ( s . some ( function ( e ) { return t . contains ( e ) } ) ) return e = t . tagName . toLowerCase ( ) , o = "" + i + e + n , p ( document . querySelectorAll ( o ) , s ) && ( r = e ) , "break" } ( ) ) break } if ( />/ . test ( r ) && ( e = r . replace ( />/ , "" ) , o = "" + i + e + n , p ( document . querySelectorAll ( o ) , s ) && ( r = e ) ) , /:nth-child/ . test ( r ) && ( e = r . replace ( /nth-child/g , "nth-of-type" ) , o = "" + i + e + n , p ( document . querySelectorAll ( o ) , s ) && ( r = e ) ) , /\.\S+\.\S+/ . test ( r ) ) { for ( var u = r . trim ( ) . split ( "." ) . slice ( 1 ) . map ( function ( e ) { return "." + e } ) . sort ( function ( e , t ) { return e . length - t . length } ) ; u . length ; ) { var h = r . replace ( u . shift ( ) , "" ) . trim ( ) ; if ( ! ( o = ( "" + i + h + n ) . trim ( ) ) . length || ">" === o . charAt ( 0 ) || ">" === o . charAt ( o . length - 1 ) ) break ; p ( document . querySelectorAll ( o ) , s ) && ( r = h ) } if ( ( u = r && r . match ( /\./g ) ) && 2 < u . length ) for ( var c = document . querySelectorAll ( "" + i + r ) , l = 0 , t = c . length ; l < t ; l ++ ) if ( "break" === function ( ) { var e , t = c [ l ] ; if ( s . some ( function ( e ) { return t . contains ( e ) } ) ) return e = t . tagName . toLowerCase ( ) , o = "" + i + e + n , p ( document . querySelectorAll ( o ) , s ) && ( r = e ) , "break" } ( ) ) break } return r } function p ( i , e ) { var r = i . length ; return r === e . length && e . every ( function ( e ) { for ( var t = 0 ; t < r ; t ++ ) if ( i [ t ] === e ) 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-05-02 15:09:38 +02:00
} ` ,geometryClass:U,vertexSize:7},e);return class extends _.AbstractBatchRenderer{constructor(e){super(e),this.shaderGenerator=new _.BatchShaderGenerator(t,i),this.geometryClass=n,this.vertexSize=r}packInterleavedGeometry(e,t,i,r,n){var{uint32View:s,float32View:o}=t,a=r/this.vertexSize,l=e.uvs,u=e.indices,h=e.vertexData,c=e.vertexData2d,p=e._texture.baseTexture._batchLocation,t=Math.min(e.worldAlpha,1),d=t<1&&e._texture.baseTexture.alphaMode?g.premultiplyTint(e._tintRGB,t):e._tintRGB+(255*t<<24);if(c){let t=0;for(let e=0;e<c.length;e+=3,t+=2)o[r++]=c[e],o[r++]=c[e+1],o[r++]=c[e+2],o[r++]=l[t],o[r++]=l[t+1],s[r++]=d,o[r++]=p}else for(let e=0;e<h.length;e+=2)o[r++]=h[e],o[r++]=h[e+1],o[r++]=1,o[r++]=l[e],o[r++]=l[e+1],s[r++]=d,o[r++]=p;for(let e=0;e<u.length;e++)i[n++]=a+u[e]}}}}class G{constructor(e,t=!0){G.prototype.__init.call(this),this.legacy=e,t&&(this.enabled=!0),this.legacy.proj=this}__init(){this._enabled=!1}get enabled(){return this._enabled}set enabled(e){this._enabled=e}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(e){var t=this.proj,i=this,r=e._worldID,n=i.localTransform,s=t.scaleAfterAffine&&2<=t.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,t._currentProjID=-1),t._projID);t._currentProjID!==o&&(t._currentProjID=o,t.updateLocalTransform(n),i._parentID=-1),i._parentID!==r&&((o=e.proj)&&!o._affine?t.world.setToMult(o.world,t.local):t.world.setToMultLegacy(e.worldTransform,t.local),n=i.worldTransform,t.world.copyTo(n,t._affine,t.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(...e){super(...e),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(e){}__init(){this._projID=0}__init2(){this._currentProjID=-1}__init3(){this._affine=a.AFFINE.NONE}__init4(){this.affinePreserveOrientation=!1}__init5(){this.scaleAfterAffine=!0}set affine(e){this._affine!==e&&(this._affine=e,this._currentProjID=-1,this.legacy._currentLocalID=-1)}get affine(){return this._affine}set enabled(e){e!==this._enabled&&(this._enabled=e,this.legacy.updateTransform=e?H:d.Transform.prototype.updateTransform,this.legacy._parentID=-1)}clear(){this._currentProjID=-1,this._projID=0}}class Y extends _.AbstractBatchRenderer{constructor(...e){super(...e),Y.prototype.__init.call(this),Y.prototype.__init2.call(this)}__init(){this.forceMaxTextures=0}getUniforms(e){return this.defUniforms}syncUniforms(e){if(e){var t=this._shader;for(const i in e)t.uniforms[i]=e[i]}}__init2(){this.defUniforms={}}buildDrawCalls(t,i,r){var{_bufferedElements:n,_attributeBuffer:s,_indexBuffer:o,vertexSize:a}=this,l=_.AbstractBatchRenderer._drawCallPool;let u=this._dcIndex,h=this._aIndex,c=this._iIndex,p=l[u];p.start=this._iIndex,p.texArray=t;for(let e=i;e<r;++e){var d=n[e],f=d._texture.baseTexture,f=g.premultiplyBlendMode[f.alphaMode?1:0][d.blendMode],m=this.getUniforms(d);n[e]=null,i<e&&(p.blend!==f||p.uniforms!==m)&&(p.size=c-p.start,i=e,(p=l[++u]).texArray=t,p.start=c),this.packInterleavedGeometry(d,s,o,h,c),h+=d.vertexData.length/2*a,c+=d.indices.length,p.blend=f,p.uniforms=m}i<r&&(p.size=c-p.start,++u),this._dcIndex=u,this._aIndex=h,this._iIndex=c}drawBatches(){var t=this._dcIndex,{gl:i,state:r,shader:n}=this.renderer,s=_.AbstractBatchRenderer._drawCallPool;let o=null,a=null;for(let e=0;e
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-05-02 15:09:38 +02:00
` ,c=new n;class K extends _.ObjectRenderer{constructor(e){super(e),K.prototype.__init.call(this);e={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-05-02 15:09:38 +02:00
` ,e),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-05-02 15:09:38 +02:00
` ,e)}__init(){this.quad=new _.QuadUv}render(e){var t=this.renderer,i=this.quad;let r=i.vertices;r[0]=r[6]=e._width*-e.anchor.x,r[1]=r[3]=e._height*-e.anchor.y,r[2]=r[4]=e._width*(1-e.anchor.x),r[5]=r[7]=e._height*(1-e.anchor.y),e.uvRespectAnchor&&((r=i.uvs)[0]=r[6]=-e.anchor.x,r[1]=r[3]=-e.anchor.y,r[2]=r[4]=1-e.anchor.x,r[5]=r[7]=1-e.anchor.y),i.invalidate();var n=e._texture,s=n.baseTexture,o=e.tileProj.world,a=e.uvMatrix;let l=s.isPowerOfTwo&&n.frame.width===s.width&&n.frame.height===s.height;l&&(s._glTextures[t.CONTEXT_UID]?l=s.wrapMode!==h.WRAP_MODES.CLAMP:s.wrapMode===h.WRAP_MODES.CLAMP&&(s.wrapMode=h.WRAP_MODES.REPEAT));var u=l?this.simpleShader:this.shader;c.identity(),c.scale(n.width,n.height),c.prepend(o),c.scale(1/e._width,1/e._height),c.invert(),l?c.prepend(a.mapCoord):(u.uniforms.uMapCoord=a.mapCoord.toArray(!0),u.uniforms.uClampFrame=a.uClampFrame,u.uniforms.uClampOffset=a.uClampOffset),u.uniforms.uTransform=c.toArray(!0),u.uniforms.uColor=g.premultiplyTintToRgba(e.tint,e.worldAlpha,u.uniforms.uColor,s.premultiplyAlpha),u.uniforms.translationMatrix=e.worldTransform.toArray(!0),u.uniforms.uSampler=n,t.shader.bind(u,!1),t.geometry.bind(i,void 0),t.state.setBlendMode(g.correctBlendMode(e.blendMode,s.premultiplyAlpha)),t.geometry.draw(h.DRAW_MODES.TRIANGLES,6,0)}}const u=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(e,t){super(e,t),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 e=this.pivot,t=this.matrix.mat3;t[6]=-(e._x*t[0]+e._y*t[3]),t[7]=-(e._x*t[1]+e._y*t[4]),this._projID++}setAxisX(e,t=1){var i=e.x,e=e.y,r=Math.sqrt(i*i+e*e),n=this.matrix.mat3;n[0]=i/r,n[1]=e/r,n[2]=t/r,this.onChange()}setAxisY(e,t=1){var i=e.x,e=e.y,r=Math.sqrt(i*i+e*e),n=this.matrix.mat3;n[3]=i/r,n[4]=e/r,n[5]=t/r,this.onChange()}mapSprite(e,t){var i=e.texture;o.x=-e.anchor.x*i.orig.width,o.y=-e.anchor.y*i.orig.height,o.width=i.orig.width,o.height=i.orig.height,this.mapQuad(o,t)}mapQuad(t,i){p[0].set(t.x,t.y),p[1].set(t.x+t.width,t.y),p[2].set(t.x+t.width,t.y+t.height),p[3].set(t.x,t.y+t.height);let r=1,n=2,s=3;t=W(i[0],i[2],i[1],i[3],u);if(0!==t){r=1,n=3,s=2;var t=Math.sqrt((i[0].x-u.x)*(i[0].x-u.x)+(i[0].y-u.y)*(i[0].y-u.y)),o=Math.sqrt((i[r].x-u.x)*(i[r].x-u.x)+(i[r].y-u.y)*(i[r].y-u.y)),a=Math.sqrt((i[n].x-u.x)*(i[n].x-u.x)+(i[n].y-u.y)*(i[n].y-u.y)),l=Math.sqrt((i[s].x-u.x)*(i[s].x-u.x)+(i[s].y-u.y)*(i[s].y-u.y)),t=(t+l)/l,l=(o+a)/a,a=(o+a)/o;let e=this.matrix.mat3;e[0]=p[0].x*t,e[1]=p[0].y*t,e[2]=t,e[3]=p[r].x*l,e[4]=p[r].y*l,e[5]=l,e[6]=p[n].x*a,e[7]=p[n].y*a,e[8]=a,this.matrix.invert(),(e=Z.mat3)[0]=i[0].x,e[1]=i[0].y,e[2]=1,e[3]=i[r].x,e[4]=i[r].y,e[5]=1,e[6]=i[n].x,e[7]=i[n].y,e[8]=1,this.matrix.setToMult(Z,this.matrix),this._projID++}}updateLocalTransform(e){0!==this._projID?this.reverseLocalOrder?this.local.setToMultLegacy2(this.matrix,e):this.local.setToMultLegacy(e,this.matrix):this.local.copyFrom(e)}clear(){super.clear(),this.matrix.identity(),this.pivot.set(0,0)}}function J(){return this.proj.affine?this.transform.worldTransform:this.proj.world}class Q extends e.Container{constructor(){super(),this.proj=new l(this.transform)}toLocal(e,t,i,r,n=a.TRANSFORM_STEP.ALL){return t&&(e=t.toGlobal(e,i,r)),r||this._recursivePostUpdateTransform(),n>=a.TRANSFORM_STEP.PROJ?(r||this.displayObjectUpdateTransform(),(this.proj.affine?this.transform.worldTransform:this.proj.world).applyInverse(e,i)):(this.parent?i=this.parent.worldTransform.applyInverse(e,i):(i.x=e.x,i.y=e.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 $ =Q.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-05-02 15:09:38 +02:00
} ` }constructor(e,t,i,r){super(e,t,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 e=this.geometry,t=e.buffers[0].data;if(e.vertexDirtyId!==this.vertexDirty||this._transformID!==this.transform._worldID){this._transformID=this.transform._worldID,this.vertexData.length!==t.length&&(this.vertexData=new Float32Array(t.length)),this.vertexData2d&&this.vertexData2d.length===3*t.length/2||(this.vertexData2d=new Float32Array(3*t.length));var i=this.proj.world.mat3,r=this.vertexData2d,n=this.vertexData;for(let e=0;e<n.length/2;e++){var s=t[2*e],o=t[2*e+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*e]=a,r[3*e+1]=l,r[3*e+2]=s,n[2*e]=a/s,n[2*e+1]=l/s}this.vertexDirty=e.vertexDirtyId}}}_renderDefault(e){var t=this.shader;t.alpha=this.worldAlpha,t.update&&t.update(),e.batch.flush(),function(e){let t=void 0,i=e[0],r=1;for(;r<e.length;){var n=e[r],s=e[r+1];if(r+=2,("optionalAccess"===n||"optionalCall"===n)&&null==i)return;"access"===n||"optionalAccess"===n?i=s(t=i):"call"!==n&&"optionalCall"!==n||(i=s((...e)=>i.call(t,...e)),t=void 0)}return i}([t,"access",e=>e.program,"access",e=>e.uniformData,"optionalAccess",e=>e.translationMatrix])&&(t.uniforms.translationMatrix=this.worldTransform.toArray(!0)),e.shader.bind(t,!1),e.state.set(this.state),e.geometry.bind(this.geometry,t),e.geometry.draw(this.drawMode,this.size,this.start,this.geometry.instanceCount)}toLocal(e,t,i,r,n=a.TRANSFORM_STEP.ALL){return $ .call(this,e,t,i,r,n)}get worldTransform(){return this.proj.affine?this.transform.worldTransform:this.proj.world}}f.__initStatic(),f.__initStatic2();class ee extends f{constructor(e,t,i,r,n){super(new s.MeshGeometry(t,i,r),new s.MeshMaterial(e,{program:_.Program.from(f.defaultVertexShader,f.defaultFragmentShader),pluginName:"batch2d"}),null,n),ee.prototype.__init2.call(this),this.geometry.getBuffer("aVertexPosition").static=!1}__init2(){this.autoUpdate=!0}get vertices(){return this.geometry.getBuffer("aVertexPosition").data}set vertices(e){this.geometry.getBuffer("aVertexPosition").data=e}_render(e){this.autoUpdate&&this.geometry.getBuffer("aVertexPosition").update(),super._render(e)}}class m extends t.Sprite{constructor(e){super(e),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,u=this._anchor;let e,t,i,r;i=l?(t=l.x-u._x*n.width,e=t+l.width,(r=l.y-u._y*n.height)+l.height):(t=-u._x*n.width,e=t+n.width,(r=-u._y*n.height)+n.height),o[0]=s[0]*t+s[3]*r+s[6],o[1]=s[1]*t+s[4]*r+s[7],o[2]=s[2]*t+s[5]*r+s[8],o[3]=s[0]*e+s[3]*r+s[6],o[4]=s[1]*e+s[4]*r+s[7],o[5]=s[2]*e+s[5]*r+s[8],o[6]=s[0]*e+s[3]*i+s[6],o[7]=s[1]*e+s[4]*i+s[7],o[8]=s[2]*e+s[5]*i+s[8],o[9]=s[0]*t+s[3]*i+s[6],o[10]=s[1]*t+s[4]*i+s[7],o[11]=s[2]*t+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 e=this.transform._worldID,t=this._texture._updateID;if(this.vertexTrimmedData){if(this._transformTrimmedID===e&&this._textureTrimmedID===t)return}else this.vertexTrimmedData=new Float32Array(8);this._transformTrimmedID=e,this._textureTrimmedID=t;var e=this._texture,t=this.vertexTrimmedData,e=e.orig,i=this.tileProj?this._width:e.width,e=this.tileProj?this._height:e.height,r=this._anchor,n=this.proj.world.mat3,s=-r._x*i,i=s+i,r=-r._y*e,e=r+e,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-05-02 15:09:38 +02:00
` ),se.prototype.__init.call(this),e.renderable=!1,this.maskSprite=e}__init(){this.maskMatrix=new n}apply(e,t,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=se.calculateSpriteMatrix(t,this.maskMatrix,n).prepend(s.uvMatrix.mapCoord),this.uniforms.alpha=n.worldAlpha,this.uniforms.maskClamp=s.uvMatrix.uClampFrame,e.applyFilter(this,t,i,r))}static calculateSpriteMatrix(e,t,i){var r=i.proj,n=e.filterFrame,r=r&&!r._affine?r.world.copyTo2dOr3d(ne):ne.copyFrom(i.transform.worldTransform),s=i.texture.orig;return t.set(e.width,0,0,e.height,n.x,n.y),r.invert(),t.setToMult(r,t),t.scaleAndTranslate(1/s.width,1/s.height,i.anchor.x,i.anchor.y),t}}_.MaskSystem.prototype.pushSpriteMask=function(e){var t=e["maskObject"],e=e._target;let i=this.alphaMaskPool[this.alphaMaskIndex];(i=i||(this.alphaMaskPool[this.alphaMaskIndex]=[new se(t)]))[0].resolution=this.renderer.resolution,i[0].maskSprite=t;var r=e.filterArea;e.filterArea=t.getBounds(!0),this.renderer.filter.push(e,i),e.filterArea=r,this.alphaMaskIndex++},_.Renderer.registerPlugin("tilingSprite2d",K);class oe extends d.Point{constructor(e,t,i){super(e,t),this.z=i}set(e,t,i){return this.x=e||0,this.y=void 0===t?this.x:t||0,this.z=void 0===t?this.x:i||0,this}copyFrom(e){return this.set(e.x,e.y,e.z||0),this}copyTo(e){return e.set(this.x,this.y,this.z),e}}class y extends d.ObservablePoint{constructor(...e){super(...e),y.prototype.__init.call(this)}__init(){this._z=0}get z(){return this._z}set z(e){this._z!==e&&(this._z=e,this.cb.call(this.scope))}set(e,t,i){var e=e||0,r=void 0===t?e:t||0,t=void 0===t?e:i||0;return this._x===e&&this._y===r&&this._z===t||(this._x=e,this._y=r,this._z=t,this.cb.call(this.scope)),this}copyFrom(e){return this.set(e.x,e.y,e.z||0),this}copyTo(e){return e.set(this._x,this._y,this._z),e}}class b{constructor(e,t,i){b.prototype.__init.call(this),b.prototype.__init2.call(this),b.prototype.__init3.call(this),this._x=e||0,this._y=t||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(e){this._x!==e&&(this._x=e,this._quatDirtyId++)}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._quatDirtyId++)}get z(){return this._z}set z(e){this._z!==e&&(this._z=e,this._quatDirtyId++)}get pitch(){return this._x}set pitch(e){this._x!==e&&(this._x=e,this._quatDirtyId++)}get yaw(){return this._y}set yaw(e){this._y!==e&&(this._y=e,this._quatDirtyId++)}get roll(){return this._z}set roll(e){this._z!==e&&(this._z=e,this._quatDirtyId++)}set(e,t,i){e=e||0,t=t||0,i=i||0;this._x===e&&this._y===t&&this._z===i||(this._x=e,this._y=t,this._z=i,this._quatDirtyId++)}copyFrom(e){var t=e.x,i=e.y,e=e.z;return this._x===t&&this._y===i&&this._z===e||(this._x=t,this._y=i,this._z=e,this._quatDirtyId++),this}copyTo(e){return e.set(this._x,this._y,this._z),e}equals(e){return this._x===e.x&&this._y===e.y&&this._z===e.z}clone(){return new b(this._x,this._y,this._z)}update(){if(this._quatUpdateId===this._quatDirtyId)return!1;this._quatUpdateId=this._quatDirtyId;var e=Math.cos(this._x/2),t=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*t*i+e*s*r,o[1]=e*s*i-n*t*r,o[2]=e*t*r+n*s*i,o[3]=e*t*i-n*s*r,!0}}class x{constructor(e,t,i,r,n){this.cb=e,this.scope=t,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(e){this._x!==e&&(this._x=e,this._quatDirtyId++,this.cb.call(this.scope))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,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-05-02 15:09:38 +02:00
} ` ,geometryClass:_e,vertexSize:16},e);return X=class extends Y{constructor(e){super(e),X.prototype.__init.call(this),X.prototype.__init2.call(this),X.prototype.__init3.call(this),this.shaderGenerator=new _.BatchShaderGenerator(t,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(e){e=e.proj;return null!==e.surface?e.uniforms:null!==e._activeProjection?e._activeProjection.uniforms:this.defUniforms}packInterleavedGeometry(e,t,i,r,n){var{uint32View:s,float32View:o}=t,a=r/this.vertexSize,l=e.indices,u=e.vertexData,h=e._texture._frame,c=e.aTrans,{_batchLocation:p,realWidth:d,realHeight:f,resolution:m}=e._texture.baseTexture,t=Math.min(e.worldAlpha,1),_=t<1&&e._texture.baseTexture.alphaMode?g.premultiplyTint(e._tintRGB,t):e._tintRGB+(255*t<<24);for(let e=0;e<u.length;e+=2)o[r]=u[e],o[r+1]=u[e+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]=h.x*m,o[r+11]=h.y*m,o[r+12]=(h.x+h.width)*m,o[r+13]=(h.y+h.height)*m,s[r+14]=_,o[r+15]=p,r+=16;for(let e=0;e<l.length;e++)i[n++]=a+l[e]}}}}const O=[new d.Point,new d.Point,new d.Point,new d.Point],R=[0,0,0,0];class C{constructor(){C.prototype.__init.call(this),C.prototype.__init2.call(this),C.prototype.__init3.call(this),C.prototype.__init4.call(this)}__init(){this.surfaceID="default"}__init2(){this._updateID=0}__init3(){this.vertexSrc=""}__init4(){this.fragmentSrc=""}fillUniforms(e){}clear(){}boundsQuad(e,t,i){let r=t[0],n=t[1],s=t[0],o=t[1];for(let e=2;e<8;e+=2)r>t[e]&&(r=t[e]),s<t[e]&&(s=t[e]),n>t[e+1]&&(n=t[e+1]),o<t[e+1]&&(o=t[e+1]);if(O[0].set(r,n),this.apply(O[0],O[0]),O[1].set(s,n),this.apply(O[1],O[1]),O[2].set(s,o),this.apply(O[2],O[2]),O[3].set(r,o),this.apply(O[3],O[3]),i)i.apply(O[0],O[0]),i.apply(O[1],O[1]),i.apply(O[2],O[2]),i.apply(O[3],O[3]),t[0]=O[0].x,t[1]=O[0].y,t[2]=O[1].x,t[3]=O[1].y,t[4]=O[2].x,t[5]=O[2].y,t[6]=O[3].x,t[7]=O[3].y;else{for(let e=1;e<=3;e++){var a;(O[e].y<O[0].y||O[e].y===O[0].y&&O[e].x<O[0].x)&&(a=O[0],O[0]=O[e],O[e]=a)}for(let e=1;e<=3;e++)R[e]=Math.atan2(O[e].y-O[0].y,O[e].x-O[0].x);for(let t=1;t<=3;t++)for(let e=t+1;e<=3;e++){var l;R[t]>R[e]&&(l=O[t],O[t]=O[e],O[e]=l,l=R[t],R[t]=R[e],R[e]=l)}t[0]=O[0].x,t[1]=O[0].y,t[2]=O[1].x,t[3]=O[1].y,t[4]=O[2].x,t[5]=O[2].y,t[6]=O[3].x,t[7]=O[3].y,(O[3].x-O[2].x)*(O[1].y-O[2].y)-(O[1].x-O[2].x)*(O[3].y-O[2].y)<0&&(t[4]=O[3].x,t[5]=O[3].y)}}}const ve=new d.Matrix,M=new d.Rectangle,I=new d.Point;class ye extends C{constructor(...e){super(...e),ye.prototype.__init.call(this)}__init(){this.distortion=new d.Point}clear(){this.distortion.set(0,0)}apply(e,t){t=t||new d.Point;var i=this.distortion,r=e.x*e.y;return t.x=e.x+i.x*r,t.y=e.y+i.y*r,t}applyInverse(e,t){t=t||new d.Point;var i=e.x,e=e.y,r=this.distortion.x,n=this.distortion.y;if(0===r)t.x=i,t.y=e/(1+n*i);else if(0===n)t.y=e,t.x=i/(1+r*e);else{var e=.5*(e*r-i*n+1)/n,s=e*e+i/n;if(s<=1e-5)return t.set(NaN,NaN),t;t.x=0<n?-e+Math.sqrt(s):-e-Math.sqrt(s),t.y=(i/t.x-1)/r}return t}mapSprite(e,t,i){var r=e.texture;return M.x=-e.anchor.x*r.orig.width,M.y=-e.anchor.y*r.orig.height,M.width=r.orig.width,M.height=r.orig.height,this.mapQuad(M,t,i||e.transform)}mapQuad(e,t,i){var r=-e.x/e.width,n=-e.y/e.height,s=(1-e.x)/e.width,e=(1-e.y)/e.height,o=t[0].x*(1-r)+t[1].x*r,a=t[0].y*(1-r)+t[1].y*r,l=t[0].x*(1-s)+t[1].x*s,u=t[0].y*(1-s)+t[1].y*s,h=t[3].x*(1-r)+t[2].x*r,r=t[3].y*(1-r)+t[2].y*r,c=t[3].x*(1-s)+t[2].x*s,t=t[3].y*(1-s)+t[2].y*s,s=o*(1-n)+h*n,p=a*(1-n)+r*n,d=l*(1-n)+c*n,n=u*(1-n)+t*n,o=o*(1-e)+h*e,h=a*(1-e)+r*e,a=l*(1-e)+c*e,r=u*(1-e)+t*e,l=ve;return l.tx=s,l.ty=p,l.a=d-s,l.b=n-p,l.c=o-s,l.d=h-p,I.set(a,r),l.applyInverse(I,I),this.distortion.set(I.x-1,I.y-1),i.setFromMatrix(l),this}fillUniforms(e){e.distortion=e.distortion||new Float32Array([0,0,0,0]);var t=Math.abs(this.distortion.x),i=Math.abs(this.distortion.y);e.distortion[0]=1e4*t<=i?0:this.distortion.x,e.distortion[1]=1e4*i<=t?0:this.distortion.y,e.distortion[2]=1/e.distortion[0],e.distortion[3]=1/e.distorti