Improve error and support handling.
This commit is contained in:
parent
c9900e9e4d
commit
a80c3e556d
@ -1,16 +1,17 @@
|
||||
function Online3DViewerLoad ()
|
||||
{
|
||||
function Error (viewerElement, message)
|
||||
{
|
||||
var context = viewerElement.getContext ('2d');
|
||||
context.font = '12px Arial';
|
||||
context.fillText (message, 0, 12);
|
||||
}
|
||||
|
||||
function LoadViewer (viewerElement)
|
||||
{
|
||||
function Error (viewerElement)
|
||||
{
|
||||
var context = viewerElement.getContext ('2d');
|
||||
context.font = '12px Arial';
|
||||
context.fillText ('Error!', 0, 12);
|
||||
}
|
||||
|
||||
var urls = viewerElement.getAttribute ('sourcefiles');
|
||||
if (urls === undefined || urls === null) {
|
||||
Error (viewerElement, 'Invalid source files.');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -18,7 +19,7 @@ function Online3DViewerLoad ()
|
||||
var urlList = urls.split ('|');
|
||||
JSM.ConvertURLListToJsonData (urlList, {
|
||||
onError : function () {
|
||||
Error (viewerElement);
|
||||
Error (viewerElement, 'Conversion failed.');
|
||||
return;
|
||||
},
|
||||
onReady : function (fileNames, jsonData) {
|
||||
@ -30,7 +31,7 @@ function Online3DViewerLoad ()
|
||||
|
||||
var viewer = new JSM.ThreeViewer ();
|
||||
if (!viewer.Start (viewerElement, viewerSettings)) {
|
||||
Error (viewerElement);
|
||||
Error (viewerElement, 'Internal error.');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -59,10 +60,16 @@ function Online3DViewerLoad ()
|
||||
});
|
||||
}
|
||||
|
||||
var supported = JSM.IsWebGLEnabled () && JSM.IsFileApiEnabled ();
|
||||
var viewers = document.getElementsByClassName ('3dviewer');
|
||||
var i;
|
||||
var i, viewer;
|
||||
for (i = 0; i < viewers.length; i++) {
|
||||
LoadViewer (viewers[i]);
|
||||
viewer = viewers[i];
|
||||
if (supported) {
|
||||
LoadViewer (viewer);
|
||||
} else {
|
||||
Error (viewer, 'No browser support.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
<canvas class="3dviewer" sourcefiles="testfiles/objects_ascii.stl" width="200" height="200"></canvas>
|
||||
<canvas class="3dviewer" sourcefiles="testfiles/objects_binary.stl" width="200" height="200"></canvas>
|
||||
<canvas class="3dviewer" sourcefiles="testfiles/wrong.3ds" width="200" height="200"></canvas>
|
||||
<canvas class="3dviewer" width="200" height="200"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
/* JSModeler 0.33.194 - http://www.github.com/kovacsv/JSModeler */ 'use strict';var JSM={mainVersion:0,subVersion:33,Eps:1E-8,Inf:9999999999,RadDeg:57.29577951308232,DegRad:0.017453292519943,IsZero:function(a){return Math.abs(a)<JSM.Eps},IsPositive:function(a){return a>JSM.Eps},IsNegative:function(a){return a<-JSM.Eps},IsLower:function(a,b){return b-a>JSM.Eps},IsGreater:function(a,b){return a-b>JSM.Eps},IsEqual:function(a,b){return Math.abs(b-a)<JSM.Eps},IsEqualWithEps:function(a,b,c){return Math.abs(b-a)<c},IsLowerOrEqual:function(a,b){return JSM.IsLower(a,b)||
|
||||
/* JSModeler 0.33.197 - http://www.github.com/kovacsv/JSModeler */ 'use strict';var JSM={mainVersion:0,subVersion:33,Eps:1E-8,Inf:9999999999,RadDeg:57.29577951308232,DegRad:0.017453292519943,IsZero:function(a){return Math.abs(a)<JSM.Eps},IsPositive:function(a){return a>JSM.Eps},IsNegative:function(a){return a<-JSM.Eps},IsLower:function(a,b){return b-a>JSM.Eps},IsGreater:function(a,b){return a-b>JSM.Eps},IsEqual:function(a,b){return Math.abs(b-a)<JSM.Eps},IsEqualWithEps:function(a,b,c){return Math.abs(b-a)<c},IsLowerOrEqual:function(a,b){return JSM.IsLower(a,b)||
|
||||
JSM.IsEqual(a,b)},IsGreaterOrEqual:function(a,b){return JSM.IsGreater(a,b)||JSM.IsEqual(a,b)},Minimum:function(a,b){return JSM.IsLower(a,b)?a:b},Maximum:function(a,b){return JSM.IsGreater(a,b)?a:b},ArcSin:function(a){return JSM.IsGreaterOrEqual(a,1)?Math.PI/2:JSM.IsLowerOrEqual(a,-1)?-Math.PI/2:Math.asin(a)},ArcCos:function(a){return JSM.IsGreaterOrEqual(a,1)?0:JSM.IsLowerOrEqual(a,-1)?Math.PI:Math.acos(a)},RandomNumber:function(a,b){return Math.random()*(b-a)+a},RandomInt:function(a,b){return Math.floor(Math.random()*
|
||||
(b-a+1)+a)},SeededRandomInt:function(a,b,c){return Math.floor((9301*c+49297)%233280/233280*(b-a+1)+a)},ValueOrDefault:function(a,b){return void 0===a||null===a?b:a},Assert:function(a,b){if(!a){var c="Assertion failed.";void 0!==b&&null!==b&&(c+=" "+b);alert(c)}},Timer:function(){this.stop=this.start=0}};JSM.Timer.prototype.Start=function(){this.start=(new Date).getTime()};JSM.Timer.prototype.Stop=function(){this.end=(new Date).getTime()};JSM.Timer.prototype.Result=function(){return this.end-this.start};
|
||||
JSM.FPSCounter=function(){this.current=this.frames=this.start=null};JSM.FPSCounter.prototype.Get=function(a){var b=(new Date).getTime();null===this.start&&(this.start=b,this.current=this.frames=0);if(null===a||void 0===a)a=1E3;this.frames+=1;var c=b-this.start;c>=a&&(this.current=1E3*(this.frames/c),this.start=b,this.frames=0);return parseInt(this.current,10)};
|
||||
JSM.BubbleSort=function(a,b){if(!(2>a.length||void 0===b||null===b)){var c,d;for(c=0;c<a.length-1;c++)for(d=0;d<a.length-c-1;d++)if(!b(a[d],a[d+1])){var e=a,f=d+1,g=e[d];e[d]=e[f];e[f]=g}}};JSM.AsyncEnvironment=function(a){this.parameters=a};JSM.AsyncEnvironment.prototype.OnStart=function(a,b){if(void 0!==this.parameters&&void 0!==this.parameters.onStart)this.parameters.onStart(a,b)};
|
||||
JSM.AsyncEnvironment.prototype.OnProcess=function(a,b){if(void 0!==this.parameters&&void 0!==this.parameters.onProcess)this.parameters.onProcess(a,b)};JSM.AsyncEnvironment.prototype.OnFinish=function(a){if(void 0!==this.parameters&&void 0!==this.parameters.onFinish)this.parameters.onFinish(a)};
|
||||
JSM.AsyncRunTask=function(a,b,c,d,e){function f(g){var h=a();b.OnProcess(g,e);h&&g<c-1?setTimeout(function(){f(g+1)},d):setTimeout(function(){b.OnFinish(e)},d)}if(void 0===b||null===b){var g,h;for(g=0;g<c&&!(h=a(),!h);g++);}else b.OnStart(c,e),f(0)};JSM.Coord2D=function(a,b){this.x=a;this.y=b};JSM.Coord2D.prototype.Set=function(a,b){this.x=a;this.y=b};JSM.Coord2D.prototype.ToString=function(){return"("+this.x+", "+this.y+")"};JSM.Coord2D.prototype.Clone=function(){return new JSM.Coord2D(this.x,this.y)};
|
||||
JSM.PolarCoord=function(a,b){this.radius=a;this.angle=b};JSM.PolarCoord.prototype.Set=function(a,b){this.radius=a;this.angle=b};JSM.PolarCoord.prototype.ToString=function(){return"("+this.radius+", "+this.angle+")"};JSM.PolarCoord.prototype.Clone=function(){return new JSM.PolarCoord(this.radius,this.angle)};JSM.Coord=function(a,b,c){this.x=a;this.y=b;this.z=c};JSM.Coord.prototype.Set=function(a,b,c){this.x=a;this.y=b;this.z=c};
|
||||
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.SphericalCoord=function(a,b,c){this.radius=a;this.theta=b;this.phi=c};JSM.SphericalCoord.prototype.Set=function(a,b,c){this.radius=a;this.theta=b;this.phi=c};JSM.SphericalCoord.prototype.ToString=function(){return"("+this.radius+", "+this.theta+", "+this.phi+")"};
|
||||
JSM.SphericalCoord.prototype.Clone=function(){return new JSM.SphericalCoord(this.radius,this.theta,this.phi)};JSM.Vector2D=JSM.Coord2D;JSM.Vector=JSM.Coord;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 x=JSM.MatrixDeterminant3x3(f,g,h,l,m,n,q,r,s),v=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 x*a-v*b+h*c-e*d};JSM.CoordFromArray2D=function(a){return new JSM.Coord2D(a[0],a[1])};JSM.CoordFromArray=function(a){return new JSM.Coord(a[0],a[1],a[2])};JSM.CoordIsEqual2D=function(a,b){return JSM.IsEqual(a.x,b.x)&&JSM.IsEqual(a.y,b.y)};
|
||||
JSM.CoordIsEqual2DWithEps=function(a,b,c){return JSM.IsEqualWithEps(a.x,b.x,c)&&JSM.IsEqualWithEps(a.y,b.y,c)};JSM.CoordDistance2D=function(a,b){var c=a.x,d=a.y,e=b.x,f=b.y;return Math.sqrt((e-c)*(e-c)+(f-d)*(f-d))};JSM.MidCoord2D=function(a,b){return new JSM.Coord2D((a.x+b.x)/2,(a.y+b.y)/2)};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.CoordTurnType2D=function(a,b,c){a=JSM.MatrixDeterminant3x3(a.x,a.y,1,b.x,b.y,1,c.x,c.y,1);return JSM.IsPositive(a)?"CounterClockwise":JSM.IsNegative(a)?"Clockwise":"Collinear"};JSM.CoordIsEqual=function(a,b){return JSM.IsEqual(a.x,b.x)&&JSM.IsEqual(a.y,b.y)&&JSM.IsEqual(a.z,b.z)};JSM.CoordIsEqualWithEps=function(a,b,c){return JSM.IsEqualWithEps(a.x,b.x,c)&&JSM.IsEqualWithEps(a.y,b.y,c)&&JSM.IsEqualWithEps(a.z,b.z,c)};
|
||||
JSM.SphericalCoordIsEqual=function(a,b){return JSM.IsEqual(a.radius,b.radius)&&JSM.IsEqual(a.phi,b.phi)&&JSM.IsEqual(a.theta,b.theta)};JSM.CoordDistance=function(a,b){var c=a.x,d=a.y,e=a.z,f=b.x,g=b.y,h=b.z;return Math.sqrt((f-c)*(f-c)+(g-d)*(g-d)+(h-e)*(h-e))};JSM.CoordSignedDistance=function(a,b,c){var d=JSM.CoordSub(b,a);a=JSM.CoordDistance(a,b);c=JSM.GetVectorsAngle(d,c);JSM.IsPositive(c)&&(a=-a);return 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.VectorMultiply=function(a,b){var c=new JSM.Vector(0,0,0);c.x=a.x*b;c.y=a.y*b;c.z=a.z*b;return c};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.VectorLength=function(a){var b=a.x,c=a.y;a=a.z;return Math.sqrt(b*b+c*c+a*a)};
|
||||
JSM.VectorNormalize=function(a){var b=JSM.VectorLength(a),c=new JSM.Vector(0,0,0);JSM.IsGreater(b,0)&&(c=JSM.VectorMultiply(a,1/b));return c};JSM.VectorSetLength=function(a,b){var c=b/JSM.VectorLength(a);return JSM.VectorMultiply(a,c)};JSM.GetVectorsAngle=function(a,b){var c=JSM.VectorNormalize(a),d=JSM.VectorNormalize(b);if(JSM.CoordIsEqual(c,d))return 0;c=JSM.VectorDot(c,d);return JSM.ArcCos(c)};
|
||||
JSM.GetVectorsFullAngle=function(a,b,c){var d=JSM.GetVectorsAngle(a,b),e=new JSM.Coord(0,0,0);"Clockwise"==JSM.CoordTurnType(a,e,b,c)&&(d=2*Math.PI-d);return d};JSM.VectorsAreCollinear=function(a,b){var c=JSM.GetVectorsAngle(a,b);return JSM.IsEqual(c,0)||JSM.IsEqual(c,Math.PI)};JSM.CoordAdd=function(a,b){return new JSM.Vector(a.x+b.x,a.y+b.y,a.z+b.z)};JSM.CoordSub=function(a,b){return new JSM.Vector(a.x-b.x,a.y-b.y,a.z-b.z)};
|
||||
JSM.CoordOffset=function(a,b,c){b=JSM.VectorNormalize(b);var d=new JSM.Coord(0,0,0);d.x=a.x+b.x*c;d.y=a.y+b.y*c;d.z=a.z+b.z*c;return d};
|
||||
JSM.AsyncRunTask=function(a,b,c,d,e){function f(g){var h=a();b.OnProcess(g,e);h&&g<c-1?setTimeout(function(){f(g+1)},d):setTimeout(function(){b.OnFinish(e)},d)}if(void 0===b||null===b){var g,h;for(g=0;g<c&&!(h=a(),!h);g++);}else b.OnStart(c,e),f(0)};JSM.IsWebGLEnabled=function(a){if(!window.WebGLRenderingContext)return!1;try{var b=document.createElement("canvas");if(!b.getContext("experimental-webgl")&&!b.getContext("webgl"))return!1}catch(c){return!1}return!0};
|
||||
JSM.IsFileApiEnabled=function(a){return!window.File||!window.FileReader||!window.FileList||!window.Blob?!1:!0};JSM.Coord2D=function(a,b){this.x=a;this.y=b};JSM.Coord2D.prototype.Set=function(a,b){this.x=a;this.y=b};JSM.Coord2D.prototype.ToString=function(){return"("+this.x+", "+this.y+")"};JSM.Coord2D.prototype.Clone=function(){return new JSM.Coord2D(this.x,this.y)};JSM.PolarCoord=function(a,b){this.radius=a;this.angle=b};JSM.PolarCoord.prototype.Set=function(a,b){this.radius=a;this.angle=b};
|
||||
JSM.PolarCoord.prototype.ToString=function(){return"("+this.radius+", "+this.angle+")"};JSM.PolarCoord.prototype.Clone=function(){return new JSM.PolarCoord(this.radius,this.angle)};JSM.Coord=function(a,b,c){this.x=a;this.y=b;this.z=c};JSM.Coord.prototype.Set=function(a,b,c){this.x=a;this.y=b;this.z=c};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.SphericalCoord=function(a,b,c){this.radius=a;this.theta=b;this.phi=c};JSM.SphericalCoord.prototype.Set=function(a,b,c){this.radius=a;this.theta=b;this.phi=c};JSM.SphericalCoord.prototype.ToString=function(){return"("+this.radius+", "+this.theta+", "+this.phi+")"};JSM.SphericalCoord.prototype.Clone=function(){return new JSM.SphericalCoord(this.radius,this.theta,this.phi)};JSM.Vector2D=JSM.Coord2D;JSM.Vector=JSM.Coord;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 x=JSM.MatrixDeterminant3x3(f,g,h,l,m,n,q,r,s),v=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 x*a-v*b+h*c-e*d};
|
||||
JSM.CoordFromArray2D=function(a){return new JSM.Coord2D(a[0],a[1])};JSM.CoordFromArray=function(a){return new JSM.Coord(a[0],a[1],a[2])};JSM.CoordIsEqual2D=function(a,b){return JSM.IsEqual(a.x,b.x)&&JSM.IsEqual(a.y,b.y)};JSM.CoordIsEqual2DWithEps=function(a,b,c){return JSM.IsEqualWithEps(a.x,b.x,c)&&JSM.IsEqualWithEps(a.y,b.y,c)};JSM.CoordDistance2D=function(a,b){var c=a.x,d=a.y,e=b.x,f=b.y;return Math.sqrt((e-c)*(e-c)+(f-d)*(f-d))};
|
||||
JSM.MidCoord2D=function(a,b){return new JSM.Coord2D((a.x+b.x)/2,(a.y+b.y)/2)};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.CoordTurnType2D=function(a,b,c){a=JSM.MatrixDeterminant3x3(a.x,a.y,1,b.x,b.y,1,c.x,c.y,1);return JSM.IsPositive(a)?"CounterClockwise":JSM.IsNegative(a)?"Clockwise":"Collinear"};
|
||||
JSM.CoordIsEqual=function(a,b){return JSM.IsEqual(a.x,b.x)&&JSM.IsEqual(a.y,b.y)&&JSM.IsEqual(a.z,b.z)};JSM.CoordIsEqualWithEps=function(a,b,c){return JSM.IsEqualWithEps(a.x,b.x,c)&&JSM.IsEqualWithEps(a.y,b.y,c)&&JSM.IsEqualWithEps(a.z,b.z,c)};JSM.SphericalCoordIsEqual=function(a,b){return JSM.IsEqual(a.radius,b.radius)&&JSM.IsEqual(a.phi,b.phi)&&JSM.IsEqual(a.theta,b.theta)};
|
||||
JSM.CoordDistance=function(a,b){var c=a.x,d=a.y,e=a.z,f=b.x,g=b.y,h=b.z;return Math.sqrt((f-c)*(f-c)+(g-d)*(g-d)+(h-e)*(h-e))};JSM.CoordSignedDistance=function(a,b,c){var d=JSM.CoordSub(b,a);a=JSM.CoordDistance(a,b);c=JSM.GetVectorsAngle(d,c);JSM.IsPositive(c)&&(a=-a);return 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.VectorMultiply=function(a,b){var c=new JSM.Vector(0,0,0);c.x=a.x*b;c.y=a.y*b;c.z=a.z*b;return c};
|
||||
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.VectorLength=function(a){var b=a.x,c=a.y;a=a.z;return Math.sqrt(b*b+c*c+a*a)};JSM.VectorNormalize=function(a){var b=JSM.VectorLength(a),c=new JSM.Vector(0,0,0);JSM.IsGreater(b,0)&&(c=JSM.VectorMultiply(a,1/b));return c};
|
||||
JSM.VectorSetLength=function(a,b){var c=b/JSM.VectorLength(a);return JSM.VectorMultiply(a,c)};JSM.GetVectorsAngle=function(a,b){var c=JSM.VectorNormalize(a),d=JSM.VectorNormalize(b);if(JSM.CoordIsEqual(c,d))return 0;c=JSM.VectorDot(c,d);return JSM.ArcCos(c)};JSM.GetVectorsFullAngle=function(a,b,c){var d=JSM.GetVectorsAngle(a,b),e=new JSM.Coord(0,0,0);"Clockwise"==JSM.CoordTurnType(a,e,b,c)&&(d=2*Math.PI-d);return d};
|
||||
JSM.VectorsAreCollinear=function(a,b){var c=JSM.GetVectorsAngle(a,b);return JSM.IsEqual(c,0)||JSM.IsEqual(c,Math.PI)};JSM.CoordAdd=function(a,b){return new JSM.Vector(a.x+b.x,a.y+b.y,a.z+b.z)};JSM.CoordSub=function(a,b){return new JSM.Vector(a.x-b.x,a.y-b.y,a.z-b.z)};JSM.CoordOffset=function(a,b,c){b=JSM.VectorNormalize(b);var d=new JSM.Coord(0,0,0);d.x=a.x+b.x*c;d.y=a.y+b.y*c;d.z=a.z+b.z*c;return d};
|
||||
JSM.CoordRotate=function(a,b,c,d){var e=JSM.CoordSub(a,d),f=JSM.VectorNormalize(b);b=f.x;a=f.y;var f=f.z,g=e.x,h=e.y,e=e.z,k=new JSM.Coord(0,0,0);k.x=-b*(-b*g-a*h-f*e)*(1-Math.cos(c))+g*Math.cos(c)+(-f*h+a*e)*Math.sin(c);k.y=-a*(-b*g-a*h-f*e)*(1-Math.cos(c))+h*Math.cos(c)+(f*g-b*e)*Math.sin(c);k.z=-f*(-b*g-a*h-f*e)*(1-Math.cos(c))+e*Math.cos(c)+(-a*g+b*h)*Math.sin(c);return k=JSM.CoordAdd(k,d)};
|
||||
JSM.GetCoord2DFromCoord=function(a,b,c){var d=new JSM.Vector(0,0,1),e=JSM.VectorCross(c,d);c=JSM.GetVectorsAngle(c,d);a=JSM.CoordRotate(a,e,c,b);return new JSM.Coord2D(a.x,a.y)};
|
||||
JSM.CoordTurnType=function(a,b,c,d){var e=new JSM.Coord(0,0,0);a=JSM.GetCoord2DFromCoord(a,e,d);b=JSM.GetCoord2DFromCoord(b,e,d);c=JSM.GetCoord2DFromCoord(c,e,d);c=JSM.CoordTurnType2D(a,b,c);e=new JSM.Vector(0,0,1);d=JSM.GetVectorsAngle(d,e);JSM.IsEqual(d,Math.PI)&&("CounterClockwise"===c?c="Clockwise":"Clockwise"===c&&(c="CounterClockwise"));return c};
|
||||
@ -422,9 +422,9 @@ JSM.RenderGeometry.prototype.SetNormalArray=function(a){this.normalArray=new Flo
|
||||
JSM.RenderGeometry.prototype.GetNormalBuffer=function(){return this.normalBuffer};JSM.RenderGeometry.prototype.GetUVBuffer=function(){return this.uvBuffer};JSM.RenderGeometry.prototype.VertexCount=function(){return parseInt(this.vertexArray.length/3,10)};JSM.RenderGeometry.prototype.GetVertex=function(a){return new JSM.Coord(this.vertexArray[3*a],this.vertexArray[3*a+1],this.vertexArray[3*a+2])};JSM.RenderGeometry.prototype.GetTransformedVertex=function(a){a=this.GetVertex(a);return this.transformation.Apply(a)};
|
||||
JSM.RenderGeometry.prototype.Compile=function(a,b){this.material.Compile(a,b);this.vertexBuffer=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,this.vertexBuffer);a.bufferData(a.ARRAY_BUFFER,this.vertexArray,a.STATIC_DRAW);this.vertexBuffer.itemSize=3;this.vertexBuffer.numItems=parseInt(this.vertexArray.length/3,10);this.normalBuffer=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,this.normalBuffer);a.bufferData(a.ARRAY_BUFFER,this.normalArray,a.STATIC_DRAW);this.normalBuffer.itemSize=3;this.normalBuffer.numItems=
|
||||
parseInt(this.normalArray.length/3,10);null!==this.uvArray&&(this.uvBuffer=a.createBuffer(),a.bindBuffer(a.ARRAY_BUFFER,this.uvBuffer),a.bufferData(a.ARRAY_BUFFER,this.uvArray,a.STATIC_DRAW),this.uvBuffer.itemSize=2,this.uvBuffer.numItems=parseInt(this.uvArray.length/2,10))};JSM.Renderer=function(){this.geometries=this.light=this.camera=this.texShader=this.shader=this.context=this.canvas=null};
|
||||
JSM.Renderer.prototype.Init=function(a,b,c){return!this.InitContext(a)||!this.InitView(b,c)||!this.InitShaders()||!this.InitBuffers()?!1:!0};
|
||||
JSM.Renderer.prototype.InitContext=function(a){if(!window.WebGLRenderingContext)return!1;this.canvas=a;if(null===this.canvas||void 0===this.canvas.getContext)return!1;this.context=this.canvas.getContext("webgl")||this.canvas.getContext("experimental-webgl");if(null===this.context)return!1;this.context.viewportWidth=this.canvas.width;this.context.viewportHeight=this.canvas.height;this.context.viewport(0,0,this.context.viewportWidth,this.context.viewportHeight);this.context.clearColor(1,1,1,1);this.context.enable(this.context.DEPTH_TEST);
|
||||
this.context.depthFunc(this.context.LEQUAL);this.context.enable(this.context.BLEND);this.context.blendEquation(this.context.FUNC_ADD);this.context.blendFunc(this.context.SRC_ALPHA,this.context.ONE_MINUS_SRC_ALPHA);return!0};
|
||||
JSM.Renderer.prototype.Init=function(a,b,c){return!JSM.IsWebGLEnabled()||!this.InitContext(a)||!this.InitView(b,c)||!this.InitShaders()||!this.InitBuffers()?!1:!0};
|
||||
JSM.Renderer.prototype.InitContext=function(a){this.canvas=a;if(null===this.canvas||void 0===this.canvas.getContext)return!1;this.context=this.canvas.getContext("webgl")||this.canvas.getContext("experimental-webgl");if(null===this.context)return!1;this.context.viewportWidth=this.canvas.width;this.context.viewportHeight=this.canvas.height;this.context.viewport(0,0,this.context.viewportWidth,this.context.viewportHeight);this.context.clearColor(1,1,1,1);this.context.enable(this.context.DEPTH_TEST);this.context.depthFunc(this.context.LEQUAL);
|
||||
this.context.enable(this.context.BLEND);this.context.blendEquation(this.context.FUNC_ADD);this.context.blendFunc(this.context.SRC_ALPHA,this.context.ONE_MINUS_SRC_ALPHA);return!0};
|
||||
JSM.Renderer.prototype.InitShaders=function(){function a(a,b,c){c=a.createShader(c);a.shaderSource(c,b);a.compileShader(c);return!a.getShaderParameter(c,a.COMPILE_STATUS)?null:c}function b(b,c,d){c=a(b,c,b.FRAGMENT_SHADER);d=a(b,d,b.VERTEX_SHADER);if(null===c||null===d)return null;var e=b.createProgram();b.attachShader(e,d);b.attachShader(e,c);b.linkProgram(e);return!b.getProgramParameter(e,b.LINK_STATUS)?null:e}function c(a){var b="";a&&(b="#define USETEXTURE");return[b,"uniform highp vec3 uPolygonAmbientColor;\nuniform highp vec3 uPolygonDiffuseColor;\nuniform highp vec3 uPolygonSpecularColor;\nuniform highp float uPolygonShininess;\nuniform highp vec3 uLightAmbientColor;\nuniform highp vec3 uLightDiffuseColor;\nuniform highp vec3 uLightSpecularColor;\nvarying highp vec3 vVertex;\nvarying highp vec3 vNormal;\nvarying highp vec3 vLight;\n#ifdef USETEXTURE\nvarying highp vec2 vUV;\nuniform sampler2D uSampler;\n#endif\nvoid main (void) {\n\thighp vec3 N = normalize (vNormal);\n\tif (!gl_FrontFacing) {\n\t\tN = -N;\n\t}\n\thighp vec3 L = normalize (-vLight);\n\thighp vec3 E = normalize (-vVertex);\n\thighp vec3 R = normalize (-reflect (L, N));\n\thighp vec3 ambientComponent = uPolygonAmbientColor * uLightAmbientColor;\n\thighp vec3 diffuseComponent = uPolygonDiffuseColor * uLightDiffuseColor * max (dot (N, L), 0.0);\n\thighp vec3 specularComponent = uPolygonSpecularColor * uLightSpecularColor * pow (max (dot (R, E), 0.0), uPolygonShininess);\n#ifdef USETEXTURE\n\thighp vec3 textureColor = texture2D (uSampler, vec2 (vUV.s, vUV.t)).xyz;\n\tambientComponent = textureColor * ambientComponent;\n\tdiffuseComponent = textureColor * diffuseComponent;\n\tspecularComponent = textureColor * specularComponent;\n#endif\n\tambientComponent = clamp (ambientComponent, 0.0, 1.0);\n\tdiffuseComponent = clamp (diffuseComponent, 0.0, 1.0);\n\tspecularComponent = clamp (specularComponent, 0.0, 1.0);\n\tgl_FragColor = vec4 (ambientComponent + diffuseComponent + specularComponent, 1.0);\n}"].join("\n")}
|
||||
function d(a){var b="";a&&(b="#define USETEXTURE");return[b,"attribute highp vec3 aVertexPosition;\nattribute highp vec3 aVertexNormal;\nuniform highp mat4 uViewMatrix;\nuniform highp mat4 uModelViewMatrix;\nuniform highp mat4 uProjectionMatrix;\nuniform highp vec3 uLightDirection;\nvarying highp vec3 vVertex;\nvarying highp vec3 vNormal;\nvarying highp vec3 vLight;\n#ifdef USETEXTURE\nattribute highp vec2 aVertexUV;\nvarying highp vec2 vUV;\n#endif\nvoid main (void) {\n\tvVertex = vec3 (uModelViewMatrix * vec4 (aVertexPosition, 1.0));\n\tvNormal = normalize (vec3 (uModelViewMatrix * vec4 (aVertexNormal, 0.0)));\n\tvLight = normalize (vec3 (uViewMatrix * vec4 (uLightDirection, 0.0)));\n#ifdef USETEXTURE\n\tvUV = aVertexUV;\n#endif\n\tgl_Position = uProjectionMatrix * vec4 (vVertex, 1.0);\n}"].join("\n")}
|
||||
function e(a,b){b.vertexPositionAttribute=a.getAttribLocation(b,"aVertexPosition");b.vertexNormalAttribute=a.getAttribLocation(b,"aVertexNormal");b.lightAmbientColorUniform=a.getUniformLocation(b,"uLightAmbientColor");b.lightDiffuseColorUniform=a.getUniformLocation(b,"uLightDiffuseColor");b.lightSpecularColorUniform=a.getUniformLocation(b,"uLightSpecularColor");b.lightDirectionUniform=a.getUniformLocation(b,"uLightDirection");b.vMatrixUniform=a.getUniformLocation(b,"uViewMatrix");b.mvMatrixUniform=
|
||||
@ -437,8 +437,8 @@ f=JSM.HexColorToNormalizedRGBComponents(this.light.specular);this.light.directio
|
||||
this.light.direction.z),this.context.uniform3f(n.lightAmbientColorUniform,d[0],d[1],d[2]),this.context.uniform3f(n.lightDiffuseColorUniform,e[0],e[1],e[2]),this.context.uniform3f(n.lightSpecularColorUniform,f[0],f[1],f[2])),c=m.material.ambient,h=m.material.diffuse,k=m.material.specular,l=m.material.shininess,this.context.uniform3f(n.polygonAmbientColorUniform,c[0],c[1],c[2]),this.context.uniform3f(n.polygonDiffuseColorUniform,h[0],h[1],h[2]),this.context.uniform3f(n.polygonSpecularColorUniform,k[0],
|
||||
k[1],k[2]),this.context.uniform1f(n.polygonShininessUniform,l),n==this.texShader&&(c=m.GetUVBuffer(),this.context.activeTexture(this.context.TEXTURE0),this.context.bindTexture(this.context.TEXTURE_2D,m.material.textureBuffer),this.context.bindBuffer(this.context.ARRAY_BUFFER,c),this.context.vertexAttribPointer(n.vertexUVAttribute,c.itemSize,this.context.FLOAT,!1,0,0),this.context.enableVertexAttribArray(n.vertexUVAttribute),this.context.uniform1i(n.samplerUniform,0)),c=JSM.MatrixMultiply(m.GetTransformationMatrix(),
|
||||
b),this.context.uniformMatrix4fv(n.mvMatrixUniform,!1,c),c=m.GetVertexBuffer(),this.context.bindBuffer(this.context.ARRAY_BUFFER,c),this.context.enableVertexAttribArray(n.vertexPositionAttribute),this.context.vertexAttribPointer(n.vertexPositionAttribute,c.itemSize,this.context.FLOAT,!1,0,0),m=m.GetNormalBuffer(),this.context.bindBuffer(this.context.ARRAY_BUFFER,m),this.context.enableVertexAttribArray(n.vertexNormalAttribute),this.context.vertexAttribPointer(n.vertexNormalAttribute,m.itemSize,this.context.FLOAT,
|
||||
!1,0,0),this.context.drawArrays(this.context.TRIANGLES,0,c.numItems)};JSM.PointCloudRenderer=function(){this.pointSize=this.points=this.camera=this.shader=this.context=this.canvas=null};JSM.PointCloudRenderer.prototype.Init=function(a,b){return!this.InitContext(a)||!this.InitShaders()||!this.InitBuffers()||!this.InitView(b)?!1:!0};
|
||||
JSM.PointCloudRenderer.prototype.InitContext=function(a){if(!window.WebGLRenderingContext)return!1;this.canvas=a;if(null===this.canvas||void 0===this.canvas.getContext)return!1;this.context=this.canvas.getContext("experimental-webgl");if(null===this.context)return!1;this.context.viewportWidth=this.canvas.width;this.context.viewportHeight=this.canvas.height;this.context.clearColor(1,1,1,1);this.context.enable(this.context.DEPTH_TEST);return!0};
|
||||
!1,0,0),this.context.drawArrays(this.context.TRIANGLES,0,c.numItems)};JSM.PointCloudRenderer=function(){this.pointSize=this.points=this.camera=this.shader=this.context=this.canvas=null};JSM.PointCloudRenderer.prototype.Init=function(a,b){return!JSM.IsWebGLEnabled()||!this.InitContext(a)||!this.InitShaders()||!this.InitBuffers()||!this.InitView(b)?!1:!0};
|
||||
JSM.PointCloudRenderer.prototype.InitContext=function(a){this.canvas=a;if(null===this.canvas||void 0===this.canvas.getContext)return!1;this.context=this.canvas.getContext("experimental-webgl");if(null===this.context)return!1;this.context.viewportWidth=this.canvas.width;this.context.viewportHeight=this.canvas.height;this.context.clearColor(1,1,1,1);this.context.enable(this.context.DEPTH_TEST);return!0};
|
||||
JSM.PointCloudRenderer.prototype.InitShaders=function(){function a(a,b,c){c=a.createShader(c);a.shaderSource(c,b);a.compileShader(c);return!a.getShaderParameter(c,a.COMPILE_STATUS)?null:c}var b=a(this.context,"varying highp vec3 vColor;\nvoid main (void) {\n\tgl_FragColor = vec4 (vColor, 1.0);\n}",this.context.FRAGMENT_SHADER),c=a(this.context,"attribute highp vec3 aVertexPosition;\nattribute highp vec3 aVertexColor;\nuniform highp mat4 uViewMatrix;\nuniform highp mat4 uProjectionMatrix;\nuniform highp float uPointSize;\nvarying highp vec3 vColor;\nvoid main (void) {\n\tvColor = aVertexColor;\n\tgl_PointSize = uPointSize;\n\tgl_Position = uProjectionMatrix * uViewMatrix * vec4 (aVertexPosition, 1.0);\n}",
|
||||
this.context.VERTEX_SHADER);if(null===b||null===c)return!1;this.shader=this.context.createProgram();this.context.attachShader(this.shader,c);this.context.attachShader(this.shader,b);this.context.linkProgram(this.shader);if(!this.context.getProgramParameter(this.shader,this.context.LINK_STATUS))return!1;this.context.useProgram(this.shader);this.shader.vertexPositionAttribute=this.context.getAttribLocation(this.shader,"aVertexPosition");this.context.enableVertexAttribArray(this.shader.vertexPositionAttribute);
|
||||
this.shader.vertexColorAttribute=this.context.getAttribLocation(this.shader,"aVertexColor");this.context.enableVertexAttribArray(this.shader.vertexColorAttribute);this.shader.pMatrixUniform=this.context.getUniformLocation(this.shader,"uProjectionMatrix");this.shader.vMatrixUniform=this.context.getUniformLocation(this.shader,"uViewMatrix");this.shader.pointSizeUniform=this.context.getUniformLocation(this.shader,"uPointSize");return!0};
|
||||
@ -502,7 +502,7 @@ color:u.getHex(),specular:H.getHex(),side:THREE.DoubleSide});1!==m.opacity&&(C.o
|
||||
0],g[z+1],g[z+2])),m.vertices.push(new THREE.Vector3(g[I+0],g[I+1],g[I+2])),m.vertices.push(new THREE.Vector3(g[J+0],g[J+1],g[J+2])),m.faces.push(new THREE.Face3(L+0,L+1,L+2)),z=[],z.push(new THREE.Vector3(h[D+0],h[D+1],h[D+2])),z.push(new THREE.Vector3(h[A+0],h[A+1],h[A+2])),z.push(new THREE.Vector3(h[B+0],h[B+1],h[B+2])),m.faces[M].vertexNormals=z,void 0!==a&&(D=[],D.push(new THREE.Vector2(r[0]+q[u+0]*s[0],r[1]+q[u+1]*s[1])),D.push(new THREE.Vector2(r[0]+q[H+0]*s[0],r[1]+q[H+1]*s[1])),D.push(new THREE.Vector2(r[0]+
|
||||
q[K+0]*s[0],r[1]+q[K+1]*s[1])),m.faceVertexUvs[0].push(D));k=new THREE.Mesh(m,C);k.originalJsonIndex=c;e.push(k)}var g=a.vertices;if(void 0!==g){var h=a.normals;if(void 0!==h){var q=a.uvs;if(void 0!==q){var r=a.triangles,s;for(s=0;s<r.length;s++)d(r[s])}}}}var e=[],f=a.materials;if(void 0===f)return e;var g=a.meshes;if(void 0===g)return e;var h=0;JSM.AsyncRunTask(function(){d(g[h],h);h+=1;return!0},c,g.length,0,e);return e};JSM.JSONFileConverter=function(a,b){this.onReady=a;this.onTextureLoaded=b};
|
||||
JSM.JSONFileConverter.prototype.Convert=function(a){(new JSM.JSONFileLoader(this.OnReady.bind(this))).Load(a)};JSM.JSONFileConverter.prototype.OnReady=function(a){null!==this.onReady&&(a=JSM.ConvertJSONDataToThreeMeshes(a,this.onTextureLoaded),this.onReady(a))};JSM.ThreeViewer=function(){this.enableDraw=this.drawLoop=this.settings=this.navigation=this.cameraMove=this.runAfterRender=this.runBeforeRender=this.directionalLight=this.ambientLight=this.renderer=this.camera=this.scene=this.canvas=null};
|
||||
JSM.ThreeViewer.prototype.Start=function(a,b){if(!this.IsWebGLEnabled()||!this.InitSettings(b)||!this.InitThree(a)||!this.InitCamera(b)||!this.InitLights())return!1;this.drawLoop=!1;this.enableDraw=!0;this.DrawIfNeeded();return!0};JSM.ThreeViewer.prototype.IsWebGLEnabled=function(){return!window.WebGLRenderingContext||!document.createElement("canvas").getContext("experimental-webgl")?!1:!0};
|
||||
JSM.ThreeViewer.prototype.Start=function(a,b){if(!JSM.IsWebGLEnabled()||!this.InitSettings(b)||!this.InitThree(a)||!this.InitCamera(b)||!this.InitLights())return!1;this.drawLoop=!1;this.enableDraw=!0;this.DrawIfNeeded();return!0};
|
||||
JSM.ThreeViewer.prototype.InitSettings=function(a){this.settings={cameraEyePosition:new JSM.Coord(1,1,1),cameraCenterPosition:new JSM.Coord(0,0,0),cameraUpVector:new JSM.Coord(0,0,1),lightAmbientColor:[0.5,0.5,0.5],lightDiffuseColor:[0.5,0.5,0.5]};void 0!==a&&(void 0!==a.cameraEyePosition&&(this.settings.cameraEyePosition=JSM.CoordFromArray(a.cameraEyePosition)),void 0!==a.cameraCenterPosition&&(this.settings.cameraCenterPosition=JSM.CoordFromArray(a.cameraCenterPosition)),void 0!==a.cameraUpVector&&
|
||||
(this.settings.cameraUpVector=JSM.CoordFromArray(a.cameraUpVector)),void 0!==a.lightAmbientColor&&(this.settings.lightAmbientColor=a.lightAmbientColor),void 0!==a.lightDiffuseColor&&(this.settings.lightDiffuseColor=a.lightDiffuseColor));return!0};
|
||||
JSM.ThreeViewer.prototype.InitThree=function(a){this.canvas=a;if(!this.canvas||!this.canvas.getContext)return!1;this.scene=new THREE.Scene;if(!this.scene)return!1;this.renderer=new THREE.WebGLRenderer({canvas:this.canvas,antialias:!0});if(!this.renderer)return!1;this.renderer.setClearColor(new THREE.Color(16777215));this.renderer.setSize(this.canvas.width,this.canvas.height);return!0};
|
||||
|
||||
@ -8,29 +8,7 @@ ImporterApp = function ()
|
||||
|
||||
ImporterApp.prototype.Init = function ()
|
||||
{
|
||||
function CheckSupport ()
|
||||
{
|
||||
if (!window.WebGLRenderingContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
var canvas = document.createElement ('canvas');
|
||||
if (!canvas.getContext ('experimental-webgl') && !canvas.getContext ('webgl')) {
|
||||
return false;
|
||||
}
|
||||
} catch (exception) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!CheckSupport ()) {
|
||||
if (!JSM.IsWebGLEnabled () || !JSM.IsFileApiEnabled ()) {
|
||||
var i, child;
|
||||
|
||||
var children = [];
|
||||
@ -48,7 +26,7 @@ ImporterApp.prototype.Init = function ()
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
var myThis = this;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user