babylon.asciiArtpostProcess.min.js 6.8 KB

12
  1. !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-postProcessesLibrary",["babylonjs"],e):"object"==typeof exports?exports["babylonjs-postProcessesLibrary"]=e(require("babylonjs")):t.POSTPROCESSLIBRARY=e(t.BABYLON)}(window,function(t){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),function(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}(r(3))},function(t,e,r){"use strict";(function(t){Object.defineProperty(e,"__esModule",{value:!0});var n=r(0),o=void 0!==t?t:"undefined"!=typeof window?window:void 0;if(void 0!==o)for(var i in n)o.BABYLON[i]=n[i];!function(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}(r(0))}).call(this,r(2))},function(t,e){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),o=this&&this.__decorate||function(t,e,r,n){var o,i=arguments.length,a=i<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(i<3?o(a):i>3?o(e,r,a):o(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a};Object.defineProperty(e,"__esModule",{value:!0});var i=r(4);i.Effect.ShadersStore.asciiartPixelShader=r(5);var a=function(t){function e(e,r,n,o){void 0===o&&(o=null);var a=t.call(this,o)||this;if(!(o=a.getScene()))return a;a.name=e,a._text,a._font,a.wrapU=i.Texture.CLAMP_ADDRESSMODE,a.wrapV=i.Texture.CLAMP_ADDRESSMODE;var c=a.getFontHeight(r),l=a.getFontWidth(r);a._charSize=Math.max(c.height,l);var f=Math.ceil(a._charSize*n.length),s=a._charSize;a._texture=o.getEngine().createDynamicTexture(f,s,!1,i.Texture.NEAREST_SAMPLINGMODE);var u=a.getSize(),p=document.createElement("canvas");p.width=u.width,p.height=u.height;var h=p.getContext("2d");h.textBaseline="top",h.font=r,h.fillStyle="white",h.imageSmoothingEnabled=!1;for(var d=0;d<n.length;d++)h.fillText(n[d],d*a._charSize,-c.offset);return o.getEngine().updateDynamicTexture(a._texture,p,!1,!0),a}return n(e,t),Object.defineProperty(e.prototype,"charSize",{get:function(){return this._charSize},enumerable:!0,configurable:!0}),e.prototype.getFontWidth=function(t){var e=document.createElement("canvas").getContext("2d");return e.fillStyle="white",e.font=t,e.measureText("W").width},e.prototype.getFontHeight=function(t){var e=document.createElement("canvas"),r=e.getContext("2d");r.fillRect(0,0,e.width,e.height),r.textBaseline="top",r.fillStyle="white",r.font=t,r.fillText("jH|",0,0);for(var n=r.getImageData(0,0,e.width,e.height).data,o=-1,i=-1,a=0;a<e.height;a++)for(var c=0;c<e.width;c++){if(0!==n[4*(a*e.width+c)]){-1===o&&(o=a);break}if(c===e.width-1&&-1!==o){i=a,a=e.height;break}}return{height:i-o+1,offset:o-1}},e.prototype.clone=function(){return new e(this.name,this._font,this._text,this.getScene())},e.Parse=function(t,r){return i.SerializationHelper.Parse(function(){return new e(t.name,t.font,t.text,r)},t,r,null)},o([i.serialize("font")],e.prototype,"_font",void 0),o([i.serialize("text")],e.prototype,"_text",void 0),e}(i.BaseTexture);e.AsciiArtFontTexture=a;var c=function(t){function e(e,r,n){var o=t.call(this,e,"asciiart",["asciiArtFontInfos","asciiArtOptions"],["asciiArtFont"],{width:r.getEngine().getRenderWidth(),height:r.getEngine().getRenderHeight()},r,i.Texture.TRILINEAR_SAMPLINGMODE,r.getEngine(),!0)||this;o.mixToTile=0,o.mixToNormal=0;var c="40px Monospace",l=" `-.'_:,\"=^;<+!*?/cL\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@";n&&("string"==typeof n?c=n:(c=n.font||c,l=n.characterSet||l,o.mixToTile=n.mixToTile||o.mixToTile,o.mixToNormal=n.mixToNormal||o.mixToNormal)),o._asciiArtFontTexture=new a(e,c,l,r.getScene());var f=o._asciiArtFontTexture.getSize();return o.onApply=function(t){t.setTexture("asciiArtFont",o._asciiArtFontTexture),t.setFloat4("asciiArtFontInfos",o._asciiArtFontTexture.charSize,l.length,f.width,f.height),t.setFloat4("asciiArtOptions",o.width,o.height,o.mixToNormal,o.mixToTile)},o}return n(e,t),e}(i.PostProcess);e.AsciiArtPostProcess=c},function(e,r){e.exports=t},function(t,e){t.exports="\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D asciiArtFont;\n\nuniform vec4 asciiArtFontInfos;\nuniform vec4 asciiArtOptions;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\nvoid main(void) \n{\nfloat caracterSize=asciiArtFontInfos.x;\nfloat numChar=asciiArtFontInfos.y-1.0;\nfloat fontx=asciiArtFontInfos.z;\nfloat fonty=asciiArtFontInfos.w;\nfloat screenx=asciiArtOptions.x;\nfloat screeny=asciiArtOptions.y;\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nfloat offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;\nfloat offsety=0.0;\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(gl_FragCoord.y,caracterSize))/fonty;\nvec4 finalColor=texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));\nfinalColor.rgb*=tileColor.rgb;\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,asciiArtOptions.w);\nfinalColor=mix(finalColor,baseColor,asciiArtOptions.z);\ngl_FragColor=finalColor;\n}"}])});
  2. //# sourceMappingURL=babylon.asciiArtPostProcess.min.js.map