提交 c4977093 编写于 作者: A alteredq

Added texture repeat support to Blender model and scene exporters.

Also fixed default camera buggy string in Blender scene exporter and changed lightmap parameter name in base Loader (to be consistent with other "maps").
上级 2b599e1a
......@@ -470,8 +470,8 @@ THREE.Loader.prototype={addStatusElement:function(){var b=document.createElement
this.statusDomElement.innerHTML=c},extractUrlbase:function(b){b=b.split("/");b.pop();return b.join("/")},init_materials:function(b,c,d){b.materials=[];for(var e=0;e<c.length;++e)b.materials[e]=[THREE.Loader.prototype.createMaterial(c[e],d)]},createMaterial:function(b,c){function d(b){b=Math.log(b)/Math.LN2;return Math.floor(b)==b}function e(b,c){var e=new Image;e.onload=function(){if(!d(this.width)||!d(this.height)){var c=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),e=Math.pow(2,Math.round(Math.log(this.height)/
Math.LN2));b.image.width=c;b.image.height=e;b.image.getContext("2d").drawImage(this,0,0,c,e)}else b.image=this;b.needsUpdate=!0};e.src=c}var f,g,j;f="MeshLambertMaterial";g={color:15658734,opacity:1,map:null,lightMap:null,wireframe:b.wireframe};b.shading&&(b.shading=="Phong"?f="MeshPhongMaterial":b.shading=="Basic"&&(f="MeshBasicMaterial"));if(b.blending)if(b.blending=="Additive")g.blending=THREE.AdditiveBlending;else if(b.blending=="Subtractive")g.blending=THREE.SubtractiveBlending;else if(b.blending==
"Multiply")g.blending=THREE.MultiplyBlending;if(b.transparent!==void 0||b.opacity<1)g.transparent=b.transparent;if(b.depthTest!==void 0)g.depthTest=b.depthTest;if(b.vertexColors!==void 0)if(b.vertexColors=="face")g.vertexColors=THREE.FaceColors;else if(b.vertexColors)g.vertexColors=THREE.VertexColors;if(b.mapDiffuse&&c){j=document.createElement("canvas");g.map=new THREE.Texture(j);g.map.sourceFile=b.mapDiffuse;if(b.mapDiffuseRepeat)g.map.repeat.set(b.mapDiffuseRepeat[0],b.mapDiffuseRepeat[1]),g.map.wrapS=
g.map.wrapT=THREE.RepeatWrapping;b.mapDiffuseOffset&&g.map.offset.set(b.mapDiffuseOffset[0],b.mapDiffuseOffset[1]);e(g.map,c+"/"+b.mapDiffuse)}else if(b.colorDiffuse)j=(b.colorDiffuse[0]*255<<16)+(b.colorDiffuse[1]*255<<8)+b.colorDiffuse[2]*255,g.color=j,g.opacity=b.transparency;else if(b.DbgColor)g.color=b.DbgColor;if(b.mapLightmap&&c){j=document.createElement("canvas");g.lightMap=new THREE.Texture(j);g.lightMap.sourceFile=b.mapLightmap;if(b.mapLightmapRepeat)g.lightMap.repeat.set(b.mapLightmapRepeat[0],
b.mapLightmapRepeat[1]),g.lightMap.wrapS=g.lightMap.wrapT=THREE.RepeatWrapping;b.mapLightmapOffset&&g.lightMap.offset.set(b.mapLightmapOffset[0],b.mapLightmapOffset[1]);e(g.lightMap,c+"/"+b.mapLightmap)}return new THREE[f](g)}};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;
g.map.wrapT=THREE.RepeatWrapping;b.mapDiffuseOffset&&g.map.offset.set(b.mapDiffuseOffset[0],b.mapDiffuseOffset[1]);e(g.map,c+"/"+b.mapDiffuse)}else if(b.colorDiffuse)j=(b.colorDiffuse[0]*255<<16)+(b.colorDiffuse[1]*255<<8)+b.colorDiffuse[2]*255,g.color=j,g.opacity=b.transparency;else if(b.DbgColor)g.color=b.DbgColor;if(b.mapLight&&c){j=document.createElement("canvas");g.lightMap=new THREE.Texture(j);g.lightMap.sourceFile=b.mapLight;if(b.mapLightmapRepeat)g.lightMap.repeat.set(b.mapLightRepeat[0],
b.mapLightRepeat[1]),g.lightMap.wrapS=g.lightMap.wrapT=THREE.RepeatWrapping;b.mapLightmapOffset&&g.lightMap.offset.set(b.mapLightmapOffset[0],b.mapLightmapOffset[1]);e(g.lightMap,c+"/"+b.mapLightmap)}return new THREE[f](g)}};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 c=this,d=b.model,e=b.callback,f=b.texture_path?b.texture_path:this.extractUrlbase(d),b=new Worker(d);b.onmessage=function(b){c.createModel(b.data,e,f);c.onLoadComplete()};this.onLoadStart();b.postMessage((new Date).getTime())};
THREE.JSONLoader.prototype.createModel=function(b,c,d){var e=new THREE.Geometry,f=b.scale!==void 0?1/b.scale:1;this.init_materials(e,b.materials,d);(function(c){if(b.version===void 0||b.version!=2)console.error("Deprecated file format.");else{var d,f,m,o,n,p,t,u,v,z,A,x,G,y,D=b.faces;p=b.vertices;var F=b.normals,B=b.colors,P=0;for(d=0;d<b.uvs.length;d++)b.uvs[d].length&&P++;for(d=0;d<P;d++)e.faceUvs[d]=[],e.faceVertexUvs[d]=[];o=0;for(n=p.length;o<n;)t=new THREE.Vertex,t.position.x=p[o++]*c,t.position.y=
p[o++]*c,t.position.z=p[o++]*c,e.vertices.push(t);o=0;for(n=D.length;o<n;){c=D[o++];p=c&1;m=c&2;d=c&4;f=c&8;u=c&16;t=c&32;z=c&64;c&=128;p?(A=new THREE.Face4,A.a=D[o++],A.b=D[o++],A.c=D[o++],A.d=D[o++],p=4):(A=new THREE.Face3,A.a=D[o++],A.b=D[o++],A.c=D[o++],p=3);if(m)m=D[o++],A.materials=e.materials[m];m=e.faces.length;if(d)for(d=0;d<P;d++)x=b.uvs[d],v=D[o++],y=x[v*2],v=x[v*2+1],e.faceUvs[d][m]=new THREE.UV(y,v);if(f)for(d=0;d<P;d++){x=b.uvs[d];G=[];for(f=0;f<p;f++)v=D[o++],y=x[v*2],v=x[v*2+1],G[f]=
......@@ -504,9 +504,9 @@ function(){h-=1;n();d.onLoadComplete()};for(z in E.cameras){D=E.cameras[z];if(D.
N.cameras[E.defaults.camera];if(N.fogs&&E.defaults.fog)N.scene.fog=N.fogs[E.defaults.fog];D=E.defaults.bgcolor;N.bgColor=new THREE.Color;N.bgColor.setRGB(D[0],D[1],D[2]);N.bgColorAlpha=E.defaults.bgalpha;for(p in E.geometries)if(A=E.geometries[p],A.type=="bin_mesh"||A.type=="ascii_mesh")T+=1,d.onLoadStart();Q=T;for(p in E.geometries)A=E.geometries[p],A.type=="cube"?(B=new THREE.CubeGeometry(A.width,A.height,A.depth,A.segmentsWidth,A.segmentsHeight,A.segmentsDepth,null,A.flipped,A.sides),N.geometries[p]=
B):A.type=="plane"?(B=new THREE.PlaneGeometry(A.width,A.height,A.segmentsWidth,A.segmentsHeight),N.geometries[p]=B):A.type=="sphere"?(B=new THREE.SphereGeometry(A.radius,A.segmentsWidth,A.segmentsHeight),N.geometries[p]=B):A.type=="cylinder"?(B=new THREE.CylinderGeometry(A.numSegs,A.topRad,A.botRad,A.height,A.topOffset,A.botOffset),N.geometries[p]=B):A.type=="torus"?(B=new THREE.TorusGeometry(A.radius,A.tube,A.segmentsR,A.segmentsT),N.geometries[p]=B):A.type=="icosahedron"?(B=new THREE.IcosahedronGeometry(A.subdivisions),
N.geometries[p]=B):A.type=="bin_mesh"?b.load({model:e(A.url,E.urlBaseType),callback:m(p)}):A.type=="ascii_mesh"?M.load({model:e(A.url,E.urlBaseType),callback:m(p)}):A.type=="embedded_mesh"&&(A=E.embeds[A.id])&&M.createModel(A,o(p),"");for(x in E.textures)if(p=E.textures[x],p.url instanceof Array){h+=p.url.length;for(b=0;b<p.url.length;b++)d.onLoadStart()}else h+=1,d.onLoadStart();R=h;for(x in E.textures){p=E.textures[x];if(p.mapping!=void 0&&THREE[p.mapping]!=void 0)p.mapping=new THREE[p.mapping];
if(p.url instanceof Array){for(var b=[],V=0;V<p.url.length;V++)b[V]=e(p.url[V],E.urlBaseType);b=THREE.ImageUtils.loadTextureCube(b,p.mapping,aa)}else{b=THREE.ImageUtils.loadTexture(e(p.url,E.urlBaseType),p.mapping,aa);if(THREE[p.minFilter]!=void 0)b.minFilter=THREE[p.minFilter];if(THREE[p.magFilter]!=void 0)b.magFilter=THREE[p.magFilter]}N.textures[x]=b}for(t in E.materials){x=E.materials[t];for(F in x.parameters)if(F=="envMap"||F=="map"||F=="lightMap")x.parameters[F]=N.textures[x.parameters[F]];
else if(F=="shading")x.parameters[F]=x.parameters[F]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(F=="blending")x.parameters[F]=THREE[x.parameters[F]]?THREE[x.parameters[F]]:THREE.NormalBlending;else if(F=="combine")x.parameters[F]=x.parameters[F]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(F=="vertexColors")if(x.parameters[F]=="face")x.parameters[F]=THREE.FaceColors;else if(x.parameters[F])x.parameters[F]=THREE.VertexColors;if(x.parameters.opacity!==void 0&&x.parameters.opacity<
1)x.parameters.transparent=!0;x=new THREE[x.type](x.parameters);N.materials[t]=x}k();d.callbackSync(N)}}};
if(p.url instanceof Array){for(var b=[],V=0;V<p.url.length;V++)b[V]=e(p.url[V],E.urlBaseType);b=THREE.ImageUtils.loadTextureCube(b,p.mapping,aa)}else{b=THREE.ImageUtils.loadTexture(e(p.url,E.urlBaseType),p.mapping,aa);if(THREE[p.minFilter]!=void 0)b.minFilter=THREE[p.minFilter];if(THREE[p.magFilter]!=void 0)b.magFilter=THREE[p.magFilter];if(p.repeat)b.repeat.set(p.repeat[0],p.repeat[1]),b.wrapS=b.wrapT=THREE.RepeatWrapping}N.textures[x]=b}for(t in E.materials){x=E.materials[t];for(F in x.parameters)if(F==
"envMap"||F=="map"||F=="lightMap")x.parameters[F]=N.textures[x.parameters[F]];else if(F=="shading")x.parameters[F]=x.parameters[F]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(F=="blending")x.parameters[F]=THREE[x.parameters[F]]?THREE[x.parameters[F]]:THREE.NormalBlending;else if(F=="combine")x.parameters[F]=x.parameters[F]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(F=="vertexColors")if(x.parameters[F]=="face")x.parameters[F]=THREE.FaceColors;else if(x.parameters[F])x.parameters[F]=
THREE.VertexColors;if(x.parameters.opacity!==void 0&&x.parameters.opacity<1)x.parameters.transparent=!0;x=new THREE[x.type](x.parameters);N.materials[t]=x}k();d.callbackSync(N)}}};
THREE.MarchingCubes=function(b,c){THREE.Object3D.call(this);this.materials=c instanceof Array?c:[c];this.init=function(b){this.isolation=80;this.size=b;this.size2=this.size*this.size;this.size3=this.size2*this.size;this.halfsize=this.size/2;this.delta=2/this.size;this.yd=this.size;this.zd=this.size2;this.field=new Float32Array(this.size3);this.normal_cache=new Float32Array(this.size3*3);this.vlist=new Float32Array(36);this.nlist=new Float32Array(36);this.firstDraw=!0;this.maxCount=4096;this.count=
0;this.hasNormal=this.hasPos=!1;this.positionArray=new Float32Array(this.maxCount*3);this.normalArray=new Float32Array(this.maxCount*3)};this.lerp=function(b,c,f){return b+(c-b)*f};this.VIntX=function(b,c,f,g,j,k,m,o,n,p){j=(j-n)/(p-n);n=this.normal_cache;c[g]=k+j*this.delta;c[g+1]=m;c[g+2]=o;f[g]=this.lerp(n[b],n[b+3],j);f[g+1]=this.lerp(n[b+1],n[b+4],j);f[g+2]=this.lerp(n[b+2],n[b+5],j)};this.VIntY=function(b,c,f,g,j,k,m,o,n,p){j=(j-n)/(p-n);n=this.normal_cache;c[g]=k;c[g+1]=m+j*this.delta;c[g+
2]=o;c=b+this.yd*3;f[g]=this.lerp(n[b],n[c],j);f[g+1]=this.lerp(n[b+1],n[c+1],j);f[g+2]=this.lerp(n[b+2],n[c+2],j)};this.VIntZ=function(b,c,f,g,j,k,m,o,n,p){j=(j-n)/(p-n);n=this.normal_cache;c[g]=k;c[g+1]=m;c[g+2]=o+j*this.delta;c=b+this.zd*3;f[g]=this.lerp(n[b],n[c],j);f[g+1]=this.lerp(n[b+1],n[c+1],j);f[g+2]=this.lerp(n[b+2],n[c+2],j)};this.compNorm=function(b){var c=b*3;this.normal_cache[c]==0&&(this.normal_cache[c]=this.field[b-1]-this.field[b+1],this.normal_cache[c+1]=this.field[b-this.yd]-this.field[b+
......
......@@ -128,8 +128,8 @@ THREE.Loader.prototype={addStatusElement:function(){var a=document.createElement
this.statusDomElement.innerHTML=b},extractUrlbase:function(a){a=a.split("/");a.pop();return a.join("/")},init_materials:function(a,b,c){a.materials=[];for(var d=0;d<b.length;++d)a.materials[d]=[THREE.Loader.prototype.createMaterial(b[d],c)]},createMaterial:function(a,b){function c(a){a=Math.log(a)/Math.LN2;return Math.floor(a)==a}function d(a,b){var d=new Image;d.onload=function(){if(!c(this.width)||!c(this.height)){var b=Math.pow(2,Math.round(Math.log(this.width)/Math.LN2)),d=Math.pow(2,Math.round(Math.log(this.height)/
Math.LN2));a.image.width=b;a.image.height=d;a.image.getContext("2d").drawImage(this,0,0,b,d)}else a.image=this;a.needsUpdate=!0};d.src=b}var e,f,g;e="MeshLambertMaterial";f={color:15658734,opacity:1,map:null,lightMap:null,wireframe:a.wireframe};a.shading&&(a.shading=="Phong"?e="MeshPhongMaterial":a.shading=="Basic"&&(e="MeshBasicMaterial"));if(a.blending)if(a.blending=="Additive")f.blending=THREE.AdditiveBlending;else if(a.blending=="Subtractive")f.blending=THREE.SubtractiveBlending;else if(a.blending==
"Multiply")f.blending=THREE.MultiplyBlending;if(a.transparent!==void 0||a.opacity<1)f.transparent=a.transparent;if(a.depthTest!==void 0)f.depthTest=a.depthTest;if(a.vertexColors!==void 0)if(a.vertexColors=="face")f.vertexColors=THREE.FaceColors;else if(a.vertexColors)f.vertexColors=THREE.VertexColors;if(a.mapDiffuse&&b){g=document.createElement("canvas");f.map=new THREE.Texture(g);f.map.sourceFile=a.mapDiffuse;if(a.mapDiffuseRepeat)f.map.repeat.set(a.mapDiffuseRepeat[0],a.mapDiffuseRepeat[1]),f.map.wrapS=
f.map.wrapT=THREE.RepeatWrapping;a.mapDiffuseOffset&&f.map.offset.set(a.mapDiffuseOffset[0],a.mapDiffuseOffset[1]);d(f.map,b+"/"+a.mapDiffuse)}else if(a.colorDiffuse)g=(a.colorDiffuse[0]*255<<16)+(a.colorDiffuse[1]*255<<8)+a.colorDiffuse[2]*255,f.color=g,f.opacity=a.transparency;else if(a.DbgColor)f.color=a.DbgColor;if(a.mapLightmap&&b){g=document.createElement("canvas");f.lightMap=new THREE.Texture(g);f.lightMap.sourceFile=a.mapLightmap;if(a.mapLightmapRepeat)f.lightMap.repeat.set(a.mapLightmapRepeat[0],
a.mapLightmapRepeat[1]),f.lightMap.wrapS=f.lightMap.wrapT=THREE.RepeatWrapping;a.mapLightmapOffset&&f.lightMap.offset.set(a.mapLightmapOffset[0],a.mapLightmapOffset[1]);d(f.lightMap,b+"/"+a.mapLightmap)}return new THREE[e](f)}};THREE.JSONLoader=function(a){THREE.Loader.call(this,a)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;THREE.JSONLoader.prototype.supr=THREE.Loader.prototype;
f.map.wrapT=THREE.RepeatWrapping;a.mapDiffuseOffset&&f.map.offset.set(a.mapDiffuseOffset[0],a.mapDiffuseOffset[1]);d(f.map,b+"/"+a.mapDiffuse)}else if(a.colorDiffuse)g=(a.colorDiffuse[0]*255<<16)+(a.colorDiffuse[1]*255<<8)+a.colorDiffuse[2]*255,f.color=g,f.opacity=a.transparency;else if(a.DbgColor)f.color=a.DbgColor;if(a.mapLight&&b){g=document.createElement("canvas");f.lightMap=new THREE.Texture(g);f.lightMap.sourceFile=a.mapLight;if(a.mapLightmapRepeat)f.lightMap.repeat.set(a.mapLightRepeat[0],
a.mapLightRepeat[1]),f.lightMap.wrapS=f.lightMap.wrapT=THREE.RepeatWrapping;a.mapLightmapOffset&&f.lightMap.offset.set(a.mapLightmapOffset[0],a.mapLightmapOffset[1]);d(f.lightMap,b+"/"+a.mapLightmap)}return new THREE[e](f)}};THREE.JSONLoader=function(a){THREE.Loader.call(this,a)};THREE.JSONLoader.prototype=new THREE.Loader;THREE.JSONLoader.prototype.constructor=THREE.JSONLoader;THREE.JSONLoader.prototype.supr=THREE.Loader.prototype;
THREE.JSONLoader.prototype.load=function(a){var b=this,c=a.model,d=a.callback,e=a.texture_path?a.texture_path:this.extractUrlbase(c),a=new Worker(c);a.onmessage=function(a){b.createModel(a.data,d,e);b.onLoadComplete()};this.onLoadStart();a.postMessage((new Date).getTime())};
THREE.JSONLoader.prototype.createModel=function(a,b,c){var d=new THREE.Geometry,e=a.scale!==void 0?1/a.scale:1;this.init_materials(d,a.materials,c);(function(c){if(a.version===void 0||a.version!=2)console.error("Deprecated file format.");else{var b,e,h,k,l,m,n,o,u,t,v,x,w,p,y=a.faces;m=a.vertices;var z=a.normals,C=a.colors,D=0;for(b=0;b<a.uvs.length;b++)a.uvs[b].length&&D++;for(b=0;b<D;b++)d.faceUvs[b]=[],d.faceVertexUvs[b]=[];k=0;for(l=m.length;k<l;)n=new THREE.Vertex,n.position.x=m[k++]*c,n.position.y=
m[k++]*c,n.position.z=m[k++]*c,d.vertices.push(n);k=0;for(l=y.length;k<l;){c=y[k++];m=c&1;h=c&2;b=c&4;e=c&8;o=c&16;n=c&32;t=c&64;c&=128;m?(v=new THREE.Face4,v.a=y[k++],v.b=y[k++],v.c=y[k++],v.d=y[k++],m=4):(v=new THREE.Face3,v.a=y[k++],v.b=y[k++],v.c=y[k++],m=3);if(h)h=y[k++],v.materials=d.materials[h];h=d.faces.length;if(b)for(b=0;b<D;b++)x=a.uvs[b],u=y[k++],p=x[u*2],u=x[u*2+1],d.faceUvs[b][h]=new THREE.UV(p,u);if(e)for(b=0;b<D;b++){x=a.uvs[b];w=[];for(e=0;e<m;e++)u=y[k++],p=x[u*2],u=x[u*2+1],w[e]=
......@@ -162,9 +162,9 @@ t.direction,light=new THREE.DirectionalLight(D,y),light.position.set(p[0],p[1],p
if(A.fogs&&B.defaults.fog)A.scene.fog=A.fogs[B.defaults.fog];y=B.defaults.bgcolor;A.bgColor=new THREE.Color;A.bgColor.setRGB(y[0],y[1],y[2]);A.bgColorAlpha=B.defaults.bgalpha;for(m in B.geometries)if(v=B.geometries[m],v.type=="bin_mesh"||v.type=="ascii_mesh")L+=1,c.onLoadStart();M=L;for(m in B.geometries)v=B.geometries[m],v.type=="cube"?(C=new THREE.CubeGeometry(v.width,v.height,v.depth,v.segmentsWidth,v.segmentsHeight,v.segmentsDepth,null,v.flipped,v.sides),A.geometries[m]=C):v.type=="plane"?(C=
new THREE.PlaneGeometry(v.width,v.height,v.segmentsWidth,v.segmentsHeight),A.geometries[m]=C):v.type=="sphere"?(C=new THREE.SphereGeometry(v.radius,v.segmentsWidth,v.segmentsHeight),A.geometries[m]=C):v.type=="cylinder"?(C=new THREE.CylinderGeometry(v.numSegs,v.topRad,v.botRad,v.height,v.topOffset,v.botOffset),A.geometries[m]=C):v.type=="torus"?(C=new THREE.TorusGeometry(v.radius,v.tube,v.segmentsR,v.segmentsT),A.geometries[m]=C):v.type=="icosahedron"?(C=new THREE.IcosahedronGeometry(v.subdivisions),
A.geometries[m]=C):v.type=="bin_mesh"?a.load({model:d(v.url,B.urlBaseType),callback:h(m)}):v.type=="ascii_mesh"?J.load({model:d(v.url,B.urlBaseType),callback:h(m)}):v.type=="embedded_mesh"&&(v=B.embeds[v.id])&&J.createModel(v,k(m),"");for(x in B.textures)if(m=B.textures[x],m.url instanceof Array){G+=m.url.length;for(a=0;a<m.url.length;a++)c.onLoadStart()}else G+=1,c.onLoadStart();H=G;for(x in B.textures){m=B.textures[x];if(m.mapping!=void 0&&THREE[m.mapping]!=void 0)m.mapping=new THREE[m.mapping];
if(m.url instanceof Array){for(var a=[],N=0;N<m.url.length;N++)a[N]=d(m.url[N],B.urlBaseType);a=THREE.ImageUtils.loadTextureCube(a,m.mapping,I)}else{a=THREE.ImageUtils.loadTexture(d(m.url,B.urlBaseType),m.mapping,I);if(THREE[m.minFilter]!=void 0)a.minFilter=THREE[m.minFilter];if(THREE[m.magFilter]!=void 0)a.magFilter=THREE[m.magFilter]}A.textures[x]=a}for(n in B.materials){x=B.materials[n];for(z in x.parameters)if(z=="envMap"||z=="map"||z=="lightMap")x.parameters[z]=A.textures[x.parameters[z]];else if(z==
"shading")x.parameters[z]=x.parameters[z]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(z=="blending")x.parameters[z]=THREE[x.parameters[z]]?THREE[x.parameters[z]]:THREE.NormalBlending;else if(z=="combine")x.parameters[z]=x.parameters[z]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(z=="vertexColors")if(x.parameters[z]=="face")x.parameters[z]=THREE.FaceColors;else if(x.parameters[z])x.parameters[z]=THREE.VertexColors;if(x.parameters.opacity!==void 0&&x.parameters.opacity<
1)x.parameters.transparent=!0;x=new THREE[x.type](x.parameters);A.materials[n]=x}j();c.callbackSync(A)}}};
if(m.url instanceof Array){for(var a=[],N=0;N<m.url.length;N++)a[N]=d(m.url[N],B.urlBaseType);a=THREE.ImageUtils.loadTextureCube(a,m.mapping,I)}else{a=THREE.ImageUtils.loadTexture(d(m.url,B.urlBaseType),m.mapping,I);if(THREE[m.minFilter]!=void 0)a.minFilter=THREE[m.minFilter];if(THREE[m.magFilter]!=void 0)a.magFilter=THREE[m.magFilter];if(m.repeat)a.repeat.set(m.repeat[0],m.repeat[1]),a.wrapS=a.wrapT=THREE.RepeatWrapping}A.textures[x]=a}for(n in B.materials){x=B.materials[n];for(z in x.parameters)if(z==
"envMap"||z=="map"||z=="lightMap")x.parameters[z]=A.textures[x.parameters[z]];else if(z=="shading")x.parameters[z]=x.parameters[z]=="flat"?THREE.FlatShading:THREE.SmoothShading;else if(z=="blending")x.parameters[z]=THREE[x.parameters[z]]?THREE[x.parameters[z]]:THREE.NormalBlending;else if(z=="combine")x.parameters[z]=x.parameters[z]=="MixOperation"?THREE.MixOperation:THREE.MultiplyOperation;else if(z=="vertexColors")if(x.parameters[z]=="face")x.parameters[z]=THREE.FaceColors;else if(x.parameters[z])x.parameters[z]=
THREE.VertexColors;if(x.parameters.opacity!==void 0&&x.parameters.opacity<1)x.parameters.transparent=!0;x=new THREE[x.type](x.parameters);A.materials[n]=x}j();c.callbackSync(A)}}};
THREE.MarchingCubes=function(a,b){THREE.Object3D.call(this);this.materials=b instanceof Array?b:[b];this.init=function(a){this.isolation=80;this.size=a;this.size2=this.size*this.size;this.size3=this.size2*this.size;this.halfsize=this.size/2;this.delta=2/this.size;this.yd=this.size;this.zd=this.size2;this.field=new Float32Array(this.size3);this.normal_cache=new Float32Array(this.size3*3);this.vlist=new Float32Array(36);this.nlist=new Float32Array(36);this.firstDraw=!0;this.maxCount=4096;this.count=
0;this.hasNormal=this.hasPos=!1;this.positionArray=new Float32Array(this.maxCount*3);this.normalArray=new Float32Array(this.maxCount*3)};this.lerp=function(a,b,e){return a+(b-a)*e};this.VIntX=function(a,b,e,f,g,j,h,k,l,m){g=(g-l)/(m-l);l=this.normal_cache;b[f]=j+g*this.delta;b[f+1]=h;b[f+2]=k;e[f]=this.lerp(l[a],l[a+3],g);e[f+1]=this.lerp(l[a+1],l[a+4],g);e[f+2]=this.lerp(l[a+2],l[a+5],g)};this.VIntY=function(a,b,e,f,g,j,h,k,l,m){g=(g-l)/(m-l);l=this.normal_cache;b[f]=j;b[f+1]=h+g*this.delta;b[f+
2]=k;b=a+this.yd*3;e[f]=this.lerp(l[a],l[b],g);e[f+1]=this.lerp(l[a+1],l[b+1],g);e[f+2]=this.lerp(l[a+2],l[b+2],g)};this.VIntZ=function(a,b,e,f,g,j,h,k,l,m){g=(g-l)/(m-l);l=this.normal_cache;b[f]=j;b[f+1]=h;b[f+2]=k+g*this.delta;b=a+this.zd*3;e[f]=this.lerp(l[a],l[b],g);e[f+1]=this.lerp(l[a+1],l[b+1],g);e[f+2]=this.lerp(l[a+2],l[b+2],g)};this.compNorm=function(a){var b=a*3;this.normal_cache[b]==0&&(this.normal_cache[b]=this.field[a-1]-this.field[a+1],this.normal_cache[b+1]=this.field[a-this.yd]-this.field[a+
......
......@@ -207,16 +207,16 @@ THREE.Loader.prototype = {
}
if ( m.mapLightmap && texture_path ) {
if ( m.mapLight && texture_path ) {
texture = document.createElement( 'canvas' );
mpars.lightMap = new THREE.Texture( texture );
mpars.lightMap.sourceFile = m.mapLightmap;
mpars.lightMap.sourceFile = m.mapLight;
if( m.mapLightmapRepeat ) {
mpars.lightMap.repeat.set( m.mapLightmapRepeat[ 0 ], m.mapLightmapRepeat[ 1 ] );
mpars.lightMap.repeat.set( m.mapLightRepeat[ 0 ], m.mapLightRepeat[ 1 ] );
mpars.lightMap.wrapS = mpars.lightMap.wrapT = THREE.RepeatWrapping;
}
......
......@@ -589,6 +589,13 @@ THREE.SceneLoader.prototype = {
if ( THREE[ tt.magFilter ] != undefined )
texture.magFilter = THREE[ tt.magFilter ];
if ( tt.repeat ) {
texture.repeat.set( tt.repeat[ 0 ], tt.repeat[ 1 ] );
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
}
}
......
......@@ -20,7 +20,6 @@
Blender exporter for Three.js (ASCII JSON format).
TODO
- export scene
- copy used images to folder where exported file goes
- binary format
"""
......@@ -162,7 +161,7 @@ TEMPLATE_GEOMETRY_EMBED = """\
TEMPLATE_TEXTURE = """\
%(texture_id)s : {
"url": %(texture_file)s
"url": %(texture_file)s%(extras)s
}"""
TEMPLATE_MATERIAL_SCENE = """\
......@@ -755,11 +754,17 @@ def extract_materials(mesh, scene, option_colors):
material["specularCoef"] = m.specular_hardness
if m.active_texture and m.active_texture.type == 'IMAGE' and m.active_texture.image:
fn = bpy.path.abspath(m.active_texture.image.filepath)
texture = m.active_texture
if texture and texture.type == 'IMAGE' and texture.image:
fn = bpy.path.abspath(texture.image.filepath)
fn = os.path.normpath(fn)
fn_strip = os.path.basename(fn)
material['mapDiffuse'] = fn_strip
if texture.repeat_x != 1 or texture.repeat_y != 1:
material['mapDiffuseRepeat'] = [texture.repeat_x, texture.repeat_y]
material["vertexColors"] = m.THREE_useVertexColors and option_colors
......@@ -769,7 +774,7 @@ def extract_materials(mesh, scene, option_colors):
# material['shading'] = "Phong"
#else:
# material['shading'] = "Lambert"
material['shading'] = m.THREE_materialType
return materials
......@@ -1182,16 +1187,25 @@ def generate_textures_scene(data):
# TODO: extract just textures actually used by some objects in the scene
for img in bpy.data.images:
for texture in bpy.data.textures:
texture_id = img.name
texture_file = extract_texture_filename(img)
if texture.type == 'IMAGE' and texture.image:
texture_string = TEMPLATE_TEXTURE % {
"texture_id" : generate_string(texture_id),
"texture_file" : generate_string(texture_file)
}
chunks.append(texture_string)
img = texture.image
texture_id = img.name
texture_file = extract_texture_filename(img)
extras = ""
if texture.repeat_x != 1 or texture.repeat_y != 1:
extras = ',\n "repeat": [%f, %f]' % (texture.repeat_x, texture.repeat_y)
texture_string = TEMPLATE_TEXTURE % {
"texture_id" : generate_string(texture_id),
"texture_file" : generate_string(texture_file),
"extras" : extras
}
chunks.append(texture_string)
return ",\n\n".join(chunks), len(chunks)
......@@ -1251,20 +1265,18 @@ def extract_material_data(m, option_colors):
if t.use_normal_map:
material['mapNormal'] = name
else:
if not material['mapDiffuse']:
material['mapDiffuse'] = name
else:
material['mapLight'] = name
if material['mapDiffuse'] and material['mapNormal'] and material['mapLight']:
break
#if m.specular_intensity > 0.0 and (m.specular_color[0] > 0 or m.specular_color[1] > 0 or m.specular_color[2] > 0):
# material['shading'] = "Phong"
#else:
# material['shading'] = "Lambert"
material['shading'] = m.THREE_materialType
return material
......@@ -1462,7 +1474,7 @@ def generate_ascii_scene(data):
default_camera = ""
if data["use_cameras"]:
default_camera = generate_string("default_camera")
default_camera = "default_camera"
parameters = {
"fname" : data["source_file"],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册