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