提交 2b599e1a 编写于 作者: A alteredq

Added support for texture repeat and offset in model JSONs to Loader base class.

上级 95966678
......@@ -469,8 +469,9 @@ this.computeFaceNormals();this.computeVertexNormals()};THREE.TorusKnotGeometry.p
THREE.Loader.prototype={addStatusElement:function(){var b=document.createElement("div");b.style.position="absolute";b.style.right="0px";b.style.top="0px";b.style.fontSize="0.8em";b.style.textAlign="left";b.style.background="rgba(0,0,0,0.25)";b.style.color="#fff";b.style.width="120px";b.style.padding="0.5em 0.5em 0.5em 0.5em";b.style.zIndex=1E3;b.innerHTML="Loading ...";return b},updateProgress:function(b){var c="Loaded ";c+=b.total?(100*b.loaded/b.total).toFixed(0)+"%":(b.loaded/1E3).toFixed(2)+" KB";
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,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,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;
"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;
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]=
......
此差异已折叠。
......@@ -180,6 +180,19 @@ THREE.Loader.prototype = {
mpars.map = new THREE.Texture( texture );
mpars.map.sourceFile = m.mapDiffuse;
if( m.mapDiffuseRepeat ) {
mpars.map.repeat.set( m.mapDiffuseRepeat[ 0 ], m.mapDiffuseRepeat[ 1 ] );
mpars.map.wrapS = mpars.map.wrapT = THREE.RepeatWrapping;
}
if( m.mapDiffuseOffset ) {
mpars.map.offset.set( m.mapDiffuseOffset[ 0 ], m.mapDiffuseOffset[ 1 ] );
}
load_image( mpars.map, texture_path + "/" + m.mapDiffuse );
} else if ( m.colorDiffuse ) {
......@@ -201,6 +214,19 @@ THREE.Loader.prototype = {
mpars.lightMap = new THREE.Texture( texture );
mpars.lightMap.sourceFile = m.mapLightmap;
if( m.mapLightmapRepeat ) {
mpars.lightMap.repeat.set( m.mapLightmapRepeat[ 0 ], m.mapLightmapRepeat[ 1 ] );
mpars.lightMap.wrapS = mpars.lightMap.wrapT = THREE.RepeatWrapping;
}
if( m.mapLightmapOffset ) {
mpars.lightMap.offset.set( m.mapLightmapOffset[ 0 ], m.mapLightmapOffset[ 1 ] );
}
load_image( mpars.lightMap, texture_path + "/" + m.mapLightmap );
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册