1 |
- var __extends=this&&this.__extends||(function(){var 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])};return function(e,r){function o(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}})(),__decorate=this&&this.__decorate||function(t,e,r,o){var n,i=arguments.length,a=i<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,o);else for(var c=t.length-1;c>=0;c--)(n=t[c])&&(a=(i<3?n(a):i>3?n(e,r,a):n(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},BABYLON;!(function(t){var e=(function(e){function r(r,o,n,i){void 0===i&&(i=null);var a=e.call(this,i)||this;if(!(i=a.getScene()))return a;a.name=r,a._text,a._font,a.wrapU=t.Texture.CLAMP_ADDRESSMODE,a.wrapV=t.Texture.CLAMP_ADDRESSMODE;var c=a.getFontHeight(o),l=a.getFontWidth(o);a._charSize=Math.max(c.height,l);var f=Math.ceil(a._charSize*n.length),s=a._charSize;a._texture=i.getEngine().createDynamicTexture(f,s,!1,t.Texture.NEAREST_SAMPLINGMODE);var h=a.getSize(),u=document.createElement("canvas");u.width=h.width,u.height=h.height;var g=u.getContext("2d");g.textBaseline="top",g.font=o,g.fillStyle="white",g.imageSmoothingEnabled=!1;for(var x=0;x<n.length;x++)g.fillText(n[x],x*a._charSize,-c.offset);return i.getEngine().updateDynamicTexture(a._texture,u,!1,!0),a}return __extends(r,e),Object.defineProperty(r.prototype,"charSize",{get:function(){return this._charSize},enumerable:!0,configurable:!0}),r.prototype.getFontWidth=function(t){var e=document.createElement("canvas"),r=e.getContext("2d");return r.fillStyle="white",r.font=t,r.measureText("W").width},r.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 o=r.getImageData(0,0,e.width,e.height).data,n=-1,i=-1,a=0;a<e.height;a++)for(var c=0;c<e.width;c++){var l=4*(a*e.width+c);{if(0!==o[l]){-1===n&&(n=a);break}if(c===e.width-1&&-1!==n){i=a,a=e.height;break}}}return{height:i-n+1,offset:n-1}},r.prototype.clone=function(){return new r(this.name,this._font,this._text,this.getScene())},r.Parse=function(e,o){return t.SerializationHelper.Parse((function(){return new r(e.name,e.font,e.text,o)}),e,o,null)},__decorate([t.serialize("font")],r.prototype,"_font",void 0),__decorate([t.serialize("text")],r.prototype,"_text",void 0),r})(t.BaseTexture);t.AsciiArtFontTexture=e;var r=(function(r){function o(o,n,i){var a=r.call(this,o,"asciiart",["asciiArtFontInfos","asciiArtOptions"],["asciiArtFont"],{width:n.getEngine().getRenderWidth(),height:n.getEngine().getRenderHeight()},n,t.Texture.TRILINEAR_SAMPLINGMODE,n.getEngine(),!0)||this;a.mixToTile=0,a.mixToNormal=0;var c="40px Monospace",l=" `-.'_:,\"=^;<+!*?/cL\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@";i&&("string"==typeof i?c=i:(c=i.font||c,l=i.characterSet||l,a.mixToTile=i.mixToTile||a.mixToTile,a.mixToNormal=i.mixToNormal||a.mixToNormal)),a._asciiArtFontTexture=new e(o,c,l,n.getScene());var f=a._asciiArtFontTexture.getSize();return a.onApply=function(t){t.setTexture("asciiArtFont",a._asciiArtFontTexture),t.setFloat4("asciiArtFontInfos",a._asciiArtFontTexture.charSize,l.length,f.width,f.height),t.setFloat4("asciiArtOptions",a.width,a.height,a.mixToNormal,a.mixToTile)},a}return __extends(o,r),o})(t.PostProcess);t.AsciiArtPostProcess=r})(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.asciiartPixelShader="\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}";
|