UNPKG

@petkoneo/phaser3-rex-plugins

Version:
2 lines (1 loc) 4 kB
var e,t;e=void 0,t=function(){const e=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,t=Phaser.Utils.Objects.GetValue,n=Phaser.Math.DegToRad,i=Phaser.Math.RadToDeg;class s extends e{constructor(e){super({name:"rexSwirlPostFx",game:e,renderTarget:!0,fragShader:"#ifdef GL_FRAGMENT_PRECISION_HIGH\n#define highmedp highp\n#else\n#define highmedp mediump\n#endif\nprecision highmedp float;\n\n// Scene buffer\nuniform sampler2D uMainSampler; \nvarying vec2 outTexCoord;\n\n// Effect parameters\nuniform vec2 texSize;\nuniform vec2 center;\nuniform float radius;\nuniform float angle;\n\nvoid main (void) {\n vec2 tc = outTexCoord * texSize;\n tc -= center;\n float dist = length(tc);\n if (dist < radius) {\n float percent = (radius - dist) / radius;\n float theta = percent * percent * angle * 8.0;\n float s = sin(theta);\n float c = cos(theta);\n tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));\n }\n tc += center;\n gl_FragColor = texture2D(uMainSampler, tc / texSize);\n}\n"}),this.centerX=0,this.centerY=0,this.radius=0,this.rotation=0}resetFromJSON(e){this.radius=t(e,"radius",0);var n=t(e,"rotation",void 0);return void 0===n?this.setAngle(t(e,"angle",0)):this.setRotation(n),this.setCenter(t(e,"center.x",void 0),t(e,"center.y",void 0)),this}onPreRender(){this.set1f("radius",this.radius),this.set1f("angle",this.rotation);var e=this.renderer.width,t=this.renderer.height;this.set2f("center",this.centerX,t-this.centerY),this.set2f("texSize",e,t)}setRadius(e){return this.radius=e,this}setRotation(e){return this.rotation=e,this}get angle(){return i(this.rotation)}set angle(e){this.rotation=n(e)}setAngle(e){return this.angle=e,this}setCenter(e,t){return void 0===e&&(e=this.renderer.width/2,t=this.renderer.height/2),this.centerX=e,this.centerY=t,this}}const r=Phaser.Game;var o=function(e){return e instanceof r};const a=Phaser.Scene;var l=function(e){return e instanceof a},h=function(e,t,n){var i;(i=e,null==i||"object"!=typeof i?null:o(i)?i:o(i.game)?i.game:l(i)?i.sys.game:l(i.scene)?i.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(t,n)};const c=Phaser.Utils.Array.SpliceOne;class d extends Phaser.Plugins.BasePlugin{setPostPipelineClass(e,t){return this.PostFxPipelineClass=e,this.postFxPipelineName=t,this}start(){this.game.events.once("destroy",this.destroy,this),h(this.game,this.postFxPipelineName,this.PostFxPipelineClass)}add(e,t){return function(e,t,n){void 0===n&&(n={}),e.setPostPipeline(t);var i=e.postPipelines[e.postPipelines.length-1];return i.resetFromJSON(n),n.name&&(i.name=n.name),i}(e,this.PostFxPipelineClass,t)}remove(e,t){return function(e,t,n){if(void 0===n)for(var i=(s=e.postPipelines).length-1;i>=0;i--)(o=s[i])instanceof t&&(o.destroy(),c(s,i));else{i=0;for(var s,r=(s=e.postPipelines).length;i<r;i++){var o;(o=s[i])instanceof t&&o.name===n&&(o.destroy(),c(s,i))}}e.hasPostPipeline=e.postPipelines.length>0}(e,this.PostFxPipelineClass,t),this}get(e,t){return function(e,t,n){if(void 0===n){for(var i=[],s=0,r=(o=e.postPipelines).length;s<r;s++)(a=o[s])instanceof t&&i.push(a);return i}var o;for(s=0,r=(o=e.postPipelines).length;s<r;s++){var a;if((a=o[s])instanceof t&&a.name===n)return a}}(e,this.PostFxPipelineClass,t)}}var f=function(e){return null==e||""===e||0===e.length};return function(e,t,n,i){if(void 0===i&&(i="."),"object"==typeof e)if(f(t)){if(null==n)return;"object"==typeof n&&(e=n)}else{"string"==typeof t&&(t=t.split(i));var s=t.pop(),r=function(e,t,n){var i=e;if(f(t));else{var s;"string"==typeof t&&(t=t.split("."));for(var r=0,o=t.length;r<o;r++){var a;null!=i[s=t[r]]&&"object"==typeof i[s]||(a=r===o-1?void 0===n?{}:n:{},i[s]=a),i=i[s]}}return i}(e,t);r[s]=n}}(window,"RexPlugins.Pipelines.SwirlPostFx",s),class extends d{constructor(e){super(e),this.setPostPipelineClass(s,"rexSwirlPostFx")}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexswirlpipelineplugin=t();