phaser3-rex-plugins
Version:
2 lines (1 loc) • 8.38 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexsplitpipelineplugin=e();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,(o=i.key,r=void 0,"symbol"==typeof(r=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(o,"string"))?r:String(r)),i);}var o,r;}function i(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&s(t,e);}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function a(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function l(t){var e=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(t){return !1}}();return function(){var n,i=r(t);if(e){var o=r(this).constructor;n=Reflect.construct(i,arguments,o);}else n=i.apply(this,arguments);return a(this,n)}}var c=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,f=Phaser.Utils.Objects.GetValue,u=Phaser.Math.DegToRad,p=Phaser.Math.RadToDeg,h=function(t){o(r,t);var n=l(r);function r(t){var i;return e(this,r),(i=n.call(this,{name:"rexSplitPostFx",game:t,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 split;\nuniform float spaceLeft;\nuniform float spaceRight;\nuniform float spaceTop;\nuniform float spaceBottom;\nuniform float angle;\nuniform float shiftEnable;\n\nvec2 rotate(vec2 uv, float angle) {\n float s = sin(angle);\n float c = cos(angle);\n return vec2(\n uv.x * c + uv.y * s,\n uv.y * c - uv.x * s\n );\n}\n\nvoid main (void) {\n vec2 tc = outTexCoord * texSize; \n tc -= split;\n tc = rotate(tc, -angle);\n\n if (\n ((tc.x > -spaceLeft) && (tc.x < spaceRight)) ||\n ((tc.y > -spaceTop) && (tc.y < spaceBottom))\n ) {\n gl_FragColor = vec4(0,0,0,0);\n } else {\n if (shiftEnable > 0.0) {\n tc.x += (tc.x < 0.0)? spaceLeft: -spaceRight;\n tc.y += (tc.y < 0.0)? spaceTop: -spaceBottom;\n }\n\n tc = rotate(tc, angle);\n tc += split;\n gl_FragColor = texture2D(uMainSampler, tc / texSize);\n }\n\n}\n"})).splitX=0,i.splitY=0,i.spaceLeft=0,i.spaceRight=0,i.spaceTop=0,i.spaceBottom=0,i.rotation=0,i.shiftEnable=!0,i}return i(r,[{key:"resetFromJSON",value:function(t){var e=f(t,"width",void 0);void 0===e?(this.spaceLeft=f(t,"left",0),this.spaceRight=f(t,"right",0)):this.splittedWidth=e;var n=f(t,"height",void 0);void 0===n?(this.spaceTop=f(t,"top",0),this.spaceBottom=f(t,"bottom",0)):this.splittedHeight=n,this.splitX=f(t,"x",this.renderer.width/2),this.splitY=f(t,"Y",this.renderer.height/2);var i=f(t,"rotation",void 0);return void 0===i?this.setAngle(f(t,"angle",0)):this.setRotation(i),this.shiftEnable=f(t,"shiftEnable",!0),this}},{key:"onPreRender",value:function(){var t=this.renderer.width,e=this.renderer.height;this.set2f("split",this.splitX,e-this.splitY),this.set1f("angle",this.rotation),this.set2f("texSize",t,e),this.set1f("spaceLeft",this.spaceLeft),this.set1f("spaceRight",this.spaceRight),this.set1f("spaceTop",this.spaceTop),this.set1f("spaceBottom",this.spaceBottom),this.set1f("shiftEnable",this.shiftEnable?1:0);}},{key:"setSplit",value:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=0),this.splitX=t,this.splitY=e,this}},{key:"splitAtCenter",value:function(t,e){return this.setSplit(this.renderer.width/2,this.renderer.height/2),void 0!==t&&this.setSplittedWidth(t),void 0!==e&&this.setSplittedHeight(e),this}},{key:"setRotation",value:function(t){return this.rotation=t,this}},{key:"angle",get:function(){return p(this.rotation)},set:function(t){this.rotation=u(t);}},{key:"setAngle",value:function(t){return this.angle=t,this}},{key:"setSpace",value:function(t,e,n,i){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.spaceLeft=t,this.spaceRight=e,this.spaceTop=n,this.spaceBottom=i,this}},{key:"splittedWidth",get:function(){return this.spaceLeft+this.spaceRight},set:function(t){this.spaceLeft=t/2,this.spaceRight=this.spaceLeft;}},{key:"setSplittedWidth",value:function(t){return void 0===t&&(t=0),this.splittedWidth=t,this}},{key:"splittedHeight",get:function(){return this.spaceTop+this.spaceBottom},set:function(t){this.spaceTop=t/2,this.spaceBottom=this.spaceTop;}},{key:"setSplittedHeight",value:function(t){return void 0===t&&(t=0),this.splittedHeight=t,this}},{key:"setShiftEnable",value:function(t){return void 0===t&&(t=!0),this.shiftEnable=t,!0}}]),r}(c),d=Phaser.Game,v=function(t){return t instanceof d},y=Phaser.Scene,g=function(t){return t instanceof y},m=function(e,n,i){var o;(o=e,null==o||"object"!==t(o)?null:v(o)?o:v(o.game)?o.game:g(o)?o.sys.game:g(o.scene)?o.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(n,i);},P=Phaser.Utils.Array.SpliceOne,b=function(t){o(r,Phaser.Plugins.BasePlugin);var n=l(r);function r(){return e(this,r),n.apply(this,arguments)}return i(r,[{key:"setPostPipelineClass",value:function(t,e){return this.PostFxPipelineClass=t,this.postFxPipelineName=e,this}},{key:"start",value:function(){this.game.events.once("destroy",this.destroy,this),m(this.game,this.postFxPipelineName,this.PostFxPipelineClass);}},{key:"add",value:function(t,e){return function(t,e,n){void 0===n&&(n={}),t.setPostPipeline(e);var i=t.postPipelines[t.postPipelines.length-1];return i.resetFromJSON(n),n.name&&(i.name=n.name),i}(t,this.PostFxPipelineClass,e)}},{key:"remove",value:function(t,e){return function(t,e,n){if(void 0===n)for(var i=(o=t.postPipelines).length-1;i>=0;i--)(s=o[i])instanceof e&&(s.destroy(),P(o,i));else {i=0;for(var o,r=(o=t.postPipelines).length;i<r;i++){var s;(s=o[i])instanceof e&&s.name===n&&(s.destroy(),P(o,i));}}}(t,this.PostFxPipelineClass,e),this}},{key:"get",value:function(t,e){return function(t,e,n){if(void 0===n){for(var i=[],o=0,r=(s=t.postPipelines).length;o<r;o++)(a=s[o])instanceof e&&i.push(a);return i}var s;for(o=0,r=(s=t.postPipelines).length;o<r;o++){var a;if((a=s[o])instanceof e&&a.name===n)return a}}(t,this.PostFxPipelineClass,e)}}]),r}(),S=function(t){return null==t||""===t||0===t.length},x=function(t){o(r,t);var n=l(r);function r(t){var i;return e(this,r),(i=n.call(this,t)).setPostPipelineClass(h,"rexSplitPostFx"),i}return i(r)}(b);return function(e,n,i,o){if(void 0===o&&(o="."),"object"===t(e)){if(S(n)){if(null==i)return;"object"===t(i)&&(e=i);}else {"string"==typeof n&&(n=n.split(o));var r=n.pop(),s=function(e,n,i){var o=e;if(S(n));else {var r;"string"==typeof n&&(n=n.split("."));for(var s=0,a=n.length;s<a;s++){var l;null!=o[r=n[s]]&&"object"===t(o[r])||(l=s===a-1?void 0===i?{}:i:{},o[r]=l),o=o[r];}}return o}(e,n);s[r]=i;}}}(window,"RexPlugins.Pipelines.SplitPostFx",h),x}));