From 477b0095a90a292897542cd907f6aee11e04d02c Mon Sep 17 00:00:00 2001 From: alteredq Date: Sun, 3 Apr 2011 08:48:08 +0200 Subject: [PATCH] Added dumping of scale to Blender exporter / handling of scale to JSONLoader. This is backwards compatible: for existing models that don't have scale nothing should change. --- build/Three.js | 10 ++-- build/custom/ThreeExtras.js | 58 +++++++++---------- src/extras/io/JSONLoader.js | 8 ++- .../op/io_mesh_threejs/export_threejs.py | 8 ++- 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/build/Three.js b/build/Three.js index af2df831bc..329ca911cc 100755 --- a/build/Three.js +++ b/build/Three.js @@ -399,11 +399,11 @@ Math.LN2));k.image.width=o;k.image.height=t;k.image.getContext("2d").drawImage(t THREE.SubtractiveBlending;else if(b.blending=="Multiply")h.blending=THREE.MultiplyBlending;if(b.transparent!==undefined)h.transparent=b.transparent;if(b.depthTest!==undefined)h.depthTest=b.depthTest;if(b.mapDiffuse&&d){j=document.createElement("canvas");h.map=new THREE.Texture(j);h.map.sourceFile=b.mapDiffuse;f(h.map,d+"/"+b.mapDiffuse)}else if(b.colorDiffuse){j=(b.colorDiffuse[0]*255<<16)+(b.colorDiffuse[1]*255<<8)+b.colorDiffuse[2]*255;h.color=j;h.opacity=b.transparency}else if(b.DbgColor)h.color= b.DbgColor;if(b.mapLightmap&&d){j=document.createElement("canvas");h.lightMap=new THREE.Texture(j);h.lightMap.sourceFile=b.mapLightmap;f(h.lightMap,d+"/"+b.mapLightmap)}return new THREE[g](h)}};THREE.JSONLoader=function(b){THREE.Loader.call(this,b)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;THREE.JSONLoader.prototype.supr=THREE.Loader.prototype; THREE.JSONLoader.prototype.load=function(b){var d=this,c=b.model,f=b.callback,g=b.texture_path?b.texture_path:this.extractUrlbase(c);b=new Worker(c);b.onmessage=function(h){d.createModel(h.data,f,g);d.onLoadComplete()};this.onLoadStart();b.postMessage((new Date).getTime())}; -THREE.JSONLoader.prototype.createModel=function(b,d,c){var f=new THREE.Geometry;this.init_materials(f,b.materials,c);(function(){if(b.version===undefined||b.version!=2)console.error("Deprecated file format.");else{var g,h,j,k,n,p,o,t,x,v,z,C,E,J,U,y=b.faces;p=b.vertices;var L=b.normals,N=b.colors,P=0;for(g=0;g>7)-127;qa|=(ha&127)<<16|Da<<8;if(qa==0&&m==-127)return 0;return(1-2*(la>>7))*(1+qa*Math.pow(2,-23))*Math.pow(2,m)}function k(O,aa){var qa=o(O,aa),Da=o(O,aa+1),ha=o(O,aa+2);return(o(O,aa+3)<<24)+(ha<<16)+(Da<<8)+qa}function n(O,aa){var qa=o(O,aa);return(o(O,aa+1)<<8)+qa}function p(O,aa){var qa=o(O,aa); diff --git a/build/custom/ThreeExtras.js b/build/custom/ThreeExtras.js index d9dbd9715c..fc8b31a644 100644 --- a/build/custom/ThreeExtras.js +++ b/build/custom/ThreeExtras.js @@ -1,11 +1,11 @@ // ThreeExtras.js r38 - http://github.com/mrdoob/three.js -var GeometryUtils={merge:function(a,f){var b=f instanceof THREE.Mesh,c=a.vertices.length,e=b?f.geometry:f,d=a.vertices,g=e.vertices,h=a.faces,m=e.faces,k=a.faceVertexUvs[0];e=e.faceVertexUvs[0];b&&f.matrixAutoUpdate&&f.updateMatrix();for(var j=0,n=g.length;j0){g(0,0,-k-(d||0));for(c=a;c0){g(0,0,k+(e||0)); for(c=a+a/2;c<2*a;c++)h.faces.push(new THREE.Face4(2*a+1,(2*c-2*a+2)%a+a,(2*c-2*a+1)%a+a,(2*c-2*a)%a+a))}this.computeCentroids();this.computeFaceNormals()};Cylinder.prototype=new THREE.Geometry;Cylinder.prototype.constructor=Cylinder; -var Icosahedron=function(a){function f(n,p,t){var x=Math.sqrt(n*n+p*p+t*t);return e.vertices.push(new THREE.Vertex(new THREE.Vector3(n/x,p/x,t/x)))-1}function b(n,p,t,x){x.faces.push(new THREE.Face3(n,p,t))}function c(n,p){var t=e.vertices[n].position,x=e.vertices[p].position;return f((t.x+x.x)/2,(t.y+x.y)/2,(t.z+x.z)/2)}var e=this,d=new THREE.Geometry,g;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;f(-1,a,0);f(1,a,0);f(-1,-a,0);f(1,-a,0);f(0,-1,a);f(0,1,a);f(0,-1,-a);f(0, +var Icosahedron=function(a){function f(n,p,t){var w=Math.sqrt(n*n+p*p+t*t);return e.vertices.push(new THREE.Vertex(new THREE.Vector3(n/w,p/w,t/w)))-1}function b(n,p,t,w){w.faces.push(new THREE.Face3(n,p,t))}function c(n,p){var t=e.vertices[n].position,w=e.vertices[p].position;return f((t.x+w.x)/2,(t.y+w.y)/2,(t.z+w.z)/2)}var e=this,d=new THREE.Geometry,g;this.subdivisions=a||0;THREE.Geometry.call(this);a=(1+Math.sqrt(5))/2;f(-1,a,0);f(1,a,0);f(-1,-a,0);f(1,-a,0);f(0,-1,a);f(0,1,a);f(0,-1,-a);f(0, 1,-a);f(a,0,-1);f(a,0,1);f(-a,0,-1);f(-a,0,1);b(0,11,5,d);b(0,5,1,d);b(0,1,7,d);b(0,7,10,d);b(0,10,11,d);b(1,5,9,d);b(5,11,4,d);b(11,10,2,d);b(10,7,6,d);b(7,1,8,d);b(3,9,4,d);b(3,4,2,d);b(3,2,6,d);b(3,6,8,d);b(3,8,9,d);b(4,9,5,d);b(2,4,11,d);b(6,2,10,d);b(8,6,7,d);b(9,8,1,d);for(a=0;a0||(j=this.vertices.push(new THREE.Vertex(new THREE.Vector3(n,h,p)))-1);k.push(j)}f.push(k)}var t,x,w;e=f.length;for(b=0;b0)for(c=0;c1){t=this.vertices[g].position.clone(); -x=this.vertices[m].position.clone();w=this.vertices[k].position.clone();t.normalize();x.normalize();w.normalize();this.faces.push(new THREE.Face3(g,m,k,[new THREE.Vector3(t.x,t.y,t.z),new THREE.Vector3(x.x,x.y,x.z),new THREE.Vector3(w.x,w.y,w.z)]));this.faceVertexUvs[0].push([j,n,u])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere; +var Sphere=function(a,f,b){THREE.Geometry.call(this);var c,e=Math.PI,d=Math.max(3,f||8),g=Math.max(2,b||6);f=[];for(b=0;b0||(j=this.vertices.push(new THREE.Vertex(new THREE.Vector3(n,h,p)))-1);k.push(j)}f.push(k)}var t,w,x;e=f.length;for(b=0;b0)for(c=0;c1){t=this.vertices[g].position.clone(); +w=this.vertices[m].position.clone();x=this.vertices[k].position.clone();t.normalize();w.normalize();x.normalize();this.faces.push(new THREE.Face3(g,m,k,[new THREE.Vector3(t.x,t.y,t.z),new THREE.Vector3(w.x,w.y,w.z),new THREE.Vector3(x.x,x.y,x.z)]));this.faceVertexUvs[0].push([j,n,u])}}}this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals();this.boundingSphere={radius:a}};Sphere.prototype=new THREE.Geometry;Sphere.prototype.constructor=Sphere; var Torus=function(a,f,b,c){this.radius=a||100;this.tube=f||40;this.segmentsR=b||8;this.segmentsT=c||6;a=[];THREE.Geometry.call(this);for(f=0;f<=this.segmentsR;++f)for(b=0;b<=this.segmentsT;++b){c=b/this.segmentsT*2*Math.PI;var e=f/this.segmentsR*2*Math.PI;this.vertices.push(new THREE.Vertex(new THREE.Vector3((this.radius+this.tube*Math.cos(e))*Math.cos(c),(this.radius+this.tube*Math.cos(e))*Math.sin(c),this.tube*Math.sin(e))));a.push([b/this.segmentsT,1-f/this.segmentsR])}for(f=1;f<=this.segmentsR;++f)for(b= 1;b<=this.segmentsT;++b){c=(this.segmentsT+1)*f+b;e=(this.segmentsT+1)*f+b-1;var d=(this.segmentsT+1)*(f-1)+b-1,g=(this.segmentsT+1)*(f-1)+b;this.faces.push(new THREE.Face4(c,e,d,g));this.faceVertexUvs[0].push([new THREE.UV(a[c][0],a[c][1]),new THREE.UV(a[e][0],a[e][1]),new THREE.UV(a[d][0],a[d][1]),new THREE.UV(a[g][0],a[g][1])])}delete a;this.computeCentroids();this.computeFaceNormals();this.computeVertexNormals()};Torus.prototype=new THREE.Geometry;Torus.prototype.constructor=Torus; -var TorusKnot=function(a,f,b,c,e,d,g){function h(n,p,t,x,w,u){p=t/x*n;t=Math.cos(p);return new THREE.Vector3(w*(2+t)*0.5*Math.cos(n),w*(2+t)*Math.sin(n)*0.5,u*w*Math.sin(p)*0.5)}THREE.Geometry.call(this);this.radius=a||200;this.tube=f||40;this.segmentsR=b||64;this.segmentsT=c||8;this.p=e||2;this.q=d||3;this.heightScale=g||1;this.grid=Array(this.segmentsR);b=new THREE.Vector3;c=new THREE.Vector3;d=new THREE.Vector3;for(a=0;a>7)-127;A|=(H&127)<<16|D<<8;if(A==0&&T==-127)return 0;return(1-2*(Q>>7))*(1+A*Math.pow(2,-23))*Math.pow(2,T)}function h(o,v){var A=j(o,v),D=j(o,v+1),H=j(o,v+2);return(j(o,v+3)<<24)+(H<<16)+(D<<8)+A}function m(o,v){var A=j(o,v);return(j(o,v+1)<<8)+A}function k(o,v){var A=j(o,v);return A>127?A-256:A}function j(o, -v){return o.charCodeAt(v)&255}function n(o){var v,A,D;v=h(a,o);A=h(a,o+G);D=h(a,o+K);o=m(a,o+J);THREE.BinaryLoader.prototype.f3(B,v,A,D,o)}function p(o){var v,A,D,H,Q,T;v=h(a,o);A=h(a,o+G);D=h(a,o+K);H=m(a,o+J);Q=h(a,o+I);T=h(a,o+E);o=h(a,o+L);THREE.BinaryLoader.prototype.f3n(B,z,v,A,D,H,Q,T,o)}function t(o){var v,A,D,H;v=h(a,o);A=h(a,o+S);D=h(a,o+P);H=h(a,o+N);o=m(a,o+O);THREE.BinaryLoader.prototype.f4(B,v,A,D,H,o)}function x(o){var v,A,D,H,Q,T,ba,ca;v=h(a,o);A=h(a,o+S);D=h(a,o+P);H=h(a,o+N);Q=m(a, -o+O);T=h(a,o+R);ba=h(a,o+F);ca=h(a,o+M);o=h(a,o+V);THREE.BinaryLoader.prototype.f4n(B,z,v,A,D,H,Q,T,ba,ca,o)}function w(o){var v,A;v=h(a,o);A=h(a,o+W);o=h(a,o+da);THREE.BinaryLoader.prototype.uv3(B.faceVertexUvs[0],C[v*2],C[v*2+1],C[A*2],C[A*2+1],C[o*2],C[o*2+1])}function u(o){var v,A,D;v=h(a,o);A=h(a,o+ea);D=h(a,o+fa);o=h(a,o+ga);THREE.BinaryLoader.prototype.uv4(B.faceVertexUvs[0],C[v*2],C[v*2+1],C[A*2],C[A*2+1],C[D*2],C[D*2+1],C[o*2],C[o*2+1])}var B=this,y=0,l,z=[],C=[],G,K,J,I,E,L,S,P,N,O,R,F, +v){return o.charCodeAt(v)&255}function n(o){var v,A,D;v=h(a,o);A=h(a,o+G);D=h(a,o+K);o=m(a,o+J);THREE.BinaryLoader.prototype.f3(B,v,A,D,o)}function p(o){var v,A,D,H,Q,T;v=h(a,o);A=h(a,o+G);D=h(a,o+K);H=m(a,o+J);Q=h(a,o+I);T=h(a,o+E);o=h(a,o+L);THREE.BinaryLoader.prototype.f3n(B,z,v,A,D,H,Q,T,o)}function t(o){var v,A,D,H;v=h(a,o);A=h(a,o+S);D=h(a,o+P);H=h(a,o+N);o=m(a,o+O);THREE.BinaryLoader.prototype.f4(B,v,A,D,H,o)}function w(o){var v,A,D,H,Q,T,ba,ca;v=h(a,o);A=h(a,o+S);D=h(a,o+P);H=h(a,o+N);Q=m(a, +o+O);T=h(a,o+R);ba=h(a,o+F);ca=h(a,o+M);o=h(a,o+V);THREE.BinaryLoader.prototype.f4n(B,z,v,A,D,H,Q,T,ba,ca,o)}function x(o){var v,A;v=h(a,o);A=h(a,o+W);o=h(a,o+da);THREE.BinaryLoader.prototype.uv3(B.faceVertexUvs[0],C[v*2],C[v*2+1],C[A*2],C[A*2+1],C[o*2],C[o*2+1])}function u(o){var v,A,D;v=h(a,o);A=h(a,o+ea);D=h(a,o+fa);o=h(a,o+ga);THREE.BinaryLoader.prototype.uv4(B.faceVertexUvs[0],C[v*2],C[v*2+1],C[A*2],C[A*2+1],C[D*2],C[D*2+1],C[o*2],C[o*2+1])}var B=this,y=0,l,z=[],C=[],G,K,J,I,E,L,S,P,N,O,R,F, M,V,W,da,ea,fa,ga,X,Y,Z,$,aa,U;THREE.Geometry.call(this);THREE.Loader.prototype.init_materials(B,c,d);l={signature:a.substr(y,8),header_bytes:j(a,y+8),vertex_coordinate_bytes:j(a,y+9),normal_coordinate_bytes:j(a,y+10),uv_coordinate_bytes:j(a,y+11),vertex_index_bytes:j(a,y+12),normal_index_bytes:j(a,y+13),uv_index_bytes:j(a,y+14),material_index_bytes:j(a,y+15),nvertices:h(a,y+16),nnormals:h(a,y+16+4),nuvs:h(a,y+16+8),ntri_flat:h(a,y+16+12),ntri_smooth:h(a,y+16+16),ntri_flat_uv:h(a,y+16+20),ntri_smooth_uv:h(a, y+16+24),nquad_flat:h(a,y+16+28),nquad_smooth:h(a,y+16+32),nquad_flat_uv:h(a,y+16+36),nquad_smooth_uv:h(a,y+16+40)};y+=l.header_bytes;G=l.vertex_index_bytes;K=l.vertex_index_bytes*2;J=l.vertex_index_bytes*3;I=l.vertex_index_bytes*3+l.material_index_bytes;E=l.vertex_index_bytes*3+l.material_index_bytes+l.normal_index_bytes;L=l.vertex_index_bytes*3+l.material_index_bytes+l.normal_index_bytes*2;S=l.vertex_index_bytes;P=l.vertex_index_bytes*2;N=l.vertex_index_bytes*3;O=l.vertex_index_bytes*4;R=l.vertex_index_bytes* 4+l.material_index_bytes;F=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes;M=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes*2;V=l.vertex_index_bytes*4+l.material_index_bytes+l.normal_index_bytes*3;W=l.uv_index_bytes;da=l.uv_index_bytes*2;ea=l.uv_index_bytes;fa=l.uv_index_bytes*2;ga=l.uv_index_bytes*3;d=l.vertex_index_bytes*3+l.material_index_bytes;U=l.vertex_index_bytes*4+l.material_index_bytes;X=l.ntri_flat*d;Y=l.ntri_smooth*(d+l.normal_index_bytes*3);Z=l.ntri_flat_uv* (d+l.uv_index_bytes*3);$=l.ntri_smooth_uv*(d+l.normal_index_bytes*3+l.uv_index_bytes*3);aa=l.nquad_flat*U;d=l.nquad_smooth*(U+l.normal_index_bytes*4);U=l.nquad_flat_uv*(U+l.uv_index_bytes*4);y+=function(o){for(var v,A,D,H=l.vertex_coordinate_bytes*3,Q=o+l.nvertices*H;o=this.maxCount-3&&h(this)};this.begin= function(){this.count=0;this.hasPos=!1;this.hasNormal=!1};this.end=function(b){if(this.count!=0){for(var c=this.count*3;cthis.size-1&&(m=this.size-1);var p=Math.floor(k-h);p<1&&(p=1);k=Math.floor(k+h);k>this.size-1&&(k=this.size-1);var t=Math.floor(j-h);t<1&&(t=1);h=Math.floor(j+h); -h>this.size-1&&(h=this.size-1);for(var x,w,u,B,y,l;n0&&(this.field[u+x]+=B)}}}};this.addPlaneX=function(b,c){var e,d,g,h,m,k=this.size,j=this.yd,n=this.zd,p=this.field,t=k*Math.sqrt(b/c);t>k&&(t=k);for(e=0;e0)for(d=0;dj&&(x=j);for(d=0;d0){m=d*n;for(e=0;esize&&(dist=size);for(g=0;g0){m=zd*g;for(d=0;dthis.size-1&&(h=this.size-1);for(var w,x,u,B,y,l;n0&&(this.field[u+w]+=B)}}}};this.addPlaneX=function(b,c){var e,d,g,h,m,k=this.size,j=this.yd,n=this.zd,p=this.field,t=k*Math.sqrt(b/c);t>k&&(t=k);for(e=0;e0)for(d=0;dj&&(w=j);for(d=0;d0){m=d*n;for(e=0;esize&&(dist=size);for(g=0;g0){m=zd*g;for(d=0;d