phaser3-rex-plugins
Version:
2 lines (1 loc) • 7.61 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).rexoutlinepipelineplugin=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 r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(o=r.key,i=void 0,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(o,"string"))?i:String(i)),r);}var o,i;}function r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(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 i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function l(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 u(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,r=i(e);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o);}else n=r.apply(this,arguments);return l(this,n)}}function a(){return a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=i(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(arguments.length<3?e:n):o.value}},a.apply(this,arguments)}var f=function(e){void 0===e&&(e=.1);var t=Math.max(100*e,1),n=(2*Math.PI/t).toFixed(7);return "#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 float thickness;\nuniform vec3 outlineColor;\n\nconst float DOUBLE_PI = 3.14159265358979323846264 * 2.;\n\nvoid main() {\n vec4 front = texture2D(uMainSampler, outTexCoord);\n\n if (thickness > 0.0) {\n vec2 mag = vec2(thickness/texSize.x, thickness/texSize.y);\n vec4 curColor;\n float maxAlpha = front.a;\n vec2 offset;\n for (float angle = 0.; angle < DOUBLE_PI; angle += #{angleStep}) {\n offset = vec2(mag.x * cos(angle), mag.y * sin(angle)); \n curColor = texture2D(uMainSampler, outTexCoord + offset);\n maxAlpha = max(maxAlpha, curColor.a);\n }\n vec3 resultColor = front.rgb + (outlineColor.rgb * (1. - front.a)) * maxAlpha;\n gl_FragColor = vec4(resultColor, maxAlpha);\n } else {\n gl_FragColor = front;\n }\n}\n".replace(/\#\{angleStep\}/,n)},c=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,p=Phaser.Utils.Objects.GetValue,h=Phaser.Display.Color.IntegerToRGB,y=Phaser.Display.Color,v=.1,d=f(v),g=function(e){o(i,e);var n=u(i);function i(e){var r;return t(this,i),(r=n.call(this,{name:"rexOutlinePostFx",game:e,renderTarget:!0,fragShader:d})).thickness=0,r._outlineColor=new y,r}return r(i,[{key:"resetFromJSON",value:function(e){return this.setThickness(p(e,"thickness",3)),this.setOutlineColor(p(e,"outlineColor",16777215)),this}},{key:"onPreRender",value:function(){this.set1f("thickness",this.thickness),this.set3f("outlineColor",this._outlineColor.redGL,this._outlineColor.greenGL,this._outlineColor.blueGL),this.set2f("texSize",this.renderer.width,this.renderer.height);}},{key:"setThickness",value:function(e){return this.thickness=e,this}},{key:"outlineColor",get:function(){return this._outlineColor},set:function(e){"number"==typeof e&&(e=h(e)),this._outlineColor.setFromRGB(e);}},{key:"setOutlineColor",value:function(e){return this.outlineColor=e,this}}],[{key:"setQuality",value:function(e){v!==e&&(v=e,d=f(e));}},{key:"getQuality",value:function(){return v}}]),i}(c),m=Phaser.Game,P=function(e){return e instanceof m},b=Phaser.Scene,x=function(e){return e instanceof b},C=function(t,n,r){var o;(o=t,null==o||"object"!==e(o)?null:P(o)?o:P(o.game)?o.game:x(o)?o.sys.game:x(o.scene)?o.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(n,r);},O=Phaser.Utils.Array.SpliceOne,k=function(e){o(i,Phaser.Plugins.BasePlugin);var n=u(i);function i(){return t(this,i),n.apply(this,arguments)}return r(i,[{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),C(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 r=e.postPipelines[e.postPipelines.length-1];return r.resetFromJSON(n),n.name&&(r.name=n.name),r}(e,this.PostFxPipelineClass,t)}},{key:"remove",value:function(e,t){return function(e,t,n){if(void 0===n)for(var r=(o=e.postPipelines).length-1;r>=0;r--)(s=o[r])instanceof t&&(s.destroy(),O(o,r));else {r=0;for(var o,i=(o=e.postPipelines).length;r<i;r++){var s;(s=o[r])instanceof t&&s.name===n&&(s.destroy(),O(o,r));}}}(e,this.PostFxPipelineClass,t),this}},{key:"get",value:function(e,t){return function(e,t,n){if(void 0===n){for(var r=[],o=0,i=(s=e.postPipelines).length;o<i;o++)(l=s[o])instanceof t&&r.push(l);return r}var s;for(o=0,i=(s=e.postPipelines).length;o<i;o++){var l;if((l=s[o])instanceof t&&l.name===n)return l}}(e,this.PostFxPipelineClass,t)}}]),i}(),S=function(e){return null==e||""===e||0===e.length},j=Phaser.Utils.Objects.GetValue,_=function(e){o(s,e);var n=u(s);function s(e){var r;return t(this,s),(r=n.call(this,e)).setPostPipelineClass(g,"rexOutlinePostFx"),r}return r(s,[{key:"add",value:function(e,t){return this.setQuality(j(t,"quality",this.quality)),a(i(s.prototype),"add",this).call(this,e,t)}},{key:"setQuality",value:function(e){return g.setQuality(e),this}},{key:"quality",get:function(){return g.getQuality()},set:function(e){this.setQuality(e);}}]),s}(k);return function(t,n,r,o){if(void 0===o&&(o="."),"object"===e(t)){if(S(n)){if(null==r)return;"object"===e(r)&&(t=r);}else {"string"==typeof n&&(n=n.split(o));var i=n.pop(),s=function(t,n,r){var o=t;if(S(n));else {var i;"string"==typeof n&&(n=n.split("."));for(var s=0,l=n.length;s<l;s++){var u;null!=o[i=n[s]]&&"object"===e(o[i])||(u=s===l-1?void 0===r?{}:r:{},o[i]=u),o=o[i];}}return o}(t,n);s[i]=r;}}}(window,"RexPlugins.Pipelines.OutlinePostFx",g),_}));