Update JSModeler.
This commit is contained in:
parent
e6bad5be12
commit
6946d96374
@ -1,13 +1,13 @@
|
||||
/* JSModeler 0.44 - http://www.github.com/kovacsv/JSModeler */ 'use strict';JSM.ConvertBodyToThreeMeshes=function(a,b,e){var d={textureLoadedCallback:null,hasConvexPolygons:!1};void 0!==e&&null!==e&&(d.textureLoadedCallback=JSM.ValueOrDefault(e.textureLoadedCallback,d.textureLoadedCallback),d.hasConvexPolygons=JSM.ValueOrDefault(e.hasConvexPolygons,d.hasConvexPolygons));var c=[],g=null,f=null;JSM.ExplodeBody(a,b,{hasConvexPolygons:d.hasConvexPolygons,onPointGeometryStart:function(a){f=new THREE.PointsMaterial({color:a.diffuse,size:a.pointSize});g=new THREE.Geometry},
|
||||
/* JSModeler 0.45 - http://www.github.com/kovacsv/JSModeler */ 'use strict';JSM.ConvertBodyToThreeMeshes=function(a,b,e){var d={textureLoadedCallback:null,hasConvexPolygons:!1};void 0!==e&&null!==e&&(d.textureLoadedCallback=JSM.ValueOrDefault(e.textureLoadedCallback,d.textureLoadedCallback),d.hasConvexPolygons=JSM.ValueOrDefault(e.hasConvexPolygons,d.hasConvexPolygons));var c=[],g=null,f=null;JSM.ExplodeBody(a,b,{hasConvexPolygons:d.hasConvexPolygons,onPointGeometryStart:function(a){f=new THREE.PointsMaterial({color:a.diffuse,size:a.pointSize});g=new THREE.Geometry},
|
||||
onPointGeometryEnd:function(){var a=new THREE.Points(g,f);c.push(a)},onPoint:function(a){g.vertices.push(new THREE.Vector3(a.x,a.y,a.z))},onLineGeometryStart:function(a){g=new THREE.Geometry;f=new THREE.LineBasicMaterial({color:a.diffuse})},onLineGeometryEnd:function(){var a=new THREE.LineSegments(g,f);c.push(a)},onLine:function(a,b){g.vertices.push(new THREE.Vector3(a.x,a.y,a.z));g.vertices.push(new THREE.Vector3(b.x,b.y,b.z))},onGeometryStart:function(a){var b=null!==a.texture,e=1!==a.opacity,c=
|
||||
a.diffuse,F=a.specular,u=a.shininess;0===u&&(F=0,u=1);f=new THREE.MeshPhongMaterial({color:c,specular:F,shininess:u});a.singleSided||(f.side=THREE.DoubleSide);e&&(f.opacity=a.opacity,f.transparent=!0);if(b){var n=f;a=a.texture;(new THREE.TextureLoader).load(a,function(a){a.image=JSM.ResizeImageToPowerOfTwoSides(a.image);a.wrapS=THREE.RepeatWrapping;a.wrapT=THREE.RepeatWrapping;n.map=a;n.needsUpdate=!0;null!==d.textureLoadedCallback&&d.textureLoadedCallback()})}g=new THREE.Geometry},onGeometryEnd:function(){g.computeFaceNormals();
|
||||
var a=new THREE.Mesh(g,f);c.push(a)},onTriangle:function(a,b,e,c,d,f,n,E,l){var p=g.vertices.length;g.vertices.push(new THREE.Vector3(a.x,a.y,a.z));g.vertices.push(new THREE.Vector3(b.x,b.y,b.z));g.vertices.push(new THREE.Vector3(e.x,e.y,e.z));a=new THREE.Face3(p+0,p+1,p+2);g.faces.push(a);null!==c&&(null!==d&&null!==f)&&(a=[],a.push(new THREE.Vector3(c.x,c.y,c.z)),a.push(new THREE.Vector3(d.x,d.y,d.z)),a.push(new THREE.Vector3(f.x,f.y,f.z)),g.faces[g.faces.length-1].vertexNormals=a);null!==n&&(null!==
|
||||
E&&null!==l)&&(c=[],c.push(new THREE.Vector2(n.x,-n.y)),c.push(new THREE.Vector2(E.x,-E.y)),c.push(new THREE.Vector2(l.x,-l.y)),g.faceVertexUvs[0].push(c))}});return c};JSM.ConvertModelToThreeMeshes=function(a,b){var e=[],d=a.GetMaterialSet(),c,g,f;for(c=0;c<a.BodyCount();c++){g=a.GetBody(c);f=JSM.ConvertBodyToThreeMeshes(g,d,b);for(g=0;g<f.length;g++)e.push(f[g])}return e};
|
||||
JSM.ConvertJSONDataToThreeMeshes=function(a,b,e){function d(a,e,c,d){function g(a,c,d,f,k,p){function n(a,b,c,e,d){var f=new THREE.Vector2(a,b);if(!JSM.IsZero(d)){var g=Math.sin(d*JSM.DegRad);d=Math.cos(d*JSM.DegRad);f.x=d*a-g*b;f.y=g*a+d*b}f.x=c[0]+f.x*e[0];f.y=c[1]+f.y*e[1];return f}var q=a.parameters,h=k[a.material];a=h.texture;k=h.offset;var l=h.scale,v=h.rotation,w=new THREE.Color,t=new THREE.Color,x=h.shininess||0;w.setRGB(h.diffuse[0],h.diffuse[1],h.diffuse[2]);t.setRGB(h.specular[0],h.specular[1],
|
||||
h.specular[2]);if(void 0!==a&&null!==a){w.setRGB(1,1,1);t.setRGB(1,1,1);if(void 0===k||null===k)k=[0,0];if(void 0===l||null===l)l=[1,1];if(void 0===v||null===v)v=0}0===x&&(t.setRGB(0,0,0),x=1);var y=new THREE.MeshPhongMaterial({color:w.getHex(),specular:t.getHex(),shininess:x,side:THREE.DoubleSide});1!==h.opacity&&(y.opacity=h.opacity,y.transparent=!0);void 0!==a&&null!==a&&(new THREE.TextureLoader).load(a,function(a){a.image=JSM.ResizeImageToPowerOfTwoSides(a.image);a.wrapS=THREE.RepeatWrapping;
|
||||
a.wrapT=THREE.RepeatWrapping;y.map=a;y.needsUpdate=!0;void 0!==b&&null!==b&&b()});var h=new THREE.Geometry,r,z,A,s,B,C,D,u,m;for(m=0;m<q.length;m+=9)r=3*q[m+0],z=3*q[m+1],A=3*q[m+2],s=3*q[m+3],B=3*q[m+4],C=3*q[m+5],w=2*q[m+6],t=2*q[m+7],x=2*q[m+8],D=h.vertices.length,u=h.faces.length,h.vertices.push(new THREE.Vector3(c[r+0],c[r+1],c[r+2])),h.vertices.push(new THREE.Vector3(c[z+0],c[z+1],c[z+2])),h.vertices.push(new THREE.Vector3(c[A+0],c[A+1],c[A+2])),h.faces.push(new THREE.Face3(D+0,D+1,D+2)),r=
|
||||
[],r.push(new THREE.Vector3(d[s+0],d[s+1],d[s+2])),r.push(new THREE.Vector3(d[B+0],d[B+1],d[B+2])),r.push(new THREE.Vector3(d[C+0],d[C+1],d[C+2])),h.faces[u].vertexNormals=r,void 0!==a&&null!==a&&(s=[],s.push(n(f[w+0],f[w+1],k,l,v)),s.push(n(f[t+0],f[t+1],k,l,v)),s.push(n(f[x+0],f[x+1],k,l,v)),h.faceVertexUvs[0].push(s));c=new THREE.Mesh(h,y);c.originalJsonIndex=e;p.push(c)}var f=a.vertices;if(void 0!==f){var k=a.normals;if(void 0!==k){var l=a.uvs;if(void 0!==l){a=a.triangles;var p;for(p=0;p<a.length;p++)g(a[p],
|
||||
f,k,l,c,d)}}}}var c=[],g=a.materials;if(void 0===g)return c;var f=a.meshes;if(void 0===f)return c;var k=0;JSM.AsyncRunTask(function(){d(f[k],k,g,c);k+=1;return!0},e,f.length,0,c);return c};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};
|
||||
a.diffuse,G=a.specular,t=a.shininess;0===t&&(G=0,t=1);f=new THREE.MeshPhongMaterial({color:c,specular:G,shininess:t});a.singleSided||(f.side=THREE.DoubleSide);e&&(f.opacity=a.opacity,f.transparent=!0);if(b){var m=f;a=a.texture;(new THREE.TextureLoader).load(a,function(a){a.image=JSM.ResizeImageToPowerOfTwoSides(a.image);a.wrapS=THREE.RepeatWrapping;a.wrapT=THREE.RepeatWrapping;m.map=a;m.needsUpdate=!0;null!==d.textureLoadedCallback&&d.textureLoadedCallback()})}g=new THREE.Geometry},onGeometryEnd:function(){g.computeFaceNormals();
|
||||
var a=new THREE.Mesh(g,f);c.push(a)},onTriangle:function(a,b,e,c,d,f,m,F,p){var n=g.vertices.length;g.vertices.push(new THREE.Vector3(a.x,a.y,a.z));g.vertices.push(new THREE.Vector3(b.x,b.y,b.z));g.vertices.push(new THREE.Vector3(e.x,e.y,e.z));a=new THREE.Face3(n+0,n+1,n+2);g.faces.push(a);null!==c&&(null!==d&&null!==f)&&(a=[],a.push(new THREE.Vector3(c.x,c.y,c.z)),a.push(new THREE.Vector3(d.x,d.y,d.z)),a.push(new THREE.Vector3(f.x,f.y,f.z)),g.faces[g.faces.length-1].vertexNormals=a);null!==m&&(null!==
|
||||
F&&null!==p)&&(c=[],c.push(new THREE.Vector2(m.x,-m.y)),c.push(new THREE.Vector2(F.x,-F.y)),c.push(new THREE.Vector2(p.x,-p.y)),g.faceVertexUvs[0].push(c))}});return c};JSM.ConvertModelToThreeMeshes=function(a,b){var e=[],d=a.GetMaterialSet(),c,g,f;for(c=0;c<a.BodyCount();c++){g=a.GetBody(c);f=JSM.ConvertBodyToThreeMeshes(g,d,b);for(g=0;g<f.length;g++)e.push(f[g])}return e};
|
||||
JSM.ConvertJSONDataToThreeMeshes=function(a,b,e){function d(a,e,c,d){function g(a,c,d,f,k,n){function m(a,b,c,e,d){var f=new THREE.Vector2(a,b);if(!JSM.IsZero(d)){var g=Math.sin(d*JSM.DegRad);d=Math.cos(d*JSM.DegRad);f.x=d*a-g*b;f.y=g*a+d*b}f.x=c[0]+f.x*e[0];f.y=c[1]+f.y*e[1];return f}var p=a.material;a=a.parameters;var h=k[p];k=h.texture;var u=h.offset,v=h.scale,w=h.rotation,x=new THREE.Color,s=new THREE.Color,y=h.shininess||0;x.setRGB(h.diffuse[0],h.diffuse[1],h.diffuse[2]);s.setRGB(h.specular[0],
|
||||
h.specular[1],h.specular[2]);if(void 0!==k&&null!==k){x.setRGB(1,1,1);s.setRGB(1,1,1);if(void 0===u||null===u)u=[0,0];if(void 0===v||null===v)v=[1,1];if(void 0===w||null===w)w=0}0===y&&(s.setRGB(0,0,0),y=1);var z=new THREE.MeshPhongMaterial({color:x.getHex(),specular:s.getHex(),shininess:y,side:THREE.DoubleSide});1!==h.opacity&&(z.opacity=h.opacity,z.transparent=!0);void 0!==k&&null!==k&&(new THREE.TextureLoader).load(k,function(a){a.image=JSM.ResizeImageToPowerOfTwoSides(a.image);a.wrapS=THREE.RepeatWrapping;
|
||||
a.wrapT=THREE.RepeatWrapping;z.map=a;z.needsUpdate=!0;void 0!==b&&null!==b&&b()});var h=new THREE.Geometry,q,A,B,r,C,D,E,t,l;for(l=0;l<a.length;l+=9)q=3*a[l+0],A=3*a[l+1],B=3*a[l+2],r=3*a[l+3],C=3*a[l+4],D=3*a[l+5],x=2*a[l+6],s=2*a[l+7],y=2*a[l+8],E=h.vertices.length,t=h.faces.length,h.vertices.push(new THREE.Vector3(c[q+0],c[q+1],c[q+2])),h.vertices.push(new THREE.Vector3(c[A+0],c[A+1],c[A+2])),h.vertices.push(new THREE.Vector3(c[B+0],c[B+1],c[B+2])),h.faces.push(new THREE.Face3(E+0,E+1,E+2)),q=
|
||||
[],q.push(new THREE.Vector3(d[r+0],d[r+1],d[r+2])),q.push(new THREE.Vector3(d[C+0],d[C+1],d[C+2])),q.push(new THREE.Vector3(d[D+0],d[D+1],d[D+2])),h.faces[t].vertexNormals=q,void 0!==k&&null!==k&&(r=[],r.push(m(f[x+0],f[x+1],u,v,w)),r.push(m(f[s+0],f[s+1],u,v,w)),r.push(m(f[y+0],f[y+1],u,v,w)),h.faceVertexUvs[0].push(r));c=new THREE.Mesh(h,z);c.originalJsonMaterialIndex=p;c.originalJsonMeshIndex=e;n.push(c)}var f=a.vertices;if(void 0!==f){var k=a.normals;if(void 0!==k){var p=a.uvs;if(void 0!==p){a=
|
||||
a.triangles;var n;for(n=0;n<a.length;n++)g(a[n],f,k,p,c,d)}}}}var c=[],g=a.materials;if(void 0===g)return c;var f=a.meshes;if(void 0===f)return c;var k=0;JSM.AsyncRunTask(function(){d(f[k],k,g,c);k+=1;return!0},e,f.length,0,c);return c};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(!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};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* JSModeler 0.44 - http://www.github.com/kovacsv/JSModeler */ 'use strict';var JSM=function(){this.mainVersion=0;this.subVersion=44};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?a-1:b-1};
|
||||
/* JSModeler 0.45 - http://www.github.com/kovacsv/JSModeler */ 'use strict';var JSM=function(){this.mainVersion=0;this.subVersion=45};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?a-1:b-1};
|
||||
JSM.NextIndex=function(a,b){return a<b-1?a+1:0};JSM.CopyObjectProperties=function(a,b,c){if(!(void 0===a||null===a||void 0===b||null===b))for(var d in a)if(a.hasOwnProperty(d)&&(c||void 0===b[d]||null===b[d]))b[d]=a[d]};JSM.GetObjectProperty=function(a,b,c){if(void 0===a||null===a)return c;a=a[b];return void 0===a||null===a?c:a};JSM.Message=function(a){console.log("JSModeler: "+a)};JSM.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.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.length-1;d++)for(e=0;e<a.length-d-1;e++)b(a[e],a[e+1])||c(e,e+1);return!0};JSM.ShiftArray=function(a,b){var c;for(c=0;c<b;c++)a.push(a.shift())};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user