diff --git a/jsmodeler/jsmodeler.js b/jsmodeler/jsmodeler.js index 99deac9..69ec743 100644 --- a/jsmodeler/jsmodeler.js +++ b/jsmodeler/jsmodeler.js @@ -1,7 +1,7 @@ /* JSModeler 0.43 - http://www.github.com/kovacsv/JSModeler */ 'use strict';var JSM=function(){this.mainVersion=0;this.subVersion=43};JSM.RandomNumber=function(a,b){return Math.random()*(b-a)+a};JSM.RandomInt=function(a,b){return Math.floor(Math.random()*(b-a+1)+a)};JSM.RandomBoolean=function(){return 1===JSM.RandomInt(0,1)};JSM.SeededRandomInt=function(a,b,c){return Math.floor((9301*c+49297)%233280/233280*(b-a+1)+a)};JSM.ValueOrDefault=function(a,b){return void 0===a||null===a?b:a};JSM.PrevIndex=function(a,b){return 0=a&&(this.current=1E3*(this.frames/c),this.start=b,this.frames=0);return parseInt(this.current,10)};JSM.SwapArrayValues=function(a,b,c){var d=a[b];a[b]=a[c];a[c]=d}; -JSM.BubbleSort=function(a,b,c){if(2>a.length||void 0===b||null===b)return!1;if(void 0===c||null===c)c=function(b,c){JSM.SwapArrayValues(a,b,c)};var d,e;for(d=0;d=a&&(this.current=1E3*(this.frames/c),this.start=b,this.frames=0);return parseInt(this.current,10)}; +JSM.SwapArrayValues=function(a,b,c){var d=a[b];a[b]=a[c];a[c]=d};JSM.BubbleSort=function(a,b,c){if(2>a.length||void 0===b||null===b)return!1;if(void 0===c||null===c)c=function(b,c){JSM.SwapArrayValues(a,b,c)};var d,e;for(d=0;dJSM.Eps};JSM.IsNegative=function(a){return a<-JSM.Eps};JSM.IsLower=function(a,b){return b-a>JSM.Eps}; @@ -17,7 +17,7 @@ JSM.Coord.prototype.MultiplyScalar=function(a){this.x*=a;this.y*=a;this.z*=a;ret JSM.Coord.prototype.Rotate=function(a,b,c){var d=a.Clone().Normalize();a=d.x;var e=d.y,d=d.z,f=this.x-c.x,g=this.y-c.y,h=this.z-c.z,k=Math.sin(b);b=Math.cos(b);this.x=-a*(-a*f-e*g-d*h)*(1-b)+f*b+(-d*g+e*h)*k;this.y=-e*(-a*f-e*g-d*h)*(1-b)+g*b+(d*f-a*h)*k;this.z=-d*(-a*f-e*g-d*h)*(1-b)+h*b+(-e*f+a*g)*k;this.x+=c.x;this.y+=c.y;this.z+=c.z;return this}; JSM.Coord.prototype.ToCoord2D=function(a){var b=new JSM.Coord(0,0,0),c=new JSM.Vector(0,0,1),d=JSM.VectorCross(a,c);a=a.AngleTo(c);b=this.Clone().Rotate(d,a,b);return new JSM.Coord2D(b.x,b.y)};JSM.Coord.prototype.ToString=function(){return"("+this.x+", "+this.y+", "+this.z+")"};JSM.Coord.prototype.Clone=function(){return new JSM.Coord(this.x,this.y,this.z)};JSM.Vector=JSM.Coord;JSM.CoordFromArray=function(a){return new JSM.Coord(a[0],a[1],a[2])};JSM.CoordToArray=function(a){return[a.x,a.y,a.z]}; JSM.CoordAdd=function(a,b){return new JSM.Coord(a.x+b.x,a.y+b.y,a.z+b.z)};JSM.CoordSub=function(a,b){return new JSM.Coord(a.x-b.x,a.y-b.y,a.z-b.z)};JSM.VectorDot=function(a,b){return a.x*b.x+a.y*b.y+a.z*b.z};JSM.VectorCross=function(a,b){var c=new JSM.Vector(0,0,0);c.x=a.y*b.z-a.z*b.y;c.y=a.z*b.x-a.x*b.z;c.z=a.x*b.y-a.y*b.x;return c};JSM.MatrixDeterminant2x2=function(a,b,c,d){return a*d-b*c}; -JSM.MatrixDeterminant3x3=function(a,b,c,d,e,f,g,h,k){var l=JSM.MatrixDeterminant2x2(e,f,h,k);f=JSM.MatrixDeterminant2x2(d,f,g,k);d=JSM.MatrixDeterminant2x2(d,e,g,h);return a*l-b*f+c*d};JSM.MatrixDeterminant4x4=function(a,b,c,d,e,f,g,h,k,l,m,n,p,q,r,s){var v=JSM.MatrixDeterminant3x3(f,g,h,l,m,n,q,r,s),u=JSM.MatrixDeterminant3x3(e,g,h,k,m,n,p,r,s);h=JSM.MatrixDeterminant3x3(e,f,h,k,l,n,p,q,s);e=JSM.MatrixDeterminant3x3(e,f,g,k,l,m,p,q,r);return v*a-u*b+h*c-e*d}; +JSM.MatrixDeterminant3x3=function(a,b,c,d,e,f,g,h,k){var l=JSM.MatrixDeterminant2x2(e,f,h,k);f=JSM.MatrixDeterminant2x2(d,f,g,k);d=JSM.MatrixDeterminant2x2(d,e,g,h);return a*l-b*f+c*d};JSM.MatrixDeterminant4x4=function(a,b,c,d,e,f,g,h,k,l,m,n,q,p,r,s){var v=JSM.MatrixDeterminant3x3(f,g,h,l,m,n,p,r,s),u=JSM.MatrixDeterminant3x3(e,g,h,k,m,n,q,r,s);h=JSM.MatrixDeterminant3x3(e,f,h,k,l,n,q,p,s);e=JSM.MatrixDeterminant3x3(e,f,g,k,l,m,q,p,r);return v*a-u*b+h*c-e*d}; JSM.Orientation={Invalid:0,CounterClockwise:1,Clockwise:2};JSM.MidCoord2D=function(a,b){return new JSM.Coord2D((a.x+b.x)/2,(a.y+b.y)/2)};JSM.CoordOrientation2D=function(a,b,c){var d=a.x;a=a.y;var e=b.x;b=b.y;var f=c.x;c=c.y;d=d*b+a*f+e*c-b*f-a*e-d*c;return JSM.IsPositive(d)?JSM.Orientation.CounterClockwise:JSM.IsNegative(d)?JSM.Orientation.Clockwise:JSM.Orientation.Invalid}; JSM.CoordSignedDistance2D=function(a,b,c){var d=JSM.CoordSub2D(b,a);a=a.DistanceTo(b);c=d.AngleTo(c);JSM.IsPositive(c)&&(a=-a);return a};JSM.PolarToCartesian=function(a,b){var c=new JSM.Coord2D(0,0);c.x=a*Math.cos(b);c.y=a*Math.sin(b);return c};JSM.GetArcLengthFromAngle=function(a,b){return b*a};JSM.GetAngleFromArcLength=function(a,b){return JSM.IsEqual(a,0)?0:b/a};JSM.MidCoord=function(a,b){return new JSM.Coord((a.x+b.x)/2,(a.y+b.y)/2,(a.z+b.z)/2)}; JSM.CoordSignedDistance=function(a,b,c){var d=JSM.CoordSub(b,a);a=a.DistanceTo(b);c=d.AngleTo(c);JSM.IsPositive(c)&&(a=-a);return a};JSM.GetVectorsFullAngle=function(a,b,c){var d=a.AngleTo(b),e=new JSM.Coord(0,0,0);JSM.CoordOrientation(a,e,b,c)==JSM.Orientation.Clockwise&&(d=2*Math.PI-d);return d}; @@ -26,11 +26,11 @@ JSM.CylindricalToCartesian=function(a,b,c){var d=new JSM.Coord(0,0,0);d.x=a*Math JSM.CalculateTriangleNormal=function(a,b,c){b=JSM.CoordSub(b,a);a=JSM.CoordSub(c,a);c=new JSM.Vector(0,0,0);c.x=b.y*a.z-b.z*a.y;c.y=b.z*a.x-b.x*a.z;c.z=b.x*a.y-b.y*a.x;c.Normalize();return c};JSM.CalculateNormal=function(a){var b=a.length,c=new JSM.Vector(0,0,0);if(3<=b){var d,e,f;for(d=0;da?0:Math.sqrt(a)}var k=a.DistanceTo(b),l=b.DistanceTo(c),m=c.DistanceTo(a);a=a.DistanceTo(g);b=b.DistanceTo(g);g=c.DistanceTo(g);c=h(k,l,m);if(JSM.IsZero(c))return d;k=h(k,a,b);l=h(l,b,g);m=h(m,a,g);d=d.Clone().MultiplyScalar(l);e=e.Clone().MultiplyScalar(m);f=f.Clone().MultiplyScalar(k);f=JSM.CoordAdd(JSM.CoordAdd(d,e),f);f.MultiplyScalar(1/c);return f}; JSM.MatrixIdentity=function(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]};JSM.MatrixClone=function(a){var b=[];b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];b[13]=a[13];b[14]=a[14];b[15]=a[15];return b}; -JSM.MatrixTranspose=function(a){var b=[];b[0]=a[0];b[1]=a[4];b[2]=a[8];b[3]=a[12];b[4]=a[1];b[5]=a[5];b[6]=a[9];b[7]=a[13];b[8]=a[2];b[9]=a[6];b[10]=a[10];b[11]=a[14];b[12]=a[3];b[13]=a[7];b[14]=a[11];b[15]=a[15];return b};JSM.MatrixVectorMultiply=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=a[1],h=a[2],k=a[3],l=a[5],m=a[6],n=a[7],p=a[9],q=a[10],r=a[11],s=a[13],v=a[14],u=a[15],t=[];t[0]=c*a[0]+d*a[4]+e*a[8]+f*a[12];t[1]=c*g+d*l+e*p+f*s;t[2]=c*h+d*m+e*q+f*v;t[3]=c*k+d*n+e*r+f*u;return t}; -JSM.MatrixMultiply=function(a,b){var c=a[0],d=a[1],e=a[2],f=a[3],g=a[4],h=a[5],k=a[6],l=a[7],m=a[8],n=a[9],p=a[10],q=a[11],r=a[12],s=a[13],v=a[14],u=a[15],t=b[0],w=b[1],A=b[2],B=b[3],x=b[4],y=b[5],z=b[6],E=b[7],H=b[8],I=b[9],D=b[10],C=b[11],K=b[12],L=b[13],F=b[14],J=b[15],G=[];G[0]=c*t+d*x+e*H+f*K;G[1]=c*w+d*y+e*I+f*L;G[2]=c*A+d*z+e*D+f*F;G[3]=c*B+d*E+e*C+f*J;G[4]=g*t+h*x+k*H+l*K;G[5]=g*w+h*y+k*I+l*L;G[6]=g*A+h*z+k*D+l*F;G[7]=g*B+h*E+k*C+l*J;G[8]=m*t+n*x+p*H+q*K;G[9]=m*w+n*y+p*I+q*L;G[10]=m*A+n*z+ -p*D+q*F;G[11]=m*B+n*E+p*C+q*J;G[12]=r*t+s*x+v*H+u*K;G[13]=r*w+s*y+v*I+u*L;G[14]=r*A+s*z+v*D+u*F;G[15]=r*B+s*E+v*C+u*J;return G};JSM.MatrixDeterminant=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],k=a[7],l=a[8],m=a[9],n=a[10],p=a[11],q=a[12],r=a[13],s=a[14];a=a[15];return(b*g-c*f)*(n*a-p*s)-(b*h-d*f)*(m*a-p*r)+(b*k-e*f)*(m*s-n*r)+(c*h-d*g)*(l*a-p*q)-(c*k-e*g)*(l*s-n*q)+(d*k-e*h)*(l*r-m*q)}; -JSM.MatrixInvert=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],k=a[7],l=a[8],m=a[9],n=a[10],p=a[11],q=a[12],r=a[13],s=a[14];a=a[15];var v=b*g-c*f,u=b*h-d*f,t=b*k-e*f,w=c*h-d*g,A=c*k-e*g,B=d*k-e*h,x=l*r-m*q,y=l*s-n*q,z=l*a-p*q,E=m*s-n*r,H=m*a-p*r,I=n*a-p*s,D=v*I-u*H+t*E+w*z-A*y+B*x;if(JSM.IsZero(D))return null;var C=[];C[0]=(g*I-h*H+k*E)/D;C[1]=(d*H-c*I-e*E)/D;C[2]=(r*B-s*A+a*w)/D;C[3]=(n*A-m*B-p*w)/D;C[4]=(h*z-f*I-k*y)/D;C[5]=(b*I-d*z+e*y)/D;C[6]=(s*t-q*B-a*u)/D;C[7]=(l*B-n*t+p* -u)/D;C[8]=(f*H-g*z+k*x)/D;C[9]=(c*z-b*H-e*x)/D;C[10]=(q*A-r*t+a*v)/D;C[11]=(m*t-l*A-p*v)/D;C[12]=(g*y-f*E-h*x)/D;C[13]=(b*E-c*y+d*x)/D;C[14]=(r*u-q*w-s*v)/D;C[15]=(l*w-m*u+n*v)/D;return C};JSM.MatrixTranslation=function(a,b,c){var d=[1,0,0,0,0,1,0,0,0,0,1,0];d[12]=a;d[13]=b;d[14]=c;d[15]=1;return d}; +JSM.MatrixTranspose=function(a){var b=[];b[0]=a[0];b[1]=a[4];b[2]=a[8];b[3]=a[12];b[4]=a[1];b[5]=a[5];b[6]=a[9];b[7]=a[13];b[8]=a[2];b[9]=a[6];b[10]=a[10];b[11]=a[14];b[12]=a[3];b[13]=a[7];b[14]=a[11];b[15]=a[15];return b};JSM.MatrixVectorMultiply=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=a[1],h=a[2],k=a[3],l=a[5],m=a[6],n=a[7],q=a[9],p=a[10],r=a[11],s=a[13],v=a[14],u=a[15],t=[];t[0]=c*a[0]+d*a[4]+e*a[8]+f*a[12];t[1]=c*g+d*l+e*q+f*s;t[2]=c*h+d*m+e*p+f*v;t[3]=c*k+d*n+e*r+f*u;return t}; +JSM.MatrixMultiply=function(a,b){var c=a[0],d=a[1],e=a[2],f=a[3],g=a[4],h=a[5],k=a[6],l=a[7],m=a[8],n=a[9],q=a[10],p=a[11],r=a[12],s=a[13],v=a[14],u=a[15],t=b[0],y=b[1],B=b[2],C=b[3],w=b[4],x=b[5],A=b[6],E=b[7],G=b[8],H=b[9],z=b[10],D=b[11],K=b[12],L=b[13],F=b[14],J=b[15],I=[];I[0]=c*t+d*w+e*G+f*K;I[1]=c*y+d*x+e*H+f*L;I[2]=c*B+d*A+e*z+f*F;I[3]=c*C+d*E+e*D+f*J;I[4]=g*t+h*w+k*G+l*K;I[5]=g*y+h*x+k*H+l*L;I[6]=g*B+h*A+k*z+l*F;I[7]=g*C+h*E+k*D+l*J;I[8]=m*t+n*w+q*G+p*K;I[9]=m*y+n*x+q*H+p*L;I[10]=m*B+n*A+ +q*z+p*F;I[11]=m*C+n*E+q*D+p*J;I[12]=r*t+s*w+v*G+u*K;I[13]=r*y+s*x+v*H+u*L;I[14]=r*B+s*A+v*z+u*F;I[15]=r*C+s*E+v*D+u*J;return I};JSM.MatrixDeterminant=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],k=a[7],l=a[8],m=a[9],n=a[10],q=a[11],p=a[12],r=a[13],s=a[14];a=a[15];return(b*g-c*f)*(n*a-q*s)-(b*h-d*f)*(m*a-q*r)+(b*k-e*f)*(m*s-n*r)+(c*h-d*g)*(l*a-q*p)-(c*k-e*g)*(l*s-n*p)+(d*k-e*h)*(l*r-m*p)}; +JSM.MatrixInvert=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],g=a[5],h=a[6],k=a[7],l=a[8],m=a[9],n=a[10],q=a[11],p=a[12],r=a[13],s=a[14];a=a[15];var v=b*g-c*f,u=b*h-d*f,t=b*k-e*f,y=c*h-d*g,B=c*k-e*g,C=d*k-e*h,w=l*r-m*p,x=l*s-n*p,A=l*a-q*p,E=m*s-n*r,G=m*a-q*r,H=n*a-q*s,z=v*H-u*G+t*E+y*A-B*x+C*w;if(JSM.IsZero(z))return null;var D=[];D[0]=(g*H-h*G+k*E)/z;D[1]=(d*G-c*H-e*E)/z;D[2]=(r*C-s*B+a*y)/z;D[3]=(n*B-m*C-q*y)/z;D[4]=(h*A-f*H-k*x)/z;D[5]=(b*H-d*A+e*x)/z;D[6]=(s*t-p*C-a*u)/z;D[7]=(l*C-n*t+q* +u)/z;D[8]=(f*G-g*A+k*w)/z;D[9]=(c*A-b*G-e*w)/z;D[10]=(p*B-r*t+a*v)/z;D[11]=(m*t-l*B-q*v)/z;D[12]=(g*x-f*E-h*w)/z;D[13]=(b*E-c*x+d*w)/z;D[14]=(r*u-p*y-s*v)/z;D[15]=(l*y-m*u+n*v)/z;return D};JSM.MatrixTranslation=function(a,b,c){var d=[1,0,0,0,0,1,0,0,0,0,1,0];d[12]=a;d[13]=b;d[14]=c;d[15]=1;return d}; JSM.MatrixRotation=function(a,b,c){var d=a.Clone().Normalize();a=d.x;var e=d.y,d=d.z,f=a*a,g=e*e,h=d*d,k=Math.sin(b);b=Math.cos(b);var l=[];if(void 0===c||null===c)l[0]=f+(g+h)*b,l[1]=a*e*(1-b)+d*k,l[2]=a*d*(1-b)-e*k,l[3]=0,l[4]=a*e*(1-b)-d*k,l[5]=g+(f+h)*b,l[6]=e*d*(1-b)+a*k,l[7]=0,l[8]=a*d*(1-b)+e*k,l[9]=e*d*(1-b)-a*k,l[10]=h+(f+g)*b,l[11]=0,l[12]=0,l[13]=0,l[14]=0;else{var m=c.x,n=c.y;c=c.z;l[0]=f+(g+h)*b;l[1]=a*e*(1-b)+d*k;l[2]=a*d*(1-b)-e*k;l[3]=0;l[4]=a*e*(1-b)-d*k;l[5]=g+(f+h)*b;l[6]=e*d*(1- b)+a*k;l[7]=0;l[8]=a*d*(1-b)+e*k;l[9]=e*d*(1-b)-a*k;l[10]=h+(f+g)*b;l[11]=0;l[12]=(m*(g+h)-a*(n*e+c*d))*(1-b)+(n*d-c*e)*k;l[13]=(n*(f+h)-e*(m*a+c*d))*(1-b)+(c*a-m*d)*k;l[14]=(c*(f+g)-d*(m*a+n*e))*(1-b)+(m*e-n*a)*k}l[15]=1;return l}; JSM.MatrixRotationQuaternion=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=b+b,g=c+c,h=d+d;a=b*f;var k=b*g,b=b*h,l=c*g,c=c*h,d=d*h,f=e*f,g=e*g,e=e*h,h=[];h[0]=1-(l+d);h[1]=k+e;h[2]=b-g;h[3]=0;h[4]=k-e;h[5]=1-(a+d);h[6]=c+f;h[7]=0;h[8]=b+g;h[9]=c-f;h[10]=1-(a+l);h[11]=0;h[12]=0;h[13]=0;h[14]=0;h[15]=1;return h};JSM.MatrixRotationX=function(a){var b=Math.sin(a);a=Math.cos(a);var c=[1,0,0,0,0];c[5]=a;c[6]=b;c[7]=0;c[8]=0;c[9]=-b;c[10]=a;c[11]=0;c[12]=0;c[13]=0;c[14]=0;c[15]=1;return c}; @@ -41,18 +41,18 @@ JSM.CoordSystem.prototype.Clone=function(){return new JSM.CoordSystem(this.origo JSM.Sector2D=function(a,b){this.beg=a;this.end=b};JSM.Sector2D.prototype.Set=function(a,b){this.beg=a;this.end=b};JSM.Sector2D.prototype.GetLength=function(){return this.beg.DistanceTo(this.end)}; JSM.Sector2D.prototype.CoordPosition=function(a){var b=a.x,c=a.y,d=this.beg.x,e=this.beg.y,f=this.end.x,g=this.end.y,h=this.GetLength();if(JSM.IsZero(h))return a.IsEqual(this.beg)?JSM.CoordSectorPosition2D.CoordOnSectorEndCoord:JSM.CoordSectorPosition2D.CoordOutsideOfSector;a=((b-d)*(f-d)+(c-e)*(g-e))/(h*h);if(JSM.IsLower(a,0)||JSM.IsGreater(a,1))return JSM.CoordSectorPosition2D.CoordOutsideOfSector;e+=a*(g-e);return!JSM.IsEqual(d+a*(f-d),b)||!JSM.IsEqual(e,c)?JSM.CoordSectorPosition2D.CoordOutsideOfSector: JSM.IsEqual(a,0)||JSM.IsEqual(a,1)?JSM.CoordSectorPosition2D.CoordOnSectorEndCoord:JSM.CoordSectorPosition2D.CoordInsideOfSector}; -JSM.Sector2D.prototype.SectorPosition=function(a,b){function c(a,b,c){return!c.IsEqual(a)&&!c.IsEqual(b)&&JSM.IsLowerOrEqual(c.x,Math.max(a.x,b.x))&&JSM.IsLowerOrEqual(c.y,Math.max(a.y,b.y))&&JSM.IsGreaterOrEqual(c.x,Math.min(a.x,b.x))&&JSM.IsGreaterOrEqual(c.y,Math.min(a.y,b.y))?!0:!1}var d=void 0!==b&&null!==b,e=this.beg,f=this.end,g=a.beg,h=a.end,k=e.IsEqual(g)||e.IsEqual(h),l=f.IsEqual(g)||f.IsEqual(h);if(k&&l)return JSM.SectorSectorPosition2D.SectorsIntersectCoincident;var m=e.x,n=e.y,p=f.x, -q=f.y,r=g.x,s=g.y,v=h.x,u=h.y,t=(v-r)*(n-s)-(u-s)*(m-r),w=(p-m)*(n-s)-(q-n)*(m-r),r=(u-s)*(p-m)-(v-r)*(q-n);if(JSM.IsZero(r)){if(JSM.IsZero(t)&&JSM.IsZero(w)){if(c(e,f,g)||c(e,f,h)||c(g,h,e)||c(g,h,f))return JSM.SectorSectorPosition2D.SectorsIntersectCoincident;if(k)return d&&(b.x=e.x,b.y=e.y),JSM.SectorSectorPosition2D.SectorsIntersectEndPoint;if(l)return d&&(b.x=f.x,b.y=f.y),JSM.SectorSectorPosition2D.SectorsIntersectEndPoint}return JSM.SectorSectorPosition2D.SectorsDontIntersect}g=t/r;w/=r;if(JSM.IsLower(g, -0)||JSM.IsGreater(g,1)||JSM.IsLower(w,0)||JSM.IsGreater(w,1))return JSM.SectorSectorPosition2D.SectorsDontIntersect;if(k)return d&&(b.x=e.x,b.y=e.y),JSM.SectorSectorPosition2D.SectorsIntersectEndPoint;if(l)return d&&(b.x=f.x,b.y=f.y),JSM.SectorSectorPosition2D.SectorsIntersectEndPoint;d&&(b.x=m+g*(p-m),b.y=n+g*(q-n));return JSM.SectorSectorPosition2D.SectorsIntersectOnePoint}; +JSM.Sector2D.prototype.SectorPosition=function(a,b){function c(a,b,c){return!c.IsEqual(a)&&!c.IsEqual(b)&&JSM.IsLowerOrEqual(c.x,Math.max(a.x,b.x))&&JSM.IsLowerOrEqual(c.y,Math.max(a.y,b.y))&&JSM.IsGreaterOrEqual(c.x,Math.min(a.x,b.x))&&JSM.IsGreaterOrEqual(c.y,Math.min(a.y,b.y))?!0:!1}var d=void 0!==b&&null!==b,e=this.beg,f=this.end,g=a.beg,h=a.end,k=e.IsEqual(g)||e.IsEqual(h),l=f.IsEqual(g)||f.IsEqual(h);if(k&&l)return JSM.SectorSectorPosition2D.SectorsIntersectCoincident;var m=e.x,n=e.y,q=f.x, +p=f.y,r=g.x,s=g.y,v=h.x,u=h.y,t=(v-r)*(n-s)-(u-s)*(m-r),y=(q-m)*(n-s)-(p-n)*(m-r),r=(u-s)*(q-m)-(v-r)*(p-n);if(JSM.IsZero(r)){if(JSM.IsZero(t)&&JSM.IsZero(y)){if(c(e,f,g)||c(e,f,h)||c(g,h,e)||c(g,h,f))return JSM.SectorSectorPosition2D.SectorsIntersectCoincident;if(k)return d&&(b.x=e.x,b.y=e.y),JSM.SectorSectorPosition2D.SectorsIntersectEndPoint;if(l)return d&&(b.x=f.x,b.y=f.y),JSM.SectorSectorPosition2D.SectorsIntersectEndPoint}return JSM.SectorSectorPosition2D.SectorsDontIntersect}g=t/r;y/=r;if(JSM.IsLower(g, +0)||JSM.IsGreater(g,1)||JSM.IsLower(y,0)||JSM.IsGreater(y,1))return JSM.SectorSectorPosition2D.SectorsDontIntersect;if(k)return d&&(b.x=e.x,b.y=e.y),JSM.SectorSectorPosition2D.SectorsIntersectEndPoint;if(l)return d&&(b.x=f.x,b.y=f.y),JSM.SectorSectorPosition2D.SectorsIntersectEndPoint;d&&(b.x=m+g*(q-m),b.y=n+g*(p-n));return JSM.SectorSectorPosition2D.SectorsIntersectOnePoint}; JSM.Sector2D.prototype.ProjectCoord=function(a){var b=a.x,c=a.y;a=this.beg;var d=this.end,e=a.x,f=a.y,g=d.x,h=d.y,k=(g-e)*(g-e)+(h-f)*(h-f);if(JSM.IsZero(k))return a.Clone();b=((g-e)*(b-e)+(h-f)*(c-f))/k;if(JSM.IsLower(b,0))return a.Clone();if(JSM.IsGreater(b,1))return d.Clone();b=JSM.CoordSub2D(d,a).MultiplyScalar(b);return JSM.CoordAdd2D(a,b)};JSM.Sector2D.prototype.Clone=function(){return new JSM.Sector2D(this.beg.Clone(),this.end.Clone())};JSM.Sector=function(a,b){this.beg=a;this.end=b}; JSM.Sector.prototype.Set=function(a,b){this.beg=a;this.end=b};JSM.Sector.prototype.GetLength=function(){return this.beg.DistanceTo(this.end)}; -JSM.Sector.prototype.CoordPosition=function(a){var b=a.x,c=a.y,d=a.z,e=this.beg,f=JSM.CoordSub(this.end,this.beg),g=e.x,h=e.y,k=e.z,l=e.x+f.x,m=e.y+f.y,n=e.z+f.z,p=(l-g)*(l-g)+(m-h)*(m-h)+(n-k)*(n-k);if(JSM.IsZero(p))return e.IsEqual(a)?JSM.CoordSectorPosition.CoordOnSectorEndCoord:JSM.CoordSectorPosition.CoordOutsideOfSector;b=((l-g)*(b-g)+(m-h)*(c-h)+(n-k)*(d-k))/p;f=f.Clone().MultiplyScalar(b);e=JSM.CoordAdd(e,f);a=a.DistanceTo(e);return JSM.IsZero(a)?JSM.IsLower(b,0)||JSM.IsGreater(b,1)?JSM.CoordSectorPosition.CoordOutsideOfSector: +JSM.Sector.prototype.CoordPosition=function(a){var b=a.x,c=a.y,d=a.z,e=this.beg,f=JSM.CoordSub(this.end,this.beg),g=e.x,h=e.y,k=e.z,l=e.x+f.x,m=e.y+f.y,n=e.z+f.z,q=(l-g)*(l-g)+(m-h)*(m-h)+(n-k)*(n-k);if(JSM.IsZero(q))return e.IsEqual(a)?JSM.CoordSectorPosition.CoordOnSectorEndCoord:JSM.CoordSectorPosition.CoordOutsideOfSector;b=((l-g)*(b-g)+(m-h)*(c-h)+(n-k)*(d-k))/q;f=f.Clone().MultiplyScalar(b);e=JSM.CoordAdd(e,f);a=a.DistanceTo(e);return JSM.IsZero(a)?JSM.IsLower(b,0)||JSM.IsGreater(b,1)?JSM.CoordSectorPosition.CoordOutsideOfSector: JSM.IsEqual(b,0)||JSM.IsEqual(b,1)?JSM.CoordSectorPosition.CoordOnSectorEndCoord:JSM.CoordSectorPosition.CoordInsideOfSector:JSM.CoordSectorPosition.CoordOutsideOfSector};JSM.Sector.prototype.Clone=function(){return new JSM.Sector(this.beg.Clone(),this.end.Clone())};JSM.GetSectorSegmentation2D=function(a,b){var c=JSM.CoordSub2D(a.end,a.beg),d=a.beg.DistanceTo(a.end)/b,e=0,f=[],g,h;for(g=0;g<=b;g++)h=a.beg.Clone().Offset(c,e),f.push(h),e+=d;return f}; JSM.GetSectorSegmentation=function(a,b){var c=JSM.CoordSub(a.end,a.beg),d=a.beg.DistanceTo(a.end)/b,e=0,f=[],g,h;for(g=0;g<=b;g++)h=a.beg.Clone().Offset(c,e),f.push(h),e+=d;return f};JSM.CoordLinePosition2D={CoordOnLine:0,CoordAtLineLeft:1,CoordAtLineRight:2};JSM.LineLinePosition2D={LinesDontIntersect:0,LinesIntersectsOnePoint:1,LinesIntersectsCoincident:2};JSM.CoordLinePosition={CoordOnLine:0,CoordOutsideOfLine:1};JSM.LineLinePosition={LinesDontIntersect:0,LinesIntersectsOnePoint:1,LinesIntersectsCoincident:2}; JSM.Line2D=function(a,b){this.start=a;this.direction=b};JSM.Line2D.prototype.Set=function(a,b){this.start=a;this.direction=b};JSM.Line2D.prototype.CoordPosition=function(a){a=this.CoordSignedDistance(a);return JSM.IsPositive(a)?JSM.CoordLinePosition2D.CoordAtLineLeft:JSM.IsNegative(a)?JSM.CoordLinePosition2D.CoordAtLineRight:JSM.CoordLinePosition2D.CoordOnLine};JSM.Line2D.prototype.CoordSignedDistance=function(a){var b=this.start,c=this.direction;return c.x*(a.y-b.y)-c.y*(a.x-b.x)}; JSM.Line2D.prototype.LinePosition=function(a,b){var c=this.start.x,d=this.start.y,e=this.start.x+this.direction.x,f=this.start.y+this.direction.y,g=a.start.x,h=a.start.y,k=a.start.x+a.direction.x,l=a.start.y+a.direction.y,m=(k-g)*(d-h)-(l-h)*(c-g),n=(e-c)*(d-h)-(f-d)*(c-g),g=(l-h)*(e-c)-(k-g)*(f-d);if(JSM.IsZero(g))return JSM.IsZero(m)&&JSM.IsZero(n)?JSM.LineLinePosition2D.LinesIntersectsCoincident:JSM.LineLinePosition2D.LinesDontIntersect;m/=g;null!==b&&(b.x=c+m*(e-c),b.y=d+m*(f-d));return JSM.LineLinePosition2D.LinesIntersectsOnePoint}; JSM.Line2D.prototype.Clone=function(){return new JSM.Line2D(this.start.Clone(),this.direction.Clone())};JSM.Line=function(a,b){this.start=a;this.direction=b};JSM.Line.prototype.Set=function(a,b){this.start=a;this.direction=b}; -JSM.Line.prototype.CoordPosition=function(a,b){var c=a.x,d=a.y,e=a.z,f=this.start,g=this.direction,h=f.x,k=f.y,l=f.z,m=f.x+g.x,n=f.y+g.y,p=f.z+g.z,q=(m-h)*(m-h)+(n-k)*(n-k)+(p-l)*(p-l);if(JSM.IsZero(q))return void 0!==b&&b.Set(f.x,f.y,f.z),f.IsEqual(a)?JSM.CoordLinePosition.CoordOnLine:JSM.CoordLinePosition.CoordOutsideOfLine;c=g.Clone().MultiplyScalar(((m-h)*(c-h)+(n-k)*(d-k)+(p-l)*(e-l))/q);f=JSM.CoordAdd(f,c);void 0!==b&&b.Set(f.x,f.y,f.z);f=a.DistanceTo(f);return JSM.IsZero(f)?JSM.CoordLinePosition.CoordOnLine: +JSM.Line.prototype.CoordPosition=function(a,b){var c=a.x,d=a.y,e=a.z,f=this.start,g=this.direction,h=f.x,k=f.y,l=f.z,m=f.x+g.x,n=f.y+g.y,q=f.z+g.z,p=(m-h)*(m-h)+(n-k)*(n-k)+(q-l)*(q-l);if(JSM.IsZero(p))return void 0!==b&&b.Set(f.x,f.y,f.z),f.IsEqual(a)?JSM.CoordLinePosition.CoordOnLine:JSM.CoordLinePosition.CoordOutsideOfLine;c=g.Clone().MultiplyScalar(((m-h)*(c-h)+(n-k)*(d-k)+(q-l)*(e-l))/p);f=JSM.CoordAdd(f,c);void 0!==b&&b.Set(f.x,f.y,f.z);f=a.DistanceTo(f);return JSM.IsZero(f)?JSM.CoordLinePosition.CoordOnLine: JSM.CoordLinePosition.CoordOutsideOfLine};JSM.Line.prototype.ProjectCoord=function(a){var b=a.x,c=a.y,d=a.z;a=this.start;var e=this.direction,f=a.x,g=a.y,h=a.z,k=a.x+e.x,l=a.y+e.y,m=a.z+e.z,n=(k-f)*(k-f)+(l-g)*(l-g)+(m-h)*(m-h);if(JSM.IsZero(n))return a.Clone();b=e.Clone().MultiplyScalar(((k-f)*(b-f)+(l-g)*(c-g)+(m-h)*(d-h))/n);return JSM.CoordAdd(a,b)}; JSM.Line.prototype.ClosestPoint=function(a,b,c){function d(a,b,c,d,e){return(a[b].x-a[c].x)*(a[d].x-a[e].x)+(a[b].y-a[c].y)*(a[d].y-a[e].y)+(a[b].z-a[c].z)*(a[d].z-a[e].z)}var e=this.direction.Clone().Normalize(),f=this.start,g=JSM.CoordAdd(f,e),h=a.direction.Clone().Normalize();a=a.start;var k=JSM.CoordAdd(a,h),l=[f,g,a,k],m=d(l,1,0,1,0),n=d(l,0,2,1,0),g=d(l,0,2,3,2),k=d(l,3,2,1,0),l=d(l,3,2,3,2),m=m*l-k*k;if(JSM.IsEqual(m,0))return!1;n=(g*k-n*l)/m;g=(g+n*k)/l;void 0!==b&&(e.MultiplyScalar(n),e= JSM.CoordAdd(f,e),b.Set(e.x,e.y,e.z));void 0!==c&&(h.MultiplyScalar(g),b=JSM.CoordAdd(a,h),c.Set(b.x,b.y,b.z));return!0};JSM.Line.prototype.LinePosition=function(a,b){var c=new JSM.Coord(0,0,0),d=new JSM.Coord(0,0,0);return!this.ClosestPoint(a,c,d)?JSM.LineLinePosition.LinesIntersectsCoincident:c.IsEqual(d)?(void 0!==b&&b.Set(c.x,c.y,c.z),JSM.LineLinePosition.LinesIntersectsOnePoint):JSM.LineLinePosition.LinesDontIntersect}; @@ -79,8 +79,8 @@ JSM.ConvexHull2D=function(a){function b(a,b){var c=a.length,d=0,e;for(e=1;en)return m;var p=new function(){this.vertices=[];this.edges=[];this.triangles=[]},q;for(q=0;qn)return m;var q=new function(){this.vertices=[];this.edges=[];this.triangles=[]},p;for(p=0;pf))if(3==f)a.push(e.map);else{f=b(e.polygon);if(null===f)return null;e=c(e,f);d.push(e.resultData1);d.push(e.resultData2)}return a}; +JSM.TriangulateConcavePolygon2D=function(a){function b(a){var b=a.VertexCount(),c,d;for(c=0;cf))if(3==f)a.push(e.map);else{f=b(e.polygon);if(null===f)return null;e=c(e,f);d.push(e.resultData1);d.push(e.resultData2)}return a}; JSM.TriangulatePolygon2D=function(a){if(null===a)return null;var b=a.VertexCount();if(3>b)return null;if(3==b)return[[0,1,2]];b=a.GetComplexity();return b===JSM.Complexity.Invalid?null:b==JSM.Complexity.Convex?JSM.TriangulateConvexPolygon(a):JSM.TriangulateConcavePolygon2D(a)};JSM.TriangulatePolygon=function(a){a=a.ToPolygon2D();return JSM.TriangulatePolygon2D(a)}; JSM.TraverseOctreeNodes=function(a,b){function c(a,b){if(b(a)&&null!==a.children){var f,g;for(f=0;ff;f++)k=c[h[f]],u.AddVertexIndex(2*b[k[0]]+2*k[1]+1),k=c[h[2-f]],t.AddVertexIndex(2*b[k[0]]+2*k[1]);g.AddPolygon(u);g.AddPolygon(t)}}}var g=new JSM.Body,h=[],k=new JSM.ContourPolygon;k.FromArray(a); -(function(a,b,c,d){var e,f,g,h,k;for(e=0;ex)JSM.Message("Invalid polygon found.");else{var y=void 0,z=void 0,E=void 0,H=void 0,I=void 0,D=void 0,C=void 0,K=void 0,L=void 0,y=!1;void 0!==n.hasConvexPolygons&&null!==n.hasConvexPolygons&&(y=n.hasConvexPolygons);var F=void 0;if(3==x||y)for(F=0;Ff)){var g,n,p,q=null;if(3===f)q=JSM.CalculateBodyPolygonNormal(a,b),g=a.GetVertex(d.GetVertexIndex(0)).position,n=a.GetVertex(d.GetVertexIndex(1)).position, -p=a.GetVertex(d.GetVertexIndex(2)).position,e(q,g,n,p);else if(g=!0,void 0!==c&&c&&(g=!1),q=JSM.CalculateBodyPolygonNormal(a,b),g){g=new JSM.Polygon;for(b=0;bw)JSM.Message("Invalid polygon found.");else{var x=void 0,A=void 0,E=void 0,G=void 0,H=void 0,z=void 0,D=void 0,K=void 0,L=void 0,x=!1;void 0!==n.hasConvexPolygons&&null!==n.hasConvexPolygons&&(x=n.hasConvexPolygons);var F=void 0;if(3==w||x)for(F=0;Ff)){var g,n,q,p=null;if(3===f)p=JSM.CalculateBodyPolygonNormal(a,b),g=a.GetVertex(d.GetVertexIndex(0)).position,n=a.GetVertex(d.GetVertexIndex(1)).position, +q=a.GetVertex(d.GetVertexIndex(2)).position,e(p,g,n,q);else if(g=!0,void 0!==c&&c&&(g=!1),p=JSM.CalculateBodyPolygonNormal(a,b),g){g=new JSM.Polygon;for(b=0;bf.mat||f.mat>=e)||d[f.mat].push(a);var p,q;for(a=0;af.mat||f.mat>=e)||d[f.mat].push(a);var q,p;for(a=0;a=a.length)d(c);else{var e=a[b],f=null,f=e.isFile?e.isArrayBuffer?JSM.GetArrayBufferFromFile:JSM.GetStringBufferFromFile:e.isArrayBuffer?JSM.GetArrayBufferFromURL:JSM.GetStringBufferFromURL;f(e.originalObject,{onReady:function(e){c.push(e);JSM.LoadMultipleBuffersInternal(a,b+1,c,d)},onError:function(){c.push(null);JSM.LoadMultipleBuffersInternal(a,b+1,c,d)}})}};JSM.LoadMultipleBuffers=function(a,b){JSM.LoadMultipleBuffersInternal(a,0,[],function(a){b(a)})}; +JSM.LoadMultipleBuffers=function(a,b){function c(a,b,f,g){if(b>=a.length)g(f);else{var h=a[b],k=null,k=h.isFile?h.isArrayBuffer?JSM.GetArrayBufferFromFile:JSM.GetStringBufferFromFile:h.isArrayBuffer?JSM.GetArrayBufferFromURL:JSM.GetStringBufferFromURL;k(h.originalObject,{onReady:function(h){f.push(h);c(a,b+1,f,g)},onError:function(){f.push(null);c(a,b+1,f,g)}})}}c(a,0,[],function(a){b(a)})}; JSM.Read3dsFile=function(a,b){function c(a,c){if(void 0!==b.onLog&&null!==b.onLog)b.onLog(a,c)}function d(a){for(var b="",c=0,d=0;64>d;){c=a.ReadCharacter();if(0===c)break;b+=String.fromCharCode(c);d+=1}return b}function e(a){var b=[],c;for(c=0;3>c;c++)b[c]=a.ReadFloat32();return b}function f(a,b,c){for(;a.GetPosition()<=b-6;){var d=a,e=c,f=d.ReadUnsignedInteger16(),d=d.ReadUnsignedInteger32();e(f,d)}}if(void 0===b||null===b)b={};(function(a,h){function k(a,b,c){var d=[0,0,0];b=a.GetPosition()+c- 6;var e=!1;f(a,b,function(b,c){b==h.MAT_COLOR?e||(d[0]=a.ReadUnsignedCharacter()/255,d[1]=a.ReadUnsignedCharacter()/255,d[2]=a.ReadUnsignedCharacter()/255):b==h.MAT_LIN_COLOR?(d[0]=a.ReadUnsignedCharacter()/255,d[1]=a.ReadUnsignedCharacter()/255,d[2]=a.ReadUnsignedCharacter()/255,e=!0):b==h.MAT_COLOR_F?e||(d[0]=a.ReadFloat32(),d[1]=a.ReadFloat32(),d[2]=a.ReadFloat32()):b==h.MAT_LIN_COLOR_F?(d[0]=a.ReadFloat32(),d[1]=a.ReadFloat32(),d[2]=a.ReadFloat32(),e=!0):a.Skip(c-6)});return d}function l(a,b, c){var d=0;b=a.GetPosition()+c-6;f(a,b,function(b,c){b==h.PERCENTAGE?d=a.ReadUnsignedInteger16()/100:b==h.PERCENTAGE_F?d=a.ReadFloat32():a.Skip(c-6)});return d}function m(a,b,c,e){e.texture=null;e.offset=[0,0];e.scale=[1,1];e.rotation=0;b=a.GetPosition()+c-6;f(a,b,function(b,c){b==h.MAT_TEXMAP_NAME?e.texture=d(a):b==h.MAT_TEXMAP_UOFFSET?e.offset[0]=a.ReadFloat32():b==h.MAT_TEXMAP_VOFFSET?e.offset[1]=a.ReadFloat32():b==h.MAT_TEXMAP_USCALE?e.scale[0]=a.ReadFloat32():b==h.MAT_TEXMAP_VSCALE?e.scale[1]= a.ReadFloat32():b==h.MAT_TEXMAP_ROTATION?e.rotation=a.ReadFloat32():a.Skip(c-6)})}function n(a,e,g){c("Read material chunk ("+e.toString(16)+", "+g+")",2);var n={},p=a.GetPosition()+g-6;f(a,p,function(b,f){b==h.MAT_NAME?(c("Read material name chunk ("+e.toString(16)+", "+g+")",3),n.name=d(a)):b==h.MAT_AMBIENT?(c("Read material ambient chunk ("+e.toString(16)+", "+g+")",3),n.ambient=k(a,b,f)):b==h.MAT_DIFFUSE?(c("Read material diffuse chunk ("+e.toString(16)+", "+g+")",3),n.diffuse=k(a,b,f)):b==h.MAT_SPECULAR? (c("Read material specular chunk ("+e.toString(16)+", "+g+")",3),n.specular=k(a,b,f)):b==h.MAT_SHININESS?(c("Read material shininess chunk ("+e.toString(16)+", "+g+")",3),n.shininess=l(a,b,f)):b==h.MAT_SHININESS_STRENGTH?(c("Read material shininess strength chunk ("+e.toString(16)+", "+g+")",3),n.shininessStrength=l(a,b,f)):b==h.MAT_TRANSPARENCY?(c("Read material transparency chunk ("+e.toString(16)+", "+g+")",3),n.transparency=l(a,b,f)):b==h.MAT_TEXMAP?(c("Read material texture map chunk ("+e.toString(16)+ -", "+g+")",3),m(a,b,f,n)):(c("Skip chunk ("+b.toString(16)+", "+f+")",3),a.Skip(f-6))});if(void 0!==b.onMaterial&&null!==b.onMaterial)b.onMaterial(n)}function p(a,e,g){c("Read faces chunk ("+e.toString(16)+", "+g+")",4);e=a.GetPosition()+g-6;var k=a.ReadUnsignedInteger16(),l,m,n,p;for(g=0;gg;g++){for(k=0;3>k;k++)f.push(a.ReadFloat32());3>g?f.push(0):f.push(1)}if(void 0!==b.onTransformation&&null!==b.onTransformation)b.onTransformation(f)}else c("Skip chunk ("+d.toString(16)+", "+e+")",4),a.Skip(e-6)})}function r(a,b, -e){c("Read object chunk ("+b.toString(16)+", "+e+")",2);b=a.GetPosition()+e-6;var g=d(a);f(a,b,function(b,d){b==h.OBJ_TRIMESH?q(a,g,b,d):(b==h.OBJ_LIGHT?c("Skip light chunk ("+g+", "+b.toString(16)+", "+d+")",3):b==h.OBJ_CAMERA?c("Skip camera chunk ("+g+", "+b.toString(16)+", "+d+")",3):c("Skip chunk ("+b.toString(16)+", "+d+")",3),a.Skip(d-6))})}function s(a,b,d){c("Read editor chunk ("+b.toString(16)+", "+d+")",1);b=a.GetPosition()+d-6;f(a,b,function(b,d){b==h.EDIT_MATERIAL?n(a,b,d):b==h.EDIT_OBJECT? +for(g=0;gg;g++){for(k=0;3>k;k++)f.push(a.ReadFloat32());3>g?f.push(0):f.push(1)}if(void 0!==b.onTransformation&&null!==b.onTransformation)b.onTransformation(f)}else c("Skip chunk ("+d.toString(16)+", "+e+")",4),a.Skip(e-6)})}function r(a,b, +e){c("Read object chunk ("+b.toString(16)+", "+e+")",2);b=a.GetPosition()+e-6;var g=d(a);f(a,b,function(b,d){b==h.OBJ_TRIMESH?p(a,g,b,d):(b==h.OBJ_LIGHT?c("Skip light chunk ("+g+", "+b.toString(16)+", "+d+")",3):b==h.OBJ_CAMERA?c("Skip camera chunk ("+g+", "+b.toString(16)+", "+d+")",3):c("Skip chunk ("+b.toString(16)+", "+d+")",3),a.Skip(d-6))})}function s(a,b,d){c("Read editor chunk ("+b.toString(16)+", "+d+")",1);b=a.GetPosition()+d-6;f(a,b,function(b,d){b==h.EDIT_MATERIAL?n(a,b,d):b==h.EDIT_OBJECT? r(a,b,d):(c("Skip chunk ("+b.toString(16)+", "+d+")",2),a.Skip(d-6))})}function v(a,g,k){function l(a,b){var c=[];a.Skip(10);var d,f,g,k=a.ReadInteger32();for(d=0;dg;g++)a[0+g]*=c,a[4+g]*=d,a[8+g]*=f;return a}function f(a,b){var c=b[0],d=b[1],e=b[2],g;for(g=0;3>g;g++)a[12+g]+=a[0+g]*c+a[4+g]*d+a[8+g]*e;return a}function g(a,b){var c,d;for(c=0;cq.length)){var s="";for(r=1;rq.length||(h.vertexCount+=1,d(parseFloat(q[1]),parseFloat(q[2]),parseFloat(q[3])));else if("vn"==q[0])4>q.length||(h.normalCount+=1,e(parseFloat(q[1]), -parseFloat(q[2]),parseFloat(q[3])));else if("vt"==q[0])3>q.length||(h.uvCount+=1,f(parseFloat(q[1]),parseFloat(q[2])));else if("f"==q[0]){if(!(4>q.length)){var s=[],v=[],u=[],t;for(r=1;rq.length)&&void 0!== -b.onUseMaterial&&null!==b.onUseMaterial)b.onUseMaterial(q[1])}else if("newmtl"==q[0]){if(!(2>q.length)&&void 0!==b.onNewMaterial&&null!==b.onNewMaterial)b.onNewMaterial(q[1])}else if("Ka"==q[0]||"Kd"==q[0]||"Ks"==q[0])4>q.length||c(q[0],parseFloat(q[1]),parseFloat(q[2]),parseFloat(q[3]));else if("Ns"==q[0]||"Tr"==q[0]||"d"==q[0]){if(!(2>q.length)&&void 0!==b.onMaterialParameter&&null!==b.onMaterialParameter)b.onMaterialParameter(q[0],q[1])}else if("map_Kd"==q[0]){if(!(2>q.length)&&(q=p(a,"map_Kd"), -void 0!==b.onMaterialTexture&&null!==b.onMaterialTexture))b.onMaterialTexture(q)}else"mtllib"==q[0]&&!(2>q.length)&&(q=p(a,"mtllib"),q=g(q.trim()),null!==q&&k(q))}}}function k(a,b){var c=a.split("\n"),d,e;for(d=0;dc||c>=b.length))return b=b[c],0===f?g=a.AddVertex(b.x,b.y,b.z):1===f?g=a.AddNormal(b.x,b.y,b.z):2===f&&(g=a.AddUV(b.x,b.y)),d[c]=g}}var f,g,h,k,l,m,n;for(f=0;fp.length)){var s="";for(r=1;rp.length||(h.vertexCount+=1,d(parseFloat(p[1]),parseFloat(p[2]),parseFloat(p[3])));else if("vn"==p[0])4>p.length||(h.normalCount+=1,e(parseFloat(p[1]), +parseFloat(p[2]),parseFloat(p[3])));else if("vt"==p[0])3>p.length||(h.uvCount+=1,f(parseFloat(p[1]),parseFloat(p[2])));else if("f"==p[0]){if(!(4>p.length)){var s=[],v=[],u=[],t;for(r=1;rp.length)&&void 0!== +b.onUseMaterial&&null!==b.onUseMaterial)b.onUseMaterial(p[1])}else if("newmtl"==p[0]){if(!(2>p.length)&&void 0!==b.onNewMaterial&&null!==b.onNewMaterial)b.onNewMaterial(p[1])}else if("Ka"==p[0]||"Kd"==p[0]||"Ks"==p[0])4>p.length||c(p[0],parseFloat(p[1]),parseFloat(p[2]),parseFloat(p[3]));else if("Ns"==p[0]||"Tr"==p[0]||"d"==p[0]){if(!(2>p.length)&&void 0!==b.onMaterialParameter&&null!==b.onMaterialParameter)b.onMaterialParameter(p[0],p[1])}else if("map_Kd"==p[0]){if(!(2>p.length)&&(p=q(a,"map_Kd"), +void 0!==b.onMaterialTexture&&null!==b.onMaterialTexture))b.onMaterialTexture(p)}else"mtllib"==p[0]&&!(2>p.length)&&(p=q(a,"mtllib"),p=g(p.trim()),null!==p&&k(p))}}}function k(a,b){var c=a.split("\n"),d,e;for(d=0;dc||c>=a.length)){var f=b[c];void 0===f&&(f=e(a[c]),b[c]=f);return f}}function e(a,b,c,f){return d(b,c,f,function(b){return a.AddVertex(b.x,b.y,b.z)})}function g(a,b,c,e){return d(b,c,e,function(b){return a.AddNormal(b.x,b.y,b.z)})}function h(a,b,c,e){return d(b,c,e,function(b){return a.AddUV(b.x, +b.y)})}var w,x,A,E,G=b.length==a.length,H=c.length==a.length,z=a.length;for(w=0;wc;c++)b[c]=a.ReadFloat32();return b}if(void 0===b||null===b)b={};var d=new JSM.BinaryReader(a,!0);d.Skip(80);var e=d.ReadUnsignedInteger32(),f,g,h,k,l;for(f=0;fd.length)return-1;var d=[parseFloat(d[2]),parseFloat(d[3]),parseFloat(d[4])],e=[],l,m;for(l=c+1;le.length;l++)if(m=a[l].trim(),0!==m.length&&(m=m.split(/\s+/),0!==m.length&&"vertex"==m[0]))if(4>m.length)break;else m=[parseFloat(m[1]),parseFloat(m[2]),parseFloat(m[3])],e.push(m);l+=1;if(3!=e.length)return-1; if(void 0!==b.onFace&&null!==b.onFace)b.onFace(e[0],e[1],e[2],d);return l}return c+1}if(void 0===b||null===b)b={};for(var d=0,e=a.split("\n");db)return!1;a=new JSM.BinaryReader(a,!0);a.Skip(80);a=a.ReadUnsignedInteger32();return b!=50*a+84?!1:!0}; JSM.ConvertStlToJsonData=function(a,b){var c=new JSM.TriangleModel,d=c.AddBody(new JSM.TriangleBody("Default")),e=c.GetBody(d);null!==a?JSM.ReadBinaryStlFile(a,{onFace:function(a,b,c,d){a=e.AddVertex(a[0],a[1],a[2]);b=e.AddVertex(b[0],b[1],b[2]);c=e.AddVertex(c[0],c[1],c[2]);d=(new JSM.Vector(d[0],d[1],d[2])).Normalize();d=e.AddNormal(d.x,d.y,d.z);e.AddTriangle(a,b,c,d,d,d)}}):null!==b&&JSM.ReadAsciiStlFile(b,{onFace:function(a,b,c,d){a=e.AddVertex(a[0],a[1],a[2]);b=e.AddVertex(b[0],b[1],b[2]);c= -e.AddVertex(c[0],c[1],c[2]);d=(new JSM.Vector(d[0],d[1],d[2])).Normalize();d=e.AddNormal(d.x,d.y,d.z);e.AddTriangle(a,b,c,d,d,d)}});c.Finalize();return JSM.ConvertTriangleModelToJsonData(c)};JSM.ImportFileList=function(){this.isFile=this.descriptors=this.originalList=null}; -JSM.ImportFileList.prototype.InitFromFiles=function(a){this.originalList=a;this.descriptors=[];var b,c;for(b=0;b=b)return-1;this.directionalLights.push(a);return this.directionalLights.length-1};JSM.Renderer.prototype.RemoveLight=function(a){a=this.directionalLights.indexOf(a);-1!=a&&this.directionalLights.splice(a,1)};JSM.Renderer.prototype.RemoveLights=function(){this.directionalLights=[]}; JSM.Renderer.prototype.GetLight=function(a){return this.directionalLights[a]};JSM.Renderer.prototype.AddBody=function(a,b){var c=this.shader;a.EnumerateMeshes(function(a){c.CompileMaterial(a.GetMaterial(),b);c.CompileMesh(a)});this.bodies.push(a)};JSM.Renderer.prototype.AddBodies=function(a,b){var c,d;for(c=0;ca.opacity&&(b+=JSM.RenderMaterialFlags.Transparent);b=d(a,b);b=new JSM.RenderMesh(b);b.SetVertexArray(g);b.SetNormalArray(h);null!==a.texture&&b.SetUVArray(k);f.AddMesh(b)},onTriangle:function(a,b,c,d,e,f,s,v,u){g.push(a.x,a.y,a.z);g.push(b.x,b.y,b.z);g.push(c.x,c.y,c.z);h.push(d.x,d.y,d.z);h.push(e.x,e.y, e.z);h.push(f.x,f.y,f.z);null!==s&&(null!==v&&null!==u)&&(k.push(s.x,s.y),k.push(v.x,v.y),k.push(u.x,u.y))}});return f};JSM.ConvertModelToRenderBodies=function(a,b){var c=[],d=a.GetMaterialSet(),e,f;for(e=0;eg;g++){h=c[d+g];for(k=0;kg;g++){h=c[d+g];for(k=0;kt;t++)u[t].z=n-c;t=JSM.GeneratePrism(u,l,c,!0,null);k.Merge(t);if(d)for(t=0;tb&&(e=a,p=!1);for(t=0;tt;t++)u[t].z=n-c;t=JSM.GeneratePrism(u,l,c,!0,null);k.Merge(t);if(d)for(t=0;tb&&(e=a,q=!1);for(t=0;tn;n++)r=0===n?p.pgon1:p.pgon2,r=b.GetVertexPosition(d[r]),q=JSM.CoordAdd(q,r);q.MultiplyScalar(0.25)}e.push(b.AddVertex(new JSM.BodyVertex(q)))}})(a,b,c,d,e);(function(a,b,c,d){function e(a,b){b.x=a.x;b.y=a.y;b.z=a.z}function m(a,b,c,d){d.x=(a.x+2*b.x+(c-3)*d.x)/c;d.y=(a.y+2*b.y+ -(c-3)*d.y)/c;d.z=(a.z+2*b.z+(c-3)*d.z)/c}var n=[],p,q;for(q=0;qn;n++)r=0===n?q.pgon1:q.pgon2,r=b.GetVertexPosition(d[r]),p=JSM.CoordAdd(p,r);p.MultiplyScalar(0.25)}e.push(b.AddVertex(new JSM.BodyVertex(p)))}})(a,b,c,d,e);(function(a,b,c,d){function e(a,b){b.x=a.x;b.y=a.y;b.z=a.z}function m(a,b,c,d){d.x=(a.x+2*b.x+(c-3)*d.x)/c;d.y=(a.y+2*b.y+ +(c-3)*d.y)/c;d.z=(a.z+2*b.z+(c-3)*d.z)/c}var n=[],q,p;for(p=0;pv 0.5', function () { myThis.WelcomeDialog (); }); + importerButtons.AddLogo ('Online 3D Viewer v 0.5.1', function () { myThis.WelcomeDialog (); }); importerButtons.AddButton ('images/openfile.png', 'Open File', function () { myThis.OpenFile (); }); importerButtons.AddButton ('images/fitinwindow.png', 'Fit In Window', function () { myThis.FitInWindow (); }); importerButtons.AddButton ('images/fixup.png', 'Enable/Disable Fixed Up Vector', function () { myThis.SetFixUp (); });