diff --git a/index.html b/index.html
index 291a917..9ae1d49 100644
--- a/index.html
+++ b/index.html
@@ -21,7 +21,7 @@
-
+
diff --git a/scripts/babylon.1.6.js b/scripts/babylon.1.6.js
deleted file mode 100644
index 1f6fd4e..0000000
--- a/scripts/babylon.1.6.js
+++ /dev/null
@@ -1,20 +0,0 @@
-var BABYLON=BABYLON||{};(function(){BABYLON.Ray=function(origin,direction){this.origin=origin;this.direction=direction;};BABYLON.Ray.prototype.intersectsBox=function(box){var d=0.0;var maxValue=Number.MAX_VALUE;if(Math.abs(this.direction.x)<0.0000001){if(this.origin.xbox.maximum.x){return false;}}else{var inv=1.0/this.direction.x;var min=(box.minimum.x-this.origin.x)*inv;var max=(box.maximum.x-this.origin.x)*inv;if(min>max){var temp=min;min=max;max=temp;}d=Math.max(min,d);maxValue=Math.min(max,maxValue);if(d>maxValue){return false;}}if(Math.abs(this.direction.y)<0.0000001){if(this.origin.ybox.maximum.y){return false;}}else{var inv=1.0/this.direction.y;var min=(box.minimum.y-this.origin.y)*inv;var max=(box.maximum.y-this.origin.y)*inv;if(min>max){var temp=min;min=max;max=temp;}d=Math.max(min,d);maxValue=Math.min(max,maxValue);if(d>maxValue){return false;}}if(Math.abs(this.direction.z)<0.0000001){if(this.origin.zbox.maximum.z){return false;}}else{var inv=1.0/this.direction.z;var min=(box.minimum.z-this.origin.z)*inv;var max=(box.maximum.z-this.origin.z)*inv;if(min>max){var temp=min;min=max;max=temp;}d=Math.max(min,d);maxValue=Math.min(max,maxValue);if(d>maxValue){return false;}}return true;};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.multiplyToRef=function(otherColor,result){result.r=this.r*otherColor.r;result.g=this.g*otherColor.g;result.b=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.scaleToRef=function(scale,result){result.r=this.r*scale;result.g=this.g*scale;result.b=this.b*scale;};BABYLON.Color3.prototype.clone=function(){return new BABYLON.Color3(this.r,this.g,this.b);};BABYLON.Color3.prototype.copyFrom=function(source){this.r=source.r;this.g=source.g;this.b=source.b;};BABYLON.Color3.prototype.copyFromFloats=function(r,g,b){this.r=r;this.g=g;this.b=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.addInPlace=function(right){this.r+=right.r;this.g+=right.g;this.b+=right.b;this.a+=right.a;};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.subtractToRef=function(right,result){result.r=this.r-right.r;result.g=this.g-right.g;result.b=this.b-right.b;result.a=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.scaleToRef=function(scale,result){result.r=this.r*scale;result.g=this.g*scale;result.b=this.b*scale;result.a=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 result=new BABYLON.Color4(0,0,0,0);BABYLON.Color4.LerpToRef(left,right,amount,result);return result;};BABYLON.Color4.LerpToRef=function(left,right,amount,result){result.r=left.r+(right.r-left.r)*amount;result.g=left.g+(right.g-left.g)*amount;result.b=left.b+(right.b-left.b)*amount;result.a=left.a+(right.a-left.a)*amount;};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.scaleInPlace=function(scale){this.x*=scale;this.y*=scale;};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.toArray=function(array,index){array[index]=this.x;array[index+1]=this.y;array[index+2]=this.z;};BABYLON.Vector3.prototype.addInPlace=function(otherVector){this.x+=otherVector.x;this.y+=otherVector.y;this.z+=otherVector.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.addToRef=function(otherVector,result){result.x=this.x+otherVector.x;result.y=this.y+otherVector.y;result.z=this.z+otherVector.z;};BABYLON.Vector3.prototype.subtractInPlace=function(otherVector){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.subtractToRef=function(otherVector,result){result.x=this.x-otherVector.x;result.y=this.y-otherVector.y;result.z=this.z-otherVector.z;};BABYLON.Vector3.prototype.subtractFromFloats=function(x,y,z){return new BABYLON.Vector3(this.x-x,this.y-y,this.z-z);};BABYLON.Vector3.prototype.subtractFromFloatsToRef=function(x,y,z,result){result.x=this.x-x;result.y=this.y-y;result.z=this.z-z;};BABYLON.Vector3.prototype.negate=function(){return new BABYLON.Vector3(-this.x,-this.y,-this.z);};BABYLON.Vector3.prototype.scaleInPlace=function(scale){this.x*=scale;this.y*=scale;this.z*=scale;};BABYLON.Vector3.prototype.scale=function(scale){return new BABYLON.Vector3(this.x*scale,this.y*scale,this.z*scale);};BABYLON.Vector3.prototype.scaleToRef=function(scale,result){result.x=this.x*scale;result.y=this.y*scale;result.z=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.equalsToFloats=function(x,y,z){return this.x===x&&this.y===y&&this.z===z;};BABYLON.Vector3.prototype.multiplyInPlace=function(otherVector){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.multiplyToRef=function(otherVector,result){result.x=this.x*otherVector.x;result.y=this.y*otherVector.y;result.z=this.z*otherVector.z;};BABYLON.Vector3.prototype.multiplyByFloats=function(x,y,z){return new BABYLON.Vector3(this.x*x,this.y*y,this.z*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.divideToRef=function(otherVector,result){result.x=this.x/otherVector.x;result.y=this.y/otherVector.y;result.z=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.prototype.copyFrom=function(source){this.x=source.x;this.y=source.y;this.z=source.z;};BABYLON.Vector3.prototype.copyFromFloats=function(x,y,z){this.x=x;this.y=y;this.z=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.FromArrayToRef=function(array,offset,result){if(!offset){offset=0;}result.x=array[offset];result.y=array[offset+1];result.z=array[offset+2];};BABYLON.Vector3.FromFloatsToRef=function(x,y,z,result){result.x=x;result.y=y;result.z=z;};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 result=BABYLON.Vector3.Zero();BABYLON.Vector3.TransformCoordinatesToRef(vector,transformation,result);return result;};BABYLON.Vector3.TransformCoordinatesToRef=function(vector,transformation,result){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];result.x=x/w;result.y=y/w;result.z=z/w;};BABYLON.Vector3.TransformCoordinatesFromFloatsToRef=function(x,y,z,transformation,result){var rx=(x*transformation.m[0])+(y*transformation.m[4])+(z*transformation.m[8])+transformation.m[12];var ry=(x*transformation.m[1])+(y*transformation.m[5])+(z*transformation.m[9])+transformation.m[13];var rz=(x*transformation.m[2])+(y*transformation.m[6])+(z*transformation.m[10])+transformation.m[14];var rw=(x*transformation.m[3])+(y*transformation.m[7])+(z*transformation.m[11])+transformation.m[15];result.x=rx/rw;result.y=ry/rw;result.z=rz/rw;};BABYLON.Vector3.TransformNormal=function(vector,transformation){var result=BABYLON.Vector3.Zero();BABYLON.Vector3.TransformNormalToRef(vector,transformation,result);return result;};BABYLON.Vector3.TransformNormalToRef=function(vector,transformation,result){result.x=(vector.x*transformation.m[0])+(vector.y*transformation.m[4])+(vector.z*transformation.m[8]);result.y=(vector.x*transformation.m[1])+(vector.y*transformation.m[5])+(vector.z*transformation.m[9]);result.z=(vector.x*transformation.m[2])+(vector.y*transformation.m[6])+(vector.z*transformation.m[10]);};BABYLON.Vector3.TransformNormalFromFloatsToRef=function(x,y,z,transformation,result){result.x=(x*transformation.m[0])+(y*transformation.m[4])+(z*transformation.m[8]);result.y=(x*transformation.m[1])+(y*transformation.m[5])+(z*transformation.m[9]);result.z=(x*transformation.m[2])+(y*transformation.m[6])+(z*transformation.m[10]);};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.equals=function(otherQuaternion){return this.x===otherQuaternion.x&&this.y===otherQuaternion.y&&this.z===otherQuaternion.z&&this.w===otherQuaternion.w;};BABYLON.Quaternion.prototype.clone=function(){return new BABYLON.Quaternion(this.x,this.y,this.z,this.w);};BABYLON.Quaternion.prototype.copyFrom=function(other){this.x=other.x;this.y=other.y;this.z=other.z;this.w=other.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.multiply=function(q1){var result=new BABYLON.Quaternion(0,0,0,1.0);this.multiplyToRef(q1,result);return result;};BABYLON.Quaternion.prototype.multiplyToRef=function(q1,result){result.x=this.x*q1.w+this.y*q1.z-this.z*q1.y+this.w*q1.x;result.y=-this.x*q1.z+this.y*q1.w+this.z*q1.x+this.w*q1.y;result.z=this.x*q1.y-this.y*q1.x+this.z*q1.w+this.w*q1.z;result.w=-this.x*q1.x-this.y*q1.y-this.z*q1.z+this.w*q1.w;};BABYLON.Quaternion.prototype.length=function(){return Math.sqrt((this.x*this.x)+(this.y*this.y)+(this.z*this.z)+(this.w*this.w));};BABYLON.Quaternion.prototype.normalize=function(){var length=1.0/this.length();this.x*=length;this.y*=length;this.z*=length;this.w*=length;};BABYLON.Quaternion.prototype.toEulerAngles=function(){var qx=this.x;var qy=this.y;var qz=this.z;var qw=this.w;var sqx=qx*qx;var sqy=qy*qy;var sqz=qz*qz;var yaw=Math.atan2(2.0*(qy*qw-qx*qz),1.0-2.0*(sqy+sqz));var pitch=Math.asin(2.0*(qx*qy+qz*qw));var roll=Math.atan2(2.0*(qx*qw-qy*qz),1.0-2.0*(sqx+sqz));var gimbaLockTest=qx*qy+qz*qw;if(gimbaLockTest>0.499){yaw=2.0*Math.atan2(qx,qw);roll=0;}else if(gimbaLockTest<-0.499){yaw=-2.0*Math.atan2(qx,qw);roll=0;}return new BABYLON.Vector3(pitch,yaw,roll);};BABYLON.Quaternion.prototype.toRotationMatrix=function(result){var xx=this.x*this.x;var yy=this.y*this.y;var zz=this.z*this.z;var xy=this.x*this.y;var zw=this.z*this.w;var zx=this.z*this.x;var yw=this.y*this.w;var yz=this.y*this.z;var xw=this.x*this.w;result.m[0]=1.0-(2.0*(yy+zz));result.m[1]=2.0*(xy+zw);result.m[2]=2.0*(zx-yw);result.m[3]=0;result.m[4]=2.0*(xy-zw);result.m[5]=1.0-(2.0*(zz+xx));result.m[6]=2.0*(yz+xw);result.m[7]=0;result.m[8]=2.0*(zx+yw);result.m[9]=2.0*(yz-xw);result.m[10]=1.0-(2.0*(yy+xx));result.m[11]=0;result.m[12]=0;result.m[13]=0;result.m[14]=0;result.m[15]=1.0;};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.RotationYawPitchRoll=function(yaw,pitch,roll){var result=new BABYLON.Quaternion();BABYLON.Quaternion.RotationYawPitchRollToRef(yaw,pitch,roll,result);return result;};BABYLON.Quaternion.RotationYawPitchRollToRef=function(yaw,pitch,roll,result){var halfRoll=roll*0.5;var halfPitch=pitch*0.5;var halfYaw=yaw*0.5;var sinRoll=Math.sin(halfRoll);var cosRoll=Math.cos(halfRoll);var sinPitch=Math.sin(halfPitch);var cosPitch=Math.cos(halfPitch);var sinYaw=Math.sin(halfYaw);var cosYaw=Math.cos(halfYaw);result.x=(cosYaw*sinPitch*cosRoll)+(sinYaw*cosPitch*sinRoll);result.y=(sinYaw*cosPitch*cosRoll)-(cosYaw*sinPitch*sinRoll);result.z=(cosYaw*cosPitch*sinRoll)-(sinYaw*sinPitch*cosRoll);result.w=(cosYaw*cosPitch*cosRoll)+(sinYaw*sinPitch*sinRoll);};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));};if(!BABYLON.MatrixType){BABYLON.MatrixType=(typeof Float32Array!=='undefined')?Float32Array:Array;}BABYLON.Matrix=function(){this.m=new BABYLON.MatrixType(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(){this.invertToRef(this);};BABYLON.Matrix.prototype.invertToRef=function(other){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);other.m[0]=l23*l27;other.m[4]=l24*l27;other.m[8]=l25*l27;other.m[12]=l26*l27;other.m[1]=-(((l2*l17)-(l3*l18))+(l4*l19))*l27;other.m[5]=(((l1*l17)-(l3*l20))+(l4*l21))*l27;other.m[9]=-(((l1*l18)-(l2*l20))+(l4*l22))*l27;other.m[13]=(((l1*l19)-(l2*l21))+(l3*l22))*l27;other.m[2]=(((l2*l28)-(l3*l29))+(l4*l30))*l27;other.m[6]=-(((l1*l28)-(l3*l31))+(l4*l32))*l27;other.m[10]=(((l1*l29)-(l2*l31))+(l4*l33))*l27;other.m[14]=-(((l1*l30)-(l2*l32))+(l3*l33))*l27;other.m[3]=-(((l2*l34)-(l3*l35))+(l4*l36))*l27;other.m[7]=(((l1*l34)-(l3*l37))+(l4*l38))*l27;other.m[11]=-(((l1*l35)-(l2*l37))+(l4*l39))*l27;other.m[15]=(((l1*l36)-(l2*l38))+(l3*l39))*l27;};BABYLON.Matrix.prototype.setTranslation=function(vector3){this.m[12]=vector3.x;this.m[13]=vector3.y;this.m[14]=vector3.z;};BABYLON.Matrix.prototype.multiply=function(other){var result=new BABYLON.Matrix();this.multiplyToRef(other,result);return result;};BABYLON.Matrix.prototype.copyFrom=function(other){for(var index=0;index<16;index++){this.m[index]=other.m[index];}};BABYLON.Matrix.prototype.multiplyToRef=function(other,result){this.multiplyToArray(other,result.m,0);};BABYLON.Matrix.prototype.multiplyToArray=function(other,result,offset){result[offset]=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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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[offset+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];};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.FromArray=function(array,offset){var result=new BABYLON.Matrix();BABYLON.Matrix.FromArrayToRef(array,offset,result);return result;};BABYLON.Matrix.FromArrayToRef=function(array,offset,result){if(!offset){offset=0;}for(var index=0;index<16;index++){result.m[index]=array[index+offset];}};BABYLON.Matrix.FromValuesToRef=function(initialM11,initialM12,initialM13,initialM14,initialM21,initialM22,initialM23,initialM24,initialM31,initialM32,initialM33,initialM34,initialM41,initialM42,initialM43,initialM44,result){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;};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.IdentityToRef=function(result){BABYLON.Matrix.FromValuesToRef(1.0,0,0,0,0,1.0,0,0,0,0,1.0,0,0,0,0,1.0,result);};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=new BABYLON.Matrix();BABYLON.Matrix.RotationXToRef(angle,result);return result;};BABYLON.Matrix.RotationXToRef=function(angle,result){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;result.m[1]=0;result.m[2]=0;result.m[3]=0;result.m[4]=0;result.m[7]=0;result.m[8]=0;result.m[11]=0;result.m[12]=0;result.m[13]=0;result.m[14]=0;};BABYLON.Matrix.RotationY=function(angle){var result=new BABYLON.Matrix();BABYLON.Matrix.RotationYToRef(angle,result);return result;};BABYLON.Matrix.RotationYToRef=function(angle,result){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;result.m[1]=0;result.m[3]=0;result.m[4]=0;result.m[6]=0;result.m[7]=0;result.m[9]=0;result.m[11]=0;result.m[12]=0;result.m[13]=0;result.m[14]=0;};BABYLON.Matrix.RotationZ=function(angle){var result=new BABYLON.Matrix();BABYLON.Matrix.RotationZToRef(angle,result);return result;};BABYLON.Matrix.RotationZToRef=function(angle,result){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;result.m[2]=0;result.m[3]=0;result.m[6]=0;result.m[7]=0;result.m[8]=0;result.m[9]=0;result.m[11]=0;result.m[12]=0;result.m[13]=0;result.m[14]=0;};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){var result=new BABYLON.Matrix();BABYLON.Matrix.RotationYawPitchRollToRef(yaw,pitch,roll,result);return result;};var tempQuaternion=new BABYLON.Quaternion();BABYLON.Matrix.RotationYawPitchRollToRef=function(yaw,pitch,roll,result){BABYLON.Quaternion.RotationYawPitchRollToRef(yaw,pitch,roll,tempQuaternion);tempQuaternion.toRotationMatrix(result);};BABYLON.Matrix.Scaling=function(x,y,z){var result=BABYLON.Matrix.Zero();BABYLON.Matrix.ScalingToRef(x,y,z,result);return result;};BABYLON.Matrix.ScalingToRef=function(x,y,z,result){result.m[0]=x;result.m[1]=0;result.m[2]=0;result.m[3]=0;result.m[4]=0;result.m[5]=y;result.m[6]=0;result.m[7]=0;result.m[8]=0;result.m[9]=0;result.m[10]=z;result.m[11]=0;result.m[12]=0;result.m[13]=0;result.m[14]=0;result.m[15]=1.0;};BABYLON.Matrix.Translation=function(x,y,z){var result=BABYLON.Matrix.Identity();BABYLON.Matrix.TranslationToRef(x,y,z,result);return result;};BABYLON.Matrix.TranslationToRef=function(x,y,z,result){BABYLON.Matrix.FromValuesToRef(1.0,0,0,0,0,1.0,0,0,0,0,1.0,0,x,y,z,1.0,result);};BABYLON.Matrix.LookAtLH=function(eye,target,up){var result=BABYLON.Matrix.Zero();BABYLON.Matrix.LookAtLHToRef(eye,target,up,result);return result;};var xAxis=BABYLON.Vector3.Zero();var yAxis=BABYLON.Vector3.Zero();var zAxis=BABYLON.Vector3.Zero();BABYLON.Matrix.LookAtLHToRef=function(eye,target,up,result){target.subtractToRef(eye,zAxis);zAxis.normalize();BABYLON.Vector3.CrossToRef(up,zAxis,xAxis);xAxis.normalize();BABYLON.Vector3.CrossToRef(zAxis,xAxis,yAxis);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.FromValuesToRef(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,result);};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();BABYLON.Matrix.OrthoOffCenterLHToRef(left,right,bottom,top,znear,zfar,matrix);return matrix;};BABYLON.Matrix.OrthoOffCenterLHToRef=function(left,right,bottom,top,znear,zfar,result){result.m[0]=2.0/(right-left);result.m[1]=result.m[2]=result.m[3]=0;result.m[5]=2.0/(top-bottom);result.m[4]=result.m[6]=result.m[7]=0;result.m[10]=-1.0/(znear-zfar);result.m[8]=result.m[9]=result.m[11]=0;result.m[12]=(left+right)/(left-right);result.m[13]=(top+bottom)/(bottom-top);result.m[14]=znear/(znear-zfar);result.m[15]=1.0;};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();BABYLON.Matrix.PerspectiveFovLHToRef(fov,aspect,znear,zfar,matrix);return matrix;};BABYLON.Matrix.PerspectiveFovLHToRef=function(fov,aspect,znear,zfar,result){var tan=1.0/(Math.tan(fov*0.5));result.m[0]=tan/aspect;result.m[1]=result.m[2]=result.m[3]=0.0;result.m[5]=tan;result.m[4]=result.m[6]=result.m[7]=0.0;result.m[8]=result.m[9]=0.0;result.m[10]=-zfar/(znear-zfar);result.m[11]=1.0;result.m[12]=result.m[13]=result.m[15]=0.0;result.m[14]=(znear*zfar)/(znear-zfar);};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();BABYLON.Matrix.ReflectionToRef(plane,matrix);return matrix;};BABYLON.Matrix.ReflectionToRef=function(plane,result){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;result.m[0]=(temp*x)+1;result.m[1]=temp2*x;result.m[2]=temp3*x;result.m[3]=0.0;result.m[4]=temp*y;result.m[5]=(temp2*y)+1;result.m[6]=temp3*y;result.m[7]=0.0;result.m[8]=temp*z;result.m[9]=temp2*z;result.m[10]=(temp3*z)+1;result.m[11]=0.0;result.m[12]=temp*plane.d;result.m[13]=temp2*plane.d;result.m[14]=temp3*plane.d;result.m[15]=1.0;};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.prototype.copyFromPoints=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;this.normal.x=yz*invPyth;this.normal.y=xz*invPyth;this.normal.z=xy*invPyth;this.d=-((this.normal.x*point1.x)+(this.normal.y*point1.y)+(this.normal.z*point1.z));};BABYLON.Plane.prototype.isFrontFacingTo=function(direction,epsilon){var dot=BABYLON.Vector3.Dot(this.normal,direction);return(dot<=epsilon);};BABYLON.Plane.prototype.signedDistanceTo=function(point){return BABYLON.Vector3.Dot(point,this.normal)+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 result=new BABYLON.Plane(0,0,0,0);result.copyFromPoints(point1,point2,point3);return result;};BABYLON.Plane.FromPositionAndNormal=function(origin,normal){var result=new BABYLON.Plane(0,0,0,0);normal.normalize();result.normal=normal;result.d=-(normal.x*origin.x+normal.y*origin.y+normal.z*origin.z);return result;};BABYLON.Plane.SignedDistanceToPlaneFromPositionAndNormal=function(origin,normal,point){var d=-(normal.x*origin.x+normal.y*origin.y+normal.z*origin.z);return BABYLON.Vector3.Dot(point,normal)+d;};BABYLON.Frustum={};BABYLON.Frustum.GetPlanes=function(transform){var frustumPlanes=[];for(var index=0;index<6;index++){frustumPlanes.push(new BABYLON.Plane(0,0,0,0));}BABYLON.Frustum.GetPlanesToRef(transform,frustumPlanes);return frustumPlanes;};BABYLON.Frustum.GetPlanesToRef=function(transform,frustumPlanes){frustumPlanes[0].normal.x=transform.m[3]+transform.m[2];frustumPlanes[0].normal.y=transform.m[7]+transform.m[6];frustumPlanes[0].normal.z=transform.m[10]+transform.m[10];frustumPlanes[0].d=transform.m[15]+transform.m[14];frustumPlanes[0].normalize();frustumPlanes[1].normal.x=transform.m[3]-transform.m[2];frustumPlanes[1].normal.y=transform.m[7]-transform.m[6];frustumPlanes[1].normal.z=transform.m[11]-transform.m[10];frustumPlanes[1].d=transform.m[15]-transform.m[14];frustumPlanes[1].normalize();frustumPlanes[2].normal.x=transform.m[3]+transform.m[0];frustumPlanes[2].normal.y=transform.m[7]+transform.m[4];frustumPlanes[2].normal.z=transform.m[11]+transform.m[8];frustumPlanes[2].d=transform.m[15]+transform.m[12];frustumPlanes[2].normalize();frustumPlanes[3].normal.x=transform.m[3]-transform.m[0];frustumPlanes[3].normal.y=transform.m[7]-transform.m[4];frustumPlanes[3].normal.z=transform.m[11]-transform.m[8];frustumPlanes[3].d=transform.m[15]-transform.m[12];frustumPlanes[3].normalize();frustumPlanes[4].normal.x=transform.m[3]-transform.m[1];frustumPlanes[4].normal.y=transform.m[7]-transform.m[5];frustumPlanes[4].normal.z=transform.m[11]-transform.m[9];frustumPlanes[4].d=transform.m[15]-transform.m[13];frustumPlanes[4].normalize();frustumPlanes[5].normal.x=transform.m[3]+transform.m[1];frustumPlanes[5].normal.y=transform.m[7]+transform.m[5];frustumPlanes[5].normal.z=transform.m[11]+transform.m[9];frustumPlanes[5].d=transform.m[15]+transform.m[13];frustumPlanes[5].normalize();};})();var BABYLON=BABYLON||{};(function(){BABYLON.Tools={};BABYLON.Tools.ExtractMinAndMax=function(positions,start,count){var minimum=new BABYLON.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE);var maximum=new BABYLON.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var index=start;indexthis.data.length){this.data.length*=2;}};BABYLON.Tools.SmartArray.prototype.pushNoDuplicate=function(value){if(this.indexOf(value)>-1){return;}this.push(value);};BABYLON.Tools.SmartArray.prototype.reset=function(){this.length=0;};BABYLON.Tools.SmartArray.prototype.concat=function(array){if(array.length===0){return;}if(this.length+array.length>this.data.length){this.data.length=(this.length+array.length)*2;}for(var index=0;indexthis.data.length){this.data.length=(this.length+array.length)*2;}for(var index=0;index=this.length){this.data[this.length++]=item;}}};BABYLON.Tools.SmartArray.prototype.indexOf=function(value){var position=this.data.indexOf(value);if(position>=this.length){return-1;}return position;};BABYLON.Tools.GetPointerPrefix=function(){var eventPrefix="pointer";if(!navigator.pointerEnabled){eventPrefix="mouse";}return eventPrefix;};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.LoadImage=function(url,onload,onerror,database){var img=new Image();img.onload=function(){onload(img);};img.onerror=function(err){onerror(img,err);};var noIndexedDB=function(){img.src=url;};var loadFromIndexedDB=function(){database.loadImageFromDB(url,img);};if(database&&database.enableTexturesOffline&&BABYLON.Database.isUASupportingBlobStorage){database.openAsync(loadFromIndexedDB,noIndexedDB);}else{noIndexedDB();}return img;};BABYLON.Tools.LoadFile=function(url,callback,progressCallBack,database){var noIndexedDB=function(){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);};var loadFromIndexedDB=function(){database.loadSceneFromDB(url,callback,progressCallBack,noIndexedDB);};if(database&&url.indexOf(".babylon")!==-1&&(database.enableSceneOffline)){database.openAsync(loadFromIndexedDB,noIndexedDB);}else{noIndexedDB();}};BABYLON.Tools.isIE=function(){return window.ActiveXObject!==undefined;};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._cachedIndexBuffer!==indexBuffer){this._cachedIndexBuffer=indexBuffer;this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,indexBuffer);}};BABYLON.Engine.prototype.bindMultiBuffers=function(vertexBuffers,indexBuffer,effect){if(this._cachedVertexBuffers!==vertexBuffers||this._cachedEffectForVertexBuffers!==effect){this._cachedVertexBuffers=vertexBuffers;this._cachedEffectForVertexBuffers=effect;var attributes=effect.getAttributesNames();for(var index=0;index=0){var vertexBuffer=vertexBuffers[attributes[index]];var stride=vertexBuffer.getStrideSize();this._gl.bindBuffer(this._gl.ARRAY_BUFFER,vertexBuffer._buffer);this._gl.vertexAttribPointer(order,stride,this._gl.FLOAT,false,stride*4,0);}}}if(this._cachedIndexBuffer!==indexBuffer){this._cachedIndexBuffer=indexBuffer;this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER,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,optionalDefines){var vertex=baseName.vertex||baseName;var fragment=baseName.fragment||baseName;var name=vertex+"+"+fragment+"@"+defines;if(this._compiledEffects[name]){return this._compiledEffects[name];}var effect=new BABYLON.Effect(baseName,attributesNames,uniformsNames,samplers,this,defines,optionalDefines);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);var error=this._gl.getProgramInfoLog(shaderProgram);if(error){throw new Error(error);}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.setMatrices=function(uniform,matrices){if(!uniform)return;this._gl.uniformMatrix4fv(uniform,false,matrices);};BABYLON.Engine.prototype.setMatrix=function(uniform,matrix){if(!uniform)return;this._gl.uniformMatrix4fv(uniform,false,matrix.toArray());};BABYLON.Engine.prototype.setFloat=function(uniform,value){if(!uniform)return;this._gl.uniform1f(uniform,value);};BABYLON.Engine.prototype.setFloat2=function(uniform,x,y){if(!uniform)return;this._gl.uniform2f(uniform,x,y);};BABYLON.Engine.prototype.setFloat3=function(uniform,x,y,z){if(!uniform)return;this._gl.uniform3f(uniform,x,y,z);};BABYLON.Engine.prototype.setBool=function(uniform,bool){if(!uniform)return;this._gl.uniform1i(uniform,bool);};BABYLON.Engine.prototype.setFloat4=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._cachedVertexBuffers=null;this._cachedVertexBuffers=null;this._cachedEffectForVertexBuffers=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 onload=function(img){var potWidth=getExponantOfTwo(img.width,that._caps.maxTextureSize);var potHeight=getExponantOfTwo(img.height,that._caps.maxTextureSize);var isPot=(img.width==potWidth&&img.height==potHeight);if(!isPot){that._workingCanvas.width=potWidth;that._workingCanvas.height=potHeight;that._workingContext.drawImage(img,0,0,img.width,img.height,0,0,potWidth,potHeight);};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,isPot?img: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=potWidth;texture._height=potHeight;texture.isReady=true;scene._removePendingData(texture);};var onerror=function(){scene._removePendingData(texture);};scene._addPendingData(texture);BABYLON.Tools.LoadImage(url,onload,onerror,scene.database);texture.url=url;texture.noMipmap=noMipmap;texture.references=1;this._loadedTexturesCache.push(texture);return texture;};BABYLON.Engine.prototype.createDynamicTexture=function(size,generateMipMaps){var texture=this._gl.createTexture();var width=getExponantOfTwo(size,this._caps.maxTextureSize);var height=width;this._gl.bindTexture(this._gl.TEXTURE_2D,texture);this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,this._gl.LINEAR);if(!generateMipMaps){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.generateMipMaps=generateMipMaps;texture.references=1;this._loadedTexturesCache.push(texture);return texture;};BABYLON.Engine.prototype.updateDynamicTexture=function(texture,canvas,invertY){this._gl.bindTexture(this._gl.TEXTURE_2D,texture);this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,invertY);this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,canvas);if(texture.generateMipMaps){this._gl.generateMipmap(this._gl.TEXTURE_2D);}this._gl.bindTexture(this._gl.TEXTURE_2D,null);this._activeTexturesCache=[];texture.isReady=true;};BABYLON.Engine.prototype.updateVideoTexture=function(texture,video){this._gl.bindTexture(this._gl.TEXTURE_2D,texture);this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,false);if(video.videoWidth!==texture._width||video.videoHeight!==texture._height){if(!texture._workingCanvas){texture._workingCanvas=document.createElement("canvas");texture._workingContext=texture._workingCanvas.getContext("2d");texture._workingCanvas.width=texture._width;texture._workingCanvas.height=texture._height;}texture._workingContext.drawImage(video,0,0,video.videoWidth,video.videoHeight,0,0,texture._width,texture._height);this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,texture._workingCanvas);}else{this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,video);}if(texture.generateMipMaps){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,options){var generateMipMaps=false;var generateDepthBuffer=true;var samplingMode=BABYLON.Texture.TRILINEAR_SAMPLINGMODE;if(options!==undefined){generateMipMaps=options.generateMipMaps===undefined?options:options.generateMipmaps;generateDepthBuffer=options.generateDepthBuffer===undefined?true:options.generateDepthBuffer;if(options.samplingMode!==undefined){samplingMode=options.samplingMode;}}var gl=this._gl;var texture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,texture);var width=size.width||size;var height=size.height||size;var magFilter=gl.NEAREST;var minFilter=gl.NEAREST;if(samplingMode===BABYLON.Texture.BILINEAR_SAMPLINGMODE){magFilter=gl.LINEAR;if(generateMipMaps){minFilter=gl.LINEAR_MIPMAP_NEAREST;}else{minFilter=gl.LINEAR;}}else if(samplingMode===BABYLON.Texture.TRILINEAR_SAMPLINGMODE){magFilter=gl.LINEAR;if(generateMipMaps){minFilter=gl.LINEAR_MIPMAP_LINEAR;}else{minFilter=gl.LINEAR;}}gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,magFilter);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,minFilter);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,width,height,0,gl.RGBA,gl.UNSIGNED_BYTE,null);var depthBuffer;if(generateDepthBuffer){depthBuffer=gl.createRenderbuffer();gl.bindRenderbuffer(gl.RENDERBUFFER,depthBuffer);gl.renderbufferStorage(gl.RENDERBUFFER,gl.DEPTH_COMPONENT16,width,height);}var framebuffer=gl.createFramebuffer();gl.bindFramebuffer(gl.FRAMEBUFFER,framebuffer);gl.framebufferTexture2D(gl.FRAMEBUFFER,gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D,texture,0);if(generateDepthBuffer){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;if(generateDepthBuffer){texture._depthBuffer=depthBuffer;}texture._width=width;texture._height=height;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;var onload=function(){loadedImages.push(img);scene._removePendingData(img);if(index!=extensions.length-1){cascadeLoad(rootUrl,index+1,loadedImages,scene,onfinish);}else{onfinish(loadedImages);}};var onerror=function(){scene._removePendingData(img);};img=BABYLON.Tools.LoadImage(rootUrl+extensions[index],onload,onerror,scene.database);scene._addPendingData(img);};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.maximumWorld.addToRef(this.minimumWorld,this.center);this.center.scaleInPlace(0.5);BABYLON.Vector3.FromArrayToRef(world.m,0,this.directions[0]);BABYLON.Vector3.FromArrayToRef(world.m,4,this.directions[1]);BABYLON.Vector3.FromArrayToRef(world.m,8,this.directions[2]);};BABYLON.BoundingBox.prototype.isInFrustrum=function(frustumPlanes){return BABYLON.BoundingBox.IsInFrustrum(this.vectorsWorld,frustumPlanes);};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.prototype.intersectsSphere=function(sphere){var vector=BABYLON.Vector3.Clamp(sphere.centerWorld,this.minimumWorld,this.maximumWorld);var num=BABYLON.Vector3.DistanceSquared(sphere.centerWorld,vector);return(num<=(sphere.radiusWorld*sphere.radiusWorld));};BABYLON.BoundingBox.prototype.intersectsMinMax=function(min,max){if(this.maximumWorld.xmax.x)return false;if(this.maximumWorld.ymax.y)return false;if(this.maximumWorld.zmax.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;};BABYLON.BoundingBox.IsInFrustrum=function(boundingVectors,frustumPlanes){for(var p=0;p<6;p++){var inCount=8;for(var i=0;i<8;i++){if(frustumPlanes[p].dotCoordinate(boundingVectors[i])<0){--inCount;}else{break;}}if(inCount==0)return false;}return true;};})();var BABYLON=BABYLON||{};(function(){BABYLON.BoundingInfo=function(minimum,maximum){this.boundingBox=new BABYLON.BoundingBox(minimum,maximum);this.boundingSphere=new BABYLON.BoundingSphere(minimum,maximum);};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);this.animations=[];};BABYLON.Light.prototype=Object.create(BABYLON.Node.prototype);BABYLON.Light.prototype.intensity=1.0;BABYLON.Light.prototype.getScene=function(){return this._scene;};BABYLON.Light.prototype.getShadowGenerator=function(){return this._shadowGenerator;};BABYLON.Light.prototype.transferToEffect=function(){};BABYLON.Light.prototype.getWorldMatrix=function(){var worldMatrix=this._getWorldMatrix();if(this.parent&&this.parent.getWorldMatrix){if(!this._parentedWorldMatrix){this._parentedWorldMatrix=BABYLON.Matrix.Identity();}worldMatrix.multiplyToRef(this.parent.getWorldMatrix(),this._parentedWorldMatrix);return this._parentedWorldMatrix;}return worldMatrix;};BABYLON.Light.prototype.dispose=function(){if(this._shadowGenerator){this._shadowGenerator.dispose();this._shadowGenerator=null;}var index=this._scene.lights.indexOf(this);this._scene.lights.splice(index,1);};})();var BABYLON=BABYLON||{};(function(){BABYLON.PointLight=function(name,position,scene){BABYLON.Light.call(this,name,scene);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);};BABYLON.PointLight.prototype=Object.create(BABYLON.Light.prototype);BABYLON.Light.prototype.transferToEffect=function(effect,positionUniformName){if(this.parent&&this.parent.getWorldMatrix){if(!this._transformedPosition){this._transformedPosition=BABYLON.Vector3.Zero();}BABYLON.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this._transformedPosition);effect.setFloat4(positionUniformName,this._transformedPosition.x,this._transformedPosition.y,this._transformedPosition.z,0);return;}effect.setFloat4(positionUniformName,this.position.x,this.position.y,this.position.z,0);};BABYLON.PointLight.prototype.getShadowGenerator=function(){return null;};BABYLON.PointLight.prototype._getWorldMatrix=function(){if(!this._worldMatrix){this._worldMatrix=BABYLON.Matrix.Identity();}BABYLON.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix);return this._worldMatrix;};})();var BABYLON=BABYLON||{};(function(){BABYLON.SpotLight=function(name,position,direction,angle,exponent,scene){BABYLON.Light.call(this,name,scene);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);};BABYLON.SpotLight.prototype=Object.create(BABYLON.Light.prototype);BABYLON.SpotLight.prototype.transferToEffect=function(effect,positionUniformName,directionUniformName){var normalizeDirection;if(this.parent&&this.parent.getWorldMatrix){if(!this._transformedDirection){this._transformedDirection=BABYLON.Vector3.Zero();}if(!this._transformedPosition){this._transformedPosition=BABYLON.Vector3.Zero();}var parentWorldMatrix=this.parent.getWorldMatrix();BABYLON.Vector3.TransformCoordinatesToRef(this.position,parentWorldMatrix,this._transformedPosition);BABYLON.Vector3.TransformNormalToRef(this.direction,parentWorldMatrix,this._transformedDirection);effect.setFloat4(positionUniformName,this._transformedPosition.x,this._transformedPosition.y,this._transformedPosition.z,this.exponent);normalizeDirection=BABYLON.Vector3.Normalize(this._transformedDirection);}else{effect.setFloat4(positionUniformName,this.position.x,this.position.y,this.position.z,this.exponent);normalizeDirection=BABYLON.Vector3.Normalize(this.direction);}effect.setFloat4(directionUniformName,normalizeDirection.x,normalizeDirection.y,normalizeDirection.z,Math.cos(this.angle*0.5));};BABYLON.SpotLight.prototype._getWorldMatrix=function(){if(!this._worldMatrix){this._worldMatrix=BABYLON.Matrix.Identity();}BABYLON.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix);return this._worldMatrix;};})();var BABYLON=BABYLON||{};(function(){BABYLON.DirectionalLight=function(name,direction,scene){BABYLON.Light.call(this,name,scene);this.position=direction.scale(-1);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);};BABYLON.DirectionalLight.prototype=Object.create(BABYLON.Light.prototype);BABYLON.DirectionalLight.prototype._computeTransformedPosition=function(){if(this.parent&&this.parent.getWorldMatrix){if(!this._transformedPosition){this._transformedPosition=BABYLON.Vector3.Zero();}BABYLON.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this._transformedPosition);return true;}return false;};BABYLON.DirectionalLight.prototype.transferToEffect=function(effect,directionUniformName){if(this.parent&&this.parent.getWorldMatrix){if(!this._transformedDirection){this._transformedDirection=BABYLON.Vector3.Zero();}BABYLON.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection);effect.setFloat4(directionUniformName,this._transformedDirection.x,this._transformedDirection.y,this._transformedDirection.z,1);return;}effect.setFloat4(directionUniformName,this.direction.x,this.direction.y,this.direction.z,1);};BABYLON.DirectionalLight.prototype._getWorldMatrix=function(){if(!this._worldMatrix){this._worldMatrix=BABYLON.Matrix.Identity();}BABYLON.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix);return this._worldMatrix;};})();var BABYLON=BABYLON||{};(function(){BABYLON.ShadowGenerator=function(mapSize,light){this._light=light;this._scene=light.getScene();light._shadowGenerator=this;this._shadowMap=new BABYLON.RenderTargetTexture(light.name+"_shadowMap",mapSize,this._scene,false);this._shadowMap.wrapU=BABYLON.Texture.CLAMP_ADDRESSMODE;this._shadowMap.wrapV=BABYLON.Texture.CLAMP_ADDRESSMODE;this._shadowMap.renderParticles=false;var that=this;var renderSubMesh=function(subMesh){var mesh=subMesh.getMesh();var world=mesh.getWorldMatrix();var engine=that._scene.getEngine();if(that.isReady(mesh)){engine.enableEffect(that._effect);if(mesh.skeleton&&mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)&&mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)){that._effect.setMatrix("world",world);that._effect.setMatrix("viewProjection",that.getTransformMatrix());that._effect.setMatrices("mBones",mesh.skeleton.getTransformMatrices());}else{world.multiplyToRef(that.getTransformMatrix(),that._worldViewProjection);that._effect.setMatrix("worldViewProjection",that._worldViewProjection);}mesh.bindAndDraw(subMesh,that._effect,false);}};this._shadowMap.customRenderFunction=function(opaqueSubMeshes,alphaTestSubMeshes){var index;for(index=0;index=0;};var intersectBoxAASphere=function(boxMin,boxMax,sphereCenter,sphereRadius){if(boxMin.x>sphereCenter.x+sphereRadius)return false;if(sphereCenter.x-sphereRadius>boxMax.x)return false;if(boxMin.y>sphereCenter.y+sphereRadius)return false;if(sphereCenter.y-sphereRadius>boxMax.y)return false;if(boxMin.z>sphereCenter.z+sphereRadius)return false;if(sphereCenter.z-sphereRadius>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(faceIndex,subMesh,p1,p2,p3){var t0;var embeddedInPlane=false;if(!subMesh._trianglePlanes){subMesh._trianglePlanes=[];}if(!subMesh._trianglePlanes[faceIndex]){subMesh._trianglePlanes[faceIndex]=new BABYLON.Plane(0,0,0,0);subMesh._trianglePlanes[faceIndex].copyFromPoints(p1,p2,p3);}var trianglePlane=subMesh._trianglePlanes[faceIndex];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;}this._collisionPoint.copyFromFloats(0,0,0);var found=false;var t=1.0;if(!embeddedInPlane){this.basePoint.subtractToRef(trianglePlane.normal,this._planeIntersectionPoint);this.velocity.scaleToRef(t0,this._tempVector);this._planeIntersectionPoint.addInPlace(this._tempVector);if(this._checkPointInTriangle(this._planeIntersectionPoint,p1,p2,p3,trianglePlane.normal)){found=true;t=t0;this._collisionPoint.copyFrom(this._planeIntersectionPoint);}}if(!found){var velocitySquaredLength=this.velocity.lengthSquared();var a=velocitySquaredLength;this.basePoint.subtractToRef(p1,this._tempVector);var b=2.0*(BABYLON.Vector3.Dot(this.velocity,this._tempVector));var c=this._tempVector.lengthSquared-1.0;var lowestRoot=getLowestRoot(a,b,c,t);if(lowestRoot.found){t=lowestRoot.root;found=true;this._collisionPoint.copyFrom(p1);}this.basePoint.subtractToRef(p2,this._tempVector);b=2.0*(BABYLON.Vector3.Dot(this.velocity,this._tempVector));c=this._tempVector.lengthSquared-1.0;lowestRoot=getLowestRoot(a,b,c,t);if(lowestRoot.found){t=lowestRoot.root;found=true;this._collisionPoint.copyFrom(p2);}this.basePoint.subtractToRef(p3,this._tempVector);b=2.0*(BABYLON.Vector3.Dot(this.velocity,this._tempVector));c=this._tempVector.lengthSquared-1.0;lowestRoot=getLowestRoot(a,b,c,t);if(lowestRoot.found){t=lowestRoot.root;found=true;this._collisionPoint.copyFrom(p3);}p2.subtractToRef(p1,this._edge);p1.subtractToRef(this.basePoint,this._baseToVertex);var edgeSquaredLength=this._edge.lengthSquared();var edgeDotVelocity=BABYLON.Vector3.Dot(this._edge,this.velocity);var edgeDotBaseToVertex=BABYLON.Vector3.Dot(this._edge,this._baseToVertex);a=edgeSquaredLength*(-velocitySquaredLength)+edgeDotVelocity*edgeDotVelocity;b=edgeSquaredLength*(2.0*BABYLON.Vector3.Dot(this.velocity,this._baseToVertex))-2.0*edgeDotVelocity*edgeDotBaseToVertex;c=edgeSquaredLength*(1.0-this._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;this._edge.scaleInPlace(f);p1.addToRef(this._edge,this._collisionPoint);}}p3.subtractToRef(p2,this._edge);p2.subtractToRef(this.basePoint,this._baseToVertex);edgeSquaredLength=this._edge.lengthSquared();edgeDotVelocity=BABYLON.Vector3.Dot(this._edge,this.velocity);edgeDotBaseToVertex=BABYLON.Vector3.Dot(this._edge,this._baseToVertex);a=edgeSquaredLength*(-velocitySquaredLength)+edgeDotVelocity*edgeDotVelocity;b=edgeSquaredLength*(2.0*BABYLON.Vector3.Dot(this.velocity,this._baseToVertex))-2.0*edgeDotVelocity*edgeDotBaseToVertex;c=edgeSquaredLength*(1.0-this._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;this._edge.scaleInPlace(f);p2.addToRef(this._edge,this._collisionPoint);}}p1.subtractToRef(p3,this._edge);p3.subtractToRef(this.basePoint,this._baseToVertex);edgeSquaredLength=this._edge.lengthSquared();edgeDotVelocity=BABYLON.Vector3.Dot(this._edge,this.velocity);edgeDotBaseToVertex=BABYLON.Vector3.Dot(this._edge,this._baseToVertex);a=edgeSquaredLength*(-velocitySquaredLength)+edgeDotVelocity*edgeDotVelocity;b=edgeSquaredLength*(2.0*BABYLON.Vector3.Dot(this.velocity,this._baseToVertex))-2.0*edgeDotVelocity*edgeDotBaseToVertex;c=edgeSquaredLength*(1.0-this._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;this._edge.scaleInPlace(f);p3.addToRef(this._edge,this._collisionPoint);}}}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),this.upVector));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,noPreventDefault){var previousPosition;var that=this;var engine=this._scene.getEngine();if(this._attachedCanvas){return;}this._attachedCanvas=canvas;if(this._onMouseDown===undefined){this._onMouseDown=function(evt){previousPosition={x:evt.clientX,y:evt.clientY};if(!noPreventDefault){evt.preventDefault();}};this._onMouseUp=function(evt){previousPosition=null;if(!noPreventDefault){evt.preventDefault();}};this._onMouseOut=function(evt){previousPosition=null;that._keys=[];if(!noPreventDefault){evt.preventDefault();}};this._onMouseMove=function(evt){if(!previousPosition&&!engine.isPointerLock){return;}var offsetX;var offsetY;if(!engine.isPointerLock){offsetX=evt.clientX-previousPosition.x;offsetY=evt.clientY-previousPosition.y;}else{offsetX=evt.movementX||evt.mozMovementX||evt.webkitMovementX||evt.msMovementX||0;offsetY=evt.movementY||evt.mozMovementY||evt.webkitMovementY||evt.msMovementY||0;}that.cameraRotation.y+=offsetX/that.angularSensibility;that.cameraRotation.x+=offsetY/that.angularSensibility;previousPosition={x:evt.clientX,y:evt.clientY};if(!noPreventDefault){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);}if(!noPreventDefault){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);}if(!noPreventDefault){evt.preventDefault();}}};this._onLostFocus=function(){that._keys=[];};this._reset=function(){that._keys=[];previousPosition=null;that.cameraDirection=new BABYLON.Vector3(0,0,0);that.cameraRotation=new BABYLON.Vector2(0,0);};}canvas.addEventListener("mousedown",this._onMouseDown,false);canvas.addEventListener("mouseup",this._onMouseUp,false);canvas.addEventListener("mouseout",this._onMouseOut,false);canvas.addEventListener("mousemove",this._onMouseMove,false);window.addEventListener("keydown",this._onKeyDown,false);window.addEventListener("keyup",this._onKeyUp,false);window.addEventListener("blur",this._onLostFocus,false);};BABYLON.FreeCamera.prototype.detachControl=function(canvas){if(this._attachedCanvas!=canvas){return;}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);this._attachedCanvas=null;if(this._reset){this._reset();}};BABYLON.FreeCamera.prototype._collideWithWorld=function(velocity){this.position.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition);this._collider.radius=this.ellipsoid;this._scene._getNewPosition(this._oldPosition,velocity,this._collider,3,this._newPosition);this._newPosition.subtractToRef(this._oldPosition,this._diffPosition);if(this._diffPosition.length()>BABYLON.Engine.collisionsEpsilon){this.position.addInPlace(this._diffPosition);}};BABYLON.FreeCamera.prototype._checkInputs=function(){if(!this._localDirection){this._localDirection=BABYLON.Vector3.Zero();this._transformedDirection=BABYLON.Vector3.Zero();}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=(BABYLON.Vector3.DistanceSquared(oldPosition,this.position)!=0);}}else{this.position.addInPlace(this.cameraDirection);}}if(needToRotate){this.rotation.x+=this.cameraRotation.x;this.rotation.y+=this.cameraRotation.y;if(!this.noRotationConstraint){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.scaleInPlace(this.inertia);}if(needToRotate){this.cameraRotation.scaleInPlace(this.inertia);}};BABYLON.FreeCamera.prototype._getViewMatrix=function(){BABYLON.Vector3.FromFloatsToRef(0,0,1,this._referencePoint);if(!this.lockedTarget){if(this.upVector.x!=0||this.upVector.y!=1.0||this.upVector.z!=0){BABYLON.Matrix.LookAtLHToRef(BABYLON.Vector3.Zero(),this._referencePoint,this.upVector,this._lookAtTemp);BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix);this._lookAtTemp.multiplyToRef(this._cameraRotationMatrix,this._tempMatrix);this._lookAtTemp.invert();this._tempMatrix.multiplyToRef(this._lookAtTemp,this._cameraRotationMatrix);}else{BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this._cameraRotationMatrix);}BABYLON.Vector3.TransformCoordinatesToRef(this._referencePoint,this._cameraRotationMatrix,this._transformedReferencePoint);this.position.addToRef(this._transformedReferencePoint,this._currentTarget);}else{if(this.lockedTarget.position){this._currentTarget.copyFrom(this.lockedTarget.position);}else{this._currentTarget.copyFrom(this.lockedTarget);}}BABYLON.Matrix.LookAtLHToRef(this.position,this._currentTarget,this.upVector,this._viewMatrix);return this._viewMatrix;};})();var BABYLON=BABYLON||{};(function(){BABYLON.TouchCamera=function(name,position,scene){BABYLON.FreeCamera.call(this,name,position,scene);this._offsetX=null;this._offsetY=null;this._pointerCount=0;this._pointerPressed=[];};BABYLON.TouchCamera.prototype=Object.create(BABYLON.FreeCamera.prototype);BABYLON.TouchCamera.prototype.angularSensibility=200000.0;BABYLON.TouchCamera.prototype.moveSensibility=500.0;BABYLON.TouchCamera.prototype.attachControl=function(canvas,noPreventDefault){var previousPosition;var that=this;if(this._attachedCanvas){return;}this._attachedCanvas=canvas;if(this._onPointerDown===undefined){this._onPointerDown=function(evt){if(!noPreventDefault){evt.preventDefault();}that._pointerPressed.push(evt.pointerId);if(that._pointerPressed.length!==1){return;}previousPosition={x:evt.clientX,y:evt.clientY};};this._onPointerUp=function(evt){if(!noPreventDefault){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){if(!noPreventDefault){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);canvas.addEventListener("pointerup",this._onPointerUp);canvas.addEventListener("pointerout",this._onPointerUp);canvas.addEventListener("pointermove",this._onPointerMove);window.addEventListener("blur",this._onLostFocus);};BABYLON.TouchCamera.prototype.detachControl=function(canvas){if(this._attachedCanvas!=canvas){return;}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);this._attachedCanvas=null;};BABYLON.TouchCamera.prototype._checkInputs=function(){if(!this._offsetX){return;}this.cameraRotation.y+=this._offsetX/this.angularSensibility;if(this._pointerPressed.length>1){this.cameraRotation.x+=-this._offsetY/this.angularSensibility;}else{var speed=this._computeLocalCameraSpeed();var direction=new BABYLON.Vector3(0,0,speed*this._offsetY/this.moveSensibility);BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix);this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction,this._cameraRotationMatrix));}};})();var BABYLON=BABYLON||{};(function(){BABYLON.DeviceOrientationCamera=function(name,position,scene){BABYLON.FreeCamera.call(this,name,position,scene);this._offsetX=null;this._offsetY=null;this._orientationGamma=0;this._orientationBeta=0;this._initialOrientationGamma=0;this._initialOrientationBeta=0;};BABYLON.DeviceOrientationCamera.prototype=Object.create(BABYLON.FreeCamera.prototype);BABYLON.DeviceOrientationCamera.prototype.angularSensibility=10000.0;BABYLON.DeviceOrientationCamera.prototype.moveSensibility=50.0;BABYLON.DeviceOrientationCamera.prototype.attachControl=function(canvas,noPreventDefault){if(this._attachedCanvas){return;}this._attachedCanvas=canvas;var that=this;if(!this._orientationChanged){this._orientationChanged=function(evt){if(!that._initialOrientationGamma){that._initialOrientationGamma=evt.gamma;that._initialOrientationBeta=evt.beta;}that._orientationGamma=evt.gamma;that._orientationBeta=evt.beta;that._offsetY=(that._initialOrientationBeta-that._orientationBeta);that._offsetX=(that._initialOrientationGamma-that._orientationGamma);};}window.addEventListener("deviceorientation",this._orientationChanged);};BABYLON.DeviceOrientationCamera.prototype.detachControl=function(canvas){if(this._attachedCanvas!=canvas){return;}window.removeEventListener("deviceorientation",this._orientationChanged);this._attachedCanvas=null;this._orientationGamma=0;this._orientationBeta=0;this._initialOrientationGamma=0;this._initialOrientationBeta=0;};BABYLON.DeviceOrientationCamera.prototype._checkInputs=function(){if(!this._offsetX){return;}this.cameraRotation.y-=this._offsetX/this.angularSensibility;var speed=this._computeLocalCameraSpeed();var direction=new BABYLON.Vector3(0,0,speed*this._offsetY/this.moveSensibility);BABYLON.Matrix.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,0,this._cameraRotationMatrix);this.cameraDirection.addInPlace(BABYLON.Vector3.TransformCoordinates(direction,this._cameraRotationMatrix));};})();var BABYLON=BABYLON||{};(function(){var eventPrefix=BABYLON.Tools.GetPointerPrefix();BABYLON.ArcRotateCamera=function(name,alpha,beta,radius,target,scene){BABYLON.Camera.call(this,name,BABYLON.Vector3.Zero(),scene);this.alpha=alpha;this.beta=beta;this.radius=radius;this.target=target;this._keys=[];this.keysUp=[38];this.keysDown=[40];this.keysLeft=[37];this.keysRight=[39];this._viewMatrix=new BABYLON.Matrix();this.getViewMatrix();};BABYLON.ArcRotateCamera.prototype=Object.create(BABYLON.Camera.prototype);BABYLON.ArcRotateCamera.prototype.inertialAlphaOffset=0;BABYLON.ArcRotateCamera.prototype.inertialBetaOffset=0;BABYLON.ArcRotateCamera.prototype.lowerAlphaLimit=null;BABYLON.ArcRotateCamera.prototype.upperAlphaLimit=null;BABYLON.ArcRotateCamera.prototype.lowerBetaLimit=null;BABYLON.ArcRotateCamera.prototype.upperBetaLimit=null;BABYLON.ArcRotateCamera.prototype.lowerRadiusLimit=null;BABYLON.ArcRotateCamera.prototype.upperRadiusLimit=null;BABYLON.ArcRotateCamera.prototype.angularSensibility=1000.0;BABYLON.ArcRotateCamera.prototype.attachControl=function(canvas,noPreventDefault){var previousPosition;var that=this;var pointerId;if(this._attachedCanvas){return;}this._attachedCanvas=canvas;var engine=this._scene.getEngine();if(this._onPointerDown===undefined){this._onPointerDown=function(evt){if(pointerId){return;}pointerId=evt.pointerId;previousPosition={x:evt.clientX,y:evt.clientY};if(!noPreventDefault){evt.preventDefault();}};this._onPointerUp=function(evt){previousPosition=null;pointerId=null;if(!noPreventDefault){evt.preventDefault();}};this._onPointerMove=function(evt){if(!previousPosition){return;}if(pointerId!==evt.pointerId){return;}var offsetX=evt.clientX-previousPosition.x;var offsetY=evt.clientY-previousPosition.y;that.inertialAlphaOffset-=offsetX/that.angularSensibility;that.inertialBetaOffset-=offsetY/that.angularSensibility;previousPosition={x:evt.clientX,y:evt.clientY};if(!noPreventDefault){evt.preventDefault();}};this._onMouseMove=function(evt){if(!engine.isPointerLock){return;}var offsetX=evt.movementX||evt.mozMovementX||evt.webkitMovementX||evt.msMovementX||0;var offsetY=evt.movementY||evt.mozMovementY||evt.webkitMovementY||evt.msMovementY||0;that.inertialAlphaOffset-=offsetX/that.angularSensibility;that.inertialBetaOffset-=offsetY/that.angularSensibility;if(!noPreventDefault){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){if(!noPreventDefault){event.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);}if(evt.preventDefault){if(!noPreventDefault){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);}if(evt.preventDefault){if(!noPreventDefault){evt.preventDefault();}}}};this._onLostFocus=function(){that._keys=[];pointerId=null;};this._onGestureStart=function(e){if(!that._MSGestureHandler){that._MSGestureHandler=new MSGesture();that._MSGestureHandler.target=canvas;}that._MSGestureHandler.addPointer(e.pointerId);};this._onGesture=function(e){that.radius*=e.scale;if(e.preventDefault){if(!noPreventDefault){e.stopPropagation();e.preventDefault();}}};this._reset=function(){that._keys=[];that.inertialAlphaOffset=0;that.inertialBetaOffset=0;previousPosition=null;pointerId=null;};}canvas.addEventListener(eventPrefix+"down",this._onPointerDown,false);canvas.addEventListener(eventPrefix+"up",this._onPointerUp,false);canvas.addEventListener(eventPrefix+"out",this._onPointerUp,false);canvas.addEventListener(eventPrefix+"move",this._onPointerMove,false);canvas.addEventListener("mousemove",this._onMouseMove,false);canvas.addEventListener("MSPointerDown",this._onGestureStart,false);canvas.addEventListener("MSGestureChange",this._onGesture,false);window.addEventListener("keydown",this._onKeyDown,false);window.addEventListener("keyup",this._onKeyUp,false);window.addEventListener('mousewheel',this._wheel,false);window.addEventListener("blur",this._onLostFocus,false);};BABYLON.ArcRotateCamera.prototype.detachControl=function(canvas){if(this._attachedCanvas!=canvas){return;}canvas.removeEventListener(eventPrefix+"down",this._onPointerDown);canvas.removeEventListener(eventPrefix+"up",this._onPointerUp);canvas.removeEventListener(eventPrefix+"out",this._onPointerUp);canvas.removeEventListener(eventPrefix+"move",this._onPointerMove);canvas.removeEventListener("mousemove",this._onMouseMove);canvas.removeEventListener("MSPointerDown",this._onGestureStart);canvas.removeEventListener("MSGestureChange",this._onGesture);window.removeEventListener("keydown",this._onKeyDown);window.removeEventListener("keyup",this._onKeyUp);window.removeEventListener('mousewheel',this._wheel);window.removeEventListener("blur",this._onLostFocus);this._MSGestureHandler=null;this._attachedCanvas=null;if(this._reset){this._reset();}};BABYLON.ArcRotateCamera.prototype._update=function(){for(var index=0;indexthis.upperAlphaLimit){this.alpha=this.upperAlphaLimit;}if(this.lowerBetaLimit&&this.betathis.upperBetaLimit){this.beta=this.upperBetaLimit;}if(this.lowerRadiusLimit&&this.radiusthis.upperRadiusLimit){this.radius=this.upperRadiusLimit;}};BABYLON.ArcRotateCamera.prototype.setPosition=function(position){var radiusv3=position.subtract(this.target.position?this.target.position:this.target);this.radius=radiusv3.length();this.alpha=Math.atan(radiusv3.z/radiusv3.x);this.beta=Math.acos(radiusv3.y/this.radius);};BABYLON.ArcRotateCamera.prototype._getViewMatrix=function(){if(this.beta>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.target.addToRef(new BABYLON.Vector3(this.radius*cosa*sinb,this.radius*cosb,this.radius*sina*sinb),this.position);BABYLON.Matrix.LookAtLHToRef(this.position,this.target,this.upVector,this._viewMatrix);return this._viewMatrix;};})();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._renderId=0;this._executeWhenReadyTimeoutId=-1;this._toBeDisposed=new BABYLON.Tools.SmartArray(256);this._onReadyCallbacks=[];this._pendingData=[];this._onBeforeRenderCallbacks=[];this.fogMode=BABYLON.Scene.FOGMODE_NONE;this.fogColor=new BABYLON.Color3(0.2,0.2,0.3);this.fogDensity=0.1;this.fogStart=0;this.fogEnd=1000.0;this.lights=[];this.cameras=[];this.activeCamera=null;this.meshes=[];this._activeMeshes=new BABYLON.Tools.SmartArray(256);this._processedMaterials=new BABYLON.Tools.SmartArray(256);this._renderTargets=new BABYLON.Tools.SmartArray(256);this._activeParticleSystems=new BABYLON.Tools.SmartArray(256);this._activeSkeletons=new BABYLON.Tools.SmartArray(32);this._renderingManager=new BABYLON.RenderingManager(this);this.materials=[];this.multiMaterials=[];this.defaultMaterial=new BABYLON.StandardMaterial("default material",this);this.textures=[];this.particlesEnabled=true;this.particleSystems=[];this.spriteManagers=[];this.layers=[];this.skeletons=[];this.collisionsEnabled=true;this.gravity=new BABYLON.Vector3(0,-9.0,0);this._activeAnimatables=[];this._transformMatrix=BABYLON.Matrix.Zero();this._scaledPosition=BABYLON.Vector3.Zero();this._scaledVelocity=BABYLON.Vector3.Zero();this.postProcessesEnabled=true;this.postProcessManager=new BABYLON.PostProcessManager(this);};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.getRenderId=function(){return this._renderId;};BABYLON.Scene.prototype.isReady=function(){if(this._pendingData.length>0){return false;}for(var index=0;index-1){this._onBeforeRenderCallbacks.splice(index,1);}};BABYLON.Scene.prototype._addPendingData=function(data){this._pendingData.push(data);};BABYLON.Scene.prototype._removePendingData=function(data){var index=this._pendingData.indexOf(data);if(index!==-1){this._pendingData.splice(index,1);}};BABYLON.Scene.prototype.getWaitingItemsCount=function(){return this._pendingData.length;};BABYLON.Scene.prototype.executeWhenReady=function(func){this._onReadyCallbacks.push(func);if(this._executeWhenReadyTimeoutId!==-1){return;}var that=this;this._executeWhenReadyTimeoutId=setTimeout(function(){that._checkIsReady();},150);};BABYLON.Scene.prototype._checkIsReady=function(){if(this.isReady()){this._onReadyCallbacks.forEach(function(func){func();});this._onReadyCallbacks=[];this._executeWhenReadyTimeoutId=-1;return;}var that=this;this._executeWhenReadyTimeoutId=setTimeout(function(){that._checkIsReady();},150);};BABYLON.Scene.prototype.beginAnimation=function(target,from,to,loop,speedRatio,onAnimationEnd){if(speedRatio===undefined){speedRatio=1.0;}if(target.animations){this.stopAnimation(target);var animatable=new BABYLON._Animatable(target,from,to,loop,speedRatio,onAnimationEnd);this._activeAnimatables.push(animatable);}if(target.getAnimatables){var animatables=target.getAnimatables();for(var index=0;index=0;index--){if(this.meshes[index].id===id){return this.meshes[index];}}return null;};BABYLON.Scene.prototype.getLastEntryByID=function(id){for(var index=this.meshes.length-1;index>=0;index--){if(this.meshes[index].id===id){return this.meshes[index];}}for(var index=this.cameras.length-1;index>=0;index--){if(this.cameras[index].id===id){return this.cameras[index];}}return null;};BABYLON.Scene.prototype.getMeshByName=function(name){for(var index=0;index=0;index--){if(this.skeletons[index].id===id){return this.skeletons[index];}}return null;};BABYLON.Scene.prototype.getSkeletonById=function(id){for(var index=0;index0&&mesh.isInFrustrum(this._frustumPlanes))){if(mesh._renderId===0){this._activeMeshes.push(mesh);}mesh._renderId=this._renderId;if(mesh.skeleton){this._activeSkeletons.pushNoDuplicate(mesh.skeleton);}var subMeshes=block.subMeshes[meshIndex];for(var subIndex=0;subIndex0&&mesh.isInFrustrum(this._frustumPlanes)){this._activeMeshes.push(mesh);if(mesh.skeleton){this._activeSkeletons.pushNoDuplicate(mesh.skeleton);}for(var subIndex=0;subIndex0){engine.restoreDefaultFramebuffer();}this._renderTargetsDuration=new Date()-beforeRenderTargetDate;this.postProcessManager._prepareFrame();var beforeRenderDate=new Date();engine.clear(this.clearColor,this.autoClear||this.forceWireframe,true);if(this.layers.length){engine.setDepthBuffer(false);var layerIndex;var layer;for(layerIndex=0;layerIndex=maximumRetry){finalPosition.copyFrom(position);return;}collider._initialize(position,velocity,closeDistance);for(var index=0;indexmax.x)max.x=v.x;if(v.y>max.y)max.y=v.y;if(v.z>max.z)max.z=v.z;};var min=new BABYLON.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE);var max=new BABYLON.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(var index=0;index=distance)continue;distance=result.distance;pickedMesh=mesh;pickedPoint=result.pickedPoint;if(fastCheck){break;}}return{hit:distance!=Number.MAX_VALUE,distance:distance,pickedMesh:pickedMesh,pickedPoint:pickedPoint};};BABYLON.Scene.FOGMODE_NONE=0;BABYLON.Scene.FOGMODE_EXP=1;BABYLON.Scene.FOGMODE_EXP2=2;BABYLON.Scene.FOGMODE_LINEAR=3;})();var BABYLON=BABYLON||{};(function(){BABYLON.VertexBuffer=function(mesh,data,kind,updatable){this._mesh=mesh;this._engine=mesh.getScene().getEngine();this._updatable=updatable;if(updatable){this._buffer=this._engine.createDynamicVertexBuffer(data.length*4);this._engine.updateDynamicVertexBuffer(this._buffer,data);}else{this._buffer=this._engine.createVertexBuffer(data);}this._data=data;this._kind=kind;switch(kind){case BABYLON.VertexBuffer.PositionKind:this._strideSize=3;this._mesh._resetPointsArrayCache();break;case BABYLON.VertexBuffer.NormalKind:this._strideSize=3;break;case BABYLON.VertexBuffer.UVKind:this._strideSize=2;break;case BABYLON.VertexBuffer.UV2Kind:this._strideSize=2;break;case BABYLON.VertexBuffer.ColorKind:this._strideSize=3;break;case BABYLON.VertexBuffer.MatricesIndicesKind:this._strideSize=4;break;case BABYLON.VertexBuffer.MatricesWeightsKind:this._strideSize=4;break;}};BABYLON.VertexBuffer.prototype.isUpdatable=function(){return this._updatable;};BABYLON.VertexBuffer.prototype.getData=function(){return this._data;};BABYLON.VertexBuffer.prototype.getStrideSize=function(){return this._strideSize;};BABYLON.VertexBuffer.prototype.update=function(data){this._engine.updateDynamicVertexBuffer(this._buffer,data);this._data=data;if(this._kind===BABYLON.VertexBuffer.PositionKind){this._mesh._resetPointsArrayCache();}};BABYLON.VertexBuffer.prototype.dispose=function(){this._engine._releaseBuffer(this._buffer);};BABYLON.VertexBuffer.PositionKind="position";BABYLON.VertexBuffer.NormalKind="normal";BABYLON.VertexBuffer.UVKind="uv";BABYLON.VertexBuffer.UV2Kind="uv2";BABYLON.VertexBuffer.ColorKind="color";BABYLON.VertexBuffer.MatricesIndicesKind="matricesIndices";BABYLON.VertexBuffer.MatricesWeightsKind="matricesWeights";})();var BABYLON=BABYLON||{};(function(){BABYLON.Mesh=function(name,scene){this.name=name;this.id=name;this._scene=scene;this._totalVertices=0;this._worldMatrix=BABYLON.Matrix.Identity();scene.meshes.push(this);this.position=new BABYLON.Vector3(0,0,0);this.rotation=new BABYLON.Vector3(0,0,0);this.rotationQuaternion=null;this.scaling=new BABYLON.Vector3(1,1,1);this._pivotMatrix=BABYLON.Matrix.Identity();this._indices=[];this.subMeshes=[];this._renderId=0;this._onBeforeRenderCallbacks=[];this.animations=[];this._positions=null;this._cache={localMatrixUpdated:false,position:BABYLON.Vector3.Zero(),scaling:BABYLON.Vector3.Zero(),rotation:BABYLON.Vector3.Zero(),rotationQuaternion:new BABYLON.Quaternion(0,0,0,0)};this._childrenFlag=false;this._localScaling=BABYLON.Matrix.Zero();this._localRotation=BABYLON.Matrix.Zero();this._localTranslation=BABYLON.Matrix.Zero();this._localBillboard=BABYLON.Matrix.Zero();this._localPivotScaling=BABYLON.Matrix.Zero();this._localPivotScalingRotation=BABYLON.Matrix.Zero();this._localWorld=BABYLON.Matrix.Zero();this._worldMatrix=BABYLON.Matrix.Zero();this._rotateYByPI=BABYLON.Matrix.RotationY(Math.PI);this._collisionsTransformMatrix=BABYLON.Matrix.Zero();this._collisionsScalingMatrix=BABYLON.Matrix.Zero();};BABYLON.Mesh.prototype=Object.create(BABYLON.Node.prototype);BABYLON.Mesh.BILLBOARDMODE_NONE=0;BABYLON.Mesh.BILLBOARDMODE_X=1;BABYLON.Mesh.BILLBOARDMODE_Y=2;BABYLON.Mesh.BILLBOARDMODE_Z=4;BABYLON.Mesh.BILLBOARDMODE_ALL=7;BABYLON.Mesh.prototype.delayLoadState=BABYLON.Engine.DELAYLOADSTATE_NONE;BABYLON.Mesh.prototype.material=null;BABYLON.Mesh.prototype.isVisible=true;BABYLON.Mesh.prototype.isPickable=true;BABYLON.Mesh.prototype.visibility=1.0;BABYLON.Mesh.prototype.billboardMode=BABYLON.Mesh.BILLBOARDMODE_NONE;BABYLON.Mesh.prototype.checkCollisions=false;BABYLON.Mesh.prototype.receiveShadows=false;BABYLON.Mesh.prototype._isDisposed=false;BABYLON.Mesh.prototype.onDispose=null;BABYLON.Mesh.prototype.skeleton=null;BABYLON.Mesh.prototype.renderingGroupId=0;BABYLON.Mesh.prototype.getBoundingInfo=function(){return this._boundingInfo;};BABYLON.Mesh.prototype.getScene=function(){return this._scene;};BABYLON.Mesh.prototype.getWorldMatrix=function(){return this._worldMatrix;};BABYLON.Mesh.prototype.getTotalVertices=function(){return this._totalVertices;};BABYLON.Mesh.prototype.getVerticesData=function(kind){return this._vertexBuffers[kind].getData();};BABYLON.Mesh.prototype.isVerticesDataPresent=function(kind){if(!this._vertexBuffers&&this._delayInfo){return this._delayInfo.indexOf(kind)!==-1;}return this._vertexBuffers[kind]!==undefined;};BABYLON.Mesh.prototype.getTotalIndices=function(){return this._indices.length;};BABYLON.Mesh.prototype.getIndices=function(){return this._indices;};BABYLON.Mesh.prototype.getVertexStrideSize=function(){return this._vertexStrideSize;};BABYLON.Mesh.prototype.setPivotMatrix=function(matrix){this._pivotMatrix=matrix;this._cache.pivotMatrixUpdated=true;};BABYLON.Mesh.prototype.getPivotMatrix=function(){return this._localMatrix;};BABYLON.Mesh.prototype.isSynchronized=function(){if(this.billboardMode!==BABYLON.Mesh.BILLBOARDMODE_NONE)return false;if(this._cache.pivotMatrixUpdated){return false;}if(!this._cache.position.equals(this.position))return false;if(this.rotationQuaternion){if(!this._cache.rotationQuaternion.equals(this.rotationQuaternion))return false;}else{if(!this._cache.rotation.equals(this.rotation))return false;}if(!this._cache.scaling.equals(this.scaling))return false;if(this.parent)return!this.parent._needToSynchonizeChildren();return true;};BABYLON.Mesh.prototype.isReady=function(){return this._isReady;};BABYLON.Mesh.prototype.isAnimated=function(){return this._animationStarted;};BABYLON.Mesh.prototype.isDisposed=function(){return this._isDisposed;};BABYLON.Mesh.prototype.markAsDirty=function(property){if(property==="rotation"){this.rotationQuaternion=null;}};BABYLON.Mesh.prototype.refreshBoundingInfo=function(){var data=this.getVerticesData(BABYLON.VertexBuffer.PositionKind);if(!data){return;}var extend=BABYLON.Tools.ExtractMinAndMax(data,0,this._totalVertices);this._boundingInfo=new BABYLON.BoundingInfo(extend.minimum,extend.maximum);for(var index=0;index-1){this._onBeforeRenderCallbacks.splice(index,1);}};BABYLON.Mesh.prototype.render=function(subMesh){if(!this._vertexBuffers||!this._indexBuffer){return;}for(var callbackIndex=0;callbackIndex1&&!subMesh._checkCollision(collider))continue;this._collideForSubMesh(subMesh,transformMatrix,collider);}};BABYLON.Mesh.prototype._checkCollision=function(collider){if(!this._boundingInfo._checkCollision(collider))return;BABYLON.Matrix.ScalingToRef(1.0/collider.radius.x,1.0/collider.radius.y,1.0/collider.radius.z,this._collisionsScalingMatrix);this._worldMatrix.multiplyToRef(this._collisionsScalingMatrix,this._collisionsTransformMatrix);this._processCollisionsForSubModels(collider,this._collisionsTransformMatrix);};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,fastCheck){if(!this._boundingInfo||!ray.intersectsSphere(this._boundingInfo.boundingSphere)||!ray.intersectsBox(this._boundingInfo.boundingBox)){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,fastCheck);if(result.hit){if((fastCheck||result.distance=0){distance=result.distance;if(fastCheck){break;}}}}if(distance>=0){var world=this.getWorldMatrix();var worldOrigin=BABYLON.Vector3.TransformCoordinates(ray.origin,world);var direction=ray.direction.clone();direction.normalize();direction=direction.scale(distance);var worldDirection=BABYLON.Vector3.TransformNormal(direction,world);var pickedPoint=worldOrigin.add(worldDirection);return{hit:true,distance:BABYLON.Vector3.Distance(worldOrigin,pickedPoint),pickedPoint:pickedPoint};}return{hit:false,distance:0};};BABYLON.Mesh.prototype.clone=function(name,newParent,doNotCloneChildren){var result=new BABYLON.Mesh(name,this._scene);result._vertexBuffers=this._vertexBuffers;for(var kind in result._vertexBuffers){result._vertexBuffers[kind].references++;}result._indexBuffer=this._indexBuffer;this._indexBuffer.references++;BABYLON.Tools.DeepCopy(this,result,["name","material","skeleton"],["_indices","_totalVertices"]);var extend=BABYLON.Tools.ExtractMinAndMax(this.getVerticesData(BABYLON.VertexBuffer.PositionKind),0,this._totalVertices);result._boundingInfo=new BABYLON.BoundingInfo(extend.minimum,extend.maximum);result.material=this.material;if(newParent){result.parent=newParent;}if(!doNotCloneChildren){for(var index=0;index0){var verticesCount=positions.length/3;for(var firstIndex=verticesCount-2*(totalYRotationSteps+1);(firstIndex+totalYRotationSteps+2)=0){distance=result.distance;if(fastCheck){break;}}}}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);};BABYLON.SubMesh.CreateFromIndices=function(materialIndex,startIndex,indexCount,mesh){var minVertexIndex=Number.MAX_VALUE;var maxVertexIndex=-Number.MAX_VALUE;var indices=mesh.getIndices();for(var index=startIndex;indexmaxVertexIndex)maxVertexIndex=vertexIndex;}return new BABYLON.SubMesh(materialIndex,minVertexIndex,maxVertexIndex-minVertexIndex,startIndex,indexCount,mesh);};})();var BABYLON=BABYLON||{};(function(){BABYLON.BaseTexture=function(url,scene){this._scene=scene;this._scene.textures.push(this);};BABYLON.BaseTexture.prototype.delayLoadState=BABYLON.Engine.DELAYLOADSTATE_NONE;BABYLON.BaseTexture.prototype.hasAlpha=false;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(){if(this.delayLoadState===BABYLON.Engine.DELAYLOADSTATE_NOTLOADED){return true;}if(this._texture){return this._texture.isReady;}return false;};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||mesh.visibility<1.0){this._transparentSubMeshes.push(subMesh);}}else if(material.needAlphaTesting()){this._alphaTestSubMeshes.push(subMesh);}else{this._opaqueSubMeshes.push(subMesh);}};})();var BABYLON=BABYLON||{};(function(){BABYLON.RenderingManager=function(scene){this._scene=scene;this._renderingGroups=[];};BABYLON.RenderingManager.prototype._renderParticles=function(index,activeMeshes){if(this._scene._activeParticleSystems.length===0){return;}var beforeParticlesDate=new Date();for(var particleIndex=0;particleIndex 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n float shadow = unpack(texture2D(shadowSampler, uv));\n\n if (depth.z > shadow)\n {\n return 0.;\n }\n return 1.;\n}\n\n// Thanks to http://devmaster.net/\nfloat ChebychevInequality(vec2 moments, float t) \n{\n if (t <= moments.x)\n {\n return 1.0;\n }\n \n float variance = moments.y - (moments.x * moments.x); \n variance = max(variance, 0.);\n\n float d = t - moments.x; \n return variance / (variance + d * d); \n}\n\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n vec4 texel = texture2D(shadowSampler, uv);\n\n vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\n return clamp(1.3 - ChebychevInequality(moments, depth.z), 0., 1.0);\n}\n#endif\n\n// Bump\n#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\nvarying vec2 vBumpUV;\nuniform vec2 vBumpInfos;\nuniform sampler2D bumpSampler;\n\n// Thanks to http://www.thetenthplanet.de/archives/1180\nmat3 cotangent_frame(vec3 normal, vec3 p, vec2 uv)\n{\n // get edge vectors of the pixel triangle\n vec3 dp1 = dFdx(p);\n vec3 dp2 = dFdy(p);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n\n // solve the linear system\n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 tangent = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 binormal = dp2perp * duv1.y + dp1perp * duv2.y;\n\n // construct a scale-invariant frame \n float invmax = inversesqrt(max(dot(tangent, tangent), dot(binormal, binormal)));\n return mat3(tangent * invmax, binormal * invmax, normal);\n}\n\nvec3 perturbNormal(vec3 viewDir)\n{\n vec3 map = texture2D(bumpSampler, vBumpUV).xyz * vBumpInfos.y;\n map = map * 255. / 127. - 128. / 127.;\n mat3 TBN = cotangent_frame(vNormalW, -viewDir, vBumpUV);\n return normalize(TBN * map);\n}\n#endif\n\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n\n// Fog\n#ifdef FOG\n\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\n\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying float fFogDistance;\n\nfloat CalcFogFactor()\n{\n float fogCoeff = 1.0;\n float fogStart = vFogInfos.y;\n float fogEnd = vFogInfos.z;\n float fogDensity = vFogInfos.w;\n\n if (FOGMODE_LINEAR == vFogInfos.x)\n {\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\n }\n else if (FOGMODE_EXP == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\n }\n else if (FOGMODE_EXP2 == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\n }\n\n return clamp(fogCoeff, 0.0, 1.0);\n}\n#endif\n\n// Light Computing\nstruct lightingInfo\n{\n vec3 diffuse;\n vec3 specular;\n};\n\nlightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor) {\n lightingInfo result;\n\n vec3 lightVectorW;\n if (lightData.w == 0.)\n {\n lightVectorW = normalize(lightData.xyz - vPositionW);\n }\n else\n {\n lightVectorW = normalize(-lightData.xyz);\n }\n\n // diffuse\n float ndl = max(0., dot(vNormal, lightVectorW));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = pow(specComp, vSpecularColor.a);\n\n result.diffuse = ndl * diffuseColor;\n result.specular = specComp * specularColor;\n\n return result;\n}\n\nlightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, vec3 specularColor) {\n lightingInfo result;\n\n vec3 lightVectorW = normalize(lightData.xyz - vPositionW);\n\n // diffuse\n float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\n float spotAtten = 0.0;\n\n if (cosAngle >= 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(vNormal, -lightDirection.xyz));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\n float specComp = max(0., dot(vNormal, 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, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor) {\n lightingInfo result;\n\n // Diffuse\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\n float specComp = max(0., dot(vNormal, 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 VERTEXCOLOR\n diffuseColor *= vColor;\n#endif\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 // Bump\n vec3 normalW = vNormalW;\n\n#ifdef BUMP\n normalW = perturbNormal(viewDirectionW);\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 float shadow = 1.;\n\n#ifdef LIGHT0\n#ifdef SPOTLIGHT0\n lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0, vLightSpecular0);\n#endif\n#ifdef HEMILIGHT0\n lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0, vLightGround0);\n#endif\n#ifdef POINTDIRLIGHT0\n lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0);\n#endif\n#ifdef SHADOW0\n #ifdef SHADOWVSM0\n shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0);\n #else\n shadow = computeShadow(vPositionFromLight0, shadowSampler0);\n #endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n specularBase += info.specular * shadow;\n#endif\n\n#ifdef LIGHT1\n#ifdef SPOTLIGHT1\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1, vLightSpecular1);\n#endif\n#ifdef HEMILIGHT1\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1, vLightGround1);\n#endif\n#ifdef POINTDIRLIGHT1\n info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1);\n#endif\n#ifdef SHADOW1\n #ifdef SHADOWVSM1\n shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1);\n #else\n shadow = computeShadow(vPositionFromLight1, shadowSampler1);\n #endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n specularBase += info.specular * shadow;\n#endif\n\n#ifdef LIGHT2\n#ifdef SPOTLIGHT2\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2, vLightSpecular2);\n#endif\n#ifdef HEMILIGHT2\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2, vLightGround2);\n#endif\n#ifdef POINTDIRLIGHT2\n info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2);\n#endif\n#ifdef SHADOW2\n #ifdef SHADOWVSM2\n shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2);\n #else\n shadow = computeShadow(vPositionFromLight2, shadowSampler2);\n #endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n specularBase += info.specular * shadow;\n#endif\n\n#ifdef LIGHT3\n#ifdef SPOTLIGHT3\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3, vLightSpecular3);\n#endif\n#ifdef HEMILIGHT3\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3, vLightGround3);\n#endif\n#ifdef POINTDIRLIGHT3\n info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3);\n#endif\n#ifdef SHADOW3\n #ifdef SHADOWVSM3\n shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3);\n #else\n shadow = computeShadow(vPositionFromLight3, shadowSampler3);\n #endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n specularBase += info.specular * shadow;\n#endif\n\n // Reflection\n vec3 reflectionColor = vec3(0., 0., 0.);\n\n#ifdef REFLECTION\n if (vReflectionInfos.z != 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 vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\n\n#ifdef FOG\n float fog = CalcFogFactor();\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\n#endif\n\n gl_FragColor = color;\n}",
-defaultVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n#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#define MAP_SKYBOX 5.\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#ifdef VERTEXCOLOR\nattribute vec3 color;\n#endif\n#ifdef BONES\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#endif\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 view;\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;\nvarying vec3 vReflectionUVW;\nuniform vec3 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#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec2 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n\n#ifdef BONES\nuniform mat4 mBones[BonesPerMesh];\nuniform mat4 viewProjection;\n#else\nuniform mat4 worldViewProjection;\n#endif\n\n// Output\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef VERTEXCOLOR\nvarying vec3 vColor;\n#endif\n\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif\n\n#ifdef FOG\nvarying float fFogDistance;\n#endif\n\n#ifdef SHADOWS\n#ifdef LIGHT0\nuniform mat4 lightMatrix0;\nvarying vec4 vPositionFromLight0;\n#endif\n#ifdef LIGHT1\nuniform mat4 lightMatrix1;\nvarying vec4 vPositionFromLight1;\n#endif\n#ifdef LIGHT2\nuniform mat4 lightMatrix2;\nvarying vec4 vPositionFromLight2;\n#endif\n#ifdef LIGHT3\nuniform mat4 lightMatrix3;\nvarying vec4 vPositionFromLight3;\n#endif\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 else if (mode == MAP_SKYBOX)\n {\n return position;\n }\n\n return vec3(0, 0, 0);\n}\n#endif\n\nvoid main(void) {\n mat4 finalWorld;\n\n#ifdef BONES\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\n\n#ifdef BONES4\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\n finalWorld = world * (m0 + m1 + m2 + m3);\n#else\n finalWorld = world * (m0 + m1 + m2);\n#endif \n\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\n#else\n finalWorld = world;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n#endif\n\n vec4 worldPos = finalWorld * vec4(position, 1.0);\n vPositionW = vec3(worldPos);\n vNormalW = normalize(vec3(finalWorld * 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#ifdef BUMP\n if (vBumpInfos.x == 0.)\n {\n vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n // Clip plane\n#ifdef CLIPPLANE\n fClipDistance = dot(worldPos, vClipPlane);\n#endif\n\n // Fog\n#ifdef FOG\n fFogDistance = (view * worldPos).z;\n#endif\n\n // Shadows\n#ifdef SHADOWS\n#ifdef LIGHT0\n vPositionFromLight0 = lightMatrix0 * vec4(position, 1.0);\n#endif\n#ifdef LIGHT1\n vPositionFromLight1 = lightMatrix1 * vec4(position, 1.0);\n#endif\n#ifdef LIGHT2\n vPositionFromLight2 = lightMatrix2 * vec4(position, 1.0);\n#endif\n#ifdef LIGHT3\n vPositionFromLight3 = lightMatrix3 * vec4(position, 1.0);\n#endif\n#endif\n\n // Vertex color\n#ifdef VERTEXCOLOR\n vColor = color;\n#endif\n}",
-fxaaPixelShader:"#define FXAA_REDUCE_MIN (1.0/128.0)\n#define FXAA_REDUCE_MUL (1.0/8.0)\n#define FXAA_SPAN_MAX 8.0\n\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform vec2 texelSize;\n\nvoid main(){\n vec2 localTexelSize = texelSize;\n vec3 rgbNW = texture2D(textureSampler, (vUV + vec2(-1.0, -1.0) * localTexelSize)).xyz;\n vec3 rgbNE = texture2D(textureSampler, (vUV + vec2(1.0, -1.0) * localTexelSize)).xyz;\n vec3 rgbSW = texture2D(textureSampler, (vUV + vec2(-1.0, 1.0) * localTexelSize)).xyz;\n vec3 rgbSE = texture2D(textureSampler, (vUV + vec2(1.0, 1.0) * localTexelSize)).xyz;\n vec3 rgbM = texture2D(textureSampler, vUV ).xyz;\n vec3 luma = vec3(0.299, 0.587, 0.114);\n float lumaNW = dot(rgbNW, luma);\n float lumaNE = dot(rgbNE, luma);\n float lumaSW = dot(rgbSW, luma);\n float lumaSE = dot(rgbSE, luma);\n float lumaM = dot(rgbM, luma);\n float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));\n float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));\n\n vec2 dir = vec2(-((lumaNW + lumaNE) - (lumaSW + lumaSE)), ((lumaNW + lumaSW) - (lumaNE + lumaSE)));\n\n float dirReduce = max(\n (lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),\n FXAA_REDUCE_MIN);\n\n float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);\n dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),\n max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),\n dir * rcpDirMin)) * localTexelSize;\n\n vec3 rgbA = 0.5 * (\n texture2D(textureSampler, vUV + dir * (1.0 / 3.0 - 0.5)).xyz +\n texture2D(textureSampler, vUV + dir * (2.0 / 3.0 - 0.5)).xyz);\n\n vec3 rgbB = rgbA * 0.5 + 0.25 * (\n texture2D(textureSampler, vUV + dir * -0.5).xyz +\n texture2D(textureSampler, vUV + dir * 0.5).xyz);\n float lumaB = dot(rgbB, luma);\n if ((lumaB < lumaMin) || (lumaB > lumaMax)) {\n gl_FragColor = vec4(rgbA, 1.0);\n }\n else {\n gl_FragColor = vec4(rgbB, 1.0);\n }\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;\n\n// Input\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef VERTEXCOLOR\nvarying vec3 vColor;\n#endif\n\n// Lights\n#ifdef LIGHT0\nuniform vec4 vLightData0;\nuniform vec3 vLightDiffuse0;\nuniform vec3 vLightSpecular0;\n#ifdef SHADOW0\nvarying vec4 vPositionFromLight0;\nuniform sampler2D shadowSampler0;\n#endif\n#ifdef SPOTLIGHT0\nuniform vec4 vLightDirection0;\n#endif\n#ifdef HEMILIGHT0\nuniform vec3 vLightGround0;\n#endif\n#endif\n\n#ifdef LIGHT1\nuniform vec4 vLightData1;\nuniform vec3 vLightDiffuse1;\nuniform vec3 vLightSpecular1;\n#ifdef SHADOW1\nvarying vec4 vPositionFromLight1;\nuniform sampler2D shadowSampler1;\n#endif\n#ifdef SPOTLIGHT1\nuniform vec4 vLightDirection1;\n#endif\n#ifdef HEMILIGHT1\nuniform vec3 vLightGround1;\n#endif\n#endif\n\n#ifdef LIGHT2\nuniform vec4 vLightData2;\nuniform vec3 vLightDiffuse2;\nuniform vec3 vLightSpecular2;\n#ifdef SHADOW2\nvarying vec4 vPositionFromLight2;\nuniform sampler2D shadowSampler2;\n#endif\n#ifdef SPOTLIGHT2\nuniform vec4 vLightDirection2;\n#endif\n#ifdef HEMILIGHT2\nuniform vec3 vLightGround2;\n#endif\n#endif\n\n#ifdef LIGHT3\nuniform vec4 vLightData3;\nuniform vec3 vLightDiffuse3;\nuniform vec3 vLightSpecular3;\n#ifdef SHADOW3\nvarying vec4 vPositionFromLight3;\nuniform sampler2D shadowSampler3;\n#endif\n#ifdef SPOTLIGHT3\nuniform vec4 vLightDirection3;\n#endif\n#ifdef HEMILIGHT3\nuniform vec3 vLightGround3;\n#endif\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 vec3 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// Shadows\n#ifdef SHADOWS\n\nfloat unpack(vec4 color)\n{\n const vec4 bitShift = vec4(1. / (255. * 255. * 255.), 1. / (255. * 255.), 1. / 255., 1.);\n return dot(color, bitShift);\n}\n\nfloat unpackHalf(vec2 color)\n{\n return color.x + (color.y / 255.0);\n}\n\nfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n float shadow = unpack(texture2D(shadowSampler, uv));\n\n if (depth.z > shadow)\n {\n return 0.;\n }\n return 1.;\n}\n\n// Thanks to http://devmaster.net/\nfloat ChebychevInequality(vec2 moments, float t)\n{\n if (t <= moments.x)\n {\n return 1.0;\n }\n\n float variance = moments.y - (moments.x * moments.x);\n variance = max(variance, 0.);\n\n float d = t - moments.x;\n return variance / (variance + d * d);\n}\n\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n vec2 uv = 0.5 * depth.xy + vec2(0.5, 0.5);\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n vec4 texel = texture2D(shadowSampler, uv);\n\n vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\n return clamp(1.3 - ChebychevInequality(moments, depth.z), 0., 1.0);\n}\n#endif\n\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n\n// Fog\n#ifdef FOG\n\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\n\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying float fFogDistance;\n\nfloat CalcFogFactor()\n{\n float fogCoeff = 1.0;\n float fogStart = vFogInfos.y;\n float fogEnd = vFogInfos.z;\n float fogDensity = vFogInfos.w;\n\n if (FOGMODE_LINEAR == vFogInfos.x)\n {\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\n }\n else if (FOGMODE_EXP == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\n }\n else if (FOGMODE_EXP2 == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\n }\n\n return clamp(fogCoeff, 0.0, 1.0);\n}\n#endif\n\n// Light Computing\nmat3 computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor) {\n mat3 result;\n\n vec3 lightVectorW;\n if (lightData.w == 0.)\n {\n lightVectorW = normalize(lightData.xyz - vPositionW);\n }\n else\n {\n lightVectorW = normalize(-lightData.xyz);\n }\n\n // diffuse\n float ndl = max(0., dot(vNormal, lightVectorW));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = max(0., pow(specComp, max(1.0, vSpecularColor.a)));\n\n result[0] = ndl * diffuseColor;\n result[1] = specComp * specularColor;\n result[2] = vec3(0.);\n\n return result;\n}\n\nmat3 computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 diffuseColor, vec3 specularColor) {\n mat3 result;\n\n vec3 lightVectorW = normalize(lightData.xyz - vPositionW);\n\n // diffuse\n float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\n float spotAtten = 0.0;\n\n if (cosAngle >= 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(vNormal, -lightDirection.xyz));\n\n // Specular\n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = pow(specComp, vSpecularColor.a);\n\n result[0] = ndl * spotAtten * diffuseColor;\n result[1] = specComp * specularColor * spotAtten;\n result[2] = vec3(0.);\n\n return result;\n }\n\n result[0] = vec3(0.);\n result[1] = vec3(0.);\n result[2] = vec3(0.);\n\n return result;\n}\n\nmat3 computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor) {\n mat3 result;\n\n // Diffuse\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\n\n // Specular\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\n float specComp = max(0., dot(vNormal, angleW));\n specComp = pow(specComp, vSpecularColor.a);\n\n result[0] = mix(groundColor, diffuseColor, ndl);\n result[1] = specComp * specularColor;\n result[2] = vec3(0.);\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 VERTEXCOLOR\n diffuseColor *= vColor;\n#endif\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 // Bump\n vec3 normalW = vNormalW;\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 float shadow = 1.;\n\n#ifdef LIGHT0\n#ifdef SPOTLIGHT0\n mat3 info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0, vLightSpecular0);\n#endif\n#ifdef HEMILIGHT0\n mat3 info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0, vLightGround0);\n#endif\n#ifdef POINTDIRLIGHT0\n mat3 info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0, vLightSpecular0);\n#endif\n#ifdef SHADOW0\n#ifdef SHADOWVSM0\n shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0);\n#else\n shadow = computeShadow(vPositionFromLight0, shadowSampler0);\n#endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info[0] * shadow;\n specularBase += info[1] * shadow;\n#endif\n\n#ifdef LIGHT1\n#ifdef SPOTLIGHT1\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1, vLightSpecular1);\n#endif\n#ifdef HEMILIGHT1\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1, vLightGround1);\n#endif\n#ifdef POINTDIRLIGHT1\n info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1, vLightSpecular1);\n#endif\n#ifdef SHADOW1\n#ifdef SHADOWVSM1\n shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1);\n#else\n shadow = computeShadow(vPositionFromLight1, shadowSampler1);\n#endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info[0] * shadow;\n specularBase += info[1] * shadow;\n#endif\n\n#ifdef LIGHT2\n#ifdef SPOTLIGHT2\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2, vLightSpecular2);\n#endif\n#ifdef HEMILIGHT2\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2, vLightGround2);\n#endif\n#ifdef POINTDIRLIGHT2\n info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2, vLightSpecular2);\n#endif\n#ifdef SHADOW2\n#ifdef SHADOWVSM2\n shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2);\n#else\n shadow = computeShadow(vPositionFromLight2, shadowSampler2);\n#endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info[0] * shadow;\n specularBase += info[1] * shadow;\n#endif\n\n#ifdef LIGHT3\n#ifdef SPOTLIGHT3\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3, vLightSpecular3);\n#endif\n#ifdef HEMILIGHT3\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3, vLightGround3);\n#endif\n#ifdef POINTDIRLIGHT3\n info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3, vLightSpecular3);\n#endif\n#ifdef SHADOW3\n#ifdef SHADOWVSM3\n shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3);\n#else\n shadow = computeShadow(vPositionFromLight3, shadowSampler3);\n#endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info[0] * shadow;\n specularBase += info[1] * shadow;\n#endif\n\n // Reflection\n vec3 reflectionColor = vec3(0., 0., 0.);\n\n#ifdef REFLECTION\n if (vReflectionInfos.z != 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 vec4 color = vec4(finalDiffuse * baseAmbientColor + finalSpecular + reflectionColor, alpha);\n\n#ifdef FOG\n float fog = CalcFogFactor();\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\n#endif\n\n gl_FragColor = color;\n}",
-iedefaultVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n#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#define MAP_SKYBOX 5.\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#ifdef VERTEXCOLOR\nattribute vec3 color;\n#endif\n#ifdef BONES\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#endif\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 view;\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;\nvarying vec3 vReflectionUVW;\nuniform vec3 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#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec2 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n\n#ifdef BONES\nuniform mat4 mBones[BonesPerMesh];\nuniform mat4 viewProjection;\n#else\nuniform mat4 worldViewProjection;\n#endif\n\n// Output\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n\n#ifdef VERTEXCOLOR\nvarying vec3 vColor;\n#endif\n\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif\n\n#ifdef FOG\nvarying float fFogDistance;\n#endif\n\n#ifdef SHADOWS\n#ifdef LIGHT0\nuniform mat4 lightMatrix0;\nvarying vec4 vPositionFromLight0;\n#endif\n#ifdef LIGHT1\nuniform mat4 lightMatrix1;\nvarying vec4 vPositionFromLight1;\n#endif\n#ifdef LIGHT2\nuniform mat4 lightMatrix2;\nvarying vec4 vPositionFromLight2;\n#endif\n#ifdef LIGHT3\nuniform mat4 lightMatrix3;\nvarying vec4 vPositionFromLight3;\n#endif\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 else if (mode == MAP_SKYBOX)\n {\n return position;\n }\n\n return vec3(0, 0, 0);\n}\n#endif\n\nvoid main(void) {\n mat4 finalWorld;\n\n#ifdef BONES\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\n\n#ifdef BONES4\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\n finalWorld = world * (m0 + m1 + m2 + m3);\n#else\n finalWorld = world * (m0 + m1 + m2);\n#endif \n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\n#else\n\n finalWorld = world;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n#endif\n\n vec4 worldPos = finalWorld * vec4(position, 1.0);\n vPositionW = vec3(worldPos);\n vNormalW = normalize(vec3(finalWorld * 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#ifdef BUMP\n if (vBumpInfos.x == 0.)\n {\n vBumpUV = vec2(bumpMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vBumpUV = vec2(bumpMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n // Clip plane\n#ifdef CLIPPLANE\n fClipDistance = dot(worldPos, vClipPlane);\n#endif\n\n // Fog\n#ifdef FOG\n fFogDistance = (view * worldPos).z;\n#endif\n\n // Shadows\n#ifdef SHADOWS\n#ifdef LIGHT0\n vPositionFromLight0 = lightMatrix0 * vec4(position, 1.0);\n#endif\n#ifdef LIGHT1\n vPositionFromLight1 = lightMatrix1 * vec4(position, 1.0);\n#endif\n#ifdef LIGHT2\n vPositionFromLight2 = lightMatrix2 * vec4(position, 1.0);\n#endif\n#ifdef LIGHT3\n vPositionFromLight3 = lightMatrix3 * vec4(position, 1.0);\n#endif\n#endif\n\n // Vertex color\n#ifdef VERTEXCOLOR\n vColor = color;\n#endif\n}",
-layerPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\n// Color\nuniform vec4 color;\n\nvoid main(void) {\n vec4 baseColor = texture2D(textureSampler, vUV);\n\n gl_FragColor = baseColor * color;\n}",
-layerVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// 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:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// 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}",
-passPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nvoid main(void) \n{\n gl_FragColor = texture2D(textureSampler, vUV);\n}",
-postprocessVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attributes\nattribute vec2 position;\n\n// Output\nvarying vec2 vUV;\n\nconst vec2 madd = vec2(0.5, 0.5);\n\nvoid main(void) { \n\n vUV = position * madd + madd;\n gl_Position = vec4(position, 0.0, 1.0);\n}",
-refractionPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D refractionSampler;\n\n// Parameters\nuniform vec3 baseColor;\nuniform float depth;\nuniform float colorLevel;\n\nvoid main() {\n float ref = 1.0 - texture2D(refractionSampler, vUV).r;\n\n vec2 uv = vUV - vec2(0.5);\n vec2 offset = uv * depth * ref;\n vec3 sourceColor = texture2D(textureSampler, vUV - offset).rgb;\n\n gl_FragColor = vec4(sourceColor + sourceColor * ref * colorLevel, 1.0);\n}",
-shadowMapPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\nvec4 pack(float depth)\n{\n const vec4 bitOffset = vec4(255. * 255. * 255., 255. * 255., 255., 1.);\n const vec4 bitMask = vec4(0., 1. / 255., 1. / 255., 1. / 255.);\n \n vec4 comp = fract(depth * bitOffset);\n comp -= comp.xxyz * bitMask;\n \n return comp;\n}\n\n// Thanks to http://devmaster.net/\nvec2 packHalf(float depth) \n{ \n const vec2 bitOffset = vec2(1.0 / 255., 0.);\n vec2 color = vec2(depth, fract(depth * 255.));\n\n return color - (color.yy * bitOffset);\n}\n\n\nvoid main(void)\n{\n#ifdef VSM\n float moment1 = gl_FragCoord.z / gl_FragCoord.w; \n float moment2 = moment1 * moment1;\n gl_FragColor = vec4(packHalf(moment1), packHalf(moment2));\n#else\n gl_FragColor = pack(gl_FragCoord.z / gl_FragCoord.w);\n#endif\n}",
-shadowMapVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attribute\nattribute vec3 position;\n#ifdef BONES\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#endif\n\n// Uniform\n#ifdef BONES\nuniform mat4 world;\nuniform mat4 mBones[BonesPerMesh];\nuniform mat4 viewProjection;\n#else\nuniform mat4 worldViewProjection;\n#endif\n\nvoid main(void)\n{\n#ifdef BONES\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\n mat4 finalWorld = world * (m0 + m1 + m2 + m3);\n gl_Position = viewProjection * finalWorld * vec4(position, 1.0);\n#else\n gl_Position = worldViewProjection * vec4(position, 1.0);\n#endif\n}",
-spritesPixelShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\nuniform bool alphaTest;\n\nvarying vec4 vColor;\n\n// Samplers\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n\n// Fog\n#ifdef FOG\n\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\n\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying float fFogDistance;\n\nfloat CalcFogFactor()\n{\n float fogCoeff = 1.0;\n float fogStart = vFogInfos.y;\n float fogEnd = vFogInfos.z;\n float fogDensity = vFogInfos.w;\n\n if (FOGMODE_LINEAR == vFogInfos.x)\n {\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\n }\n else if (FOGMODE_EXP == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\n }\n else if (FOGMODE_EXP2 == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\n }\n\n return min(1., max(0., fogCoeff));\n}\n#endif\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 baseColor *= vColor;\n\n#ifdef FOG\n float fog = CalcFogFactor();\n baseColor.rgb = fog * baseColor.rgb + (1.0 - fog) * vFogColor;\n#endif\n\n gl_FragColor = baseColor;\n}",
-spritesVertexShader:"#ifdef GL_ES\nprecision mediump float;\n#endif\n\n// Attributes\nattribute vec3 position;\nattribute vec4 options;\nattribute vec4 cellInfo;\nattribute vec4 color;\n\n// Uniforms\nuniform vec2 textureInfos;\nuniform mat4 view;\nuniform mat4 projection;\n\n// Output\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef FOG\nvarying float fFogDistance;\n#endif\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 // Color\n vColor = color;\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\n // Fog\n#ifdef FOG\n fFogDistance = viewPos.z;\n#endif\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.checkReadyOnEveryCall=true;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(mesh){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.baseDispose=function(){var index=this._scene.materials.indexOf(this);this._scene.materials.splice(index,1);if(this.onDispose){this.onDispose();}};BABYLON.Material.prototype.dispose=function(){this.baseDispose();};})();var BABYLON=BABYLON||{};(function(){BABYLON.StandardMaterial=function(name,scene){BABYLON.Material.call(this,name,scene);this.diffuseTexture=null;this.ambientTexture=null;this.opacityTexture=null;this.reflectionTexture=null;this.emissiveTexture=null;this.specularTexture=null;this.bumpTexture=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;this._renderTargets=new BABYLON.Tools.SmartArray(16);this._worldViewProjectionMatrix=BABYLON.Matrix.Zero();this._lightMatrix=BABYLON.Matrix.Zero();this._globalAmbientColor=new BABYLON.Color3(0,0,0);this._baseColor=new BABYLON.Color3();this._scaledDiffuse=new BABYLON.Color3();this._scaledSpecular=new BABYLON.Color3();};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){if(!this.checkReadyOnEveryCall){if(this._renderId===this._scene.getRenderId()){return true;}}var engine=this._scene.getEngine();var defines=[];var optionalDefines=[];if(this.diffuseTexture){if(!this.diffuseTexture.isReady()){return false;}else{defines.push("#define DIFFUSE");}}if(this.ambientTexture){if(!this.ambientTexture.isReady()){return false;}else{defines.push("#define AMBIENT");}}if(this.opacityTexture){if(!this.opacityTexture.isReady()){return false;}else{defines.push("#define OPACITY");}}if(this.reflectionTexture){if(!this.reflectionTexture.isReady()){return false;}else{defines.push("#define REFLECTION");}}if(this.emissiveTexture){if(!this.emissiveTexture.isReady()){return false;}else{defines.push("#define EMISSIVE");}}if(this.specularTexture){if(!this.specularTexture.isReady()){return false;}else{defines.push("#define SPECULAR");optionalDefines.push(defines[defines.length-1]);}}if(this._scene.getEngine().getCaps().standardDerivatives&&this.bumpTexture){if(!this.bumpTexture.isReady()){return false;}else{defines.push("#define BUMP");optionalDefines.push(defines[defines.length-1]);}}if(BABYLON.clipPlane){defines.push("#define CLIPPLANE");}if(engine.getAlphaTesting()){defines.push("#define ALPHATEST");}if(this._scene.fogMode!==BABYLON.Scene.FOGMODE_NONE){defines.push("#define FOG");optionalDefines.push(defines[defines.length-1]);}var shadowsActivated=false;var lightIndex=0;for(var index=0;index0){optionalDefines.push(defines[defines.length-1]);}var type;if(light instanceof BABYLON.SpotLight){type="#define SPOTLIGHT"+lightIndex;}else if(light instanceof BABYLON.HemisphericLight){type="#define HEMILIGHT"+lightIndex;}else{type="#define POINTDIRLIGHT"+lightIndex;}defines.push(type);if(lightIndex>0){optionalDefines.push(defines[defines.length-1]);}var shadowGenerator=light.getShadowGenerator();if(mesh&&mesh.receiveShadows&&shadowGenerator){defines.push("#define SHADOW"+lightIndex);if(lightIndex>0){optionalDefines.push(defines[defines.length-1]);}if(!shadowsActivated){defines.push("#define SHADOWS");shadowsActivated=true;}if(shadowGenerator.useVarianceShadowMap){defines.push("#define SHADOWVSM"+lightIndex);if(lightIndex>0){optionalDefines.push(defines[defines.length-1]);}}}lightIndex++;if(lightIndex==4)break;}var attribs=[BABYLON.VertexBuffer.PositionKind,BABYLON.VertexBuffer.NormalKind];if(mesh){if(mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)){attribs.push(BABYLON.VertexBuffer.UVKind);defines.push("#define UV1");}if(mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)){attribs.push(BABYLON.VertexBuffer.UV2Kind);defines.push("#define UV2");}if(mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)){attribs.push(BABYLON.VertexBuffer.ColorKind);defines.push("#define VERTEXCOLOR");}if(mesh.skeleton&&mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)&&mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)){attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);defines.push("#define BONES");defines.push("#define BonesPerMesh "+mesh.skeleton.bones.length);defines.push("#define BONES4");optionalDefines.push(defines[defines.length-1]);}}var join=defines.join("\n");if(this._cachedDefines!=join){this._cachedDefines=join;var shaderName="default";if(BABYLON.Tools.isIE()){shaderName="iedefault";}this._effect=this._scene.getEngine().createEffect(shaderName,attribs,["world","view","worldViewProjection","viewProjection","vEyePosition","vLightsType","vAmbientColor","vDiffuseColor","vSpecularColor","vEmissiveColor","vLightData0","vLightDiffuse0","vLightSpecular0","vLightDirection0","vLightGround0","lightMatrix0","vLightData1","vLightDiffuse1","vLightSpecular1","vLightDirection1","vLightGround1","lightMatrix1","vLightData2","vLightDiffuse2","vLightSpecular2","vLightDirection2","vLightGround2","lightMatrix2","vLightData3","vLightDiffuse3","vLightSpecular3","vLightDirection3","vLightGround3","lightMatrix3","vFogInfos","vFogColor","vDiffuseInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vEmissiveInfos","vSpecularInfos","vBumpInfos","mBones","vClipPlane","diffuseMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","specularMatrix","bumpMatrix"],["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3"],join,optionalDefines);}if(!this._effect.isReady()){return false;}this._renderId=this._scene.getRenderId();return true;};BABYLON.StandardMaterial.prototype.getRenderTargetTextures=function(){this._renderTargets.reset();if(this.reflectionTexture&&this.reflectionTexture.isRenderTarget){this._renderTargets.push(this.reflectionTexture);}return this._renderTargets;};BABYLON.StandardMaterial.prototype.unbind=function(){if(this.reflectionTexture&&this.reflectionTexture.isRenderTarget){this._effect.setTexture("reflection2DSampler",null);}};BABYLON.StandardMaterial.prototype.bind=function(world,mesh){this._baseColor.copyFrom(this.diffuseColor);this._effect.setMatrix("world",world);if(mesh.skeleton&&mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)&&mesh.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)){this._effect.setMatrix("viewProjection",this._scene.getTransformMatrix());this._effect.setMatrices("mBones",mesh.skeleton.getTransformMatrices());}else{world.multiplyToRef(this._scene.getTransformMatrix(),this._worldViewProjectionMatrix);this._effect.setMatrix("worldViewProjection",this._worldViewProjectionMatrix);}if(this.diffuseTexture){this._effect.setTexture("diffuseSampler",this.diffuseTexture);this._effect.setFloat2("vDiffuseInfos",this.diffuseTexture.coordinatesIndex,this.diffuseTexture.level);this._effect.setMatrix("diffuseMatrix",this.diffuseTexture._computeTextureMatrix());this._baseColor.copyFromFloats(1,1,1);}if(this.ambientTexture){this._effect.setTexture("ambientSampler",this.ambientTexture);this._effect.setFloat2("vAmbientInfos",this.ambientTexture.coordinatesIndex,this.ambientTexture.level);this._effect.setMatrix("ambientMatrix",this.ambientTexture._computeTextureMatrix());}if(this.opacityTexture){this._effect.setTexture("opacitySampler",this.opacityTexture);this._effect.setFloat2("vOpacityInfos",this.opacityTexture.coordinatesIndex,this.opacityTexture.level);this._effect.setMatrix("opacityMatrix",this.opacityTexture._computeTextureMatrix());}if(this.reflectionTexture){if(this.reflectionTexture.isCube){this._effect.setTexture("reflectionCubeSampler",this.reflectionTexture);}else{this._effect.setTexture("reflection2DSampler",this.reflectionTexture);}this._effect.setMatrix("reflectionMatrix",this.reflectionTexture._computeReflectionTextureMatrix());this._effect.setFloat3("vReflectionInfos",this.reflectionTexture.coordinatesMode,this.reflectionTexture.level,this.reflectionTexture.isCube?1:0);}if(this.emissiveTexture){this._effect.setTexture("emissiveSampler",this.emissiveTexture);this._effect.setFloat2("vEmissiveInfos",this.emissiveTexture.coordinatesIndex,this.emissiveTexture.level);this._effect.setMatrix("emissiveMatrix",this.emissiveTexture._computeTextureMatrix());}if(this.specularTexture){this._effect.setTexture("specularSampler",this.specularTexture);this._effect.setFloat2("vSpecularInfos",this.specularTexture.coordinatesIndex,this.specularTexture.level);this._effect.setMatrix("specularMatrix",this.specularTexture._computeTextureMatrix());}if(this.bumpTexture&&this._scene.getEngine().getCaps().standardDerivatives){this._effect.setTexture("bumpSampler",this.bumpTexture);this._effect.setFloat2("vBumpInfos",this.bumpTexture.coordinatesIndex,this.bumpTexture.level);this._effect.setMatrix("bumpMatrix",this.bumpTexture._computeTextureMatrix());}this._scene.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor);this._effect.setVector3("vEyePosition",this._scene.activeCamera.position);this._effect.setColor3("vAmbientColor",this._globalAmbientColor);this._effect.setColor4("vDiffuseColor",this._baseColor,this.alpha*mesh.visibility);this._effect.setColor4("vSpecularColor",this.specularColor,this.specularPower);this._effect.setColor3("vEmissiveColor",this.emissiveColor);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);}if(this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0){results.push(this.bumpTexture);}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();}if(this.bumpTexture){this.bumpTexture.dispose();}this.baseDispose();};BABYLON.StandardMaterial.prototype.clone=function(name){var newStandardMaterial=new BABYLON.StandardMaterial(name,this._scene);newStandardMaterial.checkReadyOnEveryCall=this.checkReadyOnEveryCall;newStandardMaterial.alpha=this.alpha;newStandardMaterial.wireframe=this.wireframe;newStandardMaterial.backFaceCulling=this.backFaceCulling;if(this.diffuseTexture&&this.diffuseTexture.clone){newStandardMaterial.diffuseTexture=this.diffuseTexture.clone();}if(this.ambientTexture&&this.ambientTexture.clone){newStandardMaterial.ambientTexture=this.ambientTexture.clone();}if(this.opacityTexture&&this.opacityTexture.clone){newStandardMaterial.opacityTexture=this.opacityTexture.clone();}if(this.reflectionTexture&&this.reflectionTexture.clone){newStandardMaterial.reflectionTexture=this.reflectionTexture.clone();}if(this.emissiveTexture&&this.emissiveTexture.clone){newStandardMaterial.emissiveTexture=this.emissiveTexture.clone();}if(this.specularTexture&&this.specularTexture.clone){newStandardMaterial.specularTexture=this.specularTexture.clone();}if(this.bumpTexture&&this.bumpTexture.clone){newStandardMaterial.bumpTexture=this.bumpTexture.clone();}newStandardMaterial.ambientColor=this.ambientColor.clone();newStandardMaterial.diffuseColor=this.diffuseColor.clone();newStandardMaterial.specularColor=this.specularColor.clone();newStandardMaterial.specularPower=this.specularPower;newStandardMaterial.emissiveColor=this.emissiveColor.clone();return newStandardMaterial;};})();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];};BABYLON.MultiMaterial.prototype.isReady=function(mesh){var result=true;for(var index=0;indexversion.data){that.mustUpdateRessources=true;updateInDBCallback();}else{callback(version.data);}}else{that.mustUpdateRessources=true;updateInDBCallback();}};transaction.onabort=function(event){callback(-1);};var getRequest=transaction.objectStore("versions").get(url);getRequest.onsuccess=function(event){version=event.target.result;};getRequest.onerror=function(event){console.log("Error loading version for scene "+url+" from DB.");callback(-1);};}catch(ex){console.log("Error while accessing 'versions' object store (READ OP). Exception: "+ex.message);callback(-1);}}else{console.log("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");callback(-1);}};BABYLON.Database.prototype._saveVersionIntoDBAsync=function(url,callback){if(this.isSupported&&!this.hasReachedQuota){var that=this;try{var transaction=this.db.transaction(["versions"],"readwrite");transaction.onabort=function(event){try{if(event.srcElement.error.name==="QuotaExceededError"){that.hasReachedQuota=true;}}catch(ex){}callback(-1);};transaction.oncomplete=function(event){callback(that.manifestVersionFound);};var newVersion={};newVersion.sceneUrl=url;newVersion.data=this.manifestVersionFound;var addRequest=transaction.objectStore("versions").put(newVersion);addRequest.onsuccess=function(event){console.log("");};addRequest.onerror=function(event){console.log("Error in DB add version request in BABYLON.Database.");};}catch(ex){console.log("Error while accessing 'versions' object store (WRITE OP). Exception: "+ex.message);callback(-1);}}else{callback(-1);}};BABYLON.Database.prototype.loadSceneFromDB=function(url,sceneLoaded,progressCallBack,errorCallback){var that=this;var completeUrl=BABYLON.Database.ReturnFullUrlLocation(url);var saveAndLoadScene=function(event){that._saveSceneIntoDBAsync(completeUrl,sceneLoaded,progressCallBack);};this._checkVersionFromDB(completeUrl,function(version){if(version!==-1){if(!that.mustUpdateRessources){that._loadSceneFromDBAsync(completeUrl,sceneLoaded,saveAndLoadScene);}else{that._saveSceneIntoDBAsync(completeUrl,sceneLoaded,progressCallBack);}}else{errorCallback();}});};BABYLON.Database.prototype._loadSceneFromDBAsync=function(url,callback,notInDBCallback){if(this.isSupported){var scene;var transaction=this.db.transaction(["scenes"]);transaction.oncomplete=function(event){if(scene){callback(scene.data);}else{notInDBCallback();}};transaction.onabort=function(event){notInDBCallback();};var getRequest=transaction.objectStore("scenes").get(url);getRequest.onsuccess=function(event){scene=event.target.result;};getRequest.onerror=function(event){console.log("Error loading scene "+url+" from DB.");notInDBCallback();};}else{console.log("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");callback();}};BABYLON.Database.prototype._saveSceneIntoDBAsync=function(url,callback,progressCallback){if(this.isSupported){var xhr=new XMLHttpRequest(),sceneText;var that=this;xhr.open("GET",url,true);xhr.onprogress=progressCallback;xhr.addEventListener("load",function(){if(xhr.status===200){sceneText=xhr.responseText;if(!that.hasReachedQuota){var transaction=that.db.transaction(["scenes"],"readwrite");transaction.onabort=function(event){try{if(event.srcElement.error.name==="QuotaExceededError"){that.hasReachedQuota=true;}}catch(ex){}callback(sceneText);};transaction.oncomplete=function(event){callback(sceneText);};var newScene={};newScene.sceneUrl=url;newScene.data=sceneText;newScene.version=that.manifestVersionFound;try{var addRequest=transaction.objectStore("scenes").put(newScene);addRequest.onsuccess=function(event){console.log("");};addRequest.onerror=function(event){console.log("Error in DB add scene request in BABYLON.Database.");};}catch(ex){callback(sceneText);}}else{callback(sceneText);}}else{callback();}},false);xhr.addEventListener("error",function(event){console.log("error on XHR request.");callback();},false);xhr.send();}else{console.log("Error: IndexedDB not supported by your browser or BabylonJS Database is not open.");callback();}};})();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-1){parentBone=skeleton.bones[parsedBone.parentBoneIndex];}var bone=new BABYLON.Bone(parsedBone.name,skeleton,parentBone,BABYLON.Matrix.FromArray(parsedBone.matrix));if(parsedBone.animation){bone.animations.push(parseAnimation(parsedBone.animation));}}return skeleton;};var parseMaterial=function(parsedMaterial,scene,rootUrl){var material;material=new BABYLON.StandardMaterial(parsedMaterial.name,scene);material.ambientColor=BABYLON.Color3.FromArray(parsedMaterial.ambient);material.diffuseColor=BABYLON.Color3.FromArray(parsedMaterial.diffuse);material.specularColor=BABYLON.Color3.FromArray(parsedMaterial.specular);material.specularPower=parsedMaterial.specularPower;material.emissiveColor=BABYLON.Color3.FromArray(parsedMaterial.emissive);material.alpha=parsedMaterial.alpha;material.id=parsedMaterial.id;material.backFaceCulling=parsedMaterial.backFaceCulling;if(parsedMaterial.diffuseTexture){material.diffuseTexture=loadTexture(rootUrl,parsedMaterial.diffuseTexture,scene);}if(parsedMaterial.ambientTexture){material.ambientTexture=loadTexture(rootUrl,parsedMaterial.ambientTexture,scene);}if(parsedMaterial.opacityTexture){material.opacityTexture=loadTexture(rootUrl,parsedMaterial.opacityTexture,scene);}if(parsedMaterial.reflectionTexture){material.reflectionTexture=loadTexture(rootUrl,parsedMaterial.reflectionTexture,scene);}if(parsedMaterial.emissiveTexture){material.emissiveTexture=loadTexture(rootUrl,parsedMaterial.emissiveTexture,scene);}if(parsedMaterial.specularTexture){material.specularTexture=loadTexture(rootUrl,parsedMaterial.specularTexture,scene);}if(parsedMaterial.bumpTexture){material.bumpTexture=loadTexture(rootUrl,parsedMaterial.bumpTexture,scene);}return material;};var parseMaterialById=function(id,parsedData,scene,rootUrl){for(var index=0;index-1){mesh.skeleton=scene.getLastSkeletonByID(parsedMesh.skeletonId);}if(parsedMesh.animations){for(var animationIndex=0;animationIndex>8);floatIndices.push((matricesIndex&0x00FF0000)>>16);floatIndices.push(matricesIndex>>24);}mesh.setVerticesData(floatIndices,BABYLON.VertexBuffer.MatricesIndicesKind,false);}if(parsedGeometry.matricesWeights){mesh.setVerticesData(parsedGeometry.matricesWeights,BABYLON.VertexBuffer.MatricesWeightsKind,false);}mesh.setIndices(parsedGeometry.indices);}if(parsedGeometry.subMeshes){mesh.subMeshes=[];for(var subIndex=0;subIndex-1&&scene.skeletons){var skeletonAlreadyLoaded=(loadedSkeletonsIds.indexOf(parsedMesh.skeletonId)>-1);if(!skeletonAlreadyLoaded){for(var skeletonIndex=0;skeletonIndex>0;this._vertices[arrayOffset+9]=sprite.cellIndex-offset*rowSize;this._vertices[arrayOffset+10]=offset;this._vertices[arrayOffset+11]=sprite.color.r;this._vertices[arrayOffset+12]=sprite.color.g;this._vertices[arrayOffset+13]=sprite.color.b;this._vertices[arrayOffset+14]=sprite.color.a;};BABYLON.SpriteManager.prototype.render=function(){if(!this._effectBase.isReady()||!this._effectFog.isReady()||!this._spriteTexture||!this._spriteTexture.isReady())return 0;var engine=this._scene.getEngine();var baseSize=this._spriteTexture.getBaseSize();var deltaTime=BABYLON.Tools.GetDeltaTime();var max=Math.min(this._capacity,this.sprites.length);var rowSize=baseSize.width/this.cellSize;var offset=0;for(var index=0;indexthis._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;if(this.disposeWhenFinishedAnimating){this.dispose();}}}}};BABYLON.Sprite.prototype.dispose=function(){for(var i=0;i0;for(var index=0;index=particle.lifeTime){this._stockParticles.push(this.particles.splice(index,1)[0]);index--;continue;}else{particle.colorStep.scaleToRef(this._scaledUpdateSpeed,this._scaledColorStep);particle.color.addInPlace(this._scaledColorStep);if(particle.color.a<0)particle.color.a=0;particle.direction.scaleToRef(this._scaledUpdateSpeed,this._scaledDirection);particle.position.addInPlace(this._scaledDirection);particle.angle+=particle.angularSpeed*this._scaledUpdateSpeed;this.gravity.scaleToRef(this._scaledUpdateSpeed,this._scaledGravity);particle.direction.addInPlace(this._scaledGravity);}}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 offset=0;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;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));}case BABYLON.Animation.ANIMATIONTYPE_MATRIX:switch(loopMode){case BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE:case BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT:case BABYLON.Animation.ANIMATIONLOOPMODE_RELATIVE:return startValue;}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;}var returnValue=true;if(this._keys[0].frame!=0){var newKey={frame:0,value:this._keys[0].value};this._keys.splice(0,0,newKey);}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){offsetValue=0;returnValue=false;}else{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=returnValue?from+ratio%range:to;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;indexthis._capacity){BABYLON.Octree._CreateBlocks(this._minPoint,this._maxPoint,this.meshes,this._capacity,this);}};BABYLON.OctreeBlock.prototype.addEntries=function(meshes){for(var index=0;index0){this._camera.postProcesses[0].width=-1;}};})();var BABYLON=BABYLON||{};(function(){BABYLON.PostProcessManager=function(scene){this._scene=scene;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);};BABYLON.PostProcessManager.prototype._prepareFrame=function(){var postProcesses=this._scene.activeCamera.postProcesses;if(postProcesses.length===0||!this._scene.postProcessesEnabled){return;}postProcesses[0].activate();};BABYLON.PostProcessManager.prototype._finalizeFrame=function(){var postProcesses=this._scene.activeCamera.postProcesses;if(postProcesses.length===0||!this._scene.postProcessesEnabled){return;}var engine=this._scene.getEngine();for(var index=0;indexo?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(3>o?n(s):o>3?n(t,i,s):n(t,i))||s);return o>3&&s&&Object.defineProperty(t,i,s),s},__extends=this&&this.__extends||function(e,t){function i(){this.constructor=e}for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);i.prototype=t.prototype,e.prototype=new i},BABYLON;!function(e){e.ToGammaSpace=1/2.2,e.ToLinearSpace=2.2,e.Epsilon=.001;var t=function(){function e(){}return e.WithinEpsilon=function(e,t,i){void 0===i&&(i=1.401298e-45);var r=e-t;return r>=-i&&i>=r},e.ToHex=function(e){var t=e.toString(16);return 15>=e?("0"+t).toUpperCase():t.toUpperCase()},e.Sign=function(e){return e=+e,0===e||isNaN(e)?e:e>0?1:-1},e.Clamp=function(e,t,i){return void 0===t&&(t=0),void 0===i&&(i=1),Math.min(i,Math.max(t,e))},e}();e.MathTools=t;var i=function(){function i(e,t,i){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),this.r=e,this.g=t,this.b=i}return i.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+"}"},i.prototype.getClassName=function(){return"Color3"},i.prototype.getHashCode=function(){var e=this.r||0;return e=397*e^(this.g||0),e=397*e^(this.b||0)},i.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,this},i.prototype.toColor4=function(e){return void 0===e&&(e=1),new r(this.r,this.g,this.b,e)},i.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},i.prototype.toLuminance=function(){return.3*this.r+.59*this.g+.11*this.b},i.prototype.multiply=function(e){return new i(this.r*e.r,this.g*e.g,this.b*e.b)},i.prototype.multiplyToRef=function(e,t){return t.r=this.r*e.r,t.g=this.g*e.g,t.b=this.b*e.b,this},i.prototype.equals=function(e){return e&&this.r===e.r&&this.g===e.g&&this.b===e.b},i.prototype.equalsFloats=function(e,t,i){return this.r===e&&this.g===t&&this.b===i},i.prototype.scale=function(e){return new i(this.r*e,this.g*e,this.b*e)},i.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,this},i.prototype.add=function(e){return new i(this.r+e.r,this.g+e.g,this.b+e.b)},i.prototype.addToRef=function(e,t){return t.r=this.r+e.r,t.g=this.g+e.g,t.b=this.b+e.b,this},i.prototype.subtract=function(e){return new i(this.r-e.r,this.g-e.g,this.b-e.b)},i.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,this},i.prototype.clone=function(){return new i(this.r,this.g,this.b)},i.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this},i.prototype.copyFromFloats=function(e,t,i){return this.r=e,this.g=t,this.b=i,this},i.prototype.toHexString=function(){var e=255*this.r|0,i=255*this.g|0,r=255*this.b|0;return"#"+t.ToHex(e)+t.ToHex(i)+t.ToHex(r)},i.prototype.toLinearSpace=function(){var e=new i;return this.toLinearSpaceToRef(e),e},i.prototype.toLinearSpaceToRef=function(t){return t.r=Math.pow(this.r,e.ToLinearSpace),t.g=Math.pow(this.g,e.ToLinearSpace),t.b=Math.pow(this.b,e.ToLinearSpace),this},i.prototype.toGammaSpace=function(){var e=new i;return this.toGammaSpaceToRef(e),e},i.prototype.toGammaSpaceToRef=function(t){return t.r=Math.pow(this.r,e.ToGammaSpace),t.g=Math.pow(this.g,e.ToGammaSpace),t.b=Math.pow(this.b,e.ToGammaSpace),this},i.FromHexString=function(e){if("#"!==e.substring(0,1)||7!==e.length)return new i(0,0,0);var t=parseInt(e.substring(1,3),16),r=parseInt(e.substring(3,5),16),n=parseInt(e.substring(5,7),16);return i.FromInts(t,r,n)},i.FromArray=function(e,t){return void 0===t&&(t=0),new i(e[t],e[t+1],e[t+2])},i.FromInts=function(e,t,r){return new i(e/255,t/255,r/255)},i.Lerp=function(e,t,r){var n=e.r+(t.r-e.r)*r,o=e.g+(t.g-e.g)*r,s=e.b+(t.b-e.b)*r;return new i(n,o,s)},i.Red=function(){return new i(1,0,0)},i.Green=function(){return new i(0,1,0)},i.Blue=function(){return new i(0,0,1)},i.Black=function(){return new i(0,0,0)},i.White=function(){return new i(1,1,1)},i.Purple=function(){return new i(.5,0,.5)},i.Magenta=function(){return new i(1,0,1)},i.Yellow=function(){return new i(1,1,0)},i.Gray=function(){return new i(.5,.5,.5)},i}();e.Color3=i;var r=function(){function e(e,t,i,r){this.r=e,this.g=t,this.b=i,this.a=r}return e.prototype.addInPlace=function(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this.a+=e.a,this},e.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},e.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e[t+3]=this.a,this},e.prototype.add=function(t){return new e(this.r+t.r,this.g+t.g,this.b+t.b,this.a+t.a)},e.prototype.subtract=function(t){return new e(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)},e.prototype.subtractToRef=function(e,t){return t.r=this.r-e.r,t.g=this.g-e.g,t.b=this.b-e.b,t.a=this.a-e.a,this},e.prototype.scale=function(t){return new e(this.r*t,this.g*t,this.b*t,this.a*t)},e.prototype.scaleToRef=function(e,t){return t.r=this.r*e,t.g=this.g*e,t.b=this.b*e,t.a=this.a*e,this},e.prototype.multiply=function(t){return new e(this.r*t.r,this.g*t.g,this.b*t.b,this.a*t.a)},e.prototype.multiplyToRef=function(e,t){return t.r=this.r*e.r,t.g=this.g*e.g,t.b=this.b*e.b,t.a=this.a*e.a,t},e.prototype.toString=function(){return"{R: "+this.r+" G:"+this.g+" B:"+this.b+" A:"+this.a+"}"},e.prototype.getClassName=function(){return"Color4"},e.prototype.getHashCode=function(){var e=this.r||0;return e=397*e^(this.g||0),e=397*e^(this.b||0),e=397*e^(this.a||0)},e.prototype.clone=function(){return new e(this.r,this.g,this.b,this.a)},e.prototype.copyFrom=function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this.a=e.a,this},e.prototype.toHexString=function(){var e=255*this.r|0,i=255*this.g|0,r=255*this.b|0,n=255*this.a|0;return"#"+t.ToHex(e)+t.ToHex(i)+t.ToHex(r)+t.ToHex(n)},e.FromHexString=function(t){if("#"!==t.substring(0,1)||9!==t.length)return new e(0,0,0,0);var i=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16),o=parseInt(t.substring(7,9),16);return e.FromInts(i,r,n,o)},e.Lerp=function(t,i,r){var n=new e(0,0,0,0);return e.LerpToRef(t,i,r,n),n},e.LerpToRef=function(e,t,i,r){r.r=e.r+(t.r-e.r)*i,r.g=e.g+(t.g-e.g)*i,r.b=e.b+(t.b-e.b)*i,r.a=e.a+(t.a-e.a)*i},e.FromArray=function(t,i){return void 0===i&&(i=0),new e(t[i],t[i+1],t[i+2],t[i+3])},e.FromInts=function(t,i,r,n){return new e(t/255,i/255,r/255,n/255)},e.CheckColors4=function(e,t){if(e.length===3*t){for(var i=[],r=0;rr.x?r.x:n,n=nr.y?r.y:o,o=ot.x?e.x:t.x,n=e.y>t.y?e.y:t.y;return new i(r,n)},i.Transform=function(e,t){var r=i.Zero();return i.TransformToRef(e,t,r),r},i.TransformToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+t.m[13];i.x=r,i.y=n},i.PointInTriangle=function(e,t,i,r){var n=.5*(-i.y*r.x+t.y*(-i.x+r.x)+t.x*(i.y-r.y)+i.x*r.y),o=0>n?-1:1,s=(t.y*r.x-t.x*r.y+(r.y-t.y)*e.x+(t.x-r.x)*e.y)*o,a=(t.x*i.y-t.y*i.x+(t.y-i.y)*e.x+(i.x-t.x)*e.y)*o;return s>0&&a>0&&2*n*o>s+a},i.Distance=function(e,t){return Math.sqrt(i.DistanceSquared(e,t))},i.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y;return i*i+r*r},i.DistanceOfPointFromSegment=function(e,t,r){var n=i.DistanceSquared(t,r);if(0===n)return i.Distance(e,t);var o=r.subtract(t),s=Math.max(0,Math.min(1,i.Dot(e.subtract(t),o)/n)),a=t.add(o.multiplyByFloats(s,s));return i.Distance(e,a)},i}();e.Vector2=n;var o=function(){function i(e,t,i){this.x=e,this.y=t,this.z=i}return i.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"}"},i.prototype.getClassName=function(){return"Vector3"},i.prototype.getHashCode=function(){var e=this.x||0;return e=397*e^(this.y||0),e=397*e^(this.z||0)},i.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},i.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,this},i.prototype.toQuaternion=function(){var e=new h(0,0,0,1),t=Math.cos(.5*(this.x+this.z)),i=Math.sin(.5*(this.x+this.z)),r=Math.cos(.5*(this.z-this.x)),n=Math.sin(.5*(this.z-this.x)),o=Math.cos(.5*this.y),s=Math.sin(.5*this.y);return e.x=r*s,e.y=-n*s,e.z=i*o,e.w=t*o,e},i.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this},i.prototype.add=function(e){return new i(this.x+e.x,this.y+e.y,this.z+e.z)},i.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,this},i.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this},i.prototype.subtract=function(e){return new i(this.x-e.x,this.y-e.y,this.z-e.z)},i.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,this},i.prototype.subtractFromFloats=function(e,t,r){return new i(this.x-e,this.y-t,this.z-r)},i.prototype.subtractFromFloatsToRef=function(e,t,i,r){return r.x=this.x-e,r.y=this.y-t,r.z=this.z-i,this},i.prototype.negate=function(){return new i(-this.x,-this.y,-this.z)},i.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this},i.prototype.scale=function(e){return new i(this.x*e,this.y*e,this.z*e)},i.prototype.scaleToRef=function(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e},i.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z},i.prototype.equalsWithEpsilon=function(i,r){return void 0===r&&(r=e.Epsilon),i&&t.WithinEpsilon(this.x,i.x,r)&&t.WithinEpsilon(this.y,i.y,r)&&t.WithinEpsilon(this.z,i.z,r)},i.prototype.equalsToFloats=function(e,t,i){return this.x===e&&this.y===t&&this.z===i},i.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this},i.prototype.multiply=function(e){return new i(this.x*e.x,this.y*e.y,this.z*e.z)},i.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,this},i.prototype.multiplyByFloats=function(e,t,r){return new i(this.x*e,this.y*t,this.z*r)},i.prototype.divide=function(e){return new i(this.x/e.x,this.y/e.y,this.z/e.z)},i.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,this},i.prototype.MinimizeInPlace=function(e){return e.xthis.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),this},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},i.prototype.normalize=function(){var e=this.length();if(0===e||1===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this},i.prototype.clone=function(){return new i(this.x,this.y,this.z)},i.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},i.prototype.copyFromFloats=function(e,t,i){return this.x=e,this.y=t,this.z=i,this},i.GetClipFactor=function(e,t,r,n){var o=i.Dot(e,r)-n,s=i.Dot(t,r)-n,a=o/(o-s);return a},i.FromArray=function(e,t){return t||(t=0),new i(e[t],e[t+1],e[t+2])},i.FromFloatArray=function(e,t){return t||(t=0),new i(e[t],e[t+1],e[t+2])},i.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2]},i.FromFloatArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2]},i.FromFloatsToRef=function(e,t,i,r){r.x=e,r.y=t,r.z=i},i.Zero=function(){return new i(0,0,0)},i.Up=function(){return new i(0,1,0)},i.TransformCoordinates=function(e,t){var r=i.Zero();return i.TransformCoordinatesToRef(e,t,r),r},i.TransformCoordinatesToRef=function(e,t,i){var r=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8]+t.m[12],n=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9]+t.m[13],o=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]+t.m[14],s=e.x*t.m[3]+e.y*t.m[7]+e.z*t.m[11]+t.m[15];i.x=r/s,i.y=n/s,i.z=o/s},i.TransformCoordinatesFromFloatsToRef=function(e,t,i,r,n){var o=e*r.m[0]+t*r.m[4]+i*r.m[8]+r.m[12],s=e*r.m[1]+t*r.m[5]+i*r.m[9]+r.m[13],a=e*r.m[2]+t*r.m[6]+i*r.m[10]+r.m[14],h=e*r.m[3]+t*r.m[7]+i*r.m[11]+r.m[15];n.x=o/h,n.y=s/h,n.z=a/h},i.TransformNormal=function(e,t){var r=i.Zero();return i.TransformNormalToRef(e,t,r),r},i.TransformNormalToRef=function(e,t,i){i.x=e.x*t.m[0]+e.y*t.m[4]+e.z*t.m[8],i.y=e.x*t.m[1]+e.y*t.m[5]+e.z*t.m[9],i.z=e.x*t.m[2]+e.y*t.m[6]+e.z*t.m[10]},i.TransformNormalFromFloatsToRef=function(e,t,i,r,n){n.x=e*r.m[0]+t*r.m[4]+i*r.m[8],n.y=e*r.m[1]+t*r.m[5]+i*r.m[9],n.z=e*r.m[2]+t*r.m[6]+i*r.m[10]},i.CatmullRom=function(e,t,r,n,o){var s=o*o,a=o*s,h=.5*(2*t.x+(-e.x+r.x)*o+(2*e.x-5*t.x+4*r.x-n.x)*s+(-e.x+3*t.x-3*r.x+n.x)*a),c=.5*(2*t.y+(-e.y+r.y)*o+(2*e.y-5*t.y+4*r.y-n.y)*s+(-e.y+3*t.y-3*r.y+n.y)*a),l=.5*(2*t.z+(-e.z+r.z)*o+(2*e.z-5*t.z+4*r.z-n.z)*s+(-e.z+3*t.z-3*r.z+n.z)*a);return new i(h,c,l)},i.Clamp=function(e,t,r){var n=e.x;n=n>r.x?r.x:n,n=nr.y?r.y:o,o=or.z?r.z:s,s=sP&&2>x&&(u=Math.PI+u),s.x=f,s.y=u,s.z=p},i}();e.Vector3=o;var s=function(){function i(e,t,i,r){this.x=e,this.y=t,this.z=i,this.w=r}return i.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+"W:"+this.w+"}"},i.prototype.getClassName=function(){return"Vector4"},i.prototype.getHashCode=function(){var e=this.x||0;return e=397*e^(this.y||0),e=397*e^(this.z||0),e=397*e^(this.w||0)},i.prototype.asArray=function(){var e=[];return this.toArray(e,0),e},i.prototype.toArray=function(e,t){return void 0===t&&(t=0),e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,this},i.prototype.addInPlace=function(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this},i.prototype.add=function(e){return new i(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)},i.prototype.addToRef=function(e,t){return t.x=this.x+e.x,t.y=this.y+e.y,t.z=this.z+e.z,t.w=this.w+e.w,this},i.prototype.subtractInPlace=function(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this},i.prototype.subtract=function(e){return new i(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)},i.prototype.subtractToRef=function(e,t){return t.x=this.x-e.x,t.y=this.y-e.y,t.z=this.z-e.z,t.w=this.w-e.w,this},i.prototype.subtractFromFloats=function(e,t,r,n){return new i(this.x-e,this.y-t,this.z-r,this.w-n)},i.prototype.subtractFromFloatsToRef=function(e,t,i,r,n){return n.x=this.x-e,n.y=this.y-t,n.z=this.z-i,n.w=this.w-r,this},i.prototype.negate=function(){return new i(-this.x,-this.y,-this.z,-this.w)},i.prototype.scaleInPlace=function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},i.prototype.scale=function(e){return new i(this.x*e,this.y*e,this.z*e,this.w*e)},i.prototype.scaleToRef=function(e,t){t.x=this.x*e,t.y=this.y*e,t.z=this.z*e,t.w=this.w*e},i.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},i.prototype.equalsWithEpsilon=function(i,r){return void 0===r&&(r=e.Epsilon),i&&t.WithinEpsilon(this.x,i.x,r)&&t.WithinEpsilon(this.y,i.y,r)&&t.WithinEpsilon(this.z,i.z,r)&&t.WithinEpsilon(this.w,i.w,r)},i.prototype.equalsToFloats=function(e,t,i,r){return this.x===e&&this.y===t&&this.z===i&&this.w===r},i.prototype.multiplyInPlace=function(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this},i.prototype.multiply=function(e){return new i(this.x*e.x,this.y*e.y,this.z*e.z,this.w*e.w)},i.prototype.multiplyToRef=function(e,t){return t.x=this.x*e.x,t.y=this.y*e.y,t.z=this.z*e.z,t.w=this.w*e.w,this},i.prototype.multiplyByFloats=function(e,t,r,n){return new i(this.x*e,this.y*t,this.z*r,this.w*n)},i.prototype.divide=function(e){return new i(this.x/e.x,this.y/e.y,this.z/e.z,this.w/e.w)},i.prototype.divideToRef=function(e,t){return t.x=this.x/e.x,t.y=this.y/e.y,t.z=this.z/e.z,t.w=this.w/e.w,this},i.prototype.MinimizeInPlace=function(e){return e.xthis.x&&(this.x=e.x),e.y>this.y&&(this.y=e.y),e.z>this.z&&(this.z=e.z),e.w>this.w&&(this.w=e.w),this},i.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},i.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},i.prototype.normalize=function(){var e=this.length();if(0===e)return this;var t=1/e;return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},i.prototype.toVector3=function(){return new o(this.x,this.y,this.z)},i.prototype.clone=function(){return new i(this.x,this.y,this.z,this.w)},i.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},i.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},i.FromArray=function(e,t){return t||(t=0),new i(e[t],e[t+1],e[t+2],e[t+3])},i.FromArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},i.FromFloatArrayToRef=function(e,t,i){i.x=e[t],i.y=e[t+1],i.z=e[t+2],i.w=e[t+3]},i.FromFloatsToRef=function(e,t,i,r,n){n.x=e,n.y=t,n.z=i,n.w=r},i.Zero=function(){return new i(0,0,0,0)},i.Normalize=function(e){var t=i.Zero();return i.NormalizeToRef(e,t),t},i.NormalizeToRef=function(e,t){t.copyFrom(e),t.normalize()},i.Minimize=function(e,t){var i=e.clone();return i.MinimizeInPlace(t),i},i.Maximize=function(e,t){var i=e.clone();return i.MaximizeInPlace(t),i},i.Distance=function(e,t){return Math.sqrt(i.DistanceSquared(e,t))},i.DistanceSquared=function(e,t){var i=e.x-t.x,r=e.y-t.y,n=e.z-t.z,o=e.w-t.w;return i*i+r*r+n*n+o*o},i.Center=function(e,t){var i=e.add(t);return i.scaleInPlace(.5),i},i}();e.Vector4=s;var a=function(){function e(e,t){this.width=e,this.height=t}return e.prototype.toString=function(){return"{W: "+this.width+", H: "+this.height+"}"},e.prototype.getClassName=function(){return"Size"},e.prototype.getHashCode=function(){var e=this.width||0;return e=397*e^(this.height||0)},e.prototype.copyFrom=function(e){this.width=e.width,this.height=e.height},e.prototype.clone=function(){return new e(this.width,this.height)},e.prototype.equals=function(e){return e?this.width===e.width&&this.height===e.height:!1},Object.defineProperty(e.prototype,"surface",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),e.Zero=function(){return new e(0,0)},e.prototype.add=function(t){var i=new e(this.width+t.width,this.height+t.height);return i},e.prototype.substract=function(t){var i=new e(this.width-t.width,this.height-t.height);return i},e.Lerp=function(t,i,r){var n=t.width+(i.width-t.width)*r,o=t.height+(i.height-t.height)*r;return new e(n,o)},e}();e.Size=a;var h=function(){function e(e,t,i,r){void 0===e&&(e=0),void 0===t&&(t=0),void 0===i&&(i=0),void 0===r&&(r=1),this.x=e,this.y=t,this.z=i,this.w=r}return e.prototype.toString=function(){return"{X: "+this.x+" Y:"+this.y+" Z:"+this.z+" W:"+this.w+"}"},e.prototype.getClassName=function(){return"Quaternion"},e.prototype.getHashCode=function(){var e=this.x||0;return e=397*e^(this.y||0),e=397*e^(this.z||0),e=397*e^(this.w||0)},e.prototype.asArray=function(){return[this.x,this.y,this.z,this.w]},e.prototype.equals=function(e){return e&&this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w},e.prototype.clone=function(){return new e(this.x,this.y,this.z,this.w)},e.prototype.copyFrom=function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},e.prototype.copyFromFloats=function(e,t,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,this},e.prototype.add=function(t){return new e(this.x+t.x,this.y+t.y,this.z+t.z,this.w+t.w)},e.prototype.subtract=function(t){return new e(this.x-t.x,this.y-t.y,this.z-t.z,this.w-t.w)},e.prototype.scale=function(t){return new e(this.x*t,this.y*t,this.z*t,this.w*t)},e.prototype.multiply=function(t){var i=new e(0,0,0,1);return this.multiplyToRef(t,i),i},e.prototype.multiplyToRef=function(e,t){var i=this.x*e.w+this.y*e.z-this.z*e.y+this.w*e.x,r=-this.x*e.z+this.y*e.w+this.z*e.x+this.w*e.y,n=this.x*e.y-this.y*e.x+this.z*e.w+this.w*e.z,o=-this.x*e.x-this.y*e.y-this.z*e.z+this.w*e.w;return t.copyFromFloats(i,r,n,o),this},e.prototype.multiplyInPlace=function(e){return this.multiplyToRef(e,this),this},e.prototype.conjugateToRef=function(e){return e.copyFromFloats(-this.x,-this.y,-this.z,this.w),this},e.prototype.conjugateInPlace=function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},e.prototype.conjugate=function(){var t=new e(-this.x,-this.y,-this.z,this.w);return t},e.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},e.prototype.normalize=function(){var e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},e.prototype.toEulerAngles=function(e){void 0===e&&(e="YZX");var t=o.Zero();return this.toEulerAnglesToRef(t,e),t},e.prototype.toEulerAnglesToRef=function(e,t){void 0===t&&(t="YZX");var i,r,n,o=this.x,s=this.y,a=this.z,h=this.w;switch(t){case"YZX":var c=o*s+a*h;if(c>.499&&(i=2*Math.atan2(o,h),r=Math.PI/2,n=0),-.499>c&&(i=-2*Math.atan2(o,h),r=-Math.PI/2,n=0),isNaN(i)){var l=o*o,u=s*s,f=a*a;i=Math.atan2(2*s*h-2*o*a,1-2*u-2*f),r=Math.asin(2*c),n=Math.atan2(2*o*h-2*s*a,1-2*l-2*f)}break;default:throw new Error("Euler order "+t+" not supported yet.")}return e.y=i,e.z=r,e.x=n,this},e.prototype.toRotationMatrix=function(e){var t=this.x*this.x,i=this.y*this.y,r=this.z*this.z,n=this.x*this.y,o=this.z*this.w,s=this.z*this.x,a=this.y*this.w,h=this.y*this.z,c=this.x*this.w;return e.m[0]=1-2*(i+r),e.m[1]=2*(n+o),e.m[2]=2*(s-a),e.m[3]=0,e.m[4]=2*(n-o),e.m[5]=1-2*(r+t),e.m[6]=2*(h+c),e.m[7]=0,e.m[8]=2*(s+a),e.m[9]=2*(h-c),e.m[10]=1-2*(i+t),e.m[11]=0,e.m[12]=0,e.m[13]=0,e.m[14]=0,e.m[15]=1,this},e.prototype.fromRotationMatrix=function(t){return e.FromRotationMatrixToRef(t,this),this},e.FromRotationMatrix=function(t){var i=new e;return e.FromRotationMatrixToRef(t,i),i},e.FromRotationMatrixToRef=function(e,t){var i,r=e.m,n=r[0],o=r[4],s=r[8],a=r[1],h=r[5],c=r[9],l=r[2],u=r[6],f=r[10],d=n+h+f;d>0?(i=.5/Math.sqrt(d+1),t.w=.25/i,t.x=(u-c)*i,t.y=(s-l)*i,t.z=(a-o)*i):n>h&&n>f?(i=2*Math.sqrt(1+n-h-f),t.w=(u-c)/i,t.x=.25*i,t.y=(o+a)/i,t.z=(s+l)/i):h>f?(i=2*Math.sqrt(1+h-n-f),t.w=(s-l)/i,t.x=(o+a)/i,t.y=.25*i,t.z=(c+u)/i):(i=2*Math.sqrt(1+f-n-h),t.w=(a-o)/i,t.x=(s+l)/i,t.y=(c+u)/i,t.z=.25*i)},e.Inverse=function(t){return new e(-t.x,-t.y,-t.z,t.w)},e.Identity=function(){return new e(0,0,0,1)},e.RotationAxis=function(t,i){var r=new e,n=Math.sin(i/2);return t.normalize(),r.w=Math.cos(i/2),r.x=t.x*n,r.y=t.y*n,r.z=t.z*n,r},e.FromArray=function(t,i){return i||(i=0),new e(t[i],t[i+1],t[i+2],t[i+3])},e.RotationYawPitchRoll=function(t,i,r){var n=new e;return e.RotationYawPitchRollToRef(t,i,r,n),n},e.RotationYawPitchRollToRef=function(e,t,i,r){var n=.5*i,o=.5*t,s=.5*e,a=Math.sin(n),h=Math.cos(n),c=Math.sin(o),l=Math.cos(o),u=Math.sin(s),f=Math.cos(s);r.x=f*c*h+u*l*a,r.y=u*l*h-f*c*a,r.z=f*l*a-u*c*h,r.w=f*l*h+u*c*a},e.RotationAlphaBetaGamma=function(t,i,r){var n=new e;return e.RotationAlphaBetaGammaToRef(t,i,r,n),n},e.RotationAlphaBetaGammaToRef=function(e,t,i,r){var n=.5*(i+e),o=.5*(i-e),s=.5*t;r.x=Math.cos(o)*Math.sin(s),r.y=Math.sin(o)*Math.sin(s),r.z=Math.sin(n)*Math.cos(s),r.w=Math.cos(n)*Math.cos(s)},e.Slerp=function(t,i,r){var n,o,s=r,a=t.x*i.x+t.y*i.y+t.z*i.z+t.w*i.w,h=!1;if(0>a&&(h=!0,a=-a),a>.999999)o=1-s,n=h?-s:s;else{var c=Math.acos(a),l=1/Math.sin(c);o=Math.sin((1-s)*c)*l,n=h?-Math.sin(s*c)*l:Math.sin(s*c)*l}return new e(o*t.x+n*i.x,o*t.y+n*i.y,o*t.z+n*i.z,o*t.w+n*i.w)},e}();e.Quaternion=h;var c=function(){function e(){this.m=new Float32Array(16)}return e.prototype.isIdentity=function(){return 1!==this.m[0]||1!==this.m[5]||1!==this.m[10]||1!==this.m[15]?!1:0===this.m[1]&&0===this.m[2]&&0===this.m[3]&&0===this.m[4]&&0===this.m[6]&&0===this.m[7]&&0===this.m[8]&&0===this.m[9]&&0===this.m[11]&&0===this.m[12]&&0===this.m[13]&&0===this.m[14]},e.prototype.determinant=function(){var e=this.m[10]*this.m[15]-this.m[11]*this.m[14],t=this.m[9]*this.m[15]-this.m[11]*this.m[13],i=this.m[9]*this.m[14]-this.m[10]*this.m[13],r=this.m[8]*this.m[15]-this.m[11]*this.m[12],n=this.m[8]*this.m[14]-this.m[10]*this.m[12],o=this.m[8]*this.m[13]-this.m[9]*this.m[12];return this.m[0]*(this.m[5]*e-this.m[6]*t+this.m[7]*i)-this.m[1]*(this.m[4]*e-this.m[6]*r+this.m[7]*n)+this.m[2]*(this.m[4]*t-this.m[5]*r+this.m[7]*o)-this.m[3]*(this.m[4]*i-this.m[5]*n+this.m[6]*o)},e.prototype.toArray=function(){return this.m},e.prototype.asArray=function(){return this.toArray()},e.prototype.invert=function(){return this.invertToRef(this),this},e.prototype.reset=function(){for(var e=0;16>e;e++)this.m[e]=0;return this},e.prototype.add=function(t){var i=new e;return this.addToRef(t,i),i},e.prototype.addToRef=function(e,t){for(var i=0;16>i;i++)t.m[i]=this.m[i]+e.m[i];return this},e.prototype.addToSelf=function(e){for(var t=0;16>t;t++)this.m[t]+=e.m[t];return this},e.prototype.invertToRef=function(e){var t=this.m[0],i=this.m[1],r=this.m[2],n=this.m[3],o=this.m[4],s=this.m[5],a=this.m[6],h=this.m[7],c=this.m[8],l=this.m[9],u=this.m[10],f=this.m[11],d=this.m[12],p=this.m[13],_=this.m[14],g=this.m[15],m=u*g-f*_,v=l*g-f*p,y=l*_-u*p,x=c*g-f*d,b=c*_-u*d,P=c*p-l*d,A=s*m-a*v+h*y,E=-(o*m-a*x+h*b),T=o*v-s*x+h*P,C=-(o*y-s*b+a*P),S=1/(t*A+i*E+r*T+n*C),M=a*g-h*_,I=s*g-h*p,D=s*_-a*p,R=o*g-h*d,O=o*_-a*d,w=o*p-s*d,L=a*f-h*u,B=s*f-h*l,V=s*u-a*l,F=o*f-h*c,N=o*u-a*c,z=o*l-s*c;return e.m[0]=A*S,e.m[4]=E*S,e.m[8]=T*S,e.m[12]=C*S,e.m[1]=-(i*m-r*v+n*y)*S,e.m[5]=(t*m-r*x+n*b)*S,e.m[9]=-(t*v-i*x+n*P)*S,e.m[13]=(t*y-i*b+r*P)*S,e.m[2]=(i*M-r*I+n*D)*S,e.m[6]=-(t*M-r*R+n*O)*S,e.m[10]=(t*I-i*R+n*w)*S,e.m[14]=-(t*D-i*O+r*w)*S,e.m[3]=-(i*L-r*B+n*V)*S,e.m[7]=(t*L-r*F+n*N)*S,e.m[11]=-(t*B-i*F+n*z)*S,e.m[15]=(t*V-i*N+r*z)*S,this},e.prototype.setTranslation=function(e){return this.m[12]=e.x,this.m[13]=e.y,this.m[14]=e.z,this},e.prototype.getTranslation=function(){return new o(this.m[12],this.m[13],this.m[14])},e.prototype.multiply=function(t){var i=new e;return this.multiplyToRef(t,i),i},e.prototype.copyFrom=function(e){for(var t=0;16>t;t++)this.m[t]=e.m[t];return this},e.prototype.copyToArray=function(e,t){void 0===t&&(t=0);for(var i=0;16>i;i++)e[t+i]=this.m[i];return this},e.prototype.multiplyToRef=function(e,t){return this.multiplyToArray(e,t.m,0),this},e.prototype.multiplyToArray=function(e,t,i){var r=this.m[0],n=this.m[1],o=this.m[2],s=this.m[3],a=this.m[4],h=this.m[5],c=this.m[6],l=this.m[7],u=this.m[8],f=this.m[9],d=this.m[10],p=this.m[11],_=this.m[12],g=this.m[13],m=this.m[14],v=this.m[15],y=e.m[0],x=e.m[1],b=e.m[2],P=e.m[3],A=e.m[4],E=e.m[5],T=e.m[6],C=e.m[7],S=e.m[8],M=e.m[9],I=e.m[10],D=e.m[11],R=e.m[12],O=e.m[13],w=e.m[14],L=e.m[15];
+return t[i]=r*y+n*A+o*S+s*R,t[i+1]=r*x+n*E+o*M+s*O,t[i+2]=r*b+n*T+o*I+s*w,t[i+3]=r*P+n*C+o*D+s*L,t[i+4]=a*y+h*A+c*S+l*R,t[i+5]=a*x+h*E+c*M+l*O,t[i+6]=a*b+h*T+c*I+l*w,t[i+7]=a*P+h*C+c*D+l*L,t[i+8]=u*y+f*A+d*S+p*R,t[i+9]=u*x+f*E+d*M+p*O,t[i+10]=u*b+f*T+d*I+p*w,t[i+11]=u*P+f*C+d*D+p*L,t[i+12]=_*y+g*A+m*S+v*R,t[i+13]=_*x+g*E+m*M+v*O,t[i+14]=_*b+g*T+m*I+v*w,t[i+15]=_*P+g*C+m*D+v*L,this},e.prototype.equals=function(e){return e&&this.m[0]===e.m[0]&&this.m[1]===e.m[1]&&this.m[2]===e.m[2]&&this.m[3]===e.m[3]&&this.m[4]===e.m[4]&&this.m[5]===e.m[5]&&this.m[6]===e.m[6]&&this.m[7]===e.m[7]&&this.m[8]===e.m[8]&&this.m[9]===e.m[9]&&this.m[10]===e.m[10]&&this.m[11]===e.m[11]&&this.m[12]===e.m[12]&&this.m[13]===e.m[13]&&this.m[14]===e.m[14]&&this.m[15]===e.m[15]},e.prototype.clone=function(){return e.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])},e.prototype.getClassName=function(){return"Matrix"},e.prototype.getHashCode=function(){for(var e=this.m[0]||0,t=1;16>t;t++)e=397*e^(this.m[t]||0);return e},e.prototype.decompose=function(i,r,n){n.x=this.m[12],n.y=this.m[13],n.z=this.m[14];var o=t.Sign(this.m[0]*this.m[1]*this.m[2]*this.m[3])<0?-1:1,s=t.Sign(this.m[4]*this.m[5]*this.m[6]*this.m[7])<0?-1:1,a=t.Sign(this.m[8]*this.m[9]*this.m[10]*this.m[11])<0?-1:1;if(i.x=o*Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]+this.m[2]*this.m[2]),i.y=s*Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]+this.m[6]*this.m[6]),i.z=a*Math.sqrt(this.m[8]*this.m[8]+this.m[9]*this.m[9]+this.m[10]*this.m[10]),0===i.x||0===i.y||0===i.z)return r.x=0,r.y=0,r.z=0,r.w=1,!1;var c=e.FromValues(this.m[0]/i.x,this.m[1]/i.x,this.m[2]/i.x,0,this.m[4]/i.y,this.m[5]/i.y,this.m[6]/i.y,0,this.m[8]/i.z,this.m[9]/i.z,this.m[10]/i.z,0,0,0,0,1);return h.FromRotationMatrixToRef(c,r),!0},e.FromArray=function(t,i){var r=new e;return i||(i=0),e.FromArrayToRef(t,i,r),r},e.FromArrayToRef=function(e,t,i){for(var r=0;16>r;r++)i.m[r]=e[r+t]},e.FromFloat32ArrayToRefScaled=function(e,t,i,r){for(var n=0;16>n;n++)r.m[n]=e[n+t]*i},e.FromValuesToRef=function(e,t,i,r,n,o,s,a,h,c,l,u,f,d,p,_,g){g.m[0]=e,g.m[1]=t,g.m[2]=i,g.m[3]=r,g.m[4]=n,g.m[5]=o,g.m[6]=s,g.m[7]=a,g.m[8]=h,g.m[9]=c,g.m[10]=l,g.m[11]=u,g.m[12]=f,g.m[13]=d,g.m[14]=p,g.m[15]=_},e.prototype.getRow=function(e){if(0>e||e>3)return null;var t=4*e;return new s(this.m[t+0],this.m[t+1],this.m[t+2],this.m[t+3])},e.prototype.setRow=function(e,t){if(0>e||e>3)return this;var i=4*e;return this.m[i+0]=t.x,this.m[i+1]=t.y,this.m[i+2]=t.z,this.m[i+3]=t.w,this},e.FromValues=function(t,i,r,n,o,s,a,h,c,l,u,f,d,p,_,g){var m=new e;return m.m[0]=t,m.m[1]=i,m.m[2]=r,m.m[3]=n,m.m[4]=o,m.m[5]=s,m.m[6]=a,m.m[7]=h,m.m[8]=c,m.m[9]=l,m.m[10]=u,m.m[11]=f,m.m[12]=d,m.m[13]=p,m.m[14]=_,m.m[15]=g,m},e.Compose=function(t,i,r){var n=e.FromValues(t.x,0,0,0,0,t.y,0,0,0,0,t.z,0,0,0,0,1),o=e.Identity();return i.toRotationMatrix(o),n=n.multiply(o),n.setTranslation(r),n},e.Identity=function(){return e.FromValues(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)},e.IdentityToRef=function(t){e.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,t)},e.Zero=function(){return e.FromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)},e.RotationX=function(t){var i=new e;return e.RotationXToRef(t,i),i},e.Invert=function(t){var i=new e;return t.invertToRef(i),i},e.RotationXToRef=function(e,t){var i=Math.sin(e),r=Math.cos(e);t.m[0]=1,t.m[15]=1,t.m[5]=r,t.m[10]=r,t.m[9]=-i,t.m[6]=i,t.m[1]=0,t.m[2]=0,t.m[3]=0,t.m[4]=0,t.m[7]=0,t.m[8]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},e.RotationY=function(t){var i=new e;return e.RotationYToRef(t,i),i},e.RotationYToRef=function(e,t){var i=Math.sin(e),r=Math.cos(e);t.m[5]=1,t.m[15]=1,t.m[0]=r,t.m[2]=-i,t.m[8]=i,t.m[10]=r,t.m[1]=0,t.m[3]=0,t.m[4]=0,t.m[6]=0,t.m[7]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},e.RotationZ=function(t){var i=new e;return e.RotationZToRef(t,i),i},e.RotationZToRef=function(e,t){var i=Math.sin(e),r=Math.cos(e);t.m[10]=1,t.m[15]=1,t.m[0]=r,t.m[1]=i,t.m[4]=-i,t.m[5]=r,t.m[2]=0,t.m[3]=0,t.m[6]=0,t.m[7]=0,t.m[8]=0,t.m[9]=0,t.m[11]=0,t.m[12]=0,t.m[13]=0,t.m[14]=0},e.RotationAxis=function(t,i){var r=e.Zero();return e.RotationAxisToRef(t,i,r),r},e.RotationAxisToRef=function(e,t,i){var r=Math.sin(-t),n=Math.cos(-t),o=1-n;e.normalize(),i.m[0]=e.x*e.x*o+n,i.m[1]=e.x*e.y*o-e.z*r,i.m[2]=e.x*e.z*o+e.y*r,i.m[3]=0,i.m[4]=e.y*e.x*o+e.z*r,i.m[5]=e.y*e.y*o+n,i.m[6]=e.y*e.z*o-e.x*r,i.m[7]=0,i.m[8]=e.z*e.x*o-e.y*r,i.m[9]=e.z*e.y*o+e.x*r,i.m[10]=e.z*e.z*o+n,i.m[11]=0,i.m[15]=1},e.RotationYawPitchRoll=function(t,i,r){var n=new e;return e.RotationYawPitchRollToRef(t,i,r,n),n},e.RotationYawPitchRollToRef=function(e,t,i,r){h.RotationYawPitchRollToRef(e,t,i,this._tempQuaternion),this._tempQuaternion.toRotationMatrix(r)},e.Scaling=function(t,i,r){var n=e.Zero();return e.ScalingToRef(t,i,r,n),n},e.ScalingToRef=function(e,t,i,r){r.m[0]=e,r.m[1]=0,r.m[2]=0,r.m[3]=0,r.m[4]=0,r.m[5]=t,r.m[6]=0,r.m[7]=0,r.m[8]=0,r.m[9]=0,r.m[10]=i,r.m[11]=0,r.m[12]=0,r.m[13]=0,r.m[14]=0,r.m[15]=1},e.Translation=function(t,i,r){var n=e.Identity();return e.TranslationToRef(t,i,r,n),n},e.TranslationToRef=function(t,i,r,n){e.FromValuesToRef(1,0,0,0,0,1,0,0,0,0,1,0,t,i,r,1,n)},e.Lerp=function(t,i,r){for(var n=e.Zero(),o=0;16>o;o++)n.m[o]=t.m[o]*(1-r)+i.m[o]*r;return n},e.DecomposeLerp=function(t,i,r){var n=new o(0,0,0),s=new h,a=new o(0,0,0);t.decompose(n,s,a);var c=new o(0,0,0),l=new h,u=new o(0,0,0);i.decompose(c,l,u);var f=o.Lerp(n,c,r),d=h.Slerp(s,l,r),p=o.Lerp(a,u,r);return e.Compose(f,d,p)},e.LookAtLH=function(t,i,r){var n=e.Zero();return e.LookAtLHToRef(t,i,r,n),n},e.LookAtLHToRef=function(t,i,r,n){i.subtractToRef(t,this._zAxis),this._zAxis.normalize(),o.CrossToRef(r,this._zAxis,this._xAxis),0===this._xAxis.lengthSquared()?this._xAxis.x=1:this._xAxis.normalize(),o.CrossToRef(this._zAxis,this._xAxis,this._yAxis),this._yAxis.normalize();var s=-o.Dot(this._xAxis,t),a=-o.Dot(this._yAxis,t),h=-o.Dot(this._zAxis,t);return e.FromValuesToRef(this._xAxis.x,this._yAxis.x,this._zAxis.x,0,this._xAxis.y,this._yAxis.y,this._zAxis.y,0,this._xAxis.z,this._yAxis.z,this._zAxis.z,0,s,a,h,1,n)},e.OrthoLH=function(t,i,r,n){var o=e.Zero();return e.OrthoLHToRef(t,i,r,n,o),o},e.OrthoLHToRef=function(t,i,r,n,o){var s=2/t,a=2/i,h=1/(n-r),c=r/(r-n);e.FromValuesToRef(s,0,0,0,0,a,0,0,0,0,h,0,0,0,c,1,o)},e.OrthoOffCenterLH=function(t,i,r,n,o,s){var a=e.Zero();return e.OrthoOffCenterLHToRef(t,i,r,n,o,s,a),a},e.OrthoOffCenterLHToRef=function(e,t,i,r,n,o,s){s.m[0]=2/(t-e),s.m[1]=s.m[2]=s.m[3]=0,s.m[5]=2/(r-i),s.m[4]=s.m[6]=s.m[7]=0,s.m[10]=-1/(n-o),s.m[8]=s.m[9]=s.m[11]=0,s.m[12]=(e+t)/(e-t),s.m[13]=(r+i)/(i-r),s.m[14]=n/(n-o),s.m[15]=1},e.PerspectiveLH=function(t,i,r,n){var o=e.Zero();return o.m[0]=2*r/t,o.m[1]=o.m[2]=o.m[3]=0,o.m[5]=2*r/i,o.m[4]=o.m[6]=o.m[7]=0,o.m[10]=-n/(r-n),o.m[8]=o.m[9]=0,o.m[11]=1,o.m[12]=o.m[13]=o.m[15]=0,o.m[14]=r*n/(r-n),o},e.PerspectiveFovLH=function(t,i,r,n){var o=e.Zero();return e.PerspectiveFovLHToRef(t,i,r,n,o),o},e.PerspectiveFovLHToRef=function(e,t,i,r,n,o){void 0===o&&(o=!0);var s=1/Math.tan(.5*e);o?n.m[0]=s/t:n.m[0]=s,n.m[1]=n.m[2]=n.m[3]=0,o?n.m[5]=s:n.m[5]=s*t,n.m[4]=n.m[6]=n.m[7]=0,n.m[8]=n.m[9]=0,n.m[10]=-r/(i-r),n.m[11]=1,n.m[12]=n.m[13]=n.m[15]=0,n.m[14]=i*r/(i-r)},e.GetFinalMatrix=function(t,i,r,n,o,s){var a=t.width,h=t.height,c=t.x,l=t.y,u=e.FromValues(a/2,0,0,0,0,-h/2,0,0,0,0,s-o,0,c+a/2,h/2+l,o,1);return i.multiply(r).multiply(n).multiply(u)},e.GetAsMatrix2x2=function(e){return new Float32Array([e.m[0],e.m[1],e.m[4],e.m[5]])},e.GetAsMatrix3x3=function(e){return new Float32Array([e.m[0],e.m[1],e.m[2],e.m[4],e.m[5],e.m[6],e.m[8],e.m[9],e.m[10]])},e.Transpose=function(t){var i=new e;return i.m[0]=t.m[0],i.m[1]=t.m[4],i.m[2]=t.m[8],i.m[3]=t.m[12],i.m[4]=t.m[1],i.m[5]=t.m[5],i.m[6]=t.m[9],i.m[7]=t.m[13],i.m[8]=t.m[2],i.m[9]=t.m[6],i.m[10]=t.m[10],i.m[11]=t.m[14],i.m[12]=t.m[3],i.m[13]=t.m[7],i.m[14]=t.m[11],i.m[15]=t.m[15],i},e.Reflection=function(t){var i=new e;return e.ReflectionToRef(t,i),i},e.ReflectionToRef=function(e,t){e.normalize();var i=e.normal.x,r=e.normal.y,n=e.normal.z,o=-2*i,s=-2*r,a=-2*n;t.m[0]=o*i+1,t.m[1]=s*i,t.m[2]=a*i,t.m[3]=0,t.m[4]=o*r,t.m[5]=s*r+1,t.m[6]=a*r,t.m[7]=0,t.m[8]=o*n,t.m[9]=s*n,t.m[10]=a*n+1,t.m[11]=0,t.m[12]=o*e.d,t.m[13]=s*e.d,t.m[14]=a*e.d,t.m[15]=1},e._tempQuaternion=new h,e._xAxis=o.Zero(),e._yAxis=o.Zero(),e._zAxis=o.Zero(),e}();e.Matrix=c;var l=function(){function e(e,t,i,r){this.normal=new o(e,t,i),this.d=r}return e.prototype.asArray=function(){return[this.normal.x,this.normal.y,this.normal.z,this.d]},e.prototype.clone=function(){return new e(this.normal.x,this.normal.y,this.normal.z,this.d)},e.prototype.getClassName=function(){return"Plane"},e.prototype.getHashCode=function(){var e=this.normal.getHashCode();return e=397*e^(this.d||0)},e.prototype.normalize=function(){var e=Math.sqrt(this.normal.x*this.normal.x+this.normal.y*this.normal.y+this.normal.z*this.normal.z),t=0;return 0!==e&&(t=1/e),this.normal.x*=t,this.normal.y*=t,this.normal.z*=t,this.d*=t,this},e.prototype.transform=function(t){var i=c.Transpose(t),r=this.normal.x,n=this.normal.y,o=this.normal.z,s=this.d,a=r*i.m[0]+n*i.m[1]+o*i.m[2]+s*i.m[3],h=r*i.m[4]+n*i.m[5]+o*i.m[6]+s*i.m[7],l=r*i.m[8]+n*i.m[9]+o*i.m[10]+s*i.m[11],u=r*i.m[12]+n*i.m[13]+o*i.m[14]+s*i.m[15];return new e(a,h,l,u)},e.prototype.dotCoordinate=function(e){return this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z+this.d},e.prototype.copyFromPoints=function(e,t,i){var r,n=t.x-e.x,o=t.y-e.y,s=t.z-e.z,a=i.x-e.x,h=i.y-e.y,c=i.z-e.z,l=o*c-s*h,u=s*a-n*c,f=n*h-o*a,d=Math.sqrt(l*l+u*u+f*f);return r=0!==d?1/d:0,this.normal.x=l*r,this.normal.y=u*r,this.normal.z=f*r,this.d=-(this.normal.x*e.x+this.normal.y*e.y+this.normal.z*e.z),this},e.prototype.isFrontFacingTo=function(e,t){var i=o.Dot(this.normal,e);return t>=i},e.prototype.signedDistanceTo=function(e){return o.Dot(e,this.normal)+this.d},e.FromArray=function(t){return new e(t[0],t[1],t[2],t[3])},e.FromPoints=function(t,i,r){var n=new e(0,0,0,0);return n.copyFromPoints(t,i,r),n},e.FromPositionAndNormal=function(t,i){var r=new e(0,0,0,0);return i.normalize(),r.normal=i,r.d=-(i.x*t.x+i.y*t.y+i.z*t.z),r},e.SignedDistanceToPlaneFromPositionAndNormal=function(e,t,i){var r=-(t.x*e.x+t.y*e.y+t.z*e.z);return o.Dot(i,t)+r},e}();e.Plane=l;var u=function(){function e(e,t,i,r){this.x=e,this.y=t,this.width=i,this.height=r}return e.prototype.toGlobal=function(t,i){return new e(this.x*t,this.y*i,this.width*t,this.height*i)},e}();e.Viewport=u;var f=function(){function e(){}return e.GetPlanes=function(t){for(var i=[],r=0;6>r;r++)i.push(new l(0,0,0,0));return e.GetPlanesToRef(t,i),i},e.GetPlanesToRef=function(e,t){t[0].normal.x=e.m[3]+e.m[2],t[0].normal.y=e.m[7]+e.m[6],t[0].normal.z=e.m[11]+e.m[10],t[0].d=e.m[15]+e.m[14],t[0].normalize(),t[1].normal.x=e.m[3]-e.m[2],t[1].normal.y=e.m[7]-e.m[6],t[1].normal.z=e.m[11]-e.m[10],t[1].d=e.m[15]-e.m[14],t[1].normalize(),t[2].normal.x=e.m[3]+e.m[0],t[2].normal.y=e.m[7]+e.m[4],t[2].normal.z=e.m[11]+e.m[8],t[2].d=e.m[15]+e.m[12],t[2].normalize(),t[3].normal.x=e.m[3]-e.m[0],t[3].normal.y=e.m[7]-e.m[4],t[3].normal.z=e.m[11]-e.m[8],t[3].d=e.m[15]-e.m[12],t[3].normalize(),t[4].normal.x=e.m[3]-e.m[1],t[4].normal.y=e.m[7]-e.m[5],t[4].normal.z=e.m[11]-e.m[9],t[4].d=e.m[15]-e.m[13],t[4].normalize(),t[5].normal.x=e.m[3]+e.m[1],t[5].normal.y=e.m[7]+e.m[5],t[5].normal.z=e.m[11]+e.m[9],t[5].d=e.m[15]+e.m[13],t[5].normalize()},e}();e.Frustum=f,function(e){e[e.LOCAL=0]="LOCAL",e[e.WORLD=1]="WORLD"}(e.Space||(e.Space={}));var d=(e.Space,function(){function e(){}return e.X=new o(1,0,0),e.Y=new o(0,1,0),e.Z=new o(0,0,1),e}());e.Axis=d;var p=function(){function e(){}return e.interpolate=function(e,t,i,r,n){for(var o=1-3*r+3*t,s=3*r-6*t,a=3*t,h=e,c=0;5>c;c++){var l=h*h,u=l*h,f=o*u+s*l+a*h,d=1/(3*o*l+2*s*h+a);h-=(f-e)*d,h=Math.min(1,Math.max(0,h))}return 3*Math.pow(1-h,2)*h*i+3*(1-h)*Math.pow(h,2)*n+Math.pow(h,3)},e}();e.BezierCurve=p,function(e){e[e.CW=0]="CW",e[e.CCW=1]="CCW"}(e.Orientation||(e.Orientation={}));var _=e.Orientation,g=function(){function e(e){var t=this;this.degrees=function(){return 180*t._radians/Math.PI},this.radians=function(){return t._radians},this._radians=e,this._radians<0&&(this._radians+=2*Math.PI)}return e.BetweenTwoPoints=function(t,i){var r=i.subtract(t),n=Math.atan2(r.y,r.x);return new e(n)},e.FromRadians=function(t){return new e(t)},e.FromDegrees=function(t){return new e(t*Math.PI/180)},e}();e.Angle=g;var m=function(){function e(e,t,i){this.startPoint=e,this.midPoint=t,this.endPoint=i;var r=Math.pow(t.x,2)+Math.pow(t.y,2),o=(Math.pow(e.x,2)+Math.pow(e.y,2)-r)/2,s=(r-Math.pow(i.x,2)-Math.pow(i.y,2))/2,a=(e.x-t.x)*(t.y-i.y)-(t.x-i.x)*(e.y-t.y);this.centerPoint=new n((o*(t.y-i.y)-s*(e.y-t.y))/a,((e.x-t.x)*s-(t.x-i.x)*o)/a),this.radius=this.centerPoint.subtract(this.startPoint).length(),this.startAngle=g.BetweenTwoPoints(this.centerPoint,this.startPoint);var h=this.startAngle.degrees(),c=g.BetweenTwoPoints(this.centerPoint,this.midPoint).degrees(),l=g.BetweenTwoPoints(this.centerPoint,this.endPoint).degrees();c-h>180&&(c-=360),-180>c-h&&(c+=360),l-c>180&&(l-=360),-180>l-c&&(l+=360),this.orientation=0>c-h?_.CW:_.CCW,this.angle=g.FromDegrees(this.orientation===_.CW?h-l:l-h)}return e}();e.Arc2=m;var v=function(){function e(e,t){this._points=new Array,this._length=0,this.closed=!1,this._points.push(new n(e,t))}return e.prototype.addLineTo=function(e,t){if(closed)return this;var i=new n(e,t),r=this._points[this._points.length-1];return this._points.push(i),this._length+=i.subtract(r).length(),this},e.prototype.addArcTo=function(e,t,i,r,o){if(void 0===o&&(o=36),closed)return this;var s=this._points[this._points.length-1],a=new n(e,t),h=new n(i,r),c=new m(s,a,h),l=c.angle.radians()/o;c.orientation===_.CW&&(l*=-1);for(var u=c.startAngle.radians()+l,f=0;o>f;f++){var d=Math.cos(u)*c.radius+c.centerPoint.x,p=Math.sin(u)*c.radius+c.centerPoint.y;this.addLineTo(d,p),u+=l}return this},e.prototype.close=function(){return this.closed=!0,this},e.prototype.length=function(){var e=this._length;if(!this.closed){var t=this._points[this._points.length-1],i=this._points[0];e+=i.subtract(t).length()}return e},e.prototype.getPoints=function(){return this._points},e.prototype.getPointAtLengthPosition=function(e){if(0>e||e>1)return n.Zero();for(var t=e*this.length(),i=0,r=0;r=i&&c>=t){var l=h.normalize(),u=t-i;return new n(s.x+l.x*u,s.y+l.y*u)}i=c}return n.Zero()},e.StartingAt=function(t,i){return new e(t,i)},e}();e.Path2=v;var y=function(){function i(e,t,i){this.path=e,this._curve=new Array,this._distances=new Array,this._tangents=new Array,this._normals=new Array,this._binormals=new Array;for(var r=0;rc;c++)n=this._getLastNonNullVector(c),t-1>c&&(s=this._getFirstNonNullVector(c),this._tangents[c]=n.add(s),this._tangents[c].normalize()),this._distances[c]=this._distances[c-1]+n.length(),a=this._tangents[c],h=this._binormals[c-1],this._normals[c]=o.Cross(h,a),this._raw||this._normals[c].normalize(),this._binormals[c]=o.Cross(a,this._normals[c]),this._raw||this._binormals[c].normalize()},i.prototype._getFirstNonNullVector=function(e){for(var t=1,i=this._curve[e+t].subtract(this._curve[e]);0===i.length()&&e+t+1t+1;)t++,i=this._curve[e].subtract(this._curve[e-t]);return i},i.prototype._normalVector=function(i,r,n){var s;if(void 0===n||null===n){var a;t.WithinEpsilon(r.y,1,e.Epsilon)?t.WithinEpsilon(r.x,1,e.Epsilon)?t.WithinEpsilon(r.z,1,e.Epsilon)||(a=new o(0,0,1)):a=new o(1,0,0):a=new o(0,-1,0),s=o.Cross(r,a)}else s=o.Cross(r,n),o.CrossToRef(s,r,s);return s.normalize(),s},i}();e.Path3D=y;var x=function(){function e(e){this._length=0,this._points=e,this._length=this._computeLength(e)}return e.CreateQuadraticBezier=function(t,i,r,n){n=n>2?n:3;for(var s=new Array,a=function(e,t,i,r){var n=(1-e)*(1-e)*t+2*e*(1-e)*i+e*e*r;return n},h=0;n>=h;h++)s.push(new o(a(h/n,t.x,i.x,r.x),a(h/n,t.y,i.y,r.y),a(h/n,t.z,i.z,r.z)));return new e(s)},e.CreateCubicBezier=function(t,i,r,n,s){s=s>3?s:4;for(var a=new Array,h=function(e,t,i,r,n){var o=(1-e)*(1-e)*(1-e)*t+3*e*(1-e)*(1-e)*i+3*e*e*(1-e)*r+e*e*e*n;return o},c=0;s>=c;c++)a.push(new o(h(c/s,t.x,i.x,r.x,n.x),h(c/s,t.y,i.y,r.y,n.y),h(c/s,t.z,i.z,r.z,n.z)));return new e(a)},e.CreateHermiteSpline=function(t,i,r,n,s){for(var a=new Array,h=1/s,c=0;s>=c;c++)a.push(o.Hermite(t,i,r,n,c*h));return new e(a)},e.prototype.getPoints=function(){return this._points},e.prototype.length=function(){return this._length},e.prototype["continue"]=function(t){for(var i=this._points[this._points.length-1],r=this._points.slice(),n=t.getPoints(),o=1;o0},e.prototype.clear=function(){this._observers=new Array},e.prototype.clone=function(){var t=new e;return t._observers=this._observers.slice(0),t},e}();e.Observable=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,i){this.idbFactory=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,this.callbackManifestChecked=i,this.currentSceneUrl=t.ReturnFullUrlLocation(e),this.db=null,this.enableSceneOffline=!1,this.enableTexturesOffline=!1,this.manifestVersionFound=0,this.mustUpdateRessources=!1,this.hasReachedQuota=!1,t.IDBStorageEnabled?this.checkManifestFile():this.callbackManifestChecked(!0)}return t.prototype.checkManifestFile=function(){function t(){r.enableSceneOffline=!1,r.enableTexturesOffline=!1,r.callbackManifestChecked(!1)}var i=this,r=this,n=!1,o=this.currentSceneUrl+".manifest",s=new XMLHttpRequest;navigator.onLine&&(n=!0,o=o+(null==o.match(/\?/)?"?":"&")+(new Date).getTime()),s.open("GET",o,!0),s.addEventListener("load",function(){if(200===s.status||e.Tools.ValidateXHRData(s,1))try{var r=JSON.parse(s.response);i.enableSceneOffline=r.enableSceneOffline,i.enableTexturesOffline=r.enableTexturesOffline,r.version&&!isNaN(parseInt(r.version))&&(i.manifestVersionFound=r.version),i.callbackManifestChecked&&i.callbackManifestChecked(!0)}catch(n){t()}else t()},!1),s.addEventListener("error",function(e){if(n){n=!1;var r=i.currentSceneUrl+".manifest";s.open("GET",r,!0),s.send()}else t()},!1);try{s.send()}catch(a){e.Tools.Error("Error on XHR send request."),r.callbackManifestChecked(!1)}},t.prototype.openAsync=function(t,i){function r(){o.isSupported=!1,i&&i()}var n=this,o=this;if(this.idbFactory&&(this.enableSceneOffline||this.enableTexturesOffline))if(this.db)t&&t();else{this.hasReachedQuota=!1,this.isSupported=!0;var s=this.idbFactory.open("babylonjs",1);s.onerror=function(e){r()},s.onblocked=function(t){e.Tools.Error("IDB request blocked. Please reload the page."),r()},s.onsuccess=function(e){n.db=s.result,t()},s.onupgradeneeded=function(t){n.db=t.target.result;try{n.db.createObjectStore("scenes",{keyPath:"sceneUrl"}),n.db.createObjectStore("versions",{keyPath:"sceneUrl"}),n.db.createObjectStore("textures",{keyPath:"textureUrl"})}catch(i){e.Tools.Error("Error while creating object stores. Exception: "+i.message),r()}}}else this.isSupported=!1,i&&i()},t.prototype.loadImageFromDB=function(e,i){var r=this,n=t.ReturnFullUrlLocation(e),o=function(){r.hasReachedQuota||null===r.db?i.src=e:r._saveImageIntoDBAsync(n,i)};this.mustUpdateRessources?o():this._loadImageFromDBAsync(n,i,o)},t.prototype._loadImageFromDBAsync=function(t,i,r){if(this.isSupported&&null!==this.db){var n,o=this.db.transaction(["textures"]);o.onabort=function(e){i.src=t},o.oncomplete=function(o){var s;if(n){var a=window.URL||window.webkitURL;s=a.createObjectURL(n.data,{oneTimeOnly:!0}),i.onerror=function(){e.Tools.Error("Error loading image from blob URL: "+s+" switching back to web url: "+t),i.src=t},i.src=s}else r()};var s=o.objectStore("textures").get(t);s.onsuccess=function(e){n=e.target.result},s.onerror=function(r){e.Tools.Error("Error loading texture "+t+" from DB."),i.src=t}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i.src=t},t.prototype._saveImageIntoDBAsync=function(i,r){var n=this;if(this.isSupported){var o=function(){var e;if(s){var t=window.URL||window.webkitURL;try{e=t.createObjectURL(s,{oneTimeOnly:!0})}catch(i){e=t.createObjectURL(s)}}r.src=e};if(t.IsUASupportingBlobStorage){var s,a=new XMLHttpRequest;a.open("GET",i,!0),a.responseType="blob",a.addEventListener("load",function(){if(200===a.status){s=a.response;var e=n.db.transaction(["textures"],"readwrite");e.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(t){}o()},e.oncomplete=function(e){o()};var h={textureUrl:i,data:s};try{var c=e.objectStore("textures").put(h);c.onsuccess=function(e){},c.onerror=function(e){o()}}catch(l){25===l.code&&(t.IsUASupportingBlobStorage=!1),r.src=i}}else r.src=i},!1),a.addEventListener("error",function(t){e.Tools.Error("Error in XHR request in BABYLON.Database."),r.src=i},!1),a.send()}else r.src=i}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),r.src=i},t.prototype._checkVersionFromDB=function(e,t){var i=this,r=function(r){i._saveVersionIntoDBAsync(e,t)};this._loadVersionFromDBAsync(e,t,r)},t.prototype._loadVersionFromDBAsync=function(t,i,r){var n=this;if(this.isSupported){var o;try{var s=this.db.transaction(["versions"]);s.oncomplete=function(e){o?n.manifestVersionFound>o.data?(n.mustUpdateRessources=!0,r()):i(o.data):(n.mustUpdateRessources=!0,r())},s.onabort=function(e){i(-1)};var a=s.objectStore("versions").get(t);a.onsuccess=function(e){o=e.target.result},a.onerror=function(r){e.Tools.Error("Error loading version for scene "+t+" from DB."),i(-1)}}catch(h){e.Tools.Error("Error while accessing 'versions' object store (READ OP). Exception: "+h.message),i(-1)}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i(-1)},t.prototype._saveVersionIntoDBAsync=function(t,i){var r=this;if(this.isSupported&&!this.hasReachedQuota)try{var n=this.db.transaction(["versions"],"readwrite");n.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(r.hasReachedQuota=!0)}catch(t){}i(-1)},n.oncomplete=function(e){i(r.manifestVersionFound)};var o={sceneUrl:t,data:this.manifestVersionFound},s=n.objectStore("versions").put(o);s.onsuccess=function(e){},s.onerror=function(t){e.Tools.Error("Error in DB add version request in BABYLON.Database.")}}catch(a){e.Tools.Error("Error while accessing 'versions' object store (WRITE OP). Exception: "+a.message),i(-1)}else i(-1)},t.prototype.loadFileFromDB=function(e,i,r,n,o){var s=this,a=t.ReturnFullUrlLocation(e),h=function(e){s._saveFileIntoDBAsync(a,i,r)};this._checkVersionFromDB(a,function(e){-1!==e?s.mustUpdateRessources?s._saveFileIntoDBAsync(a,i,r,o):s._loadFileFromDBAsync(a,i,h,o):n()})},t.prototype._loadFileFromDBAsync=function(t,i,r,n){if(this.isSupported){var o;o=-1!==t.indexOf(".babylon")?"scenes":"textures";var s,a=this.db.transaction([o]);a.oncomplete=function(e){s?i(s.data):r()},a.onabort=function(e){r()};var h=a.objectStore(o).get(t);h.onsuccess=function(e){s=e.target.result},h.onerror=function(i){e.Tools.Error("Error loading file "+t+" from DB."),r()}}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.prototype._saveFileIntoDBAsync=function(t,i,r,n){var o=this;if(this.isSupported){var s;s=-1!==t.indexOf(".babylon")?"scenes":"textures";var a,h=new XMLHttpRequest;h.open("GET",t,!0),n&&(h.responseType="arraybuffer"),h.onprogress=r,h.addEventListener("load",function(){if(200===h.status||e.Tools.ValidateXHRData(h,n?6:1))if(a=n?h.response:h.responseText,o.hasReachedQuota)i(a);else{var r=o.db.transaction([s],"readwrite");r.onabort=function(e){try{e.srcElement.error&&"QuotaExceededError"===e.srcElement.error.name&&(this.hasReachedQuota=!0)}catch(t){}i(a)},r.oncomplete=function(e){i(a)};var c;c="scenes"===s?{sceneUrl:t,data:a,version:o.manifestVersionFound}:{textureUrl:t,data:a};try{var l=r.objectStore(s).put(c);l.onsuccess=function(e){},l.onerror=function(t){e.Tools.Error("Error in DB add file request in BABYLON.Database.")}}catch(u){i(a)}}else i()},!1),h.addEventListener("error",function(t){e.Tools.Error("error on XHR request."),i()},!1),h.send()}else e.Tools.Error("Error: IndexedDB not supported by your browser or BabylonJS Database is not open."),i()},t.IsUASupportingBlobStorage=!0,t.IDBStorageEnabled=!0,t.parseURL=function(e){var t=document.createElement("a");t.href=e;var i=e.substring(0,e.lastIndexOf("#")),r=e.substring(i.lastIndexOf("/")+1,e.length),n=e.substring(0,e.indexOf(r,0));return n},t.ReturnFullUrlLocation=function(e){return-1===e.indexOf("http:/")?t.parseURL(window.location.href)+e:e},t}();e.Database=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(t){var i=function(){function t(){}return t.GetTGAHeader=function(e){var t=0,i={id_length:e[t++],colormap_type:e[t++],image_type:e[t++],
+colormap_index:e[t++]|e[t++]<<8,colormap_length:e[t++]|e[t++]<<8,colormap_size:e[t++],origin:[e[t++]|e[t++]<<8,e[t++]|e[t++]<<8],width:e[t++]|e[t++]<<8,height:e[t++]|e[t++]<<8,pixel_size:e[t++],flags:e[t++]};return i},t.UploadContent=function(i,r){if(r.length<19)return void e.Tools.Error("Unable to load TGA file - Not enough data to contain header");var n=18,o=t.GetTGAHeader(r);if(o.id_length+n>r.length)return void e.Tools.Error("Unable to load TGA file - Not enough data");n+=o.id_length;var s=!1,a=!1,h=!1,c=!1;switch(o.image_type){case t._TYPE_RLE_INDEXED:s=!0;case t._TYPE_INDEXED:a=!0;break;case t._TYPE_RLE_RGB:s=!0;case t._TYPE_RGB:h=!0;break;case t._TYPE_RLE_GREY:s=!0;case t._TYPE_GREY:c=!0}var l,u,f=(15&o.flags,o.pixel_size>>3),d=o.width*o.height*f;if(a&&(u=r.subarray(n,n+=o.colormap_length*(o.colormap_size>>3))),s){l=new Uint8Array(d);for(var p,_,g,m=0,v=new Uint8Array(f);d>n&&d>m;)if(p=r[n++],_=(127&p)+1,128&p){for(g=0;f>g;++g)v[g]=r[n++];for(g=0;_>g;++g)l.set(v,m+g*f);m+=f*_}else{for(_*=f,g=0;_>g;++g)l[m+g]=r[n++];m+=_}}else l=r.subarray(n,n+=a?o.width*o.height:d);var y,x,b,P,A,E;switch((o.flags&t._ORIGIN_MASK)>>t._ORIGIN_SHIFT){default:case t._ORIGIN_UL:y=0,b=1,E=o.width,x=0,P=1,A=o.height;break;case t._ORIGIN_BL:y=0,b=1,E=o.width,x=o.height-1,P=-1,A=-1;break;case t._ORIGIN_UR:y=o.width-1,b=-1,E=-1,x=0,P=1,A=o.height;break;case t._ORIGIN_BR:y=o.width-1,b=-1,E=-1,x=o.height-1,P=-1,A=-1}var T="_getImageData"+(c?"Grey":"")+o.pixel_size+"bits",C=t[T](o,u,l,x,P,A,y,b,E);i.texImage2D(i.TEXTURE_2D,0,i.RGBA,o.width,o.height,0,i.RGBA,i.UNSIGNED_BYTE,C)},t._getImageData8bits=function(e,t,i,r,n,o,s,a,h){var c,l,u,f=i,d=t,p=e.width,_=e.height,g=0,m=new Uint8Array(p*_*4);for(u=r;u!==o;u+=n)for(l=s;l!==h;l+=a,g++)c=f[g],m[4*(l+p*u)+3]=255,m[4*(l+p*u)+2]=d[3*c+0],m[4*(l+p*u)+1]=d[3*c+1],m[4*(l+p*u)+0]=d[3*c+2];return m},t._getImageData16bits=function(e,t,i,r,n,o,s,a,h){var c,l,u,f=i,d=e.width,p=e.height,_=0,g=new Uint8Array(d*p*4);for(u=r;u!==o;u+=n)for(l=s;l!==h;l+=a,_+=2)c=f[_+0]+(f[_+1]<<8),g[4*(l+d*u)+0]=(31744&c)>>7,g[4*(l+d*u)+1]=(992&c)>>2,g[4*(l+d*u)+2]=(31&c)>>3,g[4*(l+d*u)+3]=32768&c?0:255;return g},t._getImageData24bits=function(e,t,i,r,n,o,s,a,h){var c,l,u=i,f=e.width,d=e.height,p=0,_=new Uint8Array(f*d*4);for(l=r;l!==o;l+=n)for(c=s;c!==h;c+=a,p+=3)_[4*(c+f*l)+3]=255,_[4*(c+f*l)+2]=u[p+0],_[4*(c+f*l)+1]=u[p+1],_[4*(c+f*l)+0]=u[p+2];return _},t._getImageData32bits=function(e,t,i,r,n,o,s,a,h){var c,l,u=i,f=e.width,d=e.height,p=0,_=new Uint8Array(f*d*4);for(l=r;l!==o;l+=n)for(c=s;c!==h;c+=a,p+=4)_[4*(c+f*l)+2]=u[p+0],_[4*(c+f*l)+1]=u[p+1],_[4*(c+f*l)+0]=u[p+2],_[4*(c+f*l)+3]=u[p+3];return _},t._getImageDataGrey8bits=function(e,t,i,r,n,o,s,a,h){var c,l,u,f=i,d=e.width,p=e.height,_=0,g=new Uint8Array(d*p*4);for(u=r;u!==o;u+=n)for(l=s;l!==h;l+=a,_++)c=f[_],g[4*(l+d*u)+0]=c,g[4*(l+d*u)+1]=c,g[4*(l+d*u)+2]=c,g[4*(l+d*u)+3]=255;return g},t._getImageDataGrey16bits=function(e,t,i,r,n,o,s,a,h){var c,l,u=i,f=e.width,d=e.height,p=0,_=new Uint8Array(f*d*4);for(l=r;l!==o;l+=n)for(c=s;c!==h;c+=a,p+=2)_[4*(c+f*l)+0]=u[p+0],_[4*(c+f*l)+1]=u[p+0],_[4*(c+f*l)+2]=u[p+0],_[4*(c+f*l)+3]=u[p+1];return _},t._TYPE_NO_DATA=0,t._TYPE_INDEXED=1,t._TYPE_RGB=2,t._TYPE_GREY=3,t._TYPE_RLE_INDEXED=9,t._TYPE_RLE_RGB=10,t._TYPE_RLE_GREY=11,t._ORIGIN_MASK=48,t._ORIGIN_SHIFT=4,t._ORIGIN_BL=0,t._ORIGIN_BR=1,t._ORIGIN_UL=2,t._ORIGIN_UR=3,t}();t.TGATools=i}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(t){this.length=0,this._duplicateId=0,this.data=new Array(t),this._id=e._GlobalId++}return e.prototype.push=function(e){this.data[this.length++]=e,this.length>this.data.length&&(this.data.length*=2),e.__smartArrayFlags||(e.__smartArrayFlags={}),e.__smartArrayFlags[this._id]=this._duplicateId},e.prototype.pushNoDuplicate=function(e){return e.__smartArrayFlags&&e.__smartArrayFlags[this._id]===this._duplicateId?!1:(this.push(e),!0)},e.prototype.sort=function(e){this.data.sort(e)},e.prototype.reset=function(){this.length=0,this._duplicateId++},e.prototype.concat=function(e){if(0!==e.length){this.length+e.length>this.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;tthis.data.length&&(this.data.length=2*(this.length+e.length));for(var t=0;t=this.length?-1:t},e._GlobalId=0,e}();e.SmartArray=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this._count=0,this._data={}}return e.prototype.get=function(e){var t=this._data[e];return void 0!==t?t:void 0},e.prototype.getOrAddWithFactory=function(e,t){var i=this.get(e);return void 0!==i?i:(i=t(e),i&&this.add(e,i),i)},e.prototype.getOrAdd=function(e,t){var i=this.get(e);return void 0!==i?i:(this.add(e,t),t)},e.prototype.contains=function(e){return void 0!==this._data[e]},e.prototype.add=function(e,t){return void 0!==this._data[e]?!1:(this._data[e]=t,++this._count,!0)},e.prototype.set=function(e,t){return void 0===this._data[e]?!1:(this._data[e]=t,!0)},e.prototype.remove=function(e){return this.contains(e)?(delete this._data[e],--this._count,!0):!1},e.prototype.clear=function(){this._data={},this._count=0},Object.defineProperty(e.prototype,"count",{get:function(){return this._count},enumerable:!0,configurable:!0}),e.prototype.forEach=function(e){for(var t in this._data){var i=this._data[t];e(t,i)}},e.prototype.first=function(e){for(var t in this._data){var i=this._data[t],r=e(t,i);if(r)return r}return null},e}();e.StringDictionary=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){function t(e){return function(t){t.__bjsclassName__=e}}var i,r=function(t,i){return t?t instanceof e.Mesh?null:t instanceof e.SubMesh?t.clone(i):t.clone?t.clone():null:null},n=function(){function t(){}return t.Instantiate=function(e){for(var t=e.split("."),i=window||this,r=0,n=t.length;n>r;r++)i=i[t[r]];return"function"!=typeof i?null:i},t.SetImmediate=function(e){window.setImmediate?window.setImmediate(e):setTimeout(e,1)},t.IsExponentOfTwo=function(e){var t=1;do t*=2;while(e>t);return t===e},t.GetExponentOfTwo=function(e,t){var i=1;do i*=2;while(e>i);return i>t&&(i=t),i},t.GetFilename=function(e){var t=e.lastIndexOf("/");return 0>t?e:e.substring(t+1)},t.GetDOMTextContent=function(e){for(var t="",i=e.firstChild;i;)3===i.nodeType&&(t+=i.textContent),i=i.nextSibling;return t},t.ToDegrees=function(e){return 180*e/Math.PI},t.ToRadians=function(e){return e*Math.PI/180},t.EncodeArrayBufferTobase64=function(e){for(var t,i,r,n,o,s,a,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c="",l=0,u=new Uint8Array(e);l>2,o=(3&t)<<4|i>>4,s=(15&i)<<2|r>>6,a=63&r,isNaN(i)?s=a=64:isNaN(r)&&(a=64),c+=h.charAt(n)+h.charAt(o)+h.charAt(s)+h.charAt(a);return"data:image/png;base64,"+c},t.ExtractMinAndMaxIndexed=function(t,i,r,n,o){void 0===o&&(o=null);for(var s=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),a=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE),h=r;r+n>h;h++){var c=new e.Vector3(t[3*i[h]],t[3*i[h]+1],t[3*i[h]+2]);s=e.Vector3.Minimize(c,s),a=e.Vector3.Maximize(c,a)}return o&&(s.x-=s.x*o.x+o.y,s.y-=s.y*o.x+o.y,s.z-=s.z*o.x+o.y,a.x+=a.x*o.x+o.y,a.y+=a.y*o.x+o.y,a.z+=a.z*o.x+o.y),{minimum:s,maximum:a}},t.ExtractMinAndMax=function(t,i,r,n,o){void 0===n&&(n=null);var s=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),a=new e.Vector3(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);o||(o=3);for(var h=i;i+r>h;h++){var c=new e.Vector3(t[h*o],t[h*o+1],t[h*o+2]);s=e.Vector3.Minimize(c,s),a=e.Vector3.Maximize(c,a)}return n&&(s.x-=s.x*n.x+n.y,s.y-=s.y*n.x+n.y,s.z-=s.z*n.x+n.y,a.x+=a.x*n.x+n.y,a.y+=a.y*n.x+n.y,a.z+=a.z*n.x+n.y),{minimum:s,maximum:a}},t.Vector2ArrayFeeder=function(t){return function(i){var r=void 0!==t.BYTES_PER_ELEMENT,n=r?t.length/2:t.length;if(i>=n)return null;if(r){var o=t;return new e.Vector2(o[2*i+0],o[2*i+1])}var s=t;return s[i]}},t.ExtractMinAndMaxVector2=function(t,i){void 0===i&&(i=null);for(var r=new e.Vector2(Number.MAX_VALUE,Number.MAX_VALUE),n=new e.Vector2(-Number.MAX_VALUE,-Number.MAX_VALUE),o=0,s=t(o++);s;)r=e.Vector2.Minimize(s,r),n=e.Vector2.Maximize(s,n),s=t(o++);return i&&(r.x-=r.x*i.x+i.y,r.y-=r.y*i.x+i.y,n.x+=n.x*i.x+i.y,n.y+=n.y*i.x+i.y),{minimum:r,maximum:n}},t.MakeArray=function(e,t){return t===!0||void 0!==e&&null!=e?Array.isArray(e)?e:[e]:void 0},t.GetPointerPrefix=function(){var e="pointer";return window.PointerEvent||navigator.pointerEnabled||(e="mouse"),e},t.QueueNewFrame=function(e){window.requestAnimationFrame?window.requestAnimationFrame(e):window.msRequestAnimationFrame?window.msRequestAnimationFrame(e):window.webkitRequestAnimationFrame?window.webkitRequestAnimationFrame(e):window.mozRequestAnimationFrame?window.mozRequestAnimationFrame(e):window.oRequestAnimationFrame?window.oRequestAnimationFrame(e):window.setTimeout(e,16)},t.RequestFullscreen=function(e,t){var i=e.requestFullscreen||e.msRequestFullscreen||e.webkitRequestFullscreen||e.mozRequestFullScreen;i&&i.call(e,t)},t.ExitFullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen?document.webkitCancelFullScreen():document.msCancelFullScreen&&document.msCancelFullScreen()},t.CleanUrl=function(e){return e=e.replace(/#/gm,"%23")},t.LoadImage=function(i,r,n,o){i instanceof ArrayBuffer&&(i=t.EncodeArrayBufferTobase64(i)),i=t.CleanUrl(i);var s=new Image;if("data:"!==i.substr(0,5)&&t.CorsBehavior)switch(typeof t.CorsBehavior){case"function":var a=t.CorsBehavior(i);a&&(s.crossOrigin=a);break;case"string":default:s.crossOrigin=t.CorsBehavior}s.onload=function(){r(s)},s.onerror=function(e){t.Error("Error while trying to load texture: "+i),t.UseFallbackTexture?(s.src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QBmRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAAQAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMC41AP/bAEMABAIDAwMCBAMDAwQEBAQFCQYFBQUFCwgIBgkNCw0NDQsMDA4QFBEODxMPDAwSGBITFRYXFxcOERkbGRYaFBYXFv/bAEMBBAQEBQUFCgYGChYPDA8WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFv/AABEIAQABAAMBIgACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APH6KKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76CiiigD5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BQooooA+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/voKKKKAPl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FCiiigD6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++gooooA+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gUKKKKAPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76Pl+iiivuj+BT6gooor4U/vo+X6KKK+6P4FPqCiiivhT++j5fooor7o/gU+oKKKK+FP76P//Z",r(s)):n()};var h=function(){s.src=i},c=function(){o.loadImageFromDB(i,s)};if("data:"!==i.substr(0,5)&&o&&o.enableTexturesOffline&&e.Database.IsUASupportingBlobStorage)o.openAsync(c,h);else if(-1===i.indexOf("file:"))h();else try{var l,u=i.substring(5).toLowerCase();try{l=URL.createObjectURL(e.FilesInput.FilesTextures[u],{oneTimeOnly:!0})}catch(f){l=URL.createObjectURL(e.FilesInput.FilesTextures[u])}s.src=l}catch(d){s.src=null}return s},t.LoadFile=function(i,r,n,o,s,a){i=t.CleanUrl(i);var h=function(){var e=new XMLHttpRequest,o=t.BaseUrl+i;e.open("GET",o,!0),s&&(e.responseType="arraybuffer"),e.onprogress=n,e.onreadystatechange=function(){if(4===e.readyState)if(200===e.status||t.ValidateXHRData(e,s?6:1))r(s?e.response:e.responseText);else{if(!a)throw new Error("Error status: "+e.status+" - Unable to load "+o);a()}},e.send(null)},c=function(){o.loadFileFromDB(i,r,n,h,s)};if(-1!==i.indexOf("file:")){var l=i.substring(5).toLowerCase();t.ReadFile(e.FilesInput.FilesToLoad[l],r,n,s)}else o&&o.enableSceneOffline?o.openAsync(c,h):h()},t.ReadFileAsDataURL=function(e,t,i){var r=new FileReader;r.onload=function(e){t(e.target.result)},r.onprogress=i,r.readAsDataURL(e)},t.ReadFile=function(e,i,r,n){var o=new FileReader;o.onerror=function(r){t.Log("Error while reading file: "+e.name),i(JSON.stringify({autoClear:!0,clearColor:[1,0,0],ambientColor:[0,0,0],gravity:[0,-9.807,0],meshes:[],cameras:[],lights:[]}))},o.onload=function(e){i(e.target.result)},o.onprogress=r,n?o.readAsArrayBuffer(e):o.readAsText(e)},t.FileAsURL=function(e){var t=new Blob([e]),i=window.URL||window.webkitURL,r=i.createObjectURL(t);return r},t.Format=function(e,t){return void 0===t&&(t=2),e.toFixed(t)},t.CheckExtends=function(e,t,i){e.xi.x&&(i.x=e.x),e.y>i.y&&(i.y=e.y),e.z>i.z&&(i.z=e.z)},t.DeepCopy=function(e,t,i,n){for(var o in e)if(("_"!==o[0]||n&&-1!==n.indexOf(o))&&(!i||-1===i.indexOf(o))){var s=e[o],a=typeof s;if("function"!==a)if("object"===a)if(s instanceof Array){if(t[o]=[],s.length>0)if("object"==typeof s[0])for(var h=0;hh;h++)for(var c=0;o>c;c++){var l=c+h*o,u=t-h-1,f=c+u*o,d=a[l];a[l]=a[f],a[f]=d}i||(i=document.createElement("canvas")),i.width=e,i.height=t;var p=i.getContext("2d"),_=p.createImageData(e,t),g=_.data;g.set(a),p.putImageData(_,0,0);var m=i.toDataURL();if(n)n(m);else if("download"in document.createElement("a")){var v=window.document.createElement("a");v.href=m;var y=new Date,x=(y.getFullYear()+"-"+(y.getMonth()+1)).slice(-2)+"-"+y.getDate()+"_"+y.getHours()+"-"+("0"+y.getMinutes()).slice(-2);v.setAttribute("download","screenshot_"+x+".png"),window.document.body.appendChild(v),v.addEventListener("click",function(){v.parentElement.removeChild(v)}),v.click()}else{var b=window.open(""),P=b.document.createElement("img");P.src=m,b.document.body.appendChild(P)}},t.CreateScreenshot=function(i,r,n,o){var s,a;if(n.precision)s=Math.round(i.getRenderWidth()*n.precision),a=Math.round(s/i.getAspectRatio(r)),n={width:s,height:a};else if(n.width&&n.height)s=n.width,a=n.height;else if(n.width&&!n.height)s=n.width,a=Math.round(s/i.getAspectRatio(r)),n={width:s,height:a};else if(n.height&&!n.width)a=n.height,s=Math.round(a*i.getAspectRatio(r)),n={width:s,height:a};else{if(isNaN(n))return void t.Error("Invalid 'size' parameter !");a=n,s=n}var h=r.getScene(),c=null;h.activeCamera!==r&&(c=h.activeCamera,h.activeCamera=r);var l=new e.RenderTargetTexture("screenShot",n,h,!1,!1);l.renderList=h.meshes,l.onAfterRenderObservable.add(function(){t.DumpFramebuffer(s,a,i,o)}),h.incrementRenderId(),h.resetCachedMaterial(),l.render(!0),l.dispose(),c&&(h.activeCamera=c),r.getProjectionMatrix(!0)},t.ValidateXHRData=function(t,i){void 0===i&&(i=7);try{if(1&i){if(t.responseText&&t.responseText.length>0)return!0;if(1===i)return!1}if(2&i){var r=e.Internals.TGATools.GetTGAHeader(t.response);if(r.width&&r.height&&r.width>0&&r.height>0)return!0;if(2===i)return!1}if(4&i){var n=new Uint8Array(t.response,0,3);return 68===n[0]&&68===n[1]&&83===n[2]}}catch(o){}return!1},Object.defineProperty(t,"NoneLogLevel",{get:function(){return t._NoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"MessageLogLevel",{get:function(){return t._MessageLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"WarningLogLevel",{get:function(){return t._WarningLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"ErrorLogLevel",{get:function(){return t._ErrorLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"AllLogLevel",{get:function(){return t._MessageLogLevel|t._WarningLogLevel|t._ErrorLogLevel},enumerable:!0,configurable:!0}),t._AddLogEntry=function(e){t._LogCache=e+t._LogCache,t.OnNewCacheEntry&&t.OnNewCacheEntry(e)},t._FormatMessage=function(e){var t=function(e){return 10>e?"0"+e:""+e},i=new Date;return"["+t(i.getHours())+":"+t(i.getMinutes())+":"+t(i.getSeconds())+"]: "+e},t._LogDisabled=function(e){},t._LogEnabled=function(e){var i=t._FormatMessage(e);console.log("BJS - "+i);var r=""+i+"
";t._AddLogEntry(r)},t._WarnDisabled=function(e){},t._WarnEnabled=function(e){var i=t._FormatMessage(e);console.warn("BJS - "+i);var r=""+i+"
";t._AddLogEntry(r)},t._ErrorDisabled=function(e){},t._ErrorEnabled=function(e){t.errorsCount++;var i=t._FormatMessage(e);console.error("BJS - "+i);var r=""+i+"
";t._AddLogEntry(r)},Object.defineProperty(t,"LogCache",{get:function(){return t._LogCache},enumerable:!0,configurable:!0}),t.ClearLogCache=function(){t._LogCache="",t.errorsCount=0},Object.defineProperty(t,"LogLevels",{set:function(e){(e&t.MessageLogLevel)===t.MessageLogLevel?t.Log=t._LogEnabled:t.Log=t._LogDisabled,(e&t.WarningLogLevel)===t.WarningLogLevel?t.Warn=t._WarnEnabled:t.Warn=t._WarnDisabled,(e&t.ErrorLogLevel)===t.ErrorLogLevel?t.Error=t._ErrorEnabled:t.Error=t._ErrorDisabled},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PerformanceNoneLogLevel",{get:function(){return t._PerformanceNoneLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PerformanceUserMarkLogLevel",{get:function(){return t._PerformanceUserMarkLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PerformanceConsoleLogLevel",{get:function(){return t._PerformanceConsoleLogLevel},enumerable:!0,configurable:!0}),Object.defineProperty(t,"PerformanceLogLevel",{set:function(e){return(e&t.PerformanceUserMarkLogLevel)===t.PerformanceUserMarkLogLevel?(t.StartPerformanceCounter=t._StartUserMark,void(t.EndPerformanceCounter=t._EndUserMark)):(e&t.PerformanceConsoleLogLevel)===t.PerformanceConsoleLogLevel?(t.StartPerformanceCounter=t._StartPerformanceConsole,void(t.EndPerformanceCounter=t._EndPerformanceConsole)):(t.StartPerformanceCounter=t._StartPerformanceCounterDisabled,void(t.EndPerformanceCounter=t._EndPerformanceCounterDisabled))},enumerable:!0,configurable:!0}),t._StartPerformanceCounterDisabled=function(e,t){},t._EndPerformanceCounterDisabled=function(e,t){},t._StartUserMark=function(e,i){void 0===i&&(i=!0),i&&t._performance.mark&&t._performance.mark(e+"-Begin")},t._EndUserMark=function(e,i){void 0===i&&(i=!0),i&&t._performance.mark&&(t._performance.mark(e+"-End"),t._performance.measure(e,e+"-Begin",e+"-End"))},t._StartPerformanceConsole=function(e,i){void 0===i&&(i=!0),i&&(t._StartUserMark(e,i),console.time&&console.time(e))},t._EndPerformanceConsole=function(e,i){void 0===i&&(i=!0),i&&(t._EndUserMark(e,i),console.time&&console.timeEnd(e))},Object.defineProperty(t,"Now",{get:function(){return window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},enumerable:!0,configurable:!0}),t.getClassName=function(e,t){void 0===t&&(t=!1);var i=null;if(!t&&e.getClassName)i=e.getClassName();else{if(e instanceof Object){var r=t?e:Object.getPrototypeOf(e);i=r.constructor.__bjsclassName__}i||(i=typeof e)}return i},t.first=function(e,t){for(var i=0;i=e.length)return null;var r=e.charCodeAt?e.charCodeAt(i):e[i];return r&&r.getHashCode&&(r=r.getHashCode()),"string"==typeof r?t.hashCodeFromStream(t.arrayOrStringFeeder(r)):r}},t.hashCodeFromStream=function(e){for(var t=0,i=0,r=e(i++);null!=r;)t=(t<<5)-t+r,t|=0,r=e(i++);return t},t.BaseUrl="",t.CorsBehavior="anonymous",t.UseFallbackTexture=!0,t._NoneLogLevel=0,t._MessageLogLevel=1,t._WarningLogLevel=2,t._ErrorLogLevel=4,t._LogCache="",t.errorsCount=0,t.Log=t._LogEnabled,t.Warn=t._WarnEnabled,t.Error=t._ErrorEnabled,t._PerformanceNoneLogLevel=0,t._PerformanceUserMarkLogLevel=1,t._PerformanceConsoleLogLevel=2,t._performance=window.performance,t.StartPerformanceCounter=t._StartPerformanceCounterDisabled,t.EndPerformanceCounter=t._EndPerformanceCounterDisabled,t}();e.Tools=n,e.className=t;var o=function(){function e(e,t,i,r){void 0===r&&(r=0),this.iterations=e,this._fn=t,this._successCallback=i,this.index=r-1,this._done=!1}return e.prototype.executeNext=function(){this._done||(this.index+1n;++n){var s=e.index*i+n;if(s>=t)break;if(r(s),o&&o()){e.breakLoop();break}}e.executeNext()},s)},n)},e}();e.AsyncLoop=o}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=function(){function e(){this._isAlphaBlendDirty=!1,this._isBlendFunctionParametersDirty=!1,this._alphaBlend=!1,this._blendFunctionParameters=new Array(4)}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isAlphaBlendDirty||this._isBlendFunctionParametersDirty},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"alphaBlend",{get:function(){return this._alphaBlend},set:function(e){this._alphaBlend!==e&&(this._alphaBlend=e,this._isAlphaBlendDirty=!0)},enumerable:!0,configurable:!0}),e.prototype.setAlphaBlendFunctionParameters=function(e,t,i,r){this._blendFunctionParameters[0]===e&&this._blendFunctionParameters[1]===t&&this._blendFunctionParameters[2]===i&&this._blendFunctionParameters[3]===r||(this._blendFunctionParameters[0]=e,this._blendFunctionParameters[1]=t,this._blendFunctionParameters[2]=i,this._blendFunctionParameters[3]=r,this._isBlendFunctionParametersDirty=!0)},e.prototype.reset=function(){this._alphaBlend=!1,this._blendFunctionParameters[0]=null,this._blendFunctionParameters[1]=null,this._blendFunctionParameters[2]=null,this._blendFunctionParameters[3]=null,this._isAlphaBlendDirty=!0,this._isBlendFunctionParametersDirty=!1},e.prototype.apply=function(e){this.isDirty&&(this._isAlphaBlendDirty&&(this._alphaBlend?e.enable(e.BLEND):e.disable(e.BLEND),this._isAlphaBlendDirty=!1),this._isBlendFunctionParametersDirty&&(e.blendFuncSeparate(this._blendFunctionParameters[0],this._blendFunctionParameters[1],this._blendFunctionParameters[2],this._blendFunctionParameters[3]),this._isBlendFunctionParametersDirty=!1))},e}();e._AlphaState=t}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=function(){function e(){this._isDepthTestDirty=!1,this._isDepthMaskDirty=!1,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1}return Object.defineProperty(e.prototype,"isDirty",{get:function(){return this._isDepthFuncDirty||this._isDepthTestDirty||this._isDepthMaskDirty||this._isCullFaceDirty||this._isCullDirty||this._isZOffsetDirty},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"zOffset",{get:function(){return this._zOffset},set:function(e){this._zOffset!==e&&(this._zOffset=e,this._isZOffsetDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"cullFace",{get:function(){return this._cullFace},set:function(e){this._cullFace!==e&&(this._cullFace=e,this._isCullFaceDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"cull",{get:function(){return this._cull},set:function(e){this._cull!==e&&(this._cull=e,this._isCullDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthFunc",{get:function(){return this._depthFunc},set:function(e){this._depthFunc!==e&&(this._depthFunc=e,this._isDepthFuncDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthMask",{get:function(){return this._depthMask},set:function(e){this._depthMask!==e&&(this._depthMask=e,this._isDepthMaskDirty=!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"depthTest",{get:function(){return this._depthTest},set:function(e){this._depthTest!==e&&(this._depthTest=e,this._isDepthTestDirty=!0)},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this._depthMask=!0,this._depthTest=!0,this._depthFunc=null,this._cullFace=null,this._cull=null,this._zOffset=0,this._isDepthTestDirty=!0,this._isDepthMaskDirty=!0,this._isDepthFuncDirty=!1,this._isCullFaceDirty=!1,this._isCullDirty=!1,this._isZOffsetDirty=!1},e.prototype.apply=function(e){this.isDirty&&(this._isCullDirty&&(this.cull?e.enable(e.CULL_FACE):e.disable(e.CULL_FACE),this._isCullDirty=!1),this._isCullFaceDirty&&(e.cullFace(this.cullFace),this._isCullFaceDirty=!1),this._isDepthMaskDirty&&(e.depthMask(this.depthMask),this._isDepthMaskDirty=!1),this._isDepthTestDirty&&(this.depthTest?e.enable(e.DEPTH_TEST):e.disable(e.DEPTH_TEST),this._isDepthTestDirty=!1),this._isDepthFuncDirty&&(e.depthFunc(this.depthFunc),this._isDepthFuncDirty=!1),this._isZOffsetDirty&&(this.zOffset?(e.enable(e.POLYGON_OFFSET_FILL),e.polygonOffset(this.zOffset,0)):e.disable(e.POLYGON_OFFSET_FILL),this._isZOffsetDirty=!1))},e}();e._DepthCullingState=t}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e,t,i,r){var n=e.createShader("vertex"===i?e.VERTEX_SHADER:e.FRAGMENT_SHADER);if(e.shaderSource(n,(r?r+"\n":"")+t),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(n));return n},i=function(e,t){var i=e.UNSIGNED_BYTE;return t===c.TEXTURETYPE_FLOAT&&(i=e.FLOAT),i},r=function(t,i,r){var n=r.NEAREST,o=r.NEAREST;return t===e.Texture.BILINEAR_SAMPLINGMODE?(n=r.LINEAR,o=i?r.LINEAR_MIPMAP_NEAREST:r.LINEAR):t===e.Texture.TRILINEAR_SAMPLINGMODE?(n=r.LINEAR,o=i?r.LINEAR_MIPMAP_LINEAR:r.LINEAR):t===e.Texture.NEAREST_SAMPLINGMODE&&(n=r.NEAREST,o=i?r.NEAREST_MIPMAP_LINEAR:r.NEAREST),{min:o,mag:n}},n=function(t,i,n,o,s,a,h,c,l,u,f){void 0===f&&(f=e.Texture.TRILINEAR_SAMPLINGMODE);var d=n.getEngine(),p=e.Tools.GetExponentOfTwo(o,d.getCaps().maxTextureSize),_=e.Tools.GetExponentOfTwo(s,d.getCaps().maxTextureSize);i.bindTexture(i.TEXTURE_2D,t),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,void 0===a?1:a?1:0),t._baseWidth=o,t._baseHeight=s,t._width=p,t._height=_,t.isReady=!0,l(p,_);var g=r(f,!h,i);i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,g.mag),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,g.min),h||c||i.generateMipmap(i.TEXTURE_2D),i.bindTexture(i.TEXTURE_2D,null),d.resetTextureCache(),n._removePendingData(t),u&&u()},o=function(t,i,r,n,o){var s,a=function(){r[i]=s,r._internalCount++,n._removePendingData(s),6===r._internalCount&&o(r)},h=function(){n._removePendingData(s)};s=e.Tools.LoadImage(t,a,h,n.database),n._addPendingData(s)},s=function(e,t,i,r){var n=[];n._internalCount=0;for(var s=0;6>s;s++)o(r[s],s,n,t,i)},a=function(){function e(){}return e}();e.InstancingAttributeInfo=a;var h=function(){function e(){}return e}();e.EngineCapabilities=h;var c=function(){function o(t,i,r,n){var s=this;if(void 0===n&&(n=!0),this.isFullscreen=!1,this.isPointerLock=!1,this.cullBackFaces=!0,this.renderEvenInBackground=!0,this.enableOfflineSupport=!0,this.scenes=new Array,this._windowIsBackground=!1,this._webGLVersion="1.0",this._drawCalls=0,this._renderingQueueLaunched=!1,this._activeRenderLoops=[],this.fpsRange=60,this.previousFramesDuration=[],this.fps=60,this.deltaTime=0,this._depthCullingState=new e.Internals._DepthCullingState,this._alphaState=new e.Internals._AlphaState,this._alphaMode=o.ALPHA_DISABLE,this._loadedTexturesCache=new Array,this._maxTextureChannels=16,this._activeTexturesCache=new Array(this._maxTextureChannels),this._compiledEffects={},this._uintIndicesCurrentlySet=!1,this._currentBoundBuffer=new Array,this._currentInstanceLocations=new Array,this._currentInstanceBuffers=new Array,this._renderingCanvas=t,this._externalData=new e.StringDictionary,r=r||{},r.antialias=i,void 0===r.preserveDrawingBuffer&&(r.preserveDrawingBuffer=!1),!this._gl)try{this._gl=t.getContext("webgl",r)||t.getContext("experimental-webgl",r)}catch(a){throw new Error("WebGL not supported")}if(!this._gl)throw new Error("WebGL not supported");this._onBlur=function(){s._windowIsBackground=!0},this._onFocus=function(){s._windowIsBackground=!1},window.addEventListener("blur",this._onBlur),window.addEventListener("focus",this._onFocus);var c=r.limitDeviceRatio||window.devicePixelRatio||1;this._hardwareScalingLevel=n?1/Math.min(c,window.devicePixelRatio||1):1,this.resize(),this._caps=new h,this._caps.maxTexturesImageUnits=this._gl.getParameter(this._gl.MAX_TEXTURE_IMAGE_UNITS),this._caps.maxTextureSize=this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE),this._caps.maxCubemapTextureSize=this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE),
+this._caps.maxRenderTextureSize=this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE),this._glVersion=this._gl.getParameter(this._gl.VERSION);var l=this._gl.getExtension("WEBGL_debug_renderer_info");if(null!=l&&(this._glRenderer=this._gl.getParameter(l.UNMASKED_RENDERER_WEBGL),this._glVendor=this._gl.getParameter(l.UNMASKED_VENDOR_WEBGL)),this._glVendor||(this._glVendor="Unknown vendor"),this._glRenderer||(this._glRenderer="Unknown renderer"),this._caps.standardDerivatives=null!==this._gl.getExtension("OES_standard_derivatives"),this._caps.s3tc=this._gl.getExtension("WEBGL_compressed_texture_s3tc"),this._caps.textureFloat=null!==this._gl.getExtension("OES_texture_float"),this._caps.textureAnisotropicFilterExtension=this._gl.getExtension("EXT_texture_filter_anisotropic")||this._gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic")||this._gl.getExtension("MOZ_EXT_texture_filter_anisotropic"),this._caps.maxAnisotropy=this._caps.textureAnisotropicFilterExtension?this._gl.getParameter(this._caps.textureAnisotropicFilterExtension.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0,this._caps.instancedArrays=this._gl.getExtension("ANGLE_instanced_arrays"),this._caps.uintIndices=null!==this._gl.getExtension("OES_element_index_uint"),this._caps.fragmentDepthSupported=null!==this._gl.getExtension("EXT_frag_depth"),this._caps.highPrecisionShaderSupported=!0,this._caps.drawBuffersExtension=this._gl.getExtension("WEBGL_draw_buffers"),this._caps.textureFloatLinearFiltering=this._gl.getExtension("OES_texture_float_linear"),this._caps.textureLOD=this._gl.getExtension("EXT_shader_texture_lod"),this._gl.getShaderPrecisionFormat){var u=this._gl.getShaderPrecisionFormat(this._gl.FRAGMENT_SHADER,this._gl.HIGH_FLOAT);this._caps.highPrecisionShaderSupported=0!==u.precision}this.setDepthBuffer(!0),this.setDepthFunctionToLessOrEqual(),this.setDepthWrite(!0),this._onFullscreenChange=function(){void 0!==document.fullscreen?s.isFullscreen=document.fullscreen:void 0!==document.mozFullScreen?s.isFullscreen=document.mozFullScreen:void 0!==document.webkitIsFullScreen?s.isFullscreen=document.webkitIsFullScreen:void 0!==document.msIsFullScreen&&(s.isFullscreen=document.msIsFullScreen),s.isFullscreen&&s._pointerLockRequested&&(t.requestPointerLock=t.requestPointerLock||t.msRequestPointerLock||t.mozRequestPointerLock||t.webkitRequestPointerLock,t.requestPointerLock&&t.requestPointerLock())},document.addEventListener("fullscreenchange",this._onFullscreenChange,!1),document.addEventListener("mozfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("webkitfullscreenchange",this._onFullscreenChange,!1),document.addEventListener("msfullscreenchange",this._onFullscreenChange,!1),this._onPointerLockChange=function(){s.isPointerLock=document.mozPointerLockElement===t||document.webkitPointerLockElement===t||document.msPointerLockElement===t||document.pointerLockElement===t},document.addEventListener("pointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mspointerlockchange",this._onPointerLockChange,!1),document.addEventListener("mozpointerlockchange",this._onPointerLockChange,!1),document.addEventListener("webkitpointerlockchange",this._onPointerLockChange,!1),e.AudioEngine&&!o.audioEngine&&(o.audioEngine=new e.AudioEngine),this._loadingScreen=new e.DefaultLoadingScreen(this._renderingCanvas),e.Tools.Log("Babylon.js engine (v"+o.Version+") launched")}return Object.defineProperty(o,"ALPHA_DISABLE",{get:function(){return o._ALPHA_DISABLE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_ONEONE",{get:function(){return o._ALPHA_ONEONE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_ADD",{get:function(){return o._ALPHA_ADD},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_COMBINE",{get:function(){return o._ALPHA_COMBINE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_SUBTRACT",{get:function(){return o._ALPHA_SUBTRACT},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_MULTIPLY",{get:function(){return o._ALPHA_MULTIPLY},enumerable:!0,configurable:!0}),Object.defineProperty(o,"ALPHA_MAXIMIZED",{get:function(){return o._ALPHA_MAXIMIZED},enumerable:!0,configurable:!0}),Object.defineProperty(o,"DELAYLOADSTATE_NONE",{get:function(){return o._DELAYLOADSTATE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"DELAYLOADSTATE_LOADED",{get:function(){return o._DELAYLOADSTATE_LOADED},enumerable:!0,configurable:!0}),Object.defineProperty(o,"DELAYLOADSTATE_LOADING",{get:function(){return o._DELAYLOADSTATE_LOADING},enumerable:!0,configurable:!0}),Object.defineProperty(o,"DELAYLOADSTATE_NOTLOADED",{get:function(){return o._DELAYLOADSTATE_NOTLOADED},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_ALPHA",{get:function(){return o._TEXTUREFORMAT_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_LUMINANCE",{get:function(){return o._TEXTUREFORMAT_LUMINANCE},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_LUMINANCE_ALPHA",{get:function(){return o._TEXTUREFORMAT_LUMINANCE_ALPHA},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_RGB",{get:function(){return o._TEXTUREFORMAT_RGB},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTUREFORMAT_RGBA",{get:function(){return o._TEXTUREFORMAT_RGBA},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTURETYPE_UNSIGNED_INT",{get:function(){return o._TEXTURETYPE_UNSIGNED_INT},enumerable:!0,configurable:!0}),Object.defineProperty(o,"TEXTURETYPE_FLOAT",{get:function(){return o._TEXTURETYPE_FLOAT},enumerable:!0,configurable:!0}),Object.defineProperty(o,"Version",{get:function(){return"2.4.0"},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"webGLVersion",{get:function(){return this._webGLVersion},enumerable:!0,configurable:!0}),o.prototype._prepareWorkingCanvas=function(){this._workingCanvas||(this._workingCanvas=document.createElement("canvas"),this._workingContext=this._workingCanvas.getContext("2d"))},o.prototype.resetTextureCache=function(){for(var e=0;e=0&&this._activeRenderLoops.splice(t,1)},o.prototype._renderLoop=function(){var t=!0;if(!this.renderEvenInBackground&&this._windowIsBackground&&(t=!1),t){this.beginFrame();for(var i=0;i0?e.Tools.QueueNewFrame(this._bindedRenderFunction):this._renderingQueueLaunched=!1},o.prototype.runRenderLoop=function(t){-1===this._activeRenderLoops.indexOf(t)&&(this._activeRenderLoops.push(t),this._renderingQueueLaunched||(this._renderingQueueLaunched=!0,this._bindedRenderFunction=this._renderLoop.bind(this),e.Tools.QueueNewFrame(this._bindedRenderFunction)))},o.prototype.switchFullscreen=function(t,i){this.isFullscreen?e.Tools.ExitFullscreen():(this._pointerLockRequested=t,e.Tools.RequestFullscreen(this._renderingCanvas,i))},o.prototype.clear=function(e,t,i){this.applyStates(),t&&this._gl.clearColor(e.r,e.g,e.b,void 0!==e.a?e.a:1),i&&this._depthCullingState.depthMask&&this._gl.clearDepth(1);var r=0;t&&(r|=this._gl.COLOR_BUFFER_BIT),i&&this._depthCullingState.depthMask&&(r|=this._gl.DEPTH_BUFFER_BIT),this._gl.clear(r)},o.prototype.scissorClear=function(e,t,i,r,n){var o=this._gl,s=o.getParameter(o.SCISSOR_TEST),a=o.getParameter(o.SCISSOR_BOX);o.enable(o.SCISSOR_TEST),o.scissor(e,t,i,r),this.clear(n,!0,!0),o.scissor(a[0],a[1],a[2],a[3]),s===!0?o.enable(o.SCISSOR_TEST):o.disable(o.SCISSOR_TEST)},o.prototype.setViewport=function(e,t,i){var r=t||(navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.width),n=i||(navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.height),o=e.x||0,s=e.y||0;this._cachedViewport=e,this._gl.viewport(o*r,s*n,r*e.width,n*e.height)},o.prototype.setDirectViewport=function(e,t,i,r){var n=this._cachedViewport;return this._cachedViewport=null,this._gl.viewport(e,t,i,r),n},o.prototype.beginFrame=function(){this._measureFps()},o.prototype.endFrame=function(){},o.prototype.resize=function(){var e=navigator.isCocoonJS?window.innerWidth:this._renderingCanvas.clientWidth,t=navigator.isCocoonJS?window.innerHeight:this._renderingCanvas.clientHeight;this.setSize(e/this._hardwareScalingLevel,t/this._hardwareScalingLevel);for(var i=0;i65535){r=!0;break}i=r?new Uint32Array(e):new Uint16Array(e)}else i=new Uint16Array(e);return this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER,i,this._gl.STATIC_DRAW),this._resetIndexBufferBinding(),t.references=1,t.is32Bits=r,t},o.prototype.bindArrayBuffer=function(e){this.bindBuffer(e,this._gl.ARRAY_BUFFER)},o.prototype.updateArrayBuffer=function(e){this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,e)},o.prototype.bindBuffer=function(e,t){this._currentBoundBuffer[t]!==e&&(this._gl.bindBuffer(t,e),this._currentBoundBuffer[t]=e)},o.prototype.bindBuffersDirectly=function(e,t,i,r,n){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==n){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=n,this.bindBuffer(e,this._gl.ARRAY_BUFFER);for(var o=0,s=0;s=0&&this._gl.vertexAttribPointer(a,i[s],this._gl.FLOAT,!1,r,o),o+=4*i[s]}}this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this.bindBuffer(t,this._gl.ELEMENT_ARRAY_BUFFER),this._uintIndicesCurrentlySet=t.is32Bits)},o.prototype.bindBuffers=function(e,t,i){if(this._cachedVertexBuffers!==e||this._cachedEffectForVertexBuffers!==i){this._cachedVertexBuffers=e,this._cachedEffectForVertexBuffers=i;for(var r=i.getAttributesNames(),n=0;n=0){var s=e[r[n]];if(!s)continue;var a=s.getBuffer();this.bindBuffer(a,this._gl.ARRAY_BUFFER),this._gl.vertexAttribPointer(o,s.getSize(),this._gl.FLOAT,!1,4*s.getStrideSize(),4*s.getOffset()),s.getIsInstanced()&&(this._caps.instancedArrays.vertexAttribDivisorANGLE(o,1),this._currentInstanceLocations.push(o),this._currentInstanceBuffers.push(a))}}}null!=t&&this._cachedIndexBuffer!==t&&(this._cachedIndexBuffer=t,this.bindBuffer(t,this._gl.ELEMENT_ARRAY_BUFFER),this._uintIndicesCurrentlySet=t.is32Bits)},o.prototype.unbindInstanceAttributes=function(){for(var e,t=0,i=this._currentInstanceLocations.length;i>t;t++){var r=this._currentInstanceBuffers[t];e!=r&&(e=r,this.bindBuffer(r,this._gl.ARRAY_BUFFER));var n=this._currentInstanceLocations[t];this._caps.instancedArrays.vertexAttribDivisorANGLE(n,0)}this._currentInstanceBuffers.length=0,this._currentInstanceLocations.length=0},o.prototype._releaseBuffer=function(e){return e.references--,0===e.references?(this._gl.deleteBuffer(e),!0):!1},o.prototype.createInstancesBuffer=function(e){var t=this._gl.createBuffer();return t.capacity=e,this.bindBuffer(t,this._gl.ARRAY_BUFFER),this._gl.bufferData(this._gl.ARRAY_BUFFER,e,this._gl.DYNAMIC_DRAW),t},o.prototype.deleteInstancesBuffer=function(e){this._gl.deleteBuffer(e)},o.prototype.updateAndBindInstancesBuffer=function(e,t,i){if(this.bindBuffer(e,this._gl.ARRAY_BUFFER),t&&this._gl.bufferSubData(this._gl.ARRAY_BUFFER,0,t),void 0!==i[0].index){for(var r=0,n=0;ns;s++){var a=i[s];this._gl.enableVertexAttribArray(a),this._gl.vertexAttribPointer(a,4,this._gl.FLOAT,!1,64,16*s),this._caps.instancedArrays.vertexAttribDivisorANGLE(a,1),this._currentInstanceLocations.push(a),this._currentInstanceBuffers.push(e)}},o.prototype.applyStates=function(){this._depthCullingState.apply(this._gl),this._alphaState.apply(this._gl)},o.prototype.draw=function(e,t,i,r){this.applyStates(),this._drawCalls++;var n=this._uintIndicesCurrentlySet?this._gl.UNSIGNED_INT:this._gl.UNSIGNED_SHORT,o=this._uintIndicesCurrentlySet?4:2;return r?void this._caps.instancedArrays.drawElementsInstancedANGLE(e?this._gl.TRIANGLES:this._gl.LINES,i,n,t*o,r):void this._gl.drawElements(e?this._gl.TRIANGLES:this._gl.LINES,i,n,t*o)},o.prototype.drawPointClouds=function(e,t,i){return this.applyStates(),this._drawCalls++,i?void this._caps.instancedArrays.drawArraysInstancedANGLE(this._gl.POINTS,e,t,i):void this._gl.drawArrays(this._gl.POINTS,e,t)},o.prototype.drawUnIndexed=function(e,t,i,r){return this.applyStates(),this._drawCalls++,r?void this._caps.instancedArrays.drawArraysInstancedANGLE(e?this._gl.TRIANGLES:this._gl.LINES,t,i,r):void this._gl.drawArrays(e?this._gl.TRIANGLES:this._gl.LINES,t,i)},o.prototype._releaseEffect=function(e){this._compiledEffects[e._key]&&(delete this._compiledEffects[e._key],e.getProgram()&&this._gl.deleteProgram(e.getProgram()))},o.prototype.createEffect=function(t,i,r,n,o,s,a,h,c){var l=t.vertexElement||t.vertex||t,u=t.fragmentElement||t.fragment||t,f=l+"+"+u+"@"+o;if(this._compiledEffects[f])return this._compiledEffects[f];var d=new e.Effect(t,i,r,n,this,o,s,a,h,c);return d._key=f,this._compiledEffects[f]=d,d},o.prototype.createEffectForParticles=function(e,t,i,r,n,o,s){return void 0===t&&(t=[]),void 0===i&&(i=[]),void 0===r&&(r=""),this.createEffect({vertex:"particles",fragmentElement:e},["position","color","options"],["view","projection"].concat(t),["diffuseSampler"].concat(i),r,n,o,s)},o.prototype.createShaderProgram=function(e,i,r){var n=t(this._gl,e,"vertex",r),o=t(this._gl,i,"fragment",r),s=this._gl.createProgram();this._gl.attachShader(s,n),this._gl.attachShader(s,o),this._gl.linkProgram(s);var a=this._gl.getProgramParameter(s,this._gl.LINK_STATUS);if(!a){var h=this._gl.getProgramInfoLog(s);if(h)throw new Error(h)}return this._gl.deleteShader(n),this._gl.deleteShader(o),s},o.prototype.getUniforms=function(e,t){for(var i=[],r=0;rt;t++)this._vertexAttribArraysToUse[t]=!1;var r=e.getAttributesCount();for(t=0;r>t;t++){var n=e.getAttributeLocation(t);n>=0&&(this._vertexAttribArraysToUse[n]=!0)}for(t=0,i=this._vertexAttribArraysEnabled.length;i>t;t++)t>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArraysEnabled[t]||this._vertexAttribArraysToUse[t]||(this._vertexAttribArraysEnabled[t]=!1,this._gl.disableVertexAttribArray(t));for(t=0,i=this._vertexAttribArraysToUse.length;i>t;t++)this._vertexAttribArraysToUse[t]&&!this._vertexAttribArraysEnabled[t]&&(this._vertexAttribArraysEnabled[t]=!0,this._gl.enableVertexAttribArray(t));this._currentEffect=e,e.onBind&&e.onBind(e)},o.prototype.setArray=function(e,t){e&&this._gl.uniform1fv(e,t)},o.prototype.setArray2=function(e,t){e&&t.length%2===0&&this._gl.uniform2fv(e,t)},o.prototype.setArray3=function(e,t){e&&t.length%3===0&&this._gl.uniform3fv(e,t)},o.prototype.setArray4=function(e,t){e&&t.length%4===0&&this._gl.uniform4fv(e,t)},o.prototype.setMatrices=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t)},o.prototype.setMatrix=function(e,t){e&&this._gl.uniformMatrix4fv(e,!1,t.toArray())},o.prototype.setMatrix3x3=function(e,t){e&&this._gl.uniformMatrix3fv(e,!1,t)},o.prototype.setMatrix2x2=function(e,t){e&&this._gl.uniformMatrix2fv(e,!1,t)},o.prototype.setFloat=function(e,t){e&&this._gl.uniform1f(e,t)},o.prototype.setFloat2=function(e,t,i){e&&this._gl.uniform2f(e,t,i)},o.prototype.setFloat3=function(e,t,i,r){e&&this._gl.uniform3f(e,t,i,r)},o.prototype.setBool=function(e,t){e&&this._gl.uniform1i(e,t)},o.prototype.setFloat4=function(e,t,i,r,n){e&&this._gl.uniform4f(e,t,i,r,n)},o.prototype.setColor3=function(e,t){e&&this._gl.uniform3f(e,t.r,t.g,t.b)},o.prototype.setColor4=function(e,t,i){e&&this._gl.uniform4f(e,t.r,t.g,t.b,i)},o.prototype.setState=function(e,t,i,r){void 0===t&&(t=0),void 0===r&&(r=!1);var n=r?this._gl.FRONT:this._gl.BACK,o=r?this._gl.BACK:this._gl.FRONT,s=this.cullBackFaces?n:o;(this._depthCullingState.cull!==e||i||this._depthCullingState.cullFace!==s)&&(e?(this._depthCullingState.cullFace=s,this._depthCullingState.cull=!0):this._depthCullingState.cull=!1),this._depthCullingState.zOffset=t},o.prototype.setDepthBuffer=function(e){this._depthCullingState.depthTest=e},o.prototype.getDepthWrite=function(){return this._depthCullingState.depthMask},o.prototype.setDepthWrite=function(e){this._depthCullingState.depthMask=e},o.prototype.setColorWrite=function(e){this._gl.colorMask(e,e,e,e)},o.prototype.setAlphaMode=function(e,t){if(void 0===t&&(t=!1),this._alphaMode!==e){switch(e){case o.ALPHA_DISABLE:this._alphaState.alphaBlend=!1;break;case o.ALPHA_COMBINE:this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_ALPHA,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case o.ALPHA_ONEONE:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ONE,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case o.ALPHA_ADD:this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE,this._gl.ZERO,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case o.ALPHA_SUBTRACT:this._alphaState.setAlphaBlendFunctionParameters(this._gl.ZERO,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case o.ALPHA_MULTIPLY:this._alphaState.setAlphaBlendFunctionParameters(this._gl.DST_COLOR,this._gl.ZERO,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0;break;case o.ALPHA_MAXIMIZED:this._alphaState.setAlphaBlendFunctionParameters(this._gl.SRC_ALPHA,this._gl.ONE_MINUS_SRC_COLOR,this._gl.ONE,this._gl.ONE),this._alphaState.alphaBlend=!0}t||this.setDepthWrite(e===o.ALPHA_DISABLE),this._alphaMode=e}},o.prototype.getAlphaMode=function(){return this._alphaMode},o.prototype.setAlphaTesting=function(e){this._alphaTest=e},o.prototype.getAlphaTesting=function(){return this._alphaTest},o.prototype.wipeCaches=function(){this.resetTextureCache(),this._currentEffect=null,this._depthCullingState.reset(),this.setDepthFunctionToLessOrEqual(),this._alphaState.reset(),this._cachedVertexBuffers=null,this._cachedIndexBuffer=null,this._cachedEffectForVertexBuffers=null},o.prototype.setSamplingMode=function(t,i){var r=this._gl;r.bindTexture(r.TEXTURE_2D,t);var n=r.NEAREST,o=r.NEAREST;i===e.Texture.BILINEAR_SAMPLINGMODE?(n=r.LINEAR,o=r.LINEAR):i===e.Texture.TRILINEAR_SAMPLINGMODE&&(n=r.LINEAR,o=r.LINEAR_MIPMAP_LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,n),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,o),r.bindTexture(r.TEXTURE_2D,null),t.samplingMode=i},o.prototype.createTexture=function(t,i,r,o,s,a,h,c){var l=this;void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),void 0===c&&(c=null);var u,f=this._gl.createTexture(),d=!1;if("data:"===t.substr(0,5)&&(d=!0),d){var p=t;d=p.split(":"),t=p,u=d[1].substr(d[1].length-4,4).toLowerCase()}else u=t.substr(t.length-4,4).toLowerCase();var _=this.getCaps().s3tc&&".dds"===u,g=".tga"===u;o._addPendingData(f),f.url=t,f.noMipmap=i,f.references=1,f.samplingMode=s,this._loadedTexturesCache.push(f);var m,v=function(){o._removePendingData(f),h&&h()};if(g)m=function(t){var h=new Uint8Array(t),c=e.Internals.TGATools.GetTGAHeader(h);n(f,l._gl,o,c.width,c.height,r,i,!1,function(){e.Internals.TGATools.UploadContent(l._gl,h)},a,s)},d instanceof Array?m(c):e.Tools.LoadFile(t,function(e){m(e)},v,o.database,!0);else if(_)m=function(t){var h=e.Internals.DDSTools.GetDDSInfo(t),c=(h.isRGB||h.isLuminance||h.mipmapCount>1)&&!i&&h.width>>h.mipmapCount-1===1;n(f,l._gl,o,h.width,h.height,r,!c,h.isFourCC,function(){e.Internals.DDSTools.UploadDDSLevels(l._gl,l.getCaps().s3tc,t,h,c,1)},a,s)},d instanceof Array?m(c):e.Tools.LoadFile(t,function(e){m(e)},v,o.database,!0);else{var y=function(t){n(f,l._gl,o,t.width,t.height,r,i,!1,function(i,r){var n=t.width===i&&t.height===r;n||(l._prepareWorkingCanvas(),l._workingCanvas.width=i,l._workingCanvas.height=r,s===e.Texture.NEAREST_SAMPLINGMODE&&(l._workingContext.imageSmoothingEnabled=!1,l._workingContext.mozImageSmoothingEnabled=!1,l._workingContext.oImageSmoothingEnabled=!1,l._workingContext.webkitImageSmoothingEnabled=!1,l._workingContext.msImageSmoothingEnabled=!1),l._workingContext.drawImage(t,0,0,t.width,t.height,0,0,i,r),s===e.Texture.NEAREST_SAMPLINGMODE&&(l._workingContext.imageSmoothingEnabled=!0,l._workingContext.mozImageSmoothingEnabled=!0,l._workingContext.oImageSmoothingEnabled=!0,l._workingContext.webkitImageSmoothingEnabled=!0,l._workingContext.msImageSmoothingEnabled=!0)),l._gl.texImage2D(l._gl.TEXTURE_2D,0,l._gl.RGBA,l._gl.RGBA,l._gl.UNSIGNED_BYTE,n?t:l._workingCanvas)},a,s)};d instanceof Array?e.Tools.LoadImage(c,y,v,o.database):e.Tools.LoadImage(t,y,v,o.database)}return f},o.prototype._getInternalFormat=function(e){var t=this._gl.RGBA;switch(e){case o.TEXTUREFORMAT_ALPHA:t=this._gl.ALPHA;break;case o.TEXTUREFORMAT_LUMINANCE:t=this._gl.LUMINANCE;break;case o.TEXTUREFORMAT_LUMINANCE_ALPHA:t=this._gl.LUMINANCE_ALPHA;break;case o.TEXTUREFORMAT_RGB:t=this._gl.RGB;break;case o.TEXTUREFORMAT_RGBA:t=this._gl.RGBA}return t},o.prototype.updateRawTexture=function(e,t,i,r,n){void 0===n&&(n=null);var o=this._getInternalFormat(i);this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,void 0===r?1:r?1:0),e._width%4!==0&&this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT,1),n?this._gl.compressedTexImage2D(this._gl.TEXTURE_2D,0,this.getCaps().s3tc[n],e._width,e._height,0,t):this._gl.texImage2D(this._gl.TEXTURE_2D,0,o,e._width,e._height,0,o,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this.resetTextureCache(),e.isReady=!0},o.prototype.createRawTexture=function(e,t,i,n,o,s,a,h){void 0===h&&(h=null);var c=this._gl.createTexture();c._baseWidth=t,c._baseHeight=i,c._width=t,c._height=i,c.references=1,this.updateRawTexture(c,e,n,s,h),this._gl.bindTexture(this._gl.TEXTURE_2D,c);var l=r(a,o,this._gl);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,l.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,l.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null),c.samplingMode=a,this._loadedTexturesCache.push(c),c},o.prototype.createDynamicTexture=function(t,i,r,n){var o=this._gl.createTexture();return o._baseWidth=t,o._baseHeight=i,r&&(t=e.Tools.GetExponentOfTwo(t,this._caps.maxTextureSize),i=e.Tools.GetExponentOfTwo(i,this._caps.maxTextureSize)),this.resetTextureCache(),o._width=t,o._height=i,o.isReady=!1,o.generateMipMaps=r,o.references=1,o.samplingMode=n,this.updateTextureSamplingMode(n,o),this._loadedTexturesCache.push(o),o},o.prototype.updateTextureSamplingMode=function(e,t){var i=r(e,t.generateMipMaps,this._gl);t.isCube?(this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,t),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_MAG_FILTER,i.mag),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_MIN_FILTER,i.min),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null)):(this._gl.bindTexture(this._gl.TEXTURE_2D,t),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,i.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,i.min),this._gl.bindTexture(this._gl.TEXTURE_2D,null))},o.prototype.updateDynamicTexture=function(e,t,i,r){void 0===r&&(r=!1),this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,i?1:0),r&&this._gl.pixelStorei(this._gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,1),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this.resetTextureCache(),e.isReady=!0},o.prototype.updateVideoTexture=function(e,t,i){if(!e._isDisabled){this._gl.bindTexture(this._gl.TEXTURE_2D,e),this._gl.pixelStorei(this._gl.UNPACK_FLIP_Y_WEBGL,i?0:1);try{void 0===this._videoTextureSupported&&(this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t),0!==this._gl.getError()?this._videoTextureSupported=!1:this._videoTextureSupported=!0),this._videoTextureSupported?this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,t):(e._workingCanvas||(e._workingCanvas=document.createElement("canvas"),e._workingContext=e._workingCanvas.getContext("2d"),e._workingCanvas.width=e._width,e._workingCanvas.height=e._height),e._workingContext.drawImage(t,0,0,t.videoWidth,t.videoHeight,0,0,e._width,e._height),this._gl.texImage2D(this._gl.TEXTURE_2D,0,this._gl.RGBA,this._gl.RGBA,this._gl.UNSIGNED_BYTE,e._workingCanvas)),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this.resetTextureCache(),e.isReady=!0}catch(r){e._isDisabled=!0}}},o.prototype.createRenderTargetTexture=function(t,n){var s=!1,a=!0,h=o.TEXTURETYPE_UNSIGNED_INT,c=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==n&&(s=void 0===n.generateMipMaps?n:n.generateMipMaps,a=void 0===n.generateDepthBuffer?!0:n.generateDepthBuffer,h=void 0===n.type?h:n.type,void 0!==n.samplingMode&&(c=n.samplingMode),h===o.TEXTURETYPE_FLOAT&&(c=e.Texture.NEAREST_SAMPLINGMODE));var l=this._gl,u=l.createTexture();l.bindTexture(l.TEXTURE_2D,u);var f=t.width||t,d=t.height||t,p=r(c,s,l);h!==o.TEXTURETYPE_FLOAT||this._caps.textureFloat||(h=o.TEXTURETYPE_UNSIGNED_INT,e.Tools.Warn("Float textures are not supported. Render target forced to TEXTURETYPE_UNSIGNED_BYTE type")),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,p.mag),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,p.min),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),l.texImage2D(l.TEXTURE_2D,0,l.RGBA,f,d,0,l.RGBA,i(l,h),null);var _;a&&(_=l.createRenderbuffer(),l.bindRenderbuffer(l.RENDERBUFFER,_),l.renderbufferStorage(l.RENDERBUFFER,l.DEPTH_COMPONENT16,f,d));var g=l.createFramebuffer();return l.bindFramebuffer(l.FRAMEBUFFER,g),a&&l.framebufferRenderbuffer(l.FRAMEBUFFER,l.DEPTH_ATTACHMENT,l.RENDERBUFFER,_),s&&this._gl.generateMipmap(this._gl.TEXTURE_2D),l.bindTexture(l.TEXTURE_2D,null),l.bindRenderbuffer(l.RENDERBUFFER,null),l.bindFramebuffer(l.FRAMEBUFFER,null),u._framebuffer=g,a&&(u._depthBuffer=_),u._baseWidth=f,u._baseHeight=d,u._width=f,u._height=d,u.isReady=!0,u.generateMipMaps=s,u.references=1,u.samplingMode=c,this.resetTextureCache(),this._loadedTexturesCache.push(u),
+u},o.prototype.createRenderTargetCubeTexture=function(t,i){var n=this._gl,o=n.createTexture(),s=!0,a=e.Texture.TRILINEAR_SAMPLINGMODE;void 0!==i&&(s=void 0===i.generateMipMaps?i:i.generateMipMaps,void 0!==i.samplingMode&&(a=i.samplingMode)),o.isCube=!0,o.references=1,o.generateMipMaps=s,o.references=1,o.samplingMode=a;var h=r(a,s,n);n.bindTexture(n.TEXTURE_CUBE_MAP,o);for(var c=0;6>c;c++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+c,0,n.RGBA,t,t,0,n.RGBA,n.UNSIGNED_BYTE,null);n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_MAG_FILTER,h.mag),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_MIN_FILTER,h.min),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE);var l=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,l),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT16,t,t);var u=n.createFramebuffer();return n.bindFramebuffer(n.FRAMEBUFFER,u),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,l),o.generateMipMaps&&(n.bindTexture(n.TEXTURE_CUBE_MAP,o),n.generateMipmap(n.TEXTURE_CUBE_MAP)),n.bindTexture(n.TEXTURE_CUBE_MAP,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),o._framebuffer=u,o._depthBuffer=l,this.resetTextureCache(),o._width=t,o._height=t,o.isReady=!0,o},o.prototype.createCubeTexture=function(t,i,r,n){var o=this,a=this._gl,h=a.createTexture();h.isCube=!0,h.url=t,h.references=1;var c=t.substr(t.length-4,4).toLowerCase(),l=this.getCaps().s3tc&&".dds"===c;return l?e.Tools.LoadFile(t,function(t){var i=e.Internals.DDSTools.GetDDSInfo(t),r=(i.isRGB||i.isLuminance||i.mipmapCount>1)&&!n;a.bindTexture(a.TEXTURE_CUBE_MAP,h),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,1),e.Internals.DDSTools.UploadDDSLevels(o._gl,o.getCaps().s3tc,t,i,r,6),n||i.isFourCC||1!==i.mipmapCount||a.generateMipmap(a.TEXTURE_CUBE_MAP),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_MIN_FILTER,r?a.LINEAR_MIPMAP_LINEAR:a.LINEAR),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_CUBE_MAP,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.bindTexture(a.TEXTURE_CUBE_MAP,null),o.resetTextureCache(),h._width=i.width,h._height=i.height,h.isReady=!0},null,null,!0):s(t,i,function(t){var i=e.Tools.GetExponentOfTwo(t[0].width,o._caps.maxCubemapTextureSize),r=i;o._prepareWorkingCanvas(),o._workingCanvas.width=i,o._workingCanvas.height=r;var s=[a.TEXTURE_CUBE_MAP_POSITIVE_X,a.TEXTURE_CUBE_MAP_POSITIVE_Y,a.TEXTURE_CUBE_MAP_POSITIVE_Z,a.TEXTURE_CUBE_MAP_NEGATIVE_X,a.TEXTURE_CUBE_MAP_NEGATIVE_Y,a.TEXTURE_CUBE_MAP_NEGATIVE_Z];a.bindTexture(a.TEXTURE_CUBE_MAP,h),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,0);for(var c=0;c>v;u.texImage2D(n[0],v,d,y,y,0,d,p,s[v][0]),u.texImage2D(n[1],v,d,y,y,0,d,p,s[v][2]),u.texImage2D(n[2],v,d,y,y,0,d,p,s[v][4]),u.texImage2D(n[3],v,d,y,y,0,d,p,s[v][1]),u.texImage2D(n[4],v,d,y,y,0,d,p,s[v][3]),u.texImage2D(n[5],v,d,y,y,0,d,p,s[v][5])}}else{for(var x=0;xA;A++)for(var E=0;g>E;E++){var T=3*(E*_+A),C=4*(E*_+A);P[C+0]=b[T+0],P[C+1]=b[T+1],P[C+2]=b[T+2],P[C+3]=1}u.texImage2D(n[x],0,u.RGBA,_,g,0,u.RGBA,p,P)}u.generateMipmap(u.TEXTURE_CUBE_MAP)}}else a=!0;p!==u.FLOAT||l._caps.textureFloatLinearFiltering?(u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,a?u.LINEAR:u.LINEAR_MIPMAP_LINEAR)):(u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MAG_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_MIN_FILTER,u.NEAREST)),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_CUBE_MAP,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.bindTexture(u.TEXTURE_CUBE_MAP,null),f.isReady=!0,l.resetTextureCache(),i._removePendingData(f)};return e.Tools.LoadFile(t,function(e){y(e)},v,i.database,!0),f},o.prototype._releaseTexture=function(e){var t=this._gl;e._framebuffer&&t.deleteFramebuffer(e._framebuffer),e._depthBuffer&&t.deleteRenderbuffer(e._depthBuffer),t.deleteTexture(e),this.unbindAllTextures();var i=this._loadedTexturesCache.indexOf(e);-1!==i&&this._loadedTexturesCache.splice(i,1)},o.prototype.bindSamplers=function(e){this._gl.useProgram(e.getProgram());for(var t=e.getSamplers(),i=0;ie||(this._gl.activeTexture(this._gl["TEXTURE"+e]),this._gl.bindTexture(this._gl.TEXTURE_2D,t),this._activeTexturesCache[e]=null)},o.prototype.setTextureFromPostProcess=function(e,t){this._bindTexture(e,t._textures.data[t._currentRenderTextureInd])},o.prototype.unbindAllTextures=function(){for(var e=0;et)){if(!i||!i.isReady())return void(null!=this._activeTexturesCache[t]&&(this._gl.activeTexture(this._gl["TEXTURE"+t]),this._gl.bindTexture(this._gl.TEXTURE_2D,null),this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,null),this._activeTexturesCache[t]=null));var r=!1;if(i instanceof e.VideoTexture)this._gl.activeTexture(this._gl["TEXTURE"+t]),r=!0,i.update();else if(i.delayLoadState===o.DELAYLOADSTATE_NOTLOADED)return void i.delayLoad();if(this._activeTexturesCache[t]!==i){this._activeTexturesCache[t]=i;var n=i.getInternalTexture();if(r||this._gl.activeTexture(this._gl["TEXTURE"+t]),n.isCube){if(this._gl.bindTexture(this._gl.TEXTURE_CUBE_MAP,n),n._cachedCoordinatesMode!==i.coordinatesMode){n._cachedCoordinatesMode=i.coordinatesMode;var s=i.coordinatesMode!==e.Texture.CUBIC_MODE&&i.coordinatesMode!==e.Texture.SKYBOX_MODE?this._gl.REPEAT:this._gl.CLAMP_TO_EDGE;this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_S,s),this._gl.texParameteri(this._gl.TEXTURE_CUBE_MAP,this._gl.TEXTURE_WRAP_T,s)}this._setAnisotropicLevel(this._gl.TEXTURE_CUBE_MAP,i)}else{if(this._gl.bindTexture(this._gl.TEXTURE_2D,n),n._cachedWrapU!==i.wrapU)switch(n._cachedWrapU=i.wrapU,i.wrapU){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_S,this._gl.MIRRORED_REPEAT)}if(n._cachedWrapV!==i.wrapV)switch(n._cachedWrapV=i.wrapV,i.wrapV){case e.Texture.WRAP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.REPEAT);break;case e.Texture.CLAMP_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.CLAMP_TO_EDGE);break;case e.Texture.MIRROR_ADDRESSMODE:this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_WRAP_T,this._gl.MIRRORED_REPEAT)}this._setAnisotropicLevel(this._gl.TEXTURE_2D,i)}}}},o.prototype._setAnisotropicLevel=function(t,i){var r=this._caps.textureAnisotropicFilterExtension,n=i.anisotropicFilteringLevel;i.getInternalTexture().samplingMode===e.Texture.NEAREST_SAMPLINGMODE&&(n=1),r&&i._cachedAnisotropicFilteringLevel!==n&&(this._gl.texParameterf(t,r.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(n,this._caps.maxAnisotropy)),i._cachedAnisotropicFilteringLevel=n)},o.prototype.readPixels=function(e,t,i,r){var n=new Uint8Array(r*i*4);return this._gl.readPixels(e,t,i,r,this._gl.RGBA,this._gl.UNSIGNED_BYTE,n),n},o.prototype.addExternalData=function(e,t){return this._externalData.add(e,t)},o.prototype.getExternalData=function(e){return this._externalData.get(e)},o.prototype.getOrAddExternalDataWithFactory=function(e,t){return this._externalData.getOrAddWithFactory(e,t)},o.prototype.removeExternalData=function(e){return this._externalData.remove(e)},o.prototype.releaseInternalTexture=function(e){if(e&&(e.references--,0===e.references)){var t=this.getLoadedTexturesCache(),i=t.indexOf(e);i>-1&&t.splice(i,1),this._releaseTexture(e)}},o.prototype.dispose=function(){for(this.hideLoadingUI(),this.stopRenderLoop();this.scenes.length;)this.scenes[0].dispose();o.audioEngine.dispose();for(var e in this._compiledEffects)this._gl.deleteProgram(this._compiledEffects[e]._program);if(this._vertexAttribArraysEnabled)for(var t=0,i=this._vertexAttribArraysEnabled.length;i>t;t++)t>this._gl.VERTEX_ATTRIB_ARRAY_ENABLED||!this._vertexAttribArraysEnabled[t]||this._gl.disableVertexAttribArray(t);this._gl=null,window.removeEventListener("blur",this._onBlur),window.removeEventListener("focus",this._onFocus),document.removeEventListener("fullscreenchange",this._onFullscreenChange),document.removeEventListener("mozfullscreenchange",this._onFullscreenChange),document.removeEventListener("webkitfullscreenchange",this._onFullscreenChange),document.removeEventListener("msfullscreenchange",this._onFullscreenChange),document.removeEventListener("pointerlockchange",this._onPointerLockChange),document.removeEventListener("mspointerlockchange",this._onPointerLockChange),document.removeEventListener("mozpointerlockchange",this._onPointerLockChange),document.removeEventListener("webkitpointerlockchange",this._onPointerLockChange)},o.prototype.displayLoadingUI=function(){this._loadingScreen.displayLoadingUI()},o.prototype.hideLoadingUI=function(){this._loadingScreen.hideLoadingUI()},Object.defineProperty(o.prototype,"loadingScreen",{get:function(){return this._loadingScreen},set:function(e){this._loadingScreen=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"loadingUIText",{set:function(e){this._loadingScreen.loadingUIText=e},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"loadingUIBackgroundColor",{set:function(e){this._loadingScreen.loadingUIBackgroundColor=e},enumerable:!0,configurable:!0}),o.prototype.getFps=function(){return this.fps},o.prototype.getDeltaTime=function(){return this.deltaTime},o.prototype._measureFps=function(){this.previousFramesDuration.push(e.Tools.Now);var t=this.previousFramesDuration.length;if(t>=2&&(this.deltaTime=this.previousFramesDuration[t-1]-this.previousFramesDuration[t-2]),t>=this.fpsRange){t>this.fpsRange&&(this.previousFramesDuration.splice(0,1),t=this.previousFramesDuration.length);for(var i=0,r=0;t-1>r;r++)i+=this.previousFramesDuration[r+1]-this.previousFramesDuration[r];this.fps=1e3/(i/(t-1))}},o.isSupported=function(){try{if(navigator.isCocoonJS)return!0;var e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");return null!=t&&!!window.WebGLRenderingContext}catch(i){return!1}},o._ALPHA_DISABLE=0,o._ALPHA_ADD=1,o._ALPHA_COMBINE=2,o._ALPHA_SUBTRACT=3,o._ALPHA_MULTIPLY=4,o._ALPHA_MAXIMIZED=5,o._ALPHA_ONEONE=6,o._DELAYLOADSTATE_NONE=0,o._DELAYLOADSTATE_LOADED=1,o._DELAYLOADSTATE_LOADING=2,o._DELAYLOADSTATE_NOTLOADED=4,o._TEXTUREFORMAT_ALPHA=0,o._TEXTUREFORMAT_LUMINANCE=1,o._TEXTUREFORMAT_LUMINANCE_ALPHA=2,o._TEXTUREFORMAT_RGB=4,o._TEXTUREFORMAT_RGBA=5,o._TEXTURETYPE_UNSIGNED_INT=0,o._TEXTURETYPE_FLOAT=1,o.CollisionsEpsilon=.001,o.CodeRepository="src/",o.ShadersRepository="src/Shaders/",o}();e.Engine=c}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t){this.state="",this.animations=new Array,this._ranges={},this._childrenFlag=-1,this._isEnabled=!0,this._isReady=!0,this._currentRenderId=-1,this._parentRenderId=-1,this.name=e,this.id=e,this._scene=t,this._initCache()}return Object.defineProperty(t.prototype,"parent",{get:function(){return this._parentNode},set:function(e){if(this._parentNode!==e){if(this._parentNode){var t=this._parentNode._children.indexOf(this);-1!==t&&this._parentNode._children.splice(t,1)}this._parentNode=e,this._parentNode&&(this._parentNode._children||(this._parentNode._children=new Array),this._parentNode._children.push(this))}},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getEngine=function(){return this._scene.getEngine()},t.prototype.getWorldMatrix=function(){return e.Matrix.Identity()},t.prototype._initCache=function(){this._cache={},this._cache.parent=void 0},t.prototype.updateCache=function(e){!e&&this.isSynchronized()||(this._cache.parent=this.parent,this._updateCache())},t.prototype._updateCache=function(e){},t.prototype._isSynchronized=function(){return!0},t.prototype._markSyncedWithParent=function(){this._parentRenderId=this.parent._currentRenderId},t.prototype.isSynchronizedWithParent=function(){return this.parent?this._parentRenderId!==this.parent._currentRenderId?!1:this.parent.isSynchronized():!0},t.prototype.isSynchronized=function(e){var t=this.hasNewParent();return t=t||!this.isSynchronizedWithParent(),t=t||!this._isSynchronized(),e&&this.updateCache(!0),!t},t.prototype.hasNewParent=function(e){return this._cache.parent===this.parent?!1:(e&&(this._cache.parent=this.parent),!0)},t.prototype.isReady=function(){return this._isReady},t.prototype.isEnabled=function(){return this._isEnabled?this.parent?this.parent.isEnabled():!0:!1},t.prototype.setEnabled=function(e){this._isEnabled=e},t.prototype.isDescendantOf=function(e){return this.parent?this.parent===e?!0:this.parent.isDescendantOf(e):!1},t.prototype._getDescendants=function(e,t,i){if(void 0===t&&(t=!1),this._children)for(var r=0;rn;n++)this.animations[n]&&this.animations[n].createRange(t,i,r)}},t.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var i=0,r=this.animations.length;r>i;i++)this.animations[i]&&this.animations[i].deleteRange(e,t);this._ranges[e]=void 0},t.prototype.getAnimationRange=function(e){return this._ranges[e]},t.prototype.beginAnimation=function(e,t,i,r){var n=this.getAnimationRange(e);return n?void this._scene.beginAnimation(this,n.from,n.to,t,i,r):null},t.prototype.serializeAnimationRanges=function(){var e=[];for(var t in this._ranges){var i={};i.name=t,i.from=this._ranges[t].from,i.to=this._ranges[t].to,e.push(i)}return e},t.prototype.dispose=function(){this.parent=null},t.ParseAnimationRanges=function(e,t,i){if(t.ranges)for(var r=0;r0&&this._textureLoadingCallback(e)}this._currentScene.render()}},t.prototype.drag=function(e){e.stopPropagation(),e.preventDefault()},t.prototype.drop=function(e){e.stopPropagation(),e.preventDefault(),this.loadFiles(e)},t.prototype.loadFiles=function(e){if(this._startingProcessingFilesCallback&&this._startingProcessingFilesCallback(),e&&e.dataTransfer&&e.dataTransfer.files&&(this._filesToLoad=e.dataTransfer.files),e&&e.target&&e.target.files&&(this._filesToLoad=e.target.files),this._filesToLoad&&this._filesToLoad.length>0){for(var i=0;i0&&(e.Tools.ClearLogCache(),e.Tools.Log("Babylon.js engine (v"+e.Engine.Version+") launched")),this._engine.stopRenderLoop(),this._currentScene.dispose()),e.SceneLoader.Load("file:",this._sceneFileToLoad,this._engine,function(e){i._currentScene=e,i._currentScene.executeWhenReady(function(){i._currentScene.activeCamera&&0!==i._currentScene.lights.length||i._currentScene.createDefaultCameraOrLight(),i._currentScene.activeCamera.attachControl(i._canvas),i._sceneLoadedCallback&&i._sceneLoadedCallback(t._sceneFileToLoad,i._currentScene),i._engine.runRenderLoop(function(){i.renderFunction()})})},function(e){t._progressCallback&&t._progressCallback(e)})):e.Tools.Error("Please provide a valid .babylon file.")},t.FilesTextures=new Array,t.FilesToLoad=new Array,t}();e.FilesInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t,i){this.bu=e,this.bv=t,this.distance=i,this.faceId=0,this.subMeshId=0}return e}();e.IntersectionInfo=t;var i=function(){function t(){this.hit=!1,this.distance=0,this.pickedPoint=null,this.pickedMesh=null,this.bu=0,this.bv=0,this.faceId=-1,this.subMeshId=0,this.pickedSprite=null}return t.prototype.getNormal=function(t,i){if(void 0===t&&(t=!1),void 0===i&&(i=!0),!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.NormalKind))return null;var r,n=this.pickedMesh.getIndices();if(i){var o=this.pickedMesh.getVerticesData(e.VertexBuffer.NormalKind),s=e.Vector3.FromArray(o,3*n[3*this.faceId]),a=e.Vector3.FromArray(o,3*n[3*this.faceId+1]),h=e.Vector3.FromArray(o,3*n[3*this.faceId+2]);s=s.scale(this.bu),a=a.scale(this.bv),h=h.scale(1-this.bu-this.bv),r=new e.Vector3(s.x+a.x+h.x,s.y+a.y+h.y,s.z+a.z+h.z)}else{var c=this.pickedMesh.getVerticesData(e.VertexBuffer.PositionKind),l=e.Vector3.FromArray(c,3*n[3*this.faceId]),u=e.Vector3.FromArray(c,3*n[3*this.faceId+1]),f=e.Vector3.FromArray(c,3*n[3*this.faceId+2]),d=l.subtract(u),p=f.subtract(u);r=e.Vector3.Cross(d,p)}return t&&(r=e.Vector3.TransformNormal(r,this.pickedMesh.getWorldMatrix())),e.Vector3.Normalize(r)},t.prototype.getTextureCoordinates=function(){if(!this.pickedMesh||!this.pickedMesh.isVerticesDataPresent(e.VertexBuffer.UVKind))return null;var t=this.pickedMesh.getIndices(),i=this.pickedMesh.getVerticesData(e.VertexBuffer.UVKind),r=e.Vector2.FromArray(i,2*t[3*this.faceId]),n=e.Vector2.FromArray(i,2*t[3*this.faceId+1]),o=e.Vector2.FromArray(i,2*t[3*this.faceId+2]);return r=r.scale(1-this.bu-this.bv),n=n.scale(this.bu),o=o.scale(this.bv),new e.Vector2(r.x+n.x+o.x,r.y+n.y+o.y)},t}();e.PickingInfo=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.minimum=t,this.maximum=i,this._tempRadiusVector=e.Vector3.Zero();var r=e.Vector3.Distance(t,i);this.center=e.Vector3.Lerp(t,i,.5),this.radius=.5*r,this.centerWorld=e.Vector3.Zero(),this._update(e.Matrix.Identity())}return t.prototype._update=function(t){e.Vector3.TransformCoordinatesToRef(this.center,t,this.centerWorld),e.Vector3.TransformNormalFromFloatsToRef(1,1,1,t,this._tempRadiusVector),this.radiusWorld=Math.max(Math.abs(this._tempRadiusVector.x),Math.abs(this._tempRadiusVector.y),Math.abs(this._tempRadiusVector.z))*this.radius},t.prototype.isInFrustum=function(e){for(var t=0;6>t;t++)if(e[t].dotCoordinate(this.centerWorld)<=-this.radiusWorld)return!1;return!0},t.prototype.intersectsPoint=function(t){var i=this.centerWorld.x-t.x,r=this.centerWorld.y-t.y,n=this.centerWorld.z-t.z,o=Math.sqrt(i*i+r*r+n*n);return!(Math.abs(this.radiusWorld-o)this.maximumWorld.x&&(this.maximumWorld.x=r.x),r.y>this.maximumWorld.y&&(this.maximumWorld.y=r.y),r.z>this.maximumWorld.z&&(this.maximumWorld.z=r.z)}this.maximumWorld.addToRef(this.minimumWorld,this.center),this.center.scaleInPlace(.5),e.Vector3.FromFloatArrayToRef(t.m,0,this.directions[0]),e.Vector3.FromFloatArrayToRef(t.m,4,this.directions[1]),e.Vector3.FromFloatArrayToRef(t.m,8,this.directions[2]),this._worldMatrix=t},t.prototype.isInFrustum=function(e){return t.IsInFrustum(this.vectorsWorld,e)},t.prototype.isCompletelyInFrustum=function(e){return t.IsCompletelyInFrustum(this.vectorsWorld,e)},t.prototype.intersectsPoint=function(t){var i=-e.Epsilon;return this.maximumWorld.x-t.xt.x-this.minimumWorld.x?!1:this.maximumWorld.y-t.yt.y-this.minimumWorld.y?!1:!(this.maximumWorld.z-t.zt.z-this.minimumWorld.z)},t.prototype.intersectsSphere=function(e){return t.IntersectsSphere(this.minimumWorld,this.maximumWorld,e.centerWorld,e.radiusWorld)},t.prototype.intersectsMinMax=function(e,t){return this.maximumWorld.xt.x?!1:this.maximumWorld.yt.y?!1:!(this.maximumWorld.zt.z)},t.Intersects=function(e,t){return e.maximumWorld.xt.maximumWorld.x?!1:e.maximumWorld.yt.maximumWorld.y?!1:!(e.maximumWorld.zt.maximumWorld.z)},t.IntersectsSphere=function(t,i,r,n){var o=e.Vector3.Clamp(r,t,i),s=e.Vector3.DistanceSquared(r,o);return n*n>=s},t.IsCompletelyInFrustum=function(e,t){for(var i=0;6>i;i++)for(var r=0;8>r;r++)if(t[i].dotCoordinate(e[r])<0)return!1;return!0},t.IsInFrustum=function(e,t){for(var i=0;6>i;i++){for(var r=8,n=0;8>n&&t[i].dotCoordinate(e[n])<0;n++)--r;if(0===r)return!1}return!0},t}();e.BoundingBox=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t,i){var r=e.Vector3.Dot(i.center,t),n=Math.abs(e.Vector3.Dot(i.directions[0],t))*i.extendSize.x,o=Math.abs(e.Vector3.Dot(i.directions[1],t))*i.extendSize.y,s=Math.abs(e.Vector3.Dot(i.directions[2],t))*i.extendSize.z,a=n+o+s;return{min:r-a,max:r+a}},i=function(e,t,i,r){return!(e>r||i>t)},r=function(e,r,n){var o=t(e,r),s=t(e,n);return i(o.min,o.max,s.min,s.max)},n=function(){function t(t,i){this.minimum=t,this.maximum=i,this._isLocked=!1,this.boundingBox=new e.BoundingBox(t,i),this.boundingSphere=new e.BoundingSphere(t,i)}return Object.defineProperty(t.prototype,"isLocked",{get:function(){return this._isLocked},set:function(e){this._isLocked=e},enumerable:!0,configurable:!0}),t.prototype.update=function(e){this._isLocked||(this.boundingBox._update(e),this.boundingSphere._update(e))},t.prototype.isInFrustum=function(e){return this.boundingSphere.isInFrustum(e)?this.boundingBox.isInFrustum(e):!1},t.prototype.isCompletelyInFrustum=function(e){return this.boundingBox.isCompletelyInFrustum(e)},t.prototype._checkCollision=function(e){return e._canDoCollision(this.boundingSphere.centerWorld,this.boundingSphere.radiusWorld,this.boundingBox.minimumWorld,this.boundingBox.maximumWorld)},t.prototype.intersectsPoint=function(e){return this.boundingSphere.centerWorld&&this.boundingSphere.intersectsPoint(e)?!!this.boundingBox.intersectsPoint(e):!1},t.prototype.intersects=function(t,i){if(!this.boundingSphere.centerWorld||!t.boundingSphere.centerWorld)return!1;if(!e.BoundingSphere.Intersects(this.boundingSphere,t.boundingSphere))return!1;if(!e.BoundingBox.Intersects(this.boundingBox,t.boundingBox))return!1;if(!i)return!0;var n=this.boundingBox,o=t.boundingBox;return r(n.directions[0],n,o)&&r(n.directions[1],n,o)&&r(n.directions[2],n,o)&&r(o.directions[0],n,o)&&r(o.directions[1],n,o)&&r(o.directions[2],n,o)&&r(e.Vector3.Cross(n.directions[0],o.directions[0]),n,o)&&r(e.Vector3.Cross(n.directions[0],o.directions[1]),n,o)&&r(e.Vector3.Cross(n.directions[0],o.directions[2]),n,o)&&r(e.Vector3.Cross(n.directions[1],o.directions[0]),n,o)&&r(e.Vector3.Cross(n.directions[1],o.directions[1]),n,o)&&r(e.Vector3.Cross(n.directions[1],o.directions[2]),n,o)&&r(e.Vector3.Cross(n.directions[2],o.directions[0]),n,o)&&r(e.Vector3.Cross(n.directions[2],o.directions[1]),n,o)?!!r(e.Vector3.Cross(n.directions[2],o.directions[2]),n,o):!1},t}();e.BoundingInfo=n}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t,i){void 0===i&&(i=Number.MAX_VALUE),this.origin=e,this.direction=t,this.length=i}return t.prototype.intersectsBoxMinMax=function(e,t){var i,r,n,o,s=0,a=Number.MAX_VALUE;if(Math.abs(this.direction.x)<1e-7){if(this.origin.xt.x)return!1}else if(i=1/this.direction.x,r=(e.x-this.origin.x)*i,n=(t.x-this.origin.x)*i,n===-(1/0)&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,a),s>a)return!1;if(Math.abs(this.direction.y)<1e-7){if(this.origin.yt.y)return!1}else if(i=1/this.direction.y,r=(e.y-this.origin.y)*i,n=(t.y-this.origin.y)*i,n===-(1/0)&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,a),s>a)return!1;if(Math.abs(this.direction.z)<1e-7){if(this.origin.zt.z)return!1}else if(i=1/this.direction.z,r=(e.z-this.origin.z)*i,n=(t.z-this.origin.z)*i,n===-(1/0)&&(n=1/0),r>n&&(o=r,r=n,n=o),s=Math.max(r,s),a=Math.min(n,a),s>a)return!1;return!0},t.prototype.intersectsBox=function(e){return this.intersectsBoxMinMax(e.minimum,e.maximum)},t.prototype.intersectsSphere=function(e){var t=e.center.x-this.origin.x,i=e.center.y-this.origin.y,r=e.center.z-this.origin.z,n=t*t+i*i+r*r,o=e.radius*e.radius;if(o>=n)return!0;var s=t*this.direction.x+i*this.direction.y+r*this.direction.z;if(0>s)return!1;var a=n-s*s;return o>=a},t.prototype.intersectsTriangle=function(t,i,r){this._edge1||(this._edge1=e.Vector3.Zero(),this._edge2=e.Vector3.Zero(),this._pvec=e.Vector3.Zero(),this._tvec=e.Vector3.Zero(),this._qvec=e.Vector3.Zero()),i.subtractToRef(t,this._edge1),r.subtractToRef(t,this._edge2),e.Vector3.CrossToRef(this.direction,this._edge2,this._pvec);var n=e.Vector3.Dot(this._edge1,this._pvec);if(0===n)return null;var o=1/n;this.origin.subtractToRef(t,this._tvec);var s=e.Vector3.Dot(this._tvec,this._pvec)*o;if(0>s||s>1)return null;e.Vector3.CrossToRef(this._tvec,this._edge1,this._qvec);var a=e.Vector3.Dot(this.direction,this._qvec)*o;if(0>a||s+a>1)return null;var h=e.Vector3.Dot(this._edge2,this._qvec)*o;return h>this.length?null:new e.IntersectionInfo(s,a,h)},t.prototype.intersectsPlane=function(t){var i,r=e.Vector3.Dot(t.normal,this.direction);if(Math.abs(r)<9.99999997475243e-7)return null;var n=e.Vector3.Dot(t.normal,this.origin);return i=(-t.d-n)/r,0>i?-9.99999997475243e-7>i?null:0:i},t.prototype.intersectionSegment=function(i,r,n){var o,s,a,h,c=this.origin.add(this.direction.multiplyByFloats(t.rayl,t.rayl,t.rayl)),l=r.subtract(i),u=c.subtract(this.origin),f=i.subtract(this.origin),d=e.Vector3.Dot(l,l),p=e.Vector3.Dot(l,u),_=e.Vector3.Dot(u,u),g=e.Vector3.Dot(l,f),m=e.Vector3.Dot(u,f),v=d*_-p*p,y=v,x=v;
+vs?(s=0,h=m,x=_):s>y&&(s=y,h=m+p,x=_)),0>h?(h=0,0>-g?s=0:-g>d?s=y:(s=-g,y=d)):h>x&&(h=x,0>-g+p?s=0:-g+p>d?s=y:(s=-g+p,y=d)),o=Math.abs(s)0&&a<=this.length&&P.lengthSquared()e.Engine.CollisionsEpsilon&&o.position.addInPlace(o._diffPositionForCollisions),r&&o.onCollideObservable.notifyObservers(r),o.onCollisionPositionChangeObservable.notifyObservers(o.position)},n.addMesh(this)}return __extends(i,t),Object.defineProperty(i,"BILLBOARDMODE_NONE",{get:function(){return i._BILLBOARDMODE_NONE},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_X",{get:function(){return i._BILLBOARDMODE_X},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Y",{get:function(){return i._BILLBOARDMODE_Y},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_Z",{get:function(){return i._BILLBOARDMODE_Z},enumerable:!0,configurable:!0}),Object.defineProperty(i,"BILLBOARDMODE_ALL",{get:function(){return i._BILLBOARDMODE_ALL},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onCollide",{set:function(e){this._onCollideObserver&&this.onCollideObservable.remove(this._onCollideObserver),this._onCollideObserver=this.onCollideObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"onCollisionPositionChange",{set:function(e){this._onCollisionPositionChangeObserver&&this.onCollisionPositionChangeObservable.remove(this._onCollisionPositionChangeObserver),this._onCollisionPositionChangeObserver=this.onCollisionPositionChangeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"skeleton",{get:function(){return this._skeleton},set:function(e){this._skeleton&&this._skeleton.needInitialSkinMatrix&&this._skeleton._unregisterMeshWithPoseMatrix(this),e&&e.needInitialSkinMatrix&&e._registerMeshWithPoseMatrix(this),this._skeleton=e,this._skeleton||(this._bonesTransformMatrices=null)},enumerable:!0,configurable:!0}),i.prototype.toString=function(t){var i="Name: "+this.name+", isInstance: "+(this instanceof e.InstancedMesh?"YES":"NO");return i+=", # of submeshes: "+(this.subMeshes?this.subMeshes.length:0),this._skeleton&&(i+=", skeleton: "+this._skeleton.name),t&&(i+=", billboard mode: "+["NONE","X","Y",null,"Z",null,null,"ALL"][this.billboardMode],i+=", freeze wrld mat: "+(this._isWorldMatrixFrozen||this._waitingFreezeWorldMatrix?"YES":"NO")),i},Object.defineProperty(i.prototype,"rotation",{get:function(){return this._rotation},set:function(e){this._rotation=e},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"scaling",{get:function(){return this._scaling},set:function(e){this._scaling=e,this.physicsImpostor&&this.physicsImpostor.forceUpdate()},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rotationQuaternion",{get:function(){return this._rotationQuaternion},set:function(e){this._rotationQuaternion=e,e&&this.rotation.length()&&this.rotation.copyFromFloats(0,0,0)},enumerable:!0,configurable:!0}),i.prototype.updatePoseMatrix=function(e){this._poseMatrix.copyFrom(e)},i.prototype.getPoseMatrix=function(){return this._poseMatrix},i.prototype.disableEdgesRendering=function(){void 0!==this._edgesRenderer&&(this._edgesRenderer.dispose(),this._edgesRenderer=void 0)},i.prototype.enableEdgesRendering=function(t,i){void 0===t&&(t=.95),void 0===i&&(i=!1),this.disableEdgesRendering(),this._edgesRenderer=new e.EdgesRenderer(this,t,i)},Object.defineProperty(i.prototype,"isBlocked",{get:function(){return!1},enumerable:!0,configurable:!0}),i.prototype.getLOD=function(e){return this},i.prototype.getTotalVertices=function(){return 0},i.prototype.getIndices=function(){return null},i.prototype.getVerticesData=function(e){return null},i.prototype.isVerticesDataPresent=function(e){return!1},i.prototype.getBoundingInfo=function(){return this._masterMesh?this._masterMesh.getBoundingInfo():(this._boundingInfo||this._updateBoundingInfo(),this._boundingInfo)},Object.defineProperty(i.prototype,"useBones",{get:function(){return this.skeleton&&this.getScene().skeletonsEnabled&&this.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&this.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)},enumerable:!0,configurable:!0}),i.prototype._preActivate=function(){},i.prototype._preActivateForIntermediateRendering=function(e){},i.prototype._activate=function(e){this._renderId=e},i.prototype.getWorldMatrix=function(){return this._masterMesh?this._masterMesh.getWorldMatrix():(this._currentRenderId!==this.getScene().getRenderId()&&this.computeWorldMatrix(),this._worldMatrix)},Object.defineProperty(i.prototype,"worldMatrixFromCache",{get:function(){return this._worldMatrix},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"absolutePosition",{get:function(){return this._absolutePosition},enumerable:!0,configurable:!0}),i.prototype.freezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0),this._isWorldMatrixFrozen=!0},i.prototype.unfreezeWorldMatrix=function(){this._isWorldMatrixFrozen=!1,this.computeWorldMatrix(!0)},Object.defineProperty(i.prototype,"isWorldMatrixFrozen",{get:function(){return this._isWorldMatrixFrozen},enumerable:!0,configurable:!0}),i.prototype.rotate=function(t,i,r){t.normalize(),this.rotationQuaternion||(this.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z),this.rotation=e.Vector3.Zero());var n;if(r&&r!==e.Space.LOCAL){if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert(),t=e.Vector3.TransformNormal(t,o)}n=e.Quaternion.RotationAxis(t,i),this.rotationQuaternion=n.multiply(this.rotationQuaternion)}else n=e.Quaternion.RotationAxis(t,i),this.rotationQuaternion=this.rotationQuaternion.multiply(n)},i.prototype.translate=function(t,i,r){var n=t.scale(i);if(r&&r!==e.Space.LOCAL)this.setAbsolutePosition(this.getAbsolutePosition().add(n));else{var o=this.getPositionExpressedInLocalSpace().add(n);this.setPositionWithLocalVector(o)}},i.prototype.getAbsolutePosition=function(){return this.computeWorldMatrix(),this._absolutePosition},i.prototype.setAbsolutePosition=function(t){if(t){var i,r,n;if(void 0===t.x){if(arguments.length<3)return;i=arguments[0],r=arguments[1],n=arguments[2]}else i=t.x,r=t.y,n=t.z;if(this.parent){var o=this.parent.getWorldMatrix().clone();o.invert();var s=new e.Vector3(i,r,n);this.position=e.Vector3.TransformCoordinates(s,o)}else this.position.x=i,this.position.y=r,this.position.z=n}},i.prototype.movePOV=function(e,t,i){this.position.addInPlace(this.calcMovePOV(e,t,i))},i.prototype.calcMovePOV=function(t,i,r){var n=new e.Matrix,o=this.rotationQuaternion?this.rotationQuaternion:e.Quaternion.RotationYawPitchRoll(this.rotation.y,this.rotation.x,this.rotation.z);o.toRotationMatrix(n);var s=e.Vector3.Zero(),a=this.definedFacingForward?-1:1;return e.Vector3.TransformCoordinatesFromFloatsToRef(t*a,i,r*a,n,s),s},i.prototype.rotatePOV=function(e,t,i){this.rotation.addInPlace(this.calcRotatePOV(e,t,i))},i.prototype.calcRotatePOV=function(t,i,r){var n=this.definedFacingForward?1:-1;return new e.Vector3(t*n,i,r*n)},i.prototype.setPivotMatrix=function(e){this._pivotMatrix=e,this._cache.pivotMatrixUpdated=!0},i.prototype.getPivotMatrix=function(){return this._pivotMatrix},i.prototype._isSynchronized=function(){if(this._isDirty)return!1;if(this.billboardMode!==this._cache.billboardMode||this.billboardMode!==i.BILLBOARDMODE_NONE)return!1;if(this._cache.pivotMatrixUpdated)return!1;if(this.infiniteDistance)return!1;if(!this._cache.position.equals(this.position))return!1;if(this.rotationQuaternion){if(!this._cache.rotationQuaternion.equals(this.rotationQuaternion))return!1}else if(!this._cache.rotation.equals(this.rotation))return!1;return!!this._cache.scaling.equals(this.scaling)},i.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.localMatrixUpdated=!1,this._cache.position=e.Vector3.Zero(),this._cache.scaling=e.Vector3.Zero(),this._cache.rotation=e.Vector3.Zero(),this._cache.rotationQuaternion=new e.Quaternion(0,0,0,0),this._cache.billboardMode=-1},i.prototype.markAsDirty=function(e){"rotation"===e&&(this.rotationQuaternion=null),this._currentRenderId=Number.MAX_VALUE,this._isDirty=!0},i.prototype._updateBoundingInfo=function(){this._boundingInfo=this._boundingInfo||new e.BoundingInfo(this.absolutePosition,this.absolutePosition),this._boundingInfo.update(this.worldMatrixFromCache),this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)},i.prototype._updateSubMeshesBoundingInfo=function(e){if(this.subMeshes)for(var t=0;ts;s++)t._lastColliderWorldVertices.push(e.Vector3.TransformCoordinates(this._positions[s],i))}r._collide(t._trianglePlanes,t._lastColliderWorldVertices,this.getIndices(),t.indexStart,t.indexStart+t.indexCount,t.verticesStart,!!t.getMaterial()),r.collisionFound&&(r.collidedMesh=this)},i.prototype._processCollisionsForSubMeshes=function(e,t){var i,r;if(this._submeshesOctree&&this.useOctreeForCollisions){var n=e.velocityWorldLength+Math.max(e.radius.x,e.radius.y,e.radius.z),o=this._submeshesOctree.intersects(e.basePointWorld,n);r=o.length,i=o.data}else i=this.subMeshes,r=i.length;for(var s=0;r>s;s++){var a=i[s];r>1&&!a._checkCollision(e)||this._collideForSubMesh(a,t,e)}},i.prototype._checkCollision=function(t){this._boundingInfo._checkCollision(t)&&(e.Matrix.ScalingToRef(1/t.radius.x,1/t.radius.y,1/t.radius.z,this._collisionsScalingMatrix),this.worldMatrixFromCache.multiplyToRef(this._collisionsScalingMatrix,this._collisionsTransformMatrix),this._processCollisionsForSubMeshes(t,this._collisionsTransformMatrix))},i.prototype._generatePointsArray=function(){return!1},i.prototype.intersects=function(t,i){var r=new e.PickingInfo;if(!(this.subMeshes&&this._boundingInfo&&t.intersectsSphere(this._boundingInfo.boundingSphere)&&t.intersectsBox(this._boundingInfo.boundingBox)))return r;if(!this._generatePointsArray())return r;var n,o,s=null;if(this._submeshesOctree&&this.useOctreeForPicking){var a=e.Ray.Transform(t,this.getWorldMatrix()),h=this._submeshesOctree.intersectsRay(a);o=h.length,n=h.data}else n=this.subMeshes,o=n.length;for(var c=0;o>c;c++){var l=n[c];if(!(o>1)||l.canIntersects(t)){var u=l.intersects(t,this._positions,this.getIndices(),i);if(u&&(i||!s||u.distance0&&-1===this.includedOnlyMeshes.indexOf(e)?!1:this.excludedMeshes.length>0&&-1!==this.excludedMeshes.indexOf(e)?!1:0!==this.includeOnlyWithLayerMask&&0===(this.includeOnlyWithLayerMask&e.layerMask)?!1:!(0!==this.excludeWithLayerMask&&this.excludeWithLayerMask&e.layerMask):!0},i.prototype.getWorldMatrix=function(){this._currentRenderId=this.getScene().getRenderId();var t=this._getWorldMatrix();return this.parent&&this.parent.getWorldMatrix?(this._parentedWorldMatrix||(this._parentedWorldMatrix=e.Matrix.Identity()),t.multiplyToRef(this.parent.getWorldMatrix(),this._parentedWorldMatrix),this._markSyncedWithParent(),this._parentedWorldMatrix):t},i.prototype.dispose=function(){this._shadowGenerator&&(this._shadowGenerator.dispose(),this._shadowGenerator=null),this.getScene().stopAnimation(this),this.getScene().removeLight(this),t.prototype.dispose.call(this)},i.prototype.getTypeID=function(){return 0},i.prototype.clone=function(t){return e.SerializationHelper.Clone(i.GetConstructorFromName(this.getTypeID(),t,this.getScene()),this)},i.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this);return t.type=this.getTypeID(),this.parent&&(t.parentId=this.parent.id),this.excludedMeshes.length>0&&(t.excludedMeshesIds=[],this.excludedMeshes.forEach(function(e){t.excludedMeshesIds.push(e.id)})),this.includedOnlyMeshes.length>0&&(t.includedOnlyMeshesIds=[],this.includedOnlyMeshes.forEach(function(e){t.includedOnlyMeshesIds.push(e.id)})),e.Animation.AppendSerializedAnimations(this,t),t.ranges=this.serializeAnimationRanges(),t},i.GetConstructorFromName=function(t,i,r){switch(t){case 0:return function(){return new e.PointLight(i,e.Vector3.Zero(),r)};case 1:return function(){return new e.DirectionalLight(i,e.Vector3.Zero(),r)};case 2:return function(){return new e.SpotLight(i,e.Vector3.Zero(),e.Vector3.Zero(),0,0,r)};case 3:return function(){return new e.HemisphericLight(i,e.Vector3.Zero(),r)}}},i.Parse=function(t,r){var n=e.SerializationHelper.Parse(i.GetConstructorFromName(t.type,t.name,r),t,r);if(t.excludedMeshesIds&&(n._excludedMeshesIds=t.excludedMeshesIds),t.includedOnlyMeshesIds&&(n._includedOnlyMeshesIds=t.includedOnlyMeshesIds),t.parentId&&(n._waitingParentId=t.parentId),t.animations){for(var o=0;othis._orthoRight&&(this._orthoRight=o.x),o.y>this._orthoTop&&(this._orthoTop=o.y)}}}var u=this._orthoRight-this._orthoLeft,f=this._orthoTop-this._orthoBottom;e.Matrix.OrthoOffCenterLHToRef(this._orthoLeft-u*this.shadowOrthoScale,this._orthoRight+u*this.shadowOrthoScale,this._orthoBottom-f*this.shadowOrthoScale,this._orthoTop+f*this.shadowOrthoScale,-n.maxZ,n.maxZ,t)},i.prototype.supportsVSM=function(){return!0},i.prototype.needRefreshPerFrame=function(){return!0},i.prototype.needCube=function(){return!1},i.prototype.getShadowDirection=function(e){return this.direction},i.prototype.computeTransformedPosition=function(){return this.parent&&this.parent.getWorldMatrix?(this.transformedPosition||(this.transformedPosition=e.Vector3.Zero()),e.Vector3.TransformCoordinatesToRef(this.position,this.parent.getWorldMatrix(),this.transformedPosition),!0):!1},i.prototype.transferToEffect=function(t,i){return this.parent&&this.parent.getWorldMatrix?(this._transformedDirection||(this._transformedDirection=e.Vector3.Zero()),e.Vector3.TransformNormalToRef(this.direction,this.parent.getWorldMatrix(),this._transformedDirection),void t.setFloat4(i,this._transformedDirection.x,this._transformedDirection.y,this._transformedDirection.z,1)):void t.setFloat4(i,this.direction.x,this.direction.y,this.direction.z,1)},i.prototype._getWorldMatrix=function(){return this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),e.Matrix.TranslationToRef(this.position.x,this.position.y,this.position.z,this._worldMatrix),this._worldMatrix},i.prototype.getTypeID=function(){return 1},__decorate([e.serializeAsVector3()],i.prototype,"position",void 0),__decorate([e.serializeAsVector3()],i.prototype,"direction",void 0),__decorate([e.serialize()],i.prototype,"shadowOrthoScale",void 0),__decorate([e.serialize()],i.prototype,"autoUpdateExtends",void 0),i}(e.Light);e.DirectionalLight=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(i,r){var n=this;this._filter=t.FILTER_NONE,this.blurScale=2,this._blurBoxOffset=0,this._bias=5e-5,this._lightDirection=e.Vector3.Zero(),this.forceBackFacesOnly=!1,this._darkness=0,this._transparencyShadow=!1,this._viewMatrix=e.Matrix.Zero(),this._projectionMatrix=e.Matrix.Zero(),this._transformMatrix=e.Matrix.Zero(),this._worldViewProjection=e.Matrix.Zero(),this._currentFaceIndex=0,this._currentFaceIndexCache=0,this._light=r,this._scene=r.getScene(),this._mapSize=i,r._shadowGenerator=this,this._shadowMap=new e.RenderTargetTexture(r.name+"_shadowMap",i,this._scene,!1,!0,e.Engine.TEXTURETYPE_UNSIGNED_INT,r.needCube()),this._shadowMap.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._shadowMap.anisotropicFilteringLevel=1,this._shadowMap.updateSamplingMode(e.Texture.NEAREST_SAMPLINGMODE),this._shadowMap.renderParticles=!1,this._shadowMap.onBeforeRenderObservable.add(function(e){n._currentFaceIndex=e}),this._shadowMap.onAfterUnbindObservable.add(function(){n.useBlurVarianceShadowMap&&(n._shadowMap2||(n._shadowMap2=new e.RenderTargetTexture(r.name+"_shadowMap",i,n._scene,!1),n._shadowMap2.wrapU=e.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.wrapV=e.Texture.CLAMP_ADDRESSMODE,n._shadowMap2.updateSamplingMode(e.Texture.TRILINEAR_SAMPLINGMODE),n._downSamplePostprocess=new e.PassPostProcess("downScale",1/n.blurScale,null,e.Texture.BILINEAR_SAMPLINGMODE,n._scene.getEngine()),n._downSamplePostprocess.onApplyObservable.add(function(e){e.setTexture("textureSampler",n._shadowMap)}),n.blurBoxOffset=1),n._scene.postProcessManager.directRender([n._downSamplePostprocess,n._boxBlurPostprocess],n._shadowMap2.getInternalTexture()))});var o=function(t){var i=t.getRenderingMesh(),r=n._scene,o=r.getEngine();o.setState(t.getMaterial().backFaceCulling);var s=i._getInstancesRenderList(t._id);if(!s.mustReturn){var a=null!==o.getCaps().instancedArrays&&null!==s.visibleInstances[t._id]&&void 0!==s.visibleInstances[t._id];if(n.isReady(t,a)){o.enableEffect(n._effect),i._bind(t,n._effect,e.Material.TriangleFillMode);var h=t.getMaterial();if(n._effect.setMatrix("viewProjection",n.getTransformMatrix()),n._effect.setVector3("lightPosition",n.getLight().position),n.getLight().needCube()&&n._effect.setFloat2("depthValues",r.activeCamera.minZ,r.activeCamera.maxZ),h&&h.needAlphaTesting()){var c=h.getAlphaTestTexture();n._effect.setTexture("diffuseSampler",c),n._effect.setMatrix("diffuseMatrix",c.getTextureMatrix())}i.useBones&&i.computeBonesUsingShaders&&n._effect.setMatrices("mBones",i.skeleton.getTransformMatrices(i)),n.forceBackFacesOnly&&o.setState(!0,0,!1,!0),i._processRendering(t,n._effect,e.Material.TriangleFillMode,s,a,function(e,t){return n._effect.setMatrix("world",t)}),n.forceBackFacesOnly&&o.setState(!0,0,!1,!1)}else n._shadowMap.resetRefreshCounter()}};this._shadowMap.customRenderFunction=function(e,t,i){var r;for(r=0;r4&&(n.push(e.VertexBuffer.MatricesIndicesExtraKind),n.push(e.VertexBuffer.MatricesWeightsExtraKind)),r.push("#define NUM_BONE_INFLUENCERS "+o.numBoneInfluencers),r.push("#define BonesPerMesh "+(o.skeleton.bones.length+1))):r.push("#define NUM_BONE_INFLUENCERS 0"),i&&(r.push("#define INSTANCES"),n.push("world0"),n.push("world1"),n.push("world2"),n.push("world3"));var a=r.join("\n");return this._cachedDefines!==a&&(this._cachedDefines=a,this._effect=this._scene.getEngine().createEffect("shadowMap",n,["world","mBones","viewProjection","diffuseMatrix","lightPosition","depthValues"],["diffuseSampler"],a)),this._effect.isReady()},t.prototype.getShadowMap=function(){return this._shadowMap},t.prototype.getShadowMapForRendering=function(){return this._shadowMap2?this._shadowMap2:this._shadowMap},t.prototype.getLight=function(){return this._light},t.prototype.getTransformMatrix=function(){var t=this._scene;if(this._currentRenderID===t.getRenderId()&&this._currentFaceIndexCache===this._currentFaceIndex)return this._transformMatrix;this._currentRenderID=t.getRenderId(),this._currentFaceIndexCache=this._currentFaceIndex;var i=this._light.position;return e.Vector3.NormalizeToRef(this._light.getShadowDirection(this._currentFaceIndex),this._lightDirection),1===Math.abs(e.Vector3.Dot(this._lightDirection,e.Vector3.Up()))&&(this._lightDirection.z=1e-13),this._light.computeTransformedPosition()&&(i=this._light.transformedPosition),!this._light.needRefreshPerFrame()&&this._cachedPosition&&this._cachedDirection&&i.equals(this._cachedPosition)&&this._lightDirection.equals(this._cachedDirection)||(this._cachedPosition=i.clone(),this._cachedDirection=this._lightDirection.clone(),e.Matrix.LookAtLHToRef(i,i.add(this._lightDirection),e.Vector3.Up(),this._viewMatrix),this._light.setShadowProjectionMatrix(this._projectionMatrix,this._viewMatrix,this.getShadowMap().renderList),this._viewMatrix.multiplyToRef(this._projectionMatrix,this._transformMatrix)),this._transformMatrix},t.prototype.getDarkness=function(){return this._darkness},t.prototype.setDarkness=function(e){e>=1?this._darkness=1:0>=e?this._darkness=0:this._darkness=e},t.prototype.setTransparencyShadow=function(e){this._transparencyShadow=e},t.prototype._packHalf=function(t){var i=255*t,r=i-Math.floor(i);return new e.Vector2(t-r/255,r)},t.prototype.dispose=function(){this._shadowMap.dispose(),this._shadowMap2&&this._shadowMap2.dispose(),this._downSamplePostprocess&&this._downSamplePostprocess.dispose(),this._boxBlurPostprocess&&this._boxBlurPostprocess.dispose()},t.prototype.serialize=function(){var e={};e.lightId=this._light.id,e.mapSize=this.getShadowMap().getRenderSize(),e.useVarianceShadowMap=this.useVarianceShadowMap,e.usePoissonSampling=this.usePoissonSampling,e.forceBackFacesOnly=this.forceBackFacesOnly,e.renderList=[];for(var t=0;ti.x+r?!1:i.x-r>t.x?!1:e.y>i.y+r?!1:i.y-r>t.y?!1:e.z>i.z+r?!1:!(i.z-r>t.z)},i=function(e,t,i,r){var n=t*t-4*e*i,o={root:0,found:!1};if(0>n)return o;var s=Math.sqrt(n),a=(-t-s)/(2*e),h=(-t+s)/(2*e);if(a>h){var c=h;h=a,a=c}return a>0&&r>a?(o.root=a,o.found=!0,o):h>0&&r>h?(o.root=h,o.found=!0,o):o},r=function(){function r(){this.radius=new e.Vector3(1,1,1),this.retry=0,this.basePointWorld=e.Vector3.Zero(),this.velocityWorld=e.Vector3.Zero(),this.normalizedVelocity=e.Vector3.Zero(),this._collisionPoint=e.Vector3.Zero(),this._planeIntersectionPoint=e.Vector3.Zero(),this._tempVector=e.Vector3.Zero(),this._tempVector2=e.Vector3.Zero(),this._tempVector3=e.Vector3.Zero(),this._tempVector4=e.Vector3.Zero(),this._edge=e.Vector3.Zero(),this._baseToVertex=e.Vector3.Zero(),this._destinationPoint=e.Vector3.Zero(),this._slidePlaneNormal=e.Vector3.Zero(),this._displacementVector=e.Vector3.Zero()}return r.prototype._initialize=function(t,i,r){this.velocity=i,e.Vector3.NormalizeToRef(i,this.normalizedVelocity),this.basePoint=t,t.multiplyToRef(this.radius,this.basePointWorld),i.multiplyToRef(this.radius,this.velocityWorld),this.velocityWorldLength=this.velocityWorld.length(),this.epsilon=r,this.collisionFound=!1},r.prototype._checkPointInTriangle=function(t,i,r,n,o){i.subtractToRef(t,this._tempVector),r.subtractToRef(t,this._tempVector2),e.Vector3.CrossToRef(this._tempVector,this._tempVector2,this._tempVector4);var s=e.Vector3.Dot(this._tempVector4,o);return 0>s?!1:(n.subtractToRef(t,this._tempVector3),e.Vector3.CrossToRef(this._tempVector2,this._tempVector3,this._tempVector4),s=e.Vector3.Dot(this._tempVector4,o),0>s?!1:(e.Vector3.CrossToRef(this._tempVector3,this._tempVector,this._tempVector4),s=e.Vector3.Dot(this._tempVector4,o),s>=0))},r.prototype._canDoCollision=function(i,r,n,o){var s=e.Vector3.Distance(this.basePointWorld,i),a=Math.max(this.radius.x,this.radius.y,this.radius.z);return s>this.velocityWorldLength+a+r?!1:!!t(n,o,this.basePointWorld,this.velocityWorldLength+a)},r.prototype._testTriangle=function(t,r,n,o,s,a){var h,c=!1;r||(r=[]),r[t]||(r[t]=new e.Plane(0,0,0,0),r[t].copyFromPoints(n,o,s));var l=r[t];if(a||l.isFrontFacingTo(this.normalizedVelocity,0)){var u=l.signedDistanceTo(this.basePoint),f=e.Vector3.Dot(l.normal,this.velocity);if(0==f){if(Math.abs(u)>=1)return;c=!0,h=0}else{h=(-1-u)/f;var d=(1-u)/f;if(h>d){var p=d;d=h,h=p}if(h>1||0>d)return;0>h&&(h=0),h>1&&(h=1)}this._collisionPoint.copyFromFloats(0,0,0);var _=!1,g=1;if(c||(this.basePoint.subtractToRef(l.normal,this._planeIntersectionPoint),this.velocity.scaleToRef(h,this._tempVector),this._planeIntersectionPoint.addInPlace(this._tempVector),this._checkPointInTriangle(this._planeIntersectionPoint,n,o,s,l.normal)&&(_=!0,g=h,this._collisionPoint.copyFrom(this._planeIntersectionPoint))),!_){var m=this.velocity.lengthSquared(),v=m;this.basePoint.subtractToRef(n,this._tempVector);var y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(v,y,x,g);b.found&&(g=b.root,_=!0,this._collisionPoint.copyFrom(n)),this.basePoint.subtractToRef(o,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(v,y,x,g),b.found&&(g=b.root,_=!0,this._collisionPoint.copyFrom(o)),this.basePoint.subtractToRef(s,this._tempVector),y=2*e.Vector3.Dot(this.velocity,this._tempVector),x=this._tempVector.lengthSquared()-1,b=i(v,y,x,g),b.found&&(g=b.root,_=!0,this._collisionPoint.copyFrom(s)),o.subtractToRef(n,this._edge),n.subtractToRef(this.basePoint,this._baseToVertex);var P=this._edge.lengthSquared(),A=e.Vector3.Dot(this._edge,this.velocity),E=e.Vector3.Dot(this._edge,this._baseToVertex);if(v=P*-m+A*A,y=P*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*A*E,x=P*(1-this._baseToVertex.lengthSquared())+E*E,b=i(v,y,x,g),b.found){var T=(A*b.root-E)/P;T>=0&&1>=T&&(g=b.root,_=!0,this._edge.scaleInPlace(T),n.addToRef(this._edge,this._collisionPoint))}s.subtractToRef(o,this._edge),o.subtractToRef(this.basePoint,this._baseToVertex),P=this._edge.lengthSquared(),A=e.Vector3.Dot(this._edge,this.velocity),E=e.Vector3.Dot(this._edge,this._baseToVertex),v=P*-m+A*A,y=P*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*A*E,x=P*(1-this._baseToVertex.lengthSquared())+E*E,b=i(v,y,x,g),b.found&&(T=(A*b.root-E)/P,T>=0&&1>=T&&(g=b.root,_=!0,this._edge.scaleInPlace(T),o.addToRef(this._edge,this._collisionPoint))),n.subtractToRef(s,this._edge),s.subtractToRef(this.basePoint,this._baseToVertex),P=this._edge.lengthSquared(),A=e.Vector3.Dot(this._edge,this.velocity),E=e.Vector3.Dot(this._edge,this._baseToVertex),v=P*-m+A*A,y=P*(2*e.Vector3.Dot(this.velocity,this._baseToVertex))-2*A*E,x=P*(1-this._baseToVertex.lengthSquared())+E*E,b=i(v,y,x,g),b.found&&(T=(A*b.root-E)/P,T>=0&&1>=T&&(g=b.root,_=!0,this._edge.scaleInPlace(T),s.addToRef(this._edge,this._collisionPoint)))}if(_){var C=g*this.velocity.length();(!this.collisionFound||Ca;a+=3){var h=t[i[a]-o],c=t[i[a+1]-o],l=t[i[a+2]-o];this._testTriangle(a,e,l,c,h,s)}},r.prototype._getResponse=function(t,i){t.addToRef(i,this._destinationPoint),i.scaleInPlace(this.nearestDistance/i.length()),this.basePoint.addToRef(i,t),t.subtractToRef(this.intersectionPoint,this._slidePlaneNormal),this._slidePlaneNormal.normalize(),this._slidePlaneNormal.scaleToRef(this.epsilon,this._displacementVector),t.addInPlace(this._displacementVector),this.intersectionPoint.addInPlace(this._displacementVector),this._slidePlaneNormal.scaleInPlace(e.Plane.SignedDistanceToPlaneFromPositionAndNormal(this.intersectionPoint,this._slidePlaneNormal,this._destinationPoint)),this._destinationPoint.subtractInPlace(this._slidePlaneNormal),this._destinationPoint.subtractToRef(this.intersectionPoint,i)},r}();e.Collider=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){e.CollisionWorker="",function(e){e[e.INIT=0]="INIT",e[e.UPDATE=1]="UPDATE",e[e.COLLIDE=2]="COLLIDE"}(e.WorkerTaskType||(e.WorkerTaskType={}));var t=e.WorkerTaskType;!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.UNKNOWN_ERROR=1]="UNKNOWN_ERROR"}(e.WorkerReplyType||(e.WorkerReplyType={}));var i=e.WorkerReplyType,r=function(){function r(){var n=this;this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this.onMeshUpdated=function(e){n._addUpdateMeshesList[e.uniqueId]=r.SerializeMesh(e)},this.onGeometryUpdated=function(e){n._addUpdateGeometriesList[e.id]=r.SerializeGeometry(e)},this._afterRender=function(){if(n._init&&!(0==n._toRemoveGeometryArray.length&&0==n._toRemoveMeshesArray.length&&0==Object.keys(n._addUpdateGeometriesList).length&&0==Object.keys(n._addUpdateMeshesList).length||n._runningUpdated>4)){++n._runningUpdated;var e={updatedMeshes:n._addUpdateMeshesList,updatedGeometries:n._addUpdateGeometriesList,removedGeometries:n._toRemoveGeometryArray,removedMeshes:n._toRemoveMeshesArray},i={payload:e,taskType:t.UPDATE},r=[];for(var o in e.updatedGeometries)e.updatedGeometries.hasOwnProperty(o)&&(r.push(i.payload.updatedGeometries[o].indices.buffer),r.push(i.payload.updatedGeometries[o].normals.buffer),r.push(i.payload.updatedGeometries[o].positions.buffer));n._worker.postMessage(i,r),n._addUpdateMeshesList={},n._addUpdateGeometriesList={},n._toRemoveGeometryArray=[],n._toRemoveMeshesArray=[]}},this._onMessageFromWorker=function(r){var o=r.data;if(o.error!=i.SUCCESS)return void e.Tools.Warn("error returned from worker!");switch(o.taskType){case t.INIT:n._init=!0,n._scene.meshes.forEach(function(e){n.onMeshAdded(e)}),n._scene.getGeometries().forEach(function(e){n.onGeometryAdded(e)});break;case t.UPDATE:n._runningUpdated--;break;case t.COLLIDE:n._runningCollisionTask=!1;var s=o.payload;if(!n._collisionsCallbackArray[s.collisionId])return;n._collisionsCallbackArray[s.collisionId](s.collisionId,e.Vector3.FromArray(s.newPosition),n._scene.getMeshByUniqueID(s.collidedMeshUniqueId)),n._collisionsCallbackArray[s.collisionId]=void 0}},this._collisionsCallbackArray=[],this._init=!1,this._runningUpdated=0,this._runningCollisionTask=!1,this._addUpdateMeshesList={},this._addUpdateGeometriesList={},this._toRemoveGeometryArray=[],this._toRemoveMeshesArray=[]}return r.prototype.getNewPosition=function(e,i,r,n,o,s,a){if(this._init&&!this._collisionsCallbackArray[a]&&!this._collisionsCallbackArray[a+1e5]){e.divideToRef(r.radius,this._scaledPosition),i.divideToRef(r.radius,this._scaledVelocity),this._collisionsCallbackArray[a]=s;var h={collider:{position:this._scaledPosition.asArray(),velocity:this._scaledVelocity.asArray(),radius:r.radius.asArray()},collisionId:a,excludedMeshUniqueId:o?o.uniqueId:null,maximumRetry:n},c={payload:h,taskType:t.COLLIDE};this._worker.postMessage(c)}},r.prototype.init=function(i){this._scene=i,this._scene.registerAfterRender(this._afterRender);var r=e.WorkerIncluded?e.Engine.CodeRepository+"Collisions/babylon.collisionWorker.js":URL.createObjectURL(new Blob([e.CollisionWorker],{type:"application/javascript"}));this._worker=new Worker(r),this._worker.onmessage=this._onMessageFromWorker;var n={payload:{},taskType:t.INIT};this._worker.postMessage(n)},r.prototype.destroy=function(){this._scene.unregisterAfterRender(this._afterRender),this._worker.terminate()},r.prototype.onMeshAdded=function(e){e.registerAfterWorldMatrixUpdate(this.onMeshUpdated),this.onMeshUpdated(e)},r.prototype.onMeshRemoved=function(e){this._toRemoveMeshesArray.push(e.uniqueId)},r.prototype.onGeometryAdded=function(e){e.onGeometryUpdated=this.onGeometryUpdated,this.onGeometryUpdated(e)},r.prototype.onGeometryDeleted=function(e){this._toRemoveGeometryArray.push(e.id)},r.SerializeMesh=function(t){var i=[];t.subMeshes&&(i=t.subMeshes.map(function(e,t){return{position:t,verticesStart:e.verticesStart,verticesCount:e.verticesCount,indexStart:e.indexStart,indexCount:e.indexCount,hasMaterial:!!e.getMaterial(),sphereCenter:e.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:e.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:e.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:e.getBoundingInfo().boundingBox.maximumWorld.asArray()}}));var r=null;return t instanceof e.Mesh?r=t.geometry?t.geometry.id:null:t instanceof e.InstancedMesh&&(r=t.sourceMesh&&t.sourceMesh.geometry?t.sourceMesh.geometry.id:null),{uniqueId:t.uniqueId,id:t.id,name:t.name,geometryId:r,sphereCenter:t.getBoundingInfo().boundingSphere.centerWorld.asArray(),sphereRadius:t.getBoundingInfo().boundingSphere.radiusWorld,boxMinimum:t.getBoundingInfo().boundingBox.minimumWorld.asArray(),boxMaximum:t.getBoundingInfo().boundingBox.maximumWorld.asArray(),worldMatrixFromCache:t.worldMatrixFromCache.asArray(),subMeshes:i,checkCollisions:t.checkCollisions}},r.SerializeGeometry=function(t){return{id:t.id,positions:new Float32Array(t.getVerticesData(e.VertexBuffer.PositionKind)||[]),normals:new Float32Array(t.getVerticesData(e.VertexBuffer.NormalKind)||[]),indices:new Int32Array(t.getIndices()||[])}},r}();e.CollisionCoordinatorWorker=r;var n=function(){function t(){this._scaledPosition=e.Vector3.Zero(),this._scaledVelocity=e.Vector3.Zero(),this._finalPosition=e.Vector3.Zero()}return t.prototype.getNewPosition=function(e,t,i,r,n,o,s){e.divideToRef(i.radius,this._scaledPosition),t.divideToRef(i.radius,this._scaledVelocity),i.collidedMesh=null,i.retry=0,i.initialVelocity=this._scaledVelocity,i.initialPosition=this._scaledPosition,this._collideWithWorld(this._scaledPosition,this._scaledVelocity,i,r,this._finalPosition,n),this._finalPosition.multiplyInPlace(i.radius),o(s,this._finalPosition,i.collidedMesh)},t.prototype.init=function(e){this._scene=e},t.prototype.destroy=function(){},t.prototype.onMeshAdded=function(e){},t.prototype.onMeshUpdated=function(e){},t.prototype.onMeshRemoved=function(e){},t.prototype.onGeometryAdded=function(e){},t.prototype.onGeometryUpdated=function(e){},t.prototype.onGeometryDeleted=function(e){},t.prototype._collideWithWorld=function(t,i,r,n,o,s){void 0===s&&(s=null);var a=10*e.Engine.CollisionsEpsilon;if(r.retry>=n)return void o.copyFrom(t);r._initialize(t,i,a);for(var h=0;h0&&this._postProcesses[0].markTextureDirty();for(var t=0,i=this._rigCameras.length;i>t;t++){var r=this._rigCameras[t],n=r._rigPostProcess;if(n){var o=n instanceof e.PassPostProcess;o&&(r.isIntermediate=0===this._postProcesses.length),r._postProcesses=this._postProcesses.slice(0).concat(n),n.markTextureDirty()}else r._postProcesses=this._postProcesses.slice(0)}},i.prototype.attachPostProcess=function(t,i){return void 0===i&&(i=null),!t.isReusable()&&this._postProcesses.indexOf(t)>-1?(e.Tools.Error("You're trying to reuse a post process not defined as reusable."),
+0):(null==i||0>i?this._postProcesses.push(t):this._postProcesses.splice(i,0,t),this._cascadePostProcessesToRigCams(),this._postProcesses.indexOf(t))},i.prototype.detachPostProcess=function(e,t){void 0===t&&(t=null);var i,r,n=[];if(t)for(t=t instanceof Array?t:[t],i=t.length-1;i>=0;i--)this._postProcesses[t[i]]===e?this._postProcesses.splice(r,1):n.push(i);else{var o=this._postProcesses.indexOf(e);-1!==o&&this._postProcesses.splice(o,1)}return this._cascadePostProcessesToRigCams(),n},i.prototype.getWorldMatrix=function(){this._worldMatrix||(this._worldMatrix=e.Matrix.Identity());var t=this.getViewMatrix();return t.invertToRef(this._worldMatrix),this._worldMatrix},i.prototype._getViewMatrix=function(){return e.Matrix.Identity()},i.prototype.getViewMatrix=function(t){return this._computedViewMatrix=this._computeViewMatrix(t),!t&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this.parent&&this.parent.getWorldMatrix?(this._worldMatrix||(this._worldMatrix=e.Matrix.Identity()),this._computedViewMatrix.invertToRef(this._worldMatrix),this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(),this._computedViewMatrix),this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12],this._computedViewMatrix.m[13],this._computedViewMatrix.m[14]),this._computedViewMatrix.invert(),this._markSyncedWithParent()):this._globalPosition.copyFrom(this.position),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},i.prototype._computeViewMatrix=function(e){return!e&&this._isSynchronizedViewMatrix()?this._computedViewMatrix:(this._computedViewMatrix=this._getViewMatrix(),this._currentRenderId=this.getScene().getRenderId(),this._computedViewMatrix)},i.prototype.getProjectionMatrix=function(t){if(!t&&this._isSynchronizedProjectionMatrix())return this._projectionMatrix;var r=this.getEngine();if(this.mode===i.PERSPECTIVE_CAMERA)return this.minZ<=0&&(this.minZ=.1),e.Matrix.PerspectiveFovLHToRef(this.fov,r.getAspectRatio(this),this.minZ,this.maxZ,this._projectionMatrix,this.fovMode===i.FOVMODE_VERTICAL_FIXED),this._projectionMatrix;var n=r.getRenderWidth()/2,o=r.getRenderHeight()/2;return e.Matrix.OrthoOffCenterLHToRef(this.orthoLeft||-n,this.orthoRight||n,this.orthoBottom||-o,this.orthoTop||o,this.minZ,this.maxZ,this._projectionMatrix),this._projectionMatrix},i.prototype.dispose=function(){for(this.getScene().stopAnimation(this),this.getScene().removeCamera(this);this._rigCameras.length>0;)this._rigCameras.pop().dispose();for(var e=0;e0;)this._rigCameras.pop().dispose();switch(this.cameraRigMode=t,this._cameraRigParams={},this._cameraRigParams.interaxialDistance=r.interaxialDistance||.0637,this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(this._cameraRigParams.interaxialDistance/.0637),this.cameraRigMode!==i.RIG_MODE_NONE&&(this._rigCameras.push(this.createRigCamera(this.name+"_L",0)),this._rigCameras.push(this.createRigCamera(this.name+"_R",1))),this.cameraRigMode){case i.RIG_MODE_STEREOSCOPIC_ANAGLYPH:this._rigCameras[0]._rigPostProcess=new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0]),this._rigCameras[1]._rigPostProcess=new e.AnaglyphPostProcess(this.name+"_anaglyph",1,this._rigCameras);break;case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:case i.RIG_MODE_STEREOSCOPIC_OVERUNDER:var n=this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL||this.cameraRigMode===i.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED;this._rigCameras[0]._rigPostProcess=new e.PassPostProcess(this.name+"_passthru",1,this._rigCameras[0]),this._rigCameras[1]._rigPostProcess=new e.StereoscopicInterlacePostProcess(this.name+"_stereoInterlace",this._rigCameras,n);break;case i.RIG_MODE_VR:var o=r.vrCameraMetrics||e.VRCameraMetrics.GetDefault();this._rigCameras[0]._cameraRigParams.vrMetrics=o,this._rigCameras[0].viewport=new e.Viewport(0,0,.5,1),this._rigCameras[0]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[0]._cameraRigParams.vrHMatrix=o.leftHMatrix,this._rigCameras[0]._cameraRigParams.vrPreViewMatrix=o.leftPreViewMatrix,this._rigCameras[0].getProjectionMatrix=this._rigCameras[0]._getVRProjectionMatrix,this._rigCameras[1]._cameraRigParams.vrMetrics=o,this._rigCameras[1].viewport=new e.Viewport(.5,0,.5,1),this._rigCameras[1]._cameraRigParams.vrWorkMatrix=new e.Matrix,this._rigCameras[1]._cameraRigParams.vrHMatrix=o.rightHMatrix,this._rigCameras[1]._cameraRigParams.vrPreViewMatrix=o.rightPreViewMatrix,this._rigCameras[1].getProjectionMatrix=this._rigCameras[1]._getVRProjectionMatrix,o.compensateDistortion&&(this._rigCameras[0]._rigPostProcess=new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Left",this._rigCameras[0],!1,o),this._rigCameras[1]._rigPostProcess=new e.VRDistortionCorrectionPostProcess("VR_Distort_Compensation_Right",this._rigCameras[1],!0,o))}this._cascadePostProcessesToRigCams(),this._update()},i.prototype._getVRProjectionMatrix=function(){return e.Matrix.PerspectiveFovLHToRef(this._cameraRigParams.vrMetrics.aspectRatioFov,this._cameraRigParams.vrMetrics.aspectRatio,this.minZ,this.maxZ,this._cameraRigParams.vrWorkMatrix),this._cameraRigParams.vrWorkMatrix.multiplyToRef(this._cameraRigParams.vrHMatrix,this._projectionMatrix),this._projectionMatrix},i.prototype.setCameraRigParameter=function(t,i){this._cameraRigParams||(this._cameraRigParams={}),this._cameraRigParams[t]=i,"interaxialDistance"===t&&(this._cameraRigParams.stereoHalfAngle=e.Tools.ToRadians(i/.0637))},i.prototype.createRigCamera=function(e,t){return null},i.prototype._updateRigCameras=function(){for(var e=0;e=0&&r._keys.splice(t,1),i||e.preventDefault()}},e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]))},t.prototype.detachControl=function(t){this._onKeyDown&&(e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._keys=[],this._onKeyDown=null,this._onKeyUp=null)},t.prototype.checkInputs=function(){if(this._onKeyDown)for(var t=this.camera,i=0;i1)t.cameraRotation.x+=-this._offsetY/this.touchAngularSensibility;else{var i=t._computeLocalCameraSpeed(),r=new e.Vector3(0,0,i*this._offsetY/this.touchMoveSensibility);e.Matrix.RotationYawPitchRollToRef(t.rotation.y,t.rotation.x,0,t._cameraRotationMatrix),t.cameraDirection.addInPlace(e.Vector3.TransformCoordinates(r,t._cameraRotationMatrix))}}},t.prototype.getTypeName=function(){return"FreeCameraTouchInput"},t.prototype.getSimpleName=function(){return"touch"},__decorate([e.serialize()],t.prototype,"touchAngularSensibility",void 0),__decorate([e.serialize()],t.prototype,"touchMoveSensibility",void 0),t}();e.FreeCameraTouchInput=t,e.CameraInputTypes.FreeCameraTouchInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){var t=this;this._screenOrientationAngle=0,this._screenQuaternion=new e.Quaternion,this._alpha=0,this._beta=0,this._gamma=0,this._orientationChanged=function(){t._screenOrientationAngle=void 0!==window.orientation?+window.orientation:window.screen.orientation&&window.screen.orientation.angle?window.screen.orientation.angle:0,t._screenOrientationAngle=-e.Tools.ToRadians(t._screenOrientationAngle/2),t._screenQuaternion.copyFromFloats(0,Math.sin(t._screenOrientationAngle),0,Math.cos(t._screenOrientationAngle))},this._deviceOrientation=function(e){t._alpha=e.alpha,t._beta=e.beta,t._gamma=e.gamma},this._constantTranform=new e.Quaternion(-Math.sqrt(.5),0,0,Math.sqrt(.5)),this._orientationChanged()}return Object.defineProperty(t.prototype,"camera",{get:function(){return this._camera},set:function(t){this._camera=t,this._camera.rotationQuaternion||(this._camera.rotationQuaternion=new e.Quaternion)},enumerable:!0,configurable:!0}),t.prototype.attachControl=function(e,t){window.addEventListener("orientationchange",this._orientationChanged),window.addEventListener("deviceorientation",this._deviceOrientation)},t.prototype.detachControl=function(e){window.removeEventListener("orientationchange",this._orientationChanged),window.removeEventListener("deviceorientation",this._deviceOrientation)},t.prototype.checkInputs=function(){e.Quaternion.RotationYawPitchRollToRef(e.Tools.ToRadians(this._alpha),e.Tools.ToRadians(this._beta),-e.Tools.ToRadians(this._gamma),this.camera.rotationQuaternion),this._camera.rotationQuaternion.multiplyInPlace(this._screenQuaternion),this._camera.rotationQuaternion.multiplyInPlace(this._constantTranform),this._camera.rotationQuaternion.z*=-1,this._camera.rotationQuaternion.w*=-1},t.prototype.getTypeName=function(){return"FreeCameraDeviceOrientationInput"},t.prototype.getSimpleName=function(){return"deviceOrientation"},t}();e.FreeCameraDeviceOrientationInput=t,e.CameraInputTypes.FreeCameraDeviceOrientationInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this.alphaCorrection=1,this.betaCorrection=1,this.gammaCorrection=1,this._alpha=0,this._beta=0,this._gamma=0,this._dirty=!1,this._deviceOrientationHandler=this._onOrientationEvent.bind(this)}return e.prototype.attachControl=function(e,t){window.addEventListener("deviceorientation",this._deviceOrientationHandler)},e.prototype._onOrientationEvent=function(e){this.camera;this._alpha=e.alpha,this._beta=e.beta,this._gamma=e.gamma,this._dirty=!0},e.prototype.checkInputs=function(){if(this._dirty){this._dirty=!1;var e=this._gamma;e=0>e?90+e:270-e,this.camera.rotation.x=this.gammaCorrection*e/180*Math.PI,this.camera.rotation.y=this.alphaCorrection*-this._alpha/180*Math.PI,this.camera.rotation.z=this.betaCorrection*this._beta/180*Math.PI}},e.prototype.detachControl=function(e){window.removeEventListener("deviceorientation",this._deviceOrientationHandler)},e.prototype.getTypeName=function(){return"FreeCameraVRDeviceOrientationInput"},e.prototype.getSimpleName=function(){return"VRDeviceOrientation"},e}();e.FreeCameraVRDeviceOrientationInput=t,e.CameraInputTypes.FreeCameraVRDeviceOrientationInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this.gamepadAngularSensibility=200,this.gamepadMoveSensibility=40}return t.prototype.attachControl=function(t,i){var r=this;this._gamepads=new e.Gamepads(function(e){r._onNewGameConnected(e)})},t.prototype.detachControl=function(e){this._gamepads&&this._gamepads.dispose(),this.gamepad=null},t.prototype.checkInputs=function(){if(this.gamepad){var t=this.camera,i=this.gamepad.leftStick,r=i.x/this.gamepadMoveSensibility,n=i.y/this.gamepadMoveSensibility;i.x=Math.abs(r)>.005?0+r:0,i.y=Math.abs(n)>.005?0+n:0;var o=this.gamepad.rightStick,s=o.x/this.gamepadAngularSensibility,a=o.y/this.gamepadAngularSensibility;o.x=Math.abs(s)>.001?0+s:0,o.y=Math.abs(a)>.001?0+a:0;var h=e.Matrix.RotationYawPitchRoll(t.rotation.y,t.rotation.x,0),c=50*t._computeLocalCameraSpeed(),l=e.Vector3.TransformCoordinates(new e.Vector3(i.x*c,0,-i.y*c),h);t.cameraDirection=t.cameraDirection.add(l),t.cameraRotation=t.cameraRotation.add(new e.Vector2(o.y,o.x))}},t.prototype._onNewGameConnected=function(e){0===e.index&&(this.gamepad=e)},t.prototype.getTypeName=function(){return"FreeCameraGamepadInput"},t.prototype.getSimpleName=function(){return"gamepad"},__decorate([e.serialize()],t.prototype,"gamepadAngularSensibility",void 0),__decorate([e.serialize()],t.prototype,"gamepadMoveSensibility",void 0),t}();e.FreeCameraGamepadInput=t,e.CameraInputTypes.FreeCameraGamepadInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){this._keys=[],this.keysUp=[38],this.keysDown=[40],this.keysLeft=[37],this.keysRight=[39]}return t.prototype.attachControl=function(t,i){var r=this;this._onKeyDown=function(e){if(-1!==r.keysUp.indexOf(e.keyCode)||-1!==r.keysDown.indexOf(e.keyCode)||-1!==r.keysLeft.indexOf(e.keyCode)||-1!==r.keysRight.indexOf(e.keyCode)){var t=r._keys.indexOf(e.keyCode);-1===t&&r._keys.push(e.keyCode),e.preventDefault&&(i||e.preventDefault())}},this._onKeyUp=function(e){if(-1!==r.keysUp.indexOf(e.keyCode)||-1!==r.keysDown.indexOf(e.keyCode)||-1!==r.keysLeft.indexOf(e.keyCode)||-1!==r.keysRight.indexOf(e.keyCode)){var t=r._keys.indexOf(e.keyCode);t>=0&&r._keys.splice(t,1),e.preventDefault&&(i||e.preventDefault())}},this._onLostFocus=function(){r._keys=[]},e.Tools.RegisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}])},t.prototype.detachControl=function(t){e.Tools.UnregisterTopRootEvents([{name:"keydown",handler:this._onKeyDown},{name:"keyup",handler:this._onKeyUp},{name:"blur",handler:this._onLostFocus}]),this._keys=[],this._onKeyDown=null,this._onKeyUp=null,this._onLostFocus=null},t.prototype.checkInputs=function(){if(this._onKeyDown)for(var e=this.camera,t=0;t.005&&(e.inertialAlphaOffset+=i)}if(0!=t.y){var r=t.y/this.gamepadRotationSensibility;0!=r&&Math.abs(r)>.005&&(e.inertialBetaOffset+=r)}var n=this.gamepad.leftStick;if(0!=n.y){var o=n.y/this.gamepadMoveSensibility;0!=o&&Math.abs(o)>.005&&(this.camera.inertialRadiusOffset-=o)}}},t.prototype._onNewGameConnected=function(e){0===e.index&&(this.gamepad=e)},t.prototype.getTypeName=function(){return"ArcRotateCameraGamepadInput"},t.prototype.getSimpleName=function(){return"gamepad"},__decorate([e.serialize()],t.prototype,"gamepadRotationSensibility",void 0),__decorate([e.serialize()],t.prototype,"gamepadMoveSensibility",void 0),t}();e.ArcRotateCameraGamepadInput=t,e.CameraInputTypes.ArcRotateCameraGamepadInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){this.alphaCorrection=1,this.betaCorrection=1,this.gammaCorrection=1,this._alpha=0,this._beta=0,this._gamma=0,this._dirty=!1,this._deviceOrientationHandler=this._onOrientationEvent.bind(this)}return e.prototype.attachControl=function(e,t){this.camera.attachControl(e,t),window.addEventListener("deviceorientation",this._deviceOrientationHandler)},e.prototype._onOrientationEvent=function(e){this.camera;this._alpha=0|+e.alpha,this._beta=0|+e.beta,this._gamma=0|+e.gamma,this._dirty=!0},e.prototype.checkInputs=function(){this._dirty&&(this._dirty=!1,this._gamma<0&&(this._gamma=180+this._gamma),this.camera.alpha=-this._alpha/180*Math.PI%Math.PI*2,this.camera.beta=this._gamma/180*Math.PI)},e.prototype.detachControl=function(e){window.removeEventListener("deviceorientation",this._deviceOrientationHandler)},e.prototype.getTypeName=function(){return"ArcRotateCameraVRDeviceOrientationInput"},e.prototype.getSimpleName=function(){return"VRDeviceOrientation"},e}();e.ArcRotateCameraVRDeviceOrientationInput=t,e.CameraInputTypes.ArcRotateCameraVRDeviceOrientationInput=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n){t.call(this,i,r,n),this.cameraDirection=new e.Vector3(0,0,0),this.cameraRotation=new e.Vector2(0,0),this.rotation=new e.Vector3(0,0,0),this.speed=2,this.noRotationConstraint=!1,this.lockedTarget=null,this._currentTarget=e.Vector3.Zero(),this._viewMatrix=e.Matrix.Zero(),this._camMatrix=e.Matrix.Zero(),this._cameraTransformMatrix=e.Matrix.Zero(),this._cameraRotationMatrix=e.Matrix.Zero(),this._referencePoint=new e.Vector3(0,0,1),this._defaultUpVector=new e.Vector3(0,1,0),this._transformedReferencePoint=e.Vector3.Zero(),this._lookAtTemp=e.Matrix.Zero(),this._tempMatrix=e.Matrix.Zero()}return __extends(i,t),i.prototype.getFrontPosition=function(e){var t=this.getTarget().subtract(this.position);return t.normalize(),t.scaleInPlace(e),this.globalPosition.add(t)},i.prototype._getLockedTargetPosition=function(){return this.lockedTarget?this.lockedTarget.position||this.lockedTarget:null},i.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.lockedTarget=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotation=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.rotationQuaternion=new e.Quaternion(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)},i.prototype._updateCache=function(e){e||t.prototype._updateCache.call(this);var i=this._getLockedTargetPosition();i?this._cache.lockedTarget?this._cache.lockedTarget.copyFrom(i):this._cache.lockedTarget=i.clone():this._cache.lockedTarget=null,this._cache.rotation.copyFrom(this.rotation),this.rotationQuaternion&&this._cache.rotationQuaternion.copyFrom(this.rotationQuaternion)},i.prototype._isSynchronizedViewMatrix=function(){if(!t.prototype._isSynchronizedViewMatrix.call(this))return!1;var e=this._getLockedTargetPosition();return(this._cache.lockedTarget?this._cache.lockedTarget.equals(e):!e)&&(this.rotationQuaternion?this.rotationQuaternion.equals(this._cache.rotationQuaternion):this._cache.rotation.equals(this.rotation))},i.prototype._computeLocalCameraSpeed=function(){var e=this.getEngine();return this.speed*(e.getDeltaTime()/(10*e.getFps()))},i.prototype.setTarget=function(t){this.upVector.normalize(),e.Matrix.LookAtLHToRef(this.position,t,this._defaultUpVector,this._camMatrix),this._camMatrix.invert(),this.rotation.x=Math.atan(this._camMatrix.m[6]/this._camMatrix.m[10]);var i=t.subtract(this.position);i.x>=0?this.rotation.y=-Math.atan(i.z/i.x)+Math.PI/2:this.rotation.y=-Math.atan(i.z/i.x)-Math.PI/2,this.rotation.z=0,isNaN(this.rotation.x)&&(this.rotation.x=0),isNaN(this.rotation.y)&&(this.rotation.y=0),isNaN(this.rotation.z)&&(this.rotation.z=0),this.rotationQuaternion&&e.Quaternion.RotationYawPitchRollToRef(this.rotation.y,this.rotation.x,this.rotation.z,this.rotationQuaternion)},i.prototype.getTarget=function(){return this._currentTarget},i.prototype._decideIfNeedsToMove=function(){return Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},i.prototype._updatePosition=function(){this.position.addInPlace(this.cameraDirection)},i.prototype._checkInputs=function(){var i=this._decideIfNeedsToMove(),r=Math.abs(this.cameraRotation.x)>0||Math.abs(this.cameraRotation.y)>0;if(i&&this._updatePosition(),r&&(this.rotation.x+=this.cameraRotation.x,this.rotation.y+=this.cameraRotation.y,!this.noRotationConstraint)){var n=Math.PI/2*.95;this.rotation.x>n&&(this.rotation.x=n),this.rotation.x<-n&&(this.rotation.x=-n)}i&&(Math.abs(this.cameraDirection.x)e.Engine.CollisionsEpsilon&&(o.position.addInPlace(o._diffPosition),o.onCollide&&r&&o.onCollide(r))};n(i)},this.inputs=new e.FreeCameraInputsManager(this),this.inputs.addKeyboard().addMouse()}return __extends(i,t),Object.defineProperty(i.prototype,"angularSensibility",{get:function(){var e=this.inputs.attached.mouse;return e?e.angularSensibility:void 0},set:function(e){var t=this.inputs.attached.mouse;t&&(t.angularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysUp",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysUp:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysUp=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysDown",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysDown:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysDown=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysLeft",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysLeft:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysLeft=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysRight",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysRight:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysRight=e)},enumerable:!0,configurable:!0}),i.prototype.attachControl=function(e,t){this.inputs.attachElement(e,t)},i.prototype.detachControl=function(t){this.inputs.detachElement(t),this.cameraDirection=new e.Vector3(0,0,0),this.cameraRotation=new e.Vector2(0,0)},i.prototype._collideWithWorld=function(t){var i;i=this.parent?e.Vector3.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position,i.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._collider.radius=this.ellipsoid;var r=t;this.applyGravity&&(r=t.add(this.getScene().gravity)),this.getScene().collisionCoordinator.getNewPosition(this._oldPosition,r,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)},i.prototype._checkInputs=function(){this._localDirection||(this._localDirection=e.Vector3.Zero(),this._transformedDirection=e.Vector3.Zero()),this.inputs.checkInputs(),t.prototype._checkInputs.call(this)},i.prototype._decideIfNeedsToMove=function(){return this._needMoveForGravity||Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0},i.prototype._updatePosition=function(){this.checkCollisions&&this.getScene().collisionsEnabled?this._collideWithWorld(this.cameraDirection):this.position.addInPlace(this.cameraDirection)},i.prototype.dispose=function(){this.inputs.clear(),t.prototype.dispose.call(this)},i.prototype.getTypeName=function(){return"FreeCamera"},__decorate([e.serializeAsVector3()],i.prototype,"ellipsoid",void 0),__decorate([e.serialize()],i.prototype,"checkCollisions",void 0),__decorate([e.serialize()],i.prototype,"applyGravity",void 0),i}(e.TargetCamera);e.FreeCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e){t.call(this,e)}return __extends(i,t),i.prototype.addKeyboard=function(){return this.add(new e.FreeCameraKeyboardMoveInput),this},i.prototype.addMouse=function(t){return void 0===t&&(t=!0),this.add(new e.FreeCameraMouseInput(t)),this},i.prototype.addGamepad=function(){return this.add(new e.FreeCameraGamepadInput),this},i.prototype.addDeviceOrientation=function(){return this.add(new e.FreeCameraDeviceOrientationInput),this},i.prototype.addVRDeviceOrientation=function(){return this.add(new e.FreeCameraVRDeviceOrientationInput),this},i.prototype.addTouch=function(){return this.add(new e.FreeCameraTouchInput),this},i.prototype.addVirtualJoystick=function(){return this.add(new e.FreeCameraVirtualJoystickInput),this},i}(e.CameraInputsManager);e.FreeCameraInputsManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r,n){t.call(this,e,i,r),this.radius=12,this.rotationOffset=0,this.heightOffset=4,this.cameraAcceleration=.05,this.maxCameraSpeed=20,this.target=n}return __extends(i,t),i.prototype.getRadians=function(e){return e*Math.PI/180},i.prototype.follow=function(t){if(t){var i;if(t.rotationQuaternion){var r=new e.Matrix;t.rotationQuaternion.toRotationMatrix(r),i=Math.atan2(r.m[8],r.m[10])}else i=t.rotation.y;var n=this.getRadians(this.rotationOffset)+i,o=t.position.x+Math.sin(n)*this.radius,s=t.position.z+Math.cos(n)*this.radius,a=o-this.position.x,h=t.position.y+this.heightOffset-this.position.y,c=s-this.position.z,l=a*this.cameraAcceleration*2,u=h*this.cameraAcceleration,f=c*this.cameraAcceleration*2;(l>this.maxCameraSpeed||l<-this.maxCameraSpeed)&&(l=1>l?-this.maxCameraSpeed:this.maxCameraSpeed),(u>this.maxCameraSpeed||u<-this.maxCameraSpeed)&&(u=1>u?-this.maxCameraSpeed:this.maxCameraSpeed),(f>this.maxCameraSpeed||f<-this.maxCameraSpeed)&&(f=1>f?-this.maxCameraSpeed:this.maxCameraSpeed),this.position=new e.Vector3(this.position.x+l,this.position.y+u,this.position.z+f),this.setTarget(t.position)}},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow(this.target)},i.prototype.getTypeName=function(){return"FollowCamera"},__decorate([e.serialize()],i.prototype,"radius",void 0),__decorate([e.serialize()],i.prototype,"rotationOffset",void 0),__decorate([e.serialize()],i.prototype,"heightOffset",void 0),__decorate([e.serialize()],i.prototype,"cameraAcceleration",void 0),__decorate([e.serialize()],i.prototype,"maxCameraSpeed",void 0),__decorate([e.serializeAsMeshReference("lockedTargetId")],i.prototype,"target",void 0),i}(e.TargetCamera);e.FollowCamera=t;var i=function(t){function i(i,r,n,o,s,a){t.call(this,i,e.Vector3.Zero(),a),this.alpha=r,this.beta=n,this.radius=o,this.target=s,this._cartesianCoordinates=e.Vector3.Zero(),this.follow()}return __extends(i,t),i.prototype.follow=function(){this._cartesianCoordinates.x=this.radius*Math.cos(this.alpha)*Math.cos(this.beta),this._cartesianCoordinates.y=this.radius*Math.sin(this.beta),this._cartesianCoordinates.z=this.radius*Math.sin(this.alpha)*Math.cos(this.beta),this.position=this.target.position.add(this._cartesianCoordinates),this.setTarget(this.target.position)},i.prototype._checkInputs=function(){t.prototype._checkInputs.call(this),this.follow()},i.prototype.getTypeName=function(){return"ArcFollowCamera"},i}(e.TargetCamera);e.ArcFollowCamera=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r){e.call(this,t,i,r),this.inputs.addTouch(),this._setupInputs()}return __extends(t,e),Object.defineProperty(t.prototype,"touchAngularSensibility",{get:function(){var e=this.inputs.attached.touch;return e?e.touchAngularSensibility:void 0},set:function(e){var t=this.inputs.attached.touch;t&&(t.touchAngularSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"touchMoveSensibility",{get:function(){var e=this.inputs.attached.touch;return e?e.touchMoveSensibility:void 0},set:function(e){var t=this.inputs.attached.touch;t&&(t.touchMoveSensibility=e)},enumerable:!0,configurable:!0}),t.prototype.getTypeName=function(){return"TouchCamera"},t.prototype._setupInputs=function(){var e=this.inputs.attached.mouse;e&&(e.touchEnabled=!1)},t}(e.FreeCamera);e.TouchCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s,a){var h=this;t.call(this,i,e.Vector3.Zero(),a),this.inertialAlphaOffset=0,this.inertialBetaOffset=0,this.inertialRadiusOffset=0,this.lowerAlphaLimit=null,this.upperAlphaLimit=null,this.lowerBetaLimit=.01,this.upperBetaLimit=Math.PI,this.lowerRadiusLimit=null,this.upperRadiusLimit=null,this.inertialPanningX=0,this.inertialPanningY=0,this.zoomOnFactor=1,this.targetScreenOffset=e.Vector2.Zero(),this.allowUpsideDown=!0,this._viewMatrix=new e.Matrix,this.panningAxis=new e.Vector3(1,1,0),this.checkCollisions=!1,this.collisionRadius=new e.Vector3(.5,.5,.5),this._collider=new e.Collider,this._previousPosition=e.Vector3.Zero(),this._collisionVelocity=e.Vector3.Zero(),this._newPosition=e.Vector3.Zero(),this._onCollisionPositionChange=function(t,i,r){void 0===r&&(r=null),h.getScene().workerCollisions&&h.checkCollisions&&i.multiplyInPlace(h._collider.radius),r?(h.setPosition(i),h.onCollide&&h.onCollide(r)):h._previousPosition.copyFrom(h.position);var n=Math.cos(h.alpha),o=Math.sin(h.alpha),s=Math.cos(h.beta),a=Math.sin(h.beta);0===a&&(a=1e-4);var c=h._getTargetPosition();c.addToRef(new e.Vector3(h.radius*n*a,h.radius*s,h.radius*o*a),h._newPosition),h.position.copyFrom(h._newPosition);var l=h.upVector;h.allowUpsideDown&&h.beta<0&&(l=l.clone(),l=l.negate()),e.Matrix.LookAtLHToRef(h.position,c,l,h._viewMatrix),h._viewMatrix.m[12]+=h.targetScreenOffset.x,h._viewMatrix.m[13]+=h.targetScreenOffset.y,h._collisionTriggered=!1},s?this.target=s:this.target=e.Vector3.Zero(),this.alpha=r,this.beta=n,this.radius=o,this.getViewMatrix(),this.inputs=new e.ArcRotateCameraInputsManager(this),this.inputs.addKeyboard().addMouseWheel().addPointers().addGamepad()}return __extends(i,t),Object.defineProperty(i.prototype,"angularSensibilityX",{get:function(){var e=this.inputs.attached.pointers;return e?e.angularSensibilityX:void 0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.angularSensibilityX=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"angularSensibilityY",{get:function(){var e=this.inputs.attached.pointers;return e?e.angularSensibilityY:void 0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.angularSensibilityY=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"pinchPrecision",{get:function(){var e=this.inputs.attached.pointers;return e?e.pinchPrecision:void 0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.pinchPrecision=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"panningSensibility",{get:function(){var e=this.inputs.attached.pointers;return e?e.panningSensibility:void 0},set:function(e){var t=this.inputs.attached.pointers;t&&(t.panningSensibility=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysUp",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysUp:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysUp=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysDown",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysDown:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysDown=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysLeft",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysLeft:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysLeft=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"keysRight",{get:function(){var e=this.inputs.attached.keyboard;return e?e.keysRight:void 0},set:function(e){var t=this.inputs.attached.keyboard;t&&(t.keysRight=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"wheelPrecision",{get:function(){var e=this.inputs.attached.mousewheel;return e?e.wheelPrecision:void 0},set:function(e){var t=this.inputs.attached.mousewheel;t&&(t.wheelPrecision=e)},enumerable:!0,configurable:!0}),i.prototype._initCache=function(){t.prototype._initCache.call(this),this._cache.target=new e.Vector3(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),this._cache.alpha=void 0,this._cache.beta=void 0,this._cache.radius=void 0,this._cache.targetScreenOffset=e.Vector2.Zero()},i.prototype._updateCache=function(e){e||t.prototype._updateCache.call(this),this._cache.target.copyFrom(this._getTargetPosition()),this._cache.alpha=this.alpha,this._cache.beta=this.beta,this._cache.radius=this.radius,this._cache.targetScreenOffset.copyFrom(this.targetScreenOffset)},i.prototype._getTargetPosition=function(){return this.target.getAbsolutePosition?this.target.getAbsolutePosition():this.target},i.prototype._isSynchronizedViewMatrix=function(){return t.prototype._isSynchronizedViewMatrix.call(this)?this._cache.target.equals(this.target)&&this._cache.alpha===this.alpha&&this._cache.beta===this.beta&&this._cache.radius===this.radius&&this._cache.targetScreenOffset.equals(this.targetScreenOffset):!1},i.prototype.attachControl=function(e,t,i){var r=this;void 0===i&&(i=!0),this._useCtrlForPanning=i,this.inputs.attachElement(e,t),this._reset=function(){r.inertialAlphaOffset=0,r.inertialBetaOffset=0,r.inertialRadiusOffset=0}},i.prototype.detachControl=function(e){this.inputs.detachElement(e),this._reset&&this._reset()},i.prototype._checkInputs=function(){this._collisionTriggered||(this.inputs.checkInputs(),0===this.inertialAlphaOffset&&0===this.inertialBetaOffset&&0===this.inertialRadiusOffset||(this.alpha+=this.beta<=0?-this.inertialAlphaOffset:this.inertialAlphaOffset,this.beta+=this.inertialBetaOffset,this.radius-=this.inertialRadiusOffset,this.inertialAlphaOffset*=this.inertia,this.inertialBetaOffset*=this.inertia,this.inertialRadiusOffset*=this.inertia,Math.abs(this.inertialAlphaOffset)Math.PI&&(this.beta=this.beta-2*Math.PI):this.betathis.upperBetaLimit&&(this.beta=this.upperBetaLimit),this.lowerAlphaLimit&&this.alphathis.upperAlphaLimit&&(this.alpha=this.upperAlphaLimit),this.lowerRadiusLimit&&this.radiusthis.upperRadiusLimit&&(this.radius=this.upperRadiusLimit)},i.prototype.rebuildAnglesAndRadius=function(){var e=this.position.subtract(this._getTargetPosition());this.radius=e.length(),this.alpha=Math.acos(e.x/Math.sqrt(Math.pow(e.x,2)+Math.pow(e.z,2))),e.z<0&&(this.alpha=2*Math.PI-this.alpha),this.beta=Math.acos(e.y/this.radius),this._checkLimits()},i.prototype.setPosition=function(e){this.position.equals(e)||(this.position=e,this.rebuildAnglesAndRadius())},i.prototype.setTarget=function(e){this._getTargetPosition().equals(e)||(this.target=e,this.rebuildAnglesAndRadius())},i.prototype._getViewMatrix=function(){var t=Math.cos(this.alpha),i=Math.sin(this.alpha),r=Math.cos(this.beta),n=Math.sin(this.beta);0===n&&(n=1e-4);var o=this._getTargetPosition();if(o.addToRef(new e.Vector3(this.radius*t*n,this.radius*r,this.radius*i*n),this._newPosition),this.getScene().collisionsEnabled&&this.checkCollisions)this._collider.radius=this.collisionRadius,this._newPosition.subtractToRef(this.position,this._collisionVelocity),this._collisionTriggered=!0,this.getScene().collisionCoordinator.getNewPosition(this.position,this._collisionVelocity,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId);else{this.position.copyFrom(this._newPosition);var s=this.upVector;this.allowUpsideDown&&this.beta<0&&(s=s.clone(),s=s.negate()),e.Matrix.LookAtLHToRef(this.position,o,s,this._viewMatrix),this._viewMatrix.m[12]+=this.targetScreenOffset.x,this._viewMatrix.m[13]+=this.targetScreenOffset.y}return this._viewMatrix},i.prototype.zoomOn=function(t,i){void 0===i&&(i=!1),t=t||this.getScene().meshes;var r=e.Mesh.MinMax(t),n=e.Vector3.Distance(r.min,r.max);this.radius=n*this.zoomOnFactor,this.focusOn({min:r.min,max:r.max,distance:n},i)},i.prototype.focusOn=function(t,i){void 0===i&&(i=!1);var r,n;void 0===t.min?(r=t||this.getScene().meshes,r=e.Mesh.MinMax(r),n=e.Vector3.Distance(r.min,r.max)):(r=t,n=t.distance),this.target=e.Mesh.Center(r),i||(this.maxZ=2*n)},i.prototype.createRigCamera=function(t,r){var n;switch(this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:n=this._cameraRigParams.stereoHalfAngle*(0===r?1:-1);break;case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:n=this._cameraRigParams.stereoHalfAngle*(0===r?-1:1)}var o=new i(t,this.alpha+n,this.beta,this.radius,this.target,this.getScene());return o._cameraRigParams={},o},i.prototype._updateRigCameras=function(){var i=this._rigCameras[0],r=this._rigCameras[1];switch(i.beta=r.beta=this.beta,i.radius=r.radius=this.radius,this.cameraRigMode){case e.Camera.RIG_MODE_STEREOSCOPIC_ANAGLYPH:case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_PARALLEL:case e.Camera.RIG_MODE_STEREOSCOPIC_OVERUNDER:case e.Camera.RIG_MODE_VR:i.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle,r.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle;break;case e.Camera.RIG_MODE_STEREOSCOPIC_SIDEBYSIDE_CROSSEYED:i.alpha=this.alpha+this._cameraRigParams.stereoHalfAngle,r.alpha=this.alpha-this._cameraRigParams.stereoHalfAngle}t.prototype._updateRigCameras.call(this)},i.prototype.dispose=function(){this.inputs.clear(),t.prototype.dispose.call(this)},i.prototype.getTypeName=function(){return"ArcRotateCamera"},__decorate([e.serialize()],i.prototype,"alpha",void 0),__decorate([e.serialize()],i.prototype,"beta",void 0),__decorate([e.serialize()],i.prototype,"radius",void 0),__decorate([e.serializeAsVector3()],i.prototype,"target",void 0),__decorate([e.serialize()],i.prototype,"inertialAlphaOffset",void 0),__decorate([e.serialize()],i.prototype,"inertialBetaOffset",void 0),__decorate([e.serialize()],i.prototype,"inertialRadiusOffset",void 0),__decorate([e.serialize()],i.prototype,"lowerAlphaLimit",void 0),__decorate([e.serialize()],i.prototype,"upperAlphaLimit",void 0),__decorate([e.serialize()],i.prototype,"lowerBetaLimit",void 0),__decorate([e.serialize()],i.prototype,"upperBetaLimit",void 0),__decorate([e.serialize()],i.prototype,"lowerRadiusLimit",void 0),__decorate([e.serialize()],i.prototype,"upperRadiusLimit",void 0),__decorate([e.serialize()],i.prototype,"inertialPanningX",void 0),__decorate([e.serialize()],i.prototype,"inertialPanningY",void 0),__decorate([e.serialize()],i.prototype,"zoomOnFactor",void 0),__decorate([e.serialize()],i.prototype,"allowUpsideDown",void 0),i}(e.TargetCamera);e.ArcRotateCamera=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e){t.call(this,e)}return __extends(i,t),i.prototype.addMouseWheel=function(){return this.add(new e.ArcRotateCameraMouseWheelInput),this},i.prototype.addPointers=function(){return this.add(new e.ArcRotateCameraPointersInput),this},i.prototype.addKeyboard=function(){return this.add(new e.ArcRotateCameraKeyboardMoveInput),this},i.prototype.addGamepad=function(){return this.add(new e.ArcRotateCameraGamepadInput),this},i.prototype.addVRDeviceOrientation=function(){return this.add(new e.ArcRotateCameraVRDeviceOrientationInput),this},i}(e.CameraInputsManager);e.ArcRotateCameraInputsManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e){this._renderingGroups=new Array,this._scene=e}return t.prototype._renderParticles=function(t,i){if(0!==this._scene._activeParticleSystems.length){for(var r=this._scene.activeCamera,n=e.Tools.Now,o=0;ot._alphaIndex?1:e._alphaIndext._distanceToCamera?-1:0}),i=0;ie.ActionManager.LongPressDelay&&Math.abs(l._startingPointerPosition.x-l._pointerX)0&&(c=a.pickSprite(a._unTranslatedPointerX,a._unTranslatedPointerY,h,!1,a.cameraToUseForPointers),c.hit&&c.pickedSprite&&c.pickedSprite.actionManager)){switch(a._pickedDownSprite=c.pickedSprite,i.button){case 0:c.pickedSprite.actionManager.processTrigger(e.ActionManager.OnLeftPickTrigger,e.ActionEvent.CreateNewFromSprite(c.pickedSprite,a,i));break;case 1:c.pickedSprite.actionManager.processTrigger(e.ActionManager.OnCenterPickTrigger,e.ActionEvent.CreateNewFromSprite(c.pickedSprite,a,i));break;case 2:c.pickedSprite.actionManager.processTrigger(e.ActionManager.OnRightPickTrigger,e.ActionEvent.CreateNewFromSprite(c.pickedSprite,a,i))}c.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickDownTrigger,e.ActionEvent.CreateNewFromSprite(c.pickedSprite,a,i))}}},this._onPointerUp=function(i){if(a._updatePointerPosition(i),a.onPrePointerObservable.hasObservers()){var o=t.POINTERUP,s=new r(o,i,a._unTranslatedPointerX,a._unTranslatedPointerY);if(a.onPrePointerObservable.notifyObservers(s,o),s.skipOnPointerObservable)return}if(a.cameraToUseForPointers||a.activeCamera){a.pointerUpPredicate||(a.pointerUpPredicate=function(t){return t.isPickable&&t.isVisible&&t.isReady()&&(!t.actionManager||t.actionManager.hasPickTriggers||t.actionManager.hasSpecificTrigger(e.ActionManager.OnLongPressTrigger))});var c=a.pick(a._unTranslatedPointerX,a._unTranslatedPointerY,a.pointerUpPredicate,!1,a.cameraToUseForPointers);if(c.hit&&c.pickedMesh){if(null!=a._pickedDownMesh&&c.pickedMesh==a._pickedDownMesh&&(a.onPointerPick&&a.onPointerPick(i,c),a.onPointerObservable.hasObservers())){var o=t.POINTERPICK,s=new n(o,i,c);a.onPointerObservable.notifyObservers(s,o)}c.pickedMesh.actionManager&&(c.pickedMesh.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNew(c.pickedMesh,i)),Math.abs(a._startingPointerPosition.x-a._pointerX)0&&(c=a.pickSprite(a._unTranslatedPointerX,a._unTranslatedPointerY,h,!1,a.cameraToUseForPointers),c.hit&&c.pickedSprite&&c.pickedSprite.actionManager&&(c.pickedSprite.actionManager.processTrigger(e.ActionManager.OnPickUpTrigger,e.ActionEvent.CreateNewFromSprite(c.pickedSprite,a,i)),Math.abs(a._startingPointerPosition.x-a._pointerX)0)return!1;var t;for(t=0;t0)return;this._animationStartDate=e.Tools.Now}for(var t=e.Tools.Now,i=t-this._animationStartDate,r=0;r0?this.activeCamera=this.cameras[0]:this.activeCamera=null),this.onCameraRemovedObservable.notifyObservers(e),t},i.prototype.addLight=function(e){e.uniqueId=this._uniqueIdCounter++;this.lights.push(e);this.onNewLightAddedObservable.notifyObservers(e)},i.prototype.addCamera=function(e){e.uniqueId=this._uniqueIdCounter++;this.cameras.push(e);this.onNewCameraAddedObservable.notifyObservers(e)},i.prototype.swithActiveCamera=function(e,t){void 0===t&&(t=!0);var i=this._engine.getRenderingCanvas();this.activeCamera.detachControl(i),this.activeCamera=e,t&&e.attachControl(i)},i.prototype.setActiveCameraByID=function(e){var t=this.getCameraByID(e);return t?(this.activeCamera=t,t):null},i.prototype.setActiveCameraByName=function(e){var t=this.getCameraByName(e);return t?(this.activeCamera=t,t):null},i.prototype.getMaterialByID=function(e){for(var t=0;t-1?(this._geometries.splice(t,1),this.collisionCoordinator.onGeometryDeleted(e),this.onGeometryRemovedObservable.notifyObservers(e),!0):!1},i.prototype.getGeometries=function(){return this._geometries},i.prototype.getMeshByID=function(e){for(var t=0;t=0;t--)if(this.meshes[t].id===e)return this.meshes[t];return null},i.prototype.getLastEntryByID=function(e){var t;for(t=this.meshes.length-1;t>=0;t--)if(this.meshes[t].id===e)return this.meshes[t];for(t=this.cameras.length-1;t>=0;t--)if(this.cameras[t].id===e)return this.cameras[t];for(t=this.lights.length-1;t>=0;t--)if(this.lights[t].id===e)return this.lights[t];return null},i.prototype.getNodeByID=function(e){var t=this.getMeshByID(e);if(t)return t;var i=this.getLightByID(e);if(i)return i;var r=this.getCameraByID(e);if(r)return r;var n=this.getBoneByID(e);return n},i.prototype.getNodeByName=function(e){var t=this.getMeshByName(e);if(t)return t;var i=this.getLightByName(e);if(i)return i;var r=this.getCameraByName(e);if(r)return r;var n=this.getBoneByName(e);return n},i.prototype.getMeshByName=function(e){for(var t=0;t=0;t--)if(this.skeletons[t].id===e)return this.skeletons[t];return null},i.prototype.getSkeletonById=function(e){for(var t=0;tn;n++){var o=t[n];if(!o.isBlocked&&(this._totalVertices+=o.getTotalVertices(),o.isReady()&&o.isEnabled())){o.computeWorldMatrix(),o.actionManager&&o.actionManager.hasSpecificTriggers([e.ActionManager.OnIntersectionEnterTrigger,e.ActionManager.OnIntersectionExitTrigger])&&this._meshesForIntersections.pushNoDuplicate(o);var s=o.getLOD(this.activeCamera);s&&(o._preActivate(),(o.alwaysSelectAsActiveMesh||o.isVisible&&o.visibility>0&&0!==(o.layerMask&this.activeCamera.layerMask)&&o.isInFrustum(this._frustumPlanes))&&(this._activeMeshes.push(o),this.activeCamera._activeMeshes.push(o),o._activate(this._renderId),this._activeMesh(s)))}}var a=e.Tools.Now;if(this.particlesEnabled){e.Tools.StartPerformanceCounter("Particles",this.particleSystems.length>0);for(var h=0;h0)}this._particlesDuration+=e.Tools.Now-a},i.prototype._activeMesh=function(e){if(e.skeleton&&this.skeletonsEnabled&&(this._activeSkeletons.pushNoDuplicate(e.skeleton)&&e.skeleton.prepare(),e.computeBonesUsingShaders||this._softwareSkinnedMeshes.pushNoDuplicate(e)),(e.showBoundingBox||this.forceShowBoundingBoxes)&&this._boundingBoxRenderer.renderList.push(e.getBoundingInfo().boundingBox),e._edgesRenderer&&this._edgesRenderers.push(e._edgesRenderer),e&&e.subMeshes){var t,i;if(e._submeshesOctree&&e.useOctreeForRenderingSelection){var r=e._submeshesOctree.select(this._frustumPlanes);t=r.length,i=r.data}else i=e.subMeshes,t=i.length;for(var n=0;t>n;n++){var o=i[n];this._evaluateSubMesh(o,e)}}},i.prototype.updateTransformMatrix=function(e){this.setTransformMatrix(this.activeCamera.getViewMatrix(),this.activeCamera.getProjectionMatrix(e))},i.prototype._renderForCamera=function(t){var i=this._engine;if(this.activeCamera=t,!this.activeCamera)throw new Error("Active camera not set");e.Tools.StartPerformanceCounter("Rendering camera "+this.activeCamera.name),i.setViewport(this.activeCamera.viewport),this.resetCachedMaterial(),this._renderId++,this.updateTransformMatrix(),this.onBeforeCameraRenderObservable.notifyObservers(this.activeCamera);var r=e.Tools.Now;e.Tools.StartPerformanceCounter("Active meshes evaluation"),this._evaluateActiveMeshes(),this._evaluateActiveMeshesDuration+=e.Tools.Now-r,e.Tools.EndPerformanceCounter("Active meshes evaluation");for(var n=0;n0){this._intermediateRendering=!0,e.Tools.StartPerformanceCounter("Render targets",this._renderTargets.length>0);for(var a=0;a0),this._intermediateRendering=!1,this._renderId++,i.restoreDefaultFramebuffer()}this._renderTargetsDuration+=e.Tools.Now-s,this.postProcessManager._prepareFrame();var l,u,f=e.Tools.Now;if(this.layers.length){for(i.setDepthBuffer(!1),l=0;l0);for(var p=0;p0)}if(this.layers.length){for(i.setDepthBuffer(!1),l=0;l-1&&(n.trigger===e.ActionManager.OnIntersectionExitTrigger&&n._executeCurrent(e.ActionEvent.CreateNew(i,null,s)),i.actionManager.hasSpecificTrigger(e.ActionManager.OnIntersectionExitTrigger)&&n.trigger!==e.ActionManager.OnIntersectionExitTrigger||i._intersectionsInProgress.splice(h,1))}}},i.prototype.render=function(){var t=e.Tools.Now;this._particlesDuration=0,this._spritesDuration=0,this._activeParticles=0,this._renderDuration=0,this._renderTargetsDuration=0,this._evaluateActiveMeshesDuration=0,this._totalVertices=0,this._activeIndices=0,this._activeBones=0,this.getEngine().resetDrawCalls(),this._meshesForIntersections.reset(),this.resetCachedMaterial(),e.Tools.StartPerformanceCounter("Scene rendering"),this.actionManager&&this.actionManager.processTrigger(e.ActionManager.OnEveryFrameTrigger,null),this.simplificationQueue&&!this.simplificationQueue.running&&this.simplificationQueue.executeNext();var r=Math.max(i.MinDeltaTime,Math.min(this._engine.getDeltaTime(),i.MaxDeltaTime));this._animationRatio=.06*r,this._animate(),this._physicsEngine&&(e.Tools.StartPerformanceCounter("Physics"),this._physicsEngine._step(r/1e3),e.Tools.EndPerformanceCounter("Physics")),this.onBeforeRenderObservable.notifyObservers(this);var n=e.Tools.Now,o=this.getEngine(),s=this.activeCamera;if(this.renderTargetsEnabled){e.Tools.StartPerformanceCounter("Custom render targets",this.customRenderTargets.length>0);for(var a=0;a0),this._renderId++}if(this.customRenderTargets.length>0&&o.restoreDefaultFramebuffer(),this._renderTargetsDuration+=e.Tools.Now-n,this.activeCamera=s,this.proceduralTexturesEnabled){e.Tools.StartPerformanceCounter("Procedural textures",this._proceduralTextures.length>0);for(var c=0;c0)}if(this._engine.clear(this.clearColor,this.autoClear||this.forceWireframe||this.forcePointsCloud,!0),this.shadowsEnabled)for(var u=0;u0)for(var p=this._renderId,_=0;_0&&this._engine.clear(0,!1,!0),this._processSubCameras(this.activeCameras[_]);else{if(!this.activeCamera)throw new Error("No camera defined");this._processSubCameras(this.activeCamera)}this._checkIntersections(),e.AudioEngine&&this._updateAudioParameters(),this.afterRender&&this.afterRender(),this.onAfterRenderObservable.notifyObservers(this);for(var g=0;g0?this.activeCameras[0]:this.activeCamera,t&&i.canUseWebAudio){i.audioContext.listener.setPosition(t.position.x,t.position.y,t.position.z);var r=e.Matrix.Invert(t.getViewMatrix()),n=e.Vector3.TransformNormal(new e.Vector3(0,0,-1),r);n.normalize(),i.audioContext.listener.setOrientation(n.x,n.y,n.z,0,1,0);var o;for(o=0;o-1&&this._engine.scenes.splice(t,1),this._engine.wipeCaches()},i.prototype.disposeSounds=function(){this.mainSoundTrack.dispose();for(var e=0;e=n.distance))&&(n=c,r))break}return n||new e.PickingInfo},i.prototype._internalPickSprites=function(t,i,r,n){var o=null;if(n=n||this.activeCamera,this.spriteManagers.length>0)for(var s=0;s=o.distance))&&(o=h,r))break}}return o||new e.PickingInfo},i.prototype.pick=function(e,t,i,r,n){var o=this;return this._internalPick(function(i){return o.createPickingRay(e,t,i,n)},i,r)},i.prototype.pickSprite=function(e,t,i,r,n){return this._internalPickSprites(this.createPickingRayInCameraSpace(e,t,n),i,r,n)},i.prototype.pickWithRay=function(t,i,r){var n=this;return this._internalPick(function(i){return n._pickWithRayInverseMatrix||(n._pickWithRayInverseMatrix=e.Matrix.Identity()),i.invertToRef(n._pickWithRayInverseMatrix),e.Ray.Transform(t,n._pickWithRayInverseMatrix)},i,r)},i.prototype.setPointerOverMesh=function(t){this._pointerOverMesh!==t&&(this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(e.ActionManager.OnPointerOutTrigger,e.ActionEvent.CreateNew(this._pointerOverMesh)),this._pointerOverMesh=t,this._pointerOverMesh&&this._pointerOverMesh.actionManager&&this._pointerOverMesh.actionManager.processTrigger(e.ActionManager.OnPointerOverTrigger,e.ActionEvent.CreateNew(this._pointerOverMesh)))},i.prototype.getPointerOverMesh=function(){return this._pointerOverMesh},i.prototype.setPointerOverSprite=function(t){this._pointerOverSprite!==t&&(this._pointerOverSprite&&this._pointerOverSprite.actionManager&&this._pointerOverSprite.actionManager.processTrigger(e.ActionManager.OnPointerOutTrigger,e.ActionEvent.CreateNewFromSprite(this._pointerOverSprite,this)),this._pointerOverSprite=t,this._pointerOverSprite&&this._pointerOverSprite.actionManager&&this._pointerOverSprite.actionManager.processTrigger(e.ActionManager.OnPointerOverTrigger,e.ActionEvent.CreateNewFromSprite(this._pointerOverSprite,this)))},i.prototype.getPointerOverSprite=function(){return this._pointerOverSprite},i.prototype.getPhysicsEngine=function(){return this._physicsEngine},i.prototype.enablePhysics=function(t,i){if(this._physicsEngine)return!0;try{return this._physicsEngine=new e.PhysicsEngine(t,i),!0}catch(r){return e.Tools.Error(r.message),!1}},i.prototype.disablePhysicsEngine=function(){this._physicsEngine&&(this._physicsEngine.dispose(),this._physicsEngine=void 0)},i.prototype.isPhysicsEnabled=function(){return void 0!==this._physicsEngine},i.prototype.setGravity=function(t){e.Tools.Warn("Deprecated, please use 'scene.getPhysicsEngine().setGravity()'"),this._physicsEngine&&this._physicsEngine.setGravity(t)},i.prototype.createCompoundImpostor=function(t,i){e.Tools.Warn("Scene.createCompoundImpostor is deprecated. Please use PhysicsImpostor parent/child"),t.parts&&(i=t,t=t.parts);var r=t[0].mesh;r.physicsImpostor=new e.PhysicsImpostor(r,t[0].impostor,i,this);for(var n=1;n0},enumerable:!0,configurable:!0}),r.prototype._sortLODLevels=function(){this._LODLevels.sort(function(e,t){return e.distancet.distance?-1:0})},r.prototype.addLODLevel=function(t,i){if(i&&i._masterMesh)return e.Tools.Warn("You cannot use a mesh as LOD level twice"),this;var r=new e.Internals.MeshLODLevel(t,i);return this._LODLevels.push(r),i&&(i._masterMesh=this),this._sortLODLevels(),this},r.prototype.getLODLevelAtDistance=function(e){for(var t=0;ti)return this.onLODLevelSelection&&this.onLODLevelSelection(i,this,this._LODLevels[this._LODLevels.length-1].mesh),this;for(var r=0;rt)){for(var i=this.getTotalIndices(),r=i/t|0,n=0;r%3!==0;)r++;this.releaseSubMeshes();for(var o=0;t>o&&!(n>=i);o++)e.SubMesh.CreateFromIndices(0,n,Math.min(r,i-n),this),n+=r;this.synchronizeInstances()}},r.prototype.setVerticesData=function(t,i,r,n){if(this._geometry)this._geometry.setVerticesData(t,i,r,n);else{var o=new e.VertexData;o.set(i,t);var s=this.getScene();new e.Geometry(e.Geometry.RandomId(),s,o,r,this)}},r.prototype.setVerticesBuffer=function(t){if(!this._geometry){var i=this.getScene();new e.Geometry(e.Geometry.RandomId(),i).applyToMesh(this)}this._geometry.setVerticesBuffer(t)},r.prototype.updateVerticesData=function(e,t,i,r){this._geometry&&(r?(this.makeGeometryUnique(),this.updateVerticesData(e,t,i,!1)):this._geometry.updateVerticesData(e,t,i))},r.prototype.updateVerticesDataDirectly=function(t,i,r,n){e.Tools.Warn("Mesh.updateVerticesDataDirectly deprecated since 2.3."),this._geometry&&(n?(this.makeGeometryUnique(),this.updateVerticesDataDirectly(t,i,r,!1)):this._geometry.updateVerticesDataDirectly(t,i,r))},r.prototype.updateMeshPositions=function(t,i){void 0===i&&(i=!0);var r=this.getVerticesData(e.VertexBuffer.PositionKind);if(t(r),this.updateVerticesData(e.VertexBuffer.PositionKind,r,!1,!1),i){var n=this.getIndices(),o=this.getVerticesData(e.VertexBuffer.NormalKind);e.VertexData.ComputeNormals(r,n,o),this.updateVerticesData(e.VertexBuffer.NormalKind,o,!1,!1)}},r.prototype.makeGeometryUnique=function(){if(this._geometry){var t=this._geometry.copy(e.Geometry.RandomId());t.applyToMesh(this)}},r.prototype.setIndices=function(t,i){if(this._geometry)this._geometry.setIndices(t,i);else{var r=new e.VertexData;r.indices=t;var n=this.getScene();new e.Geometry(e.Geometry.RandomId(),n,r,!1,this)}},r.prototype.toLeftHanded=function(){this._geometry&&this._geometry.toLeftHanded()},r.prototype._bind=function(t,i,r){var n,o=this.getScene().getEngine();if(this._unIndexed)n=null;else switch(r){case e.Material.PointFillMode:n=null;break;case e.Material.WireFrameFillMode:n=t.getLinesIndexBuffer(this.getIndices(),o);break;default:case e.Material.TriangleFillMode:n=this._unIndexed?null:this._geometry.getIndexBuffer()}o.bindBuffers(this._geometry.getVertexBuffers(),n,i)},r.prototype._draw=function(t,i,r){if(this._geometry&&this._geometry.getVertexBuffers()&&this._geometry.getIndexBuffer()){this.onBeforeDrawObservable.notifyObservers(this);var n=this.getScene().getEngine();switch(i){case e.Material.PointFillMode:n.drawPointClouds(t.verticesStart,t.verticesCount,r);break;case e.Material.WireFrameFillMode:this._unIndexed?n.drawUnIndexed(!1,t.verticesStart,t.verticesCount,r):n.draw(!1,0,r>0?t.linesIndexCount/2:t.linesIndexCount,r);break;default:this._unIndexed?n.drawUnIndexed(!0,t.verticesStart,t.verticesCount,r):n.draw(!0,t.indexStart,t.indexCount,r)}}},r.prototype.registerBeforeRender=function(e){this.onBeforeRenderObservable.add(e)},r.prototype.unregisterBeforeRender=function(e){this.onBeforeRenderObservable.removeCallback(e)},r.prototype.registerAfterRender=function(e){this.onAfterRenderObservable.add(e)},r.prototype.unregisterAfterRender=function(e){this.onAfterRenderObservable.removeCallback(e)},r.prototype._getInstancesRenderList=function(e){var t=this.getScene();if(this._batchCache.mustReturn=!1,this._batchCache.renderSelf[e]=this.isEnabled()&&this.isVisible,this._batchCache.visibleInstances[e]=null,this._visibleInstances){var i=t.getRenderId(),r=t._isInIntermediateRendering()?this._visibleInstances.intermediateDefaultRenderId:this._visibleInstances.defaultRenderId;this._batchCache.visibleInstances[e]=this._visibleInstances[i];var n=this._renderId;if(!this._batchCache.visibleInstances[e]&&r&&(this._batchCache.visibleInstances[e]=this._visibleInstances[r],i=Math.max(r,i),n=Math.max(this._visibleInstances.selfDefaultRenderId,i)),this._batchCache.visibleInstances[e]&&this._batchCache.visibleInstances[e].length){if(this._renderIdForInstances[e]===i)return this._batchCache.mustReturn=!0,this._batchCache;i!==n&&(this._batchCache.renderSelf[e]=!1)}this._renderIdForInstances[e]=i}return this._batchCache},r.prototype._renderWithInstances=function(t,i,r,n,o){for(var s=r.visibleInstances[t._id],a=s.length+1,h=16*a*4,c=this._instancesBufferSize,l=this._instancesBuffer;this._instancesBufferSizec;c++){var d=u[c];for(t=0;t_;_++)s[i].push(o[i][d*p+_])}}var g=[],m=s[e.VertexBuffer.PositionKind];for(c=0;f>c;c+=3){u[c]=c,u[c+1]=c+1,u[c+2]=c+2;for(var v=e.Vector3.FromArray(m,3*c),y=e.Vector3.FromArray(m,3*(c+1)),x=e.Vector3.FromArray(m,3*(c+2)),b=v.subtract(y),P=x.subtract(y),A=e.Vector3.Normalize(e.Vector3.Cross(b,P)),E=0;3>E;E++)g.push(A.x),g.push(A.y),g.push(A.z)}for(this.setIndices(u),this.setVerticesData(e.VertexBuffer.NormalKind,g,a),t=0;th;h++){var f=l[h];for(t=0;tp;p++)s[i].push(o[i][f*d+p])}}for(h=0;u>h;h+=3)l[h]=h,l[h+1]=h+1,l[h+2]=h+2;for(this.setIndices(l),t=0;tr;++r){var n=o[r];if(i.equals(n)){a[t]=r;break}}},function(){for(var e=0;e-1&&(o.skeleton=i.getLastSkeletonByID(t.skeletonId),t.numBoneInfluencers&&(o.numBoneInfluencers=t.numBoneInfluencers)),t.animations){for(var s=0;s4,h=a?this.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind):null,c=a?this.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind):null,l=t.getTransformMatrices(this),u=e.Vector3.Zero(),f=new e.Matrix,d=new e.Matrix,p=0,_=0;_n&&(g=s[p+n],g>0);n++)e.Matrix.FromFloat32ArrayToRefScaled(l,16*o[p+n],g,d),f.addToSelf(d);if(a)for(n=0;4>n&&(g=c[p+n],g>0);n++)e.Matrix.FromFloat32ArrayToRefScaled(l,16*h[p+n],g,d),f.addToSelf(d);e.Vector3.TransformCoordinatesFromFloatsToRef(this._sourcePositions[_],this._sourcePositions[_+1],this._sourcePositions[_+2],f,u),u.toArray(i,_),e.Vector3.TransformNormalFromFloatsToRef(this._sourceNormals[_],this._sourceNormals[_+1],this._sourceNormals[_+2],f,u),u.toArray(r,_),f.reset()}return this.updateVerticesData(e.VertexBuffer.PositionKind,i),this.updateVerticesData(e.VertexBuffer.NormalKind,r),this}},r.MinMax=function(e){var t=null,i=null;for(var r in e){var n=e[r],o=n.getBoundingInfo().boundingBox;t?(t.MinimizeInPlace(o.minimumWorld),i.MaximizeInPlace(o.maximumWorld)):(t=o.minimumWorld,i=o.maximumWorld)}return{min:t,max:i}},r.Center=function(t){var i=void 0!==t.min?t:r.MinMax(t);return e.Vector3.Center(i.min,i.max)},r.MergeMeshes=function(t,i,n,o){void 0===i&&(i=!0);var s;if(!n){var a=0;for(s=0;s65536))return e.Tools.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices"),null}var h,c,l;for(s=0;sl)&&(n||!o||lc;c++){var l=h[c];s>l&&(s=l),l>a&&(a=l)}return new t(e,s,a-s+1,i,r,n,o)},t}();e.SubMesh=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.CreateBox=function(t,i,r){var n=new e.Mesh(t,r),o=e.VertexData.CreateBox(i);return o.applyToMesh(n,i.updatable),n},t.CreateSphere=function(t,i,r){var n=new e.Mesh(t,r),o=e.VertexData.CreateSphere(i);return o.applyToMesh(n,i.updatable),n},t.CreateDisc=function(t,i,r){var n=new e.Mesh(t,r),o=e.VertexData.CreateDisc(i);return o.applyToMesh(n,i.updatable),n},t.CreateIcoSphere=function(t,i,r){var n=new e.Mesh(t,r),o=e.VertexData.CreateIcoSphere(i);return o.applyToMesh(n,i.updatable),n},t.CreateRibbon=function(t,i,r){var n=i.pathArray,o=i.closeArray,s=i.closePath,a=(i.offset,i.sideOrientation),h=i.instance,c=i.updatable;if(h){var l=function(t){for(var i=n[0].length,r=0,o=h.sideOrientation===e.Mesh.DOUBLESIDE?2:1,s=1;o>=s;s++)for(var a=0;ai?i:l;for(var u=0;i>u;)t[r]=c[u].x,t[r+1]=c[u].y,t[r+2]=c[u].z,u++,r+=3;h._closePath&&(t[r]=c[0].x,t[r+1]=c[0].y,t[r+2]=c[0].z,r+=3)}},u=h.getVerticesData(e.VertexBuffer.PositionKind);if(l(u),h.updateVerticesData(e.VertexBuffer.PositionKind,u,!1,!1),!h.areNormalsFrozen){var f=h.getIndices(),d=h.getVerticesData(e.VertexBuffer.NormalKind);if(e.VertexData.ComputeNormals(u,f,d),h._closePath)for(var p=0,_=0,g=0;gd&&u1?1:r.arc||1,a=void 0===r.closed?!0:r.closed,h=r.shape,c=r.radius||1,l=r.tessellation||64,u=r.updatable,f=0===r.sideOrientation?0:r.sideOrientation||e.Mesh.DEFAULTSIDE,d=r.cap||e.Mesh.NO_CAP,p=2*Math.PI,_=new Array,g=0,m=0,v=p/l*s,y=new Array;for(g=0;l>=g;g++){var y=[];for(d!=e.Mesh.CAP_START&&d!=e.Mesh.CAP_ALL||(y.push(new e.Vector3(0,h[0].y,0)),y.push(new e.Vector3(Math.cos(g*v)*h[0].x*c,h[0].y,Math.sin(g*v)*h[0].x*c))),m=0;m1?1:r.arc||1;var d,p,_=function(t,i,r,n,o,s,a,h){for(var c,l,u,f,d=i.getTangents(),p=i.getNormals(),_=i.getDistances(),g=2*Math.PI,m=g/o*h,v=function(){return n},y=s||v,x=e.Tmp.Matrix[0],b=a===e.Mesh._NO_CAP||a===e.Mesh.CAP_END?0:2,P=0;PA;A++)e.Matrix.RotationAxisToRef(d[P],m*A,x),f=c[A]?c[A]:e.Vector3.Zero(),e.Vector3.TransformCoordinatesToRef(u,x,f),f.scaleInPlace(l).addInPlace(t[P]),c[A]=f;r[b]=c,b++}var E=function(e,i){for(var r=Array(),n=0;e>n;n++)r.push(t[i]);return r};switch(a){case e.Mesh.NO_CAP:break;case e.Mesh.CAP_START:r[0]=E(o,0),r[1]=r[2].slice(0);break;case e.Mesh.CAP_END:r[b]=r[b-1].slice(0),r[b+1]=E(o,t.length-1);break;case e.Mesh.CAP_ALL:r[0]=E(o,0),r[1]=r[2].slice(0),r[b]=r[b-1].slice(0),r[b+1]=E(o,t.length-1)}return r};if(f){var g=r.arc||f.arc;return d=f.path3D.update(o),p=_(o,d,f.pathArray,s,f.tessellation,h,f.cap,g),f=t.CreateRibbon(null,{pathArray:p,instance:f}),f.path3D=d,f.pathArray=p,f.arc=g,f}d=new e.Path3D(o);var m=new Array;c=0>c||c>3?0:c,p=_(o,d,m,s,a,h,c,r.arc);var v=t.CreateRibbon(i,{pathArray:p,closePath:!0,closeArray:!1,updatable:l,sideOrientation:u},n);return v.pathArray=p,v.path3D=d,v.tessellation=a,v.cap=c,v.arc=r.arc,v},t.CreatePolyhedron=function(t,i,r){var n=new e.Mesh(t,r),o=e.VertexData.CreatePolyhedron(i);return o.applyToMesh(n,i.updatable),n},t.CreateDecal=function(t,i,r){var n=i.getIndices(),o=i.getVerticesData(e.VertexBuffer.PositionKind),s=i.getVerticesData(e.VertexBuffer.NormalKind),a=r.position||e.Vector3.Zero(),h=r.normal||e.Vector3.Up(),c=r.size||new e.Vector3(1,1,1),l=r.angle||0;if(!h){var u=new e.Vector3(0,0,1),f=i.getScene().activeCamera,d=e.Vector3.TransformCoordinates(u,f.getWorldMatrix());h=f.globalPosition.subtract(d)}var p=-Math.atan2(h.z,h.x)-Math.PI/2,_=Math.sqrt(h.x*h.x+h.z*h.z),g=Math.atan2(h.y,_),m=e.Matrix.RotationYawPitchRoll(p,g,l).multiply(e.Matrix.Translation(a.x,a.y,a.z)),v=e.Matrix.Invert(m),y=i.getWorldMatrix(),x=y.multiply(v),b=new e.VertexData;b.indices=[],b.positions=[],b.normals=[],b.uvs=[];for(var P=0,A=function(t){var i=n[t],r=new e.PositionNormalVertex;return r.position=new e.Vector3(o[3*i],o[3*i+1],o[3*i+2]),r.position=e.Vector3.TransformCoordinates(r.position,x),r.normal=new e.Vector3(s[3*i],s[3*i+1],s[3*i+2]),r},E=function(t,i){if(0===t.length)return t;for(var r=.5*Math.abs(e.Vector3.Dot(c,i)),n=function(t,n){var o=e.Vector3.GetClipFactor(t.position,n.position,i,r);return new e.PositionNormalVertex(e.Vector3.Lerp(t.position,n.position,o),e.Vector3.Lerp(t.normal,n.normal,o))},o=new Array,s=0;s0,h=m>0,l=v>0,_=(a?1:0)+(h?1:0)+(l?1:0)){case 0:o.push(t[s]),o.push(t[s+1]),o.push(t[s+2]);break;case 1:if(a&&(u=t[s+1],f=t[s+2],d=n(t[s],u),p=n(t[s],f)),h){u=t[s],f=t[s+2],d=n(t[s+1],u),p=n(t[s+1],f),o.push(d),o.push(f.clone()),o.push(u.clone()),o.push(f.clone()),o.push(d.clone()),o.push(p);break}l&&(u=t[s],f=t[s+1],d=n(t[s+2],u),p=n(t[s+2],f)),o.push(u.clone()),o.push(f.clone()),o.push(d),o.push(p),o.push(d.clone()),o.push(f.clone());break;case 2:a||(u=t[s].clone(),f=n(u,t[s+1]),d=n(u,t[s+2]),o.push(u),o.push(f),o.push(d)),h||(u=t[s+1].clone(),f=n(u,t[s+2]),d=n(u,t[s]),o.push(u),o.push(f),o.push(d)),l||(u=t[s+2].clone(),f=n(u,t[s]),d=n(u,t[s+1]),o.push(u),o.push(f),o.push(d));break;case 3:}}return o},T=0;Tl||l>3?0:l,m=v(i,r,g,y,n,o,s,a,l,u);var x=e.Mesh.CreateRibbon(t,m,h,c,0,f,d,p);return x.pathArray=m,x.path3D=g,x.cap=l,x},t}();e.MeshBuilder=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t){this.hasAlpha=!1,this.getAlphaFromRGB=!1,this.level=1,this.coordinatesIndex=0,this.coordinatesMode=e.Texture.EXPLICIT_MODE,this.wrapU=e.Texture.WRAP_ADDRESSMODE,this.wrapV=e.Texture.WRAP_ADDRESSMODE,this.anisotropicFilteringLevel=4,this.isCube=!1,this.isRenderTarget=!1,this.animations=new Array,this.onDisposeObservable=new e.Observable,this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this._scene=t,this._scene.textures.push(this)}return t.prototype.toString=function(){return this.name},Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),t.prototype.getScene=function(){return this._scene},t.prototype.getTextureMatrix=function(){return null},t.prototype.getReflectionTextureMatrix=function(){return null},t.prototype.getInternalTexture=function(){return this._texture},t.prototype.isReady=function(){return this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED?!0:this._texture?this._texture.isReady:!1},t.prototype.getSize=function(){return this._texture._width?{width:this._texture._width,height:this._texture._height}:this._texture._size?{width:this._texture._size,height:this._texture._size}:{width:0,height:0}},t.prototype.getBaseSize=function(){return this.isReady()&&this._texture?this._texture._size?{width:this._texture._size,height:this._texture._size}:{width:this._texture._baseWidth,height:this._texture._baseHeight}:{width:0,height:0}},t.prototype.scale=function(e){},Object.defineProperty(t.prototype,"canRescale",{get:function(){return!1},enumerable:!0,configurable:!0}),t.prototype._removeFromCache=function(e,t){for(var i=this._scene.getEngine().getLoadedTexturesCache(),r=0;r=0&&this._scene.textures.splice(e,1),void 0!==this._texture&&(this.releaseInternalTexture(),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear())},t.prototype.serialize=function(){if(!this.name)return null;var t=e.SerializationHelper.Serialize(this);return e.Animation.AppendSerializedAnimations(this,t),t},__decorate([e.serialize()],t.prototype,"name",void 0),__decorate([e.serialize()],t.prototype,"hasAlpha",void 0),__decorate([e.serialize()],t.prototype,"getAlphaFromRGB",void 0),__decorate([e.serialize()],t.prototype,"level",void 0),__decorate([e.serialize()],t.prototype,"coordinatesIndex",void 0),__decorate([e.serialize()],t.prototype,"coordinatesMode",void 0),__decorate([e.serialize()],t.prototype,"wrapU",void 0),__decorate([e.serialize()],t.prototype,"wrapV",void 0),__decorate([e.serialize()],t.prototype,"anisotropicFilteringLevel",void 0),__decorate([e.serialize()],t.prototype,"isCube",void 0),__decorate([e.serialize()],t.prototype,"isRenderTarget",void 0),t}();e.BaseTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(r,n,o,s,a,h,c,l,u){void 0===a&&(a=i.TRILINEAR_SAMPLINGMODE),void 0===h&&(h=null),void 0===c&&(c=null),void 0===l&&(l=null),void 0===u&&(u=!1),t.call(this,n),this.uOffset=0,this.vOffset=0,this.uScale=1,this.vScale=1,this.uAng=0,this.vAng=0,this.wAng=0,this.name=r,this.url=r,this._noMipmap=o,this._invertY=s,this._samplingMode=a,this._buffer=l,this._deleteBuffer=u,r&&(this._texture=this._getFromCache(r,o,a),this._texture?e.Tools.SetImmediate(function(){h&&h()}):n.useDelayedTextureLoading?(this.delayLoadState=e.Engine.DELAYLOADSTATE_NOTLOADED,this._delayedOnLoad=h,this._delayedOnError=c):(this._texture=n.getEngine().createTexture(r,o,s,n,this._samplingMode,h,c,this._buffer),u&&delete this._buffer))}return __extends(i,t),Object.defineProperty(i.prototype,"noMipmap",{get:function(){return this._noMipmap},enumerable:!0,configurable:!0}),i.prototype.delayLoad=function(){this.delayLoadState===e.Engine.DELAYLOADSTATE_NOTLOADED&&(this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,this._texture=this._getFromCache(this.url,this._noMipmap,this._samplingMode),this._texture||(this._texture=this.getScene().getEngine().createTexture(this.url,this._noMipmap,this._invertY,this.getScene(),this._samplingMode,this._delayedOnLoad,this._delayedOnError,this._buffer),this._deleteBuffer&&delete this._buffer))},i.prototype.updateSamplingMode=function(e){this._texture&&(this._samplingMode=e,this.getScene().getEngine().updateTextureSamplingMode(e,this._texture))},i.prototype._prepareRowForTextureGeneration=function(t,i,r,n){t*=this.uScale,i*=this.vScale,t-=.5*this.uScale,i-=.5*this.vScale,r-=.5,e.Vector3.TransformCoordinatesFromFloatsToRef(t,i,r,this._rowGenerationMatrix,n),n.x+=.5*this.uScale+this.uOffset,n.y+=.5*this.vScale+this.vOffset,n.z+=.5},i.prototype.getTextureMatrix=function(){return this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.uAng===this._cachedUAng&&this.vAng===this._cachedVAng&&this.wAng===this._cachedWAng?this._cachedTextureMatrix:(this._cachedUOffset=this.uOffset,this._cachedVOffset=this.vOffset,this._cachedUScale=this.uScale,this._cachedVScale=this.vScale,this._cachedUAng=this.uAng,this._cachedVAng=this.vAng,this._cachedWAng=this.wAng,this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero(),this._rowGenerationMatrix=new e.Matrix,this._t0=e.Vector3.Zero(),this._t1=e.Vector3.Zero(),this._t2=e.Vector3.Zero()),e.Matrix.RotationYawPitchRollToRef(this.vAng,this.uAng,this.wAng,this._rowGenerationMatrix),this._prepareRowForTextureGeneration(0,0,0,this._t0),this._prepareRowForTextureGeneration(1,0,0,this._t1),this._prepareRowForTextureGeneration(0,1,0,this._t2),this._t1.subtractInPlace(this._t0),this._t2.subtractInPlace(this._t0),e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix.m[0]=this._t1.x,this._cachedTextureMatrix.m[1]=this._t1.y,this._cachedTextureMatrix.m[2]=this._t1.z,this._cachedTextureMatrix.m[4]=this._t2.x,this._cachedTextureMatrix.m[5]=this._t2.y,this._cachedTextureMatrix.m[6]=this._t2.z,this._cachedTextureMatrix.m[8]=this._t0.x,this._cachedTextureMatrix.m[9]=this._t0.y,this._cachedTextureMatrix.m[10]=this._t0.z,this._cachedTextureMatrix)},i.prototype.getReflectionTextureMatrix=function(){if(this.uOffset===this._cachedUOffset&&this.vOffset===this._cachedVOffset&&this.uScale===this._cachedUScale&&this.vScale===this._cachedVScale&&this.coordinatesMode===this._cachedCoordinatesMode)return this._cachedTextureMatrix;switch(this._cachedTextureMatrix||(this._cachedTextureMatrix=e.Matrix.Zero(),this._projectionModeMatrix=e.Matrix.Zero()),this._cachedCoordinatesMode=this.coordinatesMode,this.coordinatesMode){case i.PLANAR_MODE:e.Matrix.IdentityToRef(this._cachedTextureMatrix),this._cachedTextureMatrix[0]=this.uScale,this._cachedTextureMatrix[5]=this.vScale,this._cachedTextureMatrix[12]=this.uOffset,this._cachedTextureMatrix[13]=this.vOffset;break;case i.PROJECTION_MODE:e.Matrix.IdentityToRef(this._projectionModeMatrix),this._projectionModeMatrix.m[0]=.5,this._projectionModeMatrix.m[5]=-.5,this._projectionModeMatrix.m[10]=0,this._projectionModeMatrix.m[12]=.5,this._projectionModeMatrix.m[13]=.5,this._projectionModeMatrix.m[14]=1,this._projectionModeMatrix.m[15]=1,this.getScene().getProjectionMatrix().multiplyToRef(this._projectionModeMatrix,this._cachedTextureMatrix);break;default:e.Matrix.IdentityToRef(this._cachedTextureMatrix)}return this._cachedTextureMatrix},i.prototype.clone=function(){var t=this;return e.SerializationHelper.Clone(function(){return new i(t._texture.url,t.getScene(),t._noMipmap,t._invertY,t._samplingMode)},this)},i.CreateFromBase64String=function(e,t,r,n,o,s,a,h){return void 0===s&&(s=i.TRILINEAR_SAMPLINGMODE),void 0===a&&(a=null),void 0===h&&(h=null),new i("data:"+t,r,n,o,s,a,h,e)},i.Parse=function(t,r,n){if(t.isCube)return e.CubeTexture.Parse(t,r,n);if(!t.name&&!t.isRenderTarget)return null;var o=e.SerializationHelper.Parse(function(){if(t.mirrorPlane){var o=new e.MirrorTexture(t.name,t.renderTargetSize,r);return o._waitingRenderList=t.renderList,o.mirrorPlane=e.Plane.FromArray(t.mirrorPlane),o}if(t.isRenderTarget){var s=new e.RenderTargetTexture(t.name,t.renderTargetSize,r);return s._waitingRenderList=t.renderList,s}var a;return a=t.base64String?i.CreateFromBase64String(t.base64String,t.name,r):new i(n+t.name,r)},t,r);if(t.animations)for(var s=0;sf;f++)this.renderToTarget(f,a,e,t),i.incrementRenderId(),i.resetCachedMaterial();else this.renderToTarget(0,a,e,t);this.onAfterUnbindObservable.notifyObservers(this),this.activeCamera&&this.activeCamera!==i.activeCamera&&i.setTransformMatrix(i.activeCamera.getViewMatrix(),i.activeCamera.getProjectionMatrix(!0)),i.resetCachedMaterial()}},i.prototype.renderToTarget=function(t,i,r,n){var o=this.getScene(),s=o.getEngine();r&&o.postProcessManager._prepareFrame(this._texture)||(this.isCube?s.bindFramebuffer(this._texture,t):s.bindFramebuffer(this._texture)),this.onBeforeRenderObservable.notifyObservers(t),this.onClearObservable.hasObservers()?this.onClearObservable.notifyObservers(s):s.clear(o.clearColor,!0,!0),this._doNotChangeAspectRatio||o.updateTransformMatrix(!0),this._renderingManager.render(this.customRenderFunction,i,this.renderParticles,this.renderSprites),r&&o.postProcessManager._finalizeFrame(!1,this._texture,t),this._doNotChangeAspectRatio||o.updateTransformMatrix(!0),this.onAfterRenderObservable.notifyObservers(t),n&&e.Tools.DumpFramebuffer(this._size,this._size,s),this.isCube&&5!==t||(this.isCube&&5===t&&s.generateMipMapsForCubemap(this._texture),s.unBindFramebuffer(this._texture,this.isCube))},i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.coordinatesMode=this.coordinatesMode,t.renderList=this.renderList.slice(0),t},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);e.renderTargetSize=this.getRenderSize(),e.renderList=[];for(var i=0;io;o++)i.bindFramebuffer(this._texture,o),this._effect.setFloat("face",o),i.clear(t.clearColor,!0,!0),i.draw(!0,0,6),5===o&&i.generateMipMapsForCubemap(this._texture);else i.bindFramebuffer(this._texture),i.clear(t.clearColor,!0,!0),i.draw(!0,0,6);i.unBindFramebuffer(this._texture,this.isCube),this.onGenerated&&this.onGenerated()},i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this._fragment,this.getScene(),this._fallbackTexture,this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.coordinatesMode=this.coordinatesMode,t},i.prototype.dispose=function(){var i=this.getScene()._proceduralTextures.indexOf(this);i>=0&&this.getScene()._proceduralTextures.splice(i,1);var r=this._vertexBuffers[e.VertexBuffer.PositionKind];r&&(r.dispose(),this._vertexBuffers[e.VertexBuffer.PositionKind]=null),this._indexBuffer&&this.getScene().getEngine()._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),t.prototype.dispose.call(this)},i}(e.Texture);e.ProceduralTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){var s=this;t.call(this,i,r,n,o,!0),this.mirrorPlane=new e.Plane(0,1,0,1),this._transformMatrix=e.Matrix.Zero(),this._mirrorMatrix=e.Matrix.Zero(),this.onBeforeRenderObservable.add(function(){e.Matrix.ReflectionToRef(s.mirrorPlane,s._mirrorMatrix),s._savedViewMatrix=n.getViewMatrix(),s._mirrorMatrix.multiplyToRef(s._savedViewMatrix,s._transformMatrix),n.setTransformMatrix(s._transformMatrix,n.getProjectionMatrix()),n.clipPlane=s.mirrorPlane,n.getEngine().cullBackFaces=!1,n._mirroredCameraPosition=e.Vector3.TransformCoordinates(n.activeCamera.position,s._mirrorMatrix)}),this.onAfterRenderObservable.add(function(){n.setTransformMatrix(s._savedViewMatrix,n.getProjectionMatrix()),n.getEngine().cullBackFaces=!0,n._mirroredCameraPosition=null,delete n.clipPlane})}return __extends(i,t),i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.mirrorPlane=this.mirrorPlane.clone(),t.renderList=this.renderList.slice(0),t},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);return e.mirrorPlane=this.mirrorPlane.asArray(),e},i}(e.RenderTargetTexture);e.MirrorTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o){var s=this;t.call(this,i,r,n,o,!0),this.refractionPlane=new e.Plane(0,1,0,1),this.depth=2,this.onBeforeRenderObservable.add(function(){n.clipPlane=s.refractionPlane}),this.onAfterRenderObservable.add(function(){delete n.clipPlane})}return __extends(i,t),i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e.width,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.refractionPlane=this.refractionPlane.clone(),t.renderList=this.renderList.slice(0),t.depth=this.depth,t},i.prototype.serialize=function(){if(!this.name)return null;var e=t.prototype.serialize.call(this);return e.mirrorPlane=this.refractionPlane.asArray(),e.depth=this.depth,e},i}(e.RenderTargetTexture);e.RefractionTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s){void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,n,!o),this.name=i,this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._generateMipMaps=o,r.getContext?(this._canvas=r,this._texture=n.getEngine().createDynamicTexture(r.width,r.height,o,s)):(this._canvas=document.createElement("canvas"),r.width?this._texture=n.getEngine().createDynamicTexture(r.width,r.height,o,s):this._texture=n.getEngine().createDynamicTexture(r,r,o,s));var a=this.getSize();this._canvas.width=a.width,this._canvas.height=a.height,this._context=this._canvas.getContext("2d")}return __extends(i,t),Object.defineProperty(i.prototype,"canRescale",{get:function(){return!0},enumerable:!0,configurable:!0}),i.prototype.scale=function(e){var t=this.getSize();t.width*=e,t.height*=e,this._canvas.width=t.width,this._canvas.height=t.height,this.releaseInternalTexture(),this._texture=this.getScene().getEngine().createDynamicTexture(t.width,t.height,this._generateMipMaps,this._samplingMode)},i.prototype.getContext=function(){return this._context},i.prototype.clear=function(){var e=this.getSize();this._context.fillRect(0,0,e.width,e.height)},i.prototype.update=function(e){this.getScene().getEngine().updateDynamicTexture(this._texture,this._canvas,void 0===e?!0:e)},i.prototype.drawText=function(e,t,i,r,n,o,s,a){void 0===a&&(a=!0);var h=this.getSize();if(o&&(this._context.fillStyle=o,this._context.fillRect(0,0,h.width,h.height)),this._context.font=r,null===t){var c=this._context.measureText(e);t=(h.width-c.width)/2}this._context.fillStyle=n,this._context.fillText(e,t,i),a&&this.update(s)},i.prototype.clone=function(){var e=this.getSize(),t=new i(this.name,e,this.getScene(),this._generateMipMaps);return t.hasAlpha=this.hasAlpha,t.level=this.level,t.wrapU=this.wrapU,t.wrapV=this.wrapV,t},i}(e.Texture);e.DynamicTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s,a){var h=this;void 0===o&&(o=!1),void 0===s&&(s=!1),void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),t.call(this,null,n,!o,s),this._autoLaunch=!0;var c;this.name=i,r instanceof HTMLVideoElement?this.video=r:(c=r,this.video=document.createElement("video"),this.video.autoplay=!1,this.video.loop=!0),this._generateMipMaps=o,this._samplingMode=a,e.Tools.IsExponentOfTwo(this.video.videoWidth)&&e.Tools.IsExponentOfTwo(this.video.videoHeight)?(this.wrapU=e.Texture.WRAP_ADDRESSMODE,this.wrapV=e.Texture.WRAP_ADDRESSMODE):(this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._generateMipMaps=!1),c?(this.video.addEventListener("canplaythrough",function(){h._createTexture()}),c.forEach(function(e){var t=document.createElement("source");t.src=e,h.video.appendChild(t)})):this._createTexture(),this._lastUpdate=e.Tools.Now}return __extends(i,t),i.prototype._createTexture=function(){this._texture=this.getScene().getEngine().createDynamicTexture(this.video.videoWidth,this.video.videoHeight,this._generateMipMaps,this._samplingMode),this._texture.isReady=!0},i.prototype.update=function(){this._autoLaunch&&(this._autoLaunch=!1,this.video.play());var t=e.Tools.Now;return t-this._lastUpdate<15||this.video.readyState!==this.video.HAVE_ENOUGH_DATA?!1:(this._lastUpdate=t,this.getScene().getEngine().updateVideoTexture(this._texture,this.video,this._invertY),!0)},i}(e.Texture);e.VideoTexture=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i,r,n,o,s){t.call(this,e,r,null,n,o,s),this._animate=!0,this._time=0,this._texturePath=i,this.loadJson(i),this.refreshRate=1}return __extends(i,t),i.prototype.loadJson=function(t){function i(){e.Tools.Log("No config file found in "+t+" trying to use ShadersStore or DOM element");try{n.setFragment(n._texturePath)}catch(i){e.Tools.Error("No json or ShaderStore or DOM element found for CustomProceduralTexture")}}var r=this,n=this,o=t+"/config.json",s=new XMLHttpRequest;s.open("GET",o,!0),s.addEventListener("load",function(){if(200===s.status||e.Tools.ValidateXHRData(s,1))try{r._config=JSON.parse(s.response),r.updateShaderUniforms(),r.updateTextures(),r.setFragment(r._texturePath+"/custom"),r._animate=r._config.animate,r.refreshRate=r._config.refreshrate}catch(t){i()}else i()},!1),s.addEventListener("error",function(){i()},!1);try{s.send()}catch(a){e.Tools.Error("CustomProceduralTexture: Error on XHR send request.")}},i.prototype.isReady=function(){if(!t.prototype.isReady.call(this))return!1;for(var e in this._textures){var i=this._textures[e];if(!i.isReady())return!1}return!0},i.prototype.render=function(e){this._animate&&(this._time+=.03*this.getScene().getAnimationRatio(),this.updateShaderUniforms()),t.prototype.render.call(this,e)},i.prototype.updateTextures=function(){for(var t=0;tthis._maxRank&&(this._maxRank=e),this._defines[e]=new Array),this._defines[e].push(t)},t.prototype.addCPUSkinningFallback=function(e,t){this._meshRank=e,this._mesh=t,e>this._maxRank&&(this._maxRank=e)},Object.defineProperty(t.prototype,"isMoreFallbacks",{get:function(){return this._currentRank<=this._maxRank},enumerable:!0,configurable:!0}),t.prototype.reduce=function(t){for(var i=this._defines[this._currentRank],r=0;r-1?i:e.Engine.ShadersRepository+i,e.Tools.LoadFile(o+".vertex.fx",r)},t.prototype._loadFragmentShader=function(i,r){if(i instanceof HTMLElement){var n=e.Tools.GetDOMTextContent(i);return void r(n)}if(t.ShadersStore[i+"PixelShader"])return void r(t.ShadersStore[i+"PixelShader"]);if(t.ShadersStore[i+"FragmentShader"])return void r(t.ShadersStore[i+"FragmentShader"]);var o;o="."===i[0]||"/"===i[0]||i.indexOf("http")>-1?i:e.Engine.ShadersRepository+i,e.Tools.LoadFile(o+".fragment.fx",r)},t.prototype._dumpShadersName=function(){this.name.vertexElement?(e.Tools.Error("Vertex shader:"+this.name.vertexElement),e.Tools.Error("Fragment shader:"+this.name.fragmentElement)):this.name.vertex?(e.Tools.Error("Vertex shader:"+this.name.vertex),e.Tools.Error("Fragment shader:"+this.name.fragment)):(e.Tools.Error("Vertex shader:"+this.name),e.Tools.Error("Fragment shader:"+this.name))},t.prototype._processIncludes=function(i,r){for(var n=this,o=/#include<(.+)>(\((.*)\))*(\[(.*)\])*/g,s=o.exec(i),a=new String(i);null!=s;){var h=s[1];if(!t.IncludesShadersStore[h]){var c=e.Engine.ShadersRepository+"ShadersInclude/"+h+".fx";return void e.Tools.LoadFile(c,function(e){t.IncludesShadersStore[h]=e,n._processIncludes(a,r)})}var l=t.IncludesShadersStore[h];if(s[2])for(var u=s[3].split(","),f=0;f=x;x++)l+=y.replace(/\{X\}/g,x)+"\n"}else l=l.replace(/\{X\}/g,_)}a=a.replace(s[0],l),s=o.exec(i)}r(a)},t.prototype._processPrecision=function(e){return-1===e.indexOf("precision highp float")?e=this._engine.getCaps().highPrecisionShaderSupported?"precision highp float;\n"+e:"precision mediump float;\n"+e:this._engine.getCaps().highPrecisionShaderSupported||(e=e.replace("precision highp float","precision mediump float")),e},t.prototype._prepareEffect=function(t,i,r,n,o){try{var s=this._engine;t=this._processPrecision(t),i=this._processPrecision(i),this._program=s.createShaderProgram(t,i,n),this._uniforms=s.getUniforms(this._program,this._uniformsNames),this._attributes=s.getAttributes(this._program,r);for(var a=0;ar;r++)this._valueCache[t].m[r]=i.m[r]},t.prototype._cacheFloat2=function(e,t,i){return this._valueCache[e]?(this._valueCache[e][0]=t,void(this._valueCache[e][1]=i)):void(this._valueCache[e]=[t,i])},t.prototype._cacheFloat3=function(e,t,i,r){return this._valueCache[e]?(this._valueCache[e][0]=t,this._valueCache[e][1]=i,void(this._valueCache[e][2]=r)):void(this._valueCache[e]=[t,i,r])},t.prototype._cacheFloat4=function(e,t,i,r,n){return this._valueCache[e]?(this._valueCache[e][0]=t,this._valueCache[e][1]=i,this._valueCache[e][2]=r,void(this._valueCache[e][3]=n)):void(this._valueCache[e]=[t,i,r,n])},t.prototype.setArray=function(e,t){return this._engine.setArray(this.getUniform(e),t),this},t.prototype.setArray2=function(e,t){return this._engine.setArray2(this.getUniform(e),t),this},t.prototype.setArray3=function(e,t){return this._engine.setArray3(this.getUniform(e),t),this},t.prototype.setArray4=function(e,t){return this._engine.setArray4(this.getUniform(e),t),this},t.prototype.setMatrices=function(e,t){return this._engine.setMatrices(this.getUniform(e),t),this},t.prototype.setMatrix=function(e,t){return this._engine.setMatrix(this.getUniform(e),t),this},t.prototype.setMatrix3x3=function(e,t){return this._engine.setMatrix3x3(this.getUniform(e),t),this},t.prototype.setMatrix2x2=function(e,t){return this._engine.setMatrix2x2(this.getUniform(e),t),this},t.prototype.setFloat=function(e,t){return this._valueCache[e]&&this._valueCache[e]===t?this:(this._valueCache[e]=t,this._engine.setFloat(this.getUniform(e),t),this)},t.prototype.setBool=function(e,t){return this._valueCache[e]&&this._valueCache[e]===t?this:(this._valueCache[e]=t,this._engine.setBool(this.getUniform(e),t?1:0),this)},t.prototype.setVector2=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.x&&this._valueCache[e][1]===t.y?this:(this._cacheFloat2(e,t.x,t.y),this._engine.setFloat2(this.getUniform(e),t.x,t.y),this)},t.prototype.setFloat2=function(e,t,i){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===i?this:(this._cacheFloat2(e,t,i),this._engine.setFloat2(this.getUniform(e),t,i),this)},t.prototype.setVector3=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.x&&this._valueCache[e][1]===t.y&&this._valueCache[e][2]===t.z?this:(this._cacheFloat3(e,t.x,t.y,t.z),this._engine.setFloat3(this.getUniform(e),t.x,t.y,t.z),this)},t.prototype.setFloat3=function(e,t,i,r){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===i&&this._valueCache[e][2]===r?this:(this._cacheFloat3(e,t,i,r),this._engine.setFloat3(this.getUniform(e),t,i,r),this)},t.prototype.setVector4=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.x&&this._valueCache[e][1]===t.y&&this._valueCache[e][2]===t.z&&this._valueCache[e][3]===t.w?this:(this._cacheFloat4(e,t.x,t.y,t.z,t.w),this._engine.setFloat4(this.getUniform(e),t.x,t.y,t.z,t.w),this)},t.prototype.setFloat4=function(e,t,i,r,n){return this._valueCache[e]&&this._valueCache[e][0]===t&&this._valueCache[e][1]===i&&this._valueCache[e][2]===r&&this._valueCache[e][3]===n?this:(this._cacheFloat4(e,t,i,r,n),this._engine.setFloat4(this.getUniform(e),t,i,r,n),this)},t.prototype.setColor3=function(e,t){return this._valueCache[e]&&this._valueCache[e][0]===t.r&&this._valueCache[e][1]===t.g&&this._valueCache[e][2]===t.b?this:(this._cacheFloat3(e,t.r,t.g,t.b),this._engine.setColor3(this.getUniform(e),t),this)},t.prototype.setColor4=function(e,t,i){return this._valueCache[e]&&this._valueCache[e][0]===t.r&&this._valueCache[e][1]===t.g&&this._valueCache[e][2]===t.b&&this._valueCache[e][3]===i?this:(this._cacheFloat4(e,t.r,t.g,t.b,i),this._engine.setColor4(this.getUniform(e),t,i),this)},t.ShadersStore={},t.IncludesShadersStore={},t}();e.Effect=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.PrepareDefinesForLights=function(t,i,r,n){void 0===n&&(n=4);for(var o=0,s=!1,a=!1,h=0;h0){for(var l=0;l0){for(var f=0;fn&&i["LIGHT"+n];n++)e.push("vLightData"+n,"vLightDiffuse"+n,"vLightSpecular"+n,"vLightDirection"+n,"vLightGround"+n,"lightMatrix"+n,"shadowsInfo"+n),t.push("shadowSampler"+n)},t.HandleFallbacksForShadows=function(e,t,i){void 0===i&&(i=4);for(var r=0;i>r&&e["LIGHT"+r];r++)r>0&&t.addFallback(r,"LIGHT"+r),e["SHADOW"+r]&&t.addFallback(0,"SHADOW"+r),e["SHADOWPCF"+r]&&t.addFallback(0,"SHADOWPCF"+r),e["SHADOWVSM"+r]&&t.addFallback(0,"SHADOWVSM"+r)},t.PrepareAttributesForBones=function(t,i,r,n){r.NUM_BONE_INFLUENCERS>0&&(n.addCPUSkinningFallback(0,i),t.push(e.VertexBuffer.MatricesIndicesKind),t.push(e.VertexBuffer.MatricesWeightsKind),r.NUM_BONE_INFLUENCERS>4&&(t.push(e.VertexBuffer.MatricesIndicesExtraKind),t.push(e.VertexBuffer.MatricesWeightsExtraKind)))},t.PrepareAttributesForInstances=function(e,t){t.INSTANCES&&(e.push("world0"),e.push("world1"),e.push("world2"),e.push("world3"))},t.BindLightShadow=function(e,t,i,r,n,o){var s=e.getShadowGenerator();return i.receiveShadows&&s&&(e.needCube()?o||(o=!0,n.setFloat2("depthValues",t.activeCamera.minZ,t.activeCamera.maxZ)):n.setMatrix("lightMatrix"+r,s.getTransformMatrix()),n.setTexture("shadowSampler"+r,s.getShadowMapForRendering()),n.setFloat3("shadowsInfo"+r,s.getDarkness(),s.blurScale/s.getShadowMap().getSize().width,s.bias)),o},t.BindLightProperties=function(t,i,r){t instanceof e.PointLight?t.transferToEffect(i,"vLightData"+r):t instanceof e.DirectionalLight?t.transferToEffect(i,"vLightData"+r):t instanceof e.SpotLight?t.transferToEffect(i,"vLightData"+r,"vLightDirection"+r):t instanceof e.HemisphericLight&&t.transferToEffect(i,"vLightData"+r,"vLightGround"+r)},t.BindLights=function(i,r,n,o,s){void 0===s&&(s=4);for(var a=0,h=!1,c=0;c=0&&this._scene.materials.splice(i,1),e&&this._effect&&(this._scene.getEngine()._releaseEffect(this._effect),this._effect=null),i=0;i0&&(this._defines.ROUGHNESS=!0),this.useReflectionOverAlpha&&(this._defines.REFLECTIONOVERALPHA=!0),this.reflectionTexture.coordinatesMode===e.Texture.INVCUBIC_MODE&&(this._defines.INVERTCUBICMAP=!0),this._defines.REFLECTIONMAP_3D=this.reflectionTexture.isCube,this.reflectionTexture.coordinatesMode){case e.Texture.CUBIC_MODE:case e.Texture.INVCUBIC_MODE:this._defines.REFLECTIONMAP_CUBIC=!0;break;case e.Texture.EXPLICIT_MODE:this._defines.REFLECTIONMAP_EXPLICIT=!0;break;case e.Texture.PLANAR_MODE:this._defines.REFLECTIONMAP_PLANAR=!0;break;case e.Texture.PROJECTION_MODE:this._defines.REFLECTIONMAP_PROJECTION=!0;break;case e.Texture.SKYBOX_MODE:this._defines.REFLECTIONMAP_SKYBOX=!0;break;case e.Texture.SPHERICAL_MODE:this._defines.REFLECTIONMAP_SPHERICAL=!0;break;case e.Texture.EQUIRECTANGULAR_MODE:this._defines.REFLECTIONMAP_EQUIRECTANGULAR=!0;break;case e.Texture.FIXED_EQUIRECTANGULAR_MODE:this._defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED=!0}}if(this.emissiveTexture&&r.EmissiveTextureEnabled){if(!this.emissiveTexture.isReady())return!1;h=!0,this._defines.EMISSIVE=!0}if(this.lightmapTexture&&r.LightmapTextureEnabled){if(!this.lightmapTexture.isReady())return!1;h=!0,this._defines.LIGHTMAP=!0,this._defines.USELIGHTMAPASSHADOWMAP=this.useLightmapAsShadowmap}if(this.specularTexture&&r.SpecularTextureEnabled){if(!this.specularTexture.isReady())return!1;h=!0,this._defines.SPECULAR=!0,this._defines.GLOSSINESS=this.useGlossinessFromSpecularMapAlpha}if(o.getEngine().getCaps().standardDerivatives&&this.bumpTexture&&r.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;h=!0,this._defines.BUMP=!0,this.useParallax&&(this._defines.PARALLAX=!0,this.useParallaxOcclusion&&(this._defines.PARALLAXOCCLUSION=!0)),this.invertNormalMapX&&(this._defines.INVERTNORMALMAPX=!0),this.invertNormalMapY&&(this._defines.INVERTNORMALMAPY=!0)}if(this.refractionTexture&&r.RefractionTextureEnabled){if(!this.refractionTexture.isReady())return!1;h=!0,this._defines.REFRACTION=!0,this._defines.REFRACTIONMAP_3D=this.refractionTexture.isCube}}if(o.clipPlane&&(this._defines.CLIPPLANE=!0),s.getAlphaTesting()&&(this._defines.ALPHATEST=!0),this._shouldUseAlphaFromDiffuseTexture()&&(this._defines.ALPHAFROMDIFFUSE=!0),this.useEmissiveAsIllumination&&(this._defines.EMISSIVEASILLUMINATION=!0),this.linkEmissiveWithDiffuse&&(this._defines.LINKEMISSIVEWITHDIFFUSE=!0),this.useLogarithmicDepth&&(this._defines.LOGARITHMICDEPTH=!0),(this.pointsCloud||o.forcePointsCloud)&&(this._defines.POINTSIZE=!0),o.fogEnabled&&i&&i.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0),o.lightsEnabled&&!this.disableLighting&&(a=e.MaterialHelper.PrepareDefinesForLights(o,i,this._defines,this.maxSimultaneousLights)),r.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled||this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled||this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled||this.refractionFresnelParameters&&this.refractionFresnelParameters.isEnabled||this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled)&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._defines.DIFFUSEFRESNEL=!0),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&(this._defines.OPACITYFRESNEL=!0),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._defines.REFLECTIONFRESNEL=!0,this.useReflectionFresnelFromSpecular&&(this._defines.REFLECTIONFRESNELFROMSPECULAR=!0)),this.refractionFresnelParameters&&this.refractionFresnelParameters.isEnabled&&(this._defines.REFRACTIONFRESNEL=!0),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._defines.EMISSIVEFRESNEL=!0),a=!0,this._defines.FRESNEL=!0),this._defines.SPECULARTERM&&this.useSpecularOverAlpha&&(this._defines.SPECULAROVERALPHA=!0),i&&(a&&i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),h&&(i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),i.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(this._defines.UV2=!0)),i.useVertexColors&&i.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,i.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),i.useBones&&i.computeBonesUsingShaders&&(this._defines.NUM_BONE_INFLUENCERS=i.numBoneInfluencers,this._defines.BonesPerMesh=i.skeleton.bones.length+1),n&&(this._defines.INSTANCES=!0)),!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),o.resetCachedMaterial();var c=new e.EffectFallbacks;this._defines.REFLECTION&&c.addFallback(0,"REFLECTION"),this._defines.SPECULAR&&c.addFallback(0,"SPECULAR"),this._defines.BUMP&&c.addFallback(0,"BUMP"),this._defines.PARALLAX&&c.addFallback(1,"PARALLAX"),this._defines.PARALLAXOCCLUSION&&c.addFallback(0,"PARALLAXOCCLUSION"),this._defines.SPECULAROVERALPHA&&c.addFallback(0,"SPECULAROVERALPHA"),this._defines.FOG&&c.addFallback(1,"FOG"),this._defines.POINTSIZE&&c.addFallback(0,"POINTSIZE"),this._defines.LOGARITHMICDEPTH&&c.addFallback(0,"LOGARITHMICDEPTH"),e.MaterialHelper.HandleFallbacksForShadows(this._defines,c,this.maxSimultaneousLights),this._defines.SPECULARTERM&&c.addFallback(0,"SPECULARTERM"),this._defines.DIFFUSEFRESNEL&&c.addFallback(1,"DIFFUSEFRESNEL"),this._defines.OPACITYFRESNEL&&c.addFallback(2,"OPACITYFRESNEL"),this._defines.REFLECTIONFRESNEL&&c.addFallback(3,"REFLECTIONFRESNEL"),this._defines.EMISSIVEFRESNEL&&c.addFallback(4,"EMISSIVEFRESNEL"),this._defines.FRESNEL&&c.addFallback(4,"FRESNEL");var l=[e.VertexBuffer.PositionKind];this._defines.NORMAL&&l.push(e.VertexBuffer.NormalKind),this._defines.UV1&&l.push(e.VertexBuffer.UVKind),this._defines.UV2&&l.push(e.VertexBuffer.UV2Kind),this._defines.VERTEXCOLOR&&l.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(l,i,this._defines,c),e.MaterialHelper.PrepareAttributesForInstances(l,this._defines);var u="default";o.getEngine().getCaps().standardDerivatives||(u="legacydefault");var f=this._defines.toString(),d=["world","view","viewProjection","vEyePosition","vLightsType","vAmbientColor","vDiffuseColor","vSpecularColor","vEmissiveColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","vAmbientInfos","vOpacityInfos","vReflectionInfos","vEmissiveInfos","vSpecularInfos","vBumpInfos","vLightmapInfos","vRefractionInfos","mBones","vClipPlane","diffuseMatrix","ambientMatrix","opacityMatrix","reflectionMatrix","emissiveMatrix","specularMatrix","bumpMatrix","lightmapMatrix","refractionMatrix","depthValues","diffuseLeftColor","diffuseRightColor","opacityParts","reflectionLeftColor","reflectionRightColor","emissiveLeftColor","emissiveRightColor","refractionLeftColor","refractionRightColor","logarithmicDepthConstant"],p=["diffuseSampler","ambientSampler","opacitySampler","reflectionCubeSampler","reflection2DSampler","emissiveSampler","specularSampler","bumpSampler","lightmapSampler","refractionCubeSampler","refraction2DSampler"];e.MaterialHelper.PrepareUniformsAndSamplersList(d,p,this._defines,this.maxSimultaneousLights),this._effect=o.getEngine().createEffect(u,l,d,p,f,c,this.onCompiled,this.onError,{maxSimultaneousLights:this.maxSimultaneousLights-1})}return this._effect.isReady()?(this._renderId=o.getRenderId(),this._wasPreviouslyReady=!0,i&&(i._materialDefines||(i._materialDefines=new t),this._defines.cloneTo(i._materialDefines)),!0):!1},r.prototype.unbind=function(){this.reflectionTexture&&this.reflectionTexture.isRenderTarget&&this._effect.setTexture("reflection2DSampler",null),this.refractionTexture&&this.refractionTexture.isRenderTarget&&this._effect.setTexture("refraction2DSampler",null),i.prototype.unbind.call(this)},r.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},r.prototype.bind=function(t,n){var o=this.getScene();if(this.bindOnlyWorldMatrix(t),e.MaterialHelper.BindBonesParameters(n,this._effect),o.getCachedMaterial()!==this){if(this._effect.setMatrix("viewProjection",o.getTransformMatrix()),r.FresnelEnabled&&(this.diffuseFresnelParameters&&this.diffuseFresnelParameters.isEnabled&&(this._effect.setColor4("diffuseLeftColor",this.diffuseFresnelParameters.leftColor,this.diffuseFresnelParameters.power),this._effect.setColor4("diffuseRightColor",this.diffuseFresnelParameters.rightColor,this.diffuseFresnelParameters.bias)),this.opacityFresnelParameters&&this.opacityFresnelParameters.isEnabled&&this._effect.setColor4("opacityParts",new e.Color3(this.opacityFresnelParameters.leftColor.toLuminance(),this.opacityFresnelParameters.rightColor.toLuminance(),this.opacityFresnelParameters.bias),this.opacityFresnelParameters.power),this.reflectionFresnelParameters&&this.reflectionFresnelParameters.isEnabled&&(this._effect.setColor4("reflectionLeftColor",this.reflectionFresnelParameters.leftColor,this.reflectionFresnelParameters.power),this._effect.setColor4("reflectionRightColor",this.reflectionFresnelParameters.rightColor,this.reflectionFresnelParameters.bias)),this.refractionFresnelParameters&&this.refractionFresnelParameters.isEnabled&&(this._effect.setColor4("refractionLeftColor",this.refractionFresnelParameters.leftColor,this.refractionFresnelParameters.power),this._effect.setColor4("refractionRightColor",this.refractionFresnelParameters.rightColor,this.refractionFresnelParameters.bias)),this.emissiveFresnelParameters&&this.emissiveFresnelParameters.isEnabled&&(this._effect.setColor4("emissiveLeftColor",this.emissiveFresnelParameters.leftColor,this.emissiveFresnelParameters.power),this._effect.setColor4("emissiveRightColor",this.emissiveFresnelParameters.rightColor,this.emissiveFresnelParameters.bias))),o.texturesEnabled&&(this.diffuseTexture&&r.DiffuseTextureEnabled&&(this._effect.setTexture("diffuseSampler",this.diffuseTexture),this._effect.setFloat2("vDiffuseInfos",this.diffuseTexture.coordinatesIndex,this.diffuseTexture.level),this._effect.setMatrix("diffuseMatrix",this.diffuseTexture.getTextureMatrix())),this.ambientTexture&&r.AmbientTextureEnabled&&(this._effect.setTexture("ambientSampler",this.ambientTexture),this._effect.setFloat2("vAmbientInfos",this.ambientTexture.coordinatesIndex,this.ambientTexture.level),this._effect.setMatrix("ambientMatrix",this.ambientTexture.getTextureMatrix())),this.opacityTexture&&r.OpacityTextureEnabled&&(this._effect.setTexture("opacitySampler",this.opacityTexture),this._effect.setFloat2("vOpacityInfos",this.opacityTexture.coordinatesIndex,this.opacityTexture.level),this._effect.setMatrix("opacityMatrix",this.opacityTexture.getTextureMatrix())),this.reflectionTexture&&r.ReflectionTextureEnabled&&(this.reflectionTexture.isCube?this._effect.setTexture("reflectionCubeSampler",this.reflectionTexture):this._effect.setTexture("reflection2DSampler",this.reflectionTexture),this._effect.setMatrix("reflectionMatrix",this.reflectionTexture.getReflectionTextureMatrix()),this._effect.setFloat2("vReflectionInfos",this.reflectionTexture.level,this.roughness)),this.emissiveTexture&&r.EmissiveTextureEnabled&&(this._effect.setTexture("emissiveSampler",this.emissiveTexture),this._effect.setFloat2("vEmissiveInfos",this.emissiveTexture.coordinatesIndex,this.emissiveTexture.level),this._effect.setMatrix("emissiveMatrix",this.emissiveTexture.getTextureMatrix())),this.lightmapTexture&&r.LightmapTextureEnabled&&(this._effect.setTexture("lightmapSampler",this.lightmapTexture),this._effect.setFloat2("vLightmapInfos",this.lightmapTexture.coordinatesIndex,this.lightmapTexture.level),this._effect.setMatrix("lightmapMatrix",this.lightmapTexture.getTextureMatrix())),this.specularTexture&&r.SpecularTextureEnabled&&(this._effect.setTexture("specularSampler",this.specularTexture),this._effect.setFloat2("vSpecularInfos",this.specularTexture.coordinatesIndex,this.specularTexture.level),this._effect.setMatrix("specularMatrix",this.specularTexture.getTextureMatrix())),this.bumpTexture&&o.getEngine().getCaps().standardDerivatives&&r.BumpTextureEnabled&&(this._effect.setTexture("bumpSampler",this.bumpTexture),this._effect.setFloat3("vBumpInfos",this.bumpTexture.coordinatesIndex,1/this.bumpTexture.level,this.parallaxScaleBias),this._effect.setMatrix("bumpMatrix",this.bumpTexture.getTextureMatrix())),this.refractionTexture&&r.RefractionTextureEnabled)){var s=1;this.refractionTexture.isCube?this._effect.setTexture("refractionCubeSampler",this.refractionTexture):(this._effect.setTexture("refraction2DSampler",this.refractionTexture),this._effect.setMatrix("refractionMatrix",this.refractionTexture.getReflectionTextureMatrix()),this.refractionTexture.depth&&(s=this.refractionTexture.depth)),this._effect.setFloat4("vRefractionInfos",this.refractionTexture.level,this.indexOfRefraction,s,this.invertRefractionY?-1:1)}e.MaterialHelper.BindClipPlane(this._effect,o),this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),o.ambientColor.multiplyToRef(this.ambientColor,this._globalAmbientColor),this._effect.setVector3("vEyePosition",o._mirroredCameraPosition?o._mirroredCameraPosition:o.activeCamera.position),this._effect.setColor3("vAmbientColor",this._globalAmbientColor),this._defines.SPECULARTERM&&this._effect.setColor4("vSpecularColor",this.specularColor,this.specularPower),this._effect.setColor3("vEmissiveColor",this.emissiveColor)}o.getCachedMaterial()===this&&this.isFrozen||(this._effect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*n.visibility),o.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(o,n,this._effect,this._defines,this.maxSimultaneousLights),(o.fogEnabled&&n.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE||this.reflectionTexture||this.refractionTexture)&&this._effect.setMatrix("view",o.getViewMatrix()),e.MaterialHelper.BindFogParameters(o,n,this._effect),e.MaterialHelper.BindLogDepth(this._defines,this._effect,o)),i.prototype.bind.call(this,t,n)},r.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&e.push(this.diffuseTexture),this.ambientTexture&&this.ambientTexture.animations&&this.ambientTexture.animations.length>0&&e.push(this.ambientTexture),this.opacityTexture&&this.opacityTexture.animations&&this.opacityTexture.animations.length>0&&e.push(this.opacityTexture),this.reflectionTexture&&this.reflectionTexture.animations&&this.reflectionTexture.animations.length>0&&e.push(this.reflectionTexture),this.emissiveTexture&&this.emissiveTexture.animations&&this.emissiveTexture.animations.length>0&&e.push(this.emissiveTexture),this.specularTexture&&this.specularTexture.animations&&this.specularTexture.animations.length>0&&e.push(this.specularTexture),this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0&&e.push(this.bumpTexture),this.lightmapTexture&&this.lightmapTexture.animations&&this.lightmapTexture.animations.length>0&&e.push(this.lightmapTexture),this.refractionTexture&&this.refractionTexture.animations&&this.refractionTexture.animations.length>0&&e.push(this.refractionTexture),e},r.prototype.dispose=function(e,t){t&&(this.diffuseTexture&&this.diffuseTexture.dispose(),this.ambientTexture&&this.ambientTexture.dispose(),this.opacityTexture&&this.opacityTexture.dispose(),this.reflectionTexture&&this.reflectionTexture.dispose(),this.emissiveTexture&&this.emissiveTexture.dispose(),this.specularTexture&&this.specularTexture.dispose(),this.bumpTexture&&this.bumpTexture.dispose(),this.lightmapTexture&&this.lightmapTexture.dispose(),this.refractionTexture&&this.refractionTexture.dispose()),i.prototype.dispose.call(this,e,t)},r.prototype.clone=function(t){var i=this;return e.SerializationHelper.Clone(function(){return new r(t,i.getScene())},this)},r.prototype.serialize=function(){return e.SerializationHelper.Serialize(this)},r.Parse=function(t,i,n){return e.SerializationHelper.Parse(function(){return new r(t.name,i)},t,i,n)},r.DiffuseTextureEnabled=!0,r.AmbientTextureEnabled=!0,r.OpacityTextureEnabled=!0,r.ReflectionTextureEnabled=!0,r.EmissiveTextureEnabled=!0,r.SpecularTextureEnabled=!0,r.BumpTextureEnabled=!0,r.FresnelEnabled=!0,r.LightmapTextureEnabled=!0,r.RefractionTextureEnabled=!0,__decorate([e.serializeAsTexture()],r.prototype,"diffuseTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"ambientTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"opacityTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"reflectionTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"emissiveTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"specularTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"bumpTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"lightmapTexture",void 0),__decorate([e.serializeAsTexture()],r.prototype,"refractionTexture",void 0),__decorate([e.serializeAsColor3("ambient")],r.prototype,"ambientColor",void 0),__decorate([e.serializeAsColor3("diffuse")],r.prototype,"diffuseColor",void 0),__decorate([e.serializeAsColor3("specular")],r.prototype,"specularColor",void 0),__decorate([e.serializeAsColor3("emissive")],r.prototype,"emissiveColor",void 0),__decorate([e.serialize()],r.prototype,"specularPower",void 0),__decorate([e.serialize()],r.prototype,"useAlphaFromDiffuseTexture",void 0),__decorate([e.serialize()],r.prototype,"useEmissiveAsIllumination",void 0),__decorate([e.serialize()],r.prototype,"linkEmissiveWithDiffuse",void 0),__decorate([e.serialize()],r.prototype,"useReflectionFresnelFromSpecular",void 0),__decorate([e.serialize()],r.prototype,"useSpecularOverAlpha",void 0),__decorate([e.serialize()],r.prototype,"useReflectionOverAlpha",void 0),__decorate([e.serialize()],r.prototype,"disableLighting",void 0),__decorate([e.serialize()],r.prototype,"useParallax",void 0),__decorate([e.serialize()],r.prototype,"useParallaxOcclusion",void 0),__decorate([e.serialize()],r.prototype,"parallaxScaleBias",void 0),__decorate([e.serialize()],r.prototype,"roughness",void 0),__decorate([e.serialize()],r.prototype,"indexOfRefraction",void 0),__decorate([e.serialize()],r.prototype,"invertRefractionY",void 0),__decorate([e.serialize()],r.prototype,"useLightmapAsShadowmap",void 0),__decorate([e.serializeAsFresnelParameters()],r.prototype,"diffuseFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters()],r.prototype,"opacityFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters()],r.prototype,"reflectionFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters()],r.prototype,"refractionFresnelParameters",void 0),__decorate([e.serializeAsFresnelParameters()],r.prototype,"emissiveFresnelParameters",void 0),__decorate([e.serialize()],r.prototype,"useGlossinessFromSpecularMapAlpha",void 0),__decorate([e.serialize()],r.prototype,"maxSimultaneousLights",void 0),__decorate([e.serialize()],r.prototype,"invertNormalMapX",void 0),__decorate([e.serialize()],r.prototype,"invertNormalMapY",void 0),__decorate([e.serialize()],r.prototype,"useLogarithmicDepth",null),r}(e.Material);e.StandardMaterial=i}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(e,i){t.call(this,e,i,!0),this.subMaterials=new Array,i.multiMaterials.push(this)}return __extends(i,t),i.prototype.getSubMaterial=function(e){return 0>e||e>=this.subMaterials.length?this.getScene().defaultMaterial:this.subMaterials[e]},i.prototype.isReady=function(e){for(var t=0;to;o++){var a=i.materials[o];if(a.id===t)return e.Material.Parse(a,r,n)}return null},r=function(e,t,i){t=t instanceof Array?t:[t];for(var r in t)if(e.name===t[r])return i.push(e.id),!0;return e.parentId&&-1!==i.indexOf(e.parentId)?(i.push(e.id),!0):!1},n=function(e,t){return e+" of "+(t?t.file+" from "+t.name+" version: "+t.version+", exporter version: "+t.exporter_version:"unknown")};e.SceneLoader.RegisterPlugin({extensions:".babylon",importMesh:function(t,o,s,a,h,c,l){var u="importMesh has failed JSON parse";try{var f=JSON.parse(s);u="";var d,p,_=e.SceneLoader.loggingLevel===e.SceneLoader.DETAILED_LOGGING,g=[],m=[],v=[];for(d=0,p=f.meshes.length;p>d;d++){var y=f.meshes[d];if(!t||r(y,t,v)){if(t instanceof Array&&delete t[t.indexOf(y.name)],y.geometryId&&f.geometries){var x=!1;["boxes","spheres","cylinders","toruses","grounds","planes","torusKnots","vertexData"].forEach(function(t){!x&&f.geometries[t]&&f.geometries[t]instanceof Array&&f.geometries[t].forEach(function(i){if(i.id===y.geometryId){switch(t){case"boxes":e.Geometry.Primitives.Box.Parse(i,o);break;case"spheres":e.Geometry.Primitives.Sphere.Parse(i,o);break;case"cylinders":e.Geometry.Primitives.Cylinder.Parse(i,o);break;case"toruses":e.Geometry.Primitives.Torus.Parse(i,o);break;case"grounds":e.Geometry.Primitives.Ground.Parse(i,o);break;case"planes":e.Geometry.Primitives.Plane.Parse(i,o);break;case"torusKnots":e.Geometry.Primitives.TorusKnot.Parse(i,o);break;case"vertexData":e.Geometry.Parse(i,o,a)}x=!0}})}),x||e.Tools.Warn("Geometry not found for mesh "+y.id)}if(y.materialId){var b=-1!==m.indexOf(y.materialId);if(!b&&f.multiMaterials)for(var P=0,A=f.multiMaterials.length;A>P;P++){var E=f.multiMaterials[P];if(E.id===y.materialId){for(var T=0,C=E.materials.length;C>T;T++){var S=E.materials[T];m.push(S);var M=i(S,f,o,a);u+="\n Material "+M.toString(_)}m.push(E.id);var I=e.Material.ParseMultiMaterial(E,o);b=!0,u+="\n Multi-Material "+I.toString(_);break}}if(!b){m.push(y.materialId);var M=i(y.materialId,f,o,a);M?u+="\n Material "+M.toString(_):e.Tools.Warn("Material not found for mesh "+y.id)}}if(y.skeletonId>-1&&o.skeletons){var D=g.indexOf(y.skeletonId)>-1;if(!D)for(var R=0,O=f.skeletons.length;O>R;R++){var w=f.skeletons[R];if(w.id===y.skeletonId){var L=e.Skeleton.Parse(w,o);l.push(L),g.push(w.id),u+="\n Skeleton "+L.toString(_)}}}var B=e.Mesh.Parse(y,o,a);h.push(B),u+="\n Mesh "+B.toString(_)}}var V;for(d=0,p=o.meshes.length;p>d;d++)V=o.meshes[d],V._waitingParentId&&(V.parent=o.getLastEntryByID(V._waitingParentId),V._waitingParentId=void 0);for(d=0,p=o.meshes.length;p>d;d++)V=o.meshes[d],V._waitingFreezeWorldMatrix?(V.freezeWorldMatrix(),V._waitingFreezeWorldMatrix=void 0):V.computeWorldMatrix(!0);if(f.particleSystems)for(d=0,p=f.particleSystems.length;p>d;d++){var F=f.particleSystems[d];-1!==v.indexOf(F.emitterId)&&c.push(e.ParticleSystem.Parse(F,o,a))}return!0}catch(N){throw e.Tools.Log(n("importMesh",f.producer)+u),u=null,N}finally{null!==u&&e.SceneLoader.loggingLevel!==e.SceneLoader.NO_LOGGING&&e.Tools.Log(n("importMesh",f.producer)+(e.SceneLoader.loggingLevel!==e.SceneLoader.MINIMAL_LOGGING?u:""))}},load:function(t,i,r){var o="importScene has failed JSON parse";try{var s=JSON.parse(i);o="";var a=e.SceneLoader.loggingLevel===e.SceneLoader.DETAILED_LOGGING;if(t.useDelayedTextureLoading=s.useDelayedTextureLoading&&!e.SceneLoader.ForceFullSceneLoadingForIncremental,t.autoClear=s.autoClear,t.clearColor=e.Color4.FromArray(s.clearColor),t.ambientColor=e.Color3.FromArray(s.ambientColor),s.gravity&&(t.gravity=e.Vector3.FromArray(s.gravity)),s.fogMode&&0!==s.fogMode)switch(t.fogMode=s.fogMode,t.fogColor=e.Color3.FromArray(s.fogColor),t.fogStart=s.fogStart,t.fogEnd=s.fogEnd,t.fogDensity=s.fogDensity,o+=" Fog mode for scene: ",t.fogMode){case 1:o+="exp\n";break;case 2:o+="exp2\n";break;case 3:o+="linear\n"}if(s.physicsEnabled){var h;"cannon"===s.physicsEngine?h=new e.CannonJSPlugin:"oimo"===s.physicsEngine&&(h=new e.OimoJSPlugin),o=" Physics engine "+(s.physicsEngine?s.physicsEngine:"oimo")+" enabled\n";var c=s.physicsGravity?e.Vector3.FromArray(s.physicsGravity):null;t.enablePhysics(c,h)}void 0!=s.collisionsEnabled&&(t.collisionsEnabled=s.collisionsEnabled),t.workerCollisions=!!s.workerCollisions;var l,u;for(l=0,u=s.lights.length;u>l;l++){var f=s.lights[l],d=e.Light.Parse(f,t);o+=0===l?"\n Lights:":"",o+="\n "+d.toString(a)}if(s.animations)for(l=0,u=s.animations.length;u>l;l++){var p=s.animations[l],_=e.Animation.Parse(p);
+t.animations.push(_),o+=0===l?"\n Animations:":"",o+="\n "+_.toString(a)}if(s.autoAnimate&&t.beginAnimation(t,s.autoAnimateFrom,s.autoAnimateTo,s.autoAnimateLoop,s.autoAnimateSpeed||1),s.materials)for(l=0,u=s.materials.length;u>l;l++){var g=s.materials[l],m=e.Material.Parse(g,t,r);o+=0===l?"\n Materials:":"",o+="\n "+m.toString(a)}if(s.multiMaterials)for(l=0,u=s.multiMaterials.length;u>l;l++){var v=s.multiMaterials[l],y=e.Material.ParseMultiMaterial(v,t);o+=0===l?"\n MultiMaterials:":"",o+="\n "+y.toString(a)}if(s.skeletons)for(l=0,u=s.skeletons.length;u>l;l++){var x=s.skeletons[l],b=e.Skeleton.Parse(x,t);o+=0===l?"\n Skeletons:":"",o+="\n "+b.toString(a)}var P=s.geometries;if(P){var A=P.boxes;if(A)for(l=0,u=A.length;u>l;l++){var E=A[l];e.Geometry.Primitives.Box.Parse(E,t)}var T=P.spheres;if(T)for(l=0,u=T.length;u>l;l++){var C=T[l];e.Geometry.Primitives.Sphere.Parse(C,t)}var S=P.cylinders;if(S)for(l=0,u=S.length;u>l;l++){var M=S[l];e.Geometry.Primitives.Cylinder.Parse(M,t)}var I=P.toruses;if(I)for(l=0,u=I.length;u>l;l++){var D=I[l];e.Geometry.Primitives.Torus.Parse(D,t)}var R=P.grounds;if(R)for(l=0,u=R.length;u>l;l++){var O=R[l];e.Geometry.Primitives.Ground.Parse(O,t)}var w=P.planes;if(w)for(l=0,u=w.length;u>l;l++){var L=w[l];e.Geometry.Primitives.Plane.Parse(L,t)}var B=P.torusKnots;if(B)for(l=0,u=B.length;u>l;l++){var V=B[l];e.Geometry.Primitives.TorusKnot.Parse(V,t)}var F=P.vertexData;if(F)for(l=0,u=F.length;u>l;l++){var N=F[l];e.Geometry.Parse(N,t,r)}}for(l=0,u=s.meshes.length;u>l;l++){var z=s.meshes[l],U=e.Mesh.Parse(z,t,r);o+=0===l?"\n Meshes:":"",o+="\n "+U.toString(a)}for(l=0,u=s.cameras.length;u>l;l++){var k=s.cameras[l],G=e.Camera.Parse(k,t);o+=0===l?"\n Cameras:":"",o+="\n "+G.toString(a)}for(s.activeCameraID&&t.setActiveCameraByID(s.activeCameraID),l=0,u=t.cameras.length;u>l;l++){var G=t.cameras[l];G._waitingParentId&&(G.parent=t.getLastEntryByID(G._waitingParentId),G._waitingParentId=void 0)}for(l=0,u=t.lights.length;u>l;l++){var d=t.lights[l];d._waitingParentId&&(d.parent=t.getLastEntryByID(d._waitingParentId),d._waitingParentId=void 0)}var Y,W=[];if(e.AudioEngine&&s.sounds)for(l=0,u=s.sounds.length;u>l;l++){var H=s.sounds[l];if(e.Engine.audioEngine.canUseWebAudio)H.url||(H.url=H.name),W[H.url]?e.Sound.Parse(H,t,r,W[H.url]):(Y=e.Sound.Parse(H,t,r),W[H.url]=Y);else{new e.Sound(H.name,null,t)}}for(W=[],l=0,u=t.meshes.length;u>l;l++){var U=t.meshes[l];U._waitingParentId&&(U.parent=t.getLastEntryByID(U._waitingParentId),U._waitingParentId=void 0),U._waitingActions&&(e.ActionManager.Parse(U._waitingActions,U,t),U._waitingActions=void 0)}for(l=0,u=t.meshes.length;u>l;l++){var j=t.meshes[l];j._waitingFreezeWorldMatrix?(j.freezeWorldMatrix(),j._waitingFreezeWorldMatrix=void 0):j.computeWorldMatrix(!0)}if(s.particleSystems)for(l=0,u=s.particleSystems.length;u>l;l++){var X=s.particleSystems[l];e.ParticleSystem.Parse(X,t,r)}if(s.lensFlareSystems)for(l=0,u=s.lensFlareSystems.length;u>l;l++){var K=s.lensFlareSystems[l];e.LensFlareSystem.Parse(K,t,r)}if(s.shadowGenerators)for(l=0,u=s.shadowGenerators.length;u>l;l++){var Z=s.shadowGenerators[l];e.ShadowGenerator.Parse(Z,t)}return s.actions&&e.ActionManager.Parse(s.actions,null,t),!0}catch(q){throw e.Tools.Log(n("importScene",s.producer)+o),o=null,q}finally{null!==o&&e.SceneLoader.loggingLevel!==e.SceneLoader.NO_LOGGING&&e.Tools.Log(n("importScene",s.producer)+(e.SceneLoader.loggingLevel!==e.SceneLoader.MINIMAL_LOGGING?o:""))}}})}(t=e.Internals||(e.Internals={}))}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r,n,o,s,a){void 0===a&&(a=e.Texture.TRILINEAR_SAMPLINGMODE),this.name=t,this.cellSize=n,this.sprites=new Array,this.renderingGroupId=0,this.layerMask=268435455,this.fogEnabled=!0,this.isPickable=!1,this.onDisposeObservable=new e.Observable,this._vertexBuffers={},this._capacity=r,this._spriteTexture=new e.Texture(i,o,!0,!1,a),this._spriteTexture.wrapU=e.Texture.CLAMP_ADDRESSMODE,this._spriteTexture.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._epsilon=void 0===s?.01:s,this._scene=o,this._scene.spriteManagers.push(this);for(var h=[],c=0,l=0;r>l;l++)h.push(c),h.push(c+1),h.push(c+2),h.push(c),h.push(c+2),h.push(c+3),c+=4;this._indexBuffer=o.getEngine().createIndexBuffer(h),this._vertexData=new Float32Array(16*r*4),this._buffer=new e.Buffer(o.getEngine(),this._vertexData,!0,16);var u=this._buffer.createVertexBuffer(e.VertexBuffer.PositionKind,0,4),f=this._buffer.createVertexBuffer("options",4,4),d=this._buffer.createVertexBuffer("cellInfo",8,4),p=this._buffer.createVertexBuffer(e.VertexBuffer.ColorKind,12,4);this._vertexBuffers[e.VertexBuffer.PositionKind]=u,this._vertexBuffers.options=f,this._vertexBuffers.cellInfo=d,this._vertexBuffers[e.VertexBuffer.ColorKind]=p,this._effectBase=this._scene.getEngine().createEffect("sprites",[e.VertexBuffer.PositionKind,"options","cellInfo",e.VertexBuffer.ColorKind],["view","projection","textureInfos","alphaTest"],["diffuseSampler"],""),this._effectFog=this._scene.getEngine().createEffect("sprites",[e.VertexBuffer.PositionKind,"options","cellInfo",e.VertexBuffer.ColorKind],["view","projection","textureInfos","alphaTest","vFogInfos","vFogColor"],["diffuseSampler"],"#define FOG")}return Object.defineProperty(t.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"texture",{get:function(){return this._spriteTexture},set:function(e){this._spriteTexture=e},enumerable:!0,configurable:!0}),t.prototype._appendSpriteVertex=function(e,t,i,r,n){var o=16*e;0===i?i=this._epsilon:1===i&&(i=1-this._epsilon),0===r?r=this._epsilon:1===r&&(r=1-this._epsilon),this._vertexData[o]=t.position.x,this._vertexData[o+1]=t.position.y,this._vertexData[o+2]=t.position.z,this._vertexData[o+3]=t.angle,this._vertexData[o+4]=t.width,this._vertexData[o+5]=t.height,this._vertexData[o+6]=i,this._vertexData[o+7]=r,this._vertexData[o+8]=t.invertU?1:0,this._vertexData[o+9]=t.invertV?1:0;var s=t.cellIndex/n>>0;this._vertexData[o+10]=t.cellIndex-s*n,this._vertexData[o+11]=s,this._vertexData[o+12]=t.color.r,this._vertexData[o+13]=t.color.g,this._vertexData[o+14]=t.color.b,this._vertexData[o+15]=t.color.a},t.prototype.intersects=function(t,i,r,n){for(var o,s=Math.min(this._capacity,this.sprites.length),a=e.Vector3.Zero(),h=e.Vector3.Zero(),c=Number.MAX_VALUE,l=e.Vector3.Zero(),u=i.getViewMatrix(),f=0;s>f;f++){var d=this.sprites[f];if(d){if(r){if(!r(d))continue}else if(!d.isPickable)continue;if(e.Vector3.TransformCoordinatesToRef(d.position,u,l),a.copyFromFloats(l.x-d.width/2,l.y-d.height/2,l.z),h.copyFromFloats(l.x+d.width/2,l.y+d.height/2,l.z),t.intersectsBoxMinMax(a,h)){var p=e.Vector3.Distance(l,t.origin);if(c>p&&(c=p,o=d,n))break}}}if(o){var _=new e.PickingInfo;return _.hit=!0,_.pickedSprite=o,_.distance=c,_}return null},t.prototype.render=function(){if(this._effectBase.isReady()&&this._effectFog.isReady()&&this._spriteTexture&&this._spriteTexture.isReady()){for(var t=this._scene.getEngine(),i=this._spriteTexture.getBaseSize(),r=t.getDeltaTime(),n=Math.min(this._capacity,this.sprites.length),o=i.width/this.cellSize,s=0,a=0;n>a;a++){var h=this.sprites[a];h&&(h._animate(r),this._appendSpriteVertex(s++,h,0,0,o),this._appendSpriteVertex(s++,h,1,0,o),this._appendSpriteVertex(s++,h,1,1,o),this._appendSpriteVertex(s++,h,0,1,o))}this._buffer.update(this._vertexData);var c=this._effectBase;this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(c=this._effectFog),t.enableEffect(c);var l=this._scene.getViewMatrix();c.setTexture("diffuseSampler",this._spriteTexture),c.setMatrix("view",l),c.setMatrix("projection",this._scene.getProjectionMatrix()),c.setFloat2("textureInfos",this.cellSize/i.width,this.cellSize/i.height),this._scene.fogEnabled&&this._scene.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(c.setFloat4("vFogInfos",this._scene.fogMode,this._scene.fogStart,this._scene.fogEnd,this._scene.fogDensity),c.setColor3("vFogColor",this._scene.fogColor)),t.bindBuffers(this._vertexBuffers,this._indexBuffer,c),t.setDepthFunctionToLessOrEqual(),c.setBool("alphaTest",!0),t.setColorWrite(!1),t.draw(!0,0,6*n),t.setColorWrite(!0),c.setBool("alphaTest",!1),t.setAlphaMode(e.Engine.ALPHA_COMBINE),t.draw(!0,0,6*n),t.setAlphaMode(e.Engine.ALPHA_DISABLE)}},t.prototype.dispose=function(){this._buffer&&(this._buffer.dispose(),this._buffer=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null),this._spriteTexture&&(this._spriteTexture.dispose(),this._spriteTexture=null);var e=this._scene.spriteManagers.indexOf(this);this._scene.spriteManagers.splice(e,1),this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()},t}();e.SpriteManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){this.name=t,this.color=new e.Color4(1,1,1,1),this.width=1,this.height=1,this.angle=0,this.cellIndex=0,this.invertU=0,this.invertV=0,this.animations=new Array,this.isPickable=!1,this._animationStarted=!1,this._loopAnimation=!1,this._fromIndex=0,this._toIndex=0,this._delay=0,this._direction=1,this._frameCount=0,this._time=0,this._manager=i,this._manager.sprites.push(this),this.position=e.Vector3.Zero()}return Object.defineProperty(t.prototype,"size",{get:function(){return this.width},set:function(e){this.width=e,this.height=e},enumerable:!0,configurable:!0}),t.prototype.playAnimation=function(e,t,i,r){this._fromIndex=e,this._toIndex=t,this._loopAnimation=i,this._delay=r,this._animationStarted=!0,this._direction=t>e?1:-1,this.cellIndex=e,this._time=0},t.prototype.stopAnimation=function(){this._animationStarted=!1},t.prototype._animate=function(e){this._animationStarted&&(this._time+=e,this._time>this._delay&&(this._time=this._time%this._delay,this.cellIndex+=this._direction,this.cellIndex==this._toIndex&&(this._loopAnimation?this.cellIndex=this._fromIndex:(this._animationStarted=!1,this.disposeWhenFinishedAnimating&&this.dispose()))))},t.prototype.dispose=function(){for(var e=0;el;l++)h.push(c),h.push(c+1),h.push(c+2),h.push(c),h.push(c+2),h.push(c+3),c+=4;this._indexBuffer=o.getEngine().createIndexBuffer(h),this._vertexData=new Float32Array(11*n*4),this._vertexBuffer=new e.Buffer(o.getEngine(),this._vertexData,!0,11);var u=this._vertexBuffer.createVertexBuffer(e.VertexBuffer.PositionKind,0,3),f=this._vertexBuffer.createVertexBuffer(e.VertexBuffer.ColorKind,3,4),d=this._vertexBuffer.createVertexBuffer("options",7,4);this._vertexBuffers[e.VertexBuffer.PositionKind]=u,this._vertexBuffers[e.VertexBuffer.ColorKind]=f,this._vertexBuffers.options=d,this.startDirectionFunction=function(i,r,n,o){var s=t(a.direction1.x,a.direction2.x),h=t(a.direction1.y,a.direction2.y),c=t(a.direction1.z,a.direction2.z);e.Vector3.TransformNormalFromFloatsToRef(s*i,h*i,c*i,r,n)},this.startPositionFunction=function(i,r,n){var o=t(a.minEmitBox.x,a.maxEmitBox.x),s=t(a.minEmitBox.y,a.maxEmitBox.y),h=t(a.minEmitBox.z,a.maxEmitBox.z);e.Vector3.TransformCoordinatesFromFloatsToRef(o,s,h,i,r)},this.updateFunction=function(e){for(var t=0;t=i.lifeTime?(a.recycleParticle(i),t--):(i.colorStep.scaleToRef(a._scaledUpdateSpeed,a._scaledColorStep),i.color.addInPlace(a._scaledColorStep),i.color.a<0&&(i.color.a=0),i.angle+=i.angularSpeed*a._scaledUpdateSpeed,i.direction.scaleToRef(a._scaledUpdateSpeed,a._scaledDirection),i.position.addInPlace(a._scaledDirection),a.gravity.scaleToRef(a._scaledUpdateSpeed,a._scaledGravity),i.direction.addInPlace(a._scaledGravity))}}}return Object.defineProperty(i.prototype,"onDispose",{set:function(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)},enumerable:!0,configurable:!0}),i.prototype.recycleParticle=function(e){var t=this.particles.pop();t!==e&&(t.copyTo(e),this._stockParticles.push(t))},i.prototype.getCapacity=function(){return this._capacity},i.prototype.isAlive=function(){return this._alive},i.prototype.isStarted=function(){return this._started},i.prototype.start=function(){this._started=!0,this._stopped=!1,this._actualFrame=0},i.prototype.stop=function(){this._stopped=!0},i.prototype._appendParticleVertex=function(e,t,i,r){var n=11*e;this._vertexData[n]=t.position.x,this._vertexData[n+1]=t.position.y,this._vertexData[n+2]=t.position.z,this._vertexData[n+3]=t.color.r,this._vertexData[n+4]=t.color.g,this._vertexData[n+5]=t.color.b,this._vertexData[n+6]=t.color.a,this._vertexData[n+7]=t.angle,this._vertexData[n+8]=t.size,this._vertexData[n+9]=i,this._vertexData[n+10]=r},i.prototype._update=function(i){this._alive=this.particles.length>0,this.updateFunction(this.particles);var r;r=this.emitter.position?this.emitter.getWorldMatrix():e.Matrix.Translation(this.emitter.x,this.emitter.y,this.emitter.z);for(var n,o=0;i>o&&this.particles.length!==this._capacity;o++){0!==this._stockParticles.length?(n=this._stockParticles.pop(),n.age=0):n=new e.Particle,this.particles.push(n);var s=t(this.minEmitPower,this.maxEmitPower);this.startDirectionFunction(s,r,n.direction,n),n.lifeTime=t(this.minLifeTime,this.maxLifeTime),n.size=t(this.minSize,this.maxSize),n.angularSpeed=t(this.minAngularSpeed,this.maxAngularSpeed),this.startPositionFunction(r,n.position,n);var a=t(0,1);e.Color4.LerpToRef(this.color1,this.color2,a,n.color),this.colorDead.subtractToRef(n.color,this._colorDiff),this._colorDiff.scaleToRef(1/n.lifeTime,n.colorStep)}},i.prototype._getEffect=function(){if(this._customEffect)return this._customEffect;var t=[];this._scene.clipPlane&&t.push("#define CLIPPLANE");var i=t.join("\n");return this._cachedDefines!==i&&(this._cachedDefines=i,this._effect=this._scene.getEngine().createEffect("particles",[e.VertexBuffer.PositionKind,e.VertexBuffer.ColorKind,"options"],["invView","view","projection","vClipPlane","textureMask"],["diffuseSampler"],i)),this._effect},i.prototype.animate=function(){if(this._started){var e=this._getEffect();if(this.emitter&&e.isReady()&&this.particleTexture&&this.particleTexture.isReady()&&this._currentRenderId!==this._scene.getRenderId()){this._currentRenderId=this._scene.getRenderId(),this._scaledUpdateSpeed=this.updateSpeed*this._scene.getAnimationRatio();var t;this.manualEmitCount>-1?(t=this.manualEmitCount,this._newPartsExcess=0,this.manualEmitCount=0):(t=this.emitRate*this._scaledUpdateSpeed>>0,this._newPartsExcess+=this.emitRate*this._scaledUpdateSpeed-t),this._newPartsExcess>1&&(t+=this._newPartsExcess>>0,this._newPartsExcess-=this._newPartsExcess>>0),this._alive=!1,this._stopped?t=0:(this._actualFrame+=this._scaledUpdateSpeed,this.targetStopDuration&&this._actualFrame>=this.targetStopDuration&&this.stop()),this._update(t),this._stopped&&(this._alive||(this._started=!1,this.disposeOnStop&&this._scene._toBeDisposed.push(this)));for(var i=0,r=0;r1)throw"step size should be less than 1.";return this.value+=e,this.ensureLimits(),this.raiseOnChange(),this},t.prototype.ensureLimits=function(){for(;this.value>1;)this.value-=1;for(;this.value<0;)this.value+=1;return this},t.prototype.markAsDirty=function(e){return this.ensureLimits(),this.raiseOnChange(),this},t.prototype.raiseOnChange=function(){var e=this;return this._onchange.forEach(function(t){return t(e)}),this},t.prototype.onchange=function(e){return this._onchange.push(e),this},t}();e.PathCursor=r;var n=function(){function i(e,t,r,n,o,s){this.name=e,this.targetProperty=t,this.framePerSecond=r,this.dataType=n,this.loopMode=o,this.enableBlending=s,this._offsetsCache={},this._highLimitsCache={},this._stopped=!1,this._blendingFactor=0,this._events=new Array,this.allowMatricesInterpolation=!1,this.blendingSpeed=.01,this._ranges={},this.targetPropertyPath=t.split("."),this.dataType=n,this.loopMode=void 0===o?i.ANIMATIONLOOPMODE_CYCLE:o}return i._PrepareAnimation=function(t,r,n,o,s,a,h,c){var l=void 0;if(!isNaN(parseFloat(s))&&isFinite(s)?l=i.ANIMATIONTYPE_FLOAT:s instanceof e.Quaternion?l=i.ANIMATIONTYPE_QUATERNION:s instanceof e.Vector3?l=i.ANIMATIONTYPE_VECTOR3:s instanceof e.Vector2?l=i.ANIMATIONTYPE_VECTOR2:s instanceof e.Color3?l=i.ANIMATIONTYPE_COLOR3:s instanceof e.Size&&(l=i.ANIMATIONTYPE_SIZE),void 0==l)return null;var u=new i(t,r,n,l,h),f=[];return f.push({frame:0,value:s}),f.push({frame:o,value:a}),u.setKeys(f),void 0!==c&&u.setEasingFunction(c),u},i.CreateAndStartAnimation=function(e,t,r,n,o,s,a,h,c,l){var u=i._PrepareAnimation(e,r,n,o,s,a,h,c);return t.getScene().beginDirectAnimation(t,[u],0,o,1===u.loopMode,1,l)},i.CreateMergeAndStartAnimation=function(e,t,r,n,o,s,a,h,c,l){var u=i._PrepareAnimation(e,r,n,o,s,a,h,c);return t.animations.push(u),t.getScene().beginAnimation(t,0,o,1===u.loopMode,1,l)},i.prototype.toString=function(e){var t="Name: "+this.name+", property: "+this.targetProperty;if(t+=", datatype: "+["Float","Vector3","Quaternion","Matrix","Color3","Vector2"][this.dataType],t+=", nKeys: "+(this._keys?this._keys.length:"none"),t+=", nRanges: "+(this._ranges?Object.keys(this._ranges).length:"none"),e){t+=", Ranges: {";var i=!0;for(var r in this._ranges)i&&(t+=", ",i=!1),t+=r;t+="}"}return t},i.prototype.addEvent=function(e){this._events.push(e)},i.prototype.removeEvents=function(e){for(var t=0;t=0;n--)this._keys[n].frame>=i&&this._keys[n].frame<=r&&this._keys.splice(n,1);this._ranges[e]=void 0}},i.prototype.getRange=function(e){return this._ranges[e]},i.prototype.reset=function(){this._offsetsCache={},this._highLimitsCache={},this.currentFrame=0,this._blendingFactor=0,this._originalBlendValue=null},i.prototype.isStopped=function(){return this._stopped},i.prototype.getKeys=function(){return this._keys},i.prototype.getHighestFrame=function(){for(var e=0,t=0,i=this._keys.length;i>t;t++)e0)return o.clone?o.clone():o;this.currentFrame=e;var s=Math.max(0,Math.min(this._keys.length-1,Math.floor(this._keys.length*(e-this._keys[0].frame)/(this._keys[this._keys.length-1].frame-this._keys[0].frame))-1));if(this._keys[s].frame>=e)for(;s-1>=0&&this._keys[s].frame>=e;)s--;for(var a=s;a=e){var h=this._getKeyValue(this._keys[a].value),c=this._getKeyValue(this._keys[a+1].value),l=(e-this._keys[a].frame)/(this._keys[a+1].frame-this._keys[a].frame);switch(null!=this._easingFunction&&(l=this._easingFunction.ease(l)),this.dataType){case i.ANIMATIONTYPE_FLOAT:switch(r){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:return this.floatInterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return n*t+this.floatInterpolateFunction(h,c,l)}break;case i.ANIMATIONTYPE_QUATERNION:var u=null;switch(r){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:u=this.quaternionInterpolateFunction(h,c,l);break;case i.ANIMATIONLOOPMODE_RELATIVE:u=this.quaternionInterpolateFunction(h,c,l).add(n.scale(t))}return u;case i.ANIMATIONTYPE_VECTOR3:switch(r){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:return this.vector3InterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return this.vector3InterpolateFunction(h,c,l).add(n.scale(t))}case i.ANIMATIONTYPE_VECTOR2:switch(r){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:return this.vector2InterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return this.vector2InterpolateFunction(h,c,l).add(n.scale(t))}case i.ANIMATIONTYPE_SIZE:switch(r){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:return this.sizeInterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return this.sizeInterpolateFunction(h,c,l).add(n.scale(t))}case i.ANIMATIONTYPE_COLOR3:switch(r){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:return this.color3InterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return this.color3InterpolateFunction(h,c,l).add(n.scale(t))}case i.ANIMATIONTYPE_MATRIX:switch(r){case i.ANIMATIONLOOPMODE_CYCLE:case i.ANIMATIONLOOPMODE_CONSTANT:
+if(this.allowMatricesInterpolation)return this.matrixInterpolateFunction(h,c,l);case i.ANIMATIONLOOPMODE_RELATIVE:return h}}break}return this._getKeyValue(this._keys[this._keys.length-1].value)},i.prototype.setValue=function(t,i){void 0===i&&(i=!1);var r,n;if(this.targetPropertyPath.length>1){for(var o=this._target[this.targetPropertyPath[0]],s=1;sthis._keys[this._keys.length-1].frame&&(e=this._keys[this._keys.length-1].frame);var t=this._interpolate(e,0,this.loopMode);this.setValue(t)},i.prototype.animate=function(t,r,n,o,s,a){if(void 0===a&&(a=!1),!this.targetPropertyPath||this.targetPropertyPath.length<1)return this._stopped=!0,!1;var h=!0;if(0!==this._keys[0].frame){var c={frame:0,value:this._keys[0].value};this._keys.splice(0,0,c)}(rthis._keys[this._keys.length-1].frame)&&(r=this._keys[0].frame),(nthis._keys[this._keys.length-1].frame)&&(n=this._keys[this._keys.length-1].frame);var l,u=n-r,f=t*(this.framePerSecond*s)/1e3,d=0;if(f>u&&!o)h=!1,d=this._getKeyValue(this._keys[this._keys.length-1].value);else if(this.loopMode!==i.ANIMATIONLOOPMODE_CYCLE){var p=n.toString()+r.toString();if(!this._offsetsCache[p]){var _=this._interpolate(r,0,i.ANIMATIONLOOPMODE_CYCLE),g=this._interpolate(n,0,i.ANIMATIONLOOPMODE_CYCLE);switch(this.dataType){case i.ANIMATIONTYPE_FLOAT:this._offsetsCache[p]=g-_;break;case i.ANIMATIONTYPE_QUATERNION:this._offsetsCache[p]=g.subtract(_);break;case i.ANIMATIONTYPE_VECTOR3:this._offsetsCache[p]=g.subtract(_);case i.ANIMATIONTYPE_VECTOR2:this._offsetsCache[p]=g.subtract(_);case i.ANIMATIONTYPE_SIZE:this._offsetsCache[p]=g.subtract(_);case i.ANIMATIONTYPE_COLOR3:this._offsetsCache[p]=g.subtract(_)}this._highLimitsCache[p]=g}d=this._highLimitsCache[p],l=this._offsetsCache[p]}if(void 0===l)switch(this.dataType){case i.ANIMATIONTYPE_FLOAT:l=0;break;case i.ANIMATIONTYPE_QUATERNION:l=new e.Quaternion(0,0,0,0);break;case i.ANIMATIONTYPE_VECTOR3:l=e.Vector3.Zero();break;case i.ANIMATIONTYPE_VECTOR2:l=e.Vector2.Zero();break;case i.ANIMATIONTYPE_SIZE:l=e.Size.Zero();break;case i.ANIMATIONTYPE_COLOR3:l=e.Color3.Black()}var m=f/u>>0,v=h?r+f%u:n,y=this._interpolate(v,m,this.loopMode,l,d);this.setValue(y);for(var x=0;x=this._events[x].frame){var b=this._events[x];b.isDone||(b.onlyOnce&&(this._events.splice(x,1),x--),b.isDone=!0,b.action())}else this._events[x].isDone&&!this._events[x].onlyOnce&&(this._events[x].isDone=!1);return h||(this._stopped=!0),h},i.prototype.serialize=function(){var e={};e.name=this.name,e.property=this.targetProperty,e.framePerSecond=this.framePerSecond,e.dataType=this.dataType,e.loopBehavior=this.loopMode;var t=this.dataType;e.keys=[];for(var r=this.getKeys(),n=0;n-1){this._scene._activeAnimatables.splice(e,1);for(var t=this._animations,e=0;e=.5?.5*(1-this.easeInCore(2*(1-t)))+.5:.5*this.easeInCore(2*t)},e._EASINGMODE_EASEIN=0,e._EASINGMODE_EASEOUT=1,e._EASINGMODE_EASEINOUT=2,e}();e.EasingFunction=t;var i=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e=Math.max(0,Math.min(1,e)),1-Math.sqrt(1-e*e)},t}(t);e.CircleEase=i;var r=function(e){function t(t){void 0===t&&(t=1),e.call(this),this.amplitude=t}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.amplitude);return Math.pow(e,3)-e*t*Math.sin(3.141592653589793*e)},t}(t);e.BackEase=r;var n=function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=2),e.call(this),this.bounces=t,this.bounciness=i}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.bounces),i=this.bounciness;1>=i&&(i=1.001);var r=Math.pow(i,t),n=1-i,o=(1-r)/n+.5*r,s=e*o,a=Math.log(-s*(1-i)+1)/Math.log(i),h=Math.floor(a),c=h+1,l=(1-Math.pow(i,h))/(n*o),u=(1-Math.pow(i,c))/(n*o),f=.5*(l+u),d=e-f,p=f-l;return-Math.pow(1/i,t-h)/(p*p)*(d-p)*(d+p)},t}(t);e.BounceEase=n;var o=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e},t}(t);e.CubicEase=o;var s=function(e){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=3),e.call(this),this.oscillations=t,this.springiness=i}return __extends(t,e),t.prototype.easeInCore=function(e){var t,i=Math.max(0,this.oscillations),r=Math.max(0,this.springiness);return t=0==r?e:(Math.exp(r*e)-1)/(Math.exp(r)-1),t*Math.sin((6.283185307179586*i+1.5707963267948966)*e)},t}(t);e.ElasticEase=s;var a=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.exponent=t}return __extends(t,e),t.prototype.easeInCore=function(e){return this.exponent<=0?e:(Math.exp(this.exponent*e)-1)/(Math.exp(this.exponent)-1)},t}(t);e.ExponentialEase=a;var h=function(e){function t(t){void 0===t&&(t=2),e.call(this),this.power=t}return __extends(t,e),t.prototype.easeInCore=function(e){var t=Math.max(0,this.power);return Math.pow(e,t)},t}(t);e.PowerEase=h;var c=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e},t}(t);e.QuadraticEase=c;var l=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e},t}(t);e.QuarticEase=l;var u=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return e*e*e*e*e},t}(t);e.QuinticEase=u;var f=function(e){function t(){e.apply(this,arguments)}return __extends(t,e),t.prototype.easeInCore=function(e){return 1-Math.sin(1.5707963267948966*(1-e))},t}(t);e.SineEase=f;var d=function(t){function i(e,i,r,n){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1),void 0===n&&(n=1),t.call(this),this.x1=e,this.y1=i,this.x2=r,this.y2=n}return __extends(i,t),i.prototype.easeInCore=function(t){return e.BezierCurve.interpolate(t,this.x1,this.y1,this.x2,this.y2)},i}(t);e.BezierCurveEase=d}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(t){function i(i,r,n,o,s){t.call(this,i,r.getScene()),this.name=i,this.children=new Array,this.animations=new Array,this._worldTransform=new e.Matrix,this._absoluteTransform=new e.Matrix,this._invertedAbsoluteTransform=new e.Matrix,this._skeleton=r,this._matrix=o,this._baseMatrix=o,this._restPose=s?s:o.clone(),r.bones.push(this),n?(this._parent=n,n.children.push(this)):this._parent=null,this._updateDifferenceMatrix()}return __extends(i,t),i.prototype.getParent=function(){return this._parent},i.prototype.getLocalMatrix=function(){return this._matrix},i.prototype.getBaseMatrix=function(){return this._baseMatrix},i.prototype.getRestPose=function(){return this._restPose},i.prototype.returnToRest=function(){this.updateMatrix(this._restPose.clone())},i.prototype.getWorldMatrix=function(){return this._worldTransform},i.prototype.getInvertedAbsoluteTransform=function(){return this._invertedAbsoluteTransform},i.prototype.getAbsoluteTransform=function(){return this._absoluteTransform},i.prototype.updateMatrix=function(e){this._baseMatrix=e.clone(),this._matrix=e.clone(),this._skeleton._markAsDirty(),this._updateDifferenceMatrix()},i.prototype._updateDifferenceMatrix=function(e){e||(e=this._baseMatrix),this._parent?e.multiplyToRef(this._parent._absoluteTransform,this._absoluteTransform):this._absoluteTransform.copyFrom(e),this._absoluteTransform.invertToRef(this._invertedAbsoluteTransform);for(var t=0;tx;x++)a=f[x],a.frame>=l&&a.frame<=u&&(n?(c=a.value.clone(),g?(h=c.getTranslation(),c.setTranslation(h.scaleInPlace(m))):v?(h=c.getTranslation(),c.setTranslation(h.multiplyInPlace(o))):c=a.value):c=a.value,y.push({frame:a.frame+r,value:c}));return this.animations[0].createRange(i,l+r,u+r),!0},i}(e.Node);e.Bone=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r){this.name=t,this.id=i,this.bones=new Array,this.needInitialSkinMatrix=!1,this._isDirty=!0,this._meshesWithPoseMatrix=new Array,this._identity=e.Matrix.Identity(),this._ranges={},this.bones=[],this._scene=r,r.skeletons.push(this),this._isDirty=!0}return t.prototype.getTransformMatrices=function(e){return this.needInitialSkinMatrix&&e._bonesTransformMatrices?e._bonesTransformMatrices:this._transformMatrices},t.prototype.getScene=function(){return this._scene},t.prototype.toString=function(e){var t="Name: "+this.name+", nBones: "+this.bones.length;if(t+=", nAnimationRanges: "+(this._ranges?Object.keys(this._ranges).length:"none"),e){t+=", Ranges: {";var i=!0;for(var r in this._ranges)i&&(t+=", ",i=!1),t+=r;t+="}"}return t},t.prototype.getBoneIndexByName=function(e){for(var t=0,i=this.bones.length;i>t;t++)if(this.bones[t].name===e)return t;return-1},t.prototype.createAnimationRange=function(t,i,r){if(!this._ranges[t]){this._ranges[t]=new e.AnimationRange(t,i,r);for(var n=0,o=this.bones.length;o>n;n++)this.bones[n].animations[0]&&this.bones[n].animations[0].createRange(t,i,r)}},t.prototype.deleteAnimationRange=function(e,t){void 0===t&&(t=!0);for(var i=0,r=this.bones.length;r>i;i++)this.bones[i].animations[0]&&this.bones[i].animations[0].deleteRange(e,t);this._ranges[e]=void 0},t.prototype.getAnimationRange=function(e){return this._ranges[e]},t.prototype.getAnimationRanges=function(){var e,t=[],i=0;for(e in this._ranges)t[i]=this._ranges[e],i++;return t},t.prototype.copyAnimationRange=function(t,i,r){if(void 0===r&&(r=!1),this._ranges[i]||!t.getAnimationRange(i))return!1;var n,o,s=!0,a=this._getHighestAnimationFrame()+1,h={},c=t.bones;for(o=0,n=c.length;n>o;o++)h[c[o].name]=c[o];this.bones.length!==c.length&&(e.Tools.Warn("copyAnimationRange: this rig has "+this.bones.length+" bones, while source as "+c.length),s=!1);var l=r&&this.dimensionsAtRest&&t.dimensionsAtRest?this.dimensionsAtRest.divide(t.dimensionsAtRest):null;for(o=0,n=this.bones.length;n>o;o++){var u=this.bones[o].name,f=h[u];f?s=s&&this.bones[o].copyAnimationRange(f,i,a,r,l):(e.Tools.Warn("copyAnimationRange: not same rig, missing source bone "+u),s=!1)}var d=t.getAnimationRange(i);return this._ranges[i]=new e.AnimationRange(i,d.from+a,d.to+a),s},t.prototype.returnToRest=function(){for(var e=0;et;t++)if(this.bones[t].animations[0]){var r=this.bones[t].animations[0].getHighestFrame();r>e&&(e=r)}return e},t.prototype.beginAnimation=function(e,t,i,r){var n=this.getAnimationRange(e);return n?this._scene.beginAnimation(this,n.from,n.to,t,i,r):null},t.prototype._markAsDirty=function(){this._isDirty=!0},t.prototype._registerMeshWithPoseMatrix=function(e){this._meshesWithPoseMatrix.push(e)},t.prototype._unregisterMeshWithPoseMatrix=function(e){var t=this._meshesWithPoseMatrix.indexOf(e);t>-1&&this._meshesWithPoseMatrix.splice(t,1)},t.prototype._computeTransformMatrices=function(e,t){for(var i=0;i0&&(r.animation=i.animations[0].serialize()),e.ranges=[];for(var n in this._ranges){var o={};o.name=n,o.from=this._ranges[n].from,o.to=this._ranges[n].to,e.ranges.push(o)}}return e},t.Parse=function(i,r){var n=new t(i.name,i.id,r);i.dimensionsAtRest&&(n.dimensionsAtRest=e.Vector3.FromArray(i.dimensionsAtRest)),n.needInitialSkinMatrix=i.needInitialSkinMatrix;var o;for(o=0;o-1&&(a=n.bones[s.parentBoneIndex]);var h=s.rest?e.Matrix.FromArray(s.rest):null,c=new e.Bone(s.name,n,a,e.Matrix.FromArray(s.matrix),h);s.length&&(c.length=s.length),s.animation&&c.animations.push(e.Animation.Parse(s.animation))}if(i.ranges)for(o=0;o0){for(var c=0;c0){for(var t=0;t0&&this._camera._postProcesses[0].markTextureDirty(),this.onActivateObservable.clear(),this.onAfterRenderObservable.clear(),this.onApplyObservable.clear(),this.onBeforeRenderObservable.clear(),this.onSizeChangedObservable.clear()}},t}();e.PostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e){this._vertexBuffers={},this._scene=e}return t.prototype._prepareBuffers=function(){if(!this._vertexBuffers[e.VertexBuffer.PositionKind]){var t=[];t.push(1,1),t.push(-1,1),t.push(-1,-1),t.push(1,-1),this._vertexBuffers[e.VertexBuffer.PositionKind]=new e.VertexBuffer(this._scene.getEngine(),t,e.VertexBuffer.PositionKind,!1,!1,2);var i=[];i.push(0),i.push(1),i.push(2),i.push(0),i.push(2),i.push(3),this._indexBuffer=this._scene.getEngine().createIndexBuffer(i)}},t.prototype._prepareFrame=function(e){var t=this._scene.activeCamera._postProcesses;return 0!==t.length&&this._scene.postProcessesEnabled?(t[0].activate(this._scene.activeCamera,e),!0):!1},t.prototype.directRender=function(e,t){for(var i=this._scene.getEngine(),r=0;ro&&(s-1>o?r[o+1].activate(this._scene.activeCamera,t):t?n.bindFramebuffer(t,i):n.restoreDefaultFramebuffer(),!e);o++){var a=r[o],h=a.apply();h&&(a.onBeforeRenderObservable.notifyObservers(h),this._prepareBuffers(),n.bindBuffers(this._vertexBuffers,this._indexBuffer,h),n.draw(!0,0,6),a.onAfterRenderObservable.notifyObservers(h))}n.setDepthBuffer(!0),n.setDepthWrite(!0)}},t.prototype.dispose=function(){var t=this._vertexBuffers[e.VertexBuffer.PositionKind];t&&(t.dispose(),this._vertexBuffers[e.VertexBuffer.PositionKind]=null),this._indexBuffer&&(this._scene.getEngine()._releaseBuffer(this._indexBuffer),this._indexBuffer=null)},t}();e.PostProcessManager=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(e){function t(t,i,r,n,o,s){e.call(this,t,"pass",null,null,i,r,n,o,s)}return __extends(t,e),t}(e.PostProcess);e.PassPostProcess=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(e,t){this.type=e,this.jointData=t,t.nativeParams=t.nativeParams||{}}return Object.defineProperty(e.prototype,"physicsJoint",{get:function(){return this._physicsJoint},set:function(e){this._physicsJoint,this._physicsJoint=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"physicsPlugin",{set:function(e){this._physicsPlugin=e},enumerable:!0,configurable:!0}),e.prototype.executeNativeFunction=function(e){e(this._physicsPlugin.world,this._physicsJoint)},e.DistanceJoint=0,e.HingeJoint=1,e.BallAndSocketJoint=2,e.WheelJoint=3,e.SliderJoint=4,e.PrismaticJoint=5,e.UniversalJoint=6,e.Hinge2Joint=e.WheelJoint,e.PointToPointJoint=8,e.SpringJoint=9,e.LockJoint=10,e}();e.PhysicsJoint=t;var i=function(e){function i(i){e.call(this,t.DistanceJoint,i)}return __extends(i,e),i.prototype.updateDistance=function(e,t){this._physicsPlugin.updateDistanceJoint(this,e,t)},i}(t);e.DistanceJoint=i;var r=function(e){function t(t,i){e.call(this,t,i)}return __extends(t,e),t.prototype.setMotor=function(e,t){this._physicsPlugin.setMotor(this,e,t)},t.prototype.setLimit=function(e,t){this._physicsPlugin.setLimit(this,e,t)},t}(t);e.MotorEnabledJoint=r;var n=function(e){function i(i){e.call(this,t.HingeJoint,i)}return __extends(i,e),i.prototype.setMotor=function(e,t){this._physicsPlugin.setMotor(this,e,t)},i.prototype.setLimit=function(e,t){this._physicsPlugin.setLimit(this,e,t)},i}(r);e.HingeJoint=n;var o=function(e){function i(i){e.call(this,t.Hinge2Joint,i)}return __extends(i,e),i.prototype.setMotor=function(e,t,i){void 0===i&&(i=0),this._physicsPlugin.setMotor(this,e,t,i)},i.prototype.setLimit=function(e,t,i){void 0===i&&(i=0),this._physicsPlugin.setLimit(this,e,t,i)},i}(r);e.Hinge2Joint=o}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i,r,n){var o=this;return void 0===r&&(r={mass:0}),this.object=t,this.type=i,this._options=r,this._scene=n,this._bodyUpdateRequired=!1,this._onBeforePhysicsStepCallbacks=new Array,this._onAfterPhysicsStepCallbacks=new Array,this._onPhysicsCollideCallbacks=[],this._deltaPosition=e.Vector3.Zero(),this._tmpPositionWithDelta=e.Vector3.Zero(),this._tmpRotationWithDelta=new e.Quaternion,this.beforeStep=function(){o.object.position.subtractToRef(o._deltaPosition,o._tmpPositionWithDelta),o._deltaRotationConjugated?o.object.rotationQuaternion.multiplyToRef(o._deltaRotationConjugated,o._tmpRotationWithDelta):o._tmpRotationWithDelta.copyFrom(o.object.rotationQuaternion),o._physicsEngine.getPhysicsPlugin().setPhysicsBodyTransformation(o,o._tmpPositionWithDelta,o._tmpRotationWithDelta),
+o._onBeforePhysicsStepCallbacks.forEach(function(e){e(o)})},this.afterStep=function(){o._onAfterPhysicsStepCallbacks.forEach(function(e){e(o)}),o._physicsEngine.getPhysicsPlugin().setTransformationFromPhysicsBody(o),o.object.position.addInPlace(o._deltaPosition),o._deltaRotation&&o.object.rotationQuaternion.multiplyInPlace(o._deltaRotation)},this.onCollide=function(e){if(o._onPhysicsCollideCallbacks.length){var t=o._physicsEngine.getImpostorWithPhysicsBody(e.body);t&&o._onPhysicsCollideCallbacks.filter(function(e){return-1!==e.otherImpostors.indexOf(t)}).forEach(function(e){e.callback(o,t)})}},this.object?(!this._scene&&t.getScene&&(this._scene=t.getScene()),this._physicsEngine=this._scene.getPhysicsEngine(),void(this._physicsEngine?(this.object.rotationQuaternion||(this.object.rotation?this.object.rotationQuaternion=e.Quaternion.RotationYawPitchRoll(this.object.rotation.y,this.object.rotation.x,this.object.rotation.z):this.object.rotationQuaternion=new e.Quaternion),this._options.mass=void 0===r.mass?0:r.mass,this._options.friction=void 0===r.friction?.2:r.friction,this._options.restitution=void 0===r.restitution?.2:r.restitution,this._joints=[],this.object.parent||this._init()):e.Tools.Error("Physics not enabled. Please use scene.enablePhysics(...) before creating impostors."))):void e.Tools.Error("No object was provided. A physics object is obligatory")}return t.prototype._init=function(){this._physicsEngine.removeImpostor(this),this.physicsBody=null,this._parent=this._parent||this._getPhysicsParent(),this.parent||this._physicsEngine.addImpostor(this)},t.prototype._getPhysicsParent=function(){if(this.object.parent instanceof e.AbstractMesh){var t=this.object.parent;return t.physicsImpostor}},t.prototype.isBodyInitRequired=function(){return this._bodyUpdateRequired||!this._physicsBody&&!this._parent},t.prototype.setScalingUpdated=function(e){this.forceUpdate()},t.prototype.forceUpdate=function(){this._init(),this.parent&&this.parent.forceUpdate()},Object.defineProperty(t.prototype,"physicsBody",{get:function(){return this._parent?this._parent.physicsBody:this._physicsBody},set:function(e){this._physicsBody&&this._physicsEngine.getPhysicsPlugin().removePhysicsBody(this),this._physicsBody=e,this.resetUpdateFlags()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),t.prototype.resetUpdateFlags=function(){this._bodyUpdateRequired=!1},t.prototype.getObjectExtendSize=function(){return this.object.getBoundingInfo?(this.object.computeWorldMatrix&&this.object.computeWorldMatrix(!0),this.object.getBoundingInfo().boundingBox.extendSize.scale(2).multiply(this.object.scaling)):t.DEFAULT_OBJECT_SIZE},t.prototype.getObjectCenter=function(){return this.object.getBoundingInfo?this.object.getBoundingInfo().boundingBox.center:this.object.position},t.prototype.getParam=function(e){return this._options[e]},t.prototype.setParam=function(e,t){this._options[e]=t,this._bodyUpdateRequired=!0},t.prototype.setMass=function(e){this.getParam("mass")!==e&&this.setParam("mass",e),this._physicsEngine.getPhysicsPlugin().setBodyMass(this,e)},t.prototype.getLinearVelocity=function(){return this._physicsEngine.getPhysicsPlugin().getLinearVelocity(this)},t.prototype.setLinearVelocity=function(e){this._physicsEngine.getPhysicsPlugin().setLinearVelocity(this,e)},t.prototype.getAngularVelocity=function(){return this._physicsEngine.getPhysicsPlugin().getAngularVelocity(this)},t.prototype.setAngularVelocity=function(e){this._physicsEngine.getPhysicsPlugin().setAngularVelocity(this,e)},t.prototype.executeNativeFunction=function(e){e(this._physicsEngine.getPhysicsPlugin().world,this.physicsBody)},t.prototype.registerBeforePhysicsStep=function(e){this._onBeforePhysicsStepCallbacks.push(e)},t.prototype.unregisterBeforePhysicsStep=function(t){var i=this._onBeforePhysicsStepCallbacks.indexOf(t);i>-1?this._onBeforePhysicsStepCallbacks.splice(i,1):e.Tools.Warn("Function to remove was not found")},t.prototype.registerAfterPhysicsStep=function(e){this._onAfterPhysicsStepCallbacks.push(e)},t.prototype.unregisterAfterPhysicsStep=function(t){var i=this._onAfterPhysicsStepCallbacks.indexOf(t);i>-1?this._onAfterPhysicsStepCallbacks.splice(i,1):e.Tools.Warn("Function to remove was not found")},t.prototype.registerOnPhysicsCollide=function(e,t){var i=e instanceof Array?e:[e];this._onPhysicsCollideCallbacks.push({callback:t,otherImpostors:i})},t.prototype.unregisterOnPhysicsCollide=function(t,i){var r=t instanceof Array?t:[t],n=this._onPhysicsCollideCallbacks.indexOf({callback:i,otherImpostors:r});n>-1?this._onPhysicsCollideCallbacks.splice(n,1):e.Tools.Warn("Function to remove was not found")},t.prototype.applyForce=function(e,t){this._physicsEngine.getPhysicsPlugin().applyForce(this,e,t)},t.prototype.applyImpulse=function(e,t){this._physicsEngine.getPhysicsPlugin().applyImpulse(this,e,t)},t.prototype.createJoint=function(t,i,r){var n=new e.PhysicsJoint(i,r);this.addJoint(t,n)},t.prototype.addJoint=function(e,t){this._joints.push({otherImpostor:e,joint:t}),this._physicsEngine.addJoint(this,e,t)},t.prototype.sleep=function(){this._physicsEngine.getPhysicsPlugin().sleepBody(this)},t.prototype.wakeUp=function(){this._physicsEngine.getPhysicsPlugin().wakeUpBody(this)},t.prototype.clone=function(e){return e?new t(e,this.type,this._options,this._scene):null},t.prototype.dispose=function(){var e=this;this._physicsEngine&&(this._joints.forEach(function(t){e._physicsEngine.removeJoint(e,t.otherImpostor,t.joint)}),this._physicsEngine.removeImpostor(this),this.parent&&this.parent.forceUpdate())},t.prototype.setDeltaPosition=function(e){this._deltaPosition.copyFrom(e)},t.prototype.setDeltaRotation=function(t){this._deltaRotation||(this._deltaRotation=new e.Quaternion),this._deltaRotation.copyFrom(t),this._deltaRotationConjugated=this._deltaRotation.conjugate()},t.DEFAULT_OBJECT_SIZE=new e.Vector3(1,1,1),t.NoImpostor=0,t.SphereImpostor=1,t.BoxImpostor=2,t.PlaneImpostor=3,t.MeshImpostor=4,t.CylinderImpostor=7,t.ParticleImpostor=8,t.HeightmapImpostor=9,t}();e.PhysicsImpostor=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(t,i){if(void 0===i&&(i=new e.CannonJSPlugin),this._physicsPlugin=i,this._impostors=[],this._joints=[],!this._physicsPlugin.isSupported())throw new Error("Physics Engine "+this._physicsPlugin.name+" cannot be found. Please make sure it is included.");t=t||new e.Vector3(0,-9.807,0),this.setGravity(t),this.setTimeStep()}return t.prototype.setGravity=function(e){this.gravity=e,this._physicsPlugin.setGravity(this.gravity)},t.prototype.setTimeStep=function(e){void 0===e&&(e=1/60),this._physicsPlugin.setTimeStep(e)},t.prototype.dispose=function(){this._impostors.forEach(function(e){e.dispose()}),this._physicsPlugin.dispose()},t.prototype.getPhysicsPluginName=function(){return this._physicsPlugin.name},t.prototype.addImpostor=function(e){e.uniqueId=this._impostors.push(e),e.parent||this._physicsPlugin.generatePhysicsBody(e)},t.prototype.removeImpostor=function(e){var t=this._impostors.indexOf(e);if(t>-1){var i=this._impostors.splice(t,1);i.length&&(i[0].physicsBody=null)}},t.prototype.addJoint=function(e,t,i){var r={mainImpostor:e,connectedImpostor:t,joint:i};i.physicsPlugin=this._physicsPlugin,this._joints.push(r),this._physicsPlugin.generateJoint(r)},t.prototype.removeJoint=function(e,t,i){var r=this._joints.filter(function(r){return r.connectedImpostor===t&&r.joint===i&&r.mainImpostor===e});r.length&&this._physicsPlugin.removeJoint(r[0])},t.prototype._step=function(e){var t=this;this._impostors.forEach(function(e){e.isBodyInitRequired()&&t._physicsPlugin.generatePhysicsBody(e)}),e>.1?e=.1:0>=e&&(e=1/60),this._physicsPlugin.executeStep(e,this._impostors)},t.prototype.getPhysicsPlugin=function(){return this._physicsPlugin},t.prototype.getImpostorForPhysicsObject=function(e){for(var t=0;ta;a++)s.push(t[a]);return s}return e.concat(t)},t.prototype.serialize=function(){var e=this.serialize();return this.positions&&(e.positions=this.positions),this.normals&&(e.normals=this.normals),this.uvs&&(e.uvs=this.uvs),this.uvs2&&(e.uvs2=this.uvs2),this.uvs3&&(e.uvs3=this.uvs3),this.uvs4&&(e.uvs4=this.uvs4),this.uvs5&&(e.uvs5=this.uvs5),this.uvs6&&(e.uvs6=this.uvs6),this.colors&&(e.colors=this.colors),this.matricesIndices&&(e.matricesIndices=this.matricesIndices,e.matricesIndices._isExpanded=!0),this.matricesWeights&&(e.matricesWeights=this.matricesWeights),this.matricesIndicesExtra&&(e.matricesIndicesExtra=this.matricesIndicesExtra,e.matricesIndicesExtra._isExpanded=!0),this.matricesWeightsExtra&&(e.matricesWeightsExtra=this.matricesWeightsExtra),e.indices=this.indices,e},t.ExtractFromMesh=function(e,i){return t._ExtractFrom(e,i)},t.ExtractFromGeometry=function(e,i){return t._ExtractFrom(e,i)},t._ExtractFrom=function(i,r){var n=new t;return i.isVerticesDataPresent(e.VertexBuffer.PositionKind)&&(n.positions=i.getVerticesData(e.VertexBuffer.PositionKind,r)),i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(n.normals=i.getVerticesData(e.VertexBuffer.NormalKind,r)),i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(n.uvs=i.getVerticesData(e.VertexBuffer.UVKind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(n.uvs2=i.getVerticesData(e.VertexBuffer.UV2Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV3Kind)&&(n.uvs3=i.getVerticesData(e.VertexBuffer.UV3Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV4Kind)&&(n.uvs4=i.getVerticesData(e.VertexBuffer.UV4Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV5Kind)&&(n.uvs5=i.getVerticesData(e.VertexBuffer.UV5Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.UV6Kind)&&(n.uvs6=i.getVerticesData(e.VertexBuffer.UV6Kind,r)),i.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(n.colors=i.getVerticesData(e.VertexBuffer.ColorKind,r)),i.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesKind)&&(n.matricesIndices=i.getVerticesData(e.VertexBuffer.MatricesIndicesKind,r)),i.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsKind)&&(n.matricesWeights=i.getVerticesData(e.VertexBuffer.MatricesWeightsKind,r)),i.isVerticesDataPresent(e.VertexBuffer.MatricesIndicesExtraKind)&&(n.matricesIndicesExtra=i.getVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,r)),i.isVerticesDataPresent(e.VertexBuffer.MatricesWeightsExtraKind)&&(n.matricesWeightsExtra=i.getVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,r)),n.indices=i.getIndices(r),n},t.CreateRibbon=function(i){var r=i.pathArray,n=i.closeArray||!1,o=i.closePath||!1,s=Math.floor(r[0].length/2),a=i.offset||s;a=a>s?s:Math.floor(a);var h,c,l,u,f=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,d=[],p=[],_=[],g=[],m=[],v=[],y=[],x=[],b=[],P=[];if(r.length<2){var A=[],E=[];for(l=0;lh?h:C,u=0;C>u;)d.push(T[u].x,T[u].y,T[u].z),u>0&&(I=T[u].subtract(T[u-1]).length(),D=I+y[c],m[c].push(D),y[c]=D),u++;o&&(u--,d.push(T[0].x,T[0].y,T[0].z),I=T[u].subtract(T[0]).length(),D=I+y[c],m[c].push(D),y[c]=D),b[c]=C+M,P[c]=S,S+=C+M}var R,O,w,L;for(l=0;h+M>l;l++){for(x[l]=0,v[l]=[0],c=0;cl;l++)B=m[c][l]/y[c],V=v[l][c]/x[l],g.push(B,V);c=0;for(var F=0,N=b[c]-1,z=b[c+1]-1,U=z>N?N:z,k=P[1]-P[0],G=n?b.length:b.length-1;U>=F&&G>c;)p.push(F,F+k,F+1),p.push(F+k+1,F+1,F+k),F+=1,F===U&&(c++,c===b.length-1?(k=P[0]-P[c],N=b[c]-1,z=b[0]-1):(k=P[c+1]-P[c],N=b[c]-1,z=b[c+1]-1),F=P[c],U=z>N?N+F:z+F);if(t.ComputeNormals(d,p,_),o){var Y=0,W=0;for(c=0;c_;_++)void 0===f[_]&&(f[_]=new e.Vector4(0,0,1,1)),d&&void 0===d[_]&&(d[_]=new e.Color4(1,1,1,1));for(var g=new e.Vector3(h/2,c/2,l/2),m=0;m1?1:i.arc||1,h=i.slice<=0?1:i.slice||1,c=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,l=new e.Vector3(n/2,o/2,s/2),u=2+r,f=2*u,d=[],p=[],_=[],g=[],m=0;u>=m;m++){for(var v=m/u,y=v*Math.PI*h,x=0;f>=x;x++){var b=x/f,P=b*Math.PI*2*a,A=e.Matrix.RotationZ(-y),E=e.Matrix.RotationY(P),T=e.Vector3.TransformCoordinates(e.Vector3.Up(),A),C=e.Vector3.TransformCoordinates(T,E),S=C.multiply(l),M=C.divide(l).normalize();p.push(S.x,S.y,S.z),_.push(M.x,M.y,M.z),g.push(b,v)}if(m>0)for(var I=p.length/3,D=I-2*(f+1);I>D+f+2;D++)d.push(D),d.push(D+1),d.push(D+f+1),d.push(D+f+1),d.push(D+1),d.push(D+f+2)}t._ComputeSides(c,p,d,_,g);var R=new t;return R.indices=d,R.positions=p,R.normals=_,R.uvs=g,R},t.CreateCylinder=function(i){var r,n=i.height||2,o=0===i.diameterTop?0:i.diameterTop||i.diameter||1,s=i.diameterBottom||i.diameter||1,a=i.tessellation||24,h=i.subdivisions||1,c=i.hasRings,l=i.enclose,u=i.arc<=0||i.arc>1?1:i.arc||1,f=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,d=i.faceUV||new Array(3),p=i.faceColors,_=1!==u&&l?2:0,g=c?h:1,m=2+(1+_)*g;for(r=0;m>r;r++)p&&void 0===p[r]&&(p[r]=new e.Color4(1,1,1,1));for(r=0;m>r;r++)d&&void 0===d[r]&&(d[r]=new e.Vector4(0,0,1,1));var v,y,x,b,P,A,E=[],T=[],C=[],S=[],M=[],I=2*Math.PI*u/a,D=(s-o)/2/n,R=e.Vector3.Zero(),O=e.Vector3.Zero(),w=e.Vector3.Zero(),L=e.Vector3.Zero(),B=e.Vector3.Zero(),V=e.Axis.Y,F=1,N=1,z=0,U=0;for(b=0;h>=b;b++)for(y=b/h,x=(y*(o-s)+s)/2,F=c&&0!==b&&b!==h?2:1,A=0;F>A;A++){for(c&&(N+=A),l&&(N+=2*A),P=0;a>=P;P++)v=P*I,R.x=Math.cos(-v)*x,R.y=-n/2+y*n,R.z=Math.sin(-v)*x,0===o&&b===h?(O.x=C[C.length-3*(a+1)],O.y=C[C.length-3*(a+1)+1],O.z=C[C.length-3*(a+1)+2]):(O.x=R.x,O.z=R.z,O.y=Math.sqrt(O.x*O.x+O.z*O.z)*D,O.normalize()),0===P&&(w.copyFrom(R),L.copyFrom(O)),T.push(R.x,R.y,R.z),C.push(O.x,O.y,O.z),U=c?z!==N?d[N].y:d[N].w:d[N].y+(d[N].w-d[N].y)*y,S.push(d[N].x+(d[N].z-d[N].x)*P/a,U),p&&M.push(p[N].r,p[N].g,p[N].b,p[N].a);1!==u&&l&&(T.push(R.x,R.y,R.z),T.push(0,R.y,0),T.push(0,R.y,0),T.push(w.x,w.y,w.z),e.Vector3.CrossToRef(V,O,B),B.normalize(),C.push(B.x,B.y,B.z,B.x,B.y,B.z),e.Vector3.CrossToRef(L,V,B),B.normalize(),C.push(B.x,B.y,B.z,B.x,B.y,B.z),U=c?z!==N?d[N+1].y:d[N+1].w:d[N+1].y+(d[N+1].w-d[N+1].y)*y,S.push(d[N+1].x,U),S.push(d[N+1].z,U),U=c?z!==N?d[N+2].y:d[N+2].w:d[N+2].y+(d[N+2].w-d[N+2].y)*y,S.push(d[N+2].x,U),S.push(d[N+2].z,U),p&&(M.push(p[N+1].r,p[N+1].g,p[N+1].b,p[N+1].a),M.push(p[N+1].r,p[N+1].g,p[N+1].b,p[N+1].a),M.push(p[N+2].r,p[N+2].g,p[N+2].b,p[N+2].a),M.push(p[N+2].r,p[N+2].g,p[N+2].b,p[N+2].a))),z!==N&&(z=N)}var N,k=1!==u&&l?a+4:a;for(b=0,N=0;h>N;N++){for(P=0;a>P;P++){var G=b*(k+1)+P,Y=(b+1)*(k+1)+P,W=b*(k+1)+(P+1),H=(b+1)*(k+1)+(P+1);E.push(G,Y,W),E.push(H,W,Y)}1!==u&&l&&(E.push(G+2,Y+2,W+2),E.push(H+2,W+2,Y+2),E.push(G+4,Y+4,W+4),E.push(H+4,W+4,Y+4)),b=c?b+2:b+1}var j=function(t){var i=t?o/2:s/2;if(0!==i){var r,h,c,l,f=t?d[m-1]:d[0];p&&(l=t?p[m-1]:p[0]);var _=T.length/3,g=t?n/2:-n/2,v=new e.Vector3(0,g,0);T.push(v.x,v.y,v.z),C.push(0,t?1:-1,0),S.push(f.x+.5*(f.z-f.x),f.y+.5*(f.w-f.y)),p&&M.push(l.r,l.g,l.b,l.a);var y=new e.Vector2(.5,.5);for(c=0;a>=c;c++){r=2*Math.PI*c*u/a;var x=Math.cos(-r),b=Math.sin(-r);h=new e.Vector3(x*i,g,b*i);var P=new e.Vector2(x*y.x+.5,b*y.y+.5);T.push(h.x,h.y,h.z),C.push(0,t?1:-1,0),S.push(f.x+(f.z-f.x)*P.x,f.y+(f.w-f.y)*P.y),p&&M.push(l.r,l.g,l.b,l.a)}for(c=0;a>c;c++)t?(E.push(_),E.push(_+(c+2)),E.push(_+(c+1))):(E.push(_),E.push(_+(c+1)),E.push(_+(c+2)))}};j(!1),j(!0),t._ComputeSides(f,T,E,C,S);var X=new t;return X.indices=E,X.positions=T,X.normals=C,X.uvs=S,p&&(X.colors=M),X},t.CreateTorus=function(i){for(var r=[],n=[],o=[],s=[],a=i.diameter||1,h=i.thickness||.5,c=i.tessellation||16,l=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,u=c+1,f=0;c>=f;f++)for(var d=f/c,p=f*Math.PI*2/c-Math.PI/2,_=e.Matrix.Translation(a/2,0,0).multiply(e.Matrix.RotationY(p)),g=0;c>=g;g++){var m=1-g/c,v=g*Math.PI*2/c+Math.PI,y=Math.cos(v),x=Math.sin(v),b=new e.Vector3(y,x,0),P=b.scale(h/2),A=new e.Vector2(d,m);P=e.Vector3.TransformCoordinates(P,_),b=e.Vector3.TransformNormal(b,_),n.push(P.x,P.y,P.z),o.push(b.x,b.y,b.z),s.push(A.x,A.y);var E=(f+1)%u,T=(g+1)%u;r.push(f*u+g),r.push(f*u+T),r.push(E*u+g),r.push(f*u+T),r.push(E*u+T),r.push(E*u+g)}t._ComputeSides(l,n,r,o,s);var C=new t;return C.indices=r,C.positions=n,C.normals=o,C.uvs=s,C},t.CreateLineSystem=function(e){for(var i=[],r=[],n=e.lines,o=0,s=0;s0&&(i.push(o-1),i.push(o)),o++;var c=new t;return c.indices=i,c.positions=r,c},t.CreateDashedLines=function(i){var r=i.dashSize||3,n=i.gapSize||1,o=i.dashNb||200,s=i.points,a=new Array,h=new Array,c=e.Vector3.Zero(),l=0,u=0,f=0,d=0,p=0,_=0,g=0;for(g=0;gm;m++)p=f*m,a.push(s[g].x+p*c.x,s[g].y+p*c.y,s[g].z+p*c.z),a.push(s[g].x+(p+d)*c.x,s[g].y+(p+d)*c.y,s[g].z+(p+d)*c.z),h.push(_,_+1),_+=2}var v=new t;return v.positions=a,v.indices=h,v},t.CreateGround=function(i){var r,n,o=[],s=[],a=[],h=[],c=i.width||1,l=i.height||1,u=i.subdivisions||1;for(r=0;u>=r;r++)for(n=0;u>=n;n++){var f=new e.Vector3(n*c/u-c/2,0,(u-r)*l/u-l/2),d=new e.Vector3(0,1,0);s.push(f.x,f.y,f.z),a.push(d.x,d.y,d.z),h.push(n/u,1-r/u)}for(r=0;u>r;r++)for(n=0;u>n;n++)o.push(n+1+(r+1)*(u+1)),o.push(n+1+r*(u+1)),o.push(n+r*(u+1)),o.push(n+(r+1)*(u+1)),o.push(n+1+(r+1)*(u+1)),o.push(n+r*(u+1));var p=new t;return p.indices=o,p.positions=s,p.normals=a,p.uvs=h,p},t.CreateTiledGround=function(i){function r(t,i,r,s){var a=_.length/3,h=d.w+1;for(n=0;n1?1:i.arc||1,l=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE;r.push(0,0,0),s.push(.5,.5);for(var u=2*Math.PI*c,f=u/h,d=0;u>d;d+=f){var p=Math.cos(d),_=Math.sin(d),g=(p+1)/2,m=(1-_)/2;r.push(a*p,a*_,0),s.push(g,m)}1===c&&(r.push(r[3],r[4],r[5]),s.push(s[2],s[3]));for(var v=r.length/3,y=1;v-1>y;y++)n.push(y+1,0,y);t.ComputeNormals(r,n,o),t._ComputeSides(l,r,n,o,s);var x=new t;return x.indices=n,x.positions=r,x.normals=o,x.uvs=s,x},t.CreateIcoSphere=function(i){var r,n=i.sideOrientation||e.Mesh.DEFAULTSIDE,o=i.radius||1,s=void 0===i.flat?!0:i.flat,a=i.subdivisions||4,h=i.radiusX||o,c=i.radiusY||o,l=i.radiusZ||o,u=(1+Math.sqrt(5))/2,f=[-1,u,-0,1,u,0,-1,-u,0,1,-u,0,0,-1,-u,0,1,-u,0,-1,u,0,1,u,u,0,1,u,0,-1,-u,0,1,-u,0,-1],d=[0,11,5,0,5,1,0,1,7,0,7,10,12,22,23,1,5,20,5,11,4,23,22,13,22,18,6,7,1,8,14,21,4,14,4,2,16,13,6,15,6,19,3,8,9,4,21,5,13,17,23,6,13,22,19,6,18,9,8,1],p=[0,1,2,3,4,5,6,7,8,9,10,11,0,2,3,3,3,4,7,8,9,9,10,11],_=[5,1,3,1,6,4,0,0,5,3,4,2,2,2,4,0,2,0,1,1,6,0,6,2,0,4,3,3,4,4,3,1,4,2,4,4,0,2,1,1,2,2,3,3,1,3,2,4],g=138/1024,m=239/1024,v=60/1024,y=26/1024,x=-40/1024,b=20/1024,P=[0,0,0,0,1,0,0,1,1,0,0,0,1,1,0,0,1,1,1,0],A=[],E=[],T=[],C=[],S=0,M=new Array(3),I=new Array(3);for(r=0;3>r;r++)M[r]=e.Vector3.Zero(),I[r]=e.Vector2.Zero();for(var D=0;20>D;D++){for(r=0;3>r;r++){var R=d[3*D+r];M[r].copyFromFloats(f[3*p[R]],f[3*p[R]+1],f[3*p[R]+2]),M[r].normalize().scaleInPlace(o),I[r].copyFromFloats(_[2*R]*g+v+P[D]*x,_[2*R+1]*m+y+P[D]*b)}for(var O=function(t,i,r,n){var o=e.Vector3.Lerp(M[0],M[2],i/a),u=e.Vector3.Lerp(M[1],M[2],i/a),f=a===i?M[2]:e.Vector3.Lerp(o,u,t/(a-i));f.normalize();var d;if(s){var p=e.Vector3.Lerp(M[0],M[2],n/a),_=e.Vector3.Lerp(M[1],M[2],n/a);d=e.Vector3.Lerp(p,_,r/(a-n))}else d=new e.Vector3(f.x,f.y,f.z);d.x/=h,d.y/=c,d.z/=l,d.normalize();var g=e.Vector2.Lerp(I[0],I[2],i/a),m=e.Vector2.Lerp(I[1],I[2],i/a),v=a===i?I[2]:e.Vector2.Lerp(g,m,t/(a-i));E.push(f.x*h,f.y*c,f.z*l),T.push(d.x,d.y,d.z),C.push(v.x,v.y),A.push(S),S++},w=0;a>w;w++)for(var L=0;a>L+w;L++)O(L,w,L+1/3,w+1/3),O(L+1,w,L+1/3,w+1/3),O(L,w+1,L+1/3,w+1/3),a>L+w+1&&(O(L+1,w,L+2/3,w+2/3),O(L+1,w+1,L+2/3,w+2/3),O(L,w+1,L+2/3,w+2/3))}t._ComputeSides(n,E,A,T,C);var B=new t;return B.indices=A,B.positions=E,B.normals=T,B.uvs=C,B},t.CreatePolyhedron=function(i){var r=[];r[0]={vertex:[[0,0,1.732051],[1.632993,0,-.5773503],[-.8164966,1.414214,-.5773503],[-.8164966,-1.414214,-.5773503]],face:[[0,1,2],[0,2,3],[0,3,1],[1,3,2]]},r[1]={vertex:[[0,0,1.414214],[1.414214,0,0],[0,1.414214,0],[-1.414214,0,0],[0,-1.414214,0],[0,0,-1.414214]],face:[[0,1,2],[0,2,3],[0,3,4],[0,4,1],[1,4,5],[1,5,2],[2,5,3],[3,5,4]]},r[2]={vertex:[[0,0,1.070466],[.7136442,0,.7978784],[-.3568221,.618034,.7978784],[-.3568221,-.618034,.7978784],[.7978784,.618034,.3568221],[.7978784,-.618034,.3568221],[-.9341724,.381966,.3568221],[.1362939,1,.3568221],[.1362939,-1,.3568221],[-.9341724,-.381966,.3568221],[.9341724,.381966,-.3568221],[.9341724,-.381966,-.3568221],[-.7978784,.618034,-.3568221],[-.1362939,1,-.3568221],[-.1362939,-1,-.3568221],[-.7978784,-.618034,-.3568221],[.3568221,.618034,-.7978784],[.3568221,-.618034,-.7978784],[-.7136442,0,-.7978784],[0,0,-1.070466]],face:[[0,1,4,7,2],[0,2,6,9,3],[0,3,8,5,1],[1,5,11,10,4],[2,7,13,12,6],[3,9,15,14,8],[4,10,16,13,7],[5,8,14,17,11],[6,12,18,15,9],[10,11,17,19,16],[12,13,16,19,18],[14,15,18,19,17]]},r[3]={vertex:[[0,0,1.175571],[1.051462,0,.5257311],[.3249197,1,.5257311],[-.8506508,.618034,.5257311],[-.8506508,-.618034,.5257311],[.3249197,-1,.5257311],[.8506508,.618034,-.5257311],[.8506508,-.618034,-.5257311],[-.3249197,1,-.5257311],[-1.051462,0,-.5257311],[-.3249197,-1,-.5257311],[0,0,-1.175571]],face:[[0,1,2],[0,2,3],[0,3,4],[0,4,5],[0,5,1],[1,5,7],[1,7,6],[1,6,2],[2,6,8],[2,8,3],[3,8,9],[3,9,4],[4,9,10],[4,10,5],[5,10,7],[6,7,11],[6,11,8],[7,10,11],[8,11,9],[9,11,10]]},r[4]={vertex:[[0,0,1.070722],[.7148135,0,.7971752],[-.104682,.7071068,.7971752],[-.6841528,.2071068,.7971752],[-.104682,-.7071068,.7971752],[.6101315,.7071068,.5236279],[1.04156,.2071068,.1367736],[.6101315,-.7071068,.5236279],[-.3574067,1,.1367736],[-.7888348,-.5,.5236279],[-.9368776,.5,.1367736],[-.3574067,-1,.1367736],[.3574067,1,-.1367736],[.9368776,-.5,-.1367736],[.7888348,.5,-.5236279],[.3574067,-1,-.1367736],[-.6101315,.7071068,-.5236279],[-1.04156,-.2071068,-.1367736],[-.6101315,-.7071068,-.5236279],[.104682,.7071068,-.7971752],[.6841528,-.2071068,-.7971752],[.104682,-.7071068,-.7971752],[-.7148135,0,-.7971752],[0,0,-1.070722]],face:[[0,2,3],[1,6,5],[4,9,11],[7,15,13],[8,16,10],[12,14,19],[17,22,18],[20,21,23],[0,1,5,2],[0,3,9,4],[0,4,7,1],[1,7,13,6],[2,5,12,8],[2,8,10,3],[3,10,17,9],[4,11,15,7],[5,6,14,12],[6,13,20,14],[8,12,19,16],[9,17,18,11],[10,16,22,17],[11,18,21,15],[13,15,21,20],[14,20,23,19],[16,19,23,22],[18,22,23,21]]
+},r[5]={vertex:[[0,0,1.322876],[1.309307,0,.1889822],[-.9819805,.8660254,.1889822],[.1636634,-1.299038,.1889822],[.3273268,.8660254,-.9449112],[-.8183171,-.4330127,-.9449112]],face:[[0,3,1],[2,4,5],[0,1,4,2],[0,2,5,3],[1,3,5,4]]},r[6]={vertex:[[0,0,1.159953],[1.013464,0,.5642542],[-.3501431,.9510565,.5642542],[-.7715208,-.6571639,.5642542],[.6633206,.9510565,-.03144481],[.8682979,-.6571639,-.3996071],[-1.121664,.2938926,-.03144481],[-.2348831,-1.063314,-.3996071],[.5181548,.2938926,-.9953061],[-.5850262,-.112257,-.9953061]],face:[[0,1,4,2],[0,2,6,3],[1,5,8,4],[3,6,9,7],[5,7,9,8],[0,3,7,5,1],[2,4,8,9,6]]},r[7]={vertex:[[0,0,1.118034],[.8944272,0,.6708204],[-.2236068,.8660254,.6708204],[-.7826238,-.4330127,.6708204],[.6708204,.8660254,.2236068],[1.006231,-.4330127,-.2236068],[-1.006231,.4330127,.2236068],[-.6708204,-.8660254,-.2236068],[.7826238,.4330127,-.6708204],[.2236068,-.8660254,-.6708204],[-.8944272,0,-.6708204],[0,0,-1.118034]],face:[[0,1,4,2],[0,2,6,3],[1,5,8,4],[3,6,10,7],[5,9,11,8],[7,10,11,9],[0,3,7,9,5,1],[2,4,8,11,10,6]]},r[8]={vertex:[[-.729665,.670121,.319155],[-.655235,-.29213,-.754096],[-.093922,-.607123,.537818],[.702196,.595691,.485187],[.776626,-.36656,-.588064]],face:[[1,4,2],[0,1,2],[3,0,2],[4,3,2],[4,1,0,3]]},r[9]={vertex:[[-.868849,-.100041,.61257],[-.329458,.976099,.28078],[-.26629,-.013796,-.477654],[-.13392,-1.034115,.229829],[.738834,.707117,-.307018],[.859683,-.535264,-.338508]],face:[[3,0,2],[5,3,2],[4,5,2],[1,4,2],[0,1,2],[0,3,5,4,1]]},r[10]={vertex:[[-.610389,.243975,.531213],[-.187812,-.48795,-.664016],[-.187812,.9759,-.664016],[.187812,-.9759,.664016],[.798201,.243975,.132803]],face:[[1,3,0],[3,4,0],[3,1,4],[0,2,1],[0,4,2],[2,4,1]]},r[11]={vertex:[[-1.028778,.392027,-.048786],[-.640503,-.646161,.621837],[-.125162,-.395663,-.540059],[.004683,.888447,-.651988],[.125161,.395663,.540059],[.632925,-.791376,.433102],[1.031672,.157063,-.354165]],face:[[3,2,0],[2,1,0],[2,5,1],[0,4,3],[0,1,4],[4,1,5],[2,3,6],[3,4,6],[5,2,6],[4,5,6]]},r[12]={vertex:[[-.669867,.334933,-.529576],[-.669867,.334933,.529577],[-.4043,1.212901,0],[-.334933,-.669867,-.529576],[-.334933,-.669867,.529577],[.334933,.669867,-.529576],[.334933,.669867,.529577],[.4043,-1.212901,0],[.669867,-.334933,-.529576],[.669867,-.334933,.529577]],face:[[8,9,7],[6,5,2],[3,8,7],[5,0,2],[4,3,7],[0,1,2],[9,4,7],[1,6,2],[9,8,5,6],[8,3,0,5],[3,4,1,0],[4,9,6,1]]},r[13]={vertex:[[-.931836,.219976,-.264632],[-.636706,.318353,.692816],[-.613483,-.735083,-.264632],[-.326545,.979634,0],[-.318353,-.636706,.692816],[-.159176,.477529,-.856368],[.159176,-.477529,-.856368],[.318353,.636706,.692816],[.326545,-.979634,0],[.613482,.735082,-.264632],[.636706,-.318353,.692816],[.931835,-.219977,-.264632]],face:[[11,10,8],[7,9,3],[6,11,8],[9,5,3],[2,6,8],[5,0,3],[4,2,8],[0,1,3],[10,4,8],[1,7,3],[10,11,9,7],[11,6,5,9],[6,2,0,5],[2,4,1,0],[4,10,7,1]]},r[14]={vertex:[[-.93465,.300459,-.271185],[-.838689,-.260219,-.516017],[-.711319,.717591,.128359],[-.710334,-.156922,.080946],[-.599799,.556003,-.725148],[-.503838,-.004675,-.969981],[-.487004,.26021,.48049],[-.460089,-.750282,-.512622],[-.376468,.973135,-.325605],[-.331735,-.646985,.084342],[-.254001,.831847,.530001],[-.125239,-.494738,-.966586],[.029622,.027949,.730817],[.056536,-.982543,-.262295],[.08085,1.087391,.076037],[.125583,-.532729,.485984],[.262625,.599586,.780328],[.391387,-.726999,-.716259],[.513854,-.868287,.139347],[.597475,.85513,.326364],[.641224,.109523,.783723],[.737185,-.451155,.538891],[.848705,-.612742,-.314616],[.976075,.365067,.32976],[1.072036,-.19561,.084927]],face:[[15,18,21],[12,20,16],[6,10,2],[3,0,1],[9,7,13],[2,8,4,0],[0,4,5,1],[1,5,11,7],[7,11,17,13],[13,17,22,18],[18,22,24,21],[21,24,23,20],[20,23,19,16],[16,19,14,10],[10,14,8,2],[15,9,13,18],[12,15,21,20],[6,12,16,10],[3,6,2,0],[9,3,1,7],[9,15,12,6,3],[22,17,11,5,4,8,14,19,23,24]]};var n,o,s,a,h,c,l=i.type<0||i.type>=r.length?0:i.type||0,u=i.size,f=i.sizeX||u||1,d=i.sizeY||u||1,p=i.sizeZ||u||1,_=i.custom||r[l],g=_.face.length,m=i.faceUV||new Array(g),v=i.faceColors,y=void 0===i.flat?!0:i.flat,x=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,b=[],P=[],A=[],E=[],T=[],C=0,S=0,M=[],I=0,D=0;if(y)for(D=0;g>D;D++)v&&void 0===v[D]&&(v[D]=new e.Color4(1,1,1,1)),m&&void 0===m[D]&&(m[D]=new e.Vector4(0,0,1,1));if(y)for(D=0;g>D;D++){var R=_.face[D].length;for(s=2*Math.PI/R,a=.5*Math.tan(s/2),h=.5,I=0;R>I;I++)b.push(_.vertex[_.face[D][I]][0]*f,_.vertex[_.face[D][I]][1]*d,_.vertex[_.face[D][I]][2]*p),M.push(C),C++,n=m[D].x+(m[D].z-m[D].x)*(.5+a),o=m[D].y+(m[D].w-m[D].y)*(h-.5),E.push(n,o),c=a*Math.cos(s)-h*Math.sin(s),h=a*Math.sin(s)+h*Math.cos(s),a=c,v&&T.push(v[D].r,v[D].g,v[D].b,v[D].a);for(I=0;R-2>I;I++)P.push(M[0+S],M[I+2+S],M[I+1+S]);S+=R}else{for(I=0;I<_.vertex.length;I++)b.push(_.vertex[I][0]*f,_.vertex[I][1]*d,_.vertex[I][2]*p),E.push(0,0);for(D=0;g>D;D++)for(I=0;I<_.face[D].length-2;I++)P.push(_.face[D][0],_.face[D][I+2],_.face[D][I+1])}t.ComputeNormals(b,P,A),t._ComputeSides(x,b,P,A,E);var O=new t;return O.positions=b,O.indices=P,O.normals=A,O.uvs=E,v&&y&&(O.colors=T),O},t.CreateTorusKnot=function(i){var r,n,o=[],s=[],a=[],h=[],c=i.radius||2,l=i.tube||.5,u=i.radialSegments||32,f=i.tubularSegments||32,d=i.p||2,p=i.q||3,_=0===i.sideOrientation?0:i.sideOrientation||e.Mesh.DEFAULTSIDE,g=function(t){var i=Math.cos(t),r=Math.sin(t),n=p/d*t,o=Math.cos(n),s=c*(2+o)*.5*i,a=c*(2+o)*r*.5,h=c*Math.sin(n)*.5;return new e.Vector3(s,a,h)};for(r=0;u>=r;r++){var m=r%u,v=m/u*2*d*Math.PI,y=g(v),x=g(v+.01),b=x.subtract(y),P=x.add(y),A=e.Vector3.Cross(b,P);for(P=e.Vector3.Cross(A,b),A.normalize(),P.normalize(),n=0;f>n;n++){var E=n%f,T=E/f*2*Math.PI,C=-l*Math.cos(T),S=l*Math.sin(T);s.push(y.x+C*P.x+S*A.x),s.push(y.y+C*P.y+S*A.y),s.push(y.z+C*P.z+S*A.z),h.push(r/u),h.push(n/f)}}for(r=0;u>r;r++)for(n=0;f>n;n++){var M=(n+1)%f,I=r*f+n,D=(r+1)*f+n,R=(r+1)*f+M,O=r*f+M;o.push(O),o.push(D),o.push(I),o.push(O),o.push(R),o.push(D)}t.ComputeNormals(s,o,a),t._ComputeSides(_,s,o,a,h);var w=new t;return w.indices=o,w.positions=s,w.normals=a,w.uvs=h,w},t.ComputeNormals=function(e,t,i){var r=0,n=0,o=0,s=0,a=0,h=0,c=0,l=0,u=0,f=0,d=0,p=0,_=0,g=0;for(r=0;rr;r++)p=t[3*r],_=t[3*r+1],g=t[3*r+2],n=e[3*p]-e[3*_],o=e[3*p+1]-e[3*_+1],s=e[3*p+2]-e[3*_+2],a=e[3*g]-e[3*_],h=e[3*g+1]-e[3*_+1],c=e[3*g+2]-e[3*_+2],l=o*c-s*h,u=s*a-n*c,f=n*h-o*a,d=Math.sqrt(l*l+u*u+f*f),d=0===d?1:d,l/=d,u/=d,f/=d,i[3*p]+=l,i[3*p+1]+=u,i[3*p+2]+=f,i[3*_]+=l,i[3*_+1]+=u,i[3*_+2]+=f,i[3*g]+=l,i[3*g+1]+=u,i[3*g+2]+=f;for(r=0;rs;s+=3)l=r[s],r[s]=r[s+2],r[s+2]=l;for(a=0;c>a;a++)n[a]=-n[a];break;case e.Mesh.DOUBLESIDE:for(var u=i.length,f=u/3,d=0;u>d;d++)i[u+d]=i[d];for(s=0;h>s;s+=3)r[s+h]=r[s+2]+f,r[s+1+h]=r[s+1]+f,r[s+2+h]=r[s]+f;for(a=0;c>a;a++)n[c+a]=-n[a];for(var p=o.length,_=0;p>_;_++)o[_+p]=o[_]}},t.ImportVertexData=function(i,r){var n=new t,o=i.positions;o&&n.set(o,e.VertexBuffer.PositionKind);var s=i.normals;s&&n.set(s,e.VertexBuffer.NormalKind);var a=i.uvs;a&&n.set(a,e.VertexBuffer.UVKind);var h=i.uv2s;h&&n.set(h,e.VertexBuffer.UV2Kind);var c=i.uv3s;c&&n.set(c,e.VertexBuffer.UV3Kind);var l=i.uv4s;l&&n.set(l,e.VertexBuffer.UV4Kind);var u=i.uv5s;u&&n.set(u,e.VertexBuffer.UV5Kind);var f=i.uv6s;f&&n.set(f,e.VertexBuffer.UV6Kind);var d=i.colors;d&&n.set(e.Color4.CheckColors4(d,o.length/3),e.VertexBuffer.ColorKind);var p=i.matricesIndices;p&&n.set(p,e.VertexBuffer.MatricesIndicesKind);var _=i.matricesWeights;_&&n.set(_,e.VertexBuffer.MatricesWeightsKind);var g=i.indices;g&&(n.indices=g),r.setAllVerticesData(n,i.updatable)},t}();e.VertexData=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(){}return t.EnableFor=function(e){e._tags=e._tags||{},e.hasTags=function(){return t.HasTags(e)},e.addTags=function(i){return t.AddTagsTo(e,i)},e.removeTags=function(i){return t.RemoveTagsFrom(e,i)},e.matchesTagsQuery=function(i){return t.MatchesQuery(e,i)}},t.DisableFor=function(e){delete e._tags,delete e.hasTags,delete e.addTags,delete e.removeTags,delete e.matchesTagsQuery},t.HasTags=function(t){return t._tags?!e.Tools.IsEmpty(t._tags):!1},t.GetTags=function(e,t){if(void 0===t&&(t=!0),!e._tags)return null;if(t){var i=[];for(var r in e._tags)e._tags.hasOwnProperty(r)&&e._tags[r]===!0&&i.push(r);return i.join(" ")}return e._tags},t.AddTagsTo=function(e,i){if(i&&"string"==typeof i){var r=i.split(" ");for(var n in r)t._AddTagTo(e,r[n])}},t._AddTagTo=function(e,i){i=i.trim(),""!==i&&"true"!==i&&"false"!==i&&(i.match(/[\s]/)||i.match(/^([!]|([|]|[&]){2})/)||(t.EnableFor(e),e._tags[i]=!0))},t.RemoveTagsFrom=function(e,i){if(t.HasTags(e)){var r=i.split(" ");for(var n in r)t._RemoveTagFrom(e,r[n])}},t._RemoveTagFrom=function(e,t){delete e._tags[t]},t.MatchesQuery=function(i,r){return void 0===r?!0:""===r?t.HasTags(i):e.Internals.AndOrNotEvaluator.Eval(r,function(e){return t.HasTags(i)&&i._tags[e]})},t}();e.Tags=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t;!function(e){var t=function(){function e(){}return e.Eval=function(t,i){return t=t.match(/\([^\(\)]*\)/g)?t.replace(/\([^\(\)]*\)/g,function(t){return t=t.slice(1,t.length-1),e._HandleParenthesisContent(t,i)}):e._HandleParenthesisContent(t,i),"true"===t?!0:"false"===t?!1:e.Eval(t,i)},e._HandleParenthesisContent=function(t,i){i=i||function(e){return"true"===e};var r,n=t.split("||");for(var o in n){var s=e._SimplifyNegation(n[o].trim()),a=s.split("&&");if(a.length>1)for(var h=0;hthis.value;case i.IsLesser:return this._effectiveTarget[this._property]-1&&this._scene._actionManagers.splice(e,1)},t.prototype.getScene=function(){return this._scene},t.prototype.hasSpecificTriggers=function(e){for(var t=0;t-1)return!0}return!1},t.prototype.hasSpecificTrigger=function(e){for(var t=0;t=t._OnPickTrigger&&i.trigger<=t._OnPointerOutTrigger)return!0}return!1},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"hasPickTriggers",{get:function(){for(var e=0;e=t._OnPickTrigger&&i.trigger<=t._OnPickUpTrigger)return!0}return!1},enumerable:!0,configurable:!0}),t.prototype.registerAction=function(i){return i.trigger===t.OnEveryFrameTrigger&&this.getScene().actionManager!==this?(e.Tools.Warn("OnEveryFrameTrigger can only be used with scene.actionManager"),null):(this.actions.push(i),i._actionManager=this,i._prepare(),i)},t.prototype.processTrigger=function(e,i){for(var r=0;r0;if(2===i.type?f.push(o):f.push(r),_){for(var g=new Array,m=0;m0){var f=u.properties[0].value,d=null===u.properties[0].targetType?f:n.getMeshByName(f);l={trigger:e.ActionManager[u.name],parameter:d}}else l=e.ActionManager[u.name];for(var p=0;pa;a++){var h=o[a];h._resetPointsArrayCache(),h._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),h._createGlobalSubMesh(),h.computeWorldMatrix(!0)}}this.notifyUpdate(i)},t.prototype.updateVerticesDataDirectly=function(e,t,i){var r=this.getVertexBuffer(e);r&&(r.updateDirectly(t,i),this.notifyUpdate(e))},t.prototype.updateVerticesData=function(t,i,r){var n=this.getVertexBuffer(t);if(n){if(n.update(i),t===e.VertexBuffer.PositionKind){var o=n.getStrideSize();this._totalVertices=i.length/o,this.updateBoundingInfo(r,i)}this.notifyUpdate(t)}},t.prototype.updateBoundingInfo=function(t,i){t&&this.updateExtend(i);for(var r=this._meshes,n=r.length,o=0;n>o;o++){var s=r[o];if(s._resetPointsArrayCache(),t){s._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum);for(var a=0;as;s++)o.push(r[s]);return o}return r},t.prototype.getVertexBuffer=function(e){return this.isReady()?this._vertexBuffers[e]:null},t.prototype.getVertexBuffers=function(){return this.isReady()?this._vertexBuffers:null},t.prototype.isVerticesDataPresent=function(e){return this._vertexBuffers?void 0!==this._vertexBuffers[e]:this._delayInfo?-1!==this._delayInfo.indexOf(e):!1},t.prototype.getVerticesDataKinds=function(){var e,t=[];if(!this._vertexBuffers&&this._delayInfo)for(e in this._delayInfo)t.push(e);else for(e in this._vertexBuffers)t.push(e);return t},t.prototype.setIndices=function(e,t){this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indices=e,0!==this._meshes.length&&this._indices&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),void 0!==t&&(this._totalVertices=t);for(var i=this._meshes,r=i.length,n=0;r>n;n++)i[n]._createGlobalSubMesh();this.notifyUpdate()},t.prototype.getTotalIndices=function(){return this.isReady()?this._indices.length:0},t.prototype.getIndices=function(e){if(!this.isReady())return null;var t=this._indices;if(e&&1!==this._meshes.length){for(var i=t.length,r=[],n=0;i>n;n++)r.push(t[n]);return r}return t},t.prototype.getIndexBuffer=function(){return this.isReady()?this._indexBuffer:null},t.prototype.releaseForMesh=function(e,t){var i=this._meshes,r=i.indexOf(e);if(-1!==r){for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer)&&(this._indexBuffer=null),i.splice(r,1),e._geometry=null,0===i.length&&t&&this.dispose()}},t.prototype.applyToMesh=function(e){if(e._geometry!==this){var t=e._geometry;t&&t.releaseForMesh(e);var i=this._meshes;e._geometry=this,this._scene.pushGeometry(this),i.push(e),this.isReady()?this._applyToMesh(e):e._boundingInfo=this._boundingInfo}},t.prototype.updateExtend=function(t,i){void 0===t&&(t=null),t||(t=this._vertexBuffers[e.VertexBuffer.PositionKind].getData()),this._extend=e.Tools.ExtractMinAndMax(t,0,this._totalVertices,this.boundingBias,i)},t.prototype._applyToMesh=function(t){var i=this._meshes.length;for(var r in this._vertexBuffers)1===i&&this._vertexBuffers[r].create(),this._vertexBuffers[r].getBuffer().references=i,r===e.VertexBuffer.PositionKind&&(t._resetPointsArrayCache(),this._extend||this.updateExtend(this._vertexBuffers[r].getData()),t._boundingInfo=new e.BoundingInfo(this._extend.minimum,this._extend.maximum),t._createGlobalSubMesh(),t._updateBoundingInfo());1===i&&this._indices&&this._indices.length>0&&(this._indexBuffer=this._engine.createIndexBuffer(this._indices)),this._indexBuffer&&(this._indexBuffer.references=i)},t.prototype.notifyUpdate=function(e){this.onGeometryUpdated&&this.onGeometryUpdated(this,e)},t.prototype.load=function(t,i){var r=this;if(this.delayLoadState!==e.Engine.DELAYLOADSTATE_LOADING){if(this.isReady())return void(i&&i());this.delayLoadState=e.Engine.DELAYLOADSTATE_LOADING,t._addPendingData(this),e.Tools.LoadFile(this.delayLoadingFile,function(n){r._delayLoadingFunction(JSON.parse(n),r),r.delayLoadState=e.Engine.DELAYLOADSTATE_LOADED,r._delayInfo=[],t._removePendingData(r);for(var o=r._meshes,s=o.length,a=0;s>a;a++)r._applyToMesh(o[a]);i&&i()},function(){},t.database)}},t.prototype.toLeftHanded=function(){var t=this.getIndices(!1);if(null!=t&&t.length>0){for(var i=0;i0){for(var i=0;i0){for(var i=0;it;t++)this.releaseForMesh(i[t]);this._meshes=[];for(var n in this._vertexBuffers)this._vertexBuffers[n].dispose();this._vertexBuffers={},this._totalVertices=0,this._indexBuffer&&this._engine._releaseBuffer(this._indexBuffer),this._indexBuffer=null,this._indices=[],this.delayLoadState=e.Engine.DELAYLOADSTATE_NONE,this.delayLoadingFile=null,this._delayLoadingFunction=null,this._delayInfo=[],this._boundingInfo=null,this._scene.removeGeometry(this),this._isDisposed=!0},t.prototype.copy=function(i){var r=new e.VertexData;r.indices=[];for(var n=this.getIndices(),o=0;o0){var a=new Float32Array(t,s.positionsAttrDesc.offset,s.positionsAttrDesc.count);i.setVerticesData(e.VertexBuffer.PositionKind,a,!1)}if(s.normalsAttrDesc&&s.normalsAttrDesc.count>0){var h=new Float32Array(t,s.normalsAttrDesc.offset,s.normalsAttrDesc.count);i.setVerticesData(e.VertexBuffer.NormalKind,h,!1)}if(s.uvsAttrDesc&&s.uvsAttrDesc.count>0){var c=new Float32Array(t,s.uvsAttrDesc.offset,s.uvsAttrDesc.count);i.setVerticesData(e.VertexBuffer.UVKind,c,!1)}if(s.uvs2AttrDesc&&s.uvs2AttrDesc.count>0){var l=new Float32Array(t,s.uvs2AttrDesc.offset,s.uvs2AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV2Kind,l,!1)}if(s.uvs3AttrDesc&&s.uvs3AttrDesc.count>0){var u=new Float32Array(t,s.uvs3AttrDesc.offset,s.uvs3AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV3Kind,u,!1)}if(s.uvs4AttrDesc&&s.uvs4AttrDesc.count>0){var f=new Float32Array(t,s.uvs4AttrDesc.offset,s.uvs4AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV4Kind,f,!1)}if(s.uvs5AttrDesc&&s.uvs5AttrDesc.count>0){var d=new Float32Array(t,s.uvs5AttrDesc.offset,s.uvs5AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV5Kind,d,!1)}if(s.uvs6AttrDesc&&s.uvs6AttrDesc.count>0){var p=new Float32Array(t,s.uvs6AttrDesc.offset,s.uvs6AttrDesc.count);i.setVerticesData(e.VertexBuffer.UV6Kind,p,!1)}if(s.colorsAttrDesc&&s.colorsAttrDesc.count>0){var _=new Float32Array(t,s.colorsAttrDesc.offset,s.colorsAttrDesc.count);i.setVerticesData(e.VertexBuffer.ColorKind,_,!1,s.colorsAttrDesc.stride)}if(s.matricesIndicesAttrDesc&&s.matricesIndicesAttrDesc.count>0){var g=new Int32Array(t,s.matricesIndicesAttrDesc.offset,s.matricesIndicesAttrDesc.count);i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,g,!1)}if(s.matricesWeightsAttrDesc&&s.matricesWeightsAttrDesc.count>0){var m=new Float32Array(t,s.matricesWeightsAttrDesc.offset,s.matricesWeightsAttrDesc.count);i.setVerticesData(e.VertexBuffer.MatricesWeightsKind,m,!1)}if(s.indicesAttrDesc&&s.indicesAttrDesc.count>0){var v=new Int32Array(t,s.indicesAttrDesc.offset,s.indicesAttrDesc.count);i.setIndices(v)}if(s.subMeshesAttrDesc&&s.subMeshesAttrDesc.count>0){var y=new Int32Array(t,s.subMeshesAttrDesc.offset,5*s.subMeshesAttrDesc.count);i.subMeshes=[];for(var x=0;x>8),C.push((16711680&S)>>16),C.push(S>>24)}i.setVerticesData(e.VertexBuffer.MatricesIndicesKind,C,!1)}if(t.matricesIndicesExtra)if(t.matricesIndicesExtra._isExpanded)delete t.matricesIndices._isExpanded,i.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,t.matricesIndicesExtra,!1);else{for(var C=[],x=0;x>8),C.push((16711680&S)>>16),C.push(S>>24)}i.setVerticesData(e.VertexBuffer.MatricesIndicesExtraKind,C,!1)}t.matricesWeights&&i.setVerticesData(e.VertexBuffer.MatricesWeightsKind,t.matricesWeights,!1),t.matricesWeightsExtra&&i.setVerticesData(e.VertexBuffer.MatricesWeightsExtraKind,t.matricesWeightsExtra,!1),i.setIndices(t.indices)}if(t.subMeshes){i.subMeshes=[];for(var M=0;Mthis._maxX||tthis._maxZ)return this.position.y;this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var i=this._getFacetAt(e,t),r=-(i.x*e+i.z*t+i.w)/i.y;return r*this.scaling.y+this.position.y},i.prototype.getNormalAtCoordinates=function(t,i){var r=new e.Vector3(0,1,0);return this.getNormalAtCoordinatesToRef(t,i,r),r},i.prototype.getNormalAtCoordinatesToRef=function(e,t,i){if(e-=this.position.x,t-=this.position.z,e/=this.scaling.x,t/=this.scaling.z,!(ethis._maxX||tthis._maxZ)){this._heightQuads&&0!=this._heightQuads.length||(this._initHeightQuads(),this._computeHeightQuads());var r=this._getFacetAt(e,t);i.x=r.x,i.y=r.y,i.z=r.z}},i.prototype.updateCoordinateHeights=function(){this._heightQuads&&0!=this._heightQuads.length||this._initHeightQuads(),this._computeHeightQuads()},i.prototype._getFacetAt=function(e,t){var i,r=Math.floor((e+this._maxX)*this._subdivisions/this._width),n=Math.floor(-(t+this._maxZ)*this._subdivisions/this._height+this._subdivisions),o=this._heightQuads[n*this._subdivisions+r];return i=tt?e*(1-t/i):0},o&&(this.autoplay=o.autoplay||!1,this.loop=o.loop||!1,void 0!==o.volume&&(this._volume=o.volume),this.spatialSound=o.spatialSound||!1,this.maxDistance=o.maxDistance||100,this.useCustomAttenuation=o.useCustomAttenuation||!1,this.rolloffFactor=o.rolloffFactor||1,this.refDistance=o.refDistance||1,this.distanceModel=o.distanceModel||"linear",this._playbackRate=o.playbackRate||1,this._streaming=o.streaming||!1),e.Engine.audioEngine.canUseWebAudio?(this._soundGain=e.Engine.audioEngine.audioContext.createGain(),this._soundGain.gain.value=this._volume,this._inputAudioNode=this._soundGain,this._ouputAudioNode=this._soundGain,this.spatialSound&&this._createSpatialParameters(),this._scene.mainSoundTrack.AddSound(this),i&&("string"==typeof i?this._streaming?(this._htmlAudioElement=new Audio(i),this._htmlAudioElement.controls=!1,this._htmlAudioElement.loop=this.loop,this._htmlAudioElement.crossOrigin="anonymous",this._htmlAudioElement.preload="auto",this._htmlAudioElement.addEventListener("canplaythrough",function(){s._isReadyToPlay=!0,s.autoplay&&s.play(),s._readyToPlayCallback&&s._readyToPlayCallback()}),document.body.appendChild(this._htmlAudioElement)):e.Tools.LoadFile(i,function(e){s._soundLoaded(e)},null,this._scene.database,!0):i instanceof ArrayBuffer?i.byteLength>0&&this._soundLoaded(i):e.Tools.Error("Parameter must be a URL to the sound or an ArrayBuffer of the sound."))):(this._scene.mainSoundTrack.AddSound(this),e.Engine.audioEngine.WarnedWebAudioUnsupported||(e.Tools.Error("Web Audio is not supported by your browser."),e.Engine.audioEngine.WarnedWebAudioUnsupported=!0),this._readyToPlayCallback&&window.setTimeout(function(){s._readyToPlayCallback()},1e3))}return t.prototype.dispose=function(){e.Engine.audioEngine.canUseWebAudio&&this._isReadyToPlay&&(this.isPlaying&&this.stop(),this._isReadyToPlay=!1,-1===this.soundTrackId?this._scene.mainSoundTrack.RemoveSound(this):this._scene.soundTracks[this.soundTrackId].RemoveSound(this),this._soundGain&&(this._soundGain.disconnect(),this._soundGain=null),this._soundPanner&&(this._soundPanner.disconnect(),this._soundPanner=null),this._soundSource&&(this._soundSource.disconnect(),this._soundSource=null),this._audioBuffer=null,this._htmlAudioElement&&(this._htmlAudioElement.pause(),this._htmlAudioElement.src="",document.body.removeChild(this._htmlAudioElement)),this._connectedMesh&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._connectedMesh=null))},t.prototype._soundLoaded=function(t){var i=this;this._isLoaded=!0,e.Engine.audioEngine.audioContext.decodeAudioData(t,function(e){i._audioBuffer=e,i._isReadyToPlay=!0,i.autoplay&&i.play(),i._readyToPlayCallback&&i._readyToPlayCallback()},function(){e.Tools.Error("Error while decoding audio data for: "+i.name)})},t.prototype.setAudioBuffer=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._audioBuffer=t,this._isReadyToPlay=!0)},t.prototype.updateOptions=function(e){e&&(this.loop=e.loop||this.loop,this.maxDistance=e.maxDistance||this.maxDistance,this.useCustomAttenuation=e.useCustomAttenuation||this.useCustomAttenuation,this.rolloffFactor=e.rolloffFactor||this.rolloffFactor,this.refDistance=e.refDistance||this.refDistance,this.distanceModel=e.distanceModel||this.distanceModel,this._playbackRate=e.playbackRate||this._playbackRate,this._updateSpatialParameters(),this.isPlaying&&(this._streaming?this._htmlAudioElement.playbackRate=this._playbackRate:this._soundSource.playbackRate.value=this._playbackRate))},t.prototype._createSpatialParameters=function(){e.Engine.audioEngine.canUseWebAudio&&(this._scene.headphone&&(this._panningModel="HRTF"),this._soundPanner=e.Engine.audioEngine.audioContext.createPanner(),this._updateSpatialParameters(),this._soundPanner.connect(this._ouputAudioNode),this._inputAudioNode=this._soundPanner)},t.prototype._updateSpatialParameters=function(){this.spatialSound&&(this.useCustomAttenuation?(this._soundPanner.distanceModel="linear",this._soundPanner.maxDistance=Number.MAX_VALUE,this._soundPanner.refDistance=1,this._soundPanner.rolloffFactor=1,this._soundPanner.panningModel=this._panningModel):(this._soundPanner.distanceModel=this.distanceModel,this._soundPanner.maxDistance=this.maxDistance,this._soundPanner.refDistance=this.refDistance,this._soundPanner.rolloffFactor=this.rolloffFactor,this._soundPanner.panningModel=this._panningModel))},t.prototype.switchPanningModelToHRTF=function(){this._panningModel="HRTF",this._switchPanningModel()},t.prototype.switchPanningModelToEqualPower=function(){this._panningModel="equalpower",this._switchPanningModel()},t.prototype._switchPanningModel=function(){e.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&(this._soundPanner.panningModel=this._panningModel)},t.prototype.connectToSoundTrackAudioNode=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._isOutputConnected&&this._ouputAudioNode.disconnect(),this._ouputAudioNode.connect(t),this._isOutputConnected=!0)},t.prototype.setDirectionalCone=function(t,i,r){return t>i?void e.Tools.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle."):(this._coneInnerAngle=t,this._coneOuterAngle=i,this._coneOuterGain=r,this._isDirectional=!0,void(this.isPlaying&&this.loop&&(this.stop(),this.play())))},t.prototype.setPosition=function(t){this._position=t,e.Engine.audioEngine.canUseWebAudio&&this.spatialSound&&this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z)},t.prototype.setLocalDirectionToMesh=function(t){this._localDirection=t,e.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.isPlaying&&this._updateDirection()},t.prototype._updateDirection=function(){var t=this._connectedMesh.getWorldMatrix(),i=e.Vector3.TransformNormal(this._localDirection,t);i.normalize(),this._soundPanner.setOrientation(i.x,i.y,i.z)},t.prototype.updateDistanceFromListener=function(){if(e.Engine.audioEngine.canUseWebAudio&&this._connectedMesh&&this.useCustomAttenuation){var t=this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);this._soundGain.gain.value=this._customAttenuationFunction(this._volume,t,this.maxDistance,this.refDistance,this.rolloffFactor)}},t.prototype.setAttenuationFunction=function(e){this._customAttenuationFunction=e},t.prototype.play=function(t){var i=this;if(this._isReadyToPlay&&this._scene.audioEnabled)try{this._startOffset<0&&(t=-this._startOffset,this._startOffset=0);var r=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;this._soundSource&&this._streamingSource||this.spatialSound&&(this._soundPanner.setPosition(this._position.x,this._position.y,this._position.z),this._isDirectional&&(this._soundPanner.coneInnerAngle=this._coneInnerAngle,this._soundPanner.coneOuterAngle=this._coneOuterAngle,this._soundPanner.coneOuterGain=this._coneOuterGain,this._connectedMesh?this._updateDirection():this._soundPanner.setOrientation(this._localDirection.x,this._localDirection.y,this._localDirection.z))),this._streaming?(this._streamingSource||(this._streamingSource=e.Engine.audioEngine.audioContext.createMediaElementSource(this._htmlAudioElement),this._htmlAudioElement.onended=function(){i._onended()},this._htmlAudioElement.playbackRate=this._playbackRate),this._streamingSource.disconnect(),this._streamingSource.connect(this._inputAudioNode),this._htmlAudioElement.play()):(this._soundSource=e.Engine.audioEngine.audioContext.createBufferSource(),this._soundSource.buffer=this._audioBuffer,this._soundSource.connect(this._inputAudioNode),this._soundSource.loop=this.loop,this._soundSource.playbackRate.value=this._playbackRate,this._soundSource.onended=function(){i._onended()},this._soundSource.start(r,this.isPaused?this._startOffset%this._soundSource.buffer.duration:0)),this._startTime=r,this.isPlaying=!0,this.isPaused=!1}catch(n){e.Tools.Error("Error while trying to play audio: "+this.name+", "+n.message)}},t.prototype._onended=function(){this.isPlaying=!1,this.onended&&this.onended()},t.prototype.stop=function(t){if(this.isPlaying){if(this._streaming)this._htmlAudioElement.pause(),this._htmlAudioElement.currentTime>0&&(this._htmlAudioElement.currentTime=0);else{var i=t?e.Engine.audioEngine.audioContext.currentTime+t:e.Engine.audioEngine.audioContext.currentTime;this._soundSource.stop(i),this._soundSource.onended=null,this.isPaused||(this._startOffset=0)}this.isPlaying=!1}},t.prototype.pause=function(){this.isPlaying&&(this.isPaused=!0,this._streaming?this._htmlAudioElement.pause():(this.stop(0),this._startOffset+=e.Engine.audioEngine.audioContext.currentTime-this._startTime))},t.prototype.setVolume=function(t,i){e.Engine.audioEngine.canUseWebAudio&&(i?(this._soundGain.gain.cancelScheduledValues(e.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.setValueAtTime(this._soundGain.gain.value,e.Engine.audioEngine.audioContext.currentTime),this._soundGain.gain.linearRampToValueAtTime(t,e.Engine.audioEngine.audioContext.currentTime+i)):this._soundGain.gain.value=t),this._volume=t},t.prototype.setPlaybackRate=function(e){this._playbackRate=e,this.isPlaying&&(this._streaming?this._htmlAudioElement.playbackRate=this._playbackRate:this._soundSource.playbackRate.value=this._playbackRate)},t.prototype.getVolume=function(){return this._volume},t.prototype.attachToMesh=function(e){var t=this;this._connectedMesh&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._registerFunc=null),this._connectedMesh=e,this.spatialSound||(this.spatialSound=!0,this._createSpatialParameters(),this.isPlaying&&this.loop&&(this.stop(),this.play())),this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh),this._registerFunc=function(e){return t._onRegisterAfterWorldMatrixUpdate(e)},e.registerAfterWorldMatrixUpdate(this._registerFunc)},t.prototype.detachFromMesh=function(){this._connectedMesh&&(this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc),this._registerFunc=null,this._connectedMesh=null)},t.prototype._onRegisterAfterWorldMatrixUpdate=function(t){this.setPosition(t.getBoundingInfo().boundingSphere.centerWorld),e.Engine.audioEngine.canUseWebAudio&&this._isDirectional&&this.isPlaying&&this._updateDirection()},t.prototype.clone=function(){var e=this;if(this._streaming)return null;var i=function(){e._isReadyToPlay?(n._audioBuffer=e.getAudioBuffer(),n._isReadyToPlay=!0,n.autoplay&&n.play()):window.setTimeout(i,300)},r={autoplay:this.autoplay,loop:this.loop,volume:this._volume,spatialSound:this.spatialSound,maxDistance:this.maxDistance,useCustomAttenuation:this.useCustomAttenuation,rolloffFactor:this.rolloffFactor,refDistance:this.refDistance,distanceModel:this.distanceModel},n=new t(this.name+"_cloned",new ArrayBuffer(0),this._scene,null,r);return this.useCustomAttenuation&&n.setAttenuationFunction(this._customAttenuationFunction),n.setPosition(this._position),n.setPlaybackRate(this._playbackRate),i(),n},t.prototype.getAudioBuffer=function(){return this._audioBuffer},t.Parse=function(i,r,n,o){var s,a=i.name;s=i.url?n+i.url:n+a;var h,c={autoplay:i.autoplay,loop:i.loop,volume:i.volume,spatialSound:i.spatialSound,maxDistance:i.maxDistance,rolloffFactor:i.rolloffFactor,refDistance:i.refDistance,distanceModel:i.distanceModel,playbackRate:i.playbackRate};if(o){var l=function(){o._isReadyToPlay?(h._audioBuffer=o.getAudioBuffer(),h._isReadyToPlay=!0,h.autoplay&&h.play()):window.setTimeout(l,300)};h=new t(a,new ArrayBuffer(0),r,null,c),l()}else h=new t(a,s,r,function(){r._removePendingData(h)},c),r._addPendingData(h);if(i.position){var u=e.Vector3.FromArray(i.position);h.setPosition(u)}if(i.isDirectional&&(h.setDirectionalCone(i.coneInnerAngle||360,i.coneOuterAngle||360,i.coneOuterGain||0),i.localDirectionToMesh)){var f=e.Vector3.FromArray(i.localDirectionToMesh);h.setLocalDirectionToMesh(f)}if(i.connectedMeshId){var d=r.getMeshByID(i.connectedMeshId);d&&h.attachToMesh(d)}return h},t}();e.Sound=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function t(e,t){this.id=-1,this._isMainTrack=!1,this._isInitialized=!1,this._scene=e,this.soundCollection=new Array,this._options=t,this._isMainTrack||(this._scene.soundTracks.push(this),this.id=this._scene.soundTracks.length-1)}return t.prototype._initializeSoundTrackAudioGraph=function(){e.Engine.audioEngine.canUseWebAudio&&(this._outputAudioNode=e.Engine.audioEngine.audioContext.createGain(),this._outputAudioNode.connect(e.Engine.audioEngine.masterGain),this._options&&(this._options.volume&&(this._outputAudioNode.gain.value=this._options.volume),this._options.mainTrack&&(this._isMainTrack=this._options.mainTrack)),this._isInitialized=!0)},t.prototype.dispose=function(){if(e.Engine.audioEngine.canUseWebAudio){for(this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas();this.soundCollection.length;)this.soundCollection[0].dispose();this._outputAudioNode&&this._outputAudioNode.disconnect(),this._outputAudioNode=null}},t.prototype.AddSound=function(t){this._isInitialized||this._initializeSoundTrackAudioGraph(),e.Engine.audioEngine.canUseWebAudio&&t.connectToSoundTrackAudioNode(this._outputAudioNode),t.soundTrackId&&(-1===t.soundTrackId?this._scene.mainSoundTrack.RemoveSound(t):this._scene.soundTracks[t.soundTrackId].RemoveSound(t)),this.soundCollection.push(t),t.soundTrackId=this.id},t.prototype.RemoveSound=function(e){var t=this.soundCollection.indexOf(e);-1!==t&&this.soundCollection.splice(t,1)},t.prototype.setVolume=function(t){e.Engine.audioEngine.canUseWebAudio&&(this._outputAudioNode.gain.value=t)},t.prototype.switchPanningModelToHRTF=function(){if(e.Engine.audioEngine.canUseWebAudio)for(var t=0;tr;r++){var n=new t;n.offset=r*e,this._allEntries[r]=n,this._freeEntries[i-r-1]=n}}return e.prototype.allocElement=function(){0===this._freeEntries.length&&this._growBuffer();var e=this._freeEntries.pop();return this._lastUsed=Math.max(e.offset,this._lastUsed),e.offset===this._firstFree&&(this._freeEntries.length>0?this._firstFree=this._freeEntries[this._freeEntries.length-1].offset:this._firstFree+=this._stride),e},e.prototype.freeElement=function(e){this._firstFree=Math.min(e.offset,this._firstFree),this._freeEntries.push(e)},e.prototype.pack=function(){if(0===this._freeEntries.length)return this.buffer;if(this._lastUsed=h);l++){var u=n[l],f=u.offset,d=f-c;if(d!==i){for(var p=d/i-1,_=f-i,g=Math.min(a,p),m=0;g>m;m++){var v=s/i,y=_/i,x=o[y];this._moveElement(x,s);var b=o[v];b.offset=_,o[v]=x,o[y]=b,_-=i,s+=i}p>=a?(s=_+i,a=1+g):a=(f-s)/i+1,c=f}else++a,c=f}var P=this.buffer.subarray(0,s);return this._lastUsed=s-i,this._firstFree=s,n.pop(),this._freeEntries=n.sort(function(e,t){return t.offset-e.offset}),this._allEntries=o,P},e.prototype._moveElement=function(e,t){for(var i=0;io;o++){var s=new t;s.offset=(r+o)*this.stride,this._allEntries.push(s),this._freeEntries[n-o-1]=s}this._firstFree=r*this.stride,this.buffer=i},Object.defineProperty(e.prototype,"totalElementCount",{get:function(){return this._allEntries.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"freeElementCount",{get:function(){return this._freeEntries.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"usedElementCount",{get:function(){return this._allEntries.length-this._freeEntries.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stride",{get:function(){return this._stride},enumerable:!0,configurable:!0}),e.prototype.sort=function(){var e=this;if(!this.compareValueOffset)throw new Error("The DynamicFloatArray.sort() method needs a valid 'compareValueOffset' property");var t=this.usedElementCount;if(!this._sortTable||this._sortTable.lengths;s++,n+=o){var a=this._sortTable[s];a||(a=new r,this._sortTable[s]=a),a.compareData=this.buffer[n+this.compareValueOffset],a.offset=n,a.swapedOffset=null,this._sortedTable[s]=a}this.sortingAscending?this._sortedTable.sort(function(e,t){return e.compareData-t.compareData}):this._sortedTable.sort(function(e,t){return t.compareData-e.compareData});for(var h=function(t,i){for(var r=0;o>r;r++){var n=e.buffer[i+r];e.buffer[i+r]=e.buffer[t+r],e.buffer[t+r]=n}},s=0;t>s;s++){var c=this._sortedTable[s],l=this._sortTable[s],u=c.offset;if(c.swapedOffset){for(var f=c;f.swapedOffset;)f=this._sortTable[f.swapedOffset/o];u=f.offset}l.swapedOffset=u,u!==l.offset&&h(u,l.offset),this._allEntries[c.offset/o].offset=l.offset}return this._allEntries.sort(function(e,t){return e.offset-t.offset}),!0},e}();e.DynamicFloatArray=i;var r=function(){function e(){this.compareData=this.offset=this.swapedOffset=null}return e}()}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){}return e}();e.CharInfo=t;var i=function(i){function r(t,r,n,o,s){void 0===o&&(o=200),void 0===s&&(s=e.Texture.TRILINEAR_SAMPLINGMODE),i.call(this,null,n,!0,!1,s),this._charInfos={},this._curCharCount=0,this._lastUpdateCharCount=-1,this._usedCounter=1,this.name=t,this.wrapU=e.Texture.CLAMP_ADDRESSMODE,this.wrapV=e.Texture.CLAMP_ADDRESSMODE,this._canvas=document.createElement("canvas"),this._context=this._canvas.getContext("2d"),this._context.font=r,this._context.fillStyle="white";var a=this.getFontHeight(r);this._lineHeight=a.height,this._offset=a.offset-1;var h=this._context.measureText("W").width;this._spaceWidth=this._context.measureText(" ").width;var c=this._lineHeight*h*o,l=Math.sqrt(c),u=Math.pow(2,Math.ceil(Math.log(l)/Math.log(2)));this._texture=n.getEngine().createDynamicTexture(u,u,!1,s);var f=this.getSize();this._canvas=document.createElement("canvas"),this._canvas.width=f.width,this._canvas.height=f.height,this._context=this._canvas.getContext("2d"),this._context.textBaseline="top",this._context.font=r,this._context.fillStyle="white",this._context.imageSmoothingEnabled=!1,this._currentFreePosition=e.Vector2.Zero();for(var d=32;127>d;d++){var p=String.fromCharCode(d);this.getChar(p)}this.update()}return __extends(r,i),Object.defineProperty(r.prototype,"spaceWidth",{get:function(){return this._spaceWidth},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"lineHeight",{get:function(){return this._lineHeight},enumerable:!0,configurable:!0}),r.GetCachedFontTexture=function(t,i){var n=t;n.__fontTextureCache__||(n.__fontTextureCache__=new e.StringDictionary);var o=n.__fontTextureCache__,s=i.toLocaleLowerCase(),a=o.get(s);return a?(++a._usedCounter,a):(a=new r(null,s,t,200,e.Texture.NEAREST_SAMPLINGMODE),o.add(s,a),a)},r.ReleaseCachedFontTexture=function(e,t){var i=e,r=i.__fontTextureCache__;if(r){var n=t.toLocaleLowerCase(),o=r.get(n);0===--o._usedCounter&&(r.remove(n),o.dispose())}},r.prototype.getChar=function(i){if(1!==i.length)return null;var r=this._charInfos[i];if(r)return r;r=new t;var n=this._context.measureText(i),o=this.getSize(),s=2,a=2,h=n.width;return this._currentFreePosition.x+h+s>o.width&&(this._currentFreePosition.x=0,this._currentFreePosition.y+=this._lineHeight+a,this._currentFreePosition.y>o.height)?this.getChar("!"):(this._context.fillText(i,this._currentFreePosition.x-.5,this._currentFreePosition.y-this._offset-.5),r.topLeftUV=new e.Vector2(this._currentFreePosition.x/o.width,this._currentFreePosition.y/o.height),r.bottomRightUV=new e.Vector2(r.topLeftUV.x+h/o.width,r.topLeftUV.y+(this._lineHeight+2)/o.height),r.charWidth=h,this._charInfos[i]=r,this._curCharCount++,this._currentFreePosition.x+=h+s,r)},r.prototype.measureText=function(t,i){void 0===i&&(i=4);for(var r=0,n=0,o=1,s=0,a=0;ah||(n+=this.getChar(h).charWidth,++s);else{var c=s+i;c-=c%i,n+=(c-s)*this.spaceWidth,s=c}else r=Math.max(r,n),s=0,n=0,++o}return r=Math.max(r,n),new e.Size(r,o*this._lineHeight)},r.prototype.getFontHeight=function(e){var t=document.createElement("canvas"),i=t.getContext("2d");i.fillRect(0,0,t.width,t.height),i.textBaseline="top",i.fillStyle="white",i.font=e,i.fillText("jH|",0,0);for(var r=i.getImageData(0,0,t.width,t.height).data,n=-1,o=-1,s=0;so;o++)e.Vector2.TransformToRef(n[o],i,n[o]);t.CreateFromPointsToRef(n,r)},t.prototype.unionToRef=function(e,i){var r=Math.max(this.center.x+this.extent.x,e.center.x+e.extent.x),n=Math.max(this.center.y+this.extent.y,e.center.y+e.extent.y),o=Math.min(this.center.x-this.extent.x,e.center.x-e.extent.x),s=Math.min(this.center.y-this.extent.y,e.center.y-e.extent.y);t.CreateFromMinMaxToRef(o,r,s,n,i)},t.prototype.doesIntersect=function(e){var t=e.subtract(this.center);return t.lengthSquared()<=this.radius*this.radius?Math.abs(t.x)<=this.extent.x&&Math.abs(t.y)<=this.extent.y:!1},t._transform=new Array(e.Vector2.Zero(),e.Vector2.Zero(),e.Vector2.Zero(),e.Vector2.Zero()),t}();e.BoundingInfo2D=t}(BABYLON||(BABYLON={}));var BABYLON;!function(e){var t=function(){function e(){}return e.prototype.isLocked=function(){return this._isLocked},e.prototype.lock=function(){return this._isLocked?!0:(this.onLock(),this._isLocked=!0,!1)},e.prototype.onLock=function(){},e}();e.LockableBase=t;var i=function(t){function i(e,i){void 0===i&&(i=!1),t.call(this),this._color=e,i&&this.lock()}return __extends(i,t),i.prototype.isTransparent=function(){return this._color&&this._color.a<1},Object.defineProperty(i.prototype,"color",{get:function(){return this._color},set:function(e){this.isLocked()||(this._color=e)},enumerable:!0,configurable:!0}),i.prototype.toString=function(){return this._color.toHexString()},i=__decorate([e.className("SolidColorBrush2D")],i)}(t);e.SolidColorBrush2D=i;var r=function(t){function i(i,r,n,o,s,a){void 0===n&&(n=e.Vector2.Zero()),void 0===o&&(o=0),void 0===s&&(s=1),void 0===a&&(a=!1),t.call(this),this._color1=i,this._color2=r,this._translation=n,this._rotation=o,this._scale=s,a&&this.lock()}return __extends(i,t),i.prototype.isTransparent=function(){return this._color1&&this._color1.a<1||this._color2&&this._color2.a<1},Object.defineProperty(i.prototype,"color1",{get:function(){return this._color1},set:function(e){this.isLocked()||(this._color1=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"color2",{get:function(){return this._color2},set:function(e){this.isLocked()||(this._color2=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"translation",{get:function(){return this._translation},set:function(e){this.isLocked()||(this._translation=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"rotation",{get:function(){return this._rotation},set:function(e){this.isLocked()||(this._rotation=e)},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"scale",{get:function(){return this._scale},set:function(e){this.isLocked()||(this._scale=e)},enumerable:!0,configurable:!0}),i.prototype.toString=function(){return"C1:"+this._color1+";C2:"+this._color2+";T:"+this._translation.toString()+";R:"+this._rotation+";S:"+this._scale+";"},i.BuildKey=function(e,t,i,r,n){return"C1:"+e+";C2:"+t+";T:"+i.toString()+";R:"+r+";S:"+n+";"},i=__decorate([e.className("GradientColorBrush2D")],i)}(t);e.GradientColorBrush2D=r}(BABYLON||(BABYLON={}));var BABYLON;!function(e){function t(e,t,i,r){return void 0===i&&(i=!1),void 0===r&&(r=!1),h._hookProperty(e,t,i,r,o.PROPKIND_MODEL)}function i(e,t,i,r){return void 0===i&&(i=!1),void 0===r&&(r=!1),h._hookProperty(e,t,i,r,o.PROPKIND_INSTANCE)}function r(e,t,i,r){return void 0===i&&(i=!1),void 0===r&&(r=!1),h._hookProperty(e,t,i,r,o.PROPKIND_DYNAMIC)}var n=function(){function e(){}return e}();e.Prim2DClassInfo=n;var o=function(){function e(){}return e.PROPKIND_MODEL=1,e.PROPKIND_INSTANCE=2,e.PROPKIND_DYNAMIC=3,e}();e.Prim2DPropInfo=o;var s=function(){function e(){}return e}();e.PropertyChangedInfo=s;var a=function(){function t(t,i,r){this._baseClass=t,this._type=i,this._subClasses=new Array,this._levelContent=new e.StringDictionary,this._classContentFactory=r}return Object.defineProperty(t.prototype,"classContent",{get:function(){return this._classContent||(this._classContent=this._classContentFactory(this._baseClass?this._baseClass.classContent:null)),this._classContent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"type",{get:function(){return this._type},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"levelContent",{get:function(){return this._levelContent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"fullContent",{get:function(){if(!this._fullContent){for(var t=new e.StringDictionary,i=this;i;)i.levelContent.forEach(function(e,i){return t.add(e,i)}),i=i._baseClass;this._fullContent=t}return this._fullContent},enumerable:!0,configurable:!0}),t.prototype.getLevelOf=function(e){if(e===this._type)return this;var t=Object.getPrototypeOf(e),i=this.getOrAddType(Object.getPrototypeOf(t),t);return i||this.getLevelOf(t),this.getOrAddType(t,e)},t.prototype.getOrAddType=function(e,i){if(e===this._type){for(var r=0,n=this._subClasses;r, left: