var BABYLON=BABYLON||{};(function(){BABYLON.Ray=function(origin,direction){this.origin=origin;this.direction=direction;};BABYLON.Ray.prototype.intersectsSphere=function(sphere){var x=sphere.center.x-this.origin.x;var y=sphere.center.y-this.origin.y;var z=sphere.center.z-this.origin.z;var pyth=(x*x)+(y*y)+(z*z);var rr=sphere.radius*sphere.radius;if(pyth<=rr){return true;}var dot=(x*this.direction.x)+(y*this.direction.y)+(z*this.direction.z);if(dot<0.0){return false;}var temp=pyth-(dot*dot);return temp<=rr;};BABYLON.Ray.prototype.intersectsTriangle=function(vertex0,vertex1,vertex2){var edge1=vertex1.subtract(vertex0);var edge2=vertex2.subtract(vertex0);var pvec=BABYLON.Vector3.Cross(this.direction,edge2);var det=BABYLON.Vector3.Dot(edge1,pvec);if(det===0){return{hit:false,distance:0,bu:0,bv:0};}var invdet=1/det;var tvec=this.origin.subtract(vertex0);var bu=BABYLON.Vector3.Dot(tvec,pvec)*invdet;if(bu<0||bu>1.0){return{hit:false,distance:0,bu:bu,bv:0};}var qvec=BABYLON.Vector3.Cross(tvec,edge1);bv=BABYLON.Vector3.Dot(this.direction,qvec)*invdet;if(bv<0||bu+bv>1.0){return{hit:false,distance:0,bu:bu,bv:bv};}distance=BABYLON.Vector3.Dot(edge2,qvec)*invdet;return{hit:true,distance:distance,bu:bu,bv:bv};};BABYLON.Ray.CreateNew=function(x,y,viewportWidth,viewportHeight,world,view,projection){var start=BABYLON.Vector3.Unproject(new BABYLON.Vector3(x,y,0),viewportWidth,viewportHeight,world,view,projection);var end=BABYLON.Vector3.Unproject(new BABYLON.Vector3(x,y,1),viewportWidth,viewportHeight,world,view,projection);var direction=end.subtract(start);direction.normalize();return new BABYLON.Ray(start,direction);};BABYLON.Color3=function(initialR,initialG,initialB){this.r=initialR;this.g=initialG;this.b=initialB;};BABYLON.Color3.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}";};BABYLON.Color3.prototype.multiply=function(otherColor){return new BABYLON.Color3(this.r*otherColor.r,this.g*otherColor.g,this.b*otherColor.b);};BABYLON.Color3.prototype.equals=function(otherColor){return this.r===otherColor.r&&this.g===otherColor.g&&this.b===otherColor.b;};BABYLON.Color3.prototype.scale=function(scale){return new BABYLON.Color3(this.r*scale,this.g*scale,this.b*scale);};BABYLON.Color3.prototype.clone=function(){return new BABYLON.Color3(this.r,this.g,this.b);};BABYLON.Color3.FromArray=function(array){return new BABYLON.Color3(array[0],array[1],array[2]);};BABYLON.Color4=function(initialR,initialG,initialB,initialA){this.r=initialR;this.g=initialG;this.b=initialB;this.a=initialA;};BABYLON.Color4.prototype.add=function(right){return new BABYLON.Color4(this.r+right.r,this.g+right.g,this.b+right.b,this.a+right.a);};BABYLON.Color4.prototype.subtract=function(right){return new BABYLON.Color4(this.r-right.r,this.g-right.g,this.b-right.b,this.a-right.a);};BABYLON.Color4.prototype.scale=function(scale){return new BABYLON.Color4(this.r*scale,this.g*scale,this.b*scale,this.a*scale);};BABYLON.Color4.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}";};BABYLON.Color4.prototype.clone=function(){return new BABYLON.Color4(this.r,this.g,this.b,this.a);};BABYLON.Color4.Lerp=function(left,right,amount){var r=left.r+(right.r-left.r)*amount;var g=left.g+(right.g-left.g)*amount;var b=left.b+(right.b-left.b)*amount;var a=left.a+(right.a-left.a)*amount;return new BABYLON.Color4(r,g,b,a);};BABYLON.Color4.FromArray=function(array,offset){if(!offset){offset=0;}return new BABYLON.Color4(array[offset],array[offset+1],array[offset+2],array[offset+3]);};BABYLON.Vector2=function(initialX,initialY){this.x=initialX;this.y=initialY;};BABYLON.Vector2.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+"}";};BABYLON.Vector2.prototype.add=function(otherVector){return new BABYLON.Vector2(this.x+otherVector.x,this.y+otherVector.y);};BABYLON.Vector2.prototype.subtract=function(otherVector){return new BABYLON.Vector2(this.x-otherVector.x,this.y-otherVector.y);};BABYLON.Vector2.prototype.negate=function(){return new BABYLON.Vector2(-this.x,-this.y);};BABYLON.Vector2.prototype.scale=function(scale){return new BABYLON.Vector2(this.x*scale,this.y*scale);};BABYLON.Vector2.prototype.equals=function(otherVector){return this.x===otherVector.x&&this.y===otherVector.y;};BABYLON.Vector2.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y);};BABYLON.Vector2.prototype.lengthSquared=function(){return(this.x*this.x+this.y*this.y);};BABYLON.Vector2.prototype.normalize=function(){var len=this.length();if(len===0)return;var num=1.0/len;this.x*=num;this.y*=num;};BABYLON.Vector2.prototype.clone=function(){return new BABYLON.Vector2(this.x,this.y);};BABYLON.Vector2.Zero=function(){return new BABYLON.Vector2(0,0);};BABYLON.Vector2.CatmullRom=function(value1,value2,value3,value4,amount){var squared=amount*amount;var cubed=amount*squared;var x=0.5*((((2.0*value2.x)+((-value1.x+value3.x)*amount))+(((((2.0*value1.x)-(5.0*value2.x))+(4.0*value3.x))-value4.x)*squared))+((((-value1.x+(3.0*value2.x))-(3.0*value3.x))+value4.x)*cubed));var y=0.5*((((2.0*value2.y)+((-value1.y+value3.y)*amount))+(((((2.0*value1.y)-(5.0*value2.y))+(4.0*value3.y))-value4.y)*squared))+((((-value1.y+(3.0*value2.y))-(3.0*value3.y))+value4.y)*cubed));return new BABYLON.Vector2(x,y);};BABYLON.Vector2.Clamp=function(value,min,max){var x=value.x;x=(x>max.x)?max.x:x;x=(xmax.y)?max.y:y;y=(yright.x)?left.x:right.x;var y=(left.y>right.y)?left.y:right.y;return new BABYLON.Vector2(x,y);};BABYLON.Vector2.Transform=function(vector,transformation){var x=(vector.x*transformation.m[0])+(vector.y*transformation.m[4]);var y=(vector.x*transformation.m[1])+(vector.y*transformation.m[5]);return new BABYLON.Vector2(x,y);};BABYLON.Vector2.Distance=function(value1,value2){return Math.sqrt(BABYLON.Vector2.DistanceSquared(value1,value2));};BABYLON.Vector2.DistanceSquared=function(value1,value2){var x=value1.x-value2.x;var y=value1.y-value2.y;return(x*x)+(y*y);};BABYLON.Vector3=function(initialX,initialY,initialZ){this.x=initialX;this.y=initialY;this.z=initialZ;};BABYLON.Vector3.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}";};BABYLON.Vector3.prototype.add=function(otherVector){return new BABYLON.Vector3(this.x+otherVector.x,this.y+otherVector.y,this.z+otherVector.z);};BABYLON.Vector3.prototype.subtract=function(otherVector){return new BABYLON.Vector3(this.x-otherVector.x,this.y-otherVector.y,this.z-otherVector.z);};BABYLON.Vector3.prototype.negate=function(){return new BABYLON.Vector3(-this.x,-this.y,-this.z);};BABYLON.Vector3.prototype.scale=function(scale){return new BABYLON.Vector3(this.x*scale,this.y*scale,this.z*scale);};BABYLON.Vector3.prototype.equals=function(otherVector){return this.x===otherVector.x&&this.y===otherVector.y&&this.z===otherVector.z;};BABYLON.Vector3.prototype.multiply=function(otherVector){return new BABYLON.Vector3(this.x*otherVector.x,this.y*otherVector.y,this.z*otherVector.z);};BABYLON.Vector3.prototype.divide=function(otherVector){return new BABYLON.Vector3(this.x/otherVector.x,this.y/otherVector.y,this.z/otherVector.z);};BABYLON.Vector3.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);};BABYLON.Vector3.prototype.lengthSquared=function(){return(this.x*this.x+this.y*this.y+this.z*this.z);};BABYLON.Vector3.prototype.normalize=function(){var len=this.length();if(len===0)return;var num=1.0/len;this.x*=num;this.y*=num;this.z*=num;};BABYLON.Vector3.prototype.clone=function(){return new BABYLON.Vector3(this.x,this.y,this.z);};BABYLON.Vector3.FromArray=function(array,offset){if(!offset){offset=0;}return new BABYLON.Vector3(array[offset],array[offset+1],array[offset+2]);};BABYLON.Vector3.Zero=function(){return new BABYLON.Vector3(0,0,0);};BABYLON.Vector3.Up=function(){return new BABYLON.Vector3(0,1.0,0);};BABYLON.Vector3.TransformCoordinates=function(vector,transformation){var x=(vector.x*transformation.m[0])+(vector.y*transformation.m[4])+(vector.z*transformation.m[8])+transformation.m[12];var y=(vector.x*transformation.m[1])+(vector.y*transformation.m[5])+(vector.z*transformation.m[9])+transformation.m[13];var z=(vector.x*transformation.m[2])+(vector.y*transformation.m[6])+(vector.z*transformation.m[10])+transformation.m[14];var w=(vector.x*transformation.m[3])+(vector.y*transformation.m[7])+(vector.z*transformation.m[11])+transformation.m[15];return new BABYLON.Vector3(x/w,y/w,z/w);};BABYLON.Vector3.TransformNormal=function(vector,transformation){var x=(vector.x*transformation.m[0])+(vector.y*transformation.m[4])+(vector.z*transformation.m[8]);var y=(vector.x*transformation.m[1])+(vector.y*transformation.m[5])+(vector.z*transformation.m[9]);var z=(vector.x*transformation.m[2])+(vector.y*transformation.m[6])+(vector.z*transformation.m[10]);return new BABYLON.Vector3(x,y,z);};BABYLON.Vector3.CatmullRom=function(value1,value2,value3,value4,amount){var squared=amount*amount;var cubed=amount*squared;var x=0.5*((((2.0*value2.x)+((-value1.x+value3.x)*amount))+(((((2.0*value1.x)-(5.0*value2.x))+(4.0*value3.x))-value4.x)*squared))+((((-value1.x+(3.0*value2.x))-(3.0*value3.x))+value4.x)*cubed));var y=0.5*((((2.0*value2.y)+((-value1.y+value3.y)*amount))+(((((2.0*value1.y)-(5.0*value2.y))+(4.0*value3.y))-value4.y)*squared))+((((-value1.y+(3.0*value2.y))-(3.0*value3.y))+value4.y)*cubed));var z=0.5*((((2.0*value2.z)+((-value1.z+value3.z)*amount))+(((((2.0*value1.z)-(5.0*value2.z))+(4.0*value3.z))-value4.z)*squared))+((((-value1.z+(3.0*value2.z))-(3.0*value3.z))+value4.z)*cubed));return new BABYLON.Vector3(x,y,z);};BABYLON.Vector3.Clamp=function(value,min,max){var x=value.x;x=(x>max.x)?max.x:x;x=(xmax.y)?max.y:y;y=(ymax.z)?max.z:z;z=(zright.x)?left.x:right.x;var y=(left.y>right.y)?left.y:right.y;var z=(left.z>right.z)?left.z:right.z;return new BABYLON.Vector3(x,y,z);};BABYLON.Vector3.Distance=function(value1,value2){return Math.sqrt(BABYLON.Vector3.DistanceSquared(value1,value2));};BABYLON.Vector3.DistanceSquared=function(value1,value2){var x=value1.x-value2.x;var y=value1.y-value2.y;var z=value1.z-value2.z;return(x*x)+(y*y)+(z*z);};BABYLON.Quaternion=function(initialX,initialY,initialZ,initialW){this.x=initialX;this.y=initialY;this.z=initialZ;this.w=initialW;};BABYLON.Quaternion.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}";};BABYLON.Quaternion.prototype.clone=function(){return new BABYLON.Quaternion(this.x,this.y,this.z,this.w);};BABYLON.Quaternion.prototype.add=function(other){return new BABYLON.Quaternion(this.x+other.x,this.y+other.y,this.z+other.z,this.w+other.w);};BABYLON.Quaternion.prototype.scale=function(value){return new BABYLON.Quaternion(this.x*value,this.y*value,this.z*value,this.w*value);};BABYLON.Quaternion.prototype.toEulerAngles=function(){var q0=this.x;var q1=this.y;var q2=this.y;var q3=this.w;var x=Math.atan2(2*(q0*q1+q2*q3),1-2*(q1*q1+q2*q2));var y=Math.asin(2*(q0*q2-q3*q1));var z=Math.atan2(2*(q0*q3+q1*q2),1-2*(q2*q2+q3*q3));return new BABYLON.Vector3(x,y,z);};BABYLON.Quaternion.FromArray=function(array,offset){if(!offset){offset=0;}return new BABYLON.Quaternion(array[offset],array[offset+1],array[offset+2],array[offset+3]);};BABYLON.Quaternion.Slerp=function(left,right,amount){var num2;var num3;var num=amount;var num4=(((left.x*right.x)+(left.y*right.y))+(left.z*right.z))+(left.w*right.w);var flag=false;if(num4<0){flag=true;num4=-num4;}if(num4>0.999999){num3=1-num;num2=flag?-num:num;}else{var num5=Math.acos(num4);var num6=(1.0/Math.sin(num5));num3=(Math.sin((1.0-num)*num5))*num6;num2=flag?((-Math.sin(num*num5))*num6):((Math.sin(num*num5))*num6);}return new BABYLON.Quaternion((num3*left.x)+(num2*right.x),(num3*left.y)+(num2*right.y),(num3*left.z)+(num2*right.z),(num3*left.w)+(num2*right.w));};BABYLON.Matrix=function(){this.m=new Array(16);};BABYLON.Matrix.prototype.isIdentity=function(){if(this.m[0]!=1.0||this.m[5]!=1.0||this.m[10]!=1.0||this.m[15]!=1.0)return false;if(this.m[1]!=0.0||this.m[2]!=0.0||this.m[3]!=0.0||this.m[4]!=0.0||this.m[6]!=0.0||this.m[7]!=0.0||this.m[8]!=0.0||this.m[9]!=0.0||this.m[11]!=0.0||this.m[12]!=0.0||this.m[13]!=0.0||this.m[14]!=0.0)return false;return true;};BABYLON.Matrix.prototype.determinant=function(){var temp1=(this.m[10]*this.m[15])-(this.m[11]*this.m[14]);var temp2=(this.m[9]*this.m[15])-(this.m[11]*this.m[13]);var temp3=(this.m[9]*this.m[14])-(this.m[10]*this.m[13]);var temp4=(this.m[8]*this.m[15])-(this.m[11]*this.m[12]);var temp5=(this.m[8]*this.m[14])-(this.m[10]*this.m[12]);var temp6=(this.m[8]*this.m[13])-(this.m[9]*this.m[12]);return((((this.m[0]*(((this.m[5]*temp1)-(this.m[6]*temp2))+(this.m[7]*temp3)))-(this.m[1]*(((this.m[4]*temp1)-(this.m[6]*temp4))+(this.m[7]*temp5))))+(this.m[2]*(((this.m[4]*temp2)-(this.m[5]*temp4))+(this.m[7]*temp6))))-(this.m[3]*(((this.m[4]*temp3)-(this.m[5]*temp5))+(this.m[6]*temp6))));};BABYLON.Matrix.prototype.toArray=function(){return this.m;};BABYLON.Matrix.prototype.invert=function(){var l1=this.m[0];var l2=this.m[1];var l3=this.m[2];var l4=this.m[3];var l5=this.m[4];var l6=this.m[5];var l7=this.m[6];var l8=this.m[7];var l9=this.m[8];var l10=this.m[9];var l11=this.m[10];var l12=this.m[11];var l13=this.m[12];var l14=this.m[13];var l15=this.m[14];var l16=this.m[15];var l17=(l11*l16)-(l12*l15);var l18=(l10*l16)-(l12*l14);var l19=(l10*l15)-(l11*l14);var l20=(l9*l16)-(l12*l13);var l21=(l9*l15)-(l11*l13);var l22=(l9*l14)-(l10*l13);var l23=((l6*l17)-(l7*l18))+(l8*l19);var l24=-(((l5*l17)-(l7*l20))+(l8*l21));var l25=((l5*l18)-(l6*l20))+(l8*l22);var l26=-(((l5*l19)-(l6*l21))+(l7*l22));var l27=1.0/((((l1*l23)+(l2*l24))+(l3*l25))+(l4*l26));var l28=(l7*l16)-(l8*l15);var l29=(l6*l16)-(l8*l14);var l30=(l6*l15)-(l7*l14);var l31=(l5*l16)-(l8*l13);var l32=(l5*l15)-(l7*l13);var l33=(l5*l14)-(l6*l13);var l34=(l7*l12)-(l8*l11);var l35=(l6*l12)-(l8*l10);var l36=(l6*l11)-(l7*l10);var l37=(l5*l12)-(l8*l9);var l38=(l5*l11)-(l7*l9);var l39=(l5*l10)-(l6*l9);this.m[0]=l23*l27;this.m[4]=l24*l27;this.m[8]=l25*l27;this.m[12]=l26*l27;this.m[1]=-(((l2*l17)-(l3*l18))+(l4*l19))*l27;this.m[5]=(((l1*l17)-(l3*l20))+(l4*l21))*l27;this.m[9]=-(((l1*l18)-(l2*l20))+(l4*l22))*l27;this.m[13]=(((l1*l19)-(l2*l21))+(l3*l22))*l27;this.m[2]=(((l2*l28)-(l3*l29))+(l4*l30))*l27;this.m[6]=-(((l1*l28)-(l3*l31))+(l4*l32))*l27;this.m[10]=(((l1*l29)-(l2*l31))+(l4*l33))*l27;this.m[14]=-(((l1*l30)-(l2*l32))+(l3*l33))*l27;this.m[3]=-(((l2*l34)-(l3*l35))+(l4*l36))*l27;this.m[7]=(((l1*l34)-(l3*l37))+(l4*l38))*l27;this.m[11]=-(((l1*l35)-(l2*l37))+(l4*l39))*l27;this.m[15]=(((l1*l36)-(l2*l38))+(l3*l39))*l27;};BABYLON.Matrix.prototype.multiply=function(other){var result=new BABYLON.Matrix();result.m[0]=this.m[0]*other.m[0]+this.m[1]*other.m[4]+this.m[2]*other.m[8]+this.m[3]*other.m[12];result.m[1]=this.m[0]*other.m[1]+this.m[1]*other.m[5]+this.m[2]*other.m[9]+this.m[3]*other.m[13];result.m[2]=this.m[0]*other.m[2]+this.m[1]*other.m[6]+this.m[2]*other.m[10]+this.m[3]*other.m[14];result.m[3]=this.m[0]*other.m[3]+this.m[1]*other.m[7]+this.m[2]*other.m[11]+this.m[3]*other.m[15];result.m[4]=this.m[4]*other.m[0]+this.m[5]*other.m[4]+this.m[6]*other.m[8]+this.m[7]*other.m[12];result.m[5]=this.m[4]*other.m[1]+this.m[5]*other.m[5]+this.m[6]*other.m[9]+this.m[7]*other.m[13];result.m[6]=this.m[4]*other.m[2]+this.m[5]*other.m[6]+this.m[6]*other.m[10]+this.m[7]*other.m[14];result.m[7]=this.m[4]*other.m[3]+this.m[5]*other.m[7]+this.m[6]*other.m[11]+this.m[7]*other.m[15];result.m[8]=this.m[8]*other.m[0]+this.m[9]*other.m[4]+this.m[10]*other.m[8]+this.m[11]*other.m[12];result.m[9]=this.m[8]*other.m[1]+this.m[9]*other.m[5]+this.m[10]*other.m[9]+this.m[11]*other.m[13];result.m[10]=this.m[8]*other.m[2]+this.m[9]*other.m[6]+this.m[10]*other.m[10]+this.m[11]*other.m[14];result.m[11]=this.m[8]*other.m[3]+this.m[9]*other.m[7]+this.m[10]*other.m[11]+this.m[11]*other.m[15];result.m[12]=this.m[12]*other.m[0]+this.m[13]*other.m[4]+this.m[14]*other.m[8]+this.m[15]*other.m[12];result.m[13]=this.m[12]*other.m[1]+this.m[13]*other.m[5]+this.m[14]*other.m[9]+this.m[15]*other.m[13];result.m[14]=this.m[12]*other.m[2]+this.m[13]*other.m[6]+this.m[14]*other.m[10]+this.m[15]*other.m[14];result.m[15]=this.m[12]*other.m[3]+this.m[13]*other.m[7]+this.m[14]*other.m[11]+this.m[15]*other.m[15];return result;};BABYLON.Matrix.prototype.equals=function(value){return(this.m[0]===value.m[0]&&this.m[1]===value.m[1]&&this.m[2]===value.m[2]&&this.m[3]===value.m[3]&&this.m[4]===value.m[4]&&this.m[5]===value.m[5]&&this.m[6]===value.m[6]&&this.m[7]===value.m[7]&&this.m[8]===value.m[8]&&this.m[9]===value.m[9]&&this.m[10]===value.m[10]&&this.m[11]===value.m[11]&&this.m[12]===value.m[12]&&this.m[13]===value.m[13]&&this.m[14]===value.m[14]&&this.m[15]===value.m[15]);};BABYLON.Matrix.prototype.clone=function(){return BABYLON.Matrix.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15]);};BABYLON.Matrix.FromValues=function(initialM11,initialM12,initialM13,initialM14,initialM21,initialM22,initialM23,initialM24,initialM31,initialM32,initialM33,initialM34,initialM41,initialM42,initialM43,initialM44){var result=new BABYLON.Matrix();result.m[0]=initialM11;result.m[1]=initialM12;result.m[2]=initialM13;result.m[3]=initialM14;result.m[4]=initialM21;result.m[5]=initialM22;result.m[6]=initialM23;result.m[7]=initialM24;result.m[8]=initialM31;result.m[9]=initialM32;result.m[10]=initialM33;result.m[11]=initialM34;result.m[12]=initialM41;result.m[13]=initialM42;result.m[14]=initialM43;result.m[15]=initialM44;return result;};BABYLON.Matrix.Identity=function(){return BABYLON.Matrix.FromValues(1.0,0,0,0,0,1.0,0,0,0,0,1.0,0,0,0,0,1.0);};BABYLON.Matrix.Zero=function(){return BABYLON.Matrix.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);};BABYLON.Matrix.RotationX=function(angle){var result=BABYLON.Matrix.Zero();var s=Math.sin(angle);var c=Math.cos(angle);result.m[0]=1.0;result.m[15]=1.0;result.m[5]=c;result.m[10]=c;result.m[9]=-s;result.m[6]=s;return result;};BABYLON.Matrix.RotationY=function(angle){var result=BABYLON.Matrix.Zero();var s=Math.sin(angle);var c=Math.cos(angle);result.m[5]=1.0;result.m[15]=1.0;result.m[0]=c;result.m[2]=-s;result.m[8]=s;result.m[10]=c;return result;};BABYLON.Matrix.RotationZ=function(angle){var result=BABYLON.Matrix.Zero();var s=Math.sin(angle);var c=Math.cos(angle);result.m[10]=1.0;result.m[15]=1.0;result.m[0]=c;result.m[1]=s;result.m[4]=-s;result.m[5]=c;return result;};BABYLON.Matrix.RotationAxis=function(axis,angle){var s=Math.sin(-angle);var c=Math.cos(-angle);var c1=1-c;axis.normalize();var result=BABYLON.Matrix.Zero();result.m[0]=(axis.x*axis.x)*c1+c;result.m[1]=(axis.x*axis.y)*c1-(axis.z*s);result.m[2]=(axis.x*axis.z)*c1+(axis.y*s);result.m[3]=0.0;result.m[4]=(axis.y*axis.x)*c1+(axis.z*s);result.m[5]=(axis.y*axis.y)*c1+c;result.m[6]=(axis.y*axis.z)*c1-(axis.x*s);result.m[7]=0.0;result.m[8]=(axis.z*axis.x)*c1-(axis.y*s);result.m[9]=(axis.z*axis.y)*c1+(axis.x*s);result.m[10]=(axis.z*axis.z)*c1+c;result.m[11]=0.0;result.m[15]=1.0;return result;};BABYLON.Matrix.RotationYawPitchRoll=function(yaw,pitch,roll){return BABYLON.Matrix.RotationZ(roll).multiply(BABYLON.Matrix.RotationX(pitch)).multiply(BABYLON.Matrix.RotationY(yaw));};BABYLON.Matrix.Scaling=function(x,y,z){var result=BABYLON.Matrix.Zero();result.m[0]=x;result.m[5]=y;result.m[10]=z;result.m[15]=1.0;return result;};BABYLON.Matrix.Translation=function(x,y,z){var result=BABYLON.Matrix.Identity();result.m[12]=x;result.m[13]=y;result.m[14]=z;return result;};BABYLON.Matrix.LookAtLH=function(eye,target,up){var zAxis=target.subtract(eye);zAxis.normalize();var xAxis=BABYLON.Vector3.Cross(up,zAxis);xAxis.normalize();var yAxis=BABYLON.Vector3.Cross(zAxis,xAxis);yAxis.normalize();var ex=-BABYLON.Vector3.Dot(xAxis,eye);var ey=-BABYLON.Vector3.Dot(yAxis,eye);var ez=-BABYLON.Vector3.Dot(zAxis,eye);return BABYLON.Matrix.FromValues(xAxis.x,yAxis.x,zAxis.x,0,xAxis.y,yAxis.y,zAxis.y,0,xAxis.z,yAxis.z,zAxis.z,0,ex,ey,ez,1);};BABYLON.Matrix.OrthoLH=function(width,height,znear,zfar){var hw=2.0/width;var hh=2.0/height;var id=1.0/(zfar-znear);var nid=znear/(znear-zfar);return BABYLON.Matrix.FromValues(hw,0,0,0,0,hh,0,0,0,0,id,0,0,0,nid,1);};BABYLON.Matrix.OrthoOffCenterLH=function(left,right,bottom,top,znear,zfar){var matrix=BABYLON.Matrix.Zero();matrix.m[0]=2.0/(right-left);matrix.m[1]=matrix.m[2]=matrix.m[3]=0;matrix.m[5]=2.0/(top-bottom);matrix.m[4]=matrix.m[6]=matrix.m[7]=0;matrix.m[10]=-1.0/(znear-zfar);matrix.m[8]=matrix.m[9]=matrix.m[11]=0;matrix.m[12]=(left+right)/(left-right);matrix.m[13]=(top+bottom)/(bottom-top);matrix.m[14]=znear/(znear-zfar);matrix.m[15]=1.0;return matrix;};BABYLON.Matrix.PerspectiveLH=function(width,height,znear,zfar){var matrix=BABYLON.Matrix.Zero();matrix.m[0]=(2.0*znear)/width;matrix.m[1]=matrix.m[2]=matrix.m[3]=0.0;matrix.m[5]=(2.0*znear)/height;matrix.m[4]=matrix.m[6]=matrix.m[7]=0.0;matrix.m[10]=-zfar/(znear-zfar);matrix.m[8]=matrix.m[9]=0.0;matrix.m[11]=1.0;matrix.m[12]=matrix.m[13]=matrix.m[15]=0.0;matrix.m[14]=(znear*zfar)/(znear-zfar);return matrix;};BABYLON.Matrix.PerspectiveFovLH=function(fov,aspect,znear,zfar){var matrix=BABYLON.Matrix.Zero();var tan=1.0/(Math.tan(fov*0.5));matrix.m[0]=tan/aspect;matrix.m[1]=matrix.m[2]=matrix.m[3]=0.0;matrix.m[5]=tan;matrix.m[4]=matrix.m[6]=matrix.m[7]=0.0;matrix.m[8]=matrix.m[9]=0.0;matrix.m[10]=-zfar/(znear-zfar);matrix.m[11]=1.0;matrix.m[12]=matrix.m[13]=matrix.m[15]=0.0;matrix.m[14]=(znear*zfar)/(znear-zfar);return matrix;};BABYLON.Matrix.AffineTransformation=function(scaling,rotationCenter,rotation,translation){return BABYLON.Matrix.Scaling(scaling,scaling,scaling)*BABYLON.Matrix.Translation(-rotationCenter)*BABYLON.Matrix.RotationQuaternion(rotation)*BABYLON.Matrix.Translation(rotationCenter)*BABYLON.Matrix.Translation(translation);};BABYLON.Matrix.GetFinalMatrix=function(viewport,world,view,projection){var cw=viewport.width;var ch=viewport.height;var cx=viewport.x;var cy=viewport.y;var zmin=viewport.minZ;var zmax=viewport.maxZ;var viewportMatrix=new BABYLON.Matrix(cw/2.0,0,0,0,0,-ch/2.0,0,0,0,0,zmax-zmin,0,cx+cw/2.0,ch/2.0+cy,zmin,1);return world.multiply(view).multiply(projection).multiply(viewportMatrix);};BABYLON.Matrix.Transpose=function(matrix){var result=new BABYLON.Matrix();result.m[0]=matrix.m[0];result.m[1]=matrix.m[4];result.m[2]=matrix.m[8];result.m[3]=matrix.m[12];result.m[4]=matrix.m[1];result.m[5]=matrix.m[5];result.m[6]=matrix.m[9];result.m[7]=matrix.m[13];result.m[8]=matrix.m[2];result.m[9]=matrix.m[6];result.m[10]=matrix.m[10];result.m[11]=matrix.m[14];result.m[12]=matrix.m[3];result.m[13]=matrix.m[7];result.m[14]=matrix.m[11];result.m[15]=matrix.m[15];return result;};BABYLON.Matrix.Reflection=function(plane){var matrix=new BABYLON.Matrix();plane.normalize();var x=plane.normal.x;var y=plane.normal.y;var z=plane.normal.z;var temp=-2*x;var temp2=-2*y;var temp3=-2*z;matrix.m[0]=(temp*x)+1;matrix.m[1]=temp2*x;matrix.m[2]=temp3*x;matrix.m[3]=0.0;matrix.m[4]=temp*y;matrix.m[5]=(temp2*y)+1;matrix.m[6]=temp3*y;matrix.m[7]=0.0;matrix.m[8]=temp*z;matrix.m[9]=temp2*z;matrix.m[10]=(temp3*z)+1;matrix.m[11]=0.0;matrix.m[12]=temp*plane.d;matrix.m[13]=temp2*plane.d;matrix.m[14]=temp3*plane.d;matrix.m[15]=1.0;return matrix;};BABYLON.Plane=function(a,b,c,d){this.normal=new BABYLON.Vector3(a,b,c);this.d=d;};BABYLON.Plane.prototype.normalize=function(){var norm=(Math.sqrt((this.normal.x*this.normal.x)+(this.normal.y*this.normal.y)+(this.normal.z*this.normal.z)));var magnitude=0;if(norm!=0){magnitude=1.0/norm;}this.normal.x*=magnitude;this.normal.y*=magnitude;this.normal.z*=magnitude;this.d*=magnitude;};BABYLON.Plane.prototype.transform=function(transformation){var transposedMatrix=BABYLON.Matrix.Transpose(transformation);var x=this.normal.x;var y=this.normal.y;var z=this.normal.z;var d=this.d;var normalX=(((x*transposedMatrix.m[0])+(y*transposedMatrix.m[1]))+(z*transposedMatrix.m[2]))+(d*transposedMatrix.m[3]);var normalY=(((x*transposedMatrix.m[4])+(y*transposedMatrix.m[5]))+(z*transposedMatrix.m[6]))+(d*transposedMatrix.m[7]);var normalZ=(((x*transposedMatrix.m[8])+(y*transposedMatrix.m[9]))+(z*transposedMatrix.m[10]))+(d*transposedMatrix.m[11]);var finalD=(((x*transposedMatrix.m[12])+(y*transposedMatrix.m[13]))+(z*transposedMatrix.m[14]))+(d*transposedMatrix.m[15]);return new BABYLON.Plane(normalX,normalY,normalZ,finalD);};BABYLON.Plane.prototype.dotCoordinate=function(point){return((((this.normal.x*point.x)+(this.normal.y*point.y))+(this.normal.z*point.z))+this.d);};BABYLON.Plane.FromArray=function(array){return new BABYLON.Plane(array[0],array[1],array[2],array[3]);};BABYLON.Plane.FromPoints=function(point1,point2,point3){var x1=point2.x-point1.x;var y1=point2.y-point1.y;var z1=point2.z-point1.z;var x2=point3.x-point1.x;var y2=point3.y-point1.y;var z2=point3.z-point1.z;var yz=(y1*z2)-(z1*y2);var xz=(z1*x2)-(x1*z2);var xy=(x1*y2)-(y1*x2);var pyth=(Math.sqrt((yz*yz)+(xz*xz)+(xy*xy)));var invPyth;if(pyth!=0)invPyth=1.0/pyth;elseinvPyth=0;var normal=new BABYLON.Vector3(yz*invPyth,xz*invPyth,xy*invPyth);var d=-((normal.x*point1.x)+(normal.y*point1.y)+(normal.z*point1.z));return new BABYLON.Plane(normal.x,normal.y,normal.z,d);};BABYLON.Frustum={};BABYLON.Frustum.GetPlanes=function(transform){var frustumPlanes=[];frustumPlanes.push(new BABYLON.Plane(transform.m[3]+transform.m[2],transform.m[7]+transform.m[6],transform.m[10]+transform.m[10],transform.m[15]+transform.m[14]));frustumPlanes[0].normalize();frustumPlanes.push(new BABYLON.Plane(transform.m[3]-transform.m[2],transform.m[7]-transform.m[6],transform.m[11]-transform.m[10],transform.m[15]-transform.m[14]));frustumPlanes[1].normalize();frustumPlanes.push(new BABYLON.Plane(transform.m[3]+transform.m[0],transform.m[7]+transform.m[4],transform.m[11]+transform.m[8],transform.m[15]+transform.m[12]));frustumPlanes[2].normalize();frustumPlanes.push(new BABYLON.Plane(transform.m[3]-transform.m[0],transform.m[7]-transform.m[4],transform.m[11]-transform.m[8],transform.m[15]-transform.m[12]));frustumPlanes[3].normalize();frustumPlanes.push(new BABYLON.Plane(transform.m[3]-transform.m[1],transform.m[7]-transform.m[5],transform.m[11]-transform.m[9],transform.m[15]-transform.m[13]));frustumPlanes[4].normalize();frustumPlanes.push(new BABYLON.Plane(transform.m[3]+transform.m[1],transform.m[7]+transform.m[5],transform.m[11]+transform.m[9],transform.m[15]+transform.m[13]));frustumPlanes[5].normalize();return frustumPlanes;};})();var BABYLON=BABYLON||{};(function(){BABYLON.Tools={};BABYLON.Tools.QueueNewFrame=function(func){if(window.requestAnimationFrame)window.requestAnimationFrame(func);else if(window.msRequestAnimationFrame)window.msRequestAnimationFrame(func);else if(window.webkitRequestAnimationFrame)window.webkitRequestAnimationFrame(func);else if(window.mozRequestAnimationFrame)window.mozRequestAnimationFrame(func);else if(window.oRequestAnimationFrame)window.oRequestAnimationFrame(func);else{window.setTimeout(func,16);}};BABYLON.Tools.RequestFullscreen=function(element){if(element.requestFullscreen)element.requestFullscreen();else if(element.msRequestFullscreen)element.msRequestFullscreen();else if(element.webkitRequestFullscreen)element.webkitRequestFullscreen();else if(element.mozRequestFullscreen)element.mozRequestFullscreen();};BABYLON.Tools.ExitFullscreen=function(){if(document.exitFullscreen){document.exitFullscreen();}else if(document.mozCancelFullScreen){document.mozCancelFullScreen();}else if(document.webkitCancelFullScreen){document.webkitCancelFullScreen();}else if(document.msCancelFullScreen){document.msCancelFullScreen();}};BABYLON.Tools.BaseUrl="";BABYLON.Tools.LoadFile=function(url,callback,progressCallBack){var request=new XMLHttpRequest();var loadUrl=BABYLON.Tools.BaseUrl+url;request.open('GET',loadUrl,true);request.onprogress=progressCallBack;request.onreadystatechange=function(){if(request.readyState==4){if(request.status==200){callback(request.responseText);}else{throw new Error(request.status,"Unable to load "+loadUrl);}}};request.send(null);};BABYLON.Tools.WithinEpsilon=function(a,b){var num=a-b;return-1.401298E-45<=num&&num<=1.401298E-45;};var cloneValue=function(source,destinationObject){if(!source)return null;if(source instanceof BABYLON.Mesh){return null;}if(source instanceof BABYLON.SubMesh){return source.clone(destinationObject);}else if(source.clone){return source.clone();}return null;};BABYLON.Tools.DeepCopy=function(source,destination,doNotCopyList,mustCopyList){for(var prop in source){if(prop[0]==="_"&&(!mustCopyList||mustCopyList.indexOf(prop)===-1)){continue;}if(doNotCopyList&&doNotCopyList.indexOf(prop)!==-1){continue;}var sourceValue=source[prop];var typeOfSourceValue=typeof sourceValue;if(typeOfSourceValue=="function"){continue;}if(typeOfSourceValue=="object"){if(sourceValue instanceof Array){destination[prop]=[];if(sourceValue.length>0){if(typeof sourceValue[0]=="object"){for(var index=0;index=2){deltaTime=previousFramesDuration[length-1]-previousFramesDuration[length-2];}if(length>=fpsRange){if(length>fpsRange){previousFramesDuration.splice(0,1);length=previousFramesDuration.length;}var sum=0;for(var id=0;id=0){this._gl.vertexAttribPointer(order,vertexDeclaration[index],this._gl.FLOAT,false,vertexStrideSize,offset);offset+=vertexDeclaration[index]*4;}}}if(this._buffersCache.indexBuffer!=indexBuffer){this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,indexBuffer);this._buffersCache.indexBuffer=indexBuffer;}};BABYLON.Engine.prototype._releaseBuffer=function(buffer){buffer.references--;if(buffer.references===0){this._gl.deleteBuffer(buffer);}};BABYLON.Engine.prototype.draw=function(useTriangles,indexStart,indexCount){this._gl.drawElements(useTriangles?this._gl.TRIANGLES:this._gl.LINES,indexCount,this._gl.UNSIGNED_SHORT,indexStart*2);};BABYLON.Engine.prototype.createEffect=function(baseName,attributesNames,uniformsNames,samplers,defines){var name=baseName+"@"+defines;if(this._compiledEffects[name]){return this._compiledEffects[name];}var effect=new BABYLON.Effect(baseName,attributesNames,uniformsNames,samplers,this,defines);this._compiledEffects[name]=effect;return effect;};var compileShader=function(gl,source,type,defines){var shader=gl.createShader(type==="vertex"?gl.VERTEX_SHADER:gl.FRAGMENT_SHADER);gl.shaderSource(shader,(defines?defines+"\n":"")+source);gl.compileShader(shader);if(!gl.getShaderParameter(shader,gl.COMPILE_STATUS)){throw new Error(gl.getShaderInfoLog(shader));}return shader;};BABYLON.Engine.prototype.createShaderProgram=function(vertexCode,fragmentCode,defines){var vertexShader=compileShader(this._gl,vertexCode,"vertex",defines);var fragmentShader=compileShader(this._gl,fragmentCode,"fragment",defines);var shaderProgram=this._gl.createProgram();this._gl.attachShader(shaderProgram,vertexShader);this._gl.attachShader(shaderProgram,fragmentShader);this._gl.linkProgram(shaderProgram);this._gl.deleteShader(vertexShader);this._gl.deleteShader(fragmentShader);return shaderProgram;};BABYLON.Engine.prototype.getUniforms=function(shaderProgram,uniformsNames){var results=[];for(var index=0;index=0){this._gl.enableVertexAttribArray(effect.getAttribute(index));}}this._currentEffect=effect;};BABYLON.Engine.prototype.setMatrix=function(uniform,matrix){if(!uniform)return;this._gl.uniformMatrix4fv(uniform,false,matrix.toArray());};BABYLON.Engine.prototype.setVector2=function(uniform,x,y){if(!uniform)return;this._gl.uniform2f(uniform,x,y);};BABYLON.Engine.prototype.setVector3=function(uniform,vector3){if(!uniform)return;this._gl.uniform3f(uniform,vector3.x,vector3.y,vector3.z);};BABYLON.Engine.prototype.setBool=function(uniform,bool){if(!uniform)return;this._gl.uniform1i(uniform,bool);};BABYLON.Engine.prototype.setVector4=function(uniform,x,y,z,w){if(!uniform)return;this._gl.uniform4f(uniform,x,y,z,w);};BABYLON.Engine.prototype.setColor3=function(uniform,color3){if(!uniform)return;this._gl.uniform3f(uniform,color3.r,color3.g,color3.b);};BABYLON.Engine.prototype.setColor4=function(uniform,color3,alpha){if(!uniform)return;this._gl.uniform4f(uniform,color3.r,color3.g,color3.b,alpha);};BABYLON.Engine.prototype.setState=function(culling){if(this._currentState.culling!==culling){if(culling){this._gl.cullFace(this.cullBackFaces?this._gl.BACK:this._gl.FRONT);this._gl.enable(this._gl.CULL_FACE);}else{this._gl.disable(this._gl.CULL_FACE);}this._currentState.culling=culling;}};BABYLON.Engine.prototype.setDepthBuffer=function(enable){if(enable){this._gl.enable(this._gl.DEPTH_TEST);}else{this._gl.disable(this._gl.DEPTH_TEST);}};BABYLON.Engine.prototype.setDepthWrite=function(enable){this._gl.depthMask(enable);};BABYLON.Engine.prototype.setColorWrite=function(enable){this._gl.colorMask(enable,enable,enable,enable);};BABYLON.Engine.prototype.setAlphaMode=function(mode){switch(mode){case BABYLON.Engine.ALPHA_DISABLE:this.setDepthWrite(true);this._gl.disable(this._gl.BLEND);break;case BABYLON.Engine.ALPHA_COMBINE:this.setDepthWrite(false);this._gl.blendFuncSeparate(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ZERO,this._gl.ONE);this._gl.enable(this._gl.BLEND);break;case BABYLON.Engine.ALPHA_ADD:this.setDepthWrite(false);this._gl.blendFuncSeparate(this._gl.ONE,this._gl.ONE,this._gl.ZERO,this._gl.ONE);this._gl.enable(this._gl.BLEND);break;}};BABYLON.Engine.prototype.setAlphaTesting=function(enable){this._alphaTest=enable;};BABYLON.Engine.prototype.getAlphaTesting=function(){return this._alphaTest;};BABYLON.Engine.prototype.wipeCaches=function(){this._activeTexturesCache=[];this._currentEffect=null;this._currentState={culling:null};this._buffersCache={vertexBuffer:null,indexBuffer:null};};var getExponantOfTwo=function(value,max){var count=1;do{count*=2;}while(countmax)count=max;return count;};BABYLON.Engine.prototype.createTexture=function(url,noMipmap,invertY,scene){var texture=this._gl.createTexture();var that=this;var img=new Image();img.onload=function(){that._workingCanvas.width=getExponantOfTwo(img.width,that._caps.maxTextureSize);that._workingCanvas.height=getExponantOfTwo(img.height,that._caps.maxTextureSize);that._workingContext.drawImage(img,0,0,img.width,img.height,0,0,that._workingCanvas.width,that._workingCanvas.height);that._gl.bindTexture(that._gl.TEXTURE_2D,texture);that._gl.pixelStorei(that._gl.UNPACK_FLIP_Y_WEBGL,invertY===undefined?true:invertY);that._gl.texImage2D(that._gl.TEXTURE_2D,0,that._gl.RGBA,that._gl.RGBA,that._gl.UNSIGNED_BYTE,that._workingCanvas);that._gl.texParameteri(that._gl.TEXTURE_2D,that._gl.TEXTURE_MAG_FILTER,that._gl.LINEAR);if(noMipmap){that._gl.texParameteri(that._gl.TEXTURE_2D,that._gl.TEXTURE_MIN_FILTER,that._gl.LINEAR);}else{that._gl.texParameteri(that._gl.TEXTURE_2D,that._gl.TEXTURE_MIN_FILTER,that._gl.LINEAR_MIPMAP_LINEAR);that._gl.generateMipmap(that._gl.TEXTURE_2D);}that._gl.bindTexture(that._gl.TEXTURE_2D,null);that._activeTexturesCache=[];texture._baseWidth=img.width;texture._baseHeight=img.height;texture._width=that._workingCanvas.width;texture._height=that._workingCanvas.height;texture.isReady=true;scene._removePendingData(img);};img.onerror=function(){scene._removePendingData(img);};scene._addPendingData(img);img.src=url;texture.url=url;texture.noMipmap=noMipmap;texture.references=1;this._loadedTexturesCache.push(texture);return texture;};BABYLON.Engine.prototype.createDynamicTexture=function(size,noMipmap){var texture=this._gl.createTexture();var width=getExponantOfTwo(size,this._caps.maxTextureSize);var height=getExponantOfTwo(size,this._caps.maxTextureSize);this._gl.bindTexture(this._gl.TEXTURE_2D,texture);this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,this._gl.LINEAR);if(noMipmap){this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,this._gl.LINEAR);}else{this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,this._gl.LINEAR_MIPMAP_LINEAR);}this._gl.bindTexture(this._gl.TEXTURE_2D,null);this._activeTexturesCache=[];texture._baseWidth=width;texture._baseHeight=height;texture._width=width;texture._height=height;texture.isReady=false;texture.noMipmap=noMipmap;texture.references=1;this._loadedTexturesCache.push(texture);return texture;};BABYLON.Engine.prototype.updateDynamicTexture=function(texture,canvas){this._gl.bindTexture(this._gl.TEXTURE_2D,texture);this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,true);this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,canvas);if(!texture.noMipmap){this._gl.generateMipmap(this._gl.TEXTURE_2D);}this._gl.bindTexture(this._gl.TEXTURE_2D,null);this._activeTexturesCache=[];texture.isReady=true;};BABYLON.Engine.prototype.createRenderTargetTexture=function(size,generateMipMaps){var gl=this._gl;var texture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,texture);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,generateMipMaps?gl.LINEAR_MIPMAP_LINEAR:gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_S,gl.CLAMP_TO_EDGE);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_WRAP_T,gl.CLAMP_TO_EDGE);gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,size,size,0,gl.RGBA,gl.UNSIGNED_BYTE,null);var depthBuffer=gl.createRenderbuffer();gl.bindRenderbuffer(gl.RENDERBUFFER,depthBuffer);gl.renderbufferStorage(gl.RENDERBUFFER,gl.DEPTH_COMPONENT16,size,size);var framebuffer=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,framebuffer);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,texture,0);gl.framebufferRenderbuffer(gl.FRAMEBUFFER,gl.DEPTH_ATTACHMENT,gl.RENDERBUFFER,depthBuffer);gl.bindTexture(gl.TEXTURE_2D,null);gl.bindRenderbuffer(gl.RENDERBUFFER,null);gl.bindFramebuffer(gl.FRAMEBUFFER,null);texture._framebuffer=framebuffer;texture._depthBuffer=depthBuffer;texture._size=size;texture.isReady=true;texture.generateMipMaps=generateMipMaps;texture.references=1;this._activeTexturesCache=[];this._loadedTexturesCache.push(texture);return texture;};var extensions=["_px.jpg","_py.jpg","_pz.jpg","_nx.jpg","_ny.jpg","_nz.jpg"];var cascadeLoad=function(rootUrl,index,loadedImages,scene,onfinish){var img=new Image();img.onload=function(){loadedImages.push(this);scene._removePendingData(img);if(index!=extensions.length-1){cascadeLoad(rootUrl,index+1,loadedImages,scene,onfinish);}else{onfinish(loadedImages);}};img.onerrror=function(){scene._removePendingData(img);};scene._addPendingData(img);img.src=rootUrl+extensions[index];};BABYLON.Engine.prototype.createCubeTexture=function(rootUrl,scene){var gl=this._gl;var texture=gl.createTexture();texture.isCube=true;texture.url=rootUrl;texture.references=1;this._loadedTexturesCache.push(texture);var that=this;cascadeLoad(rootUrl,0,[],scene,function(imgs){var width=getExponantOfTwo(imgs[0].width);var height=width;that._workingCanvas.width=width;that._workingCanvas.height=height;var faces=[gl.TEXTURE_CUBE_MAP_POSITIVE_X,gl.TEXTURE_CUBE_MAP_POSITIVE_Y,gl.TEXTURE_CUBE_MAP_POSITIVE_Z,gl.TEXTURE_CUBE_MAP_NEGATIVE_X,gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,gl.TEXTURE_CUBE_MAP_NEGATIVE_Z];gl.bindTexture(gl.TEXTURE_CUBE_MAP,texture);gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL,false);for(var index=0;indexthis.maximumWorld.x)this.maximumWorld.x=v.x;if(v.y>this.maximumWorld.y)this.maximumWorld.y=v.y;if(v.z>this.maximumWorld.z)this.maximumWorld.z=v.z;}this.center=this.maximumWorld.add(this.minimumWorld).scale(0.5);this.directions[0]=BABYLON.Vector3.FromArray(world.m,0);this.directions[1]=BABYLON.Vector3.FromArray(world.m,4);this.directions[2]=BABYLON.Vector3.FromArray(world.m,8);};BABYLON.BoundingBox.prototype.isInFrustrum=function(frustumPlanes){for(var p=0;p<6;p++){var inCount=8;for(var i=0;i<8;i++){if(frustumPlanes[p].dotCoordinate(this.vectorsWorld[i])<0){--inCount;}else{break;}}if(inCount==0)return false;}return true;};BABYLON.BoundingBox.prototype.intersectsPoint=function(point){if(this.maximumWorld.xpoint.x)return false;if(this.maximumWorld.ypoint.y)return false;if(this.maximumWorld.zpoint.z)return false;return true;};BABYLON.BoundingBox.intersects=function(box0,box1){if(box0.maximumWorld.xbox1.maximumWorld.x)return false;if(box0.maximumWorld.ybox1.maximumWorld.y)return false;if(box0.maximumWorld.zbox1.maximumWorld.z)return false;return true;};})();var BABYLON=BABYLON||{};(function(){BABYLON.BoundingInfo=function(vertices,stride,verticesStart,verticesCount){this.boundingBox=new BABYLON.BoundingBox(vertices,stride,verticesStart,verticesCount);this.boundingSphere=new BABYLON.BoundingSphere(vertices,stride,verticesStart,verticesCount);};BABYLON.BoundingInfo.prototype._update=function(world,scale){this.boundingBox._update(world);this.boundingSphere._update(world,scale);};var extentsOverlap=function(min0,max0,min1,max1){return!(min0>max1||min1>max0);};var computeBoxExtents=function(axis,box){var p=BABYLON.Vector3.Dot(box.center,axis);var r0=Math.abs(BABYLON.Vector3.Dot(box.directions[0],axis))*box.extends.x;var r1=Math.abs(BABYLON.Vector3.Dot(box.directions[1],axis))*box.extends.y;var r2=Math.abs(BABYLON.Vector3.Dot(box.directions[2],axis))*box.extends.z;var r=r0+r1+r2;return{min:p-r,max:p+r};};var axisOverlap=function(axis,box0,box1){var result0=computeBoxExtents(axis,box0);var result1=computeBoxExtents(axis,box1);return extentsOverlap(result0.min,result0.max,result1.min,result1.max);};BABYLON.BoundingInfo.prototype.isInFrustrum=function(frustumPlanes){if(!this.boundingSphere.isInFrustrum(frustumPlanes))return false;return this.boundingBox.isInFrustrum(frustumPlanes);};BABYLON.BoundingInfo.prototype._checkCollision=function(collider){return collider._canDoCollision(this.boundingSphere.centerWorld,this.boundingSphere.radiusWorld,this.boundingBox.minimumWorld,this.boundingBox.maximumWorld);};BABYLON.BoundingInfo.prototype.intersectsPoint=function(point){if(!this.boundingSphere.centerWorld){return false;}if(!this.boundingSphere.intersectsPoint(point)){return false;}if(!this.boundingBox.intersectsPoint(point)){return false;}return true;};BABYLON.BoundingInfo.prototype.intersects=function(boundingInfo,precise){if(!this.boundingSphere.centerWorld||!boundingInfo.boundingSphere.centerWorld){return false;}if(!BABYLON.BoundingSphere.intersects(this.boundingSphere,boundingInfo.boundingSphere)){return false;}if(!BABYLON.BoundingBox.intersects(this.boundingBox,boundingInfo.boundingBox)){return false;}if(!precise){return true;}var box0=this.boundingBox;var box1=boundingInfo.boundingBox;if(!axisOverlap(box0.directions[0],box0,box1))return false;if(!axisOverlap(box0.directions[1],box0,box1))return false;if(!axisOverlap(box0.directions[2],box0,box1))return false;if(!axisOverlap(box1.directions[0],box0,box1))return false;if(!axisOverlap(box1.directions[1],box0,box1))return false;if(!axisOverlap(box1.directions[2],box0,box1))return false;if(!axisOverlap(BABYLON.Vector3.Cross(box0.directions[0],box1.directions[0]),box0,box1))return false;if(!axisOverlap(BABYLON.Vector3.Cross(box0.directions[0],box1.directions[1]),box0,box1))return false;if(!axisOverlap(BABYLON.Vector3.Cross(box0.directions[0],box1.directions[2]),box0,box1))return false;if(!axisOverlap(BABYLON.Vector3.Cross(box0.directions[1],box1.directions[0]),box0,box1))return false;if(!axisOverlap(BABYLON.Vector3.Cross(box0.directions[1],box1.directions[1]),box0,box1))return false;if(!axisOverlap(BABYLON.Vector3.Cross(box0.directions[1],box1.directions[2]),box0,box1))return false;if(!axisOverlap(BABYLON.Vector3.Cross(box0.directions[2],box1.directions[0]),box0,box1))return false;if(!axisOverlap(BABYLON.Vector3.Cross(box0.directions[2],box1.directions[1]),box0,box1))return false;if(!axisOverlap(BABYLON.Vector3.Cross(box0.directions[2],box1.directions[2]),box0,box1))return false;return true;};})();var BABYLON=BABYLON||{};(function(){BABYLON.Light=function(name,scene){this.name=name;this.id=name;this._scene=scene;scene.lights.push(this);};BABYLON.Light.prototype.intensity=1.0;BABYLON.Light.prototype.isEnabled=true;})();var BABYLON=BABYLON||{};(function(){BABYLON.PointLight=function(name,position,scene){this.name=name;this.id=name;this.position=position;this.diffuse=new BABYLON.Color3(1.0,1.0,1.0);this.specular=new BABYLON.Color3(1.0,1.0,1.0);this._scene=scene;scene.lights.push(this);this.animations=[];};BABYLON.PointLight.prototype=Object.create(BABYLON.Light.prototype);})();var BABYLON=BABYLON||{};(function(){BABYLON.SpotLight=function(name,position,direction,angle,exponent,scene){this.name=name;this.id=name;this.position=position;this.direction=direction;this.angle=angle;this.exponent=exponent;this.diffuse=new BABYLON.Color3(1.0,1.0,1.0);this.specular=new BABYLON.Color3(1.0,1.0,1.0);this._scene=scene;scene.lights.push(this);this.animations=[];};BABYLON.SpotLight.prototype=Object.create(BABYLON.Light.prototype);})();var BABYLON=BABYLON||{};(function(){BABYLON.DirectionalLight=function(name,direction,scene){this.name=name;this.id=name;this.direction=direction;this.diffuse=new BABYLON.Color3(1.0,1.0,1.0);this.specular=new BABYLON.Color3(1.0,1.0,1.0);this._scene=scene;scene.lights.push(this);this.animations=[];};BABYLON.DirectionalLight.prototype=Object.create(BABYLON.Light.prototype);})();var BABYLON=BABYLON||{};(function(){BABYLON.HemisphericLight=function(name,direction,scene){this.name=name;this.id=name;this.direction=direction;this.diffuse=new BABYLON.Color3(1.0,1.0,1.0);this.specular=new BABYLON.Color3(1.0,1.0,1.0);this.groundColor=new BABYLON.Color3(0.0,0.0,0.0);this._scene=scene;scene.lights.push(this);this.animations=[];};BABYLON.HemisphericLight.prototype=Object.create(BABYLON.Light.prototype);})();var BABYLON=BABYLON||{};(function(){BABYLON.CollisionPlane=function(origin,normal){this.normal=normal;this.origin=origin;normal.normalize();this.equation=[];this.equation[0]=normal.x;this.equation[1]=normal.y;this.equation[2]=normal.z;this.equation[3]=-(normal.x*origin.x+normal.y*origin.y+normal.z*origin.z);};BABYLON.CollisionPlane.prototype.isFrontFacingTo=function(direction,epsilon){var dot=BABYLON.Vector3.Dot(this.normal,direction);return(dot<=epsilon);};BABYLON.CollisionPlane.prototype.signedDistanceTo=function(point){return BABYLON.Vector3.Dot(point,this.normal)+this.equation[3];};BABYLON.CollisionPlane.CreateFromPoints=function(p1,p2,p3){var normal=BABYLON.Vector3.Cross(p2.subtract(p1),p3.subtract(p1));return new BABYLON.CollisionPlane(p1,normal);};})();var BABYLON=BABYLON||{};(function(){BABYLON.Collider=function(){this.radius=new BABYLON.Vector3(1,1,1);this.retry=0;};BABYLON.Collider.prototype._initialize=function(source,dir,e){this.velocity=dir;this.normalizedVelocity=BABYLON.Vector3.Normalize(dir);this.basePoint=source;this.basePointWorld=source.multiply(this.radius);this.velocityWorld=dir.multiply(this.radius);this.velocityWorldLength=this.velocityWorld.length();this.epsilon=e;this.collisionFound=false;};var checkPointInTriangle=function(point,pa,pb,pc,n){var e0=pa.subtract(point);var e1=pb.subtract(point);var d=BABYLON.Vector3.Dot(BABYLON.Vector3.Cross(e0,e1),n);if(d<0)return false;var e2=pc.subtract(point);d=BABYLON.Vector3.Dot(BABYLON.Vector3.Cross(e1,e2),n);if(d<0)return false;d=BABYLON.Vector3.Dot(BABYLON.Vector3.Cross(e2,e0),n);return d>=0;};var intersectBoxAASphere=function(boxMin,boxMax,sphereCenter,sphereRadius){var boxMinSphere=new BABYLON.Vector3(sphereCenter.X-sphereRadius,sphereCenter.Y-sphereRadius,sphereCenter.Z-sphereRadius);var boxMaxSphere=new BABYLON.Vector3(sphereCenter.X+sphereRadius,sphereCenter.Y+sphereRadius,sphereCenter.Z+sphereRadius);if(boxMin.X>boxMaxSphere.X)return false;if(boxMinSphere.X>boxMax.X)return false;if(boxMin.Y>boxMaxSphere.Y)return false;if(boxMinSphere.Y>boxMax.Y)return false;if(boxMin.Z>boxMaxSphere.Z)return false;if(boxMinSphere.Z>boxMax.Z)return false;return true;};var getLowestRoot=function(a,b,c,maxR){var determinant=b*b-4.0*a*c;var result={root:0,found:false};if(determinant<0)return result;var sqrtD=Math.sqrt(determinant);var r1=(-b-sqrtD)/(2.0*a);var r2=(-b+sqrtD)/(2.0*a);if(r1>r2){var temp=r2;r2=r1;r1=temp;}if(r1>0&&r10&&r2this.velocityWorldLength+max+sphereRadius){return false;}if(!intersectBoxAASphere(vecMin,vecMax,this.basePointWorld,this.velocityWorldLength+max))return false;return true;};BABYLON.Collider.prototype._testTriangle=function(subMesh,p1,p2,p3){var t0;var embeddedInPlane=false;var trianglePlane=BABYLON.CollisionPlane.CreateFromPoints(p1,p2,p3);if((!subMesh.getMaterial())&&!trianglePlane.isFrontFacingTo(this.normalizedVelocity,0))return;var signedDistToTrianglePlane=trianglePlane.signedDistanceTo(this.basePoint);var normalDotVelocity=BABYLON.Vector3.Dot(trianglePlane.normal,this.velocity);if(normalDotVelocity==0){if(Math.abs(signedDistToTrianglePlane)>=1.0)return;embeddedInPlane=true;t0=0;}else{t0=(-1.0-signedDistToTrianglePlane)/normalDotVelocity;var t1=(1.0-signedDistToTrianglePlane)/normalDotVelocity;if(t0>t1){var temp=t1;t1=t0;t0=temp;}if(t0>1.0||t1<0.0)return;if(t0<0)t0=0;if(t0>1.0)t0=1.0;}var collisionPoint=BABYLON.Vector3.Zero();var found=false;var t=1.0;if(!embeddedInPlane){var planeIntersectionPoint=(this.basePoint.subtract(trianglePlane.normal)).add(this.velocity.scale(t0));if(checkPointInTriangle(planeIntersectionPoint,p1,p2,p3,trianglePlane.normal)){found=true;t=t0;collisionPoint=planeIntersectionPoint;}}if(!found){var velocitySquaredLength=this.velocity.lengthSquared();var a=velocitySquaredLength;var b=2.0*(BABYLON.Vector3.Dot(this.velocity,this.basePoint.subtract(p1)));var c=p1.subtract(this.basePoint).lengthSquared()-1.0;var lowestRoot=getLowestRoot(a,b,c,t);if(lowestRoot.found){t=lowestRoot.root;found=true;collisionPoint=p1;}b=2.0*(BABYLON.Vector3.Dot(this.velocity,this.basePoint.subtract(p2)));c=p2.subtract(this.basePoint).lengthSquared()-1.0;lowestRoot=getLowestRoot(a,b,c,t);if(lowestRoot.found){t=lowestRoot.root;found=true;collisionPoint=p2;}b=2.0*(BABYLON.Vector3.Dot(this.velocity,this.basePoint.subtract(p3)));c=p3.subtract(this.basePoint).lengthSquared()-1.0;lowestRoot=getLowestRoot(a,b,c,t);if(lowestRoot.found){t=lowestRoot.root;found=true;collisionPoint=p3;}var edge=p2.subtract(p1);var baseToVertex=p1.subtract(this.basePoint);var edgeSquaredLength=edge.lengthSquared();var edgeDotVelocity=BABYLON.Vector3.Dot(edge,this.velocity);var edgeDotBaseToVertex=BABYLON.Vector3.Dot(edge,baseToVertex);a=edgeSquaredLength*(-velocitySquaredLength)+edgeDotVelocity*edgeDotVelocity;b=edgeSquaredLength*(2.0*BABYLON.Vector3.Dot(this.velocity,baseToVertex))-2.0*edgeDotVelocity*edgeDotBaseToVertex;c=edgeSquaredLength*(1.0-baseToVertex.lengthSquared())+edgeDotBaseToVertex*edgeDotBaseToVertex;lowestRoot=getLowestRoot(a,b,c,t);if(lowestRoot.found){var f=(edgeDotVelocity*lowestRoot.root-edgeDotBaseToVertex)/edgeSquaredLength;if(f>=0.0&&f<=1.0){t=lowestRoot.root;found=true;collisionPoint=p1.add(edge.scale(f));}}edge=p3.subtract(p2);baseToVertex=p2.subtract(this.basePoint);edgeSquaredLength=edge.lengthSquared();edgeDotVelocity=BABYLON.Vector3.Dot(edge,this.velocity);edgeDotBaseToVertex=BABYLON.Vector3.Dot(edge,baseToVertex);a=edgeSquaredLength*(-velocitySquaredLength)+edgeDotVelocity*edgeDotVelocity;b=edgeSquaredLength*(2.0*BABYLON.Vector3.Dot(this.velocity,baseToVertex))-2.0*edgeDotVelocity*edgeDotBaseToVertex;c=edgeSquaredLength*(1.0-baseToVertex.lengthSquared())+edgeDotBaseToVertex*edgeDotBaseToVertex;lowestRoot=getLowestRoot(a,b,c,t);if(lowestRoot.found){var f=(edgeDotVelocity*lowestRoot.root-edgeDotBaseToVertex)/edgeSquaredLength;if(f>=0.0&&f<=1.0){t=lowestRoot.root;found=true;collisionPoint=p2.add(edge.scale(f));}}edge=p1.subtract(p3);baseToVertex=p3.subtract(this.basePoint);edgeSquaredLength=edge.lengthSquared();edgeDotVelocity=BABYLON.Vector3.Dot(edge,this.velocity);edgeDotBaseToVertex=BABYLON.Vector3.Dot(edge,baseToVertex);a=edgeSquaredLength*(-velocitySquaredLength)+edgeDotVelocity*edgeDotVelocity;b=edgeSquaredLength*(2.0*BABYLON.Vector3.Dot(this.velocity,baseToVertex))-2.0*edgeDotVelocity*edgeDotBaseToVertex;c=edgeSquaredLength*(1.0-baseToVertex.lengthSquared())+edgeDotBaseToVertex*edgeDotBaseToVertex;lowestRoot=getLowestRoot(a,b,c,t);if(lowestRoot.found){var f=(edgeDotVelocity*lowestRoot.root-edgeDotBaseToVertex)/edgeSquaredLength;if(f>=0.0&&f<=1.0){t=lowestRoot.root;found=true;collisionPoint=p3.add(edge.scale(f));}}}if(found){var distToCollision=t*this.velocity.length();if(!this.collisionFound||distToCollision=0.0){this.rotation.y=(-Math.atan(vDir.z/vDir.x)+Math.PI/2.0);}else{this.rotation.y=(-Math.atan(vDir.z/vDir.x)-Math.PI/2.0);}this.rotation.z=-Math.acos(BABYLON.Vector3.Dot(new BABYLON.Vector3(0,1.0,0),BABYLON.Vector3.Up()));if(isNaN(this.rotation.x))this.rotation.x=0;if(isNaN(this.rotation.y))this.rotation.y=0;if(isNaN(this.rotation.z))this.rotation.z=0;};BABYLON.FreeCamera.prototype.attachControl=function(canvas){var previousPosition;var that=this;this._onMouseDown=function(evt){previousPosition={x:evt.clientX,y:evt.clientY};evt.preventDefault();};this._onMouseUp=function(evt){previousPosition=null;evt.preventDefault();};this._onMouseOut=function(evt){previousPosition=null;that._keys=[];evt.preventDefault();};this._onMouseMove=function(evt){if(!previousPosition){return;}var offsetX=evt.clientX-previousPosition.x;var offsetY=evt.clientY-previousPosition.y;that.cameraRotation.y+=offsetX/2000.0;that.cameraRotation.x+=offsetY/2000.0;previousPosition={x:evt.clientX,y:evt.clientY};evt.preventDefault();};this._onKeyDown=function(evt){if(that.keysUp.indexOf(evt.keyCode)!==-1||that.keysDown.indexOf(evt.keyCode)!==-1||that.keysLeft.indexOf(evt.keyCode)!==-1||that.keysRight.indexOf(evt.keyCode)!==-1){var index=that._keys.indexOf(evt.keyCode);if(index===-1){that._keys.push(evt.keyCode);}evt.preventDefault();}};this._onKeyUp=function(evt){if(that.keysUp.indexOf(evt.keyCode)!==-1||that.keysDown.indexOf(evt.keyCode)!==-1||that.keysLeft.indexOf(evt.keyCode)!==-1||that.keysRight.indexOf(evt.keyCode)!==-1){var index=that._keys.indexOf(evt.keyCode);if(index>=0){that._keys.splice(index,1);}evt.preventDefault();}};this._onLostFocus=function(){that._keys=[];};canvas.addEventListener("mousedown",this._onMouseDown,true);canvas.addEventListener("mouseup",this._onMouseUp,true);canvas.addEventListener("mouseout",this._onMouseOut,true);canvas.addEventListener("mousemove",this._onMouseMove,true);window.addEventListener("keydown",this._onKeyDown,true);window.addEventListener("keyup",this._onKeyUp,true);window.addEventListener("blur",this._onLostFocus,true);};BABYLON.FreeCamera.prototype.detachControl=function(canvas){canvas.removeEventListener("mousedown",this._onMouseDown);canvas.removeEventListener("mouseup",this._onMouseUp);canvas.removeEventListener("mouseout",this._onMouseOut);canvas.removeEventListener("mousemove",this._onMouseMove);window.removeEventListener("keydown",this._onKeyDown);window.removeEventListener("keyup",this._onKeyUp);window.removeEventListener("blur",this._onLostFocus);};BABYLON.FreeCamera.prototype._collideWithWorld=function(velocity){var oldPosition=this.position.subtract(new BABYLON.Vector3(0,this.ellipsoid.y,0));this._collider.radius=this.ellipsoid;var newPosition=this._scene._getNewPosition(oldPosition,velocity,this._collider,3);var diffPosition=newPosition.subtract(oldPosition);if(diffPosition.length()>BABYLON.Engine.collisionsEpsilon){this.position=this.position.add(diffPosition);}};BABYLON.FreeCamera.prototype._checkInputs=function(){for(var index=0;index0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0;var needToRotate=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(needToMove){if(this.checkCollisions&&this._scene.collisionsEnabled){this._collideWithWorld(this.cameraDirection);if(this.applyGravity){var oldPosition=this.position;this._collideWithWorld(this._scene.gravity);this._needMoveForGravity=(oldPosition.subtract(this.position).length()!=0);}}else{this.position=this.position.add(this.cameraDirection);}}if(needToRotate){this.rotation.x+=this.cameraRotation.x;this.rotation.y+=this.cameraRotation.y;var limit=(Math.PI/2)*0.95;if(this.rotation.x>limit)this.rotation.x=limit;if(this.rotation.x<-limit)this.rotation.x=-limit;}if(needToMove){this.cameraDirection=this.cameraDirection.scale(this.inertia);}if(needToRotate){this.cameraRotation=this.cameraRotation.scale(this.inertia);}};BABYLON.FreeCamera.prototype.getViewMatrix=function(){var referencePoint=new BABYLON.Vector3(0,0,1);var transform=BABYLON.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z);var currentTarget=this.position.add(BABYLON.Vector3.TransformCoordinates(referencePoint,transform));return new BABYLON.Matrix.LookAtLH(this.position,currentTarget,BABYLON.Vector3.Up());};})();var BABYLON=BABYLON||{};(function(){BABYLON.TouchCamera=function(name,position,scene){this.name=name;this.id=name;this._scene=scene;this.position=position;scene.cameras.push(this);this.cameraDirection=new BABYLON.Vector3(0,0,0);this.cameraRotation=new BABYLON.Vector2(0,0);this.rotation=new BABYLON.Vector3(0,0,0);this.ellipsoid=new BABYLON.Vector3(0.5,1,0.5);if(!scene.activeCamera){scene.activeCamera=this;}this._collider=new BABYLON.Collider();this._needMoveForGravity=true;this._offsetX=null;this._offsetY=null;this._pointerCount=0;this._pointerPressed=[];this.animations=[];};BABYLON.TouchCamera.prototype=Object.create(BABYLON.FreeCamera.prototype);BABYLON.TouchCamera.prototype.attachControl=function(canvas){var previousPosition;var that=this;this._onPointerDown=function(evt){evt.preventDefault();that._pointerPressed.push(evt.pointerId);if(that._pointerPressed.length!==1){return;}previousPosition={x:evt.clientX,y:evt.clientY};};this._onPointerUp=function(evt){evt.preventDefault();var index=that._pointerPressed.indexOf(evt.pointerId);if(index===-1){return;}that._pointerPressed.splice(index,1);if(index!=0){return;}previousPosition=null;that._offsetX=null;that._offsetY=null;};this._onPointerMove=function(evt){evt.preventDefault();if(!previousPosition){return;}var index=that._pointerPressed.indexOf(evt.pointerId);if(index!=0){return;}that._offsetX=evt.clientX-previousPosition.x;that._offsetY=-(evt.clientY-previousPosition.y);};this._onLostFocus=function(){that._offsetX=null;that._offsetY=null;};canvas.addEventListener("pointerdown",this._onPointerDown,true);canvas.addEventListener("pointerup",this._onPointerUp,true);canvas.addEventListener("pointerout",this._onPointerUp,true);canvas.addEventListener("pointermove",this._onPointerMove,true);window.addEventListener("blur",this._onLostFocus,true);};BABYLON.TouchCamera.prototype.detachControl=function(canvas){canvas.removeEventListener("pointerdown",this._onPointerDown);canvas.removeEventListener("pointerup",this._onPointerUp);canvas.removeEventListener("pointerout",this._onPointerUp);canvas.removeEventListener("pointermove",this._onPointerMove);window.removeEventListener("blur",this._onLostFocus);};BABYLON.TouchCamera.prototype._checkInputs=function(){if(!this._offsetX){return;}this.cameraRotation.y+=this._offsetX/100000.0;if(this._pointerPressed.length>1){this.cameraRotation.x+=-this._offsetY/100000.0;}else{var speed=this._computeLocalCameraSpeed();var direction=new BABYLON.Vector3(0,0,speed*this._offsetY/500.0);var cameraTransform=BABYLON.Matrix.RotationYawPitchRoll(this.rotation.y,this.rotation.x,0);this.cameraDirection=this.cameraDirection.add(BABYLON.Vector3.TransformCoordinates(direction,cameraTransform));}};})();var BABYLON=BABYLON||{};(function(){BABYLON.ArcRotateCamera=function(name,alpha,beta,radius,target,scene){this.name=name;this.id=name;this.alpha=alpha;this.beta=beta;this.radius=radius;this.target=target;this._scene=scene;scene.cameras.push(this);if(!scene.activeCamera){scene.activeCamera=this;}this.getViewMatrix();this.animations=[];};BABYLON.ArcRotateCamera.prototype=Object.create(BABYLON.Camera.prototype);BABYLON.ArcRotateCamera.prototype.inertialAlphaOffset=0;BABYLON.ArcRotateCamera.prototype.inertialBetaOffset=0;BABYLON.ArcRotateCamera.prototype.attachControl=function(canvas){var previousPosition;var that=this;this._onPointerDown=function(evt){previousPosition={x:evt.clientX,y:evt.clientY};evt.preventDefault();};this._onPointerUp=function(evt){previousPosition=null;evt.preventDefault();};this._onPointerMove=function(evt){if(!previousPosition){return;}var offsetX=evt.clientX-previousPosition.x;var offsetY=evt.clientY-previousPosition.y;that.inertialAlphaOffset-=offsetX/1000;that.inertialBetaOffset-=offsetY/1000;previousPosition={x:evt.clientX,y:evt.clientY};evt.preventDefault();};this._wheel=function(event){var delta=0;if(event.wheelDelta){delta=event.wheelDelta/120;}else if(event.detail){delta=-event.detail/3;}if(delta)that.radius-=delta;if(event.preventDefault)event.preventDefault();};canvas.addEventListener("pointerdown",this._onPointerDown);canvas.addEventListener("pointerup",this._onPointerUp);canvas.addEventListener("pointerout",this._onPointerUp);canvas.addEventListener("pointermove",this._onPointerMove);window.addEventListener('mousewheel',this._wheel);};BABYLON.ArcRotateCamera.prototype.detachControl=function(canvas){canvas.removeEventListener("pointerdown",this._onPointerDown);canvas.removeEventListener("pointerup",this._onPointerUp);canvas.removeEventListener("pointerout",this._onPointerUp);canvas.removeEventListener("pointermove",this._onPointerMove);window.removeEventListener('mousewheel',this._wheel);};BABYLON.ArcRotateCamera.prototype._update=function(){if(this.inertialAlphaOffset!=0||this.inertialBetaOffset!=0){this.alpha+=this.inertialAlphaOffset;this.beta+=this.inertialBetaOffset;this.inertialAlphaOffset*=this.inertia;this.inertialBetaOffset*=this.inertia;if(Math.abs(this.inertialAlphaOffset)Math.PI)this.beta=Math.PI;if(this.beta<=0)this.beta=0.01;var cosa=Math.cos(this.alpha);var sina=Math.sin(this.alpha);var cosb=Math.cos(this.beta);var sinb=Math.sin(this.beta);this.position=this.target.add(new BABYLON.Vector3(this.radius*cosa*sinb,this.radius*cosb,this.radius*sina*sinb));return new BABYLON.Matrix.LookAtLH(this.position,this.target,BABYLON.Vector3.Up());};})();var BABYLON=BABYLON||{};(function(){BABYLON.Scene=function(engine){this._engine=engine;this.autoClear=true;this.clearColor=new BABYLON.Color3(0.2,0.2,0.3);this.ambientColor=new BABYLON.Color3(0,0,0);engine.scenes.push(this);this._totalVertices=0;this._activeVertices=0;this._activeParticles=0;this._lastFrameDuration=0;this._evaluateActiveMeshesDuration=0;this._renderTargetsDuration=0;this._renderDuration=0;this._toBeDisposed=[];this._onReadyCallbacks=[];this._pendingData=[];this.lights=[];this.cameras=[];this.activeCamera=null;this.meshes=[];this._activeMeshes=[];this.materials=[];this.multiMaterials=[];this.defaultMaterial=new BABYLON.StandardMaterial("default material",this);this.textures=[];this.particleSystems=[];this.spriteManagers=[];this.layers=[];this.collisionsEnabled=true;this.gravity=new BABYLON.Vector3(0,0,-9);this._activeAnimatables=[];};BABYLON.Scene.prototype.getEngine=function(){return this._engine;};BABYLON.Scene.prototype.getTotalVertices=function(){return this._totalVertices;};BABYLON.Scene.prototype.getActiveVertices=function(){return this._activeVertices;};BABYLON.Scene.prototype.getTotalVertices=function(){return this._totalVertices;};BABYLON.Scene.prototype.getActiveParticles=function(){return this._activeParticles;};BABYLON.Scene.prototype.getLastFrameDuration=function(){return this._lastFrameDuration;};BABYLON.Scene.prototype.getEvaluateActiveMeshesDuration=function(){return this._evaluateActiveMeshesDuration;};BABYLON.Scene.prototype.getRenderTargetsDuration=function(){return this._renderTargetsDuration;};BABYLON.Scene.prototype.getRenderDuration=function(){return this._renderDuration;};BABYLON.Scene.prototype.getParticlesDuration=function(){return this._particlesDuration;};BABYLON.Scene.prototype.getSpritesDuration=function(){return this._spritesDuration;};BABYLON.Scene.prototype.getAnimationRatio=function(){return this._animationRatio;};BABYLON.Scene.prototype.isReady=function(){for(var index=0;index0&&mesh.isInFrustrum(frustumPlanes)){for(var subIndex=0;subIndex0||mesh.visibility<1.0){this._transparentSubMeshes.push(subMesh);}}else if(material.needAlphaTesting()){this._alphaTestSubMeshes.push(subMesh);}else{this._opaqueSubMeshes.push(subMesh);}}}}}}var beforeParticlesDate=new Date();for(var particleIndex=0;particleIndex0){engine.restoreDefaultFramebuffer();}this._renderTargetsDuration=new Date()-beforeRenderTargetDate;var beforeRenderDate=new Date();engine.clear(this.clearColor,this.autoClear,true);engine.setDepthBuffer(false);for(var layerIndex=0;layerIndex=maximumRetry){return position;}collider._initialize(position,velocity,closeDistance);for(var index=0;index=distance)continue;distance=result.distance;pickedMesh=mesh;var worldOrigin=BABYLON.Vector3.TransformCoordinates(ray.origin,world);var direction=ray.direction.clone();direction.normalize();direction=direction.scale(result.distance);var worldDirection=BABYLON.Vector3.TransformNormal(direction,world);pickedPoint=worldOrigin.add(worldDirection);}return{hit:distance!=Number.MAX_VALUE,distance:distance,pickedMesh:pickedMesh,pickedPoint:pickedPoint};};})();var BABYLON=BABYLON||{};(function(){BABYLON.Mesh=function(name,vertexDeclaration,scene){this.name=name;this.id=name;this._scene=scene;this._vertexDeclaration=vertexDeclaration;this._vertexStrideSize=0;for(var index=0;index1&&!subMesh._checkCollision(collider))continue;this._collideForSubMesh(subMesh,transformMatrix,collider);}};BABYLON.Mesh.prototype._checkCollision=function(collider){if(!this._boundingInfo._checkCollision(collider))return;var transformMatrix=this._worldMatrix.multiply(BABYLON.Matrix.Scaling(1.0/collider.radius.x,1.0/collider.radius.y,1.0/collider.radius.z));this._processCollisionsForSubModels(collider,transformMatrix);};BABYLON.Mesh.prototype.intersectsMesh=function(mesh,precise){if(!this._boundingInfo||!mesh._boundingInfo){return false;}return this._boundingInfo.intersects(mesh._boundingInfo,precise);};BABYLON.Mesh.prototype.intersectsPoint=function(point){if(!this._boundingInfo){return false;}return this._boundingInfo.intersectsPoint(point);};BABYLON.Mesh.prototype.intersects=function(ray){if(!this._boundingInfo||!ray.intersectsSphere(this._boundingInfo.boundingSphere)){return{hit:false,distance:0};}this._generatePointsArray();var distance=Number.MAX_VALUE;for(var index=0;index1&&!subMesh.canIntersects(ray))continue;var result=subMesh.intersects(ray,this._positions,this._indices);if(result.hit){if(result.distance=0){distance=result.distance;}}}if(distance>=0)return{hit:true,distance:distance};return{hit:false,distance:0};};BABYLON.Mesh.prototype.clone=function(name,newParent){var result=new BABYLON.Mesh(name,this._vertexDeclaration,this._scene);BABYLON.Tools.DeepCopy(this,result,["name","material"],["_uvCount","_vertices","_indices","_totalVertices"]);result._boundingInfo=new BABYLON.BoundingInfo(result._vertices,result.getFloatVertexStrideSize(),0,result._vertices.length);result.material=this.material;result._vertexBuffer=this._vertexBuffer;this._vertexBuffer.references++;result._indexBuffer=this._indexBuffer;this._indexBuffer.references++;if(newParent){result.parent=newParent;}for(var index=0;index0){var verticesCount=vertices.length/8;for(var firstIndex=verticesCount-2*(totalYRotationSteps+1);(firstIndex+totalYRotationSteps+2)=0){distance=result.distance;}}}if(distance>=0)return{hit:true,distance:distance};return{hit:false,distance:0};};BABYLON.SubMesh.prototype.clone=function(newMesh){return new BABYLON.SubMesh(this.materialIndex,this.verticesStart,this.verticesCount,this.indexStart,this.indexCount,newMesh);};})();var BABYLON=BABYLON||{};(function(){BABYLON.BaseTexture=function(url,scene){this._scene=scene;this._scene.textures.push(this);};BABYLON.BaseTexture.prototype.hasAlpha=false;BABYLON.BaseTexture.prototype.level=1;BABYLON.BaseTexture.prototype._texture=null;BABYLON.BaseTexture.prototype.onDispose=null;BABYLON.BaseTexture.prototype.getInternalTexture=function(){return this._texture;};BABYLON.BaseTexture.prototype.isReady=function(){return(this._texture!==undefined&&this._texture.isReady);};BABYLON.BaseTexture.prototype.getSize=function(){if(this._texture._width){return{width:this._texture._width,height:this._texture._height};}if(this._texture._size){return{width:this._texture._size,height:this._texture._size};}return{width:0,height:0};};BABYLON.BaseTexture.prototype.getBaseSize=function(){if(!this.isReady())return{width:0,height:0};if(this._texture._size){return{width:this._texture._size,height:this._texture._size};}return{width:this._texture._baseWidth,height:this._texture._baseHeight};};BABYLON.BaseTexture.prototype._getFromCache=function(url,noMipmap){var texturesCache=this._scene.getEngine().getLoadedTexturesCache();for(var index=0;index0){this._transparentSubMeshes.push(subMesh);}}else{this._opaqueSubMeshes.push(subMesh);}}}}scene._localRender(this._opaqueSubMeshes,this._alphaTestSubMeshes,this._transparentSubMeshes,this.renderList);engine.unBindFramebuffer(this._texture);if(this._onAfterRender){this._onAfterRender();}};})();var BABYLON=BABYLON||{};(function(){BABYLON.MirrorTexture=function(name,size,scene,generateMipMaps){this._scene=scene;this._scene.textures.push(this);this.name=name;this._texture=scene.getEngine().createRenderTargetTexture(size,generateMipMaps);};BABYLON.MirrorTexture.prototype=Object.create(BABYLON.RenderTargetTexture.prototype);BABYLON.MirrorTexture.prototype.mirrorPlane=new BABYLON.Plane(0,1,0,1);BABYLON.MirrorTexture.prototype._onBeforeRender=function(){var scene=this._scene;var mirrorMatrix=BABYLON.Matrix.Reflection(this.mirrorPlane);this._savedViewMatrix=scene.getViewMatrix();scene.setTransformMatrix(mirrorMatrix.multiply(this._savedViewMatrix),scene.getProjectionMatrix());BABYLON.clipPlane=this.mirrorPlane;scene.getEngine().cullBackFaces=false;};BABYLON.MirrorTexture.prototype._onAfterRender=function(){var scene=this._scene;scene.setTransformMatrix(this._savedViewMatrix,scene.getProjectionMatrix());scene.getEngine().cullBackFaces=true;delete BABYLON.clipPlane;};})();var BABYLON=BABYLON||{};(function(){BABYLON.DynamicTexture=function(name,size,scene,generateMipMaps){this._scene=scene;this._scene.textures.push(this);this.name=name;this.wrapU=false;this.wrapV=false;this._texture=scene.getEngine().createDynamicTexture(size,generateMipMaps);var size=this.getSize();this._canvas=document.createElement("canvas");this._canvas.width=size.width;this._canvas.height=size.height;this._context=this._canvas.getContext("2d");};BABYLON.DynamicTexture.prototype=Object.create(BABYLON.Texture.prototype);BABYLON.DynamicTexture.prototype.getContext=function(){return this._context;};BABYLON.DynamicTexture.prototype.update=function(){this._scene.getEngine().updateDynamicTexture(this._texture,this._canvas);};})();var BABYLON=BABYLON||{};(function(){BABYLON.Effect=function(baseName,attributesNames,uniformsNames,samplers,engine,defines){this._engine=engine;this.name=baseName;this.defines=defines;this._uniformsNames=uniformsNames.concat(samplers);this._samplers=samplers;this._isReady=false;var that=this;if(BABYLON.Effect.ShadersStore[baseName+"VertexShader"]){this._prepareEffect(BABYLON.Effect.ShadersStore[baseName+"VertexShader"],BABYLON.Effect.ShadersStore[baseName+"PixelShader"],attributesNames,defines);}else{var shaderUrl=BABYLON.Engine.ShadersRepository+baseName;BABYLON.Tools.LoadFile(shaderUrl+".vertex.fx",function(vertexSourceCode){BABYLON.Tools.LoadFile(shaderUrl+".fragment.fx",function(fragmentSourceCode){that._prepareEffect(vertexSourceCode,fragmentSourceCode,attributesNames,defines);});});}this._valueCache=[];};BABYLON.Effect.prototype.isReady=function(){return this._isReady;};BABYLON.Effect.prototype.getProgram=function(){return this._program;};BABYLON.Effect.prototype.getAttribute=function(index){return this._attributes[index];};BABYLON.Effect.prototype.getAttributesCount=function(){return this._attributes.length;};BABYLON.Effect.prototype.getUniformIndex=function(uniformName){return this._uniformsNames.indexOf(uniformName);};BABYLON.Effect.prototype.getUniform=function(uniformName){return this._uniforms[this._uniformsNames.indexOf(uniformName)];};BABYLON.Effect.prototype.getSamplers=function(){return this._samplers;};BABYLON.Effect.prototype._prepareEffect=function(vertexSourceCode,fragmentSourceCode,attributesNames,defines){var engine=this._engine;this._program=engine.createShaderProgram(vertexSourceCode,fragmentSourceCode,defines);this._uniforms=engine.getUniforms(this._program,this._uniformsNames);this._attributes=engine.getAttributes(this._program,attributesNames);for(var index=0;index= lightDirection.w)\n {\n cosAngle = max(0., pow(cosAngle, lightData.w));\n spotAtten = max(0., (cosAngle - lightDirection.w) / (1. - cosAngle));\n\n // Diffuse\n float ndl = max(0., dot(vNormalW, -lightDirection.xyz));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\n float specComp = max(0., dot(normalize(vNormalW), angleW));\n specComp = pow(specComp, vSpecularColor.a);\n\n result.diffuse = ndl * spotAtten * diffuseColor;\n result.specular = specComp * specularColor * spotAtten;\n\n return result;\n }\n\n result.diffuse = vec3(0.);\n result.specular = vec3(0.);\n\n return result;\n}\n\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor) {\n lightingInfo result;\n\n // Diffuse\n float ndl = dot(vNormalW, lightData.xyz) * 0.5 + 0.5;\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\n float specComp = max(0., dot(normalize(vNormalW), angleW));\n specComp = pow(specComp, vSpecularColor.a);\n\n result.diffuse = mix(groundColor, diffuseColor, ndl);\n result.specular = specComp * specularColor;\n\n return result;\n}\n\nvoid main(void) {\n // Clip plane\n#ifdef CLIPPLANE\n if (fClipDistance > 0.0)\n discard;\n#endif\n\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\n\n // Base color\n vec4 baseColor = vec4(1., 1., 1., 1.);\n vec3 diffuseColor = vDiffuseColor.rgb;\n\n#ifdef DIFFUSE\n baseColor = texture2D(diffuseSampler, vDiffuseUV);\n\n#ifdef ALPHATEST\n if (baseColor.a < 0.4)\n discard;\n#endif\n\n baseColor.rgb *= vDiffuseInfos.y;\n#endif\n\n // Ambient color\n vec3 baseAmbientColor = vec3(1., 1., 1.);\n\n#ifdef AMBIENT\n baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\n#endif\n\n // Lighting\n vec3 diffuseBase = vec3(0., 0., 0.);\n vec3 specularBase = vec3(0., 0., 0.);\n\n#ifdef LIGHT0\n#ifdef SPOTLIGHT0\n lightingInfo info = computeSpotLighting(viewDirectionW, vLightData0, vLightDirection0, vLightDiffuse0, vLightSpecular0);\n#endif\n#ifdef HEMILIGHT0\n lightingInfo info = computeHemisphericLighting(viewDirectionW, vLightData0, vLightDiffuse0, vLightSpecular0, vLightGround0);\n#endif\n#ifdef POINTDIRLIGHT0\n lightingInfo info = computeLighting(viewDirectionW, vLightData0, vLightDiffuse0, vLightSpecular0);\n#endif\n diffuseBase += info.diffuse;\n specularBase += info.specular;\n#endif\n\n#ifdef LIGHT1\n#ifdef SPOTLIGHT1\n info = computeSpotLighting(viewDirectionW, vLightData1, vLightDirection1, vLightDiffuse1, vLightSpecular1);\n#endif\n#ifdef HEMILIGHT1\n info = computeHemisphericLighting(viewDirectionW, vLightData1, vLightDiffuse1, vLightSpecular1, vLightGround1);\n#endif\n#ifdef POINTDIRLIGHT1\n info = computeLighting(viewDirectionW, vLightData1, vLightDiffuse1, vLightSpecular1);\n#endif\n diffuseBase += info.diffuse;\n specularBase += info.specular;\n#endif\n\n#ifdef LIGHT2\n#ifdef SPOTLIGHT2\n info = computeSpotLighting(viewDirectionW, vLightData2, vLightDirection2, vLightDiffuse2, vLightSpecular2);\n#endif\n#ifdef HEMILIGHT2\n info = computeHemisphericLighting(viewDirectionW, vLightData2, vLightDiffuse2, vLightSpecular2, vLightGround2);\n#endif\n#ifdef POINTDIRLIGHT2\n info = computeLighting(viewDirectionW, vLightData2, vLightDiffuse2, vLightSpecular2);\n#endif\n diffuseBase += info.diffuse;\n specularBase += info.specular;\n#endif\n\n#ifdef LIGHT3\n#ifdef SPOTLIGHT3\n info = computeSpotLighting(viewDirectionW, vLightData3, vLightDirection3, vLightDiffuse3, vLightSpecular3);\n#endif\n#ifdef HEMILIGHT3\n info = computeHemisphericLighting(viewDirectionW, vLightData3, vLightDiffuse3, vLightSpecular3, vLightGround3);\n#endif\n#ifdef POINTDIRLIGHT3\n info = computeLighting(viewDirectionW, vLightData3, vLightDiffuse3, vLightSpecular3);\n#endif\n diffuseBase += info.diffuse;\n specularBase += info.specular;\n#endif\n\n // Reflection\n vec3 reflectionColor = vec3(0., 0., 0.);\n\n#ifdef REFLECTION\n if (vMisc.x != 0.0)\n {\n reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y;\n }\n else\n {\n vec2 coords = vReflectionUVW.xy;\n\n if (vReflectionInfos.x == MAP_PROJECTION)\n {\n coords /= vReflectionUVW.z;\n }\n\n coords.y = 1.0 - coords.y;\n\n reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y;\n }\n#endif\n\n // Alpha\n float alpha = vDiffuseColor.a;\n\n#ifdef OPACITY\n vec3 opacityMap = texture2D(opacitySampler, vOpacityUV).rgb * vec3(0.3, 0.59, 0.11);\n alpha *= (opacityMap.x + opacityMap.y + opacityMap.z)* vOpacityInfos.y;\n#endif\n\n // Emissive\n vec3 emissiveColor = vEmissiveColor;\n#ifdef EMISSIVE\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\n#endif\n\n // Specular map\n vec3 specularColor = vSpecularColor.rgb;\n#ifdef SPECULAR\n specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y;\n#endif\n\n // Composition\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\n vec3 finalSpecular = specularBase * specularColor;\n\n gl_FragColor = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\n}", defaultVertexShader:"#define MAP_EXPLICIT 0.\n#define MAP_SPHERICAL 1.\n#define MAP_PLANAR 2.\n#define MAP_CUBIC 3.\n#define MAP_PROJECTION 4.\n\n// Attributes\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 worldViewProjection;\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n\n#ifdef REFLECTION\nuniform vec3 vEyePosition;\nuniform mat4 view;\nvarying vec3 vReflectionUVW;\n\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\n#endif\n\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n\n#ifdef SPECULAR\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n\n// Output\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif\n\n#ifdef REFLECTION\nvec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)\n{ \n if (mode == MAP_SPHERICAL)\n {\n vec3 coords = vec3(view * vec4(worldNormal, 0.0)); \n\n return vec3(reflectionMatrix * vec4(coords, 1.0));\n }\n else if (mode == MAP_PLANAR)\n {\n vec3 viewDir = worldPos.xyz - vEyePosition;\n vec3 coords = normalize(reflect(viewDir, worldNormal));\n\n return vec3(reflectionMatrix * vec4(coords, 1));\n }\n else if (mode == MAP_CUBIC)\n {\n vec3 viewDir = worldPos.xyz - vEyePosition;\n vec3 coords = reflect(viewDir, worldNormal);\n\n return vec3(reflectionMatrix * vec4(coords, 0)); \n }\n else if (mode == MAP_PROJECTION)\n {\n return vec3(reflectionMatrix * (view * worldPos));\n }\n\n return vec3(0, 0, 0);\n}\n#endif\n\nvoid main(void) {\n gl_Position = worldViewProjection * vec4(position, 1.0); \n\n vec4 worldPos = world * vec4(position, 1.0);\n vPositionW = vec3(worldPos);\n vNormalW = normalize(vec3(world * vec4(normal, 0.0)));\n\n // Texture coordinates\n#ifndef UV1\n vec2 uv = vec2(0., 0.);\n#endif\n#ifndef UV2\n vec2 uv2 = vec2(0., 0.);\n#endif\n\n#ifdef DIFFUSE\n if (vDiffuseInfos.x == 0.)\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef AMBIENT\n if (vAmbientInfos.x == 0.)\n {\n vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef OPACITY\n if (vOpacityInfos.x == 0.)\n {\n vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef REFLECTION\n vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), vNormalW);\n#endif\n\n#ifdef EMISSIVE\n if (vEmissiveInfos.x == 0.)\n {\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef SPECULAR\n if (vSpecularInfos.x == 0.)\n {\n vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n // Clip plane\n#ifdef CLIPPLANE\n fClipDistance = dot(worldPos, vClipPlane);\n#endif\n}", iedefaultPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n#define MAP_PROJECTION 4.\n\n// Constants\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vDiffuseColor;\nuniform vec4 vSpecularColor;\nuniform vec3 vEmissiveColor;\nuniform vec4 vMisc;\nuniform vec4 vLightsType;\n\n// Lights\n#ifdef LIGHT0\nuniform vec3 vLightData0;\nuniform vec3 vLightDiffuse0;\nuniform vec3 vLightSpecular0;\n#endif\n\n// Samplers\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n\n#ifdef REFLECTION\nvarying vec3 vReflectionUVW;\nuniform samplerCube reflectionCubeSampler;\nuniform sampler2D reflection2DSampler;\nuniform vec2 vReflectionInfos;\n#endif\n\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n\n#ifdef SPECULAR\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform sampler2D specularSampler;\n#endif\n\n// Input\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n\nvoid main(void) {\n // Clip plane\n#ifdef CLIPPLANE\n if (fClipDistance > 0.0)\n discard;\n#endif\n\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\n\n // Base color\n vec4 baseColor = vec4(1., 1., 1., 1.);\n vec3 diffuseColor = vDiffuseColor.rgb;\n\n#ifdef DIFFUSE\n baseColor = texture2D(diffuseSampler, vDiffuseUV);\n\n#ifdef ALPHATEST\n if (baseColor.a < 0.4)\n discard;\n#endif\n\n baseColor.rgb *= vDiffuseInfos.y;\n#endif\n\n // Ambient color\n vec3 baseAmbientColor = vec3(1., 1., 1.);\n\n#ifdef AMBIENT\n baseAmbientColor = texture2D(ambientSampler, vAmbientUV).rgb * vAmbientInfos.y;\n#endif\n\n // Lighting\n vec3 diffuseBase = vec3(0., 0., 0.);\n vec3 specularBase = vec3(0., 0., 0.);\n\n#ifdef LIGHT0\n vec3 lightVectorW;\n if (vLightsType.x == 0.)\n {\n lightVectorW = normalize(vLightData0 - vPositionW);\n }\n else \n {\n lightVectorW = normalize(-vLightData0);\n }\n\n // diffuse\n float ndl = max(0., dot(vNormalW, lightVectorW));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\n float specComp = dot(normalize(vNormalW), angleW);\n specComp = pow(specComp, vSpecularColor.a);\n\n specularBase += ndl * vLightDiffuse0;\n diffuseBase += specComp * vLightSpecular0;\n#endif\n\n // Reflection\n vec3 reflectionColor = vec3(0., 0., 0.);\n\n#ifdef REFLECTION\n if (vMisc.x != 0.0)\n {\n reflectionColor = textureCube(reflectionCubeSampler, vReflectionUVW).rgb * vReflectionInfos.y;\n }\n else\n {\n vec2 coords = vReflectionUVW.xy;\n\n if (vReflectionInfos.x == MAP_PROJECTION)\n {\n coords /= vReflectionUVW.z;\n }\n\n coords.y = 1.0 - coords.y;\n\n reflectionColor = texture2D(reflection2DSampler, coords).rgb * vReflectionInfos.y;\n } \n#endif\n\n // Alpha\n float alpha = vDiffuseColor.a;\n\n#ifdef OPACITY\n vec3 opacityMap = texture2D(opacitySampler, vOpacityUV).rgb * vec3(0.3, 0.59, 0.11);\n alpha *= (opacityMap.x + opacityMap.y + opacityMap.z )* vOpacityInfos.y;\n#endif\n\n // Emissive\n vec3 emissiveColor = vEmissiveColor;\n#ifdef EMISSIVE\n emissiveColor += texture2D(emissiveSampler, vEmissiveUV).rgb * vEmissiveInfos.y;\n#endif\n\n // Specular map\n vec3 specularColor = vSpecularColor.rgb;\n#ifdef SPECULAR\n specularColor = texture2D(specularSampler, vSpecularUV).rgb * vSpecularInfos.y; \n#endif\n\n // Composition\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor + emissiveColor + vAmbientColor, 0.0, 1.0) * baseColor.rgb;\n vec3 finalSpecular = specularBase * specularColor;\n\n gl_FragColor = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\n}", iedefaultVertexShader:"#define MAP_EXPLICIT 0.\n#define MAP_SPHERICAL 1.\n#define MAP_PLANAR 2.\n#define MAP_CUBIC 3.\n#define MAP_PROJECTION 4.\n\n// Attributes\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 worldViewProjection;\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n\n#ifdef REFLECTION\nuniform vec3 vEyePosition;\nuniform mat4 view;\nvarying vec3 vReflectionUVW;\n\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\n#endif\n\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n\n#ifdef SPECULAR\nvarying vec2 vSpecularUV;\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n\n// Output\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif\n\n#ifdef REFLECTION\nvec3 computeReflectionCoords(float mode, vec4 worldPos, vec3 worldNormal)\n{ \n if (mode == MAP_SPHERICAL)\n {\n vec3 coords = vec3(view * vec4(worldNormal, 0.0)); \n\n return vec3(reflectionMatrix * vec4(coords, 1.0));\n }\n else if (mode == MAP_PLANAR)\n {\n vec3 viewDir = worldPos.xyz - vEyePosition;\n vec3 coords = normalize(reflect(viewDir, worldNormal));\n\n return vec3(reflectionMatrix * vec4(coords, 1));\n }\n else if (mode == MAP_CUBIC)\n {\n vec3 viewDir = worldPos.xyz - vEyePosition;\n vec3 coords = reflect(viewDir, worldNormal);\n\n return vec3(reflectionMatrix * vec4(coords, 0)); \n }\n else if (mode == MAP_PROJECTION)\n {\n return vec3(reflectionMatrix * (view * worldPos));\n }\n\n return vec3(0, 0, 0);\n}\n#endif\n\nvoid main(void) {\n gl_Position = worldViewProjection * vec4(position, 1.0); \n\n vec4 worldPos = world * vec4(position, 1.0);\n vPositionW = vec3(worldPos);\n vNormalW = normalize(vec3(world * vec4(normal, 0.0)));\n\n // Texture coordinates\n#ifndef UV1\n vec2 uv = vec2(0., 0.);\n#endif\n#ifndef UV2\n vec2 uv2 = vec2(0., 0.);\n#endif\n\n#ifdef DIFFUSE\n if (vDiffuseInfos.x == 0.)\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef AMBIENT\n if (vAmbientInfos.x == 0.)\n {\n vAmbientUV = vec2(ambientMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vAmbientUV = vec2(ambientMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef OPACITY\n if (vOpacityInfos.x == 0.)\n {\n vOpacityUV = vec2(opacityMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vOpacityUV = vec2(opacityMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef REFLECTION\n vReflectionUVW = computeReflectionCoords(vReflectionInfos.x, vec4(vPositionW, 1.0), vNormalW);\n#endif\n\n#ifdef EMISSIVE\n if (vEmissiveInfos.x == 0.)\n {\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vEmissiveUV = vec2(emissiveMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n#ifdef SPECULAR\n if (vSpecularInfos.x == 0.)\n {\n vSpecularUV = vec2(specularMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vSpecularUV = vec2(specularMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n // Clip plane\n#ifdef CLIPPLANE\n fClipDistance = dot(worldPos, vClipPlane);\n#endif\n}", layerPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\n\nvoid main(void) {\n vec4 baseColor = texture2D(textureSampler, vUV);\n\n gl_FragColor = baseColor;\n}", layerVertexShader:"// Attributes\nattribute vec2 position;\n\n// Uniforms\nuniform mat4 textureMatrix;\n\n// Output\nvarying vec2 vUV;\n\nconst vec2 madd = vec2(0.5, 0.5);\n\nvoid main(void) { \n\n vUV = vec2(textureMatrix * vec4(position * madd + madd, 1.0, 0.0));\n gl_Position = vec4(position, 0.0, 1.0);\n}", particlesPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nvarying vec4 vColor;\nuniform vec4 textureMask;\nuniform sampler2D diffuseSampler;\n\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n\nvoid main(void) {\n#ifdef CLIPPLANE\n if (fClipDistance > 0.0)\n discard;\n#endif\n vec4 baseColor = texture2D(diffuseSampler, vUV);\n\n gl_FragColor = (baseColor * textureMask + (vec4(1., 1., 1., 1.) - textureMask)) * vColor;\n}", particlesVertexShader:"// Attributes\nattribute vec3 position;\nattribute vec4 color;\nattribute vec4 options;\n\n// Uniforms\nuniform mat4 view;\nuniform mat4 projection;\n\n// Output\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nuniform mat4 invView;\nvarying float fClipDistance;\n#endif\n\nvoid main(void) { \n vec3 viewPos = (view * vec4(position, 1.0)).xyz; \n vec3 cornerPos;\n float size = options.y;\n float angle = options.x;\n vec2 offset = options.zw;\n\n cornerPos = vec3(offset.x - 0.5, offset.y - 0.5, 0.) * size;\n\n // Rotate\n vec3 rotatedCorner;\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\n rotatedCorner.z = 0.;\n\n // Position\n viewPos += rotatedCorner;\n gl_Position = projection * vec4(viewPos, 1.0); \n \n vColor = color;\n vUV = offset;\n\n // Clip plane\n#ifdef CLIPPLANE\n vec4 worldPos = invView * vec4(viewPos, 1.0);\n fClipDistance = dot(worldPos, vClipPlane);\n#endif\n}", spritesPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\nuniform bool alphaTest;\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n\n\nvoid main(void) {\n vec4 baseColor = texture2D(diffuseSampler, vUV);\n\n if (alphaTest) \n {\n if (baseColor.a < 0.95)\n discard;\n }\n\n gl_FragColor = baseColor;\n}", spritesVertexShader:"// Attributes\nattribute vec3 position;\nattribute vec4 options;\nattribute vec4 cellInfo;\n\n// Uniforms\nuniform vec2 textureInfos;\nuniform mat4 view;\nuniform mat4 projection;\n\n// Output\nvarying vec2 vUV;\n\nvoid main(void) { \n vec3 viewPos = (view * vec4(position, 1.0)).xyz; \n vec3 cornerPos;\n \n float angle = options.x;\n float size = options.y;\n vec2 offset = options.zw;\n vec2 uvScale = textureInfos.xy;\n\n cornerPos = vec3(offset.x - 0.5, offset.y - 0.5, 0.) * size;\n\n // Rotate\n vec3 rotatedCorner;\n rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);\n rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);\n rotatedCorner.z = 0.;\n\n // Position\n viewPos += rotatedCorner;\n gl_Position = projection * vec4(viewPos, 1.0); \n \n // Texture\n vec2 uvOffset = vec2(abs(offset.x - cellInfo.x), 1.0 - abs(offset.y - cellInfo.y));\n\n vUV = (uvOffset + cellInfo.zw) * uvScale;\n}", };})();var BABYLON=BABYLON||{};(function(){BABYLON.Material=function(name,scene){this.name=name;this.id=name;this._scene=scene;scene.materials.push(this);};BABYLON.Material.prototype.alpha=1.0;BABYLON.Material.prototype.wireframe=false;BABYLON.Material.prototype.backFaceCulling=true;BABYLON.Material.prototype._effect=null;BABYLON.Material.prototype.onDispose=null;BABYLON.Material.prototype.isReady=function(){return true;};BABYLON.Material.prototype.getEffect=function(){return this._effect;};BABYLON.Material.prototype.needAlphaBlending=function(){return(this.alpha<1.0);};BABYLON.Material.prototype.needAlphaTesting=function(){return false;};BABYLON.Material.prototype._preBind=function(){var engine=this._scene.getEngine();engine.enableEffect(this._effect);engine.setState(this.backFaceCulling);};BABYLON.Material.prototype.bind=function(world,mesh){};BABYLON.Material.prototype.unbind=function(){};BABYLON.Material.prototype.dispose=function(){var index=this._scene.materials.indexOf(this);this._scene.materials.splice(index,1);if(this.onDispose){this.onDispose();}};})();var BABYLON=BABYLON||{};(function(){BABYLON.StandardMaterial=function(name,scene){this.name=name;this.id=name;this._scene=scene;scene.materials.push(this);this.diffuseTexture=null;this.ambientTexture=null;this.opacityTexture=null;this.reflectionTexture=null;this.emissiveTexture=null;this.specularTexture=null;this.ambientColor=new BABYLON.Color3(0,0,0);this.diffuseColor=new BABYLON.Color3(1,1,1);this.specularColor=new BABYLON.Color3(1,1,1);this.specularPower=64;this.emissiveColor=new BABYLON.Color3(0,0,0);this._cachedDefines=null;};BABYLON.StandardMaterial.prototype=Object.create(BABYLON.Material.prototype);BABYLON.StandardMaterial.prototype.needAlphaBlending=function(){return(this.alpha<1.0)||(this.opacityTexture!=null);};BABYLON.StandardMaterial.prototype.needAlphaTesting=function(){return this.diffuseTexture!=null&&this.diffuseTexture.hasAlpha;};BABYLON.StandardMaterial.prototype.isReady=function(mesh){var engine=this._scene.getEngine();if(this.diffuseTexture&&!this.diffuseTexture.isReady()){return false;}if(this.ambientTexture&&!this.ambientTexture.isReady()){return false;}if(this.opacityTexture&&!this.opacityTexture.isReady()){return false;}if(this.reflectionTexture&&!this.reflectionTexture.isReady()){return false;}if(this.emissiveTexture&&!this.emissiveTexture.isReady()){return false;}if(this.specularTexture&&!this.specularTexture.isReady()){return false;}var defines=[];if(this.diffuseTexture){defines.push("#define DIFFUSE");}if(this.ambientTexture){defines.push("#define AMBIENT");}if(this.opacityTexture){defines.push("#define OPACITY");}if(this.reflectionTexture){defines.push("#define REFLECTION");}if(this.emissiveTexture){defines.push("#define EMISSIVE");}if(this.specularTexture){defines.push("#define SPECULAR");}if(BABYLON.clipPlane){defines.push("#define CLIPPLANE");}if(engine.getAlphaTesting()){defines.push("#define ALPHATEST");}var lightIndex=0;for(var index=0;index0){results.push(this.diffuseTexture);}if(this.ambientTexture&&this.ambientTexture.animations&&this.ambientTexture.animations.length>0){results.push(this.ambientTexture);}if(this.opacityTexture&&this.opacityTexture.animations&&this.opacityTexture.animations.length>0){results.push(this.opacityTexture);}if(this.reflectionTexture&&this.reflectionTexture.animations&&this.reflectionTexture.animations.length>0){results.push(this.reflectionTexture);}if(this.emissiveTexture&&this.emissiveTexture.animations&&this.emissiveTexture.animations.length>0){results.push(this.emissiveTexture);}if(this.specularTexture&&this.specularTexture.animations&&this.specularTexture.animations.length>0){results.push(this.specularTexture);}return results;};BABYLON.StandardMaterial.prototype.dispose=function(){if(this.diffuseTexture){this.diffuseTexture.dispose();}if(this.ambientTexture){this.ambientTexture.dispose();}if(this.opacityTexture){this.opacityTexture.dispose();}if(this.reflectionTexture){this.reflectionTexture.dispose();}if(this.emissiveTexture){this.emissiveTexture.dispose();}if(this.specularTexture){this.specularTexture.dispose();}var index=this._scene.materials.indexOf(this);this._scene.materials.splice(index,1);if(this.onDispose){this.onDispose();}};})();var BABYLON=BABYLON||{};(function(){BABYLON.MultiMaterial=function(name,scene){this.name=name;this.id=name;this._scene=scene;scene.multiMaterials.push(this);this.subMaterials=[];};BABYLON.MultiMaterial.prototype.getSubMaterial=function(index){if(index<0||index>=this.subMaterials.length){return this._scene.defaultMaterial;}return this.subMaterials[index];};})();var BABYLON=BABYLON||{};(function(){var loadCubeTexture=function(rootUrl,parsedTexture,scene){var texture=new BABYLON.CubeTexture(rootUrl+parsedTexture.name,scene);texture.name=parsedTexture.name;texture.hasAlpha=parsedTexture.hasAlpha;texture.level=parsedTexture.level;texture.coordinatesMode=parsedTexture.coordinatesMode;return texture;};var loadTexture=function(rootUrl,parsedTexture,scene){if(!parsedTexture.name&&!parsedTexture.isRenderTarget){return null;}if(parsedTexture.isCube){return loadCubeTexture(rootUrl,parsedTexture,scene);}var texture;if(parsedTexture.mirrorPlane){texture=new BABYLON.MirrorTexture(parsedTexture.name,parsedTexture.renderTargetSize,scene);texture._waitingRenderList=parsedTexture.renderList;texture.mirrorPlane=BABYLON.Plane.FromArray(parsedTexture.mirrorPlane);}else if(parsedTexture.isRenderTarget){texture=new BABYLON.RenderTargetTexture(parsedTexture.name,parsedTexture.renderTargetSize,scene);texture._waitingRenderList=parsedTexture.renderList;}else{texture=new BABYLON.Texture(rootUrl+parsedTexture.name,scene);}texture.name=parsedTexture.name;texture.hasAlpha=parsedTexture.hasAlpha;texture.level=parsedTexture.level;texture.coordinatesIndex=parsedTexture.coordinatesIndex;texture.coordinatesMode=parsedTexture.coordinatesMode;texture.uOffset=parsedTexture.uOffset;texture.vOffset=parsedTexture.vOffset;texture.uScale=parsedTexture.uScale;texture.vScale=parsedTexture.vScale;texture.uAng=parsedTexture.uAng;texture.vAng=parsedTexture.vAng;texture.wAng=parsedTexture.wAng;texture.wrapU=parsedTexture.wrapU;texture.wrapV=parsedTexture.wrapV;if(parsedTexture.animations){for(var animationIndex=0;animationIndex>0;vertices.push(sprite.cellIndex-offset*rowSize);vertices.push(offset);};BABYLON.SpriteManager=function(name,imgUrl,capacity,cellSize,scene,epsilon){this.name=name;this._capacity=capacity;this.cellSize=cellSize;this._spriteTexture=new BABYLON.Texture(imgUrl,scene,true,false);this._spriteTexture.wrapU=false;this._spriteTexture.wrapV=false;this._epsilon=epsilon===undefined?0.01:epsilon;this._scene=scene;this._scene.spriteManagers.push(this);this._vertexDeclaration=[3,4,4];this._vertexStrideSize=11*4;this._vertexBuffer=scene.getEngine().createDynamicVertexBuffer(capacity*this._vertexStrideSize*4);var indices=[];var index=0;for(var count=0;countthis._delay){this._time=this._time%this._delay;this.cellIndex+=this._direction;if(this.cellIndex==this._toIndex){if(this._loopAnimation){this.cellIndex=this._fromIndex;}else{this._animationStarted=false;}}}}})();var BABYLON=BABYLON||{};(function(){BABYLON.Layer=function(name,imgUrl,scene,isBackground){this.name=name;this.texture=imgUrl?new BABYLON.Texture(imgUrl,scene,true):null;this.isBackground=isBackground===undefined?true:isBackground;this._scene=scene;this._scene.layers.push(this);var vertices=[];vertices.push(1,1);vertices.push(-1,1);vertices.push(-1,-1);vertices.push(1,-1);this._vertexDeclaration=[2];this._vertexStrideSize=2*4;this._vertexBuffer=scene.getEngine().createVertexBuffer(vertices);var indices=[];indices.push(0);indices.push(1);indices.push(2);indices.push(0);indices.push(2);indices.push(3);this._indexBuffer=scene.getEngine().createIndexBuffer(indices);this._effect=this._scene.getEngine().createEffect("layer",["position"],["textureMatrix"],["textureSampler"],"");};BABYLON.Layer.prototype.onDispose=null;BABYLON.Layer.prototype.render=function(){if(!this._effect.isReady()||!this.texture||!this.texture.isReady())return 0;var engine=this._scene.getEngine();engine.enableEffect(this._effect);this._effect.setTexture("textureSampler",this.texture);this._effect.setMatrix("textureMatrix",this.texture._computeTextureMatrix());engine.bindBuffers(this._vertexBuffer,this._indexBuffer,this._vertexDeclaration,this._vertexStrideSize,this._effect);engine.setAlphaMode(BABYLON.Engine.ALPHA_COMBINE);engine.draw(true,0,6);engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);};BABYLON.Layer.prototype.dispose=function(){if(this._vertexBuffer){this._vertexBuffer=null;}if(this._indexBuffer){this._scene.getEngine()._releaseBuffer(this._indexBuffer);this._indexBuffer=null;}if(this.texture){this.texture.dispose();this.texture=null;}var index=this._scene.layers.indexOf(this);this._scene.layers.splice(index,1);if(this.onDispose){this.onDispose();}};})();var BABYLON=BABYLON||{};(function(){BABYLON.Particle=function(){};BABYLON.Particle.prototype.position=null;BABYLON.Particle.prototype.direction=null;BABYLON.Particle.prototype.lifeTime=1.0;BABYLON.Particle.prototype.age=0;BABYLON.Particle.prototype.size=0;BABYLON.Particle.prototype.angle=0;BABYLON.Particle.prototype.angularSpeed=0;BABYLON.Particle.prototype.color=null;BABYLON.Particle.prototype.colorStep=null;})();var BABYLON=BABYLON||{};(function(){var appendParticleVertex=function(particle,vertices,offsetX,offsetY){vertices.push(particle.position.x);vertices.push(particle.position.y);vertices.push(particle.position.z);vertices.push(particle.color.r);vertices.push(particle.color.g);vertices.push(particle.color.b);vertices.push(particle.color.a);vertices.push(particle.angle);vertices.push(particle.size);vertices.push(offsetX);vertices.push(offsetY);};var randomNumber=function(min,max){if(min==max){return(min);}var random=Math.random();return((random*(max-min))+min);};BABYLON.ParticleSystem=function(name,capacity,scene){this.name=name;this.id=name;this._capacity=capacity;this._scene=scene;scene.particleSystems.push(this);this.gravity=BABYLON.Vector3.Zero();this.direction1=new BABYLON.Vector3(0,1.0,0);this.direction2=new BABYLON.Vector3(0,1.0,0);this.minEmitBox=new BABYLON.Vector3(-0.5,-0.5,-0.5);this.maxEmitBox=new BABYLON.Vector3(0.5,0.5,0.5);this.color1=new BABYLON.Color4(1.0,1.0,1.0,1.0);this.color2=new BABYLON.Color4(1.0,1.0,1.0,1.0);this.colorDead=new BABYLON.Color4(0,0,0,1.0);this.deadAlpha=0;this.textureMask=new BABYLON.Color4(1.0,1.0,1.0,1.0);this.particles=[];this._newPartsExcess=0;this._vertexDeclaration=[3,4,4];this._vertexStrideSize=11*4;this._vertexBuffer=scene.getEngine().createDynamicVertexBuffer(capacity*this._vertexStrideSize*4);var indices=[];var index=0;for(var count=0;count0;for(var index=0;index=particle.lifeTime){this.particles.splice(index,1);index--;continue;}else{particle.color=particle.color.add(particle.colorStep.scale(this._scaledUpdateSpeed));if(particle.color.a<0)particle.color.a=0;particle.position=particle.position.add(particle.direction.scale(this._scaledUpdateSpeed));particle.angle+=particle.angularSpeed*this._scaledUpdateSpeed;particle.direction=particle.direction.add(this.gravity.scale(this._scaledUpdateSpeed));}}var worldMatrix;if(this.emitter.position){worldMatrix=this.emitter.getWorldMatrix();}else{worldMatrix=BABYLON.Matrix.Translation(this.emitter.x,this.emitter.y,this.emitter.z);}for(var index=0;index-1){emitCout=this.manualEmitCount;this.manualEmitCount=0;}else{emitCout=this.emitRate;}var newParticles=((emitCout*this._scaledUpdateSpeed)>>0);this._newPartsExcess+=emitCout*this._scaledUpdateSpeed-newParticles;if(this._newPartsExcess>1.0){newParticles+=this._newPartsExcess>>0;this._newPartsExcess-=this._newPartsExcess>>0;}this._alive=false;if(!this._stopped){this._actualFrame+=this._scaledUpdateSpeed;if(this.targetStopDuration&&this._actualFrame>=this.targetStopDuration)this.stop();}else{newParticles=0;}this._update(newParticles);if(this._stopped){if(!this._alive){this._started=false;if(this.disposeOnStop){this._scene._toBeDisposed.push(this);}}}var vertices=[];for(var index=0;index0){return highLimitValue.clone?highLimitValue.clone():highLimitValue;}for(var key=0;key=currentFrame){var startValue=this._keys[key].value;var endValue=this._keys[key+1].value;var gradient=(currentFrame-this._keys[key].frame)/(this._keys[key+1].frame-this._keys[key].frame);switch(this.dataType){case BABYLON.Animation.ANIMATIONTYPE_FLOAT:switch(loopMode){case BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE:case BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT:return startValue+(endValue-startValue)*gradient;case BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE:return offsetValue*repeatCount+(startValue+(endValue-startValue)*gradient);}break;case BABYLON.Animation.ANIMATIONTYPE_QUATERNION:var quaternion=null;switch(loopMode){case BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE:case BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT:quaternion=BABYLON.Quaternion.Slerp(startValue,endValue,gradient);break;case BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE:quaternion=BABYLON.Quaternion.Slerp(startValue,endValue,gradient).add(offsetValue.scale(repeatCount));break;}return quaternion.toEulerAngles();case BABYLON.Animation.ANIMATIONTYPE_VECTOR3:switch(loopMode){case BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE:case BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT:return BABYLON.Vector3.Lerp(startValue,endValue,gradient);case BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE:return BABYLON.Vector3.Lerp(startValue,endValue,gradient).add(offsetValue.scale(repeatCount));}default:break;}break;}}return this._keys[this._keys.length-1].value;};BABYLON.Animation.prototype.animate=function(target,delay,from,to,loop,speedRatio){if(!this.targetPropertyPath||this.targetPropertyPath.length<1){return false;}if(fromthis._keys[this._keys.length-1].frame){from=this._keys[0].frame;}if(tothis._keys[this._keys.length-1].frame){to=this._keys[this._keys.length-1].frame;}var range=to-from;var ratio=delay*(this.framePerSecond*speedRatio)/1000.0;if(ratio>range&&!loop){return false;}var offsetValue=0;var highLimitValue=0;if(this.loopMode!=BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE){var keyOffset=to.toString()+from.toString();if(!this._offsetsCache[keyOffset]){var fromValue=this._interpolate(from,0,BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);var toValue=this._interpolate(to,0,BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case BABYLON.Animation.ANIMATIONTYPE_FLOAT:this._offsetsCache[keyOffset]=toValue-fromValue;break;case BABYLON.Animation.ANIMATIONTYPE_QUATERNION:this._offsetsCache[keyOffset]=toValue.subtract(fromValue);break;case BABYLON.Animation.ANIMATIONTYPE_VECTOR3:this._offsetsCache[keyOffset]=toValue.subtract(fromValue);default:break;}this._highLimitsCache[keyOffset]=toValue;}highLimitValue=this._highLimitsCache[keyOffset];offsetValue=this._offsetsCache[keyOffset];}var repeatCount=(ratio/range)>>0;var currentFrame=from+ratio%range;var currentValue=this._interpolate(currentFrame,repeatCount,this.loopMode,offsetValue,highLimitValue);if(this.targetPropertyPath.length>1){var property=target[this.targetPropertyPath[0]];for(var index=1;index