UNPKG

macaw-threejs

Version:

Macaw Three.js is ready to use library to connect Three.js with your project.<br/> Under the hood is a fully optimized, clean Three.js set up to make it easy to implement effects for images (future text, etc.). With effects out of the box, you don't even

2 lines (1 loc) 2.7 kB
class t{constructor(t){const{baseUniforms:e,baseVertex:n,baseFragment:s,isImage:r}=t;this.vertexKeys=["utils","struct","uniforms","varying","const","functions","beforeGl_Position","afterGl_Position"],this.fragmentKeys=["utils","struct","uniforms","varying","const","functions","beforeGl_FragColor","afterGl_FragColor"],this.baseUniforms=e,this.baseVertex=n,this.baseFragment=s,this.isImage=r,this.uniforms={},this.vertexShader="",this.fragmentShader="",this.create()}create(t=new Map){this.uniforms=this.baseUniforms;const e={},n={};t.forEach((t=>{var s,r,i;const{imageVertexString:a,imageUniforms:o,imageFragmentString:h,composerFragmentString:m,composerUniforms:g,composerVertexString:f}=t,c=null!==(s=this.isImage?a:f)&&void 0!==s?s:{},u=null!==(r=this.isImage?h:m)&&void 0!==r?r:{},l=null!==(i=this.isImage?o:g)&&void 0!==i?i:{};this.vertexKeys.forEach((t=>{t in c&&(e[t]=[e[t],c[t]].join("\n"))})),this.fragmentKeys.forEach((t=>{t in u&&(n[t]=[n[t],u[t]].join("\n"))})),this.uniforms=Object.assign(Object.assign({},this.uniforms),l)}));const s=`\n\t\t\t// Utils\n\t\t\t${this.baseVertex.utils}\n ${e.utils}\n\t\t\t// Struct\n\t\t\t${this.baseVertex.struct}\n ${e.struct}\n\t\t\t// Uniform\n\t\t\t${this.baseVertex.uniforms}\n ${e.uniforms}\n\t\t\t// Varying\n\t\t\t${this.baseVertex.varying}\n ${e.varying}\n\t\t\t// Const\n\t\t\t${this.baseVertex.const}\n ${e.const}\n\t\t\t// Functions\n\t\t\t${this.baseVertex.functions}\n ${e.functions}\n\t\t\tvoid main() {\n\t\t\t\t${this.baseVertex.beforeGl_Position}\n\t\t\t\t${e.beforeGl_Position}\n\t\t\t\t${this.baseVertex.afterGl_Position}\n\t\t\t\t${e.afterGl_Position}\n\t\t\t}\n `,r=`\n\t\t\t// Utils\n\t\t\t${this.baseFragment.utils}\n ${n.utils}\n\t\t\t// Struct\n\t\t\t${this.baseFragment.struct}\n\t\t\t${n.struct}\n\t\t\t// Uniform\n\t\t\t${this.baseFragment.uniforms}\n\t\t\t${n.uniforms}\n\t\t\t// Varying\n\t\t\t${this.baseFragment.varying}\n\t\t\t${n.varying}\n\t\t\t// Const\n\t\t\t${this.baseFragment.const}\n\t\t\t${n.const}\n\t\t\t// Functions\n\t\t\t${this.baseFragment.functions}\n ${n.functions}\n\t\t\tvoid main() {\n\t\t\t\t${this.baseFragment.beforeGl_FragColor}\n\t\t\t\t${n.beforeGl_FragColor}\n\t\t\t\t${this.baseFragment.afterGl_FragColor}\n\t\t\t\t${n.afterGl_FragColor}\n\t\t\t}\n `;this.vertexShader=this._removeUndefined(s),this.fragmentShader=this._removeUndefined(r)}get PrettyShaders(){return{prettyVertex:this._prettifier(this.vertexShader),prettyFragment:this._prettifier(this.fragmentShader)}}_removeUndefined(t){return t.replace(/\bundefined\b/g,"")}_prettifier(t){return t.replace(/ +/g,"").replace(/\t/g,"").replace(/^\s*[\r\n]/gm,"")}}export{t as MacawShader};