1 |
- var BABYLON,__extends=this&&this.__extends||(function(){var s=function(t,e){return(s=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}s(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}})();!(function(m){var t=function(){};m.CustomShaderStructure=t;var n=function(){};m.ShaderSpecialParts=n;var e=(function(s){function _(t,e){var r=s.call(this,t,e)||this;return r.CustomParts=new n,r.customShaderNameResolve=r.Builder,r.FragmentShader=m.Effect.ShadersStore.defaultPixelShader,r.VertexShader=m.Effect.ShadersStore.defaultVertexShader,r}return __extends(_,s),_.prototype.AttachAfterBind=function(t,e){for(var r in this._newUniformInstances){"vec2"==(s=r.toString().split("-"))[0]?e.setVector2(s[1],this._newUniformInstances[r]):"vec3"==s[0]?e.setVector3(s[1],this._newUniformInstances[r]):"vec4"==s[0]?e.setVector4(s[1],this._newUniformInstances[r]):"mat4"==s[0]?e.setMatrix(s[1],this._newUniformInstances[r]):"float"==s[0]&&e.setFloat(s[1],this._newUniformInstances[r])}for(var r in this._newSamplerInstances){var s;"sampler2D"==(s=r.toString().split("-"))[0]&&this._newSamplerInstances[r].isReady&&this._newSamplerInstances[r].isReady()&&e.setTexture(s[1],this._newSamplerInstances[r])}},_.prototype.ReviewUniform=function(t,e){if("uniform"==t)for(var r in this._newUniforms)-1==this._customUniform[r].indexOf("sampler")&&e.push(this._newUniforms[r]);if("sampler"==t)for(var r in this._newUniforms)-1!=this._customUniform[r].indexOf("sampler")&&e.push(this._newUniforms[r]);return e},_.prototype.Builder=function(t,e,r,s,n){var i=this;if(this._isCreatedShader)return this._createdShaderName;this._isCreatedShader=!1;var o="custom_"+ ++_.ShaderIndexer;this.ReviewUniform("uniform",e),this.ReviewUniform("sampler",s);var a=this._afterBind.bind(this);return this._afterBind=function(t,e){if(e){i.AttachAfterBind(t,e);try{a(t,e)}catch(e){}}},m.Effect.ShadersStore[o+"VertexShader"]=this.VertexShader.replace("#define CUSTOM_VERTEX_BEGIN",this.CustomParts.Vertex_Begin?this.CustomParts.Vertex_Begin:"").replace("#define CUSTOM_VERTEX_DEFINITIONS",(this._customUniform?this._customUniform.join("\n"):"")+(this.CustomParts.Vertex_Definitions?this.CustomParts.Vertex_Definitions:"")).replace("#define CUSTOM_VERTEX_MAIN_BEGIN",this.CustomParts.Vertex_MainBegin?this.CustomParts.Vertex_MainBegin:"").replace("#define CUSTOM_VERTEX_UPDATE_POSITION",this.CustomParts.Vertex_Before_PositionUpdated?this.CustomParts.Vertex_Before_PositionUpdated:"").replace("#define CUSTOM_VERTEX_UPDATE_NORMAL",this.CustomParts.Vertex_Before_NormalUpdated?this.CustomParts.Vertex_Before_NormalUpdated:""),m.Effect.ShadersStore[o+"PixelShader"]=this.FragmentShader.replace("#define CUSTOM_FRAGMENT_BEGIN",this.CustomParts.Fragment_Begin?this.CustomParts.Fragment_Begin:"").replace("#define CUSTOM_FRAGMENT_MAIN_BEGIN",this.CustomParts.Fragment_MainBegin?this.CustomParts.Fragment_MainBegin:"").replace("#define CUSTOM_FRAGMENT_DEFINITIONS",(this._customUniform?this._customUniform.join("\n"):"")+(this.CustomParts.Fragment_Definitions?this.CustomParts.Fragment_Definitions:"")).replace("#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE",this.CustomParts.Fragment_Custom_Diffuse?this.CustomParts.Fragment_Custom_Diffuse:"").replace("#define CUSTOM_FRAGMENT_UPDATE_ALPHA",this.CustomParts.Fragment_Custom_Alpha?this.CustomParts.Fragment_Custom_Alpha:"").replace("#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR",this.CustomParts.Fragment_Before_FragColor?this.CustomParts.Fragment_Before_FragColor:""),this._isCreatedShader=!0,this._createdShaderName=o},_.prototype.AddUniform=function(t,e,r){return this._customUniform||(this._customUniform=new Array,this._newUniforms=new Array,this._newSamplerInstances=new Array,this._newUniformInstances=new Array),r&&(e.indexOf("sampler"),this._newUniformInstances[e+"-"+t]=r),this._customUniform.push("uniform "+e+" "+t+";"),this._newUniforms.push(t),this},_.prototype.Fragment_Begin=function(t){return this.CustomParts.Fragment_Begin=t,this},_.prototype.Fragment_Definitions=function(t){return this.CustomParts.Fragment_Definitions=t,this},_.prototype.Fragment_MainBegin=function(t){return this.CustomParts.Fragment_MainBegin=t,this},_.prototype.Fragment_Custom_Diffuse=function(t){return this.CustomParts.Fragment_Custom_Diffuse=t.replace("result","diffuseColor"),this},_.prototype.Fragment_Custom_Alpha=function(t){return this.CustomParts.Fragment_Custom_Alpha=t.replace("result","alpha"),this},_.prototype.Fragment_Before_FragColor=function(t){return this.CustomParts.Fragment_Before_FragColor=t.replace("result","color"),this},_.prototype.Vertex_Begin=function(t){return this.CustomParts.Vertex_Begin=t,this},_.prototype.Vertex_Definitions=function(t){return this.CustomParts.Vertex_Definitions=t,this},_.prototype.Vertex_MainBegin=function(t){return this.CustomParts.Vertex_MainBegin=t,this},_.prototype.Vertex_Before_PositionUpdated=function(t){return this.CustomParts.Vertex_Before_PositionUpdated=t.replace("result","positionUpdated"),this},_.prototype.Vertex_Before_NormalUpdated=function(t){return this.CustomParts.Vertex_Before_NormalUpdated=t.replace("result","normalUpdated"),this},_.ShaderIndexer=1,_})(m.StandardMaterial);m.CustomMaterial=e})(BABYLON||(BABYLON={}));
|