phaser3-rex-plugins
Version:
2 lines (1 loc) • 6.6 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexfisheyepipelineplugin=t();}(undefined,(function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,(r=i.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(r,"string"))?o:String(o)),i);}var r,o;}function i(e,t,i){return t&&n(e.prototype,t),i&&n(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&s(e,t);}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function u(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function f(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return !1}}();return function(){var n,i=o(e);if(t){var r=o(this).constructor;n=Reflect.construct(i,arguments,r);}else n=i.apply(this,arguments);return u(this,n)}}var a=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,c=Phaser.Utils.Objects.GetValue,l=function(e){r(o,e);var n=f(o);function o(e){var i;return t(this,o),(i=n.call(this,{name:"rexFishEyePostFx",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 float mode;\nuniform vec2 texSize;\nuniform vec2 center;\nuniform float radius;\nuniform float intensity;\n\nvoid main (void) {\n vec2 tc = outTexCoord * texSize; \n tc -= center;\n float dist = length(tc) / radius;\n if (dist < 1.0) {\n float factor;\n if (mode > 0.0) {\n factor = sin(dist * 1.570795);\n } else {\n factor = asin(dist) / 1.570795;\n }\n tc *= mix(1.0, factor, intensity);\n }\n\n tc += center;\n gl_FragColor = texture2D(uMainSampler, tc / texSize);\n\n}\n"})).fishEyeMode=0,i.centerX=0,i.centerY=0,i.radius=0,i.intensity=1,i}return i(o,[{key:"resetFromJSON",value:function(e){return this.setFishEyeMode(c(e,"mode",0)),this.setRadius(c(e,"radius",0)),this.setCenter(c(e,"center.x",void 0),c(e,"center.y",void 0)),this.setIntensity(c(e,"intensity",1)),this}},{key:"onPreRender",value:function(){this.set1f("mode",this.fishEyeMode),this.set1f("radius",this.radius);var e=this.renderer.width,t=this.renderer.height;this.set2f("center",this.centerX,t-this.centerY),this.set2f("texSize",e,t),this.set1f("intensity",this.intensity);}},{key:"setFishEyeMode",value:function(e){return "string"==typeof e&&(e=p[e]),this.fishEyeMode=e,this}},{key:"setRadius",value:function(e){return this.radius=e,this}},{key:"setCenter",value:function(e,t){return void 0===e&&(e=this.renderer.width/2,t=this.renderer.height/2),this.centerX=e,this.centerY=t,this}},{key:"setIntensity",value:function(e){return this.intensity=e,this}}]),o}(a),p={asin:0,sin:1},h=Phaser.Game,y=function(e){return e instanceof h},d=Phaser.Scene,v=function(e){return e instanceof d},m=function(t,n,i){var r;(r=t,null==r||"object"!==e(r)?null:y(r)?r:y(r.game)?r.game:v(r)?r.sys.game:v(r.scene)?r.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(n,i);},P=Phaser.Utils.Array.SpliceOne,b=function(e){r(o,Phaser.Plugins.BasePlugin);var n=f(o);function o(){return t(this,o),n.apply(this,arguments)}return i(o,[{key:"setPostPipelineClass",value:function(e,t){return this.PostFxPipelineClass=e,this.postFxPipelineName=t,this}},{key:"start",value:function(){this.game.events.once("destroy",this.destroy,this),m(this.game,this.postFxPipelineName,this.PostFxPipelineClass);}},{key:"add",value:function(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)}},{key:"remove",value:function(e,t){return function(e,t,n){if(void 0===n)for(var i=(r=e.postPipelines).length-1;i>=0;i--)(s=r[i])instanceof t&&(s.destroy(),P(r,i));else {i=0;for(var r,o=(r=e.postPipelines).length;i<o;i++){var s;(s=r[i])instanceof t&&s.name===n&&(s.destroy(),P(r,i));}}}(e,this.PostFxPipelineClass,t),this}},{key:"get",value:function(e,t){return function(e,t,n){if(void 0===n){for(var i=[],r=0,o=(s=e.postPipelines).length;r<o;r++)(u=s[r])instanceof t&&i.push(u);return i}var s;for(r=0,o=(s=e.postPipelines).length;r<o;r++){var u;if((u=s[r])instanceof t&&u.name===n)return u}}(e,this.PostFxPipelineClass,t)}}]),o}(),g=function(e){return null==e||""===e||0===e.length},x=function(e){r(o,e);var n=f(o);function o(e){var i;return t(this,o),(i=n.call(this,e)).setPostPipelineClass(l,"rexFishEyePostFx"),i}return i(o)}(b);return function(t,n,i,r){if(void 0===r&&(r="."),"object"===e(t)){if(g(n)){if(null==i)return;"object"===e(i)&&(t=i);}else {"string"==typeof n&&(n=n.split(r));var o=n.pop(),s=function(t,n,i){var r=t;if(g(n));else {var o;"string"==typeof n&&(n=n.split("."));for(var s=0,u=n.length;s<u;s++){var f;null!=r[o=n[s]]&&"object"===e(r[o])||(f=s===u-1?void 0===i?{}:i:{},r[o]=f),r=r[o];}}return r}(t,n);s[o]=i;}}}(window,"RexPlugins.Pipelines.FishEyePostFx",l),x}));